Skip to content

Commit ec2bec3

Browse files
committed
update tests and amm cache iteration method
1 parent 571c731 commit ec2bec3

File tree

4 files changed

+4
-18
lines changed

4 files changed

+4
-18
lines changed

programs/drift/src/instructions/lp_pool.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ pub fn handle_update_constituent_target_base<'c: 'info, 'info>(
101101
let mut amm_inventories: Vec<AmmInventoryAndPrices> =
102102
Vec::with_capacity(amm_cache.len() as usize);
103103
for (idx, cache_info) in amm_cache.iter().enumerate() {
104+
if cache_info.lp_status_for_perp_market == 0 {
105+
continue;
106+
}
104107
if !is_oracle_valid_for_action(
105108
OracleValidity::try_from(cache_info.oracle_validity)?,
106109
Some(DriftAction::UpdateLpConstituentTargetBase),
@@ -126,7 +129,6 @@ pub fn handle_update_constituent_target_base<'c: 'info, 'info>(
126129
}
127130

128131
amm_inventories.push(AmmInventoryAndPrices {
129-
perp_market_index: idx as u16,
130132
inventory: cache_info.position,
131133
price: cache_info.oracle_price,
132134
});

programs/drift/src/state/lp_pool.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,6 @@ pub fn calculate_target_weight(
11881188

11891189
/// Update target base based on amm_inventory and mapping
11901190
pub struct AmmInventoryAndPrices {
1191-
pub perp_market_index: u16,
11921191
pub inventory: i64,
11931192
pub price: i64,
11941193
}
@@ -1212,12 +1211,7 @@ impl<'a> AccountZeroCopyMut<'a, TargetsDatum, ConstituentTargetBaseFixed> {
12121211

12131212
// Precompute notional by perp market index
12141213
let mut notionals: Vec<i128> = Vec::with_capacity(amm_inventory_and_prices.len());
1215-
for &AmmInventoryAndPrices {
1216-
perp_market_index,
1217-
inventory,
1218-
price,
1219-
} in amm_inventory_and_prices.iter()
1220-
{
1214+
for &AmmInventoryAndPrices { inventory, price } in amm_inventory_and_prices.iter() {
12211215
let notional = (inventory as i128)
12221216
.safe_mul(price as i128)?
12231217
.safe_div(BASE_PRECISION_I128)?;

programs/drift/src/state/lp_pool/tests.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,18 @@ mod tests {
7070

7171
let amm_inventory_and_price: Vec<AmmInventoryAndPrices> = vec![
7272
AmmInventoryAndPrices {
73-
perp_market_index: 0,
7473
inventory: 4 * BASE_PRECISION_I64,
7574
price: 100_000 * PRICE_PRECISION_I64,
7675
}, // $400k BTC
7776
AmmInventoryAndPrices {
78-
perp_market_index: 1,
7977
inventory: 2000 * BASE_PRECISION_I64,
8078
price: 200 * PRICE_PRECISION_I64,
8179
}, // $400k SOL
8280
AmmInventoryAndPrices {
83-
perp_market_index: 2,
8481
inventory: 200 * BASE_PRECISION_I64,
8582
price: 1500 * PRICE_PRECISION_I64,
8683
}, // $300k ETH
8784
AmmInventoryAndPrices {
88-
perp_market_index: 3,
8985
inventory: 16500 * BASE_PRECISION_I64,
9086
price: PRICE_PRECISION_I64,
9187
}, // $16.5k FARTCOIN
@@ -186,7 +182,6 @@ mod tests {
186182
};
187183

188184
let amm_inventory_and_prices: Vec<AmmInventoryAndPrices> = vec![AmmInventoryAndPrices {
189-
perp_market_index: 0,
190185
inventory: 1_000_000,
191186
price: 1_000_000,
192187
}];
@@ -254,7 +249,6 @@ mod tests {
254249

255250
let price = PRICE_PRECISION_I64;
256251
let amm_inventory_and_prices: Vec<AmmInventoryAndPrices> = vec![AmmInventoryAndPrices {
257-
perp_market_index: 0,
258252
inventory: BASE_PRECISION_I64,
259253
price,
260254
}];
@@ -344,7 +338,6 @@ mod tests {
344338
};
345339

346340
let amm_inventory_and_prices: Vec<AmmInventoryAndPrices> = vec![AmmInventoryAndPrices {
347-
perp_market_index: 0,
348341
inventory: 1_000_000_000,
349342
price: 1_000_000,
350343
}];
@@ -433,7 +426,6 @@ mod tests {
433426
};
434427

435428
let amm_inventory_and_prices: Vec<AmmInventoryAndPrices> = vec![AmmInventoryAndPrices {
436-
perp_market_index: 0,
437429
inventory: 1_000_000,
438430
price: 142_000_000,
439431
}];

tests/lpPoolCUs.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ describe('LP Pool', () => {
256256
await adminClient.initializeLpPool(
257257
lpPoolName,
258258
ZERO,
259-
ZERO,
260-
new BN(3600),
261259
new BN(1_000_000_000_000).mul(QUOTE_PRECISION),
262260
new BN(1_000_000).mul(QUOTE_PRECISION),
263261
new Keypair()

0 commit comments

Comments
 (0)