@exodus/solana-lib 1.6.7 → 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.
@@ -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'
@@ -18,13 +16,6 @@ import { Transaction, TransactionInstruction } from './transaction'
18
16
  * @property {number} space
19
17
  * @property {PublicKey} programId
20
18
  */
21
- export type CreateAccountParams = {|
22
- fromPubkey: PublicKey,
23
- newAccountPubkey: PublicKey,
24
- lamports: number,
25
- space: number,
26
- programId: PublicKey,
27
- |}
28
19
 
29
20
  /**
30
21
  * Transfer system transaction params
@@ -33,11 +24,6 @@ export type CreateAccountParams = {|
33
24
  * @property {PublicKey} toPubkey
34
25
  * @property {number} lamports
35
26
  */
36
- export type TransferParams = {|
37
- fromPubkey: PublicKey,
38
- toPubkey: PublicKey,
39
- lamports: number,
40
- |}
41
27
 
42
28
  /**
43
29
  * Assign system transaction params
@@ -45,10 +31,6 @@ export type TransferParams = {|
45
31
  * @property {PublicKey} accountPubkey
46
32
  * @property {PublicKey} programId
47
33
  */
48
- export type AssignParams = {|
49
- accountPubkey: PublicKey,
50
- programId: PublicKey,
51
- |}
52
34
 
53
35
  /**
54
36
  * Create account with seed system transaction params
@@ -61,15 +43,6 @@ export type AssignParams = {|
61
43
  * @property {number} space
62
44
  * @property {PublicKey} programId
63
45
  */
64
- export type CreateAccountWithSeedParams = {|
65
- fromPubkey: PublicKey,
66
- newAccountPubkey: PublicKey,
67
- basePubkey: PublicKey,
68
- seed: string,
69
- lamports: number,
70
- space: number,
71
- programId: PublicKey,
72
- |}
73
46
 
74
47
  /**
75
48
  * Create nonce account system transaction params
@@ -79,12 +52,6 @@ export type CreateAccountWithSeedParams = {|
79
52
  * @property {PublicKey} authorizedPubkey
80
53
  * @property {number} lamports
81
54
  */
82
- export type CreateNonceAccountParams = {|
83
- fromPubkey: PublicKey,
84
- noncePubkey: PublicKey,
85
- authorizedPubkey: PublicKey,
86
- lamports: number,
87
- |}
88
55
 
89
56
  /**
90
57
  * Create nonce account with seed system transaction params
@@ -96,14 +63,6 @@ export type CreateNonceAccountParams = {|
96
63
  * @property {string} seed
97
64
  * @property {number} lamports
98
65
  */
99
- export type CreateNonceAccountWithSeedParams = {|
100
- fromPubkey: PublicKey,
101
- noncePubkey: PublicKey,
102
- authorizedPubkey: PublicKey,
103
- lamports: number,
104
- basePubkey: PublicKey,
105
- seed: string,
106
- |}
107
66
 
108
67
  /**
109
68
  * Initialize nonce account system instruction params
@@ -111,10 +70,6 @@ export type CreateNonceAccountWithSeedParams = {|
111
70
  * @property {PublicKey} fromPubkey
112
71
  * @property {PublicKey} programId
113
72
  */
114
- export type InitializeNonceParams = {|
115
- noncePubkey: PublicKey,
116
- authorizedPubkey: PublicKey,
117
- |}
118
73
 
119
74
  /**
120
75
  * Advance nonce account system instruction params
@@ -122,10 +77,6 @@ export type InitializeNonceParams = {|
122
77
  * @property {PublicKey} fromPubkey
123
78
  * @property {PublicKey} programId
124
79
  */
125
- export type AdvanceNonceParams = {|
126
- noncePubkey: PublicKey,
127
- authorizedPubkey: PublicKey,
128
- |}
129
80
 
130
81
  /**
131
82
  * Withdraw nonce account system transaction params
@@ -135,12 +86,6 @@ export type AdvanceNonceParams = {|
135
86
  * @property {PublicKey} toPubkey
136
87
  * @property {number} lamports
137
88
  */
138
- export type WithdrawNonceParams = {|
139
- noncePubkey: PublicKey,
140
- authorizedPubkey: PublicKey,
141
- toPubkey: PublicKey,
142
- lamports: number,
143
- |}
144
89
 
145
90
  /**
146
91
  * Authorize nonce account system transaction params
@@ -149,11 +94,6 @@ export type WithdrawNonceParams = {|
149
94
  * @property {PublicKey} authorizedPubkey
150
95
  * @property {PublicKey} newAuthorizedPubkey
151
96
  */
152
- export type AuthorizeNonceParams = {|
153
- noncePubkey: PublicKey,
154
- authorizedPubkey: PublicKey,
155
- newAuthorizedPubkey: PublicKey,
156
- |}
157
97
 
158
98
  /**
159
99
  * Allocate account system transaction params
@@ -161,10 +101,6 @@ export type AuthorizeNonceParams = {|
161
101
  * @property {PublicKey} accountPubkey
162
102
  * @property {number} space
163
103
  */
164
- export type AllocateParams = {|
165
- accountPubkey: PublicKey,
166
- space: number,
167
- |}
168
104
 
169
105
  /**
170
106
  * Allocate account with seed system transaction params
@@ -175,13 +111,6 @@ export type AllocateParams = {|
175
111
  * @property {number} space
176
112
  * @property {PublicKey} programId
177
113
  */
178
- export type AllocateWithSeedParams = {|
179
- accountPubkey: PublicKey,
180
- basePubkey: PublicKey,
181
- seed: string,
182
- space: number,
183
- programId: PublicKey,
184
- |}
185
114
 
186
115
  /**
187
116
  * Assign account with seed system transaction params
@@ -191,12 +120,6 @@ export type AllocateWithSeedParams = {|
191
120
  * @property {string} seed
192
121
  * @property {PublicKey} programId
193
122
  */
194
- export type AssignWithSeedParams = {|
195
- accountPubkey: PublicKey,
196
- basePubkey: PublicKey,
197
- seed: string,
198
- programId: PublicKey,
199
- |}
200
123
 
201
124
  /**
202
125
  * An enumeration of valid system InstructionType's
@@ -278,7 +201,7 @@ export class SystemInstruction {
278
201
  /**
279
202
  * Decode a system instruction and retrieve the instruction type.
280
203
  */
281
- static decodeInstructionType(instruction: TransactionInstruction) {
204
+ static decodeInstructionType(instruction) {
282
205
  this.checkProgramId(instruction.programId)
283
206
 
284
207
  const instructionTypeLayout = BufferLayout.u32('instruction')
@@ -301,7 +224,7 @@ export class SystemInstruction {
301
224
  /**
302
225
  * Decode a create account system instruction and retrieve the instruction params.
303
226
  */
304
- static decodeCreateAccount(instruction: TransactionInstruction): CreateAccountParams {
227
+ static decodeCreateAccount(instruction) {
305
228
  this.checkProgramId(instruction.programId)
306
229
  this.checkKeyLength(instruction.keys, 2)
307
230
 
@@ -322,7 +245,7 @@ export class SystemInstruction {
322
245
  /**
323
246
  * Decode a transfer system instruction and retrieve the instruction params.
324
247
  */
325
- static decodeTransfer(instruction: TransactionInstruction): TransferParams {
248
+ static decodeTransfer(instruction) {
326
249
  this.checkProgramId(instruction.programId)
327
250
  this.checkKeyLength(instruction.keys, 2)
328
251
 
@@ -338,7 +261,7 @@ export class SystemInstruction {
338
261
  /**
339
262
  * Decode an allocate system instruction and retrieve the instruction params.
340
263
  */
341
- static decodeAllocate(instruction: TransactionInstruction): AllocateParams {
264
+ static decodeAllocate(instruction) {
342
265
  this.checkProgramId(instruction.programId)
343
266
  this.checkKeyLength(instruction.keys, 1)
344
267
 
@@ -353,7 +276,7 @@ export class SystemInstruction {
353
276
  /**
354
277
  * Decode an allocate with seed system instruction and retrieve the instruction params.
355
278
  */
356
- static decodeAllocateWithSeed(instruction: TransactionInstruction): AllocateWithSeedParams {
279
+ static decodeAllocateWithSeed(instruction) {
357
280
  this.checkProgramId(instruction.programId)
358
281
  this.checkKeyLength(instruction.keys, 1)
359
282
 
@@ -374,7 +297,7 @@ export class SystemInstruction {
374
297
  /**
375
298
  * Decode an assign system instruction and retrieve the instruction params.
376
299
  */
377
- static decodeAssign(instruction: TransactionInstruction): AssignParams {
300
+ static decodeAssign(instruction) {
378
301
  this.checkProgramId(instruction.programId)
379
302
  this.checkKeyLength(instruction.keys, 1)
380
303
 
@@ -389,7 +312,7 @@ export class SystemInstruction {
389
312
  /**
390
313
  * Decode an assign with seed system instruction and retrieve the instruction params.
391
314
  */
392
- static decodeAssignWithSeed(instruction: TransactionInstruction): AssignWithSeedParams {
315
+ static decodeAssignWithSeed(instruction) {
393
316
  this.checkProgramId(instruction.programId)
394
317
  this.checkKeyLength(instruction.keys, 1)
395
318
 
@@ -409,7 +332,7 @@ export class SystemInstruction {
409
332
  /**
410
333
  * Decode a create account with seed system instruction and retrieve the instruction params.
411
334
  */
412
- static decodeCreateWithSeed(instruction: TransactionInstruction): CreateAccountWithSeedParams {
335
+ static decodeCreateWithSeed(instruction) {
413
336
  this.checkProgramId(instruction.programId)
414
337
  this.checkKeyLength(instruction.keys, 2)
415
338
 
@@ -432,7 +355,7 @@ export class SystemInstruction {
432
355
  /**
433
356
  * Decode a nonce initialize system instruction and retrieve the instruction params.
434
357
  */
435
- static decodeNonceInitialize(instruction: TransactionInstruction): InitializeNonceParams {
358
+ static decodeNonceInitialize(instruction) {
436
359
  this.checkProgramId(instruction.programId)
437
360
  this.checkKeyLength(instruction.keys, 3)
438
361
 
@@ -450,7 +373,7 @@ export class SystemInstruction {
450
373
  /**
451
374
  * Decode a nonce advance system instruction and retrieve the instruction params.
452
375
  */
453
- static decodeNonceAdvance(instruction: TransactionInstruction): AdvanceNonceParams {
376
+ static decodeNonceAdvance(instruction) {
454
377
  this.checkProgramId(instruction.programId)
455
378
  this.checkKeyLength(instruction.keys, 3)
456
379
 
@@ -465,7 +388,7 @@ export class SystemInstruction {
465
388
  /**
466
389
  * Decode a nonce withdraw system instruction and retrieve the instruction params.
467
390
  */
468
- static decodeNonceWithdraw(instruction: TransactionInstruction): WithdrawNonceParams {
391
+ static decodeNonceWithdraw(instruction) {
469
392
  this.checkProgramId(instruction.programId)
470
393
  this.checkKeyLength(instruction.keys, 5)
471
394
 
@@ -485,7 +408,7 @@ export class SystemInstruction {
485
408
  /**
486
409
  * Decode a nonce authorize system instruction and retrieve the instruction params.
487
410
  */
488
- static decodeNonceAuthorize(instruction: TransactionInstruction): AuthorizeNonceParams {
411
+ static decodeNonceAuthorize(instruction) {
489
412
  this.checkProgramId(instruction.programId)
490
413
  this.checkKeyLength(instruction.keys, 2)
491
414
 
@@ -504,7 +427,7 @@ export class SystemInstruction {
504
427
  /**
505
428
  * @private
506
429
  */
507
- static checkProgramId(programId: PublicKey) {
430
+ static checkProgramId(programId) {
508
431
  if (!programId.equals(SystemProgram.programId)) {
509
432
  throw new Error('invalid instruction; programId is not SystemProgram')
510
433
  }
@@ -513,7 +436,7 @@ export class SystemInstruction {
513
436
  /**
514
437
  * @private
515
438
  */
516
- static checkKeyLength(keys: Array<any>, expectedLength: number) {
439
+ static checkKeyLength(keys, expectedLength) {
517
440
  if (keys.length < expectedLength) {
518
441
  throw new Error(
519
442
  `invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`
@@ -529,14 +452,14 @@ export class SystemProgram {
529
452
  /**
530
453
  * Public key that identifies the System program
531
454
  */
532
- static get programId(): PublicKey {
455
+ static get programId() {
533
456
  return new PublicKey('11111111111111111111111111111111')
534
457
  }
535
458
 
536
459
  /**
537
460
  * Generate a transaction instruction that creates a new account
538
461
  */
539
- static createAccount(params: CreateAccountParams): TransactionInstruction {
462
+ static createAccount(params) {
540
463
  const type = SYSTEM_INSTRUCTION_LAYOUTS.Create
541
464
  const data = encodeData(type, {
542
465
  lamports: params.lamports,
@@ -557,7 +480,7 @@ export class SystemProgram {
557
480
  /**
558
481
  * Generate a transaction instruction that transfers lamports from one account to another
559
482
  */
560
- static transfer(params: TransferParams): TransactionInstruction {
483
+ static transfer(params) {
561
484
  const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer
562
485
  const data = encodeData(type, { lamports: params.lamports })
563
486
 
@@ -574,7 +497,7 @@ export class SystemProgram {
574
497
  /**
575
498
  * Generate a transaction instruction that assigns an account to a program
576
499
  */
577
- static assign(params: AssignParams | AssignWithSeedParams): TransactionInstruction {
500
+ static assign(params) {
578
501
  let data
579
502
  if (params.basePubkey) {
580
503
  const type = SYSTEM_INSTRUCTION_LAYOUTS.AssignWithSeed
@@ -599,7 +522,7 @@ export class SystemProgram {
599
522
  * Generate a transaction instruction that creates a new account at
600
523
  * an address generated with `from`, a seed, and programId
601
524
  */
602
- static createAccountWithSeed(params: CreateAccountWithSeedParams): TransactionInstruction {
525
+ static createAccountWithSeed(params) {
603
526
  const type = SYSTEM_INSTRUCTION_LAYOUTS.CreateWithSeed
604
527
  const data = encodeData(type, {
605
528
  base: params.basePubkey.toBuffer(),
@@ -622,9 +545,7 @@ export class SystemProgram {
622
545
  /**
623
546
  * Generate a transaction that creates a new Nonce account
624
547
  */
625
- static createNonceAccount(
626
- params: CreateNonceAccountParams | CreateNonceAccountWithSeedParams
627
- ): Transaction {
548
+ static createNonceAccount(params) {
628
549
  const transaction = new Transaction()
629
550
  if (params.basePubkey && params.seed) {
630
551
  transaction.add(
@@ -662,7 +583,7 @@ export class SystemProgram {
662
583
  /**
663
584
  * Generate an instruction to initialize a Nonce account
664
585
  */
665
- static nonceInitialize(params: InitializeNonceParams): TransactionInstruction {
586
+ static nonceInitialize(params) {
666
587
  const type = SYSTEM_INSTRUCTION_LAYOUTS.InitializeNonceAccount
667
588
  const data = encodeData(type, {
668
589
  authorized: params.authorizedPubkey.toBuffer(),
@@ -686,7 +607,7 @@ export class SystemProgram {
686
607
  /**
687
608
  * Generate an instruction to advance the nonce in a Nonce account
688
609
  */
689
- static nonceAdvance(params: AdvanceNonceParams): TransactionInstruction {
610
+ static nonceAdvance(params) {
690
611
  const type = SYSTEM_INSTRUCTION_LAYOUTS.AdvanceNonceAccount
691
612
  const data = encodeData(type)
692
613
  const instructionData = {
@@ -708,7 +629,7 @@ export class SystemProgram {
708
629
  /**
709
630
  * Generate a transaction instruction that withdraws lamports from a Nonce account
710
631
  */
711
- static nonceWithdraw(params: WithdrawNonceParams): TransactionInstruction {
632
+ static nonceWithdraw(params) {
712
633
  const type = SYSTEM_INSTRUCTION_LAYOUTS.WithdrawNonceAccount
713
634
  const data = encodeData(type, { lamports: params.lamports })
714
635
 
@@ -737,7 +658,7 @@ export class SystemProgram {
737
658
  * Generate a transaction instruction that authorizes a new PublicKey as the authority
738
659
  * on a Nonce account.
739
660
  */
740
- static nonceAuthorize(params: AuthorizeNonceParams): TransactionInstruction {
661
+ static nonceAuthorize(params) {
741
662
  const type = SYSTEM_INSTRUCTION_LAYOUTS.AuthorizeNonceAccount
742
663
  const data = encodeData(type, {
743
664
  authorized: params.newAuthorizedPubkey.toBuffer(),
@@ -756,7 +677,7 @@ export class SystemProgram {
756
677
  /**
757
678
  * Generate a transaction instruction that allocates space in an account without funding
758
679
  */
759
- static allocate(params: AllocateParams | AllocateWithSeedParams): TransactionInstruction {
680
+ static allocate(params) {
760
681
  let data
761
682
  if (params.basePubkey) {
762
683
  const type = SYSTEM_INSTRUCTION_LAYOUTS.AllocateWithSeed
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import { PublicKey } from './publickey'
3
2
 
4
3
  export const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111')