Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

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

### Fixes

Expand Down
50 changes: 44 additions & 6 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ pub fn handle_update_serum_fulfillment_config_status(
Ok(())
}

pub fn handle_delete_serum_fulfillment_config(
_ctx: Context<DeleteSerumFulfillmentConfig>,
) -> Result<()> {
msg!("deleted serum fulfillment config");
Ok(())
}

pub fn handle_update_serum_vault(ctx: Context<UpdateSerumVault>) -> Result<()> {
let vault = &ctx.accounts.srm_vault;
validate!(
Expand Down Expand Up @@ -610,6 +617,13 @@ pub fn handle_update_openbook_v2_fulfillment_config_status(
Ok(())
}

pub fn handle_delete_openbook_v2_fulfillment_config(
_ctx: Context<DeleteOpenbookV2FulfillmentConfig>,
) -> Result<()> {
msg!("deleted openbook v2 fulfillment config");
Ok(())
}

pub fn handle_initialize_phoenix_fulfillment_config(
ctx: Context<InitializePhoenixFulfillmentConfig>,
market_index: u16,
Expand Down Expand Up @@ -5370,13 +5384,25 @@ pub struct InitializeSerumFulfillmentConfig<'info> {

#[derive(Accounts)]
pub struct UpdateSerumFulfillmentConfig<'info> {
pub state: Box<Account<'info, State>>,
#[account(mut)]
pub serum_fulfillment_config: AccountLoader<'info, SerumV3FulfillmentConfig>,
#[account(
has_one = admin
mut,
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
)]
pub admin: Signer<'info>,
}

#[derive(Accounts)]
pub struct DeleteSerumFulfillmentConfig<'info> {
pub state: Box<Account<'info, State>>,
#[account(mut)]
#[account(mut, close = admin)]
pub serum_fulfillment_config: AccountLoader<'info, SerumV3FulfillmentConfig>,
#[account(mut)]
#[account(
mut,
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
)]
pub admin: Signer<'info>,
}

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

#[derive(Accounts)]
pub struct UpdateOpenbookV2FulfillmentConfig<'info> {
pub state: Box<Account<'info, State>>,
#[account(mut)]
pub openbook_v2_fulfillment_config: AccountLoader<'info, OpenbookV2FulfillmentConfig>,
#[account(
has_one = admin
mut,
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
)]
pub admin: Signer<'info>,
}

#[derive(Accounts)]
pub struct DeleteOpenbookV2FulfillmentConfig<'info> {
pub state: Box<Account<'info, State>>,
#[account(mut)]
#[account(mut, close = admin)]
pub openbook_v2_fulfillment_config: AccountLoader<'info, OpenbookV2FulfillmentConfig>,
#[account(mut)]
#[account(
mut,
constraint = admin.key() == state.admin || admin.key() == admin_hot_wallet::id()
)]
pub admin: Signer<'info>,
}

Expand Down
13 changes: 13 additions & 0 deletions programs/drift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,12 @@ pub mod drift {
handle_update_serum_fulfillment_config_status(ctx, status)
}

pub fn delete_serum_fulfillment_config(
ctx: Context<DeleteSerumFulfillmentConfig>,
) -> Result<()> {
handle_delete_serum_fulfillment_config(ctx)
}

pub fn initialize_openbook_v2_fulfillment_config(
ctx: Context<InitializeOpenbookV2FulfillmentConfig>,
market_index: u16,
Expand All @@ -978,6 +984,13 @@ pub mod drift {
) -> Result<()> {
handle_update_openbook_v2_fulfillment_config_status(ctx, status)
}

pub fn delete_openbook_v2_fulfillment_config(
ctx: Context<DeleteOpenbookV2FulfillmentConfig>,
) -> Result<()> {
handle_delete_openbook_v2_fulfillment_config(ctx)
}

pub fn initialize_phoenix_fulfillment_config(
ctx: Context<InitializePhoenixFulfillmentConfig>,
market_index: u16,
Expand Down
56 changes: 56 additions & 0 deletions sdk/src/adminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,33 @@ export class AdminClient extends DriftClient {
);
}

public async deleteSerumFulfillmentConfig(
serumMarket: PublicKey
): Promise<TransactionSignature> {
const deleteIx = await this.getDeleteSerumFulfillmentConfigIx(serumMarket);
const tx = await this.buildTransaction(deleteIx);
const { txSig } = await this.sendTransaction(tx, [], this.opts);
return txSig;
}

public async getDeleteSerumFulfillmentConfigIx(
serumMarket: PublicKey
): Promise<TransactionInstruction> {
const serumFulfillmentConfig = getSerumFulfillmentConfigPublicKey(
this.program.programId,
serumMarket
);
return await this.program.instruction.deleteSerumFulfillmentConfig({
accounts: {
admin: this.isSubscribed
? this.getStateAccount().admin
: this.wallet.publicKey,
state: await this.getStatePublicKey(),
serumFulfillmentConfig,
},
});
}

public async initializePhoenixFulfillmentConfig(
marketIndex: number,
phoenixMarket: PublicKey
Expand Down Expand Up @@ -476,6 +503,35 @@ export class AdminClient extends DriftClient {
);
}

public async deleteOpenbookV2FulfillmentConfig(
openbookMarket: PublicKey
): Promise<TransactionSignature> {
const deleteIx = await this.getDeleteOpenbookV2FulfillmentConfigIx(
openbookMarket
);
const tx = await this.buildTransaction(deleteIx);
const { txSig } = await this.sendTransaction(tx, [], this.opts);
return txSig;
}

public async getDeleteOpenbookV2FulfillmentConfigIx(
openbookMarket: PublicKey
): Promise<TransactionInstruction> {
const openbookV2FulfillmentConfig = getOpenbookV2FulfillmentConfigPublicKey(
this.program.programId,
openbookMarket
);
return await this.program.instruction.deleteOpenbookV2FulfillmentConfig({
accounts: {
admin: this.isSubscribed
? this.getStateAccount().admin
: this.wallet.publicKey,
state: await this.getStatePublicKey(),
openbookV2FulfillmentConfig,
},
});
}

public async initializePerpMarket(
marketIndex: number,
priceOracle: PublicKey,
Expand Down
48 changes: 46 additions & 2 deletions sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
Expand Up @@ -4220,6 +4220,27 @@
}
]
},
{
"name": "deleteSerumFulfillmentConfig",
"accounts": [
{
"name": "state",
"isMut": false,
"isSigner": false
},
{
"name": "serumFulfillmentConfig",
"isMut": true,
"isSigner": false
},
{
"name": "admin",
"isMut": true,
"isSigner": true
}
],
"args": []
},
{
"name": "initializeOpenbookV2FulfillmentConfig",
"accounts": [
Expand Down Expand Up @@ -4309,6 +4330,27 @@
}
]
},
{
"name": "deleteOpenbookV2FulfillmentConfig",
"accounts": [
{
"name": "state",
"isMut": false,
"isSigner": false
},
{
"name": "openbookV2FulfillmentConfig",
"isMut": true,
"isSigner": false
},
{
"name": "admin",
"isMut": true,
"isSigner": true
}
],
"args": []
},
{
"name": "initializePhoenixFulfillmentConfig",
"accounts": [
Expand Down Expand Up @@ -14566,8 +14608,7 @@
{
"name": "isolatedPositionScaledBalance",
"docs": [
"The last base asset amount per lp the amm had",
"Used to settle the users lp position",
"The scaled balance of the isolated position",
"precision: SPOT_BALANCE_PRECISION"
],
"type": "u64"
Expand Down Expand Up @@ -16068,6 +16109,9 @@
},
{
"name": "HasBuilder"
},
{
"name": "IsIsolatedPosition"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions tests/openbookTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,8 @@ describe('openbook v2', () => {
);
assert(openOrdersAccountParsedData.position.baseFreeNative.eq(new BN(1e9)));
});

it('delete openbook v2 fulfillment config', async () => {
await driftClient.deleteOpenbookV2FulfillmentConfig(market.publicKey);
});
});
4 changes: 4 additions & 0 deletions tests/serumTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,8 @@ describe('serum spot market', () => {

await crankMarkets();
});

it('Delete Serum Fulfillment Config', async () => {
await makerDriftClient.deleteSerumFulfillmentConfig(serumMarketPublicKey);
});
});
Loading