-
Notifications
You must be signed in to change notification settings - Fork 206
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): close position #511
Conversation
# Conflicts: # proto/perp/v1/tx.proto # x/perp/types/tx.pb.go
if err != nil { | ||
return nil, sdkerrors.Wrap(vpooltypes.ErrClosingPosition, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was curious why we are removing the wrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It breaks module boundary responsibilities for the x/perp module to throw a vpool error type.
if err != nil { | ||
return nil, sdkerrors.Wrap(vpooltypes.ErrClosingPosition, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It breaks module boundary responsibilities for the x/perp module to throw a vpool error type.
return err | ||
} | ||
|
||
currentOpenNotional, _, err := k.getPositionNotionalAndUnrealizedPnL(ctx, *position, types.PnLCalcOption_SPOT_PRICE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentOpenNotional, _, err := k.getPositionNotionalAndUnrealizedPnL(ctx, *position, types.PnLCalcOption_SPOT_PRICE) | |
currentPositionNotional, _, err := k.getPositionNotionalAndUnrealizedPnL(ctx, *position, types.PnLCalcOption_SPOT_PRICE) |
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the check over fluctuation limit.
x/perp/keeper/perp_test.go
Outdated
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1). | ||
WithBlockTime(ctx.BlockTime().Add(1 * time.Minute)) | ||
|
||
_, err = nibiruApp.PerpKeeper.ClosePosition(ctx, pair, alice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add assertions on the positionResp
so that we can verify the funding payment and bad debt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@godismercilex if you can add this little assertions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like adding exact calculation assertions is redundant since ClosePosition is a subset of OpenPosition with no custom functionality, those assertions should be covered in the other functions that close position calls, I've anyways added some basic coverage on the expected output, not pure math.
I opened issue #603 that is related to this one in order to merge this issue. |
No description provided.