diff --git a/build/go.mod b/build/go.mod index af6fe3ff5..2e46f741f 100644 --- a/build/go.mod +++ b/build/go.mod @@ -28,7 +28,7 @@ replace ( require ( github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240321120602-0a9c50facc68 github.com/CoreumFoundation/coreum/v5 v5.0.0-20241022051641-b49ec5faa621 - github.com/CoreumFoundation/crust v0.0.0-20241023120411-b54970b4922c + github.com/CoreumFoundation/crust v0.0.0-20241029185440-e352dde6f2b2 github.com/iancoleman/strcase v0.3.0 github.com/pkg/errors v0.9.1 github.com/samber/lo v1.39.0 diff --git a/build/go.sum b/build/go.sum index fb47bf3c4..0dfdd31d6 100644 --- a/build/go.sum +++ b/build/go.sum @@ -231,8 +231,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240321120602-0a9c50facc68 h1:Tb9avuSQW3smVGrUnDh/Y+ML4eK802UsvJNZHsBgOGg= github.com/CoreumFoundation/coreum-tools v0.4.1-0.20240321120602-0a9c50facc68/go.mod h1:VD93vCHkxYaT/RhOesXTFgd/GQDW54tr0BqGi5JU1c0= -github.com/CoreumFoundation/crust v0.0.0-20241023120411-b54970b4922c h1:vtNl0+pQ8p6rogxWD4yx+Qp4r9IK8qwyo32Qki21ltg= -github.com/CoreumFoundation/crust v0.0.0-20241023120411-b54970b4922c/go.mod h1:95ZdELt65yNef7qty4vvRBcBgkgw0L0+td2tNa/JKTM= +github.com/CoreumFoundation/crust v0.0.0-20241029185440-e352dde6f2b2 h1:YCaird/0FrYgMAajomVBJ/aClatBcorVi1vAmYNjH2w= +github.com/CoreumFoundation/crust v0.0.0-20241029185440-e352dde6f2b2/go.mod h1:95ZdELt65yNef7qty4vvRBcBgkgw0L0+td2tNa/JKTM= github.com/CosmWasm/wasmd v0.53.0 h1:kdaoAi20bIb4VCsxw9pRaT2g5PpIp82Wqrr9DRVN9ao= github.com/CosmWasm/wasmd v0.53.0/go.mod h1:FJl/aWjdpGof3usAMFQpDe07Rkx77PUzp0cygFMOvtw= github.com/CosmWasm/wasmvm/v2 v2.1.2 h1:GkJ5bAsRlLHfIQVg/FY1VHwLyBwlCjAhDea0B8L+e20= diff --git a/integration-tests/ibc/dex_test.go b/integration-tests/ibc/dex_test.go index 617177ad1..3c1076910 100644 --- a/integration-tests/ibc/dex_test.go +++ b/integration-tests/ibc/dex_test.go @@ -60,11 +60,9 @@ func TestIBCDexLimitOrdersMatching(t *testing.T) { coreumChain.FundAccountWithOptions(ctx, t, coreumSender, integration.BalancesOptions{ Messages: []sdk.Msg{ &ibctransfertypes.MsgTransfer{}, - &dextypes.MsgPlaceOrder{}, - &dextypes.MsgPlaceOrder{}, &ibctransfertypes.MsgTransfer{}, }, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2).AddRaw(200_000), }) denom1 := issueFT(ctx, t, coreumChain, coreumIssuer, sdkmath.NewIntWithDecimal(1, 6), assetfttypes.Feature_ibc) @@ -115,7 +113,7 @@ func TestIBCDexLimitOrdersMatching(t *testing.T) { _, err = client.BroadcastTx( ctx, coreumChain.ClientContext.WithFromAddress(coreumSender), - coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(placeSellOrderMsg)), + coreumChain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.ErrorContains(err, cosmoserrors.ErrInsufficientFunds.Error()) @@ -157,7 +155,7 @@ func TestIBCDexLimitOrdersMatching(t *testing.T) { _, err = client.BroadcastTx( ctx, coreumChain.ClientContext.WithFromAddress(coreumSender), - coreumChain.TxFactory().WithGas(coreumChain.GasLimitByMsgs(placeSellOrderMsg)), + coreumChain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) diff --git a/integration-tests/modules/dex_test.go b/integration-tests/modules/dex_test.go index 61ce0aea9..982066786 100644 --- a/integration-tests/modules/dex_test.go +++ b/integration-tests/modules/dex_test.go @@ -45,18 +45,12 @@ func TestLimitOrdersMatching(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, acc1, sdkmath.NewIntWithDecimal(1, 6)) @@ -74,15 +68,13 @@ func TestLimitOrdersMatching(t *testing.T) { TimeInForce: dextypes.TIME_IN_FORCE_GTC, } - txResult, err := client.BroadcastTx( + _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) - // validate the deterministic gas - requireT.Equal(chain.GasLimitByMsgs(placeSellOrderMsg), uint64(txResult.GasUsed)) sellOrderRes, err := dexClient.Order(ctx, &dextypes.QueryOrderRequest{ Creator: placeSellOrderMsg.Sender, @@ -121,7 +113,7 @@ func TestLimitOrdersMatching(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -185,18 +177,12 @@ func TestMarketOrdersMatching(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, acc1, sdkmath.NewIntWithDecimal(1, 6)) @@ -217,7 +203,7 @@ func TestMarketOrdersMatching(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -236,7 +222,7 @@ func TestMarketOrdersMatching(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -246,12 +232,12 @@ func TestMarketOrdersMatching(t *testing.T) { }) requireT.NoError(err) requireT.Equal( - sdk.NewCoins( - sdk.NewCoin(denom1, sdkmath.NewInt(999900)), - sdk.NewCoin(denom2, sdkmath.NewInt(10)), - dexParamsRes.Params.OrderReserve, - ).String(), - acc1BalancesRes.Balances.String(), + sdkmath.NewInt(999900).String(), + acc1BalancesRes.Balances.AmountOf(denom1).String(), + ) + requireT.Equal( + sdkmath.NewInt(10).String(), + acc1BalancesRes.Balances.AmountOf(denom2).String(), ) acc2BalancesRes, err := bankClient.AllBalances(ctx, &banktypes.QueryAllBalancesRequest{ @@ -259,12 +245,12 @@ func TestMarketOrdersMatching(t *testing.T) { }) requireT.NoError(err) requireT.Equal( - sdk.NewCoins( - sdk.NewCoin(denom1, sdkmath.NewInt(100)), - sdk.NewCoin(denom2, sdkmath.NewInt(999990)), - dexParamsRes.Params.OrderReserve, - ).String(), - acc2BalancesRes.Balances.String(), + sdkmath.NewInt(100).String(), + acc2BalancesRes.Balances.AmountOf(denom1).String(), + ) + requireT.Equal( + sdkmath.NewInt(999990).String(), + acc2BalancesRes.Balances.AmountOf(denom2).String(), ) } @@ -291,10 +277,9 @@ func TestOrderCancellation(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, &dextypes.MsgCancelOrder{}, }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, issuer, sdkmath.NewIntWithDecimal(1, 6)) @@ -343,7 +328,7 @@ func TestOrderCancellation(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -449,10 +434,7 @@ func TestOrderTilBlockHeight(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, acc1, sdkmath.NewIntWithDecimal(1, 6)) @@ -478,7 +460,7 @@ func TestOrderTilBlockHeight(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -522,10 +504,7 @@ func TestOrderTilBlockTime(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, acc1, sdkmath.NewIntWithDecimal(1, 6)) @@ -551,7 +530,7 @@ func TestOrderTilBlockTime(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -623,13 +602,12 @@ func TestOrderBooksAndOrdersQueries(t *testing.T) { } acc1OrderPlaceMsgs := ordersToPlaceMsgs(acc1Orders) chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: acc1OrderPlaceMsgs, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(acc1OrderPlaceMsgs...)), + chain.TxFactoryAuto(), acc1OrderPlaceMsgs..., ) requireT.NoError(err) @@ -670,13 +648,12 @@ func TestOrderBooksAndOrdersQueries(t *testing.T) { } acc2OrderPlaceMsgs := ordersToPlaceMsgs(acc2Orders) chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: acc2OrderPlaceMsgs, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(int64(len(acc2OrderPlaceMsgs))), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(int64(len(acc2OrderPlaceMsgs))).AddRaw(100_000), }) _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(acc2OrderPlaceMsgs...)), + chain.TxFactoryAuto(), acc2OrderPlaceMsgs..., ) requireT.NoError(err) @@ -795,19 +772,12 @@ func TestLimitOrdersMatchingWithAssetFTFreeze(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2).Add(sdkmath.NewInt(100_000).MulRaw(2)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, issuer, sdkmath.NewIntWithDecimal(1, 6), assetfttypes.Feature_freezing) @@ -866,7 +836,7 @@ func TestLimitOrdersMatchingWithAssetFTFreeze(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.ErrorContains(err, assetfttypes.ErrDEXLockFailed.Error()) @@ -916,7 +886,7 @@ func TestLimitOrdersMatchingWithAssetFTFreeze(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -968,7 +938,7 @@ func TestLimitOrdersMatchingWithAssetFTFreeze(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -1014,19 +984,12 @@ func TestLimitOrdersMatchingWithAssetFTGloballyFreeze(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2).Add(sdkmath.NewInt(100_000).MulRaw(2)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) denom1 := issueFT(ctx, t, chain, issuer, sdkmath.NewIntWithDecimal(1, 6), assetfttypes.Feature_freezing) @@ -1084,7 +1047,7 @@ func TestLimitOrdersMatchingWithAssetFTGloballyFreeze(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.ErrorContains(err, assetfttypes.ErrDEXLockFailed.Error()) @@ -1133,7 +1096,7 @@ func TestLimitOrdersMatchingWithAssetFTGloballyFreeze(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -1184,7 +1147,7 @@ func TestLimitOrdersMatchingWithAssetFTGloballyFreeze(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -1231,11 +1194,9 @@ func TestLimitOrdersMatchingWithAssetClawback(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - &dextypes.MsgPlaceOrder{}, &dextypes.MsgCancelOrder{}, }, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2).Add(sdkmath.NewInt(100_000).MulRaw(2)), }) denom1 := issueFT(ctx, t, chain, issuer, sdkmath.NewIntWithDecimal(1, 6), assetfttypes.Feature_clawback) @@ -1294,7 +1255,7 @@ func TestLimitOrdersMatchingWithAssetClawback(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.ErrorContains(err, cosmoserrors.ErrInsufficientFunds.Error()) @@ -1346,7 +1307,7 @@ func TestLimitOrdersMatchingWithAssetClawback(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -1441,15 +1402,14 @@ func TestLimitOrdersMatchingWithStaking(t *testing.T) { customStakingParams, err := customParamsClient.StakingParams(ctx, &customparamstypes.QueryStakingParamsRequest{}) require.NoError(t, err) - delegateAmount := sdkmath.NewInt(1000) + delegateAmount := sdkmath.NewInt(1_000_000) acc := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc, integration.BalancesOptions{ Messages: []sdk.Msg{ &stakingtypes.MsgDelegate{}, - &dextypes.MsgPlaceOrder{}, }, - Amount: delegateAmount.Add(dexParamsRes.Params.OrderReserve.Amount), + Amount: delegateAmount.Add(dexParamsRes.Params.OrderReserve.Amount).Add(sdkmath.NewInt(100_000)), }) denomToStake := chain.ChainSettings.Denom @@ -1497,22 +1457,19 @@ func TestLimitOrdersMatchingWithStaking(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.ErrorContains(err, assetfttypes.ErrDEXLockFailed.Error()) chain.FundAccountWithOptions(ctx, t, acc, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, // fund one more time since we paid for the failed message - }, - Amount: delegateAmount, + Amount: delegateAmount.Add(sdkmath.NewInt(100_000)), }) _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -1522,9 +1479,8 @@ func TestLimitOrdersMatchingWithStaking(t *testing.T) { Denom: denomToStake, }) requireT.NoError(err) - requireT.Equal( - delegateAmount.Add(dexParamsRes.Params.OrderReserve.Amount).String(), - balanceRes.Balance.String(), + requireT.True( + delegateAmount.Add(dexParamsRes.Params.OrderReserve.Amount).LTE(balanceRes.Balance), ) requireT.Equal( delegateAmount.Add(dexParamsRes.Params.OrderReserve.Amount).String(), @@ -1547,18 +1503,12 @@ func TestLimitOrdersMatchingWithBurnRate(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ @@ -1608,7 +1558,7 @@ func TestLimitOrdersMatchingWithBurnRate(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -1658,7 +1608,7 @@ func TestLimitOrdersMatchingWithBurnRate(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -1702,18 +1652,12 @@ func TestLimitOrdersMatchingWithCommissionRate(t *testing.T) { acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ @@ -1763,7 +1707,7 @@ func TestLimitOrdersMatchingWithCommissionRate(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -1813,7 +1757,7 @@ func TestLimitOrdersMatchingWithCommissionRate(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -1862,26 +1806,18 @@ func TestLimitOrdersMatchingWithAssetFTWhitelist(t *testing.T) { &assetfttypes.MsgSetWhitelistedLimit{}, &banktypes.MsgSend{}, &assetfttypes.MsgSetWhitelistedLimit{}, - &dextypes.MsgPlaceOrder{}, }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) acc1 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount, + Amount: dexParamsRes.Params.OrderReserve.Amount.Add(sdkmath.NewInt(100_000)), }) acc2 := chain.GenAccount() chain.FundAccountWithOptions(ctx, t, acc2, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - &dextypes.MsgPlaceOrder{}, - }, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(2).Add(sdkmath.NewInt(100_000).MulRaw(2)), }) denom1 := issueFT(ctx, t, chain, issuer, sdkmath.NewIntWithDecimal(1, 6), assetfttypes.Feature_whitelisting) @@ -1941,7 +1877,7 @@ func TestLimitOrdersMatchingWithAssetFTWhitelist(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.ErrorContains(err, assetfttypes.ErrWhitelistedLimitExceeded.Error()) @@ -1983,7 +1919,7 @@ func TestLimitOrdersMatchingWithAssetFTWhitelist(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc2), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeBuyOrderMsg)), + chain.TxFactoryAuto(), placeBuyOrderMsg, ) requireT.NoError(err) @@ -2026,7 +1962,7 @@ func TestLimitOrdersMatchingWithAssetFTWhitelist(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -2061,7 +1997,7 @@ func TestLimitOrdersMatchingWithAssetFTWhitelist(t *testing.T) { _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(issuer), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeSellOrderMsg)), + chain.TxFactoryAuto(), placeSellOrderMsg, ) requireT.NoError(err) @@ -2117,8 +2053,7 @@ func TestCancelOrdersByDenom(t *testing.T) { } }) chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: placeMsgs, - Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(int64(len(placeMsgs))), + Amount: dexParamsRes.Params.OrderReserve.Amount.MulRaw(int64(len(placeMsgs))).AddRaw(100_000 * int64(ordersCount)), }) // send required tokens to acc1 diff --git a/integration-tests/stress/dex_test.go b/integration-tests/stress/dex_test.go index 3971b2a0d..8d6e57924 100644 --- a/integration-tests/stress/dex_test.go +++ b/integration-tests/stress/dex_test.go @@ -5,7 +5,6 @@ import ( "time" sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/samber/lo" @@ -13,9 +12,7 @@ import ( integrationtests "github.com/CoreumFoundation/coreum/v5/integration-tests" "github.com/CoreumFoundation/coreum/v5/pkg/client" - "github.com/CoreumFoundation/coreum/v5/testutil/event" "github.com/CoreumFoundation/coreum/v5/testutil/integration" - deterministicgastypes "github.com/CoreumFoundation/coreum/v5/x/deterministicgas/types" dextypes "github.com/CoreumFoundation/coreum/v5/x/dex/types" ) @@ -27,6 +24,7 @@ func TestLimitOrdersStressMatching(t *testing.T) { preCreatedOrdersCreator := "devcore1fnrehr95flfgnzjcatv7a8hpernwufpd5zjm2v" baseDenom := "dexsu-" + preCreatedOrdersCreator // created VIA the genesis quoteDenom := chain.ChainSettings.Denom + ordersCount := 2_000 requireT := require.New(t) dexClient := dextypes.NewQueryClient(chain.ClientContext) @@ -41,7 +39,7 @@ func TestLimitOrdersStressMatching(t *testing.T) { }, }) requireT.NoError(err) - requireT.Len(creatorOrdersRes.Orders, 10_000) + requireT.Len(creatorOrdersRes.Orders, ordersCount) sellTotal := sdkmath.ZeroInt() for _, order := range creatorOrdersRes.Orders { @@ -59,10 +57,8 @@ func TestLimitOrdersStressMatching(t *testing.T) { acc1 := chain.GenAccount() buyTotal := sellTotal + chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ - Messages: []sdk.Msg{ - &dextypes.MsgPlaceOrder{}, - }, Amount: dexParamsRes.Params.OrderReserve.Amount.Add(buyTotal), }) @@ -84,12 +80,28 @@ func TestLimitOrdersStressMatching(t *testing.T) { Side: dextypes.SIDE_BUY, TimeInForce: dextypes.TIME_IN_FORCE_GTC, } + + _, requiredGas, err := client.CalculateGas( + ctx, + chain.ClientContext.WithFromAddress(acc1), + chain.TxFactory(), + placeOrderMsg, + ) + requireT.NoError(err) + t.Logf("Estimated gas: %d", requiredGas) + usedGas := uint64(float64(requiredGas) * 1.05) + t.Logf("Used gas: %d", usedGas) + + chain.FundAccountWithOptions(ctx, t, acc1, integration.BalancesOptions{ + NondeterministicMessagesGas: usedGas, + }) + t.Logf("Placing order to match %d orders", len(creatorOrdersRes.Orders)) now := time.Now() - txRes, err := client.BroadcastTx( + _, err = client.BroadcastTx( ctx, chain.ClientContext.WithFromAddress(acc1), - chain.TxFactory().WithGas(chain.GasLimitByMsgs(placeOrderMsg)), + chain.TxFactory().WithGas(usedGas), placeOrderMsg, ) requireT.NoError(err) @@ -112,10 +124,4 @@ func TestLimitOrdersStressMatching(t *testing.T) { }) requireT.NoError(err) requireT.Equal(buyTotal.String(), baseDenomBalanceRes.Balance.Amount.String()) - - gasEvts, err := event.FindTypedEvents[*deterministicgastypes.EventGas](txRes.Events) - requireT.NoError(err) - requireT.Len(gasEvts, 1) - - t.Logf("RealGas: %d, deterministicGas: %d", gasEvts[0].RealGas, gasEvts[0].DeterministicGas) } diff --git a/x/deterministicgas/config.go b/x/deterministicgas/config.go index bfd3fd404..90004c42c 100644 --- a/x/deterministicgas/config.go +++ b/x/deterministicgas/config.go @@ -47,7 +47,7 @@ const ( NFTMintBaseGas = 39_000 NFTUpdateBaseGas = 40_000 GrantBaseGas = 25000 - DEXUpdateWhitelistedDenomBaseGas = 50_000 + DEXUpdateWhitelistedDenomBaseGas = 10_000 DEXWhitelistedPerDenomGas = 10_000 ) @@ -97,7 +97,7 @@ func DefaultConfig() Config { // TODO(v5): Once we add a new token upgrade MsgUpgradeTokenV2 we should remove this one and re-estimate gas. MsgToMsgURL(&assetfttypes.MsgUpgradeTokenV1{}): constantGasFunc(25_000), MsgToMsgURL(&assetfttypes.MsgUpdateDEXUnifiedRefAmount{}): constantGasFunc(10_000), - MsgToMsgURL(&assetfttypes.MsgUpdateDEXWhitelistedDenoms{}): bankUpdateDEXWhitelistedDenomsGasFunc( + MsgToMsgURL(&assetfttypes.MsgUpdateDEXWhitelistedDenoms{}): updateDEXWhitelistedDenomsGasFunc( DEXUpdateWhitelistedDenomBaseGas, DEXWhitelistedPerDenomGas, ), @@ -116,9 +116,7 @@ func DefaultConfig() Config { MsgToMsgURL(&assetnfttypes.MsgRemoveFromClassWhitelist{}): constantGasFunc(3_500), // dex - // TODO (dex): update with new values once we finish the DEX - MsgToMsgURL(&dextypes.MsgPlaceOrder{}): constantGasFunc(120_000), - MsgToMsgURL(&dextypes.MsgCancelOrder{}): constantGasFunc(15_000), + MsgToMsgURL(&dextypes.MsgCancelOrder{}): constantGasFunc(35_000), // authz MsgToMsgURL(&authz.MsgGrant{}): authzMsgGrantGasFunc(GrantBaseGas, storeConfig.WriteCostPerByte), @@ -237,6 +235,7 @@ func DefaultConfig() Config { // dex &dextypes.MsgUpdateParams{}, + &dextypes.MsgPlaceOrder{}, &dextypes.MsgCancelOrdersByDenom{}, // distribution @@ -490,7 +489,7 @@ func bankMultiSendMsgGasFunc(bankMultiSendPerOperationGas uint64) gasByMsgFunc { } } -func bankUpdateDEXWhitelistedDenomsGasFunc( +func updateDEXWhitelistedDenomsGasFunc( dexUpdateWhitelistedDenomBaseGas, dexWhitelistedPerDenomGas uint64, ) gasByMsgFunc { diff --git a/x/deterministicgas/config_test.go b/x/deterministicgas/config_test.go index 9ebc06d2e..90177fd74 100644 --- a/x/deterministicgas/config_test.go +++ b/x/deterministicgas/config_test.go @@ -107,8 +107,8 @@ func TestDeterministicGas_DeterministicMessages(t *testing.T) { // To make sure we do not increase/decrease deterministic and extension types accidentally, // we assert length to be equal to exact number, so each change requires // explicit adjustment of tests. - assert.Equal(t, 83, nondeterministicMsgCount) - assert.Equal(t, 71, deterministicMsgCount) + assert.Equal(t, 84, nondeterministicMsgCount) + assert.Equal(t, 70, deterministicMsgCount) assert.Equal(t, 14, extensionMsgCount) assert.Equal(t, 140, nonExtensionMsgCount) } diff --git a/x/deterministicgas/spec/README.md b/x/deterministicgas/spec/README.md index ca332016e..aa6dc8827 100644 --- a/x/deterministicgas/spec/README.md +++ b/x/deterministicgas/spec/README.md @@ -118,8 +118,7 @@ It should also be mentioned that this rule applies for all the messages inside ` | `/coreum.asset.nft.v1.MsgRemoveFromClassWhitelist` | 3500 | | `/coreum.asset.nft.v1.MsgRemoveFromWhitelist` | 3500 | | `/coreum.asset.nft.v1.MsgUnfreeze` | 5000 | -| `/coreum.dex.v1.MsgCancelOrder` | 15000 | -| `/coreum.dex.v1.MsgPlaceOrder` | 120000 | +| `/coreum.dex.v1.MsgCancelOrder` | 35000 | | `/cosmos.authz.v1beta1.MsgRevoke` | 8000 | | `/cosmos.distribution.v1beta1.MsgDepositValidatorRewardsPool` | 39000 | | `/cosmos.distribution.v1beta1.MsgFundCommunityPool` | 17000 | @@ -207,7 +206,7 @@ and the formula for them is `DeterministicGasForMsg = DEXUpdateWhitelistedDenomBaseGas + DEXWhitelistedPerDenomGas * NumberOfDenom` `DEXWhitelistedPerDenomGas` is currently equal to `10000`. -`DEXUpdateWhitelistedDenomBaseGas` is currently equal to `50000`. +`DEXUpdateWhitelistedDenomBaseGas` is currently equal to `10000`. ### Nondeterministic messages @@ -217,6 +216,7 @@ and the formula for them is | `/coreum.asset.nft.v1.MsgUpdateParams` | | `/coreum.customparams.v1.MsgUpdateStakingParams` | | `/coreum.dex.v1.MsgCancelOrdersByDenom` | +| `/coreum.dex.v1.MsgPlaceOrder` | | `/coreum.dex.v1.MsgUpdateParams` | | `/coreum.feemodel.v1.MsgUpdateParams` | | `/cosmos.auth.v1beta1.MsgUpdateParams` | diff --git a/x/deterministicgas/types/gas.go b/x/deterministicgas/types/gas.go index ea4ac33c7..99da562e4 100644 --- a/x/deterministicgas/types/gas.go +++ b/x/deterministicgas/types/gas.go @@ -23,15 +23,13 @@ import ( testutilconstant "github.com/CoreumFoundation/coreum/v5/testutil/constant" assetfttypes "github.com/CoreumFoundation/coreum/v5/x/asset/ft/types" "github.com/CoreumFoundation/coreum/v5/x/deterministicgas" - dextypes "github.com/CoreumFoundation/coreum/v5/x/dex/types" ) const ( - defaultFuseGasMultiplier = uint64(10) - dexOrderPlacementFuseGasMultiplier = uint64(5_000) - simFuseGasMultiplier = 1000 - expectedMaxGasFactor = 5 - untrackedMaxGasForQueries = uint64(5_000) + fuseGasMultiplier = 10 + simFuseGasMultiplier = 1000 + expectedMaxGasFactor = 5 + untrackedMaxGasForQueries = uint64(5_000) ) // NewDeterministicMsgServer returns wrapped message server charging deterministic amount of gas for @@ -169,15 +167,7 @@ func (s deterministicMsgServer) ctxForDeterministicGas( // We pass much higher amount of gas to handler to be sure that it succeeds. // We want to avoid passing infinite gas meter to always have a limit in case of mistake. - var gasMultiplier uint64 - // use custom fuse gas multiplier for some messages - switch msg.(type) { - case *dextypes.MsgPlaceOrder: - gasMultiplier = dexOrderPlacementFuseGasMultiplier - default: - gasMultiplier = defaultFuseGasMultiplier - } - + gasMultiplier := uint64(fuseGasMultiplier) if ctx.ChainID() == testutilconstant.SimAppChainID { // simulation fuse gas multiplier is different since during the simulation the modules uses the assetft denom // for the cases which are possible for the simulation only and require more gas @@ -254,7 +244,7 @@ func hasExtensionCall(ctx sdk.Context, msg sdk.Msg, assetFTKeeper AssetFTKeeper) for _, coin := range coins { // we should not count the used for this query, otherwise it will mess up the gas // requirements of the message with deterministic gas. - ctxWithUntrackedGas := ctx.WithGasMeter(storetypes.NewGasMeter(defaultFuseGasMultiplier * untrackedMaxGasForQueries)) + ctxWithUntrackedGas := ctx.WithGasMeter(storetypes.NewGasMeter(fuseGasMultiplier * untrackedMaxGasForQueries)) def, err := assetFTKeeper.GetDefinition(ctxWithUntrackedGas, coin.Denom) if assetfttypes.ErrInvalidDenom.Is(err) || assetfttypes.ErrTokenNotFound.Is(err) { // if the token is not defined in asset ft module, we assume this is different diff --git a/x/dex/types/price.go b/x/dex/types/price.go index e3298bcfc..ac08c125c 100644 --- a/x/dex/types/price.go +++ b/x/dex/types/price.go @@ -35,9 +35,7 @@ const ( orderedBytesPriceSize = store.Int8OrderedBytesSize + store.Uint64OrderedBytesSize ) -var ( - priceRegex = regexp.MustCompile(`^(([1-9])|([1-9]\d*[1-9]))(e-?[1-9]\d*)?$`) -) +var priceRegex = regexp.MustCompile(`^(([1-9])|([1-9]\d*[1-9]))(e-?[1-9]\d*)?$`) // Price is the price type. type Price struct {