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

Limit number of positions and collaterals per account #1774

Merged
merged 4 commits into from
Aug 16, 2023

Conversation

leomassazza
Copy link
Contributor

No description provided.

@leomassazza leomassazza self-assigned this Aug 15, 2023
Comment on lines 144 to 147
if (oldPosition.size == 0) {
//is a new position, check if not exceeding max positions per account
perpsAccount.canOpenNewPosition();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont think you need this validation in settle. since you can't have more than one order at a time, i don't see a scenario where validation passes commitment then fails here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes... I was wondering how that can happen, and keep it just in case. But, yeah, I'll get rid of it.

Comment on lines 75 to 78
if (PerpsMarket.accountPosition(commitment.marketId, commitment.accountId).size == 0) {
//is a new position, check if not exceeding max positions per account
PerpsAccount.load(commitment.accountId).canOpenNewPosition();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i would move the if condition into the validation itself. maybe something like this:

PerpsAccount.validateMaxPositions(commitment.marketId, commitment.accountId);

and load the position and account in the validation itself. just cleans up the modules a bit more.

Copy link
Contributor

Choose a reason for hiding this comment

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

wish we still had createValid, then this call for validating max positions can just live there.

i have some ideas on this, but can leave it to a separate PR 👍🏽

Comment on lines 56 to 59
if (account.collateralAmounts[synthMarketId] == 0) {
// if the account has no collateral in this market, we need to check if it can add a new collateral
account.canAddNewCollateral();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, move the if condition into the validation

@@ -69,6 +73,24 @@ library PerpsAccount {
}
}

function canOpenNewPosition(Data storage self) internal view {
Copy link
Contributor

Choose a reason for hiding this comment

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

would rename this to validateMaxPositions. can implies it will return a boolean.

}
}

function canAddNewCollateral(Data storage self) internal view {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, maybe validateMaxCollaterals

Copy link
Contributor

@sunnyvempati sunnyvempati left a comment

Choose a reason for hiding this comment

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

one question but looks good

) internal {
checkPendingOrder(newRequest.accountId);

PerpsAccount.load(newRequest.accountId).validateMaxPositions(newRequest.marketId);
Copy link
Contributor

Choose a reason for hiding this comment

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

can just do the account loading in the validateMaxPositions function.

so could just do PerpsAccount.validateMaxPositions(newRequest.accountId, newRequest.marketId);

non blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, will update

uint128 maxPositionsPerAccount = GlobalPerpsMarketConfiguration
.load()
.maxPositionsPerAccount;
if (maxPositionsPerAccount <= self.openPositionMarketIds.length()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why <= instead of just <?

if max is set to 5, can't you have 5 open positions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because we check here if we can add another => in your example we'll check when adding the 5th so we need to have 4 already there at most

@leomassazza leomassazza merged commit 1c5ab0c into main Aug 16, 2023
16 of 17 checks passed
@leomassazza leomassazza deleted the pv3-feature/max-positions-and-collaterals branch August 16, 2023 15:21
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