diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c5f9697..70089b8f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/programs/drift/src/instructions/admin.rs b/programs/drift/src/instructions/admin.rs index 607eaeced..d348fdbc9 100644 --- a/programs/drift/src/instructions/admin.rs +++ b/programs/drift/src/instructions/admin.rs @@ -512,6 +512,13 @@ pub fn handle_update_serum_fulfillment_config_status( Ok(()) } +pub fn handle_delete_serum_fulfillment_config( + _ctx: Context, +) -> Result<()> { + msg!("deleted serum fulfillment config"); + Ok(()) +} + pub fn handle_update_serum_vault(ctx: Context) -> Result<()> { let vault = &ctx.accounts.srm_vault; validate!( @@ -610,6 +617,13 @@ pub fn handle_update_openbook_v2_fulfillment_config_status( Ok(()) } +pub fn handle_delete_openbook_v2_fulfillment_config( + _ctx: Context, +) -> Result<()> { + msg!("deleted openbook v2 fulfillment config"); + Ok(()) +} + pub fn handle_initialize_phoenix_fulfillment_config( ctx: Context, market_index: u16, @@ -5370,13 +5384,25 @@ pub struct InitializeSerumFulfillmentConfig<'info> { #[derive(Accounts)] pub struct UpdateSerumFulfillmentConfig<'info> { + pub state: Box>, + #[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(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>, } @@ -5949,13 +5975,25 @@ pub struct InitializeOpenbookV2FulfillmentConfig<'info> { #[derive(Accounts)] pub struct UpdateOpenbookV2FulfillmentConfig<'info> { + pub state: Box>, + #[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(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>, } diff --git a/programs/drift/src/lib.rs b/programs/drift/src/lib.rs index df9d1431d..fe0b403e4 100644 --- a/programs/drift/src/lib.rs +++ b/programs/drift/src/lib.rs @@ -965,6 +965,12 @@ pub mod drift { handle_update_serum_fulfillment_config_status(ctx, status) } + pub fn delete_serum_fulfillment_config( + ctx: Context, + ) -> Result<()> { + handle_delete_serum_fulfillment_config(ctx) + } + pub fn initialize_openbook_v2_fulfillment_config( ctx: Context, market_index: u16, @@ -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, + ) -> Result<()> { + handle_delete_openbook_v2_fulfillment_config(ctx) + } + pub fn initialize_phoenix_fulfillment_config( ctx: Context, market_index: u16, diff --git a/sdk/src/adminClient.ts b/sdk/src/adminClient.ts index e6533d5a4..d82726f79 100644 --- a/sdk/src/adminClient.ts +++ b/sdk/src/adminClient.ts @@ -384,6 +384,33 @@ export class AdminClient extends DriftClient { ); } + public async deleteSerumFulfillmentConfig( + serumMarket: PublicKey + ): Promise { + 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 { + 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 @@ -476,6 +503,35 @@ export class AdminClient extends DriftClient { ); } + public async deleteOpenbookV2FulfillmentConfig( + openbookMarket: PublicKey + ): Promise { + 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 { + 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, diff --git a/sdk/src/idl/drift.json b/sdk/src/idl/drift.json index 10f48d2cd..ae07109fd 100644 --- a/sdk/src/idl/drift.json +++ b/sdk/src/idl/drift.json @@ -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": [ @@ -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": [ @@ -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" @@ -16068,6 +16109,9 @@ }, { "name": "HasBuilder" + }, + { + "name": "IsIsolatedPosition" } ] } diff --git a/tests/openbookTest.ts b/tests/openbookTest.ts index 3d57b25d9..dbf117db2 100644 --- a/tests/openbookTest.ts +++ b/tests/openbookTest.ts @@ -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); + }); }); diff --git a/tests/serumTest.ts b/tests/serumTest.ts index 7ede64540..a03c9d309 100644 --- a/tests/serumTest.ts +++ b/tests/serumTest.ts @@ -704,4 +704,8 @@ describe('serum spot market', () => { await crankMarkets(); }); + + it('Delete Serum Fulfillment Config', async () => { + await makerDriftClient.deleteSerumFulfillmentConfig(serumMarketPublicKey); + }); });