From 85aa120f54d2f6b5c9bd99feb9a535f4e5b39c07 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 24 Apr 2024 10:19:52 +0200 Subject: [PATCH] feat(ics20): support leverage/MsgRepay in Memo --- x/uibc/uics20/memo_handler.go | 4 ++++ x/uibc/uics20/memo_handler_test.go | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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},