-
Notifications
You must be signed in to change notification settings - Fork 0
(3) Settler: Proposal Lifecycle #49
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
Open
GuidoDipietro
wants to merge
43
commits into
solana/settler
Choose a base branch
from
solana/3-settler-proposal-lifecycle
base: solana/settler
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,656
−15
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
878e5ed
Add Whitelist program
GuidoDipietro 57af08c
Settler: Intent lifecycle
GuidoDipietro cc10fad
Settler: Proposal Lifecycle
GuidoDipietro f5e81b9
Fix tests
GuidoDipietro 2f91061
Merge branch 'solana/1-whitelist' into solana/2-settler-intent-lifecycle
GuidoDipietro f1545be
Trim tests to this PRs features
GuidoDipietro 9bd0e0e
Rm signatures utils as not relevant in this PR
GuidoDipietro ea31118
Trim SDK to match this PRs features
GuidoDipietro 0707a85
Trim tests to this PRs features
GuidoDipietro 1b87e10
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro 3d93df3
EVM: Deploy contracts to Ethereum (#51)
alavarello a20c769
chore: update readme
facuspagnuolo 804e2a4
Code review: simplify set admin process
GuidoDipietro a8b019b
Code review: Remove updated_by and last_update from EntityRegistry
GuidoDipietro eff0a23
Code review: rename Whitelist to Controller/Allowlist
GuidoDipietro 90c6e3c
Code review: rm EntityRegistry status and close when not in allowlist
GuidoDipietro 5cfce2b
Several fixes in Controller code
GuidoDipietro 4282a1f
Code review: address other comments
GuidoDipietro b918391
Code review: add license
GuidoDipietro 44a93c6
Merge branch 'solana/1-whitelist' into solana/2-settler-intent-lifecycle
GuidoDipietro e916fa1
Code review: adapt Settler to Controller changes
GuidoDipietro a1eb61d
Code review: rename controller::GlobalSettings to ControllerSettings,…
GuidoDipietro 5f8eb31
Code review: rm is_paused from SettlerSettings
GuidoDipietro f42465b
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro 1039442
Code review: adapt Settler to match Controller changes
GuidoDipietro 435b7dc
Rm unused is_paused flag
GuidoDipietro 5e4eb54
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro b638369
Fix lint
GuidoDipietro 3130209
Code review: rename proposal_creator to creator
GuidoDipietro efbfea9
Fix lint
GuidoDipietro e1ef9ed
Code review: several comments
GuidoDipietro c715467
Code review: context() pattern in tests
GuidoDipietro 0d815fa
Merge branch 'solana/1-whitelist' into solana/2-settler-intent-lifecycle
GuidoDipietro 40d2ad6
Fix lint and merge errors
GuidoDipietro 89ddecc
Code review: several comments
GuidoDipietro 38d0f18
Merge branch 'solana/2-settler-intent-lifecycle' into solana/3-settle…
GuidoDipietro ba1d144
Code review: change crate::controller to controller
GuidoDipietro 0ff6529
(1) Add Controller program (#45)
GuidoDipietro e690d3c
Merge branch 'solana/settler' into solana/3-settler-proposal-lifecycle
GuidoDipietro 1ac6503
Revert "Merge branch 'solana/settler' into solana/3-settler-proposal-…
GuidoDipietro 9fd1cc8
Merge branch 'solana/settler' into solana/3-settler-proposal-lifecycle
GuidoDipietro 391eb43
Correct controller.test.ts file
GuidoDipietro ce6dba5
Code review: remove batch capabilities from claim_stale_proposal
GuidoDipietro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/svm/programs/settler/src/instructions/add_instructions_to_proposal.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{ | ||
| errors::SettlerError, | ||
| state::{Proposal, ProposalInstruction}, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| #[instruction(more_instructions: Vec<ProposalInstruction>)] | ||
| pub struct AddInstructionsToProposal<'info> { | ||
| #[account(mut)] | ||
| pub creator: Signer<'info>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| realloc = Proposal::extended_size(proposal.to_account_info().data_len(), &more_instructions)?, | ||
| realloc::payer = creator, | ||
| realloc::zero = true, | ||
| has_one = creator @ SettlerError::IncorrectProposalCreator | ||
| )] | ||
| // Any proposal | ||
| pub proposal: Box<Account<'info, Proposal>>, | ||
|
|
||
| pub system_program: Program<'info, System>, | ||
| } | ||
|
|
||
| pub fn add_instructions_to_proposal( | ||
| ctx: Context<AddInstructionsToProposal>, | ||
| more_instructions: Vec<ProposalInstruction>, | ||
| finalize: bool, | ||
| ) -> Result<()> { | ||
| let now = Clock::get()?.unix_timestamp as u64; | ||
| let proposal = &mut ctx.accounts.proposal; | ||
|
|
||
| require!(proposal.deadline > now, SettlerError::ProposalIsExpired); | ||
| require!(!proposal.is_final, SettlerError::ProposalIsFinal); | ||
|
|
||
| proposal.instructions.extend_from_slice(&more_instructions); | ||
|
|
||
| if finalize { | ||
| proposal.is_final = true; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/svm/programs/settler/src/instructions/claim_stale_proposal.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{errors::SettlerError, state::Proposal}; | ||
|
|
||
| #[derive(Accounts)] | ||
| pub struct ClaimStaleProposal<'info> { | ||
| #[account(mut)] | ||
| pub creator: Signer<'info>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| close = creator, | ||
| has_one = creator @ SettlerError::IncorrectProposalCreator, | ||
| constraint = Clock::get()?.unix_timestamp as u64 > proposal.deadline @ SettlerError::ProposalNotYetExpired | ||
| )] | ||
| pub proposal: Box<Account<'info, Proposal>>, | ||
| } | ||
|
|
||
| pub fn claim_stale_proposal(_ctx: Context<ClaimStaleProposal>) -> Result<()> { | ||
| Ok(()) | ||
| } |
95 changes: 95 additions & 0 deletions
95
packages/svm/programs/settler/src/instructions/create_proposal.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{ | ||
| controller::{self, accounts::EntityRegistry, types::EntityType}, | ||
| errors::SettlerError, | ||
| state::{Intent, Proposal, ProposalInstruction}, | ||
| types::TokenFee, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| #[instruction(instructions: Vec<ProposalInstruction>, fees: Vec<TokenFee>,)] | ||
| pub struct CreateProposal<'info> { | ||
| #[account(mut)] | ||
| pub solver: Signer<'info>, | ||
|
|
||
| #[account( | ||
| seeds = [b"entity-registry", &[EntityType::Solver as u8 + 1], solver.key().as_ref()], | ||
| bump = solver_registry.bump, | ||
| seeds::program = controller::ID, | ||
| )] | ||
| pub solver_registry: Box<Account<'info, EntityRegistry>>, | ||
|
|
||
| /// Any intent | ||
| pub intent: Box<Account<'info, Intent>>, | ||
|
|
||
| #[account( | ||
| seeds = [b"fulfilled-intent", intent.hash.as_ref()], | ||
| bump | ||
| )] | ||
| /// This PDA must be uninitialized (checked by SystemAccount type) | ||
| pub fulfilled_intent: SystemAccount<'info>, | ||
|
|
||
| #[account( | ||
| init, | ||
| seeds = [b"proposal", intent.key().as_ref(), solver.key().as_ref()], | ||
| bump, | ||
| payer = solver, | ||
| space = Proposal::total_size(&instructions, fees.len())? | ||
| )] | ||
| pub proposal: Box<Account<'info, Proposal>>, | ||
|
|
||
| pub system_program: Program<'info, System>, | ||
| } | ||
|
|
||
| pub fn create_proposal( | ||
| ctx: Context<CreateProposal>, | ||
| instructions: Vec<ProposalInstruction>, | ||
| fees: Vec<TokenFee>, | ||
| deadline: u64, | ||
| is_final: bool, | ||
| ) -> Result<()> { | ||
| let now = Clock::get()?.unix_timestamp as u64; | ||
| let intent = &ctx.accounts.intent; | ||
|
|
||
| require!(deadline > now, SettlerError::DeadlineIsInThePast); | ||
| require!(intent.deadline > now, SettlerError::IntentIsExpired); | ||
| require!( | ||
| deadline <= intent.deadline, | ||
| SettlerError::ProposalDeadlineExceedsIntentDeadline | ||
| ); | ||
| require!( | ||
| intent.validators.len() >= intent.min_validations as usize, | ||
| SettlerError::InsufficientIntentValidations | ||
| ); | ||
| require!(intent.is_final, SettlerError::IntentIsNotFinal); | ||
| require!( | ||
| fees.len() == intent.max_fees.len(), | ||
| SettlerError::InvalidFeeMint | ||
| ); | ||
|
|
||
| fees.iter() | ||
| .zip(&intent.max_fees) | ||
| .try_for_each(|(fee, max_fee)| { | ||
| require_keys_eq!(fee.mint, max_fee.mint, SettlerError::InvalidFeeMint); | ||
| require_gte!( | ||
| max_fee.amount, | ||
| fee.amount, | ||
| SettlerError::FeeAmountExceedsMaxFee | ||
| ); | ||
| Ok(()) | ||
| })?; | ||
|
|
||
| let proposal = &mut ctx.accounts.proposal; | ||
|
|
||
| proposal.intent = intent.key(); | ||
| proposal.creator = ctx.accounts.solver.key(); | ||
| proposal.deadline = deadline; | ||
| proposal.is_final = is_final; | ||
| proposal.is_signed = false; | ||
| proposal.instructions = instructions; | ||
| proposal.fees = fees; | ||
| proposal.bump = ctx.bumps.proposal; | ||
|
|
||
| Ok(()) | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
packages/svm/programs/settler/src/instructions/execute_proposal.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{ | ||
| controller::{self, accounts::EntityRegistry, types::EntityType}, | ||
| errors::SettlerError, | ||
| state::{FulfilledIntent, Intent, Proposal}, | ||
| types::IntentEvent, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| pub struct ExecuteProposal<'info> { | ||
| #[account(mut)] | ||
| pub solver: Signer<'info>, | ||
|
|
||
| #[account( | ||
| seeds = [b"entity-registry", &[EntityType::Solver as u8 + 1], solver.key().as_ref()], | ||
| bump = solver_registry.bump, | ||
| seeds::program = controller::ID, | ||
| )] | ||
| pub solver_registry: Box<Account<'info, EntityRegistry>>, | ||
|
|
||
| /// CHECK: account defined in proposal | ||
| #[account(mut)] | ||
| pub proposal_creator: UncheckedAccount<'info>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| has_one = intent @ SettlerError::IncorrectIntentForProposal, | ||
| constraint = proposal.creator == proposal_creator.key() @ SettlerError::IncorrectProposalCreator, | ||
| constraint = proposal.is_signed @ SettlerError::ProposalIsNotSigned, | ||
| close = proposal_creator | ||
| )] | ||
| pub proposal: Box<Account<'info, Proposal>>, | ||
|
|
||
| /// CHECK: account defined in intent | ||
| #[account(mut)] | ||
| pub intent_creator: UncheckedAccount<'info>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| constraint = intent.creator == intent_creator.key() @ SettlerError::IncorrectIntentCreator, | ||
| close = intent_creator | ||
| )] | ||
| pub intent: Box<Account<'info, Intent>>, | ||
|
|
||
| #[account( | ||
| init, | ||
| seeds = [b"fulfilled-intent", intent.hash.as_ref()], | ||
| bump, | ||
| space = 8 + FulfilledIntent::INIT_SPACE, | ||
| payer = solver | ||
| )] | ||
| pub fulfilled_intent: Box<Account<'info, FulfilledIntent>>, | ||
|
|
||
| pub system_program: Program<'info, System>, | ||
| } | ||
|
|
||
| pub fn execute_proposal(ctx: Context<ExecuteProposal>) -> Result<()> { | ||
| let now = Clock::get()?.unix_timestamp as u64; | ||
| let proposal = &ctx.accounts.proposal; | ||
| let intent = &ctx.accounts.intent; | ||
|
|
||
| require!(proposal.deadline > now, SettlerError::ProposalIsExpired); | ||
|
|
||
| // TODO: Execute proposal | ||
|
|
||
| // TODO: Validate execution | ||
|
|
||
| // TODO: Emit events | ||
| intent.events.iter().for_each(|event| { | ||
| emit!(IntentEventEvent { | ||
| event: event.clone() | ||
| }) | ||
| }); | ||
|
|
||
| // TODO: Pay fees to Solver | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[event] | ||
| pub struct IntentEventEvent { | ||
| event: IntentEvent, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| pub mod add_instructions_to_proposal; | ||
| pub mod claim_stale_intent; | ||
| pub mod claim_stale_proposal; | ||
| pub mod create_intent; | ||
| pub mod create_proposal; | ||
| pub mod execute_proposal; | ||
| pub mod extend_intent; | ||
| pub mod initialize; | ||
|
|
||
| pub use add_instructions_to_proposal::*; | ||
| pub use claim_stale_intent::*; | ||
| pub use claim_stale_proposal::*; | ||
| pub use create_intent::*; | ||
| pub use create_proposal::*; | ||
| pub use execute_proposal::*; | ||
| pub use extend_intent::*; | ||
| pub use initialize::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| pub mod fulfilled_intent; | ||
| pub mod intent; | ||
| pub mod proposal; | ||
| pub mod settler_settings; | ||
|
|
||
| pub use fulfilled_intent::*; | ||
| pub use intent::*; | ||
| pub use proposal::*; | ||
| pub use settler_settings::*; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.