Skip to content

Commit 1a0a621

Browse files
authored
Merge pull request #308 from InjectiveLabs/cp-395/add_support_for_v1_16
[CP-395] add support for v1.16
2 parents 7d8fb1f + 07a2d52 commit 1a0a621

File tree

19 files changed

+2230
-1174
lines changed

19 files changed

+2230
-1174
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all:
22

33
clone-injective-indexer:
4-
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.0-rc2 --depth 1 --single-branch
4+
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.3 --depth 1 --single-branch
55

66
clone-injective-core:
77
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.16.0-beta.2 --depth 1 --single-branch

client/chain/chain.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
"google.golang.org/grpc"
4040
"google.golang.org/grpc/credentials/insecure"
4141

42+
erc20types "github.com/InjectiveLabs/sdk-go/chain/erc20/types"
43+
evmtypes "github.com/InjectiveLabs/sdk-go/chain/evm/types"
4244
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
4345
exchangev2types "github.com/InjectiveLabs/sdk-go/chain/exchange/types/v2"
4446
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
@@ -452,6 +454,20 @@ type ChainClient interface {
452454
FetchTxFeesParams(ctx context.Context) (*txfeestypes.QueryParamsResponse, error)
453455
FetchEipBaseFee(ctx context.Context) (*txfeestypes.QueryEipBaseFeeResponse, error)
454456

457+
// ERC20 module
458+
FetchAllTokenPairs(ctx context.Context) (*erc20types.QueryAllTokenPairsResponse, error)
459+
FetchTokenPairByDenom(ctx context.Context, bankDenom string) (*erc20types.QueryTokenPairByDenomResponse, error)
460+
FetchTokenPairByERC20Address(ctx context.Context, erc20Address string) (*erc20types.QueryTokenPairByERC20AddressResponse, error)
461+
462+
// EVM module
463+
FetchEVMAccount(ctx context.Context, evmAddress string) (*evmtypes.QueryAccountResponse, error)
464+
FetchEVMCosmosAccount(ctx context.Context, address string) (*evmtypes.QueryCosmosAccountResponse, error)
465+
FetchEVMValidatorAccount(ctx context.Context, consAddress string) (*evmtypes.QueryValidatorAccountResponse, error)
466+
FetchEVMBalance(ctx context.Context, address string) (*evmtypes.QueryBalanceResponse, error)
467+
FetchEVMStorage(ctx context.Context, address string, key *string) (*evmtypes.QueryStorageResponse, error)
468+
FetchEVMCode(ctx context.Context, address string) (*evmtypes.QueryCodeResponse, error)
469+
FetchEVMBaseFee(ctx context.Context) (*evmtypes.QueryBaseFeeResponse, error)
470+
455471
CurrentChainGasPrice() int64
456472
SetGasPrice(gasPrice int64)
457473

@@ -492,6 +508,8 @@ type chainClient struct {
492508
chainStreamClient chainstreamtypes.StreamClient
493509
chainStreamV2Client chainstreamv2types.StreamClient
494510
distributionQueryClient distributiontypes.QueryClient
511+
erc20QueryClient erc20types.QueryClient
512+
evmQueryClient evmtypes.QueryClient
495513
exchangeQueryClient exchangetypes.QueryClient
496514
exchangeV2QueryClient exchangev2types.QueryClient
497515
ibcChannelQueryClient ibcchanneltypes.QueryClient
@@ -596,6 +614,8 @@ func NewChainClient(
596614
chainStreamClient: chainstreamtypes.NewStreamClient(chainStreamConn),
597615
chainStreamV2Client: chainstreamv2types.NewStreamClient(chainStreamConn),
598616
distributionQueryClient: distributiontypes.NewQueryClient(conn),
617+
erc20QueryClient: erc20types.NewQueryClient(conn),
618+
evmQueryClient: evmtypes.NewQueryClient(conn),
599619
exchangeQueryClient: exchangetypes.NewQueryClient(conn),
600620
exchangeV2QueryClient: exchangev2types.NewQueryClient(conn),
601621
ibcChannelQueryClient: ibcchanneltypes.NewQueryClient(conn),
@@ -3586,6 +3606,94 @@ func (c *chainClient) GetNetwork() common.Network {
35863606
return c.network
35873607
}
35883608

3609+
// ERC20 module
3610+
3611+
func (c *chainClient) FetchAllTokenPairs(ctx context.Context) (*erc20types.QueryAllTokenPairsResponse, error) {
3612+
req := &erc20types.QueryAllTokenPairsRequest{}
3613+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.erc20QueryClient.AllTokenPairs, req)
3614+
3615+
return res, err
3616+
}
3617+
3618+
func (c *chainClient) FetchTokenPairByDenom(ctx context.Context, bankDenom string) (*erc20types.QueryTokenPairByDenomResponse, error) {
3619+
req := &erc20types.QueryTokenPairByDenomRequest{
3620+
BankDenom: bankDenom,
3621+
}
3622+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.erc20QueryClient.TokenPairByDenom, req)
3623+
3624+
return res, err
3625+
}
3626+
3627+
func (c *chainClient) FetchTokenPairByERC20Address(ctx context.Context, erc20Address string) (*erc20types.QueryTokenPairByERC20AddressResponse, error) {
3628+
req := &erc20types.QueryTokenPairByERC20AddressRequest{
3629+
Erc20Address: erc20Address,
3630+
}
3631+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.erc20QueryClient.TokenPairByERC20Address, req)
3632+
3633+
return res, err
3634+
}
3635+
3636+
// EVM module
3637+
3638+
func (c *chainClient) FetchEVMAccount(ctx context.Context, address string) (*evmtypes.QueryAccountResponse, error) {
3639+
req := &evmtypes.QueryAccountRequest{
3640+
Address: address,
3641+
}
3642+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.Account, req)
3643+
return res, err
3644+
}
3645+
3646+
func (c *chainClient) FetchEVMCosmosAccount(ctx context.Context, address string) (*evmtypes.QueryCosmosAccountResponse, error) {
3647+
req := &evmtypes.QueryCosmosAccountRequest{
3648+
Address: address,
3649+
}
3650+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.CosmosAccount, req)
3651+
return res, err
3652+
}
3653+
3654+
func (c *chainClient) FetchEVMValidatorAccount(ctx context.Context, consAddress string) (*evmtypes.QueryValidatorAccountResponse, error) {
3655+
req := &evmtypes.QueryValidatorAccountRequest{
3656+
ConsAddress: consAddress,
3657+
}
3658+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.ValidatorAccount, req)
3659+
return res, err
3660+
}
3661+
3662+
func (c *chainClient) FetchEVMBalance(ctx context.Context, address string) (*evmtypes.QueryBalanceResponse, error) {
3663+
req := &evmtypes.QueryBalanceRequest{
3664+
Address: address,
3665+
}
3666+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.Balance, req)
3667+
return res, err
3668+
}
3669+
3670+
func (c *chainClient) FetchEVMStorage(ctx context.Context, address string, key *string) (*evmtypes.QueryStorageResponse, error) {
3671+
req := &evmtypes.QueryStorageRequest{
3672+
Address: address,
3673+
}
3674+
3675+
if key != nil {
3676+
req.Key = *key
3677+
}
3678+
3679+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.Storage, req)
3680+
return res, err
3681+
}
3682+
3683+
func (c *chainClient) FetchEVMCode(ctx context.Context, address string) (*evmtypes.QueryCodeResponse, error) {
3684+
req := &evmtypes.QueryCodeRequest{
3685+
Address: address,
3686+
}
3687+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.Code, req)
3688+
return res, err
3689+
}
3690+
3691+
func (c *chainClient) FetchEVMBaseFee(ctx context.Context) (*evmtypes.QueryBaseFeeResponse, error) {
3692+
req := &evmtypes.QueryBaseFeeRequest{}
3693+
res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.evmQueryClient.BaseFee, req)
3694+
return res, err
3695+
}
3696+
35893697
// SyncBroadcastMsg sends Tx to chain and waits until Tx is included in block.
35903698
func (c *chainClient) SyncBroadcastMsg(msgs ...sdk.Msg) (*txtypes.BroadcastTxResponse, error) {
35913699
req, res, err := c.BroadcastMsg(txtypes.BroadcastMode_BROADCAST_MODE_SYNC, msgs...)

client/chain/chain_test_support.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
ethcommon "github.com/ethereum/go-ethereum/common"
2525
"google.golang.org/grpc"
2626

27+
erc20types "github.com/InjectiveLabs/sdk-go/chain/erc20/types"
28+
evmtypes "github.com/InjectiveLabs/sdk-go/chain/evm/types"
2729
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
2830
exchangev2types "github.com/InjectiveLabs/sdk-go/chain/exchange/types/v2"
2931
permissionstypes "github.com/InjectiveLabs/sdk-go/chain/permissions/types"
@@ -1165,6 +1167,48 @@ func (c *MockChainClient) FetchEipBaseFee(ctx context.Context) (*txfeestypes.Que
11651167
return &txfeestypes.QueryEipBaseFeeResponse{}, nil
11661168
}
11671169

1170+
// ERC20 module
1171+
func (c *MockChainClient) FetchAllTokenPairs(ctx context.Context) (*erc20types.QueryAllTokenPairsResponse, error) {
1172+
return &erc20types.QueryAllTokenPairsResponse{}, nil
1173+
}
1174+
1175+
func (c *MockChainClient) FetchTokenPairByDenom(ctx context.Context, bankDenom string) (*erc20types.QueryTokenPairByDenomResponse, error) {
1176+
return &erc20types.QueryTokenPairByDenomResponse{}, nil
1177+
}
1178+
1179+
func (c *MockChainClient) FetchTokenPairByERC20Address(ctx context.Context, erc20Address string) (*erc20types.QueryTokenPairByERC20AddressResponse, error) {
1180+
return &erc20types.QueryTokenPairByERC20AddressResponse{}, nil
1181+
}
1182+
1183+
// EVM module
1184+
func (c *MockChainClient) FetchEVMAccount(ctx context.Context, address string) (*evmtypes.QueryAccountResponse, error) {
1185+
return &evmtypes.QueryAccountResponse{}, nil
1186+
}
1187+
1188+
func (c *MockChainClient) FetchEVMCosmosAccount(ctx context.Context, address string) (*evmtypes.QueryCosmosAccountResponse, error) {
1189+
return &evmtypes.QueryCosmosAccountResponse{}, nil
1190+
}
1191+
1192+
func (c *MockChainClient) FetchEVMValidatorAccount(ctx context.Context, consAddress string) (*evmtypes.QueryValidatorAccountResponse, error) {
1193+
return &evmtypes.QueryValidatorAccountResponse{}, nil
1194+
}
1195+
1196+
func (c *MockChainClient) FetchEVMBalance(ctx context.Context, address string) (*evmtypes.QueryBalanceResponse, error) {
1197+
return &evmtypes.QueryBalanceResponse{}, nil
1198+
}
1199+
1200+
func (c *MockChainClient) FetchEVMStorage(ctx context.Context, address string, key *string) (*evmtypes.QueryStorageResponse, error) {
1201+
return &evmtypes.QueryStorageResponse{}, nil
1202+
}
1203+
1204+
func (c *MockChainClient) FetchEVMCode(ctx context.Context, address string) (*evmtypes.QueryCodeResponse, error) {
1205+
return &evmtypes.QueryCodeResponse{}, nil
1206+
}
1207+
1208+
func (c *MockChainClient) FetchEVMBaseFee(ctx context.Context) (*evmtypes.QueryBaseFeeResponse, error) {
1209+
return &evmtypes.QueryBaseFeeResponse{}, nil
1210+
}
1211+
11681212
func (c *MockChainClient) CurrentChainGasPrice() int64 {
11691213
return int64(injectiveclient.DefaultGasPrice)
11701214
}

examples/chain/12_ChainStream/example.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77

8-
chainStreamModule "github.com/InjectiveLabs/sdk-go/chain/stream/types/v2"
8+
chainstreamv2 "github.com/InjectiveLabs/sdk-go/chain/stream/types/v2"
99
"github.com/InjectiveLabs/sdk-go/client"
1010
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
1111
"github.com/InjectiveLabs/sdk-go/client/common"
@@ -39,40 +39,40 @@ func main() {
3939
injUsdtMarket := "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
4040
injUsdtPerpMarket := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
4141

42-
req := chainStreamModule.StreamRequest{
43-
BankBalancesFilter: &chainStreamModule.BankBalancesFilter{
42+
req := chainstreamv2.StreamRequest{
43+
BankBalancesFilter: &chainstreamv2.BankBalancesFilter{
4444
Accounts: []string{"*"},
4545
},
46-
SpotOrdersFilter: &chainStreamModule.OrdersFilter{
46+
SpotOrdersFilter: &chainstreamv2.OrdersFilter{
4747
MarketIds: []string{injUsdtMarket},
4848
SubaccountIds: []string{subaccountId},
4949
},
50-
DerivativeOrdersFilter: &chainStreamModule.OrdersFilter{
50+
DerivativeOrdersFilter: &chainstreamv2.OrdersFilter{
5151
MarketIds: []string{injUsdtPerpMarket},
5252
SubaccountIds: []string{subaccountId},
5353
},
54-
SpotTradesFilter: &chainStreamModule.TradesFilter{
54+
SpotTradesFilter: &chainstreamv2.TradesFilter{
5555
MarketIds: []string{injUsdtMarket},
5656
SubaccountIds: []string{"*"},
5757
},
58-
SubaccountDepositsFilter: &chainStreamModule.SubaccountDepositsFilter{
58+
SubaccountDepositsFilter: &chainstreamv2.SubaccountDepositsFilter{
5959
SubaccountIds: []string{subaccountId},
6060
},
61-
DerivativeOrderbooksFilter: &chainStreamModule.OrderbookFilter{
61+
DerivativeOrderbooksFilter: &chainstreamv2.OrderbookFilter{
6262
MarketIds: []string{injUsdtPerpMarket},
6363
},
64-
SpotOrderbooksFilter: &chainStreamModule.OrderbookFilter{
64+
SpotOrderbooksFilter: &chainstreamv2.OrderbookFilter{
6565
MarketIds: []string{injUsdtMarket},
6666
},
67-
PositionsFilter: &chainStreamModule.PositionsFilter{
67+
PositionsFilter: &chainstreamv2.PositionsFilter{
6868
SubaccountIds: []string{subaccountId},
6969
MarketIds: []string{injUsdtPerpMarket},
7070
},
71-
DerivativeTradesFilter: &chainStreamModule.TradesFilter{
71+
DerivativeTradesFilter: &chainstreamv2.TradesFilter{
7272
SubaccountIds: []string{"*"},
7373
MarketIds: []string{injUsdtPerpMarket},
7474
},
75-
OraclePriceFilter: &chainStreamModule.OraclePriceFilter{
75+
OraclePriceFilter: &chainstreamv2.OraclePriceFilter{
7676
Symbol: []string{"INJ", "USDT"},
7777
},
7878
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"time"
7+
8+
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
9+
10+
erc20types "github.com/InjectiveLabs/sdk-go/chain/erc20/types"
11+
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
12+
"github.com/InjectiveLabs/sdk-go/client/common"
13+
)
14+
15+
func main() {
16+
network := common.LoadNetwork("testnet", "lb")
17+
tmClient, err := rpchttp.New(network.TmEndpoint)
18+
if err != nil {
19+
panic(err)
20+
}
21+
22+
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
23+
os.Getenv("HOME")+"/.injectived",
24+
"injectived",
25+
"file",
26+
"inj-user",
27+
"12345678",
28+
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
29+
false,
30+
)
31+
32+
if err != nil {
33+
panic(err)
34+
}
35+
36+
clientCtx, err := chainclient.NewClientContext(
37+
network.ChainId,
38+
senderAddress.String(),
39+
cosmosKeyring,
40+
)
41+
if err != nil {
42+
panic(err)
43+
}
44+
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
45+
46+
chainClient, err := chainclient.NewChainClient(
47+
clientCtx,
48+
network,
49+
)
50+
51+
if err != nil {
52+
panic(err)
53+
}
54+
55+
gasPrice := chainClient.CurrentChainGasPrice()
56+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
57+
gasPrice = int64(float64(gasPrice) * 1.1)
58+
chainClient.SetGasPrice(gasPrice)
59+
60+
usdtDenom := "factory/inj10vkkttgxdeqcgeppu20x9qtyvuaxxev8qh0awq/usdt"
61+
usdtERC20 := "0xdAC17F958D2ee523a2206206994597C13D831ec7"
62+
63+
msg := &erc20types.MsgCreateTokenPair{
64+
Sender: senderAddress.String(),
65+
TokenPair: erc20types.TokenPair{
66+
BankDenom: usdtDenom,
67+
Erc20Address: usdtERC20,
68+
},
69+
}
70+
71+
// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
72+
err = chainClient.QueueBroadcastMsg(msg)
73+
74+
if err != nil {
75+
fmt.Println(err)
76+
}
77+
78+
time.Sleep(time.Second * 5)
79+
80+
gasFee, err := chainClient.GetGasFee()
81+
82+
if err != nil {
83+
fmt.Println(err)
84+
return
85+
}
86+
87+
fmt.Println("gas fee:", gasFee, "INJ")
88+
89+
gasPrice = chainClient.CurrentChainGasPrice()
90+
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
91+
gasPrice = int64(float64(gasPrice) * 1.1)
92+
chainClient.SetGasPrice(gasPrice)
93+
}

0 commit comments

Comments
 (0)