From b70213c28dde42e43c0cc7a78be044588ca6d5d9 Mon Sep 17 00:00:00 2001 From: abel Date: Fri, 8 Mar 2024 00:23:59 -0300 Subject: [PATCH] (feat) Added example scripts for all chain exchange module queries and messages --- auth_vote/authz_vote.go | 104 ++++ client/chain/chain.go | 494 +++++++++++++++++- client/chain/chain_test_support.go | 221 ++++++++ .../example.go | 0 .../37_decode_tx.go | 0 .../example.go | 0 .../example.go | 0 .../example.go | 0 .../example.go | 0 .../example.go | 0 .../example.go | 0 .../example.go | 0 .../example.go | 0 .../{33_GetBlock => 7_GetBlock}/example.go | 0 .../example.go | 0 .../example.go | 0 .../1_MsgBid}/example.go | 0 .../query/1_Account}/example.go | 0 .../1_MsgGrant}/example.go | 0 .../2_MsgExec}/example.go | 0 .../3_MsgRevoke}/example.go | 0 .../query/1_Grants}/example.go | 0 .../chain/{ => bank}/1_MsgSend/example.go | 0 .../2_MsgMultiSend}/example.go | 0 .../query/10_BankSendEnabled}/example.go | 0 .../query/1_BankBalance}/example.go | 0 .../query/2_BankBalances}/example.go | 0 .../query/3_BankSpendableBalances}/example.go | 0 .../example.go | 0 .../query/5_BankTotalSupply}/example.go | 0 .../query/6_BankSupplyOf}/example.go | 0 .../query/7_DenomMetadata}/example.go | 0 .../query/8_DenomsMetadata}/example.go | 0 .../query/9_DenomOwners}/example.go | 0 .../example.go | 0 .../example.go | 0 .../12_MsgCancelDerivativeOrder}/example.go | 0 .../example.go | 107 ++++ .../14_MsgSubaccountTransfer}/example.go | 0 .../15_MsgExternalTransfer}/example.go | 0 .../16_MsgLiquidatePosition}/example.go | 0 .../17_MsgIncreasePositionMargin}/example.go | 0 .../1_MsgDeposit}/example.go | 0 .../21_MsgRewardsOptOut}/example.go | 46 +- .../2_MsgWithdraw}/example.go | 0 .../3_MsgInstantSpotMarketLaunch/example.go | 101 ++++ .../example.go | 106 ++++ .../example.go | 107 ++++ .../6_MsgCreateSpotLimitOrder}/example.go | 0 .../7_MsgCreateSpotMarketOrder}/example.go | 0 .../8_MsgCancelSpotOrder}/example.go | 0 .../9_MsgBatchUpdateOrders}/example.go | 0 .../exchange/query/10_SpotMarkets/example.go | 72 +++ .../exchange/query/11_SpotMarket/example.go | 71 +++ .../query/12_FullSpotMarkets/example.go | 73 +++ .../query/13_FullSpotMarket/example.go | 72 +++ .../query/14_SpotOrderbook/example.go | 78 +++ .../query/15_TraderSpotOrders/example.go | 71 +++ .../16_AccountAddressSpotOrders/example.go | 70 +++ .../query/17_SpotOrdersByHashes/example.go | 72 +++ .../query/18_SubaccountOrders/example.go | 71 +++ .../19_TraderSpotTransientOrders/example.go | 71 +++ .../query/1_SubaccountDeposits/example.go | 70 +++ .../query/20_SpotMidPriceAndTOB/example.go | 70 +++ .../21_DerivativeMidPriceAndTOB/example.go | 70 +++ .../query/22_DerivativeOrderbook/example.go | 75 +++ .../23_TraderDerivativeOrders/example.go | 71 +++ .../example.go | 70 +++ .../25_DerivativeOrdersByHashes/example.go | 72 +++ .../example.go | 71 +++ .../query/27_DerivativeMarkets/example.go | 73 +++ .../query/28_DerivativeMarket/example.go | 71 +++ .../29_DerivativeMarketAddress/example.go | 71 +++ .../query/2_SubaccountDeposit/example.go | 71 +++ .../query/30_SubaccountTradeNonce/example.go | 71 +++ .../exchange/query/31_Positions/example.go | 69 +++ .../query/32_SubaccountPositions/example.go | 71 +++ .../33_SubaccountPositionInMarket/example.go | 72 +++ .../example.go | 72 +++ .../query/35_PerpetualMarketInfo/example.go | 71 +++ .../36_ExpiryFuturesMarketInfo/example.go | 71 +++ .../37_PerpetualMarketFunding/example.go | 71 +++ .../38_SubaccountOrderMetadata/example.go | 70 +++ .../query/39_TradeRewardPoints/example.go | 70 +++ .../query/3_ExchangeBalances/example.go | 69 +++ .../40_PendingTradeRewardPoints/example.go | 70 +++ .../query/41_TradeRewardCampaign/example.go | 68 +++ .../42_FeeDiscountAccountInfo/example.go | 68 +++ .../query/43_FeeDiscountSchedule/example.go | 68 +++ .../query/44_BalanceMismatches/example.go | 68 +++ .../45_BalanceWithBalanceHolds/example.go | 68 +++ .../46_FeeDiscountTierStatistics/example.go | 68 +++ .../query/47_MitoVaultInfos/example.go | 68 +++ .../48_QueryMarketIDFromVault/example.go | 70 +++ .../49_HistoricalTradeRecords/example.go | 71 +++ .../query/4_AggregateVolume/example.go | 79 +++ .../query/50_IsOptedOutOfRewards/example.go | 69 +++ .../51_OptedOutOfRewardsAccounts/example.go | 69 +++ .../query/52_MarketVolatility/example.go | 79 +++ .../query/53_BinaryOptionsMarkets/example.go | 71 +++ .../example.go | 71 +++ .../example.go | 71 +++ .../query/5_AggregateVolumes/example.go | 72 +++ .../query/6_AggregateMarketVolume/example.go | 71 +++ .../query/7_AggregateMarketVolumes/example.go | 71 +++ .../exchange/query/8_DenomDecimal/example.go | 71 +++ .../exchange/query/9_DenomDecimals/example.go | 71 +++ .../1_MsgRelayPriceFeedPrice}/example.go | 0 .../1_MsgSendToEth}/example.go | 0 .../example.go | 0 .../1_CreateDenom}/example.go | 0 .../2_MsgMint}/example.go | 0 .../3_MsgBurn}/example.go | 0 .../4_MsgSetDenomMetadata}/example.go | 0 .../5_MsgChangeAdmin}/example.go | 0 .../1_DenomAuthorityMetadata}/example.go | 0 .../query/2_DenomsFromCreator}/example.go | 0 .../3_TokenfactoryModuleState}/example.go | 0 .../{39_GetTx => tx/query/1_GetTx}/example.go | 0 .../query/10_ContractsByCreator}/example.go | 0 .../query/1_ContractInfo}/example.go | 0 .../query/2_ContractHistory}/example.go | 0 .../query/3_ContractsByCode}/example.go | 0 .../query/4_AllContractsState}/example.go | 0 .../query/5_RawContractState}/example.go | 0 .../query/6_SmartContractState}/example.go | 0 .../query/7_SmartContractCode}/example.go | 0 .../query/8_SmartContractCodes}/example.go | 0 .../9_SmartContractPinnedCodes}/example.go | 0 .../1_MsgExecuteContractCompat}/example.go | 0 130 files changed, 5128 insertions(+), 63 deletions(-) create mode 100644 auth_vote/authz_vote.go rename examples/chain/{36_StreamEventOrderbookUpdate => 10_StreamEventOrderbookUpdate}/example.go (100%) rename examples/chain/{37_DecodeTx => 11_DecodeTx}/37_decode_tx.go (100%) rename examples/chain/{40_ChainStream => 12_ChainStream}/example.go (100%) rename examples/chain/{41_BroadcastMsgWithoutSimulation => 13_BroadcastMsgWithoutSimulation}/example.go (100%) rename examples/chain/{0_LocalOrderHash => 1_LocalOrderHash}/example.go (100%) rename examples/chain/{9_MsgBatchCancelSpotOrders => 2_MsgBatchCancelSpotOrders}/example.go (100%) rename examples/chain/{10_MsgBatchCancelDerivativeOrders => 3_MsgBatchCancelDerivativeOrders}/example.go (100%) rename examples/chain/{11_MsgBatchCreateSpotLimitOrders => 4_MsgBatchCreateSpotLimitOrders}/example.go (100%) rename examples/chain/{12_MsgBatchCreateDerivativeLimitOrders => 5_MsgBatchCreateDerivativeLimitOrders}/example.go (100%) rename examples/chain/{24_MsgRegisterAsDMM => 6_MsgRegisterAsDMM}/example.go (100%) rename examples/chain/{33_GetBlock => 7_GetBlock}/example.go (100%) rename examples/chain/{34_OfflineSigning => 8_OfflineSigning}/example.go (100%) rename examples/chain/{35_StreamEventOrderFail => 9_StreamEventOrderFail}/example.go (100%) rename examples/chain/{18_MsgBid => auction/1_MsgBid}/example.go (100%) rename examples/chain/{32_Account => auth/query/1_Account}/example.go (100%) rename examples/chain/{19_MsgGrant => authz/1_MsgGrant}/example.go (100%) rename examples/chain/{20_MsgExec => authz/2_MsgExec}/example.go (100%) rename examples/chain/{21_MsgRevoke => authz/3_MsgRevoke}/example.go (100%) rename examples/chain/{27_QueryAuthzGrants => authz/query/1_Grants}/example.go (100%) rename examples/chain/{ => bank}/1_MsgSend/example.go (100%) rename examples/chain/{31_MsgMultiSend => bank/2_MsgMultiSend}/example.go (100%) rename examples/chain/{49_BankSendEnabled => bank/query/10_BankSendEnabled}/example.go (100%) rename examples/chain/{29_BankBalance => bank/query/1_BankBalance}/example.go (100%) rename examples/chain/{28_BankBalances => bank/query/2_BankBalances}/example.go (100%) rename examples/chain/{42_BankSpendableBalances => bank/query/3_BankSpendableBalances}/example.go (100%) rename examples/chain/{43_BankSpendableBalancesByDenom => bank/query/4_BankSpendableBalancesByDenom}/example.go (100%) rename examples/chain/{44_BankTotalSupply => bank/query/5_BankTotalSupply}/example.go (100%) rename examples/chain/{45_BankSupplyOf => bank/query/6_BankSupplyOf}/example.go (100%) rename examples/chain/{46_DenomMetadata => bank/query/7_DenomMetadata}/example.go (100%) rename examples/chain/{47_DenomsMetadata => bank/query/8_DenomsMetadata}/example.go (100%) rename examples/chain/{48_DenomOwners => bank/query/9_DenomOwners}/example.go (100%) rename examples/chain/{6_MsgCreateDerivativeLimitOrder => exchange/10_MsgCreateDerivativeLimitOrder}/example.go (100%) rename examples/chain/{7_MsgCreateDerivativeMarketOrder => exchange/11_MsgCreateDerivativeMarketOrder}/example.go (100%) rename examples/chain/{8_MsgCancelDerivativeOrder => exchange/12_MsgCancelDerivativeOrder}/example.go (100%) create mode 100644 examples/chain/exchange/13_MsgInstantBinaryOptionsMarketLaunch/example.go rename examples/chain/{16_MsgSubaccountTransfer => exchange/14_MsgSubaccountTransfer}/example.go (100%) rename examples/chain/{30_MsgExternalTransfer => exchange/15_MsgExternalTransfer}/example.go (100%) rename examples/chain/{70_MsgLiquidatePosition => exchange/16_MsgLiquidatePosition}/example.go (100%) rename examples/chain/{13_MsgIncreasePositionMargin => exchange/17_MsgIncreasePositionMargin}/example.go (100%) rename examples/chain/{2_MsgDeposit => exchange/1_MsgDeposit}/example.go (100%) rename examples/chain/{38_MsgLiquidate => exchange/21_MsgRewardsOptOut}/example.go (58%) rename examples/chain/{15_MsgWithdraw => exchange/2_MsgWithdraw}/example.go (100%) create mode 100644 examples/chain/exchange/3_MsgInstantSpotMarketLaunch/example.go create mode 100644 examples/chain/exchange/4_MsgInstantPerpetualMarketLaunch/example.go create mode 100644 examples/chain/exchange/5_MsgInstantExpiryFuturesMarketLaunch/example.go rename examples/chain/{3_MsgCreateSpotLimitOrder => exchange/6_MsgCreateSpotLimitOrder}/example.go (100%) rename examples/chain/{4_MsgCreateSpotMarketOrder => exchange/7_MsgCreateSpotMarketOrder}/example.go (100%) rename examples/chain/{5_MsgCancelSpotOrder => exchange/8_MsgCancelSpotOrder}/example.go (100%) rename examples/chain/{17_MsgBatchUpdateOrders => exchange/9_MsgBatchUpdateOrders}/example.go (100%) create mode 100644 examples/chain/exchange/query/10_SpotMarkets/example.go create mode 100644 examples/chain/exchange/query/11_SpotMarket/example.go create mode 100644 examples/chain/exchange/query/12_FullSpotMarkets/example.go create mode 100644 examples/chain/exchange/query/13_FullSpotMarket/example.go create mode 100644 examples/chain/exchange/query/14_SpotOrderbook/example.go create mode 100644 examples/chain/exchange/query/15_TraderSpotOrders/example.go create mode 100644 examples/chain/exchange/query/16_AccountAddressSpotOrders/example.go create mode 100644 examples/chain/exchange/query/17_SpotOrdersByHashes/example.go create mode 100644 examples/chain/exchange/query/18_SubaccountOrders/example.go create mode 100644 examples/chain/exchange/query/19_TraderSpotTransientOrders/example.go create mode 100644 examples/chain/exchange/query/1_SubaccountDeposits/example.go create mode 100644 examples/chain/exchange/query/20_SpotMidPriceAndTOB/example.go create mode 100644 examples/chain/exchange/query/21_DerivativeMidPriceAndTOB/example.go create mode 100644 examples/chain/exchange/query/22_DerivativeOrderbook/example.go create mode 100644 examples/chain/exchange/query/23_TraderDerivativeOrders/example.go create mode 100644 examples/chain/exchange/query/24_AccountAddressDerivativeOrders/example.go create mode 100644 examples/chain/exchange/query/25_DerivativeOrdersByHashes/example.go create mode 100644 examples/chain/exchange/query/26_TraderDerivativeTransientOrders/example.go create mode 100644 examples/chain/exchange/query/27_DerivativeMarkets/example.go create mode 100644 examples/chain/exchange/query/28_DerivativeMarket/example.go create mode 100644 examples/chain/exchange/query/29_DerivativeMarketAddress/example.go create mode 100644 examples/chain/exchange/query/2_SubaccountDeposit/example.go create mode 100644 examples/chain/exchange/query/30_SubaccountTradeNonce/example.go create mode 100644 examples/chain/exchange/query/31_Positions/example.go create mode 100644 examples/chain/exchange/query/32_SubaccountPositions/example.go create mode 100644 examples/chain/exchange/query/33_SubaccountPositionInMarket/example.go create mode 100644 examples/chain/exchange/query/34_SubaccountEffectivePositionInMarket/example.go create mode 100644 examples/chain/exchange/query/35_PerpetualMarketInfo/example.go create mode 100644 examples/chain/exchange/query/36_ExpiryFuturesMarketInfo/example.go create mode 100644 examples/chain/exchange/query/37_PerpetualMarketFunding/example.go create mode 100644 examples/chain/exchange/query/38_SubaccountOrderMetadata/example.go create mode 100644 examples/chain/exchange/query/39_TradeRewardPoints/example.go create mode 100644 examples/chain/exchange/query/3_ExchangeBalances/example.go create mode 100644 examples/chain/exchange/query/40_PendingTradeRewardPoints/example.go create mode 100644 examples/chain/exchange/query/41_TradeRewardCampaign/example.go create mode 100644 examples/chain/exchange/query/42_FeeDiscountAccountInfo/example.go create mode 100644 examples/chain/exchange/query/43_FeeDiscountSchedule/example.go create mode 100644 examples/chain/exchange/query/44_BalanceMismatches/example.go create mode 100644 examples/chain/exchange/query/45_BalanceWithBalanceHolds/example.go create mode 100644 examples/chain/exchange/query/46_FeeDiscountTierStatistics/example.go create mode 100644 examples/chain/exchange/query/47_MitoVaultInfos/example.go create mode 100644 examples/chain/exchange/query/48_QueryMarketIDFromVault/example.go create mode 100644 examples/chain/exchange/query/49_HistoricalTradeRecords/example.go create mode 100644 examples/chain/exchange/query/4_AggregateVolume/example.go create mode 100644 examples/chain/exchange/query/50_IsOptedOutOfRewards/example.go create mode 100644 examples/chain/exchange/query/51_OptedOutOfRewardsAccounts/example.go create mode 100644 examples/chain/exchange/query/52_MarketVolatility/example.go create mode 100644 examples/chain/exchange/query/53_BinaryOptionsMarkets/example.go create mode 100644 examples/chain/exchange/query/54_TraderDerivativeConditionalOrders/example.go create mode 100644 examples/chain/exchange/query/55_MarketAtomicExecutionFeeMultiplier/example.go create mode 100644 examples/chain/exchange/query/5_AggregateVolumes/example.go create mode 100644 examples/chain/exchange/query/6_AggregateMarketVolume/example.go create mode 100644 examples/chain/exchange/query/7_AggregateMarketVolumes/example.go create mode 100644 examples/chain/exchange/query/8_DenomDecimal/example.go create mode 100644 examples/chain/exchange/query/9_DenomDecimals/example.go rename examples/chain/{23_MsgRelayPriceFeedPrice => oracle/1_MsgRelayPriceFeedPrice}/example.go (100%) rename examples/chain/{22_MsgSendToEth => peggy/1_MsgSendToEth}/example.go (100%) rename examples/chain/staking/{25_MsgDelegate => 1_MsgDelegate}/example.go (100%) rename examples/chain/{64_CreateDenom => tokenfactory/1_CreateDenom}/example.go (100%) rename examples/chain/{65_MsgMint => tokenfactory/2_MsgMint}/example.go (100%) rename examples/chain/{66_MsgBurn => tokenfactory/3_MsgBurn}/example.go (100%) rename examples/chain/{67_MsgSetDenomMetadata => tokenfactory/4_MsgSetDenomMetadata}/example.go (100%) rename examples/chain/{68_MsgChangeAdmin => tokenfactory/5_MsgChangeAdmin}/example.go (100%) rename examples/chain/{60_DenomAuthorityMetadata => tokenfactory/query/1_DenomAuthorityMetadata}/example.go (100%) rename examples/chain/{61_DenomsFromCreator => tokenfactory/query/2_DenomsFromCreator}/example.go (100%) rename examples/chain/{62_TokenfactoryModuleState => tokenfactory/query/3_TokenfactoryModuleState}/example.go (100%) rename examples/chain/{39_GetTx => tx/query/1_GetTx}/example.go (100%) rename examples/chain/{59_ContractsByCreator => wasm/query/10_ContractsByCreator}/example.go (100%) rename examples/chain/{50_ContractInfo => wasm/query/1_ContractInfo}/example.go (100%) rename examples/chain/{51_ContractHistory => wasm/query/2_ContractHistory}/example.go (100%) rename examples/chain/{52_ContractsByCode => wasm/query/3_ContractsByCode}/example.go (100%) rename examples/chain/{53_AllContractsState => wasm/query/4_AllContractsState}/example.go (100%) rename examples/chain/{54_RawContractState => wasm/query/5_RawContractState}/example.go (100%) rename examples/chain/{55_SmartContractState => wasm/query/6_SmartContractState}/example.go (100%) rename examples/chain/{56_SmartContractCode => wasm/query/7_SmartContractCode}/example.go (100%) rename examples/chain/{57_SmartContractCodes => wasm/query/8_SmartContractCodes}/example.go (100%) rename examples/chain/{58_SmartContractPinnedCodes => wasm/query/9_SmartContractPinnedCodes}/example.go (100%) rename examples/chain/{69_MsgExecuteContractCompat => wasmx/1_MsgExecuteContractCompat}/example.go (100%) diff --git a/auth_vote/authz_vote.go b/auth_vote/authz_vote.go new file mode 100644 index 00000000..508a7c70 --- /dev/null +++ b/auth_vote/authz_vote.go @@ -0,0 +1,104 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "gov_account", + "", + "", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + txFactory := chainclient.NewTxFactory(clientCtx) + txFactory = txFactory.WithGasPrices(client.DefaultGasPriceWithDenom) + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionTxFactory(&txFactory), + ) + + if err != nil { + panic(err) + } + + // note that we use grantee keyring to send the msg on behalf of granter here + // sender, subaccount are from granter + validators := []string{"inj156t3yxd4udv0h9gwagfcmwnmm3quy0npqc7pks", "inj16nd8yqxe9p6ggnrz58qr7dxn5y2834yendward"} + grantee := senderAddress.String() + proposalId := uint64(375) + var msgs []sdk.Msg + + for _, validator := range validators { + msgVote := v1beta1.MsgVote{ + ProposalId: proposalId, + Voter: validator, + Option: v1beta1.OptionYes, + } + + msg0Bytes, _ := msgVote.Marshal() + msg0Any := &codectypes.Any{} + msg0Any.TypeUrl = sdk.MsgTypeURL(&msgVote) + msg0Any.Value = msg0Bytes + + msg := &authztypes.MsgExec{ + Grantee: grantee, + Msgs: []*codectypes.Any{msg0Any}, + } + + sdkMsg := sdk.Msg(msg) + msgs = append(msgs, sdkMsg) + } + + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + response, err := chainClient.AsyncBroadcastMsg(msgs...) + + if err != nil { + panic(err) + } + + str, _ := json.MarshalIndent(response, "", " ") + fmt.Print(string(str)) +} diff --git a/client/chain/chain.go b/client/chain/chain.go index 0e405c1d..058c57df 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "math" - "os" "strconv" "strings" "sync" @@ -26,7 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cosmtypes "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types" txtypes "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -61,7 +59,6 @@ const ( defaultBroadcastTimeout = 40 * time.Second defaultTimeoutHeight = 20 defaultTimeoutHeightSyncInterval = 10 * time.Second - defaultChainCookieName = ".chain_cookie" ) var ( @@ -116,8 +113,8 @@ type ChainClient interface { expireIn time.Time, ) *authztypes.MsgGrant - DefaultSubaccount(acc cosmtypes.AccAddress) eth.Hash - Subaccount(account cosmtypes.AccAddress, index int) eth.Hash + DefaultSubaccount(acc sdk.AccAddress) eth.Hash + Subaccount(account sdk.AccAddress, index int) eth.Hash GetSubAccountNonce(ctx context.Context, subaccountId eth.Hash) (*exchangetypes.QuerySubaccountTradeNonceResponse, error) GetFeeDiscountInfo(ctx context.Context, account string) (*exchangetypes.QueryFeeDiscountAccountInfoResponse, error) @@ -180,6 +177,63 @@ type ChainClient interface { FetchDelegatorWithdrawAddress(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorWithdrawAddressResponse, error) FetchCommunityPool(ctx context.Context) (*distributiontypes.QueryCommunityPoolResponse, error) + // chain exchange module + FetchSubaccountDeposits(ctx context.Context, subaccountID string) (*exchangetypes.QuerySubaccountDepositsResponse, error) + FetchSubaccountDeposit(ctx context.Context, subaccountId string, denom string) (*exchangetypes.QuerySubaccountDepositResponse, error) + FetchExchangeBalances(ctx context.Context) (*exchangetypes.QueryExchangeBalancesResponse, error) + FetchAggregateVolume(ctx context.Context, account string) (*exchangetypes.QueryAggregateVolumeResponse, error) + FetchAggregateVolumes(ctx context.Context, accounts []string, marketIds []string) (*exchangetypes.QueryAggregateVolumesResponse, error) + FetchAggregateMarketVolume(ctx context.Context, marketId string) (*exchangetypes.QueryAggregateMarketVolumeResponse, error) + FetchAggregateMarketVolumes(ctx context.Context, marketIds []string) (*exchangetypes.QueryAggregateMarketVolumesResponse, error) + FetchDenomDecimal(ctx context.Context, denom string) (*exchangetypes.QueryDenomDecimalResponse, error) + FetchDenomDecimals(ctx context.Context, denoms []string) (*exchangetypes.QueryDenomDecimalsResponse, error) + FetchChainSpotMarkets(ctx context.Context, status string, marketIds []string) (*exchangetypes.QuerySpotMarketsResponse, error) + FetchChainSpotMarket(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMarketResponse, error) + FetchChainFullSpotMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketsResponse, error) + FetchChainFullSpotMarket(ctx context.Context, marketId string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketResponse, error) + FetchChainSpotOrderbook(ctx context.Context, marketId string, limit uint64, orderSide exchangetypes.OrderSide, limitCumulativeNotional sdk.Dec, limitCumulativeQuantity sdk.Dec) (*exchangetypes.QuerySpotOrderbookResponse, error) + FetchChainTraderSpotOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) + FetchChainAccountAddressSpotOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressSpotOrdersResponse, error) + FetchChainSpotOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QuerySpotOrdersByHashesResponse, error) + FetchChainSubaccountOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountOrdersResponse, error) + FetchChainTraderSpotTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) + FetchSpotMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMidPriceAndTOBResponse, error) + FetchDerivativeMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMidPriceAndTOBResponse, error) + FetchChainDerivativeOrderbook(ctx context.Context, marketId string, limit uint64, limitCumulativeNotional sdk.Dec) (*exchangetypes.QueryDerivativeOrderbookResponse, error) + FetchChainTraderDerivativeOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) + FetchChainAccountAddressDerivativeOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressDerivativeOrdersResponse, error) + FetchChainDerivativeOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QueryDerivativeOrdersByHashesResponse, error) + FetchChainTraderDerivativeTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) + FetchChainDerivativeMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryDerivativeMarketsResponse, error) + FetchChainDerivativeMarket(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketResponse, error) + FetchDerivativeMarketAddress(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketAddressResponse, error) + FetchSubaccountTradeNonce(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountTradeNonceResponse, error) + FetchChainPositions(ctx context.Context) (*exchangetypes.QueryPositionsResponse, error) + FetchChainSubaccountPositions(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountPositionsResponse, error) + FetchChainSubaccountPositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountPositionInMarketResponse, error) + FetchChainSubaccountEffectivePositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountEffectivePositionInMarketResponse, error) + FetchChainPerpetualMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketInfoResponse, error) + FetchChainExpiryFuturesMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryExpiryFuturesMarketInfoResponse, error) + FetchChainPerpetualMarketFunding(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketFundingResponse, error) + FetchSubaccountOrderMetadata(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountOrderMetadataResponse, error) + FetchTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) + FetchPendingTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) + FetchFeeDiscountAccountInfo(ctx context.Context, account string) (*exchangetypes.QueryFeeDiscountAccountInfoResponse, error) + FetchTradeRewardCampaign(ctx context.Context) (*exchangetypes.QueryTradeRewardCampaignResponse, error) + FetchFeeDiscountSchedule(ctx context.Context) (*exchangetypes.QueryFeeDiscountScheduleResponse, error) + FetchBalanceMismatches(ctx context.Context, dustFactor int64) (*exchangetypes.QueryBalanceMismatchesResponse, error) + FetchBalanceWithBalanceHolds(ctx context.Context) (*exchangetypes.QueryBalanceWithBalanceHoldsResponse, error) + FetchFeeDiscountTierStatistics(ctx context.Context) (*exchangetypes.QueryFeeDiscountTierStatisticsResponse, error) + FetchMitoVaultInfos(ctx context.Context) (*exchangetypes.MitoVaultInfosResponse, error) + FetchMarketIDFromVault(ctx context.Context, vaultAddress string) (*exchangetypes.QueryMarketIDFromVaultResponse, error) + FetchHistoricalTradeRecords(ctx context.Context, marketId string) (*exchangetypes.QueryHistoricalTradeRecordsResponse, error) + FetchIsOptedOutOfRewards(ctx context.Context, account string) (*exchangetypes.QueryIsOptedOutOfRewardsResponse, error) + FetchOptedOutOfRewardsAccounts(ctx context.Context) (*exchangetypes.QueryOptedOutOfRewardsAccountsResponse, error) + FetchMarketVolatility(ctx context.Context, marketId string, tradeHistoryOptions *exchangetypes.TradeHistoryOptions) (*exchangetypes.QueryMarketVolatilityResponse, error) + FetchChainBinaryOptionsMarkets(ctx context.Context, status string) (*exchangetypes.QueryBinaryMarketsResponse, error) + FetchTraderDerivativeConditionalOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QueryTraderDerivativeConditionalOrdersResponse, error) + FetchMarketAtomicExecutionFeeMultiplier(ctx context.Context, marketId string) (*exchangetypes.QueryMarketAtomicExecutionFeeMultiplierResponse, error) + Close() } @@ -204,7 +258,6 @@ type chainClient struct { gasWanted uint64 gasFee string - sessionCookie string sessionEnabled bool txClient txtypes.ServiceClient @@ -327,23 +380,6 @@ func NewChainClient( go cc.syncTimeoutHeight() } - // create file if not exist - cookieFile, err := os.OpenFile(defaultChainCookieName, os.O_RDONLY|os.O_CREATE, 0666) - if err != nil { - cc.logger.Errorln(err) - } else { - defer cookieFile.Close() - } - - // attempt to load from disk - data, err := os.ReadFile(defaultChainCookieName) - if err != nil { - cc.logger.Errorln(err) - } else { - cc.sessionCookie = string(data) - cc.logger.Debugln("chain session cookie loaded from disk") - } - return cc, nil } @@ -965,11 +1001,11 @@ func (c *chainClient) GetGasFee() (string, error) { return c.gasFee, err } -func (c *chainClient) DefaultSubaccount(acc cosmtypes.AccAddress) eth.Hash { +func (c *chainClient) DefaultSubaccount(acc sdk.AccAddress) eth.Hash { return c.Subaccount(acc, 0) } -func (c *chainClient) Subaccount(account cosmtypes.AccAddress, index int) eth.Hash { +func (c *chainClient) Subaccount(account sdk.AccAddress, index int) eth.Hash { ethAddress := eth.BytesToAddress(account.Bytes()) ethLowerAddress := strings.ToLower(ethAddress.String()) @@ -1034,7 +1070,7 @@ func (c *chainClient) CreateDerivativeOrder(defaultSubaccountID eth.Hash, d *Der orderSize := market.QuantityToChainFormat(d.Quantity) orderPrice := market.PriceToChainFormat(d.Price) - orderMargin := cosmtypes.MustNewDecFromStr("0") + orderMargin := sdk.MustNewDecFromStr("0") if !d.IsReduceOnly { orderMargin = market.CalculateMarginInChainFormat(d.Quantity, d.Price, d.Leverage) @@ -1575,3 +1611,409 @@ func (c *chainClient) FetchCommunityPool(ctx context.Context) (*distributiontype req := &distributiontypes.QueryCommunityPoolRequest{} return c.distributionQueryClient.CommunityPool(ctx, req) } + +// Chain exchange module +func (c *chainClient) FetchSubaccountDeposits(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountDepositsResponse, error) { + req := &exchangetypes.QuerySubaccountDepositsRequest{ + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.SubaccountDeposits(ctx, req) +} + +func (c *chainClient) FetchSubaccountDeposit(ctx context.Context, subaccountId string, denom string) (*exchangetypes.QuerySubaccountDepositResponse, error) { + req := &exchangetypes.QuerySubaccountDepositRequest{ + SubaccountId: subaccountId, + Denom: denom, + } + return c.exchangeQueryClient.SubaccountDeposit(ctx, req) +} + +func (c *chainClient) FetchExchangeBalances(ctx context.Context) (*exchangetypes.QueryExchangeBalancesResponse, error) { + req := &exchangetypes.QueryExchangeBalancesRequest{} + return c.exchangeQueryClient.ExchangeBalances(ctx, req) +} + +func (c *chainClient) FetchAggregateVolume(ctx context.Context, account string) (*exchangetypes.QueryAggregateVolumeResponse, error) { + req := &exchangetypes.QueryAggregateVolumeRequest{ + Account: account, + } + return c.exchangeQueryClient.AggregateVolume(ctx, req) +} + +func (c *chainClient) FetchAggregateVolumes(ctx context.Context, accounts []string, marketIds []string) (*exchangetypes.QueryAggregateVolumesResponse, error) { + req := &exchangetypes.QueryAggregateVolumesRequest{ + Accounts: accounts, + MarketIds: marketIds, + } + return c.exchangeQueryClient.AggregateVolumes(ctx, req) +} + +func (c *chainClient) FetchAggregateMarketVolume(ctx context.Context, marketId string) (*exchangetypes.QueryAggregateMarketVolumeResponse, error) { + req := &exchangetypes.QueryAggregateMarketVolumeRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.AggregateMarketVolume(ctx, req) +} + +func (c *chainClient) FetchAggregateMarketVolumes(ctx context.Context, marketIds []string) (*exchangetypes.QueryAggregateMarketVolumesResponse, error) { + req := &exchangetypes.QueryAggregateMarketVolumesRequest{ + MarketIds: marketIds, + } + return c.exchangeQueryClient.AggregateMarketVolumes(ctx, req) +} + +func (c *chainClient) FetchDenomDecimal(ctx context.Context, denom string) (*exchangetypes.QueryDenomDecimalResponse, error) { + req := &exchangetypes.QueryDenomDecimalRequest{ + Denom: denom, + } + return c.exchangeQueryClient.DenomDecimal(ctx, req) +} + +func (c *chainClient) FetchDenomDecimals(ctx context.Context, denoms []string) (*exchangetypes.QueryDenomDecimalsResponse, error) { + req := &exchangetypes.QueryDenomDecimalsRequest{ + Denoms: denoms, + } + return c.exchangeQueryClient.DenomDecimals(ctx, req) +} + +func (c *chainClient) FetchChainSpotMarkets(ctx context.Context, status string, marketIds []string) (*exchangetypes.QuerySpotMarketsResponse, error) { + req := &exchangetypes.QuerySpotMarketsRequest{ + MarketIds: marketIds, + } + if status != "" { + req.Status = status + } + return c.exchangeQueryClient.SpotMarkets(ctx, req) +} + +func (c *chainClient) FetchChainSpotMarket(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMarketResponse, error) { + req := &exchangetypes.QuerySpotMarketRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.SpotMarket(ctx, req) +} + +func (c *chainClient) FetchChainFullSpotMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketsResponse, error) { + req := &exchangetypes.QueryFullSpotMarketsRequest{ + MarketIds: marketIds, + WithMidPriceAndTob: withMidPriceAndTob, + } + if status != "" { + req.Status = status + } + return c.exchangeQueryClient.FullSpotMarkets(ctx, req) +} + +func (c *chainClient) FetchChainFullSpotMarket(ctx context.Context, marketId string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketResponse, error) { + req := &exchangetypes.QueryFullSpotMarketRequest{ + MarketId: marketId, + WithMidPriceAndTob: withMidPriceAndTob, + } + return c.exchangeQueryClient.FullSpotMarket(ctx, req) +} + +func (c *chainClient) FetchChainSpotOrderbook(ctx context.Context, marketId string, limit uint64, orderSide exchangetypes.OrderSide, limitCumulativeNotional sdk.Dec, limitCumulativeQuantity sdk.Dec) (*exchangetypes.QuerySpotOrderbookResponse, error) { + req := &exchangetypes.QuerySpotOrderbookRequest{ + MarketId: marketId, + Limit: limit, + OrderSide: orderSide, + LimitCumulativeNotional: &limitCumulativeNotional, + LimitCumulativeQuantity: &limitCumulativeQuantity, + } + return c.exchangeQueryClient.SpotOrderbook(ctx, req) +} + +func (c *chainClient) FetchChainTraderSpotOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) { + req := &exchangetypes.QueryTraderSpotOrdersRequest{ + MarketId: marketId, + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.TraderSpotOrders(ctx, req) +} + +func (c *chainClient) FetchChainAccountAddressSpotOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressSpotOrdersResponse, error) { + req := &exchangetypes.QueryAccountAddressSpotOrdersRequest{ + MarketId: marketId, + AccountAddress: address, + } + return c.exchangeQueryClient.AccountAddressSpotOrders(ctx, req) +} + +func (c *chainClient) FetchChainSpotOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QuerySpotOrdersByHashesResponse, error) { + req := &exchangetypes.QuerySpotOrdersByHashesRequest{ + MarketId: marketId, + SubaccountId: subaccountId, + OrderHashes: orderHashes, + } + return c.exchangeQueryClient.SpotOrdersByHashes(ctx, req) +} + +func (c *chainClient) FetchChainSubaccountOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountOrdersResponse, error) { + req := &exchangetypes.QuerySubaccountOrdersRequest{ + SubaccountId: subaccountId, + MarketId: marketId, + } + return c.exchangeQueryClient.SubaccountOrders(ctx, req) +} + +func (c *chainClient) FetchChainTraderSpotTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) { + req := &exchangetypes.QueryTraderSpotOrdersRequest{ + MarketId: marketId, + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.TraderSpotTransientOrders(ctx, req) +} + +func (c *chainClient) FetchSpotMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMidPriceAndTOBResponse, error) { + req := &exchangetypes.QuerySpotMidPriceAndTOBRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.SpotMidPriceAndTOB(ctx, req) +} + +func (c *chainClient) FetchDerivativeMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMidPriceAndTOBResponse, error) { + req := &exchangetypes.QueryDerivativeMidPriceAndTOBRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.DerivativeMidPriceAndTOB(ctx, req) +} + +func (c *chainClient) FetchChainDerivativeOrderbook(ctx context.Context, marketId string, limit uint64, limitCumulativeNotional sdk.Dec) (*exchangetypes.QueryDerivativeOrderbookResponse, error) { + req := &exchangetypes.QueryDerivativeOrderbookRequest{ + MarketId: marketId, + Limit: limit, + LimitCumulativeNotional: &limitCumulativeNotional, + } + return c.exchangeQueryClient.DerivativeOrderbook(ctx, req) +} + +func (c *chainClient) FetchChainTraderDerivativeOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) { + req := &exchangetypes.QueryTraderDerivativeOrdersRequest{ + MarketId: marketId, + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.TraderDerivativeOrders(ctx, req) +} + +func (c *chainClient) FetchChainAccountAddressDerivativeOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressDerivativeOrdersResponse, error) { + req := &exchangetypes.QueryAccountAddressDerivativeOrdersRequest{ + MarketId: marketId, + AccountAddress: address, + } + return c.exchangeQueryClient.AccountAddressDerivativeOrders(ctx, req) +} + +func (c *chainClient) FetchChainDerivativeOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QueryDerivativeOrdersByHashesResponse, error) { + req := &exchangetypes.QueryDerivativeOrdersByHashesRequest{ + MarketId: marketId, + SubaccountId: subaccountId, + OrderHashes: orderHashes, + } + return c.exchangeQueryClient.DerivativeOrdersByHashes(ctx, req) +} + +func (c *chainClient) FetchChainTraderDerivativeTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) { + req := &exchangetypes.QueryTraderDerivativeOrdersRequest{ + MarketId: marketId, + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.TraderDerivativeTransientOrders(ctx, req) +} + +func (c *chainClient) FetchChainDerivativeMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryDerivativeMarketsResponse, error) { + req := &exchangetypes.QueryDerivativeMarketsRequest{ + MarketIds: marketIds, + WithMidPriceAndTob: withMidPriceAndTob, + } + if status != "" { + req.Status = status + } + return c.exchangeQueryClient.DerivativeMarkets(ctx, req) +} + +func (c *chainClient) FetchChainDerivativeMarket(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketResponse, error) { + req := &exchangetypes.QueryDerivativeMarketRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.DerivativeMarket(ctx, req) +} + +func (c *chainClient) FetchDerivativeMarketAddress(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketAddressResponse, error) { + req := &exchangetypes.QueryDerivativeMarketAddressRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.DerivativeMarketAddress(ctx, req) +} + +func (c *chainClient) FetchSubaccountTradeNonce(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountTradeNonceResponse, error) { + req := &exchangetypes.QuerySubaccountTradeNonceRequest{ + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.SubaccountTradeNonce(ctx, req) +} + +func (c *chainClient) FetchChainPositions(ctx context.Context) (*exchangetypes.QueryPositionsResponse, error) { + req := &exchangetypes.QueryPositionsRequest{} + return c.exchangeQueryClient.Positions(ctx, req) +} + +func (c *chainClient) FetchChainSubaccountPositions(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountPositionsResponse, error) { + req := &exchangetypes.QuerySubaccountPositionsRequest{ + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.SubaccountPositions(ctx, req) +} + +func (c *chainClient) FetchChainSubaccountPositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountPositionInMarketResponse, error) { + req := &exchangetypes.QuerySubaccountPositionInMarketRequest{ + SubaccountId: subaccountId, + MarketId: marketId, + } + return c.exchangeQueryClient.SubaccountPositionInMarket(ctx, req) +} + +func (c *chainClient) FetchChainSubaccountEffectivePositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountEffectivePositionInMarketResponse, error) { + req := &exchangetypes.QuerySubaccountEffectivePositionInMarketRequest{ + SubaccountId: subaccountId, + MarketId: marketId, + } + return c.exchangeQueryClient.SubaccountEffectivePositionInMarket(ctx, req) +} + +func (c *chainClient) FetchChainPerpetualMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketInfoResponse, error) { + req := &exchangetypes.QueryPerpetualMarketInfoRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.PerpetualMarketInfo(ctx, req) +} + +func (c *chainClient) FetchChainExpiryFuturesMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryExpiryFuturesMarketInfoResponse, error) { + req := &exchangetypes.QueryExpiryFuturesMarketInfoRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.ExpiryFuturesMarketInfo(ctx, req) +} + +func (c *chainClient) FetchChainPerpetualMarketFunding(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketFundingResponse, error) { + req := &exchangetypes.QueryPerpetualMarketFundingRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.PerpetualMarketFunding(ctx, req) +} + +func (c *chainClient) FetchSubaccountOrderMetadata(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountOrderMetadataResponse, error) { + req := &exchangetypes.QuerySubaccountOrderMetadataRequest{ + SubaccountId: subaccountId, + } + return c.exchangeQueryClient.SubaccountOrderMetadata(ctx, req) +} + +func (c *chainClient) FetchTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) { + req := &exchangetypes.QueryTradeRewardPointsRequest{ + Accounts: accounts, + } + return c.exchangeQueryClient.TradeRewardPoints(ctx, req) +} + +func (c *chainClient) FetchPendingTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) { + req := &exchangetypes.QueryTradeRewardPointsRequest{ + Accounts: accounts, + } + return c.exchangeQueryClient.PendingTradeRewardPoints(ctx, req) +} + +func (c *chainClient) FetchTradeRewardCampaign(ctx context.Context) (*exchangetypes.QueryTradeRewardCampaignResponse, error) { + req := &exchangetypes.QueryTradeRewardCampaignRequest{} + return c.exchangeQueryClient.TradeRewardCampaign(ctx, req) +} + +func (c *chainClient) FetchFeeDiscountAccountInfo(ctx context.Context, account string) (*exchangetypes.QueryFeeDiscountAccountInfoResponse, error) { + req := &exchangetypes.QueryFeeDiscountAccountInfoRequest{ + Account: account, + } + return c.exchangeQueryClient.FeeDiscountAccountInfo(ctx, req) +} + +func (c *chainClient) FetchFeeDiscountSchedule(ctx context.Context) (*exchangetypes.QueryFeeDiscountScheduleResponse, error) { + req := &exchangetypes.QueryFeeDiscountScheduleRequest{} + return c.exchangeQueryClient.FeeDiscountSchedule(ctx, req) +} + +func (c *chainClient) FetchBalanceMismatches(ctx context.Context, dustFactor int64) (*exchangetypes.QueryBalanceMismatchesResponse, error) { + req := &exchangetypes.QueryBalanceMismatchesRequest{ + DustFactor: dustFactor, + } + return c.exchangeQueryClient.BalanceMismatches(ctx, req) +} + +func (c *chainClient) FetchBalanceWithBalanceHolds(ctx context.Context) (*exchangetypes.QueryBalanceWithBalanceHoldsResponse, error) { + req := &exchangetypes.QueryBalanceWithBalanceHoldsRequest{} + return c.exchangeQueryClient.BalanceWithBalanceHolds(ctx, req) +} + +func (c *chainClient) FetchFeeDiscountTierStatistics(ctx context.Context) (*exchangetypes.QueryFeeDiscountTierStatisticsResponse, error) { + req := &exchangetypes.QueryFeeDiscountTierStatisticsRequest{} + return c.exchangeQueryClient.FeeDiscountTierStatistics(ctx, req) +} + +func (c *chainClient) FetchMitoVaultInfos(ctx context.Context) (*exchangetypes.MitoVaultInfosResponse, error) { + req := &exchangetypes.MitoVaultInfosRequest{} + return c.exchangeQueryClient.MitoVaultInfos(ctx, req) +} + +func (c *chainClient) FetchMarketIDFromVault(ctx context.Context, vaultAddress string) (*exchangetypes.QueryMarketIDFromVaultResponse, error) { + req := &exchangetypes.QueryMarketIDFromVaultRequest{ + VaultAddress: vaultAddress, + } + return c.exchangeQueryClient.QueryMarketIDFromVault(ctx, req) +} + +func (c *chainClient) FetchHistoricalTradeRecords(ctx context.Context, marketId string) (*exchangetypes.QueryHistoricalTradeRecordsResponse, error) { + req := &exchangetypes.QueryHistoricalTradeRecordsRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.HistoricalTradeRecords(ctx, req) +} + +func (c *chainClient) FetchIsOptedOutOfRewards(ctx context.Context, account string) (*exchangetypes.QueryIsOptedOutOfRewardsResponse, error) { + req := &exchangetypes.QueryIsOptedOutOfRewardsRequest{ + Account: account, + } + return c.exchangeQueryClient.IsOptedOutOfRewards(ctx, req) +} + +func (c *chainClient) FetchOptedOutOfRewardsAccounts(ctx context.Context) (*exchangetypes.QueryOptedOutOfRewardsAccountsResponse, error) { + req := &exchangetypes.QueryOptedOutOfRewardsAccountsRequest{} + return c.exchangeQueryClient.OptedOutOfRewardsAccounts(ctx, req) +} + +func (c *chainClient) FetchMarketVolatility(ctx context.Context, marketId string, tradeHistoryOptions *exchangetypes.TradeHistoryOptions) (*exchangetypes.QueryMarketVolatilityResponse, error) { + req := &exchangetypes.QueryMarketVolatilityRequest{ + MarketId: marketId, + TradeHistoryOptions: tradeHistoryOptions, + } + return c.exchangeQueryClient.MarketVolatility(ctx, req) +} + +func (c *chainClient) FetchChainBinaryOptionsMarkets(ctx context.Context, status string) (*exchangetypes.QueryBinaryMarketsResponse, error) { + req := &exchangetypes.QueryBinaryMarketsRequest{} + if status != "" { + req.Status = status + } + return c.exchangeQueryClient.BinaryOptionsMarkets(ctx, req) +} + +func (c *chainClient) FetchTraderDerivativeConditionalOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QueryTraderDerivativeConditionalOrdersResponse, error) { + req := &exchangetypes.QueryTraderDerivativeConditionalOrdersRequest{ + SubaccountId: subaccountId, + MarketId: marketId, + } + return c.exchangeQueryClient.TraderDerivativeConditionalOrders(ctx, req) +} + +func (c *chainClient) FetchMarketAtomicExecutionFeeMultiplier(ctx context.Context, marketId string) (*exchangetypes.QueryMarketAtomicExecutionFeeMultiplierResponse, error) { + req := &exchangetypes.QueryMarketAtomicExecutionFeeMultiplierRequest{ + MarketId: marketId, + } + return c.exchangeQueryClient.MarketAtomicExecutionFeeMultiplier(ctx, req) +} diff --git a/client/chain/chain_test_support.go b/client/chain/chain_test_support.go index 850fe883..5ae0cfb6 100644 --- a/client/chain/chain_test_support.go +++ b/client/chain/chain_test_support.go @@ -325,3 +325,224 @@ func (c *MockChainClient) FetchDelegatorWithdrawAddress(ctx context.Context, del func (c *MockChainClient) FetchCommunityPool(ctx context.Context) (*distributiontypes.QueryCommunityPoolResponse, error) { return &distributiontypes.QueryCommunityPoolResponse{}, nil } + +// Chain exchange module +func (c *MockChainClient) FetchSubaccountDeposits(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountDepositsResponse, error) { + return &exchangetypes.QuerySubaccountDepositsResponse{}, nil +} + +func (c *MockChainClient) FetchSubaccountDeposit(ctx context.Context, subaccountId string, denom string) (*exchangetypes.QuerySubaccountDepositResponse, error) { + return &exchangetypes.QuerySubaccountDepositResponse{}, nil +} + +func (c *MockChainClient) FetchExchangeBalances(ctx context.Context) (*exchangetypes.QueryExchangeBalancesResponse, error) { + return &exchangetypes.QueryExchangeBalancesResponse{}, nil +} + +func (c *MockChainClient) FetchAggregateVolume(ctx context.Context, account string) (*exchangetypes.QueryAggregateVolumeResponse, error) { + return &exchangetypes.QueryAggregateVolumeResponse{}, nil +} + +func (c *MockChainClient) FetchAggregateVolumes(ctx context.Context, accounts []string, marketIds []string) (*exchangetypes.QueryAggregateVolumesResponse, error) { + return &exchangetypes.QueryAggregateVolumesResponse{}, nil +} + +func (c *MockChainClient) FetchAggregateMarketVolume(ctx context.Context, marketId string) (*exchangetypes.QueryAggregateMarketVolumeResponse, error) { + return &exchangetypes.QueryAggregateMarketVolumeResponse{}, nil +} + +func (c *MockChainClient) FetchAggregateMarketVolumes(ctx context.Context, marketIds []string) (*exchangetypes.QueryAggregateMarketVolumesResponse, error) { + return &exchangetypes.QueryAggregateMarketVolumesResponse{}, nil +} + +func (c *MockChainClient) FetchDenomDecimal(ctx context.Context, denom string) (*exchangetypes.QueryDenomDecimalResponse, error) { + return &exchangetypes.QueryDenomDecimalResponse{}, nil +} + +func (c *MockChainClient) FetchDenomDecimals(ctx context.Context, denoms []string) (*exchangetypes.QueryDenomDecimalsResponse, error) { + return &exchangetypes.QueryDenomDecimalsResponse{}, nil +} + +func (c *MockChainClient) FetchChainSpotMarkets(ctx context.Context, status string, marketIds []string) (*exchangetypes.QuerySpotMarketsResponse, error) { + return &exchangetypes.QuerySpotMarketsResponse{}, nil +} + +func (c *MockChainClient) FetchChainSpotMarket(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMarketResponse, error) { + return &exchangetypes.QuerySpotMarketResponse{}, nil +} + +func (c *MockChainClient) FetchChainFullSpotMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketsResponse, error) { + return &exchangetypes.QueryFullSpotMarketsResponse{}, nil +} + +func (c *MockChainClient) FetchChainFullSpotMarket(ctx context.Context, marketId string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketResponse, error) { + return &exchangetypes.QueryFullSpotMarketResponse{}, nil +} + +func (c *MockChainClient) FetchChainSpotOrderbook(ctx context.Context, marketId string, limit uint64, orderSide exchangetypes.OrderSide, limitCumulativeNotional sdk.Dec, limitCumulativeQuantity sdk.Dec) (*exchangetypes.QuerySpotOrderbookResponse, error) { + return &exchangetypes.QuerySpotOrderbookResponse{}, nil +} + +func (c *MockChainClient) FetchChainTraderSpotOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) { + return &exchangetypes.QueryTraderSpotOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchChainAccountAddressSpotOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressSpotOrdersResponse, error) { + return &exchangetypes.QueryAccountAddressSpotOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchChainSpotOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QuerySpotOrdersByHashesResponse, error) { + return &exchangetypes.QuerySpotOrdersByHashesResponse{}, nil +} + +func (c *MockChainClient) FetchChainSubaccountOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountOrdersResponse, error) { + return &exchangetypes.QuerySubaccountOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchChainTraderSpotTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) { + return &exchangetypes.QueryTraderSpotOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchSpotMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMidPriceAndTOBResponse, error) { + return &exchangetypes.QuerySpotMidPriceAndTOBResponse{}, nil +} + +func (c *MockChainClient) FetchDerivativeMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMidPriceAndTOBResponse, error) { + return &exchangetypes.QueryDerivativeMidPriceAndTOBResponse{}, nil +} + +func (c *MockChainClient) FetchChainDerivativeOrderbook(ctx context.Context, marketId string, limit uint64, limitCumulativeNotional sdk.Dec) (*exchangetypes.QueryDerivativeOrderbookResponse, error) { + return &exchangetypes.QueryDerivativeOrderbookResponse{}, nil +} + +func (c *MockChainClient) FetchChainTraderDerivativeOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) { + return &exchangetypes.QueryTraderDerivativeOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchChainAccountAddressDerivativeOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressDerivativeOrdersResponse, error) { + return &exchangetypes.QueryAccountAddressDerivativeOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchChainDerivativeOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QueryDerivativeOrdersByHashesResponse, error) { + return &exchangetypes.QueryDerivativeOrdersByHashesResponse{}, nil +} + +func (c *MockChainClient) FetchChainTraderDerivativeTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) { + return &exchangetypes.QueryTraderDerivativeOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchChainDerivativeMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryDerivativeMarketsResponse, error) { + return &exchangetypes.QueryDerivativeMarketsResponse{}, nil +} + +func (c *MockChainClient) FetchChainDerivativeMarket(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketResponse, error) { + return &exchangetypes.QueryDerivativeMarketResponse{}, nil +} + +func (c *MockChainClient) FetchDerivativeMarketAddress(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketAddressResponse, error) { + return &exchangetypes.QueryDerivativeMarketAddressResponse{}, nil +} + +func (c *MockChainClient) FetchSubaccountTradeNonce(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountTradeNonceResponse, error) { + return &exchangetypes.QuerySubaccountTradeNonceResponse{}, nil +} + +func (c *MockChainClient) FetchChainPositions(ctx context.Context) (*exchangetypes.QueryPositionsResponse, error) { + return &exchangetypes.QueryPositionsResponse{}, nil +} + +func (c *MockChainClient) FetchChainSubaccountPositions(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountPositionsResponse, error) { + return &exchangetypes.QuerySubaccountPositionsResponse{}, nil +} + +func (c *MockChainClient) FetchChainSubaccountPositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountPositionInMarketResponse, error) { + return &exchangetypes.QuerySubaccountPositionInMarketResponse{}, nil +} + +func (c *MockChainClient) FetchChainSubaccountEffectivePositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountEffectivePositionInMarketResponse, error) { + return &exchangetypes.QuerySubaccountEffectivePositionInMarketResponse{}, nil +} + +func (c *MockChainClient) FetchChainPerpetualMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketInfoResponse, error) { + return &exchangetypes.QueryPerpetualMarketInfoResponse{}, nil +} + +func (c *MockChainClient) FetchChainExpiryFuturesMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryExpiryFuturesMarketInfoResponse, error) { + return &exchangetypes.QueryExpiryFuturesMarketInfoResponse{}, nil +} + +func (c *MockChainClient) FetchChainPerpetualMarketFunding(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketFundingResponse, error) { + return &exchangetypes.QueryPerpetualMarketFundingResponse{}, nil +} + +func (c *MockChainClient) FetchSubaccountOrderMetadata(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountOrderMetadataResponse, error) { + return &exchangetypes.QuerySubaccountOrderMetadataResponse{}, nil +} + +func (c *MockChainClient) FetchTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) { + return &exchangetypes.QueryTradeRewardPointsResponse{}, nil +} + +func (c *MockChainClient) FetchPendingTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) { + return &exchangetypes.QueryTradeRewardPointsResponse{}, nil +} + +func (c *MockChainClient) FetchTradeRewardCampaign(ctx context.Context) (*exchangetypes.QueryTradeRewardCampaignResponse, error) { + return &exchangetypes.QueryTradeRewardCampaignResponse{}, nil +} + +func (c *MockChainClient) FetchFeeDiscountAccountInfo(ctx context.Context, account string) (*exchangetypes.QueryFeeDiscountAccountInfoResponse, error) { + return &exchangetypes.QueryFeeDiscountAccountInfoResponse{}, nil +} + +func (c *MockChainClient) FetchFeeDiscountSchedule(ctx context.Context) (*exchangetypes.QueryFeeDiscountScheduleResponse, error) { + return &exchangetypes.QueryFeeDiscountScheduleResponse{}, nil +} + +func (c *MockChainClient) FetchBalanceMismatches(ctx context.Context, dustFactor int64) (*exchangetypes.QueryBalanceMismatchesResponse, error) { + return &exchangetypes.QueryBalanceMismatchesResponse{}, nil +} + +func (c *MockChainClient) FetchBalanceWithBalanceHolds(ctx context.Context) (*exchangetypes.QueryBalanceWithBalanceHoldsResponse, error) { + return &exchangetypes.QueryBalanceWithBalanceHoldsResponse{}, nil +} + +func (c *MockChainClient) FetchFeeDiscountTierStatistics(ctx context.Context) (*exchangetypes.QueryFeeDiscountTierStatisticsResponse, error) { + return &exchangetypes.QueryFeeDiscountTierStatisticsResponse{}, nil +} + +func (c *MockChainClient) FetchMitoVaultInfos(ctx context.Context) (*exchangetypes.MitoVaultInfosResponse, error) { + return &exchangetypes.MitoVaultInfosResponse{}, nil +} + +func (c *MockChainClient) FetchMarketIDFromVault(ctx context.Context, vaultAddress string) (*exchangetypes.QueryMarketIDFromVaultResponse, error) { + return &exchangetypes.QueryMarketIDFromVaultResponse{}, nil +} + +func (c *MockChainClient) FetchHistoricalTradeRecords(ctx context.Context, marketId string) (*exchangetypes.QueryHistoricalTradeRecordsResponse, error) { + return &exchangetypes.QueryHistoricalTradeRecordsResponse{}, nil +} + +func (c *MockChainClient) FetchIsOptedOutOfRewards(ctx context.Context, account string) (*exchangetypes.QueryIsOptedOutOfRewardsResponse, error) { + return &exchangetypes.QueryIsOptedOutOfRewardsResponse{}, nil +} + +func (c *MockChainClient) FetchOptedOutOfRewardsAccounts(ctx context.Context) (*exchangetypes.QueryOptedOutOfRewardsAccountsResponse, error) { + return &exchangetypes.QueryOptedOutOfRewardsAccountsResponse{}, nil +} + +func (c *MockChainClient) FetchMarketVolatility(ctx context.Context, marketId string, tradeHistoryOptions *exchangetypes.TradeHistoryOptions) (*exchangetypes.QueryMarketVolatilityResponse, error) { + return &exchangetypes.QueryMarketVolatilityResponse{}, nil +} + +func (c *MockChainClient) FetchChainBinaryOptionsMarkets(ctx context.Context, status string) (*exchangetypes.QueryBinaryMarketsResponse, error) { + return &exchangetypes.QueryBinaryMarketsResponse{}, nil +} + +func (c *MockChainClient) FetchTraderDerivativeConditionalOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QueryTraderDerivativeConditionalOrdersResponse, error) { + return &exchangetypes.QueryTraderDerivativeConditionalOrdersResponse{}, nil +} + +func (c *MockChainClient) FetchMarketAtomicExecutionFeeMultiplier(ctx context.Context, marketId string) (*exchangetypes.QueryMarketAtomicExecutionFeeMultiplierResponse, error) { + return &exchangetypes.QueryMarketAtomicExecutionFeeMultiplierResponse{}, nil +} diff --git a/examples/chain/36_StreamEventOrderbookUpdate/example.go b/examples/chain/10_StreamEventOrderbookUpdate/example.go similarity index 100% rename from examples/chain/36_StreamEventOrderbookUpdate/example.go rename to examples/chain/10_StreamEventOrderbookUpdate/example.go diff --git a/examples/chain/37_DecodeTx/37_decode_tx.go b/examples/chain/11_DecodeTx/37_decode_tx.go similarity index 100% rename from examples/chain/37_DecodeTx/37_decode_tx.go rename to examples/chain/11_DecodeTx/37_decode_tx.go diff --git a/examples/chain/40_ChainStream/example.go b/examples/chain/12_ChainStream/example.go similarity index 100% rename from examples/chain/40_ChainStream/example.go rename to examples/chain/12_ChainStream/example.go diff --git a/examples/chain/41_BroadcastMsgWithoutSimulation/example.go b/examples/chain/13_BroadcastMsgWithoutSimulation/example.go similarity index 100% rename from examples/chain/41_BroadcastMsgWithoutSimulation/example.go rename to examples/chain/13_BroadcastMsgWithoutSimulation/example.go diff --git a/examples/chain/0_LocalOrderHash/example.go b/examples/chain/1_LocalOrderHash/example.go similarity index 100% rename from examples/chain/0_LocalOrderHash/example.go rename to examples/chain/1_LocalOrderHash/example.go diff --git a/examples/chain/9_MsgBatchCancelSpotOrders/example.go b/examples/chain/2_MsgBatchCancelSpotOrders/example.go similarity index 100% rename from examples/chain/9_MsgBatchCancelSpotOrders/example.go rename to examples/chain/2_MsgBatchCancelSpotOrders/example.go diff --git a/examples/chain/10_MsgBatchCancelDerivativeOrders/example.go b/examples/chain/3_MsgBatchCancelDerivativeOrders/example.go similarity index 100% rename from examples/chain/10_MsgBatchCancelDerivativeOrders/example.go rename to examples/chain/3_MsgBatchCancelDerivativeOrders/example.go diff --git a/examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go b/examples/chain/4_MsgBatchCreateSpotLimitOrders/example.go similarity index 100% rename from examples/chain/11_MsgBatchCreateSpotLimitOrders/example.go rename to examples/chain/4_MsgBatchCreateSpotLimitOrders/example.go diff --git a/examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go b/examples/chain/5_MsgBatchCreateDerivativeLimitOrders/example.go similarity index 100% rename from examples/chain/12_MsgBatchCreateDerivativeLimitOrders/example.go rename to examples/chain/5_MsgBatchCreateDerivativeLimitOrders/example.go diff --git a/examples/chain/24_MsgRegisterAsDMM/example.go b/examples/chain/6_MsgRegisterAsDMM/example.go similarity index 100% rename from examples/chain/24_MsgRegisterAsDMM/example.go rename to examples/chain/6_MsgRegisterAsDMM/example.go diff --git a/examples/chain/33_GetBlock/example.go b/examples/chain/7_GetBlock/example.go similarity index 100% rename from examples/chain/33_GetBlock/example.go rename to examples/chain/7_GetBlock/example.go diff --git a/examples/chain/34_OfflineSigning/example.go b/examples/chain/8_OfflineSigning/example.go similarity index 100% rename from examples/chain/34_OfflineSigning/example.go rename to examples/chain/8_OfflineSigning/example.go diff --git a/examples/chain/35_StreamEventOrderFail/example.go b/examples/chain/9_StreamEventOrderFail/example.go similarity index 100% rename from examples/chain/35_StreamEventOrderFail/example.go rename to examples/chain/9_StreamEventOrderFail/example.go diff --git a/examples/chain/18_MsgBid/example.go b/examples/chain/auction/1_MsgBid/example.go similarity index 100% rename from examples/chain/18_MsgBid/example.go rename to examples/chain/auction/1_MsgBid/example.go diff --git a/examples/chain/32_Account/example.go b/examples/chain/auth/query/1_Account/example.go similarity index 100% rename from examples/chain/32_Account/example.go rename to examples/chain/auth/query/1_Account/example.go diff --git a/examples/chain/19_MsgGrant/example.go b/examples/chain/authz/1_MsgGrant/example.go similarity index 100% rename from examples/chain/19_MsgGrant/example.go rename to examples/chain/authz/1_MsgGrant/example.go diff --git a/examples/chain/20_MsgExec/example.go b/examples/chain/authz/2_MsgExec/example.go similarity index 100% rename from examples/chain/20_MsgExec/example.go rename to examples/chain/authz/2_MsgExec/example.go diff --git a/examples/chain/21_MsgRevoke/example.go b/examples/chain/authz/3_MsgRevoke/example.go similarity index 100% rename from examples/chain/21_MsgRevoke/example.go rename to examples/chain/authz/3_MsgRevoke/example.go diff --git a/examples/chain/27_QueryAuthzGrants/example.go b/examples/chain/authz/query/1_Grants/example.go similarity index 100% rename from examples/chain/27_QueryAuthzGrants/example.go rename to examples/chain/authz/query/1_Grants/example.go diff --git a/examples/chain/1_MsgSend/example.go b/examples/chain/bank/1_MsgSend/example.go similarity index 100% rename from examples/chain/1_MsgSend/example.go rename to examples/chain/bank/1_MsgSend/example.go diff --git a/examples/chain/31_MsgMultiSend/example.go b/examples/chain/bank/2_MsgMultiSend/example.go similarity index 100% rename from examples/chain/31_MsgMultiSend/example.go rename to examples/chain/bank/2_MsgMultiSend/example.go diff --git a/examples/chain/49_BankSendEnabled/example.go b/examples/chain/bank/query/10_BankSendEnabled/example.go similarity index 100% rename from examples/chain/49_BankSendEnabled/example.go rename to examples/chain/bank/query/10_BankSendEnabled/example.go diff --git a/examples/chain/29_BankBalance/example.go b/examples/chain/bank/query/1_BankBalance/example.go similarity index 100% rename from examples/chain/29_BankBalance/example.go rename to examples/chain/bank/query/1_BankBalance/example.go diff --git a/examples/chain/28_BankBalances/example.go b/examples/chain/bank/query/2_BankBalances/example.go similarity index 100% rename from examples/chain/28_BankBalances/example.go rename to examples/chain/bank/query/2_BankBalances/example.go diff --git a/examples/chain/42_BankSpendableBalances/example.go b/examples/chain/bank/query/3_BankSpendableBalances/example.go similarity index 100% rename from examples/chain/42_BankSpendableBalances/example.go rename to examples/chain/bank/query/3_BankSpendableBalances/example.go diff --git a/examples/chain/43_BankSpendableBalancesByDenom/example.go b/examples/chain/bank/query/4_BankSpendableBalancesByDenom/example.go similarity index 100% rename from examples/chain/43_BankSpendableBalancesByDenom/example.go rename to examples/chain/bank/query/4_BankSpendableBalancesByDenom/example.go diff --git a/examples/chain/44_BankTotalSupply/example.go b/examples/chain/bank/query/5_BankTotalSupply/example.go similarity index 100% rename from examples/chain/44_BankTotalSupply/example.go rename to examples/chain/bank/query/5_BankTotalSupply/example.go diff --git a/examples/chain/45_BankSupplyOf/example.go b/examples/chain/bank/query/6_BankSupplyOf/example.go similarity index 100% rename from examples/chain/45_BankSupplyOf/example.go rename to examples/chain/bank/query/6_BankSupplyOf/example.go diff --git a/examples/chain/46_DenomMetadata/example.go b/examples/chain/bank/query/7_DenomMetadata/example.go similarity index 100% rename from examples/chain/46_DenomMetadata/example.go rename to examples/chain/bank/query/7_DenomMetadata/example.go diff --git a/examples/chain/47_DenomsMetadata/example.go b/examples/chain/bank/query/8_DenomsMetadata/example.go similarity index 100% rename from examples/chain/47_DenomsMetadata/example.go rename to examples/chain/bank/query/8_DenomsMetadata/example.go diff --git a/examples/chain/48_DenomOwners/example.go b/examples/chain/bank/query/9_DenomOwners/example.go similarity index 100% rename from examples/chain/48_DenomOwners/example.go rename to examples/chain/bank/query/9_DenomOwners/example.go diff --git a/examples/chain/6_MsgCreateDerivativeLimitOrder/example.go b/examples/chain/exchange/10_MsgCreateDerivativeLimitOrder/example.go similarity index 100% rename from examples/chain/6_MsgCreateDerivativeLimitOrder/example.go rename to examples/chain/exchange/10_MsgCreateDerivativeLimitOrder/example.go diff --git a/examples/chain/7_MsgCreateDerivativeMarketOrder/example.go b/examples/chain/exchange/11_MsgCreateDerivativeMarketOrder/example.go similarity index 100% rename from examples/chain/7_MsgCreateDerivativeMarketOrder/example.go rename to examples/chain/exchange/11_MsgCreateDerivativeMarketOrder/example.go diff --git a/examples/chain/8_MsgCancelDerivativeOrder/example.go b/examples/chain/exchange/12_MsgCancelDerivativeOrder/example.go similarity index 100% rename from examples/chain/8_MsgCancelDerivativeOrder/example.go rename to examples/chain/exchange/12_MsgCancelDerivativeOrder/example.go diff --git a/examples/chain/exchange/13_MsgInstantBinaryOptionsMarketLaunch/example.go b/examples/chain/exchange/13_MsgInstantBinaryOptionsMarketLaunch/example.go new file mode 100644 index 00000000..be7b7ddc --- /dev/null +++ b/examples/chain/exchange/13_MsgInstantBinaryOptionsMarketLaunch/example.go @@ -0,0 +1,107 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types" + exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange" + + "github.com/cosmos/cosmos-sdk/types" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + if err != nil { + panic(err) + } + + exchangeClient, err := exchangeclient.NewExchangeClient(network) + if err != nil { + panic(err) + } + + ctx := context.Background() + marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient) + if err != nil { + panic(err) + } + + quoteToken := marketsAssistant.AllTokens()["USDC"] + minPriceTickSize := types.MustNewDecFromStr("0.01") + minQuantityTickSize := types.MustNewDecFromStr("0.001") + + chainMinPriceTickSize := minPriceTickSize.Mul(types.NewDecFromIntWithPrec(types.NewInt(1), int64(quoteToken.Decimals))) + chainMinQuantityTickSize := minQuantityTickSize + + msg := &exchangetypes.MsgInstantBinaryOptionsMarketLaunch{ + Sender: senderAddress.String(), + Ticker: "UFC-KHABIB-TKO-05/30/2023", + OracleSymbol: "UFC-KHABIB-TKO-05/30/2023", + OracleProvider: "UFC", + OracleType: oracletypes.OracleType_Provider, + OracleScaleFactor: 6, + MakerFeeRate: types.MustNewDecFromStr("0.0005"), + TakerFeeRate: types.MustNewDecFromStr("0.0010"), + ExpirationTimestamp: 1680730982, + SettlementTimestamp: 1690730982, + Admin: senderAddress.String(), + QuoteDenom: quoteToken.Denom, + MinPriceTickSize: chainMinPriceTickSize, + MinQuantityTickSize: chainMinQuantityTickSize, + } + + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + response, err := chainClient.AsyncBroadcastMsg(msg) + + if err != nil { + panic(err) + } + + str, _ := json.MarshalIndent(response, "", " ") + fmt.Print(string(str)) +} diff --git a/examples/chain/16_MsgSubaccountTransfer/example.go b/examples/chain/exchange/14_MsgSubaccountTransfer/example.go similarity index 100% rename from examples/chain/16_MsgSubaccountTransfer/example.go rename to examples/chain/exchange/14_MsgSubaccountTransfer/example.go diff --git a/examples/chain/30_MsgExternalTransfer/example.go b/examples/chain/exchange/15_MsgExternalTransfer/example.go similarity index 100% rename from examples/chain/30_MsgExternalTransfer/example.go rename to examples/chain/exchange/15_MsgExternalTransfer/example.go diff --git a/examples/chain/70_MsgLiquidatePosition/example.go b/examples/chain/exchange/16_MsgLiquidatePosition/example.go similarity index 100% rename from examples/chain/70_MsgLiquidatePosition/example.go rename to examples/chain/exchange/16_MsgLiquidatePosition/example.go diff --git a/examples/chain/13_MsgIncreasePositionMargin/example.go b/examples/chain/exchange/17_MsgIncreasePositionMargin/example.go similarity index 100% rename from examples/chain/13_MsgIncreasePositionMargin/example.go rename to examples/chain/exchange/17_MsgIncreasePositionMargin/example.go diff --git a/examples/chain/2_MsgDeposit/example.go b/examples/chain/exchange/1_MsgDeposit/example.go similarity index 100% rename from examples/chain/2_MsgDeposit/example.go rename to examples/chain/exchange/1_MsgDeposit/example.go diff --git a/examples/chain/38_MsgLiquidate/example.go b/examples/chain/exchange/21_MsgRewardsOptOut/example.go similarity index 58% rename from examples/chain/38_MsgLiquidate/example.go rename to examples/chain/exchange/21_MsgRewardsOptOut/example.go index c43327b7..ca877e9e 100644 --- a/examples/chain/38_MsgLiquidate/example.go +++ b/examples/chain/exchange/21_MsgRewardsOptOut/example.go @@ -8,20 +8,16 @@ import ( "github.com/InjectiveLabs/sdk-go/client" "github.com/InjectiveLabs/sdk-go/client/common" - rpchttp "github.com/cometbft/cometbft/rpc/client/http" - exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" ) func main() { - // network := common.LoadNetwork("mainnet", "k8s") - network := common.LoadNetwork("devnet-1", "") - tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket") - + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") if err != nil { - fmt.Println(err) - return + panic(err) } senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( @@ -45,11 +41,10 @@ func main() { ) if err != nil { - fmt.Println(err) - return + panic(err) } - clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC) + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) chainClient, err := chainclient.NewChainClient( clientCtx, @@ -61,38 +56,15 @@ func main() { panic(err) } - defaultSubaccountID := chainClient.DefaultSubaccount(senderAddress) - - marketId := "0x56d0c0293c4415e2d48fc2c8503a56a0c7389247396a2ef9b0a48c01f0646705" - - liqMsg := exchangetypes.MsgLiquidatePosition{ - Sender: senderAddress.String(), - SubaccountId: defaultSubaccountID.String(), - MarketId: marketId, - Order: nil, - } - - simRes, err := chainClient.SimulateMsg(clientCtx, &liqMsg) - - if err != nil { - fmt.Println(err) - return - } - - msgLiquidatePositionResponse := exchangetypes.MsgLiquidatePositionResponse{} - msgLiquidatePositionResponse.Unmarshal(simRes.Result.MsgResponses[0].Value) - - if err != nil { - fmt.Println(err) - return + msg := &exchangetypes.MsgRewardsOptOut{ + Sender: senderAddress.String(), } //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg - err = chainClient.QueueBroadcastMsg(&liqMsg) + err = chainClient.QueueBroadcastMsg(msg) if err != nil { fmt.Println(err) - return } time.Sleep(time.Second * 5) diff --git a/examples/chain/15_MsgWithdraw/example.go b/examples/chain/exchange/2_MsgWithdraw/example.go similarity index 100% rename from examples/chain/15_MsgWithdraw/example.go rename to examples/chain/exchange/2_MsgWithdraw/example.go diff --git a/examples/chain/exchange/3_MsgInstantSpotMarketLaunch/example.go b/examples/chain/exchange/3_MsgInstantSpotMarketLaunch/example.go new file mode 100644 index 00000000..2bd6e62a --- /dev/null +++ b/examples/chain/exchange/3_MsgInstantSpotMarketLaunch/example.go @@ -0,0 +1,101 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange" + + "github.com/cosmos/cosmos-sdk/types" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + if err != nil { + panic(err) + } + + exchangeClient, err := exchangeclient.NewExchangeClient(network) + if err != nil { + panic(err) + } + + ctx := context.Background() + marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient) + if err != nil { + panic(err) + } + + baseToken := marketsAssistant.AllTokens()["INJ"] + quoteToken := marketsAssistant.AllTokens()["USDC"] + minPriceTickSize := types.MustNewDecFromStr("0.01") + minQuantityTickSize := types.MustNewDecFromStr("0.001") + + chainMinPriceTickSize := minPriceTickSize.Mul(types.NewDecFromIntWithPrec(types.NewInt(1), int64(quoteToken.Decimals))) + chainMinPriceTickSize = chainMinPriceTickSize.Quo(types.NewDecFromIntWithPrec(types.NewInt(1), int64(baseToken.Decimals))) + + chainMinQuantityTickSize := minQuantityTickSize.Mul(types.NewDecFromIntWithPrec(types.NewInt(1), int64(baseToken.Decimals))) + + msg := &exchangetypes.MsgInstantSpotMarketLaunch{ + Sender: senderAddress.String(), + Ticker: "INJ/USDC", + BaseDenom: baseToken.Denom, + QuoteDenom: quoteToken.Denom, + MinPriceTickSize: chainMinPriceTickSize, + MinQuantityTickSize: chainMinQuantityTickSize, + } + + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + response, err := chainClient.AsyncBroadcastMsg(msg) + + if err != nil { + panic(err) + } + + str, _ := json.MarshalIndent(response, "", " ") + fmt.Print(string(str)) +} diff --git a/examples/chain/exchange/4_MsgInstantPerpetualMarketLaunch/example.go b/examples/chain/exchange/4_MsgInstantPerpetualMarketLaunch/example.go new file mode 100644 index 00000000..0792a6d2 --- /dev/null +++ b/examples/chain/exchange/4_MsgInstantPerpetualMarketLaunch/example.go @@ -0,0 +1,106 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types" + exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange" + + "github.com/cosmos/cosmos-sdk/types" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + if err != nil { + panic(err) + } + + exchangeClient, err := exchangeclient.NewExchangeClient(network) + if err != nil { + panic(err) + } + + ctx := context.Background() + marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient) + if err != nil { + panic(err) + } + + quoteToken := marketsAssistant.AllTokens()["USDC"] + minPriceTickSize := types.MustNewDecFromStr("0.01") + minQuantityTickSize := types.MustNewDecFromStr("0.001") + + chainMinPriceTickSize := minPriceTickSize.Mul(types.NewDecFromIntWithPrec(types.NewInt(1), int64(quoteToken.Decimals))) + chainMinQuantityTickSize := minQuantityTickSize + + msg := &exchangetypes.MsgInstantPerpetualMarketLaunch{ + Sender: senderAddress.String(), + Ticker: "INJ/USDC PERP", + QuoteDenom: quoteToken.Denom, + OracleBase: "INJ", + OracleQuote: "USDC", + OracleScaleFactor: 6, + OracleType: oracletypes.OracleType_Band, + MakerFeeRate: types.MustNewDecFromStr("-0.0001"), + TakerFeeRate: types.MustNewDecFromStr("0.001"), + InitialMarginRatio: types.MustNewDecFromStr("0.33"), + MaintenanceMarginRatio: types.MustNewDecFromStr("0.095"), + MinPriceTickSize: chainMinPriceTickSize, + MinQuantityTickSize: chainMinQuantityTickSize, + } + + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + response, err := chainClient.AsyncBroadcastMsg(msg) + + if err != nil { + panic(err) + } + + str, _ := json.MarshalIndent(response, "", " ") + fmt.Print(string(str)) +} diff --git a/examples/chain/exchange/5_MsgInstantExpiryFuturesMarketLaunch/example.go b/examples/chain/exchange/5_MsgInstantExpiryFuturesMarketLaunch/example.go new file mode 100644 index 00000000..dac6f76f --- /dev/null +++ b/examples/chain/exchange/5_MsgInstantExpiryFuturesMarketLaunch/example.go @@ -0,0 +1,107 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types" + exchangeclient "github.com/InjectiveLabs/sdk-go/client/exchange" + + "github.com/cosmos/cosmos-sdk/types" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + if err != nil { + panic(err) + } + + exchangeClient, err := exchangeclient.NewExchangeClient(network) + if err != nil { + panic(err) + } + + ctx := context.Background() + marketsAssistant, err := chainclient.NewMarketsAssistantInitializedFromChain(ctx, exchangeClient) + if err != nil { + panic(err) + } + + quoteToken := marketsAssistant.AllTokens()["USDC"] + minPriceTickSize := types.MustNewDecFromStr("0.01") + minQuantityTickSize := types.MustNewDecFromStr("0.001") + + chainMinPriceTickSize := minPriceTickSize.Mul(types.NewDecFromIntWithPrec(types.NewInt(1), int64(quoteToken.Decimals))) + chainMinQuantityTickSize := minQuantityTickSize + + msg := &exchangetypes.MsgInstantExpiryFuturesMarketLaunch{ + Sender: senderAddress.String(), + Ticker: "INJ/USDC FUT", + QuoteDenom: quoteToken.Denom, + OracleBase: "INJ", + OracleQuote: "USDC", + OracleScaleFactor: 6, + OracleType: oracletypes.OracleType_Band, + Expiry: 2000000000, + MakerFeeRate: types.MustNewDecFromStr("-0.0001"), + TakerFeeRate: types.MustNewDecFromStr("0.001"), + InitialMarginRatio: types.MustNewDecFromStr("0.33"), + MaintenanceMarginRatio: types.MustNewDecFromStr("0.095"), + MinPriceTickSize: chainMinPriceTickSize, + MinQuantityTickSize: chainMinQuantityTickSize, + } + + //AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg + response, err := chainClient.AsyncBroadcastMsg(msg) + + if err != nil { + panic(err) + } + + str, _ := json.MarshalIndent(response, "", " ") + fmt.Print(string(str)) +} diff --git a/examples/chain/3_MsgCreateSpotLimitOrder/example.go b/examples/chain/exchange/6_MsgCreateSpotLimitOrder/example.go similarity index 100% rename from examples/chain/3_MsgCreateSpotLimitOrder/example.go rename to examples/chain/exchange/6_MsgCreateSpotLimitOrder/example.go diff --git a/examples/chain/4_MsgCreateSpotMarketOrder/example.go b/examples/chain/exchange/7_MsgCreateSpotMarketOrder/example.go similarity index 100% rename from examples/chain/4_MsgCreateSpotMarketOrder/example.go rename to examples/chain/exchange/7_MsgCreateSpotMarketOrder/example.go diff --git a/examples/chain/5_MsgCancelSpotOrder/example.go b/examples/chain/exchange/8_MsgCancelSpotOrder/example.go similarity index 100% rename from examples/chain/5_MsgCancelSpotOrder/example.go rename to examples/chain/exchange/8_MsgCancelSpotOrder/example.go diff --git a/examples/chain/17_MsgBatchUpdateOrders/example.go b/examples/chain/exchange/9_MsgBatchUpdateOrders/example.go similarity index 100% rename from examples/chain/17_MsgBatchUpdateOrders/example.go rename to examples/chain/exchange/9_MsgBatchUpdateOrders/example.go diff --git a/examples/chain/exchange/query/10_SpotMarkets/example.go b/examples/chain/exchange/query/10_SpotMarkets/example.go new file mode 100644 index 00000000..9bb071e4 --- /dev/null +++ b/examples/chain/exchange/query/10_SpotMarkets/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + status := "Active" + marketIds := []string{"0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"} + + res, err := chainClient.FetchChainSpotMarkets(ctx, status, marketIds) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/11_SpotMarket/example.go b/examples/chain/exchange/query/11_SpotMarket/example.go new file mode 100644 index 00000000..0251543b --- /dev/null +++ b/examples/chain/exchange/query/11_SpotMarket/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + + res, err := chainClient.FetchChainSpotMarket(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/12_FullSpotMarkets/example.go b/examples/chain/exchange/query/12_FullSpotMarkets/example.go new file mode 100644 index 00000000..c560b9c3 --- /dev/null +++ b/examples/chain/exchange/query/12_FullSpotMarkets/example.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + status := "Active" + marketIds := []string{"0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"} + withMidPriceAndTob := true + + res, err := chainClient.FetchChainFullSpotMarkets(ctx, status, marketIds, withMidPriceAndTob) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/13_FullSpotMarket/example.go b/examples/chain/exchange/query/13_FullSpotMarket/example.go new file mode 100644 index 00000000..54700709 --- /dev/null +++ b/examples/chain/exchange/query/13_FullSpotMarket/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + withMidPriceAndTob := true + + res, err := chainClient.FetchChainFullSpotMarket(ctx, marketId, withMidPriceAndTob) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/14_SpotOrderbook/example.go b/examples/chain/exchange/query/14_SpotOrderbook/example.go new file mode 100644 index 00000000..8c127a4b --- /dev/null +++ b/examples/chain/exchange/query/14_SpotOrderbook/example.go @@ -0,0 +1,78 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + cosmostypes "github.com/cosmos/cosmos-sdk/types" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + limit := uint64(2) + orderSide := types.OrderSide_Buy + limitCumulativeNotional := cosmostypes.Dec{} + limitCumulativeQuantity := cosmostypes.Dec{} + + res, err := chainClient.FetchChainSpotOrderbook(ctx, marketId, limit, orderSide, limitCumulativeNotional, limitCumulativeQuantity) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/15_TraderSpotOrders/example.go b/examples/chain/exchange/query/15_TraderSpotOrders/example.go new file mode 100644 index 00000000..5452b06c --- /dev/null +++ b/examples/chain/exchange/query/15_TraderSpotOrders/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchChainTraderSpotOrders(ctx, marketId, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/16_AccountAddressSpotOrders/example.go b/examples/chain/exchange/query/16_AccountAddressSpotOrders/example.go new file mode 100644 index 00000000..9c5f4c05 --- /dev/null +++ b/examples/chain/exchange/query/16_AccountAddressSpotOrders/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + + res, err := chainClient.FetchChainAccountAddressSpotOrders(ctx, marketId, senderAddress.String()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/17_SpotOrdersByHashes/example.go b/examples/chain/exchange/query/17_SpotOrdersByHashes/example.go new file mode 100644 index 00000000..93dea96c --- /dev/null +++ b/examples/chain/exchange/query/17_SpotOrdersByHashes/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + subaccountId := chainClient.Subaccount(senderAddress, 0) + orderHashes := []string{"0x57a01cd26f1e2080860af3264e865d7c9c034a701e30946d01c1dc7a303cf2c1"} + + res, err := chainClient.FetchChainSpotOrdersByHashes(ctx, marketId, subaccountId.Hex(), orderHashes) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/18_SubaccountOrders/example.go b/examples/chain/exchange/query/18_SubaccountOrders/example.go new file mode 100644 index 00000000..f2ccb128 --- /dev/null +++ b/examples/chain/exchange/query/18_SubaccountOrders/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchChainSubaccountOrders(ctx, subaccountId.Hex(), marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/19_TraderSpotTransientOrders/example.go b/examples/chain/exchange/query/19_TraderSpotTransientOrders/example.go new file mode 100644 index 00000000..4df67cad --- /dev/null +++ b/examples/chain/exchange/query/19_TraderSpotTransientOrders/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchChainTraderSpotTransientOrders(ctx, marketId, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/1_SubaccountDeposits/example.go b/examples/chain/exchange/query/1_SubaccountDeposits/example.go new file mode 100644 index 00000000..526edc5a --- /dev/null +++ b/examples/chain/exchange/query/1_SubaccountDeposits/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + subaccountId := chainClient.Subaccount(senderAddress, 0) + ctx := context.Background() + + res, err := chainClient.FetchSubaccountDeposits(ctx, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/20_SpotMidPriceAndTOB/example.go b/examples/chain/exchange/query/20_SpotMidPriceAndTOB/example.go new file mode 100644 index 00000000..789ceec1 --- /dev/null +++ b/examples/chain/exchange/query/20_SpotMidPriceAndTOB/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + + res, err := chainClient.FetchSpotMidPriceAndTOB(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/21_DerivativeMidPriceAndTOB/example.go b/examples/chain/exchange/query/21_DerivativeMidPriceAndTOB/example.go new file mode 100644 index 00000000..1de6d908 --- /dev/null +++ b/examples/chain/exchange/query/21_DerivativeMidPriceAndTOB/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchDerivativeMidPriceAndTOB(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/22_DerivativeOrderbook/example.go b/examples/chain/exchange/query/22_DerivativeOrderbook/example.go new file mode 100644 index 00000000..9ab20712 --- /dev/null +++ b/examples/chain/exchange/query/22_DerivativeOrderbook/example.go @@ -0,0 +1,75 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + cosmostypes "github.com/cosmos/cosmos-sdk/types" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + limit := uint64(2) + limitCumulativeNotional := cosmostypes.Dec{} + + res, err := chainClient.FetchChainDerivativeOrderbook(ctx, marketId, limit, limitCumulativeNotional) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/23_TraderDerivativeOrders/example.go b/examples/chain/exchange/query/23_TraderDerivativeOrders/example.go new file mode 100644 index 00000000..307df66c --- /dev/null +++ b/examples/chain/exchange/query/23_TraderDerivativeOrders/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchChainTraderDerivativeOrders(ctx, marketId, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/24_AccountAddressDerivativeOrders/example.go b/examples/chain/exchange/query/24_AccountAddressDerivativeOrders/example.go new file mode 100644 index 00000000..c08c7959 --- /dev/null +++ b/examples/chain/exchange/query/24_AccountAddressDerivativeOrders/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainAccountAddressDerivativeOrders(ctx, marketId, senderAddress.String()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/25_DerivativeOrdersByHashes/example.go b/examples/chain/exchange/query/25_DerivativeOrdersByHashes/example.go new file mode 100644 index 00000000..bb8ba8db --- /dev/null +++ b/examples/chain/exchange/query/25_DerivativeOrdersByHashes/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + subaccountId := chainClient.Subaccount(senderAddress, 0) + orderHashes := []string{"0x57a01cd26f1e2080860af3264e865d7c9c034a701e30946d01c1dc7a303cf2c1"} + + res, err := chainClient.FetchChainDerivativeOrdersByHashes(ctx, marketId, subaccountId.Hex(), orderHashes) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/26_TraderDerivativeTransientOrders/example.go b/examples/chain/exchange/query/26_TraderDerivativeTransientOrders/example.go new file mode 100644 index 00000000..6d4b7b22 --- /dev/null +++ b/examples/chain/exchange/query/26_TraderDerivativeTransientOrders/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchChainTraderDerivativeTransientOrders(ctx, marketId, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/27_DerivativeMarkets/example.go b/examples/chain/exchange/query/27_DerivativeMarkets/example.go new file mode 100644 index 00000000..ad4ecb6f --- /dev/null +++ b/examples/chain/exchange/query/27_DerivativeMarkets/example.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + status := "Active" + marketIds := []string{"0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"} + withMidPriceAndTob := true + + res, err := chainClient.FetchChainDerivativeMarkets(ctx, status, marketIds, withMidPriceAndTob) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/28_DerivativeMarket/example.go b/examples/chain/exchange/query/28_DerivativeMarket/example.go new file mode 100644 index 00000000..881ba344 --- /dev/null +++ b/examples/chain/exchange/query/28_DerivativeMarket/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainDerivativeMarket(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/29_DerivativeMarketAddress/example.go b/examples/chain/exchange/query/29_DerivativeMarketAddress/example.go new file mode 100644 index 00000000..534aa4a9 --- /dev/null +++ b/examples/chain/exchange/query/29_DerivativeMarketAddress/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchDerivativeMarketAddress(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/2_SubaccountDeposit/example.go b/examples/chain/exchange/query/2_SubaccountDeposit/example.go new file mode 100644 index 00000000..02346c0e --- /dev/null +++ b/examples/chain/exchange/query/2_SubaccountDeposit/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + subaccountId := chainClient.Subaccount(senderAddress, 0) + denom := "inj" + ctx := context.Background() + + res, err := chainClient.FetchSubaccountDeposit(ctx, subaccountId.Hex(), denom) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/30_SubaccountTradeNonce/example.go b/examples/chain/exchange/query/30_SubaccountTradeNonce/example.go new file mode 100644 index 00000000..cf0ef07c --- /dev/null +++ b/examples/chain/exchange/query/30_SubaccountTradeNonce/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchSubaccountTradeNonce(ctx, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/31_Positions/example.go b/examples/chain/exchange/query/31_Positions/example.go new file mode 100644 index 00000000..5e19feca --- /dev/null +++ b/examples/chain/exchange/query/31_Positions/example.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchChainPositions(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/32_SubaccountPositions/example.go b/examples/chain/exchange/query/32_SubaccountPositions/example.go new file mode 100644 index 00000000..0d0b423e --- /dev/null +++ b/examples/chain/exchange/query/32_SubaccountPositions/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchChainSubaccountPositions(ctx, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/33_SubaccountPositionInMarket/example.go b/examples/chain/exchange/query/33_SubaccountPositionInMarket/example.go new file mode 100644 index 00000000..5fbb4f09 --- /dev/null +++ b/examples/chain/exchange/query/33_SubaccountPositionInMarket/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + subaccountId := chainClient.Subaccount(senderAddress, 0) + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainSubaccountPositionInMarket(ctx, subaccountId.Hex(), marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/34_SubaccountEffectivePositionInMarket/example.go b/examples/chain/exchange/query/34_SubaccountEffectivePositionInMarket/example.go new file mode 100644 index 00000000..1bdb9f31 --- /dev/null +++ b/examples/chain/exchange/query/34_SubaccountEffectivePositionInMarket/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + subaccountId := chainClient.Subaccount(senderAddress, 0) + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainSubaccountEffectivePositionInMarket(ctx, subaccountId.Hex(), marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/35_PerpetualMarketInfo/example.go b/examples/chain/exchange/query/35_PerpetualMarketInfo/example.go new file mode 100644 index 00000000..eb95664c --- /dev/null +++ b/examples/chain/exchange/query/35_PerpetualMarketInfo/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainPerpetualMarketInfo(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/36_ExpiryFuturesMarketInfo/example.go b/examples/chain/exchange/query/36_ExpiryFuturesMarketInfo/example.go new file mode 100644 index 00000000..59749df0 --- /dev/null +++ b/examples/chain/exchange/query/36_ExpiryFuturesMarketInfo/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainExpiryFuturesMarketInfo(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/37_PerpetualMarketFunding/example.go b/examples/chain/exchange/query/37_PerpetualMarketFunding/example.go new file mode 100644 index 00000000..11ed5cae --- /dev/null +++ b/examples/chain/exchange/query/37_PerpetualMarketFunding/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchChainPerpetualMarketFunding(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/38_SubaccountOrderMetadata/example.go b/examples/chain/exchange/query/38_SubaccountOrderMetadata/example.go new file mode 100644 index 00000000..b9d08a15 --- /dev/null +++ b/examples/chain/exchange/query/38_SubaccountOrderMetadata/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchSubaccountOrderMetadata(ctx, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/39_TradeRewardPoints/example.go b/examples/chain/exchange/query/39_TradeRewardPoints/example.go new file mode 100644 index 00000000..c6586fe8 --- /dev/null +++ b/examples/chain/exchange/query/39_TradeRewardPoints/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + accounts := []string{senderAddress.String()} + + res, err := chainClient.FetchTradeRewardPoints(ctx, accounts) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/3_ExchangeBalances/example.go b/examples/chain/exchange/query/3_ExchangeBalances/example.go new file mode 100644 index 00000000..d8cf9d47 --- /dev/null +++ b/examples/chain/exchange/query/3_ExchangeBalances/example.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchExchangeBalances(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/40_PendingTradeRewardPoints/example.go b/examples/chain/exchange/query/40_PendingTradeRewardPoints/example.go new file mode 100644 index 00000000..f5bd8f7b --- /dev/null +++ b/examples/chain/exchange/query/40_PendingTradeRewardPoints/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + accounts := []string{senderAddress.String()} + + res, err := chainClient.FetchPendingTradeRewardPoints(ctx, accounts) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/41_TradeRewardCampaign/example.go b/examples/chain/exchange/query/41_TradeRewardCampaign/example.go new file mode 100644 index 00000000..908a3813 --- /dev/null +++ b/examples/chain/exchange/query/41_TradeRewardCampaign/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchTradeRewardCampaign(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/42_FeeDiscountAccountInfo/example.go b/examples/chain/exchange/query/42_FeeDiscountAccountInfo/example.go new file mode 100644 index 00000000..018d8393 --- /dev/null +++ b/examples/chain/exchange/query/42_FeeDiscountAccountInfo/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchFeeDiscountAccountInfo(ctx, senderAddress.String()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/43_FeeDiscountSchedule/example.go b/examples/chain/exchange/query/43_FeeDiscountSchedule/example.go new file mode 100644 index 00000000..122f239c --- /dev/null +++ b/examples/chain/exchange/query/43_FeeDiscountSchedule/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchFeeDiscountSchedule(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/44_BalanceMismatches/example.go b/examples/chain/exchange/query/44_BalanceMismatches/example.go new file mode 100644 index 00000000..f4db8308 --- /dev/null +++ b/examples/chain/exchange/query/44_BalanceMismatches/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchBalanceMismatches(ctx, 1) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/45_BalanceWithBalanceHolds/example.go b/examples/chain/exchange/query/45_BalanceWithBalanceHolds/example.go new file mode 100644 index 00000000..b3677024 --- /dev/null +++ b/examples/chain/exchange/query/45_BalanceWithBalanceHolds/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchBalanceWithBalanceHolds(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/46_FeeDiscountTierStatistics/example.go b/examples/chain/exchange/query/46_FeeDiscountTierStatistics/example.go new file mode 100644 index 00000000..2fdaf947 --- /dev/null +++ b/examples/chain/exchange/query/46_FeeDiscountTierStatistics/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchFeeDiscountTierStatistics(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/47_MitoVaultInfos/example.go b/examples/chain/exchange/query/47_MitoVaultInfos/example.go new file mode 100644 index 00000000..e6b52166 --- /dev/null +++ b/examples/chain/exchange/query/47_MitoVaultInfos/example.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchMitoVaultInfos(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/48_QueryMarketIDFromVault/example.go b/examples/chain/exchange/query/48_QueryMarketIDFromVault/example.go new file mode 100644 index 00000000..5e269e30 --- /dev/null +++ b/examples/chain/exchange/query/48_QueryMarketIDFromVault/example.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + vaultAddress := "inj1qg5ega6dykkxc307y25pecuufrjkxkag6xhp6y" + + res, err := chainClient.FetchMarketIDFromVault(ctx, vaultAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/49_HistoricalTradeRecords/example.go b/examples/chain/exchange/query/49_HistoricalTradeRecords/example.go new file mode 100644 index 00000000..0d52d73a --- /dev/null +++ b/examples/chain/exchange/query/49_HistoricalTradeRecords/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + + res, err := chainClient.FetchHistoricalTradeRecords(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/4_AggregateVolume/example.go b/examples/chain/exchange/query/4_AggregateVolume/example.go new file mode 100644 index 00000000..84a66eba --- /dev/null +++ b/examples/chain/exchange/query/4_AggregateVolume/example.go @@ -0,0 +1,79 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchAggregateVolume(ctx, senderAddress.String()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + + res, err = chainClient.FetchAggregateVolume(ctx, subaccountId.Hex()) + if err != nil { + fmt.Println(err) + } + + str, _ = json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/50_IsOptedOutOfRewards/example.go b/examples/chain/exchange/query/50_IsOptedOutOfRewards/example.go new file mode 100644 index 00000000..89d915e2 --- /dev/null +++ b/examples/chain/exchange/query/50_IsOptedOutOfRewards/example.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchIsOptedOutOfRewards(ctx, senderAddress.String()) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/51_OptedOutOfRewardsAccounts/example.go b/examples/chain/exchange/query/51_OptedOutOfRewardsAccounts/example.go new file mode 100644 index 00000000..7809c836 --- /dev/null +++ b/examples/chain/exchange/query/51_OptedOutOfRewardsAccounts/example.go @@ -0,0 +1,69 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + res, err := chainClient.FetchOptedOutOfRewardsAccounts(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/52_MarketVolatility/example.go b/examples/chain/exchange/query/52_MarketVolatility/example.go new file mode 100644 index 00000000..5dc6b988 --- /dev/null +++ b/examples/chain/exchange/query/52_MarketVolatility/example.go @@ -0,0 +1,79 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + tradeHistoryOptions := types.TradeHistoryOptions{ + TradeGroupingSec: 10, + MaxAge: 0, + IncludeRawHistory: true, + IncludeMetadata: true, + } + + res, err := chainClient.FetchMarketVolatility(ctx, marketId, &tradeHistoryOptions) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/53_BinaryOptionsMarkets/example.go b/examples/chain/exchange/query/53_BinaryOptionsMarkets/example.go new file mode 100644 index 00000000..ba0ae6fe --- /dev/null +++ b/examples/chain/exchange/query/53_BinaryOptionsMarkets/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + status := "Active" + + res, err := chainClient.FetchChainBinaryOptionsMarkets(ctx, status) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/54_TraderDerivativeConditionalOrders/example.go b/examples/chain/exchange/query/54_TraderDerivativeConditionalOrders/example.go new file mode 100644 index 00000000..a26fb380 --- /dev/null +++ b/examples/chain/exchange/query/54_TraderDerivativeConditionalOrders/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + subaccountId := chainClient.Subaccount(senderAddress, 0) + + res, err := chainClient.FetchTraderDerivativeConditionalOrders(ctx, subaccountId.Hex(), marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/55_MarketAtomicExecutionFeeMultiplier/example.go b/examples/chain/exchange/query/55_MarketAtomicExecutionFeeMultiplier/example.go new file mode 100644 index 00000000..493f05ea --- /dev/null +++ b/examples/chain/exchange/query/55_MarketAtomicExecutionFeeMultiplier/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" + + res, err := chainClient.FetchMarketAtomicExecutionFeeMultiplier(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/5_AggregateVolumes/example.go b/examples/chain/exchange/query/5_AggregateVolumes/example.go new file mode 100644 index 00000000..0bae825c --- /dev/null +++ b/examples/chain/exchange/query/5_AggregateVolumes/example.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + accounts := []string{senderAddress.String()} + marketIds := []string{"0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"} + + res, err := chainClient.FetchAggregateVolumes(ctx, accounts, marketIds) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/6_AggregateMarketVolume/example.go b/examples/chain/exchange/query/6_AggregateMarketVolume/example.go new file mode 100644 index 00000000..1bf1ebbc --- /dev/null +++ b/examples/chain/exchange/query/6_AggregateMarketVolume/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketId := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe" + + res, err := chainClient.FetchAggregateMarketVolume(ctx, marketId) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/7_AggregateMarketVolumes/example.go b/examples/chain/exchange/query/7_AggregateMarketVolumes/example.go new file mode 100644 index 00000000..bb8c8ea5 --- /dev/null +++ b/examples/chain/exchange/query/7_AggregateMarketVolumes/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + marketIds := []string{"0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"} + + res, err := chainClient.FetchAggregateMarketVolumes(ctx, marketIds) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/8_DenomDecimal/example.go b/examples/chain/exchange/query/8_DenomDecimal/example.go new file mode 100644 index 00000000..97663656 --- /dev/null +++ b/examples/chain/exchange/query/8_DenomDecimal/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + denom := "peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5" + + res, err := chainClient.FetchDenomDecimal(ctx, denom) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/exchange/query/9_DenomDecimals/example.go b/examples/chain/exchange/query/9_DenomDecimals/example.go new file mode 100644 index 00000000..f4e9866c --- /dev/null +++ b/examples/chain/exchange/query/9_DenomDecimals/example.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "os" + + "github.com/InjectiveLabs/sdk-go/client" + chainclient "github.com/InjectiveLabs/sdk-go/client/chain" + "github.com/InjectiveLabs/sdk-go/client/common" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" +) + +func main() { + network := common.LoadNetwork("testnet", "lb") + tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") + if err != nil { + panic(err) + } + + senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( + os.Getenv("HOME")+"/.injectived", + "injectived", + "file", + "inj-user", + "12345678", + "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided + false, + ) + + if err != nil { + panic(err) + } + + clientCtx, err := chainclient.NewClientContext( + network.ChainId, + senderAddress.String(), + cosmosKeyring, + ) + + if err != nil { + panic(err) + } + + clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) + + chainClient, err := chainclient.NewChainClient( + clientCtx, + network, + common.OptionGasPrices(client.DefaultGasPriceWithDenom), + ) + + if err != nil { + panic(err) + } + + ctx := context.Background() + + denoms := []string{"inj", "peggy0x87aB3B4C8661e07D6372361211B96ed4Dc36B1B5"} + + res, err := chainClient.FetchDenomDecimals(ctx, denoms) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/23_MsgRelayPriceFeedPrice/example.go b/examples/chain/oracle/1_MsgRelayPriceFeedPrice/example.go similarity index 100% rename from examples/chain/23_MsgRelayPriceFeedPrice/example.go rename to examples/chain/oracle/1_MsgRelayPriceFeedPrice/example.go diff --git a/examples/chain/22_MsgSendToEth/example.go b/examples/chain/peggy/1_MsgSendToEth/example.go similarity index 100% rename from examples/chain/22_MsgSendToEth/example.go rename to examples/chain/peggy/1_MsgSendToEth/example.go diff --git a/examples/chain/staking/25_MsgDelegate/example.go b/examples/chain/staking/1_MsgDelegate/example.go similarity index 100% rename from examples/chain/staking/25_MsgDelegate/example.go rename to examples/chain/staking/1_MsgDelegate/example.go diff --git a/examples/chain/64_CreateDenom/example.go b/examples/chain/tokenfactory/1_CreateDenom/example.go similarity index 100% rename from examples/chain/64_CreateDenom/example.go rename to examples/chain/tokenfactory/1_CreateDenom/example.go diff --git a/examples/chain/65_MsgMint/example.go b/examples/chain/tokenfactory/2_MsgMint/example.go similarity index 100% rename from examples/chain/65_MsgMint/example.go rename to examples/chain/tokenfactory/2_MsgMint/example.go diff --git a/examples/chain/66_MsgBurn/example.go b/examples/chain/tokenfactory/3_MsgBurn/example.go similarity index 100% rename from examples/chain/66_MsgBurn/example.go rename to examples/chain/tokenfactory/3_MsgBurn/example.go diff --git a/examples/chain/67_MsgSetDenomMetadata/example.go b/examples/chain/tokenfactory/4_MsgSetDenomMetadata/example.go similarity index 100% rename from examples/chain/67_MsgSetDenomMetadata/example.go rename to examples/chain/tokenfactory/4_MsgSetDenomMetadata/example.go diff --git a/examples/chain/68_MsgChangeAdmin/example.go b/examples/chain/tokenfactory/5_MsgChangeAdmin/example.go similarity index 100% rename from examples/chain/68_MsgChangeAdmin/example.go rename to examples/chain/tokenfactory/5_MsgChangeAdmin/example.go diff --git a/examples/chain/60_DenomAuthorityMetadata/example.go b/examples/chain/tokenfactory/query/1_DenomAuthorityMetadata/example.go similarity index 100% rename from examples/chain/60_DenomAuthorityMetadata/example.go rename to examples/chain/tokenfactory/query/1_DenomAuthorityMetadata/example.go diff --git a/examples/chain/61_DenomsFromCreator/example.go b/examples/chain/tokenfactory/query/2_DenomsFromCreator/example.go similarity index 100% rename from examples/chain/61_DenomsFromCreator/example.go rename to examples/chain/tokenfactory/query/2_DenomsFromCreator/example.go diff --git a/examples/chain/62_TokenfactoryModuleState/example.go b/examples/chain/tokenfactory/query/3_TokenfactoryModuleState/example.go similarity index 100% rename from examples/chain/62_TokenfactoryModuleState/example.go rename to examples/chain/tokenfactory/query/3_TokenfactoryModuleState/example.go diff --git a/examples/chain/39_GetTx/example.go b/examples/chain/tx/query/1_GetTx/example.go similarity index 100% rename from examples/chain/39_GetTx/example.go rename to examples/chain/tx/query/1_GetTx/example.go diff --git a/examples/chain/59_ContractsByCreator/example.go b/examples/chain/wasm/query/10_ContractsByCreator/example.go similarity index 100% rename from examples/chain/59_ContractsByCreator/example.go rename to examples/chain/wasm/query/10_ContractsByCreator/example.go diff --git a/examples/chain/50_ContractInfo/example.go b/examples/chain/wasm/query/1_ContractInfo/example.go similarity index 100% rename from examples/chain/50_ContractInfo/example.go rename to examples/chain/wasm/query/1_ContractInfo/example.go diff --git a/examples/chain/51_ContractHistory/example.go b/examples/chain/wasm/query/2_ContractHistory/example.go similarity index 100% rename from examples/chain/51_ContractHistory/example.go rename to examples/chain/wasm/query/2_ContractHistory/example.go diff --git a/examples/chain/52_ContractsByCode/example.go b/examples/chain/wasm/query/3_ContractsByCode/example.go similarity index 100% rename from examples/chain/52_ContractsByCode/example.go rename to examples/chain/wasm/query/3_ContractsByCode/example.go diff --git a/examples/chain/53_AllContractsState/example.go b/examples/chain/wasm/query/4_AllContractsState/example.go similarity index 100% rename from examples/chain/53_AllContractsState/example.go rename to examples/chain/wasm/query/4_AllContractsState/example.go diff --git a/examples/chain/54_RawContractState/example.go b/examples/chain/wasm/query/5_RawContractState/example.go similarity index 100% rename from examples/chain/54_RawContractState/example.go rename to examples/chain/wasm/query/5_RawContractState/example.go diff --git a/examples/chain/55_SmartContractState/example.go b/examples/chain/wasm/query/6_SmartContractState/example.go similarity index 100% rename from examples/chain/55_SmartContractState/example.go rename to examples/chain/wasm/query/6_SmartContractState/example.go diff --git a/examples/chain/56_SmartContractCode/example.go b/examples/chain/wasm/query/7_SmartContractCode/example.go similarity index 100% rename from examples/chain/56_SmartContractCode/example.go rename to examples/chain/wasm/query/7_SmartContractCode/example.go diff --git a/examples/chain/57_SmartContractCodes/example.go b/examples/chain/wasm/query/8_SmartContractCodes/example.go similarity index 100% rename from examples/chain/57_SmartContractCodes/example.go rename to examples/chain/wasm/query/8_SmartContractCodes/example.go diff --git a/examples/chain/58_SmartContractPinnedCodes/example.go b/examples/chain/wasm/query/9_SmartContractPinnedCodes/example.go similarity index 100% rename from examples/chain/58_SmartContractPinnedCodes/example.go rename to examples/chain/wasm/query/9_SmartContractPinnedCodes/example.go diff --git a/examples/chain/69_MsgExecuteContractCompat/example.go b/examples/chain/wasmx/1_MsgExecuteContractCompat/example.go similarity index 100% rename from examples/chain/69_MsgExecuteContractCompat/example.go rename to examples/chain/wasmx/1_MsgExecuteContractCompat/example.go