Skip to content

Commit 627548a

Browse files
authored
program: delete sereum/ob configs ix (#2066)
* hot wallet update config stats * add delete for serum * delete ob config * CHANGELOG
1 parent 1fed025 commit 627548a

File tree

7 files changed

+168
-8
lines changed

7 files changed

+168
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Features
1111

1212
- program: isolated positions [#1757](https://github.com/drift-labs/protocol-v2/pull/1757)
13+
- program: delete serum/openbook configs [#2066](https://github.com/drift-labs/protocol-v2/pull/2066)
1314

1415
### Fixes
1516

programs/drift/src/instructions/admin.rs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ pub fn handle_update_serum_fulfillment_config_status(
512512
Ok(())
513513
}
514514

515+
pub fn handle_delete_serum_fulfillment_config(
516+
_ctx: Context<DeleteSerumFulfillmentConfig>,
517+
) -> Result<()> {
518+
msg!("deleted serum fulfillment config");
519+
Ok(())
520+
}
521+
515522
pub fn handle_update_serum_vault(ctx: Context<UpdateSerumVault>) -> Result<()> {
516523
let vault = &ctx.accounts.srm_vault;
517524
validate!(
@@ -610,6 +617,13 @@ pub fn handle_update_openbook_v2_fulfillment_config_status(
610617
Ok(())
611618
}
612619

620+
pub fn handle_delete_openbook_v2_fulfillment_config(
621+
_ctx: Context<DeleteOpenbookV2FulfillmentConfig>,
622+
) -> Result<()> {
623+
msg!("deleted openbook v2 fulfillment config");
624+
Ok(())
625+
}
626+
613627
pub fn handle_initialize_phoenix_fulfillment_config(
614628
ctx: Context<InitializePhoenixFulfillmentConfig>,
615629
market_index: u16,
@@ -5370,13 +5384,25 @@ pub struct InitializeSerumFulfillmentConfig<'info> {
53705384

53715385
#[derive(Accounts)]
53725386
pub struct UpdateSerumFulfillmentConfig<'info> {
5387+
pub state: Box<Account<'info, State>>,
5388+
#[account(mut)]
5389+
pub serum_fulfillment_config: AccountLoader<'info, SerumV3FulfillmentConfig>,
53735390
#[account(
5374-
has_one = admin
5391+
mut,
5392+
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
53755393
)]
5394+
pub admin: Signer<'info>,
5395+
}
5396+
5397+
#[derive(Accounts)]
5398+
pub struct DeleteSerumFulfillmentConfig<'info> {
53765399
pub state: Box<Account<'info, State>>,
5377-
#[account(mut)]
5400+
#[account(mut, close = admin)]
53785401
pub serum_fulfillment_config: AccountLoader<'info, SerumV3FulfillmentConfig>,
5379-
#[account(mut)]
5402+
#[account(
5403+
mut,
5404+
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
5405+
)]
53805406
pub admin: Signer<'info>,
53815407
}
53825408

@@ -5949,13 +5975,25 @@ pub struct InitializeOpenbookV2FulfillmentConfig<'info> {
59495975

59505976
#[derive(Accounts)]
59515977
pub struct UpdateOpenbookV2FulfillmentConfig<'info> {
5978+
pub state: Box<Account<'info, State>>,
5979+
#[account(mut)]
5980+
pub openbook_v2_fulfillment_config: AccountLoader<'info, OpenbookV2FulfillmentConfig>,
59525981
#[account(
5953-
has_one = admin
5982+
mut,
5983+
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
59545984
)]
5985+
pub admin: Signer<'info>,
5986+
}
5987+
5988+
#[derive(Accounts)]
5989+
pub struct DeleteOpenbookV2FulfillmentConfig<'info> {
59555990
pub state: Box<Account<'info, State>>,
5956-
#[account(mut)]
5991+
#[account(mut, close = admin)]
59575992
pub openbook_v2_fulfillment_config: AccountLoader<'info, OpenbookV2FulfillmentConfig>,
5958-
#[account(mut)]
5993+
#[account(
5994+
mut,
5995+
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
5996+
)]
59595997
pub admin: Signer<'info>,
59605998
}
59615999

programs/drift/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,12 @@ pub mod drift {
965965
handle_update_serum_fulfillment_config_status(ctx, status)
966966
}
967967

968+
pub fn delete_serum_fulfillment_config(
969+
ctx: Context<DeleteSerumFulfillmentConfig>,
970+
) -> Result<()> {
971+
handle_delete_serum_fulfillment_config(ctx)
972+
}
973+
968974
pub fn initialize_openbook_v2_fulfillment_config(
969975
ctx: Context<InitializeOpenbookV2FulfillmentConfig>,
970976
market_index: u16,
@@ -978,6 +984,13 @@ pub mod drift {
978984
) -> Result<()> {
979985
handle_update_openbook_v2_fulfillment_config_status(ctx, status)
980986
}
987+
988+
pub fn delete_openbook_v2_fulfillment_config(
989+
ctx: Context<DeleteOpenbookV2FulfillmentConfig>,
990+
) -> Result<()> {
991+
handle_delete_openbook_v2_fulfillment_config(ctx)
992+
}
993+
981994
pub fn initialize_phoenix_fulfillment_config(
982995
ctx: Context<InitializePhoenixFulfillmentConfig>,
983996
market_index: u16,

sdk/src/adminClient.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,33 @@ export class AdminClient extends DriftClient {
384384
);
385385
}
386386

387+
public async deleteSerumFulfillmentConfig(
388+
serumMarket: PublicKey
389+
): Promise<TransactionSignature> {
390+
const deleteIx = await this.getDeleteSerumFulfillmentConfigIx(serumMarket);
391+
const tx = await this.buildTransaction(deleteIx);
392+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
393+
return txSig;
394+
}
395+
396+
public async getDeleteSerumFulfillmentConfigIx(
397+
serumMarket: PublicKey
398+
): Promise<TransactionInstruction> {
399+
const serumFulfillmentConfig = getSerumFulfillmentConfigPublicKey(
400+
this.program.programId,
401+
serumMarket
402+
);
403+
return await this.program.instruction.deleteSerumFulfillmentConfig({
404+
accounts: {
405+
admin: this.isSubscribed
406+
? this.getStateAccount().admin
407+
: this.wallet.publicKey,
408+
state: await this.getStatePublicKey(),
409+
serumFulfillmentConfig,
410+
},
411+
});
412+
}
413+
387414
public async initializePhoenixFulfillmentConfig(
388415
marketIndex: number,
389416
phoenixMarket: PublicKey
@@ -476,6 +503,35 @@ export class AdminClient extends DriftClient {
476503
);
477504
}
478505

506+
public async deleteOpenbookV2FulfillmentConfig(
507+
openbookMarket: PublicKey
508+
): Promise<TransactionSignature> {
509+
const deleteIx = await this.getDeleteOpenbookV2FulfillmentConfigIx(
510+
openbookMarket
511+
);
512+
const tx = await this.buildTransaction(deleteIx);
513+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
514+
return txSig;
515+
}
516+
517+
public async getDeleteOpenbookV2FulfillmentConfigIx(
518+
openbookMarket: PublicKey
519+
): Promise<TransactionInstruction> {
520+
const openbookV2FulfillmentConfig = getOpenbookV2FulfillmentConfigPublicKey(
521+
this.program.programId,
522+
openbookMarket
523+
);
524+
return await this.program.instruction.deleteOpenbookV2FulfillmentConfig({
525+
accounts: {
526+
admin: this.isSubscribed
527+
? this.getStateAccount().admin
528+
: this.wallet.publicKey,
529+
state: await this.getStatePublicKey(),
530+
openbookV2FulfillmentConfig,
531+
},
532+
});
533+
}
534+
479535
public async initializePerpMarket(
480536
marketIndex: number,
481537
priceOracle: PublicKey,

sdk/src/idl/drift.json

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4220,6 +4220,27 @@
42204220
}
42214221
]
42224222
},
4223+
{
4224+
"name": "deleteSerumFulfillmentConfig",
4225+
"accounts": [
4226+
{
4227+
"name": "state",
4228+
"isMut": false,
4229+
"isSigner": false
4230+
},
4231+
{
4232+
"name": "serumFulfillmentConfig",
4233+
"isMut": true,
4234+
"isSigner": false
4235+
},
4236+
{
4237+
"name": "admin",
4238+
"isMut": true,
4239+
"isSigner": true
4240+
}
4241+
],
4242+
"args": []
4243+
},
42234244
{
42244245
"name": "initializeOpenbookV2FulfillmentConfig",
42254246
"accounts": [
@@ -4309,6 +4330,27 @@
43094330
}
43104331
]
43114332
},
4333+
{
4334+
"name": "deleteOpenbookV2FulfillmentConfig",
4335+
"accounts": [
4336+
{
4337+
"name": "state",
4338+
"isMut": false,
4339+
"isSigner": false
4340+
},
4341+
{
4342+
"name": "openbookV2FulfillmentConfig",
4343+
"isMut": true,
4344+
"isSigner": false
4345+
},
4346+
{
4347+
"name": "admin",
4348+
"isMut": true,
4349+
"isSigner": true
4350+
}
4351+
],
4352+
"args": []
4353+
},
43124354
{
43134355
"name": "initializePhoenixFulfillmentConfig",
43144356
"accounts": [
@@ -14566,8 +14608,7 @@
1456614608
{
1456714609
"name": "isolatedPositionScaledBalance",
1456814610
"docs": [
14569-
"The last base asset amount per lp the amm had",
14570-
"Used to settle the users lp position",
14611+
"The scaled balance of the isolated position",
1457114612
"precision: SPOT_BALANCE_PRECISION"
1457214613
],
1457314614
"type": "u64"
@@ -16068,6 +16109,9 @@
1606816109
},
1606916110
{
1607016111
"name": "HasBuilder"
16112+
},
16113+
{
16114+
"name": "IsIsolatedPosition"
1607116115
}
1607216116
]
1607316117
}

tests/openbookTest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,8 @@ describe('openbook v2', () => {
482482
);
483483
assert(openOrdersAccountParsedData.position.baseFreeNative.eq(new BN(1e9)));
484484
});
485+
486+
it('delete openbook v2 fulfillment config', async () => {
487+
await driftClient.deleteOpenbookV2FulfillmentConfig(market.publicKey);
488+
});
485489
});

tests/serumTest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,4 +704,8 @@ describe('serum spot market', () => {
704704

705705
await crankMarkets();
706706
});
707+
708+
it('Delete Serum Fulfillment Config', async () => {
709+
await makerDriftClient.deleteSerumFulfillmentConfig(serumMarketPublicKey);
710+
});
707711
});

0 commit comments

Comments
 (0)