diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 8ce8eea..f3ba45c 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -17,6 +17,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom 0.2.15", + "once_cell", + "version_check", +] + [[package]] name = "ahash" version = "0.8.11" @@ -123,7 +134,7 @@ dependencies = [ "anchor-syn", "anyhow", "bs58", - "heck", + "heck 0.3.3", "proc-macro2", "quote", "serde_json", @@ -196,7 +207,7 @@ checksum = "32e8599d21995f68e296265aa5ab0c3cef582fd58afec014d01bd0bce18a4418" dependencies = [ "anchor-lang-idl-spec", "anyhow", - "heck", + "heck 0.3.3", "serde", "serde_json", "sha2 0.10.8", @@ -220,7 +231,7 @@ checksum = "564685b759db12a2424d1b2688cfdf0fec26a023813bc461274754fb0e5d97b0" dependencies = [ "anyhow", "bs58", - "heck", + "heck 0.3.3", "proc-macro2", "quote", "serde", @@ -470,6 +481,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "blake3" version = "1.6.1" @@ -616,6 +639,28 @@ dependencies = [ "serde", ] +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta 0.1.4", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "bytemuck" version = "1.22.0" @@ -1065,7 +1110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6503af7917fea18ffef8f7e8553fb8dff89e2e6837e94e09dd7fb069c82d62c" dependencies = [ "bytes", - "rkyv", + "rkyv 0.8.10", "serde", "simdutf8", ] @@ -1137,6 +1182,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.31" @@ -1318,13 +1369,22 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] + [[package]] name = "hashbrown" version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash", + "ahash 0.8.11", ] [[package]] @@ -1342,6 +1402,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1929,8 +1995,6 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0872a77d99b56077a799be5d3ebe8f01d03ab83c026daaf3772bdf312b347cf6" dependencies = [ "bincode", "borsh 1.5.7", @@ -1941,17 +2005,17 @@ dependencies = [ "pinocchio-log 0.5.1", "pinocchio-pubkey 0.3.0", "pinocchio-system 0.3.0", + "rkyv 0.7.45", "solana-curve25519", "solana-program", "solana-security-txt", + "strum", "thiserror 1.0.69", ] [[package]] name = "magicblock-magic-program-api" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349b26eb6d819328dad699a6c9a26234548d366d9a30e7edf0d296180188ee27" +version = "0.2.3" dependencies = [ "bincode", "serde", @@ -2379,13 +2443,33 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive 0.1.4", +] + [[package]] name = "ptr_meta" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe9e76f66d3f9606f44e45598d155cb13ecf09f4a28199e48daf8c8fc937ea90" dependencies = [ - "ptr_meta_derive", + "ptr_meta_derive 0.3.0", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -2417,13 +2501,19 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rancor" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caf5f7161924b9d1cea0e4cabc97c372cea92b5f927fc13c6bca67157a0ad947" dependencies = [ - "ptr_meta", + "ptr_meta 0.3.0", ] [[package]] @@ -2555,6 +2645,15 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + [[package]] name = "rend" version = "0.5.2" @@ -2678,6 +2777,24 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rkyv" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta 0.1.4", + "rend 0.4.2", + "rkyv_derive 0.7.45", + "seahash", + "tinyvec", + "uuid", +] + [[package]] name = "rkyv" version = "0.8.10" @@ -2688,14 +2805,25 @@ dependencies = [ "hashbrown 0.15.2", "indexmap", "munge", - "ptr_meta", + "ptr_meta 0.3.0", "rancor", - "rend", - "rkyv_derive", + "rend 0.5.2", + "rkyv_derive 0.8.10", "tinyvec", "uuid", ] +[[package]] +name = "rkyv_derive" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "rkyv_derive" version = "0.8.10" @@ -2857,6 +2985,12 @@ version = "3.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "584e070911c7017da6cb2eb0788d09f43d789029b5877d3e5ecc8acf86ceee21" +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "security-framework" version = "2.11.1" @@ -3445,7 +3579,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e1d3b52b4a014efeaaab67f14e40af3972a4be61c523d612860db8e3145529" dependencies = [ - "ahash", + "ahash 0.8.11", "lazy_static", "solana-epoch-schedule", "solana-hash", @@ -4701,6 +4835,27 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.100", +] + [[package]] name = "subtle" version = "2.6.1" @@ -4797,6 +4952,12 @@ dependencies = [ "libc", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "task-local-extensions" version = "0.1.4" @@ -5608,6 +5769,15 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "yoke" version = "0.7.5" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 538cfd5..d0654c4 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -28,8 +28,8 @@ ephemeral-rollups-sdk-attribute-delegate = { path = "delegate", version = "=0.3. ephemeral-rollups-sdk-attribute-commit = { path = "commit-attribute", version = "=0.3.7" } # Magicblock -magicblock-delegation-program = { version = "1.1.2", features = ["no-entrypoint"] } -magicblock-magic-program-api = { version = "0.2.1" } +magicblock-delegation-program = { path = "../../delegation-program", features = ["no-entrypoint"] } +magicblock-magic-program-api = { path = "../../magicblock-validator/magicblock-magic-program-api" } ## External crates anchor-lang = { version = ">=0.28.0" } diff --git a/rust/sdk/src/ephem.rs b/rust/sdk/src/ephem.rs index d3e1f62..791eada 100644 --- a/rust/sdk/src/ephem.rs +++ b/rust/sdk/src/ephem.rs @@ -243,6 +243,11 @@ impl<'info> CallHandler<'info> { } } +pub enum CommitPolicy { + UseDiff, + UseFullBytes +} + /// CPI to trigger a commit for one or more accounts in the ER #[inline(always)] pub fn commit_accounts<'a, 'info>( @@ -251,7 +256,21 @@ pub fn commit_accounts<'a, 'info>( magic_context: &'a AccountInfo<'info>, magic_program: &'a AccountInfo<'info>, ) -> ProgramResult { - let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, false); + let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, false, CommitPolicy::UseFullBytes); + let mut all_accounts = vec![payer.clone(), magic_context.clone()]; + all_accounts.extend(account_infos.into_iter().cloned()); + invoke(&ix, &all_accounts) +} + +/// CPI to trigger a commit and undelegate one or more accounts in the ER +#[inline(always)] +pub fn commit_diff_and_undelegate_accounts<'a, 'info>( + payer: &'a AccountInfo<'info>, + account_infos: Vec<&'a AccountInfo<'info>>, + magic_context: &'a AccountInfo<'info>, + magic_program: &'a AccountInfo<'info>, +) -> ProgramResult { + let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, true, CommitPolicy::UseDiff); let mut all_accounts = vec![payer.clone(), magic_context.clone()]; all_accounts.extend(account_infos.into_iter().cloned()); invoke(&ix, &all_accounts) @@ -265,7 +284,7 @@ pub fn commit_and_undelegate_accounts<'a, 'info>( magic_context: &'a AccountInfo<'info>, magic_program: &'a AccountInfo<'info>, ) -> ProgramResult { - let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, true); + let ix = create_schedule_commit_ix(payer, &account_infos, magic_context, magic_program, true, CommitPolicy::UseFullBytes); let mut all_accounts = vec![payer.clone(), magic_context.clone()]; all_accounts.extend(account_infos.into_iter().cloned()); invoke(&ix, &all_accounts) @@ -277,10 +296,19 @@ pub fn create_schedule_commit_ix<'a, 'info>( magic_context: &'a AccountInfo<'info>, magic_program: &'a AccountInfo<'info>, allow_undelegation: bool, + commit_policy: CommitPolicy ) -> Instruction { let instruction = if allow_undelegation { - MagicBlockInstruction::ScheduleCommitAndUndelegate + if let CommitPolicy::UseDiff = commit_policy { + MagicBlockInstruction::ScheduleCommitDiffAndUndelegate + } + else { + MagicBlockInstruction::ScheduleCommitAndUndelegate + } } else { + if let CommitPolicy::UseDiff = commit_policy { + panic!("sdk: CommitPolicy::UseDiff not supported yet for ScheduleCommit"); + } MagicBlockInstruction::ScheduleCommit }; let mut account_metas = vec![ diff --git a/ts/web3js/package.json b/ts/web3js/package.json index 6ccd9ff..86ad713 100644 --- a/ts/web3js/package.json +++ b/ts/web3js/package.json @@ -38,7 +38,9 @@ "eslint-plugin-promise": "^6.2.0", "prettier": "^3.3.2", "rimraf": "^3.0.2", - "vitest": "^3.2.4" + "vitest": "^3.2.4", + "ts-jest": "^29.1.1", + "typescript": "5.3.0" }, "dependencies": { "@metaplex-foundation/beet": "^0.7.2",