-
Notifications
You must be signed in to change notification settings - Fork 0
(2) Settler: Intent lifecycle #48
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
Merged
GuidoDipietro
merged 3 commits into
solana/settler
from
solana/2-settler-intent-lifecycle
Jan 6, 2026
Merged
Changes from all commits
Commits
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,5 +1,5 @@ | ||
| pub mod controller_settings; | ||
| pub mod entity_registry; | ||
| pub mod global_settings; | ||
|
|
||
| pub use controller_settings::*; | ||
| pub use entity_registry::*; | ||
| pub use global_settings::*; |
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| pub const DEPLOYER_KEY: &str = env!( | ||
| "DEPLOYER_KEY", | ||
| "Please set the DEPLOYER_KEY env variable before compiling." | ||
| ); |
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,79 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| #[error_code] | ||
| pub enum SettlerError { | ||
| #[msg("Only Deployer can call this instruction")] | ||
| OnlyDeployer, | ||
|
|
||
| #[msg("Only an allowlisted solver can call this instruction")] | ||
| OnlySolver, | ||
|
|
||
| #[msg("Provided Axia address is not allowlisted")] | ||
| AxiaNotAllowlisted, | ||
|
|
||
| #[msg("Only a allowlisted validator can call this instruction")] | ||
| OnlyValidator, | ||
|
|
||
| #[msg("No max fees provided")] | ||
| NoMaxFees, | ||
|
|
||
| #[msg("Validator is not allowlisted")] | ||
| ValidatorNotAllowlisted, | ||
|
|
||
| #[msg("Signer must be intent creator")] | ||
| IncorrectIntentCreator, | ||
|
|
||
| #[msg("Signer must be proposal creator")] | ||
| IncorrectProposalCreator, | ||
|
|
||
| #[msg("Intent is already final")] | ||
| IntentIsFinal, | ||
|
|
||
| #[msg("Intent is not final")] | ||
| IntentIsNotFinal, | ||
|
|
||
| #[msg("Proposal is already final")] | ||
| ProposalIsFinal, | ||
|
|
||
| #[msg("Proposal is not final")] | ||
| ProposalIsNotFinal, | ||
|
|
||
| #[msg("Intent not yet expired. Please wait for the deadline to pass")] | ||
| IntentNotYetExpired, | ||
|
|
||
| #[msg("Intent has already expired")] | ||
| IntentIsExpired, | ||
|
|
||
| #[msg("Proposal not yet expired. Please wait for the deadline to pass")] | ||
| ProposalNotYetExpired, | ||
|
|
||
| #[msg("Proposal has already expired")] | ||
| ProposalIsExpired, | ||
|
|
||
| #[msg("Deadline must be in the future")] | ||
| DeadlineIsInThePast, | ||
|
|
||
| #[msg("Proposal deadline can't be after the Intent's deadline")] | ||
| ProposalDeadlineExceedsIntentDeadline, | ||
|
|
||
| #[msg("Intent has insufficient validations")] | ||
| InsufficientIntentValidations, | ||
|
|
||
| #[msg("Signature verification failed")] | ||
| SigVerificationFailed, | ||
|
|
||
| #[msg("Incorrect intent for proposal")] | ||
| IncorrectIntentForProposal, | ||
|
|
||
| #[msg("Proposal is not signed by Axia")] | ||
| ProposalIsNotSigned, | ||
|
|
||
| #[msg("Invalid fee mint")] | ||
| InvalidFeeMint, | ||
|
|
||
| #[msg("Fee amount exceeds max fee")] | ||
| FeeAmountExceedsMaxFee, | ||
|
|
||
| #[msg("Math Error")] | ||
| MathError, | ||
| } |
27 changes: 27 additions & 0 deletions
27
packages/svm/programs/settler/src/instructions/claim_stale_intent.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,27 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{errors::SettlerError, state::Intent}; | ||
|
|
||
| #[derive(Accounts)] | ||
| pub struct ClaimStaleIntent<'info> { | ||
| #[account(mut)] | ||
| pub creator: Signer<'info>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| close = creator, | ||
| has_one = creator @ SettlerError::IncorrectIntentCreator, | ||
| )] | ||
| pub intent: Box<Account<'info, Intent>>, | ||
| } | ||
|
|
||
| pub fn claim_stale_intent(ctx: Context<ClaimStaleIntent>) -> Result<()> { | ||
| let now = Clock::get()?.unix_timestamp as u64; | ||
|
|
||
| require!( | ||
| ctx.accounts.intent.deadline < now, | ||
| SettlerError::IntentNotYetExpired | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
81 changes: 81 additions & 0 deletions
81
packages/svm/programs/settler/src/instructions/create_intent.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,81 @@ | ||
| use anchor_lang::prelude::*; | ||
|
|
||
| use crate::{ | ||
| controller::{self, accounts::EntityRegistry, types::EntityType}, | ||
| errors::SettlerError, | ||
| state::Intent, | ||
| types::{IntentEvent, OpType, TokenFee}, | ||
| }; | ||
|
|
||
| #[derive(Accounts)] | ||
| // TODO: can we optimize this deser? we just need the three Vec<T> for their length | ||
| #[instruction(intent_hash: [u8; 32], data: Vec<u8>, max_fees: Vec<TokenFee>, events: Vec<IntentEvent>, min_validations: u16)] | ||
| pub struct CreateIntent<'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>>, | ||
|
|
||
| #[account( | ||
| init, | ||
| seeds = [b"intent", intent_hash.as_ref()], | ||
| bump, | ||
| payer = solver, | ||
| space = Intent::total_size(data.len(), max_fees.len(), &events, min_validations)? | ||
| )] | ||
| // TODO: change to AccountLoader? | ||
| // TODO: init within the handler body to save compute? | ||
| pub intent: Box<Account<'info, Intent>>, | ||
|
|
||
| #[account( | ||
| seeds = [b"fulfilled-intent", intent_hash.as_ref()], | ||
| bump | ||
| )] | ||
| /// This PDA must be uninitialized | ||
| pub fulfilled_intent: SystemAccount<'info>, | ||
|
|
||
| pub system_program: Program<'info, System>, | ||
| } | ||
|
|
||
| pub fn create_intent( | ||
| ctx: Context<CreateIntent>, | ||
| intent_hash: [u8; 32], | ||
| data: Vec<u8>, | ||
| max_fees: Vec<TokenFee>, | ||
| events: Vec<IntentEvent>, | ||
| min_validations: u16, | ||
| op: OpType, | ||
| user: Pubkey, | ||
| nonce: [u8; 32], | ||
| deadline: u64, | ||
| is_final: bool, | ||
| ) -> Result<()> { | ||
| let now = Clock::get()?.unix_timestamp as u64; | ||
| require!(deadline > now, SettlerError::DeadlineIsInThePast); | ||
| require!(max_fees.len() > 0, SettlerError::NoMaxFees); | ||
|
|
||
| // TODO: check hash | ||
|
|
||
| let intent = &mut ctx.accounts.intent; | ||
|
|
||
| intent.op = op; | ||
| intent.user = user; | ||
| intent.creator = ctx.accounts.solver.key(); | ||
| intent.hash = intent_hash; | ||
| intent.nonce = nonce; | ||
| intent.deadline = deadline; | ||
| intent.min_validations = min_validations; | ||
| intent.is_final = is_final; | ||
| intent.data = data; | ||
| intent.max_fees = max_fees; | ||
| intent.events = events; | ||
| intent.validators = vec![]; | ||
| intent.bump = ctx.bumps.intent; | ||
|
|
||
| Ok(()) | ||
| } | ||
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.
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.
are we doing something with this account?
Uh oh!
There was an error while loading. Please reload this page.
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.
We check this in a future instruction to validate that a given intent has not already been executed on-chain.
I.e., this is our on-chain proof that a given intent was fulfilled.