restaking-v2: added restaking program with tests#346
restaking-v2: added restaking program with tests#346
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.
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.
i think that makes sense.
There was a problem hiding this comment.
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.
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.
Similarly here, we may en up reducing stake by less than the amount we’ve burnt. Perhaps round down the amount?
| let amount_in_sol_decimals = 10u64.pow(SOL_DECIMALS as u32) / | ||
| 10u64.pow(token_decimals as u32); |
There was a problem hiding this comment.
This may be zero if token_decimals is greater than sol_decimals.
There was a problem hiding this comment.
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.