Skip to content
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

feat/release changes to support chain upgrade v1.12 #199

Merged
merged 47 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b40a48c
feat: add custom network constructor and fix leftovers (#171)
mmeloni Nov 2, 2023
b634832
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
Nov 7, 2023
56a44e9
(fix) Fixed errors generated by the Git merge tool
Nov 7, 2023
c94f736
(feat) Updated proto definitions to the injective-core v1.12.2-testne…
Nov 7, 2023
430d846
(fix) Fixed inconsistencies in go.sum
Nov 7, 2023
10771e6
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
Nov 7, 2023
21d896b
(fix) Fix in derivative trades example
Nov 7, 2023
8c79823
Merge pull request #176 from InjectiveLabs/feat/sync_dev_with_master_…
aarmoa Nov 7, 2023
f5d212f
(feat) Added a new example showing how to broadcast a transaction wit…
Nov 10, 2023
4588233
(fix) Updated BriadcastMsgWithoutSimulation example to use SyncBroadc…
Nov 13, 2023
adab666
Merge pull request #177 from InjectiveLabs/feat/add_example_broadcas_…
aarmoa Nov 13, 2023
ffc9e6e
Merge branch 'master' of https://github.com/InjectiveLabs/sdk-go into…
Nov 17, 2023
9af7919
Merge pull request #179 from InjectiveLabs/feat/synchronize_with_mast…
aarmoa Nov 17, 2023
ba9019b
Feat/add trade v2 indexer endpoints (#187)
aarmoa Dec 9, 2023
b8ee0e7
(feat) Refactored all examples to have the default gas price in a sin…
Dec 11, 2023
f203ea4
(fix) Fixed references to the default gas price
Dec 11, 2023
b672fa1
(fix) Fixed import issue in examples using the default gas price in t…
Dec 11, 2023
7d38d17
Merge branch 'feat/change_default_gas_price' of https://github.com/In…
Dec 11, 2023
a0704ed
(fix) Applied gas price refactoring to the chain stream example script
Dec 11, 2023
0e33b0e
Merge pull request #189 from InjectiveLabs/feat/merge_latest_changes_…
aarmoa Dec 15, 2023
176a0aa
(feat) Implemented the MarketsAssistant to get all markets and tokens…
Dec 15, 2023
88aa2ec
(fix) Refactor example to apply change in default gas price
Dec 15, 2023
77e0e44
(feat) Added new positions and account balance Indexer endpoints
Dec 20, 2023
75e344f
(fix) Fix error in orderbook example
Dec 20, 2023
505179d
Merge pull request #194 from InjectiveLabs/feat/add_new_indexer_posit…
aarmoa Dec 21, 2023
3736b38
(feat) Added configuration for pre-commit. Solved all issues found by…
Dec 21, 2023
4eb212d
(feat) Added GitHub workflow to run pre-commit for PRs and when pushi…
Dec 21, 2023
e8126fe
(fix) Fix pre-commit configuration
Dec 21, 2023
8443d0b
(fix) Fix pre-commit configuration
Dec 21, 2023
bce2da2
(feat) Added GitHub workflow to run tests and calculate coverage
Dec 22, 2023
4170d7f
(feat) Added Codecov badge in README.md
Dec 22, 2023
ed9d10e
Merge pull request #190 from InjectiveLabs/feat/markets_assistant
aarmoa Dec 22, 2023
a170f1f
(feat) Added configuration for pre-commit. Solved all issues found by…
Dec 21, 2023
0afd940
(feat) Added GitHub workflow to run pre-commit for PRs and when pushi…
Dec 21, 2023
af96e92
(fix) Fix pre-commit configuration
Dec 21, 2023
1944258
(fix) Fix pre-commit configuration
Dec 21, 2023
de6e2ac
(feat) Added GitHub workflow to run tests and calculate coverage
Dec 22, 2023
f581f64
(feat) Added Codecov badge in README.md
Dec 22, 2023
1953fda
Merge branch 'feat/activate_validation_workflow' of https://github.co…
Dec 23, 2023
c618b06
Feat/initialize tokens from chain denoms (#197)
aarmoa Dec 30, 2023
227a7c8
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-go into fe…
Jan 1, 2024
6aa890a
(fix) Fixed incorrect numbers in example script module names
Jan 1, 2024
f7516ac
(feat) Added support for all wasm module endpoints. Added also exampl…
Jan 4, 2024
37f558e
Feat/activate validation workflow (#196)
aarmoa Jan 8, 2024
ce0a554
(feat) Added support for token factory module endpoints. Included new…
Jan 8, 2024
ed3c1a5
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-go into fe…
Jan 8, 2024
d10fa53
Merge pull request #198 from InjectiveLabs/feat/add_wasm_and_token_fa…
aarmoa Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: pre-commit
on:
pull_request:
push:
branches: [master, dev]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
- uses: actions/setup-go@v5
with:
go-version: 1.19
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s - -b $(go env GOPATH)/bin v1.49.0
- run: echo "PATH=$PATH:/home/runner/go/bin" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: pre-commit/[email protected]
20 changes: 20 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: run-tests
on:
pull_request:
push:
branches: [ master, dev ]

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version: 1.19
- name: Run test and calculate coverage
run: make coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea/
.chain_cookie
.exchange_cookie
coverage.out
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
exclude: |
(?x)^(
chain/.*|
exchange/.*|
proto/.*
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
- id: go-imports
- id: golangci-lint
args: [--timeout=15m]
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ Copyright © 2020 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ copy-exchange-client:
cp -r ../injective-indexer/api/gen/grpc/injective_derivative_exchange_rpc/pb exchange/derivative_exchange_rpc/pb
cp -r ../injective-indexer/api/gen/grpc/injective_portfolio_rpc/pb exchange/portfolio_rpc/pb

.PHONY: copy-exchange-client
.PHONY: copy-exchange-client tests coverage

copy-chain-types:
cp ../injective-core/injective-chain/types/*.go chain/types
rm -rf chain/types/*test.go rm -rf chain/types/*gw.go
cp ../injective-core/injective-chain/crypto/ethsecp256k1/*.go chain/crypto/ethsecp256k1
rm -rf chain/crypto/ethsecp256k1/*test.go rm -rf chain/crypto/ethsecp256k1/*gw.go
cp ../injective-core/injective-chain/modules/auction/types/*.go chain/auction/types
rm -rf chain/auction/types/*test.go rm -rf chain/auction/types/*gw.go
cp ../injective-core/injective-chain/modules/exchange/types/*.go chain/exchange/types
Expand All @@ -46,6 +48,13 @@ copy-chain-types:
rm -rf chain/wasmx/types/*test.go rm -rf chain/wasmx/types/*gw.go
cp ../injective-core/injective-chain/modules/tokenfactory/types/*.go chain/tokenfactory/types
rm -rf chain/tokenfactory/types/*test.go rm -rf chain/tokenfactory/types/*gw.go
cp ../injective-core/injective-chain/stream/types/*.go chain/stream/types

echo "👉 Replace injective-core/injective-chain/modules with sdk-go/chain"
echo "👉 Replace injective-core/injective-chain/types with sdk-go/chain/types"
echo "👉 Replace injective-core/injective-chain/crypto with sdk-go/chain/crypto"

tests:
go test -race ./client/... ./ethereum/...
coverage:
go test -race -coverprofile=coverage.out -covermode=atomic ./client/... ./ethereum/...
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Copyright © 2020 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
Originally released by Injective Labs Inc. under: <br />
Apache License <br />
Version 2.0, January 2004 <br />
http://www.apache.org/licenses/
http://www.apache.org/licenses/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Injective Protocol Golang SDK 🌟

[![codecov](https://codecov.io/gh/InjectiveLabs/sdk-go/graph/badge.svg?token=XDGZV265EE)](https://codecov.io/gh/InjectiveLabs/sdk-go)

---

## 📚 Getting Started
Expand Down Expand Up @@ -65,4 +67,4 @@ Copyright © 2020 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
Originally released by Injective Labs Inc. under: <br />
Apache License <br />
Version 2.0, January 2004 <br />
http://www.apache.org/licenses/
http://www.apache.org/licenses/
7 changes: 4 additions & 3 deletions chain/auction/types/auction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions chain/auction/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions chain/auction/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions chain/auction/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions chain/crypto/ethsecp256k1/keys.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions chain/exchange/types/authz.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/exchange/types/common_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,11 @@ func (m *OrderType) UnmarshalJSON(data []byte) error {
*m = OrderType(value)
return nil
}

// GetOrderIdentifier returns the cid of an order if it exists, otherwise returns the order hash
func GetOrderIdentifier(orderHash, cid string) any {
if cid != "" {
return cid
}
return common.HexToHash(orderHash)
}
21 changes: 18 additions & 3 deletions chain/exchange/types/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (d *DerivativeLimitOrderDelta) OrderHash() common.Hash {
return d.Order.Hash()
}

func (d *DerivativeLimitOrderDelta) Cid() string {
return d.Order.Cid()
}

var AuctionSubaccountID = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")
var ZeroSubaccountID = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")

Expand Down Expand Up @@ -138,6 +142,11 @@ func IsValidOrderHash(orderHash string) bool {
return IsHexHash(orderHash)
}

func IsValidCid(cid string) bool {
// Arbitrarily setting max length of cid to uuid length
return len(cid) <= 36
}

// IsHexHash verifies whether a string can represent a valid hex-encoded hash or not.
func IsHexHash(s string) bool {
if !isHexString(s) {
Expand Down Expand Up @@ -337,12 +346,18 @@ func HasDuplicatesCoin(slice []sdk.Coin) bool {
}

func HasDuplicatesOrder(slice []*OrderData) bool {
seen := make(map[string]struct{})
seenHashes := make(map[string]struct{})
seenCids := make(map[string]struct{})
for _, item := range slice {
if _, ok := seen[item.OrderHash]; ok {
hash, cid := item.GetOrderHash(), item.GetCid()
_, hashExists := seenHashes[hash]
_, cidExists := seenCids[cid]

if (hash != "" && hashExists) || (cid != "" && cidExists) {
return true
}
seen[item.OrderHash] = struct{}{}
seenHashes[hash] = struct{}{}
seenCids[cid] = struct{}{}
}
return false
}
28 changes: 21 additions & 7 deletions chain/exchange/types/derivative_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import (
"github.com/ethereum/go-ethereum/common"
)

func NewMarketOrderForLiquidation(position *Position, positionSubaccountID common.Hash, liquidator sdk.AccAddress) *DerivativeMarketOrder {
func NewMarketOrderForLiquidation(
position *Position,
positionSubaccountID common.Hash,
liquidator sdk.AccAddress,
worstPrice sdk.Dec,
) *DerivativeMarketOrder {
var (
worstPrice sdk.Dec
orderType OrderType
orderType OrderType
)

// if long position, market sell order at price 0
// if short position, market buy order at price infinity
// if long position, market sell order
// if short position, market buy order
if position.IsLong {
worstPrice = sdk.ZeroDec()
orderType = OrderType_SELL
} else {
worstPrice = MaxOrderPrice
orderType = OrderType_BUY
}

Expand Down Expand Up @@ -447,10 +449,22 @@ func (o *DerivativeLimitOrder) IsConditional() bool {
return o.OrderType.IsConditional()
}

func (o *DerivativeLimitOrder) Cid() string {
return o.OrderInfo.GetCid()
}

func (o *DerivativeMarketOrder) Cid() string {
return o.OrderInfo.GetCid()
}

func (o *DerivativeOrder) SubaccountID() common.Hash {
return o.OrderInfo.SubaccountID()
}

func (o *DerivativeOrder) Cid() string {
return o.OrderInfo.GetCid()
}

func (o *DerivativeOrder) IsFromDefaultSubaccount() bool {
return o.OrderInfo.IsFromDefaultSubaccount()
}
Expand Down
4 changes: 4 additions & 0 deletions chain/exchange/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ var (
ErrTooMuchOrderMargin = errors.Register(ModuleName, 93, "Order has too much margin")
ErrBadSubaccountNonce = errors.Register(ModuleName, 94, "Subaccount nonce is invalid")
ErrInsufficientFunds = errors.Register(ModuleName, 95, "insufficient funds")
ErrPostOnlyMode = errors.Register(ModuleName, 96, "exchange is in post-only mode")
ErrClientOrderIdAlreadyExists = errors.Register(ModuleName, 97, "client order id already exists")
ErrInvalidCid = errors.Register(ModuleName, 98, "client order id is invalid. Max length is 36 chars")
ErrInvalidEmergencySettle = errors.Register(ModuleName, 99, "market cannot be settled in emergency mode")
)
2 changes: 2 additions & 0 deletions chain/exchange/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/ethereum/go-ethereum/common"
)

// Event type and attribute constants

func (e *EventOrderFail) AddOrderFail(orderHash common.Hash, flag uint32) {
e.Hashes = append(e.Hashes, orderHash.Bytes())
e.Flags = append(e.Flags, flag)
Expand Down
7 changes: 4 additions & 3 deletions chain/exchange/types/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions chain/exchange/types/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ func (e ExecutionType) IsTaker() bool {

func (s MarketStatus) SupportsOrderCancellations() bool {
switch s {
case MarketStatus_Active, MarketStatus_Demolished, MarketStatus_Expired:
case MarketStatus_Active, MarketStatus_Demolished, MarketStatus_Expired, MarketStatus_Paused:
return true
case MarketStatus_Paused:
return false
default:
return false
}
Expand Down
Loading
Loading