-
Notifications
You must be signed in to change notification settings - Fork 62
Add Chain Queries for the Insurance Module #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "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) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| clientCtx, err := chainclient.NewClientContext( | ||
| network.ChainId, | ||
| "", | ||
| nil, | ||
| ) | ||
|
|
||
| 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 := "0xfc615d2dfe6cc437c77c0d2b1721bba6947f821ce45c1aa4094dcdf333f46881" | ||
|
|
||
| res, err := chainClient.FetchInsuranceFund(ctx, marketId) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| } | ||
|
|
||
| str, _ := json.MarshalIndent(res, "", " ") | ||
| fmt.Print(string(str)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "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) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| clientCtx, err := chainclient.NewClientContext( | ||
| network.ChainId, | ||
| "", | ||
| nil, | ||
| ) | ||
|
|
||
| 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.FetchInsuranceFunds(ctx) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| } | ||
|
|
||
| str, _ := json.MarshalIndent(res, "", " ") | ||
| fmt.Print(string(str)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| userAddress, _, err := chainclient.InitCosmosKeyring( | ||
| os.Getenv("HOME")+"/.injectived", | ||
| "injectived", | ||
| "file", | ||
| "inj-user", | ||
| "12345678", | ||
| "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
| false, | ||
| ) | ||
|
Comment on lines
+22
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Private key & passphrase committed to source Embedding a plaintext passphrase ( - "12345678",
- "5d386fbd...1381e",
+ os.Getenv("INJ_KEYRING_PASSPHRASE"),
+ os.Getenv("INJ_PRIV_KEY"),🤖 Prompt for AI Agents |
||
|
|
||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| clientCtx, err := chainclient.NewClientContext( | ||
| network.ChainId, | ||
| "", | ||
| nil, | ||
| ) | ||
|
|
||
| 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 := "0xfc615d2dfe6cc437c77c0d2b1721bba6947f821ce45c1aa4094dcdf333f46881" | ||
| userAddressStr := userAddress.String() | ||
|
|
||
| res, err := chainClient.FetchPendingRedemptions(ctx, marketId, userAddressStr) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| } | ||
|
|
||
| str, _ := json.MarshalIndent(res, "", " ") | ||
| fmt.Print(string(str)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| userAddress, _, err := chainclient.InitCosmosKeyring( | ||
| os.Getenv("HOME")+"/.injectived", | ||
| "injectived", | ||
| "file", | ||
| "inj-user", | ||
| "12345678", | ||
| "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
| false, | ||
| ) | ||
|
Comment on lines
+22
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Private key & passphrase committed to source Same security concern as in the PendingRedemptions example; move secrets to environment variables. 🤖 Prompt for AI Agents |
||
|
|
||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| clientCtx, err := chainclient.NewClientContext( | ||
| network.ChainId, | ||
| "", | ||
| nil, | ||
| ) | ||
|
|
||
| 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 := "0xfc615d2dfe6cc437c77c0d2b1721bba6947f821ce45c1aa4094dcdf333f46881" | ||
| userAddressStr := userAddress.String() | ||
|
|
||
| res, err := chainClient.FetchEstimatedRedemptions(ctx, marketId, userAddressStr) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| } | ||
|
|
||
| str, _ := json.MarshalIndent(res, "", " ") | ||
| fmt.Print(string(str)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Mock does not allow configurable responses for new insurance queries
Other mock methods (e.g.
FetchChainSpotMarkets) pop predefined responses from slices, enabling deterministic tests. The four newly added insurance stubs always return empty structs, preventing unit tests from asserting specific data.Consider extending
MockChainClientwith response queues similar to existing patterns:type MockChainClient struct { ... + InsuranceFundResponses []*insurancetypes.QueryInsuranceFundResponse + InsuranceFundsResponses []*insurancetypes.QueryInsuranceFundsResponse + PendingRedemptionsResponses []*insurancetypes.QueryPendingRedemptionsResponse + EstimatedRedemptionsResponses []*insurancetypes.QueryEstimatedRedemptionsResponse }and pop from those slices inside each method.
🤖 Prompt for AI Agents