@solana/web3.js 1.78.0 → 2.0.0-development
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -112
- package/dist/index.browser.cjs +158 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +137 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +1044 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +139 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +158 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +139 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +25 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rpc-default-config.d.ts +3 -0
- package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
- package/dist/types/rpc-request-coalescer.d.ts +5 -0
- package/dist/types/rpc-request-deduplication.d.ts +2 -0
- package/dist/types/rpc-transport.d.ts +4 -0
- package/dist/types/rpc.d.ts +5 -0
- package/package.json +86 -111
- package/lib/index.browser.cjs.js +0 -10248
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -10145
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -12748
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -3904
- package/lib/index.esm.js +0 -12638
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -26757
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -20
- package/lib/index.iife.min.js.map +0 -1
- package/lib/index.native.js +0 -10248
- package/lib/index.native.js.map +0 -1
- package/src/__forks__/browser/fetch-impl.ts +0 -4
- package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
- package/src/__forks__/react-native/fetch-impl.ts +0 -4
- package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
- package/src/account-data.ts +0 -39
- package/src/account.ts +0 -55
- package/src/blockhash.ts +0 -4
- package/src/bpf-loader-deprecated.ts +0 -5
- package/src/bpf-loader.ts +0 -45
- package/src/connection.ts +0 -6796
- package/src/epoch-schedule.ts +0 -102
- package/src/errors.ts +0 -50
- package/src/fee-calculator.ts +0 -18
- package/src/fetch-impl.ts +0 -13
- package/src/index.ts +0 -24
- package/src/instruction.ts +0 -58
- package/src/keypair.ts +0 -93
- package/src/layout.ts +0 -188
- package/src/loader.ts +0 -267
- package/src/message/account-keys.ts +0 -79
- package/src/message/compiled-keys.ts +0 -165
- package/src/message/index.ts +0 -47
- package/src/message/legacy.ts +0 -326
- package/src/message/v0.ts +0 -496
- package/src/message/versioned.ts +0 -36
- package/src/nonce-account.ts +0 -82
- package/src/programs/address-lookup-table/index.ts +0 -435
- package/src/programs/address-lookup-table/state.ts +0 -84
- package/src/programs/compute-budget.ts +0 -281
- package/src/programs/ed25519.ts +0 -157
- package/src/programs/index.ts +0 -7
- package/src/programs/secp256k1.ts +0 -228
- package/src/programs/stake.ts +0 -935
- package/src/programs/system.ts +0 -1048
- package/src/programs/vote.ts +0 -543
- package/src/publickey.ts +0 -259
- package/src/rpc-websocket-factory.ts +0 -4
- package/src/rpc-websocket.ts +0 -79
- package/src/sysvar.ts +0 -37
- package/src/timing.ts +0 -23
- package/src/transaction/constants.ts +0 -12
- package/src/transaction/expiry-custom-errors.ts +0 -48
- package/src/transaction/index.ts +0 -5
- package/src/transaction/legacy.ts +0 -918
- package/src/transaction/message.ts +0 -140
- package/src/transaction/versioned.ts +0 -126
- package/src/utils/assert.ts +0 -8
- package/src/utils/bigint.ts +0 -43
- package/src/utils/borsh-schema.ts +0 -38
- package/src/utils/cluster.ts +0 -31
- package/src/utils/ed25519.ts +0 -43
- package/src/utils/index.ts +0 -5
- package/src/utils/makeWebsocketUrl.ts +0 -26
- package/src/utils/promise-timeout.ts +0 -14
- package/src/utils/secp256k1.ts +0 -11
- package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
- package/src/utils/send-and-confirm-transaction.ts +0 -98
- package/src/utils/shortvec-encoding.ts +0 -28
- package/src/utils/sleep.ts +0 -4
- package/src/utils/to-buffer.ts +0 -11
- package/src/validator-info.ts +0 -104
- package/src/vote-account.ts +0 -236
package/src/programs/system.ts
DELETED
|
@@ -1,1048 +0,0 @@
|
|
|
1
|
-
import * as BufferLayout from '@solana/buffer-layout';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
encodeData,
|
|
5
|
-
decodeData,
|
|
6
|
-
InstructionType,
|
|
7
|
-
IInstructionInputData,
|
|
8
|
-
} from '../instruction';
|
|
9
|
-
import * as Layout from '../layout';
|
|
10
|
-
import {NONCE_ACCOUNT_LENGTH} from '../nonce-account';
|
|
11
|
-
import {PublicKey} from '../publickey';
|
|
12
|
-
import {SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY} from '../sysvar';
|
|
13
|
-
import {Transaction, TransactionInstruction} from '../transaction';
|
|
14
|
-
import {toBuffer} from '../utils/to-buffer';
|
|
15
|
-
import {u64} from '../utils/bigint';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Create account system transaction params
|
|
19
|
-
*/
|
|
20
|
-
export type CreateAccountParams = {
|
|
21
|
-
/** The account that will transfer lamports to the created account */
|
|
22
|
-
fromPubkey: PublicKey;
|
|
23
|
-
/** Public key of the created account */
|
|
24
|
-
newAccountPubkey: PublicKey;
|
|
25
|
-
/** Amount of lamports to transfer to the created account */
|
|
26
|
-
lamports: number;
|
|
27
|
-
/** Amount of space in bytes to allocate to the created account */
|
|
28
|
-
space: number;
|
|
29
|
-
/** Public key of the program to assign as the owner of the created account */
|
|
30
|
-
programId: PublicKey;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Transfer system transaction params
|
|
35
|
-
*/
|
|
36
|
-
export type TransferParams = {
|
|
37
|
-
/** Account that will transfer lamports */
|
|
38
|
-
fromPubkey: PublicKey;
|
|
39
|
-
/** Account that will receive transferred lamports */
|
|
40
|
-
toPubkey: PublicKey;
|
|
41
|
-
/** Amount of lamports to transfer */
|
|
42
|
-
lamports: number | bigint;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Assign system transaction params
|
|
47
|
-
*/
|
|
48
|
-
export type AssignParams = {
|
|
49
|
-
/** Public key of the account which will be assigned a new owner */
|
|
50
|
-
accountPubkey: PublicKey;
|
|
51
|
-
/** Public key of the program to assign as the owner */
|
|
52
|
-
programId: PublicKey;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Create account with seed system transaction params
|
|
57
|
-
*/
|
|
58
|
-
export type CreateAccountWithSeedParams = {
|
|
59
|
-
/** The account that will transfer lamports to the created account */
|
|
60
|
-
fromPubkey: PublicKey;
|
|
61
|
-
/** Public key of the created account. Must be pre-calculated with PublicKey.createWithSeed() */
|
|
62
|
-
newAccountPubkey: PublicKey;
|
|
63
|
-
/** Base public key to use to derive the address of the created account. Must be the same as the base key used to create `newAccountPubkey` */
|
|
64
|
-
basePubkey: PublicKey;
|
|
65
|
-
/** Seed to use to derive the address of the created account. Must be the same as the seed used to create `newAccountPubkey` */
|
|
66
|
-
seed: string;
|
|
67
|
-
/** Amount of lamports to transfer to the created account */
|
|
68
|
-
lamports: number;
|
|
69
|
-
/** Amount of space in bytes to allocate to the created account */
|
|
70
|
-
space: number;
|
|
71
|
-
/** Public key of the program to assign as the owner of the created account */
|
|
72
|
-
programId: PublicKey;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Create nonce account system transaction params
|
|
77
|
-
*/
|
|
78
|
-
export type CreateNonceAccountParams = {
|
|
79
|
-
/** The account that will transfer lamports to the created nonce account */
|
|
80
|
-
fromPubkey: PublicKey;
|
|
81
|
-
/** Public key of the created nonce account */
|
|
82
|
-
noncePubkey: PublicKey;
|
|
83
|
-
/** Public key to set as authority of the created nonce account */
|
|
84
|
-
authorizedPubkey: PublicKey;
|
|
85
|
-
/** Amount of lamports to transfer to the created nonce account */
|
|
86
|
-
lamports: number;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Create nonce account with seed system transaction params
|
|
91
|
-
*/
|
|
92
|
-
export type CreateNonceAccountWithSeedParams = {
|
|
93
|
-
/** The account that will transfer lamports to the created nonce account */
|
|
94
|
-
fromPubkey: PublicKey;
|
|
95
|
-
/** Public key of the created nonce account */
|
|
96
|
-
noncePubkey: PublicKey;
|
|
97
|
-
/** Public key to set as authority of the created nonce account */
|
|
98
|
-
authorizedPubkey: PublicKey;
|
|
99
|
-
/** Amount of lamports to transfer to the created nonce account */
|
|
100
|
-
lamports: number;
|
|
101
|
-
/** Base public key to use to derive the address of the nonce account */
|
|
102
|
-
basePubkey: PublicKey;
|
|
103
|
-
/** Seed to use to derive the address of the nonce account */
|
|
104
|
-
seed: string;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Initialize nonce account system instruction params
|
|
109
|
-
*/
|
|
110
|
-
export type InitializeNonceParams = {
|
|
111
|
-
/** Nonce account which will be initialized */
|
|
112
|
-
noncePubkey: PublicKey;
|
|
113
|
-
/** Public key to set as authority of the initialized nonce account */
|
|
114
|
-
authorizedPubkey: PublicKey;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Advance nonce account system instruction params
|
|
119
|
-
*/
|
|
120
|
-
export type AdvanceNonceParams = {
|
|
121
|
-
/** Nonce account */
|
|
122
|
-
noncePubkey: PublicKey;
|
|
123
|
-
/** Public key of the nonce authority */
|
|
124
|
-
authorizedPubkey: PublicKey;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Withdraw nonce account system transaction params
|
|
129
|
-
*/
|
|
130
|
-
export type WithdrawNonceParams = {
|
|
131
|
-
/** Nonce account */
|
|
132
|
-
noncePubkey: PublicKey;
|
|
133
|
-
/** Public key of the nonce authority */
|
|
134
|
-
authorizedPubkey: PublicKey;
|
|
135
|
-
/** Public key of the account which will receive the withdrawn nonce account balance */
|
|
136
|
-
toPubkey: PublicKey;
|
|
137
|
-
/** Amount of lamports to withdraw from the nonce account */
|
|
138
|
-
lamports: number;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Authorize nonce account system transaction params
|
|
143
|
-
*/
|
|
144
|
-
export type AuthorizeNonceParams = {
|
|
145
|
-
/** Nonce account */
|
|
146
|
-
noncePubkey: PublicKey;
|
|
147
|
-
/** Public key of the current nonce authority */
|
|
148
|
-
authorizedPubkey: PublicKey;
|
|
149
|
-
/** Public key to set as the new nonce authority */
|
|
150
|
-
newAuthorizedPubkey: PublicKey;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Allocate account system transaction params
|
|
155
|
-
*/
|
|
156
|
-
export type AllocateParams = {
|
|
157
|
-
/** Account to allocate */
|
|
158
|
-
accountPubkey: PublicKey;
|
|
159
|
-
/** Amount of space in bytes to allocate */
|
|
160
|
-
space: number;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Allocate account with seed system transaction params
|
|
165
|
-
*/
|
|
166
|
-
export type AllocateWithSeedParams = {
|
|
167
|
-
/** Account to allocate */
|
|
168
|
-
accountPubkey: PublicKey;
|
|
169
|
-
/** Base public key to use to derive the address of the allocated account */
|
|
170
|
-
basePubkey: PublicKey;
|
|
171
|
-
/** Seed to use to derive the address of the allocated account */
|
|
172
|
-
seed: string;
|
|
173
|
-
/** Amount of space in bytes to allocate */
|
|
174
|
-
space: number;
|
|
175
|
-
/** Public key of the program to assign as the owner of the allocated account */
|
|
176
|
-
programId: PublicKey;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Assign account with seed system transaction params
|
|
181
|
-
*/
|
|
182
|
-
export type AssignWithSeedParams = {
|
|
183
|
-
/** Public key of the account which will be assigned a new owner */
|
|
184
|
-
accountPubkey: PublicKey;
|
|
185
|
-
/** Base public key to use to derive the address of the assigned account */
|
|
186
|
-
basePubkey: PublicKey;
|
|
187
|
-
/** Seed to use to derive the address of the assigned account */
|
|
188
|
-
seed: string;
|
|
189
|
-
/** Public key of the program to assign as the owner */
|
|
190
|
-
programId: PublicKey;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Transfer with seed system transaction params
|
|
195
|
-
*/
|
|
196
|
-
export type TransferWithSeedParams = {
|
|
197
|
-
/** Account that will transfer lamports */
|
|
198
|
-
fromPubkey: PublicKey;
|
|
199
|
-
/** Base public key to use to derive the funding account address */
|
|
200
|
-
basePubkey: PublicKey;
|
|
201
|
-
/** Account that will receive transferred lamports */
|
|
202
|
-
toPubkey: PublicKey;
|
|
203
|
-
/** Amount of lamports to transfer */
|
|
204
|
-
lamports: number | bigint;
|
|
205
|
-
/** Seed to use to derive the funding account address */
|
|
206
|
-
seed: string;
|
|
207
|
-
/** Program id to use to derive the funding account address */
|
|
208
|
-
programId: PublicKey;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/** Decoded transfer system transaction instruction */
|
|
212
|
-
export type DecodedTransferInstruction = {
|
|
213
|
-
/** Account that will transfer lamports */
|
|
214
|
-
fromPubkey: PublicKey;
|
|
215
|
-
/** Account that will receive transferred lamports */
|
|
216
|
-
toPubkey: PublicKey;
|
|
217
|
-
/** Amount of lamports to transfer */
|
|
218
|
-
lamports: bigint;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
/** Decoded transferWithSeed system transaction instruction */
|
|
222
|
-
export type DecodedTransferWithSeedInstruction = {
|
|
223
|
-
/** Account that will transfer lamports */
|
|
224
|
-
fromPubkey: PublicKey;
|
|
225
|
-
/** Base public key to use to derive the funding account address */
|
|
226
|
-
basePubkey: PublicKey;
|
|
227
|
-
/** Account that will receive transferred lamports */
|
|
228
|
-
toPubkey: PublicKey;
|
|
229
|
-
/** Amount of lamports to transfer */
|
|
230
|
-
lamports: bigint;
|
|
231
|
-
/** Seed to use to derive the funding account address */
|
|
232
|
-
seed: string;
|
|
233
|
-
/** Program id to use to derive the funding account address */
|
|
234
|
-
programId: PublicKey;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* System Instruction class
|
|
239
|
-
*/
|
|
240
|
-
export class SystemInstruction {
|
|
241
|
-
/**
|
|
242
|
-
* @internal
|
|
243
|
-
*/
|
|
244
|
-
constructor() {}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Decode a system instruction and retrieve the instruction type.
|
|
248
|
-
*/
|
|
249
|
-
static decodeInstructionType(
|
|
250
|
-
instruction: TransactionInstruction,
|
|
251
|
-
): SystemInstructionType {
|
|
252
|
-
this.checkProgramId(instruction.programId);
|
|
253
|
-
|
|
254
|
-
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
255
|
-
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
256
|
-
|
|
257
|
-
let type: SystemInstructionType | undefined;
|
|
258
|
-
for (const [ixType, layout] of Object.entries(SYSTEM_INSTRUCTION_LAYOUTS)) {
|
|
259
|
-
if (layout.index == typeIndex) {
|
|
260
|
-
type = ixType as SystemInstructionType;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (!type) {
|
|
266
|
-
throw new Error('Instruction type incorrect; not a SystemInstruction');
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return type;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Decode a create account system instruction and retrieve the instruction params.
|
|
274
|
-
*/
|
|
275
|
-
static decodeCreateAccount(
|
|
276
|
-
instruction: TransactionInstruction,
|
|
277
|
-
): CreateAccountParams {
|
|
278
|
-
this.checkProgramId(instruction.programId);
|
|
279
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
280
|
-
|
|
281
|
-
const {lamports, space, programId} = decodeData(
|
|
282
|
-
SYSTEM_INSTRUCTION_LAYOUTS.Create,
|
|
283
|
-
instruction.data,
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
return {
|
|
287
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
288
|
-
newAccountPubkey: instruction.keys[1].pubkey,
|
|
289
|
-
lamports,
|
|
290
|
-
space,
|
|
291
|
-
programId: new PublicKey(programId),
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Decode a transfer system instruction and retrieve the instruction params.
|
|
297
|
-
*/
|
|
298
|
-
static decodeTransfer(
|
|
299
|
-
instruction: TransactionInstruction,
|
|
300
|
-
): DecodedTransferInstruction {
|
|
301
|
-
this.checkProgramId(instruction.programId);
|
|
302
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
303
|
-
|
|
304
|
-
const {lamports} = decodeData(
|
|
305
|
-
SYSTEM_INSTRUCTION_LAYOUTS.Transfer,
|
|
306
|
-
instruction.data,
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
311
|
-
toPubkey: instruction.keys[1].pubkey,
|
|
312
|
-
lamports,
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Decode a transfer with seed system instruction and retrieve the instruction params.
|
|
318
|
-
*/
|
|
319
|
-
static decodeTransferWithSeed(
|
|
320
|
-
instruction: TransactionInstruction,
|
|
321
|
-
): DecodedTransferWithSeedInstruction {
|
|
322
|
-
this.checkProgramId(instruction.programId);
|
|
323
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
324
|
-
|
|
325
|
-
const {lamports, seed, programId} = decodeData(
|
|
326
|
-
SYSTEM_INSTRUCTION_LAYOUTS.TransferWithSeed,
|
|
327
|
-
instruction.data,
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
return {
|
|
331
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
332
|
-
basePubkey: instruction.keys[1].pubkey,
|
|
333
|
-
toPubkey: instruction.keys[2].pubkey,
|
|
334
|
-
lamports,
|
|
335
|
-
seed,
|
|
336
|
-
programId: new PublicKey(programId),
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Decode an allocate system instruction and retrieve the instruction params.
|
|
342
|
-
*/
|
|
343
|
-
static decodeAllocate(instruction: TransactionInstruction): AllocateParams {
|
|
344
|
-
this.checkProgramId(instruction.programId);
|
|
345
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
346
|
-
|
|
347
|
-
const {space} = decodeData(
|
|
348
|
-
SYSTEM_INSTRUCTION_LAYOUTS.Allocate,
|
|
349
|
-
instruction.data,
|
|
350
|
-
);
|
|
351
|
-
|
|
352
|
-
return {
|
|
353
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
354
|
-
space,
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Decode an allocate with seed system instruction and retrieve the instruction params.
|
|
360
|
-
*/
|
|
361
|
-
static decodeAllocateWithSeed(
|
|
362
|
-
instruction: TransactionInstruction,
|
|
363
|
-
): AllocateWithSeedParams {
|
|
364
|
-
this.checkProgramId(instruction.programId);
|
|
365
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
366
|
-
|
|
367
|
-
const {base, seed, space, programId} = decodeData(
|
|
368
|
-
SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed,
|
|
369
|
-
instruction.data,
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
374
|
-
basePubkey: new PublicKey(base),
|
|
375
|
-
seed,
|
|
376
|
-
space,
|
|
377
|
-
programId: new PublicKey(programId),
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Decode an assign system instruction and retrieve the instruction params.
|
|
383
|
-
*/
|
|
384
|
-
static decodeAssign(instruction: TransactionInstruction): AssignParams {
|
|
385
|
-
this.checkProgramId(instruction.programId);
|
|
386
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
387
|
-
|
|
388
|
-
const {programId} = decodeData(
|
|
389
|
-
SYSTEM_INSTRUCTION_LAYOUTS.Assign,
|
|
390
|
-
instruction.data,
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
return {
|
|
394
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
395
|
-
programId: new PublicKey(programId),
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Decode an assign with seed system instruction and retrieve the instruction params.
|
|
401
|
-
*/
|
|
402
|
-
static decodeAssignWithSeed(
|
|
403
|
-
instruction: TransactionInstruction,
|
|
404
|
-
): AssignWithSeedParams {
|
|
405
|
-
this.checkProgramId(instruction.programId);
|
|
406
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
407
|
-
|
|
408
|
-
const {base, seed, programId} = decodeData(
|
|
409
|
-
SYSTEM_INSTRUCTION_LAYOUTS.AssignWithSeed,
|
|
410
|
-
instruction.data,
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
return {
|
|
414
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
415
|
-
basePubkey: new PublicKey(base),
|
|
416
|
-
seed,
|
|
417
|
-
programId: new PublicKey(programId),
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Decode a create account with seed system instruction and retrieve the instruction params.
|
|
423
|
-
*/
|
|
424
|
-
static decodeCreateWithSeed(
|
|
425
|
-
instruction: TransactionInstruction,
|
|
426
|
-
): CreateAccountWithSeedParams {
|
|
427
|
-
this.checkProgramId(instruction.programId);
|
|
428
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
429
|
-
|
|
430
|
-
const {base, seed, lamports, space, programId} = decodeData(
|
|
431
|
-
SYSTEM_INSTRUCTION_LAYOUTS.CreateWithSeed,
|
|
432
|
-
instruction.data,
|
|
433
|
-
);
|
|
434
|
-
|
|
435
|
-
return {
|
|
436
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
437
|
-
newAccountPubkey: instruction.keys[1].pubkey,
|
|
438
|
-
basePubkey: new PublicKey(base),
|
|
439
|
-
seed,
|
|
440
|
-
lamports,
|
|
441
|
-
space,
|
|
442
|
-
programId: new PublicKey(programId),
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Decode a nonce initialize system instruction and retrieve the instruction params.
|
|
448
|
-
*/
|
|
449
|
-
static decodeNonceInitialize(
|
|
450
|
-
instruction: TransactionInstruction,
|
|
451
|
-
): InitializeNonceParams {
|
|
452
|
-
this.checkProgramId(instruction.programId);
|
|
453
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
454
|
-
|
|
455
|
-
const {authorized} = decodeData(
|
|
456
|
-
SYSTEM_INSTRUCTION_LAYOUTS.InitializeNonceAccount,
|
|
457
|
-
instruction.data,
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
return {
|
|
461
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
462
|
-
authorizedPubkey: new PublicKey(authorized),
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Decode a nonce advance system instruction and retrieve the instruction params.
|
|
468
|
-
*/
|
|
469
|
-
static decodeNonceAdvance(
|
|
470
|
-
instruction: TransactionInstruction,
|
|
471
|
-
): AdvanceNonceParams {
|
|
472
|
-
this.checkProgramId(instruction.programId);
|
|
473
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
474
|
-
|
|
475
|
-
decodeData(
|
|
476
|
-
SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount,
|
|
477
|
-
instruction.data,
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
return {
|
|
481
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
482
|
-
authorizedPubkey: instruction.keys[2].pubkey,
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Decode a nonce withdraw system instruction and retrieve the instruction params.
|
|
488
|
-
*/
|
|
489
|
-
static decodeNonceWithdraw(
|
|
490
|
-
instruction: TransactionInstruction,
|
|
491
|
-
): WithdrawNonceParams {
|
|
492
|
-
this.checkProgramId(instruction.programId);
|
|
493
|
-
this.checkKeyLength(instruction.keys, 5);
|
|
494
|
-
|
|
495
|
-
const {lamports} = decodeData(
|
|
496
|
-
SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount,
|
|
497
|
-
instruction.data,
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
return {
|
|
501
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
502
|
-
toPubkey: instruction.keys[1].pubkey,
|
|
503
|
-
authorizedPubkey: instruction.keys[4].pubkey,
|
|
504
|
-
lamports,
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Decode a nonce authorize system instruction and retrieve the instruction params.
|
|
510
|
-
*/
|
|
511
|
-
static decodeNonceAuthorize(
|
|
512
|
-
instruction: TransactionInstruction,
|
|
513
|
-
): AuthorizeNonceParams {
|
|
514
|
-
this.checkProgramId(instruction.programId);
|
|
515
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
516
|
-
|
|
517
|
-
const {authorized} = decodeData(
|
|
518
|
-
SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount,
|
|
519
|
-
instruction.data,
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
return {
|
|
523
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
524
|
-
authorizedPubkey: instruction.keys[1].pubkey,
|
|
525
|
-
newAuthorizedPubkey: new PublicKey(authorized),
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* @internal
|
|
531
|
-
*/
|
|
532
|
-
static checkProgramId(programId: PublicKey) {
|
|
533
|
-
if (!programId.equals(SystemProgram.programId)) {
|
|
534
|
-
throw new Error('invalid instruction; programId is not SystemProgram');
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* @internal
|
|
540
|
-
*/
|
|
541
|
-
static checkKeyLength(keys: Array<any>, expectedLength: number) {
|
|
542
|
-
if (keys.length < expectedLength) {
|
|
543
|
-
throw new Error(
|
|
544
|
-
`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`,
|
|
545
|
-
);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* An enumeration of valid SystemInstructionType's
|
|
552
|
-
*/
|
|
553
|
-
export type SystemInstructionType =
|
|
554
|
-
// FIXME
|
|
555
|
-
// It would be preferable for this type to be `keyof SystemInstructionInputData`
|
|
556
|
-
// but Typedoc does not transpile `keyof` expressions.
|
|
557
|
-
// See https://github.com/TypeStrong/typedoc/issues/1894
|
|
558
|
-
| 'AdvanceNonceAccount'
|
|
559
|
-
| 'Allocate'
|
|
560
|
-
| 'AllocateWithSeed'
|
|
561
|
-
| 'Assign'
|
|
562
|
-
| 'AssignWithSeed'
|
|
563
|
-
| 'AuthorizeNonceAccount'
|
|
564
|
-
| 'Create'
|
|
565
|
-
| 'CreateWithSeed'
|
|
566
|
-
| 'InitializeNonceAccount'
|
|
567
|
-
| 'Transfer'
|
|
568
|
-
| 'TransferWithSeed'
|
|
569
|
-
| 'WithdrawNonceAccount'
|
|
570
|
-
| 'UpgradeNonceAccount';
|
|
571
|
-
|
|
572
|
-
type SystemInstructionInputData = {
|
|
573
|
-
AdvanceNonceAccount: IInstructionInputData;
|
|
574
|
-
Allocate: IInstructionInputData & {
|
|
575
|
-
space: number;
|
|
576
|
-
};
|
|
577
|
-
AllocateWithSeed: IInstructionInputData & {
|
|
578
|
-
base: Uint8Array;
|
|
579
|
-
programId: Uint8Array;
|
|
580
|
-
seed: string;
|
|
581
|
-
space: number;
|
|
582
|
-
};
|
|
583
|
-
Assign: IInstructionInputData & {
|
|
584
|
-
programId: Uint8Array;
|
|
585
|
-
};
|
|
586
|
-
AssignWithSeed: IInstructionInputData & {
|
|
587
|
-
base: Uint8Array;
|
|
588
|
-
seed: string;
|
|
589
|
-
programId: Uint8Array;
|
|
590
|
-
};
|
|
591
|
-
AuthorizeNonceAccount: IInstructionInputData & {
|
|
592
|
-
authorized: Uint8Array;
|
|
593
|
-
};
|
|
594
|
-
Create: IInstructionInputData & {
|
|
595
|
-
lamports: number;
|
|
596
|
-
programId: Uint8Array;
|
|
597
|
-
space: number;
|
|
598
|
-
};
|
|
599
|
-
CreateWithSeed: IInstructionInputData & {
|
|
600
|
-
base: Uint8Array;
|
|
601
|
-
lamports: number;
|
|
602
|
-
programId: Uint8Array;
|
|
603
|
-
seed: string;
|
|
604
|
-
space: number;
|
|
605
|
-
};
|
|
606
|
-
InitializeNonceAccount: IInstructionInputData & {
|
|
607
|
-
authorized: Uint8Array;
|
|
608
|
-
};
|
|
609
|
-
Transfer: IInstructionInputData & {
|
|
610
|
-
lamports: bigint;
|
|
611
|
-
};
|
|
612
|
-
TransferWithSeed: IInstructionInputData & {
|
|
613
|
-
lamports: bigint;
|
|
614
|
-
programId: Uint8Array;
|
|
615
|
-
seed: string;
|
|
616
|
-
};
|
|
617
|
-
WithdrawNonceAccount: IInstructionInputData & {
|
|
618
|
-
lamports: number;
|
|
619
|
-
};
|
|
620
|
-
UpgradeNonceAccount: IInstructionInputData;
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* An enumeration of valid system InstructionType's
|
|
625
|
-
* @internal
|
|
626
|
-
*/
|
|
627
|
-
export const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze<{
|
|
628
|
-
[Instruction in SystemInstructionType]: InstructionType<
|
|
629
|
-
SystemInstructionInputData[Instruction]
|
|
630
|
-
>;
|
|
631
|
-
}>({
|
|
632
|
-
Create: {
|
|
633
|
-
index: 0,
|
|
634
|
-
layout: BufferLayout.struct<SystemInstructionInputData['Create']>([
|
|
635
|
-
BufferLayout.u32('instruction'),
|
|
636
|
-
BufferLayout.ns64('lamports'),
|
|
637
|
-
BufferLayout.ns64('space'),
|
|
638
|
-
Layout.publicKey('programId'),
|
|
639
|
-
]),
|
|
640
|
-
},
|
|
641
|
-
Assign: {
|
|
642
|
-
index: 1,
|
|
643
|
-
layout: BufferLayout.struct<SystemInstructionInputData['Assign']>([
|
|
644
|
-
BufferLayout.u32('instruction'),
|
|
645
|
-
Layout.publicKey('programId'),
|
|
646
|
-
]),
|
|
647
|
-
},
|
|
648
|
-
Transfer: {
|
|
649
|
-
index: 2,
|
|
650
|
-
layout: BufferLayout.struct<SystemInstructionInputData['Transfer']>([
|
|
651
|
-
BufferLayout.u32('instruction'),
|
|
652
|
-
u64('lamports'),
|
|
653
|
-
]),
|
|
654
|
-
},
|
|
655
|
-
CreateWithSeed: {
|
|
656
|
-
index: 3,
|
|
657
|
-
layout: BufferLayout.struct<SystemInstructionInputData['CreateWithSeed']>([
|
|
658
|
-
BufferLayout.u32('instruction'),
|
|
659
|
-
Layout.publicKey('base'),
|
|
660
|
-
Layout.rustString('seed'),
|
|
661
|
-
BufferLayout.ns64('lamports'),
|
|
662
|
-
BufferLayout.ns64('space'),
|
|
663
|
-
Layout.publicKey('programId'),
|
|
664
|
-
]),
|
|
665
|
-
},
|
|
666
|
-
AdvanceNonceAccount: {
|
|
667
|
-
index: 4,
|
|
668
|
-
layout: BufferLayout.struct<
|
|
669
|
-
SystemInstructionInputData['AdvanceNonceAccount']
|
|
670
|
-
>([BufferLayout.u32('instruction')]),
|
|
671
|
-
},
|
|
672
|
-
WithdrawNonceAccount: {
|
|
673
|
-
index: 5,
|
|
674
|
-
layout: BufferLayout.struct<
|
|
675
|
-
SystemInstructionInputData['WithdrawNonceAccount']
|
|
676
|
-
>([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')]),
|
|
677
|
-
},
|
|
678
|
-
InitializeNonceAccount: {
|
|
679
|
-
index: 6,
|
|
680
|
-
layout: BufferLayout.struct<
|
|
681
|
-
SystemInstructionInputData['InitializeNonceAccount']
|
|
682
|
-
>([BufferLayout.u32('instruction'), Layout.publicKey('authorized')]),
|
|
683
|
-
},
|
|
684
|
-
AuthorizeNonceAccount: {
|
|
685
|
-
index: 7,
|
|
686
|
-
layout: BufferLayout.struct<
|
|
687
|
-
SystemInstructionInputData['AuthorizeNonceAccount']
|
|
688
|
-
>([BufferLayout.u32('instruction'), Layout.publicKey('authorized')]),
|
|
689
|
-
},
|
|
690
|
-
Allocate: {
|
|
691
|
-
index: 8,
|
|
692
|
-
layout: BufferLayout.struct<SystemInstructionInputData['Allocate']>([
|
|
693
|
-
BufferLayout.u32('instruction'),
|
|
694
|
-
BufferLayout.ns64('space'),
|
|
695
|
-
]),
|
|
696
|
-
},
|
|
697
|
-
AllocateWithSeed: {
|
|
698
|
-
index: 9,
|
|
699
|
-
layout: BufferLayout.struct<SystemInstructionInputData['AllocateWithSeed']>(
|
|
700
|
-
[
|
|
701
|
-
BufferLayout.u32('instruction'),
|
|
702
|
-
Layout.publicKey('base'),
|
|
703
|
-
Layout.rustString('seed'),
|
|
704
|
-
BufferLayout.ns64('space'),
|
|
705
|
-
Layout.publicKey('programId'),
|
|
706
|
-
],
|
|
707
|
-
),
|
|
708
|
-
},
|
|
709
|
-
AssignWithSeed: {
|
|
710
|
-
index: 10,
|
|
711
|
-
layout: BufferLayout.struct<SystemInstructionInputData['AssignWithSeed']>([
|
|
712
|
-
BufferLayout.u32('instruction'),
|
|
713
|
-
Layout.publicKey('base'),
|
|
714
|
-
Layout.rustString('seed'),
|
|
715
|
-
Layout.publicKey('programId'),
|
|
716
|
-
]),
|
|
717
|
-
},
|
|
718
|
-
TransferWithSeed: {
|
|
719
|
-
index: 11,
|
|
720
|
-
layout: BufferLayout.struct<SystemInstructionInputData['TransferWithSeed']>(
|
|
721
|
-
[
|
|
722
|
-
BufferLayout.u32('instruction'),
|
|
723
|
-
u64('lamports'),
|
|
724
|
-
Layout.rustString('seed'),
|
|
725
|
-
Layout.publicKey('programId'),
|
|
726
|
-
],
|
|
727
|
-
),
|
|
728
|
-
},
|
|
729
|
-
UpgradeNonceAccount: {
|
|
730
|
-
index: 12,
|
|
731
|
-
layout: BufferLayout.struct<
|
|
732
|
-
SystemInstructionInputData['UpgradeNonceAccount']
|
|
733
|
-
>([BufferLayout.u32('instruction')]),
|
|
734
|
-
},
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Factory class for transactions to interact with the System program
|
|
739
|
-
*/
|
|
740
|
-
export class SystemProgram {
|
|
741
|
-
/**
|
|
742
|
-
* @internal
|
|
743
|
-
*/
|
|
744
|
-
constructor() {}
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* Public key that identifies the System program
|
|
748
|
-
*/
|
|
749
|
-
static programId: PublicKey = new PublicKey(
|
|
750
|
-
'11111111111111111111111111111111',
|
|
751
|
-
);
|
|
752
|
-
|
|
753
|
-
/**
|
|
754
|
-
* Generate a transaction instruction that creates a new account
|
|
755
|
-
*/
|
|
756
|
-
static createAccount(params: CreateAccountParams): TransactionInstruction {
|
|
757
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Create;
|
|
758
|
-
const data = encodeData(type, {
|
|
759
|
-
lamports: params.lamports,
|
|
760
|
-
space: params.space,
|
|
761
|
-
programId: toBuffer(params.programId.toBuffer()),
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
return new TransactionInstruction({
|
|
765
|
-
keys: [
|
|
766
|
-
{pubkey: params.fromPubkey, isSigner: true, isWritable: true},
|
|
767
|
-
{pubkey: params.newAccountPubkey, isSigner: true, isWritable: true},
|
|
768
|
-
],
|
|
769
|
-
programId: this.programId,
|
|
770
|
-
data,
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
/**
|
|
775
|
-
* Generate a transaction instruction that transfers lamports from one account to another
|
|
776
|
-
*/
|
|
777
|
-
static transfer(
|
|
778
|
-
params: TransferParams | TransferWithSeedParams,
|
|
779
|
-
): TransactionInstruction {
|
|
780
|
-
let data;
|
|
781
|
-
let keys;
|
|
782
|
-
if ('basePubkey' in params) {
|
|
783
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.TransferWithSeed;
|
|
784
|
-
data = encodeData(type, {
|
|
785
|
-
lamports: BigInt(params.lamports),
|
|
786
|
-
seed: params.seed,
|
|
787
|
-
programId: toBuffer(params.programId.toBuffer()),
|
|
788
|
-
});
|
|
789
|
-
keys = [
|
|
790
|
-
{pubkey: params.fromPubkey, isSigner: false, isWritable: true},
|
|
791
|
-
{pubkey: params.basePubkey, isSigner: true, isWritable: false},
|
|
792
|
-
{pubkey: params.toPubkey, isSigner: false, isWritable: true},
|
|
793
|
-
];
|
|
794
|
-
} else {
|
|
795
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer;
|
|
796
|
-
data = encodeData(type, {lamports: BigInt(params.lamports)});
|
|
797
|
-
keys = [
|
|
798
|
-
{pubkey: params.fromPubkey, isSigner: true, isWritable: true},
|
|
799
|
-
{pubkey: params.toPubkey, isSigner: false, isWritable: true},
|
|
800
|
-
];
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
return new TransactionInstruction({
|
|
804
|
-
keys,
|
|
805
|
-
programId: this.programId,
|
|
806
|
-
data,
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* Generate a transaction instruction that assigns an account to a program
|
|
812
|
-
*/
|
|
813
|
-
static assign(
|
|
814
|
-
params: AssignParams | AssignWithSeedParams,
|
|
815
|
-
): TransactionInstruction {
|
|
816
|
-
let data;
|
|
817
|
-
let keys;
|
|
818
|
-
if ('basePubkey' in params) {
|
|
819
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AssignWithSeed;
|
|
820
|
-
data = encodeData(type, {
|
|
821
|
-
base: toBuffer(params.basePubkey.toBuffer()),
|
|
822
|
-
seed: params.seed,
|
|
823
|
-
programId: toBuffer(params.programId.toBuffer()),
|
|
824
|
-
});
|
|
825
|
-
keys = [
|
|
826
|
-
{pubkey: params.accountPubkey, isSigner: false, isWritable: true},
|
|
827
|
-
{pubkey: params.basePubkey, isSigner: true, isWritable: false},
|
|
828
|
-
];
|
|
829
|
-
} else {
|
|
830
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Assign;
|
|
831
|
-
data = encodeData(type, {
|
|
832
|
-
programId: toBuffer(params.programId.toBuffer()),
|
|
833
|
-
});
|
|
834
|
-
keys = [{pubkey: params.accountPubkey, isSigner: true, isWritable: true}];
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
return new TransactionInstruction({
|
|
838
|
-
keys,
|
|
839
|
-
programId: this.programId,
|
|
840
|
-
data,
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
/**
|
|
845
|
-
* Generate a transaction instruction that creates a new account at
|
|
846
|
-
* an address generated with `from`, a seed, and programId
|
|
847
|
-
*/
|
|
848
|
-
static createAccountWithSeed(
|
|
849
|
-
params: CreateAccountWithSeedParams,
|
|
850
|
-
): TransactionInstruction {
|
|
851
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.CreateWithSeed;
|
|
852
|
-
const data = encodeData(type, {
|
|
853
|
-
base: toBuffer(params.basePubkey.toBuffer()),
|
|
854
|
-
seed: params.seed,
|
|
855
|
-
lamports: params.lamports,
|
|
856
|
-
space: params.space,
|
|
857
|
-
programId: toBuffer(params.programId.toBuffer()),
|
|
858
|
-
});
|
|
859
|
-
let keys = [
|
|
860
|
-
{pubkey: params.fromPubkey, isSigner: true, isWritable: true},
|
|
861
|
-
{pubkey: params.newAccountPubkey, isSigner: false, isWritable: true},
|
|
862
|
-
];
|
|
863
|
-
if (params.basePubkey != params.fromPubkey) {
|
|
864
|
-
keys.push({
|
|
865
|
-
pubkey: params.basePubkey,
|
|
866
|
-
isSigner: true,
|
|
867
|
-
isWritable: false,
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
return new TransactionInstruction({
|
|
872
|
-
keys,
|
|
873
|
-
programId: this.programId,
|
|
874
|
-
data,
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* Generate a transaction that creates a new Nonce account
|
|
880
|
-
*/
|
|
881
|
-
static createNonceAccount(
|
|
882
|
-
params: CreateNonceAccountParams | CreateNonceAccountWithSeedParams,
|
|
883
|
-
): Transaction {
|
|
884
|
-
const transaction = new Transaction();
|
|
885
|
-
if ('basePubkey' in params && 'seed' in params) {
|
|
886
|
-
transaction.add(
|
|
887
|
-
SystemProgram.createAccountWithSeed({
|
|
888
|
-
fromPubkey: params.fromPubkey,
|
|
889
|
-
newAccountPubkey: params.noncePubkey,
|
|
890
|
-
basePubkey: params.basePubkey,
|
|
891
|
-
seed: params.seed,
|
|
892
|
-
lamports: params.lamports,
|
|
893
|
-
space: NONCE_ACCOUNT_LENGTH,
|
|
894
|
-
programId: this.programId,
|
|
895
|
-
}),
|
|
896
|
-
);
|
|
897
|
-
} else {
|
|
898
|
-
transaction.add(
|
|
899
|
-
SystemProgram.createAccount({
|
|
900
|
-
fromPubkey: params.fromPubkey,
|
|
901
|
-
newAccountPubkey: params.noncePubkey,
|
|
902
|
-
lamports: params.lamports,
|
|
903
|
-
space: NONCE_ACCOUNT_LENGTH,
|
|
904
|
-
programId: this.programId,
|
|
905
|
-
}),
|
|
906
|
-
);
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
const initParams = {
|
|
910
|
-
noncePubkey: params.noncePubkey,
|
|
911
|
-
authorizedPubkey: params.authorizedPubkey,
|
|
912
|
-
};
|
|
913
|
-
|
|
914
|
-
transaction.add(this.nonceInitialize(initParams));
|
|
915
|
-
return transaction;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Generate an instruction to initialize a Nonce account
|
|
920
|
-
*/
|
|
921
|
-
static nonceInitialize(
|
|
922
|
-
params: InitializeNonceParams,
|
|
923
|
-
): TransactionInstruction {
|
|
924
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.InitializeNonceAccount;
|
|
925
|
-
const data = encodeData(type, {
|
|
926
|
-
authorized: toBuffer(params.authorizedPubkey.toBuffer()),
|
|
927
|
-
});
|
|
928
|
-
const instructionData = {
|
|
929
|
-
keys: [
|
|
930
|
-
{pubkey: params.noncePubkey, isSigner: false, isWritable: true},
|
|
931
|
-
{
|
|
932
|
-
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
933
|
-
isSigner: false,
|
|
934
|
-
isWritable: false,
|
|
935
|
-
},
|
|
936
|
-
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false},
|
|
937
|
-
],
|
|
938
|
-
programId: this.programId,
|
|
939
|
-
data,
|
|
940
|
-
};
|
|
941
|
-
return new TransactionInstruction(instructionData);
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* Generate an instruction to advance the nonce in a Nonce account
|
|
946
|
-
*/
|
|
947
|
-
static nonceAdvance(params: AdvanceNonceParams): TransactionInstruction {
|
|
948
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
|
|
949
|
-
const data = encodeData(type);
|
|
950
|
-
const instructionData = {
|
|
951
|
-
keys: [
|
|
952
|
-
{pubkey: params.noncePubkey, isSigner: false, isWritable: true},
|
|
953
|
-
{
|
|
954
|
-
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
955
|
-
isSigner: false,
|
|
956
|
-
isWritable: false,
|
|
957
|
-
},
|
|
958
|
-
{pubkey: params.authorizedPubkey, isSigner: true, isWritable: false},
|
|
959
|
-
],
|
|
960
|
-
programId: this.programId,
|
|
961
|
-
data,
|
|
962
|
-
};
|
|
963
|
-
return new TransactionInstruction(instructionData);
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
/**
|
|
967
|
-
* Generate a transaction instruction that withdraws lamports from a Nonce account
|
|
968
|
-
*/
|
|
969
|
-
static nonceWithdraw(params: WithdrawNonceParams): TransactionInstruction {
|
|
970
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
|
|
971
|
-
const data = encodeData(type, {lamports: params.lamports});
|
|
972
|
-
|
|
973
|
-
return new TransactionInstruction({
|
|
974
|
-
keys: [
|
|
975
|
-
{pubkey: params.noncePubkey, isSigner: false, isWritable: true},
|
|
976
|
-
{pubkey: params.toPubkey, isSigner: false, isWritable: true},
|
|
977
|
-
{
|
|
978
|
-
pubkey: SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
979
|
-
isSigner: false,
|
|
980
|
-
isWritable: false,
|
|
981
|
-
},
|
|
982
|
-
{
|
|
983
|
-
pubkey: SYSVAR_RENT_PUBKEY,
|
|
984
|
-
isSigner: false,
|
|
985
|
-
isWritable: false,
|
|
986
|
-
},
|
|
987
|
-
{pubkey: params.authorizedPubkey, isSigner: true, isWritable: false},
|
|
988
|
-
],
|
|
989
|
-
programId: this.programId,
|
|
990
|
-
data,
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
/**
|
|
995
|
-
* Generate a transaction instruction that authorizes a new PublicKey as the authority
|
|
996
|
-
* on a Nonce account.
|
|
997
|
-
*/
|
|
998
|
-
static nonceAuthorize(params: AuthorizeNonceParams): TransactionInstruction {
|
|
999
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
|
|
1000
|
-
const data = encodeData(type, {
|
|
1001
|
-
authorized: toBuffer(params.newAuthorizedPubkey.toBuffer()),
|
|
1002
|
-
});
|
|
1003
|
-
|
|
1004
|
-
return new TransactionInstruction({
|
|
1005
|
-
keys: [
|
|
1006
|
-
{pubkey: params.noncePubkey, isSigner: false, isWritable: true},
|
|
1007
|
-
{pubkey: params.authorizedPubkey, isSigner: true, isWritable: false},
|
|
1008
|
-
],
|
|
1009
|
-
programId: this.programId,
|
|
1010
|
-
data,
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
/**
|
|
1015
|
-
* Generate a transaction instruction that allocates space in an account without funding
|
|
1016
|
-
*/
|
|
1017
|
-
static allocate(
|
|
1018
|
-
params: AllocateParams | AllocateWithSeedParams,
|
|
1019
|
-
): TransactionInstruction {
|
|
1020
|
-
let data;
|
|
1021
|
-
let keys;
|
|
1022
|
-
if ('basePubkey' in params) {
|
|
1023
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
|
|
1024
|
-
data = encodeData(type, {
|
|
1025
|
-
base: toBuffer(params.basePubkey.toBuffer()),
|
|
1026
|
-
seed: params.seed,
|
|
1027
|
-
space: params.space,
|
|
1028
|
-
programId: toBuffer(params.programId.toBuffer()),
|
|
1029
|
-
});
|
|
1030
|
-
keys = [
|
|
1031
|
-
{pubkey: params.accountPubkey, isSigner: false, isWritable: true},
|
|
1032
|
-
{pubkey: params.basePubkey, isSigner: true, isWritable: false},
|
|
1033
|
-
];
|
|
1034
|
-
} else {
|
|
1035
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
|
|
1036
|
-
data = encodeData(type, {
|
|
1037
|
-
space: params.space,
|
|
1038
|
-
});
|
|
1039
|
-
keys = [{pubkey: params.accountPubkey, isSigner: true, isWritable: true}];
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
return new TransactionInstruction({
|
|
1043
|
-
keys,
|
|
1044
|
-
programId: this.programId,
|
|
1045
|
-
data,
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
}
|