Skip to content

Commit

Permalink
fixing negative custody amount issue (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
avkr003 authored Sep 24, 2024
1 parent c219ea2 commit 5c8fe66
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion x/perpetual/keeper/repay.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (k Keeper) Repay(ctx sdk.Context, mtp *types.MTP, pool *types.Pool, ammPool
}

mtp.Custody = mtp.Custody.Sub(amount)
if mtp.Custody.IsZero() {
// This is for accounting purposes, mtp.Custody gets reduced by borrowInterestPaymentCustody and funding fee. so msg.Amount is greater than mtp.Custody here. So if it's negative it should be closed
if mtp.Custody.IsZero() || mtp.Custody.IsNegative() {
err = k.DestroyMTP(ctx, mtp.GetAccountAddress(), mtp.Id)
if err != nil {
return err
Expand Down

0 comments on commit 5c8fe66

Please sign in to comment.