From d2a747f88bd0fadd83fe2eb4c11f49e2c8a7544f Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 13 Nov 2025 15:46:38 +0800 Subject: [PATCH 1/2] use backwards compatible u128/i128 in zero_copy(unsafe) accounts --- Cargo.lock | 2 +- programs/drift/Cargo.toml | 2 +- programs/drift/src/controller/insurance.rs | 37 ++-- programs/drift/src/controller/liquidation.rs | 12 +- programs/drift/src/controller/orders.rs | 12 +- programs/drift/src/controller/spot_balance.rs | 48 ++-- programs/drift/src/instructions/admin.rs | 40 ++-- programs/drift/src/instructions/if_staker.rs | 14 +- programs/drift/src/instructions/keeper.rs | 10 +- programs/drift/src/instructions/lp_admin.rs | 16 +- programs/drift/src/instructions/lp_pool.rs | 68 +++--- programs/drift/src/instructions/user.rs | 115 +++++----- programs/drift/src/math/bn.rs | 205 ++++++++++++++++++ programs/drift/src/math/insurance.rs | 2 +- programs/drift/src/math/liquidation.rs | 3 +- programs/drift/src/math/spot_balance.rs | 14 +- programs/drift/src/math/spot_withdraw.rs | 14 +- .../state/fulfillment_params/openbook_v2.rs | 2 +- .../src/state/fulfillment_params/phoenix.rs | 2 +- .../src/state/fulfillment_params/serum.rs | 2 +- .../src/state/high_leverage_mode_config.rs | 2 +- .../drift/src/state/if_rebalance_config.rs | 2 +- .../drift/src/state/insurance_fund_stake.rs | 29 +-- programs/drift/src/state/lp_pool.rs | 50 +++-- programs/drift/src/state/oracle.rs | 2 +- programs/drift/src/state/perp_market.rs | 2 +- .../src/state/protected_maker_mode_config.rs | 2 +- programs/drift/src/state/pyth_lazer_oracle.rs | 2 +- programs/drift/src/state/revenue_share.rs | 2 +- programs/drift/src/state/spot_market.rs | 56 +++-- programs/drift/src/state/user.rs | 59 +++-- 31 files changed, 575 insertions(+), 253 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6337d630f..34aa6c7449 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -728,9 +728,9 @@ dependencies = [ [[package]] name = "drift-macros" version = "0.1.0" -source = "git+https://github.com/drift-labs/drift-macros.git?rev=c57d87#c57d87e073d13d43f4d1fb09fe6822915a4ccc11" dependencies = [ "quote", + "static_assertions", "syn 1.0.109", ] diff --git a/programs/drift/Cargo.toml b/programs/drift/Cargo.toml index 3fb45115f0..49c9ef8b91 100644 --- a/programs/drift/Cargo.toml +++ b/programs/drift/Cargo.toml @@ -39,7 +39,7 @@ enumflags2 = "0.6.4" phoenix-v1 = { git = "https://github.com/jordy25519/phoenix-v1", branch = "master", features = ["no-entrypoint"] } solana-security-txt = "1.1.0" static_assertions = "1.1.0" -drift-macros = { git = "https://github.com/drift-labs/drift-macros.git", rev = "c57d87" } +drift-macros = { path = "../../../drift-macros" } switchboard = { path = "../switchboard", features = ["no-entrypoint"] } openbook-v2-light = { path = "../openbook_v2", features = ["no-entrypoint"] } switchboard-on-demand = { path = "../switchboard-on-demand", features = ["no-entrypoint"] } diff --git a/programs/drift/src/controller/insurance.rs b/programs/drift/src/controller/insurance.rs index fa53164733..c849495d91 100644 --- a/programs/drift/src/controller/insurance.rs +++ b/programs/drift/src/controller/insurance.rs @@ -220,25 +220,26 @@ pub fn apply_rebase_to_insurance_fund_stake( insurance_fund_stake: &mut InsuranceFundStake, spot_market: &mut SpotMarket, ) -> DriftResult { - if spot_market.insurance_fund.shares_base != insurance_fund_stake.if_base { + if spot_market.insurance_fund.shares_base != insurance_fund_stake.if_base.as_u128() { validate!( - spot_market.insurance_fund.shares_base > insurance_fund_stake.if_base, + spot_market.insurance_fund.shares_base > insurance_fund_stake.if_base.as_u128(), ErrorCode::InvalidIFRebase, "Rebase expo out of bounds" )?; - let expo_diff = (spot_market.insurance_fund.shares_base - insurance_fund_stake.if_base) - .cast::()?; + let expo_diff = (spot_market.insurance_fund.shares_base + - insurance_fund_stake.if_base.as_u128()) + .cast::()?; let rebase_divisor = 10_u128.pow(expo_diff); msg!( "rebasing insurance fund stake: base: {} -> {} ", - insurance_fund_stake.if_base, + insurance_fund_stake.if_base.as_u128(), spot_market.insurance_fund.shares_base, ); - insurance_fund_stake.if_base = spot_market.insurance_fund.shares_base; + insurance_fund_stake.if_base = spot_market.insurance_fund.shares_base.into(); let old_if_shares = insurance_fund_stake.unchecked_if_shares(); let new_if_shares = old_if_shares.safe_div(rebase_divisor)?; @@ -252,7 +253,9 @@ pub fn apply_rebase_to_insurance_fund_stake( insurance_fund_stake.last_withdraw_request_shares = insurance_fund_stake .last_withdraw_request_shares - .safe_div(rebase_divisor)?; + .as_u128() + .safe_div(rebase_divisor)? + .into(); } Ok(()) @@ -267,7 +270,7 @@ pub fn request_remove_insurance_fund_stake( now: i64, ) -> DriftResult { msg!("n_shares {}", n_shares); - insurance_fund_stake.last_withdraw_request_shares = n_shares; + insurance_fund_stake.last_withdraw_request_shares = n_shares.into(); apply_rebase_to_insurance_fund(insurance_vault_amount, spot_market)?; apply_rebase_to_insurance_fund_stake(insurance_fund_stake, spot_market)?; @@ -277,22 +280,22 @@ pub fn request_remove_insurance_fund_stake( let user_if_shares_before = spot_market.insurance_fund.user_shares; validate!( - insurance_fund_stake.last_withdraw_request_shares + insurance_fund_stake.last_withdraw_request_shares.as_u128() <= insurance_fund_stake.checked_if_shares(spot_market)?, ErrorCode::InvalidInsuranceUnstakeSize, "last_withdraw_request_shares exceeds if_shares {} > {}", - insurance_fund_stake.last_withdraw_request_shares, + insurance_fund_stake.last_withdraw_request_shares.as_u128(), insurance_fund_stake.checked_if_shares(spot_market)? )?; validate!( - insurance_fund_stake.if_base == spot_market.insurance_fund.shares_base, + insurance_fund_stake.if_base.as_u128() == spot_market.insurance_fund.shares_base, ErrorCode::InvalidIFRebase, "if stake base != spot market base" )?; insurance_fund_stake.last_withdraw_request_value = if_shares_to_vault_amount( - insurance_fund_stake.last_withdraw_request_shares, + insurance_fund_stake.last_withdraw_request_shares.as_u128(), spot_market.insurance_fund.total_shares, insurance_vault_amount, )? @@ -351,13 +354,13 @@ pub fn cancel_request_remove_insurance_fund_stake( let user_if_shares_before = spot_market.insurance_fund.user_shares; validate!( - insurance_fund_stake.if_base == spot_market.insurance_fund.shares_base, + insurance_fund_stake.if_base.as_u128() == spot_market.insurance_fund.shares_base, ErrorCode::InvalidIFRebase, "if stake base != spot market base" )?; validate!( - insurance_fund_stake.last_withdraw_request_shares != 0, + insurance_fund_stake.last_withdraw_request_shares.as_u128() != 0, ErrorCode::InvalidIFUnstakeCancel, "No withdraw request in progress" )?; @@ -403,7 +406,7 @@ pub fn cancel_request_remove_insurance_fund_stake( user_if_shares_after: spot_market.insurance_fund.user_shares, }); - insurance_fund_stake.last_withdraw_request_shares = 0; + insurance_fund_stake.last_withdraw_request_shares = 0.into(); insurance_fund_stake.last_withdraw_request_value = 0; insurance_fund_stake.last_withdraw_request_ts = now; @@ -432,7 +435,7 @@ pub fn remove_insurance_fund_stake( let total_if_shares_before = spot_market.insurance_fund.total_shares; let user_if_shares_before = spot_market.insurance_fund.user_shares; - let n_shares = insurance_fund_stake.last_withdraw_request_shares; + let n_shares = insurance_fund_stake.last_withdraw_request_shares.as_u128(); validate!( n_shares > 0, @@ -469,7 +472,7 @@ pub fn remove_insurance_fund_stake( spot_market.insurance_fund.user_shares.safe_sub(n_shares)?; // reset insurance_fund_stake withdraw request info - insurance_fund_stake.last_withdraw_request_shares = 0; + insurance_fund_stake.last_withdraw_request_shares = 0.into(); insurance_fund_stake.last_withdraw_request_value = 0; insurance_fund_stake.last_withdraw_request_ts = now; diff --git a/programs/drift/src/controller/liquidation.rs b/programs/drift/src/controller/liquidation.rs index 4e5543d313..24b1cca611 100644 --- a/programs/drift/src/controller/liquidation.rs +++ b/programs/drift/src/controller/liquidation.rs @@ -3602,15 +3602,21 @@ pub fn resolve_spot_bankruptcy( spot_market.cumulative_deposit_interest = spot_market .cumulative_deposit_interest - .safe_sub(cumulative_deposit_interest_delta)?; + .as_u128() + .safe_sub(cumulative_deposit_interest_delta)? + .into(); spot_market.total_social_loss = spot_market .total_social_loss - .safe_add(borrow_amount.cast()?)?; + .as_u128() + .safe_add(borrow_amount.cast()?)? + .into(); spot_market.total_quote_social_loss = spot_market .total_quote_social_loss - .safe_add(quote_social_loss.unsigned_abs().cast()?)?; + .as_u128() + .safe_add(quote_social_loss.unsigned_abs().cast()?)? + .into(); } // exit bankruptcy diff --git a/programs/drift/src/controller/orders.rs b/programs/drift/src/controller/orders.rs index bc8b3aec4c..885f3e3e2f 100644 --- a/programs/drift/src/controller/orders.rs +++ b/programs/drift/src/controller/orders.rs @@ -4986,7 +4986,11 @@ pub fn fulfill_spot_order_with_match( } // Update base market - base_market.total_spot_fee = base_market.total_spot_fee.safe_add(fee_to_market.cast()?)?; + base_market.total_spot_fee = base_market + .total_spot_fee + .as_u128() + .safe_add(fee_to_market.cast()?)? + .into(); update_spot_balances( fee_to_market.cast()?, @@ -5275,7 +5279,11 @@ pub fn fulfill_spot_order_with_external_market( )?; } - base_market.total_spot_fee = base_market.total_spot_fee.safe_add(fee_to_market.cast()?)?; + base_market.total_spot_fee = base_market + .total_spot_fee + .as_u128() + .safe_add(fee_to_market.cast()?)? + .into(); let fill_record_id = get_then_update_id!(base_market, next_fill_record_id); let order_action_record = get_order_action_record( diff --git a/programs/drift/src/controller/spot_balance.rs b/programs/drift/src/controller/spot_balance.rs index f8e1b625e9..6d84d09e76 100644 --- a/programs/drift/src/controller/spot_balance.rs +++ b/programs/drift/src/controller/spot_balance.rs @@ -39,13 +39,13 @@ pub fn update_spot_market_twap_stats( let from_start = max(1_i64, SPOT_MARKET_TOKEN_TWAP_WINDOW.safe_sub(since_last)?); let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), spot_market, &SpotBalanceType::Borrow, )?; @@ -153,16 +153,20 @@ pub fn update_spot_market_cumulative_interest( if deposit_interest_for_lenders > 0 { spot_market.cumulative_deposit_interest = spot_market .cumulative_deposit_interest - .safe_add(deposit_interest_for_lenders)?; + .as_u128() + .safe_add(deposit_interest_for_lenders)? + .into(); spot_market.cumulative_borrow_interest = spot_market .cumulative_borrow_interest - .safe_add(borrow_interest)?; + .as_u128() + .safe_add(borrow_interest)? + .into(); spot_market.last_interest_ts = now.cast()?; // add deposit_interest_for_stakers as balance for revenue_pool let token_amount = get_interest_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, deposit_interest_for_stakers, )?; @@ -172,10 +176,10 @@ pub fn update_spot_market_cumulative_interest( emit!(SpotInterestRecord { ts: now, market_index: spot_market.market_index, - deposit_balance: spot_market.deposit_balance, - cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - borrow_balance: spot_market.borrow_balance, - cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + deposit_balance: spot_market.deposit_balance.as_u128(), + cumulative_deposit_interest: spot_market.cumulative_deposit_interest.as_u128(), + borrow_balance: spot_market.borrow_balance.as_u128(), + cumulative_borrow_interest: spot_market.cumulative_borrow_interest.as_u128(), optimal_utilization: spot_market.optimal_utilization, optimal_borrow_rate: spot_market.optimal_borrow_rate, max_borrow_rate: spot_market.max_borrow_rate, @@ -261,13 +265,13 @@ pub fn update_spot_balances( if is_leaving_drift && update_direction == &SpotBalanceType::Borrow { let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), spot_market, &SpotBalanceType::Borrow, )?; @@ -302,10 +306,10 @@ pub fn transfer_spot_balances( if from_spot_balance.balance_type() == &SpotBalanceType::Deposit { validate!( - spot_market.deposit_balance >= from_spot_balance.balance(), + spot_market.deposit_balance.as_u128() >= from_spot_balance.balance(), ErrorCode::InvalidSpotMarketState, "spot_market.deposit_balance={} lower than individual spot balance={}", - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), from_spot_balance.balance() )?; } @@ -435,10 +439,15 @@ fn increase_spot_balance( ) -> DriftResult { match balance_type { SpotBalanceType::Deposit => { - spot_market.deposit_balance = spot_market.deposit_balance.safe_add(delta)? + spot_market.deposit_balance = spot_market + .deposit_balance + .as_u128() + .safe_add(delta)? + .into(); } SpotBalanceType::Borrow => { - spot_market.borrow_balance = spot_market.borrow_balance.safe_add(delta)? + spot_market.borrow_balance = + spot_market.borrow_balance.as_u128().safe_add(delta)?.into(); } } @@ -452,10 +461,15 @@ fn decrease_spot_balance( ) -> DriftResult { match balance_type { SpotBalanceType::Deposit => { - spot_market.deposit_balance = spot_market.deposit_balance.safe_sub(delta)? + spot_market.deposit_balance = spot_market + .deposit_balance + .as_u128() + .safe_sub(delta)? + .into(); } SpotBalanceType::Borrow => { - spot_market.borrow_balance = spot_market.borrow_balance.safe_sub(delta)? + spot_market.borrow_balance = + spot_market.borrow_balance.as_u128().safe_sub(delta)?.into(); } } diff --git a/programs/drift/src/instructions/admin.rs b/programs/drift/src/instructions/admin.rs index 14de7e9216..d083ec60de 100644 --- a/programs/drift/src/instructions/admin.rs +++ b/programs/drift/src/instructions/admin.rs @@ -321,16 +321,16 @@ pub fn handle_initialize_spot_market( optimal_utilization, optimal_borrow_rate, max_borrow_rate, - deposit_balance: 0, - borrow_balance: 0, + deposit_balance: 0.into(), + borrow_balance: 0.into(), max_token_deposits: 0, deposit_token_twap: 0, borrow_token_twap: 0, utilization_twap: 0, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - total_social_loss: 0, - total_quote_social_loss: 0, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + total_social_loss: 0.into(), + total_quote_social_loss: 0.into(), last_interest_ts: now, last_twap_ts: now, initial_asset_weight, @@ -348,7 +348,7 @@ pub fn handle_initialize_spot_market( next_fill_record_id: 1, next_deposit_record_id: 1, spot_fee_pool: PoolBalance::default(), // in quote asset - total_spot_fee: 0, + total_spot_fee: 0.into(), orders_enabled: spot_market_index != 0, paused_operations: 0, if_paused_operations: 0, @@ -1250,16 +1250,16 @@ pub fn handle_delete_initialized_spot_market( "spot_market.status != Initialized", )?; validate!( - spot_market.deposit_balance == 0, + spot_market.deposit_balance.as_u128() == 0, ErrorCode::InvalidMarketAccountforDeletion, "spot_market.number_of_users={} != 0", - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), )?; validate!( - spot_market.borrow_balance == 0, + spot_market.borrow_balance.as_u128() == 0, ErrorCode::InvalidMarketAccountforDeletion, "spot_market.borrow_balance={} != 0", - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), )?; validate!( spot_market.market_index == market_index, @@ -2121,11 +2121,11 @@ pub fn handle_deposit_into_spot_market_vault<'c: 'info, 'info>( let token_precision = spot_market.get_precision(); - let cumulative_deposit_interest_before = spot_market.cumulative_deposit_interest; + let cumulative_deposit_interest_before = spot_market.cumulative_deposit_interest.as_u128(); let cumulative_deposit_interest_after = deposit_token_amount_after .safe_mul(SPOT_CUMULATIVE_INTEREST_PRECISION)? - .safe_div(spot_market.deposit_balance)? + .safe_div(spot_market.deposit_balance.as_u128())? .safe_mul(SPOT_BALANCE_PRECISION)? .safe_div(token_precision.cast()?)?; @@ -2137,7 +2137,7 @@ pub fn handle_deposit_into_spot_market_vault<'c: 'info, 'info>( cumulative_deposit_interest_before )?; - spot_market.cumulative_deposit_interest = cumulative_deposit_interest_after; + spot_market.cumulative_deposit_interest = cumulative_deposit_interest_after.into(); controller::token::receive( &ctx.accounts.token_program, @@ -2161,7 +2161,7 @@ pub fn handle_deposit_into_spot_market_vault<'c: 'info, 'info>( emit!(SpotMarketVaultDepositRecord { ts: Clock::get()?.unix_timestamp, market_index: spot_market.market_index, - deposit_balance: spot_market.deposit_balance, + deposit_balance: spot_market.deposit_balance.as_u128(), cumulative_deposit_interest_before, cumulative_deposit_interest_after, deposit_token_amount_before: deposit_token_amount_before.cast()?, @@ -4587,7 +4587,7 @@ pub fn handle_update_protocol_if_shares_transfer_config( config.max_transfer_per_epoch, max_transfer_per_epoch ); - config.max_transfer_per_epoch = max_transfer_per_epoch; + config.max_transfer_per_epoch = max_transfer_per_epoch.into(); } else { msg!("max_transfer_per_epoch: unchanged"); } @@ -4951,10 +4951,10 @@ pub fn handle_admin_deposit<'c: 'info, 'info>( direction: DepositDirection::Deposit, amount, oracle_price, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance.as_u128(), + market_withdraw_balance: spot_market.borrow_balance.as_u128(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest.as_u128(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest.as_u128(), total_deposits_after, total_withdraws_after, market_index, diff --git a/programs/drift/src/instructions/if_staker.rs b/programs/drift/src/instructions/if_staker.rs index bdc506abe8..8e468d2e01 100644 --- a/programs/drift/src/instructions/if_staker.rs +++ b/programs/drift/src/instructions/if_staker.rs @@ -95,7 +95,7 @@ pub fn handle_add_insurance_fund_stake<'c: 'info, 'info>( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares == 0 + insurance_fund_stake.last_withdraw_request_shares.as_u128() == 0 && insurance_fund_stake.last_withdraw_request_value == 0, ErrorCode::IFWithdrawRequestInProgress, "withdraw request in progress" @@ -187,7 +187,7 @@ pub fn handle_request_remove_insurance_fund_stake( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares == 0, + insurance_fund_stake.last_withdraw_request_shares.as_u128() == 0, ErrorCode::IFWithdrawRequestInProgress, "Withdraw request is already in progress" )?; @@ -236,7 +236,7 @@ pub fn handle_cancel_request_remove_insurance_fund_stake( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares != 0, + insurance_fund_stake.last_withdraw_request_shares.as_u128() != 0, ErrorCode::NoIFWithdrawRequestInProgress, "No withdraw request in progress" )?; @@ -343,7 +343,11 @@ pub fn handle_transfer_protocol_if_shares( transfer_config.update_epoch(now)?; transfer_config.validate_transfer(shares)?; - transfer_config.current_epoch_transfer += shares; + transfer_config.current_epoch_transfer = transfer_config + .current_epoch_transfer + .as_u128() + .safe_add(shares)? + .into(); let mut if_stake = ctx.accounts.insurance_fund_stake.load_mut()?; let mut user_stats = ctx.accounts.user_stats.load_mut()?; @@ -862,7 +866,7 @@ pub fn handle_deposit_into_insurance_fund_stake<'c: 'info, 'info>( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares == 0 + insurance_fund_stake.last_withdraw_request_shares.as_u128() == 0 && insurance_fund_stake.last_withdraw_request_value == 0, ErrorCode::IFWithdrawRequestInProgress, "withdraw request in progress" diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index 21d3e871e3..21137aeb5e 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -3503,7 +3503,7 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>( .last_exchange_fees .safe_sub(cached_info.last_settle_amm_ex_fees)? .cast::()?, - lp_aum: lp_pool.last_aum, + lp_aum: lp_pool.last_aum.into(), lp_price: lp_pool.get_price(lp_pool.token_supply)?, lp_pool: lp_pool_key, }); @@ -3527,12 +3527,16 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>( SettlementDirection::FromLpPool => { lp_pool.cumulative_quote_sent_to_perp_markets = lp_pool .cumulative_quote_sent_to_perp_markets - .saturating_add(settlement_result.amount_transferred as u128); + .as_u128() + .saturating_add(settlement_result.amount_transferred as u128) + .into() } SettlementDirection::ToLpPool => { lp_pool.cumulative_quote_received_from_perp_markets = lp_pool .cumulative_quote_received_from_perp_markets - .saturating_add(settlement_result.amount_transferred as u128); + .as_u128() + .saturating_add(settlement_result.amount_transferred as u128) + .into() } SettlementDirection::None => {} } diff --git a/programs/drift/src/instructions/lp_admin.rs b/programs/drift/src/instructions/lp_admin.rs index 0e5225d832..af7f91030b 100644 --- a/programs/drift/src/instructions/lp_admin.rs +++ b/programs/drift/src/instructions/lp_admin.rs @@ -61,20 +61,20 @@ pub fn handle_initialize_lp_pool( constituent_target_base: ctx.accounts.constituent_target_base.key(), constituent_correlations: ctx.accounts.constituent_correlations.key(), constituents: 0, - max_aum, - last_aum: 0, + max_aum: max_aum.into(), + last_aum: 0.into(), last_aum_slot: 0, max_settle_quote_amount: max_settle_quote_amount_per_market, _padding: 0, - total_mint_redeem_fees_paid: 0, + total_mint_redeem_fees_paid: 0.into(), bump: ctx.bumps.lp_pool, min_mint_fee, token_supply: 0, mint_redeem_id: 1, settle_id: 1, quote_consituent_index: 0, - cumulative_quote_sent_to_perp_markets: 0, - cumulative_quote_received_from_perp_markets: 0, + cumulative_quote_sent_to_perp_markets: 0.into(), + cumulative_quote_received_from_perp_markets: 0.into(), gamma_execution: 2, volatility: 4, xi: 2, @@ -431,12 +431,12 @@ pub fn handle_update_lp_pool_params<'info>( if let Some(max_aum) = lp_pool_params.max_aum { validate!( - max_aum >= lp_pool.max_aum, + max_aum >= lp_pool.max_aum.as_u128(), ErrorCode::DefaultError, "new max_aum must be greater than or equal to current max_aum" )?; - msg!("max_aum: {:?} -> {:?}", lp_pool.max_aum, max_aum); - lp_pool.max_aum = max_aum; + msg!("max_aum: {:?} -> {:?}", lp_pool.max_aum.as_u128(), max_aum); + lp_pool.max_aum = max_aum.into(); } Ok(()) diff --git a/programs/drift/src/instructions/lp_pool.rs b/programs/drift/src/instructions/lp_pool.rs index 3108af7ca9..c5232afaa4 100644 --- a/programs/drift/src/instructions/lp_pool.rs +++ b/programs/drift/src/instructions/lp_pool.rs @@ -376,13 +376,13 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>( in_constituent.constituent_index, &in_spot_market, in_oracle.price, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?; let out_target_weight = constituent_target_base.get_target_weight( out_constituent.constituent_index, &out_spot_market, out_oracle.price, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?; let in_target_datum = constituent_target_base.get(in_constituent.constituent_index as u32); let in_target_position_slot_delay = slot.saturating_sub(in_target_datum.last_position_slot); @@ -463,20 +463,20 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>( in_constituent_index: in_constituent.constituent_index, out_oracle_price: out_oracle.price, in_oracle_price: in_oracle.price, - last_aum: lp_pool.last_aum, + last_aum: lp_pool.last_aum.as_u128(), last_aum_slot: lp_pool.last_aum_slot, in_market_current_weight: in_constituent.get_weight( in_oracle.price, &in_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?, in_market_target_weight: in_target_weight, out_market_current_weight: out_constituent.get_weight( out_oracle.price, &out_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?, out_market_target_weight: out_target_weight, in_swap_id, @@ -722,15 +722,15 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( update_spot_market_cumulative_interest(&mut in_spot_market, Some(&in_oracle), now)?; - msg!("aum: {}", lp_pool.last_aum); - let in_target_weight = if lp_pool.last_aum == 0 { + msg!("aum: {}", lp_pool.last_aum.as_u128()); + let in_target_weight = if lp_pool.last_aum.as_u128() == 0 { PERCENTAGE_PRECISION_I64 // 100% weight if no aum } else { constituent_target_base.get_target_weight( in_constituent.constituent_index, &in_spot_market, in_oracle.price, - lp_pool.last_aum, // TODO: add in_amount * in_oracle to est post add_liquidity aum + lp_pool.last_aum.into(), // TODO: add in_amount * in_oracle to est post add_liquidity aum )? }; @@ -817,14 +817,18 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( let mut lp_pool = ctx.accounts.lp_pool.load_mut()?; - lp_pool.last_aum = lp_pool.last_aum.safe_add( - in_amount - .cast::()? - .safe_mul(in_oracle.price.cast::()?)? - .safe_div(10_u128.pow(in_spot_market.decimals))?, - )?; + lp_pool.last_aum = lp_pool + .last_aum + .as_u128() + .safe_add( + in_amount + .cast::()? + .safe_mul(in_oracle.price.cast::()?)? + .safe_div(10_u128.pow(in_spot_market.decimals))?, + )? + .into(); - if lp_pool.last_aum > lp_pool.max_aum { + if lp_pool.last_aum.as_u128() > lp_pool.max_aum.as_u128() { return Err(ErrorCode::MaxDlpAumBreached.into()); } @@ -864,13 +868,13 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( lp_fee: lp_fee_amount, lp_price: lp_price_after, mint_redeem_id, - last_aum: lp_pool.last_aum, + last_aum: lp_pool.last_aum.as_u128(), last_aum_slot: lp_pool.last_aum_slot, in_market_current_weight: in_constituent.get_weight( in_oracle.price, &in_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?, in_market_target_weight: in_target_weight, lp_pool: lp_pool_key, @@ -938,15 +942,15 @@ pub fn handle_view_lp_pool_add_liquidity_fees<'c: 'info, 'info>( return Err(ErrorCode::InvalidOracle.into()); } - msg!("aum: {}", lp_pool.last_aum); - let in_target_weight = if lp_pool.last_aum == 0 { + msg!("aum: {}", lp_pool.last_aum.as_u128()); + let in_target_weight = if lp_pool.last_aum.as_u128() == 0 { PERCENTAGE_PRECISION_I64 // 100% weight if no aum } else { constituent_target_base.get_target_weight( in_constituent.constituent_index, &in_spot_market, in_oracle.price, - lp_pool.last_aum, // TODO: add in_amount * in_oracle to est post add_liquidity aum + lp_pool.last_aum.into(), // TODO: add in_amount * in_oracle to est post add_liquidity aum )? }; @@ -1094,7 +1098,7 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( out_constituent.constituent_index, &out_spot_market, out_oracle.price, - lp_pool.last_aum, // TODO: remove out_amount * out_oracle to est post remove_liquidity aum + lp_pool.last_aum.into(), // TODO: remove out_amount * out_oracle to est post remove_liquidity aum )?; let dlp_total_supply = ctx.accounts.lp_mint.supply; @@ -1219,12 +1223,16 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( let mut lp_pool = ctx.accounts.lp_pool.load_mut()?; - lp_pool.last_aum = lp_pool.last_aum.safe_sub( - out_amount_net_fees - .cast::()? - .safe_mul(out_oracle.price.cast::()?)? - .safe_div(10_u128.pow(out_spot_market.decimals))?, - )?; + lp_pool.last_aum = lp_pool + .last_aum + .as_u128() + .safe_sub( + out_amount_net_fees + .cast::()? + .safe_mul(out_oracle.price.cast::()?)? + .safe_div(10_u128.pow(out_spot_market.decimals))?, + )? + .into(); ctx.accounts.constituent_out_token_account.reload()?; ctx.accounts.lp_mint.reload()?; @@ -1262,13 +1270,13 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( lp_fee: lp_fee_amount, lp_price: lp_price_after, mint_redeem_id, - last_aum: lp_pool.last_aum, + last_aum: lp_pool.last_aum.as_u128(), last_aum_slot: lp_pool.last_aum_slot, in_market_current_weight: out_constituent.get_weight( out_oracle.price, &out_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?, in_market_target_weight: out_target_weight, lp_pool: lp_pool_key, @@ -1346,7 +1354,7 @@ pub fn handle_view_lp_pool_remove_liquidity_fees<'c: 'info, 'info>( out_constituent.constituent_index, &out_spot_market, out_oracle.price, - lp_pool.last_aum, + lp_pool.last_aum.into(), )?; let dlp_total_supply = ctx.accounts.lp_mint.supply; diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index e75f02ca1c..6be5622be9 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -424,12 +424,12 @@ pub fn handle_sweep_fuel<'c: 'info, 'info>( user_stats_fuel_positions: user_stats.fuel_positions, user_stats_fuel_taker: user_stats.fuel_taker, user_stats_fuel_maker: user_stats.fuel_maker, - fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance, - fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits, - fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows, - fuel_overflow_fuel_positions: fuel_overflow.fuel_positions, - fuel_overflow_fuel_taker: fuel_overflow.fuel_taker, - fuel_overflow_fuel_maker: fuel_overflow.fuel_maker, + fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance.as_u128(), + fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits.as_u128(), + fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows.as_u128(), + fuel_overflow_fuel_positions: fuel_overflow.fuel_positions.as_u128(), + fuel_overflow_fuel_taker: fuel_overflow.fuel_taker.as_u128(), + fuel_overflow_fuel_maker: fuel_overflow.fuel_maker.as_u128(), }); fuel_overflow.update_from_user_stats(&user_stats, clock.unix_timestamp.cast()?)?; @@ -459,24 +459,24 @@ pub fn handle_reset_fuel_season<'c: 'info, 'info>( user_stats_fuel_positions: user_stats.fuel_positions, user_stats_fuel_taker: user_stats.fuel_taker, user_stats_fuel_maker: user_stats.fuel_maker, - fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance, - fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits, - fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows, - fuel_overflow_fuel_positions: fuel_overflow.fuel_positions, - fuel_overflow_fuel_taker: fuel_overflow.fuel_taker, - fuel_overflow_fuel_maker: fuel_overflow.fuel_maker, + fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance.as_u128(), + fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits.as_u128(), + fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows.as_u128(), + fuel_overflow_fuel_positions: fuel_overflow.fuel_positions.as_u128(), + fuel_overflow_fuel_taker: fuel_overflow.fuel_taker.as_u128(), + fuel_overflow_fuel_maker: fuel_overflow.fuel_maker.as_u128(), }); fuel_overflow.update_from_user_stats(&user_stats, clock.unix_timestamp.cast()?)?; emit!(FuelSeasonRecord { ts: clock.unix_timestamp.cast()?, authority: ctx.accounts.authority.key(), - fuel_insurance: fuel_overflow.fuel_insurance, - fuel_deposits: fuel_overflow.fuel_deposits, - fuel_borrows: fuel_overflow.fuel_borrows, - fuel_positions: fuel_overflow.fuel_positions, - fuel_taker: fuel_overflow.fuel_taker, - fuel_maker: fuel_overflow.fuel_maker, + fuel_insurance: fuel_overflow.fuel_insurance.as_u128(), + fuel_deposits: fuel_overflow.fuel_deposits.as_u128(), + fuel_borrows: fuel_overflow.fuel_borrows.as_u128(), + fuel_positions: fuel_overflow.fuel_positions.as_u128(), + fuel_taker: fuel_overflow.fuel_taker.as_u128(), + fuel_maker: fuel_overflow.fuel_maker.as_u128(), fuel_total: fuel_overflow.total_fuel()?, }); fuel_overflow.reset_fuel(clock.unix_timestamp.cast()?); @@ -806,10 +806,10 @@ pub fn handle_deposit<'c: 'info, 'info>( direction: DepositDirection::Deposit, amount, oracle_price, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance.as_u128(), + market_withdraw_balance: spot_market.borrow_balance.as_u128(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest.as_u128(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest.as_u128(), total_deposits_after, total_withdraws_after, market_index, @@ -962,10 +962,10 @@ pub fn handle_withdraw<'c: 'info, 'info>( oracle_price, amount, market_index, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance.as_u128(), + market_withdraw_balance: spot_market.borrow_balance.as_u128(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest.as_u128(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest.as_u128(), total_deposits_after: user.total_deposits, total_withdraws_after: user.total_withdraws, explanation: deposit_explanation, @@ -1132,10 +1132,10 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>( amount, oracle_price, market_index, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance.into(), + market_withdraw_balance: spot_market.borrow_balance.into(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest.into(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest.into(), total_deposits_after: from_user.total_deposits, total_withdraws_after: from_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1196,10 +1196,10 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>( amount, oracle_price, market_index, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance.into(), + market_withdraw_balance: spot_market.borrow_balance.into(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest.into(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest.into(), total_deposits_after, total_withdraws_after, explanation: DepositExplanation::Transfer, @@ -1407,11 +1407,14 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: deposit_transfer, oracle_price: deposit_from_oracle_price_data.price, market_index: deposit_from_market_index, - market_deposit_balance: deposit_from_spot_market.deposit_balance, - market_withdraw_balance: deposit_from_spot_market.borrow_balance, + market_deposit_balance: deposit_from_spot_market.deposit_balance.into(), + market_withdraw_balance: deposit_from_spot_market.borrow_balance.into(), market_cumulative_deposit_interest: deposit_from_spot_market - .cumulative_deposit_interest, - market_cumulative_borrow_interest: deposit_from_spot_market.cumulative_borrow_interest, + .cumulative_deposit_interest + .into(), + market_cumulative_borrow_interest: deposit_from_spot_market + .cumulative_borrow_interest + .into(), total_deposits_after: from_user.total_deposits, total_withdraws_after: from_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1442,10 +1445,14 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: deposit_transfer, oracle_price: deposit_to_oracle_price_data.price, market_index: deposit_to_market_index, - market_deposit_balance: deposit_to_spot_market.deposit_balance, - market_withdraw_balance: deposit_to_spot_market.borrow_balance, - market_cumulative_deposit_interest: deposit_to_spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: deposit_to_spot_market.cumulative_borrow_interest, + market_deposit_balance: deposit_to_spot_market.deposit_balance.into(), + market_withdraw_balance: deposit_to_spot_market.borrow_balance.into(), + market_cumulative_deposit_interest: deposit_to_spot_market + .cumulative_deposit_interest + .into(), + market_cumulative_borrow_interest: deposit_to_spot_market + .cumulative_borrow_interest + .into(), total_deposits_after: to_user.total_deposits, total_withdraws_after: to_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1508,10 +1515,14 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: borrow_transfer, oracle_price: borrow_from_oracle_price_data.price, market_index: borrow_from_market_index, - market_deposit_balance: borrow_from_spot_market.deposit_balance, - market_withdraw_balance: borrow_from_spot_market.borrow_balance, - market_cumulative_deposit_interest: borrow_from_spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: borrow_from_spot_market.cumulative_borrow_interest, + market_deposit_balance: borrow_from_spot_market.deposit_balance.into(), + market_withdraw_balance: borrow_from_spot_market.borrow_balance.into(), + market_cumulative_deposit_interest: borrow_from_spot_market + .cumulative_deposit_interest + .into(), + market_cumulative_borrow_interest: borrow_from_spot_market + .cumulative_borrow_interest + .into(), total_deposits_after: from_user.total_deposits, total_withdraws_after: from_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1542,10 +1553,14 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: borrow_transfer, oracle_price: borrow_to_oracle_price_data.price, market_index: borrow_to_market_index, - market_deposit_balance: borrow_to_spot_market.deposit_balance, - market_withdraw_balance: borrow_to_spot_market.borrow_balance, - market_cumulative_deposit_interest: borrow_to_spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: borrow_to_spot_market.cumulative_borrow_interest, + market_deposit_balance: borrow_to_spot_market.deposit_balance.into(), + market_withdraw_balance: borrow_to_spot_market.borrow_balance.into(), + market_cumulative_deposit_interest: borrow_to_spot_market + .cumulative_deposit_interest + .into(), + market_cumulative_borrow_interest: borrow_to_spot_market + .cumulative_borrow_interest + .into(), total_deposits_after: to_user.total_deposits, total_withdraws_after: to_user.total_withdraws, explanation: DepositExplanation::Transfer, diff --git a/programs/drift/src/math/bn.rs b/programs/drift/src/math/bn.rs index 0218b2a5a3..587b695857 100644 --- a/programs/drift/src/math/bn.rs +++ b/programs/drift/src/math/bn.rs @@ -12,6 +12,211 @@ use uint::construct_uint; use crate::error::DriftResult; +pub mod compat { + use bytemuck::{Pod, Zeroable}; + use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; + + /// `u128` with legacy bit layout + #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] + #[repr(transparent)] + pub struct u128([u8; 16]); + + // Safety: u128 is a transparent wrapper around [u8; 16], which is Pod + Zeroable + unsafe impl Pod for self::u128 {} + unsafe impl Zeroable for self::u128 {} + impl u128 { + pub const ONE: Self = u128(1_u128.to_le_bytes()); + pub const ZERO: Self = u128(0_u128.to_le_bytes()); + /// convert to std u128 + #[inline] + pub fn as_u128(self) -> std::primitive::u128 { + std::primitive::u128::from_le_bytes(self.0) + } + pub const fn one() -> Self { + Self::ONE + } + pub const fn zero() -> Self { + Self::ZERO + } + } + impl From for u128 { + fn from(value: std::primitive::u128) -> Self { + u128(value.to_le_bytes()) + } + } + impl From for std::primitive::u128 { + fn from(value: u128) -> Self { + value.as_u128() + } + } + + // Arithmetic operations for u128 - using From/Into conversions + impl Add for u128 { + type Output = Self; + #[inline(always)] + fn add(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + let b: std::primitive::u128 = other.into(); + Self::from(a + b) + } + } + impl AddAssign for u128 { + #[inline(always)] + fn add_assign(&mut self, other: Self) { + *self = *self + other; + } + } + impl Sub for u128 { + type Output = Self; + #[inline(always)] + fn sub(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + let b: std::primitive::u128 = other.into(); + Self::from(a - b) + } + } + impl SubAssign for u128 { + #[inline(always)] + fn sub_assign(&mut self, other: Self) { + *self = *self - other; + } + } + impl Mul for u128 { + type Output = Self; + #[inline(always)] + fn mul(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + + let b: std::primitive::u128 = other.into(); + Self::from(a * b) + } + } + impl MulAssign for u128 { + #[inline(always)] + fn mul_assign(&mut self, other: Self) { + *self = *self * other; + } + } + impl Div for u128 { + type Output = Self; + #[inline(always)] + fn div(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + + let b: std::primitive::u128 = other.into(); + Self::from(a / b) + } + } + impl DivAssign for u128 { + #[inline(always)] + fn div_assign(&mut self, other: Self) { + *self = *self / other; + } + } + + /// `i128` with legacy bit layout + #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] + #[repr(transparent)] + pub struct i128([u8; 16]); + + // Safety: i128 is a transparent wrapper around [u8; 16], which is Pod + Zeroable + unsafe impl Pod for self::i128 {} + unsafe impl Zeroable for self::i128 {} + impl i128 { + pub const ONE: Self = i128(1_i128.to_le_bytes()); + pub const ZERO: Self = i128(0_i128.to_le_bytes()); + + pub const fn one() -> Self { + Self::ONE + } + pub const fn zero() -> Self { + Self::ZERO + } + + /// convert to std i128 + #[inline] + pub fn as_i128(self) -> std::primitive::i128 { + std::primitive::i128::from_le_bytes(self.0) + } + } + impl From for i128 { + fn from(value: std::primitive::i128) -> Self { + i128(value.to_le_bytes()) + } + } + impl From for std::primitive::i128 { + fn from(value: i128) -> Self { + value.as_i128() + } + } + + // Arithmetic operations for i128 - using From/Into conversions + impl Add for i128 { + type Output = Self; + #[inline(always)] + fn add(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a + b) + } + } + impl AddAssign for i128 { + #[inline(always)] + fn add_assign(&mut self, other: Self) { + *self = *self + other; + } + } + impl Sub for i128 { + type Output = Self; + #[inline(always)] + fn sub(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a - b) + } + } + impl SubAssign for i128 { + #[inline(always)] + fn sub_assign(&mut self, other: Self) { + *self = *self - other; + } + } + impl Mul for i128 { + type Output = Self; + #[inline(always)] + fn mul(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a * b) + } + } + impl MulAssign for i128 { + #[inline(always)] + fn mul_assign(&mut self, other: Self) { + *self = *self * other; + } + } + impl Div for i128 { + type Output = Self; + #[inline(always)] + fn div(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a / b) + } + } + impl DivAssign for i128 { + #[inline(always)] + fn div_assign(&mut self, other: Self) { + *self = *self / other; + } + } +} + construct_uint! { /// 256-bit unsigned integer. pub struct U256(4); diff --git a/programs/drift/src/math/insurance.rs b/programs/drift/src/math/insurance.rs index 4658f97db6..2028e52b5e 100644 --- a/programs/drift/src/math/insurance.rs +++ b/programs/drift/src/math/insurance.rs @@ -87,7 +87,7 @@ pub fn calculate_if_shares_lost( spot_market: &SpotMarket, insurance_fund_vault_balance: u64, ) -> DriftResult { - let n_shares = insurance_fund_stake.last_withdraw_request_shares; + let n_shares = insurance_fund_stake.last_withdraw_request_shares.as_u128(); let amount = if_shares_to_vault_amount( n_shares, diff --git a/programs/drift/src/math/liquidation.rs b/programs/drift/src/math/liquidation.rs index dbe608ceaa..e77d20e833 100644 --- a/programs/drift/src/math/liquidation.rs +++ b/programs/drift/src/math/liquidation.rs @@ -286,13 +286,14 @@ pub fn calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy( spot_market: &SpotMarket, ) -> DriftResult { let total_deposits = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )?; spot_market .cumulative_deposit_interest + .as_u128() .safe_mul(borrow)? .safe_div_ceil(total_deposits) .or(Ok(0)) diff --git a/programs/drift/src/math/spot_balance.rs b/programs/drift/src/math/spot_balance.rs index da5261a487..f75fc2540c 100644 --- a/programs/drift/src/math/spot_balance.rs +++ b/programs/drift/src/math/spot_balance.rs @@ -22,8 +22,8 @@ pub fn get_spot_balance( let precision_increase = 10_u128.pow(19_u32.safe_sub(spot_market.decimals)?); let cumulative_interest = match balance_type { - SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest, - SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest, + SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest.as_u128(), + SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest.as_u128(), }; let mut balance = token_amount @@ -45,8 +45,8 @@ pub fn get_token_amount( let precision_decrease = 10_u128.pow(19_u32.safe_sub(spot_market.decimals)?); let cumulative_interest = match balance_type { - SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest, - SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest, + SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest.as_u128(), + SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest.as_u128(), }; let token_amount = match balance_type { @@ -111,12 +111,12 @@ pub fn calculate_utilization( pub fn calculate_spot_market_utilization(spot_market: &SpotMarket) -> DriftResult { let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), spot_market, &SpotBalanceType::Borrow, )?; @@ -162,6 +162,7 @@ pub fn calculate_accumulated_interest( let borrow_interest = spot_market .cumulative_borrow_interest + .as_u128() .safe_mul(modified_borrow_rate)? .safe_div(ONE_YEAR)? .safe_div(SPOT_RATE_PRECISION)? @@ -169,6 +170,7 @@ pub fn calculate_accumulated_interest( let deposit_interest = spot_market .cumulative_deposit_interest + .as_u128() .safe_mul(modified_deposit_rate)? .safe_div(ONE_YEAR)? .safe_div(SPOT_RATE_PRECISION)?; diff --git a/programs/drift/src/math/spot_withdraw.rs b/programs/drift/src/math/spot_withdraw.rs index 9f0b3e0b5a..4c7e4ce897 100644 --- a/programs/drift/src/math/spot_withdraw.rs +++ b/programs/drift/src/math/spot_withdraw.rs @@ -153,12 +153,12 @@ pub fn check_withdraw_limits( // calculates min/max deposit/borrow amounts permitted for immediate withdraw // takes the stricter of absolute caps on level changes and utilization changes vs 24hr moving averrages let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), spot_market, &SpotBalanceType::Borrow, )?; @@ -231,13 +231,13 @@ pub fn get_max_withdraw_for_market_with_token_amount( is_leaving_drift: bool, ) -> DriftResult { let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), spot_market, &SpotBalanceType::Borrow, )?; @@ -308,13 +308,13 @@ pub fn get_max_withdraw_for_market_with_token_amount( pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult { let depositors_amount: u64 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.as_u128(), spot_market, &SpotBalanceType::Deposit, )? .cast()?; let borrowers_amount: u64 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.as_u128(), spot_market, &SpotBalanceType::Borrow, )? @@ -338,7 +338,7 @@ pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult { revenue_amount, depositors_amount, depositors_claim, - spot_market.deposit_balance + spot_market.deposit_balance.as_u128() )?; Ok(depositors_claim) diff --git a/programs/drift/src/state/fulfillment_params/openbook_v2.rs b/programs/drift/src/state/fulfillment_params/openbook_v2.rs index 869602ac16..ed1b2a1fd8 100644 --- a/programs/drift/src/state/fulfillment_params/openbook_v2.rs +++ b/programs/drift/src/state/fulfillment_params/openbook_v2.rs @@ -32,7 +32,7 @@ use solana_program::pubkey::Pubkey; use std::cell::Ref; use std::convert::TryFrom; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, PartialEq, Eq, Debug)] #[repr(C)] pub struct OpenbookV2FulfillmentConfig { diff --git a/programs/drift/src/state/fulfillment_params/phoenix.rs b/programs/drift/src/state/fulfillment_params/phoenix.rs index a17e48d93d..b2f64b6ba3 100644 --- a/programs/drift/src/state/fulfillment_params/phoenix.rs +++ b/programs/drift/src/state/fulfillment_params/phoenix.rs @@ -90,7 +90,7 @@ pub fn compute_base_lot_size( )) } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, PartialEq, Eq, Debug)] #[repr(C)] pub struct PhoenixV1FulfillmentConfig { diff --git a/programs/drift/src/state/fulfillment_params/serum.rs b/programs/drift/src/state/fulfillment_params/serum.rs index fa30f65eac..61b3146456 100644 --- a/programs/drift/src/state/fulfillment_params/serum.rs +++ b/programs/drift/src/state/fulfillment_params/serum.rs @@ -33,7 +33,7 @@ use std::convert::TryFrom; use std::num::NonZeroU64; use std::ops::{Deref, DerefMut}; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, PartialEq, Eq, Debug)] #[repr(C)] pub struct SerumV3FulfillmentConfig { diff --git a/programs/drift/src/state/high_leverage_mode_config.rs b/programs/drift/src/state/high_leverage_mode_config.rs index 2e69bd2553..b459f98975 100644 --- a/programs/drift/src/state/high_leverage_mode_config.rs +++ b/programs/drift/src/state/high_leverage_mode_config.rs @@ -8,7 +8,7 @@ use anchor_lang::prelude::*; use super::user::MarginMode; use super::user::User; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct HighLeverageModeConfig { diff --git a/programs/drift/src/state/if_rebalance_config.rs b/programs/drift/src/state/if_rebalance_config.rs index 06c9bd7b66..498dc5d8db 100644 --- a/programs/drift/src/state/if_rebalance_config.rs +++ b/programs/drift/src/state/if_rebalance_config.rs @@ -5,7 +5,7 @@ use crate::state::traits::Size; use crate::validate; use anchor_lang::prelude::*; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct IfRebalanceConfig { diff --git a/programs/drift/src/state/insurance_fund_stake.rs b/programs/drift/src/state/insurance_fund_stake.rs index 25d81f4b0d..c616fca132 100644 --- a/programs/drift/src/state/insurance_fund_stake.rs +++ b/programs/drift/src/state/insurance_fund_stake.rs @@ -13,7 +13,7 @@ use anchor_lang::prelude::*; #[cfg(test)] mod tests; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct InsuranceFundStake { @@ -39,23 +39,23 @@ impl InsuranceFundStake { InsuranceFundStake { authority, market_index, - last_withdraw_request_shares: 0, + last_withdraw_request_shares: 0.into(), last_withdraw_request_value: 0, last_withdraw_request_ts: 0, cost_basis: 0, - if_base: 0, + if_base: 0.into(), last_valid_ts: now, - if_shares: 0, + if_shares: 0.into(), padding: [0; 14], } } fn validate_base(&self, spot_market: &SpotMarket) -> DriftResult { validate!( - self.if_base == spot_market.insurance_fund.shares_base, + self.if_base.as_u128() == spot_market.insurance_fund.shares_base, ErrorCode::InvalidIFRebase, "if stake bases mismatch. user base: {} market base {}", - self.if_base, + self.if_base.as_u128(), spot_market.insurance_fund.shares_base )?; @@ -64,34 +64,34 @@ impl InsuranceFundStake { pub fn checked_if_shares(&self, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - Ok(self.if_shares) + Ok(self.if_shares.as_u128()) } pub fn unchecked_if_shares(&self) -> u128 { - self.if_shares + self.if_shares.as_u128() } pub fn increase_if_shares(&mut self, delta: u128, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - safe_increment!(self.if_shares, delta); + self.if_shares = self.if_shares.as_u128().safe_add(delta)?.into(); Ok(()) } pub fn decrease_if_shares(&mut self, delta: u128, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - safe_decrement!(self.if_shares, delta); + self.if_shares = self.if_shares.as_u128().safe_sub(delta)?.into(); Ok(()) } pub fn update_if_shares(&mut self, new_shares: u128, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - self.if_shares = new_shares; + self.if_shares = new_shares.into(); Ok(()) } } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct ProtocolIfSharesTransferConfig { @@ -130,7 +130,7 @@ impl ProtocolIfSharesTransferConfig { .next_epoch_ts .safe_add(EPOCH_DURATION.safe_mul(n_epoch_durations)?)?; - self.current_epoch_transfer = 0; + self.current_epoch_transfer = 0.into(); } Ok(()) @@ -139,7 +139,8 @@ impl ProtocolIfSharesTransferConfig { pub fn validate_transfer(&self, requested_transfer: u128) -> DriftResult { let max_transfer = self .max_transfer_per_epoch - .saturating_sub(self.current_epoch_transfer); + .as_u128() + .saturating_sub(self.current_epoch_transfer.as_u128()); validate!( requested_transfer < max_transfer, diff --git a/programs/drift/src/state/lp_pool.rs b/programs/drift/src/state/lp_pool.rs index f975ce9e81..b8f82477b1 100644 --- a/programs/drift/src/state/lp_pool.rs +++ b/programs/drift/src/state/lp_pool.rs @@ -59,7 +59,7 @@ pub const MAX_ORACLE_STALENESS_FOR_TARGET_CALC: u64 = 10u64; #[cfg(test)] mod tests; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Debug)] #[repr(C)] pub struct LPPool { @@ -138,11 +138,11 @@ impl Default for LPPool { whitelist_mint: Pubkey::default(), constituent_target_base: Pubkey::default(), constituent_correlations: Pubkey::default(), - max_aum: 0, - last_aum: 0, - cumulative_quote_sent_to_perp_markets: 0, - cumulative_quote_received_from_perp_markets: 0, - total_mint_redeem_fees_paid: 0, + max_aum: 0.into(), + last_aum: 0.into(), + cumulative_quote_sent_to_perp_markets: 0.into(), + cumulative_quote_received_from_perp_markets: 0.into(), + total_mint_redeem_fees_paid: 0.into(), last_aum_slot: 0, max_settle_quote_amount: 0, _padding: 0, @@ -180,6 +180,7 @@ impl LPPool { // TODO: assuming mint decimals = quote decimals = 6 Ok(self .last_aum + .as_u128() .safe_mul(PRICE_PRECISION)? .safe_div(supply as u128)?) } @@ -297,7 +298,7 @@ impl LPPool { in_target_weight: i64, dlp_total_supply: u64, ) -> DriftResult<(u64, u128, i64, i128)> { - let (mut in_fee_pct, out_fee_pct) = if self.last_aum == 0 { + let (mut in_fee_pct, out_fee_pct) = if self.last_aum.as_u128() == 0 { (0, 0) } else { self.get_swap_fees( @@ -341,7 +342,7 @@ impl LPPool { } else { token_amount_usd .safe_mul(dlp_total_supply as u128)? - .safe_div(self.last_aum)? + .safe_div(self.last_aum.as_u128())? .safe_div(token_precision_denominator)? }; @@ -399,6 +400,7 @@ impl LPPool { // Apply proportion to AUM and convert to token amount let out_amount = self .last_aum + .as_u128() .safe_mul(proportion)? .safe_mul(token_precision_denominator)? .safe_div(PERCENTAGE_PRECISION)? @@ -481,13 +483,13 @@ impl LPPool { .safe_mul(PERCENTAGE_PRECISION_I128)? .safe_div(trade_notional.cast::()?)? .safe_mul(QUOTE_PRECISION_I128)? - .safe_div(self.last_aum.cast::()?)?; + .safe_div(self.last_aum.as_u128().cast::()?)?; let out_fee = c_post_out .safe_sub(c_pre_out)? .safe_mul(PERCENTAGE_PRECISION_I128)? .safe_div(trade_notional.cast::()?)? .safe_mul(QUOTE_PRECISION_I128)? - .safe_div(self.last_aum.cast::()?)?; + .safe_div(self.last_aum.as_u128().cast::()?)?; Ok((in_fee, out_fee)) } @@ -558,7 +560,7 @@ impl LPPool { out_target_weight .unwrap() .cast::()? - .safe_mul(self.last_aum.cast::()?)? + .safe_mul(self.last_aum.as_u128().cast::()?)? .safe_div(PERCENTAGE_PRECISION_I128)?, out_constituent.get_notional_with_delta(out_oracle_price, out_spot_market, 0)?, out_constituent.get_notional_with_delta( @@ -595,7 +597,7 @@ impl LPPool { // Compute notional targets and errors let in_notional_target = in_target_weight .cast::()? - .safe_mul(self.last_aum.cast::()?)? + .safe_mul(self.last_aum.as_u128().cast::()?)? .safe_div(PERCENTAGE_PRECISION_I128)?; let in_notional_pre = in_constituent.get_notional_with_delta(in_oracle_price, in_spot_market, 0)?; @@ -610,6 +612,7 @@ impl LPPool { } else { let adjusted_aum = self .last_aum + .as_u128() .cast::()? .safe_add(notional_trade_size)?; let in_notional_target_post_mint_redeem = in_target_weight @@ -625,7 +628,12 @@ impl LPPool { let trade_ratio: i128 = notional_trade_size .abs() .safe_mul(PERCENTAGE_PRECISION_I128)? - .safe_div(self.last_aum.max(MIN_AUM_EXECUTION_FEE).cast::()?)?; + .safe_div( + self.last_aum + .as_u128() + .max(MIN_AUM_EXECUTION_FEE) + .cast::()?, + )?; // Linear fee computation amount let in_fee_execution_linear = @@ -716,7 +724,9 @@ impl LPPool { pub fn record_mint_redeem_fees(&mut self, amount: i64) -> DriftResult { self.total_mint_redeem_fees_paid = self .total_mint_redeem_fees_paid - .safe_add(amount.cast::()?)?; + .as_i128() + .safe_add(amount.cast::()?)? + .into(); Ok(()) } @@ -832,7 +842,7 @@ impl LPPool { } let aum_u128 = aum.max(0).cast::()?; - self.last_aum = aum_u128; + self.last_aum = aum_u128.into(); self.last_aum_slot = slot; Ok((aum_u128, crypto_delta, derivative_groups)) @@ -905,7 +915,7 @@ impl ConstituentSpotBalance { } } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Debug)] #[repr(C)] pub struct Constituent { @@ -990,7 +1000,7 @@ impl Default for Constituent { mint: Pubkey::default(), lp_pool: Pubkey::default(), vault: Pubkey::default(), - total_swap_fees: 0, + total_swap_fees: 0.into(), spot_balance: ConstituentSpotBalance::default(), last_spot_balance_token_amount: 0, cumulative_spot_interest_accrued_token_amount: 0, @@ -1096,7 +1106,11 @@ impl Constituent { } pub fn record_swap_fees(&mut self, amount: i128) -> DriftResult { - self.total_swap_fees = self.total_swap_fees.safe_add(amount)?; + self.total_swap_fees = self + .total_swap_fees + .as_i128() + .safe_add(amount.into())? + .into(); Ok(()) } diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index 0275a5549a..68f98617a3 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -694,7 +694,7 @@ impl StrictOraclePrice { } } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Eq, PartialEq, Debug)] #[repr(C)] pub struct PrelaunchOracle { diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 5a6b441c1c..716fff16e5 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -154,7 +154,7 @@ impl ContractTier { } } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Eq, PartialEq, Debug)] #[repr(C)] pub struct PerpMarket { diff --git a/programs/drift/src/state/protected_maker_mode_config.rs b/programs/drift/src/state/protected_maker_mode_config.rs index 8b92eadca7..8524148133 100644 --- a/programs/drift/src/state/protected_maker_mode_config.rs +++ b/programs/drift/src/state/protected_maker_mode_config.rs @@ -4,7 +4,7 @@ use crate::state::traits::Size; use crate::validate; use anchor_lang::prelude::*; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct ProtectedMakerModeConfig { diff --git a/programs/drift/src/state/pyth_lazer_oracle.rs b/programs/drift/src/state/pyth_lazer_oracle.rs index bec409a94a..3048789d17 100644 --- a/programs/drift/src/state/pyth_lazer_oracle.rs +++ b/programs/drift/src/state/pyth_lazer_oracle.rs @@ -9,7 +9,7 @@ impl Size for PythLazerOracle { const SIZE: usize = 48; } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct PythLazerOracle { diff --git a/programs/drift/src/state/revenue_share.rs b/programs/drift/src/state/revenue_share.rs index 7997b2fb4e..b337dc6ca7 100644 --- a/programs/drift/src/state/revenue_share.rs +++ b/programs/drift/src/state/revenue_share.rs @@ -24,7 +24,7 @@ pub enum RevenueShareOrderBitFlag { Referral = 0b00000100, } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Eq, PartialEq, Debug, Default)] pub struct RevenueShare { /// the owner of this account, a builder or referrer diff --git a/programs/drift/src/state/spot_market.rs b/programs/drift/src/state/spot_market.rs index c42000a7b1..31199ef60e 100644 --- a/programs/drift/src/state/spot_market.rs +++ b/programs/drift/src/state/spot_market.rs @@ -30,7 +30,7 @@ use crate::validate; use super::oracle_map::OracleIdentifier; -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(PartialEq, Eq, Debug)] #[repr(C)] pub struct SpotMarket { @@ -223,13 +223,13 @@ impl Default for SpotMarket { revenue_pool: PoolBalance::default(), spot_fee_pool: PoolBalance::default(), insurance_fund: InsuranceFund::default(), - total_spot_fee: 0, - deposit_balance: 0, - borrow_balance: 0, - cumulative_deposit_interest: 0, - cumulative_borrow_interest: 0, - total_social_loss: 0, - total_quote_social_loss: 0, + total_spot_fee: 0.into(), + deposit_balance: 0.into(), + borrow_balance: 0.into(), + cumulative_deposit_interest: 0.into(), + cumulative_borrow_interest: 0.into(), + total_social_loss: 0.into(), + total_quote_social_loss: 0.into(), withdraw_guard_threshold: 0, max_token_deposits: 0, deposit_token_twap: 0, @@ -449,11 +449,19 @@ impl SpotMarket { } pub fn get_deposits(&self) -> DriftResult { - get_token_amount(self.deposit_balance, self, &SpotBalanceType::Deposit) + get_token_amount( + self.deposit_balance.as_u128(), + self, + &SpotBalanceType::Deposit, + ) } pub fn get_borrows(&self) -> DriftResult { - get_token_amount(self.borrow_balance, self, &SpotBalanceType::Borrow) + get_token_amount( + self.borrow_balance.as_u128(), + self, + &SpotBalanceType::Borrow, + ) } pub fn get_tvl(&self) -> DriftResult { @@ -499,11 +507,17 @@ impl SpotMarket { } pub fn get_available_deposits(&self) -> DriftResult { - let deposit_token_amount = - get_token_amount(self.deposit_balance, self, &SpotBalanceType::Deposit)?; + let deposit_token_amount = get_token_amount( + self.deposit_balance.as_u128(), + self, + &SpotBalanceType::Deposit, + )?; - let borrow_token_amount = - get_token_amount(self.borrow_balance, self, &SpotBalanceType::Borrow)?; + let borrow_token_amount = get_token_amount( + self.borrow_balance.as_u128(), + self, + &SpotBalanceType::Borrow, + )?; deposit_token_amount.safe_sub(borrow_token_amount) } @@ -513,11 +527,17 @@ impl SpotMarket { } pub fn get_utilization(self) -> DriftResult { - let deposit_token_amount = - get_token_amount(self.deposit_balance, &self, &SpotBalanceType::Deposit)?; + let deposit_token_amount = get_token_amount( + self.deposit_balance.as_u128(), + &self, + &SpotBalanceType::Deposit, + )?; - let borrow_token_amount = - get_token_amount(self.borrow_balance, &self, &SpotBalanceType::Borrow)?; + let borrow_token_amount = get_token_amount( + self.borrow_balance.as_u128(), + &self, + &SpotBalanceType::Borrow, + )?; calculate_utilization(deposit_token_amount, borrow_token_amount) } diff --git a/programs/drift/src/state/user.rs b/programs/drift/src/state/user.rs index a89467cce3..199e4620e4 100644 --- a/programs/drift/src/state/user.rs +++ b/programs/drift/src/state/user.rs @@ -63,7 +63,7 @@ impl Size for User { const SIZE: usize = 4376; } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct User { @@ -1640,7 +1640,7 @@ pub enum OrderBitFlag { HasBuilder = 0b00010000, } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Eq, PartialEq, Debug)] #[repr(C)] #[derive(Default)] @@ -2052,7 +2052,7 @@ impl<'a: 'info, 'info, T: anchor_lang::Bumps> FuelOverflowProvider<'a> } } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] pub struct ReferrerName { @@ -2085,7 +2085,7 @@ impl FuelOverflowStatus { status & FuelOverflowStatus::Exists as u8 != 0 } } -#[account(zero_copy(unsafe))] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Default, Debug)] #[repr(C)] pub struct FuelOverflow { @@ -2111,39 +2111,56 @@ impl FuelOverflow { pub fn update_from_user_stats(&mut self, user_stats: &UserStats, now: u32) -> DriftResult<()> { self.fuel_insurance = self .fuel_insurance - .safe_add(user_stats.fuel_insurance.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_insurance.cast()?)? + .into(); self.fuel_deposits = self .fuel_deposits - .safe_add(user_stats.fuel_deposits.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_deposits.cast()?)? + .into(); self.fuel_borrows = self .fuel_borrows - .safe_add(user_stats.fuel_borrows.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_borrows.cast()?)? + .into(); self.fuel_positions = self .fuel_positions - .safe_add(user_stats.fuel_positions.cast()?)?; - self.fuel_taker = self.fuel_taker.safe_add(user_stats.fuel_taker.cast()?)?; - self.fuel_maker = self.fuel_maker.safe_add(user_stats.fuel_maker.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_positions.cast()?)? + .into(); + self.fuel_taker = self + .fuel_taker + .as_u128() + .safe_add(user_stats.fuel_taker.cast()?)? + .into(); + self.fuel_maker = self + .fuel_maker + .as_u128() + .safe_add(user_stats.fuel_maker.cast()?)? + .into(); self.last_fuel_sweep_ts = now; Ok(()) } pub fn reset_fuel(&mut self, now: u32) { - self.fuel_insurance = 0; - self.fuel_deposits = 0; - self.fuel_borrows = 0; - self.fuel_positions = 0; - self.fuel_taker = 0; - self.fuel_maker = 0; + self.fuel_insurance = 0.into(); + self.fuel_deposits = 0.into(); + self.fuel_borrows = 0.into(); + self.fuel_positions = 0.into(); + self.fuel_taker = 0.into(); + self.fuel_maker = 0.into(); self.last_reset_ts = now; } pub fn total_fuel(&self) -> DriftResult { self.fuel_insurance - .safe_add(self.fuel_deposits)? - .safe_add(self.fuel_borrows)? - .safe_add(self.fuel_positions)? - .safe_add(self.fuel_taker)? - .safe_add(self.fuel_maker) + .as_u128() + .safe_add(self.fuel_deposits.as_u128())? + .safe_add(self.fuel_borrows.as_u128())? + .safe_add(self.fuel_positions.as_u128())? + .safe_add(self.fuel_taker.as_u128())? + .safe_add(self.fuel_maker.as_u128()) } } From 2479d69a6cb1aecd74d5c00ba6f0aeb22661c26b Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 13 Nov 2025 20:55:20 +0800 Subject: [PATCH 2/2] backwards compatiable u/i128 --- programs/drift/src/controller/amm/tests.rs | 130 +++--- .../drift/src/controller/insurance/tests.rs | 117 +++--- .../drift/src/controller/liquidation/tests.rs | 376 +++++++++--------- .../src/controller/orders/amm_jit_tests.rs | 26 +- .../drift/src/controller/orders/fuel_tests.rs | 10 +- programs/drift/src/controller/orders/tests.rs | 220 +++++----- .../drift/src/controller/pnl/delisting.rs | 74 ++-- programs/drift/src/controller/pnl/tests.rs | 56 +-- .../drift/src/controller/position/tests.rs | 12 +- .../src/controller/spot_balance/tests.rs | 300 ++++++++------ .../src/controller/spot_position/tests.rs | 8 +- programs/drift/src/instructions/lp_admin.rs | 2 +- programs/drift/src/math/insurance/tests.rs | 6 +- programs/drift/src/math/liquidation/tests.rs | 8 +- programs/drift/src/math/margin/tests.rs | 286 ++++++------- programs/drift/src/math/orders/tests.rs | 116 +++--- programs/drift/src/math/spot_balance/tests.rs | 2 +- programs/drift/src/state/lp_pool.rs | 2 +- programs/drift/src/state/lp_pool/tests.rs | 63 +-- programs/drift/src/state/perp_market.rs | 10 +- programs/drift/src/state/spot_market.rs | 23 +- programs/drift/src/state/user/tests.rs | 12 +- 22 files changed, 964 insertions(+), 895 deletions(-) diff --git a/programs/drift/src/controller/amm/tests.rs b/programs/drift/src/controller/amm/tests.rs index ba51779f5e..62ac5bf88a 100644 --- a/programs/drift/src/controller/amm/tests.rs +++ b/programs/drift/src/controller/amm/tests.rs @@ -276,13 +276,13 @@ fn update_pool_balances_test_high_util_borrow() { let now = 33928058; let mut spot_market = SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), ..SpotMarket::default() }; // 100% util - spot_market.deposit_balance = 10_u128.pow(19_u32); - spot_market.borrow_balance = 10_u128.pow(19_u32); + spot_market.deposit_balance = 10_u128.pow(19_u32).into(); + spot_market.borrow_balance = 10_u128.pow(19_u32).into(); spot_market.deposit_token_twap = 10_u64.pow(16_u32); // would lead to a borrow @@ -300,7 +300,7 @@ fn update_pool_balances_test_high_util_borrow() { assert_eq!(to_settle_with_user, 0); // util is low => neg settle ok - spot_market.borrow_balance = 0; + spot_market.borrow_balance = 0.into(); let unsettled_pnl = -100; let to_settle_with_user = update_pool_balances( &mut market, @@ -313,7 +313,7 @@ fn update_pool_balances_test_high_util_borrow() { assert_eq!(to_settle_with_user, unsettled_pnl); // util is high - spot_market.borrow_balance = 10_u128.pow(19_u32); + spot_market.borrow_balance = 10_u128.pow(19_u32).into(); // user has a little bit deposited => settle how much they have deposited update_spot_balances( 50, @@ -371,11 +371,11 @@ fn update_pool_balances_test() { let now = 33928058; let mut spot_market = SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), ..SpotMarket::default() }; - spot_market.deposit_balance = 10_u128.pow(19_u32); + spot_market.deposit_balance = 10_u128.pow(19_u32).into(); spot_market.deposit_token_twap = 10_u64.pow(16_u32); let spot_position = SpotPosition::default(); @@ -530,9 +530,9 @@ fn update_pool_balances_fee_to_revenue_test() { 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, + deposit_balance: (100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance::default(), ..SpotMarket::default() }; @@ -555,7 +555,7 @@ fn update_pool_balances_fee_to_revenue_test() { assert_eq!( get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit ) @@ -641,9 +641,9 @@ fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { 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, + deposit_balance: (100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance::default(), ..SpotMarket::default() }; @@ -666,7 +666,7 @@ fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { assert_eq!( get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit ) @@ -750,9 +750,9 @@ fn update_pool_balances_revenue_to_fee_test() { let mut now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 200 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, scaled_balance: 100 * SPOT_BALANCE_PRECISION, @@ -795,7 +795,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!( get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit ) @@ -831,7 +831,10 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 0); market.insurance_claim.max_revenue_withdraw_per_period = 100000000 * 2; - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); + assert_eq!( + spot_market.deposit_balance, + (200 * SPOT_BALANCE_PRECISION).into() + ); assert_eq!( spot_market.revenue_pool.scaled_balance, 100 * SPOT_BALANCE_PRECISION @@ -855,7 +858,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, now); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) @@ -884,7 +887,10 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(spot_market.revenue_pool.scaled_balance, 0); // add deposits and revenue to pool - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); + assert_eq!( + spot_market.deposit_balance, + (200 * SPOT_BALANCE_PRECISION).into() + ); spot_market.revenue_pool.scaled_balance = 9900000001000; let spot_market_backup = spot_market; @@ -892,18 +898,18 @@ fn update_pool_balances_revenue_to_fee_test() { assert!(update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).is_err()); // assert is_err if any way has revenue pool above deposit balances spot_market = spot_market_backup; market = market_backup; - spot_market.deposit_balance += 9900000001000; + spot_market.deposit_balance += 9900000001000u128.into(); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap() as u64; - assert_eq!(spot_market.deposit_balance, 10100000001000); + assert_eq!(spot_market.deposit_balance, 10100000001000u128.into()); assert_eq!(spot_market_vault_amount, 10100000001); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(spot_market.deposit_balance, 10100000001000); + assert_eq!(spot_market.deposit_balance, 10100000001000u128.into()); assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); assert_eq!(market.amm.fee_pool.scaled_balance, 105000000000); assert_eq!(market.pnl_pool.scaled_balance, 195000000000); @@ -943,7 +949,7 @@ fn update_pool_balances_revenue_to_fee_test() { // do a revenue settlement to allow up to max again assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 33928059); - assert_eq!(spot_market.deposit_balance, 10100000001000); + assert_eq!(spot_market.deposit_balance, 10100000001000u128.into()); spot_market.insurance_fund.total_factor = 1; spot_market.insurance_fund.revenue_settle_period = 1; @@ -958,14 +964,14 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(res, 9800000001); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap() as u64; - assert_eq!(spot_market.deposit_balance, 300000000000); // 100000000 was added to market fee/pnl pool - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance, 300000000000u128.into()); // 100000000 was added to market fee/pnl pool + assert_eq!(spot_market.borrow_balance, 0u128.into()); assert_eq!(spot_market_vault_amount, 300000000); assert_eq!(spot_market.revenue_pool.scaled_balance, 0); @@ -983,7 +989,7 @@ fn update_pool_balances_revenue_to_fee_test() { ); // assert is_err if any way has revenue pool above deposit balances market = market_backup; spot_market = spot_market_backup; - spot_market.deposit_balance += 9800000000001; + spot_market.deposit_balance += 9800000000001u128.into(); assert_eq!(market.amm.fee_pool.scaled_balance, 5000000000); assert_eq!(market.pnl_pool.scaled_balance, 295000000000); @@ -1057,9 +1063,9 @@ fn update_pool_balances_revenue_to_fee_devnet_state_test() { let now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 200 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, scaled_balance: 100 * SPOT_BALANCE_PRECISION, @@ -1096,7 +1102,10 @@ fn update_pool_balances_revenue_to_fee_devnet_state_test() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 0); market.insurance_claim.max_revenue_withdraw_per_period = 100000000 * 2; - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); + assert_eq!( + spot_market.deposit_balance, + (200 * SPOT_BALANCE_PRECISION).into() + ); assert_eq!( spot_market.revenue_pool.scaled_balance, 100 * SPOT_BALANCE_PRECISION @@ -1148,9 +1157,9 @@ fn update_pool_balances_revenue_to_fee_new_market() { let now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 200 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, scaled_balance: 100 * SPOT_BALANCE_PRECISION, @@ -1187,7 +1196,10 @@ fn update_pool_balances_revenue_to_fee_new_market() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058); market.insurance_claim.max_revenue_withdraw_per_period = 100000000 * 2; - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); + assert_eq!( + spot_market.deposit_balance, + (200 * SPOT_BALANCE_PRECISION).into() + ); assert_eq!(spot_market.revenue_pool.scaled_balance, 50000000000); } @@ -1220,9 +1232,9 @@ mod revenue_pool_transfer_tests { ..PerpMarket::default() }; let mut spot_market = SpotMarket { - deposit_balance: 20020 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (20020 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, scaled_balance: 100 * SPOT_BALANCE_PRECISION, @@ -1338,7 +1350,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 20 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); market.amm.total_exchange_fee = 3000 * QUOTE_PRECISION; let result = calculate_revenue_pool_transfer( &market, @@ -1352,7 +1364,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1365,7 +1377,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); market.amm.total_liquidation_fee = 800 * QUOTE_PRECISION; let result = calculate_revenue_pool_transfer( &market, @@ -1379,7 +1391,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); market.amm.total_liquidation_fee = 200 * QUOTE_PRECISION; let result = calculate_revenue_pool_transfer( &market, @@ -1396,7 +1408,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 600 * QUOTE_PRECISION; + market.amm.total_social_loss = (600 * QUOTE_PRECISION).into(); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1409,7 +1421,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after: u128 = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 40 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1422,7 +1434,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1437,7 +1449,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = -1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1450,7 +1462,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = -1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 2000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.total_social_loss = (100 * QUOTE_PRECISION).into(); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1491,10 +1503,10 @@ mod revenue_pool_transfer_tests { ..PerpMarket::default() }; let mut spot_market = SpotMarket { - deposit_balance: 20020 * SPOT_BALANCE_PRECISION, + deposit_balance: (20020 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 20020 * QUOTE_PRECISION_U64, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, scaled_balance: 10000 * SPOT_BALANCE_PRECISION, @@ -1608,10 +1620,10 @@ mod revenue_pool_transfer_tests { ..PerpMarket::default() }; let mut spot_market = SpotMarket { - deposit_balance: 20020000 * SPOT_BALANCE_PRECISION, + deposit_balance: (20020000 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 20020000 * QUOTE_PRECISION_U64, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, scaled_balance: 10000 * SPOT_BALANCE_PRECISION, diff --git a/programs/drift/src/controller/insurance/tests.rs b/programs/drift/src/controller/insurance/tests.rs index c71948c3d3..2a1d4a30d2 100644 --- a/programs/drift/src/controller/insurance/tests.rs +++ b/programs/drift/src/controller/insurance/tests.rs @@ -25,8 +25,8 @@ pub fn basic_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -72,7 +72,7 @@ pub fn basic_stake_if_test() { .unwrap(); assert_eq!( if_stake.last_withdraw_request_shares, - if_stake.unchecked_if_shares() + if_stake.unchecked_if_shares().into() ); assert_eq!(if_stake.last_withdraw_request_value, if_balance - 1); //rounding in favor assert_eq!(if_stake.unchecked_if_shares(), amount as u128); @@ -92,7 +92,7 @@ pub fn basic_stake_if_test() { assert_eq!(if_stake.unchecked_if_shares(), 0); assert_eq!(if_stake.cost_basis, 1); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(spot_market.insurance_fund.total_shares, 0); assert_eq!(spot_market.insurance_fund.shares_base, 0); @@ -124,8 +124,8 @@ pub fn basic_seeded_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -177,7 +177,7 @@ pub fn basic_seeded_stake_if_test() { .unwrap(); assert_eq!( if_stake.last_withdraw_request_shares, - if_stake.unchecked_if_shares() + if_stake.unchecked_if_shares().into() ); assert_eq!(if_stake.last_withdraw_request_value, 1000000); @@ -194,7 +194,7 @@ pub fn basic_seeded_stake_if_test() { assert_eq!(if_stake.unchecked_if_shares(), 0); assert_eq!(if_stake.cost_basis, 0); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(if_balance, 1000000000); @@ -224,8 +224,8 @@ pub fn large_num_seeded_stake_if_test() { // all funds in revenue pool let mut spot_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, revenue_settle_period: 1, @@ -269,7 +269,7 @@ pub fn large_num_seeded_stake_if_test() { .is_err()); assert_eq!(if_stake.unchecked_if_shares(), amount as u128); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) @@ -287,7 +287,7 @@ pub fn large_num_seeded_stake_if_test() { assert_eq!(flow, 11); assert_eq!(spot_market.revenue_pool.scaled_balance, 90099009901); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) @@ -307,7 +307,7 @@ pub fn large_num_seeded_stake_if_test() { .unwrap(); assert_eq!( if_stake.last_withdraw_request_shares, - if_stake.unchecked_if_shares() + if_stake.unchecked_if_shares().into() ); assert_eq!(if_stake.last_withdraw_request_value, 199000001); @@ -324,7 +324,7 @@ pub fn large_num_seeded_stake_if_test() { assert_eq!(if_stake.unchecked_if_shares(), 0); assert_eq!(if_stake.cost_basis, 0); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(if_balance, 199000000000011); assert_eq!(spot_market.insurance_fund.user_shares, 0); @@ -369,8 +369,8 @@ pub fn gains_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -494,8 +494,8 @@ pub fn losses_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -622,8 +622,8 @@ pub fn escrow_losses_stake_if_test() { }; let amount = (QUOTE_PRECISION * 100_000) as u64; // $100k let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 60 * 60 * 24 * 7, // 7 weeks ..InsuranceFund::default() @@ -658,7 +658,7 @@ pub fn escrow_losses_stake_if_test() { if_balance, ) .unwrap(); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); request_remove_insurance_fund_stake( n_shares / 3, @@ -669,7 +669,10 @@ pub fn escrow_losses_stake_if_test() { now, ) .unwrap(); - assert_eq!(if_stake.last_withdraw_request_shares, 33333333333); + assert_eq!( + if_stake.last_withdraw_request_shares, + 33333333333u128.into() + ); assert_eq!( if_stake.last_withdraw_request_value, expected_amount_returned @@ -719,8 +722,8 @@ pub fn escrow_gains_stake_if_test() { }; let amount = 100_000_384_939_u64; // $100k + change let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 60 * 60 * 24 * 7, // 7 weeks total_shares: 1, @@ -813,7 +816,7 @@ pub fn escrow_gains_stake_if_test() { now + 60 * 60 * 24 * 7 + 3254, )) .unwrap(); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); assert_eq!(if_stake.last_withdraw_request_value, 0); if_balance -= amount_returned; @@ -839,8 +842,8 @@ pub fn drained_stake_if_test_rebase_on_new_add() { let amount = 100_000_384_939_u64; // $100k + change let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 60 * 60 * 24 * 7, // 7 weeks total_shares: 100_000 * QUOTE_PRECISION, @@ -909,10 +912,10 @@ pub fn drained_stake_if_test_rebase_on_new_add() { ); assert_eq!(spot_market.insurance_fund.shares_base, 10); - assert_eq!(if_stake.if_base, 10); + assert_eq!(if_stake.if_base, 10u128.into()); // check orig if stake is good (on add) - assert_eq!(orig_if_stake.if_base, 0); + assert_eq!(orig_if_stake.if_base, 0u128.into()); assert_eq!(orig_if_stake.unchecked_if_shares(), 80000000000); let expected_shares_for_amount = @@ -931,7 +934,7 @@ pub fn drained_stake_if_test_rebase_on_new_add() { .unwrap(); assert_eq!(spot_market.insurance_fund.shares_base, 10); - assert_eq!(orig_if_stake.if_base, 10); + assert_eq!(orig_if_stake.if_base, 10u128.into()); assert_eq!( orig_if_stake.unchecked_if_shares(), 80000000000 / 10000000000 + expected_shares_for_amount @@ -947,8 +950,8 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all() { let mut if_balance = 0; let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, total_shares: 100_000 * QUOTE_PRECISION, @@ -1041,8 +1044,8 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { let mut if_balance = 0; let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, total_shares: 100_930_021_053, @@ -1093,7 +1096,7 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { let unstake_amt = if_stake.unchecked_if_shares() / 2; assert_eq!(unstake_amt, 20000000000); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(if_stake.last_withdraw_request_ts, 0); @@ -1108,7 +1111,10 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { .unwrap(); // rebase occurs in request - assert_eq!(if_stake.last_withdraw_request_shares, unstake_amt / 1000); + assert_eq!( + if_stake.last_withdraw_request_shares, + (unstake_amt / 1000).into() + ); // (that rebase occurs when you pass in shares you wanna unstake) :/ assert_eq!(if_stake.unchecked_if_shares(), 40000000); assert_eq!(if_stake.last_withdraw_request_value, 328245); @@ -1186,8 +1192,11 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { // check rebase math assert_eq!(if_stake.unchecked_if_shares(), 20000000); - assert_eq!(if_stake.if_base, spot_market.insurance_fund.shares_base); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!( + if_stake.if_base, + spot_market.insurance_fund.shares_base.into() + ); + assert_eq!(if_stake.last_withdraw_request_shares, 0u128.into()); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(amount_returned, 328245); @@ -1255,8 +1264,8 @@ pub fn multiple_if_stakes_and_rebase() { let amount = (QUOTE_PRECISION * 100_000) as u64; // $100k let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -1290,7 +1299,7 @@ pub fn multiple_if_stakes_and_rebase() { // if gets drained if_balance = QUOTE_PRECISION as u64; - assert_eq!(if_stake_1.if_base, 0); + assert_eq!(if_stake_1.if_base, 0u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 0); request_remove_insurance_fund_stake( @@ -1302,7 +1311,7 @@ pub fn multiple_if_stakes_and_rebase() { 0, ) .unwrap(); - assert_eq!(if_stake_1.if_base, 4); + assert_eq!(if_stake_1.if_base, 4u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 4); let amount_returned = (remove_insurance_fund_stake( @@ -1316,7 +1325,7 @@ pub fn multiple_if_stakes_and_rebase() { assert_eq!(amount_returned, 500000); if_balance -= amount_returned; - assert_eq!(if_stake_2.if_base, 0); + assert_eq!(if_stake_2.if_base, 0u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 4); request_remove_insurance_fund_stake( if_stake_2.unchecked_if_shares(), @@ -1327,10 +1336,10 @@ pub fn multiple_if_stakes_and_rebase() { 0, ) .unwrap(); - assert_eq!(if_stake_2.if_base, 4); + assert_eq!(if_stake_2.if_base, 4u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 4); assert_eq!( - if_stake_2.if_base < spot_market.insurance_fund.total_shares, + if_stake_2.if_base.as_u128() < spot_market.insurance_fund.total_shares, true ); assert_eq!( @@ -1374,8 +1383,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { let amount = (QUOTE_PRECISION * 100_000) as u64; // $100k let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -1430,7 +1439,7 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { // if gets drained if_balance = QUOTE_PRECISION as u64; - assert_eq!(if_stake_1.if_base, 0); + assert_eq!(if_stake_1.if_base, 0u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 0); request_remove_insurance_fund_stake( @@ -1442,7 +1451,7 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { 0, ) .unwrap(); - assert_eq!(if_stake_1.if_base, 4); + assert_eq!(if_stake_1.if_base, 4u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 4); let amount_returned = (remove_insurance_fund_stake( @@ -1456,7 +1465,7 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { assert_eq!(amount_returned, 499750); if_balance -= amount_returned; - assert_eq!(if_stake_2.if_base, 0); + assert_eq!(if_stake_2.if_base, 0u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 4); request_remove_insurance_fund_stake( if_stake_2.unchecked_if_shares(), @@ -1467,10 +1476,10 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { 0, ) .unwrap(); - assert_eq!(if_stake_2.if_base, 4); + assert_eq!(if_stake_2.if_base, 4u128.into()); assert_eq!(spot_market.insurance_fund.shares_base, 4); assert_eq!( - if_stake_2.if_base < spot_market.insurance_fund.total_shares, + if_stake_2.if_base.as_u128() < spot_market.insurance_fund.total_shares, true ); assert_eq!( @@ -1536,8 +1545,8 @@ fn test_transfer_protocol_owned_stake() { }; let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() diff --git a/programs/drift/src/controller/liquidation/tests.rs b/programs/drift/src/controller/liquidation/tests.rs index e8cf21acde..e2aff3ef14 100644 --- a/programs/drift/src/controller/liquidation/tests.rs +++ b/programs/drift/src/controller/liquidation/tests.rs @@ -86,7 +86,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -236,7 +236,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -385,7 +385,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -520,7 +520,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -669,7 +669,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -849,7 +849,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1048,7 +1048,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1180,7 +1180,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1312,7 +1312,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1458,7 +1458,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1735,7 +1735,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1872,7 +1872,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1997,7 +1997,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2125,7 +2125,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2254,7 +2254,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2464,7 +2464,7 @@ pub mod liquidate_perp_with_fill { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2673,7 +2673,7 @@ pub mod liquidate_perp_with_fill { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2887,7 +2887,7 @@ pub mod liquidate_perp_with_fill { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -3058,7 +3058,7 @@ pub mod liquidate_perp_with_fill { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -3226,11 +3226,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3244,15 +3244,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -3369,11 +3369,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3387,15 +3387,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 1442 / 10000), @@ -3543,11 +3543,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3561,15 +3561,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -3762,11 +3762,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3780,15 +3780,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -3889,11 +3889,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3907,15 +3907,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -4016,11 +4016,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4034,15 +4034,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -4148,11 +4148,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4166,15 +4166,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 10 * SPOT_BALANCE_PRECISION, - borrow_balance: 10 * SPOT_BALANCE_PRECISION, + deposit_balance: (10 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (10 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -4378,11 +4378,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4396,15 +4396,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 20, historical_oracle_data: HistoricalOracleData { @@ -4418,11 +4418,11 @@ pub mod liquidate_spot { let mut usdt_market = SpotMarket { market_index: 2, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4610,11 +4610,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4628,15 +4628,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -4765,11 +4765,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4783,15 +4783,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -4964,11 +4964,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4982,15 +4982,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5119,11 +5119,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5137,15 +5137,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5266,11 +5266,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5284,15 +5284,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5413,11 +5413,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5431,15 +5431,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION / 50, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: (SPOT_BALANCE_PRECISION / 50).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -5570,11 +5570,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5588,15 +5588,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, - borrow_balance: 11 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (11 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -5844,11 +5844,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5862,15 +5862,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6000,11 +6000,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6018,15 +6018,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6158,11 +6158,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6176,15 +6176,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6313,11 +6313,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6331,15 +6331,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6460,11 +6460,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6478,15 +6478,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6608,11 +6608,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6626,15 +6626,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6764,11 +6764,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6782,15 +6782,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6996,11 +6996,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, asset_tier: AssetTier::Collateral, historical_oracle_data: HistoricalOracleData { @@ -7016,15 +7016,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 10 * SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: (10 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -7266,11 +7266,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -7284,15 +7284,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -7509,7 +7509,7 @@ pub mod resolve_perp_bankruptcy { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -7723,9 +7723,9 @@ pub mod resolve_perp_bankruptcy { let mut spot_market = SpotMarket { market_index: 0, - deposit_balance: 500 * SPOT_BALANCE_PRECISION, + deposit_balance: (500 * SPOT_BALANCE_PRECISION).into(), oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -7961,12 +7961,12 @@ pub mod resolve_spot_bankruptcy { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -8015,11 +8015,11 @@ pub mod resolve_spot_bankruptcy { expected_user.total_social_loss = 100000000; let mut expected_spot_market = spot_market; - expected_spot_market.borrow_balance = 0; + expected_spot_market.borrow_balance = 0u128.into(); expected_spot_market.cumulative_deposit_interest = - 9 * SPOT_CUMULATIVE_INTEREST_PRECISION / 10; - expected_spot_market.total_social_loss = 100 * QUOTE_PRECISION; - expected_spot_market.total_quote_social_loss = 100 * QUOTE_PRECISION; + (9 * SPOT_CUMULATIVE_INTEREST_PRECISION / 10).into(); + expected_spot_market.total_social_loss = (100 * QUOTE_PRECISION).into(); + expected_spot_market.total_quote_social_loss = (100 * QUOTE_PRECISION).into(); resolve_spot_bankruptcy( 0, @@ -8040,8 +8040,12 @@ pub mod resolve_spot_bankruptcy { let spot_market = spot_market_map.get_ref_mut(&0).unwrap(); let deposit_balance = spot_market.deposit_balance; - let deposit_token_amount = - get_token_amount(deposit_balance, &spot_market, &SpotBalanceType::Deposit).unwrap(); + let deposit_token_amount = get_token_amount( + deposit_balance.into(), + &spot_market, + &SpotBalanceType::Deposit, + ) + .unwrap(); assert_eq!(deposit_token_amount, 900 * QUOTE_PRECISION); } @@ -8126,7 +8130,7 @@ pub mod set_user_status_to_being_liquidated { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -8303,7 +8307,7 @@ pub mod set_user_status_to_being_liquidated { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -8413,11 +8417,11 @@ pub mod liquidate_spot_with_swap { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -8431,15 +8435,15 @@ pub mod liquidate_spot_with_swap { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 100, historical_oracle_data: HistoricalOracleData { diff --git a/programs/drift/src/controller/orders/amm_jit_tests.rs b/programs/drift/src/controller/orders/amm_jit_tests.rs index 87c160b78d..14595f6083 100644 --- a/programs/drift/src/controller/orders/amm_jit_tests.rs +++ b/programs/drift/src/controller/orders/amm_jit_tests.rs @@ -242,7 +242,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -439,7 +439,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -653,7 +653,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -863,7 +863,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1084,7 +1084,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1298,7 +1298,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1517,7 +1517,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1722,7 +1722,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1919,7 +1919,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2132,7 +2132,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2352,7 +2352,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2635,7 +2635,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2921,7 +2921,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, diff --git a/programs/drift/src/controller/orders/fuel_tests.rs b/programs/drift/src/controller/orders/fuel_tests.rs index 24959f9e3b..4d48c92cd7 100644 --- a/programs/drift/src/controller/orders/fuel_tests.rs +++ b/programs/drift/src/controller/orders/fuel_tests.rs @@ -178,7 +178,7 @@ pub mod fuel_scoring { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -454,7 +454,7 @@ pub mod fuel_scoring { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -471,8 +471,8 @@ pub mod fuel_scoring { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION * 2, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION * 4, + cumulative_deposit_interest: (SPOT_CUMULATIVE_INTEREST_PRECISION * 2).into(), + cumulative_borrow_interest: (SPOT_CUMULATIVE_INTEREST_PRECISION * 4).into(), decimals: 9, initial_asset_weight: SPOT_WEIGHT_PRECISION * 8 / 10, maintenance_asset_weight: SPOT_WEIGHT_PRECISION * 9 / 10, @@ -724,7 +724,7 @@ pub mod fuel_scoring { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, diff --git a/programs/drift/src/controller/orders/tests.rs b/programs/drift/src/controller/orders/tests.rs index 5a51991cba..f695c62ba9 100644 --- a/programs/drift/src/controller/orders/tests.rs +++ b/programs/drift/src/controller/orders/tests.rs @@ -183,7 +183,7 @@ pub mod fill_order_protected_maker { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3279,7 +3279,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3525,7 +3525,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3742,7 +3742,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3962,7 +3962,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4182,7 +4182,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4350,7 +4350,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4551,7 +4551,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4740,7 +4740,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4920,7 +4920,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5108,7 +5108,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5276,7 +5276,7 @@ pub mod fulfill_order { // let mut spot_market = SpotMarket { // market_index: 0, // oracle_source: OracleSource::QuoteAsset, - // cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + // cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), // decimals: 6, // initial_asset_weight: SPOT_WEIGHT_PRECISION, // maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5437,7 +5437,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5749,7 +5749,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6006,7 +6006,7 @@ pub mod fill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6207,7 +6207,7 @@ pub mod fill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6373,7 +6373,7 @@ pub mod fill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -6547,7 +6547,7 @@ pub mod fill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6705,11 +6705,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -6769,7 +6769,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -6830,11 +6830,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 161 * SPOT_BALANCE_PRECISION, + deposit_balance: (161 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -6894,7 +6894,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 160000000); assert_eq!(maker_stats.fees.total_fee_rebate, 48000); - assert_eq!(base_market.total_spot_fee, 32000); + assert_eq!(base_market.total_spot_fee, 32000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 32000000); } @@ -6955,11 +6955,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7019,7 +7019,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -7080,11 +7080,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7144,7 +7144,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 70000000); assert_eq!(maker_stats.fees.total_fee_rebate, 21000); - assert_eq!(base_market.total_spot_fee, 14000); + assert_eq!(base_market.total_spot_fee, 14000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 14000000); } @@ -7205,11 +7205,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7304,11 +7304,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7403,11 +7403,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7502,11 +7502,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7601,11 +7601,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7677,7 +7677,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -7738,11 +7738,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7814,7 +7814,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -7877,11 +7877,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7941,7 +7941,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -8000,11 +8000,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8064,7 +8064,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -8123,11 +8123,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8187,7 +8187,7 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); + assert_eq!(base_market.total_spot_fee, 20000u128.into()); assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); } @@ -8247,11 +8247,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8344,11 +8344,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0u128.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8441,12 +8441,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 101 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() @@ -8541,11 +8541,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0u128.into(), ..SpotMarket::default_quote_market() }; @@ -8638,12 +8638,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -8737,12 +8737,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0u128.into(), deposit_token_twap: 0, ..SpotMarket::default_quote_market() }; @@ -8836,12 +8836,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -8935,11 +8935,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0u128.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -9032,12 +9032,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 101 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -9131,14 +9131,14 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), utilization_twap: SPOT_UTILIZATION_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, - borrow_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (101 * SPOT_BALANCE_PRECISION).into(), utilization_twap: SPOT_UTILIZATION_PRECISION as u64, ..SpotMarket::default_quote_market() }; @@ -9274,12 +9274,12 @@ pub mod fulfill_spot_order { // let mut base_market = SpotMarket { // oracle: oracle_price_key, // market_index: 1, - // deposit_balance: SPOT_BALANCE_PRECISION, + // deposit_balance: SPOT_BALANCE_PRECISION.into(), // ..SpotMarket::default_base_market() // }; // create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); // let mut quote_market = SpotMarket { - // deposit_balance: 101 * SPOT_BALANCE_PRECISION, + // deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), // ..SpotMarket::default_quote_market() // }; // create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -9445,7 +9445,7 @@ pub mod fulfill_spot_order { let mut base_market = SpotMarket { market_index: 1, - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), ..SpotMarket::default_base_market() @@ -9453,7 +9453,7 @@ pub mod fulfill_spot_order { create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut second_base_market = SpotMarket { market_index: 2, - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), ..SpotMarket::default_base_market() }; @@ -9464,7 +9464,7 @@ pub mod fulfill_spot_order { ); let mut quote_market = SpotMarket { market_index: 0, - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -9717,7 +9717,7 @@ pub mod fulfill_spot_order { let mut base_market = SpotMarket { market_index: 1, - deposit_balance: 2 * SPOT_BALANCE_PRECISION, + deposit_balance: (2 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), ..SpotMarket::default_base_market() @@ -9725,7 +9725,7 @@ pub mod fulfill_spot_order { create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut quote_market = SpotMarket { market_index: 0, - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -10004,7 +10004,7 @@ pub mod fulfill_spot_order { let mut base_market = SpotMarket { market_index: 1, - deposit_balance: 10 * SPOT_BALANCE_PRECISION, + deposit_balance: (10 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 10 * LAMPORTS_PER_SOL_U64, oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), @@ -10013,7 +10013,7 @@ pub mod fulfill_spot_order { create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut quote_market = SpotMarket { market_index: 0, - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -10192,13 +10192,13 @@ pub mod fill_spot_order { let perp_market_map = PerpMarketMap::empty(); let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), historical_oracle_data: HistoricalOracleData::default_price(PRICE_PRECISION_I64), ..SpotMarket::default_base_market() }; create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -10424,9 +10424,9 @@ pub mod force_cancel_orders { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - deposit_balance: SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -10436,9 +10436,9 @@ pub mod force_cancel_orders { let mut sol_spot_market = SpotMarket { market_index: 1, - deposit_balance: SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -10714,7 +10714,7 @@ pub mod get_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -10904,7 +10904,7 @@ pub mod get_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11095,7 +11095,7 @@ pub mod get_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11272,7 +11272,7 @@ pub mod get_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11523,7 +11523,7 @@ pub mod get_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11716,7 +11716,7 @@ pub mod get_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11919,7 +11919,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11929,7 +11929,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12076,7 +12076,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12086,7 +12086,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12235,7 +12235,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12245,7 +12245,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12379,7 +12379,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12389,7 +12389,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12601,7 +12601,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12611,7 +12611,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12762,7 +12762,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12772,7 +12772,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; diff --git a/programs/drift/src/controller/pnl/delisting.rs b/programs/drift/src/controller/pnl/delisting.rs index db148230f0..bc28b31940 100644 --- a/programs/drift/src/controller/pnl/delisting.rs +++ b/programs/drift/src/controller/pnl/delisting.rs @@ -109,7 +109,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -231,7 +231,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -341,7 +341,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -455,7 +455,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -569,7 +569,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -686,14 +686,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -906,14 +906,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1129,14 +1129,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1334,14 +1334,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 300000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (300000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1350,15 +1350,15 @@ pub mod delisting_test { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), @@ -1759,15 +1759,15 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1776,15 +1776,15 @@ pub mod delisting_test { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), @@ -2143,15 +2143,15 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 40000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (40000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -2160,15 +2160,15 @@ pub mod delisting_test { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), diff --git a/programs/drift/src/controller/pnl/tests.rs b/programs/drift/src/controller/pnl/tests.rs index 4a35df4e49..6efc1162ff 100644 --- a/programs/drift/src/controller/pnl/tests.rs +++ b/programs/drift/src/controller/pnl/tests.rs @@ -107,10 +107,10 @@ pub fn user_no_position() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default() }; create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); @@ -226,11 +226,11 @@ pub fn user_does_not_meet_maintenance_requirement() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -351,11 +351,11 @@ pub fn user_does_not_meet_strict_maintenance_requirement() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap_5min: PRICE_PRECISION_I64 / 2, ..HistoricalOracleData::default_price(QUOTE_PRECISION_I64) @@ -494,11 +494,11 @@ pub fn user_unsettled_negative_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -630,11 +630,11 @@ pub fn user_unsettled_positive_pnl_more_than_pool() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -766,11 +766,11 @@ pub fn user_unsettled_positive_pnl_less_than_pool() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -905,11 +905,11 @@ pub fn market_fee_pool_receives_portion() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1049,11 +1049,11 @@ pub fn market_fee_pool_pays_back_to_pnl_pool() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1186,11 +1186,11 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1324,11 +1324,11 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl_price_breached() let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1459,11 +1459,11 @@ pub fn user_long_negative_unrealized_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1597,11 +1597,11 @@ pub fn user_short_positive_unrealized_pnl_up_to_max_positive_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1735,11 +1735,11 @@ pub fn user_short_negative_unrealized_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1872,11 +1872,11 @@ pub fn user_invalid_oracle_position() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; diff --git a/programs/drift/src/controller/position/tests.rs b/programs/drift/src/controller/position/tests.rs index 390e8502a5..e8ff01fefe 100644 --- a/programs/drift/src/controller/position/tests.rs +++ b/programs/drift/src/controller/position/tests.rs @@ -71,12 +71,12 @@ fn amm_pool_balance_liq_fees_example() { ); let mut spot_market = SpotMarket { - cumulative_deposit_interest: 11425141382, - cumulative_borrow_interest: 12908327537, + cumulative_deposit_interest: 11425141382u128.into(), + cumulative_borrow_interest: 12908327537u128.into(), decimals: 6, ..SpotMarket::default() }; - spot_market.deposit_balance = 10_u128.pow(19_u32); + spot_market.deposit_balance = 10_u128.pow(19_u32).into(); spot_market.deposit_token_twap = 10_u64.pow(16_u32); let spot_position = SpotPosition::default(); @@ -204,7 +204,7 @@ fn amm_pred_expiry_price_yes_market_example() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -317,7 +317,7 @@ fn amm_pred_expiry_price_market_example() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -429,7 +429,7 @@ fn amm_pred_settle_market_example() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, diff --git a/programs/drift/src/controller/spot_balance/tests.rs b/programs/drift/src/controller/spot_balance/tests.rs index b1c19153c1..f49e8ded86 100644 --- a/programs/drift/src/controller/spot_balance/tests.rs +++ b/programs/drift/src/controller/spot_balance/tests.rs @@ -102,14 +102,14 @@ fn test_daily_withdraw_limits() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, status: MarketStatus::Active, @@ -120,15 +120,15 @@ fn test_daily_withdraw_limits() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: (SPOT_BALANCE_PRECISION * 10) as u64, borrow_token_twap: 0, @@ -160,11 +160,11 @@ fn test_daily_withdraw_limits() { assert_eq!( spot_market.cumulative_deposit_interest, - SPOT_CUMULATIVE_INTEREST_PRECISION + SPOT_CUMULATIVE_INTEREST_PRECISION.into() ); assert_eq!( spot_market.cumulative_borrow_interest, - SPOT_CUMULATIVE_INTEREST_PRECISION + SPOT_CUMULATIVE_INTEREST_PRECISION.into() ); // TEST USER WITHDRAW @@ -181,13 +181,13 @@ fn test_daily_withdraw_limits() { .is_err()); spot_market = spot_market_backup; user = user_backup; - assert_eq!(spot_market.deposit_balance, SPOT_BALANCE_PRECISION); + assert_eq!(spot_market.deposit_balance, SPOT_BALANCE_PRECISION.into()); // .50 * .2 = .1 assert_eq!(spot_market.deposit_token_twap, 500000); assert_eq!(user.spot_positions[0].scaled_balance, 1000000000); - assert_eq!(spot_market.deposit_balance, 1000000000); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance, 1000000000u128.into()); + assert_eq!(spot_market.borrow_balance, 0u128.into()); assert_eq!((amount / 2), 500000); update_spot_balances_and_cumulative_deposits_with_limits( (amount / 2) as u128, @@ -198,8 +198,8 @@ fn test_daily_withdraw_limits() { .unwrap(); assert_eq!(user.spot_positions[0].scaled_balance, 499999999); assert_eq!(spot_market.deposit_token_twap, 500000); - assert_eq!(spot_market.deposit_balance, 499999999); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance, 499999999u128.into()); + assert_eq!(spot_market.borrow_balance, 0u128.into()); // .50 * .25 = .125 update_spot_balances_and_cumulative_deposits_with_limits( @@ -222,7 +222,7 @@ fn test_daily_withdraw_limits() { .is_err()); spot_market = spot_market_backup; user = user_backup; - assert_eq!(spot_market.deposit_balance, 375001998); + assert_eq!(spot_market.deposit_balance, 375001998u128.into()); assert_eq!(user.spot_positions[0].scaled_balance, 375001998); assert_eq!(user.spot_positions[0].market_index, 0); @@ -245,7 +245,7 @@ fn test_daily_withdraw_limits() { &mut user, ) .unwrap(); - assert_eq!(spot_market.deposit_balance, 100000375001998); + assert_eq!(spot_market.deposit_balance, 100000375001998u128.into()); assert_eq!(user.spot_positions[0].scaled_balance, 100000375001998); assert_eq!(user.spot_positions[1].scaled_balance, 0); @@ -268,7 +268,7 @@ fn test_daily_withdraw_limits() { }), ..User::default() }; - sol_spot_market.deposit_balance = 50 * SPOT_BALANCE_PRECISION; + sol_spot_market.deposit_balance = (50 * SPOT_BALANCE_PRECISION).into(); sol_spot_market.deposit_token_twap = (500 * SPOT_BALANCE_PRECISION) as u64; sol_spot_market.optimal_utilization = 1_000_000 as u32; //20% APR @@ -344,8 +344,8 @@ fn test_daily_withdraw_limits() { ) .unwrap(); - assert_eq!(sol_spot_market.deposit_balance, 50000000000); - assert_eq!(sol_spot_market.borrow_balance, 8000000002); + assert_eq!(sol_spot_market.deposit_balance, 50000000000u128.into()); + assert_eq!(sol_spot_market.borrow_balance, 8000000002u128.into()); assert_eq!(sol_spot_market.borrow_token_twap, 0); update_spot_market_cumulative_interest(&mut sol_spot_market, None, now + 3655 * 24).unwrap(); @@ -419,14 +419,14 @@ fn test_check_withdraw_limits() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, status: MarketStatus::Active, @@ -437,15 +437,15 @@ fn test_check_withdraw_limits() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 2 * SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: (2 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, deposit_token_twap: 28_000_000_000_u64, status: MarketStatus::Active, @@ -512,8 +512,8 @@ fn test_check_withdraw_limits_below_optimal_utilization() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: 1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, - cumulative_borrow_interest: 1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + cumulative_deposit_interest: (1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), + cumulative_borrow_interest: (1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), optimal_utilization: 700000, optimal_borrow_rate: 60000, @@ -524,8 +524,8 @@ fn test_check_withdraw_limits_below_optimal_utilization() { maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 200_000 * SPOT_BALANCE_PRECISION, // 200k sol - borrow_balance: 100_000 * SPOT_BALANCE_PRECISION, + deposit_balance: (200_000 * SPOT_BALANCE_PRECISION).into(), // 200k sol + borrow_balance: (100_000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, deposit_token_twap: 204000000000000_u64, borrow_token_twap: 122200000000000_u64, @@ -541,13 +541,13 @@ fn test_check_withdraw_limits_below_optimal_utilization() { ); // below optimal util let deposit_tokens_1 = get_token_amount( - sol_spot_market.deposit_balance, + sol_spot_market.deposit_balance.into(), &sol_spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - sol_spot_market.borrow_balance, + sol_spot_market.borrow_balance.into(), &sol_spot_market, &SpotBalanceType::Borrow, ) @@ -584,11 +584,11 @@ fn test_check_withdraw_limits_below_optimal_utilization() { assert_eq!(valid_withdraw, true); // ensure it fails due to higher min_dep above - sol_spot_market.deposit_balance = 174571428571428 / 1020 * 1000; + sol_spot_market.deposit_balance = (174571428571428 / 1020 * 1000).into(); sol_spot_market.utilization_twap = 100000; let deposit_tokens_1 = get_token_amount( - sol_spot_market.deposit_balance, + sol_spot_market.deposit_balance.into(), &sol_spot_market, &SpotBalanceType::Deposit, ) @@ -613,8 +613,8 @@ fn test_check_withdraw_limits_above_optimal_utilization() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: 1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, - cumulative_borrow_interest: 1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + cumulative_deposit_interest: (1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), + cumulative_borrow_interest: (1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), optimal_utilization: 700000, // 70% optimal_borrow_rate: 60000, // 6% @@ -625,8 +625,8 @@ fn test_check_withdraw_limits_above_optimal_utilization() { maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 200_000 * SPOT_BALANCE_PRECISION, // 200k sol - borrow_balance: 160_000 * SPOT_BALANCE_PRECISION, + deposit_balance: (200_000 * SPOT_BALANCE_PRECISION).into(), // 200k sol + borrow_balance: (160_000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, deposit_token_twap: 204000000000000_u64, borrow_token_twap: 199200000000000_u64, @@ -642,13 +642,13 @@ fn test_check_withdraw_limits_above_optimal_utilization() { ); // below optimal util let deposit_tokens_1 = get_token_amount( - sol_spot_market.deposit_balance, + sol_spot_market.deposit_balance.into(), &sol_spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - sol_spot_market.borrow_balance, + sol_spot_market.borrow_balance.into(), &sol_spot_market, &SpotBalanceType::Borrow, ) @@ -711,7 +711,7 @@ fn test_check_withdraw_limits_above_optimal_utilization() { assert_eq!(valid_withdraw, true); // now ensure it fails due to higher min_dep above - sol_spot_market.deposit_balance = min_dep / 1020 * 1000; + sol_spot_market.deposit_balance = (min_dep / 1020 * 1000).into(); let valid_withdraw = check_withdraw_limits(&sol_spot_market, None, None).unwrap(); assert_eq!(valid_withdraw, false); } @@ -765,13 +765,13 @@ fn check_fee_collection() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64, optimal_utilization: SPOT_UTILIZATION_PRECISION_U32 / 2, @@ -787,15 +787,15 @@ fn check_fee_collection() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, insurance_fund: InsuranceFund { revenue_settle_period: 1, @@ -827,8 +827,8 @@ fn check_fee_collection() { spot_market.insurance_fund.total_factor = 1000; //1_000_000 assert_eq!(spot_market.utilization_twap, 0); - assert_eq!(spot_market.deposit_balance, 1000000000); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance, 1000000000u128.into()); + assert_eq!(spot_market.borrow_balance, 0u128.into()); let amount = QUOTE_PRECISION / 4; update_spot_balances_and_cumulative_deposits_with_limits( @@ -842,27 +842,33 @@ fn check_fee_collection() { assert_eq!(user.total_deposits, 0); assert_eq!(user.total_withdraws, 0); - assert_eq!(spot_market.deposit_balance, 1000000000); - assert_eq!(spot_market.borrow_balance, 125000001); + assert_eq!(spot_market.deposit_balance, 1000000000u128.into()); + assert_eq!(spot_market.borrow_balance, 125000001u128.into()); assert_eq!(spot_market.utilization_twap, 0); update_spot_market_cumulative_interest(&mut spot_market, None, now + 100).unwrap(); assert_eq!(spot_market.revenue_pool.scaled_balance, 0); - assert_eq!(spot_market.cumulative_deposit_interest, 10000019799); - assert_eq!(spot_market.cumulative_borrow_interest, 10000158551); + assert_eq!( + spot_market.cumulative_deposit_interest, + 10000019799u128.into() + ); + assert_eq!( + spot_market.cumulative_borrow_interest, + 10000158551u128.into() + ); assert_eq!(spot_market.last_interest_ts, 100); assert_eq!(spot_market.last_twap_ts, 100); assert_eq!(spot_market.utilization_twap, 143); let deposit_tokens_1 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -884,18 +890,24 @@ fn check_fee_collection() { assert_eq!(spot_market.last_twap_ts, 7500); assert_eq!(spot_market.utilization_twap, 10846); - assert_eq!(spot_market.cumulative_deposit_interest, 10001484937); - assert_eq!(spot_market.cumulative_borrow_interest, 10011891454); + assert_eq!( + spot_market.cumulative_deposit_interest, + 10001484937u128.into() + ); + assert_eq!( + spot_market.cumulative_borrow_interest, + 10011891454u128.into() + ); assert_eq!(spot_market.revenue_pool.scaled_balance, 0); let deposit_tokens_2 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_2 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -926,18 +938,24 @@ fn check_fee_collection() { now = now + 750 + (60 * 60 * 24 * 365); - assert_eq!(spot_market.cumulative_deposit_interest, 16257818378); - assert_eq!(spot_market.cumulative_borrow_interest, 60112684636); + assert_eq!( + spot_market.cumulative_deposit_interest, + 16257818378u128.into() + ); + assert_eq!( + spot_market.cumulative_borrow_interest, + 60112684636u128.into() + ); assert_eq!(spot_market.revenue_pool.scaled_balance, 385045); let deposit_tokens_3 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_3 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -985,13 +1003,13 @@ fn check_fee_collection() { assert_eq!(spot_market.utilization_twap, 462005); let deposit_tokens_4 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_4 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1026,13 +1044,13 @@ fn check_fee_collection() { .unwrap(); let deposit_tokens_5 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_5 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1070,13 +1088,13 @@ fn check_fee_collection() { .unwrap(); let deposit_tokens_6 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_6 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1138,13 +1156,13 @@ fn check_fee_collection_larger_nums() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000000 * SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: (1000000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, optimal_utilization: SPOT_UTILIZATION_PRECISION_U32 / 2, @@ -1158,15 +1176,15 @@ fn check_fee_collection_larger_nums() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, ..SpotMarket::default() }; @@ -1195,9 +1213,9 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.utilization_twap, 0); assert_eq!( spot_market.deposit_balance, - 1000000 * SPOT_BALANCE_PRECISION + (1000000 * SPOT_BALANCE_PRECISION).into() ); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.borrow_balance, 0u128.into()); let amount = 540510 * QUOTE_PRECISION; update_spot_balances( @@ -1211,9 +1229,9 @@ fn check_fee_collection_larger_nums() { assert_eq!( spot_market.deposit_balance, - 1000000 * SPOT_BALANCE_PRECISION + (1000000 * SPOT_BALANCE_PRECISION).into() ); - assert_eq!(spot_market.borrow_balance, 540510000000001); + assert_eq!(spot_market.borrow_balance, 540510000000001u128.into()); assert_eq!(spot_market.utilization_twap, 0); update_spot_market_cumulative_interest(&mut spot_market, None, now + 100).unwrap(); @@ -1221,20 +1239,26 @@ fn check_fee_collection_larger_nums() { let br = calculate_borrow_rate(&spot_market, spot_market.get_utilization().unwrap()).unwrap(); assert_eq!(br, 20173678); assert_eq!(spot_market.revenue_pool.scaled_balance, 3457492406); - assert_eq!(spot_market.cumulative_deposit_interest, 10000311188); - assert_eq!(spot_market.cumulative_borrow_interest, 10000639702); + assert_eq!( + spot_market.cumulative_deposit_interest, + 10000311188u128.into() + ); + assert_eq!( + spot_market.cumulative_borrow_interest, + 10000639702u128.into() + ); assert_eq!(spot_market.last_interest_ts, 100); assert_eq!(spot_market.last_twap_ts, 100); assert_eq!(spot_market.utilization_twap, 624); let deposit_tokens_1 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1256,18 +1280,24 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.last_twap_ts, 7500); assert_eq!(spot_market.utilization_twap, 46964); - assert_eq!(spot_market.cumulative_deposit_interest, 10023340555); - assert_eq!(spot_market.cumulative_borrow_interest, 10047980763); + assert_eq!( + spot_market.cumulative_deposit_interest, + 10023340555u128.into() + ); + assert_eq!( + spot_market.cumulative_borrow_interest, + 10047980763u128.into() + ); assert_eq!(spot_market.revenue_pool.scaled_balance, 258744322775); let deposit_tokens_2 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_2 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1300,18 +1330,24 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.get_utilization().unwrap(), 961580); - assert_eq!(spot_market.cumulative_deposit_interest, 108608729074); - assert_eq!(spot_market.cumulative_borrow_interest, 212759822472); + assert_eq!( + spot_market.cumulative_deposit_interest, + 108608729074u128.into() + ); + assert_eq!( + spot_market.cumulative_borrow_interest, + 212759822472u128.into() + ); assert_eq!(spot_market.revenue_pool.scaled_balance, 101141669831135); let deposit_tokens_3 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_3 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1361,13 +1397,13 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.utilization_twap, 961580); let deposit_tokens_4 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance.into(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_4 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance.into(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1388,13 +1424,13 @@ fn test_multi_stage_borrow_rate_curve() { let spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1_000_000 * SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: (1_000_000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, optimal_utilization: SPOT_UTILIZATION_PRECISION_U32 * 70 / 100, // 70% @@ -1553,14 +1589,14 @@ fn attempt_borrow_with_massive_upnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1572,15 +1608,15 @@ fn attempt_borrow_with_massive_upnl() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, status: MarketStatus::Active, @@ -1682,13 +1718,13 @@ fn check_usdc_spot_market_twap() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1827,13 +1863,13 @@ fn check_spot_market_max_borrow_fraction() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1861,27 +1897,27 @@ fn check_spot_market_max_borrow_fraction() { assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_err()); - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 100_u128).into(); assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_err()); - spot_market.borrow_balance = spot_market.deposit_balance / (10000 - 2); // just above 10000th + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / (10000 - 2)).into(); // just above 10000th assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_err()); - spot_market.borrow_balance = spot_market.deposit_balance / (10000); // exactly 10000th of deposit + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 10000).into(); // exactly 10000th of deposit assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); - spot_market.borrow_balance = spot_market.deposit_balance / (10000 + 1); // < 10000th of deposit + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / (10000 + 1)).into(); // < 10000th of deposit assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); - spot_market.borrow_balance = spot_market.deposit_balance / 100000; // 1/10th of 10000 + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 100000).into(); // 1/10th of 10000 assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); @@ -1896,13 +1932,13 @@ fn check_spot_market_min_borrow_rate() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0u128.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1928,28 +1964,28 @@ fn check_spot_market_min_borrow_rate() { assert_eq!(accum_interest.deposit_interest, 0); spot_market.min_borrow_rate = 1; // .5% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 100).into(); let accum_interest = calculate_accumulated_interest(&spot_market, now + 10000).unwrap(); assert_eq!(accum_interest.borrow_interest, 15903); assert_eq!(accum_interest.deposit_interest, 159); spot_market.min_borrow_rate = 10; // 5% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 100).into(); let accum_interest = calculate_accumulated_interest(&spot_market, now + 10000).unwrap(); assert_eq!(accum_interest.borrow_interest, 159025); assert_eq!(accum_interest.deposit_interest, 1590); spot_market.min_borrow_rate = 10; // 5% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 100).into(); let accum_interest = calculate_accumulated_interest(&spot_market, now + 1000000).unwrap(); assert_eq!(accum_interest.borrow_interest, 15855372); assert_eq!(accum_interest.deposit_interest, 158553); spot_market.min_borrow_rate = 200; // 100% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.borrow_balance = (spot_market.deposit_balance.as_u128() / 100).into(); let accum_interest = calculate_accumulated_interest(&spot_market, now + 1000000).unwrap(); assert_eq!(accum_interest.borrow_interest, 317107433); diff --git a/programs/drift/src/controller/spot_position/tests.rs b/programs/drift/src/controller/spot_position/tests.rs index 9618d09969..fc2d3002a7 100644 --- a/programs/drift/src/controller/spot_position/tests.rs +++ b/programs/drift/src/controller/spot_position/tests.rs @@ -31,7 +31,7 @@ mod update_spot_position_balance { fn borrow() { let mut user = User::default(); let mut spot_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -55,7 +55,7 @@ mod update_spot_position_balance { let mut user2 = User::default(); let mut spot_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -111,12 +111,12 @@ mod update_spot_position_balance { }; let mut spot_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; let mut sol_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_base_market() }; diff --git a/programs/drift/src/instructions/lp_admin.rs b/programs/drift/src/instructions/lp_admin.rs index af7f91030b..65596a7eb2 100644 --- a/programs/drift/src/instructions/lp_admin.rs +++ b/programs/drift/src/instructions/lp_admin.rs @@ -62,7 +62,7 @@ pub fn handle_initialize_lp_pool( constituent_correlations: ctx.accounts.constituent_correlations.key(), constituents: 0, max_aum: max_aum.into(), - last_aum: 0.into(), + last_aum: 0u128.into(), last_aum_slot: 0, max_settle_quote_amount: max_settle_quote_amount_per_market, _padding: 0, diff --git a/programs/drift/src/math/insurance/tests.rs b/programs/drift/src/math/insurance/tests.rs index 46287cedb3..50420be9a7 100644 --- a/programs/drift/src/math/insurance/tests.rs +++ b/programs/drift/src/math/insurance/tests.rs @@ -101,8 +101,8 @@ pub fn basic_stake_if_test() { pub fn if_shares_lost_test() { let _amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, total_shares: 1000 * QUOTE_PRECISION, @@ -116,7 +116,7 @@ pub fn if_shares_lost_test() { if_stake .update_if_shares(100 * QUOTE_PRECISION, &spot_market) .unwrap(); - if_stake.last_withdraw_request_shares = 100 * QUOTE_PRECISION; + if_stake.last_withdraw_request_shares = (100 * QUOTE_PRECISION).into(); if_stake.last_withdraw_request_value = ((100 * QUOTE_PRECISION) - 1) as u64; let if_balance = (1000 * QUOTE_PRECISION) as u64; diff --git a/programs/drift/src/math/liquidation/tests.rs b/programs/drift/src/math/liquidation/tests.rs index 04c066b76e..f3720bc13d 100644 --- a/programs/drift/src/math/liquidation/tests.rs +++ b/programs/drift/src/math/liquidation/tests.rs @@ -543,8 +543,8 @@ mod calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy { fn zero_total_deposits() { let loss = 100 * QUOTE_PRECISION; let spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0u128.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), ..SpotMarket::default() }; @@ -559,8 +559,8 @@ mod calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy { fn non_zero_total_deposits() { let loss = 11 * QUOTE_PRECISION; let spot_market = SpotMarket { - deposit_balance: 120 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (120 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, ..SpotMarket::default() }; diff --git a/programs/drift/src/math/margin/tests.rs b/programs/drift/src/math/margin/tests.rs index d4b1eefd2e..b2de678000 100644 --- a/programs/drift/src/math/margin/tests.rs +++ b/programs/drift/src/math/margin/tests.rs @@ -195,34 +195,34 @@ mod test { decimals: 9, imf_factor: 0, scale_initial_asset_weight_start: 500_000 * QUOTE_PRECISION_U64, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), ..SpotMarket::default() }; let oracle_price = 25 * PRICE_PRECISION_I64; - sol_spot_market.deposit_balance = SPOT_BALANCE_PRECISION; + sol_spot_market.deposit_balance = SPOT_BALANCE_PRECISION.into(); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); assert_eq!(asset_weight, 9000); - sol_spot_market.deposit_balance = 20000 * SPOT_BALANCE_PRECISION; + sol_spot_market.deposit_balance = (20000 * SPOT_BALANCE_PRECISION).into(); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); assert_eq!(asset_weight, 9000); - sol_spot_market.deposit_balance = 40000 * SPOT_BALANCE_PRECISION; + sol_spot_market.deposit_balance = (40000 * SPOT_BALANCE_PRECISION).into(); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); assert_eq!(asset_weight, 4500); - sol_spot_market.deposit_balance = 60000 * SPOT_BALANCE_PRECISION; + sol_spot_market.deposit_balance = (60000 * SPOT_BALANCE_PRECISION).into(); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); @@ -443,11 +443,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -457,8 +457,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -534,11 +534,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -548,8 +548,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -625,13 +625,13 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -641,15 +641,15 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default() }; create_anchor_account_info!(sol_spot_market, SpotMarket, sol_spot_market_account_info); @@ -739,11 +739,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -753,8 +753,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -936,11 +936,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -950,8 +950,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1121,11 +1121,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1135,8 +1135,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1247,11 +1247,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1261,8 +1261,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION / 99, // big loss - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: (SPOT_CUMULATIVE_INTEREST_PRECISION / 99).into(), // big loss + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1370,11 +1370,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1384,8 +1384,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1520,11 +1520,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap_5min: PRICE_PRECISION_I64 * 9 / 10, @@ -1537,8 +1537,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1637,12 +1637,12 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1652,8 +1652,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1754,12 +1754,12 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1769,8 +1769,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1866,12 +1866,12 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1881,8 +1881,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2008,11 +2008,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2022,8 +2022,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2120,11 +2120,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2134,8 +2134,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2276,11 +2276,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2290,8 +2290,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2379,11 +2379,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::PythStableCoin, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), oracle: usdc_oracle_price_key, @@ -2394,8 +2394,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: usdc_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2530,13 +2530,13 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::PythStableCoin, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), oracle: usdc_oracle_price_key, @@ -2547,8 +2547,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: usdc_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2676,11 +2676,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::PythStableCoin, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_price(usdc_price), oracle: usdc_oracle_price_key, @@ -2691,8 +2691,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: usdc_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2853,11 +2853,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2867,8 +2867,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2970,11 +2970,11 @@ mod calculate_max_withdrawable_amount { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2984,8 +2984,8 @@ mod calculate_max_withdrawable_amount { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3056,12 +3056,12 @@ mod calculate_max_withdrawable_amount { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, liquidator_fee: 0, @@ -3073,8 +3073,8 @@ mod calculate_max_withdrawable_amount { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3144,12 +3144,12 @@ mod calculate_max_withdrawable_amount { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, liquidator_fee: 0, @@ -3161,8 +3161,8 @@ mod calculate_max_withdrawable_amount { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3260,11 +3260,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3273,8 +3273,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3343,11 +3343,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3356,8 +3356,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3426,11 +3426,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3439,8 +3439,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3509,11 +3509,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3522,8 +3522,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3592,11 +3592,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3605,8 +3605,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3675,11 +3675,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3688,8 +3688,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3780,11 +3780,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3793,8 +3793,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3939,11 +3939,11 @@ mod calculate_user_equity { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -4037,11 +4037,11 @@ mod calculate_user_equity { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -4101,11 +4101,11 @@ mod calculate_user_equity { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -4115,8 +4115,8 @@ mod calculate_user_equity { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -4354,11 +4354,11 @@ mod pools { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), pool_id: 1, @@ -4510,11 +4510,11 @@ mod get_margin_calculation_for_disable_high_leverage_mode { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -4524,8 +4524,8 @@ mod get_margin_calculation_for_disable_high_leverage_mode { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, diff --git a/programs/drift/src/math/orders/tests.rs b/programs/drift/src/math/orders/tests.rs index ffb3d11380..4cb9671516 100644 --- a/programs/drift/src/math/orders/tests.rs +++ b/programs/drift/src/math/orders/tests.rs @@ -466,7 +466,7 @@ mod get_max_fill_amounts { #[test] fn fully_collateralized_selling_base() { let base_market = SpotMarket { - deposit_balance: 4 * 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (4 * 100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 4 * 100 * LAMPORTS_PER_SOL_U64, ..SpotMarket::default_base_market() }; @@ -546,7 +546,7 @@ mod get_max_fill_amounts { #[test] fn selling_base_with_borrow_liquidity_greater_than_order() { let base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; @@ -588,7 +588,7 @@ mod get_max_fill_amounts { fn fully_collateralized_selling_quote() { let base_market = SpotMarket::default_base_market(); let quote_market = SpotMarket { - deposit_balance: 4 * 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (4 * 100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 4 * 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -668,7 +668,7 @@ mod get_max_fill_amounts { fn selling_quote_with_borrow_liquidity_greater_than_order() { let base_market = SpotMarket::default_base_market(); let quote_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() @@ -1108,11 +1108,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1122,8 +1122,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1215,11 +1215,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1229,8 +1229,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1323,11 +1323,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1337,8 +1337,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1430,11 +1430,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1444,8 +1444,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1520,11 +1520,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1534,8 +1534,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1628,11 +1628,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1642,8 +1642,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1736,11 +1736,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1750,8 +1750,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1844,11 +1844,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1858,8 +1858,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2022,11 +2022,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2144,11 +2144,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2249,11 +2249,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2371,11 +2371,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2476,11 +2476,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2599,11 +2599,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2723,11 +2723,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2845,11 +2845,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2968,11 +2968,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -3092,11 +3092,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -3217,11 +3217,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, diff --git a/programs/drift/src/math/spot_balance/tests.rs b/programs/drift/src/math/spot_balance/tests.rs index 5fbe7427a4..d9dffd9ff1 100644 --- a/programs/drift/src/math/spot_balance/tests.rs +++ b/programs/drift/src/math/spot_balance/tests.rs @@ -7,7 +7,7 @@ mod test { #[test] fn bonk() { let spot_market = SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 5, ..SpotMarket::default_quote_market() }; diff --git a/programs/drift/src/state/lp_pool.rs b/programs/drift/src/state/lp_pool.rs index b8f82477b1..426c73c3fa 100644 --- a/programs/drift/src/state/lp_pool.rs +++ b/programs/drift/src/state/lp_pool.rs @@ -139,7 +139,7 @@ impl Default for LPPool { constituent_target_base: Pubkey::default(), constituent_correlations: Pubkey::default(), max_aum: 0.into(), - last_aum: 0.into(), + last_aum: 0u128.into(), cumulative_quote_sent_to_perp_markets: 0.into(), cumulative_quote_received_from_perp_markets: 0.into(), total_mint_redeem_fees_paid: 0.into(), diff --git a/programs/drift/src/state/lp_pool/tests.rs b/programs/drift/src/state/lp_pool/tests.rs index 3e76383af9..22774cc669 100644 --- a/programs/drift/src/state/lp_pool/tests.rs +++ b/programs/drift/src/state/lp_pool/tests.rs @@ -581,7 +581,7 @@ mod swap_tests { out_volatility: u64, ) { let lp_pool = LPPool { - last_aum: 1_000_000_000_000, + last_aum: 1_000_000_000_000u128.into(), target_oracle_delay_fee_bps_per_10_slots: 2, target_position_delay_fee_bps_per_10_slots: 10, ..LPPool::default() @@ -596,10 +596,12 @@ mod swap_tests { ..OraclePriceData::default() }; - let in_notional = (in_current_weight as u128) * lp_pool.last_aum / PERCENTAGE_PRECISION; + let in_notional = + (in_current_weight as u128) * lp_pool.last_aum.as_u128() / PERCENTAGE_PRECISION; let in_token_amount = in_notional * 10_u128.pow(in_decimals) / oracle_0.price as u128; - let out_notional = (out_current_weight as u128) * lp_pool.last_aum / PERCENTAGE_PRECISION; + let out_notional = + (out_current_weight as u128) * lp_pool.last_aum.as_u128() / PERCENTAGE_PRECISION; let out_token_amount = out_notional * 10_u128.pow(out_decimals) / oracle_1.price as u128; let constituent_0 = Constituent { @@ -762,7 +764,7 @@ mod swap_tests { let spot_market = SpotMarket { market_index: 0, decimals: 6, - cumulative_deposit_interest: 10_000_000_000_000, + cumulative_deposit_interest: 10_000_000_000_000u128.into(), ..SpotMarket::default() }; @@ -810,7 +812,7 @@ mod swap_tests { volatility: u64, ) { let lp_pool = LPPool { - last_aum, + last_aum: last_aum.into(), _padding: 0, min_mint_fee: 0, ..LPPool::default() @@ -1002,7 +1004,7 @@ mod swap_tests { volatility: u64, ) { let lp_pool = LPPool { - last_aum, + last_aum: last_aum.into(), _padding: 0, min_mint_fee: 100, // 1 bps ..LPPool::default() @@ -1213,7 +1215,7 @@ mod swap_tests { out_target_weight: i64, ) -> (u128, u128, i128, i128, i128, i128) { let lp_pool = LPPool { - last_aum: 1_000_000_000_000, + last_aum: 1_000_000_000_000u128.into(), ..LPPool::default() }; @@ -1226,7 +1228,8 @@ mod swap_tests { ..OraclePriceData::default() }; - let in_notional = (in_current_weight as i128) * lp_pool.last_aum.cast::().unwrap() + let in_notional = (in_current_weight as i128) + * lp_pool.last_aum.as_u128().cast::().unwrap() / PERCENTAGE_PRECISION_I128; let in_token_amount = in_notional * 10_i128.pow(6) / oracle_0.price as i128; let in_spot_balance = if in_token_amount > 0 { @@ -1247,7 +1250,8 @@ mod swap_tests { } }; - let out_notional = (out_current_weight as i128) * lp_pool.last_aum.cast::().unwrap() + let out_notional = (out_current_weight as i128) + * lp_pool.last_aum.as_u128().cast::().unwrap() / PERCENTAGE_PRECISION_I128; let out_token_amount = out_notional * 10_i128.pow(6) / oracle_1.price as i128; let out_spot_balance = if out_token_amount > 0 { @@ -1589,7 +1593,7 @@ mod swap_fee_tests { #[test] fn test_lp_pool_get_linear_fee_execution() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 ..LPPool::default() }; @@ -1610,7 +1614,7 @@ mod swap_fee_tests { #[test] fn test_lp_pool_get_quadratic_fee_execution() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 ..LPPool::default() }; @@ -1631,7 +1635,7 @@ mod swap_fee_tests { #[test] fn test_lp_pool_get_quadratic_fee_inventory() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 ..LPPool::default() }; @@ -1657,7 +1661,7 @@ mod swap_fee_tests { #[test] fn test_target_delays() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 target_oracle_delay_fee_bps_per_10_slots: 2, target_position_delay_fee_bps_per_10_slots: 10, ..LPPool::default() @@ -2534,7 +2538,7 @@ mod update_aum_tests { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2545,7 +2549,7 @@ mod update_aum_tests { market_index: 1, oracle_source: OracleSource::PythLazer, oracle: sol_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(200 * PRICE_PRECISION_I64), ..SpotMarket::default() @@ -2556,7 +2560,7 @@ mod update_aum_tests { market_index: 2, oracle_source: OracleSource::PythLazer, oracle: btc_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 8, historical_oracle_data: HistoricalOracleData::default_price( 100_000 * PRICE_PRECISION_I64, @@ -2569,7 +2573,7 @@ mod update_aum_tests { market_index: 3, oracle_source: OracleSource::PythLazer, oracle: bonk_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 5, historical_oracle_data: HistoricalOracleData::default_price(22), ..SpotMarket::default() @@ -2671,7 +2675,8 @@ mod update_aum_tests { // Verify LP pool state was updated assert_eq!( - lp_pool.last_aum, aum, + lp_pool.last_aum, + aum.into(), "{}: last_aum should match calculated AUM", test_name ); @@ -2942,7 +2947,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -2957,7 +2962,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative1_index, oracle_source: OracleSource::PythLazer, oracle: derivative1_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative1_oracle.price), ..SpotMarket::default() @@ -2972,7 +2977,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative2_index, oracle_source: OracleSource::PythLazer, oracle: derivative2_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative2_oracle.price), ..SpotMarket::default() @@ -2987,7 +2992,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative3_index, oracle_source: OracleSource::PythLazer, oracle: derivative3_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative3_oracle.price), ..SpotMarket::default() @@ -3258,7 +3263,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -3273,7 +3278,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative_index, oracle_source: OracleSource::PythLazer, oracle: derivative_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative_oracle.price), ..SpotMarket::default() @@ -3547,7 +3552,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -3562,7 +3567,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative_index, oracle_source: OracleSource::PythLazer, oracle: derivative_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative_oracle.price), ..SpotMarket::default() @@ -3761,7 +3766,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -3776,7 +3781,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative1_index, oracle_source: OracleSource::PythLazer, oracle: derivative1_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative1_oracle.price), ..SpotMarket::default() @@ -3791,7 +3796,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative2_index, oracle_source: OracleSource::PythLazer, oracle: derivative2_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative2_oracle.price), ..SpotMarket::default() diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 716fff16e5..1f2056fff5 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -1031,7 +1031,7 @@ pub struct PoolBalance { /// To get the pool's token amount, you must multiply the scaled balance by the market's cumulative /// deposit interest /// precision: SPOT_BALANCE_PRECISION - pub scaled_balance: u128, + pub scaled_balance: crate::math::bn::compat::u128, /// The spot market the pool is for pub market_index: u16, pub padding: [u8; 6], @@ -1047,16 +1047,16 @@ impl SpotBalance for PoolBalance { } fn balance(&self) -> u128 { - self.scaled_balance + self.scaled_balance.as_u128() } fn increase_balance(&mut self, delta: u128) -> DriftResult { - self.scaled_balance = self.scaled_balance.safe_add(delta)?; + self.scaled_balance = self.scaled_balance.as_u128().safe_add(delta)?.into(); Ok(()) } fn decrease_balance(&mut self, delta: u128) -> DriftResult { - self.scaled_balance = self.scaled_balance.safe_sub(delta)?; + self.scaled_balance = self.scaled_balance.as_u128().safe_sub(delta)?.into(); Ok(()) } @@ -1066,7 +1066,7 @@ impl SpotBalance for PoolBalance { } #[assert_no_slop] -#[zero_copy(unsafe)] +#[drift_macros::legacy_account(zero_copy(unsafe))] #[derive(Debug, PartialEq, Eq)] #[repr(C)] pub struct AMM { diff --git a/programs/drift/src/state/spot_market.rs b/programs/drift/src/state/spot_market.rs index 31199ef60e..40ad519ecc 100644 --- a/programs/drift/src/state/spot_market.rs +++ b/programs/drift/src/state/spot_market.rs @@ -226,7 +226,7 @@ impl Default for SpotMarket { total_spot_fee: 0.into(), deposit_balance: 0.into(), borrow_balance: 0.into(), - cumulative_deposit_interest: 0.into(), + cumulative_deposit_interest: 0u128.into(), cumulative_borrow_interest: 0.into(), total_social_loss: 0.into(), total_quote_social_loss: 0.into(), @@ -617,8 +617,8 @@ impl SpotMarket { pub fn default_base_market() -> Self { SpotMarket { market_index: 1, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), initial_liability_weight: 12000, maintenance_liability_weight: 11000, initial_asset_weight: 8000, @@ -633,8 +633,8 @@ impl SpotMarket { pub fn default_quote_market() -> Self { SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_liability_weight: 10000, maintenance_liability_weight: 10000, @@ -711,10 +711,10 @@ pub enum AssetTier { #[repr(C)] pub struct InsuranceFund { pub vault: Pubkey, - pub total_shares: u128, - pub user_shares: u128, - pub shares_base: u128, // exponent for lp shares (for rebasing) - pub unstaking_period: i64, // if_unstaking_period + pub total_shares: crate::math::bn::compat::u128, + pub user_shares: crate::math::bn::compat::u128, + pub shares_base: crate::math::bn::compat::u128, // exponent for lp shares (for rebasing) + pub unstaking_period: i64, // if_unstaking_period pub last_revenue_settle_ts: i64, pub revenue_settle_period: i64, pub total_factor: u32, // percentage of interest for total insurance @@ -723,7 +723,10 @@ pub struct InsuranceFund { impl InsuranceFund { pub fn get_protocol_shares(&self) -> DriftResult { - self.total_shares.safe_sub(self.user_shares) + self.total_shares + .as_u128() + .safe_sub(self.user_shares.as_u128()) + .into() } } diff --git a/programs/drift/src/state/user/tests.rs b/programs/drift/src/state/user/tests.rs index 4b2392d1ba..1ad1086ebf 100644 --- a/programs/drift/src/state/user/tests.rs +++ b/programs/drift/src/state/user/tests.rs @@ -214,11 +214,11 @@ mod get_claimable_pnl { let usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -320,11 +320,11 @@ mod get_claimable_pnl { let usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -471,11 +471,11 @@ mod get_claimable_pnl { let usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() };