Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ephemeral-rollups-sdk-attribute-delegate = { path = "delegate", version = "=0.2.
ephemeral-rollups-sdk-attribute-commit = { path = "commit-attribute", version = "=0.2.7" }
magic-domain-program = { version = "0.0.1" }

# Magicblock
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "00d720", features = ["no-entrypoint"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't depend on github in order to publish the crate on crates.io (we could publish the other crate though)

magicblock-core = { git = "https://github.com/magicblock-labs/magicblock-validator.git", rev = "f08144" }

## External crates
anchor-lang = { version = ">=0.28.0" }
proc-macro2 = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions rust/pinocchio/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct DelegateAccountArgs<'a> {
pub validator: Option<Pubkey>,
}

impl<'a> Default for DelegateAccountArgs<'a> {
impl Default for DelegateAccountArgs<'_> {
fn default() -> Self {
DelegateAccountArgs {
commit_frequency_ms: u32::MAX,
Expand All @@ -27,7 +27,7 @@ impl<'a> Default for DelegateAccountArgs<'a> {
}
}

impl<'a> DelegateAccountArgs<'a> {
impl DelegateAccountArgs<'_> {
pub fn try_to_slice<'b>(&self, data: &'b mut [u8]) -> Result<&'b [u8], ProgramError> {
if self.seeds.len() >= MAX_SEEDS {
return Err(ProgramError::InvalidArgument);
Expand Down
5 changes: 5 additions & 0 deletions rust/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ ephemeral-rollups-sdk-attribute-delegate = { workspace = true }
ephemeral-rollups-sdk-attribute-ephemeral = { workspace = true }
ephemeral-rollups-sdk-attribute-commit = { workspace = true }
solana-program = { workspace = true }
magicblock-core = { workspace = true }
magicblock-delegation-program = { workspace = true, features = ["no-entrypoint"] }

[dev-dependencies]
bincode = "1.3.3"
28 changes: 4 additions & 24 deletions rust/sdk/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
// NOTE: this should go into a core package that both the sdk + the program can depend on
use solana_program::pubkey;
use solana_program::pubkey::Pubkey;

/// The delegation program ID.
pub const DELEGATION_PROGRAM_ID: Pubkey = pubkey!("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh");
pub use dlp::consts::*;
use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY;

/// The magic program ID.
pub const MAGIC_PROGRAM_ID: Pubkey = pubkey!("Magic11111111111111111111111111111111111111");
pub const MAGIC_PROGRAM_ID: Pubkey = magicblock_core::magic_program::ID;

/// The magic context ID.
pub const MAGIC_CONTEXT_ID: Pubkey = pubkey!("MagicContext1111111111111111111111111111111");

///
/// The seed of the authority account PDA.
pub const DELEGATION_RECORD: &[u8] = b"delegation";

/// The account to store the delegated account seeds.
pub const DELEGATION_METADATA: &[u8] = b"delegation-metadata";

/// The seed of the buffer account PDA.
pub const BUFFER: &[u8] = b"buffer";

/// The seed of the committed state PDA.
pub const COMMIT_STATE: &[u8] = b"state-diff";

/// The seed of a commit state record PDA.
pub const COMMIT_RECORD: &[u8] = b"commit-state-record";

/// The discriminator for the external undelegate instruction.
pub const EXTERNAL_UNDELEGATE_DISCRIMINATOR: [u8; 8] = [196, 28, 41, 206, 48, 37, 51, 167];
pub const MAGIC_CONTEXT_ID: Pubkey = MAGIC_CONTEXT_PUBKEY;
9 changes: 6 additions & 3 deletions rust/sdk/src/cpi.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use borsh::BorshSerialize;
use dlp::delegate_buffer_seeds_from_delegated_account;
use solana_program::account_info::AccountInfo;
use solana_program::entrypoint::ProgramResult;
use solana_program::instruction::{AccountMeta, Instruction};
use solana_program::program_error::ProgramError;
use solana_program::pubkey::Pubkey;

// TODO: import from the delegation program crate once open-sourced
use crate::consts::BUFFER;
use crate::consts::DELEGATION_PROGRAM_ID;
use crate::types::DelegateAccountArgs;
use crate::utils::{close_pda_with_system_transfer, create_pda, seeds_with_bump};

Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn delegate_account<'a, 'info>(
pda_seeds: &[&[u8]],
config: DelegateConfig,
) -> ProgramResult {
let buffer_seeds: &[&[u8]] = &[BUFFER, accounts.pda.key.as_ref()];
let buffer_seeds: &[&[u8]] = delegate_buffer_seeds_from_delegated_account!(accounts.pda.key);

let (_, delegate_account_bump) =
Pubkey::find_program_address(pda_seeds, accounts.owner_program.key);
Expand Down Expand Up @@ -123,6 +123,9 @@ pub fn undelegate_account<'a, 'info>(
if !buffer.is_signer {
return Err(ProgramError::MissingRequiredSignature);
}
if buffer.owner != &DELEGATION_PROGRAM_ID {
return Err(ProgramError::InvalidAccountOwner);
}

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

Expand Down
13 changes: 5 additions & 8 deletions rust/sdk/src/delegate_args.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use dlp::pda::{
delegate_buffer_pda_from_delegated_account_and_owner_program,
delegation_metadata_pda_from_delegated_account, delegation_record_pda_from_delegated_account,
};
use solana_program::{instruction::AccountMeta, pubkey::Pubkey, system_program};

use crate::{
consts::DELEGATION_PROGRAM_ID,
pda::{
delegate_buffer_pda_from_delegated_account_and_owner_program,
delegation_metadata_pda_from_delegated_account,
delegation_record_pda_from_delegated_account,
},
};
use crate::consts::DELEGATION_PROGRAM_ID;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DelegateAccounts {
Expand Down
Loading