Skip to content
Merged

DLP #1885

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5cef2f8
Bigz/init lp pool (#1884)
moosecat2 Sep 16, 2025
03b22b8
add vamm cache percent scalar (default is 100)
moosecat2 Sep 17, 2025
eecbe20
Merge pull request #1888 from drift-labs/nour/vamm-cache-percent
moosecat2 Sep 17, 2025
dc43396
aum cant go below zero (#1890)
moosecat2 Sep 17, 2025
497638d
reassing dlp taker bot wallet
moosecat2 Sep 18, 2025
6976e55
add event subscriber changes for dlp events
moosecat2 Sep 18, 2025
9d7a2b6
give permission for dlp taker bot to deposit withdraw from program va…
moosecat2 Sep 19, 2025
a814f7b
fix max withdrawals bug
moosecat2 Sep 19, 2025
d1060ff
get max transfer bug fix
moosecat2 Sep 20, 2025
2db9320
merge master
moosecat2 Sep 20, 2025
010c210
Wphan/merge-master (#1915)
wphan Sep 25, 2025
8757c93
add new bulk instruction packaging
moosecat2 Sep 29, 2025
e3d08a0
logging changes
moosecat2 Sep 29, 2025
ecd8d3a
Wphan/master-dlp (#1918)
wphan Sep 29, 2025
53a5009
borrow lend accounting (#1905)
moosecat2 Sep 29, 2025
88d1dc8
remove duplicate admin client funcs
moosecat2 Sep 29, 2025
6faf6a2
update idl
wphan Sep 29, 2025
f1a23d8
bump constituent map max size
moosecat2 Sep 30, 2025
cec4e6d
make working devcontainer and dockerfile
wphan Sep 30, 2025
61a5657
bug fixes
moosecat2 Sep 30, 2025
bcb5ded
bug fixes
moosecat2 Sep 30, 2025
025eaf3
add dev container
moosecat2 Sep 30, 2025
55b530d
fix node version
wphan Sep 30, 2025
51e2e27
update dockerfile
moosecat2 Sep 30, 2025
dfec9a3
fixed idl
moosecat2 Sep 30, 2025
199f504
dockerfile and dev container working, and anchor build working
moosecat2 Sep 30, 2025
19efd62
add dev container.json and dockerfile
moosecat2 Sep 30, 2025
c768376
update dlp types to include lp pool key
moosecat2 Oct 1, 2025
340b6c9
stable target base liquidity fix + cleanup
moosecat2 Oct 1, 2025
631c962
relax transfer from program lp invariant for devnet
moosecat2 Oct 1, 2025
8f6f9bc
further restrict constituent max borrow
moosecat2 Oct 2, 2025
ede599b
give 1% flexilibity for race conditions on max transfer amount
moosecat2 Oct 2, 2025
60a9231
introduce max borrow buffer
moosecat2 Oct 2, 2025
72a5e42
include new amm inventory limit (#1932)
moosecat2 Oct 3, 2025
bc1ae68
refactor amm cache
moosecat2 Oct 3, 2025
6f881ba
change amm cache pda seed for devnet reset
moosecat2 Oct 3, 2025
8b73b66
update sdk types file to be up to parity
moosecat2 Oct 6, 2025
41fbaa3
merge master into dlp
moosecat2 Oct 6, 2025
69afe90
clean up and guard against negative amm_inventory_limit
moosecat2 Oct 7, 2025
0cd3560
Target delay increases fees (#1943)
moosecat2 Oct 8, 2025
84ce292
update idl
moosecat2 Oct 8, 2025
290b7e9
merge master
moosecat2 Oct 15, 2025
0ca25a0
Moose review (#1948)
moosecat2 Oct 16, 2025
b295031
remove unnecessary admin func
moosecat2 Oct 16, 2025
f3bd586
idl
moosecat2 Oct 17, 2025
9d7e7a0
delete unused errors
moosecat2 Oct 22, 2025
73a4d4f
Merge branch 'master' into dlp
moosecat2 Oct 22, 2025
309fa74
make linter happy
moosecat2 Oct 22, 2025
648bf33
fix all compiler warnings
moosecat2 Oct 22, 2025
70c4a4d
merge master
moosecat2 Oct 22, 2025
00139c4
Use lp pool id (#1992)
moosecat2 Oct 27, 2025
8d3e848
address comments round 2
moosecat2 Oct 28, 2025
4b5735a
add additional settle pnl invariant check
moosecat2 Oct 28, 2025
71dd9c1
create separate hot wallet for lp pool
moosecat2 Oct 28, 2025
7e67ac8
Merge branch 'master' into dlp
moosecat2 Oct 28, 2025
3c6ad68
remove any unused fields
moosecat2 Oct 28, 2025
af376f2
add oracle map logging argument
moosecat2 Oct 28, 2025
503fa41
generalize lp pool test failure
moosecat2 Oct 28, 2025
e6dd77a
unified swap mode compatibility
moosecat2 Oct 28, 2025
d14dc14
clippy and whitelist changes
moosecat2 Oct 28, 2025
3b052d4
make prettify and lint happy
moosecat2 Oct 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ ENV HOME="/root"
ENV PATH="/usr/local/cargo/bin:${PATH}"
ENV PATH="/root/.local/share/solana/install/active_release/bin:${PATH}"

RUN mkdir -p /workdir /tmp && \
apt-get update -qq && apt-get upgrade -qq && apt-get install -y --no-install-recommends \
build-essential git curl wget jq pkg-config python3-pip xz-utils ca-certificates \
libssl-dev libudev-dev bash && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p /workdir /tmp \
&& apt-get update -qq \
&& apt-get upgrade -qq \
&& apt-get install -y --no-install-recommends \
build-essential git curl wget jq pkg-config python3-pip xz-utils ca-certificates \
libssl-dev libudev-dev bash software-properties-common \
&& add-apt-repository 'deb http://deb.debian.org/debian bookworm main' \
&& apt-get update -qq \
&& apt-get install -y libc6 libc6-dev \
&& rm -rf /var/lib/apt/lists/*

RUN rustup component add rustfmt

RUN rustup install 1.78.0 \
&& rustup component add rustfmt clippy --toolchain 1.78.0
Expand Down
10 changes: 0 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking

## [2.135.0] - 2025-08-22

### Features

### Fixes

- program: trigger price use 5min mark price ([#1830](https://github.com/drift-labs/protocol-v2/pull/1830))

### Breaking

## [2.134.0] - 2025-08-13

### Features
Expand Down
2 changes: 1 addition & 1 deletion programs/drift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ drift-rs=[]
[dependencies]
anchor-lang = "0.29.0"
solana-program = "1.16"
anchor-spl = "0.29.0"
anchor-spl = { version = "0.29.0", features = [] }
pyth-client = "0.2.2"
pyth-lazer-solana-contract = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "d790d1cb4da873a949cf33ff70349b7614b232eb", features = ["no-entrypoint"]}
pythnet-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "3e8a24ecd0bcf22b787313e2020f4186bb22c729"}
Expand Down
6 changes: 3 additions & 3 deletions programs/drift/src/controller/insurance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use crate::error::ErrorCode;
use crate::math::amm::calculate_net_user_pnl;
use crate::math::casting::Cast;
use crate::math::constants::{
MAX_APR_PER_REVENUE_SETTLE_TO_INSURANCE_FUND_VAULT,
FUEL_START_TS, GOV_SPOT_MARKET_INDEX, MAX_APR_PER_REVENUE_SETTLE_TO_INSURANCE_FUND_VAULT,
MAX_APR_PER_REVENUE_SETTLE_TO_INSURANCE_FUND_VAULT_GOV, ONE_YEAR, PERCENTAGE_PRECISION,
SHARE_OF_REVENUE_ALLOCATED_TO_INSURANCE_FUND_VAULT_DENOMINATOR,
QUOTE_SPOT_MARKET_INDEX, SHARE_OF_REVENUE_ALLOCATED_TO_INSURANCE_FUND_VAULT_DENOMINATOR,
SHARE_OF_REVENUE_ALLOCATED_TO_INSURANCE_FUND_VAULT_NUMERATOR,
};
use crate::math::fuel::calculate_insurance_fuel_bonus;
Expand All @@ -40,7 +40,7 @@ use crate::state::perp_market::PerpMarket;
use crate::state::spot_market::{SpotBalanceType, SpotMarket};
use crate::state::state::State;
use crate::state::user::UserStats;
use crate::{emit, validate, FUEL_START_TS, GOV_SPOT_MARKET_INDEX, QUOTE_SPOT_MARKET_INDEX};
use crate::{emit, validate};

#[cfg(test)]
mod tests;
Expand Down
10 changes: 6 additions & 4 deletions programs/drift/src/controller/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use crate::error::{DriftResult, ErrorCode};
use crate::math::bankruptcy::is_user_bankrupt;
use crate::math::casting::Cast;
use crate::math::constants::{
LIQUIDATION_FEE_PRECISION_U128, LIQUIDATION_PCT_PRECISION, QUOTE_PRECISION,
QUOTE_PRECISION_I128, QUOTE_PRECISION_U64, QUOTE_SPOT_MARKET_INDEX, SPOT_WEIGHT_PRECISION,
LIQUIDATION_FEE_PRECISION, LIQUIDATION_FEE_PRECISION_U128, LIQUIDATION_PCT_PRECISION,
QUOTE_PRECISION, QUOTE_PRECISION_I128, QUOTE_PRECISION_U64, QUOTE_SPOT_MARKET_INDEX,
SPOT_WEIGHT_PRECISION,
};
use crate::math::liquidation::{
calculate_asset_transfer_for_liability_transfer,
Expand All @@ -48,6 +49,7 @@ use crate::math::orders::{
use crate::math::position::calculate_base_asset_value_with_oracle_price;
use crate::math::safe_math::SafeMath;

use crate::math::constants::LST_POOL_ID;
use crate::math::spot_balance::get_token_value;
use crate::state::events::{
LiquidateBorrowForPerpPnlRecord, LiquidatePerpPnlForDepositRecord, LiquidatePerpRecord,
Expand All @@ -66,8 +68,8 @@ use crate::state::spot_market_map::SpotMarketMap;
use crate::state::state::State;
use crate::state::user::{MarketType, Order, OrderStatus, OrderType, User, UserStats};
use crate::state::user_map::{UserMap, UserStatsMap};
use crate::{get_then_update_id, load_mut, LST_POOL_ID};
use crate::{validate, LIQUIDATION_FEE_PRECISION};
use crate::validate;
use crate::{get_then_update_id, load_mut};

#[cfg(test)]
mod tests;
Expand Down
6 changes: 4 additions & 2 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::state::revenue_share::{
};
use anchor_lang::prelude::*;

use crate::controller;
use crate::controller::funding::settle_funding_payment;
use crate::controller::position;
use crate::controller::position::{
Expand All @@ -32,7 +33,9 @@ use crate::math::amm::calculate_amm_available_liquidity;
use crate::math::amm_jit::calculate_amm_jit_liquidity;
use crate::math::auction::{calculate_auction_params_for_trigger_order, calculate_auction_prices};
use crate::math::casting::Cast;
use crate::math::constants::{BASE_PRECISION_U64, PERP_DECIMALS, QUOTE_SPOT_MARKET_INDEX};
use crate::math::constants::{
BASE_PRECISION_U64, MARGIN_PRECISION, PERP_DECIMALS, QUOTE_SPOT_MARKET_INDEX,
};
use crate::math::fees::{determine_user_fee_tier, ExternalFillFees, FillFees};
use crate::math::fulfillment::{
determine_perp_fulfillment_methods, determine_spot_fulfillment_methods,
Expand Down Expand Up @@ -81,7 +84,6 @@ use crate::validation;
use crate::validation::order::{
validate_order, validate_order_for_force_reduce_only, validate_spot_order,
};
use crate::{controller, MARGIN_PRECISION};

#[cfg(test)]
mod tests;
Expand Down
55 changes: 19 additions & 36 deletions programs/drift/src/controller/position/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ fn amm_pool_balance_liq_fees_example() {
let perp_market_loader: AccountLoader<PerpMarket> =
AccountLoader::try_from(&perp_market_account_info).unwrap();

let perp_market_map = PerpMarketMap::load_one(&perp_market_account_info, true).unwrap();

let now = 1725948560;
let clock_slot = 326319440;
let clock = Clock {
unix_timestamp: now,
slot: clock_slot,
..Clock::default()
};

let mut state = State::default();

let mut prelaunch_oracle_price = PrelaunchOracle {
price: PRICE_PRECISION_I64,
Expand All @@ -77,9 +67,8 @@ fn amm_pool_balance_liq_fees_example() {
prelaunch_oracle_price,
&prelaunch_oracle_price_key,
PrelaunchOracle,
oracle_account_info
_oracle_account_info
);
let mut oracle_map = OracleMap::load_one(&oracle_account_info, clock_slot, None).unwrap();

let mut spot_market = SpotMarket {
cumulative_deposit_interest: 11425141382,
Expand Down Expand Up @@ -609,11 +598,11 @@ fn amm_ref_price_decay_tail_test() {

let signed_liquidity_ratio = liquidity_ratio
.checked_mul(
(perp_market
perp_market
.amm
.get_protocol_owned_position()
.unwrap()
.signum() as i128),
.signum() as i128,
)
.unwrap();

Expand Down Expand Up @@ -654,7 +643,7 @@ fn amm_ref_price_decay_tail_test() {
&state.oracle_guard_rails.validity,
)
.unwrap();
let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -687,7 +676,7 @@ fn amm_ref_price_decay_tail_test() {
)
.unwrap();

let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -786,11 +775,11 @@ fn amm_ref_price_offset_decay_logic() {

let signed_liquidity_ratio = liquidity_ratio
.checked_mul(
(perp_market
perp_market
.amm
.get_protocol_owned_position()
.unwrap()
.signum() as i128),
.signum() as i128,
)
.unwrap();

Expand Down Expand Up @@ -831,7 +820,7 @@ fn amm_ref_price_offset_decay_logic() {
&state.oracle_guard_rails.validity,
)
.unwrap();
let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -871,7 +860,7 @@ fn amm_ref_price_offset_decay_logic() {
)
.unwrap();

let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -961,11 +950,11 @@ fn amm_negative_ref_price_offset_decay_logic() {

let signed_liquidity_ratio = liquidity_ratio
.checked_mul(
(perp_market
perp_market
.amm
.get_protocol_owned_position()
.unwrap()
.signum() as i128),
.signum() as i128,
)
.unwrap();

Expand Down Expand Up @@ -1006,7 +995,7 @@ fn amm_negative_ref_price_offset_decay_logic() {
&state.oracle_guard_rails.validity,
)
.unwrap();
let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -1047,7 +1036,7 @@ fn amm_negative_ref_price_offset_decay_logic() {
)
.unwrap();

let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -1147,11 +1136,11 @@ fn amm_perp_ref_offset() {

let signed_liquidity_ratio = liquidity_ratio
.checked_mul(
(perp_market
perp_market
.amm
.get_protocol_owned_position()
.unwrap()
.signum() as i128),
.signum() as i128,
)
.unwrap();

Expand All @@ -1173,7 +1162,7 @@ fn amm_perp_ref_offset() {
max_ref_offset,
)
.unwrap();
assert_eq!(res, (perp_market.amm.max_spread / 2) as i32);
assert_eq!(res, 45000);
assert_eq!(perp_market.amm.reference_price_offset, 18000); // not updated vs market account

let now = 1741207620 + 1;
Expand All @@ -1193,7 +1182,7 @@ fn amm_perp_ref_offset() {
&state.oracle_guard_rails.validity,
)
.unwrap();
let cost = _update_amm(
_update_amm(
&mut perp_market,
&mm_oracle_price_data,
&state,
Expand Down Expand Up @@ -1252,21 +1241,15 @@ fn amm_perp_ref_offset() {
// Uses the original oracle if the slot is old, ignoring MM oracle
perp_market.amm.mm_oracle_price = mm_oracle_price_data.get_price() * 995 / 1000;
perp_market.amm.mm_oracle_slot = clock_slot - 100;
let mut mm_oracle_price = perp_market
let mm_oracle_price = perp_market
.get_mm_oracle_price_data(
oracle_price_data,
clock_slot,
&state.oracle_guard_rails.validity,
)
.unwrap();

let _ = _update_amm(
&mut perp_market,
&mut mm_oracle_price,
&state,
now,
clock_slot,
);
let _ = _update_amm(&mut perp_market, &mm_oracle_price, &state, now, clock_slot);
let reserve_price_mm_offset_3 = perp_market.amm.reserve_price().unwrap();
let (b3, a3) = perp_market
.amm
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/src/controller/repeg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub fn update_amm_test_bad_oracle() {
#[test]
pub fn update_amm_larg_conf_test() {
let now = 1662800000 + 60;
let mut slot = 81680085;
let slot = 81680085;

let mut market = PerpMarket::default_btc_test();
assert_eq!(market.amm.base_asset_amount_with_amm, -1000000000);
Expand Down Expand Up @@ -409,7 +409,7 @@ pub fn update_amm_larg_conf_test() {
#[test]
pub fn update_amm_larg_conf_w_neg_tfmd_test() {
let now = 1662800000 + 60;
let mut slot = 81680085;
let slot = 81680085;

let mut market = PerpMarket::default_btc_test();
market.amm.concentration_coef = 1414213;
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/src/controller/spot_balance/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ fn check_fee_collection_larger_nums() {

#[test]
fn test_multi_stage_borrow_rate_curve() {
let mut spot_market = SpotMarket {
let spot_market = SpotMarket {
market_index: 0,
oracle_source: OracleSource::QuoteAsset,
cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION,
Expand Down Expand Up @@ -1455,7 +1455,7 @@ fn test_multi_stage_borrow_rate_curve_sol() {

let spot_market_loader: AccountLoader<SpotMarket> =
AccountLoader::try_from(&sol_market_account_info).unwrap();
let mut spot_market = spot_market_loader.load_mut().unwrap();
let spot_market = spot_market_loader.load_mut().unwrap();

// Store all rates to verify monotonicity and smoothness later
let mut last_rate = 0_u128;
Expand Down
Loading
Loading