Skip to content

Commit fa901c7

Browse files
committed
Release of new version
1 parent 7f821a4 commit fa901c7

File tree

50 files changed

+4222
-1680
lines changed

Some content is hidden

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

50 files changed

+4222
-1680
lines changed

client/docs/swagger-ui/swagger.yaml

Lines changed: 2041 additions & 648 deletions
Large diffs are not rendered by default.

injective-chain/app/app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ func (app *InjectiveApp) GetStakingKeeper() *stakingkeeper.Keeper {
870870
return app.StakingKeeper
871871
}
872872

873+
func (app *InjectiveApp) GetAccountKeeper() authante.AccountKeeper {
874+
return app.AccountKeeper
875+
}
876+
873877
// GetTKey returns the TransientStoreKey for the provided store key.
874878
//
875879
// NOTE: This is solely to be used for testing purposes.

injective-chain/app/upgrade.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ import (
1515
v1dot16dot0 "github.com/InjectiveLabs/injective-core/injective-chain/app/upgrades/v1.16.0"
1616
v1dot16b2 "github.com/InjectiveLabs/injective-core/injective-chain/app/upgrades/v1.16.0-beta.2"
1717
v1dot16b3 "github.com/InjectiveLabs/injective-core/injective-chain/app/upgrades/v1.16.0-beta.3"
18+
v1dot16b4 "github.com/InjectiveLabs/injective-core/injective-chain/app/upgrades/v1.16.0-beta.4"
1819
)
1920

2021
var _ upgrades.InjectiveApplication = &InjectiveApp{}
2122

2223
var upgradeNames = []string{
2324
v1dot16b2.UpgradeName,
2425
v1dot16b3.UpgradeName,
26+
v1dot16b4.UpgradeName,
2527
v1dot16dot0.UpgradeName,
2628
}
2729

2830
var upgradeSteps = map[string]UpgradeStepsFn{
2931
v1dot16b2.UpgradeName: v1dot16b2.UpgradeSteps,
3032
v1dot16b3.UpgradeName: v1dot16b3.UpgradeSteps,
33+
v1dot16b4.UpgradeName: v1dot16b4.UpgradeSteps,
3134
v1dot16dot0.UpgradeName: v1dot16dot0.UpgradeSteps,
3235

3336
// NOTE: use NoSteps for upgrades that don't have any migration steps
@@ -36,6 +39,7 @@ var upgradeSteps = map[string]UpgradeStepsFn{
3639
var storeUpgrades = map[string]storetypes.StoreUpgrades{
3740
v1dot16b2.UpgradeName: v1dot16b2.StoreUpgrades(),
3841
v1dot16b3.UpgradeName: v1dot16b3.StoreUpgrades(),
42+
v1dot16b4.UpgradeName: v1dot16b4.StoreUpgrades(),
3943
v1dot16dot0.UpgradeName: v1dot16dot0.StoreUpgrades(),
4044
}
4145

injective-chain/app/upgrades/upgrade_utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
storetypes "cosmossdk.io/store/types"
1010
upgradetypes "cosmossdk.io/x/upgrade/types"
1111
sdk "github.com/cosmos/cosmos-sdk/types"
12+
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
1213
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
1314
"github.com/pkg/errors"
1415

@@ -119,6 +120,7 @@ type InjectiveApplication interface {
119120
GetKey(storeKey string) *storetypes.KVStoreKey
120121
GetPeggyKeeper() *peggykeeper.Keeper
121122
GetStakingKeeper() *stakingkeeper.Keeper
123+
GetAccountKeeper() authante.AccountKeeper
122124
}
123125

124126
func LogUpgradeProgress(logger log.Logger, startTime, lastUpdatedTime time.Time, currentUpdateNumber, totalUpdates int) {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package v1dot16dot0
2+
3+
import (
4+
"cosmossdk.io/errors"
5+
"cosmossdk.io/log"
6+
storetypes "cosmossdk.io/store/types"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
8+
ethcommon "github.com/ethereum/go-ethereum/common"
9+
10+
"github.com/InjectiveLabs/injective-core/injective-chain/app/upgrades"
11+
)
12+
13+
const (
14+
UpgradeName = "v1.16.0-beta.4"
15+
)
16+
17+
func StoreUpgrades() storetypes.StoreUpgrades {
18+
return storetypes.StoreUpgrades{
19+
Added: nil,
20+
Renamed: nil,
21+
Deleted: nil,
22+
}
23+
}
24+
25+
//revive:disable:function-length // This is a long function, but it is not a problem
26+
func UpgradeSteps() []*upgrades.UpgradeHandlerStep {
27+
upgradeSteps := []*upgrades.UpgradeHandlerStep{
28+
upgrades.NewUpgradeHandlerStep(
29+
"RESET CREATE2 PROXY SENDER NONCE",
30+
UpgradeName,
31+
upgrades.TestnetChainID,
32+
ResetCreate2ProxySenderNonce,
33+
),
34+
upgrades.NewUpgradeHandlerStep(
35+
"RESET CREATE2 PROXY SENDER NONCE",
36+
UpgradeName,
37+
upgrades.DevnetChainID,
38+
ResetCreate2ProxySenderNonce,
39+
),
40+
}
41+
42+
return upgradeSteps
43+
}
44+
45+
func ResetCreate2ProxySenderNonce(ctx sdk.Context, app upgrades.InjectiveApplication, logger log.Logger) error {
46+
accountKeeper := app.GetAccountKeeper()
47+
48+
var create2ProxySender = ethcommon.HexToAddress("0x3fab184622dc19b6109349b94811493bf2a45362")
49+
var create2ProxySenderInjAddress = sdk.AccAddress(create2ProxySender.Bytes())
50+
51+
account := accountKeeper.GetAccount(ctx, create2ProxySenderInjAddress)
52+
if account == nil {
53+
logger.Warn(
54+
"ResetCreate2ProxySenderNonce: account not found",
55+
"hex_address", create2ProxySender.Hex(),
56+
"inj_address", create2ProxySenderInjAddress.String(),
57+
)
58+
59+
return nil
60+
}
61+
62+
oldNonce := account.GetSequence()
63+
if err := account.SetSequence(0); err != nil {
64+
return errors.Wrap(err, "failed to reset sequence")
65+
}
66+
67+
logger.Info(
68+
"ResetCreate2ProxySenderNonce: account has nonce reset",
69+
"hex_address", create2ProxySender.Hex(),
70+
"inj_address", create2ProxySenderInjAddress.String(),
71+
"old_nonce", oldNonce,
72+
)
73+
74+
accountKeeper.SetAccount(ctx, account)
75+
return nil
76+
}

injective-chain/modules/auction/types/tx.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

injective-chain/modules/evm/ante/eth_ante.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ func ValidateEthBasic(ctx sdk.Context, tx sdk.Tx, evmParams *evmtypes.Params) er
226226
return errorsmod.Wrap(evmtypes.ErrCallDisabled, "failed to call contract")
227227
}
228228

229-
if tx.Type() == ethtypes.DynamicFeeTxType {
230-
return errorsmod.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported")
231-
}
232-
233229
if !allowUnprotectedTxs && !tx.Protected() {
234230
return errorsmod.Wrapf(
235231
errortypes.ErrNotSupported,

injective-chain/modules/evm/keeper/keeper.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
cosmostracing "github.com/InjectiveLabs/injective-core/injective-chain/modules/evm/tracing"
99

10-
errorsmod "cosmossdk.io/errors"
1110
"cosmossdk.io/log"
1211
storetypes "cosmossdk.io/store/types"
1312
"github.com/cosmos/cosmos-sdk/codec"
@@ -234,29 +233,3 @@ func (k *Keeper) GetEVMDenomBalance(ctx sdk.Context, addr common.Address) *big.I
234233
func (k *Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) *big.Int {
235234
return k.bankKeeper.GetBalance(ctx, addr, denom).Amount.BigInt()
236235
}
237-
238-
// GetTransientGasUsed returns the gas used by current cosmos tx.
239-
func (k Keeper) GetTransientGasUsed(ctx sdk.Context) uint64 {
240-
store := ctx.ObjectStore(k.objectKey)
241-
v := store.Get(types.ObjectGasUsedKey(ctx.TxIndex()))
242-
if v == nil {
243-
return 0
244-
}
245-
return v.(uint64)
246-
}
247-
248-
// SetTransientGasUsed sets the gas used by current cosmos tx.
249-
func (k Keeper) SetTransientGasUsed(ctx sdk.Context, gasUsed uint64) {
250-
store := ctx.ObjectStore(k.objectKey)
251-
store.Set(types.ObjectGasUsedKey(ctx.TxIndex()), gasUsed)
252-
}
253-
254-
// AddTransientGasUsed accumulate gas used by each eth msgs included in current cosmos tx.
255-
func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, error) {
256-
result := k.GetTransientGasUsed(ctx) + gasUsed
257-
if result < gasUsed {
258-
return 0, errorsmod.Wrap(types.ErrGasOverflow, "transient gas used")
259-
}
260-
k.SetTransientGasUsed(ctx, result)
261-
return result, nil
262-
}

injective-chain/modules/evm/keeper/state_transition.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx)
252252
return nil, errorsmod.Wrapf(err, "failed to refund leftover gas to sender %s", msg.From)
253253
}
254254

255-
if _, err = k.AddTransientGasUsed(ctx, res.GasUsed); err != nil {
256-
return nil, errorsmod.Wrap(err, "failed to add transient gas used")
257-
}
258-
259255
// consume gas on the original gas meter
260256
ctx.GasMeter().ConsumeGas(res.GasUsed, "apply evm transaction")
261257

injective-chain/modules/evm/precompiles/exchange/exchange.go

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ const (
6767
)
6868

6969
var (
70-
exchangeABI abi.ABI
71-
exchangeContractAddress = common.BytesToAddress([]byte{101})
72-
exchangeGasRequiredByMethod = map[[4]byte]uint64{}
70+
exchangeABI abi.ABI
71+
exchangeContractAddress = common.BytesToAddress([]byte{101})
7372
)
7473

7574
var (
@@ -80,52 +79,6 @@ func init() {
8079
if err := exchangeABI.UnmarshalJSON([]byte(exchange.ExchangeModuleMetaData.ABI)); err != nil {
8180
panic(err)
8281
}
83-
for methodName := range exchangeABI.Methods {
84-
var methodID [4]byte
85-
copy(methodID[:], exchangeABI.Methods[methodName].ID[:4])
86-
switch methodName {
87-
case ApproveMethodName:
88-
exchangeGasRequiredByMethod[methodID] = 200_000
89-
case RevokeMethodName:
90-
exchangeGasRequiredByMethod[methodID] = 200_000
91-
case DepositMethodName:
92-
exchangeGasRequiredByMethod[methodID] = 200_000
93-
case WithdrawMethodName:
94-
exchangeGasRequiredByMethod[methodID] = 200_000
95-
case SubaccountTransferMethodName:
96-
exchangeGasRequiredByMethod[methodID] = 200_000
97-
case ExternalTransferMethodName:
98-
exchangeGasRequiredByMethod[methodID] = 200_000
99-
case CreateDerivativeLimitOrderMethodName:
100-
exchangeGasRequiredByMethod[methodID] = 200_000
101-
case BatchCreateDerivativeLimitOrdersMethodName:
102-
exchangeGasRequiredByMethod[methodID] = 200_000
103-
case CreateDerivativeMarketOrderMethodName:
104-
exchangeGasRequiredByMethod[methodID] = 200_000
105-
case CancelDerivativeOrderMethodName:
106-
exchangeGasRequiredByMethod[methodID] = 200_000
107-
case BatchCancelDerivativeOrdersMethodName:
108-
exchangeGasRequiredByMethod[methodID] = 200_000
109-
case IncreasePositionMarginMethodName:
110-
exchangeGasRequiredByMethod[methodID] = 200_000
111-
case DecreasePositionMarginMethodName:
112-
exchangeGasRequiredByMethod[methodID] = 200_000
113-
case BatchUpdateOrdersMethodName:
114-
exchangeGasRequiredByMethod[methodID] = 200_000
115-
case CreateSpotLimitOrderMethodName:
116-
exchangeGasRequiredByMethod[methodID] = 200_000
117-
case BatchCreateSpotLimitOrdersMethodName:
118-
exchangeGasRequiredByMethod[methodID] = 200_000
119-
case CreateSpotMarketOrderMethodName:
120-
exchangeGasRequiredByMethod[methodID] = 200_000
121-
case CancelSpotOrderMethodName:
122-
exchangeGasRequiredByMethod[methodID] = 200_000
123-
case BatchCancelSpotOrdersMethodName:
124-
exchangeGasRequiredByMethod[methodID] = 200_000
125-
default:
126-
exchangeGasRequiredByMethod[methodID] = 0
127-
}
128-
}
12982
}
13083

13184
type ExchangeContract struct {
@@ -164,14 +117,88 @@ func (ec *ExchangeContract) RequiredGas(input []byte) uint64 {
164117
}
165118

166119
// base cost to prevent large input size
167-
baseCost := uint64(len(input)) * ec.kvGasConfig.WriteCostPerByte
168-
var methodID [4]byte
169-
copy(methodID[:], input[:4])
170-
requiredGas, ok := exchangeGasRequiredByMethod[methodID]
171-
if ok {
172-
return requiredGas + baseCost
173-
}
174-
return baseCost
120+
cost := uint64(len(input)) * ec.kvGasConfig.WriteCostPerByte
121+
122+
method, err := exchangeABI.MethodById(input[:4])
123+
if err != nil {
124+
return cost
125+
}
126+
127+
args, err := method.Inputs.Unpack(input[4:])
128+
if err != nil {
129+
return cost
130+
}
131+
132+
switch method.Name {
133+
case ApproveMethodName:
134+
cost += 200_000
135+
case RevokeMethodName:
136+
cost += 200_000
137+
case DepositMethodName:
138+
cost += exchangekeeper.MsgDepositGas
139+
case WithdrawMethodName:
140+
cost += exchangekeeper.MsgWithdrawGas
141+
case SubaccountTransferMethodName:
142+
cost += exchangekeeper.MsgSubaccountTransferGas
143+
case ExternalTransferMethodName:
144+
cost += exchangekeeper.MsgExternalTransferGas
145+
case CreateDerivativeLimitOrderMethodName:
146+
cost += exchangekeeper.MsgCreateDerivativeLimitOrderGas
147+
case CreateDerivativeMarketOrderMethodName:
148+
cost += exchangekeeper.MsgCreateDerivativeMarketOrderGas
149+
case CancelDerivativeOrderMethodName:
150+
cost += exchangekeeper.MsgCancelDerivativeOrderGas
151+
case IncreasePositionMarginMethodName:
152+
cost += exchangekeeper.MsgIncreasePositionMarginGas
153+
case DecreasePositionMarginMethodName:
154+
cost += exchangekeeper.MsgDecreasePositionMarginGas
155+
case CreateSpotLimitOrderMethodName:
156+
cost += exchangekeeper.MsgCreateSpotLimitOrderGas
157+
case CreateSpotMarketOrderMethodName:
158+
cost += exchangekeeper.MsgCreateSpotMarketOrderGas
159+
case CancelSpotOrderMethodName:
160+
cost += exchangekeeper.MsgCancelSpotOrderGas
161+
}
162+
163+
switch method.Name {
164+
case BatchCreateDerivativeLimitOrdersMethodName:
165+
_, orders, err := CastCreateDerivativeOrdersParams(method.Inputs, args)
166+
if err != nil {
167+
return cost
168+
}
169+
cost += exchangekeeper.MsgCreateDerivativeLimitOrderGas * uint64(len(orders))
170+
case BatchCancelDerivativeOrdersMethodName:
171+
_, orders, err := CastBatchCancelOrdersParams(method.Inputs, args)
172+
if err != nil {
173+
return cost
174+
}
175+
cost += exchangekeeper.MsgCancelDerivativeOrderGas * uint64(len(orders))
176+
case BatchCreateSpotLimitOrdersMethodName:
177+
_, orders, err := CastCreateSpotOrdersParams(method.Inputs, args)
178+
if err != nil {
179+
return cost
180+
}
181+
cost += exchangekeeper.MsgCreateSpotLimitOrderGas * uint64(len(orders))
182+
case BatchCancelSpotOrdersMethodName:
183+
_, orders, err := CastBatchCancelOrdersParams(method.Inputs, args)
184+
if err != nil {
185+
return cost
186+
}
187+
cost += exchangekeeper.MsgCancelSpotOrderGas * uint64(len(orders))
188+
case BatchUpdateOrdersMethodName:
189+
_, msg, err := CastBatchUpdateOrdersParams(method.Inputs, args)
190+
if err != nil {
191+
return cost
192+
}
193+
cost += uint64(len(msg.DerivativeOrdersToCancel)) * exchangekeeper.MsgCancelDerivativeOrderGas
194+
cost += uint64(len(msg.DerivativeOrdersToCreate)) * exchangekeeper.MsgCreateDerivativeLimitOrderGas
195+
cost += uint64(len(msg.DerivativeMarketIdsToCancelAll)) * exchangekeeper.MsgCancelDerivativeOrderGas
196+
cost += uint64(len(msg.SpotOrdersToCancel)) * exchangekeeper.MsgCancelSpotOrderGas
197+
cost += uint64(len(msg.SpotOrdersToCreate)) * exchangekeeper.MsgCreateSpotLimitOrderGas
198+
cost += uint64(len(msg.SpotMarketIdsToCancelAll)) * 100_000
199+
}
200+
201+
return cost
175202
}
176203

177204
func (ec *ExchangeContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) (output []byte, err error) {

0 commit comments

Comments
 (0)