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): close position #511

Merged
merged 21 commits into from
Jun 15, 2022
Merged

feat(perp): close position #511

merged 21 commits into from
Jun 15, 2022

Conversation

testinginprod
Copy link
Collaborator

No description provided.

@testinginprod testinginprod marked this pull request as ready for review June 8, 2022 16:35
@testinginprod testinginprod requested a review from a team as a code owner June 8, 2022 16:35
if err != nil {
return nil, sdkerrors.Wrap(vpooltypes.ErrClosingPosition, err.Error())
Copy link
Contributor

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?

Copy link
Contributor

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.

x/perp/keeper/perp_test.go Outdated Show resolved Hide resolved
if err != nil {
return nil, sdkerrors.Wrap(vpooltypes.ErrClosingPosition, err.Error())
Copy link
Contributor

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.

x/perp/keeper/msg_server.go Outdated Show resolved Hide resolved
x/perp/keeper/perp_test.go Show resolved Hide resolved
x/perp/keeper/perp_test.go Show resolved Hide resolved
x/perp/keeper/clearing_house.go Show resolved Hide resolved
return err
}

currentOpenNotional, _, err := k.getPositionNotionalAndUnrealizedPnL(ctx, *position, types.PnLCalcOption_SPOT_PRICE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}

Copy link
Contributor

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.

@Unique-Divine Unique-Divine changed the title add: close position feat(perp): close position Jun 12, 2022
x/perp/keeper/clearing_house.go Show resolved Hide resolved
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).
WithBlockTime(ctx.BlockTime().Add(1 * time.Minute))

_, err = nibiruApp.PerpKeeper.ClosePosition(ctx, pair, alice)
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@AgentSmithMatrix
Copy link
Contributor

I opened issue #603 that is related to this one in order to merge this issue.

@NibiruHeisenberg NibiruHeisenberg added CLI type: tests Unit and integration test additions and improvements labels Jun 14, 2022
x/perp/keeper/perp_test.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: tests Unit and integration test additions and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants