Skip to content

Commit 61769c9

Browse files
0xbigzcrispheaney
andauthored
program: update pmm invariant (#1506)
* program: pmm-config-update-invariant * correct ordering of validate * lints --------- Co-authored-by: Chris Heaney <chrisheaney30@gmail.com>
1 parent bf0cd0d commit 61769c9

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

programs/drift/src/instructions/admin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4386,9 +4386,13 @@ pub fn handle_update_protected_maker_mode_config(
43864386
ctx: Context<UpdateProtectedMakerModeConfig>,
43874387
max_users: u32,
43884388
reduce_only: bool,
4389+
current_users: Option<u32>,
43894390
) -> Result<()> {
43904391
let mut config = load_mut!(ctx.accounts.protected_maker_mode_config)?;
43914392

4393+
if current_users.is_some() {
4394+
config.current_users = current_users.unwrap();
4395+
}
43924396
config.max_users = max_users;
43934397
config.reduce_only = reduce_only as u8;
43944398

programs/drift/src/instructions/user.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,17 @@ pub fn handle_update_user_protected_maker_orders(
28032803

28042804
validate!(!user.is_being_liquidated(), ErrorCode::LiquidationsOngoing)?;
28052805

2806+
validate!(
2807+
protected_maker_orders != user.is_protected_maker(),
2808+
ErrorCode::DefaultError,
2809+
"user already {} protected maker mode",
2810+
if protected_maker_orders {
2811+
"in"
2812+
} else {
2813+
"out of"
2814+
}
2815+
)?;
2816+
28062817
user.update_protected_maker_orders_status(protected_maker_orders)?;
28072818

28082819
let mut config = load_mut!(ctx.accounts.protected_maker_mode_config)?;

programs/drift/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,8 +1659,9 @@ pub mod drift {
16591659
ctx: Context<UpdateProtectedMakerModeConfig>,
16601660
max_users: u32,
16611661
reduce_only: bool,
1662+
current_users: Option<u32>,
16621663
) -> Result<()> {
1663-
handle_update_protected_maker_mode_config(ctx, max_users, reduce_only)
1664+
handle_update_protected_maker_mode_config(ctx, max_users, reduce_only, current_users)
16641665
}
16651666
}
16661667

sdk/src/adminClient.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,10 +4136,15 @@ export class AdminClient extends DriftClient {
41364136

41374137
public async updateProtectedMakerModeConfig(
41384138
maxUsers: number,
4139-
reduceOnly: boolean
4139+
reduceOnly: boolean,
4140+
currentUsers: undefined
41404141
): Promise<TransactionSignature> {
41414142
const updateProtectedMakerModeConfigIx =
4142-
await this.getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly);
4143+
await this.getUpdateProtectedMakerModeConfigIx(
4144+
maxUsers,
4145+
reduceOnly,
4146+
currentUsers
4147+
);
41434148

41444149
const tx = await this.buildTransaction(updateProtectedMakerModeConfigIx);
41454150

@@ -4150,11 +4155,13 @@ export class AdminClient extends DriftClient {
41504155

41514156
public async getUpdateProtectedMakerModeConfigIx(
41524157
maxUsers: number,
4153-
reduceOnly: boolean
4158+
reduceOnly: boolean,
4159+
currentUsers: undefined
41544160
): Promise<TransactionInstruction> {
41554161
return await this.program.instruction.updateProtectedMakerModeConfig(
41564162
maxUsers,
41574163
reduceOnly,
4164+
currentUsers,
41584165
{
41594166
accounts: {
41604167
admin: this.isSubscribed

0 commit comments

Comments
 (0)