Skip to content

bigz/init-lp-pool #1565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 158 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
f251378
program: init lp pool
0xbigz Apr 8, 2025
be58c57
cargo fmt --
0xbigz Apr 8, 2025
2cf149d
add total fee fields
0xbigz Apr 8, 2025
b2cf992
add update_target_weights math
0xbigz Apr 9, 2025
a405a56
program: use sparse matrix for constituent map and update tests
0xbigz Apr 18, 2025
34b044c
zero copy accounts, init ix (#1578)
wphan Apr 18, 2025
5d3fd5e
update accounts (#1580)
wphan Apr 21, 2025
9826453
zero copy + permissionless crank ixs (#1581)
NourAlharithi Apr 21, 2025
b7e0cab
program: support negative target weights for borrow-lend
0xbigz Apr 21, 2025
57b4ec2
fix tests to work with zero copy
NourAlharithi Apr 22, 2025
81dd06e
few comment changes
NourAlharithi Apr 22, 2025
73b32d5
remove discriminator from impl macro
NourAlharithi Apr 22, 2025
afdfe7b
add get_swap_amount, get_swap_fees, get_weight (#1579)
wphan Apr 23, 2025
9383688
fix swap fee calc (#1582)
wphan Apr 23, 2025
007bace
add init amm mapping to lp context (#1583)
NourAlharithi Apr 23, 2025
10d070e
init constituent
NourAlharithi Apr 24, 2025
6cd4254
Merge pull request #1584 from drift-labs/nour/init-constituent
NourAlharithi Apr 24, 2025
1d7fd00
add initializeLpPool test (#1585)
wphan Apr 24, 2025
be22c24
add add datum ix
NourAlharithi Apr 24, 2025
ffd6a51
Merge branch 'bigz/init-lp-pool' into nour/add-mapping-datum
NourAlharithi Apr 24, 2025
188ab4e
add init tests and invariant checks
NourAlharithi Apr 24, 2025
6353b62
Merge pull request #1587 from drift-labs/nour/add-mapping-datum
NourAlharithi Apr 24, 2025
f450cb2
rename data to more useful names
NourAlharithi Apr 24, 2025
c803c16
dlp use spl token program (#1588)
wphan Apr 24, 2025
f7fac79
add crank ix
NourAlharithi Apr 24, 2025
6bbe40d
update total_weight for validation_flags check
0xbigz Apr 24, 2025
55014a0
push test so far
NourAlharithi Apr 24, 2025
4b13618
overriding perp position works
NourAlharithi Apr 25, 2025
39726c5
remove message
NourAlharithi Apr 25, 2025
222a335
Merge pull request #1589 from drift-labs/nour/crank-constituent-targe…
NourAlharithi Apr 25, 2025
bddb41f
fix dup total_weight add
0xbigz Apr 25, 2025
495977f
constituent map remaining accounts
NourAlharithi Apr 25, 2025
014b4a3
compiles
NourAlharithi Apr 26, 2025
228b94b
bankrun tests pass
NourAlharithi Apr 28, 2025
0b7049c
compiles but casting failure in overflow protection test
NourAlharithi Apr 28, 2025
9372702
address comment and change token arguments from u64 to u128
NourAlharithi Apr 28, 2025
9addd8c
bankrun tests pass
NourAlharithi Apr 29, 2025
33dbe08
Merge branch 'nour/crank-aum' into nour/remove-amm-mappings
NourAlharithi Apr 29, 2025
5d6f15f
Merge pull request #1595 from drift-labs/nour/remove-amm-mappings
NourAlharithi Apr 29, 2025
e950e5d
init constituent token account (#1596)
wphan Apr 29, 2025
f145aa1
update aum calc
NourAlharithi Apr 29, 2025
4c8a721
add update /remove mapping ixs
NourAlharithi Apr 29, 2025
16ab911
Merge branch 'bigz/init-lp-pool' into nour/crank-aum
NourAlharithi Apr 29, 2025
b6ec47c
Merge pull request #1593 from drift-labs/nour/crank-aum
NourAlharithi Apr 29, 2025
3923458
fix test - init constituent spot market
wphan Apr 29, 2025
11fed5f
add crank improvements
NourAlharithi Apr 29, 2025
8721f9b
crank improvements
NourAlharithi Apr 30, 2025
a059f00
passes tests
NourAlharithi Apr 30, 2025
cbf3395
precision fix crank aum
NourAlharithi Apr 30, 2025
a7830f4
precision fixes and constituent map check for account owner
NourAlharithi May 1, 2025
420b85f
Merge pull request #1598 from drift-labs/nour/crank-aum-improvements
NourAlharithi May 1, 2025
1c24027
add passthrough account logic (#1602)
NourAlharithi May 2, 2025
cb34da4
Wphan/dlp-swap-ixs (#1592)
wphan May 2, 2025
4974540
Merge branch 'master' into bigz/init-lp-pool
wphan May 2, 2025
2589040
post-merge fixes
wphan May 3, 2025
961d6ed
store bumps on accounts (#1604)
NourAlharithi May 5, 2025
9bfbab1
address comments
NourAlharithi May 7, 2025
b363288
Merge pull request #1611 from drift-labs/nour/address-comments
NourAlharithi May 7, 2025
dce2442
Wphan/add liquidity (#1607)
wphan May 8, 2025
8f19f61
program: lp-pool-to-use-target-base-vector (#1615)
0xbigz May 12, 2025
acab7f5
add beta and cost to trade in bps to target datum
NourAlharithi May 12, 2025
9f99b1d
add more tests
NourAlharithi May 12, 2025
ec2e2f0
Merge pull request #1617 from drift-labs/nour/beta-cost-to-trade
NourAlharithi May 13, 2025
db3ad52
add fields to LP events, fix tests (#1620)
wphan May 14, 2025
b9efc52
dlp jup swap (#1636)
NourAlharithi May 29, 2025
ee50a60
cleanup
NourAlharithi May 29, 2025
1f70026
transfer oracle data ix to constituent (#1643)
NourAlharithi May 30, 2025
83e22ec
big cargo test (#1644)
NourAlharithi Jun 3, 2025
e980aa7
derivative constituents + better testing + bug fixes (#1657)
NourAlharithi Jun 10, 2025
2ae54d1
deposit/borrow working and changing positions (#1652)
NourAlharithi Jun 10, 2025
b1fb7a8
sdk: allow custom coder
wphan Jun 17, 2025
81e442a
program: dlp add upnl for settles to amm cache (#1659)
0xbigz Jun 18, 2025
d374e55
remove unused accounts coder
wphan Jun 18, 2025
a4a2f02
move customCoder into sdk, lint
wphan Jun 18, 2025
0871d9d
testing: ix: settle perp to dlp, insufficient balance edge case and i…
NourAlharithi Jun 19, 2025
34e9f99
added more settle test coverage and squash bugs (#1689)
NourAlharithi Jun 20, 2025
feda828
dlp: add constituentMap (#1699)
wphan Jun 27, 2025
71db8bf
Nour/gauntlet fee impl (#1698)
NourAlharithi Jun 27, 2025
7a94a4a
update aum considers amm cache (#1701)
NourAlharithi Jun 30, 2025
f5d5a4f
prettify (#1702)
NourAlharithi Jun 30, 2025
30fe08f
Wphan/merge master dlp (#1703)
wphan Jun 30, 2025
bd615ea
slot staleness checks (#1705)
NourAlharithi Jul 2, 2025
b41cd6e
Nour/derivative constituent testing (#1708)
NourAlharithi Jul 2, 2025
7efab3e
merge
crispheaney Jul 4, 2025
c00ebb6
Merge branch 'master' into bigz/init-lp-pool
wphan Jul 4, 2025
4fe3146
Merge branch 'master' into bigz/init-lp-pool
wphan Jul 4, 2025
d5643a1
remove incorrect usage of nav
wphan Jul 4, 2025
6cfa245
Merge remote-tracking branch 'origin/bigz/init-lp-pool' into bigz/ini…
wphan Jul 4, 2025
8be6977
fix adminClient and tests
wphan Jul 4, 2025
99b52ac
Nour/fee grid search testing (#1714)
NourAlharithi Jul 6, 2025
6e6813a
Nour/address comments (#1715)
NourAlharithi Jul 7, 2025
84569d6
add swap fee unit tests (#1713)
wphan Jul 8, 2025
9ebb39a
Nour/settle accounting (#1723)
NourAlharithi Jul 9, 2025
bac790e
dont update lp quote owed unless collateralized
NourAlharithi Jul 9, 2025
0e9a454
Nour/settle testing (#1725)
NourAlharithi Jul 9, 2025
c5ccdea
prettify
NourAlharithi Jul 9, 2025
464e1d3
Nour/address more comments (#1726)
NourAlharithi Jul 9, 2025
19c88f8
refactor update_aum, add unit tests (#1727)
wphan Jul 10, 2025
b8a8030
Nour/parameterize dlp (#1731)
NourAlharithi Jul 11, 2025
a3e2ee0
Merge branch 'master' into bigz/init-lp-pool
NourAlharithi Jul 11, 2025
0bafd5a
fixes
NourAlharithi Jul 18, 2025
016dda3
update idl
NourAlharithi Jul 21, 2025
5f8f4f0
bug fixes
NourAlharithi Jul 21, 2025
839c17d
mostly sdk fixes
NourAlharithi Jul 22, 2025
0dffd52
bug fixes
NourAlharithi Jul 22, 2025
ee408ae
merge in master and fix conflicts
NourAlharithi Jul 23, 2025
edb3039
bug fix and deploy script
NourAlharithi Jul 23, 2025
ce30260
merge in master
NourAlharithi Jul 23, 2025
e6eef9d
program: new amm oracle (#1738)
NourAlharithi Jul 23, 2025
f493187
fix tests (#1764)
NourAlharithi Jul 23, 2025
fa47f31
Nour/move ixs around (#1766)
NourAlharithi Jul 23, 2025
2bb3ab4
add devnet oracle crank wallet
NourAlharithi Jul 23, 2025
35a5939
refactored mm oracle
NourAlharithi Jul 24, 2025
bd9c1ac
Merge branch 'master' into nour/mm-oracle-2
NourAlharithi Jul 24, 2025
13264f1
sdk changes + cargo fmt
NourAlharithi Jul 24, 2025
7015234
fix tests
NourAlharithi Jul 24, 2025
10d9178
validate price bands with fill fix
NourAlharithi Jul 24, 2025
d6708e2
normalize fill within price bands
NourAlharithi Jul 24, 2025
254990e
add sdk warning
NourAlharithi Jul 24, 2025
d812fd2
updated type
NourAlharithi Jul 24, 2025
7377f16
undefined guard so anchor tests pass
NourAlharithi Jul 24, 2025
742ac6c
accept vec for update amm and view amm
NourAlharithi Jul 24, 2025
ee40ac8
adjust test to work with new price bands
NourAlharithi Jul 24, 2025
ddf3067
Revert "adjust test to work with new price bands"
NourAlharithi Jul 24, 2025
607a687
remove price bands logic
NourAlharithi Jul 24, 2025
c66099e
add zero ix for mm oracle for reset
NourAlharithi Jul 25, 2025
4b5aa72
merge mm oracle refactor
NourAlharithi Jul 25, 2025
a886a49
add new drift client ix grouping
NourAlharithi Jul 25, 2025
4c36b9f
v1 safety improvements
NourAlharithi Jul 26, 2025
406dc91
isolate funding from MM oracle
NourAlharithi Jul 26, 2025
4a83337
add cargo tests for amm availability
NourAlharithi Jul 26, 2025
9ba8217
change oracle validity log bool to enum
NourAlharithi Jul 26, 2025
5588574
address comment
NourAlharithi Jul 26, 2025
396cd47
make validate fill direction agnostic
NourAlharithi Jul 26, 2025
de784dd
merge master
NourAlharithi Jul 28, 2025
6158c74
fix liquidate borrow for perp pnl test
NourAlharithi Jul 28, 2025
213d0f2
merge master
NourAlharithi Jul 28, 2025
4105ecc
fix tests and address comments
NourAlharithi Jul 29, 2025
ce3b2ef
Merge branch 'nour/safety-improvements' into bigz/init-lp-pool
NourAlharithi Jul 29, 2025
04c1a3e
Merge branch 'nour/validate-fill-change' into bigz/init-lp-pool
NourAlharithi Jul 29, 2025
8451b2d
merge in master
NourAlharithi Jul 29, 2025
9af0257
merge master
NourAlharithi Aug 5, 2025
cd716ea
commit constituent map to barrel file
NourAlharithi Aug 5, 2025
df1f5d8
add lp fields to perp market account
NourAlharithi Aug 5, 2025
9da4114
rearrange perp market struct for lp fields
NourAlharithi Aug 5, 2025
a2ffde0
bug fix for notional position tracking
NourAlharithi Aug 7, 2025
fcd1c65
view function
NourAlharithi Aug 7, 2025
9070282
fee view functions
NourAlharithi Aug 8, 2025
5ddfdf1
max aum + whitelist check and removing get_mint_redeem_fee for now
NourAlharithi Aug 9, 2025
f2c9f22
add wsol support for add liquidity
NourAlharithi Aug 11, 2025
6add765
fix sdk and typing bugs
NourAlharithi Aug 12, 2025
101fd6e
update lp pool params ix
NourAlharithi Aug 12, 2025
0a2171a
merge master
NourAlharithi Aug 12, 2025
300e343
admin override cache and disable settle functions
NourAlharithi Aug 12, 2025
abc450e
devnet swap working
NourAlharithi Aug 12, 2025
6b5142a
dlp taker discovered bug fixes and sdk changes
NourAlharithi Aug 14, 2025
dca7093
refactor last settle ts to last settle slot
NourAlharithi Aug 14, 2025
3bf665d
Nour/settle pnl fix (#1817)
NourAlharithi Aug 15, 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
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
16 changes: 5 additions & 11 deletions programs/drift/src/controller/position/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,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 Down Expand Up @@ -1281,21 +1281,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 Expand Up @@ -1730,7 +1724,7 @@ fn amm_split_large_k_with_rebase() {
delay: 14,
has_sufficient_number_of_data_points: true,
};
let mut mm_oracle_price = perp_market
let mm_oracle_price_data = perp_market
.get_mm_oracle_price_data(
oracle_price_data,
clock_slot,
Expand All @@ -1740,7 +1734,7 @@ fn amm_split_large_k_with_rebase() {

let cost = _update_amm(
&mut perp_market,
&mut mm_oracle_price,
&mm_oracle_price_data,
&state,
now,
clock_slot,
Expand Down
54 changes: 53 additions & 1 deletion programs/drift/src/controller/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anchor_spl::token_2022::spl_token_2022::extension::{
};
use anchor_spl::token_2022::spl_token_2022::state::Mint as MintInner;
use anchor_spl::token_interface::{
self, CloseAccount, Mint, TokenAccount, TokenInterface, Transfer, TransferChecked,
self, Burn, CloseAccount, Mint, MintTo, TokenAccount, TokenInterface, Transfer, TransferChecked,
};
use std::iter::Peekable;
use std::slice::Iter;
Expand Down Expand Up @@ -137,6 +137,58 @@ pub fn close_vault<'info>(
token_interface::close_account(cpi_context)
}

pub fn mint_tokens<'info>(
token_program: &Interface<'info, TokenInterface>,
destination: &InterfaceAccount<'info, TokenAccount>,
authority: &AccountInfo<'info>,
nonce: u8,
amount: u64,
mint: &InterfaceAccount<'info, Mint>,
) -> Result<()> {
let signature_seeds = get_signer_seeds(&nonce);
let signers = &[&signature_seeds[..]];

let mint_account_info = mint.to_account_info();

validate_mint_fee(&mint_account_info)?;

let cpi_accounts = MintTo {
mint: mint_account_info,
to: destination.to_account_info(),
authority: authority.to_account_info(),
};

let cpi_program = token_program.to_account_info();
let cpi_context = CpiContext::new_with_signer(cpi_program, cpi_accounts, signers);
token_interface::mint_to(cpi_context, amount)
}

pub fn burn_tokens<'info>(
token_program: &Interface<'info, TokenInterface>,
destination: &InterfaceAccount<'info, TokenAccount>,
authority: &AccountInfo<'info>,
nonce: u8,
amount: u64,
mint: &InterfaceAccount<'info, Mint>,
) -> Result<()> {
let signature_seeds = get_signer_seeds(&nonce);
let signers = &[&signature_seeds[..]];

let mint_account_info = mint.to_account_info();

validate_mint_fee(&mint_account_info)?;

let cpi_accounts = Burn {
mint: mint_account_info,
from: destination.to_account_info(),
authority: authority.to_account_info(),
};

let cpi_program = token_program.to_account_info();
let cpi_context = CpiContext::new_with_signer(cpi_program, cpi_accounts, signers);
token_interface::burn(cpi_context, amount)
}

pub fn validate_mint_fee(account_info: &AccountInfo) -> Result<()> {
let mint_data = account_info.try_borrow_data()?;
let mint_with_extension = StateWithExtensions::<MintInner>::unpack(&mint_data)?;
Expand Down
35 changes: 34 additions & 1 deletion programs/drift/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anchor_lang::prelude::*;

pub type DriftResult<T = ()> = std::result::Result<T, ErrorCode>;

#[error_code]
Expand Down Expand Up @@ -639,6 +638,40 @@ pub enum ErrorCode {
InvalidIfRebalanceConfig,
#[msg("Invalid If Rebalance Swap")]
InvalidIfRebalanceSwap,
#[msg("Invalid Constituent")]
InvalidConstituent,
#[msg("Invalid Amm Constituent Mapping argument")]
InvalidAmmConstituentMappingArgument,
#[msg("Invalid update constituent update target weights argument")]
InvalidUpdateConstituentTargetBaseArgument,
#[msg("Constituent not found")]
ConstituentNotFound,
#[msg("Constituent could not load")]
ConstituentCouldNotLoad,
#[msg("Constituent wrong mutability")]
ConstituentWrongMutability,
#[msg("Wrong number of constituents passed to instruction")]
WrongNumberOfConstituents,
#[msg("Oracle too stale for LP AUM update")]
OracleTooStaleForLPAUMUpdate,
#[msg("Insufficient constituent token balance")]
InsufficientConstituentTokenBalance,
#[msg("Amm Cache data too stale")]
AMMCacheStale,
#[msg("LP Pool AUM not updated recently")]
LpPoolAumDelayed,
#[msg("Constituent oracle is stale")]
ConstituentOracleStale,
#[msg("LP Invariant failed")]
LpInvariantFailed,
#[msg("Invalid constituent derivative weights")]
InvalidConstituentDerivativeWeights,
#[msg("Unauthorized dlp authority")]
UnauthorizedDlpAuthority,
#[msg("Max DLP AUM Breached")]
MaxDlpAumBreached,
#[msg("Settle Lp Pool Disabled")]
SettleLpPoolDisabled,
}

#[macro_export]
Expand Down
16 changes: 16 additions & 0 deletions programs/drift/src/ids.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use anchor_lang::prelude::Pubkey;
use solana_program::pubkey;

pub mod pyth_program {
use solana_program::declare_id;
#[cfg(feature = "mainnet-beta")]
Expand Down Expand Up @@ -88,6 +91,11 @@ pub mod lighthouse {
declare_id!("L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95");
}

pub mod usdc_mint {
use solana_program::declare_id;
declare_id!("BJE5MMbqXjVwjAF7oxwPYXnTXDyspzZyt4vwenNw5ruG");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt mainnet usdc?

}

pub mod mm_oracle_crank_wallet {
use solana_program::declare_id;
#[cfg(not(feature = "anchor-test"))]
Expand All @@ -107,3 +115,11 @@ pub mod amm_spread_adjust_wallet {
#[cfg(feature = "anchor-test")]
declare_id!("1ucYHAGrBbi1PaecC4Ptq5ocZLWGLBmbGWysoDGNB1N");
}

#[cfg(not(feature = "mainnet-beta"))]
pub const DLP_WHITELIST: [Pubkey; 2] = [
pubkey!("4rmhwytmKH1XsgGAUyUUH7U64HS5FtT6gM8HGKAfwcFE"),
pubkey!("1ucYHAGrBbi1PaecC4Ptq5ocZLWGLBmbGWysoDGNB1N"),
];
#[cfg(feature = "mainnet-beta")]
pub const DLP_WHITELIST: [Pubkey; 1] = [pubkey!("1ucYHAGrBbi1PaecC4Ptq5ocZLWGLBmbGWysoDGNB1N")];
Loading
Loading