@exodus/solana-lib 1.6.6 → 1.6.8
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 +4 -4
- package/src/encode.js +11 -15
- package/src/helpers/spl-token.js +5 -14
- package/src/helpers/tokenTransfer.js +7 -7
- package/src/helpers/transaction-strategy.js +1 -1
- package/src/index.js +0 -2
- package/src/keypair.js +4 -9
- package/src/transaction.js +2 -3
- package/src/tx/build-raw-transaction.js +3 -3
- package/src/tx/create-and-sign-tx.js +1 -2
- package/src/tx/create-unsigned-tx.js +1 -3
- package/src/tx/decode-tx-instructions.js +22 -46
- package/src/tx/parse-unsigned-tx.js +1 -2
- package/src/tx/sign-unsigned-tx.js +1 -5
- package/src/tx/simulate-and-sign-tx.js +1 -1
- package/src/vendor/account.js +4 -6
- package/src/vendor/instruction.js +2 -10
- package/src/vendor/message.js +11 -29
- package/src/vendor/nonce-account.js +6 -7
- package/src/vendor/publickey.js +9 -14
- package/src/vendor/stake-program.js +22 -83
- package/src/vendor/system-program.js +25 -104
- package/src/vendor/sysvar.js +0 -1
- package/src/vendor/transaction.js +37 -70
- package/src/vendor/utils/blockhash.js +0 -3
- package/src/vendor/utils/fee-calculator.js +0 -4
- package/src/vendor/utils/layout.js +7 -8
- package/src/vendor/utils/shortvec-encoding.js +2 -4
- package/src/vendor/utils/to-buffer.js +1 -1
- package/src/versioned-transaction.js +1 -1
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as BufferLayout from '@exodus/buffer-layout'
|
|
3
2
|
|
|
4
3
|
import { PublicKey } from './publickey'
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
import * as Layout from './utils/layout'
|
|
7
|
-
|
|
6
|
+
|
|
8
7
|
import { FeeCalculatorLayout } from './utils/fee-calculator'
|
|
9
8
|
import { toBuffer } from './utils/to-buffer'
|
|
10
9
|
|
|
@@ -27,9 +26,9 @@ export const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span
|
|
|
27
26
|
* NonceAccount class
|
|
28
27
|
*/
|
|
29
28
|
export class NonceAccount {
|
|
30
|
-
authorizedPubkey
|
|
31
|
-
nonce
|
|
32
|
-
feeCalculator
|
|
29
|
+
authorizedPubkey
|
|
30
|
+
nonce
|
|
31
|
+
feeCalculator
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* Deserialize NonceAccount from the account data.
|
|
@@ -37,7 +36,7 @@ export class NonceAccount {
|
|
|
37
36
|
* @param buffer account data
|
|
38
37
|
* @return NonceAccount
|
|
39
38
|
*/
|
|
40
|
-
static fromAccountData(buffer
|
|
39
|
+
static fromAccountData(buffer) {
|
|
41
40
|
const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0)
|
|
42
41
|
nonceAccount.authorizedPubkey = new PublicKey(nonceAccount.authorizedPubkey)
|
|
43
42
|
nonceAccount.nonce = new PublicKey(nonceAccount.nonce).toString()
|
package/src/vendor/publickey.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import BN from 'bn.js'
|
|
3
2
|
import bs58 from 'bs58'
|
|
4
3
|
import nacl from 'tweetnacl'
|
|
@@ -16,12 +15,12 @@ export const MAX_SEED_LENGTH = 32
|
|
|
16
15
|
* A public key
|
|
17
16
|
*/
|
|
18
17
|
export class PublicKey {
|
|
19
|
-
_bn
|
|
18
|
+
_bn
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Create a new PublicKey object
|
|
23
22
|
*/
|
|
24
|
-
constructor(value
|
|
23
|
+
constructor(value) {
|
|
25
24
|
if (typeof value === 'string') {
|
|
26
25
|
// assume base 58 encoding by default
|
|
27
26
|
const decoded = bs58.decode(value)
|
|
@@ -41,21 +40,21 @@ export class PublicKey {
|
|
|
41
40
|
/**
|
|
42
41
|
* Checks if two publicKeys are equal
|
|
43
42
|
*/
|
|
44
|
-
equals(publicKey
|
|
43
|
+
equals(publicKey) {
|
|
45
44
|
return this._bn.eq(publicKey._bn)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Return the base-58 representation of the public key
|
|
50
49
|
*/
|
|
51
|
-
toBase58()
|
|
50
|
+
toBase58() {
|
|
52
51
|
return bs58.encode(this.toBuffer())
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
55
|
* Return the Buffer representation of the public key
|
|
57
56
|
*/
|
|
58
|
-
toBuffer()
|
|
57
|
+
toBuffer() {
|
|
59
58
|
const b = this._bn.toArrayLike(Buffer)
|
|
60
59
|
if (b.length === 32) {
|
|
61
60
|
return b
|
|
@@ -69,7 +68,7 @@ export class PublicKey {
|
|
|
69
68
|
/**
|
|
70
69
|
* Returns a string representation of the public key
|
|
71
70
|
*/
|
|
72
|
-
toString()
|
|
71
|
+
toString() {
|
|
73
72
|
return this.toBase58()
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -81,7 +80,7 @@ export class PublicKey {
|
|
|
81
80
|
* results in a valid program address.
|
|
82
81
|
* HACK: transformed in sync function
|
|
83
82
|
*/
|
|
84
|
-
static findProgramAddress(seeds
|
|
83
|
+
static findProgramAddress(seeds, programId) {
|
|
85
84
|
let nonce = 255
|
|
86
85
|
let address
|
|
87
86
|
while (nonce !== 0) {
|
|
@@ -101,11 +100,7 @@ export class PublicKey {
|
|
|
101
100
|
* Derive a public key from another key, a seed, and a program ID.
|
|
102
101
|
* HACK: transformed in sync function
|
|
103
102
|
*/
|
|
104
|
-
static createWithSeed(
|
|
105
|
-
fromPublicKey: PublicKey,
|
|
106
|
-
seed: string,
|
|
107
|
-
programId: PublicKey
|
|
108
|
-
): Promise<PublicKey> {
|
|
103
|
+
static createWithSeed(fromPublicKey, seed, programId) {
|
|
109
104
|
const buffer = Buffer.concat([
|
|
110
105
|
fromPublicKey.toBuffer(),
|
|
111
106
|
Buffer.from(seed),
|
|
@@ -120,7 +115,7 @@ export class PublicKey {
|
|
|
120
115
|
/**
|
|
121
116
|
* Derive a program address from seeds and a program ID.
|
|
122
117
|
*/
|
|
123
|
-
static createProgramAddress(seeds
|
|
118
|
+
static createProgramAddress(seeds, programId) {
|
|
124
119
|
let buffer = Buffer.alloc(0)
|
|
125
120
|
seeds.forEach(function(seed) {
|
|
126
121
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import * as BufferLayout from '@exodus/buffer-layout'
|
|
4
2
|
|
|
5
3
|
import { encodeData, decodeData } from './instruction'
|
|
@@ -12,27 +10,27 @@ import { Transaction, TransactionInstruction } from './transaction'
|
|
|
12
10
|
export const STAKE_CONFIG_ID = new PublicKey('StakeConfig11111111111111111111111111111111')
|
|
13
11
|
|
|
14
12
|
export class Authorized {
|
|
15
|
-
staker
|
|
16
|
-
withdrawer
|
|
13
|
+
staker
|
|
14
|
+
withdrawer
|
|
17
15
|
|
|
18
16
|
/**
|
|
19
17
|
* Create a new Authorized object
|
|
20
18
|
*/
|
|
21
|
-
constructor(staker
|
|
19
|
+
constructor(staker, withdrawer) {
|
|
22
20
|
this.staker = staker
|
|
23
21
|
this.withdrawer = withdrawer
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export class Lockup {
|
|
28
|
-
unixTimestamp
|
|
29
|
-
epoch
|
|
30
|
-
custodian
|
|
26
|
+
unixTimestamp
|
|
27
|
+
epoch
|
|
28
|
+
custodian
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* Create a new Lockup object
|
|
34
32
|
*/
|
|
35
|
-
constructor(unixTimestamp
|
|
33
|
+
constructor(unixTimestamp, epoch, custodian) {
|
|
36
34
|
this.unixTimestamp = unixTimestamp
|
|
37
35
|
this.epoch = epoch
|
|
38
36
|
this.custodian = custodian
|
|
@@ -48,13 +46,6 @@ export class Lockup {
|
|
|
48
46
|
* @property {Lockup} lockup
|
|
49
47
|
* @property {number} lamports
|
|
50
48
|
*/
|
|
51
|
-
export type CreateStakeAccountParams = {|
|
|
52
|
-
fromPubkey: PublicKey,
|
|
53
|
-
stakePubkey: PublicKey,
|
|
54
|
-
authorized: Authorized,
|
|
55
|
-
lockup: Lockup,
|
|
56
|
-
lamports: number,
|
|
57
|
-
|}
|
|
58
49
|
|
|
59
50
|
/**
|
|
60
51
|
* Create stake account with seed transaction params
|
|
@@ -67,15 +58,6 @@ export type CreateStakeAccountParams = {|
|
|
|
67
58
|
* @property {Lockup} lockup
|
|
68
59
|
* @property {number} lamports
|
|
69
60
|
*/
|
|
70
|
-
export type CreateStakeAccountWithSeedParams = {|
|
|
71
|
-
fromPubkey: PublicKey,
|
|
72
|
-
stakePubkey: PublicKey,
|
|
73
|
-
basePubkey: PublicKey,
|
|
74
|
-
seed: string,
|
|
75
|
-
authorized: Authorized,
|
|
76
|
-
lockup: Lockup,
|
|
77
|
-
lamports: number,
|
|
78
|
-
|}
|
|
79
61
|
|
|
80
62
|
/**
|
|
81
63
|
* Initialize stake instruction params
|
|
@@ -84,11 +66,6 @@ export type CreateStakeAccountWithSeedParams = {|
|
|
|
84
66
|
* @property {Authorized} authorized
|
|
85
67
|
* @property {Lockup} lockup
|
|
86
68
|
*/
|
|
87
|
-
export type InitializeStakeParams = {|
|
|
88
|
-
stakePubkey: PublicKey,
|
|
89
|
-
authorized: Authorized,
|
|
90
|
-
lockup: Lockup,
|
|
91
|
-
|}
|
|
92
69
|
|
|
93
70
|
/**
|
|
94
71
|
* Delegate stake instruction params
|
|
@@ -97,19 +74,11 @@ export type InitializeStakeParams = {|
|
|
|
97
74
|
* @property {PublicKey} authorizedPubkey
|
|
98
75
|
* @property {PublicKey} votePubkey
|
|
99
76
|
*/
|
|
100
|
-
export type DelegateStakeParams = {|
|
|
101
|
-
stakePubkey: PublicKey,
|
|
102
|
-
authorizedPubkey: PublicKey,
|
|
103
|
-
votePubkey: PublicKey,
|
|
104
|
-
|}
|
|
105
77
|
|
|
106
78
|
/**
|
|
107
79
|
* @typedef {Object} StakeAuthorizationType
|
|
108
80
|
* @property (index} The Stake Authorization index (from solana-stake-program)
|
|
109
81
|
*/
|
|
110
|
-
export type StakeAuthorizationType = {|
|
|
111
|
-
index: number,
|
|
112
|
-
|}
|
|
113
82
|
|
|
114
83
|
/**
|
|
115
84
|
* Authorize stake instruction params
|
|
@@ -119,12 +88,6 @@ export type StakeAuthorizationType = {|
|
|
|
119
88
|
* @property {PublicKey} newAuthorizedPubkey
|
|
120
89
|
* @property {StakeAuthorizationType} stakeAuthorizationType
|
|
121
90
|
*/
|
|
122
|
-
export type AuthorizeStakeParams = {|
|
|
123
|
-
stakePubkey: PublicKey,
|
|
124
|
-
authorizedPubkey: PublicKey,
|
|
125
|
-
newAuthorizedPubkey: PublicKey,
|
|
126
|
-
stakeAuthorizationType: StakeAuthorizationType,
|
|
127
|
-
|}
|
|
128
91
|
|
|
129
92
|
/**
|
|
130
93
|
* Authorize stake instruction params using a derived key
|
|
@@ -136,14 +99,6 @@ export type AuthorizeStakeParams = {|
|
|
|
136
99
|
* @property {PublicKey} newAuthorizedPubkey
|
|
137
100
|
* @property {StakeAuthorizationType} stakeAuthorizationType
|
|
138
101
|
*/
|
|
139
|
-
export type AuthorizeWithSeedStakeParams = {|
|
|
140
|
-
stakePubkey: PublicKey,
|
|
141
|
-
authorityBase: PublicKey,
|
|
142
|
-
authoritySeed: string,
|
|
143
|
-
authorityOwner: PublicKey,
|
|
144
|
-
newAuthorizedPubkey: PublicKey,
|
|
145
|
-
stakeAuthorizationType: StakeAuthorizationType,
|
|
146
|
-
|}
|
|
147
102
|
|
|
148
103
|
/**
|
|
149
104
|
* Split stake instruction params
|
|
@@ -153,12 +108,6 @@ export type AuthorizeWithSeedStakeParams = {|
|
|
|
153
108
|
* @property {PublicKey} splitStakePubkey
|
|
154
109
|
* @property {number} lamports
|
|
155
110
|
*/
|
|
156
|
-
export type SplitStakeParams = {|
|
|
157
|
-
stakePubkey: PublicKey,
|
|
158
|
-
authorizedPubkey: PublicKey,
|
|
159
|
-
splitStakePubkey: PublicKey,
|
|
160
|
-
lamports: number,
|
|
161
|
-
|}
|
|
162
111
|
|
|
163
112
|
/**
|
|
164
113
|
* Withdraw stake instruction params
|
|
@@ -168,12 +117,6 @@ export type SplitStakeParams = {|
|
|
|
168
117
|
* @property {PublicKey} toPubkey
|
|
169
118
|
* @property {number} lamports
|
|
170
119
|
*/
|
|
171
|
-
export type WithdrawStakeParams = {|
|
|
172
|
-
stakePubkey: PublicKey,
|
|
173
|
-
authorizedPubkey: PublicKey,
|
|
174
|
-
toPubkey: PublicKey,
|
|
175
|
-
lamports: number,
|
|
176
|
-
|}
|
|
177
120
|
|
|
178
121
|
/**
|
|
179
122
|
* Deactivate stake instruction params
|
|
@@ -181,10 +124,6 @@ export type WithdrawStakeParams = {|
|
|
|
181
124
|
* @property {PublicKey} stakePubkey
|
|
182
125
|
* @property {PublicKey} authorizedPubkey
|
|
183
126
|
*/
|
|
184
|
-
export type DeactivateStakeParams = {|
|
|
185
|
-
stakePubkey: PublicKey,
|
|
186
|
-
authorizedPubkey: PublicKey,
|
|
187
|
-
|}
|
|
188
127
|
|
|
189
128
|
/**
|
|
190
129
|
* An enumeration of valid stake InstructionType's
|
|
@@ -241,7 +180,7 @@ export class StakeInstruction {
|
|
|
241
180
|
/**
|
|
242
181
|
* Decode a stake instruction and retrieve the instruction type.
|
|
243
182
|
*/
|
|
244
|
-
static decodeInstructionType(instruction
|
|
183
|
+
static decodeInstructionType(instruction) {
|
|
245
184
|
this.checkProgramId(instruction.programId)
|
|
246
185
|
|
|
247
186
|
const instructionTypeLayout = BufferLayout.u32('instruction')
|
|
@@ -264,7 +203,7 @@ export class StakeInstruction {
|
|
|
264
203
|
/**
|
|
265
204
|
* Decode a initialize stake instruction and retrieve the instruction params.
|
|
266
205
|
*/
|
|
267
|
-
static decodeInitialize(instruction
|
|
206
|
+
static decodeInitialize(instruction) {
|
|
268
207
|
this.checkProgramId(instruction.programId)
|
|
269
208
|
this.checkKeyLength(instruction.keys, 2)
|
|
270
209
|
|
|
@@ -286,7 +225,7 @@ export class StakeInstruction {
|
|
|
286
225
|
/**
|
|
287
226
|
* Decode a delegate stake instruction and retrieve the instruction params.
|
|
288
227
|
*/
|
|
289
|
-
static decodeDelegate(instruction
|
|
228
|
+
static decodeDelegate(instruction) {
|
|
290
229
|
this.checkProgramId(instruction.programId)
|
|
291
230
|
this.checkKeyLength(instruction.keys, 6)
|
|
292
231
|
decodeData(STAKE_INSTRUCTION_LAYOUTS.Delegate, instruction.data)
|
|
@@ -301,7 +240,7 @@ export class StakeInstruction {
|
|
|
301
240
|
/**
|
|
302
241
|
* Decode a withdraw stake instruction and retrieve the instruction params.
|
|
303
242
|
*/
|
|
304
|
-
static decodeWithdraw(instruction
|
|
243
|
+
static decodeWithdraw(instruction) {
|
|
305
244
|
this.checkProgramId(instruction.programId)
|
|
306
245
|
this.checkKeyLength(instruction.keys, 5)
|
|
307
246
|
const { lamports } = decodeData(STAKE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data)
|
|
@@ -317,7 +256,7 @@ export class StakeInstruction {
|
|
|
317
256
|
/**
|
|
318
257
|
* Decode a deactivate stake instruction and retrieve the instruction params.
|
|
319
258
|
*/
|
|
320
|
-
static decodeDeactivate(instruction
|
|
259
|
+
static decodeDeactivate(instruction) {
|
|
321
260
|
this.checkProgramId(instruction.programId)
|
|
322
261
|
this.checkKeyLength(instruction.keys, 3)
|
|
323
262
|
decodeData(STAKE_INSTRUCTION_LAYOUTS.Deactivate, instruction.data)
|
|
@@ -331,7 +270,7 @@ export class StakeInstruction {
|
|
|
331
270
|
/**
|
|
332
271
|
* @private
|
|
333
272
|
*/
|
|
334
|
-
static checkProgramId(programId
|
|
273
|
+
static checkProgramId(programId) {
|
|
335
274
|
if (!programId.equals(StakeProgram.programId)) {
|
|
336
275
|
throw new Error('invalid instruction; programId is not StakeProgram')
|
|
337
276
|
}
|
|
@@ -340,7 +279,7 @@ export class StakeInstruction {
|
|
|
340
279
|
/**
|
|
341
280
|
* @private
|
|
342
281
|
*/
|
|
343
|
-
static checkKeyLength(keys
|
|
282
|
+
static checkKeyLength(keys, expectedLength) {
|
|
344
283
|
if (keys.length < expectedLength) {
|
|
345
284
|
throw new Error(
|
|
346
285
|
`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`
|
|
@@ -368,7 +307,7 @@ export class StakeProgram {
|
|
|
368
307
|
/**
|
|
369
308
|
* Public key that identifies the Stake program
|
|
370
309
|
*/
|
|
371
|
-
static get programId()
|
|
310
|
+
static get programId() {
|
|
372
311
|
return new PublicKey('Stake11111111111111111111111111111111111111')
|
|
373
312
|
}
|
|
374
313
|
|
|
@@ -379,14 +318,14 @@ export class StakeProgram {
|
|
|
379
318
|
* `std::mem::size_of::<StakeState>()`:
|
|
380
319
|
* https://docs.rs/solana-stake-program/1.4.4/solana_stake_program/stake_state/enum.StakeState.html
|
|
381
320
|
*/
|
|
382
|
-
static get space()
|
|
321
|
+
static get space() {
|
|
383
322
|
return 200
|
|
384
323
|
}
|
|
385
324
|
|
|
386
325
|
/**
|
|
387
326
|
* Generate an Initialize instruction to add to a Stake Create transaction
|
|
388
327
|
*/
|
|
389
|
-
static initialize(params
|
|
328
|
+
static initialize(params) {
|
|
390
329
|
const { stakePubkey, authorized, lockup } = params
|
|
391
330
|
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize
|
|
392
331
|
const data = encodeData(type, {
|
|
@@ -415,7 +354,7 @@ export class StakeProgram {
|
|
|
415
354
|
* Generate a Transaction that creates a new Stake account at
|
|
416
355
|
* an address generated with `from`, a seed, and the Stake programId
|
|
417
356
|
*/
|
|
418
|
-
static createAccountWithSeed(params
|
|
357
|
+
static createAccountWithSeed(params) {
|
|
419
358
|
const transaction = new Transaction()
|
|
420
359
|
transaction.add(
|
|
421
360
|
SystemProgram.createAccountWithSeed({
|
|
@@ -436,7 +375,7 @@ export class StakeProgram {
|
|
|
436
375
|
/**
|
|
437
376
|
* Generate a Transaction that creates a new Stake account
|
|
438
377
|
*/
|
|
439
|
-
static createAccount(params
|
|
378
|
+
static createAccount(params) {
|
|
440
379
|
const transaction = new Transaction()
|
|
441
380
|
transaction.add(
|
|
442
381
|
SystemProgram.createAccount({
|
|
@@ -457,7 +396,7 @@ export class StakeProgram {
|
|
|
457
396
|
* Vote PublicKey. This transaction can also be used to redelegate Stake
|
|
458
397
|
* to a new validator Vote PublicKey.
|
|
459
398
|
*/
|
|
460
|
-
static delegate(params
|
|
399
|
+
static delegate(params) {
|
|
461
400
|
const { stakePubkey, authorizedPubkey, votePubkey } = params
|
|
462
401
|
|
|
463
402
|
const type = STAKE_INSTRUCTION_LAYOUTS.Delegate
|
|
@@ -484,7 +423,7 @@ export class StakeProgram {
|
|
|
484
423
|
/**
|
|
485
424
|
* Generate a Transaction that withdraws deactivated Stake tokens.
|
|
486
425
|
*/
|
|
487
|
-
static withdraw(params
|
|
426
|
+
static withdraw(params) {
|
|
488
427
|
const { stakePubkey, authorizedPubkey, toPubkey, lamports } = params
|
|
489
428
|
const type = STAKE_INSTRUCTION_LAYOUTS.Withdraw
|
|
490
429
|
const data = encodeData(type, { lamports })
|
|
@@ -509,7 +448,7 @@ export class StakeProgram {
|
|
|
509
448
|
/**
|
|
510
449
|
* Generate a Transaction that deactivates Stake tokens.
|
|
511
450
|
*/
|
|
512
|
-
static deactivate(params
|
|
451
|
+
static deactivate(params) {
|
|
513
452
|
const { stakePubkey, authorizedPubkey } = params
|
|
514
453
|
const type = STAKE_INSTRUCTION_LAYOUTS.Deactivate
|
|
515
454
|
const data = encodeData(type)
|