-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add Magic Context * fix: Fix commit CPI * chore: Refactoring
- Loading branch information
1 parent
bf9fbc5
commit 07a2f4a
Showing
6 changed files
with
42 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ members = [ | |
resolver = "2" | ||
|
||
[workspace.package] | ||
version = "0.0.4" | ||
version = "0.0.5" | ||
authors = ["Magicblock Labs <[email protected]>"] | ||
edition = "2021" | ||
license = "MIT" | ||
|
@@ -17,7 +17,7 @@ readme = "./README.md" | |
keywords = ["solana", "crypto", "delegation", "ephemeral-rollups", "magicblock"] | ||
|
||
[workspace.dependencies] | ||
ephemeral-rollups-sdk-attribute-delegate = { path = "sdk/delegate", version = "=0.0.4" } | ||
ephemeral-rollups-sdk-attribute-delegate = { path = "sdk/delegate", version = "=0.0.5" } | ||
|
||
## External crates | ||
borsh = "0.10.3" | ||
|
This file contains 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 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,51 +1,66 @@ | ||
use solana_program::account_info::AccountInfo; | ||
use solana_program::entrypoint::ProgramResult; | ||
use solana_program::instruction::{AccountMeta, Instruction}; | ||
use solana_program::msg; | ||
use solana_program::program::invoke; | ||
|
||
/// CPI to trigger a commit for one or more accounts in the ER | ||
#[inline(always)] | ||
pub fn commit_accounts<'a, 'info>( | ||
payer: &'a AccountInfo<'info>, | ||
account_infos: Vec<&'a AccountInfo<'info>>, | ||
magic_context: &'a AccountInfo<'info>, | ||
magic_program: &'a AccountInfo<'info>, | ||
) -> ProgramResult { | ||
let mut accounts = vec![payer]; | ||
accounts.extend(account_infos.iter()); | ||
let ix = create_schedule_commit_ix(magic_program, &accounts, false); | ||
invoke(&ix, &accounts.into_iter().cloned().collect::<Vec<_>>()) | ||
let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, false); | ||
let mut all_accounts = vec![payer.clone(), magic_context.clone()]; | ||
all_accounts.extend(account_infos.into_iter().cloned()); | ||
invoke(&ix, &all_accounts) | ||
} | ||
|
||
/// CPI to trigger a commit and undelegate one or more accounts in the ER | ||
#[inline(always)] | ||
pub fn commit_and_undelegate_accounts<'a, 'info>( | ||
payer: &'a AccountInfo<'info>, | ||
account_infos: Vec<&'a AccountInfo<'info>>, | ||
magic_context: &'a AccountInfo<'info>, | ||
magic_program: &'a AccountInfo<'info>, | ||
) -> ProgramResult { | ||
let mut accounts = vec![payer]; | ||
accounts.extend(account_infos.iter()); | ||
let ix = create_schedule_commit_ix(magic_program, &accounts, true); | ||
invoke(&ix, &accounts.into_iter().cloned().collect::<Vec<_>>()) | ||
let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, true); | ||
let mut all_accounts = vec![payer.clone(), magic_context.clone()]; | ||
all_accounts.extend(account_infos.into_iter().cloned()); | ||
invoke(&ix, &all_accounts) | ||
} | ||
|
||
pub fn create_schedule_commit_ix<'a, 'info>( | ||
magic_program: &'a AccountInfo<'info>, | ||
payer: &'a AccountInfo<'info>, | ||
account_infos: &[&'a AccountInfo<'info>], | ||
magic_context: &'a AccountInfo<'info>, | ||
magic_program: &'a AccountInfo<'info>, | ||
allow_undelegation: bool, | ||
) -> Instruction { | ||
let instruction_data = if allow_undelegation { | ||
vec![2, 0, 0, 0] | ||
} else { | ||
vec![1, 0, 0, 0] | ||
}; | ||
let account_metas = account_infos | ||
.iter() | ||
.map(|x| AccountMeta { | ||
pubkey: *x.key, | ||
is_signer: x.is_signer, | ||
is_writable: x.is_writable, | ||
}) | ||
.collect::<Vec<AccountMeta>>(); | ||
let mut account_metas = vec![ | ||
AccountMeta { | ||
pubkey: *payer.key, | ||
is_signer: true, | ||
is_writable: true, | ||
}, | ||
AccountMeta { | ||
pubkey: *magic_context.key, | ||
is_signer: false, | ||
is_writable: true, | ||
}, | ||
]; | ||
account_metas.extend(account_infos.iter().map(|x| AccountMeta { | ||
pubkey: *x.key, | ||
is_signer: x.is_signer, | ||
is_writable: x.is_writable, | ||
})); | ||
msg!("Keys: {:?}", account_metas); | ||
Instruction::new_with_bytes(*magic_program.key, &instruction_data, account_metas) | ||
} |
This file contains 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 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