1
1
import {
2
+ createApplyInstruction ,
2
3
createAddEntityInstruction ,
3
4
createInitializeComponentInstruction ,
4
5
createInitializeNewWorldInstruction ,
@@ -47,14 +48,15 @@ export async function InitializeNewWorld({
47
48
const registry = await Registry . fromAccountAddress ( connection , registryPda ) ;
48
49
const worldId = new BN ( registry . worlds ) ;
49
50
const worldPda = FindWorldPda ( { worldId } ) ;
50
- const initializeWorldIx = createInitializeNewWorldInstruction ( {
51
+ const instruction = createInitializeNewWorldInstruction ( {
51
52
world : worldPda ,
52
53
registry : registryPda ,
53
54
payer,
54
55
} ) ;
56
+ const transaction = new Transaction ( ) . add ( instruction ) ;
55
57
return {
56
- instruction : initializeWorldIx ,
57
- transaction : new Transaction ( ) . add ( initializeWorldIx ) ,
58
+ instruction,
59
+ transaction,
58
60
worldPda,
59
61
worldId,
60
62
} ;
@@ -87,17 +89,18 @@ export async function AddAuthority({
87
89
) as unknown as Program < WorldProgram > ;
88
90
const worldInstance = await World . fromAccountAddress ( connection , world ) ;
89
91
const worldId = new BN ( worldInstance . id ) ;
90
- const addAuthorityIx = await program . methods
92
+ const instruction = await program . methods
91
93
. addAuthority ( worldId )
92
94
. accounts ( {
93
95
authority,
94
96
newAuthority,
95
97
world,
96
98
} )
97
99
. instruction ( ) ;
100
+ const transaction = new Transaction ( ) . add ( instruction ) ;
98
101
return {
99
- instruction : addAuthorityIx ,
100
- transaction : new Transaction ( ) . add ( addAuthorityIx ) ,
102
+ instruction,
103
+ transaction,
101
104
} ;
102
105
}
103
106
@@ -128,17 +131,18 @@ export async function RemoveAuthority({
128
131
) as unknown as Program < WorldProgram > ;
129
132
const worldInstance = await World . fromAccountAddress ( connection , world ) ;
130
133
const worldId = new BN ( worldInstance . id ) ;
131
- const removeAuthorityIx = await program . methods
134
+ const instruction = await program . methods
132
135
. removeAuthority ( worldId )
133
136
. accounts ( {
134
137
authority,
135
138
authorityToDelete,
136
139
world,
137
140
} )
138
141
. instruction ( ) ;
142
+ const transaction = new Transaction ( ) . add ( instruction ) ;
139
143
return {
140
- instruction : removeAuthorityIx ,
141
- transaction : new Transaction ( ) . add ( removeAuthorityIx ) ,
144
+ instruction,
145
+ transaction,
142
146
} ;
143
147
}
144
148
@@ -164,17 +168,18 @@ export async function ApproveSystem({
164
168
const program = new Program (
165
169
worldIdl as Idl ,
166
170
) as unknown as Program < WorldProgram > ;
167
- const approveSystemIx = await program . methods
171
+ const instruction = await program . methods
168
172
. approveSystem ( )
169
173
. accounts ( {
170
174
authority,
171
175
system : systemToApprove ,
172
176
world,
173
177
} )
174
178
. instruction ( ) ;
179
+ const transaction = new Transaction ( ) . add ( instruction ) ;
175
180
return {
176
- instruction : approveSystemIx ,
177
- transaction : new Transaction ( ) . add ( approveSystemIx ) ,
181
+ instruction,
182
+ transaction,
178
183
} ;
179
184
}
180
185
@@ -200,17 +205,18 @@ export async function RemoveSystem({
200
205
const program = new Program (
201
206
worldIdl as Idl ,
202
207
) as unknown as Program < WorldProgram > ;
203
- const removeSystemIx = await program . methods
208
+ const instruction = await program . methods
204
209
. removeSystem ( )
205
210
. accounts ( {
206
211
authority,
207
212
system : systemToRemove ,
208
213
world,
209
214
} )
210
215
. instruction ( ) ;
216
+ const transaction = new Transaction ( ) . add ( instruction ) ;
211
217
return {
212
- instruction : removeSystemIx ,
213
- transaction : new Transaction ( ) . add ( removeSystemIx ) ,
218
+ instruction,
219
+ transaction,
214
220
} ;
215
221
}
216
222
@@ -242,17 +248,18 @@ export async function AddEntity({
242
248
seed !== undefined
243
249
? FindEntityPda ( { worldId, seed } )
244
250
: FindEntityPda ( { worldId, entityId : new BN ( worldInstance . entities ) } ) ;
245
- const addEntityIx = createAddEntityInstruction (
251
+ const instruction = createAddEntityInstruction (
246
252
{
247
253
world,
248
254
payer,
249
255
entity : entityPda ,
250
256
} ,
251
257
{ extraSeed : seed ?? null } ,
252
258
) ;
259
+ const transaction = new Transaction ( ) . add ( instruction ) ;
253
260
return {
254
- instruction : addEntityIx ,
255
- transaction : new Transaction ( ) . add ( addEntityIx ) ,
261
+ instruction,
262
+ transaction,
256
263
entityPda,
257
264
} ;
258
265
}
@@ -287,7 +294,7 @@ export async function InitializeComponent({
287
294
componentPda : PublicKey ;
288
295
} > {
289
296
const componentPda = FindComponentPda ( { componentId, entity, seed } ) ;
290
- const initializeComponentIx = createInitializeComponentInstruction ( {
297
+ const instruction = createInitializeComponentInstruction ( {
291
298
payer,
292
299
entity,
293
300
data : componentPda ,
@@ -296,13 +303,55 @@ export async function InitializeComponent({
296
303
instructionSysvarAccount : SYSVAR_INSTRUCTIONS_PUBKEY ,
297
304
anchorRemainingAccounts,
298
305
} ) ;
306
+ const transaction = new Transaction ( ) . add ( instruction ) ;
299
307
return {
300
- instruction : initializeComponentIx ,
301
- transaction : new Transaction ( ) . add ( initializeComponentIx ) ,
308
+ instruction,
309
+ transaction,
302
310
componentPda,
303
311
} ;
304
312
}
305
313
314
+ export async function Apply ( {
315
+ authority,
316
+ boltSystem,
317
+ boltComponent,
318
+ componentProgram,
319
+ anchorRemainingAccounts,
320
+ world,
321
+ args,
322
+ } : {
323
+ authority : PublicKey ;
324
+ boltSystem : PublicKey ;
325
+ boltComponent : PublicKey ;
326
+ componentProgram : PublicKey ;
327
+ world : PublicKey ;
328
+ anchorRemainingAccounts ?: web3 . AccountMeta [ ] ;
329
+ args : Uint8Array ;
330
+ } ) : Promise < {
331
+ instruction : TransactionInstruction ;
332
+ transaction : Transaction ;
333
+ } > {
334
+ const instruction = createApplyInstruction (
335
+ {
336
+ authority,
337
+ boltSystem,
338
+ boltComponent,
339
+ componentProgram,
340
+ instructionSysvarAccount : SYSVAR_INSTRUCTIONS_PUBKEY ,
341
+ anchorRemainingAccounts,
342
+ world,
343
+ } ,
344
+ {
345
+ args,
346
+ } ,
347
+ ) ;
348
+ const transaction = new Transaction ( ) . add ( instruction ) ;
349
+ return {
350
+ instruction,
351
+ transaction,
352
+ } ;
353
+ }
354
+
306
355
interface ApplySystemInstruction {
307
356
authority : PublicKey ;
308
357
systemId : PublicKey ;
@@ -410,16 +459,17 @@ export async function ApplySystem({
410
459
extraAccounts ?: web3 . AccountMeta [ ] ;
411
460
args ?: object ;
412
461
} ) : Promise < { instruction : TransactionInstruction ; transaction : Transaction } > {
413
- const applySystemIx = await createApplySystemInstruction ( {
462
+ const instruction = await createApplySystemInstruction ( {
414
463
authority,
415
464
systemId,
416
465
entities,
417
466
world,
418
467
extraAccounts,
419
468
args,
420
469
} ) ;
470
+ const transaction = new Transaction ( ) . add ( instruction ) ;
421
471
return {
422
- instruction : applySystemIx ,
423
- transaction : new Transaction ( ) . add ( applySystemIx ) ,
472
+ instruction,
473
+ transaction,
424
474
} ;
425
475
}
0 commit comments