Skip to content
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

Scaffold LSD Depository #280

Closed
wants to merge 6 commits into from
Closed

Scaffold LSD Depository #280

wants to merge 6 commits into from

Conversation

acamill
Copy link
Member

@acamill acamill commented Jul 21, 2023

No description provided.

Copy link
Contributor

@Orelsanpls Orelsanpls left a comment

Choose a reason for hiding this comment

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

a good start!

bump,
payer = payer,
)]
pub profits_token_account: Account<'info, TokenAccount>,
Copy link
Contributor

@cnek cnek Jul 21, 2023

Choose a reason for hiding this comment

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

if we design to have a borrow fee settings here,
then it also require a token account storing the redeemable that the user pay upon borrowing?
And same with repay fee.
So in total there would be redeemable_profits_token_account, collateral_profits_token_account, liquidation_profits_token_account ,
and each of their own profits beneficiary

Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking based on my reading of the rest of the PR:

  • this ATA is probably going to be in "liquidation_mint" amount so more like "profits_liquidation"
  • the user most likely will pay fees using collateral rather than redeemable right ? or we just mint "less" redeemable ? I dont know if we need to store any redeemable inside of the depository

Copy link
Contributor

Choose a reason for hiding this comment

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

Depends on how we wanna store fee as, but like for solend if there are a borrow fee, then its collected on the borrowing mint which is redeemable on our case, like if u are borrowing 10k UXD and borrowing fee on 0.05% then 10k is minted but u only take home 9995, and we take the 5 remaining. To repay the whole position u have to mint/swap elsewhere 5 more.
But agree "mint less" is a easier way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yhea, for now I factored it all into a profits token account and I left a comment somewhere "swap to profit mint" on collection

pub collateral_amount: u64,
pub redeemable_amount: u64,
pub effective_ltv_bps: u8,
pub liquidation_price: u64,
Copy link
Contributor

@crypto-vincent crypto-vincent Jul 24, 2023

Choose a reason for hiding this comment

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

nit: is the liquidation price in liquidation_mint amount ? if so maybe it could be in the name of the variable ?

Copy link
Member Author

Choose a reason for hiding this comment

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

default price is in the target mint, if specified _usd it's in USD I would say?

pub collateral_mint_decimals: u8,
pub liquidation_mint: Pubkey, // when liquidation occurs, this is the target mint (should )
pub liquidation_mint_decimals: u8,
pub profits_token_account: Pubkey, // using liquidation_mint. Contains liquidation profits + borrowing fees if any
Copy link
Contributor

Choose a reason for hiding this comment

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

using the naming used in other places this could be: depository_liquidation ?

pub depository: Pubkey,
pub collateral_amount: u64,
pub redeemable_amount: u64,
pub effective_ltv_bps: u8,
Copy link
Contributor

Choose a reason for hiding this comment

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

qq: im not sure I understand the purpose of this field

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes me neither, removed a few minutes ago before seeing that comment 😆

/// #4
#[account(
mut,
seeds = [LSD_DEPOSITORY_NAMESPACE, collateral_mint.key().as_ref()],
Copy link
Contributor

Choose a reason for hiding this comment

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

should we include the liquidation mint in the depository seeds?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would mean running two LSD depository for the same collateral with different liquidation mints... which we won't do 99.999% chance. Tbh if USDC dies, we die 😓

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah fair enough, I guess my point was: is there any downside to include it? no strong opinion tho

payer = payer,
bump,
)]
pub lsd_position_collateral_token_account: Box<Account<'info, TokenAccount>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

micro-nit: in other places in the code, we would just call this:

lsd_position_collateral

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed

"editor.formatOnSave": true,
"rust-analyzer.linkedProjects": [
"./programs/uxd/Cargo.toml"
]
Copy link
Contributor

Choose a reason for hiding this comment

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

interdasting, im curious what this is for

Copy link
Member Author

Choose a reason for hiding this comment

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

Me too, vscode what have you done 😄

@crypto-vincent
Copy link
Contributor

quick nit: should we target this to develop ?

@acamill acamill changed the base branch from main to develop July 25, 2023 03:42
{
// - 0.1 verify that borrows are enabled
let lsd_depository = ctx.accounts.depository.load()?;
require!(lsd_depository.borrowing_disabled == false, UxdError::BorrowingDisabled);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: probably can be done in a validate function (we usually use the validate pattern for this stuff)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe aware of that I wrote it 😏
Normally the validate function, as the name suggest, validates the input parameters. For convenience we let the program frozen get there, which is not really related.
For business checks I find it clearer to keep them in the body of the function

}

// - 2 [MINT REDEEMABLES] --------------------------------------------------
let redeemable_borrow_amount = collateral_amount / u64::from(loan_to_value_bps) * u64::from(BPS_POWER);
Copy link
Contributor

Choose a reason for hiding this comment

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

might want to use checked_math there, i'd feel safer

Copy link
Member Author

Choose a reason for hiding this comment

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

yes need to update to checked everywhere

Copy link
Member Author

Choose a reason for hiding this comment

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

Updating these in the other PR, thanks for the feedback

curtime,
false,
)?;
let lsd_price_usd = lsd_price.get_asset_amount_usd(collateral_amount, depository.collateral_mint_decimals)?;
Copy link
Contributor

@crypto-vincent crypto-vincent Jul 30, 2023

Choose a reason for hiding this comment

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

wow that is a thing? how do they compute this?? Very cool!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe yes neat!

false,
)?;
let lsd_price_usd = lsd_price.get_asset_amount_usd(collateral_amount, depository.collateral_mint_decimals)?;
liquidation_price = maths::checked_mul(redeemable_borrow_amount, maths::checked_div(u64::from(depository.max_loan_to_value_bps), u64::from(BPS_POWER))?)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

sounds like we need a utility function to compute this, its used in many places

Copy link
Member Author

Choose a reason for hiding this comment

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

Just 2 op I rather keep things flat x)
I know we diverge on this, but I think it's more straight forward. There might be a function in the math lib already though, else I would stick to what's there

@acamill
Copy link
Member Author

acamill commented Jul 31, 2023

replaced by #283 and #284

@acamill acamill closed this Jul 31, 2023
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