Skip to content

Commit 58a17a2

Browse files
committed
✨ Bundled components are optionally delegateable
1 parent 7ff577f commit 58a17a2

File tree

19 files changed

+70
-118
lines changed

19 files changed

+70
-118
lines changed

.github/workflows/publish-bolt-crates.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ jobs:
185185
-p bolt-attribute-bolt-component \
186186
-p bolt-attribute-bolt-component-deserialize \
187187
-p bolt-attribute-bolt-component-id \
188-
-p bolt-attribute-bolt-delegate \
189188
-p bolt-attribute-bolt-extra-accounts \
190189
-p bolt-attribute-bolt-system \
191190
-p bolt-attribute-bolt-system-input

Cargo.lock

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ bolt-lang = { path = "crates/bolt-lang", version = "=0.2.6" }
2222
bolt-attribute = { path = "crates/bolt-lang/attribute", version = "=0.2.6" }
2323
bolt-attribute-bolt-bundle = { path = "crates/bolt-lang/attribute/bundle", version = "=0.2.6" }
2424
bolt-attribute-bolt-program = { path = "crates/bolt-lang/attribute/bolt-program", version = "=0.2.6" }
25-
bolt-attribute-bolt-delegate = { path = "crates/bolt-lang/attribute/delegate", version = "=0.2.6" }
2625
bolt-attribute-bolt-component = { path = "crates/bolt-lang/attribute/component", version = "=0.2.6" }
2726
bolt-attribute-bolt-system = { path = "crates/bolt-lang/attribute/system", version = "=0.2.6"}
2827
bolt-attribute-bolt-system-input = { path = "crates/bolt-lang/attribute/system-input", version = "=0.2.6" }
@@ -63,6 +62,7 @@ tokio = { version = "^1", features = ["full"] }
6362
sysinfo = "=0.36.1"
6463
bytemuck_derive = "^1"
6564
const-crypto = "0.3.0"
65+
sha2 = "^0.10"
6666

6767
[profile.release]
6868
overflow-checks = true

clients/csharp/Solana.Unity.Bolt/WorldProgram/Bolt/DelegateComponent.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ public static async Task<DelegateComponentInstruction> DelegateComponent(PublicK
3333
byte[] commitFrequencyBytes = BitConverter.GetBytes(commitFrequencyMs); // little-endian on most platforms
3434
byte[] validatorNoneTag = new byte[] { 0 }; // COption None
3535

36-
// pdaSeeds = [seedBytes, entityPubkeyBytes]
37-
var seedBytes = Encoding.UTF8.GetBytes(seed ?? "");
38-
var entityBytes = entity.KeyBytes;
39-
byte[] pdaSeeds = BuildVecOfBytes(new byte[][] { seedBytes, entityBytes });
40-
41-
var data = Concat(discriminator, commitFrequencyBytes, validatorNoneTag, pdaSeeds);
36+
var data = Concat(discriminator, commitFrequencyBytes, validatorNoneTag);
4237

4338
TransactionInstruction instruction = new TransactionInstruction() {
4439
ProgramId = componentId,
@@ -76,11 +71,7 @@ public static async Task<DelegateComponentInstruction> DelegateComponent(PublicK
7671
byte[] commitFrequencyBytes = BitConverter.GetBytes(commitFrequencyMs);
7772
byte[] validatorNoneTag = new byte[] { 0 };
7873

79-
var seedBytes = Encoding.UTF8.GetBytes(component.Seeds(seed));
80-
var entityBytes = entity.KeyBytes;
81-
byte[] pdaSeeds = BuildVecOfBytes(new byte[][] { seedBytes, entityBytes });
82-
83-
var data = Concat(discriminator, commitFrequencyBytes, validatorNoneTag, pdaSeeds);
74+
var data = Concat(discriminator, commitFrequencyBytes, validatorNoneTag);
8475

8576
TransactionInstruction instruction = new TransactionInstruction() {
8677
ProgramId = component.Program,

clients/typescript/src/delegation/delegate.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
export interface DelegateInstructionArgs {
1818
commitFrequencyMs: number;
1919
validator: beet.COption<PublicKey>;
20-
pdaSeeds: Uint8Array[];
2120
}
2221

2322
export const delegateStruct = new beet.FixableBeetArgsStruct<
@@ -29,7 +28,6 @@ export const delegateStruct = new beet.FixableBeetArgsStruct<
2928
["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
3029
["commitFrequencyMs", beet.u32],
3130
["validator", beet.coption(beetSolana.publicKey)],
32-
["pdaSeeds", beet.array(beet.bytes)],
3331
],
3432
"DelegateInstructionArgs",
3533
);
@@ -61,7 +59,6 @@ export const delegateInstructionDiscriminator = [
6159

6260
export function createDelegateInstruction(
6361
accounts: DelegateInstructionAccounts,
64-
pdaSeeds: Uint8Array[],
6562
commitFrequencyMs: number = 0,
6663
validator?: PublicKey,
6764
programId = accounts.ownerProgram,
@@ -70,7 +67,6 @@ export function createDelegateInstruction(
7067
instructionDiscriminator: delegateInstructionDiscriminator,
7168
commitFrequencyMs,
7269
validator: validator ?? null,
73-
pdaSeeds,
7470
});
7571

7672
const delegationRecord = delegationRecordPdaFromDelegatedAccount(
@@ -182,22 +178,18 @@ export async function DelegateComponent({
182178
}> {
183179
const component = Component.from(componentId);
184180
let ownerProgram = component.program;
185-
const pdaSeeds = component.seeds(seed);
186181
const componentPda = component.pda(entity, seed);
187-
const delegateComponentIx = createDelegateInstruction(
188-
{
189-
payer,
190-
entity,
191-
account: componentPda,
192-
ownerProgram,
193-
buffer,
194-
delegationRecord,
195-
delegationMetadata,
196-
delegationProgram,
197-
systemProgram,
198-
},
199-
[Buffer.from(pdaSeeds), entity.toBytes()],
200-
);
182+
const delegateComponentIx = createDelegateInstruction({
183+
payer,
184+
entity,
185+
account: componentPda,
186+
ownerProgram,
187+
buffer,
188+
delegationRecord,
189+
delegationMetadata,
190+
delegationProgram,
191+
systemProgram,
192+
});
201193

202194
return {
203195
instruction: delegateComponentIx,

crates/bolt-lang/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ anchor-lang = { workspace = true }
1717

1818
# Bolt Attributes
1919
bolt-attribute-bolt-bundle = { workspace = true }
20-
bolt-attribute-bolt-delegate = { workspace = true }
2120
bolt-attribute-bolt-component = { workspace = true }
2221
bolt-attribute-bolt-system = { workspace = true }
2322
bolt-attribute-bolt-system-input = { workspace = true }

crates/bolt-lang/attribute/component-deserialize/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ syn = { workspace = true }
1616
bolt-utils = { workspace = true }
1717
quote = { workspace = true }
1818
proc-macro2 = { workspace = true }
19+
sha2 = { workspace = true }

crates/bolt-lang/attribute/component-deserialize/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bolt_utils::add_bolt_metadata;
2+
use sha2::{Digest, Sha256};
23
use proc_macro::TokenStream;
34
use quote::quote;
45
use syn::{parse_macro_input, Attribute, DeriveInput};
@@ -38,6 +39,9 @@ pub fn component_deserialize(_attr: TokenStream, item: TokenStream) -> TokenStre
3839
}
3940
};
4041
}
42+
let mut sha256 = Sha256::new();
43+
sha256.update(name_str.as_bytes());
44+
let discriminator = sha256.finalize()[0..8].to_vec();
4145
let expanded = quote! {
4246
#input
4347

@@ -70,7 +74,7 @@ pub fn component_deserialize(_attr: TokenStream, item: TokenStream) -> TokenStre
7074

7175
#[automatically_derived]
7276
impl anchor_lang::Discriminator for #name {
73-
const DISCRIMINATOR: &'static [u8] = &[1, 1, 1, 1, 1, 1, 1, 1];
77+
const DISCRIMINATOR: &'static [u8] = &[#(#discriminator),*];
7478
}
7579

7680
#owner_definition

crates/bolt-lang/attribute/delegate/Cargo.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.

crates/bolt-lang/attribute/delegate/src/lib.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)