Skip to content

Commit ad9b6ba

Browse files
feat: Add undelegation trough CPI (#1)
1 parent 34e2a77 commit ad9b6ba

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
resolver = "2"
77

88
[workspace.package]
9-
version = "0.0.1"
9+
version = "0.0.2"
1010
authors = ["Magicblock Labs <[email protected]>"]
1111
edition = "2021"
1212
license = "MIT"
@@ -17,7 +17,7 @@ readme = "./README.md"
1717
keywords = ["solana", "crypto", "delegation", "ephemeral-rollups", "magicblock"]
1818

1919
[workspace.dependencies]
20-
ephemeral-rollups-sdk-attribute-delegate = { path = "sdk/delegate", version = "=0.0.1" }
20+
ephemeral-rollups-sdk-attribute-delegate = { path = "sdk/delegate", version = "=0.0.2" }
2121

2222
## External crates
2323
borsh = "0.10.3"

sdk/src/er.rs renamed to sdk/src/ephem.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,33 @@ pub fn commit_accounts<'a, 'info>(
1212
) -> ProgramResult {
1313
let mut accounts = vec![payer];
1414
accounts.extend(account_infos.iter());
15-
let ix = create_schedule_commit_ix(magic_program, &accounts);
15+
let ix = create_schedule_commit_ix(magic_program, &accounts, false);
16+
invoke(&ix, &accounts.into_iter().cloned().collect::<Vec<_>>())
17+
}
18+
19+
/// CPI to trigger a commit and undelegate one or more accounts in the ER
20+
#[inline(always)]
21+
pub fn commit_and_undelegate_accounts<'a, 'info>(
22+
payer: &'a AccountInfo<'info>,
23+
account_infos: Vec<&'a AccountInfo<'info>>,
24+
magic_program: &'a AccountInfo<'info>,
25+
) -> ProgramResult {
26+
let mut accounts = vec![payer];
27+
accounts.extend(account_infos.iter());
28+
let ix = create_schedule_commit_ix(magic_program, &accounts, true);
1629
invoke(&ix, &accounts.into_iter().cloned().collect::<Vec<_>>())
1730
}
1831

1932
pub fn create_schedule_commit_ix<'a, 'info>(
2033
magic_program: &'a AccountInfo<'info>,
2134
account_infos: &[&'a AccountInfo<'info>],
35+
allow_undelegation: bool,
2236
) -> Instruction {
23-
let instruction_data = vec![1, 0, 0, 0];
37+
let instruction_data = if allow_undelegation {
38+
vec![2, 0, 0, 0]
39+
} else {
40+
vec![1, 0, 0, 0]
41+
};
2442
let account_metas = account_infos
2543
.iter()
2644
.map(|x| AccountMeta {
@@ -30,4 +48,4 @@ pub fn create_schedule_commit_ix<'a, 'info>(
3048
})
3149
.collect::<Vec<AccountMeta>>();
3250
Instruction::new_with_bytes(*magic_program.key, &instruction_data, account_metas)
33-
}
51+
}

sdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod anchor;
66
pub mod consts;
77
pub mod cpi;
88
pub mod delegate_args;
9-
pub mod er;
9+
pub mod ephem;
1010
pub mod pda;
1111
pub mod types;
1212
pub mod utils;

sdk/ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@magicblock-labs/ephemeral-rollups-sdk",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"author": "MagicBlock Labs",
55
"license": "MIT",
66
"publishConfig": {

0 commit comments

Comments
 (0)