diff --git a/client/chain/chain.go b/client/chain/chain.go index e5340eba..ada8f805 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "math" "os" "strconv" @@ -167,6 +168,17 @@ type ChainClient interface { FetchDenomsFromCreator(ctx context.Context, creator string) (*tokenfactorytypes.QueryDenomsFromCreatorResponse, error) FetchTokenfactoryModuleState(ctx context.Context) (*tokenfactorytypes.QueryModuleStateResponse, error) + // distribution module + FetchValidatorDistributionInfo(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorDistributionInfoResponse, error) + FetchValidatorOutstandingRewards(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorOutstandingRewardsResponse, error) + FetchValidatorCommission(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorCommissionResponse, error) + FetchValidatorSlashes(ctx context.Context, validatorAddress string, startingHeight uint64, endingHeight uint64, pagination *query.PageRequest) (*distributiontypes.QueryValidatorSlashesResponse, error) + FetchDelegationRewards(ctx context.Context, delegatorAddress string, validatorAddress string) (*distributiontypes.QueryDelegationRewardsResponse, error) + FetchDelegationTotalRewards(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegationTotalRewardsResponse, error) + FetchDelegatorValidators(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorValidatorsResponse, error) + FetchDelegatorWithdrawAddress(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorWithdrawAddressResponse, error) + FetchCommunityPool(ctx context.Context) (*distributiontypes.QueryCommunityPoolResponse, error) + Close() } @@ -202,6 +214,7 @@ type chainClient struct { wasmQueryClient wasmtypes.QueryClient chainStreamClient chainstreamtypes.StreamClient tokenfactoryQueryClient tokenfactorytypes.QueryClient + distributionQueryClient distributiontypes.QueryClient subaccountToNonce map[ethcommon.Hash]uint32 closed int64 @@ -296,6 +309,7 @@ func NewChainClient( wasmQueryClient: wasmtypes.NewQueryClient(conn), chainStreamClient: chainstreamtypes.NewStreamClient(chainStreamConn), tokenfactoryQueryClient: tokenfactorytypes.NewQueryClient(conn), + distributionQueryClient: distributiontypes.NewQueryClient(conn), subaccountToNonce: make(map[ethcommon.Hash]uint32), } @@ -1494,3 +1508,69 @@ type OrderCancelData struct { OrderHash string Cid string } + +// Distribution module +func (c *chainClient) FetchValidatorDistributionInfo(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorDistributionInfoResponse, error) { + req := &distributiontypes.QueryValidatorDistributionInfoRequest{ + ValidatorAddress: validatorAddress, + } + return c.distributionQueryClient.ValidatorDistributionInfo(ctx, req) +} + +func (c *chainClient) FetchValidatorOutstandingRewards(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorOutstandingRewardsResponse, error) { + req := &distributiontypes.QueryValidatorOutstandingRewardsRequest{ + ValidatorAddress: validatorAddress, + } + return c.distributionQueryClient.ValidatorOutstandingRewards(ctx, req) +} + +func (c *chainClient) FetchValidatorCommission(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorCommissionResponse, error) { + req := &distributiontypes.QueryValidatorCommissionRequest{ + ValidatorAddress: validatorAddress, + } + return c.distributionQueryClient.ValidatorCommission(ctx, req) +} + +func (c *chainClient) FetchValidatorSlashes(ctx context.Context, validatorAddress string, startingHeight uint64, endingHeight uint64, pagination *query.PageRequest) (*distributiontypes.QueryValidatorSlashesResponse, error) { + req := &distributiontypes.QueryValidatorSlashesRequest{ + ValidatorAddress: validatorAddress, + StartingHeight: startingHeight, + EndingHeight: endingHeight, + Pagination: pagination, + } + return c.distributionQueryClient.ValidatorSlashes(ctx, req) +} + +func (c *chainClient) FetchDelegationRewards(ctx context.Context, delegatorAddress string, validatorAddress string) (*distributiontypes.QueryDelegationRewardsResponse, error) { + req := &distributiontypes.QueryDelegationRewardsRequest{ + DelegatorAddress: delegatorAddress, + ValidatorAddress: validatorAddress, + } + return c.distributionQueryClient.DelegationRewards(ctx, req) +} + +func (c *chainClient) FetchDelegationTotalRewards(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegationTotalRewardsResponse, error) { + req := &distributiontypes.QueryDelegationTotalRewardsRequest{ + DelegatorAddress: delegatorAddress, + } + return c.distributionQueryClient.DelegationTotalRewards(ctx, req) +} + +func (c *chainClient) FetchDelegatorValidators(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorValidatorsResponse, error) { + req := &distributiontypes.QueryDelegatorValidatorsRequest{ + DelegatorAddress: delegatorAddress, + } + return c.distributionQueryClient.DelegatorValidators(ctx, req) +} + +func (c *chainClient) FetchDelegatorWithdrawAddress(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorWithdrawAddressResponse, error) { + req := &distributiontypes.QueryDelegatorWithdrawAddressRequest{ + DelegatorAddress: delegatorAddress, + } + return c.distributionQueryClient.DelegatorWithdrawAddress(ctx, req) +} + +func (c *chainClient) FetchCommunityPool(ctx context.Context) (*distributiontypes.QueryCommunityPoolResponse, error) { + req := &distributiontypes.QueryCommunityPoolRequest{} + return c.distributionQueryClient.CommunityPool(ctx, req) +} diff --git a/client/chain/chain_test_support.go b/client/chain/chain_test_support.go index 5d15bd13..06bc95e8 100644 --- a/client/chain/chain_test_support.go +++ b/client/chain/chain_test_support.go @@ -3,6 +3,7 @@ package chain import ( "context" "errors" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "time" tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types" @@ -286,3 +287,40 @@ func (c *MockChainClient) FetchDenomsFromCreator(ctx context.Context, creator st func (c *MockChainClient) FetchTokenfactoryModuleState(ctx context.Context) (*tokenfactorytypes.QueryModuleStateResponse, error) { return &tokenfactorytypes.QueryModuleStateResponse{}, nil } + +// Distribution module +func (c *MockChainClient) FetchValidatorDistributionInfo(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorDistributionInfoResponse, error) { + return &distributiontypes.QueryValidatorDistributionInfoResponse{}, nil +} + +func (c *MockChainClient) FetchValidatorOutstandingRewards(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorOutstandingRewardsResponse, error) { + return &distributiontypes.QueryValidatorOutstandingRewardsResponse{}, nil +} + +func (c *MockChainClient) FetchValidatorCommission(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorCommissionResponse, error) { + return &distributiontypes.QueryValidatorCommissionResponse{}, nil +} + +func (c *MockChainClient) FetchValidatorSlashes(ctx context.Context, validatorAddress string, startingHeight uint64, endingHeight uint64, pagination *query.PageRequest) (*distributiontypes.QueryValidatorSlashesResponse, error) { + return &distributiontypes.QueryValidatorSlashesResponse{}, nil +} + +func (c *MockChainClient) FetchDelegationRewards(ctx context.Context, delegatorAddress string, validatorAddress string) (*distributiontypes.QueryDelegationRewardsResponse, error) { + return &distributiontypes.QueryDelegationRewardsResponse{}, nil +} + +func (c *MockChainClient) FetchDelegationTotalRewards(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegationTotalRewardsResponse, error) { + return &distributiontypes.QueryDelegationTotalRewardsResponse{}, nil +} + +func (c *MockChainClient) FetchDelegatorValidators(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorValidatorsResponse, error) { + return &distributiontypes.QueryDelegatorValidatorsResponse{}, nil +} + +func (c *MockChainClient) FetchDelegatorWithdrawAddress(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorWithdrawAddressResponse, error) { + return &distributiontypes.QueryDelegatorWithdrawAddressResponse{}, nil +} + +func (c *MockChainClient) FetchCommunityPool(ctx context.Context) (*distributiontypes.QueryCommunityPoolResponse, error) { + return &distributiontypes.QueryCommunityPoolResponse{}, nil +} diff --git a/examples/chain/distribution/1_SetWithdrawAddress/example.go b/examples/chain/distribution/1_SetWithdrawAddress/example.go new file mode 100644 index 00000000..387cdc2f --- /dev/null +++ b/examples/chain/distribution/1_SetWithdrawAddress/example.go @@ -0,0 +1,74 @@ +package main + +import ( + "encoding/json" + "fmt" + "github.com/cosmos/cosmos-sdk/x/distribution/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) + } + + withdrawAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" + + msg := &types.MsgSetWithdrawAddress{ + DelegatorAddress: senderAddress.String(), + WithdrawAddress: withdrawAddress, + } + + //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/26_MsgWithdrawDelegatorReward/example.go b/examples/chain/distribution/2_MsgWithdrawDelegatorReward/example.go similarity index 100% rename from examples/chain/26_MsgWithdrawDelegatorReward/example.go rename to examples/chain/distribution/2_MsgWithdrawDelegatorReward/example.go diff --git a/examples/chain/distribution/3_WithdrawValidatorCommission/example.go b/examples/chain/distribution/3_WithdrawValidatorCommission/example.go new file mode 100644 index 00000000..b421df61 --- /dev/null +++ b/examples/chain/distribution/3_WithdrawValidatorCommission/example.go @@ -0,0 +1,73 @@ +package main + +import ( + "encoding/json" + "fmt" + "github.com/cosmos/cosmos-sdk/x/distribution/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) + } + + validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5" + + msg := &types.MsgWithdrawValidatorCommission{ + ValidatorAddress: validatorAddress, + } + + //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/distribution/4_FundCommunityPool/example.go b/examples/chain/distribution/4_FundCommunityPool/example.go new file mode 100644 index 00000000..2861484f --- /dev/null +++ b/examples/chain/distribution/4_FundCommunityPool/example.go @@ -0,0 +1,75 @@ +package main + +import ( + "encoding/json" + "fmt" + "github.com/cosmos/cosmos-sdk/types" + distriutiontypes "github.com/cosmos/cosmos-sdk/x/distribution/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) + } + + amount := types.NewCoin("inj", types.NewInt(1)) + + msg := &distriutiontypes.MsgFundCommunityPool{ + Amount: []types.Coin{amount}, + Depositor: senderAddress.String(), + } + + //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/distribution/query/1_ValidatorDistributionInfo/example.go b/examples/chain/distribution/query/1_ValidatorDistributionInfo/example.go new file mode 100644 index 00000000..f542c779 --- /dev/null +++ b/examples/chain/distribution/query/1_ValidatorDistributionInfo/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) + } + + validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" + ctx := context.Background() + + res, err := chainClient.FetchValidatorDistributionInfo(ctx, validatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/2_ValidatorOutstandingRewards/example.go b/examples/chain/distribution/query/2_ValidatorOutstandingRewards/example.go new file mode 100644 index 00000000..e172cb07 --- /dev/null +++ b/examples/chain/distribution/query/2_ValidatorOutstandingRewards/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) + } + + validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" + ctx := context.Background() + + res, err := chainClient.FetchValidatorOutstandingRewards(ctx, validatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/3_ValidatorCommission/example.go b/examples/chain/distribution/query/3_ValidatorCommission/example.go new file mode 100644 index 00000000..b12df4bf --- /dev/null +++ b/examples/chain/distribution/query/3_ValidatorCommission/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) + } + + validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" + ctx := context.Background() + + res, err := chainClient.FetchValidatorCommission(ctx, validatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/4_ValidatorSlashes/example.go b/examples/chain/distribution/query/4_ValidatorSlashes/example.go new file mode 100644 index 00000000..9749277e --- /dev/null +++ b/examples/chain/distribution/query/4_ValidatorSlashes/example.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + "github.com/cosmos/cosmos-sdk/types/query" + "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) + } + + validatorAddress := "injvaloper1jue5dpr9lerjn6wlwtrywxrsenrf28ru89z99z" + startingHeight := uint64(0) + endingHeight := uint64(0) + pagination := query.PageRequest{Limit: 10} + ctx := context.Background() + + res, err := chainClient.FetchValidatorSlashes(ctx, validatorAddress, startingHeight, endingHeight, &pagination) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/5_DelegationRewards/example.go b/examples/chain/distribution/query/5_DelegationRewards/example.go new file mode 100644 index 00000000..0d8780f2 --- /dev/null +++ b/examples/chain/distribution/query/5_DelegationRewards/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) + } + + delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" + validatorAddress := "injvaloper156t3yxd4udv0h9gwagfcmwnmm3quy0nph7tyh5" + ctx := context.Background() + + res, err := chainClient.FetchDelegationRewards(ctx, delegatorAddress, validatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/6_DelegationTotalRewards/example.go b/examples/chain/distribution/query/6_DelegationTotalRewards/example.go new file mode 100644 index 00000000..5c71a72d --- /dev/null +++ b/examples/chain/distribution/query/6_DelegationTotalRewards/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) + } + + delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" + ctx := context.Background() + + res, err := chainClient.FetchDelegationTotalRewards(ctx, delegatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/7_DelegatorValidators/example.go b/examples/chain/distribution/query/7_DelegatorValidators/example.go new file mode 100644 index 00000000..6a9e0a29 --- /dev/null +++ b/examples/chain/distribution/query/7_DelegatorValidators/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) + } + + delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" + ctx := context.Background() + + res, err := chainClient.FetchDelegatorValidators(ctx, delegatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/8_DelegatorWithdrawAddress/example.go b/examples/chain/distribution/query/8_DelegatorWithdrawAddress/example.go new file mode 100644 index 00000000..6f850e40 --- /dev/null +++ b/examples/chain/distribution/query/8_DelegatorWithdrawAddress/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) + } + + delegatorAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" + ctx := context.Background() + + res, err := chainClient.FetchDelegatorWithdrawAddress(ctx, delegatorAddress) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/distribution/query/9_CommunityPool/example.go b/examples/chain/distribution/query/9_CommunityPool/example.go new file mode 100644 index 00000000..4adb0ee3 --- /dev/null +++ b/examples/chain/distribution/query/9_CommunityPool/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.FetchCommunityPool(ctx) + if err != nil { + fmt.Println(err) + } + + str, _ := json.MarshalIndent(res, "", " ") + fmt.Print(string(str)) + +} diff --git a/examples/chain/25_MsgDelegate/example.go b/examples/chain/staking/25_MsgDelegate/example.go similarity index 100% rename from examples/chain/25_MsgDelegate/example.go rename to examples/chain/staking/25_MsgDelegate/example.go