Skip to content

Commit

Permalink
feat(ics20): support leverage/MsgRepay in Memo
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Apr 24, 2024
1 parent 1c35124 commit 85aa120
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions x/uibc/uics20/memo_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions x/uibc/uics20/memo_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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}, ""},
Expand Down Expand Up @@ -167,6 +169,7 @@ func TestMemoExecute(t *testing.T) {
mh := MemoHandler{leverage: lvg}
ctx, _ := tsdk.NewCtxOneStore(t, storetypes.NewMemoryStoreKey("quota"))
msgs := []sdk.Msg{&ltypes.MsgSupply{}}
msgsRepay := []sdk.Msg{&ltypes.MsgRepay{}}

tcs := []struct {
enabled bool
Expand All @@ -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},
Expand Down

0 comments on commit 85aa120

Please sign in to comment.