Skip to content

Commit a158b34

Browse files
authored
Merge pull request #42 from magicblock-labs/feat/base-layer-ix
Base layer ix
2 parents 61742dc + cd8c522 commit a158b34

File tree

11 files changed

+390
-197
lines changed

11 files changed

+390
-197
lines changed

rust/Cargo.lock

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

rust/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ ephemeral-rollups-sdk-attribute-ephemeral = { path = "ephemeral", version = "=0.
2727
ephemeral-rollups-sdk-attribute-delegate = { path = "delegate", version = "=0.2.12" }
2828
ephemeral-rollups-sdk-attribute-commit = { path = "commit-attribute", version = "=0.2.12" }
2929

30+
# Magicblock
31+
magicblock-delegation-program = { version = "1.1.1", features = ["no-entrypoint"] }
32+
magicblock-magic-program-api = "0.1.7"
33+
3034
## External crates
3135
anchor-lang = { version = ">=0.28.0" }
3236
proc-macro2 = "1.0"

rust/delegate/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn delegate(_attr: TokenStream, item: TokenStream) -> TokenStream {
6464
new_fields.push(quote! {
6565
/// CHECK: The buffer account
6666
#[account(
67-
mut, seeds = [ephemeral_rollups_sdk::consts::BUFFER, #field_name.key().as_ref()],
67+
mut, seeds = [ephemeral_rollups_sdk::pda::DELEGATE_BUFFER_TAG, #field_name.key().as_ref()],
6868
bump, seeds::program = crate::id()
6969
)]
7070
pub #buffer_field: AccountInfo<'info>,
@@ -73,7 +73,7 @@ pub fn delegate(_attr: TokenStream, item: TokenStream) -> TokenStream {
7373
new_fields.push(quote! {
7474
/// CHECK: The delegation record account
7575
#[account(
76-
mut, seeds = [ephemeral_rollups_sdk::consts::DELEGATION_RECORD, #field_name.key().as_ref()],
76+
mut, seeds = [ephemeral_rollups_sdk::pda::DELEGATION_RECORD_TAG, #field_name.key().as_ref()],
7777
bump, seeds::program = delegation_program.key()
7878
)]
7979
pub #delegation_record_field: AccountInfo<'info>,
@@ -82,7 +82,7 @@ pub fn delegate(_attr: TokenStream, item: TokenStream) -> TokenStream {
8282
new_fields.push(quote! {
8383
/// CHECK: The delegation metadata account
8484
#[account(
85-
mut, seeds = [ephemeral_rollups_sdk::consts::DELEGATION_METADATA, #field_name.key().as_ref()],
85+
mut, seeds = [ephemeral_rollups_sdk::pda::DELEGATION_METADATA_TAG, #field_name.key().as_ref()],
8686
bump, seeds::program = delegation_program.key()
8787
)]
8888
pub #delegation_metadata_field: AccountInfo<'info>,

rust/pinocchio/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct DelegateAccountArgs<'a> {
1717
pub validator: Option<Pubkey>,
1818
}
1919

20-
impl<'a> Default for DelegateAccountArgs<'a> {
20+
impl Default for DelegateAccountArgs<'_> {
2121
fn default() -> Self {
2222
DelegateAccountArgs {
2323
commit_frequency_ms: u32::MAX,
@@ -27,7 +27,7 @@ impl<'a> Default for DelegateAccountArgs<'a> {
2727
}
2828
}
2929

30-
impl<'a> DelegateAccountArgs<'a> {
30+
impl DelegateAccountArgs<'_> {
3131
pub fn try_to_slice<'b>(&self, data: &'b mut [u8]) -> Result<&'b [u8], ProgramError> {
3232
if self.seeds.len() >= MAX_SEEDS {
3333
return Err(ProgramError::InvalidArgument);

rust/sdk/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ ephemeral-rollups-sdk-attribute-delegate = { workspace = true }
2222
ephemeral-rollups-sdk-attribute-ephemeral = { workspace = true }
2323
ephemeral-rollups-sdk-attribute-commit = { workspace = true }
2424
solana-program = { workspace = true }
25+
magicblock-magic-program-api = { workspace = true }
26+
magicblock-delegation-program = { workspace = true, features = ["no-entrypoint"] }
27+
28+
[dev-dependencies]
29+
bincode = "1.3.3"

rust/sdk/src/consts.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
// NOTE: this should go into a core package that both the sdk + the program can depend on
2-
use solana_program::pubkey;
32
use solana_program::pubkey::Pubkey;
43

5-
/// The delegation program ID.
6-
pub const DELEGATION_PROGRAM_ID: Pubkey = pubkey!("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh");
4+
pub use dlp::consts::*;
5+
use magicblock_magic_program_api::MAGIC_CONTEXT_PUBKEY;
76

87
/// The magic program ID.
9-
pub const MAGIC_PROGRAM_ID: Pubkey = pubkey!("Magic11111111111111111111111111111111111111");
8+
pub const MAGIC_PROGRAM_ID: Pubkey = magicblock_magic_program_api::ID;
109

1110
/// The magic context ID.
12-
pub const MAGIC_CONTEXT_ID: Pubkey = pubkey!("MagicContext1111111111111111111111111111111");
13-
14-
///
15-
/// The seed of the authority account PDA.
16-
pub const DELEGATION_RECORD: &[u8] = b"delegation";
17-
18-
/// The account to store the delegated account seeds.
19-
pub const DELEGATION_METADATA: &[u8] = b"delegation-metadata";
20-
21-
/// The seed of the buffer account PDA.
22-
pub const BUFFER: &[u8] = b"buffer";
23-
24-
/// The seed of the committed state PDA.
25-
pub const COMMIT_STATE: &[u8] = b"state-diff";
26-
27-
/// The seed of a commit state record PDA.
28-
pub const COMMIT_RECORD: &[u8] = b"commit-state-record";
29-
30-
/// The discriminator for the external undelegate instruction.
31-
pub const EXTERNAL_UNDELEGATE_DISCRIMINATOR: [u8; 8] = [196, 28, 41, 206, 48, 37, 51, 167];
11+
pub const MAGIC_CONTEXT_ID: Pubkey = MAGIC_CONTEXT_PUBKEY;

rust/sdk/src/cpi.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::consts::BUFFER;
21
use crate::types::DelegateAccountArgs;
32
use crate::utils::{close_pda_with_system_transfer, create_pda, seeds_with_bump};
43
use borsh::BorshSerialize;
4+
use dlp::consts::DELEGATION_PROGRAM_ID;
5+
use dlp::delegate_buffer_seeds_from_delegated_account;
56
use solana_program::account_info::AccountInfo;
67
use solana_program::entrypoint::ProgramResult;
78
use solana_program::instruction::{AccountMeta, Instruction};
@@ -42,7 +43,7 @@ pub fn delegate_account<'a, 'info>(
4243
pda_seeds: &[&[u8]],
4344
config: DelegateConfig,
4445
) -> ProgramResult {
45-
let buffer_seeds: &[&[u8]] = &[BUFFER, accounts.pda.key.as_ref()];
46+
let buffer_seeds: &[&[u8]] = delegate_buffer_seeds_from_delegated_account!(accounts.pda.key);
4647

4748
let (_, delegate_account_bump) =
4849
Pubkey::find_program_address(pda_seeds, accounts.owner_program.key);
@@ -138,6 +139,9 @@ pub fn undelegate_account<'a, 'info>(
138139
if !buffer.is_signer {
139140
return Err(ProgramError::MissingRequiredSignature);
140141
}
142+
if buffer.owner != &DELEGATION_PROGRAM_ID {
143+
return Err(ProgramError::InvalidAccountOwner);
144+
}
141145

142146
let account_seeds: Vec<&[u8]> = account_signer_seeds.iter().map(|v| v.as_slice()).collect();
143147

rust/sdk/src/delegate_args.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
use dlp::pda::{
2+
delegate_buffer_pda_from_delegated_account_and_owner_program,
3+
delegation_metadata_pda_from_delegated_account, delegation_record_pda_from_delegated_account,
4+
};
15
use solana_program::{instruction::AccountMeta, pubkey::Pubkey, system_program};
26

3-
use crate::{
4-
consts::DELEGATION_PROGRAM_ID,
5-
pda::{
6-
delegate_buffer_pda_from_delegated_account_and_owner_program,
7-
delegation_metadata_pda_from_delegated_account,
8-
delegation_record_pda_from_delegated_account,
9-
},
10-
};
7+
use crate::consts::DELEGATION_PROGRAM_ID;
118

129
#[derive(Debug, Clone, PartialEq, Eq)]
1310
pub struct DelegateAccounts {

0 commit comments

Comments
 (0)