@exodus/solana-lib 1.2.9-build → 1.2.9
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/package.json +3 -3
- package/src/constants.js +12 -0
- package/src/encode.js +57 -0
- package/src/fee-data/index.js +1 -0
- package/src/fee-data/solana.js +9 -0
- package/src/helpers/spl-token.js +108 -0
- package/src/helpers/tokenTransfer.js +72 -0
- package/src/index.js +8 -0
- package/src/keypair.js +32 -0
- package/src/tokens.js +19 -0
- package/src/transaction.js +240 -0
- package/src/tx/create-and-sign-tx.js +8 -0
- package/{lib → src}/tx/create-unsigned-tx.js +11 -18
- package/src/tx/index.js +4 -0
- package/src/tx/parse-unsigned-tx.js +41 -0
- package/src/tx/sign-unsigned-tx.js +78 -0
- package/src/vendor/account.js +38 -0
- package/src/vendor/index.js +9 -0
- package/src/vendor/instruction.js +46 -0
- package/src/vendor/message.js +216 -0
- package/src/vendor/nonce-account.js +46 -0
- package/src/vendor/publickey.js +212 -0
- package/src/vendor/stake-program.js +527 -0
- package/src/vendor/system-program.js +782 -0
- package/src/vendor/sysvar.js +16 -0
- package/src/vendor/transaction.js +594 -0
- package/src/vendor/utils/blockhash.js +6 -0
- package/src/vendor/utils/fee-calculator.js +17 -0
- package/src/vendor/utils/layout.js +80 -0
- package/src/vendor/utils/shortvec-encoding.js +30 -0
- package/src/vendor/utils/to-buffer.js +9 -0
- package/lib/constants.js +0 -19
- package/lib/encode.js +0 -67
- package/lib/fee-data/index.js +0 -15
- package/lib/fee-data/solana.js +0 -14
- package/lib/helpers/spl-token.js +0 -122
- package/lib/helpers/tokenTransfer.js +0 -78
- package/lib/index.js +0 -79
- package/lib/keypair.js +0 -38
- package/lib/tokens.js +0 -21
- package/lib/transaction.js +0 -279
- package/lib/tx/create-and-sign-tx.js +0 -15
- package/lib/tx/index.js +0 -53
- package/lib/tx/parse-unsigned-tx.js +0 -55
- package/lib/tx/sign-unsigned-tx.js +0 -90
- package/lib/vendor/account.js +0 -48
- package/lib/vendor/index.js +0 -113
- package/lib/vendor/instruction.js +0 -48
- package/lib/vendor/message.js +0 -167
- package/lib/vendor/nonce-account.js +0 -56
- package/lib/vendor/publickey.js +0 -211
- package/lib/vendor/stake-program.js +0 -476
- package/lib/vendor/system-program.js +0 -640
- package/lib/vendor/sysvar.js +0 -19
- package/lib/vendor/transaction.js +0 -594
- package/lib/vendor/utils/blockhash.js +0 -1
- package/lib/vendor/utils/fee-calculator.js +0 -25
- package/lib/vendor/utils/layout.js +0 -97
- package/lib/vendor/utils/shortvec-encoding.js +0 -41
- package/lib/vendor/utils/to-buffer.js +0 -18
|
@@ -1,640 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SystemProgram = exports.SystemInstruction = exports.SYSTEM_INSTRUCTION_LAYOUTS = void 0;
|
|
7
|
-
|
|
8
|
-
var BufferLayout = _interopRequireWildcard(require("@exodus/buffer-layout"));
|
|
9
|
-
|
|
10
|
-
var _instruction = require("./instruction");
|
|
11
|
-
|
|
12
|
-
var Layout = _interopRequireWildcard(require("./utils/layout"));
|
|
13
|
-
|
|
14
|
-
var _nonceAccount = require("./nonce-account");
|
|
15
|
-
|
|
16
|
-
var _publickey = require("./publickey");
|
|
17
|
-
|
|
18
|
-
var _sysvar = require("./sysvar");
|
|
19
|
-
|
|
20
|
-
var _transaction = require("./transaction");
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* An enumeration of valid system InstructionType's
|
|
28
|
-
*/
|
|
29
|
-
const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
30
|
-
Create: {
|
|
31
|
-
index: 0,
|
|
32
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports'), BufferLayout.ns64('space'), Layout.publicKey('programId')])
|
|
33
|
-
},
|
|
34
|
-
Assign: {
|
|
35
|
-
index: 1,
|
|
36
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('programId')])
|
|
37
|
-
},
|
|
38
|
-
Transfer: {
|
|
39
|
-
index: 2,
|
|
40
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
41
|
-
},
|
|
42
|
-
CreateWithSeed: {
|
|
43
|
-
index: 3,
|
|
44
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('base'), Layout.rustString('seed'), BufferLayout.ns64('lamports'), BufferLayout.ns64('space'), Layout.publicKey('programId')])
|
|
45
|
-
},
|
|
46
|
-
AdvanceNonceAccount: {
|
|
47
|
-
index: 4,
|
|
48
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
49
|
-
},
|
|
50
|
-
WithdrawNonceAccount: {
|
|
51
|
-
index: 5,
|
|
52
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
53
|
-
},
|
|
54
|
-
InitializeNonceAccount: {
|
|
55
|
-
index: 6,
|
|
56
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('authorized')])
|
|
57
|
-
},
|
|
58
|
-
AuthorizeNonceAccount: {
|
|
59
|
-
index: 7,
|
|
60
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('authorized')])
|
|
61
|
-
},
|
|
62
|
-
Allocate: {
|
|
63
|
-
index: 8,
|
|
64
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('space')])
|
|
65
|
-
},
|
|
66
|
-
AllocateWithSeed: {
|
|
67
|
-
index: 9,
|
|
68
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('base'), Layout.rustString('seed'), BufferLayout.ns64('space'), Layout.publicKey('programId')])
|
|
69
|
-
},
|
|
70
|
-
AssignWithSeed: {
|
|
71
|
-
index: 10,
|
|
72
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('base'), Layout.rustString('seed'), Layout.publicKey('programId')])
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
/**
|
|
76
|
-
* System Instruction class
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
|
|
80
|
-
|
|
81
|
-
class SystemInstruction {
|
|
82
|
-
/**
|
|
83
|
-
* Decode a system instruction and retrieve the instruction type.
|
|
84
|
-
*/
|
|
85
|
-
static decodeInstructionType(instruction) {
|
|
86
|
-
this.checkProgramId(instruction.programId);
|
|
87
|
-
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
88
|
-
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
89
|
-
let type;
|
|
90
|
-
|
|
91
|
-
for (const t of Object.keys(SYSTEM_INSTRUCTION_LAYOUTS)) {
|
|
92
|
-
if (SYSTEM_INSTRUCTION_LAYOUTS[t].index === typeIndex) {
|
|
93
|
-
type = t;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!type) {
|
|
98
|
-
throw new Error('Instruction type incorrect; not a SystemInstruction');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return type;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Decode a create account system instruction and retrieve the instruction params.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
static decodeCreateAccount(instruction) {
|
|
109
|
-
this.checkProgramId(instruction.programId);
|
|
110
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
111
|
-
const {
|
|
112
|
-
lamports,
|
|
113
|
-
space,
|
|
114
|
-
programId
|
|
115
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.Create, instruction.data);
|
|
116
|
-
return {
|
|
117
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
118
|
-
newAccountPubkey: instruction.keys[1].pubkey,
|
|
119
|
-
lamports,
|
|
120
|
-
space,
|
|
121
|
-
programId: new _publickey.PublicKey(programId)
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Decode a transfer system instruction and retrieve the instruction params.
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
static decodeTransfer(instruction) {
|
|
130
|
-
this.checkProgramId(instruction.programId);
|
|
131
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
132
|
-
const {
|
|
133
|
-
lamports
|
|
134
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.Transfer, instruction.data);
|
|
135
|
-
return {
|
|
136
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
137
|
-
toPubkey: instruction.keys[1].pubkey,
|
|
138
|
-
lamports
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Decode an allocate system instruction and retrieve the instruction params.
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
static decodeAllocate(instruction) {
|
|
147
|
-
this.checkProgramId(instruction.programId);
|
|
148
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
149
|
-
const {
|
|
150
|
-
space
|
|
151
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.Allocate, instruction.data);
|
|
152
|
-
return {
|
|
153
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
154
|
-
space
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Decode an allocate with seed system instruction and retrieve the instruction params.
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
static decodeAllocateWithSeed(instruction) {
|
|
163
|
-
this.checkProgramId(instruction.programId);
|
|
164
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
165
|
-
const {
|
|
166
|
-
base,
|
|
167
|
-
seed,
|
|
168
|
-
space,
|
|
169
|
-
programId
|
|
170
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed, instruction.data);
|
|
171
|
-
return {
|
|
172
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
173
|
-
basePubkey: new _publickey.PublicKey(base),
|
|
174
|
-
seed,
|
|
175
|
-
space,
|
|
176
|
-
programId: new _publickey.PublicKey(programId)
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Decode an assign system instruction and retrieve the instruction params.
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
static decodeAssign(instruction) {
|
|
185
|
-
this.checkProgramId(instruction.programId);
|
|
186
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
187
|
-
const {
|
|
188
|
-
programId
|
|
189
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.Assign, instruction.data);
|
|
190
|
-
return {
|
|
191
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
192
|
-
programId: new _publickey.PublicKey(programId)
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Decode an assign with seed system instruction and retrieve the instruction params.
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
static decodeAssignWithSeed(instruction) {
|
|
201
|
-
this.checkProgramId(instruction.programId);
|
|
202
|
-
this.checkKeyLength(instruction.keys, 1);
|
|
203
|
-
const {
|
|
204
|
-
base,
|
|
205
|
-
seed,
|
|
206
|
-
programId
|
|
207
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.AssignWithSeed, instruction.data);
|
|
208
|
-
return {
|
|
209
|
-
accountPubkey: instruction.keys[0].pubkey,
|
|
210
|
-
basePubkey: new _publickey.PublicKey(base),
|
|
211
|
-
seed,
|
|
212
|
-
programId: new _publickey.PublicKey(programId)
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Decode a create account with seed system instruction and retrieve the instruction params.
|
|
217
|
-
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
static decodeCreateWithSeed(instruction) {
|
|
221
|
-
this.checkProgramId(instruction.programId);
|
|
222
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
223
|
-
const {
|
|
224
|
-
base,
|
|
225
|
-
seed,
|
|
226
|
-
lamports,
|
|
227
|
-
space,
|
|
228
|
-
programId
|
|
229
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.CreateWithSeed, instruction.data);
|
|
230
|
-
return {
|
|
231
|
-
fromPubkey: instruction.keys[0].pubkey,
|
|
232
|
-
newAccountPubkey: instruction.keys[1].pubkey,
|
|
233
|
-
basePubkey: new _publickey.PublicKey(base),
|
|
234
|
-
seed,
|
|
235
|
-
lamports,
|
|
236
|
-
space,
|
|
237
|
-
programId: new _publickey.PublicKey(programId)
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Decode a nonce initialize system instruction and retrieve the instruction params.
|
|
242
|
-
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
static decodeNonceInitialize(instruction) {
|
|
246
|
-
this.checkProgramId(instruction.programId);
|
|
247
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
248
|
-
const {
|
|
249
|
-
authorized
|
|
250
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.InitializeNonceAccount, instruction.data);
|
|
251
|
-
return {
|
|
252
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
253
|
-
authorizedPubkey: new _publickey.PublicKey(authorized)
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Decode a nonce advance system instruction and retrieve the instruction params.
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
static decodeNonceAdvance(instruction) {
|
|
262
|
-
this.checkProgramId(instruction.programId);
|
|
263
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
264
|
-
(0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount, instruction.data);
|
|
265
|
-
return {
|
|
266
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
267
|
-
authorizedPubkey: instruction.keys[2].pubkey
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Decode a nonce withdraw system instruction and retrieve the instruction params.
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
static decodeNonceWithdraw(instruction) {
|
|
276
|
-
this.checkProgramId(instruction.programId);
|
|
277
|
-
this.checkKeyLength(instruction.keys, 5);
|
|
278
|
-
const {
|
|
279
|
-
lamports
|
|
280
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount, instruction.data);
|
|
281
|
-
return {
|
|
282
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
283
|
-
toPubkey: instruction.keys[1].pubkey,
|
|
284
|
-
authorizedPubkey: instruction.keys[4].pubkey,
|
|
285
|
-
lamports
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Decode a nonce authorize system instruction and retrieve the instruction params.
|
|
290
|
-
*/
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
static decodeNonceAuthorize(instruction) {
|
|
294
|
-
this.checkProgramId(instruction.programId);
|
|
295
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
296
|
-
const {
|
|
297
|
-
authorized
|
|
298
|
-
} = (0, _instruction.decodeData)(SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount, instruction.data);
|
|
299
|
-
return {
|
|
300
|
-
noncePubkey: instruction.keys[0].pubkey,
|
|
301
|
-
authorizedPubkey: instruction.keys[1].pubkey,
|
|
302
|
-
newAuthorizedPubkey: new _publickey.PublicKey(authorized)
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* @private
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
static checkProgramId(programId) {
|
|
311
|
-
if (!programId.equals(SystemProgram.programId)) {
|
|
312
|
-
throw new Error('invalid instruction; programId is not SystemProgram');
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* @private
|
|
317
|
-
*/
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
static checkKeyLength(keys, expectedLength) {
|
|
321
|
-
if (keys.length < expectedLength) {
|
|
322
|
-
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Factory class for transactions to interact with the System program
|
|
329
|
-
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
exports.SystemInstruction = SystemInstruction;
|
|
333
|
-
|
|
334
|
-
class SystemProgram {
|
|
335
|
-
/**
|
|
336
|
-
* Public key that identifies the System program
|
|
337
|
-
*/
|
|
338
|
-
static get programId() {
|
|
339
|
-
return new _publickey.PublicKey('11111111111111111111111111111111');
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Generate a transaction instruction that creates a new account
|
|
343
|
-
*/
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
static createAccount(params) {
|
|
347
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Create;
|
|
348
|
-
const data = (0, _instruction.encodeData)(type, {
|
|
349
|
-
lamports: params.lamports,
|
|
350
|
-
space: params.space,
|
|
351
|
-
programId: params.programId.toBuffer()
|
|
352
|
-
});
|
|
353
|
-
return new _transaction.TransactionInstruction({
|
|
354
|
-
keys: [{
|
|
355
|
-
pubkey: params.fromPubkey,
|
|
356
|
-
isSigner: true,
|
|
357
|
-
isWritable: true
|
|
358
|
-
}, {
|
|
359
|
-
pubkey: params.newAccountPubkey,
|
|
360
|
-
isSigner: true,
|
|
361
|
-
isWritable: true
|
|
362
|
-
}],
|
|
363
|
-
programId: this.programId,
|
|
364
|
-
data
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Generate a transaction instruction that transfers lamports from one account to another
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
static transfer(params) {
|
|
373
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer;
|
|
374
|
-
const data = (0, _instruction.encodeData)(type, {
|
|
375
|
-
lamports: params.lamports
|
|
376
|
-
});
|
|
377
|
-
return new _transaction.TransactionInstruction({
|
|
378
|
-
keys: [{
|
|
379
|
-
pubkey: params.fromPubkey,
|
|
380
|
-
isSigner: true,
|
|
381
|
-
isWritable: true
|
|
382
|
-
}, {
|
|
383
|
-
pubkey: params.toPubkey,
|
|
384
|
-
isSigner: false,
|
|
385
|
-
isWritable: true
|
|
386
|
-
}],
|
|
387
|
-
programId: this.programId,
|
|
388
|
-
data
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Generate a transaction instruction that assigns an account to a program
|
|
393
|
-
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
static assign(params) {
|
|
397
|
-
let data;
|
|
398
|
-
|
|
399
|
-
if (params.basePubkey) {
|
|
400
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AssignWithSeed;
|
|
401
|
-
data = (0, _instruction.encodeData)(type, {
|
|
402
|
-
base: params.basePubkey.toBuffer(),
|
|
403
|
-
seed: params.seed,
|
|
404
|
-
programId: params.programId.toBuffer()
|
|
405
|
-
});
|
|
406
|
-
} else {
|
|
407
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Assign;
|
|
408
|
-
data = (0, _instruction.encodeData)(type, {
|
|
409
|
-
programId: params.programId.toBuffer()
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return new _transaction.TransactionInstruction({
|
|
414
|
-
keys: [{
|
|
415
|
-
pubkey: params.accountPubkey,
|
|
416
|
-
isSigner: true,
|
|
417
|
-
isWritable: true
|
|
418
|
-
}],
|
|
419
|
-
programId: this.programId,
|
|
420
|
-
data
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Generate a transaction instruction that creates a new account at
|
|
425
|
-
* an address generated with `from`, a seed, and programId
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
static createAccountWithSeed(params) {
|
|
430
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.CreateWithSeed;
|
|
431
|
-
const data = (0, _instruction.encodeData)(type, {
|
|
432
|
-
base: params.basePubkey.toBuffer(),
|
|
433
|
-
seed: params.seed,
|
|
434
|
-
lamports: params.lamports,
|
|
435
|
-
space: params.space,
|
|
436
|
-
programId: params.programId.toBuffer()
|
|
437
|
-
});
|
|
438
|
-
return new _transaction.TransactionInstruction({
|
|
439
|
-
keys: [{
|
|
440
|
-
pubkey: params.fromPubkey,
|
|
441
|
-
isSigner: true,
|
|
442
|
-
isWritable: true
|
|
443
|
-
}, {
|
|
444
|
-
pubkey: params.newAccountPubkey,
|
|
445
|
-
isSigner: false,
|
|
446
|
-
isWritable: true
|
|
447
|
-
}],
|
|
448
|
-
programId: this.programId,
|
|
449
|
-
data
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Generate a transaction that creates a new Nonce account
|
|
454
|
-
*/
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
static createNonceAccount(params) {
|
|
458
|
-
const transaction = new _transaction.Transaction();
|
|
459
|
-
|
|
460
|
-
if (params.basePubkey && params.seed) {
|
|
461
|
-
transaction.add(SystemProgram.createAccountWithSeed({
|
|
462
|
-
fromPubkey: params.fromPubkey,
|
|
463
|
-
newAccountPubkey: params.noncePubkey,
|
|
464
|
-
basePubkey: params.basePubkey,
|
|
465
|
-
seed: params.seed,
|
|
466
|
-
lamports: params.lamports,
|
|
467
|
-
space: _nonceAccount.NONCE_ACCOUNT_LENGTH,
|
|
468
|
-
programId: this.programId
|
|
469
|
-
}));
|
|
470
|
-
} else {
|
|
471
|
-
transaction.add(SystemProgram.createAccount({
|
|
472
|
-
fromPubkey: params.fromPubkey,
|
|
473
|
-
newAccountPubkey: params.noncePubkey,
|
|
474
|
-
lamports: params.lamports,
|
|
475
|
-
space: _nonceAccount.NONCE_ACCOUNT_LENGTH,
|
|
476
|
-
programId: this.programId
|
|
477
|
-
}));
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
const initParams = {
|
|
481
|
-
noncePubkey: params.noncePubkey,
|
|
482
|
-
authorizedPubkey: params.authorizedPubkey
|
|
483
|
-
};
|
|
484
|
-
transaction.add(this.nonceInitialize(initParams));
|
|
485
|
-
return transaction;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Generate an instruction to initialize a Nonce account
|
|
489
|
-
*/
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
static nonceInitialize(params) {
|
|
493
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.InitializeNonceAccount;
|
|
494
|
-
const data = (0, _instruction.encodeData)(type, {
|
|
495
|
-
authorized: params.authorizedPubkey.toBuffer()
|
|
496
|
-
});
|
|
497
|
-
const instructionData = {
|
|
498
|
-
keys: [{
|
|
499
|
-
pubkey: params.noncePubkey,
|
|
500
|
-
isSigner: false,
|
|
501
|
-
isWritable: true
|
|
502
|
-
}, {
|
|
503
|
-
pubkey: _sysvar.SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
504
|
-
isSigner: false,
|
|
505
|
-
isWritable: false
|
|
506
|
-
}, {
|
|
507
|
-
pubkey: _sysvar.SYSVAR_RENT_PUBKEY,
|
|
508
|
-
isSigner: false,
|
|
509
|
-
isWritable: false
|
|
510
|
-
}],
|
|
511
|
-
programId: this.programId,
|
|
512
|
-
data
|
|
513
|
-
};
|
|
514
|
-
return new _transaction.TransactionInstruction(instructionData);
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Generate an instruction to advance the nonce in a Nonce account
|
|
518
|
-
*/
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
static nonceAdvance(params) {
|
|
522
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount;
|
|
523
|
-
const data = (0, _instruction.encodeData)(type);
|
|
524
|
-
const instructionData = {
|
|
525
|
-
keys: [{
|
|
526
|
-
pubkey: params.noncePubkey,
|
|
527
|
-
isSigner: false,
|
|
528
|
-
isWritable: true
|
|
529
|
-
}, {
|
|
530
|
-
pubkey: _sysvar.SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
531
|
-
isSigner: false,
|
|
532
|
-
isWritable: false
|
|
533
|
-
}, {
|
|
534
|
-
pubkey: params.authorizedPubkey,
|
|
535
|
-
isSigner: true,
|
|
536
|
-
isWritable: false
|
|
537
|
-
}],
|
|
538
|
-
programId: this.programId,
|
|
539
|
-
data
|
|
540
|
-
};
|
|
541
|
-
return new _transaction.TransactionInstruction(instructionData);
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Generate a transaction instruction that withdraws lamports from a Nonce account
|
|
545
|
-
*/
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
static nonceWithdraw(params) {
|
|
549
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount;
|
|
550
|
-
const data = (0, _instruction.encodeData)(type, {
|
|
551
|
-
lamports: params.lamports
|
|
552
|
-
});
|
|
553
|
-
return new _transaction.TransactionInstruction({
|
|
554
|
-
keys: [{
|
|
555
|
-
pubkey: params.noncePubkey,
|
|
556
|
-
isSigner: false,
|
|
557
|
-
isWritable: true
|
|
558
|
-
}, {
|
|
559
|
-
pubkey: params.toPubkey,
|
|
560
|
-
isSigner: false,
|
|
561
|
-
isWritable: true
|
|
562
|
-
}, {
|
|
563
|
-
pubkey: _sysvar.SYSVAR_RECENT_BLOCKHASHES_PUBKEY,
|
|
564
|
-
isSigner: false,
|
|
565
|
-
isWritable: false
|
|
566
|
-
}, {
|
|
567
|
-
pubkey: _sysvar.SYSVAR_RENT_PUBKEY,
|
|
568
|
-
isSigner: false,
|
|
569
|
-
isWritable: false
|
|
570
|
-
}, {
|
|
571
|
-
pubkey: params.authorizedPubkey,
|
|
572
|
-
isSigner: true,
|
|
573
|
-
isWritable: false
|
|
574
|
-
}],
|
|
575
|
-
programId: this.programId,
|
|
576
|
-
data
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Generate a transaction instruction that authorizes a new PublicKey as the authority
|
|
581
|
-
* on a Nonce account.
|
|
582
|
-
*/
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
static nonceAuthorize(params) {
|
|
586
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount;
|
|
587
|
-
const data = (0, _instruction.encodeData)(type, {
|
|
588
|
-
authorized: params.newAuthorizedPubkey.toBuffer()
|
|
589
|
-
});
|
|
590
|
-
return new _transaction.TransactionInstruction({
|
|
591
|
-
keys: [{
|
|
592
|
-
pubkey: params.noncePubkey,
|
|
593
|
-
isSigner: false,
|
|
594
|
-
isWritable: true
|
|
595
|
-
}, {
|
|
596
|
-
pubkey: params.authorizedPubkey,
|
|
597
|
-
isSigner: true,
|
|
598
|
-
isWritable: false
|
|
599
|
-
}],
|
|
600
|
-
programId: this.programId,
|
|
601
|
-
data
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* Generate a transaction instruction that allocates space in an account without funding
|
|
606
|
-
*/
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
static allocate(params) {
|
|
610
|
-
let data;
|
|
611
|
-
|
|
612
|
-
if (params.basePubkey) {
|
|
613
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed;
|
|
614
|
-
data = (0, _instruction.encodeData)(type, {
|
|
615
|
-
base: params.basePubkey.toBuffer(),
|
|
616
|
-
seed: params.seed,
|
|
617
|
-
space: params.space,
|
|
618
|
-
programId: params.programId.toBuffer()
|
|
619
|
-
});
|
|
620
|
-
} else {
|
|
621
|
-
const type = SYSTEM_INSTRUCTION_LAYOUTS.Allocate;
|
|
622
|
-
data = (0, _instruction.encodeData)(type, {
|
|
623
|
-
space: params.space
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return new _transaction.TransactionInstruction({
|
|
628
|
-
keys: [{
|
|
629
|
-
pubkey: params.accountPubkey,
|
|
630
|
-
isSigner: true,
|
|
631
|
-
isWritable: true
|
|
632
|
-
}],
|
|
633
|
-
programId: this.programId,
|
|
634
|
-
data
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
exports.SystemProgram = SystemProgram;
|
package/lib/vendor/sysvar.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYSVAR_STAKE_HISTORY_PUBKEY = exports.SYSVAR_REWARDS_PUBKEY = exports.SYSVAR_RENT_PUBKEY = exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = exports.SYSVAR_CLOCK_PUBKEY = void 0;
|
|
7
|
-
|
|
8
|
-
var _publickey = require("./publickey");
|
|
9
|
-
|
|
10
|
-
const SYSVAR_CLOCK_PUBKEY = new _publickey.PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
11
|
-
exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
|
|
12
|
-
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new _publickey.PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
13
|
-
exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
|
|
14
|
-
const SYSVAR_RENT_PUBKEY = new _publickey.PublicKey('SysvarRent111111111111111111111111111111111');
|
|
15
|
-
exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
|
|
16
|
-
const SYSVAR_REWARDS_PUBKEY = new _publickey.PublicKey('SysvarRewards111111111111111111111111111111');
|
|
17
|
-
exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
|
|
18
|
-
const SYSVAR_STAKE_HISTORY_PUBKEY = new _publickey.PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
19
|
-
exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
|