@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/stake.ts
DELETED
|
@@ -1,935 +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 {PublicKey} from '../publickey';
|
|
11
|
-
import {SystemProgram} from './system';
|
|
12
|
-
import {
|
|
13
|
-
SYSVAR_CLOCK_PUBKEY,
|
|
14
|
-
SYSVAR_RENT_PUBKEY,
|
|
15
|
-
SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
16
|
-
} from '../sysvar';
|
|
17
|
-
import {Transaction, TransactionInstruction} from '../transaction';
|
|
18
|
-
import {toBuffer} from '../utils/to-buffer';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Address of the stake config account which configures the rate
|
|
22
|
-
* of stake warmup and cooldown as well as the slashing penalty.
|
|
23
|
-
*/
|
|
24
|
-
export const STAKE_CONFIG_ID = new PublicKey(
|
|
25
|
-
'StakeConfig11111111111111111111111111111111',
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Stake account authority info
|
|
30
|
-
*/
|
|
31
|
-
export class Authorized {
|
|
32
|
-
/** stake authority */
|
|
33
|
-
staker: PublicKey;
|
|
34
|
-
/** withdraw authority */
|
|
35
|
-
withdrawer: PublicKey;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Create a new Authorized object
|
|
39
|
-
* @param staker the stake authority
|
|
40
|
-
* @param withdrawer the withdraw authority
|
|
41
|
-
*/
|
|
42
|
-
constructor(staker: PublicKey, withdrawer: PublicKey) {
|
|
43
|
-
this.staker = staker;
|
|
44
|
-
this.withdrawer = withdrawer;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type AuthorizedRaw = Readonly<{
|
|
49
|
-
staker: Uint8Array;
|
|
50
|
-
withdrawer: Uint8Array;
|
|
51
|
-
}>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Stake account lockup info
|
|
55
|
-
*/
|
|
56
|
-
export class Lockup {
|
|
57
|
-
/** Unix timestamp of lockup expiration */
|
|
58
|
-
unixTimestamp: number;
|
|
59
|
-
/** Epoch of lockup expiration */
|
|
60
|
-
epoch: number;
|
|
61
|
-
/** Lockup custodian authority */
|
|
62
|
-
custodian: PublicKey;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Create a new Lockup object
|
|
66
|
-
*/
|
|
67
|
-
constructor(unixTimestamp: number, epoch: number, custodian: PublicKey) {
|
|
68
|
-
this.unixTimestamp = unixTimestamp;
|
|
69
|
-
this.epoch = epoch;
|
|
70
|
-
this.custodian = custodian;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Default, inactive Lockup value
|
|
75
|
-
*/
|
|
76
|
-
static default: Lockup = new Lockup(0, 0, PublicKey.default);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type LockupRaw = Readonly<{
|
|
80
|
-
custodian: Uint8Array;
|
|
81
|
-
epoch: number;
|
|
82
|
-
unixTimestamp: number;
|
|
83
|
-
}>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Create stake account transaction params
|
|
87
|
-
*/
|
|
88
|
-
export type CreateStakeAccountParams = {
|
|
89
|
-
/** Address of the account which will fund creation */
|
|
90
|
-
fromPubkey: PublicKey;
|
|
91
|
-
/** Address of the new stake account */
|
|
92
|
-
stakePubkey: PublicKey;
|
|
93
|
-
/** Authorities of the new stake account */
|
|
94
|
-
authorized: Authorized;
|
|
95
|
-
/** Lockup of the new stake account */
|
|
96
|
-
lockup?: Lockup;
|
|
97
|
-
/** Funding amount */
|
|
98
|
-
lamports: number;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Create stake account with seed transaction params
|
|
103
|
-
*/
|
|
104
|
-
export type CreateStakeAccountWithSeedParams = {
|
|
105
|
-
fromPubkey: PublicKey;
|
|
106
|
-
stakePubkey: PublicKey;
|
|
107
|
-
basePubkey: PublicKey;
|
|
108
|
-
seed: string;
|
|
109
|
-
authorized: Authorized;
|
|
110
|
-
lockup?: Lockup;
|
|
111
|
-
lamports: number;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Initialize stake instruction params
|
|
116
|
-
*/
|
|
117
|
-
export type InitializeStakeParams = {
|
|
118
|
-
stakePubkey: PublicKey;
|
|
119
|
-
authorized: Authorized;
|
|
120
|
-
lockup?: Lockup;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Delegate stake instruction params
|
|
125
|
-
*/
|
|
126
|
-
export type DelegateStakeParams = {
|
|
127
|
-
stakePubkey: PublicKey;
|
|
128
|
-
authorizedPubkey: PublicKey;
|
|
129
|
-
votePubkey: PublicKey;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Authorize stake instruction params
|
|
134
|
-
*/
|
|
135
|
-
export type AuthorizeStakeParams = {
|
|
136
|
-
stakePubkey: PublicKey;
|
|
137
|
-
authorizedPubkey: PublicKey;
|
|
138
|
-
newAuthorizedPubkey: PublicKey;
|
|
139
|
-
stakeAuthorizationType: StakeAuthorizationType;
|
|
140
|
-
custodianPubkey?: PublicKey;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Authorize stake instruction params using a derived key
|
|
145
|
-
*/
|
|
146
|
-
export type AuthorizeWithSeedStakeParams = {
|
|
147
|
-
stakePubkey: PublicKey;
|
|
148
|
-
authorityBase: PublicKey;
|
|
149
|
-
authoritySeed: string;
|
|
150
|
-
authorityOwner: PublicKey;
|
|
151
|
-
newAuthorizedPubkey: PublicKey;
|
|
152
|
-
stakeAuthorizationType: StakeAuthorizationType;
|
|
153
|
-
custodianPubkey?: PublicKey;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Split stake instruction params
|
|
158
|
-
*/
|
|
159
|
-
export type SplitStakeParams = {
|
|
160
|
-
stakePubkey: PublicKey;
|
|
161
|
-
authorizedPubkey: PublicKey;
|
|
162
|
-
splitStakePubkey: PublicKey;
|
|
163
|
-
lamports: number;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Split with seed transaction params
|
|
168
|
-
*/
|
|
169
|
-
export type SplitStakeWithSeedParams = {
|
|
170
|
-
stakePubkey: PublicKey;
|
|
171
|
-
authorizedPubkey: PublicKey;
|
|
172
|
-
splitStakePubkey: PublicKey;
|
|
173
|
-
basePubkey: PublicKey;
|
|
174
|
-
seed: string;
|
|
175
|
-
lamports: number;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Withdraw stake instruction params
|
|
180
|
-
*/
|
|
181
|
-
export type WithdrawStakeParams = {
|
|
182
|
-
stakePubkey: PublicKey;
|
|
183
|
-
authorizedPubkey: PublicKey;
|
|
184
|
-
toPubkey: PublicKey;
|
|
185
|
-
lamports: number;
|
|
186
|
-
custodianPubkey?: PublicKey;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Deactivate stake instruction params
|
|
191
|
-
*/
|
|
192
|
-
export type DeactivateStakeParams = {
|
|
193
|
-
stakePubkey: PublicKey;
|
|
194
|
-
authorizedPubkey: PublicKey;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Merge stake instruction params
|
|
199
|
-
*/
|
|
200
|
-
export type MergeStakeParams = {
|
|
201
|
-
stakePubkey: PublicKey;
|
|
202
|
-
sourceStakePubKey: PublicKey;
|
|
203
|
-
authorizedPubkey: PublicKey;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Stake Instruction class
|
|
208
|
-
*/
|
|
209
|
-
export class StakeInstruction {
|
|
210
|
-
/**
|
|
211
|
-
* @internal
|
|
212
|
-
*/
|
|
213
|
-
constructor() {}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Decode a stake instruction and retrieve the instruction type.
|
|
217
|
-
*/
|
|
218
|
-
static decodeInstructionType(
|
|
219
|
-
instruction: TransactionInstruction,
|
|
220
|
-
): StakeInstructionType {
|
|
221
|
-
this.checkProgramId(instruction.programId);
|
|
222
|
-
|
|
223
|
-
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
224
|
-
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
225
|
-
|
|
226
|
-
let type: StakeInstructionType | undefined;
|
|
227
|
-
for (const [ixType, layout] of Object.entries(STAKE_INSTRUCTION_LAYOUTS)) {
|
|
228
|
-
if (layout.index == typeIndex) {
|
|
229
|
-
type = ixType as StakeInstructionType;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (!type) {
|
|
235
|
-
throw new Error('Instruction type incorrect; not a StakeInstruction');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return type;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Decode a initialize stake instruction and retrieve the instruction params.
|
|
243
|
-
*/
|
|
244
|
-
static decodeInitialize(
|
|
245
|
-
instruction: TransactionInstruction,
|
|
246
|
-
): InitializeStakeParams {
|
|
247
|
-
this.checkProgramId(instruction.programId);
|
|
248
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
249
|
-
|
|
250
|
-
const {authorized, lockup} = decodeData(
|
|
251
|
-
STAKE_INSTRUCTION_LAYOUTS.Initialize,
|
|
252
|
-
instruction.data,
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
return {
|
|
256
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
257
|
-
authorized: new Authorized(
|
|
258
|
-
new PublicKey(authorized.staker),
|
|
259
|
-
new PublicKey(authorized.withdrawer),
|
|
260
|
-
),
|
|
261
|
-
lockup: new Lockup(
|
|
262
|
-
lockup.unixTimestamp,
|
|
263
|
-
lockup.epoch,
|
|
264
|
-
new PublicKey(lockup.custodian),
|
|
265
|
-
),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Decode a delegate stake instruction and retrieve the instruction params.
|
|
271
|
-
*/
|
|
272
|
-
static decodeDelegate(
|
|
273
|
-
instruction: TransactionInstruction,
|
|
274
|
-
): DelegateStakeParams {
|
|
275
|
-
this.checkProgramId(instruction.programId);
|
|
276
|
-
this.checkKeyLength(instruction.keys, 6);
|
|
277
|
-
decodeData(STAKE_INSTRUCTION_LAYOUTS.Delegate, instruction.data);
|
|
278
|
-
|
|
279
|
-
return {
|
|
280
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
281
|
-
votePubkey: instruction.keys[1].pubkey,
|
|
282
|
-
authorizedPubkey: instruction.keys[5].pubkey,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Decode an authorize stake instruction and retrieve the instruction params.
|
|
288
|
-
*/
|
|
289
|
-
static decodeAuthorize(
|
|
290
|
-
instruction: TransactionInstruction,
|
|
291
|
-
): AuthorizeStakeParams {
|
|
292
|
-
this.checkProgramId(instruction.programId);
|
|
293
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
294
|
-
const {newAuthorized, stakeAuthorizationType} = decodeData(
|
|
295
|
-
STAKE_INSTRUCTION_LAYOUTS.Authorize,
|
|
296
|
-
instruction.data,
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
const o: AuthorizeStakeParams = {
|
|
300
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
301
|
-
authorizedPubkey: instruction.keys[2].pubkey,
|
|
302
|
-
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
303
|
-
stakeAuthorizationType: {
|
|
304
|
-
index: stakeAuthorizationType,
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
if (instruction.keys.length > 3) {
|
|
308
|
-
o.custodianPubkey = instruction.keys[3].pubkey;
|
|
309
|
-
}
|
|
310
|
-
return o;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Decode an authorize-with-seed stake instruction and retrieve the instruction params.
|
|
315
|
-
*/
|
|
316
|
-
static decodeAuthorizeWithSeed(
|
|
317
|
-
instruction: TransactionInstruction,
|
|
318
|
-
): AuthorizeWithSeedStakeParams {
|
|
319
|
-
this.checkProgramId(instruction.programId);
|
|
320
|
-
this.checkKeyLength(instruction.keys, 2);
|
|
321
|
-
|
|
322
|
-
const {
|
|
323
|
-
newAuthorized,
|
|
324
|
-
stakeAuthorizationType,
|
|
325
|
-
authoritySeed,
|
|
326
|
-
authorityOwner,
|
|
327
|
-
} = decodeData(
|
|
328
|
-
STAKE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed,
|
|
329
|
-
instruction.data,
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
const o: AuthorizeWithSeedStakeParams = {
|
|
333
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
334
|
-
authorityBase: instruction.keys[1].pubkey,
|
|
335
|
-
authoritySeed: authoritySeed,
|
|
336
|
-
authorityOwner: new PublicKey(authorityOwner),
|
|
337
|
-
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
338
|
-
stakeAuthorizationType: {
|
|
339
|
-
index: stakeAuthorizationType,
|
|
340
|
-
},
|
|
341
|
-
};
|
|
342
|
-
if (instruction.keys.length > 3) {
|
|
343
|
-
o.custodianPubkey = instruction.keys[3].pubkey;
|
|
344
|
-
}
|
|
345
|
-
return o;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Decode a split stake instruction and retrieve the instruction params.
|
|
350
|
-
*/
|
|
351
|
-
static decodeSplit(instruction: TransactionInstruction): SplitStakeParams {
|
|
352
|
-
this.checkProgramId(instruction.programId);
|
|
353
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
354
|
-
const {lamports} = decodeData(
|
|
355
|
-
STAKE_INSTRUCTION_LAYOUTS.Split,
|
|
356
|
-
instruction.data,
|
|
357
|
-
);
|
|
358
|
-
|
|
359
|
-
return {
|
|
360
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
361
|
-
splitStakePubkey: instruction.keys[1].pubkey,
|
|
362
|
-
authorizedPubkey: instruction.keys[2].pubkey,
|
|
363
|
-
lamports,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Decode a merge stake instruction and retrieve the instruction params.
|
|
369
|
-
*/
|
|
370
|
-
static decodeMerge(instruction: TransactionInstruction): MergeStakeParams {
|
|
371
|
-
this.checkProgramId(instruction.programId);
|
|
372
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
373
|
-
decodeData(STAKE_INSTRUCTION_LAYOUTS.Merge, instruction.data);
|
|
374
|
-
|
|
375
|
-
return {
|
|
376
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
377
|
-
sourceStakePubKey: instruction.keys[1].pubkey,
|
|
378
|
-
authorizedPubkey: instruction.keys[4].pubkey,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Decode a withdraw stake instruction and retrieve the instruction params.
|
|
384
|
-
*/
|
|
385
|
-
static decodeWithdraw(
|
|
386
|
-
instruction: TransactionInstruction,
|
|
387
|
-
): WithdrawStakeParams {
|
|
388
|
-
this.checkProgramId(instruction.programId);
|
|
389
|
-
this.checkKeyLength(instruction.keys, 5);
|
|
390
|
-
const {lamports} = decodeData(
|
|
391
|
-
STAKE_INSTRUCTION_LAYOUTS.Withdraw,
|
|
392
|
-
instruction.data,
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
const o: WithdrawStakeParams = {
|
|
396
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
397
|
-
toPubkey: instruction.keys[1].pubkey,
|
|
398
|
-
authorizedPubkey: instruction.keys[4].pubkey,
|
|
399
|
-
lamports,
|
|
400
|
-
};
|
|
401
|
-
if (instruction.keys.length > 5) {
|
|
402
|
-
o.custodianPubkey = instruction.keys[5].pubkey;
|
|
403
|
-
}
|
|
404
|
-
return o;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Decode a deactivate stake instruction and retrieve the instruction params.
|
|
409
|
-
*/
|
|
410
|
-
static decodeDeactivate(
|
|
411
|
-
instruction: TransactionInstruction,
|
|
412
|
-
): DeactivateStakeParams {
|
|
413
|
-
this.checkProgramId(instruction.programId);
|
|
414
|
-
this.checkKeyLength(instruction.keys, 3);
|
|
415
|
-
decodeData(STAKE_INSTRUCTION_LAYOUTS.Deactivate, instruction.data);
|
|
416
|
-
|
|
417
|
-
return {
|
|
418
|
-
stakePubkey: instruction.keys[0].pubkey,
|
|
419
|
-
authorizedPubkey: instruction.keys[2].pubkey,
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* @internal
|
|
425
|
-
*/
|
|
426
|
-
static checkProgramId(programId: PublicKey) {
|
|
427
|
-
if (!programId.equals(StakeProgram.programId)) {
|
|
428
|
-
throw new Error('invalid instruction; programId is not StakeProgram');
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* @internal
|
|
434
|
-
*/
|
|
435
|
-
static checkKeyLength(keys: Array<any>, expectedLength: number) {
|
|
436
|
-
if (keys.length < expectedLength) {
|
|
437
|
-
throw new Error(
|
|
438
|
-
`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`,
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* An enumeration of valid StakeInstructionType's
|
|
446
|
-
*/
|
|
447
|
-
export type StakeInstructionType =
|
|
448
|
-
// FIXME
|
|
449
|
-
// It would be preferable for this type to be `keyof StakeInstructionInputData`
|
|
450
|
-
// but Typedoc does not transpile `keyof` expressions.
|
|
451
|
-
// See https://github.com/TypeStrong/typedoc/issues/1894
|
|
452
|
-
| 'Authorize'
|
|
453
|
-
| 'AuthorizeWithSeed'
|
|
454
|
-
| 'Deactivate'
|
|
455
|
-
| 'Delegate'
|
|
456
|
-
| 'Initialize'
|
|
457
|
-
| 'Merge'
|
|
458
|
-
| 'Split'
|
|
459
|
-
| 'Withdraw';
|
|
460
|
-
|
|
461
|
-
type StakeInstructionInputData = {
|
|
462
|
-
Authorize: IInstructionInputData &
|
|
463
|
-
Readonly<{
|
|
464
|
-
newAuthorized: Uint8Array;
|
|
465
|
-
stakeAuthorizationType: number;
|
|
466
|
-
}>;
|
|
467
|
-
AuthorizeWithSeed: IInstructionInputData &
|
|
468
|
-
Readonly<{
|
|
469
|
-
authorityOwner: Uint8Array;
|
|
470
|
-
authoritySeed: string;
|
|
471
|
-
instruction: number;
|
|
472
|
-
newAuthorized: Uint8Array;
|
|
473
|
-
stakeAuthorizationType: number;
|
|
474
|
-
}>;
|
|
475
|
-
Deactivate: IInstructionInputData;
|
|
476
|
-
Delegate: IInstructionInputData;
|
|
477
|
-
Initialize: IInstructionInputData &
|
|
478
|
-
Readonly<{
|
|
479
|
-
authorized: AuthorizedRaw;
|
|
480
|
-
lockup: LockupRaw;
|
|
481
|
-
}>;
|
|
482
|
-
Merge: IInstructionInputData;
|
|
483
|
-
Split: IInstructionInputData &
|
|
484
|
-
Readonly<{
|
|
485
|
-
lamports: number;
|
|
486
|
-
}>;
|
|
487
|
-
Withdraw: IInstructionInputData &
|
|
488
|
-
Readonly<{
|
|
489
|
-
lamports: number;
|
|
490
|
-
}>;
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* An enumeration of valid stake InstructionType's
|
|
495
|
-
* @internal
|
|
496
|
-
*/
|
|
497
|
-
export const STAKE_INSTRUCTION_LAYOUTS = Object.freeze<{
|
|
498
|
-
[Instruction in StakeInstructionType]: InstructionType<
|
|
499
|
-
StakeInstructionInputData[Instruction]
|
|
500
|
-
>;
|
|
501
|
-
}>({
|
|
502
|
-
Initialize: {
|
|
503
|
-
index: 0,
|
|
504
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Initialize']>([
|
|
505
|
-
BufferLayout.u32('instruction'),
|
|
506
|
-
Layout.authorized(),
|
|
507
|
-
Layout.lockup(),
|
|
508
|
-
]),
|
|
509
|
-
},
|
|
510
|
-
Authorize: {
|
|
511
|
-
index: 1,
|
|
512
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Authorize']>([
|
|
513
|
-
BufferLayout.u32('instruction'),
|
|
514
|
-
Layout.publicKey('newAuthorized'),
|
|
515
|
-
BufferLayout.u32('stakeAuthorizationType'),
|
|
516
|
-
]),
|
|
517
|
-
},
|
|
518
|
-
Delegate: {
|
|
519
|
-
index: 2,
|
|
520
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Delegate']>([
|
|
521
|
-
BufferLayout.u32('instruction'),
|
|
522
|
-
]),
|
|
523
|
-
},
|
|
524
|
-
Split: {
|
|
525
|
-
index: 3,
|
|
526
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Split']>([
|
|
527
|
-
BufferLayout.u32('instruction'),
|
|
528
|
-
BufferLayout.ns64('lamports'),
|
|
529
|
-
]),
|
|
530
|
-
},
|
|
531
|
-
Withdraw: {
|
|
532
|
-
index: 4,
|
|
533
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Withdraw']>([
|
|
534
|
-
BufferLayout.u32('instruction'),
|
|
535
|
-
BufferLayout.ns64('lamports'),
|
|
536
|
-
]),
|
|
537
|
-
},
|
|
538
|
-
Deactivate: {
|
|
539
|
-
index: 5,
|
|
540
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Deactivate']>([
|
|
541
|
-
BufferLayout.u32('instruction'),
|
|
542
|
-
]),
|
|
543
|
-
},
|
|
544
|
-
Merge: {
|
|
545
|
-
index: 7,
|
|
546
|
-
layout: BufferLayout.struct<StakeInstructionInputData['Merge']>([
|
|
547
|
-
BufferLayout.u32('instruction'),
|
|
548
|
-
]),
|
|
549
|
-
},
|
|
550
|
-
AuthorizeWithSeed: {
|
|
551
|
-
index: 8,
|
|
552
|
-
layout: BufferLayout.struct<StakeInstructionInputData['AuthorizeWithSeed']>(
|
|
553
|
-
[
|
|
554
|
-
BufferLayout.u32('instruction'),
|
|
555
|
-
Layout.publicKey('newAuthorized'),
|
|
556
|
-
BufferLayout.u32('stakeAuthorizationType'),
|
|
557
|
-
Layout.rustString('authoritySeed'),
|
|
558
|
-
Layout.publicKey('authorityOwner'),
|
|
559
|
-
],
|
|
560
|
-
),
|
|
561
|
-
},
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Stake authorization type
|
|
566
|
-
*/
|
|
567
|
-
export type StakeAuthorizationType = {
|
|
568
|
-
/** The Stake Authorization index (from solana-stake-program) */
|
|
569
|
-
index: number;
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* An enumeration of valid StakeAuthorizationLayout's
|
|
574
|
-
*/
|
|
575
|
-
export const StakeAuthorizationLayout = Object.freeze({
|
|
576
|
-
Staker: {
|
|
577
|
-
index: 0,
|
|
578
|
-
},
|
|
579
|
-
Withdrawer: {
|
|
580
|
-
index: 1,
|
|
581
|
-
},
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Factory class for transactions to interact with the Stake program
|
|
586
|
-
*/
|
|
587
|
-
export class StakeProgram {
|
|
588
|
-
/**
|
|
589
|
-
* @internal
|
|
590
|
-
*/
|
|
591
|
-
constructor() {}
|
|
592
|
-
|
|
593
|
-
/**
|
|
594
|
-
* Public key that identifies the Stake program
|
|
595
|
-
*/
|
|
596
|
-
static programId: PublicKey = new PublicKey(
|
|
597
|
-
'Stake11111111111111111111111111111111111111',
|
|
598
|
-
);
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Max space of a Stake account
|
|
602
|
-
*
|
|
603
|
-
* This is generated from the solana-stake-program StakeState struct as
|
|
604
|
-
* `StakeState::size_of()`:
|
|
605
|
-
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.StakeState.html
|
|
606
|
-
*/
|
|
607
|
-
static space: number = 200;
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Generate an Initialize instruction to add to a Stake Create transaction
|
|
611
|
-
*/
|
|
612
|
-
static initialize(params: InitializeStakeParams): TransactionInstruction {
|
|
613
|
-
const {stakePubkey, authorized, lockup: maybeLockup} = params;
|
|
614
|
-
const lockup: Lockup = maybeLockup || Lockup.default;
|
|
615
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
616
|
-
const data = encodeData(type, {
|
|
617
|
-
authorized: {
|
|
618
|
-
staker: toBuffer(authorized.staker.toBuffer()),
|
|
619
|
-
withdrawer: toBuffer(authorized.withdrawer.toBuffer()),
|
|
620
|
-
},
|
|
621
|
-
lockup: {
|
|
622
|
-
unixTimestamp: lockup.unixTimestamp,
|
|
623
|
-
epoch: lockup.epoch,
|
|
624
|
-
custodian: toBuffer(lockup.custodian.toBuffer()),
|
|
625
|
-
},
|
|
626
|
-
});
|
|
627
|
-
const instructionData = {
|
|
628
|
-
keys: [
|
|
629
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
630
|
-
{pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false},
|
|
631
|
-
],
|
|
632
|
-
programId: this.programId,
|
|
633
|
-
data,
|
|
634
|
-
};
|
|
635
|
-
return new TransactionInstruction(instructionData);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Generate a Transaction that creates a new Stake account at
|
|
640
|
-
* an address generated with `from`, a seed, and the Stake programId
|
|
641
|
-
*/
|
|
642
|
-
static createAccountWithSeed(
|
|
643
|
-
params: CreateStakeAccountWithSeedParams,
|
|
644
|
-
): Transaction {
|
|
645
|
-
const transaction = new Transaction();
|
|
646
|
-
transaction.add(
|
|
647
|
-
SystemProgram.createAccountWithSeed({
|
|
648
|
-
fromPubkey: params.fromPubkey,
|
|
649
|
-
newAccountPubkey: params.stakePubkey,
|
|
650
|
-
basePubkey: params.basePubkey,
|
|
651
|
-
seed: params.seed,
|
|
652
|
-
lamports: params.lamports,
|
|
653
|
-
space: this.space,
|
|
654
|
-
programId: this.programId,
|
|
655
|
-
}),
|
|
656
|
-
);
|
|
657
|
-
|
|
658
|
-
const {stakePubkey, authorized, lockup} = params;
|
|
659
|
-
return transaction.add(this.initialize({stakePubkey, authorized, lockup}));
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Generate a Transaction that creates a new Stake account
|
|
664
|
-
*/
|
|
665
|
-
static createAccount(params: CreateStakeAccountParams): Transaction {
|
|
666
|
-
const transaction = new Transaction();
|
|
667
|
-
transaction.add(
|
|
668
|
-
SystemProgram.createAccount({
|
|
669
|
-
fromPubkey: params.fromPubkey,
|
|
670
|
-
newAccountPubkey: params.stakePubkey,
|
|
671
|
-
lamports: params.lamports,
|
|
672
|
-
space: this.space,
|
|
673
|
-
programId: this.programId,
|
|
674
|
-
}),
|
|
675
|
-
);
|
|
676
|
-
|
|
677
|
-
const {stakePubkey, authorized, lockup} = params;
|
|
678
|
-
return transaction.add(this.initialize({stakePubkey, authorized, lockup}));
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Generate a Transaction that delegates Stake tokens to a validator
|
|
683
|
-
* Vote PublicKey. This transaction can also be used to redelegate Stake
|
|
684
|
-
* to a new validator Vote PublicKey.
|
|
685
|
-
*/
|
|
686
|
-
static delegate(params: DelegateStakeParams): Transaction {
|
|
687
|
-
const {stakePubkey, authorizedPubkey, votePubkey} = params;
|
|
688
|
-
|
|
689
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Delegate;
|
|
690
|
-
const data = encodeData(type);
|
|
691
|
-
|
|
692
|
-
return new Transaction().add({
|
|
693
|
-
keys: [
|
|
694
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
695
|
-
{pubkey: votePubkey, isSigner: false, isWritable: false},
|
|
696
|
-
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
|
|
697
|
-
{
|
|
698
|
-
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
699
|
-
isSigner: false,
|
|
700
|
-
isWritable: false,
|
|
701
|
-
},
|
|
702
|
-
{pubkey: STAKE_CONFIG_ID, isSigner: false, isWritable: false},
|
|
703
|
-
{pubkey: authorizedPubkey, isSigner: true, isWritable: false},
|
|
704
|
-
],
|
|
705
|
-
programId: this.programId,
|
|
706
|
-
data,
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* Generate a Transaction that authorizes a new PublicKey as Staker
|
|
712
|
-
* or Withdrawer on the Stake account.
|
|
713
|
-
*/
|
|
714
|
-
static authorize(params: AuthorizeStakeParams): Transaction {
|
|
715
|
-
const {
|
|
716
|
-
stakePubkey,
|
|
717
|
-
authorizedPubkey,
|
|
718
|
-
newAuthorizedPubkey,
|
|
719
|
-
stakeAuthorizationType,
|
|
720
|
-
custodianPubkey,
|
|
721
|
-
} = params;
|
|
722
|
-
|
|
723
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Authorize;
|
|
724
|
-
const data = encodeData(type, {
|
|
725
|
-
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
726
|
-
stakeAuthorizationType: stakeAuthorizationType.index,
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
const keys = [
|
|
730
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
731
|
-
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: true},
|
|
732
|
-
{pubkey: authorizedPubkey, isSigner: true, isWritable: false},
|
|
733
|
-
];
|
|
734
|
-
if (custodianPubkey) {
|
|
735
|
-
keys.push({
|
|
736
|
-
pubkey: custodianPubkey,
|
|
737
|
-
isSigner: false,
|
|
738
|
-
isWritable: false,
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
return new Transaction().add({
|
|
742
|
-
keys,
|
|
743
|
-
programId: this.programId,
|
|
744
|
-
data,
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* Generate a Transaction that authorizes a new PublicKey as Staker
|
|
750
|
-
* or Withdrawer on the Stake account.
|
|
751
|
-
*/
|
|
752
|
-
static authorizeWithSeed(params: AuthorizeWithSeedStakeParams): Transaction {
|
|
753
|
-
const {
|
|
754
|
-
stakePubkey,
|
|
755
|
-
authorityBase,
|
|
756
|
-
authoritySeed,
|
|
757
|
-
authorityOwner,
|
|
758
|
-
newAuthorizedPubkey,
|
|
759
|
-
stakeAuthorizationType,
|
|
760
|
-
custodianPubkey,
|
|
761
|
-
} = params;
|
|
762
|
-
|
|
763
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
764
|
-
const data = encodeData(type, {
|
|
765
|
-
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
766
|
-
stakeAuthorizationType: stakeAuthorizationType.index,
|
|
767
|
-
authoritySeed: authoritySeed,
|
|
768
|
-
authorityOwner: toBuffer(authorityOwner.toBuffer()),
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
const keys = [
|
|
772
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
773
|
-
{pubkey: authorityBase, isSigner: true, isWritable: false},
|
|
774
|
-
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
|
|
775
|
-
];
|
|
776
|
-
if (custodianPubkey) {
|
|
777
|
-
keys.push({
|
|
778
|
-
pubkey: custodianPubkey,
|
|
779
|
-
isSigner: false,
|
|
780
|
-
isWritable: false,
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
return new Transaction().add({
|
|
784
|
-
keys,
|
|
785
|
-
programId: this.programId,
|
|
786
|
-
data,
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* @internal
|
|
792
|
-
*/
|
|
793
|
-
static splitInstruction(params: SplitStakeParams): TransactionInstruction {
|
|
794
|
-
const {stakePubkey, authorizedPubkey, splitStakePubkey, lamports} = params;
|
|
795
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Split;
|
|
796
|
-
const data = encodeData(type, {lamports});
|
|
797
|
-
return new TransactionInstruction({
|
|
798
|
-
keys: [
|
|
799
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
800
|
-
{pubkey: splitStakePubkey, isSigner: false, isWritable: true},
|
|
801
|
-
{pubkey: authorizedPubkey, isSigner: true, isWritable: false},
|
|
802
|
-
],
|
|
803
|
-
programId: this.programId,
|
|
804
|
-
data,
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Generate a Transaction that splits Stake tokens into another stake account
|
|
810
|
-
*/
|
|
811
|
-
static split(params: SplitStakeParams): Transaction {
|
|
812
|
-
const transaction = new Transaction();
|
|
813
|
-
transaction.add(
|
|
814
|
-
SystemProgram.createAccount({
|
|
815
|
-
fromPubkey: params.authorizedPubkey,
|
|
816
|
-
newAccountPubkey: params.splitStakePubkey,
|
|
817
|
-
lamports: 0,
|
|
818
|
-
space: this.space,
|
|
819
|
-
programId: this.programId,
|
|
820
|
-
}),
|
|
821
|
-
);
|
|
822
|
-
return transaction.add(this.splitInstruction(params));
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/**
|
|
826
|
-
* Generate a Transaction that splits Stake tokens into another account
|
|
827
|
-
* derived from a base public key and seed
|
|
828
|
-
*/
|
|
829
|
-
static splitWithSeed(params: SplitStakeWithSeedParams): Transaction {
|
|
830
|
-
const {
|
|
831
|
-
stakePubkey,
|
|
832
|
-
authorizedPubkey,
|
|
833
|
-
splitStakePubkey,
|
|
834
|
-
basePubkey,
|
|
835
|
-
seed,
|
|
836
|
-
lamports,
|
|
837
|
-
} = params;
|
|
838
|
-
const transaction = new Transaction();
|
|
839
|
-
transaction.add(
|
|
840
|
-
SystemProgram.allocate({
|
|
841
|
-
accountPubkey: splitStakePubkey,
|
|
842
|
-
basePubkey,
|
|
843
|
-
seed,
|
|
844
|
-
space: this.space,
|
|
845
|
-
programId: this.programId,
|
|
846
|
-
}),
|
|
847
|
-
);
|
|
848
|
-
return transaction.add(
|
|
849
|
-
this.splitInstruction({
|
|
850
|
-
stakePubkey,
|
|
851
|
-
authorizedPubkey,
|
|
852
|
-
splitStakePubkey,
|
|
853
|
-
lamports,
|
|
854
|
-
}),
|
|
855
|
-
);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* Generate a Transaction that merges Stake accounts.
|
|
860
|
-
*/
|
|
861
|
-
static merge(params: MergeStakeParams): Transaction {
|
|
862
|
-
const {stakePubkey, sourceStakePubKey, authorizedPubkey} = params;
|
|
863
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Merge;
|
|
864
|
-
const data = encodeData(type);
|
|
865
|
-
|
|
866
|
-
return new Transaction().add({
|
|
867
|
-
keys: [
|
|
868
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
869
|
-
{pubkey: sourceStakePubKey, isSigner: false, isWritable: true},
|
|
870
|
-
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
|
|
871
|
-
{
|
|
872
|
-
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
873
|
-
isSigner: false,
|
|
874
|
-
isWritable: false,
|
|
875
|
-
},
|
|
876
|
-
{pubkey: authorizedPubkey, isSigner: true, isWritable: false},
|
|
877
|
-
],
|
|
878
|
-
programId: this.programId,
|
|
879
|
-
data,
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
/**
|
|
884
|
-
* Generate a Transaction that withdraws deactivated Stake tokens.
|
|
885
|
-
*/
|
|
886
|
-
static withdraw(params: WithdrawStakeParams): Transaction {
|
|
887
|
-
const {stakePubkey, authorizedPubkey, toPubkey, lamports, custodianPubkey} =
|
|
888
|
-
params;
|
|
889
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
890
|
-
const data = encodeData(type, {lamports});
|
|
891
|
-
|
|
892
|
-
const keys = [
|
|
893
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
894
|
-
{pubkey: toPubkey, isSigner: false, isWritable: true},
|
|
895
|
-
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
|
|
896
|
-
{
|
|
897
|
-
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
898
|
-
isSigner: false,
|
|
899
|
-
isWritable: false,
|
|
900
|
-
},
|
|
901
|
-
{pubkey: authorizedPubkey, isSigner: true, isWritable: false},
|
|
902
|
-
];
|
|
903
|
-
if (custodianPubkey) {
|
|
904
|
-
keys.push({
|
|
905
|
-
pubkey: custodianPubkey,
|
|
906
|
-
isSigner: false,
|
|
907
|
-
isWritable: false,
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
return new Transaction().add({
|
|
911
|
-
keys,
|
|
912
|
-
programId: this.programId,
|
|
913
|
-
data,
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
/**
|
|
918
|
-
* Generate a Transaction that deactivates Stake tokens.
|
|
919
|
-
*/
|
|
920
|
-
static deactivate(params: DeactivateStakeParams): Transaction {
|
|
921
|
-
const {stakePubkey, authorizedPubkey} = params;
|
|
922
|
-
const type = STAKE_INSTRUCTION_LAYOUTS.Deactivate;
|
|
923
|
-
const data = encodeData(type);
|
|
924
|
-
|
|
925
|
-
return new Transaction().add({
|
|
926
|
-
keys: [
|
|
927
|
-
{pubkey: stakePubkey, isSigner: false, isWritable: true},
|
|
928
|
-
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
|
|
929
|
-
{pubkey: authorizedPubkey, isSigner: true, isWritable: false},
|
|
930
|
-
],
|
|
931
|
-
programId: this.programId,
|
|
932
|
-
data,
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
}
|