Skip to content

Commit b0f68ed

Browse files
authored
Merge pull request #199 from InjectiveLabs/dev
feat/release changes to support chain upgrade v1.12
2 parents f196717 + d10fa53 commit b0f68ed

File tree

300 files changed

+44092
-28109
lines changed

Some content is hidden

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

300 files changed

+44092
-28109
lines changed

.github/workflows/pre-commit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pre-commit
2+
on:
3+
pull_request:
4+
push:
5+
branches: [master, dev]
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/setup-python@v4
12+
- uses: actions/setup-go@v5
13+
with:
14+
go-version: 1.19
15+
- run: go install golang.org/x/tools/cmd/goimports@latest
16+
- run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s - -b $(go env GOPATH)/bin v1.49.0
17+
- run: echo "PATH=$PATH:/home/runner/go/bin" >> $GITHUB_ENV
18+
- uses: actions/checkout@v3
19+
- uses: pre-commit/action@v2.0.2

.github/workflows/run-tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: run-tests
2+
on:
3+
pull_request:
4+
push:
5+
branches: [ master, dev ]
6+
7+
jobs:
8+
run-tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 2
14+
- uses: actions/setup-go@v5
15+
with:
16+
go-version: 1.19
17+
- name: Run test and calculate coverage
18+
run: make coverage
19+
- name: Upload coverage to Codecov
20+
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea/
33
.chain_cookie
44
.exchange_cookie
5+
coverage.out

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
exclude: |
2+
(?x)^(
3+
chain/.*|
4+
exchange/.*|
5+
proto/.*
6+
)$
7+
repos:
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.5.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: end-of-file-fixer
14+
- id: check-yaml
15+
- repo: https://github.com/dnephin/pre-commit-golang
16+
rev: v0.5.0
17+
hooks:
18+
- id: go-fmt
19+
- id: go-imports
20+
- id: golangci-lint
21+
args: [--timeout=15m]

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,4 @@ Copyright © 2020 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
200200
distributed under the License is distributed on an "AS IS" BASIS,
201201
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202202
See the License for the specific language governing permissions and
203-
limitations under the License.
203+
limitations under the License.

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ copy-exchange-client:
2424
cp -r ../injective-indexer/api/gen/grpc/injective_derivative_exchange_rpc/pb exchange/derivative_exchange_rpc/pb
2525
cp -r ../injective-indexer/api/gen/grpc/injective_portfolio_rpc/pb exchange/portfolio_rpc/pb
2626

27-
.PHONY: copy-exchange-client
27+
.PHONY: copy-exchange-client tests coverage
2828

2929
copy-chain-types:
3030
cp ../injective-core/injective-chain/types/*.go chain/types
31+
rm -rf chain/types/*test.go rm -rf chain/types/*gw.go
3132
cp ../injective-core/injective-chain/crypto/ethsecp256k1/*.go chain/crypto/ethsecp256k1
33+
rm -rf chain/crypto/ethsecp256k1/*test.go rm -rf chain/crypto/ethsecp256k1/*gw.go
3234
cp ../injective-core/injective-chain/modules/auction/types/*.go chain/auction/types
3335
rm -rf chain/auction/types/*test.go rm -rf chain/auction/types/*gw.go
3436
cp ../injective-core/injective-chain/modules/exchange/types/*.go chain/exchange/types
@@ -46,6 +48,13 @@ copy-chain-types:
4648
rm -rf chain/wasmx/types/*test.go rm -rf chain/wasmx/types/*gw.go
4749
cp ../injective-core/injective-chain/modules/tokenfactory/types/*.go chain/tokenfactory/types
4850
rm -rf chain/tokenfactory/types/*test.go rm -rf chain/tokenfactory/types/*gw.go
51+
cp ../injective-core/injective-chain/stream/types/*.go chain/stream/types
4952

5053
echo "👉 Replace injective-core/injective-chain/modules with sdk-go/chain"
5154
echo "👉 Replace injective-core/injective-chain/types with sdk-go/chain/types"
55+
echo "👉 Replace injective-core/injective-chain/crypto with sdk-go/chain/crypto"
56+
57+
tests:
58+
go test -race ./client/... ./ethereum/...
59+
coverage:
60+
go test -race -coverprofile=coverage.out -covermode=atomic ./client/... ./ethereum/...

NOTICE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Copyright © 2020 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
55
Originally released by Injective Labs Inc. under: <br />
66
Apache License <br />
77
Version 2.0, January 2004 <br />
8-
http://www.apache.org/licenses/
8+
http://www.apache.org/licenses/

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Injective Protocol Golang SDK 🌟
22

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

57
## 📚 Getting Started
@@ -65,4 +67,4 @@ Copyright © 2020 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
6567
Originally released by Injective Labs Inc. under: <br />
6668
Apache License <br />
6769
Version 2.0, January 2004 <br />
68-
http://www.apache.org/licenses/
70+
http://www.apache.org/licenses/

chain/auction/types/auction.pb.go

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

chain/auction/types/genesis.pb.go

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

chain/auction/types/query.pb.go

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

chain/auction/types/tx.pb.go

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

chain/crypto/ethsecp256k1/keys.pb.go

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

chain/exchange/types/authz.pb.go

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

chain/exchange/types/common_order.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,11 @@ func (m *OrderType) UnmarshalJSON(data []byte) error {
186186
*m = OrderType(value)
187187
return nil
188188
}
189+
190+
// GetOrderIdentifier returns the cid of an order if it exists, otherwise returns the order hash
191+
func GetOrderIdentifier(orderHash, cid string) any {
192+
if cid != "" {
193+
return cid
194+
}
195+
return common.HexToHash(orderHash)
196+
}

chain/exchange/types/common_utils.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (d *DerivativeLimitOrderDelta) OrderHash() common.Hash {
7575
return d.Order.Hash()
7676
}
7777

78+
func (d *DerivativeLimitOrderDelta) Cid() string {
79+
return d.Order.Cid()
80+
}
81+
7882
var AuctionSubaccountID = common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")
7983
var ZeroSubaccountID = common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000")
8084

@@ -138,6 +142,11 @@ func IsValidOrderHash(orderHash string) bool {
138142
return IsHexHash(orderHash)
139143
}
140144

145+
func IsValidCid(cid string) bool {
146+
// Arbitrarily setting max length of cid to uuid length
147+
return len(cid) <= 36
148+
}
149+
141150
// IsHexHash verifies whether a string can represent a valid hex-encoded hash or not.
142151
func IsHexHash(s string) bool {
143152
if !isHexString(s) {
@@ -337,12 +346,18 @@ func HasDuplicatesCoin(slice []sdk.Coin) bool {
337346
}
338347

339348
func HasDuplicatesOrder(slice []*OrderData) bool {
340-
seen := make(map[string]struct{})
349+
seenHashes := make(map[string]struct{})
350+
seenCids := make(map[string]struct{})
341351
for _, item := range slice {
342-
if _, ok := seen[item.OrderHash]; ok {
352+
hash, cid := item.GetOrderHash(), item.GetCid()
353+
_, hashExists := seenHashes[hash]
354+
_, cidExists := seenCids[cid]
355+
356+
if (hash != "" && hashExists) || (cid != "" && cidExists) {
343357
return true
344358
}
345-
seen[item.OrderHash] = struct{}{}
359+
seenHashes[hash] = struct{}{}
360+
seenCids[cid] = struct{}{}
346361
}
347362
return false
348363
}

chain/exchange/types/derivative_orders.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import (
66
"github.com/ethereum/go-ethereum/common"
77
)
88

9-
func NewMarketOrderForLiquidation(position *Position, positionSubaccountID common.Hash, liquidator sdk.AccAddress) *DerivativeMarketOrder {
9+
func NewMarketOrderForLiquidation(
10+
position *Position,
11+
positionSubaccountID common.Hash,
12+
liquidator sdk.AccAddress,
13+
worstPrice sdk.Dec,
14+
) *DerivativeMarketOrder {
1015
var (
11-
worstPrice sdk.Dec
12-
orderType OrderType
16+
orderType OrderType
1317
)
1418

15-
// if long position, market sell order at price 0
16-
// if short position, market buy order at price infinity
19+
// if long position, market sell order
20+
// if short position, market buy order
1721
if position.IsLong {
18-
worstPrice = sdk.ZeroDec()
1922
orderType = OrderType_SELL
2023
} else {
21-
worstPrice = MaxOrderPrice
2224
orderType = OrderType_BUY
2325
}
2426

@@ -447,10 +449,22 @@ func (o *DerivativeLimitOrder) IsConditional() bool {
447449
return o.OrderType.IsConditional()
448450
}
449451

452+
func (o *DerivativeLimitOrder) Cid() string {
453+
return o.OrderInfo.GetCid()
454+
}
455+
456+
func (o *DerivativeMarketOrder) Cid() string {
457+
return o.OrderInfo.GetCid()
458+
}
459+
450460
func (o *DerivativeOrder) SubaccountID() common.Hash {
451461
return o.OrderInfo.SubaccountID()
452462
}
453463

464+
func (o *DerivativeOrder) Cid() string {
465+
return o.OrderInfo.GetCid()
466+
}
467+
454468
func (o *DerivativeOrder) IsFromDefaultSubaccount() bool {
455469
return o.OrderInfo.IsFromDefaultSubaccount()
456470
}

chain/exchange/types/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ var (
100100
ErrTooMuchOrderMargin = errors.Register(ModuleName, 93, "Order has too much margin")
101101
ErrBadSubaccountNonce = errors.Register(ModuleName, 94, "Subaccount nonce is invalid")
102102
ErrInsufficientFunds = errors.Register(ModuleName, 95, "insufficient funds")
103+
ErrPostOnlyMode = errors.Register(ModuleName, 96, "exchange is in post-only mode")
104+
ErrClientOrderIdAlreadyExists = errors.Register(ModuleName, 97, "client order id already exists")
105+
ErrInvalidCid = errors.Register(ModuleName, 98, "client order id is invalid. Max length is 36 chars")
106+
ErrInvalidEmergencySettle = errors.Register(ModuleName, 99, "market cannot be settled in emergency mode")
103107
)

chain/exchange/types/events.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"github.com/ethereum/go-ethereum/common"
55
)
66

7+
// Event type and attribute constants
8+
79
func (e *EventOrderFail) AddOrderFail(orderHash common.Hash, flag uint32) {
810
e.Hashes = append(e.Hashes, orderHash.Bytes())
911
e.Flags = append(e.Flags, flag)

chain/exchange/types/events.pb.go

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

chain/exchange/types/exchange.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ func (e ExecutionType) IsTaker() bool {
3636

3737
func (s MarketStatus) SupportsOrderCancellations() bool {
3838
switch s {
39-
case MarketStatus_Active, MarketStatus_Demolished, MarketStatus_Expired:
39+
case MarketStatus_Active, MarketStatus_Demolished, MarketStatus_Expired, MarketStatus_Paused:
4040
return true
41-
case MarketStatus_Paused:
42-
return false
4341
default:
4442
return false
4543
}

0 commit comments

Comments
 (0)