-
Notifications
You must be signed in to change notification settings - Fork 170
Add initial impl - need to fix current test #3249
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -535,6 +535,33 @@ func (k Keeper) CanUpdateSubaccounts( | |||||||||||||||||||||||||||||||
| return success, successPerUpdate, err | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func (k Keeper) checkDepositConstraints( | ||||||||||||||||||||||||||||||||
| settledUpdates []types.SettledUpdate, | ||||||||||||||||||||||||||||||||
| ) ( | ||||||||||||||||||||||||||||||||
| success bool, | ||||||||||||||||||||||||||||||||
| successPerUpdate []types.UpdateResult, | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
| success = true | ||||||||||||||||||||||||||||||||
| successPerUpdate = make([]types.UpdateResult, len(settledUpdates)) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for i, u := range settledUpdates { | ||||||||||||||||||||||||||||||||
| for _, assetUpdate := range u.AssetUpdates { | ||||||||||||||||||||||||||||||||
| // Reject deposit if the account the account is new (no perp position, no usdc position) and the deposit/transfer | ||||||||||||||||||||||||||||||||
| // is less than the minimum initial deposit. | ||||||||||||||||||||||||||||||||
| // TODO: we need to be careful this doesn't break any existing valid flows. | ||||||||||||||||||||||||||||||||
| if assetUpdate.AssetId == assettypes.AssetUsdc.Id && | ||||||||||||||||||||||||||||||||
| assetUpdate.BigQuantumsDelta.Cmp(big.NewInt(types.MIN_SUBACCOUNT_INITIAL_DEPOSIT_QUANTUMS)) < 0 && | ||||||||||||||||||||||||||||||||
| u.SettledSubaccount.GetUsdcPosition().Sign() == 0 && | ||||||||||||||||||||||||||||||||
| len(u.SettledSubaccount.PerpetualPositions) == 0 { | ||||||||||||||||||||||||||||||||
| successPerUpdate[i] = types.ViolatesDepositConstraints | ||||||||||||||||||||||||||||||||
| success = false | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+552
to
+558
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Add positive delta check for clarity and efficiency. The comparison Apply this diff: if assetUpdate.AssetId == assettypes.AssetUsdc.Id &&
+ assetUpdate.BigQuantumsDelta.Sign() > 0 &&
assetUpdate.BigQuantumsDelta.Cmp(big.NewInt(types.MIN_SUBACCOUNT_INITIAL_DEPOSIT_QUANTUMS)) < 0 &&
u.SettledSubaccount.GetUsdcPosition().Sign() == 0 &&
len(u.SettledSubaccount.PerpetualPositions) == 0 {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return success, successPerUpdate | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func (k Keeper) internalCanUpdateSubaccountsWithLeverage( | ||||||||||||||||||||||||||||||||
| ctx sdk.Context, | ||||||||||||||||||||||||||||||||
| settledUpdates []types.SettledUpdate, | ||||||||||||||||||||||||||||||||
|
|
@@ -557,11 +584,16 @@ func (k Keeper) internalCanUpdateSubaccountsWithLeverage( | |||||||||||||||||||||||||||||||
| return success, successPerUpdate, nil | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Block all withdrawals and transfers if either of the following is true within the last | ||||||||||||||||||||||||||||||||
| // `WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS`: | ||||||||||||||||||||||||||||||||
| // - There was a negative TNC subaccount seen for any of the collateral pools of subaccounts being updated | ||||||||||||||||||||||||||||||||
| // - There was a chain outage that lasted at least five minutes. | ||||||||||||||||||||||||||||||||
| if updateType == types.Withdrawal || updateType == types.Transfer { | ||||||||||||||||||||||||||||||||
| success, successPerUpdate = k.checkDepositConstraints(settledUpdates) | ||||||||||||||||||||||||||||||||
| if !success { | ||||||||||||||||||||||||||||||||
| return success, successPerUpdate, nil | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
Comment on lines
587
to
+592
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include deposit updates in the minimum deposit gate Right now we only invoke - if updateType == types.Withdrawal || updateType == types.Transfer {
+ if updateType == types.Withdrawal || updateType == types.Transfer || updateType == types.Deposit {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| // Block all withdrawals and transfers if either of the following is true within the last | ||||||||||||||||||||||||||||||||
| // `WITHDRAWAL_AND_TRANSFERS_BLOCKED_AFTER_NEGATIVE_TNC_SUBACCOUNT_SEEN_BLOCKS`: | ||||||||||||||||||||||||||||||||
| // - There was a negative TNC subaccount seen for any of the collateral pools of subaccounts being updated | ||||||||||||||||||||||||||||||||
| // - There was a chain outage that lasted at least five minutes. | ||||||||||||||||||||||||||||||||
| lastBlockNegativeTncSubaccountSeen, negativeTncSubaccountExists, err := k.getLastBlockNegativeSubaccountSeen( | ||||||||||||||||||||||||||||||||
| ctx, | ||||||||||||||||||||||||||||||||
| settledUpdates, | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
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.
Fix typo in comment.
The comment contains a repeated phrase.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents