Skip to content

Commit

Permalink
add admin update on market number_of_users
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbigz committed Apr 5, 2024
1 parent 06b495d commit 964a50a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 4 deletions.
24 changes: 24 additions & 0 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,30 @@ pub fn handle_update_perp_market_fee_adjustment(
Ok(())
}

pub fn handle_update_perp_market_number_of_users<'info>(

Check warning on line 2313 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2313

Added line #L2313 was not covered by tests
ctx: Context<AdminUpdatePerpMarket>,
number_of_users: Option<u32>,
number_of_users_with_base: Option<u32>,
) -> Result<()> {
let perp_market = &mut load_mut!(ctx.accounts.perp_market)?;

Check warning on line 2318 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2318

Added line #L2318 was not covered by tests

if let Some(number_of_users) = number_of_users {
perp_market.number_of_users = number_of_users;

Check warning on line 2321 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2320-L2321

Added lines #L2320 - L2321 were not covered by tests
}

if let Some(number_of_users_with_base) = number_of_users_with_base {
perp_market.number_of_users_with_base = number_of_users_with_base;

Check warning on line 2325 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2324-L2325

Added lines #L2324 - L2325 were not covered by tests
}

validate!(
perp_market.number_of_users >= perp_market.number_of_users_with_base,
ErrorCode::DefaultError,

Check warning on line 2330 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2328-L2330

Added lines #L2328 - L2330 were not covered by tests
"number_of_users must be >= number_of_users_with_base "
)?;

Ok(())

Check warning on line 2334 in programs/drift/src/instructions/admin.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/instructions/admin.rs#L2334

Added line #L2334 was not covered by tests
}

#[access_control(
spot_market_valid(&ctx.accounts.spot_market)
)]
Expand Down
8 changes: 8 additions & 0 deletions programs/drift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,14 @@ pub mod drift {
handle_update_perp_market_max_open_interest(ctx, max_open_interest)
}

pub fn update_perp_market_number_of_users(

Check warning on line 1131 in programs/drift/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/lib.rs#L1131

Added line #L1131 was not covered by tests
ctx: Context<AdminUpdatePerpMarket>,
number_of_users: Option<u32>,
number_of_users_with_base: Option<u32>,
) -> Result<()> {
handle_update_perp_market_number_of_users(ctx, number_of_users, number_of_users_with_base)

Check warning on line 1136 in programs/drift/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/lib.rs#L1136

Added line #L1136 was not covered by tests
}

pub fn update_perp_market_fee_adjustment(
ctx: Context<AdminUpdatePerpMarket>,
fee_adjustment: i16,
Expand Down
42 changes: 42 additions & 0 deletions sdk/src/adminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2905,6 +2905,48 @@ export class AdminClient extends DriftClient {
);
}

public async updatePerpMarketNumberOfUser(
perpMarketIndex: number,
numberOfUsers?: number,
numberOfUsersWithBase?: number
): Promise<TransactionSignature> {
const updatepPerpMarketFeeAdjustmentIx =
await this.getUpdatePerpMarketNumberOfUsersIx(
perpMarketIndex,
numberOfUsers,
numberOfUsersWithBase
);

const tx = await this.buildTransaction(updatepPerpMarketFeeAdjustmentIx);

const { txSig } = await this.sendTransaction(tx, [], this.opts);

return txSig;
}

public async getUpdatePerpMarketNumberOfUsersIx(
perpMarketIndex: number,
numberOfUsers?: number,
numberOfUsersWithBase?: number
): Promise<TransactionInstruction> {
return await this.program.instruction.updatePerpMarketNumberOfUsers(
numberOfUsers,
numberOfUsersWithBase,
{
accounts: {
admin: this.isSubscribed
? this.getStateAccount().admin
: this.wallet.publicKey,
state: await this.getStatePublicKey(),
perpMarket: await getPerpMarketPublicKey(
this.program.programId,
perpMarketIndex
),
},
}
);
}

public async updatePerpMarketFeeAdjustment(
perpMarketIndex: number,
feeAdjustment: number
Expand Down
34 changes: 34 additions & 0 deletions sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
Expand Up @@ -4758,6 +4758,40 @@
}
]
},
{
"name": "updatePerpMarketNumberOfUsers",
"accounts": [
{
"name": "admin",
"isMut": false,
"isSigner": true
},
{
"name": "state",
"isMut": false,
"isSigner": false
},
{
"name": "perpMarket",
"isMut": true,
"isSigner": false
}
],
"args": [
{
"name": "numberOfUsers",
"type": {
"option": "u32"
}
},
{
"name": "numberOfUsersWithBase",
"type": {
"option": "u32"
}
}
]
},
{
"name": "updatePerpMarketFeeAdjustment",
"accounts": [
Expand Down
12 changes: 9 additions & 3 deletions sdk/src/tx/forwardOnlyTxSender.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { AnchorProvider } from '@coral-xyz/anchor';
import { ConfirmOptions, Connection, VersionedTransaction } from '@solana/web3.js';
import {
ConfirmOptions,
Connection,
VersionedTransaction,
} from '@solana/web3.js';
import bs58 from 'bs58';
import { IWallet } from '../types';
import { BaseTxSender } from './baseTxSender';
Expand Down Expand Up @@ -75,7 +79,6 @@ export class ForwardOnlyTxSender extends BaseTxSender {
rawTransaction: Buffer | Uint8Array,
opts: ConfirmOptions
): Promise<TxSigAndSlot> {

const deserializedTx = VersionedTransaction.deserialize(rawTransaction);

const txSig = deserializedTx.signatures[0];
Expand Down Expand Up @@ -107,7 +110,10 @@ export class ForwardOnlyTxSender extends BaseTxSender {

let slot: number;
try {
const result = await this.confirmTransaction(encodedTxSig, opts.commitment);
const result = await this.confirmTransaction(
encodedTxSig,
opts.commitment
);
slot = result.context.slot;
// eslint-disable-next-line no-useless-catch
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/tx/whileValidTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export class WhileValidTxSender extends BaseTxSender {
}

// handle subclass-specific side effects
const txSig = bs58.encode(signedTx.signatures[0]?.signature || signedTx.signatures[0]);
const txSig = bs58.encode(
signedTx.signatures[0]?.signature || signedTx.signatures[0]
);
this.untilValid.set(txSig, latestBlockhash);

return signedTx;
Expand Down

0 comments on commit 964a50a

Please sign in to comment.