Skip to content

Commit 28afe45

Browse files
Feat/sdk compatibility (#13)
* chore: improve sdk compatibility * chore: refactor
1 parent 9ec69e7 commit 28afe45

File tree

10 files changed

+511
-272
lines changed

10 files changed

+511
-272
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "magic-domain-program"
33
description = "Domain registration program for Ephemeral Rollups"
4-
version = "0.0.1"
4+
version = "0.1.0"
55
authors = ["Magicblock Labs <dev@magicblock.gg>"]
66
edition = "2021"
77
license = "MIT"
@@ -17,21 +17,24 @@ name = "mdp"
1717

1818
[dependencies]
1919
# solana
20-
solana-program = { version = "^2, <3" }
21-
security-txt = { version = "1.1.1", package = "solana-security-txt", optional = true }
20+
solana-program = { version = ">=1.6" }
21+
solana-system-interface = { version = ">=1", features = ["bincode"]}
22+
security-txt = { version = ">=1", package = "solana-security-txt", optional = true }
2223

2324
# serialization/deserialization
24-
borsh = { version = "1", features = [ "derive" ] }
25-
bytemuck_derive = "<=1.8"
25+
borsh = { version = ">=1", features = [ "derive" ] }
26+
bytemuck_derive = ">=1"
2627

2728
[dev-dependencies]
28-
program-test = { package = "solana-program-test", version = "^2, <3" }
29-
sdk = { package = "solana-sdk", version = "^2, <3" }
30-
tokio = { version = "1.0", features = [ "macros", "rt" ] }
29+
solana-sdk = { version = ">=1.6" }
30+
solana-program-test = { version = ">=1.6" }
31+
tokio = { version = ">=1", features = [ "macros", "rt" ] }
3132

3233
[features]
3334
entrypoint = ["security-txt"]
3435
default = ["entrypoint"]
36+
disable-realloc = []
37+
modular-sdk = []
3538

3639

3740

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod state;
1010
pub mod entrypoint;
1111
#[cfg(feature = "entrypoint")]
1212
mod processors;
13+
mod solana_compact;
1314

1415
declare_id!("DmnRGfyyftzacFb1XadYhWF6vWqXwtQk5tbr6XgR3BA1");
1516

src/processors/register.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use borsh::BorshSerialize;
2+
use solana_compact::solana::system_instruction::create_account;
23
use solana_program::msg;
34
use solana_program::{
45
account_info::{next_account_info, AccountInfo},
56
program::invoke_signed,
67
program_error::ProgramError,
78
rent::Rent,
8-
system_instruction::create_account,
99
sysvar::Sysvar,
1010
};
1111

12-
use crate::{state::record::ErRecord, ID};
12+
use crate::{solana_compact, state::record::ErRecord, ID};
1313

1414
/// Registers ER node in domain registry, by creating a record (PDA) with all the relevant ER information
1515
pub fn process_registration<'a>(

src/processors/sync.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use solana_program::{
44
program::invoke,
55
program_error::ProgramError,
66
rent::Rent,
7-
system_instruction,
87
sysvar::Sysvar,
98
};
109

10+
use crate::solana_compact::resize;
11+
use crate::solana_compact::solana::system_instruction;
1112
use crate::{instructions::sync::SyncInstruction, state::record::ErRecord, ID};
1213

1314
/// Synchronize updated ER information with existing domain registry record
@@ -76,7 +77,7 @@ pub fn process_sync_record<'a>(
7677
**pda_account.try_borrow_mut_lamports()? -= rent_old - rent_new;
7778
**payer.try_borrow_mut_lamports()? += rent_old - rent_new;
7879
}
79-
pda_account.realloc(new_size, false)?;
80+
resize(pda_account, new_size)?;
8081
data = pda_account.try_borrow_mut_data()?;
8182
record.serialize(&mut *data)?;
8283

src/processors/unregister.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use solana_program::{
66
program_error::ProgramError,
77
};
88

9+
use crate::solana_compact::resize;
910
use crate::state::record::ErRecord;
1011
use crate::ID;
1112

@@ -65,7 +66,7 @@ pub fn process_unregistration<'a>(
6566
**pda_account.try_borrow_mut_lamports()? = 0;
6667

6768
pda_account.assign(system_program.key);
68-
pda_account.realloc(0, false)?;
69+
resize(pda_account, 0)?;
6970

7071
Ok(())
7172
}

src/solana_compact.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use solana_program::account_info::AccountInfo;
2+
use solana_program::entrypoint::ProgramResult;
3+
4+
#[inline(always)]
5+
pub fn resize(target_account: &AccountInfo, new_len: usize) -> ProgramResult {
6+
#[cfg(not(feature = "disable-realloc"))]
7+
{
8+
#[allow(deprecated)]
9+
target_account.realloc(new_len, false)
10+
}
11+
12+
#[cfg(feature = "disable-realloc")]
13+
{
14+
target_account.resize(new_len)
15+
}
16+
}
17+
18+
#[cfg(not(feature = "modular-sdk"))]
19+
pub mod solana {
20+
pub use solana_program::system_instruction;
21+
}
22+
23+
#[cfg(feature = "modular-sdk")]
24+
pub mod solana {
25+
pub use solana_system_interface::instruction as system_instruction;
26+
}

tests/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use mdp::{
77
version::v0::RecordV0,
88
},
99
};
10-
use program_test::{BanksClient, BanksClientError, ProgramTest};
11-
use sdk::{
10+
use solana_program_test::{BanksClient, BanksClientError, ProgramTest};
11+
use solana_sdk::{
1212
account::Account,
1313
instruction::{AccountMeta, Instruction as SolanaInstruction},
1414
native_token::LAMPORTS_PER_SOL,

tests/test_registration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use mdp::state::{
44
features::{Feature, FeaturesSet},
55
record::ErRecord,
66
};
7-
use sdk::{account::Account, signer::Signer};
7+
use solana_sdk::{account::Account, signer::Signer};
88

99
pub mod common;
1010

tests/test_sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use borsh::BorshDeserialize;
22
use common::TestEnv;
33
use mdp::state::{record::ErRecord, status::ErStatus};
4-
use sdk::account::Account;
4+
use solana_sdk::account::Account;
55

66
pub mod common;
77

0 commit comments

Comments
 (0)