-
Notifications
You must be signed in to change notification settings - Fork 7
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
restaking-v2: added restaking program with tests #346
base: master
Are you sure you want to change the base?
Conversation
anchor_spl::token::mint_to(cpi_ctx, amount)?; | ||
|
||
// Call guest chain program to update the stake equally | ||
let stake_per_validator = amount / common_state.validators.len() as u64; |
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.
amount may be indivisible by the number of validators. We may want to add a reminder to a random validator.
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.
i think that makes sense.
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.
i think we should add the remainder to a particular validator because during withdrawal we might be withdrawing the remainder from a different validator.
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.
not that the remainder value would be high, but i think it can cause underflow during withdrawal. The other option might be that if it causes underflow, we remove it from a different validator but then we need to deserialize the chain data on restaking layer which i dont think is really worth it.
anchor_spl::token::burn(cpi_ctx, amount)?; | ||
|
||
// Call guest chain program to update the stake equally | ||
let stake_per_validator = (amount / common_state.validators.len() as u64) as i128; |
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.
Similarly here, we may en up reducing stake by less than the amount we’ve burnt. Perhaps round down the amount?
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.
yes
let amount_in_sol_decimals = 10u64.pow(SOL_DECIMALS as u32) / | ||
10u64.pow(token_decimals as u32); |
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.
This may be zero if token_decimals is greater than sol_decimals.
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.
storing the value by multiplying with exponent so that we dont miss the fractions.
In this restaking model, the deposit is equally distributed to all the validators and same during withdrawal. The validators have an option to be part of this model. The validators would have to bond a minimum amount to be part of this new restaking program.