From 75c7835e4f9a975250975146f7f7c21fd2caad43 Mon Sep 17 00:00:00 2001 From: 0xbigz Date: Mon, 13 Mar 2023 12:05:18 -0400 Subject: [PATCH 1/8] bigz/update-amm-revenue-pool-logic --- programs/drift/src/controller/amm.rs | 56 +++++++++++++++++----- programs/drift/src/controller/amm/tests.rs | 19 +++++--- programs/drift/src/controller/insurance.rs | 8 +++- programs/drift/src/state/perp_market.rs | 2 +- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/programs/drift/src/controller/amm.rs b/programs/drift/src/controller/amm.rs index 97729979e..e68bfdce7 100644 --- a/programs/drift/src/controller/amm.rs +++ b/programs/drift/src/controller/amm.rs @@ -464,7 +464,7 @@ pub fn update_pool_balances( .total_fee_minus_distributions .safe_sub(market.amm.total_fee_withdrawn.cast()?)?; - if terminal_state_surplus < 0 { + if terminal_state_surplus < FEE_POOL_TO_REVENUE_POOL_THRESHOLD.cast()? { // market can perform withdraw from revenue pool if spot_market.insurance_fund.last_revenue_settle_ts > market.insurance_claim.last_revenue_withdraw_ts @@ -482,6 +482,7 @@ pub fn update_pool_balances( let max_revenue_withdraw_allowed = market .insurance_claim .max_revenue_withdraw_per_period + .cast::()? .safe_sub(market.insurance_claim.revenue_withdraw_since_last_settle)? .cast::()?; @@ -516,28 +517,57 @@ pub fn update_pool_balances( market.insurance_claim.last_revenue_withdraw_ts = now; } } else { - let revenue_pool_transfer = get_total_fee_lower_bound(market)? - .cast::()? - .safe_add(market.amm.total_liquidation_fee.cast()?)? - .safe_sub(market.amm.total_fee_withdrawn.cast()?)? - .min( - amm_fee_pool_token_amount_after - .saturating_sub(FEE_POOL_TO_REVENUE_POOL_THRESHOLD) + let total_liq_fees_for_revenue_pool = if market.insurance_claim.quote_max_insurance == 0 + { + 0 + } else { + market.amm.total_liquidation_fee.cast()? + }; + + let max_revenue_to_settle = market + .insurance_claim + .revenue_withdraw_since_last_settle + .safe_add( + market + .insurance_claim + .max_revenue_withdraw_per_period .cast()?, - ) - .max(0) - .unsigned_abs(); + )? + .max(0); + + let fee_pool_threshold = amm_fee_pool_token_amount_after + .saturating_sub(FEE_POOL_TO_REVENUE_POOL_THRESHOLD) + .cast()?; + + let total_fee_for_if = get_total_fee_lower_bound(market)?.cast::()?; + + let revenue_pool_transfer = total_fee_for_if + .safe_add(total_liq_fees_for_revenue_pool)? + .safe_sub(market.amm.total_fee_withdrawn.cast()?)? + .min(fee_pool_threshold) + .min(max_revenue_to_settle.cast()?); + + crate::dlog!(total_fee_for_if); + crate::dlog!(total_liq_fees_for_revenue_pool); + crate::dlog!(fee_pool_threshold); + crate::dlog!(max_revenue_to_settle); + crate::dlog!(revenue_pool_transfer); transfer_spot_balance_to_revenue_pool( - revenue_pool_transfer, + revenue_pool_transfer.unsigned_abs(), spot_market, &mut market.amm.fee_pool, )?; + market.insurance_claim.revenue_withdraw_since_last_settle = market + .insurance_claim + .revenue_withdraw_since_last_settle + .safe_sub(revenue_pool_transfer.cast()?)?; + market.amm.total_fee_withdrawn = market .amm .total_fee_withdrawn - .safe_add(revenue_pool_transfer)?; + .safe_add(revenue_pool_transfer.unsigned_abs())?; } } diff --git a/programs/drift/src/controller/amm/tests.rs b/programs/drift/src/controller/amm/tests.rs index 8fd8a6faf..bb17b5eb8 100644 --- a/programs/drift/src/controller/amm/tests.rs +++ b/programs/drift/src/controller/amm/tests.rs @@ -4,7 +4,7 @@ use crate::math::constants::{ AMM_RESERVE_PRECISION, MAX_CONCENTRATION_COEFFICIENT, PRICE_PRECISION_I64, QUOTE_PRECISION, QUOTE_SPOT_MARKET_INDEX, SPOT_BALANCE_PRECISION, SPOT_CUMULATIVE_INTEREST_PRECISION, }; -use crate::state::perp_market::PoolBalance; +use crate::state::perp_market::{InsuranceClaim, PoolBalance}; #[test] fn concentration_coef_tests() { @@ -571,6 +571,11 @@ fn update_pool_balances_fee_to_revenue_test() { market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, + insurance_claim: InsuranceClaim { + quote_max_insurance: 0, // no liq fees for revenue pool + max_revenue_withdraw_per_period: 1000 * QUOTE_PRECISION as u64, + ..InsuranceClaim::default() + }, ..PerpMarket::default() }; let now = 33928058; @@ -627,10 +632,10 @@ fn update_pool_balances_fee_to_revenue_test() { market.amm.fee_pool.scaled_balance = prev_fee_pool_2; update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 294000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); assert_eq!(market.amm.total_fee_withdrawn, 6000000); + assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); + assert_eq!(market.amm.fee_pool.scaled_balance, 294000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD assert!(market.amm.fee_pool.scaled_balance < prev_fee_pool_2); assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); @@ -817,7 +822,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(market.amm.total_fee_withdrawn, 0); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, - market.insurance_claim.max_revenue_withdraw_per_period + market.insurance_claim.max_revenue_withdraw_per_period as i64 ); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058); @@ -830,7 +835,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, - market.insurance_claim.max_revenue_withdraw_per_period + market.insurance_claim.max_revenue_withdraw_per_period as i64 ); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058); @@ -843,7 +848,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, - market.insurance_claim.max_revenue_withdraw_per_period + market.insurance_claim.max_revenue_withdraw_per_period as i64 ); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058); @@ -909,6 +914,6 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(spot_market.revenue_pool.scaled_balance, 9600000001000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, - market.insurance_claim.max_revenue_withdraw_per_period + market.insurance_claim.max_revenue_withdraw_per_period as i64 ); } diff --git a/programs/drift/src/controller/insurance.rs b/programs/drift/src/controller/insurance.rs index ce82cf9d6..928607b8e 100644 --- a/programs/drift/src/controller/insurance.rs +++ b/programs/drift/src/controller/insurance.rs @@ -695,7 +695,13 @@ pub fn resolve_perp_pnl_deficit( let max_revenue_withdraw_per_period = market .insurance_claim .max_revenue_withdraw_per_period - .safe_sub(market.insurance_claim.revenue_withdraw_since_last_settle)? + .cast::()? + .safe_sub( + market + .insurance_claim + .revenue_withdraw_since_last_settle + .cast()?, + )? .cast::()?; validate!( max_revenue_withdraw_per_period > 0, diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 6a5b611bf..14cd1577d 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -311,7 +311,7 @@ impl PerpMarket { #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct InsuranceClaim { - pub revenue_withdraw_since_last_settle: u64, + pub revenue_withdraw_since_last_settle: i64, pub max_revenue_withdraw_per_period: u64, pub quote_max_insurance: u64, pub quote_settled_insurance: u64, From 1259b77d7c0f4ef38aaa28e33cd1f0b6115712f6 Mon Sep 17 00:00:00 2001 From: 0xbigz Date: Mon, 20 Mar 2023 12:41:46 -0400 Subject: [PATCH 2/8] amm.rs: throttle liq fees to if --- programs/drift/src/controller/amm.rs | 28 ++++++++++++++-------- programs/drift/src/controller/amm/tests.rs | 18 ++++++++++---- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/programs/drift/src/controller/amm.rs b/programs/drift/src/controller/amm.rs index e68bfdce7..d6ac3ae13 100644 --- a/programs/drift/src/controller/amm.rs +++ b/programs/drift/src/controller/amm.rs @@ -517,12 +517,21 @@ pub fn update_pool_balances( market.insurance_claim.last_revenue_withdraw_ts = now; } } else { - let total_liq_fees_for_revenue_pool = if market.insurance_claim.quote_max_insurance == 0 - { - 0 - } else { - market.amm.total_liquidation_fee.cast()? - }; + let fee_pool_threshold = amm_fee_pool_token_amount_after + .saturating_sub(FEE_POOL_TO_REVENUE_POOL_THRESHOLD) + .cast()?; + + let total_liq_fees_for_revenue_pool: i128 = market + .amm + .total_liquidation_fee + .min( + market + .insurance_claim + .quote_settled_insurance + .safe_add(market.insurance_claim.quote_max_insurance)? + .cast()?, + ) + .cast()?; let max_revenue_to_settle = market .insurance_claim @@ -533,12 +542,9 @@ pub fn update_pool_balances( .max_revenue_withdraw_per_period .cast()?, )? + .min(market.amm.net_revenue_since_last_funding) .max(0); - let fee_pool_threshold = amm_fee_pool_token_amount_after - .saturating_sub(FEE_POOL_TO_REVENUE_POOL_THRESHOLD) - .cast()?; - let total_fee_for_if = get_total_fee_lower_bound(market)?.cast::()?; let revenue_pool_transfer = total_fee_for_if @@ -549,6 +555,8 @@ pub fn update_pool_balances( crate::dlog!(total_fee_for_if); crate::dlog!(total_liq_fees_for_revenue_pool); + crate::dlog!(market.amm.total_fee_withdrawn); + crate::dlog!(market.amm.total_liquidation_fee); crate::dlog!(fee_pool_threshold); crate::dlog!(max_revenue_to_settle); crate::dlog!(revenue_pool_transfer); diff --git a/programs/drift/src/controller/amm/tests.rs b/programs/drift/src/controller/amm/tests.rs index bb17b5eb8..b8cedf5bb 100644 --- a/programs/drift/src/controller/amm/tests.rs +++ b/programs/drift/src/controller/amm/tests.rs @@ -556,7 +556,7 @@ fn update_pool_balances_fee_to_revenue_test() { total_mm_fee: 990 * QUOTE_PRECISION as i128, total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, total_liquidation_fee: QUOTE_PRECISION, - + net_revenue_since_last_funding: 10000 * QUOTE_PRECISION as i64, curve_update_intensity: 100, fee_pool: PoolBalance { @@ -633,13 +633,23 @@ fn update_pool_balances_fee_to_revenue_test() { update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); - assert_eq!(market.amm.total_fee_withdrawn, 6000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); - assert_eq!(market.amm.fee_pool.scaled_balance, 294000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD + assert_eq!(market.amm.total_fee_withdrawn, 5000000); + assert_eq!(spot_market.revenue_pool.scaled_balance, 5000000000000000); + assert_eq!(market.amm.fee_pool.scaled_balance, 295000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD assert!(market.amm.fee_pool.scaled_balance < prev_fee_pool_2); assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); assert!(spot_market.revenue_pool.scaled_balance > prev_rev_pool); + + market.insurance_claim.quote_max_insurance = 1; // add min insurance + update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); + assert_eq!(market.amm.total_fee_withdrawn, 5000001); + assert_eq!(spot_market.revenue_pool.scaled_balance, 5000001000000000); + + market.insurance_claim.quote_max_insurance = 100000000; // add lots of insurance + update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); + assert_eq!(market.amm.total_fee_withdrawn, 6000000); + assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); } #[test] From 66663fa5ae7c154ac1505ebcc453dc325bc3cd5d Mon Sep 17 00:00:00 2001 From: 0xbigz Date: Mon, 20 Mar 2023 16:03:29 -0400 Subject: [PATCH 3/8] add test / fix test --- programs/drift/src/controller/amm/tests.rs | 115 +++++++++++++++++++++ sdk/src/idl/drift.json | 2 +- tests/delistMarket.ts | 4 +- 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/programs/drift/src/controller/amm/tests.rs b/programs/drift/src/controller/amm/tests.rs index b8cedf5bb..e33c78601 100644 --- a/programs/drift/src/controller/amm/tests.rs +++ b/programs/drift/src/controller/amm/tests.rs @@ -652,6 +652,121 @@ fn update_pool_balances_fee_to_revenue_test() { assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); } +#[test] +fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { + let mut market = PerpMarket { + amm: AMM { + base_asset_reserve: 5122950819670000, + quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, + sqrt_k: 500 * AMM_RESERVE_PRECISION, + peg_multiplier: 50000, + base_asset_amount_with_amm: -122950819670000, + + total_exchange_fee: 10 * QUOTE_PRECISION, + total_fee: 10 * QUOTE_PRECISION as i128, + total_mm_fee: 990 * QUOTE_PRECISION as i128, + total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + total_liquidation_fee: QUOTE_PRECISION, + net_revenue_since_last_funding: QUOTE_PRECISION as i64, + curve_update_intensity: 100, + + fee_pool: PoolBalance { + scaled_balance: 50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + market_index: QUOTE_SPOT_MARKET_INDEX, + ..PoolBalance::default() + }, + ..AMM::default() + }, + pnl_pool: PoolBalance { + scaled_balance: 50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + market_index: QUOTE_SPOT_MARKET_INDEX, + ..PoolBalance::default() + }, + insurance_claim: InsuranceClaim { + quote_max_insurance: 0, // no liq fees for revenue pool + max_revenue_withdraw_per_period: 1000 * QUOTE_PRECISION as u64, + ..InsuranceClaim::default() + }, + ..PerpMarket::default() + }; + let now = 33928058; + + let mut spot_market = SpotMarket { + deposit_balance: 100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + revenue_pool: PoolBalance::default(), + ..SpotMarket::default() + }; + + let prev_fee_pool = market.amm.fee_pool.scaled_balance; + let prev_pnl_pool = market.amm.fee_pool.scaled_balance; + let prev_rev_pool = spot_market.revenue_pool.scaled_balance; + + assert_eq!(market.amm.total_fee_withdrawn, 0); + + assert_eq!( + get_token_amount( + market.amm.fee_pool.balance(), + &spot_market, + &SpotBalanceType::Deposit + ) + .unwrap(), + 50 * QUOTE_PRECISION + ); + + assert_eq!( + get_token_amount( + spot_market.deposit_balance, + &spot_market, + &SpotBalanceType::Deposit + ) + .unwrap(), + 100 * QUOTE_PRECISION + ); + + let spot_position = SpotPosition::default(); + update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); + + assert_eq!(market.amm.fee_pool.scaled_balance, 50000000000000000); // under FEE_POOL_TO_REVENUE_POOL_THRESHOLD + assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance, 0); + assert_eq!(market.amm.total_fee_withdrawn, 0); + + assert!(market.amm.fee_pool.scaled_balance == prev_fee_pool); + assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); + assert!(spot_market.revenue_pool.scaled_balance == prev_rev_pool); + + // add FEE_POOL_TO_REVENUE_POOL_THRESHOLD + let prev_fee_pool_2 = + (FEE_POOL_TO_REVENUE_POOL_THRESHOLD + 50 * QUOTE_PRECISION) * SPOT_BALANCE_PRECISION; + market.amm.fee_pool.scaled_balance = prev_fee_pool_2; + update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); + + assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); + assert_eq!(market.amm.total_fee_withdrawn, 1000000); + assert_eq!(spot_market.revenue_pool.scaled_balance, 1000000000000000); + assert_eq!(market.amm.fee_pool.scaled_balance, 299000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD + + assert!(market.amm.fee_pool.scaled_balance < prev_fee_pool_2); + assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); + assert!(spot_market.revenue_pool.scaled_balance > prev_rev_pool); + + market.insurance_claim.quote_max_insurance = 1; // add min insurance + market.amm.net_revenue_since_last_funding = 1; + + update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); + assert_eq!(market.amm.total_fee_withdrawn, 1000001); + assert_eq!(spot_market.revenue_pool.scaled_balance, 1000001000000000); + + market.insurance_claim.quote_max_insurance = 100000000; // add lots of insurance + market.amm.net_revenue_since_last_funding = 100000000; + + update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); + assert_eq!(market.amm.total_fee_withdrawn, 6000000); + assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); +} + #[test] fn update_pool_balances_revenue_to_fee_test() { let mut market = PerpMarket { diff --git a/sdk/src/idl/drift.json b/sdk/src/idl/drift.json index 653a78732..4a82d8117 100644 --- a/sdk/src/idl/drift.json +++ b/sdk/src/idl/drift.json @@ -5119,7 +5119,7 @@ "fields": [ { "name": "revenueWithdrawSinceLastSettle", - "type": "u64" + "type": "i64" }, { "name": "maxRevenueWithdrawPerPeriod", diff --git a/tests/delistMarket.ts b/tests/delistMarket.ts index bb8f177c6..b3a1e846a 100644 --- a/tests/delistMarket.ts +++ b/tests/delistMarket.ts @@ -614,7 +614,9 @@ describe('delist market', () => { 'totalExchangeFee:', marketAfter.amm.totalExchangeFee.toString() ); - assert(marketAfter.amm.feePool.scaledBalance.eq(new BN(21567000))); + // assert(marketAfter.amm.feePool.scaledBalance.eq(new BN(21567000))); + assert(marketAfter.amm.feePool.scaledBalance.eq(new BN(64700000))); + // assert(marketAfter.amm.totalExchangeFee.eq(new BN(43134))); assert(marketAfter.amm.totalExchangeFee.eq(new BN(129401))); }); From 4568788c92425757e51860c53d4166301dba1604 Mon Sep 17 00:00:00 2001 From: 0xbigz Date: Tue, 21 Mar 2023 12:24:36 -0400 Subject: [PATCH 4/8] amm.rs update threshold --- programs/drift/src/controller/amm.rs | 4 +++- programs/drift/src/controller/insurance.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/drift/src/controller/amm.rs b/programs/drift/src/controller/amm.rs index d6ac3ae13..904ec018b 100644 --- a/programs/drift/src/controller/amm.rs +++ b/programs/drift/src/controller/amm.rs @@ -518,7 +518,9 @@ pub fn update_pool_balances( } } else { let fee_pool_threshold = amm_fee_pool_token_amount_after - .saturating_sub(FEE_POOL_TO_REVENUE_POOL_THRESHOLD) + .saturating_sub( + FEE_POOL_TO_REVENUE_POOL_THRESHOLD.safe_add(market.amm.total_social_loss)?, + ) .cast()?; let total_liq_fees_for_revenue_pool: i128 = market diff --git a/programs/drift/src/controller/insurance.rs b/programs/drift/src/controller/insurance.rs index 928607b8e..b2b0d5dad 100644 --- a/programs/drift/src/controller/insurance.rs +++ b/programs/drift/src/controller/insurance.rs @@ -580,7 +580,7 @@ pub fn settle_revenue_to_insurance_fund( .max(1), )? .cast::()?; - let capped_token_pct_amount = token_amount.safe_div(5)?; + let capped_token_pct_amount = token_amount.safe_div(10)?; token_amount = capped_token_pct_amount.min(capped_apr_amount); } From 969f29a9fe744793b1ab3f1daa4b2a8470067800 Mon Sep 17 00:00:00 2001 From: 0xbigz Date: Tue, 21 Mar 2023 16:17:11 -0400 Subject: [PATCH 5/8] cleanup --- programs/drift/src/controller/amm.rs | 8 -------- tests/delistMarket.ts | 1 - 2 files changed, 9 deletions(-) diff --git a/programs/drift/src/controller/amm.rs b/programs/drift/src/controller/amm.rs index 904ec018b..4d725bda5 100644 --- a/programs/drift/src/controller/amm.rs +++ b/programs/drift/src/controller/amm.rs @@ -555,14 +555,6 @@ pub fn update_pool_balances( .min(fee_pool_threshold) .min(max_revenue_to_settle.cast()?); - crate::dlog!(total_fee_for_if); - crate::dlog!(total_liq_fees_for_revenue_pool); - crate::dlog!(market.amm.total_fee_withdrawn); - crate::dlog!(market.amm.total_liquidation_fee); - crate::dlog!(fee_pool_threshold); - crate::dlog!(max_revenue_to_settle); - crate::dlog!(revenue_pool_transfer); - transfer_spot_balance_to_revenue_pool( revenue_pool_transfer.unsigned_abs(), spot_market, diff --git a/tests/delistMarket.ts b/tests/delistMarket.ts index b3a1e846a..72f1b670c 100644 --- a/tests/delistMarket.ts +++ b/tests/delistMarket.ts @@ -614,7 +614,6 @@ describe('delist market', () => { 'totalExchangeFee:', marketAfter.amm.totalExchangeFee.toString() ); - // assert(marketAfter.amm.feePool.scaledBalance.eq(new BN(21567000))); assert(marketAfter.amm.feePool.scaledBalance.eq(new BN(64700000))); // assert(marketAfter.amm.totalExchangeFee.eq(new BN(43134))); From 2e7e101e27de24999cdfe302bc4e69eea80f3988 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 22 Mar 2023 16:06:13 -0400 Subject: [PATCH 6/8] fix tests/imbalancePerpPnl.ts --- tests/imbalancePerpPnl.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/imbalancePerpPnl.ts b/tests/imbalancePerpPnl.ts index c20ab4a65..0460548d0 100644 --- a/tests/imbalancePerpPnl.ts +++ b/tests/imbalancePerpPnl.ts @@ -411,7 +411,7 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { ); console.log('pnlimbalance00:', imbalance00.toString()); - assert(imbalance00.eq(new BN(-9821952))); + assert(imbalance00.eq(new BN(-1009821952))); const bank0Value1p5 = driftClientLoserUser.getSpotMarketAssetValue(0); console.log('uL.bank0Value1p5:', bank0Value1p5.toString()); @@ -566,7 +566,7 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { ); console.log('pnlimbalance:', imbalance.toString()); - assert(imbalance.eq(new BN(44462178048))); //44k! :o + assert(imbalance.eq(new BN(43462178048))); //44k! :o console.log( 'lastOraclePrice:', @@ -607,7 +607,7 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { ); console.log('pnlimbalance:', imbalance.toString()); - assert(imbalance.eq(new BN(44462178048))); //44k! :o + assert(imbalance.eq(new BN(43462178048))); //44k! :o console.log( 'lastOraclePrice:', @@ -686,7 +686,7 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { ); console.log('pnlimbalance:', imbalance.toString()); - assert(imbalance.eq(new BN(44_462_178_048))); //44k still :o + assert(imbalance.eq(new BN(43462178048))); //44k still :o assert(perpMarket.insuranceClaim.revenueWithdrawSinceLastSettle.eq(ZERO)); console.log('pnlimbalance:', imbalance.toString()); @@ -884,7 +884,7 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { console.log('pnlimbalance:', imbalance.toString()); assert(imbalance.lt(new BN(44454544927 + 20000))); //44k still :o - assert(imbalance.gt(new BN(44454544927 - 20000))); //44k still :o + assert(imbalance.gt(new BN(43454561797))); //44k still :o console.log( 'revenueWithdrawSinceLastSettle:', From 0564ecdda1ed3c9ef901d92934dc3e90d2617387 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 22 Mar 2023 16:11:16 -0400 Subject: [PATCH 7/8] try fix test again --- tests/imbalancePerpPnl.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/imbalancePerpPnl.ts b/tests/imbalancePerpPnl.ts index 0460548d0..f5aa559fc 100644 --- a/tests/imbalancePerpPnl.ts +++ b/tests/imbalancePerpPnl.ts @@ -883,8 +883,8 @@ describe('imbalanced large perp pnl w/ borrow hitting limits', () => { ); console.log('pnlimbalance:', imbalance.toString()); - assert(imbalance.lt(new BN(44454544927 + 20000))); //44k still :o - assert(imbalance.gt(new BN(43454561797))); //44k still :o + assert(imbalance.lt(new BN(43454561797 + 20000))); //44k still :o + assert(imbalance.gt(new BN(43454561797 - 20000))); //44k still :o console.log( 'revenueWithdrawSinceLastSettle:', From d1769a5a606714a484a2862e0f8eff80b6696d7b Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 22 Mar 2023 16:40:51 -0400 Subject: [PATCH 8/8] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de5eafe2..44ba1f8bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features - sdk: add isUserBankrupt ([#399](https://github.com/drift-labs/protocol-v2/pull/399)) +- program: update revenue pool fund settlement logic ([#398](https://github.com/drift-labs/protocol-v2/pull/398)) ### Fixes