Skip to content

Commit e9ac891

Browse files
committed
cpi-zig: Update to newest SDK and SPL libs
#### Problem The Zig CPI example uses a few too many compute units due to the overhead from entrypoint and CPI allocations, but the newest SDK and SPL libraries avoid allocations. #### Summary of changes Update the dependencies and use them, reducing CUs by over 300.
1 parent f064cf0 commit e9ac891

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,5 @@ the address and `invoke_signed` to CPI to the system program.
180180
| Language | CU Usage |
181181
| --- | --- |
182182
| Rust | 3662 |
183-
| Zig | 3141 |
183+
| Zig | 2825 |
184184
| C | 3122 |

cpi/zig/build.zig.zon

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@
1515
// Once all dependencies are fetched, `zig build` no longer requires
1616
// internet connectivity.
1717
.dependencies = .{
18-
.base58 = .{
19-
.url = "https://github.com/joncinque/base58-zig/archive/refs/tags/v0.13.3.tar.gz",
20-
.hash = "1220fd067bf167b9062cc29ccf715ff97643c2d3f8958beea863b6036876bb71bcb8",
21-
},
2218
.@"solana-program-sdk" = .{
23-
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.13.1.tar.gz",
24-
.hash = "122030336f1257e3c0aa64243f5243f554b903c6b9ef3a91d48bfbe896c0c7d9b13b",
19+
.url = "https://github.com/joncinque/solana-program-sdk-zig/archive/refs/tags/v0.14.0.tar.gz",
20+
.hash = "1220bdfa4ea1ab6330959ce4bc40feb5b39a7f98923a266a94b69e27fd20c3526786",
2521
},
2622
.@"solana-program-library" = .{
27-
.url = "https://github.com/joncinque/solana-program-library-zig/archive/refs/tags/v0.13.1.tar.gz",
28-
.hash = "12208555f3e41bfba0ac89c4a7c6884595c78aa5d4ff4f99869c7ae0e396fd762448",
23+
.url = "https://github.com/joncinque/solana-program-library-zig/archive/refs/tags/v0.14.0.tar.gz",
24+
.hash = "1220b5f9dbfa8e36b67c4bcbddb44d1e74a1c8eda0f10f485c553f4a316994e1a3d5",
2925
},
3026
},
3127

cpi/zig/main.zig

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ const SIZE = 42;
66

77
export fn entrypoint(input: [*]u8) u64 {
88
const context = sol.Context.load(input) catch return 1;
9-
const accounts = context.loadRawAccounts(sol.allocator) catch return 1;
10-
defer accounts.deinit();
11-
12-
const allocated = accounts.items[0];
9+
const allocated = context.accounts[0];
1310

1411
const expected_allocated_key = sol.PublicKey.createProgramAddress(
1512
&.{ "You pass butter", &.{context.data[0]} },
@@ -20,12 +17,11 @@ export fn entrypoint(input: [*]u8) u64 {
2017
if (!allocated.id().equals(expected_allocated_key)) return 1;
2118

2219
// Invoke the system program to allocate account data
23-
system_ix.allocate(
24-
sol.allocator,
25-
allocated.info(),
26-
SIZE,
27-
.{ .seeds = &.{&.{ "You pass butter", &.{context.data[0]} }} },
28-
) catch return 1;
20+
system_ix.allocate(.{
21+
.account = allocated.info(),
22+
.space = SIZE,
23+
.seeds = &.{&.{ "You pass butter", &.{context.data[0]} }},
24+
}) catch return 1;
2925

3026
return 0;
3127
}

0 commit comments

Comments
 (0)