Skip to content

restaking-v2: added restaking program with tests#346

Open
dhruvja wants to merge 41 commits intomasterfrom
restaking-v2
Open

restaking-v2: added restaking program with tests#346
dhruvja wants to merge 41 commits intomasterfrom
restaking-v2

Conversation

@dhruvja
Copy link
Contributor

@dhruvja dhruvja commented Jun 15, 2024

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.

@dhruvja dhruvja requested a review from mina86 June 15, 2024 23:16
@dhruvja dhruvja marked this pull request as draft June 15, 2024 23:17
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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

@dhruvja dhruvja marked this pull request as ready for review July 8, 2024 10:51
Comment on lines +422 to +423
let amount_in_sol_decimals = 10u64.pow(SOL_DECIMALS as u32) /
10u64.pow(token_decimals as u32);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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.

2 participants