From 9c81308be48a61932cc8659305a09f110b37d1e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:19:23 +0100 Subject: [PATCH 01/11] build(deps): Bump github.com/CosmWasm/wasmvm from 1.5.0 to 1.5.1 (#2386) Bumps [github.com/CosmWasm/wasmvm](https://github.com/CosmWasm/wasmvm) from 1.5.0 to 1.5.1. - [Release notes](https://github.com/CosmWasm/wasmvm/releases) - [Changelog](https://github.com/CosmWasm/wasmvm/blob/main/CHANGELOG.md) - [Commits](https://github.com/CosmWasm/wasmvm/compare/v1.5.0...v1.5.1) --- updated-dependencies: - dependency-name: github.com/CosmWasm/wasmvm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0ab30ad185..e8d7e30db5 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( cosmossdk.io/math v1.2.0 cosmossdk.io/tools/rosetta v0.2.1 github.com/CosmWasm/wasmd v0.43.0 - github.com/CosmWasm/wasmvm v1.5.0 + github.com/CosmWasm/wasmvm v1.5.1 github.com/cometbft/cometbft v0.37.4 github.com/cometbft/cometbft-db v0.9.1 github.com/cosmos/cosmos-proto v1.0.0-beta.2 // NOTE: v1.0.0-beta.2+ is not compatible with sdk v0.47 diff --git a/go.sum b/go.sum index e97aca2345..2b25b4d154 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,8 @@ github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRr github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/CosmWasm/wasmd v0.43.0 h1:4xQAiNf6Ej+TuYe4PXwrtVJ9C+xyFrbsdqHH/kU9Vxk= github.com/CosmWasm/wasmd v0.43.0/go.mod h1:gpri8YvkRErBz+qDme5jOThGZmSlHfyN532bWibXOl4= -github.com/CosmWasm/wasmvm v1.5.0 h1:3hKeT9SfwfLhxTGKH3vXaKFzBz1yuvP8SlfwfQXbQfw= -github.com/CosmWasm/wasmvm v1.5.0/go.mod h1:fXB+m2gyh4v9839zlIXdMZGeLAxqUdYdFQqYsTha2hc= +github.com/CosmWasm/wasmvm v1.5.1 h1:2MHN9uFyHP6pxfvpBJ0JW6ujvAIBk9kQk283zyri0Ro= +github.com/CosmWasm/wasmvm v1.5.1/go.mod h1:fXB+m2gyh4v9839zlIXdMZGeLAxqUdYdFQqYsTha2hc= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= From 4ada8f56c55474f8b1f94b8645fd4914723ebd62 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:11:39 +0100 Subject: [PATCH 02/11] build(deps): Bump cosmossdk.io/errors from 1.0.0 to 1.0.1 (#2387) Bumps [cosmossdk.io/errors](https://github.com/cosmos/cosmos-sdk) from 1.0.0 to 1.0.1. - [Release notes](https://github.com/cosmos/cosmos-sdk/releases) - [Changelog](https://github.com/cosmos/cosmos-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/cosmos/cosmos-sdk/compare/log/v1.0.0...math/v1.0.1) --- updated-dependencies: - dependency-name: cosmossdk.io/errors dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index e8d7e30db5..a5a8539963 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( cosmossdk.io/api v0.3.1 - cosmossdk.io/errors v1.0.0 + cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.2.0 cosmossdk.io/tools/rosetta v0.2.1 github.com/CosmWasm/wasmd v0.43.0 @@ -32,7 +32,7 @@ require ( github.com/spf13/viper v1.16.0 // must be v1.16.0 otherwise it will update golang.org/x/exp to new version v0.0.0-20230905200255-921286631fa9 github.com/stretchr/testify v1.8.4 golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // must be v0.0.0-20230711153332-06a737ee72cb for gogoproto v1.4.10 - google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 + google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f google.golang.org/grpc v1.60.1 google.golang.org/protobuf v1.32.0 gopkg.in/yaml.v3 v3.0.1 @@ -333,8 +333,8 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.153.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect + google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect honnef.co/go/tools v0.4.6 // indirect diff --git a/go.sum b/go.sum index 2b25b4d154..492ee535ca 100644 --- a/go.sum +++ b/go.sum @@ -198,8 +198,8 @@ cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI= cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= -cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04= -cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0= +cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= +cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk= cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4= cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig= @@ -2205,12 +2205,12 @@ google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e/go.mod h1:3526vdqw google.golang.org/genproto v0.0.0-20221014173430-6e2ab493f96b/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM= google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM= google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy1+IPwWHZUzoD0IccYZIrXILAQpc+Qy9CMhY= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 h1:JpwMPBpFN3uKhdaekDpiNlImDdkUAyiJ6ez/uxGaUSo= -google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc= +google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 h1:1hfbdAfFbkmpg41000wDVqr7jUpK/Yo+LPnIxxGzmkg= +google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3/go.mod h1:5RBcpGRxr25RbDzY5w+dmaqpSEvl8Gwl1x2CICf60ic= +google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f h1:2yNACc1O40tTnrsbk9Cv6oxiW8pxI/pXj0wRtdlYmgY= +google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f/go.mod h1:Uy9bTZJqmfrw2rIBxgGLnamc78euZULUBrLZ9XTITKI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 h1:/jFB8jK5R3Sq3i/lmeZO0cATSzFfZaJq1J2Euan3XKU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0/go.mod h1:FUoWkonphQm3RhTS+kOEhF8h0iDpm4tdXolVCeZ9KKA= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= From ee125f6f582a6c66384ac1012c3316a034325a20 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 15 Jan 2024 09:01:29 +0100 Subject: [PATCH 03/11] fix(sdkclient): bring back the acc sequence setting fix 2 (#2384) * fix(sdkclient): bing back the acc sequence setting fix * add tests * try fix * print sequence number * fix * update error messages * add sleep between leverage txs * reduce the sleep time * change to 1s --- client/client.go | 4 ++++ sdkclient/tx/client.go | 19 ++++++++++++++++--- sdkclient/tx/client_test.go | 16 ++++++++++++++++ tests/e2e/e2e_ibc_test.go | 3 +-- tests/e2e/e2e_leverage_test.go | 9 +++++++++ tests/e2e/setup/utils.go | 17 ++++++++++------- 6 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 sdkclient/tx/client_test.go diff --git a/client/client.go b/client/client.go index b2c8c8f06f..24c0338c9b 100644 --- a/client/client.go +++ b/client/client.go @@ -36,6 +36,10 @@ func NewClient( }, nil } +func (c Client) IncAccSeq() { + c.Client.Tx.IncAccSeq() +} + func (c Client) SetAccSeq(seq uint64) { c.Client.Tx.SetAccSeq(seq) } diff --git a/sdkclient/tx/client.go b/sdkclient/tx/client.go index 8a68b7c03f..068823a889 100644 --- a/sdkclient/tx/client.go +++ b/sdkclient/tx/client.go @@ -125,6 +125,7 @@ func (c *Client) initTxFactory() { c.txFactory = &f } +// Broadcasts transaction. On success, increments the client sequence number. func (c *Client) BroadcastTx(idx int, msgs ...sdk.Msg) (*sdk.TxResponse, error) { var err error r := c.keyringRecord[idx] @@ -135,12 +136,24 @@ func (c *Client) BroadcastTx(idx int, msgs ...sdk.Msg) (*sdk.TxResponse, error) c.logger.Fatalln("can't get keyring record, idx=", idx, err) } f := c.txFactory.WithFromName(r.Name) - return BroadcastTx(cctx, f, msgs...) + resp, err := BroadcastTx(cctx, f, msgs...) + if err == nil { + c.SetAccSeq(0) + // c.IncAccSeq() + } + return resp, err +} + +func (c *Client) GetAccSeq() uint64 { + return c.txFactory.Sequence() +} + +func (c *Client) IncAccSeq() { + c.SetAccSeq(c.txFactory.Sequence() + 1) } func (c *Client) SetAccSeq(seq uint64) { - // *c.txFactory = c.txFactory.WithSequence(seq) - c.txFactory.WithSequence(seq) + *c.txFactory = c.txFactory.WithSequence(seq) } func (c *Client) WithAsyncBlock() *Client { diff --git a/sdkclient/tx/client_test.go b/sdkclient/tx/client_test.go new file mode 100644 index 0000000000..a4cc2f9cff --- /dev/null +++ b/sdkclient/tx/client_test.go @@ -0,0 +1,16 @@ +package tx + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/stretchr/testify/assert" +) + +func TestClientSetters(t *testing.T) { + f := tx.Factory{}.WithSequence(2) + + c := Client{txFactory: &f} + c.SetAccSeq(30) + assert.Equal(t, 30, int(c.txFactory.Sequence())) +} diff --git a/tests/e2e/e2e_ibc_test.go b/tests/e2e/e2e_ibc_test.go index f41ca7bcac..c790f1ca12 100644 --- a/tests/e2e/e2e_ibc_test.go +++ b/tests/e2e/e2e_ibc_test.go @@ -199,9 +199,9 @@ func (s *E2ETest) TestIBCTokenTransfer() { return false } if amount.IsZero() { - s.T().Logf("quota is reset : %s is 0", appparams.BondDenom) return true } + s.T().Logf("quota didn't reset yet, outflows: %s", amount) return false }, 4*time.Minute, @@ -219,7 +219,6 @@ func (s *E2ETest) TestIBCTokenTransfer() { s.AccountClient(0), uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_DISABLED, ) - if err == nil { break } diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 26b38229f3..7ded5561d3 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -1,6 +1,8 @@ package e2e import ( + "time" + sdk "github.com/cosmos/cosmos-sdk/types" appparams "github.com/umee-network/umee/v6/app/params" @@ -105,21 +107,28 @@ func (s *E2ETest) TestLeverageBasics() { // valAddr, err := s.Chain.Validators[0].KeyInfo.GetAddress() // s.Require().NoError(err) + // TODO: check the blocks, rather than waiting arbitrary number of seconds + // next tests depnds on the previous one, and we need to wait for the block. + sleepTime := time.Millisecond * 1000 // 1.1s + // s.Run( "initial leverage supply", func() { s.leverageSupply(0, appparams.BondDenom, 100_000_000) }, ) + time.Sleep(sleepTime) s.Run( "initial leverage withdraw", func() { s.leverageWithdraw(0, "u/"+appparams.BondDenom, 10_000_000) }, ) + time.Sleep(sleepTime) s.Run( "initial leverage collateralize", func() { s.leverageCollateralize(0, "u/"+appparams.BondDenom, 80_000_000) }, ) + time.Sleep(sleepTime) s.Run( "initial leverage borrow", func() { s.leverageBorrow(0, appparams.BondDenom, 12_000_000) diff --git a/tests/e2e/setup/utils.go b/tests/e2e/setup/utils.go index 2cee614f78..87b6580aea 100644 --- a/tests/e2e/setup/utils.go +++ b/tests/e2e/setup/utils.go @@ -56,8 +56,10 @@ func (s *E2ETestSuite) Delegate(testAccount, valIndex int, amount uint64) error } func (s *E2ETestSuite) SendIBC(srcChainID, dstChainID, recipient string, token sdk.Coin, failDueToQuota bool, desc string) { - s.T().Logf("sending %s from %s to %s (exceed quota: %t) %s", token, srcChainID, dstChainID, failDueToQuota, desc) - // ibctransfertypes.NewMsgTransfer() + if failDueToQuota { + s.T().Logf("sending %s from %s to %s (exceed quota: %v) %s", + token, srcChainID, dstChainID, failDueToQuota, desc) + } ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -301,17 +303,18 @@ func (s *E2ETestSuite) BroadcastTxWithRetry(msg sdk.Msg, cli client.Client) erro return nil } - if err != nil && !strings.Contains(err.Error(), "incorrect account sequence") { + errStr := err.Error() + if err != nil && !strings.Contains(errStr, "incorrect account sequence") { return err } // if we were told an expected account sequence, we should use it next time re := regexp.MustCompile(`expected [\d]+`) - n, err := strconv.Atoi(strings.TrimPrefix(re.FindString(err.Error()), "expected ")) - if err != nil { - return err + n, errParse := strconv.Atoi(strings.TrimPrefix(re.FindString(errStr), "expected ")) + if errParse != nil { + return fmt.Errorf("can't find expected acc number: %s [%w]", errParse, err) } - s.T().Log("expected sequence numbern", n) + s.T().Log("expected sequence number:", n, ", got:", cli.Tx.GetAccSeq()) cli.SetAccSeq(uint64(n)) time.Sleep(time.Millisecond * 300) From 08653078e6e6c5f7ca5d0c6b431a3cbc3cf1e5a2 Mon Sep 17 00:00:00 2001 From: kosegor <30661385+kosegor@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:23:09 -0300 Subject: [PATCH 04/11] test: add disable supply to leverage for meToken index scenario (#2389) * add disable supply to leverage scenario * fix imports * Update x/metoken/keeper/intest/reserves_test.go --------- Co-authored-by: Robert Zaremba --- x/metoken/keeper/intest/reserves_test.go | 67 +++++++++++++++++++++--- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/x/metoken/keeper/intest/reserves_test.go b/x/metoken/keeper/intest/reserves_test.go index b07e4e3a62..f47ad074cd 100644 --- a/x/metoken/keeper/intest/reserves_test.go +++ b/x/metoken/keeper/intest/reserves_test.go @@ -2,11 +2,12 @@ package intest import ( "testing" - - "github.com/stretchr/testify/require" + "time" sdkmath "cosmossdk.io/math" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" "github.com/umee-network/umee/v6/app" "github.com/umee-network/umee/v6/util/checkers" @@ -65,7 +66,7 @@ func TestRebalanceReserves(t *testing.T) { k := app.MetokenKeeperB.Keeper(&ctx) // check the initial balances are balanced - checkBalances(t, ctx, app, k, index.Denom, true) + checkBalances(t, ctx, app, k, index.Denom, true, true) // change index setting modifying the reserve_portion // usdt_reserve_portion from 0.2 to 0.25 @@ -100,13 +101,62 @@ func TestRebalanceReserves(t *testing.T) { require.NoError(t, err) // confirm now the balances are unbalanced - checkBalances(t, ctx, app, k, index.Denom, false) + checkBalances(t, ctx, app, k, index.Denom, false, true) err = k.RebalanceReserves() require.NoError(t, err) // confirm the balances are good now - checkBalances(t, ctx, app, k, index.Denom, true) + checkBalances(t, ctx, app, k, index.Denom, true, true) + + // change index setting modifying the reserve_portion + // usdt_reserve_portion from 0.25 to 1.0 + usdtReservePortion = sdk.MustNewDecFromStr("1.0") + usdtSettings, i = index.AcceptedAsset(mocks.USDTBaseDenom) + require.True(t, i >= 0) + usdtSettings.ReservePortion = usdtReservePortion + index.SetAcceptedAsset(usdtSettings) + + // usdc_reserve_portion from 0.5 to 1.0 + usdcReservePortion = sdk.MustNewDecFromStr("1.0") + usdcSettings, i = index.AcceptedAsset(mocks.USDCBaseDenom) + require.True(t, i >= 0) + usdcSettings.ReservePortion = usdcReservePortion + index.SetAcceptedAsset(usdcSettings) + + // ist_reserve_portion from 0.035 to 1.0 + istReservePortion = sdk.MustNewDecFromStr("1.0") + istSettings, i = index.AcceptedAsset(mocks.ISTBaseDenom) + require.True(t, i >= 0) + istSettings.ReservePortion = istReservePortion + index.SetAcceptedAsset(istSettings) + + // update index + _, err = msgServer.GovUpdateRegistry( + ctx, &metoken.MsgGovUpdateRegistry{ + Authority: checkers.GovModuleAddr, + AddIndex: nil, + UpdateIndex: []metoken.Index{index}, + }, + ) + require.NoError(t, err) + + // confirm now the balances are unbalanced + checkBalances(t, ctx, app, k, index.Denom, false, true) + + // move ctx to match rebalance time + futureCtx := app.NewContext( + false, tmproto.Header{ + ChainID: ctx.ChainID(), + Height: ctx.BlockHeight(), + }, + ).WithBlockTime(time.Now().Add(24 * time.Hour)) + + err = app.MetokenKeeperB.Keeper(&futureCtx).RebalanceReserves() + require.NoError(t, err) + + // confirm the balances are good now + checkBalances(t, ctx, app, k, index.Denom, true, false) } func checkBalances( @@ -116,6 +166,7 @@ func checkBalances( k keeper.Keeper, meTokenDenom string, shouldBeBalanced bool, + supplyToLeverageAllowed bool, ) { meTokenAddr := keeper.ModuleAddr() // get index @@ -142,8 +193,10 @@ func checkBalances( require.NoError(t, err) found, assetSupplied := allSupplied.Find(balance.Denom) - require.True(t, found) - require.True(t, assetSupplied.Amount.Equal(balance.Leveraged)) + require.Equal(t, supplyToLeverageAllowed, found) + if supplyToLeverageAllowed { + require.True(t, assetSupplied.Amount.Equal(balance.Leveraged)) + } // confirm balance in x/bank and x/module state is the same found, bBalance := bankBalance.Find(balance.Denom) From 85de508bd8019f639a9627453953bd02a83fa324 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:17:58 +0530 Subject: [PATCH 05/11] build(deps): Bump DavidAnson/markdownlint-cli2-action from 14 to 15 (#2395) Bumps [DavidAnson/markdownlint-cli2-action](https://github.com/davidanson/markdownlint-cli2-action) from 14 to 15. - [Release notes](https://github.com/davidanson/markdownlint-cli2-action/releases) - [Commits](https://github.com/davidanson/markdownlint-cli2-action/compare/v14...v15) --- updated-dependencies: - dependency-name: DavidAnson/markdownlint-cli2-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 264405081d..387cf2878f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -45,7 +45,7 @@ jobs: with: files: "**/*.md" separator: "," - - uses: DavidAnson/markdownlint-cli2-action@v14 + - uses: DavidAnson/markdownlint-cli2-action@v15 if: steps.changed-files.outputs.any_changed == 'true' with: globs: ${{ steps.changed-files.outputs.all_changed_files }} From b0973431910b92713b8d5a8d363758b8f676e4c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 03:49:52 +0000 Subject: [PATCH 06/11] build(deps): Bump tj-actions/changed-files from 41 to 42 (#2394) Bumps [tj-actions/changed-files](https://github.com/tj-actions/changed-files) from 41 to 42. - [Release notes](https://github.com/tj-actions/changed-files/releases) - [Changelog](https://github.com/tj-actions/changed-files/blob/main/HISTORY.md) - [Commits](https://github.com/tj-actions/changed-files/compare/v41...v42) --- updated-dependencies: - dependency-name: tj-actions/changed-files dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 387cf2878f..6b640e0208 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -40,7 +40,7 @@ jobs: with: fetch-depth: 0 # lint only changed files - - uses: tj-actions/changed-files@v41 + - uses: tj-actions/changed-files@v42 id: changed-files with: files: "**/*.md" From 7db052b2416acb2fb1387ce55d4eeff115e1a7a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 03:51:31 +0000 Subject: [PATCH 07/11] build(deps): Bump actions/dependency-review-action from 3 to 4 (#2393) Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 3 to 4. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sai Kumar <17549398+gsk967@users.noreply.github.com> --- .github/workflows/dependencies-review.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependencies-review.yml b/.github/workflows/dependencies-review.yml index 2abc615212..bb64c115ff 100644 --- a/.github/workflows/dependencies-review.yml +++ b/.github/workflows/dependencies-review.yml @@ -15,4 +15,4 @@ jobs: - name: "Checkout Repository" uses: actions/checkout@v4 - name: "Dependency Review" - uses: actions/dependency-review-action@v3 + uses: actions/dependency-review-action@v4 From 00578a657f15c326f739636660b00e4dd1e2a541 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:23:51 +0530 Subject: [PATCH 08/11] build(deps): Bump actions/cache from 3 to 4 (#2391) Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sai Kumar <17549398+gsk967@users.noreply.github.com> --- .github/workflows/simulations.yml | 8 ++++---- .github/workflows/tests.yml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/simulations.yml b/.github/workflows/simulations.yml index afd258da9c..d7af927852 100644 --- a/.github/workflows/simulations.yml +++ b/.github/workflows/simulations.yml @@ -19,7 +19,7 @@ jobs: - name: Install runsim run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/go/bin key: ${{ runner.os }}-go-runsim-binary @@ -67,7 +67,7 @@ jobs: with: go-version: "1.21" cache: true - - uses: actions/cache@v3 + - uses: actions/cache@v4 if: env.GIT_DIFF with: path: ~/go/bin @@ -97,7 +97,7 @@ jobs: with: go-version: "1.21" cache: true - - uses: actions/cache@v3 + - uses: actions/cache@v4 if: env.GIT_DIFF with: path: ~/go/bin @@ -126,7 +126,7 @@ jobs: with: go-version: "1.21" cache: true - - uses: actions/cache@v3 + - uses: actions/cache@v4 if: env.GIT_DIFF with: path: ~/go/bin diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 380be0cff0..048d8f8e29 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version: "1.21" - - uses: actions/cache@v3 + - uses: actions/cache@v4 id: cache-go-tparse with: path: ~/go/bin @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@v4 - name: Cache binaries id: cache-binaries - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ./cmd/umeed/umeed key: umeed-${{ matrix.targetos }}-${{ matrix.arch }} @@ -136,7 +136,7 @@ jobs: - name: Cache updated version binary id: cache-binaries - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ./cmd/umeed/umeed key: umeed-linux-amd64 From 9b33e3679dd25f7139b69be1f66741fea5bf606e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:27:34 +0000 Subject: [PATCH 09/11] build(deps): Bump github.com/CosmWasm/wasmvm from 1.5.1 to 1.5.2 (#2392) Bumps [github.com/CosmWasm/wasmvm](https://github.com/CosmWasm/wasmvm) from 1.5.1 to 1.5.2. - [Release notes](https://github.com/CosmWasm/wasmvm/releases) - [Changelog](https://github.com/CosmWasm/wasmvm/blob/main/CHANGELOG.md) - [Commits](https://github.com/CosmWasm/wasmvm/compare/v1.5.1...v1.5.2) --- updated-dependencies: - dependency-name: github.com/CosmWasm/wasmvm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Robert Zaremba --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a5a8539963..5838db3782 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( cosmossdk.io/math v1.2.0 cosmossdk.io/tools/rosetta v0.2.1 github.com/CosmWasm/wasmd v0.43.0 - github.com/CosmWasm/wasmvm v1.5.1 + github.com/CosmWasm/wasmvm v1.5.2 github.com/cometbft/cometbft v0.37.4 github.com/cometbft/cometbft-db v0.9.1 github.com/cosmos/cosmos-proto v1.0.0-beta.2 // NOTE: v1.0.0-beta.2+ is not compatible with sdk v0.47 diff --git a/go.sum b/go.sum index 492ee535ca..006f869662 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,8 @@ github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRr github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/CosmWasm/wasmd v0.43.0 h1:4xQAiNf6Ej+TuYe4PXwrtVJ9C+xyFrbsdqHH/kU9Vxk= github.com/CosmWasm/wasmd v0.43.0/go.mod h1:gpri8YvkRErBz+qDme5jOThGZmSlHfyN532bWibXOl4= -github.com/CosmWasm/wasmvm v1.5.1 h1:2MHN9uFyHP6pxfvpBJ0JW6ujvAIBk9kQk283zyri0Ro= -github.com/CosmWasm/wasmvm v1.5.1/go.mod h1:fXB+m2gyh4v9839zlIXdMZGeLAxqUdYdFQqYsTha2hc= +github.com/CosmWasm/wasmvm v1.5.2 h1:+pKB1Mz9GZVt1vadxB+EDdD1FOz3dMNjIKq/58/lrag= +github.com/CosmWasm/wasmvm v1.5.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= From 45f10a1f088f8be1a3182f6b15b29d01089b5362 Mon Sep 17 00:00:00 2001 From: Udit Gulati <85029005+udit-gulati@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:25:20 +0530 Subject: [PATCH 10/11] feat: add packet forward middleware (#2381) * feat: add packet forward middleware * fix linter error * tests and sims passing now --- app/app.go | 57 +++++++++++++++++++++++++++++++++++++++++++----------- go.mod | 2 ++ go.sum | 4 ++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index ebe7ff3536..ee5f9cb8ca 100644 --- a/app/app.go +++ b/app/app.go @@ -101,6 +101,9 @@ import ( upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward" + packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" @@ -203,6 +206,7 @@ func init() { wasm.AppModuleBasic{}, incentivemodule.AppModuleBasic{}, metokenmodule.AppModuleBasic{}, + packetforward.AppModuleBasic{}, } // if Experimental {} @@ -269,15 +273,16 @@ type UmeeApp struct { NFTKeeper nftkeeper.Keeper WasmKeeper wasmkeeper.Keeper - IBCTransferKeeper ibctransferkeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - ICAHostKeeper icahostkeeper.Keeper - LeverageKeeper leveragekeeper.Keeper - IncentiveKeeper incentivekeeper.Keeper - OracleKeeper oraclekeeper.Keeper - UIbcQuotaKeeperB uibcquota.KeeperBuilder - UGovKeeperB ugovkeeper.Builder - MetokenKeeperB metokenkeeper.Builder + IBCTransferKeeper ibctransferkeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + PacketForwardKeeper *packetforwardkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper + LeverageKeeper leveragekeeper.Keeper + IncentiveKeeper incentivekeeper.Keeper + OracleKeeper oraclekeeper.Keeper + UIbcQuotaKeeperB uibcquota.KeeperBuilder + UGovKeeperB ugovkeeper.Builder + MetokenKeeperB metokenkeeper.Builder // make scoped keepers public for testing purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -338,7 +343,7 @@ func New( evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, icahosttypes.StoreKey, - leveragetypes.StoreKey, oracletypes.StoreKey, + leveragetypes.StoreKey, oracletypes.StoreKey, packetforwardtypes.StoreKey, uibc.StoreKey, ugov.StoreKey, wasmtypes.StoreKey, incentive.StoreKey, @@ -559,11 +564,15 @@ func New( * SendPacket, originates from the application to an IBC channel: transferKeeper.SendPacket -> uibcquota.SendPacket -> channel.SendPacket * RecvPacket, message that originates from an IBC channel and goes down to app, the flow is the other way - channel.RecvPacket -> uibcquota.OnRecvPacket -> transfer.OnRecvPacket + channel.RecvPacket -> uibcquota.OnRecvPacket -> forward.OnRecvPacket -> transfer.OnRecvPacket + + * Note that the forward middleware is only integrated on the "receive" direction. + It can be safely skipped when sending. * transfer stack contains (from top to bottom): - Umee IBC Transfer - IBC Rate Limit Middleware + - Packet Forward Middleware **********/ quotaICS4 := uics20.NewICS4(app.IBCKeeper.ChannelKeeper, app.UIbcQuotaKeeperB) @@ -577,10 +586,30 @@ func New( app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper, ) + // Packet Forward Middleware + // Initialize packet forward middleware router + app.PacketForwardKeeper = packetforwardkeeper.NewKeeper( + appCodec, + keys[packetforwardtypes.StoreKey], + app.IBCTransferKeeper, + app.IBCKeeper.ChannelKeeper, + app.DistrKeeper, + app.BankKeeper, + quotaICS4, // ISC4 Wrapper: fee IBC middleware + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + // create IBC module from bottom to top of stack var transferStack ibcporttypes.IBCModule transferStack = ibctransfer.NewIBCModule(app.IBCTransferKeeper) // transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper) + transferStack = packetforward.NewIBCMiddleware( + transferStack, + app.PacketForwardKeeper, + 0, // retries on timeout + packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout + packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout + ) transferStack = uics20.NewICS20Module(transferStack, appCodec, app.UIbcQuotaKeeperB, leveragekeeper.NewMsgServerImpl(app.LeverageKeeper)) @@ -712,6 +741,7 @@ func New( leverage.NewAppModule(appCodec, app.LeverageKeeper, app.AccountKeeper, app.BankKeeper), oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper), uibcmodule.NewAppModule(appCodec, app.UIbcQuotaKeeperB), + packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)), ugovmodule.NewAppModule(appCodec, app.UGovKeeperB), wasm.NewAppModule(app.appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), //nolint: lll incentivemodule.NewAppModule(appCodec, app.IncentiveKeeper, app.BankKeeper, app.LeverageKeeper), @@ -752,6 +782,7 @@ func New( metoken.ModuleName, oracletypes.ModuleName, uibc.ModuleName, + packetforwardtypes.ModuleName, ugov.ModuleName, wasmtypes.ModuleName, incentive.ModuleName, @@ -770,6 +801,7 @@ func New( icatypes.ModuleName, // ibcfeetypes.ModuleName, leveragetypes.ModuleName, uibc.ModuleName, + packetforwardtypes.ModuleName, ugov.ModuleName, wasmtypes.ModuleName, incentive.ModuleName, @@ -793,6 +825,7 @@ func New( oracletypes.ModuleName, leveragetypes.ModuleName, uibc.ModuleName, + packetforwardtypes.ModuleName, ugov.ModuleName, wasmtypes.ModuleName, incentive.ModuleName, @@ -809,6 +842,7 @@ func New( oracletypes.ModuleName, leveragetypes.ModuleName, uibc.ModuleName, + packetforwardtypes.ModuleName, ugov.ModuleName, wasmtypes.ModuleName, incentive.ModuleName, @@ -1138,6 +1172,7 @@ func initParamsKeeper( paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) paramsKeeper.Subspace(leveragetypes.ModuleName) paramsKeeper.Subspace(oracletypes.ModuleName) paramsKeeper.Subspace(wasmtypes.ModuleName) diff --git a/go.mod b/go.mod index 5838db3782..c85399f112 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/cosmos/cosmos-sdk v0.47.8-0.20231226160248-5d406c19b204 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.4.10 // NOTE: v1.4.11+ is not compatible with sdk v0.47 + github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1 github.com/cosmos/ibc-go/v7 v7.3.1 github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/mock v1.6.0 @@ -197,6 +198,7 @@ require ( github.com/hdevalence/ed25519consensus v0.1.0 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect github.com/huandu/skiplist v1.2.0 // indirect + github.com/iancoleman/orderedmap v0.2.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index 006f869662..f3b40f4f21 100644 --- a/go.sum +++ b/go.sum @@ -475,6 +475,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= +github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1 h1:PqIK9vTr6zxCdQmrDZwxwL4KMAqg/GRGsiMEiaMP4wA= +github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1/go.mod h1:UvDmcGIWJPIytq+Q78/ff5NTOsuX/7IrNgEugTW5i0s= github.com/cosmos/ibc-go/v7 v7.3.1 h1:bil1IjnHdyWDASFYKfwdRiNtFP6WK3osW7QFEAgU4I8= github.com/cosmos/ibc-go/v7 v7.3.1/go.mod h1:wvx4pPBofe5ZdMNV3OFRxSI4auEP5Qfqf8JXLLNV04g= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= @@ -954,6 +956,8 @@ github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXM github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y= github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= +github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA= +github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= From 631eefe4a8cbaa3af82fecd8234a0fb1ea8a65c3 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 19 Jan 2024 16:38:17 +0100 Subject: [PATCH 11/11] feat(ics20_module): check sender address (#2396) * feat(ics20_module): check sender address * add tests * add ftdata check * lint * lint * Update x/oracle/keeper/grpc_query.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix lint --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .golangci.yml | 2 +- util/genmap/genmap_test.go | 1 - x/oracle/keeper/grpc_query.go | 4 +- x/uibc/mocks/leverage_noop.go | 76 ++++++++++++++++++++++++++ x/uibc/quota/grpc_query.go | 3 +- x/uibc/quota/params.go | 1 - x/uibc/quota/quota.go | 1 - x/uibc/uics20/ibc_module.go | 35 +++++++++--- x/uibc/uics20/ics4_module_int_test.go | 8 ++- x/uibc/uics20/ics4_module_memo_test.go | 48 ++++++++++++++++ 10 files changed, 161 insertions(+), 18 deletions(-) create mode 100644 x/uibc/mocks/leverage_noop.go create mode 100644 x/uibc/uics20/ics4_module_memo_test.go diff --git a/.golangci.yml b/.golangci.yml index 1f542c6c9a..a5442d8097 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -97,4 +97,4 @@ linters-settings: - name: unreachable-code - name: unused-parameter - name: var-declaration - - name: var-naming \ No newline at end of file + - name: var-naming diff --git a/util/genmap/genmap_test.go b/util/genmap/genmap_test.go index 9ca484d4ff..53b557b3ab 100644 --- a/util/genmap/genmap_test.go +++ b/util/genmap/genmap_test.go @@ -42,5 +42,4 @@ func TestMapToSlice(t *testing.T) { m = map[string]int{} ls = MapValues(m) assert.DeepEqual(t, []int{}, ls) - } diff --git a/x/oracle/keeper/grpc_query.go b/x/oracle/keeper/grpc_query.go index 06f2d4b690..fe3e206b16 100644 --- a/x/oracle/keeper/grpc_query.go +++ b/x/oracle/keeper/grpc_query.go @@ -364,8 +364,8 @@ func (q querier) ExgRatesWithTimestamp( } // MissCounters implements types.QueryServer. -func (q querier) MissCounters(goCtx context.Context, req *types.QueryMissCounters) (*types.QueryMissCountersResponse, - error) { +func (q querier) MissCounters(goCtx context.Context, req *types.QueryMissCounters, +) (*types.QueryMissCountersResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) var pfMissCounts []types.PriceMissCounter diff --git a/x/uibc/mocks/leverage_noop.go b/x/uibc/mocks/leverage_noop.go new file mode 100644 index 0000000000..96304a856e --- /dev/null +++ b/x/uibc/mocks/leverage_noop.go @@ -0,0 +1,76 @@ +package mocks + +import ( + "context" + + ltypes "github.com/umee-network/umee/v6/x/leverage/types" +) + +type lvgNoop struct{} + +func NewLvgNoopMsgSrv() ltypes.MsgServer { + return lvgNoop{} +} + +func (l lvgNoop) Supply(context.Context, *ltypes.MsgSupply) (*ltypes.MsgSupplyResponse, error) { + return nil, nil +} + +func (l lvgNoop) Withdraw(context.Context, *ltypes.MsgWithdraw) (*ltypes.MsgWithdrawResponse, error) { + return nil, nil +} + +func (l lvgNoop) MaxWithdraw(context.Context, *ltypes.MsgMaxWithdraw) (*ltypes.MsgMaxWithdrawResponse, error) { + return nil, nil +} + +func (l lvgNoop) Collateralize(context.Context, *ltypes.MsgCollateralize, +) (*ltypes.MsgCollateralizeResponse, error) { + return nil, nil +} + +func (l lvgNoop) Decollateralize(context.Context, *ltypes.MsgDecollateralize, +) (*ltypes.MsgDecollateralizeResponse, error) { + return nil, nil +} + +func (l lvgNoop) Borrow(context.Context, *ltypes.MsgBorrow) (*ltypes.MsgBorrowResponse, error) { + return nil, nil +} + +func (l lvgNoop) MaxBorrow(context.Context, *ltypes.MsgMaxBorrow) (*ltypes.MsgMaxBorrowResponse, error) { + return nil, nil +} + +func (l lvgNoop) Repay(context.Context, *ltypes.MsgRepay) (*ltypes.MsgRepayResponse, error) { + return nil, nil +} + +func (l lvgNoop) Liquidate(context.Context, *ltypes.MsgLiquidate) (*ltypes.MsgLiquidateResponse, error) { + return nil, nil +} + +func (l lvgNoop) LeveragedLiquidate(context.Context, *ltypes.MsgLeveragedLiquidate, +) (*ltypes.MsgLeveragedLiquidateResponse, error) { + return nil, nil +} + +func (l lvgNoop) SupplyCollateral(context.Context, *ltypes.MsgSupplyCollateral, +) (*ltypes.MsgSupplyCollateralResponse, error) { + return nil, nil +} + +func (l lvgNoop) GovUpdateRegistry(context.Context, *ltypes.MsgGovUpdateRegistry, +) (*ltypes.MsgGovUpdateRegistryResponse, error) { + return nil, nil +} + +func (l lvgNoop) GovUpdateSpecialAssets(context.Context, *ltypes.MsgGovUpdateSpecialAssets, +) (*ltypes.MsgGovUpdateSpecialAssetsResponse, error) { + return nil, nil +} + +func (l lvgNoop) GovSetParams(context.Context, *ltypes.MsgGovSetParams, +) (*ltypes.MsgGovSetParamsResponse, error) { + return nil, nil +} diff --git a/x/uibc/quota/grpc_query.go b/x/uibc/quota/grpc_query.go index 6a36dab9a9..22fe8b49c1 100644 --- a/x/uibc/quota/grpc_query.go +++ b/x/uibc/quota/grpc_query.go @@ -83,7 +83,8 @@ func (q Querier) Inflows(goCtx context.Context, req *uibc.QueryInflows) (*uibc.Q // QuotaExpires returns the current ibc quota expire time. func (q Querier) QuotaExpires(goCtx context.Context, _ *uibc.QueryQuotaExpires) (*uibc.QueryQuotaExpiresResponse, - error) { + error, +) { ctx := sdk.UnwrapSDKContext(goCtx) quotaExpireTime, err := q.Keeper(&ctx).GetExpire() diff --git a/x/uibc/quota/params.go b/x/uibc/quota/params.go index af57db6959..b60a1c3d50 100644 --- a/x/uibc/quota/params.go +++ b/x/uibc/quota/params.go @@ -30,7 +30,6 @@ func (k Keeper) GetParams() (params uibc.Params) { // UpdateQuotaParams update the ibc-transfer quota params for ibc denoms func (k Keeper) UpdateQuotaParams(msg *uibc.MsgGovUpdateQuota, byEmergencyGroup bool) error { - pOld := k.GetParams() pNew := pOld pNew.TotalQuota = msg.Total diff --git a/x/uibc/quota/quota.go b/x/uibc/quota/quota.go index a0c737cd0e..93cc98d4fa 100644 --- a/x/uibc/quota/quota.go +++ b/x/uibc/quota/quota.go @@ -231,7 +231,6 @@ func (k Keeper) UndoUpdateQuota(denom string, amount sdkmath.Int) error { // RecordIBCInflow will save the inflow amount if token is registered otherwise it will skip func (k Keeper) RecordIBCInflow(packet channeltypes.Packet, denom, amount string, ) exported.Acknowledgement { - // if chain is recevier and sender chain is source then we need create ibc_denom (ibc/hash(channel,denom)) to // check ibc_denom is exists in leverage token registry if !ics20types.SenderChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), denom) { diff --git a/x/uibc/uics20/ibc_module.go b/x/uibc/uics20/ibc_module.go index 3578cb30fa..cf568b2748 100644 --- a/x/uibc/uics20/ibc_module.go +++ b/x/uibc/uics20/ibc_module.go @@ -52,19 +52,36 @@ func (im ICS20Module) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, return ackResp } + ack := im.IBCModule.OnRecvPacket(ctx, packet, relayer) + if !ack.Success() { + return ack + } if ftData.Memo != "" { + logger := ctx.Logger() msgs, err := DeserializeMemoMsgs(im.cdc, []byte(ftData.Memo)) if err != nil { // TODO: need to verify if we want to stop the handle the error or revert the ibc transerf // -> same logic in dispatchMemoMsgs - ctx.Logger().Error("can't JSON deserialize ftData Memo, expecting list of Msg", "err", err) + logger.Error("can't JSON deserialize ftData Memo, expecting list of Msg", "err", err) } else { // TODO: need to handle fees! - im.dispatchMemoMsgs(&ctx, msgs) + logger.Info("handling IBC transfer with memo", "sender", ftData.Sender, + "receiver", ftData.Receiver) + + // TODO: we need to rework this if this is not a case, and check receiver! + if ftData.Sender != ftData.Receiver { + logger.Error("sender and receiver are not the same") + } + + sender, err := sdk.AccAddressFromBech32(ftData.Sender) + if err != nil { + logger.Error("can't parse bech32 address", "err", err) + } + im.dispatchMemoMsgs(&ctx, sender, msgs) } } - return im.IBCModule.OnRecvPacket(ctx, packet, relayer) + return ack } // OnAcknowledgementPacket is called on the packet sender chain, once the receiver acknowledged @@ -103,8 +120,7 @@ func (im ICS20Module) onAckErr(ctx *sdk.Context, packet channeltypes.Packet) { // runs messages encoded in the ICS20 memo. // NOTE: storage is forked, and only committed (flushed) if all messages pass and if all // messages are supported. Otherwise the fork storage is discarded. -func (im ICS20Module) dispatchMemoMsgs(ctx *sdk.Context, msgs []sdk.Msg) { - +func (im ICS20Module) dispatchMemoMsgs(ctx *sdk.Context, sender sdk.AccAddress, msgs []sdk.Msg) { if len(msgs) > 2 { ctx.Logger().Error("ics20 memo with more than 2 messages are not supported") return @@ -114,7 +130,7 @@ func (im ICS20Module) dispatchMemoMsgs(ctx *sdk.Context, msgs []sdk.Msg) { cacheCtx, flush := ctx.CacheContext() logger := ctx.Logger().With("scope", "ics20-OnRecvPacket") for _, m := range msgs { - if err := im.handleMemoMsg(&cacheCtx, m); err != nil { + if err := im.handleMemoMsg(&cacheCtx, sender, m); err != nil { // ignore changes in cacheCtx and return logger.Error("error dispatching", "msg: %v\t\t err: %v", m, err) return @@ -124,7 +140,11 @@ func (im ICS20Module) dispatchMemoMsgs(ctx *sdk.Context, msgs []sdk.Msg) { flush() } -func (im ICS20Module) handleMemoMsg(ctx *sdk.Context, msg sdk.Msg) (err error) { +func (im ICS20Module) handleMemoMsg(ctx *sdk.Context, sender sdk.AccAddress, msg sdk.Msg) (err error) { + if signers := msg.GetSigners(); len(signers) != 1 || !signers[0].Equals(sender) { + return sdkerrors.ErrInvalidRequest.Wrapf( + "msg signer doesn't match the sender, expected signer: %s", sender) + } switch msg := msg.(type) { case *ltypes.MsgSupply: _, err = im.leverage.Supply(*ctx, msg) @@ -140,7 +160,6 @@ func (im ICS20Module) handleMemoMsg(ctx *sdk.Context, msg sdk.Msg) (err error) { func deserializeFTData(cdc codec.JSONCodec, packet channeltypes.Packet, ) (d ics20types.FungibleTokenPacketData, err error) { - if err = cdc.UnmarshalJSON(packet.GetData(), &d); err != nil { err = errors.Wrap(err, "cannot unmarshal ICS-20 transfer packet data") diff --git a/x/uibc/uics20/ics4_module_int_test.go b/x/uibc/uics20/ics4_module_int_test.go index a55e298632..1f8c65e563 100644 --- a/x/uibc/uics20/ics4_module_int_test.go +++ b/x/uibc/uics20/ics4_module_int_test.go @@ -18,13 +18,15 @@ func TestMsgMarshalling(t *testing.T) { assert := assert.New(t) cdc := tsdk.NewCodec(uibc.RegisterInterfaces, ltypes.RegisterInterfaces) msgs := []sdk.Msg{ - &uibc.MsgGovSetIBCStatus{Authority: "auth1", Description: "d1", - IbcStatus: uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_OUT_DISABLED}, + &uibc.MsgGovSetIBCStatus{ + Authority: "auth1", Description: "d1", + IbcStatus: uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_OUT_DISABLED, + }, ltypes.NewMsgCollateralize(accs.Alice, sdk.NewCoin("ATOM", sdk.NewInt(1020))), } anyMsg, err := tx.SetMsgs(msgs) assert.NoError(err) - var memo = uibc.ICS20Memo{Messages: anyMsg} + memo := uibc.ICS20Memo{Messages: anyMsg} bz, err := cdc.MarshalJSON(&memo) assert.NoError(err) diff --git a/x/uibc/uics20/ics4_module_memo_test.go b/x/uibc/uics20/ics4_module_memo_test.go new file mode 100644 index 0000000000..64e36cd1fa --- /dev/null +++ b/x/uibc/uics20/ics4_module_memo_test.go @@ -0,0 +1,48 @@ +package uics20 + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + + "github.com/umee-network/umee/v6/tests/accs" + "github.com/umee-network/umee/v6/util/coin" + ltypes "github.com/umee-network/umee/v6/x/leverage/types" + "github.com/umee-network/umee/v6/x/uibc/mocks" +) + +func TestMemoSignerCheck(t *testing.T) { + assert := assert.New(t) + sender := accs.Alice + wrongSignerErr := "signer doesn't match the sender" + asset := coin.New("atom", 10) + im := ICS20Module{leverage: mocks.NewLvgNoopMsgSrv()} + sdkCtx := sdk.Context{} + tcs := []struct { + msg sdk.Msg + errstr string + }{ + {ltypes.NewMsgSupply(accs.Bob, asset), wrongSignerErr}, + {ltypes.NewMsgSupplyCollateral(accs.Bob, asset), wrongSignerErr}, + {ltypes.NewMsgBorrow(accs.Bob, asset), wrongSignerErr}, + + {ltypes.NewMsgSupply(sender, asset), ""}, + {ltypes.NewMsgSupplyCollateral(sender, asset), ""}, + {ltypes.NewMsgBorrow(sender, asset), ""}, + + { + ltypes.NewMsgDecollateralize(sender, asset), + "unsupported type in the ICS20 memo", + }, + } + + for _, tc := range tcs { + err := im.handleMemoMsg(&sdkCtx, sender, tc.msg) + if tc.errstr != "" { + assert.ErrorContains(err, tc.errstr) + } else { + assert.NoError(err) + } + } +}