Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
dec5d55
(feat) Added support for Exchange V2 queries, messages and types
aarmoa Nov 8, 2024
b78770a
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-go into fe…
aarmoa Nov 14, 2024
5acf635
Merge branch 'dev' into feat/add_exchange_v2_support
aarmoa Nov 14, 2024
bcafaa0
(feat) Added support for chain stream V2 types
aarmoa Nov 20, 2024
95e6e8b
(fix) Fixed pre-commit issues
aarmoa Nov 20, 2024
49b9c7f
Merge pull request #287 from InjectiveLabs/fix/synced_dev_with_v1_14_…
aarmoa Feb 10, 2025
73bbcef
feat: removed the deprecated pre-commit repo pre-commit-golang. Added…
aarmoa Feb 13, 2025
e02f973
fix: added skip directories into the golanci lint config
aarmoa Feb 13, 2025
dbc043b
fix: fixed lint errors
aarmoa Feb 13, 2025
b192fa9
fix: fixed lint errors
aarmoa Feb 13, 2025
291a94f
Merge pull request #290 from InjectiveLabs/feat/remove_deprecated_pre…
aarmoa Feb 13, 2025
dd659b9
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-go into fe…
aarmoa Mar 13, 2025
d5b0498
fix: fix error in golangci-lint configuration
aarmoa Mar 13, 2025
7ff73cb
fix: sync golangci-lint configuration with injective-core
aarmoa Mar 13, 2025
9a9d61e
fix: fixed a couple of lint errors and a pre-commit issue
aarmoa Mar 13, 2025
a7bd626
feat: updated proto definitions for the chain upgrade v1.15
aarmoa Mar 17, 2025
e1db3a2
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
aarmoa Mar 17, 2025
ac29b76
fix: synced go.mod dependecnies with Injective core
aarmoa Mar 17, 2025
93b527b
fix: fixed lint errors
aarmoa Mar 17, 2025
e43baff
fix: fixed lint errors
aarmoa Mar 17, 2025
41ce320
feat: updated all proto definitions for v1.15 chain upgrade. Added an…
aarmoa Mar 20, 2025
552f79c
feat: updated all examples to query gas price from the chain instead …
aarmoa Mar 25, 2025
1128442
Feat/sync with master v1.56.2 (#298)
aarmoa Apr 2, 2025
c111ad5
feat: updated proto definitions for the chain upgrade v1.15
aarmoa Mar 17, 2025
c3429ee
(fix) Applied the fixes for EIP712 JSON unmarshalling to the master b…
aarmoa Jan 23, 2025
f55a39f
fix: updated the oracle stream prices script to send the oracle type …
aarmoa Feb 17, 2025
3820ac0
fix: updated the oracle stream prices script to send the oracle type …
aarmoa Feb 17, 2025
8851821
fix: synced go.mod dependecnies with Injective core
aarmoa Mar 17, 2025
4660e8f
fix: fixed lint errors
aarmoa Mar 17, 2025
4504d9c
fix: fixed lint errors
aarmoa Mar 17, 2025
fc6517d
feat: updated all proto definitions for v1.15 chain upgrade. Added an…
aarmoa Mar 20, 2025
002eed1
feat: updated all examples to query gas price from the chain instead …
aarmoa Mar 25, 2025
1186d18
fix: fix function parameter type
aarmoa Apr 2, 2025
8c6f25c
Merge branch 'feat/chain_upgrade_v1_15' of https://github.com/Injecti…
aarmoa Apr 2, 2025
282864b
feat: updated proto definition to v1.15.0-beta.2 and v1.14.48 for Ind…
aarmoa Apr 7, 2025
3c555ae
fix: update ofac.json file
aarmoa Apr 7, 2025
4b7c4c0
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
aarmoa Apr 7, 2025
7476eb3
Merge pull request #294 from InjectiveLabs/feat/chain_upgrade_v1_15
aarmoa Apr 8, 2025
bc7c61e
Improve error messaging and enhance documentation in eip712_cosmos.go…
meetrick Apr 8, 2025
6be9ce4
fix: fixed array creatin in a unit test (#299)
aarmoa Apr 8, 2025
77e624d
Release/v1.57 for chain v1.15 (#302) (#303)
aarmoa Apr 16, 2025
7d83c17
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-go into fe…
aarmoa Apr 30, 2025
5824e4e
chore: Updated all proto dependencies to the latest version of `maste…
aarmoa May 7, 2025
cbc585b
chore: updated the branch with the latest version of `master` in inje…
aarmoa May 7, 2025
14bc7ef
chore: updated the branch with the latest version of in injective co…
aarmoa May 12, 2025
5066aa5
fix: fixed lint errors
aarmoa May 12, 2025
6f2486d
fix: update lint configuration
aarmoa May 12, 2025
6e0faea
fix: fix errors in ling config yml file
aarmoa May 12, 2025
922829c
fix: fix lint errors
aarmoa May 12, 2025
1362b2e
fix: fix lint errors
aarmoa May 13, 2025
de0458f
fix: fixed issues when creating rpchttp connections to the tendermint…
aarmoa May 14, 2025
fec751e
fix: fixed lint errors
aarmoa May 15, 2025
8f2dda0
chore: updated market's logic to convert values now that markets have…
aarmoa May 20, 2025
6dc05e3
feat: updated examples and helper functions for GTB orders and the ne…
aarmoa May 21, 2025
0da105a
chore: updated indexer version to v1.16.0-rc2
aarmoa May 21, 2025
0495311
Merge pull request #263 from InjectiveLabs/feat/add_exchange_v2_support
aarmoa May 22, 2025
948c59f
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
aarmoa May 26, 2025
7173b32
chore: updated proto definitions
aarmoa May 26, 2025
7d8fb1f
Merge pull request #307 from InjectiveLabs/chore/sync_dev_with_master…
aarmoa May 26, 2025
79e8f9b
cp-395: added support for the new evm and erc20 modules queries. Adde…
aarmoa May 27, 2025
07a2d52
Merge branch 'dev' into cp-395/add_support_for_v1_16
aarmoa May 27, 2025
1a0a621
Merge pull request #308 from InjectiveLabs/cp-395/add_support_for_v1_16
aarmoa May 27, 2025
b77d838
feat: added logic in Makefile to generate a list of all chain message…
aarmoa May 29, 2025
78016d6
fix: applied the changes suggested in the rabbit review
aarmoa May 29, 2025
678af51
Merge pull request #309 from InjectiveLabs/feat/add_chain_messages_list
aarmoa May 29, 2025
97d1a82
feat: preserve caller-defined headers in ExecuteCall
arrivets Jun 15, 2025
4f14305
fix: instantiate tendermint client in example 62
arrivets Jun 15, 2025
6b69496
fix: rename duplicate example 62 to 65
arrivets Jun 16, 2025
84f2f22
Merge pull request #313 from InjectiveLabs/feat/preserve-caller-defin…
aarmoa Jun 16, 2025
38ca30d
feat: created ChainClientV2 to support exchange V2 queries. Created V…
aarmoa Jun 16, 2025
fe5be3a
feat: updated proto definitions from core v1.16.0-beta.3 and indexer …
aarmoa Jun 16, 2025
0de5580
fix: fix precommit issue
aarmoa Jun 16, 2025
be05f2b
Merge pull request #315 from InjectiveLabs/cp-447/refactor_support_fo…
aarmoa Jun 16, 2025
f1c6e3d
feat: updated proto definitions for indexer v1.16.20. Updated queries…
aarmoa Jun 16, 2025
f6dd233
Merge pull request #316 from InjectiveLabs/chore/update_indexer_v1_16_20
aarmoa Jun 16, 2025
ae27d1f
fix: renamed example scripts
aarmoa Jun 23, 2025
7dfdce0
Merge pull request #317 from InjectiveLabs/chore/update_example_scripts
aarmoa Jun 23, 2025
c853ca0
fix: changed the chain connection configurations to ensure they use t…
aarmoa Jul 8, 2025
19f96de
fix: fixed pre-commit and lint issues
aarmoa Jul 8, 2025
2a7357b
Merge pull request #321 from InjectiveLabs/cp-502/fix_chain_responses…
aarmoa Jul 8, 2025
9753940
[CP-517] Added a context parameter to broadcast functions in ChainCli…
aarmoa Jul 17, 2025
a8b8b8b
[CP-517] Fixed incorrect function comments
aarmoa Jul 17, 2025
9acaa50
[CP-517] Fixed errors spotted in the PR comments
aarmoa Jul 17, 2025
500561a
Merge pull request #323 from InjectiveLabs/cp-517/improve_broadcast_f…
aarmoa Jul 18, 2025
3d69450
[CHORE] Updated proto definitions to the v1.16 mainnet upgrade versio…
aarmoa Jul 28, 2025
a95aae8
Merge pull request #324 from InjectiveLabs/chore/final_v1_16_alignmen…
aarmoa Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
version: v2.1.6

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea/
.vscode/
.chain_cookie
.exchange_cookie
coverage.out
95 changes: 51 additions & 44 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,69 @@
version: "2"
run:
tests: false
linters:
fast: false
enable:
- errcheck
- errorlint
- gas
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- megacheck
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- unconvert
- unparam
disable:
- unused

linters-settings:
revive:
enable-all-rules: true
settings:
gocritic:
disabled-checks:
- singleCaseSwitch
- deferInLoop
- hugeParam
- unnamedResult
enabled-tags:
- performance
- diagnostic
- style
- opinionated
- experimental
revive:
enable-all-rules: true
rules:
- name: var-naming
arguments:
- - ID
- name: add-constant
disabled: true
- name: line-length-limit
arguments:
- 140
- name: cognitive-complexity
arguments:
- 20
disabled: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- name: var-naming
arguments:
- ["ID"]
- name: add-constant
disabled: true
- name: line-length-limit
arguments:
- 140
gocritic:
enabled-tags:
- performance
- diagnostic
- style
- opinionated
- experimental
disabled-checks:
- singleCaseSwitch
- deferInLoop
- hugeParam
- unnamedResult
- linters:
- revive
text: ALL_CAPS
paths:
- chain
- exchange
- injective_data
- proto
- client/keyring/testdata
- client/chain/chain_test_support.go
- typeddata
- eip712_cosmos.go
- eip712.go
issues:
exclude-rules:
- linters:
- revive
text: ALL_CAPS
exclude-dirs:
- chain
- exchange
- injective_data
- proto
- client/keyring/testdata
max-issues-per-linter: 0

run:
tests: false
60 changes: 56 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
all:

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

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

copy-exchange-client: clone-injective-indexer
rm -rf exchange/*
Expand Down Expand Up @@ -51,9 +51,34 @@ copy-chain-types: clone-injective-core
mkdir -p chain/auction/types && \
cp injective-core/injective-chain/modules/auction/types/*.pb.go chain/auction/types && \
cp injective-core/injective-chain/modules/auction/types/codec.go chain/auction/types
mkdir -p chain/erc20/types && \
cp injective-core/injective-chain/modules/erc20/types/*.pb.go chain/erc20/types && \
cp injective-core/injective-chain/modules/erc20/types/codec.go chain/erc20/types
mkdir -p chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/*.pb.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/access_list.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/access_list_tx.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/chain_config.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/codec.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/dynamic_fee_tx.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/errors.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/eth.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/events.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/key.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/legacy_tx.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/logs.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/msg.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/params.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/storage.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/tx.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/tx_data.go chain/evm/types && \
cp injective-core/injective-chain/modules/evm/types/utils.go chain/evm/types
mkdir -p chain/exchange/types && \
cp injective-core/injective-chain/modules/exchange/types/*.go chain/exchange/types && \
rm -rf chain/exchange/types/*test.go && rm -rf chain/exchange/types/*gw.go
mkdir -p chain/exchange/types/v2 && \
cp injective-core/injective-chain/modules/exchange/types/v2/*.go chain/exchange/types/v2 && \
rm -rf chain/exchange/types/v2/*test.go && rm -rf chain/exchange/types/v2/*gw.go
mkdir -p chain/insurance/types && \
cp injective-core/injective-chain/modules/insurance/types/*.pb.go chain/insurance/types && \
cp injective-core/injective-chain/modules/insurance/types/codec.go chain/insurance/types
Expand Down Expand Up @@ -109,18 +134,41 @@ copy-chain-types: clone-injective-core
cp injective-core/injective-chain/modules/wasmx/types/proposal.go chain/wasmx/types
mkdir -p chain/stream/types && \
cp injective-core/injective-chain/stream/types/*.pb.go chain/stream/types
mkdir -p chain/stream/types/v2 && \
cp injective-core/injective-chain/stream/types/v2/*.pb.go chain/stream/types/v2
mkdir -p chain/types && \
cp injective-core/injective-chain/types/*.pb.go injective-core/injective-chain/types/config.go chain/types && \
cp injective-core/injective-chain/types/chain_id.go chain/types && \
cp injective-core/injective-chain/types/codec.go chain/types && \
cp injective-core/injective-chain/types/util.go chain/types
cp injective-core/injective-chain/types/errors.go chain/types && \
cp injective-core/injective-chain/types/int.go chain/types && \
cp injective-core/injective-chain/types/util.go chain/types && \
cp injective-core/injective-chain/types/validation.go chain/types

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

mkdir -p chain/evm/precompiles/bank && mkdir -p chain/evm/precompiles/exchange && mkdir -p chain/evm/precompiles/staking && \
cp injective-core/injective-chain/modules/evm/precompiles/bindings/cosmos/precompile/bank/*.go chain/evm/precompiles/bank && \
cp injective-core/injective-chain/modules/evm/precompiles/bindings/cosmos/precompile/exchange/*.go chain/evm/precompiles/exchange && \
cp injective-core/injective-chain/modules/evm/precompiles/bindings/cosmos/precompile/staking/*.go chain/evm/precompiles/staking

rm -rf proto
cp -r injective-core/proto ./

rm -rf injective-core
make extract-message-names

extract-message-names:
@echo "Extracting message names from tx.pb.go files..."
@mkdir -p injective_data
@find ./chain -name "tx.pb.go" -exec grep -h "proto\.RegisterType" {} \; | \
sed -n 's/.*proto\.RegisterType([^"]*"\([^"]*\)".*/\1/p' | \
grep -v 'Response$$' | \
sort -u | \
jq -R -s 'split("\n")[:-1]' > injective_data/chain_messages_list.json
@echo "Message names extracted to injective_data/chain_messages_list.json (excluding Response messages)"
@echo "Total messages found: $$(jq length injective_data/chain_messages_list.json)"

#gen: gen-proto
#
Expand Down Expand Up @@ -168,4 +216,8 @@ lint-master: export GOPROXY=direct
lint-master:
golangci-lint run --timeout=15m -v --new-from-rev=master

.PHONY: copy-exchange-client tests coverage lint lint-last-commit lint-master
lint-all: export GOPROXY=direct
lint-all:
golangci-lint run --timeout=15m -v

.PHONY: copy-exchange-client tests coverage lint lint-last-commit lint-master lint-all extract-message-names
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,60 @@ go run examples/exchange/derivatives/4_Orderbook/example.go

---

## Choose Exchange V1 or Exchange V2 queries

The SDK provides two different clients for interacting with the Injective Exchange:

- `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.

- `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.

Example usage:
```go
// For Exchange V1
client := chainclient.NewChainClient(...)

// For Exchange V2
clientV2 := chainclient.NewChainClientV2(...)
```

### Markets Assistant

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:

```go
// For Exchange V1 markets
marketsAssistant, err := chain.NewMarketsAssistant(ctx, client) // ChainClient instance
if err != nil {
// Handle error
}

// For Exchange V2 markets
marketsAssistantV2, err := chain.NewHumanReadableMarketsAssistant(ctx, clientV2) // ChainClientV2 instance
if err != nil {
// Handle error
}
```

The Markets Assistant provides helper methods to:
- Fetch market information
- Get market prices
- Query orderbooks
- Access market statistics

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.

### Format Differences

There are important format differences between V1 and V2 endpoints:

- **Exchange V1**: All values (amounts, prices, margins, notionals) are returned in chain format (raw numbers)
- **Exchange V2**: Most values are returned in human-readable format for better usability:
- Amounts, prices, margins, and notionals are in human-readable format
- Deposit-related information remains in chain format to maintain consistency with the Bank module

This format difference is one of the key improvements in V2, making it easier to work with market data without manual conversion.

## Updating Exchange API proto and client

```bash
Expand Down
23 changes: 15 additions & 8 deletions auth_vote/authz_vote.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"
"time"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authztypes "github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
"github.com/InjectiveLabs/sdk-go/client/common"
)

//revive:disable:function-length // this is an example script
func main() {
network := common.LoadNetwork("testnet", "lb")
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
tmClient, err := rpchttp.New(network.TmEndpoint)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -48,7 +52,7 @@ func main() {
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)

txFactory := chainclient.NewTxFactory(clientCtx)
chainClient, err := chainclient.NewChainClient(
chainClient, err := chainclient.NewChainClientV2(
clientCtx,
network,
common.OptionTxFactory(&txFactory),
Expand All @@ -58,7 +62,10 @@ func main() {
panic(err)
}

gasPrice := chainClient.CurrentChainGasPrice()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

gasPrice := chainClient.CurrentChainGasPrice(ctx)
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
gasPrice = int64(float64(gasPrice) * 1.1)
chainClient.SetGasPrice(gasPrice)
Expand Down Expand Up @@ -92,16 +99,16 @@ func main() {
}

// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
response, err := chainClient.AsyncBroadcastMsg(msgs...)
response, err := chainClient.AsyncBroadcastMsg(ctx, msgs...)

if err != nil {
panic(err)
}

str, _ := json.MarshalIndent(response, "", " ")
str, _ := json.MarshalIndent(response, "", "\t")
fmt.Print(string(str))

gasPrice = chainClient.CurrentChainGasPrice()
gasPrice = chainClient.CurrentChainGasPrice(ctx)
// adjust gas price to make it valid even if it changes between the time it is requested and the TX is broadcasted
gasPrice = int64(float64(gasPrice) * 1.1)
chainClient.SetGasPrice(gasPrice)
Expand Down
Loading
Loading