Skip to content

Commit ea29cb2

Browse files
committed
🐛 Fixing authority account mutability
1 parent 15e4712 commit ea29cb2

File tree

18 files changed

+192
-130
lines changed

18 files changed

+192
-130
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vscode
12
.idea*
23
.idea
34
.anchor

clients/csharp/Solana.Unity.Bolt.Test/ECSTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public static async Task CheckPositionOnEntity1IsDefault(Framework framework) {
108108

109109
public static async Task ApplySimpleMovementSystemUpOnEntity1(Framework framework) {
110110
var apply = new ApplyAccounts() {
111-
CpiAuth = WorldProgram.CPI_AUTH_ADDRESS,
111+
CpiAuth = WorldProgram.FindCpiAuthPda(),
112112
Authority = framework.Wallet.Account.PublicKey,
113113
BoltSystem = framework.SystemSimpleMovement,
114114
World = framework.WorldPda,
115-
Buffer = WorldProgram.FindBufferPda(),
115+
Buffer = WorldProgram.FindBufferPda(framework.Wallet.Account.PublicKey),
116116
};
117117
var instruction = WorldProgram.Apply(apply, Bolt.World.SerializeArgs(new { direction = "Up" }));
118118
instruction.Keys.Add(AccountMeta.ReadOnly(framework.ExampleComponentPosition, false));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static async Task<DestroyComponentInstruction> DestroyComponent(PublicKey
3030
public static async Task<DestroyComponentInstruction> DestroyComponent(PublicKey authority, PublicKey receiver, PublicKey entity, PublicKey componentProgram, PublicKey componentPda) {
3131
var componentProgramData = WorldProgram.FindComponentProgramDataPda(componentProgram);
3232
var destroyComponent = new DestroyComponentAccounts() {
33-
CpiAuth = WorldProgram.CPI_AUTH_ADDRESS,
33+
CpiAuth = WorldProgram.FindCpiAuthPda(),
3434
Authority = authority,
3535
Receiver = receiver,
3636
Entity = entity,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static async Task<InitializeComponentInstruction> InitializeComponent(Pub
3030

3131
public static async Task<InitializeComponentInstruction> InitializeComponent(PublicKey payer, PublicKey entity, PublicKey componentId, PublicKey componentPda, PublicKey authority = null) {
3232
var initializeComponent = new InitializeComponentAccounts() {
33-
CpiAuth = WorldProgram.CPI_AUTH_ADDRESS,
33+
CpiAuth = WorldProgram.FindCpiAuthPda(),
3434
Payer = payer,
3535
Entity = entity,
3636
Data = componentPda,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction Apply(ApplyAccounts
513513
{
514514
programId ??= new(ID);
515515
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
516-
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Buffer, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.BoltSystem, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Authority, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.CpiAuth, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.World, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
516+
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Buffer, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.BoltSystem, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Authority, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.CpiAuth, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.World, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
517517
byte[] _data = new byte[1200];
518518
int offset = 0;
519519
_data.WriteU64(16258613031726085112UL, offset);
@@ -531,7 +531,7 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction ApplyWithSession(Ap
531531
{
532532
programId ??= new(ID);
533533
List<Solana.Unity.Rpc.Models.AccountMeta> keys = new()
534-
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Buffer, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.BoltSystem, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Authority, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.CpiAuth, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.World, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
534+
{Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Buffer, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.BoltSystem, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Authority, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.CpiAuth, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.World, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)};
535535
byte[] _data = new byte[1200];
536536
int offset = 0;
537537
_data.WriteU64(7459768094276011477UL, offset);

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ namespace Program
1515
{
1616
public partial class WorldProgram
1717
{
18-
public static readonly PublicKey CPI_AUTH_ADDRESS = new("B2f2y3QTBv346wE6nWKor72AUhUvFF6mPk7TWCF2QVhi");
19-
2018
public static Solana.Unity.Rpc.Models.TransactionInstruction AddEntity(AddEntityAccounts accounts, PublicKey programId = null)
2119
{
2220
programId ??= new(ID);
@@ -29,14 +27,18 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction AddEntity(AddEntity
2927
return AddEntity(accounts, System.Text.Encoding.UTF8.GetBytes(extraSeed), programId);
3028
}
3129

32-
public static PublicKey FindBufferPda() {
30+
public static PublicKey FindCpiAuthPda() {
3331
PublicKey.TryFindProgramAddress(new[]
3432
{
35-
Encoding.UTF8.GetBytes("buffer"),
33+
Encoding.UTF8.GetBytes("cpi_auth"),
3634
}, new PublicKey(ID), out var pda, out _);
3735
return pda;
3836
}
3937

38+
public static PublicKey FindBufferPda(PublicKey account) {
39+
return FindBufferPda(account, new PublicKey(ID));
40+
}
41+
4042
public static PublicKey FindSessionTokenPda(PublicKey sessionSigner, PublicKey authority)
4143
{
4244
PublicKey.TryFindProgramAddress(new[]
@@ -233,8 +235,8 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
233235
Solana.Unity.Rpc.Models.TransactionInstruction instruction;
234236
if (sessionToken != null) {
235237
var apply = new ApplyWithSessionAccounts() {
236-
CpiAuth = CPI_AUTH_ADDRESS,
237-
Buffer = FindBufferPda(),
238+
CpiAuth = WorldProgram.FindCpiAuthPda(),
239+
Buffer = FindBufferPda(authority),
238240
BoltSystem = system,
239241
Authority = authority,
240242
World = world,
@@ -243,8 +245,8 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
243245
instruction = ApplyWithSession(apply, args, programId);
244246
} else {
245247
var apply = new ApplyAccounts() {
246-
CpiAuth = CPI_AUTH_ADDRESS,
247-
Buffer = FindBufferPda(),
248+
CpiAuth = WorldProgram.FindCpiAuthPda(),
249+
Buffer = FindBufferPda(authority),
248250
BoltSystem = system,
249251
Authority = authority,
250252
World = world,

clients/typescript/src/generated/idl/world.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
},
126126
{
127127
"name": "authority",
128+
"writable": true,
128129
"signer": true
129130
},
130131
{
@@ -167,6 +168,7 @@
167168
},
168169
{
169170
"name": "authority",
171+
"writable": true,
170172
"signer": true
171173
},
172174
{
@@ -521,6 +523,19 @@
521523
218
522524
]
523525
},
526+
{
527+
"name": "SessionToken",
528+
"discriminator": [
529+
233,
530+
4,
531+
115,
532+
14,
533+
46,
534+
21,
535+
1,
536+
15
537+
]
538+
},
524539
{
525540
"name": "World",
526541
"discriminator": [
@@ -597,6 +612,30 @@
597612
]
598613
}
599614
},
615+
{
616+
"name": "SessionToken",
617+
"type": {
618+
"kind": "struct",
619+
"fields": [
620+
{
621+
"name": "authority",
622+
"type": "pubkey"
623+
},
624+
{
625+
"name": "target_program",
626+
"type": "pubkey"
627+
},
628+
{
629+
"name": "session_signer",
630+
"type": "pubkey"
631+
},
632+
{
633+
"name": "valid_until",
634+
"type": "i64"
635+
}
636+
]
637+
}
638+
},
600639
{
601640
"name": "World",
602641
"type": {

clients/typescript/src/generated/instructions/apply.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as beet from "@metaplex-foundation/beet";
99
import * as web3 from "@solana/web3.js";
10-
import { CPI_AUTH_ADDRESS } from "../../world/transactions";
10+
import { FindCpiAuthPda } from "../../index";
1111

1212
/**
1313
* @category Instructions
@@ -98,7 +98,7 @@ export function createApplyInstruction(
9898
isSigner: false,
9999
},
100100
{
101-
pubkey: CPI_AUTH_ADDRESS,
101+
pubkey: FindCpiAuthPda(),
102102
isWritable: false,
103103
isSigner: false,
104104
},

clients/typescript/src/generated/instructions/initializeComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as beet from "@metaplex-foundation/beet";
99
import * as web3 from "@solana/web3.js";
10-
import { CPI_AUTH_ADDRESS } from "../../world/transactions";
10+
import { FindCpiAuthPda } from "../../index";
1111

1212
/**
1313
* @category Instructions
@@ -89,7 +89,7 @@ export function createInitializeComponentInstruction(
8989
isSigner: false,
9090
},
9191
{
92-
pubkey: CPI_AUTH_ADDRESS,
92+
pubkey: FindCpiAuthPda(),
9393
isWritable: false,
9494
isSigner: false,
9595
},

clients/typescript/src/generated/types/world.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export type World = {
9898
},
9999
{
100100
name: "authority";
101+
writable: true;
101102
signer: true;
102103
},
103104
{
@@ -131,6 +132,7 @@ export type World = {
131132
},
132133
{
133134
name: "authority";
135+
writable: true;
134136
signer: true;
135137
},
136138
{
@@ -383,6 +385,10 @@ export type World = {
383385
name: "registry";
384386
discriminator: [47, 174, 110, 246, 184, 182, 252, 218];
385387
},
388+
{
389+
name: "sessionToken";
390+
discriminator: [233, 4, 115, 14, 46, 21, 1, 15];
391+
},
386392
{
387393
name: "world";
388394
discriminator: [145, 45, 170, 174, 122, 32, 155, 124];
@@ -450,6 +456,30 @@ export type World = {
450456
];
451457
};
452458
},
459+
{
460+
name: "sessionToken";
461+
type: {
462+
kind: "struct";
463+
fields: [
464+
{
465+
name: "authority";
466+
type: "pubkey";
467+
},
468+
{
469+
name: "targetProgram";
470+
type: "pubkey";
471+
},
472+
{
473+
name: "sessionSigner";
474+
type: "pubkey";
475+
},
476+
{
477+
name: "validUntil";
478+
type: "i64";
479+
},
480+
];
481+
};
482+
},
453483
{
454484
name: "world";
455485
type: {

0 commit comments

Comments
 (0)