-
Notifications
You must be signed in to change notification settings - Fork 141
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
base: master
Are you sure you want to change the base?
bigz/init-lp-pool #1565
Conversation
* add get_swap_amount, get_swap_fees, get_weight * update accounts * add back ts * rebase * add constituent swap fees
init constituent
* add initializeLpPool test * add check for constituent target weights
Nour/add mapping datum
…t-weights add crank ix
Nour/remove amm mappings
Nour/crank aum
Nour/crank aum improvements
* add passthrough account logic * cant read yet * fix all zc alignment issues * make oracle source a u8 on zc struct
* add lp_swap ix * rebase * test helpers * swap works * fix swaps, add more cargo tests for fees n swap amt * remove console.logs * address PR comments * merge upstream
#[zero_copy(unsafe)] | ||
#[derive(Default, Eq, PartialEq, Debug, BorshDeserialize, BorshSerialize)] | ||
#[repr(C)] | ||
pub struct BLPosition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ConstituentSpotPosition might be more consistent name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constituent spot position is actually a computed value -- it's named this because it's only the borrow-lend position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never use BL any where so it's introduction of new naming convention, think we should try to make it closer to what we use for user/spot market. So SpotPosition or PoolBalance
Do you mean it's computed because there are tokens in the token account too?
programs/drift/src/state/lp_pool.rs
Outdated
pub constituent_index: u16, | ||
|
||
pub decimals: u8, | ||
_padding1: [u8; 3], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the algo to minimize padding is to sort the fields by size desc, thats what we did for spot/perp mkts
Ok(()) | ||
} | ||
|
||
pub fn handle_update_init_amm_cache_info<'c: 'info, 'info>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it called update_init cuz we just run this once the first time we deploy dlp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah exactly. it'll init to the default value for the size of all the perp markets we have, then we go and update the values in place aftewards for existing markets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant you just make it so the update cache fn will handle this on the first crank?
mint::decimals = 6, | ||
mint::authority = lp_pool.key(), | ||
)] | ||
pub mint: Account<'info, anchor_spl::token::Mint>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we wanna make this a pda? or we want vanity addy?
token::mint = spot_market_mint, | ||
token::authority = drift_signer | ||
)] | ||
pub constituent_vault: Box<InterfaceAccount<'info, TokenAccount>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically we could make the vault the authority for itself.
pro's: might make reading balances in explorer easier
con's: breaks current drift v2 pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually think itll save you address on swap so prob worth it even though it breaks pattern
for (i, constituent_index) in constituents_indexes.iter().enumerate() { | ||
let mut target_amount = 0i128; | ||
|
||
for (perp_market_index, inventory) in amm_inventory.iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two for loops feels like could be a lot of CUs; will need CU test for when there are a ton of markets
#[account( | ||
constraint = in_market_mint.key() == in_constituent.load()?.mint, | ||
)] | ||
pub in_market_mint: Box<InterfaceAccount<'info, Mint>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you only need the mint for token 22 programs, might be worth it to make it optional to save accounts
pub constituent_target_weights: AccountInfo<'info>, | ||
|
||
#[account(mut)] | ||
pub constituent_in_token_account: Box<InterfaceAccount<'info, TokenAccount>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to validate this is the constituent's token account?
mint_in: in_constituent.mint, | ||
}); | ||
|
||
receive( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe im missing it but how does this account for the amount thats in drift vs in token account?
* store bumps on accounts * do pda check in constituent map
address comments
* add add remove liquidity fees calc * add liquidity ix * fix init mint and lppool token account, refactor test fees * add removeLiquidity bankrun test * merge upstream * add LPPool.next_mint_redeem_id
No description provided.