Repository navigation
Base layer actions #75
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bdb6411
feat: raw finalize with args
taco-paco ff12645
feat: working finalize with handler
taco-paco 224c0ea
refacor: renaming + cleaning
taco-paco ec450c4
refactor: update example to access escrow_index
taco-paco ac6fcea
refactor: some cleaning + fmt
taco-paco c3121c8
feat: generall CallHandler entrypoint. Context should be set by valid…
taco-paco fd8f819
feat: transfer example with post delegation
taco-paco 0633356
feat: commit now required to be sequential
taco-paco fa4ac06
fix: rebase
taco-paco 374603f
fix: necessary impls
taco-paco e8629b2
feat: set error on commit id out of order
taco-paco b149f8a
feat: added & fixed tests + file cleanup
taco-paco 6edfe00
refactor: zombie code
taco-paco 3586c01
feat: delegation program uses only valid escrow pda
taco-paco 00d7205
feat: update tests and undelegation
taco-paco ed34ee3
fix: lint
taco-paco 2bcfd25
fix: greptile comments
taco-paco 6835ae8
fix: addressed pr comments, changed descriptions + removed msg
taco-paco ce5add9
refactor: comment fixes
taco-paco 4449f43
fix: test compilation
taco-paco 5fb8d20
refactor: CommitStateArgs::slot to CommitStateArgs::nonce rename and …
taco-paco 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
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,15 @@ | ||
| use borsh::{BorshDeserialize, BorshSerialize}; | ||
|
|
||
| #[derive(BorshSerialize, BorshDeserialize, Clone, Copy)] | ||
| pub enum Context { | ||
| Commit, | ||
| Undelegate, | ||
| Standalone, | ||
| } | ||
|
|
||
| #[derive(BorshSerialize, BorshDeserialize)] | ||
| pub struct CallHandlerArgs { | ||
| pub escrow_index: u8, | ||
| pub data: Vec<u8>, | ||
| pub context: Context, | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use crate::args::CallHandlerArgs; | ||
| use crate::discriminator::DlpDiscriminator; | ||
| use crate::pda::{ephemeral_balance_pda_from_payer, validator_fees_vault_pda_from_validator}; | ||
| use borsh::to_vec; | ||
| use solana_program::instruction::Instruction; | ||
| use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; | ||
|
|
||
| /// Builds a call handler instruction. | ||
| /// See [crate::processor::call_handler] for docs. | ||
| pub fn call_handler( | ||
| validator: Pubkey, | ||
| destination_program: Pubkey, | ||
| escrow_authority: Pubkey, | ||
| other_accounts: Vec<AccountMeta>, | ||
| args: CallHandlerArgs, | ||
| ) -> Instruction { | ||
| let validator_fees_vault_pda = validator_fees_vault_pda_from_validator(&validator); | ||
|
|
||
| // handler accounts | ||
| let escrow_account = ephemeral_balance_pda_from_payer(&escrow_authority, args.escrow_index); | ||
| let mut accounts = vec![ | ||
| AccountMeta::new(validator, true), | ||
| AccountMeta::new(validator_fees_vault_pda, false), | ||
| AccountMeta::new_readonly(destination_program, false), | ||
| AccountMeta::new(escrow_authority, false), | ||
| AccountMeta::new(escrow_account, false), | ||
| ]; | ||
| // append other accounts at the end | ||
| accounts.extend(other_accounts); | ||
|
|
||
| Instruction { | ||
| program_id: crate::id(), | ||
| accounts, | ||
| data: [ | ||
| DlpDiscriminator::CallHandler.to_vec(), | ||
| to_vec(&args).unwrap(), | ||
| ] | ||
| .concat(), | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| use crate::args::CallHandlerArgs; | ||
| use crate::consts::EXTERNAL_CALL_HANDLER_DISCRIMINATOR; | ||
| use crate::ephemeral_balance_seeds_from_payer; | ||
| use crate::processor::utils::loaders::{ | ||
| load_initialized_validator_fees_vault, load_owned_pda, load_pda, load_signer, | ||
| }; | ||
|
|
||
| use borsh::BorshDeserialize; | ||
| use solana_program::account_info::AccountInfo; | ||
| use solana_program::entrypoint::ProgramResult; | ||
| use solana_program::instruction::{AccountMeta, Instruction}; | ||
| use solana_program::program::invoke_signed; | ||
| use solana_program::program_error::ProgramError; | ||
| use solana_program::pubkey::Pubkey; | ||
| use solana_program::{msg, system_program}; | ||
|
|
||
| pub const INVALID_ESCROW_PDA: &str = "invalid escrow pda in CallHandler"; | ||
| pub const INVALID_ESCROW_OWNER: &str = "escrow can not be delegated in CallHandler"; | ||
|
|
||
| /// Calls a handler on user specified program | ||
| /// | ||
| /// Accounts: | ||
| /// 0: `[signer]` validator | ||
| /// 1: `[]` validator fee vault to verify its registration | ||
| /// 2: `[]` destination program of an action | ||
| /// 3: `[]` escrow authority account which created escrow account | ||
| /// 4: `[writable]` non delegated escrow pda created from 3 | ||
| /// 5: `[readonly/writable]` other accounts needed for action | ||
| /// 6: `[readonly/writable]` other accounts needed for action | ||
| /// 7: ... | ||
| /// | ||
| /// Requirements: | ||
| /// | ||
| /// - escrow account initialized | ||
| /// - escrow account not delegated | ||
| /// - validator as a caller | ||
| /// | ||
| /// Steps: | ||
| /// 1. Verify that signer is a valid registered validator | ||
| /// 2. Verify escrow pda exists and not delegated | ||
| /// 3. Invoke signed on behalf of escrow pda user specified action | ||
| /// | ||
| /// Usage: | ||
| /// | ||
| /// This instruction is meant to be called via CPI with the owning program signing for the | ||
| /// delegated account. | ||
| pub fn process_call_handler( | ||
| _program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| data: &[u8], | ||
| ) -> ProgramResult { | ||
| const OTHER_ACCOUNTS_OFFSET: usize = 5; | ||
|
|
||
| if accounts.len() < OTHER_ACCOUNTS_OFFSET { | ||
| return Err(ProgramError::NotEnoughAccountKeys); | ||
| } | ||
|
|
||
| let ( | ||
| [validator, validator_fees_vault, destination_program, escrow_authority_account, escrow_account], | ||
| other_accounts, | ||
| ) = accounts.split_at(OTHER_ACCOUNTS_OFFSET) | ||
| else { | ||
| return Err(ProgramError::NotEnoughAccountKeys); | ||
| }; | ||
|
|
||
| let args = CallHandlerArgs::try_from_slice(data)?; | ||
|
|
||
| // verify account is a signer | ||
| load_signer(validator, "validator")?; | ||
| // verify signer is a registered validator | ||
| load_initialized_validator_fees_vault(validator, validator_fees_vault, true)?; | ||
| // Check if destination program is executable | ||
| if !destination_program.executable { | ||
| msg!( | ||
| "{} program is not executable: destination program", | ||
| destination_program.key | ||
| ); | ||
| return Err(ProgramError::InvalidAccountData); | ||
| } | ||
|
|
||
| // verify passed escrow_account derived from escrow authority | ||
| let escrow_seeds: &[&[u8]] = | ||
| ephemeral_balance_seeds_from_payer!(escrow_authority_account.key, args.escrow_index); | ||
| let escrow_bump = load_pda( | ||
| escrow_account, | ||
| escrow_seeds, | ||
| &crate::id(), | ||
| true, | ||
| INVALID_ESCROW_PDA, | ||
| )?; | ||
| load_owned_pda(escrow_account, &system_program::id(), INVALID_ESCROW_OWNER)?; | ||
|
|
||
| // deduce necessary accounts for CPI | ||
| let (accounts_meta, handler_accounts): (Vec<AccountMeta>, Vec<AccountInfo>) = | ||
| [escrow_authority_account, escrow_account] | ||
| .into_iter() | ||
| .chain(other_accounts) | ||
| .filter(|account| account.key != validator.key) | ||
| .map(|account| { | ||
| ( | ||
| // We enable only escrow to be a signer | ||
| AccountMeta { | ||
| pubkey: *account.key, | ||
| is_writable: account.is_writable, | ||
| is_signer: account.key == escrow_account.key, | ||
| }, | ||
| account.clone(), | ||
| ) | ||
| }) | ||
| .collect(); | ||
|
|
||
| let data = [EXTERNAL_CALL_HANDLER_DISCRIMINATOR.to_vec(), data.to_vec()].concat(); | ||
| let handler_instruction = Instruction { | ||
| program_id: *destination_program.key, | ||
| data, | ||
| accounts: accounts_meta, | ||
| }; | ||
| let bump_slice = &[escrow_bump]; | ||
| let escrow_signer_seeds = [escrow_seeds, &[bump_slice]].concat(); | ||
|
|
||
| invoke_signed( | ||
| &handler_instruction, | ||
| &handler_accounts, | ||
| &[&escrow_signer_seeds], | ||
| ) | ||
| } |
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
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.