Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(perp): Gracefully handle errors in MsgLiquidate #844

Closed
3 tasks
Unique-Divine opened this issue Aug 23, 2022 · 5 comments · Fixed by #875
Closed
3 tasks

feat(perp): Gracefully handle errors in MsgLiquidate #844

Unique-Divine opened this issue Aug 23, 2022 · 5 comments · Fixed by #875
Assignees

Comments

@Unique-Divine
Copy link
Member

Makes the validation checks skip the part of execution that closes a position and sends funds if there's:

  • an invalid trading pair
  • an non-existent position
  • an invalid trader address

Desired use case: If two MsgLiquidate messages are included in the same transaction and one raises an error, the transaction should still succeed (and only liquidate based on the valid message).

@AgentSmithMatrix
Copy link
Contributor

Let's keep this without merging, there are some comments from @godismercilex about it.

@testinginprod
Copy link
Collaborator

testinginprod commented Aug 25, 2022

I think for the sake of simplicity, I would add a new Msg called MsgMultiLiquidate:

message MsgMultiLiquidate {
repeated msgs_liquidate MsgLiquidate = 1;
}

message MsgMultiLiquidateResponse {
   message LiquidationResponse {
     // reports the index of a successful liquidation
      uint64 index = 1;
      MsgLiquidateResponse resp = 2;
   }
   
   repeated LiquidationResponse = 1;
}

At golang level:

func (k Keeper) MultiLiquidate(ctx sdk.Context, m MsgMultiLiquidate) MsgMultiLiquidateResponse {
   var responses []LiquidationResponse
    for index, liquidation := range m.MsgsLiquidate {
        cacheCtx, commit := ctx.CacheContext()
        liquidationResp, err := k.Liquidate(cacheCtx, liquidation)
        if err != nil {
              continue
              // or maybe here we wanna add extra failure events ???
       }
       commit()
       responses = append(responses, LiquidationResponse { Index: index, MsgLiquidateResponse: liquidationResp }
   }
}

@matthiasmatt
Copy link
Contributor

If we add the error in the liquidation response proto that would be nice

@AgentSmithMatrix
Copy link
Contributor

All in then with the MultiLiquidate message.

@NibiruHeisenberg
Copy link
Contributor

Need to think about limiting the number of liquidations per block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants