Skip to content

Commit be05f2b

Browse files
authored
Merge pull request #315 from InjectiveLabs/cp-447/refactor_support_for_exchange_v2
[CP-447] refactor support for exchange v2
2 parents 84f2f22 + 0de5580 commit be05f2b

File tree

356 files changed

+14405
-6665
lines changed

Some content is hidden

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

356 files changed

+14405
-6665
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@ linters:
6262
- proto
6363
- client/keyring/testdata
6464
- client/chain/chain_test_support.go
65+
- typeddata
66+
- eip712_cosmos.go
67+
- eip712.go
6568
issues:
6669
max-issues-per-linter: 0

Makefile

Lines changed: 9 additions & 2 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.16.3 --depth 1 --single-branch
4+
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.16.16 --depth 1 --single-branch
55

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

99
copy-exchange-client: clone-injective-indexer
1010
rm -rf exchange/*
@@ -138,14 +138,21 @@ copy-chain-types: clone-injective-core
138138
cp injective-core/injective-chain/stream/types/v2/*.pb.go chain/stream/types/v2
139139
mkdir -p chain/types && \
140140
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 && \
141142
cp injective-core/injective-chain/types/codec.go chain/types && \
143+
cp injective-core/injective-chain/types/errors.go chain/types && \
142144
cp injective-core/injective-chain/types/int.go chain/types && \
143145
cp injective-core/injective-chain/types/util.go chain/types && \
144146
cp injective-core/injective-chain/types/validation.go chain/types
145147

146148
@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" {} \;
147149
@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" {} \;
148150

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+
149156
rm -rf proto
150157
cp -r injective-core/proto ./
151158

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
5050

5151
txFactory := chainclient.NewTxFactory(clientCtx)
52-
chainClient, err := chainclient.NewChainClient(
52+
chainClient, err := chainclient.NewChainClientV2(
5353
clientCtx,
5454
network,
5555
common.OptionTxFactory(&txFactory),
@@ -99,7 +99,7 @@ func main() {
9999
panic(err)
100100
}
101101

102-
str, _ := json.MarshalIndent(response, "", " ")
102+
str, _ := json.MarshalIndent(response, "", "\t")
103103
fmt.Print(string(str))
104104

105105
gasPrice = chainClient.CurrentChainGasPrice()

chain/erc20/types/params.pb.go

Lines changed: 73 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)