From 97af6be24331bf793cb94162279665804dcf31d6 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 24 Apr 2024 12:01:11 +0200 Subject: [PATCH] feat(ics20): support leverage/MsgRepay in Memo (#2506) * feat(ics20): support leverage/MsgRepay in Memo * changelog * lint --- CHANGELOG.md | 1 + x/uibc/uics20/memo_handler.go | 4 ++++ x/uibc/uics20/memo_handler_test.go | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e00bdc8ee6..f7f6e0ca08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - [2472](https://github.com/umee-network/umee/pull/2472) un-wire the `crisis` module from umee app. - [2500](https://github.com/umee-network/umee/pull/2500) (x/leverage): add Rewards Auction fees and `params.rewards_auction_factor`. +- [2506](https://github.com/umee-network/umee/pull/2506) (ics20): support leverage/MsgRepay in Memo ### Improvements diff --git a/x/uibc/uics20/memo_handler.go b/x/uibc/uics20/memo_handler.go index d8ec86d66d..450ef0e083 100644 --- a/x/uibc/uics20/memo_handler.go +++ b/x/uibc/uics20/memo_handler.go @@ -161,6 +161,8 @@ func (mh MemoHandler) validateMemoMsg() error { // collateral = asset case *ltypes.MsgSupply: asset = &msg.Asset + case *ltypes.MsgRepay: + asset = &msg.Asset case *ltypes.MsgLiquidate: asset = &msg.Repayment default: @@ -197,6 +199,8 @@ func (mh MemoHandler) handleMemoMsg(ctx *sdk.Context, msg sdk.Msg) (err error) { _, err = mh.leverage.Supply(*ctx, msg) case *ltypes.MsgSupplyCollateral: _, err = mh.leverage.SupplyCollateral(*ctx, msg) + case *ltypes.MsgRepay: + _, err = mh.leverage.Repay(*ctx, msg) case *ltypes.MsgLiquidate: _, err = mh.leverage.Liquidate(*ctx, msg) default: diff --git a/x/uibc/uics20/memo_handler_test.go b/x/uibc/uics20/memo_handler_test.go index d9d594e588..e8ddd6ca31 100644 --- a/x/uibc/uics20/memo_handler_test.go +++ b/x/uibc/uics20/memo_handler_test.go @@ -29,6 +29,7 @@ func TestValidateMemoMsg(t *testing.T) { goodMsgSupplyColl := ltypes.NewMsgSupplyCollateral(receiver, asset) // goodMsgSupplyCollH := ltypes.NewMsgSupplyCollateral(receiver, assetH) goodMsgSupplyColl11 := ltypes.NewMsgSupplyCollateral(receiver, asset11) + goodMsgRepay := ltypes.NewMsgRepay(receiver, asset11) goodMsgBorrow := ltypes.NewMsgBorrow(receiver, asset) goodMsgBorrowH := ltypes.NewMsgBorrow(receiver, assetH) goodMsgLiquidate := ltypes.NewMsgLiquidate(receiver, accs.Bob, assetH, "uumee") @@ -53,9 +54,10 @@ func TestValidateMemoMsg(t *testing.T) { // good messages[0] {[]sdk.Msg{goodMsgSupply}, ""}, {[]sdk.Msg{goodMsgSupplyColl}, ""}, - {[]sdk.Msg{goodMsgLiquidate}, ""}, // in handlers v2 this will be a good message + {[]sdk.Msg{goodMsgRepay}, ""}, + {[]sdk.Msg{goodMsgLiquidate}, ""}, - // messages[0] use more assets than the transfer -> OK + // messages[0] use more assets than the transfer -> OK: should be adjusted {[]sdk.Msg{goodMsgSupply11}, ""}, {[]sdk.Msg{goodMsgSupplyColl11}, ""}, {[]sdk.Msg{goodMsgSupplyColl11}, ""}, @@ -167,6 +169,7 @@ func TestMemoExecute(t *testing.T) { mh := MemoHandler{leverage: lvg} ctx, _ := tsdk.NewCtxOneStore(t, storetypes.NewMemoryStoreKey("quota")) msgs := []sdk.Msg{<ypes.MsgSupply{}} + msgsRepay := []sdk.Msg{<ypes.MsgRepay{}} tcs := []struct { enabled bool @@ -176,6 +179,7 @@ func TestMemoExecute(t *testing.T) { }{ {true, true, msgs, nil}, {true, false, msgs, nil}, + {true, false, msgsRepay, nil}, {true, false, nil, nil}, {false, true, nil, errHooksDisabled},