Skip to content

Commit dac033a

Browse files
committed
merge devnet
2 parents 54088e6 + 722f553 commit dac033a

File tree

7 files changed

+134
-15
lines changed

7 files changed

+134
-15
lines changed

programs/drift/src/instructions/admin.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,11 @@ pub fn handle_resize_amm_cache(ctx: Context<ResizeAmmCache>) -> Result<()> {
11661166
Ok(())
11671167
}
11681168

1169+
pub fn handle_delete_amm_cache(_ctx: Context<DeleteAmmCache>) -> Result<()> {
1170+
msg!("deleted amm cache");
1171+
Ok(())
1172+
}
1173+
11691174
#[access_control(
11701175
perp_market_valid(&ctx.accounts.perp_market)
11711176
)]
@@ -5563,6 +5568,23 @@ pub struct ResizeAmmCache<'info> {
55635568
pub system_program: Program<'info, System>,
55645569
}
55655570

5571+
#[derive(Accounts)]
5572+
pub struct DeleteAmmCache<'info> {
5573+
#[account(mut)]
5574+
pub admin: Signer<'info>,
5575+
#[account(
5576+
has_one = admin
5577+
)]
5578+
pub state: Box<Account<'info, State>>,
5579+
#[account(
5580+
mut,
5581+
seeds = [AMM_POSITIONS_CACHE.as_ref()],
5582+
bump,
5583+
close = admin,
5584+
)]
5585+
pub amm_cache: Box<Account<'info, AmmCache>>,
5586+
}
5587+
55665588
#[derive(Accounts)]
55675589
pub struct DeleteInitializedPerpMarket<'info> {
55685590
#[account(mut)]

programs/drift/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,18 @@ pub mod drift {
10621062
handle_initialize_amm_cache(ctx)
10631063
}
10641064

1065+
pub fn resize_amm_cache<'c: 'info, 'info>(
1066+
ctx: Context<'_, '_, 'c, 'info, ResizeAmmCache<'info>>,
1067+
) -> Result<()> {
1068+
handle_resize_amm_cache(ctx)
1069+
}
1070+
1071+
pub fn delete_amm_cache<'c: 'info, 'info>(
1072+
ctx: Context<'_, '_, 'c, 'info, DeleteAmmCache<'info>>,
1073+
) -> Result<()> {
1074+
handle_delete_amm_cache(ctx)
1075+
}
1076+
10651077
pub fn update_initial_amm_cache_info<'c: 'info, 'info>(
10661078
ctx: Context<'_, '_, 'c, 'info, UpdateInitialAmmCacheInfo<'info>>,
10671079
) -> Result<()> {

sdk/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.146.0-beta.2
1+
2.146.0-beta.3

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@drift-labs/sdk",
3-
"version": "2.146.0-beta.2",
3+
"version": "2.146.0-beta.3",
44
"main": "lib/node/index.js",
55
"types": "lib/node/index.d.ts",
66
"module": "./lib/browser/index.js",

sdk/src/adminClient.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ export class AdminClient extends DriftClient {
665665
public async resizeAmmCache(
666666
txParams?: TxParams
667667
): Promise<TransactionSignature> {
668-
const initializeAmmCacheIx = await this.getInitializeAmmCacheIx();
668+
const initializeAmmCacheIx = await this.getResizeAmmCacheIx();
669669

670670
const tx = await this.buildTransaction(initializeAmmCacheIx, txParams);
671671

@@ -688,6 +688,28 @@ export class AdminClient extends DriftClient {
688688
});
689689
}
690690

691+
public async deleteAmmCache(
692+
txParams?: TxParams
693+
): Promise<TransactionSignature> {
694+
const deleteAmmCacheIx = await this.getDeleteAmmCacheIx();
695+
696+
const tx = await this.buildTransaction(deleteAmmCacheIx, txParams);
697+
698+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
699+
700+
return txSig;
701+
}
702+
703+
public async getDeleteAmmCacheIx(): Promise<TransactionInstruction> {
704+
return await this.program.instruction.deleteAmmCache({
705+
accounts: {
706+
state: await this.getStatePublicKey(),
707+
admin: this.getStateAccount().admin,
708+
ammCache: getAmmCachePublicKey(this.program.programId),
709+
},
710+
});
711+
}
712+
691713
public async updateInitialAmmCacheInfo(
692714
perpMarketIndexes: number[],
693715
txParams?: TxParams

sdk/src/idl/drift.json

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4610,6 +4610,58 @@
46104610
],
46114611
"args": []
46124612
},
4613+
{
4614+
"name": "resizeAmmCache",
4615+
"accounts": [
4616+
{
4617+
"name": "admin",
4618+
"isMut": true,
4619+
"isSigner": true
4620+
},
4621+
{
4622+
"name": "state",
4623+
"isMut": false,
4624+
"isSigner": false
4625+
},
4626+
{
4627+
"name": "ammCache",
4628+
"isMut": true,
4629+
"isSigner": false
4630+
},
4631+
{
4632+
"name": "rent",
4633+
"isMut": false,
4634+
"isSigner": false
4635+
},
4636+
{
4637+
"name": "systemProgram",
4638+
"isMut": false,
4639+
"isSigner": false
4640+
}
4641+
],
4642+
"args": []
4643+
},
4644+
{
4645+
"name": "deleteAmmCache",
4646+
"accounts": [
4647+
{
4648+
"name": "admin",
4649+
"isMut": true,
4650+
"isSigner": true
4651+
},
4652+
{
4653+
"name": "state",
4654+
"isMut": false,
4655+
"isSigner": false
4656+
},
4657+
{
4658+
"name": "ammCache",
4659+
"isMut": true,
4660+
"isSigner": false
4661+
}
4662+
],
4663+
"args": []
4664+
},
46134665
{
46144666
"name": "updateInitialAmmCacheInfo",
46154667
"accounts": [
@@ -13215,12 +13267,6 @@
1321513267
"type": {
1321613268
"option": "u16"
1321713269
}
13218-
},
13219-
{
13220-
"name": "isolatedPositionDeposit",
13221-
"type": {
13222-
"option": "u64"
13223-
}
1322413270
}
1322513271
]
1322613272
}
@@ -13286,12 +13332,6 @@
1328613332
"type": {
1328713333
"option": "u16"
1328813334
}
13289-
},
13290-
{
13291-
"name": "isolatedPositionDeposit",
13292-
"type": {
13293-
"option": "u64"
13294-
}
1329513335
}
1329613336
]
1329713337
}

tests/lpPool.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,4 +1733,27 @@ describe('LP Pool', () => {
17331733
assert(e.message.includes('0x18'));
17341734
}
17351735
});
1736+
1737+
it('can delete amm cache and then init and realloc and update', async () => {
1738+
const ammCacheKey = getAmmCachePublicKey(program.programId);
1739+
const ammCacheBefore = (await adminClient.program.account.ammCache.fetch(
1740+
ammCacheKey
1741+
)) as AmmCache;
1742+
1743+
await adminClient.deleteAmmCache();
1744+
await adminClient.initializeAmmCache();
1745+
await adminClient.resizeAmmCache();
1746+
await adminClient.updateInitialAmmCacheInfo([0, 1, 2]);
1747+
await adminClient.updateAmmCache([0, 1, 2]);
1748+
1749+
const ammCacheAfter = (await adminClient.program.account.ammCache.fetch(
1750+
ammCacheKey
1751+
)) as AmmCache;
1752+
1753+
for (let i = 0; i < ammCacheBefore.cache.length; i++) {
1754+
assert(
1755+
ammCacheBefore.cache[i].position.eq(ammCacheAfter.cache[i].position)
1756+
);
1757+
}
1758+
});
17361759
});

0 commit comments

Comments
 (0)