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 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 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
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ sdk/src/**/*.js.map
.DS_STORE
.vscode
migrations
/**/*.env
/**/*.env
vendor
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
54 changes: 53 additions & 1 deletion programs/drift/src/controller/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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,
};

pub fn send_from_program_vault<'info>(
Expand Down Expand Up @@ -106,6 +106,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
20 changes: 20 additions & 0 deletions programs/drift/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anchor_lang::prelude::*;

use crate::state::lp_pool::Constituent;

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

#[error_code]
Expand Down Expand Up @@ -635,6 +637,24 @@ pub enum ErrorCode {
InvalidSignedMsgUserOrdersResize,
#[msg("Could not deserialize high leverage mode config")]
CouldNotDeserializeHighLeverageModeConfig,
#[msg("Invalid Constituent")]
InvalidConstituent,
#[msg("Invalid Amm Constituent Mapping argument")]
InvalidAmmConstituentMappingArgument,
#[msg("Invalid update constituent update target weights argument")]
InvalidUpdateConstituentTargetWeightsArgument,
#[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,
}

#[macro_export]
Expand Down
Loading
Loading