diff --git a/.gitmodules b/.gitmodules index d9925a32df..6a47fa9da8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,7 +17,7 @@ path = deps/juno url = https://github.com/CosmosContracts/juno.git [submodule "deps/osmosis"] - # Commit: v20.5.0-no-fees + # Commit: v27.0.0-no-fees path = deps/osmosis url = https://github.com/Stride-Labs/osmosis.git [submodule "deps/stargaze"] diff --git a/app/app.go b/app/app.go index 721c889d7a..a7fa69bba7 100644 --- a/app/app.go +++ b/app/app.go @@ -129,6 +129,14 @@ import ( airdrop "github.com/Stride-Labs/stride/v24/x/airdrop" airdropkeeper "github.com/Stride-Labs/stride/v24/x/airdrop/keeper" airdroptypes "github.com/Stride-Labs/stride/v24/x/airdrop/types" + "github.com/Stride-Labs/stride/v24/x/auction" + auctionkeeper "github.com/Stride-Labs/stride/v24/x/auction/keeper" + auctiontypes "github.com/Stride-Labs/stride/v24/x/auction/types" + + "github.com/Stride-Labs/stride/v24/x/strdburner" + strdburnerkeeper "github.com/Stride-Labs/stride/v24/x/strdburner/keeper" + strdburnertypes "github.com/Stride-Labs/stride/v24/x/strdburner/types" + "github.com/Stride-Labs/stride/v24/x/autopilot" autopilotkeeper "github.com/Stride-Labs/stride/v24/x/autopilot/keeper" autopilottypes "github.com/Stride-Labs/stride/v24/x/autopilot/types" @@ -146,6 +154,9 @@ import ( icaoracle "github.com/Stride-Labs/stride/v24/x/icaoracle" icaoraclekeeper "github.com/Stride-Labs/stride/v24/x/icaoracle/keeper" icaoracletypes "github.com/Stride-Labs/stride/v24/x/icaoracle/types" + icqoracle "github.com/Stride-Labs/stride/v24/x/icqoracle" + icqoraclekeeper "github.com/Stride-Labs/stride/v24/x/icqoracle/keeper" + icqoracletypes "github.com/Stride-Labs/stride/v24/x/icqoracle/types" "github.com/Stride-Labs/stride/v24/x/interchainquery" interchainquerykeeper "github.com/Stride-Labs/stride/v24/x/interchainquery/keeper" interchainquerytypes "github.com/Stride-Labs/stride/v24/x/interchainquery/types" @@ -236,6 +247,9 @@ var ( ibchooks.AppModuleBasic{}, ibcwasm.AppModuleBasic{}, airdrop.AppModuleBasic{}, + icqoracle.AppModuleBasic{}, + auction.AppModuleBasic{}, + strdburner.AppModuleBasic{}, ) // module account permissions @@ -260,6 +274,10 @@ var ( stakedymtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, stakedymtypes.FeeAddress: nil, wasmtypes.ModuleName: {authtypes.Burner}, + icqoracletypes.ModuleName: nil, + auctiontypes.ModuleName: nil, + // strdburner module needs burn access to burn STRD tokens that are sent to it + strdburnertypes.ModuleName: {authtypes.Burner}, } ) @@ -348,6 +366,9 @@ type StrideApp struct { StaketiaKeeper staketiakeeper.Keeper StakedymKeeper stakedymkeeper.Keeper AirdropKeeper airdropkeeper.Keeper + ICQOracleKeeper icqoraclekeeper.Keeper + AuctionKeeper auctionkeeper.Keeper + StrdBurnerKeeper strdburnerkeeper.Keeper mm *module.Manager sm *module.SimulationManager @@ -404,6 +425,9 @@ func NewStrideApp( ibchookstypes.StoreKey, ibcwasmtypes.StoreKey, airdroptypes.StoreKey, + icqoracletypes.StoreKey, + auctiontypes.StoreKey, + strdburnertypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -757,6 +781,29 @@ func NewStrideApp( app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.StakingKeeper, ) + app.ICQOracleKeeper = *icqoraclekeeper.NewKeeper( + appCodec, + keys[icqoracletypes.StoreKey], + ) + icqOracleModule := icqoracle.NewAppModule(appCodec, app.ICQOracleKeeper) + + app.AuctionKeeper = *auctionkeeper.NewKeeper( + appCodec, + keys[auctiontypes.StoreKey], + app.AccountKeeper, + app.BankKeeper, + app.ICQOracleKeeper, + ) + auctionModule := auction.NewAppModule(appCodec, app.AuctionKeeper) + + app.StrdBurnerKeeper = *strdburnerkeeper.NewKeeper( + appCodec, + keys[strdburnertypes.StoreKey], + app.AccountKeeper, + app.BankKeeper, + ) + strdburnerModule := strdburner.NewAppModule(appCodec, app.StrdBurnerKeeper) + // Register Gov (must be registered after stakeibc) govRouter := govtypesv1beta1.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypesv1beta1.ProposalHandler). @@ -933,6 +980,10 @@ func NewStrideApp( stakeTiaModule, stakeDymModule, airdropModule, + stakeTiaModule, + icqOracleModule, + auctionModule, + strdburnerModule, ) // During begin block slashing happens after distr.BeginBlocker so that @@ -978,6 +1029,9 @@ func NewStrideApp( ibchookstypes.ModuleName, ibcwasmtypes.ModuleName, airdroptypes.ModuleName, + icqoracletypes.ModuleName, + auctiontypes.ModuleName, + strdburnertypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -1019,6 +1073,9 @@ func NewStrideApp( ibchookstypes.ModuleName, ibcwasmtypes.ModuleName, airdroptypes.ModuleName, + icqoracletypes.ModuleName, + auctiontypes.ModuleName, + strdburnertypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -1065,6 +1122,9 @@ func NewStrideApp( ibchookstypes.ModuleName, ibcwasmtypes.ModuleName, airdroptypes.ModuleName, + icqoracletypes.ModuleName, + auctiontypes.ModuleName, + strdburnertypes.ModuleName, ) app.mm.RegisterInvariants(app.CrisisKeeper) diff --git a/app/upgrades.go b/app/upgrades.go index fbcc5f36fa..bfb35d4694 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -34,6 +34,7 @@ import ( v22 "github.com/Stride-Labs/stride/v24/app/upgrades/v22" v23 "github.com/Stride-Labs/stride/v24/app/upgrades/v23" v24 "github.com/Stride-Labs/stride/v24/app/upgrades/v24" + v25 "github.com/Stride-Labs/stride/v24/app/upgrades/v25" v3 "github.com/Stride-Labs/stride/v24/app/upgrades/v3" v4 "github.com/Stride-Labs/stride/v24/app/upgrades/v4" v5 "github.com/Stride-Labs/stride/v24/app/upgrades/v5" @@ -46,6 +47,9 @@ import ( claimtypes "github.com/Stride-Labs/stride/v24/x/claim/types" icacallbacktypes "github.com/Stride-Labs/stride/v24/x/icacallbacks/types" icaoracletypes "github.com/Stride-Labs/stride/v24/x/icaoracle/types" + auctiontypes "github.com/Stride-Labs/stride/v24/x/icqoracle/types" + icqoracletypes "github.com/Stride-Labs/stride/v24/x/icqoracle/types" + strdburnertypes "github.com/Stride-Labs/stride/v24/x/icqoracle/types" recordtypes "github.com/Stride-Labs/stride/v24/x/records/types" stakedymtypes "github.com/Stride-Labs/stride/v24/x/stakedym/types" stakeibctypes "github.com/Stride-Labs/stride/v24/x/stakeibc/types" @@ -324,6 +328,16 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { ), ) + // v25 upgrade handler + app.UpgradeKeeper.SetUpgradeHandler( + v25.UpgradeName, + v25.CreateUpgradeHandler( + app.mm, + app.configurator, + app.ICQOracleKeeper, + ), + ) + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() if err != nil { panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err)) @@ -385,6 +399,10 @@ func (app *StrideApp) setupUpgradeHandlers(appOpts servertypes.AppOptions) { storeUpgrades = &storetypes.StoreUpgrades{ Added: []string{ibcwasmtypes.ModuleName, airdroptypes.ModuleName}, } + case "v25": + storeUpgrades = &storetypes.StoreUpgrades{ + Added: []string{icqoracletypes.ModuleName, strdburnertypes.ModuleName, auctiontypes.ModuleName}, + } } if storeUpgrades != nil { diff --git a/app/upgrades/v25/upgrades.go b/app/upgrades/v25/upgrades.go new file mode 100644 index 0000000000..45d09032e6 --- /dev/null +++ b/app/upgrades/v25/upgrades.go @@ -0,0 +1,39 @@ +package v25 + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + icqoraclekeeper "github.com/Stride-Labs/stride/v24/x/icqoracle/keeper" + icqoracletypes "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +var UpgradeName = "v25" + +// CreateUpgradeHandler creates an SDK upgrade handler for v23 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + icqoracleKeeper icqoraclekeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Starting upgrade v25...") + + err := icqoracleKeeper.SetParams(ctx, icqoracletypes.Params{ + OsmosisChainId: "osmosis-1", + OsmosisConnectionId: "connection-2", + UpdateIntervalSec: 5 * 60, // 5 min + PriceExpirationTimeoutSec: 10 * 60, // 10 min + IcqTimeoutSec: 2 * 60, // 2 min + }) + if err != nil { + panic(fmt.Errorf("unable to set icqoracle params: %w", err)) + } + + ctx.Logger().Info("Running module migrations...") + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/deps/osmosis b/deps/osmosis index 30532bd83e..2ce269b07f 160000 --- a/deps/osmosis +++ b/deps/osmosis @@ -1 +1 @@ -Subproject commit 30532bd83ebac4e8985fb9d4ead91bc2722810fb +Subproject commit 2ce269b07f4b6cec6649fbe7994dbf2e7d386e7d diff --git a/dockernet/config.sh b/dockernet/config.sh index bf52f7c7a2..def4d63ed4 100755 --- a/dockernet/config.sh +++ b/dockernet/config.sh @@ -35,7 +35,7 @@ ACCESSORY_CHAINS=() if [[ "${ALL_HOST_CHAINS:-false}" == "true" ]]; then HOST_CHAINS=(GAIA EVMOS HOST) elif [[ "${#HOST_CHAINS[@]}" == "0" ]]; then - HOST_CHAINS=(GAIA) + HOST_CHAINS=(GAIA OSMO) fi REWARD_CONVERTER_HOST_ZONE=${HOST_CHAINS[0]} diff --git a/dockernet/dockerfiles/Dockerfile.osmo b/dockernet/dockerfiles/Dockerfile.osmo index e8e0278b3b..caf8d5c980 100644 --- a/dockernet/dockerfiles/Dockerfile.osmo +++ b/dockernet/dockerfiles/Dockerfile.osmo @@ -1,10 +1,10 @@ -FROM golang:1.20-alpine3.16 AS builder +FROM golang:1.23-alpine3.21 AS builder WORKDIR /opt/ RUN set -eux; apk add --no-cache ca-certificates build-base; apk add git linux-headers -ENV COMMIT_HASH=v20.5.0-no-fees +ENV COMMIT_HASH=v27.0.0-no-fees RUN git clone https://github.com/Stride-Labs/osmosis.git \ && cd osmosis \ @@ -13,16 +13,16 @@ RUN git clone https://github.com/Stride-Labs/osmosis.git \ WORKDIR /opt/osmosis # Cosmwasm - download correct libwasmvm version and verify checksum -# Note: checksum not available for v1.2.3, otherwise command should be -# wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt -# && sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1) -RUN WASMVM_VERSION=v1.2.3 \ - && wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \ - -O /lib/libwasmvm_muslc.a +RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm/v2 | sed 's/.* //') && \ + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \ + -O /lib/libwasmvm_muslc.$ARCH.a && \ + # verify checksum + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \ + sha256sum /lib/libwasmvm_muslc.$ARCH.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1) RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build -FROM alpine:3.16 +FROM alpine:3.21 COPY --from=builder /opt/osmosis/build/osmosisd /usr/local/bin/ RUN apk add bash vim \ && addgroup -g 1000 osmosis \ diff --git a/dockernet/ts-tests/README.md b/dockernet/ts-tests/README.md index d04d6a260a..05faa81347 100644 --- a/dockernet/ts-tests/README.md +++ b/dockernet/ts-tests/README.md @@ -2,7 +2,7 @@ ```bash # build stride locally and run dokcernet -(cd ../.. && make sync && make start-docker build=sgr) +(cd ../.. && make sync && make start-docker build=sgro) # install deps pnpm i @@ -23,9 +23,11 @@ IMPORTANT: `@cosmjs/*` dependencies must match the versions used by stridejs. To ### test new protobufs - go to https://github.com/Stride-Labs/stridejs + - remove `/dist` from `.gitignore` - update the config in `scripts/clone_repos.ts` to point to the new `stride/cosmos-sdk/ibc-go` version - run `pnpm i` - run `pnpm codegen` + - run `pnpm build` - run `git commit...` - run `git push` - get the current `stridejs` commit using `git rev-parse HEAD` diff --git a/dockernet/ts-tests/package.json b/dockernet/ts-tests/package.json index 0a96351a1d..3dfef7a28a 100644 --- a/dockernet/ts-tests/package.json +++ b/dockernet/ts-tests/package.json @@ -1,10 +1,11 @@ { "name": "stride-integration-tests", "version": "1.0.0", + "type": "module", "description": "integration tests for stride chain", "scripts": { - "test": "vitest run", - "test-watch": "vitest watch" + "test": "NODE_OPTIONS=--conditions=node vitest run", + "test-watch": "NODE_OPTIONS=--conditions=node vitest watch" }, "keywords": [ "wow", @@ -25,7 +26,7 @@ "bech32": "2.0.0", "jest": "29.7.0", "prettier": "3.3.3", - "stridejs": "github:Stride-Labs/stridejs#e17c404f6451bad95ef0093f2b41244248bd7ebd", + "stridejs": "github:Stride-Labs/stridejs#e949e35", "typescript": "5.5.3", "vitest": "2.0.3" }, diff --git a/dockernet/ts-tests/pnpm-lock.yaml b/dockernet/ts-tests/pnpm-lock.yaml index 6963e63875..79354fd853 100644 --- a/dockernet/ts-tests/pnpm-lock.yaml +++ b/dockernet/ts-tests/pnpm-lock.yaml @@ -42,8 +42,8 @@ importers: specifier: 3.3.3 version: 3.3.3 stridejs: - specifier: github:Stride-Labs/stridejs#e17c404f6451bad95ef0093f2b41244248bd7ebd - version: https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e17c404f6451bad95ef0093f2b41244248bd7ebd + specifier: github:Stride-Labs/stridejs#e949e35 + version: https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e949e35 typescript: specifier: 5.5.3 version: 5.5.3 @@ -209,10 +209,6 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 - '@babel/runtime@7.24.8': - resolution: {integrity: sha512-5F7SDGs1T72ZczbRwbGO9lQi0NLjQxzl6i4lJxLxfW9U5UluCSyEJeniWvnhl3/euNiqQVbo8zruhsDfid0esA==} - engines: {node: '>=6.9.0'} - '@babel/template@7.24.7': resolution: {integrity: sha512-jYqfPrU9JTF0PmPy1tLYHW4Mp4KlgxJD9l2nP9fD6yT/ICi554DmrWBAEYpIelzjHf1msDP3PxJIRt/nFNfBig==} engines: {node: '>=6.9.0'} @@ -1587,9 +1583,6 @@ packages: readonly-date@1.0.0: resolution: {integrity: sha512-tMKIV7hlk0h4mO3JTmmVuIlJVXjKk3Sep9Bf5OH0O+758ruuVkUy2J9SttDLm91IEX/WHlXPSpxMGjPj4beMIQ==} - regenerator-runtime@0.14.1: - resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} - require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -1676,9 +1669,9 @@ packages: std-env@3.7.0: resolution: {integrity: sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==} - stridejs@https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e17c404f6451bad95ef0093f2b41244248bd7ebd: - resolution: {tarball: https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e17c404f6451bad95ef0093f2b41244248bd7ebd} - version: 0.10.0-alpha + stridejs@https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e949e35: + resolution: {tarball: https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e949e35} + version: 0.11.4 string-length@4.0.2: resolution: {integrity: sha512-+l6rNN5fYHNhZZy41RXsYptCjA2Igmq4EG7kZAYFQI1E1VTXarr6ZPXBg6eq7Y6eK4FEhY6AJlyuFIb/v/S0VQ==} @@ -2111,10 +2104,6 @@ snapshots: '@babel/core': 7.24.9 '@babel/helper-plugin-utils': 7.24.8 - '@babel/runtime@7.24.8': - dependencies: - regenerator-runtime: 0.14.1 - '@babel/template@7.24.7': dependencies: '@babel/code-frame': 7.24.7 @@ -3753,8 +3742,6 @@ snapshots: readonly-date@1.0.0: {} - regenerator-runtime@0.14.1: {} - require-directory@2.1.1: {} resolve-cwd@3.0.0: @@ -3838,9 +3825,8 @@ snapshots: std-env@3.7.0: {} - stridejs@https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e17c404f6451bad95ef0093f2b41244248bd7ebd: + stridejs@https://codeload.github.com/Stride-Labs/stridejs/tar.gz/e949e35: dependencies: - '@babel/runtime': 7.24.8 '@cosmjs/amino': 0.32.4 '@cosmjs/encoding': 0.32.4 '@cosmjs/math': 0.32.4 diff --git a/dockernet/ts-tests/test/main.test.ts b/dockernet/ts-tests/test/main.test.ts index f2c76536e6..5b69fcf64e 100644 --- a/dockernet/ts-tests/test/main.test.ts +++ b/dockernet/ts-tests/test/main.test.ts @@ -131,12 +131,13 @@ describe("x/airdrop", () => { } expect(tx.code).toBe(0); - const { airdrop } = await stridejs.query.stride.airdrop.airdrop({ - id: airdropId, - }); + const { id, earlyClaimPenalty } = + await stridejs.query.stride.airdrop.airdrop({ + id: airdropId, + }); - expect(airdrop!.id).toBe(airdropId); - expect(airdrop!.earlyClaimPenalty).toBe("0.5"); + expect(id).toBe(airdropId); + expect(earlyClaimPenalty).toBe("0.5"); }); }); diff --git a/dockernet/ts-tests/vitest.config.ts b/dockernet/ts-tests/vitest.config.ts new file mode 100644 index 0000000000..c5659342b7 --- /dev/null +++ b/dockernet/ts-tests/vitest.config.ts @@ -0,0 +1,26 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + globals: true, + environment: "node", + testTimeout: 30000, + hookTimeout: 30000, + pool: "forks", + poolOptions: { + forks: { + singleFork: true, + }, + }, + server: { + deps: { + inline: ["stridejs"], + }, + }, + }, + resolve: { + alias: { + stridejs: "stridejs/dist/esm", // Force ESM path + }, + }, +}); diff --git a/proto/stride/auction/auction.proto b/proto/stride/auction/auction.proto new file mode 100644 index 0000000000..91136ecd0f --- /dev/null +++ b/proto/stride/auction/auction.proto @@ -0,0 +1,60 @@ +syntax = "proto3"; +package stride.auction; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/auction/types"; + +enum AuctionType { + // Default value - should not be used + AUCTION_TYPE_UNSPECIFIED = 0; + // First-Come First-Served auction + AUCTION_TYPE_FCFS = 1; +} +message Params {} + +message Auction { + // Auction type + AuctionType type = 1; + + // A unique auction name + string name = 2; + + // Token denom being sold in the auction + string selling_denom = 3; + + // Token denom used to place bids + string payment_denom = 4; + + // Whether auction is active + bool enabled = 5; + + // Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle price) + // bids_floor_price = oracle_price * min_price_multiplier + string min_price_multiplier = 6 [ + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; + + // Minimum payment token bid amount + string min_bid_amount = 7 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + // Address to send the auction proceeds to + string beneficiary = 8 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // Total amount of payment token received + string total_payment_token_received = 9 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + // Total amount of selling token sold + string total_selling_token_sold = 10 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/stride/auction/genesis.proto b/proto/stride/auction/genesis.proto new file mode 100644 index 0000000000..3d3fca6871 --- /dev/null +++ b/proto/stride/auction/genesis.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package stride.auction; + +import "gogoproto/gogo.proto"; +import "stride/auction/auction.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/auction/types"; + +// GenesisState defines the auction module's genesis state +message GenesisState { + // Module parameters + Params params = 1 [ (gogoproto.nullable) = false ]; + + // List of token auctions + repeated Auction auctions = 2 [ (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/stride/auction/query.proto b/proto/stride/auction/query.proto new file mode 100644 index 0000000000..7586a64cc7 --- /dev/null +++ b/proto/stride/auction/query.proto @@ -0,0 +1,45 @@ +syntax = "proto3"; +package stride.auction; + +import "cosmos/base/query/v1beta1/pagination.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "stride/auction/auction.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/auction/types"; + +// Query defines the gRPC querier service. +service Query { + // Auction queries the auction info for a specific token + rpc Auction(QueryAuctionRequest) returns (QueryAuctionResponse) { + option (google.api.http).get = "/stride/auction/{name}"; + } + + // Auctions queries the auction info for a specific token + rpc Auctions(QueryAuctionsRequest) returns (QueryAuctionsResponse) { + option (google.api.http).get = "/stride/auction/auctions"; + } +} + +// QueryAuctionRequest is the request type for the Query/Auction RPC +// method +message QueryAuctionRequest { string name = 1; } + +// QueryAuctionResponse is the response type for the Query/Auction RPC +// method +message QueryAuctionResponse { + Auction auction = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryAuctionsRequest is the request type for the +// Query/Auctions RPC method +message QueryAuctionsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryAuctionsResponse is the response type for the +// Query/Auctions RPC method +message QueryAuctionsResponse { + repeated Auction auctions = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} diff --git a/proto/stride/auction/tx.proto b/proto/stride/auction/tx.proto new file mode 100644 index 0000000000..c58a98b9e1 --- /dev/null +++ b/proto/stride/auction/tx.proto @@ -0,0 +1,129 @@ +syntax = "proto3"; +package stride.auction; + +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "gogoproto/gogo.proto"; +import "stride/auction/auction.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/auction/types"; + +// Msg defines the Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // User messages + + // PlaceBid places a bid to buy a token off an auction + rpc PlaceBid(MsgPlaceBid) returns (MsgPlaceBidResponse); + + // Admin messages + + // CreateAuction creates a new auction + rpc CreateAuction(MsgCreateAuction) returns (MsgCreateAuctionResponse); + // CreateAuction updates an existing auction + rpc UpdateAuction(MsgUpdateAuction) returns (MsgUpdateAuctionResponse); +} + +// MsgPlaceBid defines the message for bidding in a token auction +message MsgPlaceBid { + option (cosmos.msg.v1.signer) = "bidder"; + option (amino.name) = "auction/MsgPlaceBid"; + + // Bidder's address + string bidder = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // Token being bid on + string auction_name = 2; + + // Amount of tokens requested in base units (utoken) + string selling_token_amount = 3 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + // Amount of tokens being paid in base units (utoken) + string payment_token_amount = 4 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} + +message MsgPlaceBidResponse {} + +// MsgCreateAuction defines the message for adding a token auction +message MsgCreateAuction { + option (cosmos.msg.v1.signer) = "admin"; + option (amino.name) = "auction/MsgCreateAuction"; + + // Admin's address + string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // A unique auction name + string auction_name = 2; + + // Auction type + AuctionType auction_type = 3; + + // Denom on Stride of the token being auctioned off (e.g. "ibc/...") + string selling_denom = 4; + + // Denom on Stride of the token being used to place bids (e.g. "ustrd") + string payment_denom = 5; + + // Whether auction is active + bool enabled = 6; + + // Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle price) + // bids_floor_price = oracle_price * min_price_multiplier + string min_price_multiplier = 7 [ + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; + + // Minimum payment token bid amount + string min_bid_amount = 8 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + string beneficiary = 9 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgCreateAuctionResponse {} + +// MsgUpdateAuction defines the message for adding a token auction +message MsgUpdateAuction { + option (cosmos.msg.v1.signer) = "admin"; + option (amino.name) = "auction/MsgUpdateAuction"; + + // Admin's address + string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // A unique auction name + string auction_name = 2; + + // Auction type + AuctionType auction_type = 3; + + // Whether auction is active + bool enabled = 4; + + // Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle price) + // bids_floor_price = oracle_price * min_price_multiplier + string min_price_multiplier = 5 [ + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; + + // Minimum payment token bid amount + string min_bid_amount = 6 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + + string beneficiary = 7 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +message MsgUpdateAuctionResponse {} diff --git a/proto/stride/icqoracle/genesis.proto b/proto/stride/icqoracle/genesis.proto new file mode 100644 index 0000000000..b82dfdf0c6 --- /dev/null +++ b/proto/stride/icqoracle/genesis.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package stride.icqoracle; + +import "gogoproto/gogo.proto"; +import "stride/icqoracle/icqoracle.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/icqoracle/types"; + +// GenesisState defines the icqoracle module's genesis state +message GenesisState { + // Module parameters + Params params = 1 [ (gogoproto.nullable) = false ]; + + // List of token prices + repeated TokenPrice token_prices = 2 [ (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/stride/icqoracle/icqoracle.proto b/proto/stride/icqoracle/icqoracle.proto new file mode 100644 index 0000000000..97d28489b3 --- /dev/null +++ b/proto/stride/icqoracle/icqoracle.proto @@ -0,0 +1,67 @@ +syntax = "proto3"; +package stride.icqoracle; + +import "gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/icqoracle/types"; + +// TokenPrice stores latest price data for a token +message TokenPrice { + // Token denom on Stride + string base_denom = 1; + // Quote denom on Stride + string quote_denom = 2; + // Token denom on Osmosis + string osmosis_base_denom = 3; + // Quote denom on Osmosis + string osmosis_quote_denom = 4; + // Pool ID on Osmosis + string osmosis_pool_id = 5; + + // Spot price of base_denom denominated in quote_denom + string spot_price = 6 [ + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (gogoproto.nullable) = false + ]; + + // Last update timestamp + google.protobuf.Timestamp updated_at = 7 + [ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + + // Whether there is a spot price query currently in progress + bool query_in_progress = 8; +} + +// OracleParams stores global oracle parameters +message Params { + // Osmosis chain identifier + string osmosis_chain_id = 1 [ + (gogoproto.moretags) = "yaml:\"osmosis_chain_id\"", + (gogoproto.jsontag) = "osmosis_chain_id" + ]; + + // Osmosis IBC connection identifier + string osmosis_connection_id = 2 [ + (gogoproto.moretags) = "yaml:\"osmosis_connection_id\"", + (gogoproto.jsontag) = "osmosis_connection_id" + ]; + + // Time between price updates + uint64 update_interval_sec = 3 [ + (gogoproto.moretags) = "yaml:\"update_interval_sec\"", + (gogoproto.jsontag) = "update_interval_sec" + ]; + + // Max time before price is considered stale/expired + uint64 price_expiration_timeout_sec = 4 [ + (gogoproto.moretags) = "yaml:\"price_expiration_timeout_sec\"", + (gogoproto.jsontag) = "price_expiration_timeout_sec" + ]; + + // ICQ timeout + uint64 icq_timeout_sec = 5 [ + (gogoproto.moretags) = "yaml:\"icq_timeout_sec\"", + (gogoproto.jsontag) = "icq_timeout_sec" + ]; +} diff --git a/proto/stride/icqoracle/query.proto b/proto/stride/icqoracle/query.proto new file mode 100644 index 0000000000..d4797039ee --- /dev/null +++ b/proto/stride/icqoracle/query.proto @@ -0,0 +1,84 @@ +syntax = "proto3"; +package stride.icqoracle; + +import "stride/icqoracle/icqoracle.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/icqoracle/types"; + +// Query defines the gRPC querier service. +service Query { + // TokenPrice queries the current price for a specific token + rpc TokenPrice(QueryTokenPriceRequest) returns (QueryTokenPriceResponse) { + option (google.api.http).get = "/stride/icqoracle/price"; + } + + // TokenPrices queries all token prices + rpc TokenPrices(QueryTokenPricesRequest) returns (QueryTokenPricesResponse) { + option (google.api.http).get = "/stride/icqoracle/prices"; + } + + // Params queries the oracle parameters + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/stride/icqoracle/params"; + } + + // TokenPriceForQuoteDenom queries the exchange rate between two tokens + rpc TokenPriceForQuoteDenom(QueryTokenPriceForQuoteDenomRequest) + returns (QueryTokenPriceForQuoteDenomResponse) { + option (google.api.http).get = "/stride/icqoracle/quote_price"; + } +} + +// QueryTokenPriceRequest is the request type for the Query/TokenPrice RPC +// method +message QueryTokenPriceRequest { + string base_denom = 1; + string quote_denom = 2; + string pool_id = 3; +} + +// QueryTokenPriceResponse is the response type for the Query/TokenPrice RPC +// method +message QueryTokenPriceResponse { + TokenPrice token_price = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryTokenPricesRequest is the request type for the Query/TokenPrices RPC +// method +message QueryTokenPricesRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryTokenPricesResponse is the response type for the Query/TokenPrices RPC +// method +message QueryTokenPricesResponse { + repeated TokenPrice token_prices = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + +// QueryParamsRequest is the request type for the Query/Params RPC method +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method +message QueryParamsResponse { + Params params = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryTokenPriceForQuoteDenomRequest is the request type for the +// Query/TokenPriceForQuoteDenom RPC method +message QueryTokenPriceForQuoteDenomRequest { + string base_denom = 1; + string quote_denom = 2; +} + +// QueryTokenPriceForQuoteDenomResponse is the response type for the +// Query/TokenPriceForQuoteDenom RPC method +message QueryTokenPriceForQuoteDenomResponse { + string price = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/proto/stride/icqoracle/tx.proto b/proto/stride/icqoracle/tx.proto new file mode 100644 index 0000000000..2a1624ed8d --- /dev/null +++ b/proto/stride/icqoracle/tx.proto @@ -0,0 +1,60 @@ +syntax = "proto3"; +package stride.icqoracle; + +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/icqoracle/types"; + +// Msg defines the Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // RegisterTokenPriceQuery registers a new token to track prices for + rpc RegisterTokenPriceQuery(MsgRegisterTokenPriceQuery) + returns (MsgRegisterTokenPriceQueryResponse); + + // RemoveTokenPriceQuery removes a token from price tracking + rpc RemoveTokenPriceQuery(MsgRemoveTokenPriceQuery) + returns (MsgRemoveTokenPriceQueryResponse); +} + +// MsgRegisterTokenPriceQuery defines the message for adding a new token to +// track prices +message MsgRegisterTokenPriceQuery { + option (cosmos.msg.v1.signer) = "admin"; + option (amino.name) = "icqoracle/MsgRegisterTokenPriceQuery"; + + string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // Token denom on Stride + string base_denom = 2; + // Quote denom on Stride + string quote_denom = 3; + // Token denom on Osmosis + string osmosis_base_denom = 4; + // Quote denom on Osmosis + string osmosis_quote_denom = 5; + // Pool ID on Osmosis + string osmosis_pool_id = 6; +} + +message MsgRegisterTokenPriceQueryResponse {} + +// MsgRemoveTokenPriceQuery defines the message for removing a token from price +// tracking +message MsgRemoveTokenPriceQuery { + option (cosmos.msg.v1.signer) = "admin"; + option (amino.name) = "icqoracle/MsgRemoveTokenPriceQuery"; + + string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // Token denom on Stride + string base_denom = 2; + // Quote denom on Stride + string quote_denom = 3; + // Pool ID on Osmosis + string osmosis_pool_id = 4; +} + +message MsgRemoveTokenPriceQueryResponse {} \ No newline at end of file diff --git a/proto/stride/strdburner/genesis.proto b/proto/stride/strdburner/genesis.proto new file mode 100644 index 0000000000..7c7248a59b --- /dev/null +++ b/proto/stride/strdburner/genesis.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package stride.strdburner; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/strdburner/types"; + +// GenesisState defines the strdburner module's genesis state +message GenesisState { + // Total amount of ustrd burned + string total_ustrd_burned = 9 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/proto/stride/strdburner/query.proto b/proto/stride/strdburner/query.proto new file mode 100644 index 0000000000..65acb4ba58 --- /dev/null +++ b/proto/stride/strdburner/query.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; +package stride.strdburner; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; + +option go_package = "github.com/Stride-Labs/stride/v24/x/strdburner/types"; + +// Query defines the gRPC querier service. +service Query { + // StrdBurnerAddress queries the address of the strdburner module + rpc StrdBurnerAddress(QueryStrdBurnerAddressRequest) + returns (QueryStrdBurnerAddressResponse) { + option (google.api.http).get = "/stride/strdburner/address"; + } + + // StrdBurnerAddress queries the address of the strdburner module + rpc TotalStrdBurned(QueryTotalStrdBurnedRequest) + returns (QueryTotalStrdBurnedResponse) { + option (google.api.http).get = "/stride/strdburner/total_burned"; + } +} + +// QueryStrdBurnerAddressRequest is the request type for the Query/strdburner +// RPC method +message QueryStrdBurnerAddressRequest {} + +// QueryStrdBurnerAddressResponse is the response type for the Query/strdburner +// RPC method +message QueryStrdBurnerAddressResponse { + string address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; +} + +// QueryTotalStrdBurnedRequest is the request type for the Query/strdburner +// RPC method +message QueryTotalStrdBurnedRequest {} + +// QueryTotalStrdBurnedResponse is the response type for the Query/strdburner +// RPC method +message QueryTotalStrdBurnedResponse { + string total_burned = 1 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/utils/utils.go b/utils/utils.go index 0a39951603..1765b22029 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -229,6 +229,26 @@ func LogWithHostZone(chainId string, s string, a ...any) string { return fmt.Sprintf("| %-13s | %s", strings.ToUpper(chainId), msg) } +// Returns a log string with a base denom, quote denom and tab as the prefix +// Ex: +// +// | uosmo/ustrd | string +func LogWithTokenPriceQuery(baseDenom, quoteDenom, osmosisPoolId, s string, a ...any, +) string { + msg := fmt.Sprintf(s, a...) + return fmt.Sprintf("| %s/%s/%s | %s", baseDenom, quoteDenom, osmosisPoolId, msg) +} + +// Returns a log string with a chain Id and callback as a prefix +// callbackType is either ICACALLBACK or ICQCALLBACK +// Format: +// +// | uosmo/ustrd | {CALLBACK_ID} {CALLBACK_TYPE} | string +func logCallbackWithTokenPriceQuery(baseDenom, quoteDenom, osmosisPoolId, callbackId string, callbackType string, s string, a ...any) string { + msg := fmt.Sprintf(s, a...) + return fmt.Sprintf("| %s/%s/%s | %s %s | %s", baseDenom, quoteDenom, osmosisPoolId, strings.ToUpper(callbackId), callbackType, msg) +} + // Returns a log string with a chain Id and callback as a prefix // callbackType is either ICACALLBACK or ICQCALLBACK // Format: @@ -272,6 +292,14 @@ func LogICQCallbackWithHostZone(chainId string, callbackId string, s string, a . return logCallbackWithHostZone(chainId, callbackId, "ICQCALLBACK", s, a...) } +// Returns a log string with a chain Id and icqcallback as a prefix +// Ex: +// +// | COSMOSHUB-4 | WITHDRAWALHOSTBALANCE ICQCALLBACK | string +func LogICQCallbackWithTokenPriceQuery(baseDenom, quoteDenom, osmosisPoolId, callbackId string, s string, a ...any) string { + return logCallbackWithTokenPriceQuery(baseDenom, quoteDenom, osmosisPoolId, callbackId, "ICQCALLBACK", s, a...) +} + // Returns a log header string with a dash padding on either side // Ex: // diff --git a/x/auction/client/cli/query.go b/x/auction/client/cli/query.go new file mode 100644 index 0000000000..082dcf6013 --- /dev/null +++ b/x/auction/client/cli/query.go @@ -0,0 +1,78 @@ +package cli + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +// GetQueryCmd returns the cli query commands for this module. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdQueryAuction(), + CmdQueryAuctions(), + ) + + return cmd +} + +func CmdQueryAuction() *cobra.Command { + cmd := &cobra.Command{ + Use: "auction [name]", + Short: "Query the auction info for a specific auction", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryAuctionRequest{ + Name: args[0], + } + res, err := queryClient.Auction(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + return cmd +} + +func CmdQueryAuctions() *cobra.Command { + cmd := &cobra.Command{ + Use: "auctions", + Short: "Get all auctions", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryAuctionsRequest{} + res, err := queryClient.Auctions(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + return cmd +} diff --git a/x/auction/client/cli/tx.go b/x/auction/client/cli/tx.go new file mode 100644 index 0000000000..1de5714fc0 --- /dev/null +++ b/x/auction/client/cli/tx.go @@ -0,0 +1,183 @@ +package cli + +import ( + "fmt" + "strconv" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + "github.com/spf13/cobra" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdPlaceBid(), + CmdCreateAuction(), + CmdUpdateAuction(), + ) + + return cmd +} + +func CmdPlaceBid() *cobra.Command { + cmd := &cobra.Command{ + Use: "place-bid [auction-name] [selling-token-amount] [payment-token-amount]", + Short: "Place a bid on an auction", + Long: strings.TrimSpace( + fmt.Sprintf(`Place a bid on an auction for a specific token. + +Example: + $ %[1]s tx %[2]s place-bid auctionName 123 1000000 --from mykey +`, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + sellingTokenAmount, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return fmt.Errorf("cannot parse sellingTokenAmount as uint64 from '%s': %w", args[1], err) + } + + paymentTokenAmount, err := strconv.ParseUint(args[2], 10, 64) + if err != nil { + return fmt.Errorf("cannot parse paymentTokenAmount as uint64 from '%s': %w", args[2], err) + } + + msg := types.NewMsgPlaceBid( + clientCtx.GetFromAddress().String(), + args[0], + sellingTokenAmount, + paymentTokenAmount, + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdCreateAuction() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-auction [name] [selling-denom] [payment-denom] [enabled] [min-price-multiplier] [min-bid-amount] [beneficiary]", + Short: "Create a new auction", + Long: strings.TrimSpace( + fmt.Sprintf(`Create a new auction for a specific token. + +Example: + $ %[1]s tx %[2]s create-auction my-auction ibc/DEADBEEF true 0.95 1000000 --from admin +`, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(7), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + enabled := args[3] == "true" + + minBidAmount, err := strconv.ParseUint(args[3], 10, 64) + if err != nil { + return fmt.Errorf("cannot parse minBidAmount as uint64 from '%s': %w", args[3], err) + } + + msg := types.NewMsgCreateAuction( + clientCtx.GetFromAddress().String(), + args[0], + types.AuctionType_AUCTION_TYPE_FCFS, + args[1], + args[2], + enabled, + args[4], + minBidAmount, + args[6], + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdUpdateAuction() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-auction [name] [enabled] [min-price-multiplier] [min-bid-amount] [beneficiary]", + Short: "Update an existing auction", + Long: strings.TrimSpace( + fmt.Sprintf(`Update an existing auction's parameters. + +Example: + $ %[1]s tx %[2]s update-auction auctionName true 0.97 500000 --from admin +`, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(5), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + enabled, err := strconv.ParseBool(args[1]) + if err != nil { + return fmt.Errorf("cannot parse enabled as bool from '%s': %w", args[1], err) + } + + minBidAmount, err := strconv.ParseUint(args[3], 10, 64) + if err != nil { + return fmt.Errorf("cannot parse minBidAmount as uint64 from '%s': %w", args[3], err) + } + + msg := types.NewMsgUpdateAuction( + clientCtx.GetFromAddress().String(), + args[0], + types.AuctionType_AUCTION_TYPE_FCFS, + enabled, + args[2], + minBidAmount, + args[4], + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/auction/keeper/auction_type.go b/x/auction/keeper/auction_type.go new file mode 100644 index 0000000000..65e4bb76e9 --- /dev/null +++ b/x/auction/keeper/auction_type.go @@ -0,0 +1,117 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +// Define a type for bid handler functions +type AuctionBidHandler func(ctx sdk.Context, k Keeper, auction *types.Auction, bid *types.MsgPlaceBid) error + +// Map of auction types to their handlers +var bidHandlers = map[types.AuctionType]AuctionBidHandler{ + types.AuctionType_AUCTION_TYPE_FCFS: fcfsBidHandler, +} + +// fcfsBidHandler handles bids for First Come First Serve auctions +func fcfsBidHandler(ctx sdk.Context, k Keeper, auction *types.Auction, bid *types.MsgPlaceBid) error { + // Get token amount being auctioned off + moduleAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) + balance := k.bankKeeper.GetBalance(ctx, moduleAddr, auction.SellingDenom) + sellingAmountAvailable := balance.Amount + + // Verify auction has enough sellingtokens to service the bid + if bid.SellingTokenAmount.GT(sellingAmountAvailable) { + return fmt.Errorf("bid wants to buy %s%s but auction has only %s%s", + bid.SellingTokenAmount.String(), + auction.SellingDenom, + sellingAmountAvailable.String(), + auction.SellingDenom, + ) + } + + // Note: price converts SellingToken to PaymentToken + // Any calculation down the road makes sense only if price is multiplied by a derivative of SellingToken + price, err := k.icqoracleKeeper.GetTokenPriceForQuoteDenom(ctx, auction.SellingDenom, auction.PaymentDenom) + if err != nil { + return err + } + + // Apply MinPriceMultiplier + bidsFloorPrice := price.Mul(auction.MinPriceMultiplier) + + // if paymentAmount < sellingAmount * bidsFloorPrice + if bid.PaymentTokenAmount.ToLegacyDec().LT(bid.SellingTokenAmount.ToLegacyDec(). + Mul(bidsFloorPrice)) { + return fmt.Errorf("bid price too low: offered %s%s for %s%s, bids floor price is %s%s (price=%s %s/%s)", + bid.PaymentTokenAmount.String(), + auction.PaymentDenom, + bid.SellingTokenAmount.String(), + auction.SellingDenom, + bid.SellingTokenAmount.ToLegacyDec().Mul(bidsFloorPrice).String(), + auction.PaymentDenom, + bidsFloorPrice.String(), + auction.PaymentDenom, + auction.SellingDenom, + ) + } + + // Safe to use MustAccAddressFromBech32 because bid.Bidder passed ValidateBasic + bidder := sdk.MustAccAddressFromBech32(bid.Bidder) + + // Send paymentToken to beneficiary + err = k.bankKeeper.SendCoins( + ctx, + bidder, + sdk.MustAccAddressFromBech32(auction.Beneficiary), + sdk.NewCoins(sdk.NewCoin(auction.PaymentDenom, bid.PaymentTokenAmount)), + ) + if err != nil { + return fmt.Errorf("failed to send payment tokens from bidder '%s' to beneficiary '%s': %w", + bid.Bidder, + auction.Beneficiary, + err, + ) + } + + // Send sellingToken to bidder + err = k.bankKeeper.SendCoinsFromModuleToAccount( + ctx, + types.ModuleName, + bidder, + sdk.NewCoins(sdk.NewCoin(auction.SellingDenom, bid.SellingTokenAmount)), + ) + if err != nil { + return fmt.Errorf("failed to send auction tokens from module '%s' to bidder '%s': %w", + types.ModuleName, + bid.Bidder, + err, + ) + } + + auction.TotalSellingTokenSold = auction.TotalSellingTokenSold.Add(bid.SellingTokenAmount) + auction.TotalPaymentTokenReceived = auction.TotalPaymentTokenReceived.Add(bid.PaymentTokenAmount) + + err = k.SetAuction(ctx, auction) + if err != nil { + return fmt.Errorf("failed to update auction stats") + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeBidAccepted, + sdk.NewAttribute(types.AttributeKeyAuctionName, auction.Name), + sdk.NewAttribute(types.AttributeKeyBidder, bid.Bidder), + sdk.NewAttribute(types.AttributeKeyPaymentAmount, bid.PaymentTokenAmount.String()), + sdk.NewAttribute(types.AttributeKeyPaymentDenom, auction.PaymentDenom), + sdk.NewAttribute(types.AttributeKeySellingAmount, bid.SellingTokenAmount.String()), + sdk.NewAttribute(types.AttributeKeySellingDenom, auction.SellingDenom), + sdk.NewAttribute(types.AttributeKeyPrice, bidsFloorPrice.String()), + ), + ) + + return nil +} diff --git a/x/auction/keeper/genesis.go b/x/auction/keeper/genesis.go new file mode 100644 index 0000000000..686f31a96b --- /dev/null +++ b/x/auction/keeper/genesis.go @@ -0,0 +1,34 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +// Loads module state from genesis +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } + + for _, auction := range genState.Auctions { + if err := k.SetAuction(ctx, &auction); err != nil { + panic(err) + } + } +} + +// Export's module state into genesis file +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + params, err := k.GetParams(ctx) + if err != nil { + panic(err) + } + + genesis := types.DefaultGenesis() + genesis.Params = params + genesis.Auctions = k.GetAllAuctions(ctx) + return genesis +} diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go new file mode 100644 index 0000000000..5cc28af10f --- /dev/null +++ b/x/auction/keeper/keeper.go @@ -0,0 +1,108 @@ +package keeper + +import ( + "fmt" + + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/store/prefix" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + icqoracleKeeper types.IcqOracleKeeper +} + +func NewKeeper( + cdc codec.Codec, + storeKey storetypes.StoreKey, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, + icqoracleKeeper types.IcqOracleKeeper, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + icqoracleKeeper: icqoracleKeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// SetAuction stores auction info for a token +func (k Keeper) SetAuction(ctx sdk.Context, auction *types.Auction) error { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AuctionPrefix) + key := []byte(auction.Name) + + bz, err := k.cdc.Marshal(auction) + if err != nil { + return fmt.Errorf("error setting auction for name='%s': %w", auction.Name, err) + } + + store.Set(key, bz) + return nil +} + +// GetAuction retrieves auction info for a token +func (k Keeper) GetAuction(ctx sdk.Context, name string) (*types.Auction, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AuctionPrefix) + key := []byte(name) + + bz := store.Get(key) + if bz == nil { + return &types.Auction{}, fmt.Errorf("auction not found for denom '%s'", name) + } + + var auction types.Auction + if err := k.cdc.Unmarshal(bz, &auction); err != nil { + return &types.Auction{}, fmt.Errorf("error retrieving auction for denom '%s': %w", auction.SellingDenom, err) + } + + return &auction, nil +} + +// GetAllAuctions retrieves all stored auctions +func (k Keeper) GetAllAuctions(ctx sdk.Context) []types.Auction { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.AuctionPrefix) + iterator := sdk.KVStorePrefixIterator(store, []byte(types.AuctionPrefix)) + defer iterator.Close() + + auctions := []types.Auction{} + for ; iterator.Valid(); iterator.Next() { + var auction types.Auction + k.cdc.MustUnmarshal(iterator.Value(), &auction) + auctions = append(auctions, auction) + } + + return auctions +} + +// PlaceBid places an auction bid and executes it based on the auction type +func (k Keeper) PlaceBid(ctx sdk.Context, bid *types.MsgPlaceBid) error { + // Get auction + auction, err := k.GetAuction(ctx, bid.AuctionName) + if err != nil { + return fmt.Errorf("cannot get auction for name='%s': %w", bid.AuctionName, err) + } + + // Get the appropriate auctionBidHandler for the auction type + auctionBidHandler, exists := bidHandlers[auction.Type] + if !exists { + return fmt.Errorf("unsupported auction type: %s", auction.Type) + } + + // Call the handler + return auctionBidHandler(ctx, k, auction, bid) +} diff --git a/x/auction/keeper/msg_server.go b/x/auction/keeper/msg_server.go new file mode 100644 index 0000000000..c698e7e81e --- /dev/null +++ b/x/auction/keeper/msg_server.go @@ -0,0 +1,87 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// PlaceBid places a bid to buy a token off an auction +func (ms msgServer) PlaceBid(goCtx context.Context, msg *types.MsgPlaceBid) (*types.MsgPlaceBidResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + err := ms.Keeper.PlaceBid(ctx, msg) + if err != nil { + return nil, err + } + + return &types.MsgPlaceBidResponse{}, nil +} + +// CreateAuction creates a new auction +func (ms msgServer) CreateAuction(goCtx context.Context, msg *types.MsgCreateAuction) (*types.MsgCreateAuctionResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + _, err := ms.Keeper.GetAuction(ctx, msg.AuctionName) + if err == nil { + return nil, types.ErrAuctionAlreadyExists.Wrapf("auction with name '%s' already exists", msg.AuctionName) + } + + auction := types.Auction{ + Type: msg.AuctionType, + Name: msg.AuctionName, + SellingDenom: msg.SellingDenom, + PaymentDenom: msg.PaymentDenom, + Enabled: msg.Enabled, + MinPriceMultiplier: msg.MinPriceMultiplier, + MinBidAmount: msg.MinBidAmount, + Beneficiary: msg.Beneficiary, + TotalPaymentTokenReceived: math.ZeroInt(), + TotalSellingTokenSold: math.ZeroInt(), + } + + err = ms.Keeper.SetAuction(ctx, &auction) + if err != nil { + return nil, err + } + + return &types.MsgCreateAuctionResponse{}, nil +} + +// CreateAuction updates an existing auction +func (ms msgServer) UpdateAuction(goCtx context.Context, msg *types.MsgUpdateAuction) (*types.MsgUpdateAuctionResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + auction, err := ms.Keeper.GetAuction(ctx, msg.AuctionName) + if err != nil { + return nil, types.ErrAuctionDoesntExist.Wrapf("cannot find auction with name '%s'", msg.AuctionName) + } + + auction.Type = msg.AuctionType + auction.Enabled = msg.Enabled + auction.MinBidAmount = msg.MinBidAmount + auction.MinPriceMultiplier = msg.MinPriceMultiplier + auction.Beneficiary = msg.Beneficiary + + err = ms.Keeper.SetAuction(ctx, auction) + if err != nil { + return nil, err + } + + return &types.MsgUpdateAuctionResponse{}, nil +} diff --git a/x/auction/keeper/params.go b/x/auction/keeper/params.go new file mode 100644 index 0000000000..9675b09115 --- /dev/null +++ b/x/auction/keeper/params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +// GetParams get params +func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get([]byte(types.ParamsKey)) + params := types.Params{} + err := k.cdc.UnmarshalJSON(bz, ¶ms) + return params, err +} + +// SetParams set params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.MarshalJSON(¶ms) + if err != nil { + return err + } + store.Set([]byte(types.ParamsKey), bz) + return nil +} diff --git a/x/auction/keeper/query.go b/x/auction/keeper/query.go new file mode 100644 index 0000000000..768a9ff694 --- /dev/null +++ b/x/auction/keeper/query.go @@ -0,0 +1,49 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +var _ types.QueryServer = Keeper{} + +// Auction queries the auction info for a specific token +func (k Keeper) Auction(goCtx context.Context, req *types.QueryAuctionRequest) (*types.QueryAuctionResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + auction, err := k.GetAuction(ctx, req.Name) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + return &types.QueryAuctionResponse{ + Auction: *auction, + }, nil +} + +// Auctions queries the auction info for a specific token +func (k Keeper) Auctions(goCtx context.Context, req *types.QueryAuctionsRequest) (*types.QueryAuctionsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + auctions := k.GetAllAuctions(ctx) + + // TODO impl paging + + return &types.QueryAuctionsResponse{ + Auctions: auctions, + }, nil +} diff --git a/x/auction/module.go b/x/auction/module.go new file mode 100644 index 0000000000..95244872ef --- /dev/null +++ b/x/auction/module.go @@ -0,0 +1,156 @@ +package auction + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/Stride-Labs/stride/v24/x/auction/client/cli" + "github.com/Stride-Labs/stride/v24/x/auction/keeper" + "github.com/Stride-Labs/stride/v24/x/auction/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/auction/types/auction.pb.go b/x/auction/types/auction.pb.go new file mode 100644 index 0000000000..0f902642b5 --- /dev/null +++ b/x/auction/types/auction.pb.go @@ -0,0 +1,915 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/auction/auction.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type AuctionType int32 + +const ( + // Default value - should not be used + AuctionType_AUCTION_TYPE_UNSPECIFIED AuctionType = 0 + // First-Come First-Served auction + AuctionType_AUCTION_TYPE_FCFS AuctionType = 1 +) + +var AuctionType_name = map[int32]string{ + 0: "AUCTION_TYPE_UNSPECIFIED", + 1: "AUCTION_TYPE_FCFS", +} + +var AuctionType_value = map[string]int32{ + "AUCTION_TYPE_UNSPECIFIED": 0, + "AUCTION_TYPE_FCFS": 1, +} + +func (x AuctionType) String() string { + return proto.EnumName(AuctionType_name, int32(x)) +} + +func (AuctionType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_739480caccbf7be9, []int{0} +} + +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_739480caccbf7be9, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +type Auction struct { + // Auction type + Type AuctionType `protobuf:"varint,1,opt,name=type,proto3,enum=stride.auction.AuctionType" json:"type,omitempty"` + // A unique auction name + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + // Token denom being sold in the auction + SellingDenom string `protobuf:"bytes,3,opt,name=selling_denom,json=sellingDenom,proto3" json:"selling_denom,omitempty"` + // Token denom used to place bids + PaymentDenom string `protobuf:"bytes,4,opt,name=payment_denom,json=paymentDenom,proto3" json:"payment_denom,omitempty"` + // Whether auction is active + Enabled bool `protobuf:"varint,5,opt,name=enabled,proto3" json:"enabled,omitempty"` + // Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle reported + // price) bids_floor_price = oracle_price * min_price_multiplier + MinPriceMultiplier cosmossdk_io_math.LegacyDec `protobuf:"bytes,6,opt,name=min_price_multiplier,json=minPriceMultiplier,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_price_multiplier"` + // Minimum payment token bid amount + MinBidAmount cosmossdk_io_math.Int `protobuf:"bytes,7,opt,name=min_bid_amount,json=minBidAmount,proto3,customtype=cosmossdk.io/math.Int" json:"min_bid_amount"` + // Address to send the auction proceeds to + Beneficiary string `protobuf:"bytes,8,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"` + // Total amount of payment token received + TotalPaymentTokenReceived cosmossdk_io_math.Int `protobuf:"bytes,9,opt,name=total_payment_token_received,json=totalPaymentTokenReceived,proto3,customtype=cosmossdk.io/math.Int" json:"total_payment_token_received"` + // Total amount of selling token sold + TotalSellingTokenSold cosmossdk_io_math.Int `protobuf:"bytes,10,opt,name=total_selling_token_sold,json=totalSellingTokenSold,proto3,customtype=cosmossdk.io/math.Int" json:"total_selling_token_sold"` +} + +func (m *Auction) Reset() { *m = Auction{} } +func (m *Auction) String() string { return proto.CompactTextString(m) } +func (*Auction) ProtoMessage() {} +func (*Auction) Descriptor() ([]byte, []int) { + return fileDescriptor_739480caccbf7be9, []int{1} +} +func (m *Auction) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Auction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Auction.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Auction) XXX_Merge(src proto.Message) { + xxx_messageInfo_Auction.Merge(m, src) +} +func (m *Auction) XXX_Size() int { + return m.Size() +} +func (m *Auction) XXX_DiscardUnknown() { + xxx_messageInfo_Auction.DiscardUnknown(m) +} + +var xxx_messageInfo_Auction proto.InternalMessageInfo + +func (m *Auction) GetType() AuctionType { + if m != nil { + return m.Type + } + return AuctionType_AUCTION_TYPE_UNSPECIFIED +} + +func (m *Auction) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Auction) GetSellingDenom() string { + if m != nil { + return m.SellingDenom + } + return "" +} + +func (m *Auction) GetPaymentDenom() string { + if m != nil { + return m.PaymentDenom + } + return "" +} + +func (m *Auction) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + +func (m *Auction) GetBeneficiary() string { + if m != nil { + return m.Beneficiary + } + return "" +} + +func init() { + proto.RegisterEnum("stride.auction.AuctionType", AuctionType_name, AuctionType_value) + proto.RegisterType((*Params)(nil), "stride.auction.Params") + proto.RegisterType((*Auction)(nil), "stride.auction.Auction") +} + +func init() { proto.RegisterFile("stride/auction/auction.proto", fileDescriptor_739480caccbf7be9) } + +var fileDescriptor_739480caccbf7be9 = []byte{ + // 525 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x3e, + 0x18, 0xc7, 0x9b, 0xdf, 0xaf, 0x6c, 0x9d, 0x37, 0xaa, 0x61, 0xb5, 0x92, 0xb7, 0x95, 0xac, 0xda, + 0x2e, 0x15, 0xd2, 0x12, 0x31, 0x38, 0x71, 0xeb, 0x5f, 0xa9, 0x62, 0x8c, 0x2a, 0x69, 0x91, 0xe0, + 0x40, 0xe4, 0x24, 0x26, 0xb3, 0x16, 0xdb, 0x51, 0xec, 0x4e, 0xf4, 0x5d, 0xf0, 0x62, 0x78, 0x05, + 0x9c, 0x76, 0x9c, 0x38, 0x21, 0x0e, 0x13, 0x6a, 0xdf, 0x08, 0x8a, 0x9d, 0x4e, 0x9b, 0xb8, 0xec, + 0x14, 0xfb, 0xfb, 0x7c, 0xbf, 0x9f, 0x58, 0xf6, 0xf3, 0x80, 0x96, 0x54, 0x39, 0x8d, 0x89, 0x8b, + 0xe7, 0x91, 0xa2, 0x82, 0xaf, 0xbf, 0x4e, 0x96, 0x0b, 0x25, 0x60, 0xdd, 0x54, 0x9d, 0x52, 0xdd, + 0xdf, 0x8b, 0x84, 0x64, 0x42, 0x06, 0xba, 0xea, 0x9a, 0x8d, 0xb1, 0xee, 0x37, 0x12, 0x91, 0x08, + 0xa3, 0x17, 0x2b, 0xa3, 0x1e, 0xd5, 0xc0, 0xc6, 0x04, 0xe7, 0x98, 0xc9, 0xa3, 0x1f, 0x55, 0xb0, + 0xd9, 0x35, 0x18, 0xe8, 0x82, 0xaa, 0x5a, 0x64, 0x04, 0x59, 0x6d, 0xab, 0x53, 0x3f, 0x3d, 0x70, + 0x1e, 0xfe, 0xc5, 0x29, 0x6d, 0xd3, 0x45, 0x46, 0x3c, 0x6d, 0x84, 0x10, 0x54, 0x39, 0x66, 0x04, + 0xfd, 0xd7, 0xb6, 0x3a, 0x5b, 0x9e, 0x5e, 0xc3, 0x63, 0xf0, 0x54, 0x92, 0x34, 0xa5, 0x3c, 0x09, + 0x62, 0xc2, 0x05, 0x43, 0xff, 0xeb, 0xe2, 0x4e, 0x29, 0x0e, 0x0a, 0xad, 0x30, 0x65, 0x78, 0xc1, + 0x08, 0x57, 0xa5, 0xa9, 0x6a, 0x4c, 0xa5, 0x68, 0x4c, 0x08, 0x6c, 0x12, 0x8e, 0xc3, 0x94, 0xc4, + 0xe8, 0x49, 0xdb, 0xea, 0xd4, 0xbc, 0xf5, 0x16, 0xce, 0x40, 0x83, 0x51, 0x1e, 0x64, 0x39, 0x8d, + 0x48, 0xc0, 0xe6, 0xa9, 0xa2, 0x59, 0x4a, 0x49, 0x8e, 0x36, 0x0a, 0x4a, 0xef, 0xf8, 0xfa, 0xf6, + 0xb0, 0xf2, 0xfb, 0xf6, 0xf0, 0xc0, 0x5c, 0x84, 0x8c, 0x2f, 0x1d, 0x2a, 0x5c, 0x86, 0xd5, 0x85, + 0x73, 0x46, 0x12, 0x1c, 0x2d, 0x06, 0x24, 0xf2, 0x20, 0xa3, 0x7c, 0x52, 0xe4, 0xdf, 0xdd, 0xc5, + 0x61, 0x1f, 0xd4, 0x0b, 0x6c, 0x48, 0xe3, 0x00, 0x33, 0x31, 0xe7, 0x0a, 0x6d, 0x6a, 0xe0, 0xf3, + 0x12, 0xd8, 0xfc, 0x17, 0x38, 0xe6, 0xca, 0xdb, 0x61, 0x94, 0xf7, 0x68, 0xdc, 0xd5, 0x11, 0xf8, + 0x06, 0x6c, 0x87, 0x84, 0x93, 0x2f, 0x34, 0xa2, 0x38, 0x5f, 0xa0, 0x9a, 0x26, 0xa0, 0x9f, 0xdf, + 0x4f, 0x1a, 0xe5, 0xbb, 0x74, 0xe3, 0x38, 0x27, 0x52, 0xfa, 0x2a, 0xa7, 0x3c, 0xf1, 0xee, 0x9b, + 0xe1, 0x67, 0xd0, 0x52, 0x42, 0xe1, 0x34, 0x58, 0x5f, 0x8e, 0x12, 0x97, 0x84, 0x07, 0x39, 0x89, + 0x08, 0xbd, 0x22, 0x31, 0xda, 0x7a, 0xcc, 0x71, 0xf6, 0x34, 0x62, 0x62, 0x08, 0xd3, 0x02, 0xe0, + 0x95, 0x79, 0xf8, 0x01, 0x20, 0xc3, 0x5f, 0xbf, 0x90, 0xe1, 0x4b, 0x91, 0xc6, 0x08, 0x3c, 0x86, + 0xdd, 0xd4, 0x71, 0xdf, 0xa4, 0x35, 0xdb, 0x17, 0x69, 0xfc, 0xa2, 0x07, 0xb6, 0xef, 0x35, 0x07, + 0x6c, 0x01, 0xd4, 0x9d, 0xf5, 0xa7, 0xe3, 0xf7, 0xe7, 0xc1, 0xf4, 0xe3, 0x64, 0x18, 0xcc, 0xce, + 0xfd, 0xc9, 0xb0, 0x3f, 0x1e, 0x8d, 0x87, 0x83, 0xdd, 0x0a, 0x6c, 0x82, 0x67, 0x0f, 0xaa, 0xa3, + 0xfe, 0xc8, 0xdf, 0xb5, 0x7a, 0x6f, 0xaf, 0x97, 0xb6, 0x75, 0xb3, 0xb4, 0xad, 0x3f, 0x4b, 0xdb, + 0xfa, 0xb6, 0xb2, 0x2b, 0x37, 0x2b, 0xbb, 0xf2, 0x6b, 0x65, 0x57, 0x3e, 0xbd, 0x4c, 0xa8, 0xba, + 0x98, 0x87, 0x4e, 0x24, 0x98, 0xeb, 0xeb, 0x96, 0x3c, 0x39, 0xc3, 0xa1, 0x74, 0xcb, 0x11, 0xb9, + 0x3a, 0x7d, 0xed, 0x7e, 0xbd, 0x1b, 0x94, 0xa2, 0x2f, 0x65, 0xb8, 0xa1, 0xdb, 0xfc, 0xd5, 0xdf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x69, 0x7d, 0xc8, 0xb0, 0x47, 0x03, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *Auction) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Auction) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Auction) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.TotalSellingTokenSold.Size() + i -= size + if _, err := m.TotalSellingTokenSold.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintAuction(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x52 + { + size := m.TotalPaymentTokenReceived.Size() + i -= size + if _, err := m.TotalPaymentTokenReceived.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintAuction(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + if len(m.Beneficiary) > 0 { + i -= len(m.Beneficiary) + copy(dAtA[i:], m.Beneficiary) + i = encodeVarintAuction(dAtA, i, uint64(len(m.Beneficiary))) + i-- + dAtA[i] = 0x42 + } + { + size := m.MinBidAmount.Size() + i -= size + if _, err := m.MinBidAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintAuction(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + { + size := m.MinPriceMultiplier.Size() + i -= size + if _, err := m.MinPriceMultiplier.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintAuction(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if len(m.PaymentDenom) > 0 { + i -= len(m.PaymentDenom) + copy(dAtA[i:], m.PaymentDenom) + i = encodeVarintAuction(dAtA, i, uint64(len(m.PaymentDenom))) + i-- + dAtA[i] = 0x22 + } + if len(m.SellingDenom) > 0 { + i -= len(m.SellingDenom) + copy(dAtA[i:], m.SellingDenom) + i = encodeVarintAuction(dAtA, i, uint64(len(m.SellingDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintAuction(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.Type != 0 { + i = encodeVarintAuction(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintAuction(dAtA []byte, offset int, v uint64) int { + offset -= sovAuction(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *Auction) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovAuction(uint64(m.Type)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovAuction(uint64(l)) + } + l = len(m.SellingDenom) + if l > 0 { + n += 1 + l + sovAuction(uint64(l)) + } + l = len(m.PaymentDenom) + if l > 0 { + n += 1 + l + sovAuction(uint64(l)) + } + if m.Enabled { + n += 2 + } + l = m.MinPriceMultiplier.Size() + n += 1 + l + sovAuction(uint64(l)) + l = m.MinBidAmount.Size() + n += 1 + l + sovAuction(uint64(l)) + l = len(m.Beneficiary) + if l > 0 { + n += 1 + l + sovAuction(uint64(l)) + } + l = m.TotalPaymentTokenReceived.Size() + n += 1 + l + sovAuction(uint64(l)) + l = m.TotalSellingTokenSold.Size() + n += 1 + l + sovAuction(uint64(l)) + return n +} + +func sovAuction(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAuction(x uint64) (n int) { + return sovAuction(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipAuction(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuction + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Auction) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Auction: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Auction: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= AuctionType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SellingDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SellingDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PaymentDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PaymentDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinPriceMultiplier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinPriceMultiplier.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinBidAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinBidAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Beneficiary", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Beneficiary = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalPaymentTokenReceived", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalPaymentTokenReceived.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalSellingTokenSold", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAuction + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuction + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalSellingTokenSold.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAuction(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuction + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAuction(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAuction + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAuction + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAuction + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAuction + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAuction + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAuction + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAuction = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAuction = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAuction = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auction/types/codec.go b/x/auction/types/codec.go new file mode 100644 index 0000000000..171d9f1dab --- /dev/null +++ b/x/auction/types/codec.go @@ -0,0 +1,42 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgPlaceBid{}, "auction/MsgPlaceBid") + legacy.RegisterAminoMsg(cdc, &MsgCreateAuction{}, "auction/MsgCreateAuction") + legacy.RegisterAminoMsg(cdc, &MsgUpdateAuction{}, "auction/MsgUpdateAuction") +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgPlaceBid{}, + &MsgCreateAuction{}, + &MsgUpdateAuction{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgSubmitProposal instances + RegisterLegacyAminoCodec(govcodec.Amino) +} diff --git a/x/auction/types/errors.go b/x/auction/types/errors.go new file mode 100644 index 0000000000..9d35039f96 --- /dev/null +++ b/x/auction/types/errors.go @@ -0,0 +1,13 @@ +package types + +// DONTCOVER + +import ( + sdkerrors "cosmossdk.io/errors" +) + +// x/auction module sentinel errors +var ( + ErrAuctionAlreadyExists = sdkerrors.Register(ModuleName, 7001, "auction already exists") + ErrAuctionDoesntExist = sdkerrors.Register(ModuleName, 7002, "auction doesn't exists") +) diff --git a/x/auction/types/events.go b/x/auction/types/events.go new file mode 100644 index 0000000000..49e8dbc64a --- /dev/null +++ b/x/auction/types/events.go @@ -0,0 +1,15 @@ +package types + +// Event types and attribute keys for auction module +const ( + EventTypeBidPlaced = "bid_placed" + EventTypeBidAccepted = "bid_accepted" + + AttributeKeyAuctionName = "auction_name" + AttributeKeyBidder = "bidder" + AttributeKeyPaymentAmount = "payment_amount" + AttributeKeyPaymentDenom = "payment_denom" + AttributeKeySellingAmount = "selling_amount" + AttributeKeySellingDenom = "selling_denom" + AttributeKeyPrice = "discounted_price" +) diff --git a/x/auction/types/expected_keepers.go b/x/auction/types/expected_keepers.go new file mode 100644 index 0000000000..91e2160752 --- /dev/null +++ b/x/auction/types/expected_keepers.go @@ -0,0 +1,23 @@ +package types + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Required AccountKeeper functions +type AccountKeeper interface { + GetModuleAddress(moduleName string) sdk.AccAddress +} + +// Required BankKeeper functions +type BankKeeper interface { + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error +} + +// Required IcqOracleKeeper functions +type IcqOracleKeeper interface { + GetTokenPriceForQuoteDenom(ctx sdk.Context, baseDenom string, quoteDenom string) (price math.LegacyDec, err error) +} diff --git a/x/auction/types/genesis.go b/x/auction/types/genesis.go new file mode 100644 index 0000000000..981feb11b9 --- /dev/null +++ b/x/auction/types/genesis.go @@ -0,0 +1,30 @@ +package types + +import ( + "fmt" +) + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{} +} + +// Performs basic genesis state validation by iterating through all auctions and validating +// using ValidateCreateAuctionParams() +func (gs GenesisState) Validate() error { + for i, auction := range gs.Auctions { + err := ValidateCreateAuctionParams( + auction.Name, + auction.Type, + auction.SellingDenom, + auction.PaymentDenom, + auction.MinPriceMultiplier, + auction.MinBidAmount, + auction.Beneficiary, + ) + if err != nil { + return fmt.Errorf("invalid genesis auction at index %d: %w", i, err) + } + } + return nil +} diff --git a/x/auction/types/genesis.pb.go b/x/auction/types/genesis.pb.go new file mode 100644 index 0000000000..57a415a4a2 --- /dev/null +++ b/x/auction/types/genesis.pb.go @@ -0,0 +1,386 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/auction/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the auction module's genesis state +type GenesisState struct { + // Module parameters + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // List of token auctions + Auctions []Auction `protobuf:"bytes,2,rep,name=auctions,proto3" json:"auctions"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_94bb6618fc080329, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetAuctions() []Auction { + if m != nil { + return m.Auctions + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "stride.auction.GenesisState") +} + +func init() { proto.RegisterFile("stride/auction/genesis.proto", fileDescriptor_94bb6618fc080329) } + +var fileDescriptor_94bb6618fc080329 = []byte{ + // 220 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x2e, 0x29, 0xca, + 0x4c, 0x49, 0xd5, 0x4f, 0x2c, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0xd3, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, + 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0xc8, 0xea, 0x41, 0x65, 0xa5, + 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0x95, 0x14, 0xba, 0x19, 0x50, + 0x1a, 0x22, 0xab, 0x54, 0xcf, 0xc5, 0xe3, 0x0e, 0x31, 0x34, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0xc8, + 0x84, 0x8b, 0xad, 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, + 0x4c, 0x0f, 0xd5, 0x12, 0xbd, 0x00, 0xb0, 0xac, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x50, + 0xb5, 0x42, 0x96, 0x5c, 0x1c, 0x50, 0xf9, 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x71, + 0x74, 0x7d, 0x8e, 0x10, 0x1a, 0xaa, 0x11, 0xae, 0xdc, 0xc9, 0xfb, 0xc4, 0x23, 0x39, 0xc6, 0x0b, + 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, + 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x0c, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, + 0xf5, 0x83, 0xc1, 0x86, 0xe9, 0xfa, 0x24, 0x26, 0x15, 0xeb, 0x43, 0xfd, 0x53, 0x66, 0x64, 0xa2, + 0x5f, 0x01, 0xf7, 0x55, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x53, 0xc6, 0x80, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x1b, 0xbc, 0x9c, 0x7c, 0x38, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Auctions) > 0 { + for iNdEx := len(m.Auctions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Auctions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.Auctions) > 0 { + for _, e := range m.Auctions { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Auctions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Auctions = append(m.Auctions, Auction{}) + if err := m.Auctions[len(m.Auctions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auction/types/keys.go b/x/auction/types/keys.go new file mode 100644 index 0000000000..ea08ff65d7 --- /dev/null +++ b/x/auction/types/keys.go @@ -0,0 +1,16 @@ +package types + +const ( + ModuleName = "auction" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the routing key + RouterKey = ModuleName +) + +var ( + ParamsKey = []byte("params") + AuctionPrefix = []byte("auction") +) diff --git a/x/auction/types/msgs.go b/x/auction/types/msgs.go new file mode 100644 index 0000000000..4d686c8503 --- /dev/null +++ b/x/auction/types/msgs.go @@ -0,0 +1,230 @@ +package types + +import ( + "errors" + "fmt" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + + "github.com/Stride-Labs/stride/v24/utils" +) + +const ( + TypeMsgPlaceBid = "place_bid" + TypeMsgCreateAuction = "create_auction" + TypeMsgUpdateAuction = "update_auction" +) + +var ( + _ sdk.Msg = &MsgPlaceBid{} + _ sdk.Msg = &MsgCreateAuction{} + _ sdk.Msg = &MsgUpdateAuction{} + + // Implement legacy interface for ledger support + _ legacytx.LegacyMsg = &MsgPlaceBid{} + _ legacytx.LegacyMsg = &MsgCreateAuction{} + _ legacytx.LegacyMsg = &MsgUpdateAuction{} +) + +// ---------------------------------------------- +// MsgPlaceBid +// ---------------------------------------------- + +func NewMsgPlaceBid( + bidder string, + AuctionName string, + sellingTokenAmount uint64, + paymentTokenAmount uint64, +) *MsgPlaceBid { + return &MsgPlaceBid{ + Bidder: bidder, + AuctionName: AuctionName, + SellingTokenAmount: math.NewIntFromUint64(sellingTokenAmount), + PaymentTokenAmount: math.NewIntFromUint64(paymentTokenAmount), + } +} + +func (msg MsgPlaceBid) Type() string { + return TypeMsgPlaceBid +} + +func (msg MsgPlaceBid) Route() string { + return RouterKey +} + +func (msg *MsgPlaceBid) GetSigners() []sdk.AccAddress { + sender, err := sdk.AccAddressFromBech32(msg.Bidder) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sender} +} + +func (msg *MsgPlaceBid) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgPlaceBid) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Bidder); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address (%s)", err) + } + if msg.AuctionName == "" { + return errors.New("auction-name must be specified") + } + if msg.SellingTokenAmount.IsZero() { + return errors.New("selling-token-amount cannot be 0") + } + if msg.PaymentTokenAmount.IsZero() { + return errors.New("payment-token-amount cannot be 0") + } + + return nil +} + +// ---------------------------------------------- +// MsgCreateAuction +// ---------------------------------------------- + +func NewMsgCreateAuction( + admin string, + auctionName string, + auctionType AuctionType, + sellingDenom string, + paymentDenom string, + enabled bool, + minPriceMultiplier string, + minBidAmount uint64, + beneficiary string, +) *MsgCreateAuction { + minPriceMultiplierDec, err := math.LegacyNewDecFromStr(minPriceMultiplier) + if err != nil { + panic(fmt.Sprintf("cannot parse LegacyDecimal from minPriceMultiplier '%s'", minPriceMultiplier)) + } + + return &MsgCreateAuction{ + Admin: admin, + AuctionName: auctionName, + AuctionType: auctionType, + SellingDenom: sellingDenom, + PaymentDenom: paymentDenom, + Enabled: enabled, + MinPriceMultiplier: minPriceMultiplierDec, + MinBidAmount: math.NewIntFromUint64(minBidAmount), + Beneficiary: beneficiary, + } +} + +func (msg MsgCreateAuction) Type() string { + return TypeMsgCreateAuction +} + +func (msg MsgCreateAuction) Route() string { + return RouterKey +} + +func (msg *MsgCreateAuction) GetSigners() []sdk.AccAddress { + sender, err := sdk.AccAddressFromBech32(msg.Admin) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sender} +} + +func (msg *MsgCreateAuction) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCreateAuction) ValidateBasic() error { + if err := utils.ValidateAdminAddress(msg.Admin); err != nil { + return err + } + + return ValidateCreateAuctionParams( + msg.AuctionName, + msg.AuctionType, + msg.SellingDenom, + msg.PaymentDenom, + msg.MinPriceMultiplier, + msg.MinBidAmount, + msg.Beneficiary, + ) +} + +// ---------------------------------------------- +// MsgUpdateAuction +// ---------------------------------------------- + +func NewMsgUpdateAuction( + admin string, + auctionName string, + auctionType AuctionType, + enabled bool, + minPriceMultiplier string, + minBidAmount uint64, + beneficiary string, +) *MsgUpdateAuction { + minPriceMultiplierDec, err := math.LegacyNewDecFromStr(minPriceMultiplier) + if err != nil { + panic(fmt.Sprintf("cannot parse LegacyDecimal from minPriceMultiplier '%s'", minPriceMultiplier)) + } + + return &MsgUpdateAuction{ + Admin: admin, + AuctionName: auctionName, + AuctionType: auctionType, + Enabled: enabled, + MinPriceMultiplier: minPriceMultiplierDec, + MinBidAmount: math.NewIntFromUint64(minBidAmount), + Beneficiary: beneficiary, + } +} + +func (msg MsgUpdateAuction) Type() string { + return TypeMsgUpdateAuction +} + +func (msg MsgUpdateAuction) Route() string { + return RouterKey +} + +func (msg *MsgUpdateAuction) GetSigners() []sdk.AccAddress { + sender, err := sdk.AccAddressFromBech32(msg.Admin) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sender} +} + +func (msg *MsgUpdateAuction) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgUpdateAuction) ValidateBasic() error { + if err := utils.ValidateAdminAddress(msg.Admin); err != nil { + return err + } + if msg.AuctionName == "" { + return errors.New("auction-name must be specified") + } + if _, ok := AuctionType_name[int32(msg.AuctionType)]; !ok { + return errors.New("auction-type is invalid") + } + if msg.MinPriceMultiplier.IsZero() { + return errors.New("min-price-multiplier cannot be 0") + } + if msg.MinBidAmount.LT(math.ZeroInt()) { + return errors.New("min-bid-amount must be at least 0") + } + if _, err := sdk.AccAddressFromBech32(msg.Beneficiary); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid address (%s)", err) + } + + return nil +} diff --git a/x/auction/types/params.go b/x/auction/types/params.go new file mode 100644 index 0000000000..874012a4b8 --- /dev/null +++ b/x/auction/types/params.go @@ -0,0 +1,16 @@ +package types + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams() +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} diff --git a/x/auction/types/query.pb.go b/x/auction/types/query.pb.go new file mode 100644 index 0000000000..35dc30bbea --- /dev/null +++ b/x/auction/types/query.pb.go @@ -0,0 +1,1059 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/auction/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryAuctionRequest is the request type for the Query/Auction RPC +// method +type QueryAuctionRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *QueryAuctionRequest) Reset() { *m = QueryAuctionRequest{} } +func (m *QueryAuctionRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAuctionRequest) ProtoMessage() {} +func (*QueryAuctionRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8113674a9412675c, []int{0} +} +func (m *QueryAuctionRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuctionRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuctionRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAuctionRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuctionRequest.Merge(m, src) +} +func (m *QueryAuctionRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAuctionRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuctionRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuctionRequest proto.InternalMessageInfo + +func (m *QueryAuctionRequest) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// QueryAuctionResponse is the response type for the Query/Auction RPC +// method +type QueryAuctionResponse struct { + Auction Auction `protobuf:"bytes,1,opt,name=auction,proto3" json:"auction"` +} + +func (m *QueryAuctionResponse) Reset() { *m = QueryAuctionResponse{} } +func (m *QueryAuctionResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAuctionResponse) ProtoMessage() {} +func (*QueryAuctionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8113674a9412675c, []int{1} +} +func (m *QueryAuctionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuctionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuctionResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAuctionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuctionResponse.Merge(m, src) +} +func (m *QueryAuctionResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAuctionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuctionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuctionResponse proto.InternalMessageInfo + +func (m *QueryAuctionResponse) GetAuction() Auction { + if m != nil { + return m.Auction + } + return Auction{} +} + +// QueryAuctionsRequest is the request type for the +// Query/Auctions RPC method +type QueryAuctionsRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAuctionsRequest) Reset() { *m = QueryAuctionsRequest{} } +func (m *QueryAuctionsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAuctionsRequest) ProtoMessage() {} +func (*QueryAuctionsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_8113674a9412675c, []int{2} +} +func (m *QueryAuctionsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuctionsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuctionsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAuctionsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuctionsRequest.Merge(m, src) +} +func (m *QueryAuctionsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAuctionsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuctionsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuctionsRequest proto.InternalMessageInfo + +func (m *QueryAuctionsRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryAuctionsResponse is the response type for the +// Query/Auctions RPC method +type QueryAuctionsResponse struct { + Auctions []Auction `protobuf:"bytes,1,rep,name=auctions,proto3" json:"auctions"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryAuctionsResponse) Reset() { *m = QueryAuctionsResponse{} } +func (m *QueryAuctionsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAuctionsResponse) ProtoMessage() {} +func (*QueryAuctionsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_8113674a9412675c, []int{3} +} +func (m *QueryAuctionsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAuctionsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAuctionsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAuctionsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAuctionsResponse.Merge(m, src) +} +func (m *QueryAuctionsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAuctionsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAuctionsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAuctionsResponse proto.InternalMessageInfo + +func (m *QueryAuctionsResponse) GetAuctions() []Auction { + if m != nil { + return m.Auctions + } + return nil +} + +func (m *QueryAuctionsResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +func init() { + proto.RegisterType((*QueryAuctionRequest)(nil), "stride.auction.QueryAuctionRequest") + proto.RegisterType((*QueryAuctionResponse)(nil), "stride.auction.QueryAuctionResponse") + proto.RegisterType((*QueryAuctionsRequest)(nil), "stride.auction.QueryAuctionsRequest") + proto.RegisterType((*QueryAuctionsResponse)(nil), "stride.auction.QueryAuctionsResponse") +} + +func init() { proto.RegisterFile("stride/auction/query.proto", fileDescriptor_8113674a9412675c) } + +var fileDescriptor_8113674a9412675c = []byte{ + // 422 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x4f, 0x6b, 0xdb, 0x30, + 0x14, 0xb7, 0xb2, 0x6c, 0xc9, 0x34, 0xd8, 0x41, 0xcb, 0x36, 0x63, 0x86, 0x17, 0xbc, 0xff, 0x83, + 0x49, 0x24, 0x1b, 0x8c, 0x1d, 0x97, 0xc3, 0x76, 0x68, 0xa1, 0xad, 0x7b, 0xeb, 0xa1, 0x20, 0xa7, + 0xc2, 0x35, 0x34, 0x96, 0x13, 0xc9, 0xa1, 0xa1, 0xf4, 0xd2, 0x4f, 0x50, 0xe8, 0xb1, 0x5f, 0x28, + 0xc7, 0x40, 0x2f, 0x3d, 0x95, 0x92, 0xf4, 0x43, 0xf4, 0x58, 0x2c, 0xc9, 0x69, 0x6c, 0x42, 0x72, + 0xf2, 0xc3, 0xef, 0xf7, 0x4f, 0xef, 0x3d, 0xe8, 0x08, 0x39, 0x88, 0x0e, 0x18, 0xa1, 0x69, 0x57, + 0x46, 0x3c, 0x26, 0xfd, 0x94, 0x0d, 0x46, 0x38, 0x19, 0x70, 0xc9, 0xd1, 0x4b, 0xdd, 0xc3, 0xa6, + 0xe7, 0x7c, 0xef, 0x72, 0xd1, 0xe3, 0x82, 0x04, 0x54, 0x30, 0x0d, 0x24, 0xc3, 0x56, 0xc0, 0x24, + 0x6d, 0x91, 0x84, 0x86, 0x51, 0x4c, 0x33, 0x94, 0xe6, 0x3a, 0x8d, 0x90, 0x87, 0x5c, 0x95, 0x24, + 0xab, 0xcc, 0xdf, 0x77, 0x21, 0xe7, 0xe1, 0x11, 0x23, 0x34, 0x89, 0x08, 0x8d, 0x63, 0x2e, 0x15, + 0x45, 0xe4, 0xdd, 0x52, 0x16, 0xf3, 0xd5, 0x5d, 0xef, 0x1b, 0x7c, 0xb5, 0x93, 0x79, 0xfe, 0xd5, + 0x7f, 0x7d, 0xd6, 0x4f, 0x99, 0x90, 0x08, 0xc1, 0x6a, 0x4c, 0x7b, 0xcc, 0x06, 0x4d, 0xf0, 0xf5, + 0xb9, 0xaf, 0x6a, 0x6f, 0x0b, 0x36, 0x8a, 0x50, 0x91, 0xf0, 0x58, 0x30, 0xf4, 0x1b, 0xd6, 0x8c, + 0xa6, 0x82, 0xbf, 0x68, 0xbf, 0xc5, 0xc5, 0x27, 0x62, 0xc3, 0xe8, 0x54, 0xc7, 0x37, 0xef, 0x2d, + 0x3f, 0x47, 0x7b, 0xfb, 0x45, 0x41, 0x91, 0x9b, 0xff, 0x83, 0xf0, 0xf1, 0xe5, 0x46, 0xf3, 0x33, + 0xd6, 0x63, 0xc2, 0xd9, 0x98, 0xb0, 0x9e, 0xa7, 0x19, 0x13, 0xde, 0xa6, 0x21, 0x33, 0x5c, 0x7f, + 0x81, 0xe9, 0x5d, 0x02, 0xf8, 0xba, 0x64, 0x60, 0x22, 0xff, 0x81, 0x75, 0x13, 0x42, 0xd8, 0xa0, + 0xf9, 0x64, 0x7d, 0xe6, 0x39, 0x1c, 0xfd, 0x2f, 0x84, 0xab, 0xa8, 0x70, 0x5f, 0xd6, 0x86, 0xd3, + 0xbe, 0x8b, 0xe9, 0xda, 0xf7, 0x00, 0x3e, 0x55, 0xe9, 0x90, 0x84, 0x35, 0xe3, 0x86, 0x3e, 0x94, + 0x63, 0x2c, 0x59, 0x8e, 0xf3, 0x71, 0x35, 0x48, 0x7b, 0x79, 0xee, 0xd9, 0xd5, 0xdd, 0x45, 0xc5, + 0x46, 0x6f, 0x48, 0xe9, 0x00, 0x4e, 0xb2, 0x6d, 0x9e, 0xa2, 0x11, 0xac, 0xe7, 0x73, 0x41, 0x2b, + 0x15, 0xf3, 0xbd, 0x38, 0x9f, 0xd6, 0xa0, 0x8c, 0x71, 0x53, 0x19, 0x3b, 0xc8, 0x26, 0xcb, 0x2f, + 0x4f, 0x74, 0x36, 0xc6, 0x53, 0x17, 0x4c, 0xa6, 0x2e, 0xb8, 0x9d, 0xba, 0xe0, 0x7c, 0xe6, 0x5a, + 0x93, 0x99, 0x6b, 0x5d, 0xcf, 0x5c, 0x6b, 0xaf, 0x15, 0x46, 0xf2, 0x30, 0x0d, 0x70, 0x97, 0xf7, + 0xc8, 0xae, 0x62, 0xff, 0xd8, 0xa4, 0x81, 0xc8, 0x95, 0x86, 0xed, 0x5f, 0xe4, 0x78, 0xae, 0x27, + 0x47, 0x09, 0x13, 0xc1, 0x33, 0x75, 0xc8, 0x3f, 0x1f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xad, 0x54, + 0x0c, 0x04, 0x74, 0x03, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Auction queries the auction info for a specific token + Auction(ctx context.Context, in *QueryAuctionRequest, opts ...grpc.CallOption) (*QueryAuctionResponse, error) + // Auctions queries the auction info for a specific token + Auctions(ctx context.Context, in *QueryAuctionsRequest, opts ...grpc.CallOption) (*QueryAuctionsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Auction(ctx context.Context, in *QueryAuctionRequest, opts ...grpc.CallOption) (*QueryAuctionResponse, error) { + out := new(QueryAuctionResponse) + err := c.cc.Invoke(ctx, "/stride.auction.Query/Auction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Auctions(ctx context.Context, in *QueryAuctionsRequest, opts ...grpc.CallOption) (*QueryAuctionsResponse, error) { + out := new(QueryAuctionsResponse) + err := c.cc.Invoke(ctx, "/stride.auction.Query/Auctions", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Auction queries the auction info for a specific token + Auction(context.Context, *QueryAuctionRequest) (*QueryAuctionResponse, error) + // Auctions queries the auction info for a specific token + Auctions(context.Context, *QueryAuctionsRequest) (*QueryAuctionsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Auction(ctx context.Context, req *QueryAuctionRequest) (*QueryAuctionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Auction not implemented") +} +func (*UnimplementedQueryServer) Auctions(ctx context.Context, req *QueryAuctionsRequest) (*QueryAuctionsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Auctions not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Auction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAuctionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Auction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.auction.Query/Auction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Auction(ctx, req.(*QueryAuctionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Auctions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAuctionsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Auctions(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.auction.Query/Auctions", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Auctions(ctx, req.(*QueryAuctionsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.auction.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Auction", + Handler: _Query_Auction_Handler, + }, + { + MethodName: "Auctions", + Handler: _Query_Auctions_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stride/auction/query.proto", +} + +func (m *QueryAuctionRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAuctionRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuctionRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAuctionResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAuctionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuctionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Auction.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAuctionsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAuctionsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuctionsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAuctionsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAuctionsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAuctionsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Auctions) > 0 { + for iNdEx := len(m.Auctions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Auctions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryAuctionRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAuctionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Auction.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAuctionsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAuctionsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Auctions) > 0 { + for _, e := range m.Auctions { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryAuctionRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAuctionRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuctionRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAuctionResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAuctionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuctionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Auction", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Auction.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAuctionsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAuctionsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuctionsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAuctionsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAuctionsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAuctionsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Auctions", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Auctions = append(m.Auctions, Auction{}) + if err := m.Auctions[len(m.Auctions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auction/types/query.pb.gw.go b/x/auction/types/query.pb.gw.go new file mode 100644 index 0000000000..6ae3c71981 --- /dev/null +++ b/x/auction/types/query.pb.gw.go @@ -0,0 +1,272 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stride/auction/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Auction_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuctionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + msg, err := client.Auction(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Auction_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuctionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + msg, err := server.Auction(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Auctions_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Auctions_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuctionsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Auctions_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Auctions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Auctions_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAuctionsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Auctions_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Auctions(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Auction_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Auction_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Auction_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Auctions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Auctions_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Auctions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Auction_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Auction_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Auction_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Auctions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Auctions_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Auctions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Auction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"stride", "auction", "name"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Auctions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "auction", "auctions"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Auction_0 = runtime.ForwardResponseMessage + + forward_Query_Auctions_0 = runtime.ForwardResponseMessage +) diff --git a/x/auction/types/tx.pb.go b/x/auction/types/tx.pb.go new file mode 100644 index 0000000000..621f6639c2 --- /dev/null +++ b/x/auction/types/tx.pb.go @@ -0,0 +1,2026 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/auction/tx.proto + +package types + +import ( + context "context" + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgPlaceBid defines the message for bidding in a token auction +type MsgPlaceBid struct { + // Bidder's address + Bidder string `protobuf:"bytes,1,opt,name=bidder,proto3" json:"bidder,omitempty"` + // Token being bid on + AuctionName string `protobuf:"bytes,2,opt,name=auction_name,json=auctionName,proto3" json:"auction_name,omitempty"` + // Amount of tokens requested in base units (utoken) + SellingTokenAmount cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=selling_token_amount,json=sellingTokenAmount,proto3,customtype=cosmossdk.io/math.Int" json:"selling_token_amount"` + // Amount of tokens being paid in base units (utoken) + PaymentTokenAmount cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=payment_token_amount,json=paymentTokenAmount,proto3,customtype=cosmossdk.io/math.Int" json:"payment_token_amount"` +} + +func (m *MsgPlaceBid) Reset() { *m = MsgPlaceBid{} } +func (m *MsgPlaceBid) String() string { return proto.CompactTextString(m) } +func (*MsgPlaceBid) ProtoMessage() {} +func (*MsgPlaceBid) Descriptor() ([]byte, []int) { + return fileDescriptor_07b888fb549a7ca8, []int{0} +} +func (m *MsgPlaceBid) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPlaceBid) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPlaceBid.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgPlaceBid) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPlaceBid.Merge(m, src) +} +func (m *MsgPlaceBid) XXX_Size() int { + return m.Size() +} +func (m *MsgPlaceBid) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPlaceBid.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPlaceBid proto.InternalMessageInfo + +func (m *MsgPlaceBid) GetBidder() string { + if m != nil { + return m.Bidder + } + return "" +} + +func (m *MsgPlaceBid) GetAuctionName() string { + if m != nil { + return m.AuctionName + } + return "" +} + +type MsgPlaceBidResponse struct { +} + +func (m *MsgPlaceBidResponse) Reset() { *m = MsgPlaceBidResponse{} } +func (m *MsgPlaceBidResponse) String() string { return proto.CompactTextString(m) } +func (*MsgPlaceBidResponse) ProtoMessage() {} +func (*MsgPlaceBidResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_07b888fb549a7ca8, []int{1} +} +func (m *MsgPlaceBidResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPlaceBidResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPlaceBidResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgPlaceBidResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPlaceBidResponse.Merge(m, src) +} +func (m *MsgPlaceBidResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgPlaceBidResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPlaceBidResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPlaceBidResponse proto.InternalMessageInfo + +// MsgCreateAuction defines the message for adding a token auction +type MsgCreateAuction struct { + // Admin's address + Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` + // A unique auction name + AuctionName string `protobuf:"bytes,2,opt,name=auction_name,json=auctionName,proto3" json:"auction_name,omitempty"` + // Auction type + AuctionType AuctionType `protobuf:"varint,3,opt,name=auction_type,json=auctionType,proto3,enum=stride.auction.AuctionType" json:"auction_type,omitempty"` + // Denom on Stride of the token being auctioned off (e.g. "ibc/...") + SellingDenom string `protobuf:"bytes,4,opt,name=selling_denom,json=sellingDenom,proto3" json:"selling_denom,omitempty"` + // Denom on Stride of the token being used to place bids (e.g. "ustrd") + PaymentDenom string `protobuf:"bytes,5,opt,name=payment_denom,json=paymentDenom,proto3" json:"payment_denom,omitempty"` + // Whether auction is active + Enabled bool `protobuf:"varint,6,opt,name=enabled,proto3" json:"enabled,omitempty"` + // Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle reported + // price) bids_floor_price = oracle_price * min_price_multiplier + MinPriceMultiplier cosmossdk_io_math.LegacyDec `protobuf:"bytes,7,opt,name=min_price_multiplier,json=minPriceMultiplier,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_price_multiplier"` + // Minimum payment token bid amount + MinBidAmount cosmossdk_io_math.Int `protobuf:"bytes,8,opt,name=min_bid_amount,json=minBidAmount,proto3,customtype=cosmossdk.io/math.Int" json:"min_bid_amount"` + Beneficiary string `protobuf:"bytes,9,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"` +} + +func (m *MsgCreateAuction) Reset() { *m = MsgCreateAuction{} } +func (m *MsgCreateAuction) String() string { return proto.CompactTextString(m) } +func (*MsgCreateAuction) ProtoMessage() {} +func (*MsgCreateAuction) Descriptor() ([]byte, []int) { + return fileDescriptor_07b888fb549a7ca8, []int{2} +} +func (m *MsgCreateAuction) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateAuction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateAuction.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateAuction) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateAuction.Merge(m, src) +} +func (m *MsgCreateAuction) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateAuction) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateAuction.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateAuction proto.InternalMessageInfo + +func (m *MsgCreateAuction) GetAdmin() string { + if m != nil { + return m.Admin + } + return "" +} + +func (m *MsgCreateAuction) GetAuctionName() string { + if m != nil { + return m.AuctionName + } + return "" +} + +func (m *MsgCreateAuction) GetAuctionType() AuctionType { + if m != nil { + return m.AuctionType + } + return AuctionType_AUCTION_TYPE_UNSPECIFIED +} + +func (m *MsgCreateAuction) GetSellingDenom() string { + if m != nil { + return m.SellingDenom + } + return "" +} + +func (m *MsgCreateAuction) GetPaymentDenom() string { + if m != nil { + return m.PaymentDenom + } + return "" +} + +func (m *MsgCreateAuction) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + +func (m *MsgCreateAuction) GetBeneficiary() string { + if m != nil { + return m.Beneficiary + } + return "" +} + +type MsgCreateAuctionResponse struct { +} + +func (m *MsgCreateAuctionResponse) Reset() { *m = MsgCreateAuctionResponse{} } +func (m *MsgCreateAuctionResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateAuctionResponse) ProtoMessage() {} +func (*MsgCreateAuctionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_07b888fb549a7ca8, []int{3} +} +func (m *MsgCreateAuctionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateAuctionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateAuctionResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateAuctionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateAuctionResponse.Merge(m, src) +} +func (m *MsgCreateAuctionResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateAuctionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateAuctionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateAuctionResponse proto.InternalMessageInfo + +// MsgUpdateAuction defines the message for adding a token auction +type MsgUpdateAuction struct { + // Admin's address + Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` + // A unique auction name + AuctionName string `protobuf:"bytes,2,opt,name=auction_name,json=auctionName,proto3" json:"auction_name,omitempty"` + // Auction type + AuctionType AuctionType `protobuf:"varint,3,opt,name=auction_type,json=auctionType,proto3,enum=stride.auction.AuctionType" json:"auction_type,omitempty"` + // Whether auction is active + Enabled bool `protobuf:"varint,4,opt,name=enabled,proto3" json:"enabled,omitempty"` + // Minimum price multiplier (e.g. 0.95 for 5% discount off the oracle reported + // price) bids_floor_price = oracle_price * min_price_multiplier + MinPriceMultiplier cosmossdk_io_math.LegacyDec `protobuf:"bytes,5,opt,name=min_price_multiplier,json=minPriceMultiplier,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_price_multiplier"` + // Minimum payment token bid amount + MinBidAmount cosmossdk_io_math.Int `protobuf:"bytes,6,opt,name=min_bid_amount,json=minBidAmount,proto3,customtype=cosmossdk.io/math.Int" json:"min_bid_amount"` + Beneficiary string `protobuf:"bytes,7,opt,name=beneficiary,proto3" json:"beneficiary,omitempty"` +} + +func (m *MsgUpdateAuction) Reset() { *m = MsgUpdateAuction{} } +func (m *MsgUpdateAuction) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateAuction) ProtoMessage() {} +func (*MsgUpdateAuction) Descriptor() ([]byte, []int) { + return fileDescriptor_07b888fb549a7ca8, []int{4} +} +func (m *MsgUpdateAuction) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateAuction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateAuction.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateAuction) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateAuction.Merge(m, src) +} +func (m *MsgUpdateAuction) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateAuction) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateAuction.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateAuction proto.InternalMessageInfo + +func (m *MsgUpdateAuction) GetAdmin() string { + if m != nil { + return m.Admin + } + return "" +} + +func (m *MsgUpdateAuction) GetAuctionName() string { + if m != nil { + return m.AuctionName + } + return "" +} + +func (m *MsgUpdateAuction) GetAuctionType() AuctionType { + if m != nil { + return m.AuctionType + } + return AuctionType_AUCTION_TYPE_UNSPECIFIED +} + +func (m *MsgUpdateAuction) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + +func (m *MsgUpdateAuction) GetBeneficiary() string { + if m != nil { + return m.Beneficiary + } + return "" +} + +type MsgUpdateAuctionResponse struct { +} + +func (m *MsgUpdateAuctionResponse) Reset() { *m = MsgUpdateAuctionResponse{} } +func (m *MsgUpdateAuctionResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateAuctionResponse) ProtoMessage() {} +func (*MsgUpdateAuctionResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_07b888fb549a7ca8, []int{5} +} +func (m *MsgUpdateAuctionResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateAuctionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateAuctionResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateAuctionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateAuctionResponse.Merge(m, src) +} +func (m *MsgUpdateAuctionResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateAuctionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateAuctionResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateAuctionResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgPlaceBid)(nil), "stride.auction.MsgPlaceBid") + proto.RegisterType((*MsgPlaceBidResponse)(nil), "stride.auction.MsgPlaceBidResponse") + proto.RegisterType((*MsgCreateAuction)(nil), "stride.auction.MsgCreateAuction") + proto.RegisterType((*MsgCreateAuctionResponse)(nil), "stride.auction.MsgCreateAuctionResponse") + proto.RegisterType((*MsgUpdateAuction)(nil), "stride.auction.MsgUpdateAuction") + proto.RegisterType((*MsgUpdateAuctionResponse)(nil), "stride.auction.MsgUpdateAuctionResponse") +} + +func init() { proto.RegisterFile("stride/auction/tx.proto", fileDescriptor_07b888fb549a7ca8) } + +var fileDescriptor_07b888fb549a7ca8 = []byte{ + // 687 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0x3d, 0x4f, 0xdc, 0x4a, + 0x14, 0x5d, 0x03, 0xbb, 0xc0, 0xf0, 0xa1, 0xf7, 0xcc, 0x22, 0xfc, 0x96, 0xf7, 0x16, 0xde, 0x6e, + 0x11, 0x84, 0x84, 0x1d, 0x48, 0x2a, 0x8a, 0x48, 0x2c, 0x34, 0x51, 0xd8, 0x04, 0x19, 0x68, 0x92, + 0x62, 0x35, 0xf6, 0x4c, 0xcc, 0x88, 0x9d, 0x19, 0xcb, 0x33, 0x8b, 0xd8, 0x2e, 0x4a, 0x49, 0x95, + 0x22, 0x7f, 0x22, 0x1d, 0x45, 0x7e, 0x40, 0x4a, 0x4a, 0x94, 0x2a, 0x4a, 0x81, 0x22, 0x28, 0xf8, + 0x1b, 0x91, 0x3d, 0xe3, 0xc5, 0x86, 0x55, 0x58, 0x29, 0x14, 0x69, 0x30, 0xf7, 0xde, 0x73, 0x8e, + 0xbd, 0xe7, 0x5c, 0xcd, 0x80, 0x39, 0x21, 0x23, 0x82, 0xb0, 0x03, 0x3b, 0xbe, 0x24, 0x9c, 0x39, + 0xf2, 0xd8, 0x0e, 0x23, 0x2e, 0xb9, 0x39, 0xad, 0x06, 0xb6, 0x1e, 0x54, 0xfe, 0x86, 0x94, 0x30, + 0xee, 0x24, 0x7f, 0x15, 0xa4, 0xf2, 0x8f, 0xcf, 0x05, 0xe5, 0xa2, 0x95, 0x54, 0x8e, 0x2a, 0xf4, + 0x68, 0x4e, 0x55, 0x0e, 0x15, 0x81, 0x73, 0xb4, 0x1a, 0x3f, 0xf4, 0xa0, 0x1c, 0xf0, 0x80, 0x2b, + 0x42, 0xfc, 0x9f, 0xee, 0xfe, 0x7b, 0xeb, 0x2b, 0xf4, 0x53, 0x4d, 0x6b, 0x9f, 0x86, 0xc0, 0x44, + 0x53, 0x04, 0x3b, 0x6d, 0xe8, 0xe3, 0x06, 0x41, 0xe6, 0x63, 0x50, 0xf2, 0x08, 0x42, 0x38, 0xb2, + 0x8c, 0x45, 0x63, 0x69, 0xbc, 0x61, 0x7d, 0xfd, 0xbc, 0x52, 0xd6, 0xaf, 0xdf, 0x40, 0x28, 0xc2, + 0x42, 0xec, 0xca, 0x88, 0xb0, 0xc0, 0xd5, 0x38, 0xf3, 0x7f, 0x30, 0xa9, 0x25, 0x5b, 0x0c, 0x52, + 0x6c, 0x0d, 0xc5, 0x3c, 0x77, 0x42, 0xf7, 0x5e, 0x42, 0x8a, 0xcd, 0x57, 0xa0, 0x2c, 0x70, 0xbb, + 0x4d, 0x58, 0xd0, 0x92, 0xfc, 0x10, 0xb3, 0x16, 0xa4, 0xbc, 0xc3, 0xa4, 0x35, 0x9c, 0xbc, 0xe2, + 0xbf, 0xb3, 0x8b, 0x85, 0xc2, 0xf7, 0x8b, 0x85, 0x59, 0xf5, 0x1a, 0x81, 0x0e, 0x6d, 0xc2, 0x1d, + 0x0a, 0xe5, 0x81, 0xfd, 0x9c, 0x49, 0xd7, 0xd4, 0xd4, 0xbd, 0x98, 0xb9, 0x91, 0x10, 0x63, 0xc1, + 0x10, 0x76, 0x29, 0x66, 0x32, 0x2f, 0x38, 0x32, 0x90, 0xa0, 0xa6, 0x66, 0x04, 0xd7, 0xeb, 0xef, + 0xaf, 0x4f, 0x97, 0xf5, 0x2f, 0x3a, 0xb9, 0x3e, 0x5d, 0x9e, 0x49, 0xdd, 0xca, 0x78, 0x53, 0x9b, + 0x05, 0x33, 0x99, 0xd2, 0xc5, 0x22, 0xe4, 0x4c, 0xe0, 0xda, 0xc9, 0x08, 0xf8, 0xab, 0x29, 0x82, + 0xcd, 0x08, 0x43, 0x89, 0x37, 0x14, 0xcf, 0xb4, 0x41, 0x11, 0x22, 0x4a, 0xd8, 0xbd, 0x36, 0x2a, + 0xd8, 0x20, 0x2e, 0x3e, 0xbb, 0x81, 0xc8, 0x6e, 0x88, 0x13, 0xf7, 0xa6, 0xd7, 0xe6, 0xed, 0xfc, + 0x32, 0xd9, 0xfa, 0x0b, 0xf6, 0xba, 0x21, 0xee, 0xf1, 0xe3, 0xc2, 0xac, 0x83, 0xa9, 0x34, 0x05, + 0x84, 0x19, 0xa7, 0xca, 0x2d, 0x77, 0x52, 0x37, 0xb7, 0xe2, 0x5e, 0x0c, 0x4a, 0x9d, 0x55, 0xa0, + 0xa2, 0x02, 0xe9, 0xa6, 0x02, 0x59, 0x60, 0x14, 0x33, 0xe8, 0xb5, 0x31, 0xb2, 0x4a, 0x8b, 0xc6, + 0xd2, 0x98, 0x9b, 0x96, 0xe6, 0x3e, 0x28, 0x53, 0xc2, 0x5a, 0x61, 0x44, 0x7c, 0xdc, 0xa2, 0x9d, + 0xb6, 0x24, 0x61, 0x9b, 0xe0, 0xc8, 0x1a, 0x4d, 0x5c, 0xa8, 0xeb, 0x60, 0xe6, 0xef, 0x06, 0xb3, + 0x8d, 0x03, 0xe8, 0x77, 0xb7, 0xb0, 0xef, 0x9a, 0x94, 0xb0, 0x9d, 0x98, 0xdf, 0xec, 0xd1, 0xcd, + 0x4d, 0x30, 0x1d, 0xcb, 0x7a, 0x04, 0xa5, 0x49, 0x8f, 0x0d, 0x92, 0xf4, 0x24, 0x25, 0xac, 0x41, + 0x90, 0x5e, 0x9a, 0x75, 0x30, 0xe1, 0x61, 0x86, 0xdf, 0x12, 0x9f, 0xc0, 0xa8, 0x6b, 0x8d, 0xdf, + 0x13, 0x4c, 0x16, 0xbc, 0xfe, 0x28, 0xde, 0x0f, 0x15, 0x55, 0xbc, 0x1e, 0x56, 0x66, 0x3d, 0x72, + 0xb9, 0xd7, 0x2a, 0xc0, 0xba, 0xdd, 0xeb, 0x2d, 0xca, 0x97, 0xe1, 0x64, 0x51, 0xf6, 0x43, 0xf4, + 0x67, 0x2f, 0x4a, 0x26, 0xde, 0x91, 0xc1, 0xe2, 0x2d, 0x3e, 0x74, 0xbc, 0xa5, 0xdf, 0x8e, 0x77, + 0xf4, 0x81, 0xe2, 0xcd, 0xa5, 0xa5, 0xe3, 0xcd, 0xf5, 0xd2, 0x78, 0xd7, 0x3e, 0x0e, 0x81, 0xe1, + 0xa6, 0x08, 0xcc, 0x6d, 0x30, 0xd6, 0x3b, 0x4e, 0xef, 0x98, 0x9e, 0x39, 0x40, 0x2a, 0xf5, 0x5f, + 0x0c, 0x53, 0x55, 0xf3, 0x0d, 0x98, 0xca, 0x9f, 0x2c, 0x8b, 0x7d, 0x58, 0x39, 0x44, 0x65, 0xe9, + 0x3e, 0x44, 0x56, 0x3c, 0xbf, 0x8d, 0xfd, 0xc4, 0x73, 0x88, 0xbe, 0xe2, 0x7d, 0xfd, 0xa8, 0x14, + 0xdf, 0x5d, 0x9f, 0x2e, 0x1b, 0x8d, 0x17, 0x67, 0x97, 0x55, 0xe3, 0xfc, 0xb2, 0x6a, 0xfc, 0xb8, + 0xac, 0x1a, 0x1f, 0xae, 0xaa, 0x85, 0xf3, 0xab, 0x6a, 0xe1, 0xdb, 0x55, 0xb5, 0xf0, 0x7a, 0x35, + 0x20, 0xf2, 0xa0, 0xe3, 0xd9, 0x3e, 0xa7, 0xce, 0x6e, 0x22, 0xba, 0xb2, 0x0d, 0x3d, 0xe1, 0xe8, + 0x0b, 0xeb, 0x68, 0xed, 0xa9, 0x73, 0x7c, 0x73, 0x79, 0x76, 0x43, 0x2c, 0xbc, 0x52, 0x72, 0x6b, + 0x3d, 0xf9, 0x19, 0x00, 0x00, 0xff, 0xff, 0x42, 0xdb, 0xea, 0x9b, 0x5b, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // PlaceBid places a bid to buy a token off an auction + PlaceBid(ctx context.Context, in *MsgPlaceBid, opts ...grpc.CallOption) (*MsgPlaceBidResponse, error) + // CreateAuction creates a new auction + CreateAuction(ctx context.Context, in *MsgCreateAuction, opts ...grpc.CallOption) (*MsgCreateAuctionResponse, error) + // CreateAuction updates an existing auction + UpdateAuction(ctx context.Context, in *MsgUpdateAuction, opts ...grpc.CallOption) (*MsgUpdateAuctionResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) PlaceBid(ctx context.Context, in *MsgPlaceBid, opts ...grpc.CallOption) (*MsgPlaceBidResponse, error) { + out := new(MsgPlaceBidResponse) + err := c.cc.Invoke(ctx, "/stride.auction.Msg/PlaceBid", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) CreateAuction(ctx context.Context, in *MsgCreateAuction, opts ...grpc.CallOption) (*MsgCreateAuctionResponse, error) { + out := new(MsgCreateAuctionResponse) + err := c.cc.Invoke(ctx, "/stride.auction.Msg/CreateAuction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateAuction(ctx context.Context, in *MsgUpdateAuction, opts ...grpc.CallOption) (*MsgUpdateAuctionResponse, error) { + out := new(MsgUpdateAuctionResponse) + err := c.cc.Invoke(ctx, "/stride.auction.Msg/UpdateAuction", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // PlaceBid places a bid to buy a token off an auction + PlaceBid(context.Context, *MsgPlaceBid) (*MsgPlaceBidResponse, error) + // CreateAuction creates a new auction + CreateAuction(context.Context, *MsgCreateAuction) (*MsgCreateAuctionResponse, error) + // CreateAuction updates an existing auction + UpdateAuction(context.Context, *MsgUpdateAuction) (*MsgUpdateAuctionResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) PlaceBid(ctx context.Context, req *MsgPlaceBid) (*MsgPlaceBidResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PlaceBid not implemented") +} +func (*UnimplementedMsgServer) CreateAuction(ctx context.Context, req *MsgCreateAuction) (*MsgCreateAuctionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateAuction not implemented") +} +func (*UnimplementedMsgServer) UpdateAuction(ctx context.Context, req *MsgUpdateAuction) (*MsgUpdateAuctionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateAuction not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_PlaceBid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgPlaceBid) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).PlaceBid(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.auction.Msg/PlaceBid", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).PlaceBid(ctx, req.(*MsgPlaceBid)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_CreateAuction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateAuction) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateAuction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.auction.Msg/CreateAuction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateAuction(ctx, req.(*MsgCreateAuction)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateAuction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateAuction) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateAuction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.auction.Msg/UpdateAuction", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateAuction(ctx, req.(*MsgUpdateAuction)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.auction.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "PlaceBid", + Handler: _Msg_PlaceBid_Handler, + }, + { + MethodName: "CreateAuction", + Handler: _Msg_CreateAuction_Handler, + }, + { + MethodName: "UpdateAuction", + Handler: _Msg_UpdateAuction_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stride/auction/tx.proto", +} + +func (m *MsgPlaceBid) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgPlaceBid) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPlaceBid) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.PaymentTokenAmount.Size() + i -= size + if _, err := m.PaymentTokenAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.SellingTokenAmount.Size() + i -= size + if _, err := m.SellingTokenAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.AuctionName) > 0 { + i -= len(m.AuctionName) + copy(dAtA[i:], m.AuctionName) + i = encodeVarintTx(dAtA, i, uint64(len(m.AuctionName))) + i-- + dAtA[i] = 0x12 + } + if len(m.Bidder) > 0 { + i -= len(m.Bidder) + copy(dAtA[i:], m.Bidder) + i = encodeVarintTx(dAtA, i, uint64(len(m.Bidder))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgPlaceBidResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgPlaceBidResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPlaceBidResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgCreateAuction) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateAuction) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateAuction) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Beneficiary) > 0 { + i -= len(m.Beneficiary) + copy(dAtA[i:], m.Beneficiary) + i = encodeVarintTx(dAtA, i, uint64(len(m.Beneficiary))) + i-- + dAtA[i] = 0x4a + } + { + size := m.MinBidAmount.Size() + i -= size + if _, err := m.MinBidAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + { + size := m.MinPriceMultiplier.Size() + i -= size + if _, err := m.MinPriceMultiplier.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x30 + } + if len(m.PaymentDenom) > 0 { + i -= len(m.PaymentDenom) + copy(dAtA[i:], m.PaymentDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.PaymentDenom))) + i-- + dAtA[i] = 0x2a + } + if len(m.SellingDenom) > 0 { + i -= len(m.SellingDenom) + copy(dAtA[i:], m.SellingDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.SellingDenom))) + i-- + dAtA[i] = 0x22 + } + if m.AuctionType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.AuctionType)) + i-- + dAtA[i] = 0x18 + } + if len(m.AuctionName) > 0 { + i -= len(m.AuctionName) + copy(dAtA[i:], m.AuctionName) + i = encodeVarintTx(dAtA, i, uint64(len(m.AuctionName))) + i-- + dAtA[i] = 0x12 + } + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintTx(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateAuctionResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateAuctionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateAuctionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateAuction) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateAuction) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateAuction) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Beneficiary) > 0 { + i -= len(m.Beneficiary) + copy(dAtA[i:], m.Beneficiary) + i = encodeVarintTx(dAtA, i, uint64(len(m.Beneficiary))) + i-- + dAtA[i] = 0x3a + } + { + size := m.MinBidAmount.Size() + i -= size + if _, err := m.MinBidAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + { + size := m.MinPriceMultiplier.Size() + i -= size + if _, err := m.MinPriceMultiplier.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x20 + } + if m.AuctionType != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.AuctionType)) + i-- + dAtA[i] = 0x18 + } + if len(m.AuctionName) > 0 { + i -= len(m.AuctionName) + copy(dAtA[i:], m.AuctionName) + i = encodeVarintTx(dAtA, i, uint64(len(m.AuctionName))) + i-- + dAtA[i] = 0x12 + } + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintTx(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateAuctionResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateAuctionResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateAuctionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgPlaceBid) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Bidder) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.AuctionName) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.SellingTokenAmount.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.PaymentTokenAmount.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgPlaceBidResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgCreateAuction) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.AuctionName) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.AuctionType != 0 { + n += 1 + sovTx(uint64(m.AuctionType)) + } + l = len(m.SellingDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PaymentDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Enabled { + n += 2 + } + l = m.MinPriceMultiplier.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.MinBidAmount.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Beneficiary) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreateAuctionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateAuction) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.AuctionName) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.AuctionType != 0 { + n += 1 + sovTx(uint64(m.AuctionType)) + } + if m.Enabled { + n += 2 + } + l = m.MinPriceMultiplier.Size() + n += 1 + l + sovTx(uint64(l)) + l = m.MinBidAmount.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Beneficiary) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateAuctionResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgPlaceBid) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgPlaceBid: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPlaceBid: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bidder", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bidder = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AuctionName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SellingTokenAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SellingTokenAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PaymentTokenAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PaymentTokenAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgPlaceBidResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgPlaceBidResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPlaceBidResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateAuction) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateAuction: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateAuction: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AuctionName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionType", wireType) + } + m.AuctionType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AuctionType |= AuctionType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SellingDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SellingDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PaymentDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PaymentDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinPriceMultiplier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinPriceMultiplier.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinBidAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinBidAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Beneficiary", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Beneficiary = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateAuctionResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateAuctionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateAuctionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateAuction) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateAuction: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateAuction: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionName", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AuctionName = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionType", wireType) + } + m.AuctionType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AuctionType |= AuctionType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinPriceMultiplier", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinPriceMultiplier.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinBidAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinBidAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Beneficiary", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Beneficiary = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateAuctionResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateAuctionResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateAuctionResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auction/types/validate.go b/x/auction/types/validate.go new file mode 100644 index 0000000000..b5404425f1 --- /dev/null +++ b/x/auction/types/validate.go @@ -0,0 +1,45 @@ +package types + +import ( + "errors" + fmt "fmt" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func ValidateCreateAuctionParams( + auctionName string, + auctionType AuctionType, + sellingDenom string, + paymentDenom string, + minPriceMultiplier math.LegacyDec, + minBidAmount math.Int, + beneficiary string, +) error { + if auctionName == "" { + return errors.New("auction-name must be specified") + } + if _, ok := AuctionType_name[int32(auctionType)]; !ok { + return fmt.Errorf("auction-type %d is invalid", auctionType) + } + if sellingDenom == "" { + return errors.New("selling-denom must be specified") + } + if paymentDenom == "" { + return errors.New("payment-denom must be specified") + } + if !(minPriceMultiplier.GT(math.LegacyZeroDec()) && minPriceMultiplier.LTE(math.LegacyOneDec())) { + return errors.New("min-price-multiplier must be > 0 and <= 1 (0 > minPriceMultiplier >= 1)") + } + if minBidAmount.LT(math.ZeroInt()) { + return errors.New("min-bid-amount must be >= 0") + } + if _, err := sdk.AccAddressFromBech32(beneficiary); err != nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid beneficiary address (%s)", err) + } + + return nil +} diff --git a/x/icqoracle/client/cli/query.go b/x/icqoracle/client/cli/query.go new file mode 100644 index 0000000000..d1c2356893 --- /dev/null +++ b/x/icqoracle/client/cli/query.go @@ -0,0 +1,104 @@ +package cli + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +// GetQueryCmd returns the cli query commands for this module. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdQueryTokenPrice(), + CmdQueryTokenPrices(), + CmdQueryParams(), + ) + + return cmd +} + +func CmdQueryTokenPrice() *cobra.Command { + cmd := &cobra.Command{ + Use: "token-price [base-denom] [quote-denom]", + Short: "Query the current price for a specific token", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + baseDenom := args[0] + quoteDenom := args[1] + + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryTokenPriceRequest{ + BaseDenom: baseDenom, + QuoteDenom: quoteDenom, + } + res, err := queryClient.TokenPrice(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + return cmd +} + +func CmdQueryTokenPrices() *cobra.Command { + cmd := &cobra.Command{ + Use: "token-prices", + Short: "Query all token prices", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + req := &types.QueryTokenPricesRequest{} + res, err := queryClient.TokenPrices(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + return cmd +} + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Get the parameters", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + req := &types.QueryParamsRequest{} + res, err := queryClient.Params(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + return cmd +} diff --git a/x/icqoracle/client/cli/tx.go b/x/icqoracle/client/cli/tx.go new file mode 100644 index 0000000000..7a00cdda75 --- /dev/null +++ b/x/icqoracle/client/cli/tx.go @@ -0,0 +1,110 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + "github.com/spf13/cobra" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdAddTokenPrice(), + CmdRemoveTokenPrice(), + ) + + return cmd +} + +func CmdAddTokenPrice() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-token-price [base-denom] [quote-denom] [osmosis-pool-id] [osmosis-base-denom] [osmosis-quote-denom]", + Short: "Add a token to price tracking", + Long: strings.TrimSpace( + fmt.Sprintf(`Add a token to price tracking. + +Example: + $ %[1]s tx %[2]s add-token-price uosmo uatom 123 uosmo ibc/... --from admin +`, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(5), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgRegisterTokenPriceQuery( + clientCtx.GetFromAddress().String(), + args[0], + args[1], + args[2], + args[3], + args[4], + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func CmdRemoveTokenPrice() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove-token-price [base-denom] [quote-denom] [osmosis-pool-id]", + Short: "Remove a token from price tracking", + Long: strings.TrimSpace( + fmt.Sprintf(`Remove a token from price tracking. + +Example: + $ %[1]s tx %[2]s remove-token-price uatom uosmo 123 --from admin +`, version.AppName, types.ModuleName), + ), + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgRemoveTokenPriceQuery( + clientCtx.GetFromAddress().String(), + args[0], + args[1], + args[2], + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/icqoracle/deps/osmomath/decimal.go b/x/icqoracle/deps/osmomath/decimal.go new file mode 100644 index 0000000000..2515e1e2eb --- /dev/null +++ b/x/icqoracle/deps/osmomath/decimal.go @@ -0,0 +1,1287 @@ +// Forked from https://github.com/osmosis-labs/osmosis/blob/v27.0.0/osmomath/decimal.go under the Apache v2.0 License +package osmomath + +import ( + "encoding/json" + "errors" + "fmt" + "math/big" + "strconv" + "strings" + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// NOTE: never use new(BigDec) or else we will panic unmarshalling into the +// nil embedded big.Int +type BigDec struct { + i *big.Int +} + +const ( + // number of decimal places + BigDecPrecision = 36 + + // bytes required to represent the above precision + // Ceiling[Log2[10**Precision - 1]] + BigDecimalPrecisionBits = 120 + + maxDecBitLen = maxBitLen + BigDecimalPrecisionBits + + // max number of iterations in ApproxRoot function + maxApproxRootIterations = 100 + + // max number of iterations in Log2 function + maxLog2Iterations = 300 +) + +var ( + defaultBigDecPrecisionReuse = new(big.Int).Exp(big.NewInt(10), big.NewInt(BigDecPrecision), nil) + precisionReuseSDKDec = new(big.Int).Exp(big.NewInt(10), big.NewInt(DecPrecision), nil) + + //nolint:unused + bigDecDecPrecision = new(big.Int).Mul(defaultBigDecPrecisionReuse, precisionReuseSDKDec) + squaredPrecisionReuse = new(big.Int).Mul(defaultBigDecPrecisionReuse, defaultBigDecPrecisionReuse) + bigDecDecPrecisionFactorDiff = new(big.Int).Exp(big.NewInt(10), big.NewInt(BigDecPrecision-DecPrecision), nil) + + //nolint:unused + tenTimesPrecision = new(big.Int).Exp(big.NewInt(10), big.NewInt(BigDecPrecision+1), nil) + fivePrecision = new(big.Int).Quo(defaultBigDecPrecisionReuse, big.NewInt(2)) + fivePrecisionSDKDec = new(big.Int).Quo(precisionReuseSDKDec, big.NewInt(2)) + + precisionMultipliers []*big.Int + zeroInt = big.NewInt(0) + oneInt = big.NewInt(1) + //nolint:unused + fiveInt = big.NewInt(5) + tenInt = big.NewInt(10) + + // log_2(e) + // From: https://www.wolframalpha.com/input?i=log_2%28e%29+with+37+digits + logOfEbase2 = MustNewBigDecFromStr("1.442695040888963407359924681001892137") + + // log_2(1.0001) + // From: https://www.wolframalpha.com/input?i=log_2%281.0001%29+to+33+digits + tickLogOf2 = MustNewBigDecFromStr("0.000144262291094554178391070900057480") + // initialized in init() since requires + // precision to be defined. + twoBigDec BigDec = MustNewBigDecFromStr("2") + + // precisionFactors are used to adjust the scale of big.Int values to match the desired precision + precisionFactors = make(map[uint64]*big.Int) + + zeroBigDec BigDec = ZeroBigDec() + oneBigDec BigDec = OneBigDec() + oneHalfBigDec BigDec = oneBigDec.Quo(twoBigDec) + negOneBigDec BigDec = oneBigDec.Neg() +) + +// Decimal errors +var ( + ErrEmptyDecimalStr = errors.New("decimal string cannot be empty") + ErrInvalidDecimalLength = errors.New("invalid decimal length") + ErrInvalidDecimalStr = errors.New("invalid decimal string") +) + +// Set precision multipliers +func init() { + precisionMultipliers = make([]*big.Int, BigDecPrecision+1) + for i := 0; i <= BigDecPrecision; i++ { + precisionMultipliers[i] = calcPrecisionMultiplier(int64(i)) + } + + for precision := uint64(0); precision <= BigDecPrecision; precision++ { + precisionFactor := new(big.Int).Exp(big.NewInt(10), big.NewInt(BigDecPrecision-int64(precision)), nil) + precisionFactors[precision] = precisionFactor + } +} + +func precisionInt() *big.Int { + return new(big.Int).Set(defaultBigDecPrecisionReuse) +} + +func ZeroBigDec() BigDec { return BigDec{new(big.Int).Set(zeroInt)} } +func OneBigDec() BigDec { return BigDec{precisionInt()} } +func SmallestBigDec() BigDec { return BigDec{new(big.Int).Set(oneInt)} } + +// calculate the precision multiplier +func calcPrecisionMultiplier(prec int64) *big.Int { + if prec > BigDecPrecision { + panic(fmt.Sprintf("too much precision, maximum %v, provided %v", BigDecPrecision, prec)) + } + zerosToAdd := BigDecPrecision - prec + multiplier := new(big.Int).Exp(tenInt, big.NewInt(zerosToAdd), nil) + return multiplier +} + +// get the precision multiplier, do not mutate result +func precisionMultiplier(prec int64) *big.Int { + if prec > BigDecPrecision { + panic(fmt.Sprintf("too much precision, maximum %v, provided %v", BigDecPrecision, prec)) + } + return precisionMultipliers[prec] +} + +// create a new NewBigDec from integer assuming whole number +func NewBigDec(i int64) BigDec { + return NewBigDecWithPrec(i, 0) +} + +// create a new BigDec from integer with decimal place at prec +// CONTRACT: prec <= BigDecPrecision +func NewBigDecWithPrec(i, prec int64) BigDec { + bi := big.NewInt(i) + return BigDec{ + bi.Mul(bi, precisionMultiplier(prec)), + } +} + +// create a new BigDec from big integer assuming whole numbers +// CONTRACT: prec <= BigDecPrecision +func NewBigDecFromBigInt(i *big.Int) BigDec { + return NewBigDecFromBigIntWithPrec(i, 0) +} + +func NewBigDecFromBigIntMut(i *big.Int) BigDec { + return NewBigDecFromBigIntMutWithPrec(i, 0) +} + +// create a new BigDec from big integer assuming whole numbers +// CONTRACT: prec <= BigDecPrecision +func NewBigDecFromBigIntWithPrec(i *big.Int, prec int64) BigDec { + return BigDec{ + new(big.Int).Mul(i, precisionMultiplier(prec)), + } +} + +// returns a BigDec, built using a mutated copy of the passed in bigint. +// CONTRACT: prec <= BigDecPrecision +func NewBigDecFromBigIntMutWithPrec(i *big.Int, prec int64) BigDec { + return BigDec{ + i.Mul(i, precisionMultiplier(prec)), + } +} + +// create a new BigDec from big integer assuming whole numbers +// CONTRACT: prec <= BigDecPrecision +func NewBigDecFromInt(i BigInt) BigDec { + return NewBigDecFromIntWithPrec(i, 0) +} + +// create a new BigDec from big integer with decimal place at prec +// CONTRACT: prec <= BigDecPrecision +func NewBigDecFromIntWithPrec(i BigInt, prec int64) BigDec { + return BigDec{ + new(big.Int).Mul(i.BigInt(), precisionMultiplier(prec)), + } +} + +func NewBigDecFromDecMulDec(a, b Dec) BigDec { + newBi := new(big.Int).Mul(a.BigIntMut(), b.BigIntMut()) + return BigDec{newBi} +} + +// create a decimal from an input decimal string. +// valid must come in the form: +// +// (-) whole integers (.) decimal integers +// +// examples of acceptable input include: +// +// -123.456 +// 456.7890 +// 345 +// -456789 +// +// NOTE - An error will return if more decimal places +// are provided in the string than the constant Precision. +// +// CONTRACT - This function does not mutate the input str. +func NewBigDecFromStr(str string) (BigDec, error) { + if len(str) == 0 { + return BigDec{}, ErrEmptyDecimalStr + } + + // first extract any negative symbol + neg := false + if str[0] == '-' { + neg = true + str = str[1:] + } + + if len(str) == 0 { + return BigDec{}, ErrEmptyDecimalStr + } + + strs := strings.Split(str, ".") + lenDecs := 0 + combinedStr := strs[0] + + if len(strs) == 2 { // has a decimal place + lenDecs = len(strs[1]) + if lenDecs == 0 || len(combinedStr) == 0 { + return BigDec{}, ErrInvalidDecimalLength + } + combinedStr += strs[1] + } else if len(strs) > 2 { + return BigDec{}, ErrInvalidDecimalStr + } + + if lenDecs > BigDecPrecision { + return BigDec{}, fmt.Errorf("invalid precision; max: %d, got: %d", BigDecPrecision, lenDecs) + } + + // add some extra zero's to correct to the Precision factor + zerosToAdd := BigDecPrecision - lenDecs + zeros := fmt.Sprintf(`%0`+strconv.Itoa(zerosToAdd)+`s`, "") + combinedStr += zeros + + combined, ok := new(big.Int).SetString(combinedStr, 10) // base 10 + if !ok { + return BigDec{}, fmt.Errorf("failed to set decimal string: %s", combinedStr) + } + if combined.BitLen() > maxBitLen { + return BigDec{}, fmt.Errorf("decimal out of range; bitLen: got %d, max %d", combined.BitLen(), maxBitLen) + } + if neg { + combined = new(big.Int).Neg(combined) + } + + return BigDec{combined}, nil +} + +// Decimal from string, panic on error +func MustNewBigDecFromStr(s string) BigDec { + dec, err := NewBigDecFromStr(s) + if err != nil { + panic(err) + } + return dec +} + +func (d BigDec) IsNil() bool { return d.i == nil } // is decimal nil +func (d BigDec) IsZero() bool { return (d.i).Sign() == 0 } // is equal to zero +func (d BigDec) IsNegative() bool { return (d.i).Sign() == -1 } // is negative +func (d BigDec) IsPositive() bool { return (d.i).Sign() == 1 } // is positive +func (d BigDec) Equal(d2 BigDec) bool { return (d.i).Cmp(d2.i) == 0 } // equal decimals +func (d BigDec) GT(d2 BigDec) bool { return (d.i).Cmp(d2.i) > 0 } // greater than +func (d BigDec) GTE(d2 BigDec) bool { return (d.i).Cmp(d2.i) >= 0 } // greater than or equal +func (d BigDec) LT(d2 BigDec) bool { return (d.i).Cmp(d2.i) < 0 } // less than +func (d BigDec) LTE(d2 BigDec) bool { return (d.i).Cmp(d2.i) <= 0 } // less than or equal +func (d BigDec) Neg() BigDec { return BigDec{new(big.Int).Neg(d.i)} } // reverse the decimal sign +// nolint: stylecheck +func (d BigDec) Abs() BigDec { return BigDec{new(big.Int).Abs(d.i)} } // absolute value +func (d BigDec) AbsMut() BigDec { d.i.Abs(d.i); return d } // absolute value + +// BigInt returns a copy of the underlying big.Int. +func (d BigDec) BigInt() *big.Int { + if d.IsNil() { + return nil + } + + cp := new(big.Int) + return cp.Set(d.i) +} + +// BigIntMut returns the pointer of the underlying big.Int. +func (d BigDec) BigIntMut() *big.Int { + if d.IsNil() { + return nil + } + + return d.i +} + +// addition +func (d BigDec) Add(d2 BigDec) BigDec { + copy := d.Clone() + copy.AddMut(d2) + return copy +} + +// mutative addition +func (d BigDec) AddMut(d2 BigDec) BigDec { + d.i.Add(d.i, d2.i) + + assertMaxBitLen(d.i) + + return d +} + +// subtraction +func (d BigDec) Sub(d2 BigDec) BigDec { + copy := d.Clone() + copy.SubMut(d2) + return copy +} + +func (d BigDec) SubMut(d2 BigDec) BigDec { + res := d.i.Sub(d.i, d2.i) + assertMaxBitLen(res) + return BigDec{res} +} + +func (d BigDec) NegMut() BigDec { + d.i.Neg(d.i) + return d +} // reverse the decimal sign + +// Clone performs a deep copy of the receiver +// and returns the new result. +func (d BigDec) Clone() BigDec { + copy := BigDec{new(big.Int)} + copy.i.Set(d.i) + return copy +} + +// Mut performs non-mutative multiplication. +// The receiver is not modifier but the result is. +func (d BigDec) Mul(d2 BigDec) BigDec { + copy := d.Clone() + copy.MulMut(d2) + return copy +} + +// Mut performs non-mutative multiplication. +// The receiver is not modifier but the result is. +func (d BigDec) MulMut(d2 BigDec) BigDec { + d.i.Mul(d.i, d2.i) + d.i = chopPrecisionAndRound(d.i) + + assertMaxBitLen(d.i) + return BigDec{d.i} +} + +func (d BigDec) MulDec(d2 Dec) BigDec { + copy := d.Clone() + copy.MulDecMut(d2) + return copy +} + +func (d BigDec) MulDecMut(d2 Dec) BigDec { + d.i.Mul(d.i, d2.BigIntMut()) + d.i = chopPrecisionAndRoundSdkDec(d.i) + + assertMaxBitLen(d.i) + return BigDec{d.i} +} + +// multiplication truncate +func (d BigDec) MulTruncate(d2 BigDec) BigDec { + mul := new(big.Int).Mul(d.i, d2.i) + chopped := chopPrecisionAndTruncateMut(mul, defaultBigDecPrecisionReuse) + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +func (d BigDec) MulTruncateDec(d2 Dec) BigDec { + mul := new(big.Int).Mul(d.i, d2.BigIntMut()) + chopped := chopPrecisionAndTruncateMut(mul, precisionReuseSDKDec) + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +// multiplication round up +func (d BigDec) MulRoundUp(d2 BigDec) BigDec { + mul := new(big.Int).Mul(d.i, d2.i) + chopped := chopPrecisionAndRoundUpMut(mul, defaultBigDecPrecisionReuse) + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +// multiplication round up by Dec +func (d BigDec) MulRoundUpDec(d2 Dec) BigDec { + mul := new(big.Int).Mul(d.i, d2.BigIntMut()) + chopped := chopPrecisionAndRoundUpMut(mul, precisionReuseSDKDec) + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +// multiplication +func (d BigDec) MulInt(i BigInt) BigDec { + mul := new(big.Int).Mul(d.i, i.i) + assertMaxBitLen(mul) + return BigDec{mul} +} + +// MulInt64 - multiplication with int64 +func (d BigDec) MulInt64(i int64) BigDec { + bi := big.NewInt(i) + mul := bi.Mul(d.i, bi) + assertMaxBitLen(mul) + return BigDec{mul} +} + +// quotient +func (d BigDec) Quo(d2 BigDec) BigDec { + copy := d.Clone() + copy.QuoMut(d2) + return copy +} + +// mutative quotient +func (d BigDec) QuoMut(d2 BigDec) BigDec { + // multiply precision twice + // TODO: Use lower overhead thing here + d.i.Mul(d.i, squaredPrecisionReuse) + + d.i.Quo(d.i, d2.i) + chopPrecisionAndRound(d.i) + + assertMaxBitLen(d.i) + return d +} + +func (d BigDec) QuoRaw(d2 int64) BigDec { + // multiply precision, so we can chop it later + // TODO: There is certainly more efficient ways to do this, come back later + mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) + + quo := mul.Quo(mul, big.NewInt(d2)) + chopped := chopPrecisionAndRound(quo) + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +// quotient truncate +func (d BigDec) QuoTruncate(d2 BigDec) BigDec { + mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) + quo := mul.Quo(mul, d2.i) + assertMaxBitLen(quo) + return BigDec{quo} +} + +// quotient truncate (mutative) +func (d BigDec) QuoTruncateMut(d2 BigDec) BigDec { + // multiply bigDec precision + d.i.Mul(d.i, defaultBigDecPrecisionReuse) + d.i.Quo(d.i, d2.i) + assertMaxBitLen(d.i) + return d +} + +// quotient truncate +func (d BigDec) QuoTruncateDec(d2 Dec) BigDec { + // multiply Dec Precision + mul := new(big.Int).Mul(d.i, precisionReuseSDKDec) + quo := mul.Quo(mul, d2.BigIntMut()) + assertMaxBitLen(quo) + return BigDec{quo} +} + +// quotient truncate (mutative) +func (d BigDec) QuoTruncateDecMut(d2 Dec) BigDec { + // multiply Dec Precision + d.i.Mul(d.i, precisionReuseSDKDec) + d.i.Quo(d.i, d2.BigIntMut()) + + assertMaxBitLen(d.i) + return d +} + +// quotient, round up +func (d BigDec) QuoRoundUp(d2 BigDec) BigDec { + mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) + + chopped, rem := mul.QuoRem(mul, d2.i, new(big.Int)) + if rem.Sign() > 0 { + chopped.Add(chopped, oneInt) + } + + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +// quotient, round up +func (d BigDec) QuoByDecRoundUp(d2 Dec) BigDec { + mul := new(big.Int).Mul(d.i, precisionReuseSDKDec) + + chopped, rem := mul.QuoRem(mul, d2.BigIntMut(), new(big.Int)) + if rem.Sign() > 0 { + chopped.Add(chopped, oneInt) + } + + assertMaxBitLen(chopped) + return BigDec{chopped} +} + +// quotient, round up (mutative) +func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { + d.i.Mul(d.i, defaultBigDecPrecisionReuse) + _, rem := d.i.QuoRem(d.i, d2.i, new(big.Int)) + + d.i = incBasedOnRem(rem, d.i) + assertMaxBitLen(d.i) + return BigDec{d.i} +} + +// quotient, round up to next integer (mutative) +func (d BigDec) QuoRoundUpNextIntMut(d2 BigDec) BigDec { + _, rem := d.i.QuoRem(d.i, d2.i, new(big.Int)) + + d.i = incBasedOnRem(rem, d.i) + d.i.Mul(d.i, defaultBigDecPrecisionReuse) + assertMaxBitLen(d.i) + return BigDec{d.i} +} + +// quotient +func (d BigDec) QuoInt(i BigInt) BigDec { + mul := new(big.Int).Quo(d.i, i.i) + return BigDec{mul} +} + +// QuoInt64 - quotient with int64 +func (d BigDec) QuoInt64(i int64) BigDec { + mul := new(big.Int).Quo(d.i, big.NewInt(i)) + return BigDec{mul} +} + +// ApproxRoot returns an approximate estimation of a Dec's positive real nth root +// using Newton's method (where n is positive). The algorithm starts with some guess and +// computes the sequence of improved guesses until an answer converges to an +// approximate answer. It returns `|d|.ApproxRoot() * -1` if input is negative. +// A maximum number of 100 iterations is used a backup boundary condition for +// cases where the answer never converges enough to satisfy the main condition. +func (d BigDec) ApproxRoot(root uint64) (guess BigDec, err error) { + defer func() { + if r := recover(); r != nil { + var ok bool + err, ok = r.(error) + if !ok { + err = errors.New("out of bounds") + } + } + }() + + if d.IsNegative() { + absRoot, err := d.MulInt64(-1).ApproxRoot(root) + return absRoot.MulInt64(-1), err + } + + if root == 1 || d.IsZero() || d.Equal(oneBigDec) { + return d, nil + } + + if root == 0 { + return OneBigDec(), nil + } + + rootInt := NewBigIntFromUint64(root) + guess, delta := OneBigDec(), OneBigDec() + + for iter := 0; delta.Abs().GT(SmallestBigDec()) && iter < maxApproxRootIterations; iter++ { + prev := guess.PowerInteger(root - 1) + if prev.IsZero() { + prev = SmallestBigDec() + } + delta = d.Quo(prev) + delta.SubMut(guess) + delta = delta.QuoInt(rootInt) + + guess = guess.Add(delta) + } + + return guess, nil +} + +func assertMaxBitLen(i *big.Int) { + if i.BitLen() > maxDecBitLen { + panic("Int overflow") + } +} + +// ApproxSqrt is a wrapper around ApproxRoot for the common special case +// of finding the square root of a number. It returns -(sqrt(abs(d)) if input is negative. +// TODO: Optimize this to be faster just using native big int sqrt. +func (d BigDec) ApproxSqrt() (BigDec, error) { + return d.ApproxRoot(2) +} + +// is integer, e.g. decimals are zero +func (d BigDec) IsInteger() bool { + return new(big.Int).Rem(d.i, defaultBigDecPrecisionReuse).Sign() == 0 +} + +// format decimal state +func (d BigDec) Format(s fmt.State, verb rune) { + _, err := s.Write([]byte(d.String())) + if err != nil { + panic(err) + } +} + +// String returns a BigDec as a string. +func (d BigDec) String() string { + if d.i == nil { + return d.i.String() + } + + isNeg := d.IsNegative() + + if isNeg { + d = d.Neg() + } + + bzInt, err := d.i.MarshalText() + if err != nil { + return "" + } + inputSize := len(bzInt) + + var bzStr []byte + + // TODO: Remove trailing zeros + // case 1, purely decimal + if inputSize <= BigDecPrecision { + bzStr = make([]byte, BigDecPrecision+2) + + // 0. prefix + bzStr[0] = byte('0') + bzStr[1] = byte('.') + + // set relevant digits to 0 + for i := 0; i < BigDecPrecision-inputSize; i++ { + bzStr[i+2] = byte('0') + } + + // set final digits + copy(bzStr[2+(BigDecPrecision-inputSize):], bzInt) + } else { + // inputSize + 1 to account for the decimal point that is being added + bzStr = make([]byte, inputSize+1) + decPointPlace := inputSize - BigDecPrecision + + copy(bzStr, bzInt[:decPointPlace]) // pre-decimal digits + bzStr[decPointPlace] = byte('.') // decimal point + copy(bzStr[decPointPlace+1:], bzInt[decPointPlace:]) // post-decimal digits + } + + if isNeg { + return "-" + string(bzStr) + } + + return string(bzStr) +} + +// Float64 returns the float64 representation of a BigDec. +// Will return the error if the conversion failed. +func (d BigDec) Float64() (float64, error) { + return strconv.ParseFloat(d.String(), 64) +} + +// MustFloat64 returns the float64 representation of a BigDec. +// Would panic if the conversion failed. +func (d BigDec) MustFloat64() float64 { + if value, err := strconv.ParseFloat(d.String(), 64); err != nil { + panic(err) + } else { + return value + } +} + +// Dec returns the osmomath.Dec representation of a BigDec. +// Values in any additional decimal places are truncated. +func (d BigDec) Dec() Dec { + dec := math.LegacyNewDec(0) + decBi := dec.BigIntMut() + decBi.Quo(d.i, bigDecDecPrecisionFactorDiff) + return dec +} + +// DecWithPrecision converts BigDec to Dec with desired precision +// Example: +// BigDec: 1.010100000000153000000000000000000000 +// precision: 4 +// Output Dec: 1.010100000000000000 +// Panics if precision exceeds DecPrecision +func (d BigDec) DecWithPrecision(precision uint64) Dec { + var precisionFactor *big.Int + if precision > DecPrecision { + panic(fmt.Sprintf("maximum Dec precision is (%v), provided (%v)", DecPrecision, precision)) + } else { + precisionFactor = precisionFactors[precision] + } + + // Truncate any additional decimal values that exist due to BigDec's additional precision + // This relies on big.Int's Quo function doing floor division + intRepresentation := new(big.Int).Quo(d.BigIntMut(), precisionFactor) + + // convert int representation back to SDK Dec precision + truncatedDec := NewDecFromBigIntWithPrec(intRepresentation, int64(precision)) + + return truncatedDec +} + +// ChopPrecisionMut truncates all decimals after precision numbers after decimal point. Mutative +// CONTRACT: precision <= BigDecPrecision +// Panics if precision exceeds BigDecPrecision +func (d *BigDec) ChopPrecisionMut(precision uint64) BigDec { + if precision > BigDecPrecision { + panic(fmt.Sprintf("maximum BigDec precision is (%v), provided (%v)", DecPrecision, precision)) + } + + precisionFactor := precisionFactors[precision] + // big.Quo truncates numbers that would have been after decimal point + d.i.Quo(d.i, precisionFactor) + d.i.Mul(d.i, precisionFactor) + return BigDec{d.i} +} + +// ChopPrecision truncates all decimals after precision numbers after decimal point +// CONTRACT: precision <= BigDecPrecision +// Panics if precision exceeds BigDecPrecision +func (d *BigDec) ChopPrecision(precision uint64) BigDec { + copy := d.Clone() + return copy.ChopPrecisionMut(precision) +} + +// DecRoundUp returns the osmomath.Dec representation of a BigDec. +// Round up at precision end. +// Values in any additional decimal places are truncated. +func (d BigDec) DecRoundUp() Dec { + dec := math.LegacyZeroDec() + decBi := dec.BigIntMut() + decBi, rem := decBi.QuoRem(d.i, bigDecDecPrecisionFactorDiff, big.NewInt(0)) + incBasedOnRem(rem, decBi) + return dec +} + +// BigDecFromDec returns the BigDec representation of an Dec. +// Values in any additional decimal places are truncated. +func BigDecFromDec(d Dec) BigDec { + return NewBigDecFromBigIntMutWithPrec(d.BigInt(), DecPrecision) +} + +// BigDecFromDec returns the BigDec representation of an Dec. +// Values in any additional decimal places are truncated. +func BigDecFromDecMut(d Dec) BigDec { + return NewBigDecFromBigIntMutWithPrec(d.BigIntMut(), DecPrecision) +} + +// BigDecFromSDKInt returns the BigDec representation of an sdkInt. +// Values in any additional decimal places are truncated. +func BigDecFromSDKInt(i Int) BigDec { + return NewBigDecFromBigIntWithPrec(i.BigIntMut(), 0) +} + +// BigDecFromDecSlice returns the []BigDec representation of an []Dec. +// Values in any additional decimal places are truncated. +func BigDecFromDecSlice(ds []Dec) []BigDec { + result := make([]BigDec, len(ds)) + for i, d := range ds { + result[i] = NewBigDecFromBigIntMutWithPrec(d.BigInt(), DecPrecision) + } + return result +} + +// BigDecFromDecSlice returns the []BigDec representation of an []Dec. +// Values in any additional decimal places are truncated. +func BigDecFromDecCoinSlice(ds []sdk.DecCoin) []BigDec { + result := make([]BigDec, len(ds)) + for i, d := range ds { + result[i] = NewBigDecFromBigIntMutWithPrec(d.Amount.BigInt(), DecPrecision) + } + return result +} + +// ____ +// __| |__ "chop 'em +// ` \ round!" +// ___|| ~ _ -bankers +// | | __ +// | | | __|__|__ +// |_____: / | $$$ | +// |________| + +// Remove a Precision amount of rightmost digits and perform bankers rounding +// on the remainder (gaussian rounding) on the digits which have been removed. +// +// Mutates the input. Use the non-mutative version if that is undesired +func chopPrecisionAndRound(d *big.Int) *big.Int { + // remove the negative and add it back when returning + if d.Sign() == -1 { + // make d positive, compute chopped value, and then un-mutate d + d = d.Neg(d) + d = chopPrecisionAndRound(d) + d = d.Neg(d) + return d + } + + // get the truncated quotient and remainder + quo, rem := d, big.NewInt(0) + quo, rem = quo.QuoRem(d, defaultBigDecPrecisionReuse, rem) + + if rem.Sign() == 0 { // remainder is zero + return quo + } + + switch rem.Cmp(fivePrecision) { + case -1: + return quo + case 1: + return quo.Add(quo, oneInt) + default: // bankers rounding must take place + // always round to an even number + if quo.Bit(0) == 0 { + return quo + } + return quo.Add(quo, oneInt) + } +} + +// TODO: Abstract code +func chopPrecisionAndRoundSdkDec(d *big.Int) *big.Int { + // remove the negative and add it back when returning + if d.Sign() == -1 { + // make d positive, compute chopped value, and then un-mutate d + d = d.Neg(d) + d = chopPrecisionAndRoundSdkDec(d) + d = d.Neg(d) + return d + } + + // get the truncated quotient and remainder + quo, rem := d, big.NewInt(0) + quo, rem = quo.QuoRem(d, precisionReuseSDKDec, rem) + + if rem.Sign() == 0 { // remainder is zero + return quo + } + + switch rem.Cmp(fivePrecisionSDKDec) { + case -1: + return quo + case 1: + return quo.Add(quo, oneInt) + default: // bankers rounding must take place + // always round to an even number + if quo.Bit(0) == 0 { + return quo + } + return quo.Add(quo, oneInt) + } +} + +// chopPrecisionAndRoundUpDec removes DecPrecision amount of rightmost digits and rounds up. +// Non-mutative. +// +//nolint:unused +func chopPrecisionAndRoundUpDec(d *big.Int) *big.Int { + copy := new(big.Int).Set(d) + return chopPrecisionAndRoundUpMut(copy, precisionReuseSDKDec) +} + +func incBasedOnRem(rem *big.Int, d *big.Int) *big.Int { + if rem.Sign() == 0 { + return d + } + return d.Add(d, oneInt) +} + +// chopPrecisionAndRoundUp removes a Precision amount of rightmost digits and rounds up. +// Mutates input d. +// Mutations occur: +// - By calling chopPrecisionAndTruncateMut. +// - Using input d directly in QuoRem. +func chopPrecisionAndRoundUpMut(d *big.Int, precisionReuse *big.Int) *big.Int { + // remove the negative and add it back when returning + if d.Sign() == -1 { + // make d positive, compute chopped value, and then un-mutate d + d = d.Neg(d) + // truncate since d is negative... + d = chopPrecisionAndTruncateMut(d, precisionReuse) + d = d.Neg(d) + return d + } + + // get the truncated quotient and remainder + _, rem := d.QuoRem(d, precisionReuse, big.NewInt(0)) + return incBasedOnRem(rem, d) +} + +func chopPrecisionAndRoundNonMutative(d *big.Int) *big.Int { + tmp := new(big.Int).Set(d) + return chopPrecisionAndRound(tmp) +} + +// RoundInt64 rounds the decimal using bankers rounding +func (d BigDec) RoundInt64() int64 { + chopped := chopPrecisionAndRoundNonMutative(d.i) + if !chopped.IsInt64() { + panic("Int64() out of bound") + } + return chopped.Int64() +} + +// RoundInt round the decimal using bankers rounding +func (d BigDec) RoundInt() BigInt { + return NewBigIntFromBigInt(chopPrecisionAndRoundNonMutative(d.i)) +} + +// chopPrecisionAndTruncate is similar to chopPrecisionAndRound, +// but always rounds down. It does not mutate the input. +func chopPrecisionAndTruncate(d *big.Int, precisionReuse *big.Int) *big.Int { + return new(big.Int).Quo(d, precisionReuse) +} + +// chopPrecisionAndTruncate is similar to chopPrecisionAndRound, +// but always rounds down. It mutates the input. +func chopPrecisionAndTruncateMut(d, precisionReuse *big.Int) *big.Int { + return d.Quo(d, precisionReuse) +} + +// TruncateInt64 truncates the decimals from the number and returns an int64 +func (d BigDec) TruncateInt64() int64 { + chopped := chopPrecisionAndTruncate(d.i, defaultBigDecPrecisionReuse) + if !chopped.IsInt64() { + panic("Int64() out of bound") + } + return chopped.Int64() +} + +// TruncateInt truncates the decimals from the number and returns an Int +func (d BigDec) TruncateInt() BigInt { + return NewBigIntFromBigInt(chopPrecisionAndTruncate(d.i, defaultBigDecPrecisionReuse)) +} + +// TruncateDec truncates the decimals from the number and returns a Dec +func (d BigDec) TruncateDec() BigDec { + return NewBigDecFromBigInt(chopPrecisionAndTruncate(d.i, defaultBigDecPrecisionReuse)) +} + +// Ceil returns the smallest integer value (as a decimal) that is greater than +// or equal to the given decimal. +func (d BigDec) Ceil() BigDec { + tmp := new(big.Int).Set(d.i) + return BigDec{i: tmp}.CeilMut() +} + +func (d BigDec) CeilMut() BigDec { + quo, rem := d.i, big.NewInt(0) + quo, rem = quo.QuoRem(quo, defaultBigDecPrecisionReuse, rem) + + // no need to round with a zero remainder regardless of sign + if rem.Sign() <= 0 { + return NewBigDecFromBigIntMut(quo) + } + + return NewBigDecFromBigIntMut(quo.Add(quo, oneInt)) +} + +// reuse nil values +var nilJSON []byte + +func init() { + empty := new(big.Int) + bz, _ := empty.MarshalText() + nilJSON, _ = json.Marshal(string(bz)) +} + +// MarshalJSON marshals the decimal +func (d BigDec) MarshalJSON() ([]byte, error) { + if d.i == nil { + return nilJSON, nil + } + return json.Marshal(d.String()) +} + +// UnmarshalJSON defines custom decoding scheme +func (d *BigDec) UnmarshalJSON(bz []byte) error { + if d.i == nil { + d.i = new(big.Int) + } + + var text string + err := json.Unmarshal(bz, &text) + if err != nil { + return err + } + + // TODO: Reuse dec allocation + newDec, err := NewBigDecFromStr(text) + if err != nil { + return err + } + + d.i = newDec.i + return nil +} + +// MarshalYAML returns the YAML representation. +func (d BigDec) MarshalYAML() (interface{}, error) { + return d.String(), nil +} + +// Marshal implements the gogo proto custom type interface. +func (d BigDec) Marshal() ([]byte, error) { + if d.i == nil { + d.i = new(big.Int) + } + return d.i.MarshalText() +} + +// MarshalTo implements the gogo proto custom type interface. +func (d *BigDec) MarshalTo(data []byte) (n int, err error) { + if d.i == nil { + d.i = new(big.Int) + } + + if d.i.Sign() == 0 { + copy(data, []byte{0x30}) + return 1, nil + } + + bz, err := d.Marshal() + if err != nil { + return 0, err + } + + copy(data, bz) + return len(bz), nil +} + +// Unmarshal implements the gogo proto custom type interface. +func (d *BigDec) Unmarshal(data []byte) error { + if len(data) == 0 { + d = nil + return nil + } + + if d.i == nil { + d.i = new(big.Int) + } + + if err := d.i.UnmarshalText(data); err != nil { + return err + } + + if d.i.BitLen() > maxBitLen { + return fmt.Errorf("decimal out of range; got: %d, max: %d", d.i.BitLen(), maxBitLen) + } + + return nil +} + +// Size implements the gogo proto custom type interface. +func (d *BigDec) Size() int { + bz, _ := d.Marshal() + return len(bz) +} + +// Override Amino binary serialization by proxying to protobuf. +func (d BigDec) MarshalAmino() ([]byte, error) { return d.Marshal() } +func (d *BigDec) UnmarshalAmino(bz []byte) error { return d.Unmarshal(bz) } + +// helpers + +// DecsEqual tests if two decimal arrays are equal +func DecsEqual(d1s, d2s []BigDec) bool { + if len(d1s) != len(d2s) { + return false + } + + for i, d1 := range d1s { + if !d1.Equal(d2s[i]) { + return false + } + } + return true +} + +// MinBigDec gets minimum decimal between two +func MinBigDec(d1, d2 BigDec) BigDec { + if d1.LT(d2) { + return d1 + } + return d2 +} + +// MaxBigDec gets maximum decimal between two +func MaxBigDec(d1, d2 BigDec) BigDec { + if d1.LT(d2) { + return d2 + } + return d1 +} + +// DecEq returns true if two given decimals are equal. +// Intended to be used with require/assert: require.True(t, DecEq(...)) +// +//nolint:thelper +func DecEq(t *testing.T, exp, got BigDec) (*testing.T, bool, string, string, string) { + return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() +} + +// DecApproxEq returns true if the differences between two given decimals are smaller than the tolerance range. +// Intended to be used with require/assert: require.True(t, DecEq(...)) +// +//nolint:thelper +func DecApproxEq(t *testing.T, d1 BigDec, d2 BigDec, tol BigDec) (*testing.T, bool, string, string, string) { + diff := d1.Sub(d2).Abs() + return t, diff.LTE(tol), "expected |d1 - d2| <:\t%v\ngot |d1 - d2| = \t\t%v", tol.String(), diff.String() +} + +// LogBase2 returns log_2 {x}. +// Rounds down by truncations during division and right shifting. +// Accurate up to 32 precision digits. +// Implementation is based on: +// https://stm32duinoforum.com/forum/dsp/BinaryLogarithm.pdf +func (x BigDec) LogBase2() BigDec { + // create a new decimal to avoid mutating + // the receiver's int buffer. + xCopy := BigDec{} + xCopy.i = new(big.Int).Set(x.i) + if xCopy.LTE(zeroBigDec) { + panic(fmt.Sprintf("log is not defined at <= 0, given (%s)", xCopy)) + } + + // Normalize x to be 1 <= x < 2. + + // y is the exponent that results in a whole multiple of 2. + y := ZeroBigDec() + + // repeat until: x >= 1. + for xCopy.LT(oneBigDec) { + xCopy.i.Lsh(xCopy.i, 1) + y.AddMut(negOneBigDec) + } + + // repeat until: x < 2. + for xCopy.GTE(twoBigDec) { + xCopy.i.Rsh(xCopy.i, 1) + y.AddMut(oneBigDec) + } + + b := oneHalfBigDec.Clone() + + // N.B. At this point x is a positive real number representing + // mantissa of the log. We estimate it using the following + // algorithm: + // https://stm32duinoforum.com/forum/dsp/BinaryLogarithm.pdf + // This has shown precision of 32 digits relative + // to Wolfram Alpha in tests. + for i := 0; i < maxLog2Iterations; i++ { + xCopy.MulMut(xCopy) + if xCopy.GTE(twoBigDec) { + xCopy.i.Rsh(xCopy.i, 1) + y.AddMut(b) + } + b.i.Rsh(b.i, 1) + } + + return y +} + +// Natural logarithm of x. +// Formula: ln(x) = log_2(x) / log_2(e) +func (x BigDec) Ln() BigDec { + log2x := x.LogBase2() + + y := log2x.Quo(logOfEbase2) + + return y +} + +// log_1.0001(x) "tick" base logarithm +// Formula: log_1.0001(b) = log_2(b) / log_2(1.0001) +func (x BigDec) TickLog() BigDec { + log2x := x.LogBase2() + + y := log2x.Quo(tickLogOf2) + + return y +} + +// log_a(x) custom base logarithm +// Formula: log_a(b) = log_2(b) / log_2(a) +func (x BigDec) CustomBaseLog(base BigDec) BigDec { + if base.LTE(ZeroBigDec()) || base.Equal(OneBigDec()) { + panic(fmt.Sprintf("log is not defined at base <= 0 or base == 1, base given (%s)", base)) + } + + log2x_argument := x.LogBase2() + log2x_base := base.LogBase2() + + y := log2x_argument.Quo(log2x_base) + + return y +} + +// PowerInteger takes a given decimal to an integer power +// and returns the result. Non-mutative. Uses square and multiply +// algorithm for performing the calculation. +func (d BigDec) PowerInteger(power uint64) BigDec { + clone := d.Clone() + return clone.PowerIntegerMut(power) +} + +// PowerIntegerMut takes a given decimal to an integer power +// and returns the result. Mutative. Uses square and multiply +// algorithm for performing the calculation. +func (d BigDec) PowerIntegerMut(power uint64) BigDec { + if power == 0 { + return OneBigDec() + } else if power == 1 { + return d + } else if power == 2 { + // save a oneBigDec allocation + return d.MulMut(d) + } + tmp := OneBigDec() + + for i := power; i > 1; { + if i%2 != 0 { + tmp = tmp.MulMut(d) + } + i /= 2 + d = d.MulMut(d) + } + + return d.MulMut(tmp) +} + +// Power returns a result of raising the given big dec to +// a positive decimal power. Panics if the power is negative. +// Panics if the base is negative. Does not mutate the receiver. +// The max supported exponent is defined by the global maxSupportedExponent. +// If a greater exponent is given, the function panics. +// The error is not bounded but expected to be around 10^-18, use with care. +// See the underlying Exp2, LogBase2 and Mul for the details of their bounds. +// WARNING: This function is broken for base < 1. The reason is that logarithm function is +// negative between zero and 1, and the Exp2(k) is undefined for negative k. +// As a result, this function panics if called for d < 1. +func (d BigDec) Power(power BigDec) BigDec { + if d.IsNegative() { + panic(fmt.Sprintf("negative base is not supported for Power(), base was (%s)", d)) + } + if power.IsNegative() { + panic(fmt.Sprintf("negative power is not supported for Power(), power was (%s)", power)) + } + if power.Abs().GT(maxSupportedExponent) { + panic(fmt.Sprintf("integer exponent %s is too large, max (%s)", power, maxSupportedExponent)) + } + // TODO: Potentially expensive?? + if power.IsInteger() { + return d.PowerInteger(power.TruncateInt().Uint64()) + } + if power.IsZero() { + return OneBigDec() + } + if d.IsZero() { + return ZeroBigDec() + } + if d.LT(oneBigDec) { + panic(fmt.Sprintf("Power() is not supported for base < 1, base was (%s)", d)) + } + if d.Equal(twoBigDec) { + return Exp2(power) + } + + // d^power = exp2(power * log_2{base}) + result := Exp2(d.LogBase2().Mul(power)) + + return result +} diff --git a/x/icqoracle/deps/osmomath/exp2.go b/x/icqoracle/deps/osmomath/exp2.go new file mode 100644 index 0000000000..d9b43313f2 --- /dev/null +++ b/x/icqoracle/deps/osmomath/exp2.go @@ -0,0 +1,102 @@ +// Forked from https://github.com/osmosis-labs/osmosis/blob/v27.0.0/osmomath/exp2.go under the Apache v2.0 License +package osmomath + +import "fmt" + +var ( + // Truncated at precision end. + // See scripts/approximations/main.py exponent_approximation_choice function for details. + numeratorCoefficients13Param = []BigDec{ + MustNewBigDecFromStr("1.000000000000000000000044212244679434"), + MustNewBigDecFromStr("0.352032455817400196452603772766844426"), + MustNewBigDecFromStr("0.056507868883666405413116800969512484"), + MustNewBigDecFromStr("0.005343900728213034434757419480319916"), + MustNewBigDecFromStr("0.000317708814342353603087543715930732"), + MustNewBigDecFromStr("0.000011429747507407623028722262874632"), + MustNewBigDecFromStr("0.000000198381965651614980168744540366"), + } + + // Rounded up at precision end. + // See scripts/approximations/main.py exponent_approximation_choice function for details. + denominatorCoefficients13Param = []BigDec{ + OneBigDec(), + MustNewBigDecFromStr("0.341114724742545112949699755780593311").Neg(), + MustNewBigDecFromStr("0.052724071627342653404436933178482287"), + MustNewBigDecFromStr("0.004760950735524957576233524801866342").Neg(), + MustNewBigDecFromStr("0.000267168475410566529819971616894193"), + MustNewBigDecFromStr("0.000008923715368802211181557353097439").Neg(), + MustNewBigDecFromStr("0.000000140277233177373698516010555916"), + } + + // maxSupportedExponent = 2^10. The value is chosen by benchmarking + // when the underlying internal functions overflow. + // If needed in the future, Exp2 can be reimplemented to allow for greater exponents. + maxSupportedExponent = MustNewBigDecFromStr("2").PowerInteger(9) +) + +// Exp2 takes 2 to the power of a given non-negative decimal exponent +// and returns the result. +// The computation is performed by using th following property: +// 2^decimal_exp = 2^{integer_exp + fractional_exp} = 2^integer_exp * 2^fractional_exp +// The max supported exponent is defined by the global maxSupportedExponent. +// If a greater exponent is given, the function panics. +// Panics if the exponent is negative. +// The answer is correct up to a factor of 10^-18. +// Meaning, result = result * k for k in [1 - 10^(-18), 1 + 10^(-18)] +// Note: our Python script plots show accuracy up to a factor of 10^22. +// However, in Go tests we only test up to 10^18. Therefore, this is the guarantee. +func Exp2(exponent BigDec) BigDec { + if exponent.IsNegative() { + panic(fmt.Sprintf("negative exponent %s is not supported", exponent)) + } + if exponent.Abs().GT(maxSupportedExponent) { + panic(fmt.Sprintf("integer exponent %s is too large, max (%s)", exponent, maxSupportedExponent)) + } + + integerExponent := exponent.TruncateDec() + + fractionalExponent := exponent.Sub(integerExponent) + fractionalResult := exp2ChebyshevRationalApprox(fractionalExponent) + + // Left bit shift is equivalent to multiplying by 2^integerExponent. + fractionalResult.i = fractionalResult.i.Lsh(fractionalResult.i, uint(integerExponent.TruncateInt().Uint64())) + + return fractionalResult +} + +// exp2ChebyshevRationalApprox takes 2 to the power of a given decimal exponent. +// The result is approximated by a 13 parameter Chebyshev rational approximation. +// f(x) = h(x) / p(x) (7, 7) terms. We set the first term of p(x) to 1. +// As a result, this ends up being 7 + 6 = 13 parameters. +// The numerator coefficients are truncated at precision end. The denominator +// coefficients are rounded up at precision end. +// See scripts/approximations/README.md for details of the scripts used +// to compute the coefficients. +// CONTRACT: exponent must be in the range [0, 1], panics if not. +// The answer is correct up to a factor of 10^-18. +// Meaning, result = result * k for k in [1 - 10^(-18), 1 + 10^(-18)] +// Note: our Python script plots show accuracy up to a factor of 10^22. +// However, in Go tests we only test up to 10^18. Therefore, this is the guarantee. +func exp2ChebyshevRationalApprox(x BigDec) BigDec { + if x.LT(ZeroBigDec()) || x.GT(OneBigDec()) { + panic(fmt.Sprintf("exponent must be in the range [0, 1], got %s", x)) + } + if x.IsZero() { + return OneBigDec() + } + if x.Equal(OneBigDec()) { + return twoBigDec + } + + h_x := numeratorCoefficients13Param[0].Clone() + p_x := denominatorCoefficients13Param[0].Clone() + x_exp_i := OneBigDec() + for i := 1; i < len(numeratorCoefficients13Param); i++ { + x_exp_i.MulMut(x) + + h_x.AddMut(numeratorCoefficients13Param[i].Mul(x_exp_i)) + p_x.AddMut(denominatorCoefficients13Param[i].Mul(x_exp_i)) + } + + return h_x.QuoMut(p_x) +} diff --git a/x/icqoracle/deps/osmomath/int.go b/x/icqoracle/deps/osmomath/int.go new file mode 100644 index 0000000000..93e0c6ab5c --- /dev/null +++ b/x/icqoracle/deps/osmomath/int.go @@ -0,0 +1,441 @@ +// Forked from https://github.com/osmosis-labs/osmosis/blob/v27.0.0/osmomath/int.go under the Apache v2.0 License +package osmomath + +import ( + "encoding" + "encoding/json" + "fmt" + "math/big" + "testing" +) + +const maxBitLen = 1024 + +func newIntegerFromString(s string) (*big.Int, bool) { + return new(big.Int).SetString(s, 0) +} + +func equal(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) == 0 } + +// Greater than +func gt(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) == 1 } + +// Greater than or equal to +func gte(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) >= 0 } + +// Less than +func lt(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) == -1 } + +// Less than or equal to +func lte(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) <= 0 } + +func add(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Add(i, i2) } + +func sub(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Sub(i, i2) } + +func mul(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mul(i, i2) } + +func div(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Quo(i, i2) } + +func mod(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mod(i, i2) } + +func neg(i *big.Int) *big.Int { return new(big.Int).Neg(i) } + +func abs(i *big.Int) *big.Int { return new(big.Int).Abs(i) } + +func min(i *big.Int, i2 *big.Int) *big.Int { + if i.Cmp(i2) == 1 { + return new(big.Int).Set(i2) + } + + return new(big.Int).Set(i) +} + +func max(i *big.Int, i2 *big.Int) *big.Int { + if i.Cmp(i2) == -1 { + return new(big.Int).Set(i2) + } + + return new(big.Int).Set(i) +} + +func unmarshalText(i *big.Int, text string) error { + if err := i.UnmarshalText([]byte(text)); err != nil { + return err + } + + if i.BitLen() > maxBitLen { + return fmt.Errorf("integer out of range: %s", text) + } + + return nil +} + +// Int wraps big.Int with a 257 bit range bound +// Checks overflow, underflow and division by zero +// Exists in range from -(2^256 - 1) to 2^256 - 1 +type BigInt struct { + i *big.Int +} + +// BigInt converts Int to big.Int +func (i BigInt) BigInt() *big.Int { + if i.IsNil() { + return nil + } + return new(big.Int).Set(i.i) +} + +// IsNil returns true if Int is uninitialized +func (i BigInt) IsNil() bool { + return i.i == nil +} + +// NewBigInt constructs Int from int64 +func NewBigInt(n int64) BigInt { + return BigInt{big.NewInt(n)} +} + +// NewBigIntFromUint64 constructs an Int from a uint64. +func NewBigIntFromUint64(n uint64) BigInt { + b := big.NewInt(0) + b.SetUint64(n) + return BigInt{b} +} + +// NewBigIntFromBigInt constructs Int from big.Int. If the provided big.Int is nil, +// it returns an empty instance. This function panics if the bit length is > 256. +func NewBigIntFromBigInt(i *big.Int) BigInt { + if i == nil { + return BigInt{} + } + + if i.BitLen() > maxBitLen { + panic("NewIntFromBigInt() out of bound") + } + return BigInt{i} +} + +// NewBigIntFromString constructs Int from string +func NewBigIntFromString(s string) (res BigInt, ok bool) { + i, ok := newIntegerFromString(s) + if !ok { + return + } + // Check overflow + if i.BitLen() > maxBitLen { + ok = false + return + } + return BigInt{i}, true +} + +// NewBigIntWithDecimal constructs Int with decimal +// Result value is n*10^dec +func NewBigIntWithDecimal(n int64, dec int) BigInt { + if dec < 0 { + panic("NewIntWithDecimal() decimal is negative") + } + exp := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(dec)), nil) + i := new(big.Int) + i.Mul(big.NewInt(n), exp) + + // Check overflow + if i.BitLen() > maxBitLen { + panic("NewIntWithDecimal() out of bound") + } + return BigInt{i} +} + +// ZeroBigInt returns Int value with zero +func ZeroBigInt() BigInt { return BigInt{big.NewInt(0)} } + +// OneBigInt returns Int value with one +func OneBigInt() BigInt { return BigInt{big.NewInt(1)} } + +// ToDec converts Int to Dec +func (i BigInt) ToDec() BigDec { + return NewBigDecFromInt(i) +} + +// Int64 converts Int to int64 +// Panics if the value is out of range +func (i BigInt) Int64() int64 { + if !i.i.IsInt64() { + panic("Int64() out of bound") + } + return i.i.Int64() +} + +// IsInt64 returns true if Int64() not panics +func (i BigInt) IsInt64() bool { + return i.i.IsInt64() +} + +// Uint64 converts Int to uint64 +// Panics if the value is out of range +func (i BigInt) Uint64() uint64 { + if !i.i.IsUint64() { + panic("Uint64() out of bounds") + } + return i.i.Uint64() +} + +// IsUint64 returns true if Uint64() not panics +func (i BigInt) IsUint64() bool { + return i.i.IsUint64() +} + +// IsZero returns true if Int is zero +func (i BigInt) IsZero() bool { + return i.i.Sign() == 0 +} + +// IsNegative returns true if Int is negative +func (i BigInt) IsNegative() bool { + return i.i.Sign() == -1 +} + +// IsPositive returns true if Int is positive +func (i BigInt) IsPositive() bool { + return i.i.Sign() == 1 +} + +// Sign returns sign of Int +func (i BigInt) Sign() int { + return i.i.Sign() +} + +// Equal compares two Ints +func (i BigInt) Equal(i2 BigInt) bool { + return equal(i.i, i2.i) +} + +// GT returns true if first Int is greater than second +func (i BigInt) GT(i2 BigInt) bool { + return gt(i.i, i2.i) +} + +// GTE returns true if receiver Int is greater than or equal to the parameter +// Int. +func (i BigInt) GTE(i2 BigInt) bool { + return gte(i.i, i2.i) +} + +// LT returns true if first Int is lesser than second +func (i BigInt) LT(i2 BigInt) bool { + return lt(i.i, i2.i) +} + +// LTE returns true if first Int is less than or equal to second +func (i BigInt) LTE(i2 BigInt) bool { + return lte(i.i, i2.i) +} + +// Add adds Int from another +func (i BigInt) Add(i2 BigInt) (res BigInt) { + res = BigInt{add(i.i, i2.i)} + // Check overflow + if res.i.BitLen() > maxBitLen { + panic("Int overflow") + } + return +} + +// AddRaw adds int64 to Int +func (i BigInt) AddRaw(i2 int64) BigInt { + return i.Add(NewBigInt(i2)) +} + +// Sub subtracts Int from another +func (i BigInt) Sub(i2 BigInt) (res BigInt) { + res = BigInt{sub(i.i, i2.i)} + // Check overflow + if res.i.BitLen() > maxBitLen { + panic("Int overflow") + } + return +} + +// SubRaw subtracts int64 from Int +func (i BigInt) SubRaw(i2 int64) BigInt { + return i.Sub(NewBigInt(i2)) +} + +// Mul multiples two Ints +func (i BigInt) Mul(i2 BigInt) (res BigInt) { + // Check overflow + if i.i.BitLen()+i2.i.BitLen()-1 > maxBitLen { + panic("Int overflow") + } + res = BigInt{mul(i.i, i2.i)} + // Check overflow if sign of both are same + if res.i.BitLen() > maxBitLen { + panic("Int overflow") + } + return +} + +// MulRaw multiplies Int and int64 +func (i BigInt) MulRaw(i2 int64) BigInt { + return i.Mul(NewBigInt(i2)) +} + +// Quo divides Int with Int +func (i BigInt) Quo(i2 BigInt) (res BigInt) { + // Check division-by-zero + if i2.i.Sign() == 0 { + panic("Division by zero") + } + return BigInt{div(i.i, i2.i)} +} + +// QuoRaw divides Int with int64 +func (i BigInt) QuoRaw(i2 int64) BigInt { + return i.Quo(NewBigInt(i2)) +} + +// Mod returns remainder after dividing with Int +func (i BigInt) Mod(i2 BigInt) BigInt { + if i2.Sign() == 0 { + panic("division-by-zero") + } + return BigInt{mod(i.i, i2.i)} +} + +// ModRaw returns remainder after dividing with int64 +func (i BigInt) ModRaw(i2 int64) BigInt { + return i.Mod(NewBigInt(i2)) +} + +// Neg negates Int +func (i BigInt) Neg() (res BigInt) { + return BigInt{neg(i.i)} +} + +// Abs returns the absolute value of Int. +func (i BigInt) Abs() BigInt { + return BigInt{abs(i.i)} +} + +// return the minimum of the ints +func MinBigInt(i1, i2 BigInt) BigInt { + return BigInt{min(i1.BigInt(), i2.BigInt())} +} + +// MaxBigInt returns the maximum between two integers. +func MaxBigInt(i, i2 BigInt) BigInt { + return BigInt{max(i.BigInt(), i2.BigInt())} +} + +// Human readable string +func (i BigInt) String() string { + return i.i.String() +} + +// MarshalJSON defines custom encoding scheme +func (i BigInt) MarshalJSON() ([]byte, error) { + if i.i == nil { // Necessary since default Uint initialization has i.i as nil + i.i = new(big.Int) + } + return marshalJSON(i.i) +} + +// UnmarshalJSON defines custom decoding scheme +func (i *BigInt) UnmarshalJSON(bz []byte) error { + if i.i == nil { // Necessary since default Int initialization has i.i as nil + i.i = new(big.Int) + } + return unmarshalJSON(i.i, bz) +} + +// MarshalJSON for custom encoding scheme +// Must be encoded as a string for JSON precision +func marshalJSON(i encoding.TextMarshaler) ([]byte, error) { + text, err := i.MarshalText() + if err != nil { + return nil, err + } + + return json.Marshal(string(text)) +} + +// UnmarshalJSON for custom decoding scheme +// Must be encoded as a string for JSON precision +func unmarshalJSON(i *big.Int, bz []byte) error { + var text string + if err := json.Unmarshal(bz, &text); err != nil { + return err + } + + return unmarshalText(i, text) +} + +// MarshalYAML returns the YAML representation. +func (i BigInt) MarshalYAML() (interface{}, error) { + return i.String(), nil +} + +// Marshal implements the gogo proto custom type interface. +func (i BigInt) Marshal() ([]byte, error) { + if i.i == nil { + i.i = new(big.Int) + } + return i.i.MarshalText() +} + +// MarshalTo implements the gogo proto custom type interface. +func (i *BigInt) MarshalTo(data []byte) (n int, err error) { + if i.i == nil { + i.i = new(big.Int) + } + if i.i.BitLen() == 0 { // The value 0 + copy(data, []byte{0x30}) + return 1, nil + } + + bz, err := i.Marshal() + if err != nil { + return 0, err + } + + copy(data, bz) + return len(bz), nil +} + +// Unmarshal implements the gogo proto custom type interface. +func (i *BigInt) Unmarshal(data []byte) error { + if len(data) == 0 { + i = nil + return nil + } + + if i.i == nil { + i.i = new(big.Int) + } + + if err := i.i.UnmarshalText(data); err != nil { + return err + } + + if i.i.BitLen() > maxBitLen { + return fmt.Errorf("integer out of range; got: %d, max: %d", i.i.BitLen(), maxBitLen) + } + + return nil +} + +// Size implements the gogo proto custom type interface. +func (i *BigInt) Size() int { + bz, _ := i.Marshal() + return len(bz) +} + +// Override Amino binary serialization by proxying to protobuf. +func (i BigInt) MarshalAmino() ([]byte, error) { return i.Marshal() } +func (i *BigInt) UnmarshalAmino(bz []byte) error { return i.Unmarshal(bz) } + +// intended to be used with require/assert: require.True(IntEq(...)) +func BigIntEq(t *testing.T, exp, got BigInt) (*testing.T, bool, string, string, string) { + return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() +} diff --git a/x/icqoracle/deps/osmomath/sdk_math_alias.go b/x/icqoracle/deps/osmomath/sdk_math_alias.go new file mode 100644 index 0000000000..accf9ec891 --- /dev/null +++ b/x/icqoracle/deps/osmomath/sdk_math_alias.go @@ -0,0 +1,56 @@ +// Forked from https://github.com/osmosis-labs/osmosis/blob/v27.0.0/osmomath/sdk_math_alias.go under the Apache v2.0 License +// This file creates type and function aliases the sdkmath.LegacyDec +// This is done for reducing verbosity and improving readability. +// +// For consistency, we also alias Int and Uint so that sdkmath does not have +// to be directly imported in files where both decimal and integer types are used. +package osmomath + +import ( + sdkmath "cosmossdk.io/math" +) + +type ( + Dec = sdkmath.LegacyDec + Int = sdkmath.Int + Uint = sdkmath.Uint +) + +const ( + DecPrecision = sdkmath.LegacyPrecision + DecimalPrecisionBits = sdkmath.LegacyDecimalPrecisionBits +) + +var ( + // Dec + NewDec = sdkmath.LegacyNewDec + NewDecWithPrec = sdkmath.LegacyNewDecWithPrec + NewDecFromBigInt = sdkmath.LegacyNewDecFromBigInt + NewDecFromBigIntWithPrec = sdkmath.LegacyNewDecFromBigIntWithPrec + NewDecFromInt = sdkmath.LegacyNewDecFromInt + NewDecFromIntWithPrec = sdkmath.LegacyNewDecFromIntWithPrec + NewDecFromStr = sdkmath.LegacyNewDecFromStr + MustNewDecFromStr = sdkmath.LegacyMustNewDecFromStr + ZeroDec = sdkmath.LegacyZeroDec + OneDec = sdkmath.LegacyOneDec + SmallestDec = sdkmath.LegacySmallestDec + + // Int + NewInt = sdkmath.NewInt + NewIntFromUint64 = sdkmath.NewIntFromUint64 + NewIntFromBigInt = sdkmath.NewIntFromBigInt + NewIntFromString = sdkmath.NewIntFromString + NewIntWithDecimal = sdkmath.NewIntWithDecimal + ZeroInt = sdkmath.ZeroInt + OneInt = sdkmath.OneInt + IntEq = sdkmath.IntEq + MinInt = sdkmath.MinInt + MaxInt = sdkmath.MaxInt + + // Uint + NewUint = sdkmath.NewUint + NewUintFromString = sdkmath.NewUintFromString + + MinDec = sdkmath.LegacyMinDec + MaxDec = sdkmath.LegacyMaxDec +) diff --git a/x/icqoracle/deps/types/osmosis_concentrated_liquidity_pool.go b/x/icqoracle/deps/types/osmosis_concentrated_liquidity_pool.go new file mode 100644 index 0000000000..a6a178466e --- /dev/null +++ b/x/icqoracle/deps/types/osmosis_concentrated_liquidity_pool.go @@ -0,0 +1,36 @@ +package types + +import ( + fmt "fmt" + + "cosmossdk.io/math" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/deps/osmomath" +) + +// SpotPrice returns the spot price of the pool. +// If base asset is the Token0 of the pool, we use the current sqrt price of the pool. +// If not, we calculate the inverse of the current sqrt price of the pool. +// +// Forked from https://github.com/osmosis-labs/osmosis/blob/v27.0.0/x/concentrated-liquidity/model/pool.go#L108-L129 under the Apache v2.0 License. +// Modified to return math.LegacyDec instead of osmomath.BigDec. +// Removed unused ctx param. +func (p OsmosisConcentratedLiquidityPool) SpotPrice(quoteAssetDenom string, baseAssetDenom string) (math.LegacyDec, error) { + // validate base asset is in pool + if baseAssetDenom != p.Token0 && baseAssetDenom != p.Token1 { + return math.LegacyDec{}, fmt.Errorf("base asset denom (%s) is not in pool with (%s, %s) pair", baseAssetDenom, p.Token0, p.Token1) + } + // validate quote asset is in pool + if quoteAssetDenom != p.Token0 && quoteAssetDenom != p.Token1 { + return math.LegacyDec{}, fmt.Errorf("quote asset denom (%s) is not in pool with (%s, %s) pair", quoteAssetDenom, p.Token0, p.Token1) + } + + priceSquared := p.CurrentSqrtPrice.PowerInteger(2) + // The reason why we convert the result to Dec and then back to BigDec is to temporarily + // maintain backwards compatibility with the original implementation. + // TODO: remove before https://github.com/osmosis-labs/osmosis/issues/5726 is complete + if baseAssetDenom == p.Token0 { + return priceSquared.Dec(), nil + } + return osmomath.OneBigDec().QuoMut(priceSquared).Dec(), nil +} diff --git a/x/icqoracle/deps/types/osmosis_concentrated_liquidity_pool.pb.go b/x/icqoracle/deps/types/osmosis_concentrated_liquidity_pool.pb.go new file mode 100644 index 0000000000..dc77cf7e26 --- /dev/null +++ b/x/icqoracle/deps/types/osmosis_concentrated_liquidity_pool.pb.go @@ -0,0 +1,842 @@ +// Forked from https://github.com/osmosis-labs/osmosis/blob/3941926d1ace180a689951f66b01a0ecc0603d93/x/concentrated-liquidity/model/pool.pb.go under the Apache v2.0 License +// Changes made: +// 1. Pointed import path of osmomath to Stride's forked version +// 2. Implemented `func (m *Pool) String() string` (difference in gogoproto version between Osmosis and Stride) +// 3. Renamed Pool -> OsmosisConcentratedLiquidityPool + +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: osmosis/concentratedliquidity/v1beta1/pool.proto + +// This is a legacy package that requires additional migration logic +// in order to use the correct package. Decision made to use legacy package path +// until clear steps for migration logic and the unknowns for state breaking are +// investigated for changing proto package. + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + "github.com/Stride-Labs/stride/v24/x/icqoracle/deps/osmomath" + _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type OsmosisConcentratedLiquidityPool struct { + // pool's address holding all liquidity tokens. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` + // address holding the incentives liquidity. + IncentivesAddress string `protobuf:"bytes,2,opt,name=incentives_address,json=incentivesAddress,proto3" json:"incentives_address,omitempty" yaml:"incentives_address"` + // address holding spread rewards from swaps. + SpreadRewardsAddress string `protobuf:"bytes,3,opt,name=spread_rewards_address,json=spreadRewardsAddress,proto3" json:"spread_rewards_address,omitempty" yaml:"spread_rewards_address"` + Id uint64 `protobuf:"varint,4,opt,name=id,proto3" json:"id,omitempty"` + // Amount of total liquidity + CurrentTickLiquidity cosmossdk_io_math.LegacyDec `protobuf:"bytes,5,opt,name=current_tick_liquidity,json=currentTickLiquidity,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"current_tick_liquidity" yaml:"current_tick_liquidity"` + Token0 string `protobuf:"bytes,6,opt,name=token0,proto3" json:"token0,omitempty"` + Token1 string `protobuf:"bytes,7,opt,name=token1,proto3" json:"token1,omitempty"` + CurrentSqrtPrice osmomath.BigDec `protobuf:"bytes,8,opt,name=current_sqrt_price,json=currentSqrtPrice,proto3,customtype=github.com/osmosis-labs/osmosis/osmomath.BigDec" json:"current_sqrt_price" yaml:"spot_price"` + CurrentTick int64 `protobuf:"varint,9,opt,name=current_tick,json=currentTick,proto3" json:"current_tick,omitempty" yaml:"current_tick"` + // tick_spacing must be one of the authorized_tick_spacing values set in the + // concentrated-liquidity parameters + TickSpacing uint64 `protobuf:"varint,10,opt,name=tick_spacing,json=tickSpacing,proto3" json:"tick_spacing,omitempty" yaml:"tick_spacing"` + ExponentAtPriceOne int64 `protobuf:"varint,11,opt,name=exponent_at_price_one,json=exponentAtPriceOne,proto3" json:"exponent_at_price_one,omitempty" yaml:"exponent_at_price_one"` + // spread_factor is the ratio that is charged on the amount of token in. + SpreadFactor cosmossdk_io_math.LegacyDec `protobuf:"bytes,12,opt,name=spread_factor,json=spreadFactor,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"spread_factor" yaml:"spread_factor"` + // last_liquidity_update is the last time either the pool liquidity or the + // active tick changed + LastLiquidityUpdate time.Time `protobuf:"bytes,13,opt,name=last_liquidity_update,json=lastLiquidityUpdate,proto3,stdtime" json:"last_liquidity_update" yaml:"last_liquidity_update"` +} + +func (m *OsmosisConcentratedLiquidityPool) Reset() { *m = OsmosisConcentratedLiquidityPool{} } +func (m *OsmosisConcentratedLiquidityPool) String() string { return proto.CompactTextString(m) } +func (*OsmosisConcentratedLiquidityPool) ProtoMessage() {} +func (*OsmosisConcentratedLiquidityPool) Descriptor() ([]byte, []int) { + return fileDescriptor_8b899353e6a19a1a, []int{0} +} +func (m *OsmosisConcentratedLiquidityPool) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OsmosisConcentratedLiquidityPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Pool.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *OsmosisConcentratedLiquidityPool) XXX_Merge(src proto.Message) { + xxx_messageInfo_Pool.Merge(m, src) +} +func (m *OsmosisConcentratedLiquidityPool) XXX_Size() int { + return m.Size() +} +func (m *OsmosisConcentratedLiquidityPool) XXX_DiscardUnknown() { + xxx_messageInfo_Pool.DiscardUnknown(m) +} + +var xxx_messageInfo_Pool proto.InternalMessageInfo + +func init() { + proto.RegisterType((*OsmosisConcentratedLiquidityPool)(nil), "osmosis.concentratedliquidity.v1beta1.Pool") +} + +func init() { + proto.RegisterFile("osmosis/concentratedliquidity/v1beta1/pool.proto", fileDescriptor_8b899353e6a19a1a) +} + +var fileDescriptor_8b899353e6a19a1a = []byte{ + // 661 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x4e, 0xdb, 0x40, + 0x10, 0x8e, 0xf9, 0x2d, 0x1b, 0x40, 0x65, 0x09, 0xd4, 0xd0, 0x12, 0xa7, 0x96, 0x2a, 0xe5, 0x50, + 0x6c, 0x42, 0x0f, 0x95, 0xe8, 0x89, 0x08, 0x55, 0xaa, 0x14, 0xa9, 0x68, 0xa1, 0xaa, 0x54, 0x55, + 0x72, 0x37, 0xf6, 0x62, 0x56, 0x71, 0xbc, 0xc6, 0xbb, 0xa1, 0xc0, 0x13, 0xf4, 0xc8, 0xb1, 0x47, + 0x1e, 0xa2, 0x0f, 0x81, 0x7a, 0x29, 0xc7, 0xaa, 0x07, 0xb7, 0x82, 0x37, 0xc8, 0x13, 0x54, 0xde, + 0x5d, 0x93, 0x20, 0x22, 0xb5, 0xa7, 0x64, 0xbe, 0x99, 0xef, 0xdb, 0x6f, 0xc6, 0xb3, 0x0b, 0x36, + 0x18, 0xef, 0x32, 0x4e, 0xb9, 0xeb, 0xb3, 0xd8, 0x27, 0xb1, 0x48, 0xb1, 0x20, 0x41, 0x44, 0x8f, + 0x7a, 0x34, 0xa0, 0xe2, 0xd4, 0x3d, 0x6e, 0xb4, 0x89, 0xc0, 0x0d, 0x37, 0x61, 0x2c, 0x72, 0x92, + 0x94, 0x09, 0x06, 0x9f, 0x69, 0x86, 0x33, 0x92, 0xe1, 0x68, 0xc6, 0xea, 0x8a, 0x2f, 0xeb, 0x3c, + 0x49, 0x72, 0x55, 0xa0, 0x14, 0x56, 0x2b, 0x21, 0x0b, 0x99, 0xc2, 0xf3, 0x7f, 0x1a, 0xb5, 0x42, + 0xc6, 0xc2, 0x88, 0xb8, 0x32, 0x6a, 0xf7, 0x0e, 0x5c, 0x41, 0xbb, 0x84, 0x0b, 0xdc, 0x4d, 0x54, + 0x81, 0xfd, 0x63, 0x1a, 0x4c, 0xec, 0x32, 0x16, 0xc1, 0xe7, 0x60, 0x1a, 0x07, 0x41, 0x4a, 0x38, + 0x37, 0x8d, 0x9a, 0x51, 0x9f, 0x69, 0xc2, 0x7e, 0x66, 0xcd, 0x9f, 0xe2, 0x6e, 0xb4, 0x65, 0xeb, + 0x84, 0x8d, 0x8a, 0x12, 0xd8, 0x02, 0x90, 0x4a, 0xa3, 0xf4, 0x98, 0x70, 0xaf, 0x20, 0x8e, 0x49, + 0xe2, 0x5a, 0x3f, 0xb3, 0x56, 0x14, 0xf1, 0x7e, 0x8d, 0x8d, 0x16, 0x06, 0xe0, 0xb6, 0x56, 0x7b, + 0x0f, 0x96, 0x79, 0x92, 0x12, 0x1c, 0x78, 0x29, 0xf9, 0x8c, 0xd3, 0x60, 0xa0, 0x38, 0x2e, 0x15, + 0x9f, 0xf6, 0x33, 0x6b, 0x4d, 0x29, 0x8e, 0xae, 0xb3, 0x51, 0x45, 0x25, 0x90, 0xc2, 0x0b, 0xe1, + 0x79, 0x30, 0x46, 0x03, 0x73, 0xa2, 0x66, 0xd4, 0x27, 0xd0, 0x18, 0x0d, 0xe0, 0x19, 0x58, 0xf6, + 0x7b, 0x69, 0x4a, 0x62, 0xe1, 0x09, 0xea, 0x77, 0xbc, 0xdb, 0x09, 0x9b, 0x93, 0xf2, 0xa0, 0x9d, + 0xcb, 0xcc, 0x2a, 0xfd, 0xca, 0xac, 0xc7, 0x6a, 0xb4, 0x3c, 0xe8, 0x38, 0x94, 0xb9, 0x5d, 0x2c, + 0x0e, 0x9d, 0x16, 0x09, 0xb1, 0x7f, 0xba, 0x43, 0xfc, 0x81, 0x97, 0xd1, 0x52, 0x36, 0xaa, 0xe8, + 0xc4, 0x3e, 0xf5, 0x3b, 0xad, 0x02, 0x86, 0xcb, 0x60, 0x4a, 0xb0, 0x0e, 0x89, 0x37, 0xcc, 0xa9, + 0xfc, 0x2c, 0xa4, 0xa3, 0x5b, 0xbc, 0x61, 0x4e, 0x0f, 0xe1, 0x0d, 0x78, 0x06, 0x60, 0x71, 0x00, + 0x3f, 0x4a, 0x85, 0x97, 0xa4, 0xd4, 0x27, 0xe6, 0x03, 0xe9, 0xb3, 0xa5, 0x7d, 0xba, 0x21, 0x15, + 0x87, 0xbd, 0xb6, 0xe3, 0xb3, 0xae, 0xab, 0x37, 0x68, 0x3d, 0xc2, 0x6d, 0x5e, 0x04, 0xf2, 0x57, + 0xda, 0x6f, 0xd2, 0x50, 0x79, 0x5f, 0x28, 0xe6, 0xc8, 0xb4, 0xa4, 0x8d, 0x1e, 0xea, 0x73, 0xf6, + 0x8e, 0x52, 0xb1, 0x9b, 0x43, 0x70, 0x0b, 0xcc, 0x0e, 0x37, 0x67, 0xce, 0xd4, 0x8c, 0xfa, 0x78, + 0xf3, 0x51, 0x3f, 0xb3, 0x16, 0xef, 0xb7, 0x6e, 0xa3, 0xf2, 0x50, 0xc3, 0x39, 0x57, 0x0e, 0x84, + 0x27, 0xd8, 0xa7, 0x71, 0x68, 0x82, 0x7c, 0xfa, 0xc3, 0xdc, 0xe1, 0xac, 0x8d, 0xca, 0x79, 0xb8, + 0xa7, 0x22, 0xb8, 0x07, 0x96, 0xc8, 0x49, 0xc2, 0xe2, 0x5c, 0x1a, 0x6b, 0x7f, 0x1e, 0x8b, 0x89, + 0x59, 0x96, 0x06, 0x6a, 0xfd, 0xcc, 0x7a, 0xa2, 0x44, 0x46, 0x96, 0xd9, 0x08, 0x16, 0xf8, 0xb6, + 0xea, 0xe4, 0x6d, 0x4c, 0xe0, 0x27, 0x30, 0xa7, 0xb7, 0xe6, 0x00, 0xfb, 0x82, 0xa5, 0xe6, 0xac, + 0x9c, 0xe1, 0xab, 0xff, 0xfb, 0xd6, 0x95, 0x3b, 0x7b, 0xa7, 0x14, 0x6c, 0x34, 0xab, 0xe2, 0xd7, + 0x32, 0x84, 0x27, 0x60, 0x29, 0xc2, 0x5c, 0x0c, 0x76, 0xc0, 0xeb, 0x25, 0x01, 0x16, 0xc4, 0x9c, + 0xab, 0x19, 0xf5, 0xf2, 0xe6, 0xaa, 0xa3, 0x6e, 0xa1, 0x53, 0xdc, 0x42, 0x67, 0xbf, 0xb8, 0x85, + 0xcd, 0x7a, 0xee, 0x62, 0xd0, 0xd6, 0x48, 0x19, 0xfb, 0xfc, 0xb7, 0x65, 0xa0, 0xc5, 0x3c, 0x77, + 0xbb, 0x4e, 0xef, 0x64, 0x66, 0x6b, 0xe1, 0xcb, 0x85, 0x55, 0xfa, 0x7a, 0x61, 0x95, 0xbe, 0x7f, + 0x5b, 0x9f, 0xcc, 0xef, 0xf1, 0x9b, 0xe6, 0xc7, 0xcb, 0xeb, 0xaa, 0x71, 0x75, 0x5d, 0x35, 0xfe, + 0x5c, 0x57, 0x8d, 0xf3, 0x9b, 0x6a, 0xe9, 0xea, 0xa6, 0x5a, 0xfa, 0x79, 0x53, 0x2d, 0x7d, 0x68, + 0xfe, 0x6b, 0x5b, 0x8e, 0x37, 0x5f, 0xba, 0x27, 0x77, 0x1e, 0xad, 0xf5, 0xc1, 0xab, 0xd5, 0x65, + 0x01, 0x89, 0xda, 0x53, 0xb2, 0x87, 0x17, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xd4, 0xe2, 0x15, + 0xf7, 0xe3, 0x04, 0x00, 0x00, +} + +func (m *OsmosisConcentratedLiquidityPool) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OsmosisConcentratedLiquidityPool) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OsmosisConcentratedLiquidityPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.LastLiquidityUpdate, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.LastLiquidityUpdate):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintPool(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x6a + { + size := m.SpreadFactor.Size() + i -= size + if _, err := m.SpreadFactor.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x62 + if m.ExponentAtPriceOne != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.ExponentAtPriceOne)) + i-- + dAtA[i] = 0x58 + } + if m.TickSpacing != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.TickSpacing)) + i-- + dAtA[i] = 0x50 + } + if m.CurrentTick != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.CurrentTick)) + i-- + dAtA[i] = 0x48 + } + { + size := m.CurrentSqrtPrice.Size() + i -= size + if _, err := m.CurrentSqrtPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + if len(m.Token1) > 0 { + i -= len(m.Token1) + copy(dAtA[i:], m.Token1) + i = encodeVarintPool(dAtA, i, uint64(len(m.Token1))) + i-- + dAtA[i] = 0x3a + } + if len(m.Token0) > 0 { + i -= len(m.Token0) + copy(dAtA[i:], m.Token0) + i = encodeVarintPool(dAtA, i, uint64(len(m.Token0))) + i-- + dAtA[i] = 0x32 + } + { + size := m.CurrentTickLiquidity.Size() + i -= size + if _, err := m.CurrentTickLiquidity.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if m.Id != 0 { + i = encodeVarintPool(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x20 + } + if len(m.SpreadRewardsAddress) > 0 { + i -= len(m.SpreadRewardsAddress) + copy(dAtA[i:], m.SpreadRewardsAddress) + i = encodeVarintPool(dAtA, i, uint64(len(m.SpreadRewardsAddress))) + i-- + dAtA[i] = 0x1a + } + if len(m.IncentivesAddress) > 0 { + i -= len(m.IncentivesAddress) + copy(dAtA[i:], m.IncentivesAddress) + i = encodeVarintPool(dAtA, i, uint64(len(m.IncentivesAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintPool(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPool(dAtA []byte, offset int, v uint64) int { + offset -= sovPool(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *OsmosisConcentratedLiquidityPool) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.IncentivesAddress) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.SpreadRewardsAddress) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + if m.Id != 0 { + n += 1 + sovPool(uint64(m.Id)) + } + l = m.CurrentTickLiquidity.Size() + n += 1 + l + sovPool(uint64(l)) + l = len(m.Token0) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = len(m.Token1) + if l > 0 { + n += 1 + l + sovPool(uint64(l)) + } + l = m.CurrentSqrtPrice.Size() + n += 1 + l + sovPool(uint64(l)) + if m.CurrentTick != 0 { + n += 1 + sovPool(uint64(m.CurrentTick)) + } + if m.TickSpacing != 0 { + n += 1 + sovPool(uint64(m.TickSpacing)) + } + if m.ExponentAtPriceOne != 0 { + n += 1 + sovPool(uint64(m.ExponentAtPriceOne)) + } + l = m.SpreadFactor.Size() + n += 1 + l + sovPool(uint64(l)) + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.LastLiquidityUpdate) + n += 1 + l + sovPool(uint64(l)) + return n +} + +func sovPool(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPool(x uint64) (n int) { + return sovPool(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *OsmosisConcentratedLiquidityPool) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Pool: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Pool: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IncentivesAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.IncentivesAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpreadRewardsAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpreadRewardsAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentTickLiquidity", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CurrentTickLiquidity.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token0", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Token0 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Token1", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Token1 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentSqrtPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CurrentSqrtPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentTick", wireType) + } + m.CurrentTick = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentTick |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TickSpacing", wireType) + } + m.TickSpacing = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TickSpacing |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExponentAtPriceOne", wireType) + } + m.ExponentAtPriceOne = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExponentAtPriceOne |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpreadFactor", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SpreadFactor.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastLiquidityUpdate", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPool + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.LastLiquidityUpdate, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPool(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPool + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPool(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPool + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPool + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPool + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPool + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPool + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPool + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPool = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPool = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPool = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqoracle/keeper/abci.go b/x/icqoracle/keeper/abci.go new file mode 100644 index 0000000000..8f6dd6eec6 --- /dev/null +++ b/x/icqoracle/keeper/abci.go @@ -0,0 +1,44 @@ +package keeper + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) BeginBlocker(ctx sdk.Context) { + // Get all token prices + params, err := k.GetParams(ctx) + if err != nil { + // Can't really do anything but log + // A panic would halt the chain + ctx.Logger().Error("failed to get icqoracle params: %w", err) + return + } + + currentTime := ctx.BlockTime() + + // Iterate through each token price + tokenPrices := k.GetAllTokenPrices(ctx) + for _, tokenPrice := range tokenPrices { + // Get last update time for this token + lastUpdate := tokenPrice.UpdatedAt + + // If never updated or update interval has passed + if lastUpdate.IsZero() || !tokenPrice.QueryInProgress && currentTime.Sub(lastUpdate) >= time.Second*time.Duration(params.UpdateIntervalSec) { + // Update price for this specific token + err := k.SubmitOsmosisClPoolICQ(ctx, tokenPrice) + if err != nil { + // Can't really do anything but log + ctx.Logger().Error( + "failed to submit Osmosis CL pool ICQ error='%w' baseToken='%s' quoteToken='%s' poolId='%s'", + err, + tokenPrice.BaseDenom, + tokenPrice.QuoteDenom, + tokenPrice.OsmosisPoolId, + ) + continue + } + } + } +} diff --git a/x/icqoracle/keeper/genesis.go b/x/icqoracle/keeper/genesis.go new file mode 100644 index 0000000000..cb31e53f76 --- /dev/null +++ b/x/icqoracle/keeper/genesis.go @@ -0,0 +1,41 @@ +package keeper + +import ( + "time" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +// Loads module state from genesis +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { + err := k.SetParams(ctx, genState.Params) + if err != nil { + panic(err) + } + + for _, tokenPrice := range genState.TokenPrices { + tokenPrice.SpotPrice = math.LegacyZeroDec() + tokenPrice.UpdatedAt = time.Time{} + tokenPrice.QueryInProgress = false + + if err := k.SetTokenPrice(ctx, tokenPrice); err != nil { + panic(err) + } + } +} + +// Export's module state into genesis file +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + params, err := k.GetParams(ctx) + if err != nil { + panic(err) + } + + genesis := types.DefaultGenesis() + genesis.Params = params + genesis.TokenPrices = k.GetAllTokenPrices(ctx) + return genesis +} diff --git a/x/icqoracle/keeper/icq.go b/x/icqoracle/keeper/icq.go new file mode 100644 index 0000000000..f935d12b42 --- /dev/null +++ b/x/icqoracle/keeper/icq.go @@ -0,0 +1,157 @@ +package keeper + +import ( + "encoding/hex" + "fmt" + "strconv" + "time" + + errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + proto "github.com/cosmos/gogoproto/proto" + + "github.com/Stride-Labs/stride/v24/utils" + deps "github.com/Stride-Labs/stride/v24/x/icqoracle/deps/types" + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" + icqtypes "github.com/Stride-Labs/stride/v24/x/interchainquery/types" +) + +const ( + ICQCallbackID_OsmosisClPool = "osmosisclpool" +) + +// ICQCallbacks wrapper struct for stakeibc keeper +type ICQCallback func(Keeper, sdk.Context, []byte, icqtypes.Query) error + +type ICQCallbacks struct { + k Keeper + callbacks map[string]ICQCallback +} + +var _ icqtypes.QueryCallbacks = ICQCallbacks{} + +func (k Keeper) ICQCallbackHandler() ICQCallbacks { + return ICQCallbacks{k, make(map[string]ICQCallback)} +} + +func (c ICQCallbacks) CallICQCallback(ctx sdk.Context, id string, args []byte, query icqtypes.Query) error { + return c.callbacks[id](c.k, ctx, args, query) +} + +func (c ICQCallbacks) HasICQCallback(id string) bool { + _, found := c.callbacks[id] + return found +} + +func (c ICQCallbacks) AddICQCallback(id string, fn interface{}) icqtypes.QueryCallbacks { + c.callbacks[id] = fn.(ICQCallback) + return c +} + +func (c ICQCallbacks) RegisterICQCallbacks() icqtypes.QueryCallbacks { + return c. + AddICQCallback(ICQCallbackID_OsmosisClPool, ICQCallback(OsmosisClPoolCallback)) +} + +// Submits an ICQ to get a concentrated liquidity pool from Osmosis' store +func (k Keeper) SubmitOsmosisClPoolICQ( + ctx sdk.Context, + tokenPrice types.TokenPrice, +) error { + k.Logger(ctx).Info(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Submitting OsmosisClPool ICQ")) + + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Error getting module params: %s", err.Error())) + return err + } + + osmosisPoolId, err := strconv.ParseUint(tokenPrice.OsmosisPoolId, 10, 64) + if err != nil { + k.Logger(ctx).Error(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Error converting osmosis pool id '%s' to uint64, error '%s'", tokenPrice.OsmosisPoolId, err.Error())) + return err + } + + tokenPriceBz, err := k.cdc.Marshal(&tokenPrice) + if err != nil { + k.Logger(ctx).Error(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Error serializing tokenPrice '%+v' to bytes, error '%s'", tokenPrice, err.Error())) + return err + } + + queryId := fmt.Sprintf("%s|%s|%s|%d", tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, ctx.BlockHeight()) + query := icqtypes.Query{ + Id: queryId, + ChainId: params.OsmosisChainId, + ConnectionId: params.OsmosisConnectionId, + QueryType: icqtypes.CONCENTRATEDLIQUIDITY_STORE_QUERY_WITH_PROOF, + RequestData: icqtypes.FormatOsmosisKeyPool(osmosisPoolId), + CallbackModule: types.ModuleName, + CallbackId: ICQCallbackID_OsmosisClPool, + CallbackData: tokenPriceBz, + TimeoutDuration: time.Duration(params.IcqTimeoutSec) * time.Second, + TimeoutPolicy: icqtypes.TimeoutPolicy_REJECT_QUERY_RESPONSE, + } + if err := k.icqKeeper.SubmitICQRequest(ctx, query, true); err != nil { + k.Logger(ctx).Error(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Error submitting OsmosisClPool ICQ, error '%s'", err.Error())) + return err + } + + if err := k.SetTokenPriceQueryInProgress(ctx, tokenPrice, true); err != nil { + k.Logger(ctx).Error(utils.LogWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "Error updating queryInProgress=true, error '%s'", err.Error())) + return err + } + + return nil +} + +func OsmosisClPoolCallback(k Keeper, ctx sdk.Context, args []byte, query icqtypes.Query) error { + var tokenPrice types.TokenPrice + if err := k.cdc.Unmarshal(query.CallbackData, &tokenPrice); err != nil { + return fmt.Errorf("Error deserializing query.CallbackData '%s' as TokenPrice", hex.EncodeToString(query.CallbackData)) + } + + k.Logger(ctx).Info(utils.LogICQCallbackWithTokenPriceQuery(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId, "OsmosisClPool", + "Starting OsmosisClPool ICQ callback, QueryId: %vs, QueryType: %s, Connection: %s", query.Id, query.QueryType, query.ConnectionId)) + + tokenPrice, err := k.GetTokenPrice(ctx, tokenPrice) + if err != nil { + return errorsmod.Wrap(err, "Error getting current spot price") + } + + // TODO review this + // this should never happen + if !tokenPrice.QueryInProgress { + return nil + } + + // Unmarshal the query response args to determine the balance + newSpotPrice, err := unmarshalSpotPriceFromOsmosisClPool(tokenPrice, args) + if err != nil { + return errorsmod.Wrap(err, "Error determining spot price from query response") + } + + tokenPrice.SpotPrice = newSpotPrice + tokenPrice.QueryInProgress = false + tokenPrice.UpdatedAt = ctx.BlockTime() + + if err := k.SetTokenPrice(ctx, tokenPrice); err != nil { + return errorsmod.Wrap(err, "Error updating spot price from query response") + } + + return nil +} + +func unmarshalSpotPriceFromOsmosisClPool(tokenPrice types.TokenPrice, queryResponseBz []byte) (price math.LegacyDec, err error) { + var pool deps.OsmosisConcentratedLiquidityPool + if err := proto.Unmarshal(queryResponseBz, &pool); err != nil { + return math.LegacyZeroDec(), err + } + + spotPrice, err := pool.SpotPrice(tokenPrice.OsmosisQuoteDenom, tokenPrice.OsmosisBaseDenom) + if err != nil { + return math.LegacyZeroDec(), err + } + + return spotPrice, nil +} diff --git a/x/icqoracle/keeper/keeper.go b/x/icqoracle/keeper/keeper.go new file mode 100644 index 0000000000..ebbd258ec5 --- /dev/null +++ b/x/icqoracle/keeper/keeper.go @@ -0,0 +1,234 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/math" + "github.com/cometbft/cometbft/libs/log" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + interchainquerykeeper "github.com/Stride-Labs/stride/v24/x/interchainquery/keeper" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +type Keeper struct { + cdc codec.Codec + storeKey storetypes.StoreKey + icqKeeper interchainquerykeeper.Keeper +} + +func NewKeeper( + cdc codec.Codec, + storeKey storetypes.StoreKey, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +// SetTokenPrice stores price query for a token +func (k Keeper) SetTokenPrice(ctx sdk.Context, tokenPrice types.TokenPrice) error { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PriceQueryPrefix) + key := types.TokenPriceQueryKey(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId) + + bz, err := k.cdc.Marshal(&tokenPrice) + if err != nil { + return err + } + + store.Set(key, bz) + return nil +} + +// RemoveTokenPrice removes price query for a token +func (k Keeper) RemoveTokenPrice(ctx sdk.Context, tokenPrice types.TokenPrice) { + store := ctx.KVStore(k.storeKey) + key := types.TokenPriceQueryKey(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId) + store.Delete(key) +} + +func (k Keeper) SetTokenPriceQueryInProgress(ctx sdk.Context, tokenPrice types.TokenPrice, queryInProgress bool) error { + tokenPrice, err := k.GetTokenPrice(ctx, tokenPrice) + if err != nil { + return err + } + + tokenPrice.QueryInProgress = queryInProgress + err = k.SetTokenPrice(ctx, tokenPrice) + if err != nil { + return err + } + + return nil +} + +// GetTokenPrice retrieves price data for a token +func (k Keeper) GetTokenPrice(ctx sdk.Context, tokenPrice types.TokenPrice) (types.TokenPrice, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PriceQueryPrefix) + key := types.TokenPriceQueryKey(tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId) + + bz := store.Get(key) + if bz == nil { + return types.TokenPrice{}, fmt.Errorf("price not found for baseDenom='%s' quoteDenom='%s' poolId='%s'", tokenPrice.BaseDenom, tokenPrice.QuoteDenom, tokenPrice.OsmosisPoolId) + } + + var price types.TokenPrice + if err := k.cdc.Unmarshal(bz, &price); err != nil { + return types.TokenPrice{}, err + } + + return price, nil +} + +// GetTokenPriceByDenom retrieves all price data for a base denom +// Returned as a mapping of each quote denom to the spot price +func (k Keeper) GetTokenPricesByDenom(ctx sdk.Context, baseDenom string) (map[string]*types.TokenPrice, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PriceQueryPrefix) + + // Create prefix iterator for all keys starting with baseDenom + iterator := sdk.KVStorePrefixIterator(store, types.TokenPriceByDenomKey(baseDenom)) + defer iterator.Close() + + prices := make(map[string]*types.TokenPrice) + + for ; iterator.Valid(); iterator.Next() { + var price types.TokenPrice + if err := k.cdc.Unmarshal(iterator.Value(), &price); err != nil { + return nil, err + } + + // Use quoteDenom as the map key + prices[price.QuoteDenom] = &price + } + + return prices, nil +} + +// GetTokenPriceForQuoteDenom calculates and retrieves the exchange rate between two tokens. +// The exchange rate is determined by finding a common quote token between both tokens, +// and then dividing their respective spot prices. +// +// For example, if we have: +// - baseToken/USDC = 10 +// - quoteToken/USDC = 5 +// +// Then: +// - baseToken/quoteToken = 10/5 = 2 +// +// Parameters: +// - ctx: SDK Context for accessing the store +// - baseDenom: The denom of the token to get the price for +// - quoteDenom: The denom to price the base token in +// +// Returns: +// - math.LegacyDec: The exchange rate of 1 baseToken in terms of quoteToken +// - error: Returns an error if: +// - No prices exist for either token +// - No common quote token exists between the two tokens +// - All available prices with a common quote token are stale (exceeded the stale timeout) +func (k Keeper) GetTokenPriceForQuoteDenom(ctx sdk.Context, baseDenom string, quoteDenom string) (price math.LegacyDec, err error) { + // Get all price for baseToken + baseTokenPrices, err := k.GetTokenPricesByDenom(ctx, baseDenom) + if err != nil { + return math.LegacyDec{}, fmt.Errorf("error getting price for '%s': %w", baseDenom, err) + } + if len(baseTokenPrices) == 0 { + return math.LegacyDec{}, fmt.Errorf("no price for '%s'", baseDenom) + } + + // Get all price for quoteToken + quoteTokenPrices, err := k.GetTokenPricesByDenom(ctx, quoteDenom) + if err != nil { + return math.LegacyDec{}, fmt.Errorf("error getting price for '%s': %w", quoteDenom, err) + } + if len(quoteTokenPrices) == 0 { + return math.LegacyDec{}, fmt.Errorf("no price for '%s'", quoteDenom) + } + + // Get price expiration timeout + params, err := k.GetParams(ctx) + if err != nil { + return math.LegacyDec{}, fmt.Errorf("error getting params: %w", err) + } + priceExpirationTimeoutSec := int64(params.PriceExpirationTimeoutSec) + + // Init price + price = math.LegacyZeroDec() + + // Define flags to allow for better error messages + foundCommonQuoteToken := false + foundBaseTokenStalePrice := false + foundQuoteTokenStalePrice := false + foundQuoteTokenZeroPrice := false + + // Find a common quote denom and calculate baseToken to quoteToken price + for quoteDenom1, baseTokenPrice := range baseTokenPrices { + for quoteDenom2, quoteTokenPrice := range quoteTokenPrices { + if quoteDenom1 == quoteDenom2 { + foundCommonQuoteToken = true + + // Check that both prices are not stale + if ctx.BlockTime().Unix()-baseTokenPrice.UpdatedAt.Unix() > priceExpirationTimeoutSec { + foundBaseTokenStalePrice = true + continue + } + if ctx.BlockTime().Unix()-quoteTokenPrice.UpdatedAt.Unix() > priceExpirationTimeoutSec { + foundQuoteTokenStalePrice = true + continue + } + + // Check that quote price is not zero to prevent division by zero + if quoteTokenPrice.SpotPrice.IsZero() { + foundQuoteTokenZeroPrice = true + continue + } + + // Calculate the price of 1 baseToken in quoteToken + price = baseTokenPrice.SpotPrice.Quo(quoteTokenPrice.SpotPrice) + + break + } + } + } + + if price.IsZero() { + return math.LegacyDec{}, fmt.Errorf( + "could not calculate price for baseToken='%s' quoteToken='%s' (foundCommonQuoteToken='%v', foundBaseTokenStalePrice='%v', foundQuoteTokenStalePrice='%v', foundQuoteTokenZeroPrice='%v')", + baseDenom, + quoteDenom, + foundCommonQuoteToken, + foundBaseTokenStalePrice, + foundQuoteTokenStalePrice, + foundQuoteTokenZeroPrice, + ) + } + + return price, nil +} + +// GetAllTokenPrices retrieves all stored token prices +func (k Keeper) GetAllTokenPrices(ctx sdk.Context) []types.TokenPrice { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PriceQueryPrefix) + + iterator := sdk.KVStorePrefixIterator(store, []byte(types.PriceQueryPrefix)) + defer iterator.Close() + + prices := []types.TokenPrice{} + for ; iterator.Valid(); iterator.Next() { + var price types.TokenPrice + k.cdc.MustUnmarshal(iterator.Value(), &price) + prices = append(prices, price) + } + + return prices +} diff --git a/x/icqoracle/keeper/msg_server.go b/x/icqoracle/keeper/msg_server.go new file mode 100644 index 0000000000..bbb0d60260 --- /dev/null +++ b/x/icqoracle/keeper/msg_server.go @@ -0,0 +1,64 @@ +package keeper + +import ( + "context" + "time" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// RegisterTokenPriceQuery registers a token to price tracking +func (ms msgServer) RegisterTokenPriceQuery(goCtx context.Context, msg *types.MsgRegisterTokenPriceQuery) (*types.MsgRegisterTokenPriceQueryResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO check admin + + tokenPrice := types.TokenPrice{ + BaseDenom: msg.BaseDenom, + QuoteDenom: msg.QuoteDenom, + OsmosisPoolId: msg.OsmosisPoolId, + OsmosisBaseDenom: msg.OsmosisBaseDenom, + OsmosisQuoteDenom: msg.OsmosisQuoteDenom, + UpdatedAt: time.Time{}, + SpotPrice: sdkmath.LegacyZeroDec(), + QueryInProgress: false, + } + + err := ms.Keeper.SetTokenPrice(ctx, tokenPrice) + if err != nil { + return nil, err + } + + return &types.MsgRegisterTokenPriceQueryResponse{}, nil +} + +// RemoveTokenPriceQuery removes a token from price tracking +func (ms msgServer) RemoveTokenPriceQuery(goCtx context.Context, msg *types.MsgRemoveTokenPriceQuery) (*types.MsgRemoveTokenPriceQueryResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO check admin + + tokenPrice := types.TokenPrice{ + BaseDenom: msg.BaseDenom, + QuoteDenom: msg.QuoteDenom, + OsmosisPoolId: msg.OsmosisPoolId, + } + ms.Keeper.RemoveTokenPrice(ctx, tokenPrice) + + return &types.MsgRemoveTokenPriceQueryResponse{}, nil +} diff --git a/x/icqoracle/keeper/params.go b/x/icqoracle/keeper/params.go new file mode 100644 index 0000000000..fbd5c91684 --- /dev/null +++ b/x/icqoracle/keeper/params.go @@ -0,0 +1,27 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +// GetParams get params +func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { + store := ctx.KVStore(k.storeKey) + bz := store.Get([]byte(types.ParamsKey)) + params := types.Params{} + err := k.cdc.UnmarshalJSON(bz, ¶ms) + return params, err +} + +// SetParams set params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.MarshalJSON(¶ms) + if err != nil { + return err + } + store.Set([]byte(types.ParamsKey), bz) + return nil +} diff --git a/x/icqoracle/keeper/query.go b/x/icqoracle/keeper/query.go new file mode 100644 index 0000000000..44606380f2 --- /dev/null +++ b/x/icqoracle/keeper/query.go @@ -0,0 +1,89 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +var _ types.QueryServer = Keeper{} + +// TokenPrice queries the current price for a specific token +func (k Keeper) TokenPrice(goCtx context.Context, req *types.QueryTokenPriceRequest) (*types.QueryTokenPriceResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + tokenPrice := types.TokenPrice{ + BaseDenom: req.BaseDenom, + QuoteDenom: req.QuoteDenom, + OsmosisPoolId: req.PoolId, + } + price, err := k.GetTokenPrice(ctx, tokenPrice) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + return &types.QueryTokenPriceResponse{ + TokenPrice: price, + }, nil +} + +// TokenPrices queries all token prices +func (k Keeper) TokenPrices(goCtx context.Context, req *types.QueryTokenPricesRequest) (*types.QueryTokenPricesResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO impl paging + + prices := k.GetAllTokenPrices(ctx) + + return &types.QueryTokenPricesResponse{ + TokenPrices: prices, + }, nil +} + +// Params queries the oracle parameters +func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + params, err := k.GetParams(ctx) + if err != nil { + return nil, err + } + + return &types.QueryParamsResponse{ + Params: params, + }, nil +} + +// TokenPriceForQuoteDenom queries the exchange rate between two tokens +func (k Keeper) TokenPriceForQuoteDenom(goCtx context.Context, req *types.QueryTokenPriceForQuoteDenomRequest) (*types.QueryTokenPriceForQuoteDenomResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + price, err := k.GetTokenPriceForQuoteDenom(ctx, req.BaseDenom, req.QuoteDenom) + if err != nil { + return nil, status.Error(codes.NotFound, err.Error()) + } + + return &types.QueryTokenPriceForQuoteDenomResponse{ + Price: price, + }, nil +} diff --git a/x/icqoracle/module.go b/x/icqoracle/module.go new file mode 100644 index 0000000000..d7102d32fc --- /dev/null +++ b/x/icqoracle/module.go @@ -0,0 +1,158 @@ +package icqoracle + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/Stride-Labs/stride/v24/x/icqoracle/client/cli" + "github.com/Stride-Labs/stride/v24/x/icqoracle/keeper" + "github.com/Stride-Labs/stride/v24/x/icqoracle/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + am.keeper.BeginBlocker(ctx) +} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/icqoracle/types/codec.go b/x/icqoracle/types/codec.go new file mode 100644 index 0000000000..1c2bbd1582 --- /dev/null +++ b/x/icqoracle/types/codec.go @@ -0,0 +1,40 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgRegisterTokenPriceQuery{}, "icqoracle/MsgRegisterTokenPriceQuery") + legacy.RegisterAminoMsg(cdc, &MsgRemoveTokenPriceQuery{}, "icqoracle/MsgRemoveTokenPriceQuery") +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgRegisterTokenPriceQuery{}, + &MsgRemoveTokenPriceQuery{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgSubmitProposal instances + RegisterLegacyAminoCodec(govcodec.Amino) +} diff --git a/x/icqoracle/types/expected_keepers.go b/x/icqoracle/types/expected_keepers.go new file mode 100644 index 0000000000..ab1254f4c2 --- /dev/null +++ b/x/icqoracle/types/expected_keepers.go @@ -0,0 +1 @@ +package types diff --git a/x/icqoracle/types/genesis.go b/x/icqoracle/types/genesis.go new file mode 100644 index 0000000000..bddce61281 --- /dev/null +++ b/x/icqoracle/types/genesis.go @@ -0,0 +1,29 @@ +package types + +import ( + fmt "fmt" +) + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{} +} + +// Performs basic genesis state validation by iterating through all token prices and validating +// using ValidateTokenPriceQueryParams(). +// We ignore the SpotPrice, UpdatedAt & QueryInProgress fields since they are reset in InitGenesis(). +func (gs GenesisState) Validate() error { + for i, tokenPrice := range gs.TokenPrices { + err := ValidateTokenPriceQueryParams( + tokenPrice.BaseDenom, + tokenPrice.QuoteDenom, + tokenPrice.OsmosisPoolId, + tokenPrice.OsmosisBaseDenom, + tokenPrice.OsmosisQuoteDenom, + ) + if err != nil { + return fmt.Errorf("invalid genesis token price query at index %d: %w", i, err) + } + } + return nil +} diff --git a/x/icqoracle/types/genesis.pb.go b/x/icqoracle/types/genesis.pb.go new file mode 100644 index 0000000000..9ab1a5af1a --- /dev/null +++ b/x/icqoracle/types/genesis.pb.go @@ -0,0 +1,387 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/icqoracle/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the icqoracle module's genesis state +type GenesisState struct { + // Module parameters + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // List of token prices + TokenPrices []TokenPrice `protobuf:"bytes,2,rep,name=token_prices,json=tokenPrices,proto3" json:"token_prices"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_a0cfd8712dde4d4a, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetTokenPrices() []TokenPrice { + if m != nil { + return m.TokenPrices + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "stride.icqoracle.GenesisState") +} + +func init() { proto.RegisterFile("stride/icqoracle/genesis.proto", fileDescriptor_a0cfd8712dde4d4a) } + +var fileDescriptor_a0cfd8712dde4d4a = []byte{ + // 240 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x2e, 0x29, 0xca, + 0x4c, 0x49, 0xd5, 0xcf, 0x4c, 0x2e, 0xcc, 0x2f, 0x4a, 0x4c, 0xce, 0x49, 0xd5, 0x4f, 0x4f, 0xcd, + 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x80, 0xc8, 0xeb, 0xc1, + 0xe5, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x92, 0xfa, 0x20, 0x16, 0x44, 0x9d, 0x94, 0x02, + 0x86, 0x39, 0x70, 0x16, 0x44, 0x85, 0x52, 0x2f, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0xec, 0xe0, 0x92, + 0xc4, 0x92, 0x54, 0x21, 0x33, 0x2e, 0xb6, 0x82, 0xc4, 0xa2, 0xc4, 0xdc, 0x62, 0x09, 0x46, 0x05, + 0x46, 0x0d, 0x6e, 0x23, 0x09, 0x3d, 0x74, 0xbb, 0xf4, 0x02, 0xc0, 0xf2, 0x4e, 0x2c, 0x27, 0xee, + 0xc9, 0x33, 0x04, 0x41, 0x55, 0x0b, 0xb9, 0x72, 0xf1, 0x94, 0xe4, 0x67, 0xa7, 0xe6, 0xc5, 0x17, + 0x14, 0x65, 0x26, 0xa7, 0x16, 0x4b, 0x30, 0x29, 0x30, 0x6b, 0x70, 0x1b, 0xc9, 0x60, 0xea, 0x0e, + 0x01, 0xa9, 0x0a, 0x00, 0x29, 0x82, 0x9a, 0xc0, 0x5d, 0x02, 0x17, 0x29, 0x76, 0xf2, 0x3d, 0xf1, + 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xe3, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, + 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0x60, 0xb0, 0xa1, 0xba, 0x3e, 0x89, 0x49, 0xc5, 0xfa, 0x50, 0x2f, + 0x96, 0x19, 0x99, 0xe8, 0x57, 0x20, 0x79, 0xb4, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, + 0x4b, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x21, 0x4a, 0x5a, 0xfa, 0x51, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.TokenPrices) > 0 { + for iNdEx := len(m.TokenPrices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TokenPrices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.TokenPrices) > 0 { + for _, e := range m.TokenPrices { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TokenPrices", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TokenPrices = append(m.TokenPrices, TokenPrice{}) + if err := m.TokenPrices[len(m.TokenPrices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqoracle/types/icqoracle.pb.go b/x/icqoracle/types/icqoracle.pb.go new file mode 100644 index 0000000000..75b384f326 --- /dev/null +++ b/x/icqoracle/types/icqoracle.pb.go @@ -0,0 +1,1033 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/icqoracle/icqoracle.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "github.com/cosmos/gogoproto/types" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// TokenPrice stores latest price data for a token +type TokenPrice struct { + // Token denom on Stride + BaseDenom string `protobuf:"bytes,1,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"` + // Quote denom on Stride + QuoteDenom string `protobuf:"bytes,2,opt,name=quote_denom,json=quoteDenom,proto3" json:"quote_denom,omitempty"` + // Token denom on Osmosis + OsmosisBaseDenom string `protobuf:"bytes,3,opt,name=osmosis_base_denom,json=osmosisBaseDenom,proto3" json:"osmosis_base_denom,omitempty"` + // Quote denom on Osmosis + OsmosisQuoteDenom string `protobuf:"bytes,4,opt,name=osmosis_quote_denom,json=osmosisQuoteDenom,proto3" json:"osmosis_quote_denom,omitempty"` + // Pool ID on Osmosis + OsmosisPoolId string `protobuf:"bytes,5,opt,name=osmosis_pool_id,json=osmosisPoolId,proto3" json:"osmosis_pool_id,omitempty"` + // Spot price of base_denom denominated in quote_denom + SpotPrice cosmossdk_io_math.LegacyDec `protobuf:"bytes,6,opt,name=spot_price,json=spotPrice,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"spot_price"` + // Last update timestamp + UpdatedAt time.Time `protobuf:"bytes,7,opt,name=updated_at,json=updatedAt,proto3,stdtime" json:"updated_at"` + // Whether there is a spot price query currently in progress + QueryInProgress bool `protobuf:"varint,8,opt,name=query_in_progress,json=queryInProgress,proto3" json:"query_in_progress,omitempty"` +} + +func (m *TokenPrice) Reset() { *m = TokenPrice{} } +func (m *TokenPrice) String() string { return proto.CompactTextString(m) } +func (*TokenPrice) ProtoMessage() {} +func (*TokenPrice) Descriptor() ([]byte, []int) { + return fileDescriptor_08ead8ab9516d7fc, []int{0} +} +func (m *TokenPrice) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TokenPrice) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TokenPrice.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TokenPrice) XXX_Merge(src proto.Message) { + xxx_messageInfo_TokenPrice.Merge(m, src) +} +func (m *TokenPrice) XXX_Size() int { + return m.Size() +} +func (m *TokenPrice) XXX_DiscardUnknown() { + xxx_messageInfo_TokenPrice.DiscardUnknown(m) +} + +var xxx_messageInfo_TokenPrice proto.InternalMessageInfo + +func (m *TokenPrice) GetBaseDenom() string { + if m != nil { + return m.BaseDenom + } + return "" +} + +func (m *TokenPrice) GetQuoteDenom() string { + if m != nil { + return m.QuoteDenom + } + return "" +} + +func (m *TokenPrice) GetOsmosisBaseDenom() string { + if m != nil { + return m.OsmosisBaseDenom + } + return "" +} + +func (m *TokenPrice) GetOsmosisQuoteDenom() string { + if m != nil { + return m.OsmosisQuoteDenom + } + return "" +} + +func (m *TokenPrice) GetOsmosisPoolId() string { + if m != nil { + return m.OsmosisPoolId + } + return "" +} + +func (m *TokenPrice) GetUpdatedAt() time.Time { + if m != nil { + return m.UpdatedAt + } + return time.Time{} +} + +func (m *TokenPrice) GetQueryInProgress() bool { + if m != nil { + return m.QueryInProgress + } + return false +} + +// OracleParams stores global oracle parameters +type Params struct { + // Osmosis chain identifier + OsmosisChainId string `protobuf:"bytes,1,opt,name=osmosis_chain_id,json=osmosisChainId,proto3" json:"osmosis_chain_id" yaml:"osmosis_chain_id"` + // Osmosis IBC connection identifier + OsmosisConnectionId string `protobuf:"bytes,2,opt,name=osmosis_connection_id,json=osmosisConnectionId,proto3" json:"osmosis_connection_id" yaml:"osmosis_connection_id"` + // Time between price updates + UpdateIntervalSec uint64 `protobuf:"varint,3,opt,name=update_interval_sec,json=updateIntervalSec,proto3" json:"update_interval_sec" yaml:"update_interval_sec"` + // Max time before price is considered stale/expired + PriceExpirationTimeoutSec uint64 `protobuf:"varint,4,opt,name=price_expiration_timeout_sec,json=priceExpirationTimeoutSec,proto3" json:"price_expiration_timeout_sec" yaml:"price_expiration_timeout_sec"` + // ICQ timeout + IcqTimeoutSec uint64 `protobuf:"varint,5,opt,name=icq_timeout_sec,json=icqTimeoutSec,proto3" json:"icq_timeout_sec" yaml:"icq_timeout_sec"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_08ead8ab9516d7fc, []int{1} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetOsmosisChainId() string { + if m != nil { + return m.OsmosisChainId + } + return "" +} + +func (m *Params) GetOsmosisConnectionId() string { + if m != nil { + return m.OsmosisConnectionId + } + return "" +} + +func (m *Params) GetUpdateIntervalSec() uint64 { + if m != nil { + return m.UpdateIntervalSec + } + return 0 +} + +func (m *Params) GetPriceExpirationTimeoutSec() uint64 { + if m != nil { + return m.PriceExpirationTimeoutSec + } + return 0 +} + +func (m *Params) GetIcqTimeoutSec() uint64 { + if m != nil { + return m.IcqTimeoutSec + } + return 0 +} + +func init() { + proto.RegisterType((*TokenPrice)(nil), "stride.icqoracle.TokenPrice") + proto.RegisterType((*Params)(nil), "stride.icqoracle.Params") +} + +func init() { proto.RegisterFile("stride/icqoracle/icqoracle.proto", fileDescriptor_08ead8ab9516d7fc) } + +var fileDescriptor_08ead8ab9516d7fc = []byte{ + // 617 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x94, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x1b, 0xd6, 0x8d, 0xd5, 0xd3, 0xd8, 0x96, 0xf1, 0xa7, 0x94, 0x51, 0x57, 0x99, 0x84, + 0x26, 0xc4, 0x12, 0x69, 0x83, 0x03, 0xdc, 0xc8, 0x86, 0x50, 0xa5, 0x21, 0x95, 0x6c, 0x1c, 0xe0, + 0x12, 0xb9, 0x8e, 0xc9, 0xac, 0x35, 0x71, 0x1a, 0x3b, 0xd3, 0xfa, 0x09, 0xe0, 0xb8, 0x3b, 0x5f, + 0x68, 0xc7, 0x1d, 0x11, 0x07, 0x83, 0xb6, 0x5b, 0x8f, 0xfd, 0x04, 0x28, 0x76, 0xd2, 0x95, 0x52, + 0xed, 0x96, 0x3c, 0xbf, 0xc7, 0xef, 0x63, 0xbf, 0xaf, 0x65, 0xd0, 0xe2, 0x22, 0xa5, 0x01, 0x71, + 0x28, 0xee, 0xb3, 0x14, 0xe1, 0xde, 0xc4, 0x97, 0x9d, 0xa4, 0x4c, 0x30, 0x73, 0x55, 0x3b, 0xec, + 0xb1, 0xde, 0xb8, 0x1f, 0xb2, 0x90, 0x29, 0xe8, 0xe4, 0x5f, 0xda, 0xd7, 0x80, 0x21, 0x63, 0x61, + 0x8f, 0x38, 0xea, 0xaf, 0x9b, 0x7d, 0x75, 0x04, 0x8d, 0x08, 0x17, 0x28, 0x4a, 0xb4, 0xc1, 0xfa, + 0x36, 0x07, 0xc0, 0x11, 0x3b, 0x21, 0x71, 0x27, 0xa5, 0x98, 0x98, 0x4f, 0x01, 0xe8, 0x22, 0x4e, + 0xfc, 0x80, 0xc4, 0x2c, 0xaa, 0x1b, 0x2d, 0x63, 0xab, 0xe6, 0xd5, 0x72, 0x65, 0x3f, 0x17, 0x4c, + 0x08, 0x96, 0xfa, 0x19, 0x13, 0x25, 0xbf, 0xa3, 0x38, 0x50, 0x92, 0x36, 0xbc, 0x00, 0x26, 0xe3, + 0x11, 0xe3, 0x94, 0xfb, 0x13, 0x75, 0xe6, 0x94, 0x6f, 0xb5, 0x20, 0xee, 0xb8, 0x9c, 0x0d, 0xd6, + 0x4b, 0xf7, 0x64, 0xd9, 0xaa, 0xb2, 0xaf, 0x15, 0xe8, 0xe3, 0x4d, 0xf5, 0x67, 0x60, 0xa5, 0xf4, + 0x27, 0x8c, 0xf5, 0x7c, 0x1a, 0xd4, 0xe7, 0x95, 0x77, 0xb9, 0x90, 0x3b, 0x8c, 0xf5, 0xda, 0x81, + 0xe9, 0x02, 0xc0, 0x13, 0x26, 0xfc, 0x24, 0x3f, 0x53, 0x7d, 0x21, 0xb7, 0xb8, 0x9b, 0x17, 0x12, + 0x56, 0x7e, 0x49, 0xf8, 0x04, 0x2b, 0x2f, 0x0f, 0x4e, 0x6c, 0xca, 0x9c, 0x08, 0x89, 0x63, 0xfb, + 0x80, 0x84, 0x08, 0x0f, 0xf6, 0x09, 0xf6, 0x6a, 0xf9, 0x32, 0xdd, 0x89, 0x3d, 0x00, 0xb2, 0x24, + 0x40, 0x82, 0x04, 0x3e, 0x12, 0xf5, 0xbb, 0x2d, 0x63, 0x6b, 0x69, 0xa7, 0x61, 0xeb, 0x76, 0xda, + 0x65, 0x3b, 0xed, 0xa3, 0xb2, 0x9d, 0xee, 0x62, 0x5e, 0xff, 0xfc, 0x37, 0x34, 0xbc, 0x5a, 0xb1, + 0xee, 0xad, 0x30, 0x9f, 0x83, 0xb5, 0x7e, 0x46, 0xd2, 0x81, 0x4f, 0x63, 0x3f, 0x49, 0x59, 0x98, + 0x12, 0xce, 0xeb, 0x8b, 0x2d, 0x63, 0x6b, 0xd1, 0x5b, 0x51, 0xa0, 0x1d, 0x77, 0x0a, 0xd9, 0xfa, + 0x51, 0x05, 0x0b, 0x1d, 0x94, 0xa2, 0x88, 0x9b, 0x9f, 0x41, 0xd9, 0x2b, 0x1f, 0x1f, 0x23, 0x1a, + 0xe7, 0x07, 0x55, 0xb3, 0x70, 0x9d, 0xa1, 0x84, 0xff, 0xb1, 0x91, 0x84, 0x8f, 0x06, 0x28, 0xea, + 0xbd, 0xb1, 0xa6, 0x89, 0xe5, 0xdd, 0x2b, 0xa4, 0xbd, 0x5c, 0x69, 0x07, 0x66, 0x04, 0x1e, 0x8c, + 0x4d, 0x2c, 0x8e, 0x09, 0x16, 0x94, 0xa9, 0xfa, 0x6a, 0x96, 0xee, 0xeb, 0xa1, 0x84, 0xb3, 0x0d, + 0x23, 0x09, 0x37, 0xa6, 0x42, 0x26, 0xb1, 0xe5, 0x95, 0xa3, 0xdc, 0x1b, 0xcb, 0xed, 0xc0, 0x24, + 0x60, 0x5d, 0x77, 0xc3, 0xa7, 0xb1, 0x20, 0xe9, 0x29, 0xea, 0xf9, 0x9c, 0x60, 0x75, 0x21, 0xaa, + 0xee, 0xab, 0xa1, 0x84, 0xb3, 0xf0, 0x48, 0xc2, 0x86, 0x8e, 0x9a, 0x01, 0x2d, 0x6f, 0x4d, 0xab, + 0xed, 0x42, 0x3c, 0x24, 0xd8, 0xfc, 0x6e, 0x80, 0x0d, 0x35, 0x6c, 0x9f, 0x9c, 0x25, 0x34, 0x45, + 0x6a, 0x53, 0xf9, 0x55, 0x67, 0x99, 0x50, 0x81, 0x55, 0x15, 0xf8, 0x7e, 0x28, 0xe1, 0xad, 0xbe, + 0x91, 0x84, 0x9b, 0x3a, 0xf9, 0x36, 0x97, 0xe5, 0x3d, 0x56, 0xf8, 0xdd, 0x98, 0x1e, 0x69, 0x98, + 0x6f, 0xe5, 0x13, 0x58, 0xa1, 0xb8, 0xff, 0x4f, 0xf8, 0xbc, 0x0a, 0xdf, 0x1e, 0x4a, 0x38, 0x8d, + 0x46, 0x12, 0x3e, 0xd4, 0x79, 0x53, 0xc0, 0xf2, 0x96, 0x29, 0xee, 0xdf, 0x94, 0x75, 0x3f, 0x5c, + 0x5c, 0x35, 0x8d, 0xcb, 0xab, 0xa6, 0xf1, 0xe7, 0xaa, 0x69, 0x9c, 0x5f, 0x37, 0x2b, 0x97, 0xd7, + 0xcd, 0xca, 0xcf, 0xeb, 0x66, 0xe5, 0xcb, 0x6e, 0x48, 0xc5, 0x71, 0xd6, 0xb5, 0x31, 0x8b, 0x9c, + 0x43, 0xf5, 0x2a, 0x6c, 0x1f, 0xa0, 0x2e, 0x77, 0x8a, 0x37, 0xe4, 0x74, 0xe7, 0xa5, 0x73, 0x36, + 0xf1, 0x92, 0x88, 0x41, 0x42, 0x78, 0x77, 0x41, 0xdd, 0xe0, 0xdd, 0xbf, 0x01, 0x00, 0x00, 0xff, + 0xff, 0x4d, 0x8e, 0x4f, 0xd6, 0x6a, 0x04, 0x00, 0x00, +} + +func (m *TokenPrice) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TokenPrice) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TokenPrice) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.QueryInProgress { + i-- + if m.QueryInProgress { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x40 + } + n1, err1 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.UpdatedAt, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.UpdatedAt):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintIcqoracle(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x3a + { + size := m.SpotPrice.Size() + i -= size + if _, err := m.SpotPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintIcqoracle(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if len(m.OsmosisPoolId) > 0 { + i -= len(m.OsmosisPoolId) + copy(dAtA[i:], m.OsmosisPoolId) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.OsmosisPoolId))) + i-- + dAtA[i] = 0x2a + } + if len(m.OsmosisQuoteDenom) > 0 { + i -= len(m.OsmosisQuoteDenom) + copy(dAtA[i:], m.OsmosisQuoteDenom) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.OsmosisQuoteDenom))) + i-- + dAtA[i] = 0x22 + } + if len(m.OsmosisBaseDenom) > 0 { + i -= len(m.OsmosisBaseDenom) + copy(dAtA[i:], m.OsmosisBaseDenom) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.OsmosisBaseDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.QuoteDenom) > 0 { + i -= len(m.QuoteDenom) + copy(dAtA[i:], m.QuoteDenom) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.QuoteDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.BaseDenom) > 0 { + i -= len(m.BaseDenom) + copy(dAtA[i:], m.BaseDenom) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.BaseDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.IcqTimeoutSec != 0 { + i = encodeVarintIcqoracle(dAtA, i, uint64(m.IcqTimeoutSec)) + i-- + dAtA[i] = 0x28 + } + if m.PriceExpirationTimeoutSec != 0 { + i = encodeVarintIcqoracle(dAtA, i, uint64(m.PriceExpirationTimeoutSec)) + i-- + dAtA[i] = 0x20 + } + if m.UpdateIntervalSec != 0 { + i = encodeVarintIcqoracle(dAtA, i, uint64(m.UpdateIntervalSec)) + i-- + dAtA[i] = 0x18 + } + if len(m.OsmosisConnectionId) > 0 { + i -= len(m.OsmosisConnectionId) + copy(dAtA[i:], m.OsmosisConnectionId) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.OsmosisConnectionId))) + i-- + dAtA[i] = 0x12 + } + if len(m.OsmosisChainId) > 0 { + i -= len(m.OsmosisChainId) + copy(dAtA[i:], m.OsmosisChainId) + i = encodeVarintIcqoracle(dAtA, i, uint64(len(m.OsmosisChainId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintIcqoracle(dAtA []byte, offset int, v uint64) int { + offset -= sovIcqoracle(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *TokenPrice) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BaseDenom) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + l = len(m.QuoteDenom) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + l = len(m.OsmosisBaseDenom) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + l = len(m.OsmosisQuoteDenom) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + l = len(m.OsmosisPoolId) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + l = m.SpotPrice.Size() + n += 1 + l + sovIcqoracle(uint64(l)) + l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.UpdatedAt) + n += 1 + l + sovIcqoracle(uint64(l)) + if m.QueryInProgress { + n += 2 + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OsmosisChainId) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + l = len(m.OsmosisConnectionId) + if l > 0 { + n += 1 + l + sovIcqoracle(uint64(l)) + } + if m.UpdateIntervalSec != 0 { + n += 1 + sovIcqoracle(uint64(m.UpdateIntervalSec)) + } + if m.PriceExpirationTimeoutSec != 0 { + n += 1 + sovIcqoracle(uint64(m.PriceExpirationTimeoutSec)) + } + if m.IcqTimeoutSec != 0 { + n += 1 + sovIcqoracle(uint64(m.IcqTimeoutSec)) + } + return n +} + +func sovIcqoracle(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozIcqoracle(x uint64) (n int) { + return sovIcqoracle(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *TokenPrice) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TokenPrice: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TokenPrice: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisBaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisBaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisQuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisQuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisPoolId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisPoolId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpotPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SpotPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdatedAt", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.UpdatedAt, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field QueryInProgress", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.QueryInProgress = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipIcqoracle(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthIcqoracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisChainId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisChainId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisConnectionId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthIcqoracle + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthIcqoracle + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisConnectionId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UpdateIntervalSec", wireType) + } + m.UpdateIntervalSec = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UpdateIntervalSec |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PriceExpirationTimeoutSec", wireType) + } + m.PriceExpirationTimeoutSec = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PriceExpirationTimeoutSec |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IcqTimeoutSec", wireType) + } + m.IcqTimeoutSec = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IcqTimeoutSec |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipIcqoracle(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthIcqoracle + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipIcqoracle(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowIcqoracle + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthIcqoracle + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupIcqoracle + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthIcqoracle + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthIcqoracle = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowIcqoracle = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupIcqoracle = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqoracle/types/keys.go b/x/icqoracle/types/keys.go new file mode 100644 index 0000000000..db3fc06fe0 --- /dev/null +++ b/x/icqoracle/types/keys.go @@ -0,0 +1,26 @@ +package types + +import fmt "fmt" + +const ( + ModuleName = "icqoracle" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the routing key + RouterKey = ModuleName +) + +var ( + ParamsKey = []byte("params") + PriceQueryPrefix = []byte("pricequery") +) + +func TokenPriceQueryKey(baseDenom, quoteDenom, poolId string) []byte { + return []byte(fmt.Sprintf("%s|%s|%s", baseDenom, quoteDenom, poolId)) +} + +func TokenPriceByDenomKey(baseDenom string) []byte { + return []byte(baseDenom) +} diff --git a/x/icqoracle/types/msgs.go b/x/icqoracle/types/msgs.go new file mode 100644 index 0000000000..e3b21b6551 --- /dev/null +++ b/x/icqoracle/types/msgs.go @@ -0,0 +1,125 @@ +package types + +import ( + "errors" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + + "github.com/Stride-Labs/stride/v24/utils" +) + +const ( + TypeMsgRegisterTokenPriceQuery = "register_token_price_query" + TypeMsgRemoveTokenPriceQuery = "remove_token_price_query" +) + +var ( + _ sdk.Msg = &MsgRegisterTokenPriceQuery{} + _ sdk.Msg = &MsgRemoveTokenPriceQuery{} + + // Implement legacy interface for ledger support + _ legacytx.LegacyMsg = &MsgRegisterTokenPriceQuery{} + _ legacytx.LegacyMsg = &MsgRemoveTokenPriceQuery{} +) + +// ---------------------------------------------- +// MsgClaim +// ---------------------------------------------- + +func NewMsgRegisterTokenPriceQuery(admin, baseDenom, quoteDenom, poolId, osmosisBaseDenom, osmosisQuoteDenom string) *MsgRegisterTokenPriceQuery { + return &MsgRegisterTokenPriceQuery{ + Admin: admin, + BaseDenom: baseDenom, + QuoteDenom: quoteDenom, + OsmosisPoolId: poolId, + OsmosisBaseDenom: osmosisBaseDenom, + OsmosisQuoteDenom: osmosisQuoteDenom, + } +} + +func (msg MsgRegisterTokenPriceQuery) Type() string { + return TypeMsgRegisterTokenPriceQuery +} + +func (msg MsgRegisterTokenPriceQuery) Route() string { + return RouterKey +} + +func (msg *MsgRegisterTokenPriceQuery) GetSigners() []sdk.AccAddress { + sender, err := sdk.AccAddressFromBech32(msg.Admin) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sender} +} + +func (msg *MsgRegisterTokenPriceQuery) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRegisterTokenPriceQuery) ValidateBasic() error { + if err := utils.ValidateAdminAddress(msg.Admin); err != nil { + return err + } + return ValidateTokenPriceQueryParams( + msg.BaseDenom, + msg.QuoteDenom, + msg.OsmosisPoolId, + msg.OsmosisBaseDenom, + msg.OsmosisQuoteDenom, + ) +} + +// ---------------------------------------------- +// MsgRemoveTokenPriceQuery +// ---------------------------------------------- + +func NewMsgRemoveTokenPriceQuery(admin, baseDenom, quoteDenom, osmosisPoolId string) *MsgRemoveTokenPriceQuery { + return &MsgRemoveTokenPriceQuery{ + Admin: admin, + BaseDenom: baseDenom, + QuoteDenom: quoteDenom, + OsmosisPoolId: osmosisPoolId, + } +} + +func (msg MsgRemoveTokenPriceQuery) Type() string { + return TypeMsgRemoveTokenPriceQuery +} + +func (msg MsgRemoveTokenPriceQuery) Route() string { + return RouterKey +} + +func (msg *MsgRemoveTokenPriceQuery) GetSigners() []sdk.AccAddress { + sender, err := sdk.AccAddressFromBech32(msg.Admin) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sender} +} + +func (msg *MsgRemoveTokenPriceQuery) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRemoveTokenPriceQuery) ValidateBasic() error { + if err := utils.ValidateAdminAddress(msg.Admin); err != nil { + return err + } + if msg.BaseDenom == "" { + return errors.New("base-denom must be specified") + } + if msg.QuoteDenom == "" { + return errors.New("quote-denom must be specified") + } + if _, err := strconv.ParseUint(msg.OsmosisPoolId, 10, 64); err != nil { + return errors.New("osmosis-pool-id must be uint64") + } + + return nil +} diff --git a/x/icqoracle/types/params.go b/x/icqoracle/types/params.go new file mode 100644 index 0000000000..874012a4b8 --- /dev/null +++ b/x/icqoracle/types/params.go @@ -0,0 +1,16 @@ +package types + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams() +} + +// Validate validates the set of params +func (p Params) Validate() error { + return nil +} diff --git a/x/icqoracle/types/query.pb.go b/x/icqoracle/types/query.pb.go new file mode 100644 index 0000000000..f1628335b0 --- /dev/null +++ b/x/icqoracle/types/query.pb.go @@ -0,0 +1,1934 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/icqoracle/query.proto + +package types + +import ( + context "context" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryTokenPriceRequest is the request type for the Query/TokenPrice RPC +// method +type QueryTokenPriceRequest struct { + BaseDenom string `protobuf:"bytes,1,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"` + QuoteDenom string `protobuf:"bytes,2,opt,name=quote_denom,json=quoteDenom,proto3" json:"quote_denom,omitempty"` + PoolId string `protobuf:"bytes,3,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"` +} + +func (m *QueryTokenPriceRequest) Reset() { *m = QueryTokenPriceRequest{} } +func (m *QueryTokenPriceRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTokenPriceRequest) ProtoMessage() {} +func (*QueryTokenPriceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{0} +} +func (m *QueryTokenPriceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTokenPriceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTokenPriceRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTokenPriceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTokenPriceRequest.Merge(m, src) +} +func (m *QueryTokenPriceRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTokenPriceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTokenPriceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTokenPriceRequest proto.InternalMessageInfo + +func (m *QueryTokenPriceRequest) GetBaseDenom() string { + if m != nil { + return m.BaseDenom + } + return "" +} + +func (m *QueryTokenPriceRequest) GetQuoteDenom() string { + if m != nil { + return m.QuoteDenom + } + return "" +} + +func (m *QueryTokenPriceRequest) GetPoolId() string { + if m != nil { + return m.PoolId + } + return "" +} + +// QueryTokenPriceResponse is the response type for the Query/TokenPrice RPC +// method +type QueryTokenPriceResponse struct { + TokenPrice TokenPrice `protobuf:"bytes,1,opt,name=token_price,json=tokenPrice,proto3" json:"token_price"` +} + +func (m *QueryTokenPriceResponse) Reset() { *m = QueryTokenPriceResponse{} } +func (m *QueryTokenPriceResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTokenPriceResponse) ProtoMessage() {} +func (*QueryTokenPriceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{1} +} +func (m *QueryTokenPriceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTokenPriceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTokenPriceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTokenPriceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTokenPriceResponse.Merge(m, src) +} +func (m *QueryTokenPriceResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTokenPriceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTokenPriceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTokenPriceResponse proto.InternalMessageInfo + +func (m *QueryTokenPriceResponse) GetTokenPrice() TokenPrice { + if m != nil { + return m.TokenPrice + } + return TokenPrice{} +} + +// QueryTokenPricesRequest is the request type for the Query/TokenPrices RPC +// method +type QueryTokenPricesRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryTokenPricesRequest) Reset() { *m = QueryTokenPricesRequest{} } +func (m *QueryTokenPricesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTokenPricesRequest) ProtoMessage() {} +func (*QueryTokenPricesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{2} +} +func (m *QueryTokenPricesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTokenPricesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTokenPricesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTokenPricesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTokenPricesRequest.Merge(m, src) +} +func (m *QueryTokenPricesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTokenPricesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTokenPricesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTokenPricesRequest proto.InternalMessageInfo + +func (m *QueryTokenPricesRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryTokenPricesResponse is the response type for the Query/TokenPrices RPC +// method +type QueryTokenPricesResponse struct { + TokenPrices []TokenPrice `protobuf:"bytes,1,rep,name=token_prices,json=tokenPrices,proto3" json:"token_prices"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryTokenPricesResponse) Reset() { *m = QueryTokenPricesResponse{} } +func (m *QueryTokenPricesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTokenPricesResponse) ProtoMessage() {} +func (*QueryTokenPricesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{3} +} +func (m *QueryTokenPricesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTokenPricesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTokenPricesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTokenPricesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTokenPricesResponse.Merge(m, src) +} +func (m *QueryTokenPricesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTokenPricesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTokenPricesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTokenPricesResponse proto.InternalMessageInfo + +func (m *QueryTokenPricesResponse) GetTokenPrices() []TokenPrice { + if m != nil { + return m.TokenPrices + } + return nil +} + +func (m *QueryTokenPricesResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryParamsRequest is the request type for the Query/Params RPC method +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{4} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method +type QueryParamsResponse struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{5} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryTokenPriceForQuoteDenomRequest is the request type for the +// Query/TokenPriceForQuoteDenom RPC method +type QueryTokenPriceForQuoteDenomRequest struct { + BaseDenom string `protobuf:"bytes,1,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"` + QuoteDenom string `protobuf:"bytes,2,opt,name=quote_denom,json=quoteDenom,proto3" json:"quote_denom,omitempty"` +} + +func (m *QueryTokenPriceForQuoteDenomRequest) Reset() { *m = QueryTokenPriceForQuoteDenomRequest{} } +func (m *QueryTokenPriceForQuoteDenomRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTokenPriceForQuoteDenomRequest) ProtoMessage() {} +func (*QueryTokenPriceForQuoteDenomRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{6} +} +func (m *QueryTokenPriceForQuoteDenomRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTokenPriceForQuoteDenomRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTokenPriceForQuoteDenomRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTokenPriceForQuoteDenomRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTokenPriceForQuoteDenomRequest.Merge(m, src) +} +func (m *QueryTokenPriceForQuoteDenomRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTokenPriceForQuoteDenomRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTokenPriceForQuoteDenomRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTokenPriceForQuoteDenomRequest proto.InternalMessageInfo + +func (m *QueryTokenPriceForQuoteDenomRequest) GetBaseDenom() string { + if m != nil { + return m.BaseDenom + } + return "" +} + +func (m *QueryTokenPriceForQuoteDenomRequest) GetQuoteDenom() string { + if m != nil { + return m.QuoteDenom + } + return "" +} + +// QueryTokenPriceForQuoteDenomResponse is the response type for the +// Query/TokenPriceForQuoteDenom RPC method +type QueryTokenPriceForQuoteDenomResponse struct { + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price"` +} + +func (m *QueryTokenPriceForQuoteDenomResponse) Reset() { *m = QueryTokenPriceForQuoteDenomResponse{} } +func (m *QueryTokenPriceForQuoteDenomResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTokenPriceForQuoteDenomResponse) ProtoMessage() {} +func (*QueryTokenPriceForQuoteDenomResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_51a2bacbcf1e1cb4, []int{7} +} +func (m *QueryTokenPriceForQuoteDenomResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTokenPriceForQuoteDenomResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTokenPriceForQuoteDenomResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTokenPriceForQuoteDenomResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTokenPriceForQuoteDenomResponse.Merge(m, src) +} +func (m *QueryTokenPriceForQuoteDenomResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTokenPriceForQuoteDenomResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTokenPriceForQuoteDenomResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTokenPriceForQuoteDenomResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*QueryTokenPriceRequest)(nil), "stride.icqoracle.QueryTokenPriceRequest") + proto.RegisterType((*QueryTokenPriceResponse)(nil), "stride.icqoracle.QueryTokenPriceResponse") + proto.RegisterType((*QueryTokenPricesRequest)(nil), "stride.icqoracle.QueryTokenPricesRequest") + proto.RegisterType((*QueryTokenPricesResponse)(nil), "stride.icqoracle.QueryTokenPricesResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "stride.icqoracle.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "stride.icqoracle.QueryParamsResponse") + proto.RegisterType((*QueryTokenPriceForQuoteDenomRequest)(nil), "stride.icqoracle.QueryTokenPriceForQuoteDenomRequest") + proto.RegisterType((*QueryTokenPriceForQuoteDenomResponse)(nil), "stride.icqoracle.QueryTokenPriceForQuoteDenomResponse") +} + +func init() { proto.RegisterFile("stride/icqoracle/query.proto", fileDescriptor_51a2bacbcf1e1cb4) } + +var fileDescriptor_51a2bacbcf1e1cb4 = []byte{ + // 622 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xfb, 0x13, 0xd4, 0x09, 0x07, 0xb4, 0x54, 0xc4, 0x58, 0xa9, 0x13, 0x99, 0xb6, 0x94, + 0x4a, 0xf5, 0xaa, 0x29, 0xf4, 0x01, 0x42, 0x28, 0x42, 0xa2, 0x52, 0x1a, 0x38, 0x71, 0x20, 0xda, + 0x38, 0x2b, 0x63, 0x35, 0xf1, 0x3a, 0x5e, 0xa7, 0xd0, 0x6b, 0x0f, 0x9c, 0x91, 0x78, 0x0b, 0x2e, + 0xbc, 0x02, 0xc7, 0x1e, 0x2b, 0x71, 0x41, 0x1c, 0x2a, 0x94, 0xf0, 0x20, 0xc8, 0xbb, 0xeb, 0xfc, + 0xd4, 0x09, 0x09, 0x12, 0xa7, 0x6c, 0x66, 0xbe, 0x99, 0xf9, 0xe6, 0xdb, 0xcf, 0x0b, 0x05, 0x1e, + 0x85, 0x5e, 0x8b, 0x62, 0xcf, 0xe9, 0xb2, 0x90, 0x38, 0x6d, 0x8a, 0xbb, 0x3d, 0x1a, 0x9e, 0xdb, + 0x41, 0xc8, 0x22, 0x86, 0xee, 0xc8, 0xac, 0x3d, 0xcc, 0x1a, 0xa5, 0x14, 0x7e, 0x78, 0x92, 0x35, + 0xc6, 0xba, 0xcb, 0x5c, 0x26, 0x8e, 0x38, 0x3e, 0xa9, 0x68, 0xc1, 0x65, 0xcc, 0x6d, 0x53, 0x4c, + 0x02, 0x0f, 0x13, 0xdf, 0x67, 0x11, 0x89, 0x3c, 0xe6, 0x73, 0x95, 0xdd, 0x75, 0x18, 0xef, 0x30, + 0x8e, 0x9b, 0x84, 0x2b, 0x02, 0xf8, 0x6c, 0xbf, 0x49, 0x23, 0xb2, 0x8f, 0x03, 0xe2, 0x7a, 0xbe, + 0x00, 0x4b, 0xac, 0xd5, 0x85, 0x7b, 0x27, 0x31, 0xe2, 0x35, 0x3b, 0xa5, 0x7e, 0x2d, 0xf4, 0x1c, + 0x5a, 0xa7, 0xdd, 0x1e, 0xe5, 0x11, 0xda, 0x00, 0x88, 0x1b, 0x34, 0x5a, 0xd4, 0x67, 0x1d, 0x5d, + 0x2b, 0x69, 0x3b, 0x6b, 0xf5, 0xb5, 0x38, 0x52, 0x8d, 0x03, 0xa8, 0x08, 0xb9, 0x6e, 0x8f, 0x45, + 0x49, 0x7e, 0x49, 0xe4, 0x41, 0x84, 0x24, 0x20, 0x0f, 0xb7, 0x02, 0xc6, 0xda, 0x0d, 0xaf, 0xa5, + 0x2f, 0x8b, 0x64, 0x36, 0xfe, 0xfb, 0xa2, 0x65, 0xbd, 0x85, 0x7c, 0x6a, 0x24, 0x0f, 0x98, 0xcf, + 0x29, 0x7a, 0x0a, 0xb9, 0x28, 0x8e, 0x36, 0x82, 0x38, 0x2c, 0x86, 0xe6, 0xca, 0x05, 0xfb, 0xa6, + 0x6e, 0xf6, 0xa8, 0xb4, 0xb2, 0x72, 0x79, 0x5d, 0xcc, 0xd4, 0x21, 0x1a, 0x46, 0x2c, 0x92, 0xea, + 0xcf, 0x93, 0x9d, 0x8e, 0x00, 0x46, 0x0a, 0xa8, 0xf6, 0xdb, 0xb6, 0x94, 0xcb, 0x8e, 0x77, 0xb3, + 0xe5, 0x7d, 0x29, 0xb9, 0xec, 0x1a, 0x71, 0x13, 0x3d, 0xea, 0x63, 0x95, 0xd6, 0x17, 0x0d, 0xf4, + 0xf4, 0x0c, 0xb5, 0xc4, 0x33, 0xb8, 0x3d, 0xb6, 0x04, 0xd7, 0xb5, 0xd2, 0xf2, 0x82, 0x5b, 0xe4, + 0x46, 0x5b, 0x70, 0xf4, 0x7c, 0x82, 0xeb, 0x92, 0xe0, 0xfa, 0x70, 0x2e, 0x57, 0xc9, 0x61, 0x82, + 0xec, 0x3a, 0x20, 0xc1, 0xb5, 0x46, 0x42, 0xd2, 0x49, 0xa4, 0xb0, 0x8e, 0xe1, 0xee, 0x44, 0x54, + 0x91, 0x3f, 0x84, 0x6c, 0x20, 0x22, 0x4a, 0x1d, 0x3d, 0x4d, 0x5b, 0x56, 0x28, 0xca, 0x0a, 0x6d, + 0x51, 0x78, 0x70, 0x43, 0x90, 0x23, 0x16, 0x9e, 0x0c, 0xdd, 0xf0, 0x9f, 0x4c, 0x65, 0xb5, 0x61, + 0xf3, 0xef, 0x63, 0xd4, 0x1a, 0x55, 0x58, 0x1d, 0x59, 0x68, 0xad, 0x62, 0xc7, 0x5c, 0x7f, 0x5e, + 0x17, 0xb7, 0x5d, 0x2f, 0x7a, 0xd7, 0x6b, 0xda, 0x0e, 0xeb, 0x60, 0xf5, 0x91, 0xc8, 0x9f, 0x3d, + 0xde, 0x3a, 0xc5, 0xd1, 0x79, 0x40, 0xb9, 0x5d, 0xa5, 0x4e, 0x5d, 0x16, 0x97, 0xbf, 0xad, 0xc0, + 0xaa, 0x18, 0x87, 0x2e, 0x34, 0x80, 0xd1, 0x4c, 0xb4, 0x93, 0x56, 0x65, 0xfa, 0x57, 0x64, 0x3c, + 0x5a, 0x00, 0x29, 0x39, 0x5b, 0xc5, 0x8b, 0xef, 0xbf, 0x3f, 0x2f, 0xdd, 0x47, 0x79, 0x9c, 0x7a, + 0x15, 0x04, 0x1d, 0xf4, 0x51, 0x83, 0xdc, 0x98, 0xe1, 0xd0, 0xfc, 0xde, 0xc9, 0x6d, 0x1b, 0xbb, + 0x8b, 0x40, 0x15, 0x8f, 0x92, 0xe0, 0x61, 0x20, 0x7d, 0x06, 0x0f, 0x8e, 0xde, 0x43, 0x56, 0x9a, + 0x00, 0x6d, 0xce, 0xe8, 0x3b, 0xe1, 0x35, 0x63, 0x6b, 0x0e, 0x6a, 0x81, 0xc1, 0x72, 0xdc, 0x57, + 0x0d, 0xf2, 0x33, 0xae, 0x1e, 0x3d, 0x99, 0xbb, 0xe2, 0x34, 0x47, 0x1a, 0x87, 0xff, 0x5a, 0xa6, + 0xc8, 0x6e, 0x09, 0xb2, 0x45, 0xb4, 0x81, 0xa7, 0xbc, 0xf9, 0xb1, 0x85, 0x85, 0x56, 0x95, 0xe3, + 0xcb, 0xbe, 0xa9, 0x5d, 0xf5, 0x4d, 0xed, 0x57, 0xdf, 0xd4, 0x3e, 0x0d, 0xcc, 0xcc, 0xd5, 0xc0, + 0xcc, 0xfc, 0x18, 0x98, 0x99, 0x37, 0x07, 0x63, 0x5e, 0x7c, 0x25, 0x5a, 0xec, 0xbd, 0x24, 0x4d, + 0x9e, 0xb4, 0x3b, 0x2b, 0x3f, 0xc6, 0x1f, 0xc6, 0x9a, 0x0a, 0x73, 0x36, 0xb3, 0xe2, 0xd5, 0x3e, + 0xf8, 0x13, 0x00, 0x00, 0xff, 0xff, 0x8d, 0xcb, 0x26, 0x10, 0x69, 0x06, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // TokenPrice queries the current price for a specific token + TokenPrice(ctx context.Context, in *QueryTokenPriceRequest, opts ...grpc.CallOption) (*QueryTokenPriceResponse, error) + // TokenPrices queries all token prices + TokenPrices(ctx context.Context, in *QueryTokenPricesRequest, opts ...grpc.CallOption) (*QueryTokenPricesResponse, error) + // Params queries the oracle parameters + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // TokenPriceForQuoteDenom queries the exchange rate between two tokens + TokenPriceForQuoteDenom(ctx context.Context, in *QueryTokenPriceForQuoteDenomRequest, opts ...grpc.CallOption) (*QueryTokenPriceForQuoteDenomResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) TokenPrice(ctx context.Context, in *QueryTokenPriceRequest, opts ...grpc.CallOption) (*QueryTokenPriceResponse, error) { + out := new(QueryTokenPriceResponse) + err := c.cc.Invoke(ctx, "/stride.icqoracle.Query/TokenPrice", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TokenPrices(ctx context.Context, in *QueryTokenPricesRequest, opts ...grpc.CallOption) (*QueryTokenPricesResponse, error) { + out := new(QueryTokenPricesResponse) + err := c.cc.Invoke(ctx, "/stride.icqoracle.Query/TokenPrices", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/stride.icqoracle.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TokenPriceForQuoteDenom(ctx context.Context, in *QueryTokenPriceForQuoteDenomRequest, opts ...grpc.CallOption) (*QueryTokenPriceForQuoteDenomResponse, error) { + out := new(QueryTokenPriceForQuoteDenomResponse) + err := c.cc.Invoke(ctx, "/stride.icqoracle.Query/TokenPriceForQuoteDenom", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // TokenPrice queries the current price for a specific token + TokenPrice(context.Context, *QueryTokenPriceRequest) (*QueryTokenPriceResponse, error) + // TokenPrices queries all token prices + TokenPrices(context.Context, *QueryTokenPricesRequest) (*QueryTokenPricesResponse, error) + // Params queries the oracle parameters + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // TokenPriceForQuoteDenom queries the exchange rate between two tokens + TokenPriceForQuoteDenom(context.Context, *QueryTokenPriceForQuoteDenomRequest) (*QueryTokenPriceForQuoteDenomResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) TokenPrice(ctx context.Context, req *QueryTokenPriceRequest) (*QueryTokenPriceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TokenPrice not implemented") +} +func (*UnimplementedQueryServer) TokenPrices(ctx context.Context, req *QueryTokenPricesRequest) (*QueryTokenPricesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TokenPrices not implemented") +} +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) TokenPriceForQuoteDenom(ctx context.Context, req *QueryTokenPriceForQuoteDenomRequest) (*QueryTokenPriceForQuoteDenomResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TokenPriceForQuoteDenom not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_TokenPrice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTokenPriceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TokenPrice(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.icqoracle.Query/TokenPrice", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TokenPrice(ctx, req.(*QueryTokenPriceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TokenPrices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTokenPricesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TokenPrices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.icqoracle.Query/TokenPrices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TokenPrices(ctx, req.(*QueryTokenPricesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.icqoracle.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TokenPriceForQuoteDenom_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTokenPriceForQuoteDenomRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TokenPriceForQuoteDenom(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.icqoracle.Query/TokenPriceForQuoteDenom", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TokenPriceForQuoteDenom(ctx, req.(*QueryTokenPriceForQuoteDenomRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.icqoracle.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "TokenPrice", + Handler: _Query_TokenPrice_Handler, + }, + { + MethodName: "TokenPrices", + Handler: _Query_TokenPrices_Handler, + }, + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "TokenPriceForQuoteDenom", + Handler: _Query_TokenPriceForQuoteDenom_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stride/icqoracle/query.proto", +} + +func (m *QueryTokenPriceRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTokenPriceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTokenPriceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PoolId) > 0 { + i -= len(m.PoolId) + copy(dAtA[i:], m.PoolId) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PoolId))) + i-- + dAtA[i] = 0x1a + } + if len(m.QuoteDenom) > 0 { + i -= len(m.QuoteDenom) + copy(dAtA[i:], m.QuoteDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuoteDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.BaseDenom) > 0 { + i -= len(m.BaseDenom) + copy(dAtA[i:], m.BaseDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTokenPriceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTokenPriceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTokenPriceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.TokenPrice.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryTokenPricesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTokenPricesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTokenPricesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTokenPricesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTokenPricesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTokenPricesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.TokenPrices) > 0 { + for iNdEx := len(m.TokenPrices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TokenPrices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryTokenPriceForQuoteDenomRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTokenPriceForQuoteDenomRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTokenPriceForQuoteDenomRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.QuoteDenom) > 0 { + i -= len(m.QuoteDenom) + copy(dAtA[i:], m.QuoteDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuoteDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.BaseDenom) > 0 { + i -= len(m.BaseDenom) + copy(dAtA[i:], m.BaseDenom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.BaseDenom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTokenPriceForQuoteDenomResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTokenPriceForQuoteDenomResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTokenPriceForQuoteDenomResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Price.Size() + i -= size + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryTokenPriceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BaseDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.QuoteDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.PoolId) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTokenPriceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.TokenPrice.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryTokenPricesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTokenPricesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.TokenPrices) > 0 { + for _, e := range m.TokenPrices { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryTokenPriceForQuoteDenomRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.BaseDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.QuoteDenom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTokenPriceForQuoteDenomResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Price.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryTokenPriceRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTokenPriceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTokenPriceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PoolId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTokenPriceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTokenPriceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTokenPriceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TokenPrice", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TokenPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTokenPricesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTokenPricesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTokenPricesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTokenPricesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTokenPricesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTokenPricesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TokenPrices", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TokenPrices = append(m.TokenPrices, TokenPrice{}) + if err := m.TokenPrices[len(m.TokenPrices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTokenPriceForQuoteDenomRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTokenPriceForQuoteDenomRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTokenPriceForQuoteDenomRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTokenPriceForQuoteDenomResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTokenPriceForQuoteDenomResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTokenPriceForQuoteDenomResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqoracle/types/query.pb.gw.go b/x/icqoracle/types/query.pb.gw.go new file mode 100644 index 0000000000..26446a8d16 --- /dev/null +++ b/x/icqoracle/types/query.pb.gw.go @@ -0,0 +1,402 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stride/icqoracle/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_TokenPrice_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_TokenPrice_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTokenPriceRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TokenPrice_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.TokenPrice(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TokenPrice_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTokenPriceRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TokenPrice_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.TokenPrice(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_TokenPrices_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_TokenPrices_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTokenPricesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TokenPrices_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.TokenPrices(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TokenPrices_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTokenPricesRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TokenPrices_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.TokenPrices(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_TokenPriceForQuoteDenom_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_TokenPriceForQuoteDenom_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTokenPriceForQuoteDenomRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TokenPriceForQuoteDenom_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.TokenPriceForQuoteDenom(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TokenPriceForQuoteDenom_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTokenPriceForQuoteDenomRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TokenPriceForQuoteDenom_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.TokenPriceForQuoteDenom(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_TokenPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_TokenPrice_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TokenPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TokenPrices_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_TokenPrices_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TokenPrices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TokenPriceForQuoteDenom_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_TokenPriceForQuoteDenom_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TokenPriceForQuoteDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_TokenPrice_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_TokenPrice_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TokenPrice_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TokenPrices_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_TokenPrices_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TokenPrices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TokenPriceForQuoteDenom_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_TokenPriceForQuoteDenom_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TokenPriceForQuoteDenom_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_TokenPrice_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "icqoracle", "price"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_TokenPrices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "icqoracle", "prices"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "icqoracle", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_TokenPriceForQuoteDenom_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "icqoracle", "quote_price"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_TokenPrice_0 = runtime.ForwardResponseMessage + + forward_Query_TokenPrices_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_TokenPriceForQuoteDenom_0 = runtime.ForwardResponseMessage +) diff --git a/x/icqoracle/types/tx.pb.go b/x/icqoracle/types/tx.pb.go new file mode 100644 index 0000000000..8dee348ce7 --- /dev/null +++ b/x/icqoracle/types/tx.pb.go @@ -0,0 +1,1290 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/icqoracle/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgRegisterTokenPriceQuery defines the message for adding a new token to +// track prices +type MsgRegisterTokenPriceQuery struct { + Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` + // Token denom on Stride + BaseDenom string `protobuf:"bytes,2,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"` + // Quote denom on Stride + QuoteDenom string `protobuf:"bytes,3,opt,name=quote_denom,json=quoteDenom,proto3" json:"quote_denom,omitempty"` + // Token denom on Osmosis + OsmosisBaseDenom string `protobuf:"bytes,4,opt,name=osmosis_base_denom,json=osmosisBaseDenom,proto3" json:"osmosis_base_denom,omitempty"` + // Quote denom on Osmosis + OsmosisQuoteDenom string `protobuf:"bytes,5,opt,name=osmosis_quote_denom,json=osmosisQuoteDenom,proto3" json:"osmosis_quote_denom,omitempty"` + // Pool ID on Osmosis + OsmosisPoolId string `protobuf:"bytes,6,opt,name=osmosis_pool_id,json=osmosisPoolId,proto3" json:"osmosis_pool_id,omitempty"` +} + +func (m *MsgRegisterTokenPriceQuery) Reset() { *m = MsgRegisterTokenPriceQuery{} } +func (m *MsgRegisterTokenPriceQuery) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterTokenPriceQuery) ProtoMessage() {} +func (*MsgRegisterTokenPriceQuery) Descriptor() ([]byte, []int) { + return fileDescriptor_be640eb75c1babd5, []int{0} +} +func (m *MsgRegisterTokenPriceQuery) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterTokenPriceQuery) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterTokenPriceQuery.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRegisterTokenPriceQuery) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterTokenPriceQuery.Merge(m, src) +} +func (m *MsgRegisterTokenPriceQuery) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterTokenPriceQuery) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterTokenPriceQuery.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterTokenPriceQuery proto.InternalMessageInfo + +func (m *MsgRegisterTokenPriceQuery) GetAdmin() string { + if m != nil { + return m.Admin + } + return "" +} + +func (m *MsgRegisterTokenPriceQuery) GetBaseDenom() string { + if m != nil { + return m.BaseDenom + } + return "" +} + +func (m *MsgRegisterTokenPriceQuery) GetQuoteDenom() string { + if m != nil { + return m.QuoteDenom + } + return "" +} + +func (m *MsgRegisterTokenPriceQuery) GetOsmosisBaseDenom() string { + if m != nil { + return m.OsmosisBaseDenom + } + return "" +} + +func (m *MsgRegisterTokenPriceQuery) GetOsmosisQuoteDenom() string { + if m != nil { + return m.OsmosisQuoteDenom + } + return "" +} + +func (m *MsgRegisterTokenPriceQuery) GetOsmosisPoolId() string { + if m != nil { + return m.OsmosisPoolId + } + return "" +} + +type MsgRegisterTokenPriceQueryResponse struct { +} + +func (m *MsgRegisterTokenPriceQueryResponse) Reset() { *m = MsgRegisterTokenPriceQueryResponse{} } +func (m *MsgRegisterTokenPriceQueryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterTokenPriceQueryResponse) ProtoMessage() {} +func (*MsgRegisterTokenPriceQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_be640eb75c1babd5, []int{1} +} +func (m *MsgRegisterTokenPriceQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterTokenPriceQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterTokenPriceQueryResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRegisterTokenPriceQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterTokenPriceQueryResponse.Merge(m, src) +} +func (m *MsgRegisterTokenPriceQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterTokenPriceQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterTokenPriceQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterTokenPriceQueryResponse proto.InternalMessageInfo + +// MsgRemoveTokenPriceQuery defines the message for removing a token from price +// tracking +type MsgRemoveTokenPriceQuery struct { + Admin string `protobuf:"bytes,1,opt,name=admin,proto3" json:"admin,omitempty"` + // Token denom on Stride + BaseDenom string `protobuf:"bytes,2,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"` + // Quote denom on Stride + QuoteDenom string `protobuf:"bytes,3,opt,name=quote_denom,json=quoteDenom,proto3" json:"quote_denom,omitempty"` + // Pool ID on Osmosis + OsmosisPoolId string `protobuf:"bytes,4,opt,name=osmosis_pool_id,json=osmosisPoolId,proto3" json:"osmosis_pool_id,omitempty"` +} + +func (m *MsgRemoveTokenPriceQuery) Reset() { *m = MsgRemoveTokenPriceQuery{} } +func (m *MsgRemoveTokenPriceQuery) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveTokenPriceQuery) ProtoMessage() {} +func (*MsgRemoveTokenPriceQuery) Descriptor() ([]byte, []int) { + return fileDescriptor_be640eb75c1babd5, []int{2} +} +func (m *MsgRemoveTokenPriceQuery) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveTokenPriceQuery) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveTokenPriceQuery.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveTokenPriceQuery) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveTokenPriceQuery.Merge(m, src) +} +func (m *MsgRemoveTokenPriceQuery) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveTokenPriceQuery) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveTokenPriceQuery.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveTokenPriceQuery proto.InternalMessageInfo + +func (m *MsgRemoveTokenPriceQuery) GetAdmin() string { + if m != nil { + return m.Admin + } + return "" +} + +func (m *MsgRemoveTokenPriceQuery) GetBaseDenom() string { + if m != nil { + return m.BaseDenom + } + return "" +} + +func (m *MsgRemoveTokenPriceQuery) GetQuoteDenom() string { + if m != nil { + return m.QuoteDenom + } + return "" +} + +func (m *MsgRemoveTokenPriceQuery) GetOsmosisPoolId() string { + if m != nil { + return m.OsmosisPoolId + } + return "" +} + +type MsgRemoveTokenPriceQueryResponse struct { +} + +func (m *MsgRemoveTokenPriceQueryResponse) Reset() { *m = MsgRemoveTokenPriceQueryResponse{} } +func (m *MsgRemoveTokenPriceQueryResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveTokenPriceQueryResponse) ProtoMessage() {} +func (*MsgRemoveTokenPriceQueryResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_be640eb75c1babd5, []int{3} +} +func (m *MsgRemoveTokenPriceQueryResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveTokenPriceQueryResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveTokenPriceQueryResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveTokenPriceQueryResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveTokenPriceQueryResponse.Merge(m, src) +} +func (m *MsgRemoveTokenPriceQueryResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveTokenPriceQueryResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveTokenPriceQueryResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveTokenPriceQueryResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgRegisterTokenPriceQuery)(nil), "stride.icqoracle.MsgRegisterTokenPriceQuery") + proto.RegisterType((*MsgRegisterTokenPriceQueryResponse)(nil), "stride.icqoracle.MsgRegisterTokenPriceQueryResponse") + proto.RegisterType((*MsgRemoveTokenPriceQuery)(nil), "stride.icqoracle.MsgRemoveTokenPriceQuery") + proto.RegisterType((*MsgRemoveTokenPriceQueryResponse)(nil), "stride.icqoracle.MsgRemoveTokenPriceQueryResponse") +} + +func init() { proto.RegisterFile("stride/icqoracle/tx.proto", fileDescriptor_be640eb75c1babd5) } + +var fileDescriptor_be640eb75c1babd5 = []byte{ + // 466 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x94, 0x4f, 0x6b, 0xd4, 0x40, + 0x18, 0xc6, 0x37, 0xdb, 0x6e, 0xa1, 0xaf, 0x88, 0x6d, 0x54, 0x9a, 0x06, 0x8c, 0x25, 0x14, 0x91, + 0xa5, 0xcd, 0xd0, 0xdd, 0x9e, 0xbc, 0xb9, 0x78, 0x11, 0x5c, 0x68, 0x53, 0x4f, 0x5e, 0x42, 0xfe, + 0x0c, 0x71, 0x70, 0x93, 0x37, 0x9d, 0xc9, 0xae, 0xed, 0x41, 0x10, 0xf1, 0xe4, 0xc9, 0x8f, 0xb2, + 0x07, 0xbf, 0x83, 0x1e, 0x8b, 0x27, 0x8f, 0xb2, 0x8b, 0xec, 0xd7, 0x90, 0xcc, 0x24, 0xed, 0xba, + 0x24, 0xa0, 0x27, 0x2f, 0xbb, 0xcc, 0xf3, 0xfc, 0xe6, 0x49, 0xe6, 0x99, 0xc9, 0xc0, 0xae, 0xc8, + 0x39, 0x8b, 0x28, 0x61, 0xe1, 0x39, 0x72, 0x3f, 0x1c, 0x51, 0x92, 0x5f, 0x38, 0x19, 0xc7, 0x1c, + 0xf5, 0x2d, 0x65, 0x39, 0xd7, 0x96, 0xb9, 0x13, 0xa2, 0x48, 0x50, 0x90, 0x44, 0xc4, 0x64, 0x72, + 0x54, 0xfc, 0x29, 0xd4, 0xdc, 0xf6, 0x13, 0x96, 0x22, 0x91, 0xbf, 0xa5, 0xb4, 0xab, 0x58, 0x4f, + 0x8e, 0x88, 0x1a, 0x28, 0xcb, 0xfe, 0xda, 0x06, 0x73, 0x28, 0x62, 0x97, 0xc6, 0x4c, 0xe4, 0x94, + 0xbf, 0xc4, 0x37, 0x34, 0x3d, 0xe1, 0x2c, 0xa4, 0xa7, 0x63, 0xca, 0x2f, 0x75, 0x07, 0x3a, 0x7e, + 0x94, 0xb0, 0xd4, 0xd0, 0xf6, 0xb4, 0xc7, 0x9b, 0x03, 0xe3, 0xfb, 0x97, 0xc3, 0x7b, 0xe5, 0xfc, + 0xa7, 0x51, 0xc4, 0xa9, 0x10, 0x67, 0x39, 0x67, 0x69, 0xec, 0x2a, 0x4c, 0x7f, 0x00, 0x10, 0xf8, + 0x82, 0x7a, 0x11, 0x4d, 0x31, 0x31, 0xda, 0xc5, 0x24, 0x77, 0xb3, 0x50, 0x9e, 0x15, 0x82, 0xfe, + 0x10, 0x6e, 0x9d, 0x8f, 0x31, 0xaf, 0xfc, 0x35, 0xe9, 0x83, 0x94, 0x14, 0x70, 0x00, 0xba, 0x4c, + 0x67, 0xc2, 0x5b, 0xca, 0x59, 0x97, 0xdc, 0x56, 0xe9, 0x0c, 0xae, 0xe3, 0x1c, 0xb8, 0x5b, 0xd1, + 0xcb, 0xb1, 0x1d, 0x89, 0x6f, 0x97, 0xd6, 0xe9, 0x4d, 0xfa, 0x23, 0xb8, 0x53, 0xf1, 0x19, 0xe2, + 0xc8, 0x63, 0x91, 0xb1, 0x21, 0xd9, 0xdb, 0xa5, 0x7c, 0x82, 0x38, 0x7a, 0x1e, 0x3d, 0xe9, 0x7f, + 0x58, 0x4c, 0xbb, 0x6a, 0x45, 0x9f, 0x16, 0xd3, 0xee, 0xfe, 0xcd, 0x86, 0x34, 0x57, 0x65, 0xef, + 0x83, 0xdd, 0xec, 0xba, 0x54, 0x64, 0x98, 0x0a, 0x6a, 0xff, 0xd2, 0xc0, 0x90, 0x58, 0x82, 0x13, + 0xfa, 0xbf, 0xdb, 0xae, 0xe9, 0x63, 0xbd, 0xae, 0x8f, 0xa3, 0x3f, 0xfb, 0xb0, 0x57, 0xfa, 0xa8, + 0x59, 0x8a, 0x6d, 0xc3, 0x5e, 0x93, 0x57, 0x75, 0xd1, 0xfb, 0xd8, 0x86, 0xb5, 0xa1, 0x88, 0xf5, + 0x77, 0xb0, 0xd3, 0x74, 0xfe, 0x0e, 0x9c, 0xd5, 0x83, 0xef, 0x34, 0x97, 0x6c, 0x1e, 0xff, 0x0b, + 0x5d, 0xbd, 0x86, 0xfe, 0x16, 0xee, 0xd7, 0x6f, 0x47, 0xb7, 0x21, 0xae, 0x86, 0x35, 0x7b, 0x7f, + 0xcf, 0x56, 0x0f, 0x36, 0x3b, 0xef, 0x17, 0xd3, 0xae, 0x36, 0x18, 0x7e, 0x9b, 0x59, 0xda, 0xd5, + 0xcc, 0xd2, 0x7e, 0xce, 0x2c, 0xed, 0xf3, 0xdc, 0x6a, 0x5d, 0xcd, 0xad, 0xd6, 0x8f, 0xb9, 0xd5, + 0x7a, 0xd5, 0x8f, 0x59, 0xfe, 0x7a, 0x1c, 0x38, 0x21, 0x26, 0xe4, 0x4c, 0xc6, 0x1f, 0xbe, 0xf0, + 0x03, 0x41, 0xca, 0x7b, 0x62, 0xd2, 0x3b, 0x26, 0x17, 0xcb, 0xb7, 0xc5, 0x65, 0x46, 0x45, 0xb0, + 0x21, 0x3f, 0xec, 0xfe, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe5, 0x44, 0x3a, 0x25, 0x4e, 0x04, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // RegisterTokenPriceQuery registers a new token to track prices for + RegisterTokenPriceQuery(ctx context.Context, in *MsgRegisterTokenPriceQuery, opts ...grpc.CallOption) (*MsgRegisterTokenPriceQueryResponse, error) + // RemoveTokenPriceQuery removes a token from price tracking + RemoveTokenPriceQuery(ctx context.Context, in *MsgRemoveTokenPriceQuery, opts ...grpc.CallOption) (*MsgRemoveTokenPriceQueryResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) RegisterTokenPriceQuery(ctx context.Context, in *MsgRegisterTokenPriceQuery, opts ...grpc.CallOption) (*MsgRegisterTokenPriceQueryResponse, error) { + out := new(MsgRegisterTokenPriceQueryResponse) + err := c.cc.Invoke(ctx, "/stride.icqoracle.Msg/RegisterTokenPriceQuery", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveTokenPriceQuery(ctx context.Context, in *MsgRemoveTokenPriceQuery, opts ...grpc.CallOption) (*MsgRemoveTokenPriceQueryResponse, error) { + out := new(MsgRemoveTokenPriceQueryResponse) + err := c.cc.Invoke(ctx, "/stride.icqoracle.Msg/RemoveTokenPriceQuery", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // RegisterTokenPriceQuery registers a new token to track prices for + RegisterTokenPriceQuery(context.Context, *MsgRegisterTokenPriceQuery) (*MsgRegisterTokenPriceQueryResponse, error) + // RemoveTokenPriceQuery removes a token from price tracking + RemoveTokenPriceQuery(context.Context, *MsgRemoveTokenPriceQuery) (*MsgRemoveTokenPriceQueryResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) RegisterTokenPriceQuery(ctx context.Context, req *MsgRegisterTokenPriceQuery) (*MsgRegisterTokenPriceQueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterTokenPriceQuery not implemented") +} +func (*UnimplementedMsgServer) RemoveTokenPriceQuery(ctx context.Context, req *MsgRemoveTokenPriceQuery) (*MsgRemoveTokenPriceQueryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveTokenPriceQuery not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_RegisterTokenPriceQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRegisterTokenPriceQuery) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterTokenPriceQuery(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.icqoracle.Msg/RegisterTokenPriceQuery", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterTokenPriceQuery(ctx, req.(*MsgRegisterTokenPriceQuery)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveTokenPriceQuery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveTokenPriceQuery) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveTokenPriceQuery(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.icqoracle.Msg/RemoveTokenPriceQuery", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveTokenPriceQuery(ctx, req.(*MsgRemoveTokenPriceQuery)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.icqoracle.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RegisterTokenPriceQuery", + Handler: _Msg_RegisterTokenPriceQuery_Handler, + }, + { + MethodName: "RemoveTokenPriceQuery", + Handler: _Msg_RemoveTokenPriceQuery_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stride/icqoracle/tx.proto", +} + +func (m *MsgRegisterTokenPriceQuery) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRegisterTokenPriceQuery) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterTokenPriceQuery) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.OsmosisPoolId) > 0 { + i -= len(m.OsmosisPoolId) + copy(dAtA[i:], m.OsmosisPoolId) + i = encodeVarintTx(dAtA, i, uint64(len(m.OsmosisPoolId))) + i-- + dAtA[i] = 0x32 + } + if len(m.OsmosisQuoteDenom) > 0 { + i -= len(m.OsmosisQuoteDenom) + copy(dAtA[i:], m.OsmosisQuoteDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.OsmosisQuoteDenom))) + i-- + dAtA[i] = 0x2a + } + if len(m.OsmosisBaseDenom) > 0 { + i -= len(m.OsmosisBaseDenom) + copy(dAtA[i:], m.OsmosisBaseDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.OsmosisBaseDenom))) + i-- + dAtA[i] = 0x22 + } + if len(m.QuoteDenom) > 0 { + i -= len(m.QuoteDenom) + copy(dAtA[i:], m.QuoteDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.QuoteDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.BaseDenom) > 0 { + i -= len(m.BaseDenom) + copy(dAtA[i:], m.BaseDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.BaseDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintTx(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterTokenPriceQueryResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRegisterTokenPriceQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterTokenPriceQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgRemoveTokenPriceQuery) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveTokenPriceQuery) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveTokenPriceQuery) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.OsmosisPoolId) > 0 { + i -= len(m.OsmosisPoolId) + copy(dAtA[i:], m.OsmosisPoolId) + i = encodeVarintTx(dAtA, i, uint64(len(m.OsmosisPoolId))) + i-- + dAtA[i] = 0x22 + } + if len(m.QuoteDenom) > 0 { + i -= len(m.QuoteDenom) + copy(dAtA[i:], m.QuoteDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.QuoteDenom))) + i-- + dAtA[i] = 0x1a + } + if len(m.BaseDenom) > 0 { + i -= len(m.BaseDenom) + copy(dAtA[i:], m.BaseDenom) + i = encodeVarintTx(dAtA, i, uint64(len(m.BaseDenom))) + i-- + dAtA[i] = 0x12 + } + if len(m.Admin) > 0 { + i -= len(m.Admin) + copy(dAtA[i:], m.Admin) + i = encodeVarintTx(dAtA, i, uint64(len(m.Admin))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveTokenPriceQueryResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveTokenPriceQueryResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveTokenPriceQueryResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgRegisterTokenPriceQuery) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BaseDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.QuoteDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.OsmosisBaseDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.OsmosisQuoteDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.OsmosisPoolId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterTokenPriceQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveTokenPriceQuery) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Admin) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.BaseDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.QuoteDenom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.OsmosisPoolId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveTokenPriceQueryResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgRegisterTokenPriceQuery) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRegisterTokenPriceQuery: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterTokenPriceQuery: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisBaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisBaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisQuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisQuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisPoolId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisPoolId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRegisterTokenPriceQueryResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRegisterTokenPriceQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterTokenPriceQueryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveTokenPriceQuery) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveTokenPriceQuery: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveTokenPriceQuery: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Admin", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Admin = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BaseDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuoteDenom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuoteDenom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OsmosisPoolId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OsmosisPoolId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveTokenPriceQueryResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveTokenPriceQueryResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveTokenPriceQueryResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/icqoracle/types/validate.go b/x/icqoracle/types/validate.go new file mode 100644 index 0000000000..a84a72984c --- /dev/null +++ b/x/icqoracle/types/validate.go @@ -0,0 +1,26 @@ +package types + +import ( + "errors" + "strconv" +) + +func ValidateTokenPriceQueryParams(baseDenom, quoteDenom, osmosisPoolId, osmosisBaseDenom, osmosisQuoteDenom string) error { + if baseDenom == "" { + return errors.New("base-denom must be specified") + } + if quoteDenom == "" { + return errors.New("quote-denom must be specified") + } + if _, err := strconv.ParseUint(osmosisPoolId, 10, 64); err != nil { + return errors.New("osmosis-pool-id must be uint64") + } + if osmosisBaseDenom == "" { + return errors.New("osmosis-base-denom must be specified") + } + if osmosisQuoteDenom == "" { + return errors.New("osmosis-quote-denom must be specified") + } + + return nil +} diff --git a/x/interchainquery/types/keys.go b/x/interchainquery/types/keys.go index 7da8303e94..e3ca5c9e4a 100644 --- a/x/interchainquery/types/keys.go +++ b/x/interchainquery/types/keys.go @@ -1,6 +1,9 @@ package types -import fmt "fmt" +import ( + fmt "fmt" + "strconv" +) const ( // ModuleName defines the module name @@ -35,6 +38,8 @@ const ( BANK_STORE_QUERY_WITH_PROOF = "store/bank/key" // The Osmosis twap store - key'd by the pool ID and denom's TWAP_STORE_QUERY_WITH_PROOF = "store/twap/key" + // The Osmosis concentrated liquidity store + CONCENTRATEDLIQUIDITY_STORE_QUERY_WITH_PROOF = "store/concentratedliquidity/key" ) var ( @@ -62,3 +67,17 @@ func FormatOsmosisMostRecentTWAPKey(poolId uint64, denom1, denom2 string) []byte poolIdBz := fmt.Sprintf("%0.20d", poolId) return []byte(fmt.Sprintf("%s%s%s%s%s%s", OsmosisMostRecentTWAPsPrefix, poolIdBz, OsmosisKeySeparator, denom1, OsmosisKeySeparator, denom2)) } + +// Source: https://github.com/osmosis-labs/osmosis/blob/v27.0.0/x/concentrated-liquidity/types/keys.go#L227-L235 +// Used by: https://github.com/osmosis-labs/osmosis/blob/v27.0.0/x/concentrated-liquidity/pool.go#L117-L130 +// Which is used by: https://github.com/osmosis-labs/osmosis/blob/v27.0.0/x/concentrated-liquidity/pool.go#L179-L209 +// +// Pool Prefix Keys +// keyPool is used to map a pool id to a pool struct +func FormatOsmosisKeyPool(poolId uint64) []byte { + // Start with PoolPrefix initialized + result := []byte{0x03} + // Directly append the string representation of poolId as bytes + result = strconv.AppendUint(result, poolId, 10) + return result +} diff --git a/x/strdburner/client/cli/query.go b/x/strdburner/client/cli/query.go new file mode 100644 index 0000000000..81c5475540 --- /dev/null +++ b/x/strdburner/client/cli/query.go @@ -0,0 +1,51 @@ +package cli + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + + "github.com/Stride-Labs/stride/v24/x/strdburner/types" +) + +// GetQueryCmd returns the cli query commands for this module. +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdQueryStrdBurnerAddress(), + ) + + return cmd +} + +func CmdQueryStrdBurnerAddress() *cobra.Command { + cmd := &cobra.Command{ + Use: "address", + Short: "Query the address of the stride burner module", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := &types.QueryStrdBurnerAddressRequest{} + res, err := queryClient.StrdBurnerAddress(context.Background(), req) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + return cmd +} diff --git a/x/strdburner/keeper/abci.go b/x/strdburner/keeper/abci.go new file mode 100644 index 0000000000..a9b08e313d --- /dev/null +++ b/x/strdburner/keeper/abci.go @@ -0,0 +1,39 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/strdburner/types" +) + +func EndBlocker(ctx sdk.Context, k Keeper) { + strdBurnerAddress := k.GetStrdBurnerAddress() + + // Get STRD balance + strdBalance := k.bankKeeper.GetBalance(ctx, strdBurnerAddress, "ustrd") + + // Exit early if nothing to burn + if strdBalance.IsZero() { + return + } + + // Burn all STRD balance + err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(strdBalance)) + if err != nil { + k.Logger(ctx).Error("unable to burn %s: %w", strdBalance.String(), err) + return + } + + // Update TotalStrdBurned + currentTotalBurned := k.GetTotalStrdBurned(ctx) + newTotalBurned := currentTotalBurned.Add(strdBalance.Amount) + k.SetTotalStrdBurned(ctx, newTotalBurned) + + // Emit burn event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeBurn, + sdk.NewAttribute(types.AttributeAmount, strdBalance.String()), + ), + ) +} diff --git a/x/strdburner/keeper/genesis.go b/x/strdburner/keeper/genesis.go new file mode 100644 index 0000000000..e2bdbe61c4 --- /dev/null +++ b/x/strdburner/keeper/genesis.go @@ -0,0 +1,19 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/strdburner/types" +) + +// Loads module state from genesis +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { + k.SetTotalStrdBurned(ctx, genState.TotalUstrdBurned) +} + +// Export's module state into genesis file +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + genesis := types.DefaultGenesis() + genesis.TotalUstrdBurned = k.GetTotalStrdBurned(ctx) + return genesis +} diff --git a/x/strdburner/keeper/keeper.go b/x/strdburner/keeper/keeper.go new file mode 100644 index 0000000000..52463f6225 --- /dev/null +++ b/x/strdburner/keeper/keeper.go @@ -0,0 +1,59 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/math" + "github.com/cometbft/cometbft/libs/log" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/strdburner/types" +) + +type Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper +} + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey storetypes.StoreKey, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, +) *Keeper { + return &Keeper{ + cdc: cdc, + storeKey: storeKey, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +func (k Keeper) GetStrdBurnerAddress() sdk.AccAddress { + return k.accountKeeper.GetModuleAddress(types.ModuleName) +} + +func (k Keeper) SetTotalStrdBurned(ctx sdk.Context, amount math.Int) { + bz := sdk.Uint64ToBigEndian(amount.Uint64()) + ctx.KVStore(k.storeKey).Set([]byte(types.TotalStrdBurnedKey), bz) +} + +func (k Keeper) GetTotalStrdBurned(ctx sdk.Context) math.Int { + bz := ctx.KVStore(k.storeKey).Get([]byte(types.TotalStrdBurnedKey)) + + // If no value has been set, return zero + if bz == nil { + return math.ZeroInt() + } + + return math.NewIntFromUint64(sdk.BigEndianToUint64(bz)) +} diff --git a/x/strdburner/keeper/query.go b/x/strdburner/keeper/query.go new file mode 100644 index 0000000000..0144e9363e --- /dev/null +++ b/x/strdburner/keeper/query.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/Stride-Labs/stride/v24/x/strdburner/types" +) + +var _ types.QueryServer = Keeper{} + +// Auction queries the auction info for a specific token +func (k Keeper) StrdBurnerAddress(goCtx context.Context, req *types.QueryStrdBurnerAddressRequest) (*types.QueryStrdBurnerAddressResponse, error) { + return &types.QueryStrdBurnerAddressResponse{ + Address: k.GetStrdBurnerAddress().String(), + }, nil +} + +func (k Keeper) TotalStrdBurned(goCtx context.Context, req *types.QueryTotalStrdBurnedRequest) (*types.QueryTotalStrdBurnedResponse, error) { + return &types.QueryTotalStrdBurnedResponse{ + TotalBurned: k.GetTotalStrdBurned(sdk.UnwrapSDKContext(goCtx)), + }, nil +} diff --git a/x/strdburner/module.go b/x/strdburner/module.go new file mode 100644 index 0000000000..ac84331660 --- /dev/null +++ b/x/strdburner/module.go @@ -0,0 +1,155 @@ +package strdburner + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/Stride-Labs/stride/v24/x/strdburner/client/cli" + "github.com/Stride-Labs/stride/v24/x/strdburner/keeper" + "github.com/Stride-Labs/stride/v24/x/strdburner/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface for the capability module. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the capability module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the capability module's default genesis state. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis performs genesis state validation for the capability module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterRESTRoutes registers the capability module's REST service handlers. +func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) { +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the capability module's root tx command. +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the capability module's root query command. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface for the capability module. +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the capability module's invariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the capability module's genesis initialization It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion implements ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all ABCI EndBlock logic respective to the capability module. It +// returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} diff --git a/x/strdburner/types/codec.go b/x/strdburner/types/codec.go new file mode 100644 index 0000000000..f19b5671fb --- /dev/null +++ b/x/strdburner/types/codec.go @@ -0,0 +1,30 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" +) + +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgSubmitProposal instances + RegisterLegacyAminoCodec(govcodec.Amino) +} diff --git a/x/strdburner/types/events.go b/x/strdburner/types/events.go new file mode 100644 index 0000000000..bd53b10940 --- /dev/null +++ b/x/strdburner/types/events.go @@ -0,0 +1,8 @@ +package types + +// strdburner module event typs +const ( + EventTypeBurn = "burn" + + AttributeAmount = "amount" +) diff --git a/x/strdburner/types/expected_keepers.go b/x/strdburner/types/expected_keepers.go new file mode 100644 index 0000000000..b6ef118391 --- /dev/null +++ b/x/strdburner/types/expected_keepers.go @@ -0,0 +1,16 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// Required AccountKeeper functions +type AccountKeeper interface { + GetModuleAddress(moduleName string) sdk.AccAddress +} + +// Required BankKeeper functions +type BankKeeper interface { + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error +} diff --git a/x/strdburner/types/genesis.go b/x/strdburner/types/genesis.go new file mode 100644 index 0000000000..aa88885642 --- /dev/null +++ b/x/strdburner/types/genesis.go @@ -0,0 +1,23 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" +) + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return &GenesisState{ + TotalUstrdBurned: math.ZeroInt(), + } +} + +// Performs basic genesis state validation by +func (gs GenesisState) Validate() error { + if gs.TotalUstrdBurned.IsNil() { + return fmt.Errorf("GenesisState.TotalUstrdBurned cannot be nil") + } else { + return nil + } +} diff --git a/x/strdburner/types/genesis.pb.go b/x/strdburner/types/genesis.pb.go new file mode 100644 index 0000000000..dd7693f273 --- /dev/null +++ b/x/strdburner/types/genesis.pb.go @@ -0,0 +1,318 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/strdburner/genesis.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the strdburner module's genesis state +type GenesisState struct { + // Total amount of ustrd burned + TotalUstrdBurned cosmossdk_io_math.Int `protobuf:"bytes,9,opt,name=total_ustrd_burned,json=totalUstrdBurned,proto3,customtype=cosmossdk.io/math.Int" json:"total_ustrd_burned"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_003ecc60d66895bb, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "stride.strdburner.GenesisState") +} + +func init() { proto.RegisterFile("stride/strdburner/genesis.proto", fileDescriptor_003ecc60d66895bb) } + +var fileDescriptor_003ecc60d66895bb = []byte{ + // 223 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2f, 0x2e, 0x29, 0xca, + 0x4c, 0x49, 0xd5, 0x2f, 0x2e, 0x29, 0x4a, 0x49, 0x2a, 0x2d, 0xca, 0x4b, 0x2d, 0xd2, 0x4f, 0x4f, + 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0x28, 0xd0, + 0x43, 0x28, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xea, 0x83, 0x58, 0x10, 0x85, 0x4a, + 0xd1, 0x5c, 0x3c, 0xee, 0x10, 0x9d, 0xc1, 0x25, 0x89, 0x25, 0xa9, 0x42, 0xde, 0x5c, 0x42, 0x25, + 0xf9, 0x25, 0x89, 0x39, 0xf1, 0xa5, 0x20, 0xad, 0xf1, 0x60, 0xbd, 0x29, 0x12, 0x9c, 0x0a, 0x8c, + 0x1a, 0x9c, 0x4e, 0xb2, 0x27, 0xee, 0xc9, 0x33, 0xdc, 0xba, 0x27, 0x2f, 0x9a, 0x9c, 0x5f, 0x9c, + 0x9b, 0x5f, 0x5c, 0x9c, 0x92, 0xad, 0x97, 0x99, 0xaf, 0x9f, 0x9b, 0x58, 0x92, 0xa1, 0xe7, 0x99, + 0x57, 0x12, 0x24, 0x00, 0xd6, 0x18, 0x0a, 0xd2, 0xe7, 0x04, 0xd6, 0xe6, 0xe4, 0x77, 0xe2, 0x91, + 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, + 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x26, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, + 0xc9, 0xf9, 0xb9, 0xfa, 0xc1, 0x60, 0xa7, 0xea, 0xfa, 0x24, 0x26, 0x15, 0xeb, 0x43, 0xfd, 0x55, + 0x66, 0x64, 0xa2, 0x5f, 0x81, 0xec, 0xbb, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x9b, + 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb9, 0x11, 0x3a, 0xa0, 0xff, 0x00, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.TotalUstrdBurned.Size() + i -= size + if _, err := m.TotalUstrdBurned.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.TotalUstrdBurned.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalUstrdBurned", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalUstrdBurned.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/strdburner/types/keys.go b/x/strdburner/types/keys.go new file mode 100644 index 0000000000..269cc15aef --- /dev/null +++ b/x/strdburner/types/keys.go @@ -0,0 +1,13 @@ +package types + +const ( + ModuleName = "strdburner" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the routing key + RouterKey = ModuleName + + TotalStrdBurnedKey = "total_burned" +) diff --git a/x/strdburner/types/query.pb.go b/x/strdburner/types/query.pb.go new file mode 100644 index 0000000000..43b0c31a11 --- /dev/null +++ b/x/strdburner/types/query.pb.go @@ -0,0 +1,871 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: stride/strdburner/query.proto + +package types + +import ( + context "context" + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryStrdBurnerAddressRequest is the request type for the Query/strdburner +// RPC method +type QueryStrdBurnerAddressRequest struct { +} + +func (m *QueryStrdBurnerAddressRequest) Reset() { *m = QueryStrdBurnerAddressRequest{} } +func (m *QueryStrdBurnerAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryStrdBurnerAddressRequest) ProtoMessage() {} +func (*QueryStrdBurnerAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_76c45869caa19016, []int{0} +} +func (m *QueryStrdBurnerAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryStrdBurnerAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryStrdBurnerAddressRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryStrdBurnerAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryStrdBurnerAddressRequest.Merge(m, src) +} +func (m *QueryStrdBurnerAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryStrdBurnerAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryStrdBurnerAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryStrdBurnerAddressRequest proto.InternalMessageInfo + +// QueryStrdBurnerAddressResponse is the response type for the Query/strdburner +// RPC method +type QueryStrdBurnerAddressResponse struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *QueryStrdBurnerAddressResponse) Reset() { *m = QueryStrdBurnerAddressResponse{} } +func (m *QueryStrdBurnerAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryStrdBurnerAddressResponse) ProtoMessage() {} +func (*QueryStrdBurnerAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_76c45869caa19016, []int{1} +} +func (m *QueryStrdBurnerAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryStrdBurnerAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryStrdBurnerAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryStrdBurnerAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryStrdBurnerAddressResponse.Merge(m, src) +} +func (m *QueryStrdBurnerAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryStrdBurnerAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryStrdBurnerAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryStrdBurnerAddressResponse proto.InternalMessageInfo + +func (m *QueryStrdBurnerAddressResponse) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +// QueryTotalStrdBurnedRequest is the request type for the Query/strdburner +// RPC method +type QueryTotalStrdBurnedRequest struct { +} + +func (m *QueryTotalStrdBurnedRequest) Reset() { *m = QueryTotalStrdBurnedRequest{} } +func (m *QueryTotalStrdBurnedRequest) String() string { return proto.CompactTextString(m) } +func (*QueryTotalStrdBurnedRequest) ProtoMessage() {} +func (*QueryTotalStrdBurnedRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_76c45869caa19016, []int{2} +} +func (m *QueryTotalStrdBurnedRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalStrdBurnedRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalStrdBurnedRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTotalStrdBurnedRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalStrdBurnedRequest.Merge(m, src) +} +func (m *QueryTotalStrdBurnedRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalStrdBurnedRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalStrdBurnedRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalStrdBurnedRequest proto.InternalMessageInfo + +// QueryTotalStrdBurnedResponse is the response type for the Query/strdburner +// RPC method +type QueryTotalStrdBurnedResponse struct { + TotalBurned cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=total_burned,json=totalBurned,proto3,customtype=cosmossdk.io/math.Int" json:"total_burned"` +} + +func (m *QueryTotalStrdBurnedResponse) Reset() { *m = QueryTotalStrdBurnedResponse{} } +func (m *QueryTotalStrdBurnedResponse) String() string { return proto.CompactTextString(m) } +func (*QueryTotalStrdBurnedResponse) ProtoMessage() {} +func (*QueryTotalStrdBurnedResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_76c45869caa19016, []int{3} +} +func (m *QueryTotalStrdBurnedResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryTotalStrdBurnedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryTotalStrdBurnedResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryTotalStrdBurnedResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryTotalStrdBurnedResponse.Merge(m, src) +} +func (m *QueryTotalStrdBurnedResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryTotalStrdBurnedResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryTotalStrdBurnedResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryTotalStrdBurnedResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*QueryStrdBurnerAddressRequest)(nil), "stride.strdburner.QueryStrdBurnerAddressRequest") + proto.RegisterType((*QueryStrdBurnerAddressResponse)(nil), "stride.strdburner.QueryStrdBurnerAddressResponse") + proto.RegisterType((*QueryTotalStrdBurnedRequest)(nil), "stride.strdburner.QueryTotalStrdBurnedRequest") + proto.RegisterType((*QueryTotalStrdBurnedResponse)(nil), "stride.strdburner.QueryTotalStrdBurnedResponse") +} + +func init() { proto.RegisterFile("stride/strdburner/query.proto", fileDescriptor_76c45869caa19016) } + +var fileDescriptor_76c45869caa19016 = []byte{ + // 402 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0x2e, 0x29, 0xca, + 0x4c, 0x49, 0xd5, 0x2f, 0x2e, 0x29, 0x4a, 0x49, 0x2a, 0x2d, 0xca, 0x4b, 0x2d, 0xd2, 0x2f, 0x2c, + 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0x48, 0xeb, 0x21, 0xa4, + 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xe3, 0xc1, 0x0a, 0xf4, 0x21, 0x1c, 0x88, 0x6a, + 0x29, 0x91, 0xf4, 0xfc, 0xf4, 0x7c, 0x88, 0x38, 0x88, 0x05, 0x15, 0x95, 0x49, 0xcf, 0xcf, 0x4f, + 0xcf, 0x49, 0xd5, 0x4f, 0x2c, 0xc8, 0xd4, 0x4f, 0xcc, 0xcb, 0xcb, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, + 0xcf, 0x83, 0xea, 0x51, 0x92, 0xe7, 0x92, 0x0d, 0x04, 0x59, 0x18, 0x5c, 0x52, 0x94, 0xe2, 0x04, + 0xb6, 0xc1, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x38, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, + 0x29, 0x84, 0x4b, 0x0e, 0x97, 0x82, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x23, 0x2e, 0xf6, + 0x44, 0x88, 0x90, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xa7, 0x93, 0xc4, 0xa5, 0x2d, 0xba, 0x22, 0x50, + 0x97, 0x41, 0x15, 0x07, 0x97, 0x14, 0x65, 0xe6, 0xa5, 0x07, 0xc1, 0x14, 0x2a, 0xc9, 0x72, 0x49, + 0x83, 0x4d, 0x0d, 0xc9, 0x2f, 0x49, 0xcc, 0x81, 0x1b, 0x9d, 0x02, 0xb3, 0x34, 0x81, 0x4b, 0x06, + 0xbb, 0x34, 0xd4, 0x4a, 0x07, 0x2e, 0x9e, 0x12, 0x90, 0x54, 0x3c, 0x38, 0x50, 0x52, 0xa0, 0xf6, + 0xca, 0x9e, 0xb8, 0x27, 0xcf, 0x70, 0xeb, 0x9e, 0xbc, 0x28, 0xc4, 0xee, 0xe2, 0x94, 0x6c, 0xbd, + 0xcc, 0x7c, 0xfd, 0xdc, 0xc4, 0x92, 0x0c, 0x3d, 0xcf, 0xbc, 0x92, 0x20, 0x6e, 0xb0, 0x16, 0x88, + 0x49, 0x46, 0x47, 0x98, 0xb8, 0x58, 0xc1, 0x56, 0x08, 0xcd, 0x61, 0xe4, 0x12, 0xc4, 0xf0, 0x9c, + 0x90, 0x81, 0x1e, 0x46, 0xd0, 0xeb, 0xe1, 0x0d, 0x28, 0x29, 0x43, 0x12, 0x74, 0x40, 0xbc, 0xa1, + 0xa4, 0xd4, 0x74, 0xf9, 0xc9, 0x64, 0x26, 0x19, 0x21, 0x29, 0x7d, 0xcc, 0x64, 0x00, 0x0d, 0x29, + 0xa1, 0xd9, 0x8c, 0x5c, 0xfc, 0x68, 0xc1, 0x20, 0xa4, 0x87, 0xcb, 0x2a, 0xec, 0xc1, 0x29, 0xa5, + 0x4f, 0xb4, 0x7a, 0xa8, 0xc3, 0xd4, 0xc1, 0x0e, 0x53, 0x14, 0x92, 0xc7, 0xe2, 0x30, 0xe4, 0x80, + 0x77, 0xf2, 0x3b, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, + 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x93, 0xf4, 0xcc, + 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0x60, 0xb0, 0x21, 0xba, 0x3e, 0x89, 0x49, + 0xc5, 0x30, 0x03, 0xcb, 0x8c, 0x4c, 0xf4, 0x2b, 0x50, 0x8c, 0xad, 0x2c, 0x48, 0x2d, 0x4e, 0x62, + 0x03, 0xa7, 0x4a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xba, 0x0c, 0x0a, 0x2f, 0x18, 0x03, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // StrdBurnerAddress queries the address of the strdburner module + StrdBurnerAddress(ctx context.Context, in *QueryStrdBurnerAddressRequest, opts ...grpc.CallOption) (*QueryStrdBurnerAddressResponse, error) + // StrdBurnerAddress queries the address of the strdburner module + TotalStrdBurned(ctx context.Context, in *QueryTotalStrdBurnedRequest, opts ...grpc.CallOption) (*QueryTotalStrdBurnedResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) StrdBurnerAddress(ctx context.Context, in *QueryStrdBurnerAddressRequest, opts ...grpc.CallOption) (*QueryStrdBurnerAddressResponse, error) { + out := new(QueryStrdBurnerAddressResponse) + err := c.cc.Invoke(ctx, "/stride.strdburner.Query/StrdBurnerAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) TotalStrdBurned(ctx context.Context, in *QueryTotalStrdBurnedRequest, opts ...grpc.CallOption) (*QueryTotalStrdBurnedResponse, error) { + out := new(QueryTotalStrdBurnedResponse) + err := c.cc.Invoke(ctx, "/stride.strdburner.Query/TotalStrdBurned", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // StrdBurnerAddress queries the address of the strdburner module + StrdBurnerAddress(context.Context, *QueryStrdBurnerAddressRequest) (*QueryStrdBurnerAddressResponse, error) + // StrdBurnerAddress queries the address of the strdburner module + TotalStrdBurned(context.Context, *QueryTotalStrdBurnedRequest) (*QueryTotalStrdBurnedResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) StrdBurnerAddress(ctx context.Context, req *QueryStrdBurnerAddressRequest) (*QueryStrdBurnerAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method StrdBurnerAddress not implemented") +} +func (*UnimplementedQueryServer) TotalStrdBurned(ctx context.Context, req *QueryTotalStrdBurnedRequest) (*QueryTotalStrdBurnedResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TotalStrdBurned not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_StrdBurnerAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryStrdBurnerAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).StrdBurnerAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.strdburner.Query/StrdBurnerAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).StrdBurnerAddress(ctx, req.(*QueryStrdBurnerAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_TotalStrdBurned_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryTotalStrdBurnedRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).TotalStrdBurned(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/stride.strdburner.Query/TotalStrdBurned", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).TotalStrdBurned(ctx, req.(*QueryTotalStrdBurnedRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "stride.strdburner.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "StrdBurnerAddress", + Handler: _Query_StrdBurnerAddress_Handler, + }, + { + MethodName: "TotalStrdBurned", + Handler: _Query_TotalStrdBurned_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "stride/strdburner/query.proto", +} + +func (m *QueryStrdBurnerAddressRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryStrdBurnerAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryStrdBurnerAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryStrdBurnerAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryStrdBurnerAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryStrdBurnerAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryTotalStrdBurnedRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTotalStrdBurnedRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalStrdBurnedRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryTotalStrdBurnedResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryTotalStrdBurnedResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryTotalStrdBurnedResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.TotalBurned.Size() + i -= size + if _, err := m.TotalBurned.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryStrdBurnerAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryStrdBurnerAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryTotalStrdBurnedRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryTotalStrdBurnedResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.TotalBurned.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryStrdBurnerAddressRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryStrdBurnerAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryStrdBurnerAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryStrdBurnerAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryStrdBurnerAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryStrdBurnerAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTotalStrdBurnedRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTotalStrdBurnedRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalStrdBurnedRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryTotalStrdBurnedResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryTotalStrdBurnedResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryTotalStrdBurnedResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalBurned", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TotalBurned.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/strdburner/types/query.pb.gw.go b/x/strdburner/types/query.pb.gw.go new file mode 100644 index 0000000000..64ef5e65ae --- /dev/null +++ b/x/strdburner/types/query.pb.gw.go @@ -0,0 +1,218 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: stride/strdburner/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_StrdBurnerAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryStrdBurnerAddressRequest + var metadata runtime.ServerMetadata + + msg, err := client.StrdBurnerAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_StrdBurnerAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryStrdBurnerAddressRequest + var metadata runtime.ServerMetadata + + msg, err := server.StrdBurnerAddress(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_TotalStrdBurned_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalStrdBurnedRequest + var metadata runtime.ServerMetadata + + msg, err := client.TotalStrdBurned(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_TotalStrdBurned_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryTotalStrdBurnedRequest + var metadata runtime.ServerMetadata + + msg, err := server.TotalStrdBurned(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_StrdBurnerAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_StrdBurnerAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_StrdBurnerAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalStrdBurned_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_TotalStrdBurned_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalStrdBurned_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_StrdBurnerAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_StrdBurnerAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_StrdBurnerAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_TotalStrdBurned_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_TotalStrdBurned_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_TotalStrdBurned_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_StrdBurnerAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "strdburner", "address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_TotalStrdBurned_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"stride", "strdburner", "total_burned"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_StrdBurnerAddress_0 = runtime.ForwardResponseMessage + + forward_Query_TotalStrdBurned_0 = runtime.ForwardResponseMessage +)