Skip to content

Commit

Permalink
feat(ics20): support leverage/MsgRepay in Memo (#2506)
Browse files Browse the repository at this point in the history
* feat(ics20): support leverage/MsgRepay in Memo

* changelog

* lint
  • Loading branch information
robert-zaremba committed Apr 24, 2024
1 parent 1c35124 commit 97af6be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 97af6be

Please sign in to comment.