Skip to content

Commit

Permalink
⬆️ Upgrade ephemeral rollups sdk (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielePicco authored Jan 5, 2025
1 parent 0bca0f4 commit b0d5380
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 249 deletions.
188 changes: 118 additions & 70 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ anyhow = "1.0.32"
heck = "0.5.0"
clap = { version = "4.2.4", features = ["derive"] }
ahash = "=0.8.11"
ephemeral-rollups-sdk = "=0.0.6"
ephemeral-rollups-sdk = "=0.2.1"

[profile.release]
overflow-checks = true
Expand Down
2 changes: 1 addition & 1 deletion clients/bolt-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"private": false,
"dependencies": {
"@magicblock-labs/ephemeral-rollups-sdk": "0.0.6",
"@magicblock-labs/ephemeral-rollups-sdk": "0.2.1",
"@metaplex-foundation/beet": "^0.7.1",
"@metaplex-foundation/beet-solana": "^0.4.0",
"@coral-xyz/anchor": "^0.30.1"
Expand Down
75 changes: 0 additions & 75 deletions clients/bolt-sdk/src/delegation/allow_undelegation.ts

This file was deleted.

27 changes: 19 additions & 8 deletions clients/bolt-sdk/src/delegation/delegate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as beet from "@metaplex-foundation/beet";
import * as beetSolana from "@metaplex-foundation/beet-solana";
import * as web3 from "@solana/web3.js";
import {
DelegateAccounts,
delegateBufferPdaFromDelegatedAccountAndOwnerProgram,
DELEGATION_PROGRAM_ID,
delegationMetadataPdaFromDelegatedAccount,
delegationRecordPdaFromDelegatedAccount,
} from "@magicblock-labs/ephemeral-rollups-sdk";
import { FindComponentPda } from "../index";
import {
Expand All @@ -12,8 +15,8 @@ import {
} from "@solana/web3.js";

export interface DelegateInstructionArgs {
validUntil: beet.bignum;
commitFrequencyMs: number;
validator: beet.COption<PublicKey>;
}

export const delegateStruct = new beet.FixableBeetArgsStruct<
Expand All @@ -23,8 +26,8 @@ export const delegateStruct = new beet.FixableBeetArgsStruct<
>(
[
["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
["validUntil", beet.i64],
["commitFrequencyMs", beet.u32],
["validator", beet.coption(beetSolana.publicKey)],
],
"DelegateInstructionArgs",
);
Expand Down Expand Up @@ -56,17 +59,25 @@ export const delegateInstructionDiscriminator = [

export function createDelegateInstruction(
accounts: DelegateInstructionAccounts,
validUntil: beet.bignum = 0,
commitFrequencyMs: number = 30000,
commitFrequencyMs: number = 0,
validator?: PublicKey,
programId = accounts.ownerProgram,
) {
const [data] = delegateStruct.serialize({
instructionDiscriminator: delegateInstructionDiscriminator,
validUntil,
commitFrequencyMs,
validator: validator ?? null,
});

const { delegationPda, delegationMetadata, bufferPda } = DelegateAccounts(
const delegationRecord = delegationRecordPdaFromDelegatedAccount(
accounts.account,
);

const delegationMetadata = delegationMetadataPdaFromDelegatedAccount(
accounts.account,
);

const bufferPda = delegateBufferPdaFromDelegatedAccountAndOwnerProgram(
accounts.account,
accounts.ownerProgram,
);
Expand Down Expand Up @@ -98,7 +109,7 @@ export function createDelegateInstruction(
isSigner: false,
},
{
pubkey: accounts.delegationRecord ?? delegationPda,
pubkey: accounts.delegationRecord ?? delegationRecord,
isWritable: true,
isSigner: false,
},
Expand Down
2 changes: 1 addition & 1 deletion clients/bolt-sdk/src/generated/idl/world.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"address": "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n",
"metadata": {
"name": "world",
"version": "0.1.10",
"version": "0.1.12",
"spec": "0.1.0",
"description": "Bolt World program",
"repository": "https://github.com/magicblock-labs/bolt"
Expand Down
2 changes: 1 addition & 1 deletion clients/bolt-sdk/src/generated/types/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type World = {
address: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
metadata: {
name: "world";
version: "0.1.10";
version: "0.1.12";
spec: "0.1.0";
description: "Bolt World program";
repository: "https://github.com/magicblock-labs/bolt";
Expand Down
1 change: 0 additions & 1 deletion clients/bolt-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * from "./generated/instructions";
export * from "./world/transactions";
export * from "./delegation/delegate";
export * from "./delegation/undelegate";
export * from "./delegation/allow_undelegation";
export { DELEGATION_PROGRAM_ID } from "@magicblock-labs/ephemeral-rollups-sdk";

// Re-export anchor
Expand Down
76 changes: 21 additions & 55 deletions clients/bolt-sdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.24.7":
version "7.24.7"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.7.tgz#f4f0d5530e8dbdf59b3451b9b3e594b6ba082e12"
integrity sha512-UwgBRMjJP+xv857DCngvqXI3Iq6J4v0wXmwc6sapg+zyhbwmQX67LUEFrkK5tbyJ30jGuG3ZvWpBiB9LCy1kWw==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.25.0":
version "7.25.7"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.25.7.tgz#7ffb53c37a8f247c8c4d335e89cdf16a2e0d0fb6"
Expand Down Expand Up @@ -69,13 +62,14 @@
wrap-ansi "^8.1.0"
wrap-ansi-cjs "npm:wrap-ansi@^7.0.0"

"@magicblock-labs/ephemeral-rollups-sdk@0.0.6":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@magicblock-labs/ephemeral-rollups-sdk/-/ephemeral-rollups-sdk-0.0.6.tgz#47a667d9fd7df76752660a6d82688e54174241ab"
integrity sha512-moep9ja4fmDXPa0OcjJBvvOTUNrds8rwTzxmbGd5Myu/6AsykcCpTuUZjleQCRotu/yODLVkpheMDr1S0/mtpA==
"@magicblock-labs/ephemeral-rollups-sdk@0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@magicblock-labs/ephemeral-rollups-sdk/-/ephemeral-rollups-sdk-0.2.1.tgz#bf85a0725b9fe47bc96738a99bf9e84aa9e405d0"
integrity sha512-s1j6kXLbg6hA5ysSkG1pGEutAdxPOymtl2I94pD5UVfWWILcR0rbqONOvNV1WKDGZbILqC1AjFl/7GJGRMKB5Q==
dependencies:
"@metaplex-foundation/beet" "^0.7.2"
"@solana/web3.js" "^1.92.3"
"@solana/web3.js" "^1.98.0"
rpc-websockets "^9.0.4"

"@metaplex-foundation/beet-solana@^0.3.1":
version "0.3.1"
Expand Down Expand Up @@ -150,13 +144,6 @@
dependencies:
"@noble/hashes" "1.3.3"

"@noble/curves@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.4.0.tgz#f05771ef64da724997f69ee1261b2417a49522d6"
integrity sha512-p+4cb332SFCrReJkCYe8Xzm0OWi4Jji5jVdIZRL/PmacmDkFNw6MrrV+gGpiPxLHbV+zKFRywUWbaseT+tZRXg==
dependencies:
"@noble/hashes" "1.4.0"

"@noble/curves@^1.4.2":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.6.0.tgz#be5296ebcd5a1730fccea4786d420f87abfeb40b"
Expand All @@ -169,16 +156,16 @@
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz"
integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==

"@noble/[email protected]", "@noble/hashes@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426"
integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==

"@noble/[email protected]":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.5.0.tgz#abadc5ca20332db2b1b2aa3e496e9af1213570b0"
integrity sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==

"@noble/hashes@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426"
integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==

"@pkgjs/parseargs@^0.11.0":
version "0.11.0"
resolved "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz"
Expand Down Expand Up @@ -233,13 +220,13 @@
rpc-websockets "^9.0.2"
superstruct "^2.0.2"

"@solana/web3.js@^1.92.3":
version "1.93.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.93.0.tgz#4b6975020993cec2f6626e4f2bf559ca042df8db"
integrity sha512-suf4VYwWxERz4tKoPpXCRHFRNst7jmcFUaD65kII+zg9urpy5PeeqgLV6G5eWGzcVzA9tZeXOju1A1Y+0ojEVw==
"@solana/web3.js@^1.98.0":
version "1.98.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.98.0.tgz#21ecfe8198c10831df6f0cfde7f68370d0405917"
integrity sha512-nz3Q5OeyGFpFCR+erX2f6JPt3sKhzhYcSycBCSPkWjzSVDh/Rr1FqTVMRe58FKO16/ivTUcuJjeS5MyBvpkbzA==
dependencies:
"@babel/runtime" "^7.24.7"
"@noble/curves" "^1.4.0"
"@babel/runtime" "^7.25.0"
"@noble/curves" "^1.4.2"
"@noble/hashes" "^1.4.0"
"@solana/buffer-layout" "^4.0.1"
agentkeepalive "^4.5.0"
Expand All @@ -249,10 +236,10 @@
bs58 "^4.0.1"
buffer "6.0.3"
fast-stable-stringify "^1.0.0"
jayson "^4.1.0"
jayson "^4.1.1"
node-fetch "^2.7.0"
rpc-websockets "^9.0.0"
superstruct "^1.0.4"
rpc-websockets "^9.0.2"
superstruct "^2.0.2"

"@swc/helpers@^0.5.11":
version "0.5.11"
Expand Down Expand Up @@ -1071,23 +1058,7 @@ rpc-websockets@^7.5.1:
bufferutil "^4.0.1"
utf-8-validate "^5.0.2"

rpc-websockets@^9.0.0:
version "9.0.2"
resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-9.0.2.tgz#4c1568d00b8100f997379a363478f41f8f4b242c"
integrity sha512-YzggvfItxMY3Lwuax5rC18inhbjJv9Py7JXRHxTIi94JOLrqBsSsUUc5bbl5W6c11tXhdfpDPK0KzBhoGe8jjw==
dependencies:
"@swc/helpers" "^0.5.11"
"@types/uuid" "^8.3.4"
"@types/ws" "^8.2.2"
buffer "^6.0.3"
eventemitter3 "^5.0.1"
uuid "^8.3.2"
ws "^8.5.0"
optionalDependencies:
bufferutil "^4.0.1"
utf-8-validate "^5.0.2"

rpc-websockets@^9.0.2:
rpc-websockets@^9.0.2, rpc-websockets@^9.0.4:
version "9.0.4"
resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-9.0.4.tgz#9d8ee82533b5d1e13d9ded729e3e38d0d8fa083f"
integrity sha512-yWZWN0M+bivtoNLnaDbtny4XchdAIF5Q4g/ZsC5UC61Ckbp0QczwO8fg44rV3uYmY4WHd+EZQbn90W1d8ojzqQ==
Expand Down Expand Up @@ -1243,11 +1214,6 @@ superstruct@^0.15.4:
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-0.15.5.tgz#0f0a8d3ce31313f0d84c6096cd4fa1bfdedc9dab"
integrity sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ==

superstruct@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-1.0.4.tgz#0adb99a7578bd2f1c526220da6571b2d485d91ca"
integrity sha512-7JpaAoX2NGyoFlI9NBh66BQXGONc+uE+MRS5i2iOBKuS4e+ccgMDjATgZldkah+33DakBxDHiss9kvUcGAO8UQ==

superstruct@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-2.0.2.tgz#3f6d32fbdc11c357deff127d591a39b996300c54"
Expand Down
44 changes: 20 additions & 24 deletions crates/bolt-lang/attribute/delegate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,31 @@ fn generate_delegate(component_type: &Type) -> (TokenStream2, TokenStream2) {
(
quote! {
#[automatically_derived]
pub fn delegate(ctx: Context<DelegateInput>, valid_until: i64, commit_frequency_ms: u32) -> Result<()> {
pub fn delegate(ctx: Context<DelegateInput>, commit_frequency_ms: u32, validator: Option<Pubkey>) -> Result<()> {
let pda_seeds: &[&[u8]] = &[<#component_type>::seed(), &ctx.accounts.entity.key().to_bytes()];

let [payer, entity, account, owner_program, buffer, delegation_record, delegate_account_seeds, delegation_program, system_program] = [
&ctx.accounts.payer,
&ctx.accounts.entity.to_account_info(),
&ctx.accounts.account,
&ctx.accounts.owner_program,
&ctx.accounts.buffer,
&ctx.accounts.delegation_record,
&ctx.accounts.delegate_account_seeds,
&ctx.accounts.delegation_program,
&ctx.accounts.system_program,
];
let del_accounts = ::bolt_lang::DelegateAccounts {
payer: &ctx.accounts.payer,
pda: &ctx.accounts.account,
owner_program: &ctx.accounts.owner_program,
buffer: &ctx.accounts.buffer,
delegation_record: &ctx.accounts.delegation_record,
delegation_metadata: &ctx.accounts.delegation_metadata,
delegation_program: &ctx.accounts.delegation_program,
system_program: &ctx.accounts.system_program,
};

let pda_seeds: &[&[u8]] = &[<#component_type>::seed(), &entity.key.to_bytes()];
let config = ::bolt_lang::DelegateConfig {
commit_frequency_ms,
validator,
};

::bolt_lang::delegate_account(
payer,
account,
owner_program,
buffer,
delegation_record,
delegate_account_seeds,
delegation_program,
system_program,
del_accounts,
pda_seeds,
valid_until,
commit_frequency_ms,
config,
)?;

Ok(())
}
},
Expand All @@ -189,7 +185,7 @@ fn generate_delegate(component_type: &Type) -> (TokenStream2, TokenStream2) {
pub delegation_record: AccountInfo<'info>,
/// CHECK:`
#[account(mut)]
pub delegate_account_seeds: AccountInfo<'info>,
pub delegation_metadata: AccountInfo<'info>,
/// CHECK:`
pub delegation_program: AccountInfo<'info>,
/// CHECK:`
Expand Down
Loading

0 comments on commit b0d5380

Please sign in to comment.