Skip to content

Commit 72a5e42

Browse files
authored
include new amm inventory limit (#1932)
1 parent 60a9231 commit 72a5e42

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

programs/drift/src/instructions/lp_admin.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ pub struct OverrideAmmCacheParams {
944944
pub last_fee_pool_token_amount: Option<u128>,
945945
pub last_net_pnl_pool_token_amount: Option<i128>,
946946
pub amm_position_scalar: Option<u8>,
947+
pub amm_inventory_limit: Option<i64>,
947948
}
948949

949950
pub fn handle_override_amm_cache_info<'c: 'info, 'info>(
@@ -977,6 +978,14 @@ pub fn handle_override_amm_cache_info<'c: 'info, 'info>(
977978
cache_entry.amm_position_scalar = amm_position_scalar;
978979
}
979980

981+
if let Some(amm_position_scalar) = override_params.amm_position_scalar {
982+
cache_entry.amm_position_scalar = amm_position_scalar;
983+
}
984+
985+
if let Some(amm_inventory_limit) = override_params.amm_inventory_limit {
986+
cache_entry.amm_inventory_limit = amm_inventory_limit;
987+
}
988+
980989
Ok(())
981990
}
982991

programs/drift/src/instructions/lp_pool.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ pub fn handle_update_constituent_target_base<'c: 'info, 'info>(
134134
inventory: cache_info
135135
.position
136136
.safe_mul(cache_info.amm_position_scalar as i64)?
137-
.safe_div(100)?,
137+
.safe_div(100)?
138+
.abs()
139+
.min(cache_info.amm_inventory_limit)
140+
.safe_mul(cache_info.position.signum())?,
138141
price: cache_info.oracle_price,
139142
});
140143
}

programs/drift/src/state/amm_cache.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,18 @@ pub struct CacheInfo {
5050
pub last_settle_slot: u64,
5151
pub last_settle_ts: i64,
5252
pub quote_owed_from_lp_pool: i64,
53+
pub amm_inventory_limit: i64,
5354
pub oracle_price: i64,
5455
pub oracle_slot: u64,
5556
pub oracle_source: u8,
5657
pub oracle_validity: u8,
5758
pub lp_status_for_perp_market: u8,
5859
pub amm_position_scalar: u8,
59-
pub _padding: [u8; 12],
60+
_padding: [u8; 28],
6061
}
6162

6263
impl Size for CacheInfo {
63-
const SIZE: usize = 192;
64+
const SIZE: usize = 224;
6465
}
6566

6667
impl Default for CacheInfo {
@@ -80,11 +81,12 @@ impl Default for CacheInfo {
8081
last_settle_ts: 0i64,
8182
last_settle_amm_pnl: 0i128,
8283
last_settle_amm_ex_fees: 0u128,
84+
amm_inventory_limit: 0i64,
8385
oracle_source: 0u8,
8486
quote_owed_from_lp_pool: 0i64,
8587
lp_status_for_perp_market: 0u8,
86-
amm_position_scalar: 100u8,
87-
_padding: [0u8; 12],
88+
amm_position_scalar: 0u8,
89+
_padding: [0u8; 28],
8890
}
8991
}
9092
}

sdk/src/adminClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ export class AdminClient extends DriftClient {
715715
lastFeePoolTokenAmount?: BN;
716716
lastNetPnlPoolTokenAmount?: BN;
717717
ammPositionScalar?: number;
718+
ammInventoryLimit?: BN;
718719
},
719720
txParams?: TxParams
720721
): Promise<TransactionSignature> {
@@ -737,6 +738,7 @@ export class AdminClient extends DriftClient {
737738
lastFeePoolTokenAmount?: BN;
738739
lastNetPnlPoolTokenAmount?: BN;
739740
ammPositionScalar?: number;
741+
ammInventoryLimit?: BN;
740742
}
741743
): Promise<TransactionInstruction> {
742744
return this.program.instruction.overrideAmmCacheInfo(
@@ -749,6 +751,7 @@ export class AdminClient extends DriftClient {
749751
lastFeePoolTokenAmount: null,
750752
lastNetPnlPoolTokenAmount: null,
751753
ammPositionScalar: null,
754+
ammInventoryLimit: null,
752755
},
753756
params
754757
),

sdk/src/idl/drift.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12074,6 +12074,12 @@
1207412074
"type": {
1207512075
"option": "u8"
1207612076
}
12077+
},
12078+
{
12079+
"name": "ammInventoryLimit",
12080+
"type": {
12081+
"option": "i64"
12082+
}
1207712083
}
1207812084
]
1207912085
}
@@ -12154,6 +12160,10 @@
1215412160
"name": "quoteOwedFromLpPool",
1215512161
"type": "i64"
1215612162
},
12163+
{
12164+
"name": "ammInventoryLimit",
12165+
"type": "i64"
12166+
},
1215712167
{
1215812168
"name": "oraclePrice",
1215912169
"type": "i64"
@@ -12183,7 +12193,7 @@
1218312193
"type": {
1218412194
"array": [
1218512195
"u8",
12186-
12
12196+
28
1218712197
]
1218812198
}
1218912199
}

sdk/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,9 +1415,9 @@ export interface IWallet {
14151415
publicKey: PublicKey;
14161416
payer?: Keypair;
14171417
supportedTransactionVersions?:
1418-
| ReadonlySet<TransactionVersion>
1419-
| null
1420-
| undefined;
1418+
| ReadonlySet<TransactionVersion>
1419+
| null
1420+
| undefined;
14211421
}
14221422
export interface IVersionedWallet {
14231423
signVersionedTransaction(

tests/lpPool.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,19 @@ describe('LP Pool', () => {
722722
);
723723
await adminClient.updateAmmCache([0, 1, 2]);
724724

725+
await adminClient.overrideAmmCacheInfo(0, {
726+
ammPositionScalar: 100,
727+
ammInventoryLimit: BASE_PRECISION.muln(5000),
728+
});
729+
await adminClient.overrideAmmCacheInfo(1, {
730+
ammPositionScalar: 100,
731+
ammInventoryLimit: BASE_PRECISION.muln(5000),
732+
});
733+
await adminClient.overrideAmmCacheInfo(2, {
734+
ammPositionScalar: 100,
735+
ammInventoryLimit: BASE_PRECISION.muln(5000),
736+
});
737+
725738
let tx = new Transaction();
726739
tx.add(await adminClient.getUpdateAmmCacheIx([0, 1, 2]));
727740
tx.add(

0 commit comments

Comments
 (0)