Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ keywords = ["solana", "crypto", "delegation", "ephemeral-rollups", "magicblock"]
delegation-sdk-attribute-delegate = { path = "sdk/delegate", version = "0.1.0" }

## External crates
solana-program = "^1.16"
borsh = "0.10.3"
paste = "^1.0"
solana-program = "^1.16"

[package]
name = "delegation-program"
Expand Down Expand Up @@ -46,8 +47,8 @@ solana-program = { workspace = true }
borsh = { workspace = true }
bytemuck = "^1.14.3"
num_enum = "^0.7.2"
paste = { workspace = true }
thiserror = "^1.0.57"
paste = "^1.0"
solana-security-txt = { version = "1.1.1", optional = true }

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
solana-program = { workspace = true }
borsh = { workspace = true }
delegation-sdk-attribute-delegate = { workspace = true }
delegation-sdk-attribute-delegate = { workspace = true }
paste = { workspace = true }
solana-program = { workspace = true }
2 changes: 1 addition & 1 deletion sdk/delegate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ edition = { workspace = true }
proc-macro = true

[dependencies]
proc-macro2 = "1.0"
syn = { version = "1.0.60", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
22 changes: 19 additions & 3 deletions sdk/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
// 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 seed of the buffer account PDA.
pub const BUFFER: &[u8] = b"buffer";

/// The delegation program ID.
pub const DELEGATION_PROGRAM_ID: Pubkey = pubkey!("DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh");

/// The magic program ID.
pub const MAGIC_PROGRAM_ID: Pubkey = pubkey!("Magic11111111111111111111111111111111111111");
///
/// 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];
63 changes: 63 additions & 0 deletions sdk/src/delegate_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use solana_program::{instruction::AccountMeta, pubkey::Pubkey, system_program};

use crate::{
consts::{BUFFER, DELEGATION_PROGRAM_ID},
pda::{delegation_metadata_pda_from_pubkey, delegation_record_pda_from_pubkey},
};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DelegateAccounts {
pub delegate_account: Pubkey,
pub buffer: Pubkey,
pub delegation_record: Pubkey,
pub delegation_metadata: Pubkey,
pub owner_program: Pubkey,
pub delegation_program: Pubkey,
pub system_program: Pubkey,
}

impl DelegateAccounts {
pub fn new(delegate_account: Pubkey, owner_program: Pubkey) -> Self {
let buffer =
Pubkey::find_program_address(&[BUFFER, &delegate_account.to_bytes()], &owner_program);
let delegation_record = delegation_record_pda_from_pubkey(&delegate_account);
let delegation_metadata = delegation_metadata_pda_from_pubkey(&delegate_account);

Self {
delegate_account,
buffer: buffer.0,
delegation_record,
delegation_metadata,
owner_program,
delegation_program: DELEGATION_PROGRAM_ID,
system_program: system_program::id(),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DelegateAccountMetas {
pub payer: AccountMeta,
pub delegate_account: AccountMeta,
pub owner_program: AccountMeta,
pub buffer: AccountMeta,
pub delegation_record: AccountMeta,
pub delegation_metadata: AccountMeta,
pub delegation_program: AccountMeta,
pub system_program: AccountMeta,
}

impl From<DelegateAccounts> for DelegateAccountMetas {
fn from(accounts: DelegateAccounts) -> Self {
Self {
payer: AccountMeta::new_readonly(accounts.delegate_account, false),
delegate_account: AccountMeta::new(accounts.delegate_account, false),
owner_program: AccountMeta::new_readonly(accounts.owner_program, false),
buffer: AccountMeta::new(accounts.buffer, false),
delegation_record: AccountMeta::new(accounts.delegation_record, false),
delegation_metadata: AccountMeta::new(accounts.delegation_metadata, false),
delegation_program: AccountMeta::new_readonly(accounts.delegation_program, false),
system_program: AccountMeta::new_readonly(accounts.system_program, false),
}
}
}
8 changes: 5 additions & 3 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::consts::BUFFER;
use crate::types::DelegateAccountArgs;
use crate::utils::{close_pda, create_pda, seeds_with_bump};
pub mod consts;
pub mod delegate_args;
pub mod pda;
pub mod types;
pub mod utils;

Expand Down Expand Up @@ -132,12 +134,12 @@ pub fn undelegate_account<'a, 'info>(

// Re-create the original PDA
create_pda(
&delegated_account,
delegated_account,
owner_program,
buffer.data_len(),
account_signer_seeds,
&system_program,
&payer,
system_program,
payer,
)?;

let mut data = delegated_account.try_borrow_mut_data()?;
Expand Down
Loading