@exodus/solana-lib 1.2.12 → 1.2.14
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/lib/constants.js +19 -0
- package/lib/encode.js +67 -0
- package/lib/fee-data/index.js +15 -0
- package/lib/fee-data/solana.js +14 -0
- package/lib/helpers/spl-token.js +122 -0
- package/lib/helpers/tokenTransfer.js +78 -0
- package/lib/index.js +88 -0
- package/lib/keypair.js +38 -0
- package/lib/tokens.js +21 -0
- package/lib/transaction.js +338 -0
- package/lib/tx/create-and-sign-tx.js +15 -0
- package/{src → lib}/tx/create-unsigned-tx.js +18 -11
- package/lib/tx/index.js +53 -0
- package/lib/tx/parse-unsigned-tx.js +55 -0
- package/lib/tx/sign-unsigned-tx.js +90 -0
- package/lib/vendor/account.js +48 -0
- package/lib/vendor/index.js +113 -0
- package/lib/vendor/instruction.js +48 -0
- package/lib/vendor/message.js +167 -0
- package/lib/vendor/nonce-account.js +56 -0
- package/lib/vendor/publickey.js +211 -0
- package/lib/vendor/stake-program.js +476 -0
- package/lib/vendor/system-program.js +640 -0
- package/lib/vendor/sysvar.js +19 -0
- package/lib/vendor/transaction.js +594 -0
- package/lib/vendor/utils/blockhash.js +1 -0
- package/lib/vendor/utils/fee-calculator.js +25 -0
- package/lib/vendor/utils/layout.js +97 -0
- package/lib/vendor/utils/shortvec-encoding.js +41 -0
- package/lib/vendor/utils/to-buffer.js +18 -0
- package/package.json +7 -8
- package/src/constants.js +0 -12
- package/src/encode.js +0 -57
- package/src/fee-data/index.js +0 -1
- package/src/fee-data/solana.js +0 -9
- package/src/helpers/spl-token.js +0 -108
- package/src/helpers/tokenTransfer.js +0 -72
- package/src/index.js +0 -9
- package/src/keypair.js +0 -32
- package/src/tokens.js +0 -19
- package/src/transaction.js +0 -292
- package/src/tx/create-and-sign-tx.js +0 -8
- package/src/tx/index.js +0 -4
- package/src/tx/parse-unsigned-tx.js +0 -41
- package/src/tx/sign-unsigned-tx.js +0 -78
- package/src/vendor/account.js +0 -38
- package/src/vendor/index.js +0 -9
- package/src/vendor/instruction.js +0 -46
- package/src/vendor/message.js +0 -216
- package/src/vendor/nonce-account.js +0 -46
- package/src/vendor/publickey.js +0 -212
- package/src/vendor/stake-program.js +0 -527
- package/src/vendor/system-program.js +0 -782
- package/src/vendor/sysvar.js +0 -16
- package/src/vendor/transaction.js +0 -594
- package/src/vendor/utils/blockhash.js +0 -6
- package/src/vendor/utils/fee-calculator.js +0 -17
- package/src/vendor/utils/layout.js +0 -80
- package/src/vendor/utils/shortvec-encoding.js +0 -30
- package/src/vendor/utils/to-buffer.js +0 -9
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StakeProgram = exports.StakeAuthorizationLayout = exports.StakeInstruction = exports.STAKE_INSTRUCTION_LAYOUTS = exports.Lockup = exports.Authorized = exports.STAKE_CONFIG_ID = 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 _publickey = require("./publickey");
|
|
15
|
+
|
|
16
|
+
var _systemProgram = require("./system-program");
|
|
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
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
|
|
28
|
+
const STAKE_CONFIG_ID = new _publickey.PublicKey('StakeConfig11111111111111111111111111111111');
|
|
29
|
+
exports.STAKE_CONFIG_ID = STAKE_CONFIG_ID;
|
|
30
|
+
|
|
31
|
+
class Authorized {
|
|
32
|
+
/**
|
|
33
|
+
* Create a new Authorized object
|
|
34
|
+
*/
|
|
35
|
+
constructor(staker, withdrawer) {
|
|
36
|
+
_defineProperty(this, "staker", void 0);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "withdrawer", void 0);
|
|
39
|
+
|
|
40
|
+
this.staker = staker;
|
|
41
|
+
this.withdrawer = withdrawer;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.Authorized = Authorized;
|
|
47
|
+
|
|
48
|
+
class Lockup {
|
|
49
|
+
/**
|
|
50
|
+
* Create a new Lockup object
|
|
51
|
+
*/
|
|
52
|
+
constructor(unixTimestamp, epoch, custodian) {
|
|
53
|
+
_defineProperty(this, "unixTimestamp", void 0);
|
|
54
|
+
|
|
55
|
+
_defineProperty(this, "epoch", void 0);
|
|
56
|
+
|
|
57
|
+
_defineProperty(this, "custodian", void 0);
|
|
58
|
+
|
|
59
|
+
this.unixTimestamp = unixTimestamp;
|
|
60
|
+
this.epoch = epoch;
|
|
61
|
+
this.custodian = custodian;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create stake account transaction params
|
|
67
|
+
* @typedef {Object} CreateStakeAccountParams
|
|
68
|
+
* @property {PublicKey} fromPubkey
|
|
69
|
+
* @property {PublicKey} stakePubkey
|
|
70
|
+
* @property {Authorized} authorized
|
|
71
|
+
* @property {Lockup} lockup
|
|
72
|
+
* @property {number} lamports
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
exports.Lockup = Lockup;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* An enumeration of valid stake InstructionType's
|
|
80
|
+
*/
|
|
81
|
+
const STAKE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
82
|
+
Initialize: {
|
|
83
|
+
index: 0,
|
|
84
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.authorized(), Layout.lockup()])
|
|
85
|
+
},
|
|
86
|
+
Authorize: {
|
|
87
|
+
index: 1,
|
|
88
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('newAuthorized'), BufferLayout.u32('stakeAuthorizationType')])
|
|
89
|
+
},
|
|
90
|
+
Delegate: {
|
|
91
|
+
index: 2,
|
|
92
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
93
|
+
},
|
|
94
|
+
Split: {
|
|
95
|
+
index: 3,
|
|
96
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
97
|
+
},
|
|
98
|
+
Withdraw: {
|
|
99
|
+
index: 4,
|
|
100
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
101
|
+
},
|
|
102
|
+
Deactivate: {
|
|
103
|
+
index: 5,
|
|
104
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
105
|
+
},
|
|
106
|
+
AuthorizeWithSeed: {
|
|
107
|
+
index: 8,
|
|
108
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), Layout.publicKey('newAuthorized'), BufferLayout.u32('stakeAuthorizationType'), Layout.rustString('authoritySeed'), Layout.publicKey('authorityOwner')])
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Stake Instruction class
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
|
|
116
|
+
|
|
117
|
+
class StakeInstruction {
|
|
118
|
+
/**
|
|
119
|
+
* Decode a stake instruction and retrieve the instruction type.
|
|
120
|
+
*/
|
|
121
|
+
static decodeInstructionType(instruction) {
|
|
122
|
+
this.checkProgramId(instruction.programId);
|
|
123
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
124
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
125
|
+
let type;
|
|
126
|
+
|
|
127
|
+
for (const t of Object.keys(STAKE_INSTRUCTION_LAYOUTS)) {
|
|
128
|
+
if (STAKE_INSTRUCTION_LAYOUTS[t].index === typeIndex) {
|
|
129
|
+
type = t;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!type) {
|
|
134
|
+
throw new Error('Instruction type incorrect; not a StakeInstruction');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return type;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Decode a initialize stake instruction and retrieve the instruction params.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
static decodeInitialize(instruction) {
|
|
145
|
+
this.checkProgramId(instruction.programId);
|
|
146
|
+
this.checkKeyLength(instruction.keys, 2);
|
|
147
|
+
const {
|
|
148
|
+
authorized,
|
|
149
|
+
lockup
|
|
150
|
+
} = (0, _instruction.decodeData)(STAKE_INSTRUCTION_LAYOUTS.Initialize, instruction.data);
|
|
151
|
+
return {
|
|
152
|
+
stakePubkey: instruction.keys[0].pubkey,
|
|
153
|
+
authorized: new Authorized(new _publickey.PublicKey(authorized.staker), new _publickey.PublicKey(authorized.withdrawer)),
|
|
154
|
+
lockup: new Lockup(lockup.unixTimestamp, lockup.epoch, new _publickey.PublicKey(lockup.custodian))
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Decode a delegate stake instruction and retrieve the instruction params.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
static decodeDelegate(instruction) {
|
|
163
|
+
this.checkProgramId(instruction.programId);
|
|
164
|
+
this.checkKeyLength(instruction.keys, 6);
|
|
165
|
+
(0, _instruction.decodeData)(STAKE_INSTRUCTION_LAYOUTS.Delegate, instruction.data);
|
|
166
|
+
return {
|
|
167
|
+
stakePubkey: instruction.keys[0].pubkey,
|
|
168
|
+
votePubkey: instruction.keys[1].pubkey,
|
|
169
|
+
authorizedPubkey: instruction.keys[5].pubkey
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Decode a withdraw stake instruction and retrieve the instruction params.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
static decodeWithdraw(instruction) {
|
|
178
|
+
this.checkProgramId(instruction.programId);
|
|
179
|
+
this.checkKeyLength(instruction.keys, 5);
|
|
180
|
+
const {
|
|
181
|
+
lamports
|
|
182
|
+
} = (0, _instruction.decodeData)(STAKE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
183
|
+
return {
|
|
184
|
+
stakePubkey: instruction.keys[0].pubkey,
|
|
185
|
+
toPubkey: instruction.keys[1].pubkey,
|
|
186
|
+
authorizedPubkey: instruction.keys[4].pubkey,
|
|
187
|
+
lamports
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Decode a deactivate stake instruction and retrieve the instruction params.
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
static decodeDeactivate(instruction) {
|
|
196
|
+
this.checkProgramId(instruction.programId);
|
|
197
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
198
|
+
(0, _instruction.decodeData)(STAKE_INSTRUCTION_LAYOUTS.Deactivate, instruction.data);
|
|
199
|
+
return {
|
|
200
|
+
stakePubkey: instruction.keys[0].pubkey,
|
|
201
|
+
authorizedPubkey: instruction.keys[2].pubkey
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @private
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
static checkProgramId(programId) {
|
|
210
|
+
if (!programId.equals(StakeProgram.programId)) {
|
|
211
|
+
throw new Error('invalid instruction; programId is not StakeProgram');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
static checkKeyLength(keys, expectedLength) {
|
|
220
|
+
if (keys.length < expectedLength) {
|
|
221
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* An enumeration of valid StakeAuthorizationLayout's
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
exports.StakeInstruction = StakeInstruction;
|
|
232
|
+
const StakeAuthorizationLayout = Object.freeze({
|
|
233
|
+
Staker: {
|
|
234
|
+
index: 0
|
|
235
|
+
},
|
|
236
|
+
Withdrawer: {
|
|
237
|
+
index: 1
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
/**
|
|
241
|
+
* Factory class for transactions to interact with the Stake program
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
exports.StakeAuthorizationLayout = StakeAuthorizationLayout;
|
|
245
|
+
|
|
246
|
+
class StakeProgram {
|
|
247
|
+
/**
|
|
248
|
+
* Public key that identifies the Stake program
|
|
249
|
+
*/
|
|
250
|
+
static get programId() {
|
|
251
|
+
return new _publickey.PublicKey('Stake11111111111111111111111111111111111111');
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Max space of a Stake account
|
|
255
|
+
*
|
|
256
|
+
* This is generated from the solana-stake-program StakeState struct as
|
|
257
|
+
* `std::mem::size_of::<StakeState>()`:
|
|
258
|
+
* https://docs.rs/solana-stake-program/1.4.4/solana_stake_program/stake_state/enum.StakeState.html
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
static get space() {
|
|
263
|
+
return 200;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Generate an Initialize instruction to add to a Stake Create transaction
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
static initialize(params) {
|
|
271
|
+
const {
|
|
272
|
+
stakePubkey,
|
|
273
|
+
authorized,
|
|
274
|
+
lockup
|
|
275
|
+
} = params;
|
|
276
|
+
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
277
|
+
const data = (0, _instruction.encodeData)(type, {
|
|
278
|
+
authorized: {
|
|
279
|
+
staker: authorized.staker.toBuffer(),
|
|
280
|
+
withdrawer: authorized.withdrawer.toBuffer()
|
|
281
|
+
},
|
|
282
|
+
lockup: {
|
|
283
|
+
unixTimestamp: lockup.unixTimestamp,
|
|
284
|
+
epoch: lockup.epoch,
|
|
285
|
+
custodian: lockup.custodian.toBuffer()
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const instructionData = {
|
|
289
|
+
keys: [{
|
|
290
|
+
pubkey: stakePubkey,
|
|
291
|
+
isSigner: false,
|
|
292
|
+
isWritable: true
|
|
293
|
+
}, {
|
|
294
|
+
pubkey: _sysvar.SYSVAR_RENT_PUBKEY,
|
|
295
|
+
isSigner: false,
|
|
296
|
+
isWritable: false
|
|
297
|
+
}],
|
|
298
|
+
programId: this.programId,
|
|
299
|
+
data
|
|
300
|
+
};
|
|
301
|
+
return new _transaction.TransactionInstruction(instructionData);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Generate a Transaction that creates a new Stake account at
|
|
305
|
+
* an address generated with `from`, a seed, and the Stake programId
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
static createAccountWithSeed(params) {
|
|
310
|
+
const transaction = new _transaction.Transaction();
|
|
311
|
+
transaction.add(_systemProgram.SystemProgram.createAccountWithSeed({
|
|
312
|
+
fromPubkey: params.fromPubkey,
|
|
313
|
+
newAccountPubkey: params.stakePubkey,
|
|
314
|
+
basePubkey: params.basePubkey,
|
|
315
|
+
seed: params.seed,
|
|
316
|
+
lamports: params.lamports,
|
|
317
|
+
space: this.space,
|
|
318
|
+
programId: this.programId
|
|
319
|
+
}));
|
|
320
|
+
const {
|
|
321
|
+
stakePubkey,
|
|
322
|
+
authorized,
|
|
323
|
+
lockup
|
|
324
|
+
} = params;
|
|
325
|
+
return transaction.add(this.initialize({
|
|
326
|
+
stakePubkey,
|
|
327
|
+
authorized,
|
|
328
|
+
lockup
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Generate a Transaction that creates a new Stake account
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
static createAccount(params) {
|
|
337
|
+
const transaction = new _transaction.Transaction();
|
|
338
|
+
transaction.add(_systemProgram.SystemProgram.createAccount({
|
|
339
|
+
fromPubkey: params.fromPubkey,
|
|
340
|
+
newAccountPubkey: params.stakePubkey,
|
|
341
|
+
lamports: params.lamports,
|
|
342
|
+
space: this.space,
|
|
343
|
+
programId: this.programId
|
|
344
|
+
}));
|
|
345
|
+
const {
|
|
346
|
+
stakePubkey,
|
|
347
|
+
authorized,
|
|
348
|
+
lockup
|
|
349
|
+
} = params;
|
|
350
|
+
return transaction.add(this.initialize({
|
|
351
|
+
stakePubkey,
|
|
352
|
+
authorized,
|
|
353
|
+
lockup
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Generate a Transaction that delegates Stake tokens to a validator
|
|
358
|
+
* Vote PublicKey. This transaction can also be used to redelegate Stake
|
|
359
|
+
* to a new validator Vote PublicKey.
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
static delegate(params) {
|
|
364
|
+
const {
|
|
365
|
+
stakePubkey,
|
|
366
|
+
authorizedPubkey,
|
|
367
|
+
votePubkey
|
|
368
|
+
} = params;
|
|
369
|
+
const type = STAKE_INSTRUCTION_LAYOUTS.Delegate;
|
|
370
|
+
const data = (0, _instruction.encodeData)(type);
|
|
371
|
+
return new _transaction.Transaction().add({
|
|
372
|
+
keys: [{
|
|
373
|
+
pubkey: stakePubkey,
|
|
374
|
+
isSigner: false,
|
|
375
|
+
isWritable: true
|
|
376
|
+
}, {
|
|
377
|
+
pubkey: votePubkey,
|
|
378
|
+
isSigner: false,
|
|
379
|
+
isWritable: false
|
|
380
|
+
}, {
|
|
381
|
+
pubkey: _sysvar.SYSVAR_CLOCK_PUBKEY,
|
|
382
|
+
isSigner: false,
|
|
383
|
+
isWritable: false
|
|
384
|
+
}, {
|
|
385
|
+
pubkey: _sysvar.SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
386
|
+
isSigner: false,
|
|
387
|
+
isWritable: false
|
|
388
|
+
}, {
|
|
389
|
+
pubkey: STAKE_CONFIG_ID,
|
|
390
|
+
isSigner: false,
|
|
391
|
+
isWritable: false
|
|
392
|
+
}, {
|
|
393
|
+
pubkey: authorizedPubkey,
|
|
394
|
+
isSigner: true,
|
|
395
|
+
isWritable: false
|
|
396
|
+
}],
|
|
397
|
+
programId: this.programId,
|
|
398
|
+
data
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Generate a Transaction that withdraws deactivated Stake tokens.
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
static withdraw(params) {
|
|
407
|
+
const {
|
|
408
|
+
stakePubkey,
|
|
409
|
+
authorizedPubkey,
|
|
410
|
+
toPubkey,
|
|
411
|
+
lamports
|
|
412
|
+
} = params;
|
|
413
|
+
const type = STAKE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
414
|
+
const data = (0, _instruction.encodeData)(type, {
|
|
415
|
+
lamports
|
|
416
|
+
});
|
|
417
|
+
return new _transaction.Transaction().add({
|
|
418
|
+
keys: [{
|
|
419
|
+
pubkey: stakePubkey,
|
|
420
|
+
isSigner: false,
|
|
421
|
+
isWritable: true
|
|
422
|
+
}, {
|
|
423
|
+
pubkey: toPubkey,
|
|
424
|
+
isSigner: false,
|
|
425
|
+
isWritable: true
|
|
426
|
+
}, {
|
|
427
|
+
pubkey: _sysvar.SYSVAR_CLOCK_PUBKEY,
|
|
428
|
+
isSigner: false,
|
|
429
|
+
isWritable: false
|
|
430
|
+
}, {
|
|
431
|
+
pubkey: _sysvar.SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
432
|
+
isSigner: false,
|
|
433
|
+
isWritable: false
|
|
434
|
+
}, {
|
|
435
|
+
pubkey: authorizedPubkey,
|
|
436
|
+
isSigner: true,
|
|
437
|
+
isWritable: false
|
|
438
|
+
}],
|
|
439
|
+
programId: this.programId,
|
|
440
|
+
data
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Generate a Transaction that deactivates Stake tokens.
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
static deactivate(params) {
|
|
449
|
+
const {
|
|
450
|
+
stakePubkey,
|
|
451
|
+
authorizedPubkey
|
|
452
|
+
} = params;
|
|
453
|
+
const type = STAKE_INSTRUCTION_LAYOUTS.Deactivate;
|
|
454
|
+
const data = (0, _instruction.encodeData)(type);
|
|
455
|
+
return new _transaction.Transaction().add({
|
|
456
|
+
keys: [{
|
|
457
|
+
pubkey: stakePubkey,
|
|
458
|
+
isSigner: false,
|
|
459
|
+
isWritable: true
|
|
460
|
+
}, {
|
|
461
|
+
pubkey: _sysvar.SYSVAR_CLOCK_PUBKEY,
|
|
462
|
+
isSigner: false,
|
|
463
|
+
isWritable: false
|
|
464
|
+
}, {
|
|
465
|
+
pubkey: authorizedPubkey,
|
|
466
|
+
isSigner: true,
|
|
467
|
+
isWritable: false
|
|
468
|
+
}],
|
|
469
|
+
programId: this.programId,
|
|
470
|
+
data
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
exports.StakeProgram = StakeProgram;
|