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

refactor(perp): Refactor ClosePosition to use closePositionEntirely #690

Merged
merged 4 commits into from
Jul 11, 2022

Conversation

NibiruHeisenberg
Copy link
Contributor

ClosePosition currently calls openReversePosition which calls closePositionEntirely under the hood. This PR removes the indirect call and calls closePositionEntirely directly.

@NibiruHeisenberg NibiruHeisenberg requested a review from a team as a code owner July 9, 2022 16:54
@NibiruHeisenberg NibiruHeisenberg self-assigned this Jul 9, 2022
Copy link
Collaborator

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

Considering closeAndOpenReversePosition goes to the case in which remaining_open_notional is not positive, is not negative but is zero then this path shortcut should be fine.

// ClosePosition gets the current position, and calls OpenPosition to open a reverse position with amount equal to the current open notional.
func (k Keeper) ClosePosition(ctx sdk.Context, pair common.AssetPair, addr sdk.AccAddress) (*types.PositionResp, error) {
position, err := k.PositionsState(ctx).Get(pair, addr)
/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Golang comments blocks with /**/ are not as idiomatic as comment blocks with //

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted but it's not harmful in any way right?

@NibiruHeisenberg NibiruHeisenberg merged commit 09fe399 into master Jul 11, 2022
@NibiruHeisenberg NibiruHeisenberg deleted the refactor/perp/close-position branch July 11, 2022 16:18
@NibiruHeisenberg NibiruHeisenberg restored the refactor/perp/close-position branch July 12, 2022 20:24
@NibiruHeisenberg NibiruHeisenberg deleted the refactor/perp/close-position branch July 12, 2022 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants