Skip to content

Commit 00efb6b

Browse files
authored
Merge pull request #369 from InjectiveLabs/chore/release-v1.20.1
2 parents 62400a7 + cd4446f commit 00efb6b

14 files changed

Lines changed: 734 additions & 332 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.exchange_cookie
66
coverage.out
77
.env
8+
.cache

Makefile

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

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

99
copy-exchange-client: clone-injective-indexer
1010
rm -rf exchange/*

chain/exchange/types/authz_exchange_generic.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,24 @@ func (a GenericExchangeAuthorization) MsgTypeURL() string {
115115
}
116116

117117
// Accept implements Authorization.Accept.
118-
func (a GenericExchangeAuthorization) Accept(ctx context.Context, msg sdk.Msg) (authz.AcceptResponse, error) {
119-
// SpendLimit is optional, so we only check it if it is set
120-
if a.SpendLimit != nil {
121-
hold, ok := getHold(ctx)
122-
if !ok {
118+
func (a GenericExchangeAuthorization) Accept(ctx context.Context, _ sdk.Msg) (authz.AcceptResponse, error) {
119+
hold, _ := getHold(ctx)
120+
121+
if a.SpendLimit.IsZero() && !hold.IsZero() { // on an exhausted grant only allow zero hold messages (like cancellations) (BB-225)
122+
return authz.AcceptResponse{Accept: false}, nil
123+
}
124+
125+
limit := a.SpendLimit
126+
for _, coin := range hold {
127+
allowance := limit.AmountOf(coin.Denom)
128+
if allowance.LT(coin.Amount) {
123129
return authz.AcceptResponse{Accept: false}, nil
124130
}
125131

126-
for _, coin := range hold {
127-
allowed := a.SpendLimit.AmountOf(coin.Denom)
128-
if allowed.LT(coin.Amount) {
129-
return authz.AcceptResponse{Accept: false}, nil
130-
}
131-
a.SpendLimit = a.SpendLimit.Sub(sdk.NewCoin(coin.Denom, coin.Amount))
132-
}
132+
limit = limit.Sub(sdk.NewCoin(coin.Denom, coin.Amount))
133133
}
134-
return authz.AcceptResponse{Accept: true, Updated: &a}, nil
134+
135+
return authz.AcceptResponse{Accept: true, Updated: NewGenericExchangeAuthorization(a.Msg, limit)}, nil
135136
}
136137

137138
// getHold returns the hold from the context. Hold is the amount of coins that

chain/exchange/types/v2/authz_exchange_generic.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,9 @@ func (a GenericExchangeAuthorization) MsgTypeURL() string {
108108
// the incoming message type, and it would not have been created if the
109109
// message type was not allowed.
110110
func (a GenericExchangeAuthorization) Accept(ctx context.Context, _ sdk.Msg) (authz.AcceptResponse, error) {
111-
if noLimit := a.SpendLimit == nil; noLimit {
112-
return authz.AcceptResponse{Accept: true, Updated: NewGenericExchangeAuthorization(a.Msg, nil)}, nil
113-
}
111+
hold, _ := getHold(ctx)
114112

115-
hold, ok := getHold(ctx)
116-
if !ok {
113+
if a.SpendLimit.IsZero() && !hold.IsZero() { // on an exhausted grant only allow zero hold messages (like cancellations) (BB-225)
117114
return authz.AcceptResponse{Accept: false}, nil
118115
}
119116

chain/exchange/types/v2/derivative_orders.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,21 @@ func (m *DerivativeLimitOrder) GetCancelDepositDelta(feeRate math.LegacyDec) *v1
201201
func (m *DerivativeLimitOrder) GetCancelRefundAmount(feeRate math.LegacyDec) math.LegacyDec {
202202
marginHoldRefund := math.LegacyZeroDec()
203203
if m.IsVanilla() {
204+
if !m.OrderInfo.Quantity.IsPositive() {
205+
// Malformed legacy state can have no usable denominator; only release
206+
// margin when there is remaining fillable quantity to cancel.
207+
if !m.Fillable.IsPositive() {
208+
return marginHoldRefund
209+
}
210+
return m.Margin
211+
}
212+
204213
// negative fees are only accounted for upon matching
205-
//nolint:all
206214
// Refund = (FillableQuantity / Quantity) * (Margin + Price * Quantity * feeRate)
207-
marginHoldRefund = m.Fillable.Mul(m.GetMarginHold(feeRate)).Quo(m.OrderInfo.Quantity)
215+
positiveFeeRatePart := math.LegacyMaxDec(feeRate, math.LegacyZeroDec())
216+
marginRefund := m.Fillable.Mul(m.Margin).Quo(m.OrderInfo.Quantity)
217+
feeRefund := m.Fillable.Mul(m.OrderInfo.Price).Mul(positiveFeeRatePart)
218+
marginHoldRefund = marginRefund.Add(feeRefund)
208219
}
209220
return marginHoldRefund
210221
}

chain/peggy/types/msgs.pb.go

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

chain/peggy/types/rate_limit.pb.go

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

client/chain/context.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import (
88
"cosmossdk.io/x/tx/signing"
99
upgradetypes "cosmossdk.io/x/upgrade/types"
1010
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
11-
hyperlaneinterchainsecuritytypes "github.com/bcp-innovations/hyperlane-cosmos/x/core/01_interchain_security/types"
12-
hyperlanepostdispatchtypes "github.com/bcp-innovations/hyperlane-cosmos/x/core/02_post_dispatch/types"
13-
hyperlanecoretypes "github.com/bcp-innovations/hyperlane-cosmos/x/core/types"
14-
hyperlanewarptypes "github.com/bcp-innovations/hyperlane-cosmos/x/warp/types"
11+
probabilistic "github.com/cardano-foundation/cardano-ibc-incubator/cosmos/cardano-probabilistic-light-client-v8"
1512
"github.com/cosmos/cosmos-sdk/client"
1613
"github.com/cosmos/cosmos-sdk/codec"
1714
"github.com/cosmos/cosmos-sdk/codec/address"
@@ -186,10 +183,9 @@ func createInjectiveProtoCodec() (injectiveCodec *codec.ProtoCodec, interfaceReg
186183
ibcclienttypes.RegisterInterfaces(interfaceRegistry)
187184
ibcconnectiontypes.RegisterInterfaces(interfaceRegistry)
188185
ibctransfertypes.RegisterInterfaces(interfaceRegistry)
189-
hyperlanecoretypes.RegisterInterfaces(interfaceRegistry)
190-
hyperlanewarptypes.RegisterInterfaces(interfaceRegistry)
191-
hyperlanepostdispatchtypes.RegisterInterfaces(interfaceRegistry)
192-
hyperlaneinterchainsecuritytypes.RegisterInterfaces(interfaceRegistry)
186+
evmtypes.RegisterInterfaces(interfaceRegistry)
187+
erc20types.RegisterInterfaces(interfaceRegistry)
188+
probabilistic.RegisterInterfaces(interfaceRegistry)
193189

194190
injectiveCodec = codec.NewProtoCodec(interfaceRegistry)
195191

0 commit comments

Comments
 (0)