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

bigz/init-lp-pool #1565

wants to merge 59 commits into from

Conversation

0xbigz
Copy link
Member

@0xbigz 0xbigz commented Apr 8, 2025

No description provided.

0xbigz and others added 30 commits April 8, 2025 13:06
* add get_swap_amount, get_swap_fees, get_weight

* update accounts

* add back ts

* rebase

* add constituent swap fees
* add initializeLpPool test

* add check for constituent target weights
0xbigz and others added 25 commits April 25, 2025 12:28
* 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 {
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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?

pub constituent_index: u16,

pub decimals: u8,
_padding1: [u8; 3],
Copy link
Member

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>(
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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>,
Copy link
Member

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>>,
Copy link
Member

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

Copy link
Member

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() {
Copy link
Member

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>>,
Copy link
Member

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>>,
Copy link
Member

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(
Copy link
Member

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?

NourAlharithi and others added 4 commits May 5, 2025 14:07
* store bumps on accounts

* do pda check in constituent map
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants