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

restaking-v2: added restaking program with tests #346

Open
wants to merge 41 commits into
base: master
Choose a base branch
from

Conversation

dhruvja
Copy link
Collaborator

@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
Collaborator

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
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator

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
Collaborator Author

Choose a reason for hiding this comment

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

yes

solana/restaking-v2/programs/restaking-v2/src/lib.rs Outdated Show resolved Hide resolved
solana/restaking-v2/programs/restaking-v2/src/lib.rs Outdated Show resolved Hide resolved
@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
Collaborator

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
Collaborator 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