Skip to content

Commit 9ccb3b7

Browse files
authored
Merge pull request #325 from InjectiveLabs/release/v1_58_for_chain_v1_16
Release/v1 58 for chain v1 16
2 parents 680fe94 + a95aae8 commit 9ccb3b7

File tree

529 files changed

+186796
-14323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

529 files changed

+186796
-14323
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ jobs:
1313
name: lint
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- uses: actions/setup-go@v5
1818
with:
1919
go-version-file: "go.mod"
2020
check-latest: true
2121
- name: golangci-lint
22-
uses: golangci/golangci-lint-action@v6
22+
uses: golangci/golangci-lint-action@v8
2323
with:
2424
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
25-
version: latest
25+
version: v2.1.6
2626

2727
# Optional: working directory, useful for monorepos
2828
# working-directory: somedir

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.idea/
3+
.vscode/
34
.chain_cookie
45
.exchange_cookie
56
coverage.out

.golangci.yml

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,69 @@
1+
version: "2"
2+
run:
3+
tests: false
14
linters:
2-
fast: false
35
enable:
46
- errcheck
57
- errorlint
6-
- gas
78
- gocritic
8-
- gofmt
9-
- goimports
10-
- gosimple
119
- govet
1210
- ineffassign
13-
- megacheck
1411
- misspell
1512
- nakedret
1613
- prealloc
1714
- revive
18-
- staticcheck
1915
- unconvert
2016
- unparam
2117
disable:
2218
- unused
23-
24-
linters-settings:
25-
revive:
26-
enable-all-rules: true
19+
settings:
20+
gocritic:
21+
disabled-checks:
22+
- singleCaseSwitch
23+
- deferInLoop
24+
- hugeParam
25+
- unnamedResult
26+
enabled-tags:
27+
- performance
28+
- diagnostic
29+
- style
30+
- opinionated
31+
- experimental
32+
revive:
33+
enable-all-rules: true
34+
rules:
35+
- name: var-naming
36+
arguments:
37+
- - ID
38+
- name: add-constant
39+
disabled: true
40+
- name: line-length-limit
41+
arguments:
42+
- 140
43+
- name: cognitive-complexity
44+
arguments:
45+
- 20
46+
disabled: false
47+
exclusions:
48+
generated: lax
49+
presets:
50+
- comments
51+
- common-false-positives
52+
- legacy
53+
- std-error-handling
2754
rules:
28-
- name: var-naming
29-
arguments:
30-
- ["ID"]
31-
- name: add-constant
32-
disabled: true
33-
- name: line-length-limit
34-
arguments:
35-
- 140
36-
gocritic:
37-
enabled-tags:
38-
- performance
39-
- diagnostic
40-
- style
41-
- opinionated
42-
- experimental
43-
disabled-checks:
44-
- singleCaseSwitch
45-
- deferInLoop
46-
- hugeParam
47-
- unnamedResult
55+
- linters:
56+
- revive
57+
text: ALL_CAPS
58+
paths:
59+
- chain
60+
- exchange
61+
- injective_data
62+
- proto
63+
- client/keyring/testdata
64+
- client/chain/chain_test_support.go
65+
- typeddata
66+
- eip712_cosmos.go
67+
- eip712.go
4868
issues:
49-
exclude-rules:
50-
- linters:
51-
- revive
52-
text: ALL_CAPS
53-
exclude-dirs:
54-
- chain
55-
- exchange
56-
- injective_data
57-
- proto
58-
- client/keyring/testdata
5969
max-issues-per-linter: 0
60-
61-
run:
62-
tests: false

Makefile

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
all:
22

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

66
clone-injective-core:
7-
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.15.0 --depth 1 --single-branch
7+
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.16.0 --depth 1 --single-branch
88

99
copy-exchange-client: clone-injective-indexer
1010
rm -rf exchange/*
@@ -51,9 +51,34 @@ copy-chain-types: clone-injective-core
5151
mkdir -p chain/auction/types && \
5252
cp injective-core/injective-chain/modules/auction/types/*.pb.go chain/auction/types && \
5353
cp injective-core/injective-chain/modules/auction/types/codec.go chain/auction/types
54+
mkdir -p chain/erc20/types && \
55+
cp injective-core/injective-chain/modules/erc20/types/*.pb.go chain/erc20/types && \
56+
cp injective-core/injective-chain/modules/erc20/types/codec.go chain/erc20/types
57+
mkdir -p chain/evm/types && \
58+
cp injective-core/injective-chain/modules/evm/types/*.pb.go chain/evm/types && \
59+
cp injective-core/injective-chain/modules/evm/types/access_list.go chain/evm/types && \
60+
cp injective-core/injective-chain/modules/evm/types/access_list_tx.go chain/evm/types && \
61+
cp injective-core/injective-chain/modules/evm/types/chain_config.go chain/evm/types && \
62+
cp injective-core/injective-chain/modules/evm/types/codec.go chain/evm/types && \
63+
cp injective-core/injective-chain/modules/evm/types/dynamic_fee_tx.go chain/evm/types && \
64+
cp injective-core/injective-chain/modules/evm/types/errors.go chain/evm/types && \
65+
cp injective-core/injective-chain/modules/evm/types/eth.go chain/evm/types && \
66+
cp injective-core/injective-chain/modules/evm/types/events.go chain/evm/types && \
67+
cp injective-core/injective-chain/modules/evm/types/key.go chain/evm/types && \
68+
cp injective-core/injective-chain/modules/evm/types/legacy_tx.go chain/evm/types && \
69+
cp injective-core/injective-chain/modules/evm/types/logs.go chain/evm/types && \
70+
cp injective-core/injective-chain/modules/evm/types/msg.go chain/evm/types && \
71+
cp injective-core/injective-chain/modules/evm/types/params.go chain/evm/types && \
72+
cp injective-core/injective-chain/modules/evm/types/storage.go chain/evm/types && \
73+
cp injective-core/injective-chain/modules/evm/types/tx.go chain/evm/types && \
74+
cp injective-core/injective-chain/modules/evm/types/tx_data.go chain/evm/types && \
75+
cp injective-core/injective-chain/modules/evm/types/utils.go chain/evm/types
5476
mkdir -p chain/exchange/types && \
5577
cp injective-core/injective-chain/modules/exchange/types/*.go chain/exchange/types && \
5678
rm -rf chain/exchange/types/*test.go && rm -rf chain/exchange/types/*gw.go
79+
mkdir -p chain/exchange/types/v2 && \
80+
cp injective-core/injective-chain/modules/exchange/types/v2/*.go chain/exchange/types/v2 && \
81+
rm -rf chain/exchange/types/v2/*test.go && rm -rf chain/exchange/types/v2/*gw.go
5782
mkdir -p chain/insurance/types && \
5883
cp injective-core/injective-chain/modules/insurance/types/*.pb.go chain/insurance/types && \
5984
cp injective-core/injective-chain/modules/insurance/types/codec.go chain/insurance/types
@@ -109,18 +134,41 @@ copy-chain-types: clone-injective-core
109134
cp injective-core/injective-chain/modules/wasmx/types/proposal.go chain/wasmx/types
110135
mkdir -p chain/stream/types && \
111136
cp injective-core/injective-chain/stream/types/*.pb.go chain/stream/types
137+
mkdir -p chain/stream/types/v2 && \
138+
cp injective-core/injective-chain/stream/types/v2/*.pb.go chain/stream/types/v2
112139
mkdir -p chain/types && \
113140
cp injective-core/injective-chain/types/*.pb.go injective-core/injective-chain/types/config.go chain/types && \
141+
cp injective-core/injective-chain/types/chain_id.go chain/types && \
114142
cp injective-core/injective-chain/types/codec.go chain/types && \
115-
cp injective-core/injective-chain/types/util.go chain/types
143+
cp injective-core/injective-chain/types/errors.go chain/types && \
144+
cp injective-core/injective-chain/types/int.go chain/types && \
145+
cp injective-core/injective-chain/types/util.go chain/types && \
146+
cp injective-core/injective-chain/types/validation.go chain/types
116147

117148
@find ./chain -type f -name "*.go" -exec sed -i "" -e "s|github.com/InjectiveLabs/injective-core/injective-chain/modules|github.com/InjectiveLabs/sdk-go/chain|g" {} \;
118149
@find ./chain -type f -name "*.go" -exec sed -i "" -e "s|github.com/InjectiveLabs/injective-core/injective-chain|github.com/InjectiveLabs/sdk-go/chain|g" {} \;
119150

151+
mkdir -p chain/evm/precompiles/bank && mkdir -p chain/evm/precompiles/exchange && mkdir -p chain/evm/precompiles/staking && \
152+
cp injective-core/injective-chain/modules/evm/precompiles/bindings/cosmos/precompile/bank/*.go chain/evm/precompiles/bank && \
153+
cp injective-core/injective-chain/modules/evm/precompiles/bindings/cosmos/precompile/exchange/*.go chain/evm/precompiles/exchange && \
154+
cp injective-core/injective-chain/modules/evm/precompiles/bindings/cosmos/precompile/staking/*.go chain/evm/precompiles/staking
155+
120156
rm -rf proto
121157
cp -r injective-core/proto ./
122158

123159
rm -rf injective-core
160+
make extract-message-names
161+
162+
extract-message-names:
163+
@echo "Extracting message names from tx.pb.go files..."
164+
@mkdir -p injective_data
165+
@find ./chain -name "tx.pb.go" -exec grep -h "proto\.RegisterType" {} \; | \
166+
sed -n 's/.*proto\.RegisterType([^"]*"\([^"]*\)".*/\1/p' | \
167+
grep -v 'Response$$' | \
168+
sort -u | \
169+
jq -R -s 'split("\n")[:-1]' > injective_data/chain_messages_list.json
170+
@echo "Message names extracted to injective_data/chain_messages_list.json (excluding Response messages)"
171+
@echo "Total messages found: $$(jq length injective_data/chain_messages_list.json)"
124172

125173
#gen: gen-proto
126174
#
@@ -168,4 +216,8 @@ lint-master: export GOPROXY=direct
168216
lint-master:
169217
golangci-lint run --timeout=15m -v --new-from-rev=master
170218

171-
.PHONY: copy-exchange-client tests coverage lint lint-last-commit lint-master
219+
lint-all: export GOPROXY=direct
220+
lint-all:
221+
golangci-lint run --timeout=15m -v
222+
223+
.PHONY: copy-exchange-client tests coverage lint lint-last-commit lint-master lint-all extract-message-names

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,60 @@ go run examples/exchange/derivatives/4_Orderbook/example.go
2828

2929
---
3030

31+
## Choose Exchange V1 or Exchange V2 queries
32+
33+
The SDK provides two different clients for interacting with the Injective Exchange:
34+
35+
- `ChainClient`: Use this client if you need to interact with Exchange V1. This client maintains compatibility with the original exchange implementation and is suitable for existing applications that haven't migrated to V2 yet. Note that this client will not include any new endpoints added to the Exchange module - for access to new features, you should migrate to V2.
36+
37+
- `ChainClientV2`: Use this client for all new applications or when you need to interact with Exchange V2 features. This client provides access to the latest exchange functionality and improvements, including all new endpoints added to the Exchange module.
38+
39+
Example usage:
40+
```go
41+
// For Exchange V1
42+
client := chainclient.NewChainClient(...)
43+
44+
// For Exchange V2
45+
clientV2 := chainclient.NewChainClientV2(...)
46+
```
47+
48+
### Markets Assistant
49+
50+
The SDK provides a Markets Assistant to help you interact with markets in both V1 and V2. Here's how to create instances for each version:
51+
52+
```go
53+
// For Exchange V1 markets
54+
marketsAssistant, err := chain.NewMarketsAssistant(ctx, client) // ChainClient instance
55+
if err != nil {
56+
// Handle error
57+
}
58+
59+
// For Exchange V2 markets
60+
marketsAssistantV2, err := chain.NewHumanReadableMarketsAssistant(ctx, clientV2) // ChainClientV2 instance
61+
if err != nil {
62+
// Handle error
63+
}
64+
```
65+
66+
The Markets Assistant provides helper methods to:
67+
- Fetch market information
68+
- Get market prices
69+
- Query orderbooks
70+
- Access market statistics
71+
72+
Make sure to use the correct version of the Markets Assistant that matches your ChainClient version to ensure compatibility. The V1 assistant (`NewMarketsAssistant`) will only work with V1 markets, while the V2 assistant (`NewHumanReadableMarketsAssistant`) provides access to V2 markets and their features.
73+
74+
### Format Differences
75+
76+
There are important format differences between V1 and V2 endpoints:
77+
78+
- **Exchange V1**: All values (amounts, prices, margins, notionals) are returned in chain format (raw numbers)
79+
- **Exchange V2**: Most values are returned in human-readable format for better usability:
80+
- Amounts, prices, margins, and notionals are in human-readable format
81+
- Deposit-related information remains in chain format to maintain consistency with the Bank module
82+
83+
This format difference is one of the key improvements in V2, making it easier to work with market data without manual conversion.
84+
3185
## Updating Exchange API proto and client
3286

3387
```bash

auth_vote/authz_vote.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"os"
8+
"time"
79

8-
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
9-
"github.com/InjectiveLabs/sdk-go/client/common"
1010
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
1111
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
1212
sdk "github.com/cosmos/cosmos-sdk/types"
1313
authztypes "github.com/cosmos/cosmos-sdk/x/authz"
1414
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
15+
16+
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
17+
"github.com/InjectiveLabs/sdk-go/client/common"
1518
)
1619

20+
//revive:disable:function-length // this is an example script
1721
func main() {
1822
network := common.LoadNetwork("testnet", "lb")
19-
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
23+
tmClient, err := rpchttp.New(network.TmEndpoint)
2024
if err != nil {
2125
panic(err)
2226
}
@@ -48,7 +52,7 @@ func main() {
4852
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
4953

5054
txFactory := chainclient.NewTxFactory(clientCtx)
51-
chainClient, err := chainclient.NewChainClient(
55+
chainClient, err := chainclient.NewChainClientV2(
5256
clientCtx,
5357
network,
5458
common.OptionTxFactory(&txFactory),
@@ -58,7 +62,10 @@ func main() {
5862
panic(err)
5963
}
6064

61-
gasPrice := chainClient.CurrentChainGasPrice()
65+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
66+
defer cancel()
67+
68+
gasPrice := chainClient.CurrentChainGasPrice(ctx)
6269
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
6370
gasPrice = int64(float64(gasPrice) * 1.1)
6471
chainClient.SetGasPrice(gasPrice)
@@ -92,16 +99,16 @@ func main() {
9299
}
93100

94101
// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
95-
response, err := chainClient.AsyncBroadcastMsg(msgs...)
102+
response, err := chainClient.AsyncBroadcastMsg(ctx, msgs...)
96103

97104
if err != nil {
98105
panic(err)
99106
}
100107

101-
str, _ := json.MarshalIndent(response, "", " ")
108+
str, _ := json.MarshalIndent(response, "", "\t")
102109
fmt.Print(string(str))
103110

104-
gasPrice = chainClient.CurrentChainGasPrice()
111+
gasPrice = chainClient.CurrentChainGasPrice(ctx)
105112
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
106113
gasPrice = int64(float64(gasPrice) * 1.1)
107114
chainClient.SetGasPrice(gasPrice)

0 commit comments

Comments
 (0)