@atomiqlabs/chain-solana 8.0.3 → 9.0.0-beta.0

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.
Files changed (86) hide show
  1. package/dist/index.d.ts +11 -11
  2. package/dist/index.js +11 -11
  3. package/dist/solana/SolanaChainType.d.ts +3 -2
  4. package/dist/solana/SolanaInitializer.d.ts +2 -2
  5. package/dist/solana/SolanaInitializer.js +9 -5
  6. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +4 -4
  7. package/dist/solana/btcrelay/SolanaBtcRelay.js +13 -14
  8. package/dist/solana/{base → chain}/SolanaAction.d.ts +2 -2
  9. package/dist/solana/chain/SolanaChainInterface.d.ts +58 -0
  10. package/dist/solana/chain/SolanaChainInterface.js +112 -0
  11. package/dist/solana/{base → chain}/SolanaModule.d.ts +3 -3
  12. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -0
  13. package/dist/solana/{base → chain}/modules/SolanaAddresses.js +2 -3
  14. package/dist/solana/events/SolanaChainEvents.d.ts +0 -4
  15. package/dist/solana/events/SolanaChainEvents.js +0 -16
  16. package/dist/solana/events/SolanaChainEventsBrowser.js +0 -1
  17. package/dist/solana/program/SolanaProgramBase.d.ts +11 -5
  18. package/dist/solana/program/SolanaProgramBase.js +7 -7
  19. package/dist/solana/program/SolanaProgramModule.d.ts +8 -0
  20. package/dist/solana/program/SolanaProgramModule.js +11 -0
  21. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +4 -3
  22. package/dist/solana/program/modules/SolanaProgramEvents.js +8 -8
  23. package/dist/solana/swaps/SolanaSwapData.js +1 -1
  24. package/dist/solana/swaps/SolanaSwapModule.d.ts +6 -5
  25. package/dist/solana/swaps/SolanaSwapModule.js +5 -6
  26. package/dist/solana/swaps/SolanaSwapProgram.d.ts +4 -23
  27. package/dist/solana/swaps/SolanaSwapProgram.js +22 -98
  28. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +3 -2
  29. package/dist/solana/swaps/modules/SolanaDataAccount.js +9 -9
  30. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +1 -1
  31. package/dist/solana/swaps/modules/SolanaLpVault.js +13 -13
  32. package/dist/solana/swaps/modules/SwapClaim.d.ts +3 -2
  33. package/dist/solana/swaps/modules/SwapClaim.js +15 -15
  34. package/dist/solana/swaps/modules/SwapInit.d.ts +1 -1
  35. package/dist/solana/swaps/modules/SwapInit.js +21 -21
  36. package/dist/solana/swaps/modules/SwapRefund.d.ts +1 -1
  37. package/dist/solana/swaps/modules/SwapRefund.js +17 -17
  38. package/package.json +2 -2
  39. package/src/index.ts +11 -11
  40. package/src/solana/SolanaChainType.ts +7 -2
  41. package/src/solana/SolanaInitializer.ts +13 -9
  42. package/src/solana/btcrelay/SolanaBtcRelay.ts +17 -17
  43. package/src/solana/{base → chain}/SolanaAction.ts +3 -3
  44. package/src/solana/chain/SolanaChainInterface.ts +175 -0
  45. package/src/solana/{base → chain}/SolanaModule.ts +3 -3
  46. package/src/solana/{base → chain}/modules/SolanaAddresses.ts +2 -3
  47. package/src/solana/events/SolanaChainEvents.ts +0 -17
  48. package/src/solana/events/SolanaChainEventsBrowser.ts +0 -1
  49. package/src/solana/program/SolanaProgramBase.ts +13 -10
  50. package/src/solana/program/SolanaProgramModule.ts +16 -0
  51. package/src/solana/program/modules/SolanaProgramEvents.ts +10 -9
  52. package/src/solana/swaps/SolanaSwapData.ts +1 -1
  53. package/src/solana/swaps/SolanaSwapModule.ts +8 -8
  54. package/src/solana/swaps/SolanaSwapProgram.ts +28 -133
  55. package/src/solana/swaps/modules/SolanaDataAccount.ts +11 -10
  56. package/src/solana/swaps/modules/SolanaLpVault.ts +15 -15
  57. package/src/solana/swaps/modules/SwapClaim.ts +17 -16
  58. package/src/solana/swaps/modules/SwapInit.ts +22 -22
  59. package/src/solana/swaps/modules/SwapRefund.ts +18 -18
  60. package/dist/solana/base/SolanaBase.d.ts +0 -36
  61. package/dist/solana/base/SolanaBase.js +0 -30
  62. package/dist/solana/base/modules/SolanaAddresses.d.ts +0 -9
  63. package/src/solana/base/SolanaBase.ts +0 -56
  64. /package/dist/solana/{base → chain}/SolanaAction.js +0 -0
  65. /package/dist/solana/{base → chain}/SolanaModule.js +0 -0
  66. /package/dist/solana/{base → chain}/modules/SolanaBlocks.d.ts +0 -0
  67. /package/dist/solana/{base → chain}/modules/SolanaBlocks.js +0 -0
  68. /package/dist/solana/{base → chain}/modules/SolanaEvents.d.ts +0 -0
  69. /package/dist/solana/{base → chain}/modules/SolanaEvents.js +0 -0
  70. /package/dist/solana/{base → chain}/modules/SolanaFees.d.ts +0 -0
  71. /package/dist/solana/{base → chain}/modules/SolanaFees.js +0 -0
  72. /package/dist/solana/{base → chain}/modules/SolanaSignatures.d.ts +0 -0
  73. /package/dist/solana/{base → chain}/modules/SolanaSignatures.js +0 -0
  74. /package/dist/solana/{base → chain}/modules/SolanaSlots.d.ts +0 -0
  75. /package/dist/solana/{base → chain}/modules/SolanaSlots.js +0 -0
  76. /package/dist/solana/{base → chain}/modules/SolanaTokens.d.ts +0 -0
  77. /package/dist/solana/{base → chain}/modules/SolanaTokens.js +0 -0
  78. /package/dist/solana/{base → chain}/modules/SolanaTransactions.d.ts +0 -0
  79. /package/dist/solana/{base → chain}/modules/SolanaTransactions.js +0 -0
  80. /package/src/solana/{base → chain}/modules/SolanaBlocks.ts +0 -0
  81. /package/src/solana/{base → chain}/modules/SolanaEvents.ts +0 -0
  82. /package/src/solana/{base → chain}/modules/SolanaFees.ts +0 -0
  83. /package/src/solana/{base → chain}/modules/SolanaSignatures.ts +0 -0
  84. /package/src/solana/{base → chain}/modules/SolanaSlots.ts +0 -0
  85. /package/src/solana/{base → chain}/modules/SolanaTokens.ts +0 -0
  86. /package/src/solana/{base → chain}/modules/SolanaTransactions.ts +0 -0
@@ -1,9 +1,8 @@
1
1
  import {SolanaSwapData} from "./SolanaSwapData";
2
2
  import {IdlAccounts} from "@coral-xyz/anchor";
3
3
  import {
4
- Connection, Keypair,
4
+ Connection,
5
5
  PublicKey,
6
- SendOptions
7
6
  } from "@solana/web3.js";
8
7
  import {sha256} from "@noble/hashes/sha2";
9
8
  import {SolanaBtcRelay} from "../btcrelay/SolanaBtcRelay";
@@ -16,11 +15,11 @@ import {SolanaBtcStoredHeader} from "../btcrelay/headers/SolanaBtcStoredHeader";
16
15
  import {
17
16
  getAssociatedTokenAddressSync,
18
17
  } from "@solana/spl-token";
19
- import {SolanaFees} from "../base/modules/SolanaFees";
18
+ import {SolanaFees} from "../chain/modules/SolanaFees";
20
19
  import {SwapProgram} from "./programTypes";
21
- import {SolanaRetryPolicy} from "../base/SolanaBase";
20
+ import {SolanaChainInterface, SolanaRetryPolicy} from "../chain/SolanaChainInterface";
22
21
  import {SolanaProgramBase} from "../program/SolanaProgramBase";
23
- import {SolanaTx} from "../base/modules/SolanaTransactions";
22
+ import {SolanaTx} from "../chain/modules/SolanaTransactions";
24
23
  import {SwapInit, SolanaPreFetchData, SolanaPreFetchVerification} from "./modules/SwapInit";
25
24
  import {SolanaDataAccount, StoredDataAccount} from "./modules/SolanaDataAccount";
26
25
  import {SwapRefund} from "./modules/SwapRefund";
@@ -28,9 +27,8 @@ import {SwapClaim} from "./modules/SwapClaim";
28
27
  import {SolanaLpVault} from "./modules/SolanaLpVault";
29
28
  import {Buffer} from "buffer";
30
29
  import {SolanaSigner} from "../wallet/SolanaSigner";
31
- import {SolanaKeypairWallet} from "../wallet/SolanaKeypairWallet";
32
30
  import {fromClaimHash, toBN, toClaimHash} from "../../utils/Utils";
33
- import {SolanaTokens} from "../base/modules/SolanaTokens";
31
+ import {SolanaTokens} from "../chain/modules/SolanaTokens";
34
32
  import * as BN from "bn.js";
35
33
 
36
34
  function toPublicKeyOrNull(str: string | null): PublicKey | null {
@@ -80,20 +78,18 @@ export class SolanaSwapProgram
80
78
  readonly LpVault: SolanaLpVault;
81
79
 
82
80
  constructor(
83
- connection: Connection,
81
+ chainInterface: SolanaChainInterface,
84
82
  btcRelay: SolanaBtcRelay<any>,
85
83
  storage: IStorageManager<StoredDataAccount>,
86
- programAddress?: string,
87
- retryPolicy?: SolanaRetryPolicy,
88
- solanaFeeEstimator: SolanaFees = btcRelay.Fees || new SolanaFees(connection)
84
+ programAddress?: string
89
85
  ) {
90
- super(connection, programIdl, programAddress, retryPolicy, solanaFeeEstimator);
86
+ super(chainInterface, programIdl, programAddress);
91
87
 
92
- this.Init = new SwapInit(this);
93
- this.Refund = new SwapRefund(this);
94
- this.Claim = new SwapClaim(this, btcRelay);
95
- this.DataAccount = new SolanaDataAccount(this, storage);
96
- this.LpVault = new SolanaLpVault(this);
88
+ this.Init = new SwapInit(chainInterface, this);
89
+ this.Refund = new SwapRefund(chainInterface, this);
90
+ this.Claim = new SwapClaim(chainInterface, this, btcRelay);
91
+ this.DataAccount = new SolanaDataAccount(chainInterface, this, storage);
92
+ this.LpVault = new SolanaLpVault(chainInterface, this);
97
93
  }
98
94
 
99
95
  async start(): Promise<void> {
@@ -143,11 +139,11 @@ export class SolanaSwapProgram
143
139
  }
144
140
 
145
141
  getDataSignature(signer: SolanaSigner, data: Buffer): Promise<string> {
146
- return this.Signatures.getDataSignature(signer, data);
142
+ return this.Chain.Signatures.getDataSignature(signer, data);
147
143
  }
148
144
 
149
145
  isValidDataSignature(data: Buffer, signature: string, publicKey: string): Promise<boolean> {
150
- return this.Signatures.isValidDataSignature(data, signature, publicKey);
146
+ return this.Chain.Signatures.isValidDataSignature(data, signature, publicKey);
151
147
  }
152
148
 
153
149
  ////////////////////////////////////////////
@@ -384,19 +380,14 @@ export class SolanaSwapProgram
384
380
  ////////////////////////////////////////////
385
381
  //// Utils
386
382
  async getBalance(signer: string, tokenAddress: string, inContract: boolean): Promise<bigint> {
383
+ if(!inContract) {
384
+ return await this.Chain.getBalance(signer, tokenAddress);
385
+ }
386
+
387
387
  const token = new PublicKey(tokenAddress);
388
388
  const publicKey = new PublicKey(signer);
389
389
 
390
- if(inContract) return await this.getIntermediaryBalance(publicKey, token);
391
-
392
- let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
393
- if(token.equals(SolanaTokens.WSOL_ADDRESS)) {
394
- const accountRentExemptCost = 1000000n;
395
- balance = balance - accountRentExemptCost;
396
- if(balance < 0n) balance = 0n;
397
- }
398
- this.logger.debug("getBalance(): token balance, token: "+token.toBase58()+" balance: "+balance.toString(10));
399
- return balance;
390
+ return await this.getIntermediaryBalance(publicKey, token);
400
391
  }
401
392
 
402
393
  getIntermediaryData(address: string, token: string): Promise<{
@@ -414,14 +405,6 @@ export class SolanaSwapProgram
414
405
  return this.LpVault.getIntermediaryBalance(address, token);
415
406
  }
416
407
 
417
- isValidAddress(address: string): boolean {
418
- return this.Addresses.isValidAddress(address);
419
- }
420
-
421
- getNativeCurrencyAddress(): string {
422
- return this.Tokens.getNativeCurrencyAddress().toString();
423
- }
424
-
425
408
  ////////////////////////////////////////////
426
409
  //// Transaction initializers
427
410
  async txsClaimWithSecret(
@@ -478,10 +461,6 @@ export class SolanaSwapProgram
478
461
  return this.LpVault.txsDeposit(new PublicKey(signer), new PublicKey(token), amount, feeRate);
479
462
  }
480
463
 
481
- txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]> {
482
- return this.Tokens.txsTransfer(new PublicKey(signer), new PublicKey(token), amount, new PublicKey(dstAddress), feeRate);
483
- }
484
-
485
464
  ////////////////////////////////////////////
486
465
  //// Executors
487
466
  async claimWithSecret(
@@ -493,7 +472,7 @@ export class SolanaSwapProgram
493
472
  txOptions?: TransactionConfirmationOptions
494
473
  ): Promise<string> {
495
474
  const result = await this.Claim.txsClaimWithSecret(signer.getPublicKey(), swapData, secret, checkExpiry, initAta, txOptions?.feeRate);
496
- const [signature] = await this.Transactions.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
475
+ const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
497
476
  return signature;
498
477
  }
499
478
 
@@ -521,7 +500,7 @@ export class SolanaSwapProgram
521
500
  if(txs===null) throw new Error("Btc relay not synchronized to required blockheight!");
522
501
 
523
502
  //TODO: This doesn't return proper tx signature
524
- const [signature] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal);
503
+ const [signature] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal);
525
504
  await this.DataAccount.removeDataAccount(data.storageAcc);
526
505
 
527
506
  return signature;
@@ -536,7 +515,7 @@ export class SolanaSwapProgram
536
515
  ): Promise<string> {
537
516
  let result = await this.txsRefund(signer.getAddress(), swapData, check, initAta, txOptions?.feeRate);
538
517
 
539
- const [signature] = await this.Transactions.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
518
+ const [signature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
540
519
 
541
520
  return signature;
542
521
  }
@@ -551,7 +530,7 @@ export class SolanaSwapProgram
551
530
  ): Promise<string> {
552
531
  let result = await this.txsRefundWithAuthorization(signer.getAddress(), swapData, signature, check, initAta, txOptions?.feeRate);
553
532
 
554
- const [txSignature] = await this.Transactions.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
533
+ const [txSignature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
555
534
 
556
535
  return txSignature;
557
536
  }
@@ -571,7 +550,7 @@ export class SolanaSwapProgram
571
550
 
572
551
  const result = await this.txsInit(swapData, signature, skipChecks, txOptions?.feeRate);
573
552
 
574
- const [txSignature] = await this.Transactions.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
553
+ const [txSignature] = await this.Chain.sendAndConfirm(signer, result, txOptions?.waitForConfirmation, txOptions?.abortSignal);
575
554
 
576
555
  return txSignature;
577
556
  }
@@ -589,7 +568,7 @@ export class SolanaSwapProgram
589
568
  const txsCommit = await this.txsInit(swapData, signature, skipChecks, txOptions?.feeRate);
590
569
  const txsClaim = await this.Claim.txsClaimWithSecret(signer.getPublicKey(), swapData, secret, true, false, txOptions?.feeRate, true);
591
570
 
592
- return await this.Transactions.sendAndConfirm(signer, txsCommit.concat(txsClaim), txOptions?.waitForConfirmation, txOptions?.abortSignal);
571
+ return await this.Chain.sendAndConfirm(signer, txsCommit.concat(txsClaim), txOptions?.waitForConfirmation, txOptions?.abortSignal);
593
572
  }
594
573
 
595
574
  async withdraw(
@@ -599,7 +578,7 @@ export class SolanaSwapProgram
599
578
  txOptions?: TransactionConfirmationOptions
600
579
  ): Promise<string> {
601
580
  const txs = await this.LpVault.txsWithdraw(signer.getPublicKey(), new PublicKey(token), amount, txOptions?.feeRate);
602
- const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
581
+ const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
603
582
  return txId;
604
583
  }
605
584
 
@@ -610,51 +589,10 @@ export class SolanaSwapProgram
610
589
  txOptions?: TransactionConfirmationOptions
611
590
  ): Promise<string> {
612
591
  const txs = await this.LpVault.txsDeposit(signer.getPublicKey(), new PublicKey(token), amount, txOptions?.feeRate);
613
- const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
614
- return txId;
615
- }
616
-
617
- async transfer(
618
- signer: SolanaSigner,
619
- token: string,
620
- amount: bigint,
621
- dstAddress: string,
622
- txOptions?: TransactionConfirmationOptions
623
- ): Promise<string> {
624
- const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new PublicKey(token), amount, new PublicKey(dstAddress), txOptions?.feeRate);
625
- const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
592
+ const [txId] = await this.Chain.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
626
593
  return txId;
627
594
  }
628
595
 
629
- ////////////////////////////////////////////
630
- //// Transactions
631
- sendAndConfirm(
632
- signer: SolanaSigner,
633
- txs: SolanaTx[],
634
- waitForConfirmation?: boolean,
635
- abortSignal?: AbortSignal,
636
- parallel?: boolean,
637
- onBeforePublish?: (txId: string, rawTx: string) => Promise<void>
638
- ): Promise<string[]> {
639
- return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
640
- }
641
-
642
- serializeTx(tx: SolanaTx): Promise<string> {
643
- return this.Transactions.serializeTx(tx);
644
- }
645
-
646
- deserializeTx(txData: string): Promise<SolanaTx> {
647
- return this.Transactions.deserializeTx(txData);
648
- }
649
-
650
- getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted"> {
651
- return this.Transactions.getTxIdStatus(txId);
652
- }
653
-
654
- getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted"> {
655
- return this.Transactions.getTxStatus(tx);
656
- }
657
-
658
596
  ////////////////////////////////////////////
659
597
  //// Fees
660
598
  getInitPayInFeeRate(offerer?: string, claimer?: string, token?: string, claimHash?: string): Promise<string> {
@@ -721,49 +659,6 @@ export class SolanaSwapProgram
721
659
  return this.Refund.getRawRefundFee(swapData, feeRate);
722
660
  }
723
661
 
724
- ///////////////////////////////////
725
- //// Callbacks & handlers
726
- offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean {
727
- return true;
728
- }
729
-
730
- onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void {}
731
-
732
- onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void {
733
- this.Transactions.onBeforeTxSigned(callback);
734
- }
735
-
736
- offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean {
737
- return this.Transactions.offBeforeTxSigned(callback);
738
- }
739
-
740
- onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void {
741
- this.Transactions.onSendTransaction(callback);
742
- }
743
-
744
- offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean {
745
- return this.Transactions.offSendTransaction(callback);
746
- }
747
-
748
- isValidToken(tokenIdentifier: string): boolean {
749
- try {
750
- new PublicKey(tokenIdentifier);
751
- return true;
752
- } catch (e) {
753
- return false;
754
- }
755
- }
756
-
757
- randomAddress(): string {
758
- return Keypair.generate().publicKey.toString();
759
- }
760
-
761
- randomSigner(): SolanaSigner {
762
- const keypair = Keypair.generate();
763
- const wallet = new SolanaKeypairWallet(keypair);
764
- return new SolanaSigner(wallet, keypair);
765
- }
766
-
767
662
  getExtraData(outputScript: Buffer, amount: bigint, confirmations: number, nonce?: bigint): Buffer {
768
663
  return Buffer.from(sha256(Buffer.concat([
769
664
  BigIntBufferUtils.toBuffer(amount, "le", 8),
@@ -2,11 +2,12 @@ import {SolanaSwapModule} from "../SolanaSwapModule";
2
2
  import {AccountInfo, PublicKey, Signer, SystemProgram} from "@solana/web3.js";
3
3
  import {IStorageManager, StorageObject} from "@atomiqlabs/base";
4
4
  import {SolanaSwapProgram} from "../SolanaSwapProgram";
5
- import {SolanaAction} from "../../base/SolanaAction";
6
- import {SolanaTx} from "../../base/modules/SolanaTransactions";
5
+ import {SolanaAction} from "../../chain/SolanaAction";
6
+ import {SolanaTx} from "../../chain/modules/SolanaTransactions";
7
7
  import {tryWithRetries} from "../../../utils/Utils";
8
8
  import {SolanaSigner} from "../../wallet/SolanaSigner";
9
9
  import {randomBytes} from "@noble/hashes/utils";
10
+ import {SolanaChainInterface} from "../../chain/SolanaChainInterface";
10
11
 
11
12
  export class StoredDataAccount implements StorageObject {
12
13
 
@@ -37,10 +38,10 @@ export class StoredDataAccount implements StorageObject {
37
38
 
38
39
  export class SolanaDataAccount extends SolanaSwapModule {
39
40
 
40
- readonly SwapTxDataAlt = this.root.keypair(
41
+ readonly SwapTxDataAlt = this.program.keypair(
41
42
  (reversedTxId: Buffer, signer: Signer) => [Buffer.from(signer.secretKey), reversedTxId]
42
43
  );
43
- readonly SwapTxDataAltBuffer = this.root.keypair((reversedTxId: Buffer, secret: Buffer) => [secret, reversedTxId]);
44
+ readonly SwapTxDataAltBuffer = this.program.keypair((reversedTxId: Buffer, secret: Buffer) => [secret, reversedTxId]);
44
45
 
45
46
  readonly storage: IStorageManager<StoredDataAccount>;
46
47
 
@@ -76,9 +77,9 @@ export class SolanaDataAccount extends SolanaSwapModule {
76
77
  newAccountPubkey: accountKey.publicKey,
77
78
  lamports: lamportsDeposit,
78
79
  space: accountSize,
79
- programId: this.program.programId
80
+ programId: this.swapProgram.programId
80
81
  }),
81
- await this.program.methods
82
+ await this.swapProgram.methods
82
83
  .initData()
83
84
  .accounts({
84
85
  signer,
@@ -98,7 +99,7 @@ export class SolanaDataAccount extends SolanaSwapModule {
98
99
  return new SolanaAction(
99
100
  signer,
100
101
  this.root,
101
- await this.program.methods
102
+ await this.swapProgram.methods
102
103
  .closeData()
103
104
  .accounts({
104
105
  signer,
@@ -134,7 +135,7 @@ export class SolanaDataAccount extends SolanaSwapModule {
134
135
  return {
135
136
  bytesWritten: writeLen,
136
137
  action: new SolanaAction(signer, this.root,
137
- await this.program.methods
138
+ await this.swapProgram.methods
138
139
  .writeData(offset, writeData.slice(offset, offset+writeLen))
139
140
  .accounts({
140
141
  signer,
@@ -146,8 +147,8 @@ export class SolanaDataAccount extends SolanaSwapModule {
146
147
  };
147
148
  }
148
149
 
149
- constructor(root: SolanaSwapProgram, storage: IStorageManager<StoredDataAccount>) {
150
- super(root);
150
+ constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram, storage: IStorageManager<StoredDataAccount>) {
151
+ super(chainInterface, program);
151
152
  this.storage = storage;
152
153
  }
153
154
 
@@ -1,5 +1,5 @@
1
1
  import {SolanaSwapModule} from "../SolanaSwapModule";
2
- import {SolanaAction} from "../../base/SolanaAction";
2
+ import {SolanaAction} from "../../chain/SolanaAction";
3
3
  import {PublicKey, SystemProgram} from "@solana/web3.js";
4
4
  import {
5
5
  Account,
@@ -7,12 +7,12 @@ import {
7
7
  getAssociatedTokenAddressSync,
8
8
  TOKEN_PROGRAM_ID
9
9
  } from "@solana/spl-token";
10
- import {SolanaTx} from "../../base/modules/SolanaTransactions";
10
+ import {SolanaTx} from "../../chain/modules/SolanaTransactions";
11
11
  import {toBigInt, toBN, tryWithRetries} from "../../../utils/Utils";
12
12
  import {SwapProgram} from "../programTypes";
13
13
  import { IntermediaryReputationType } from "@atomiqlabs/base";
14
14
  import { IdlAccounts } from "@coral-xyz/anchor";
15
- import {SolanaTokens} from "../../base/modules/SolanaTokens";
15
+ import {SolanaTokens} from "../../chain/modules/SolanaTokens";
16
16
 
17
17
  export class SolanaLpVault extends SolanaSwapModule {
18
18
 
@@ -33,14 +33,14 @@ export class SolanaLpVault extends SolanaSwapModule {
33
33
  private async Withdraw(signer: PublicKey, token: PublicKey, amount: bigint): Promise<SolanaAction> {
34
34
  const ata = getAssociatedTokenAddressSync(token, signer);
35
35
  return new SolanaAction(signer, this.root,
36
- await this.program.methods
36
+ await this.swapProgram.methods
37
37
  .withdraw(toBN(amount))
38
38
  .accounts({
39
39
  signer,
40
40
  signerAta: ata,
41
- userData: this.root.SwapUserVault(signer, token),
42
- vault: this.root.SwapVault(token),
43
- vaultAuthority: this.root.SwapVaultAuthority,
41
+ userData: this.program.SwapUserVault(signer, token),
42
+ vault: this.program.SwapVault(token),
43
+ vaultAuthority: this.program.SwapVaultAuthority,
44
44
  mint: token,
45
45
  tokenProgram: TOKEN_PROGRAM_ID
46
46
  })
@@ -61,14 +61,14 @@ export class SolanaLpVault extends SolanaSwapModule {
61
61
  private async Deposit(signer: PublicKey, token: PublicKey, amount: bigint): Promise<SolanaAction> {
62
62
  const ata = getAssociatedTokenAddressSync(token, signer);
63
63
  return new SolanaAction(signer, this.root,
64
- await this.program.methods
64
+ await this.swapProgram.methods
65
65
  .deposit(toBN(amount))
66
66
  .accounts({
67
67
  signer,
68
68
  signerAta: ata,
69
- userData: this.root.SwapUserVault(signer, token),
70
- vault: this.root.SwapVault(token),
71
- vaultAuthority: this.root.SwapVaultAuthority,
69
+ userData: this.program.SwapUserVault(signer, token),
70
+ vault: this.program.SwapVault(token),
71
+ vaultAuthority: this.program.SwapVaultAuthority,
72
72
  mint: token,
73
73
  systemProgram: SystemProgram.programId,
74
74
  tokenProgram: TOKEN_PROGRAM_ID
@@ -88,8 +88,8 @@ export class SolanaLpVault extends SolanaSwapModule {
88
88
  balance: bigint,
89
89
  reputation: IntermediaryReputationType
90
90
  }> {
91
- const data: IdlAccounts<SwapProgram>["userAccount"] = await this.program.account.userAccount.fetchNullable(
92
- this.root.SwapUserVault(address, token)
91
+ const data: IdlAccounts<SwapProgram>["userAccount"] = await this.swapProgram.account.userAccount.fetchNullable(
92
+ this.program.SwapUserVault(address, token)
93
93
  );
94
94
 
95
95
  if(data==null) return null;
@@ -208,8 +208,8 @@ export class SolanaLpVault extends SolanaSwapModule {
208
208
  return this.root.Fees.getFeeRate([
209
209
  signer,
210
210
  ata,
211
- this.root.SwapUserVault(signer, token),
212
- this.root.SwapVault(token)
211
+ this.program.SwapUserVault(signer, token),
212
+ this.program.SwapVault(token)
213
213
  ])
214
214
  }
215
215
 
@@ -1,17 +1,18 @@
1
1
  import {SolanaSwapModule} from "../SolanaSwapModule";
2
2
  import {SolanaSwapData} from "../SolanaSwapData";
3
- import {SolanaAction} from "../../base/SolanaAction";
3
+ import {SolanaAction} from "../../chain/SolanaAction";
4
4
  import {TOKEN_PROGRAM_ID} from "@solana/spl-token";
5
5
  import {ChainSwapType, RelaySynchronizer, SwapDataVerificationError} from "@atomiqlabs/base";
6
6
  import {PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY} from "@solana/web3.js";
7
- import {SolanaTx} from "../../base/modules/SolanaTransactions";
7
+ import {SolanaTx} from "../../chain/modules/SolanaTransactions";
8
8
  import {SolanaBtcStoredHeader} from "../../btcrelay/headers/SolanaBtcStoredHeader";
9
9
  import {tryWithRetries} from "../../../utils/Utils";
10
10
  import {SolanaBtcRelay} from "../../btcrelay/SolanaBtcRelay";
11
11
  import {SolanaSwapProgram} from "../SolanaSwapProgram";
12
12
  import {SolanaSigner} from "../../wallet/SolanaSigner";
13
- import {SolanaTokens} from "../../base/modules/SolanaTokens";
13
+ import {SolanaTokens} from "../../chain/modules/SolanaTokens";
14
14
  import * as BN from "bn.js";
15
+ import {SolanaChainInterface} from "../../chain/SolanaChainInterface";
15
16
 
16
17
  export class SwapClaim extends SolanaSwapModule {
17
18
 
@@ -54,7 +55,7 @@ export class SwapClaim extends SolanaSwapModule {
54
55
  const accounts = {
55
56
  signer,
56
57
  initializer: swapData.isPayIn() ? swapData.offerer : swapData.claimer,
57
- escrowState: this.root.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")),
58
+ escrowState: this.program.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")),
58
59
  ixSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
59
60
  data: isDataKey ? secretOrDataKey : null,
60
61
  };
@@ -64,13 +65,13 @@ export class SwapClaim extends SolanaSwapModule {
64
65
 
65
66
  if(swapData.isPayOut()) {
66
67
  return new SolanaAction(signer, this.root,
67
- await this.program.methods
68
+ await this.swapProgram.methods
68
69
  .claimerClaimPayOut(secretBuffer)
69
70
  .accounts({
70
71
  ...accounts,
71
72
  claimerAta: swapData.claimerAta,
72
- vault: this.root.SwapVault(swapData.token),
73
- vaultAuthority: this.root.SwapVaultAuthority,
73
+ vault: this.program.SwapVault(swapData.token),
74
+ vaultAuthority: this.program.SwapVaultAuthority,
74
75
  tokenProgram: TOKEN_PROGRAM_ID
75
76
  })
76
77
  .instruction(),
@@ -78,11 +79,11 @@ export class SwapClaim extends SolanaSwapModule {
78
79
  );
79
80
  } else {
80
81
  return new SolanaAction(signer, this.root,
81
- await this.program.methods
82
+ await this.swapProgram.methods
82
83
  .claimerClaim(secretBuffer)
83
84
  .accounts({
84
85
  ...accounts,
85
- claimerUserData: this.root.SwapUserVault(swapData.claimer, swapData.token)
86
+ claimerUserData: this.program.SwapUserVault(swapData.claimer, swapData.token)
86
87
  })
87
88
  .instruction(),
88
89
  this.getComputeBudget(swapData)
@@ -123,8 +124,8 @@ export class SwapClaim extends SolanaSwapModule {
123
124
  return action;
124
125
  }
125
126
 
126
- constructor(root: SolanaSwapProgram, btcRelay: SolanaBtcRelay<any>) {
127
- super(root);
127
+ constructor(chainInterface: SolanaChainInterface, program: SolanaSwapProgram, btcRelay: SolanaBtcRelay<any>) {
128
+ super(chainInterface, program);
128
129
  this.btcRelay = btcRelay;
129
130
  }
130
131
 
@@ -216,7 +217,7 @@ export class SwapClaim extends SolanaSwapModule {
216
217
  ]);
217
218
  this.logger.debug("addTxsWriteTransactionData(): writing transaction data: ", writeData.toString("hex"));
218
219
 
219
- return this.root.DataAccount.addTxsWriteData(signer, reversedTxId, writeData, txs, feeRate);
220
+ return this.program.DataAccount.addTxsWriteData(signer, reversedTxId, writeData, txs, feeRate);
220
221
  }
221
222
 
222
223
  /**
@@ -255,7 +256,7 @@ export class SwapClaim extends SolanaSwapModule {
255
256
  ): Promise<SolanaTx[]> {
256
257
  //We need to be sure that this transaction confirms in time, otherwise we reveal the secret to the counterparty
257
258
  // and won't claim the funds
258
- if(checkExpiry && await this.root.isExpired(swapData.claimer.toString(), swapData)) {
259
+ if(checkExpiry && await this.program.isExpired(swapData.claimer.toString(), swapData)) {
259
260
  throw new SwapDataVerificationError("Not enough time to reliably pay the invoice");
260
261
  }
261
262
  const shouldInitAta = !skipAtaCheck && swapData.isPayOut() && !await this.root.Tokens.ataExists(swapData.claimerAta);
@@ -343,7 +344,7 @@ export class SwapClaim extends SolanaSwapModule {
343
344
  public getClaimFeeRate(signer: PublicKey, swapData: SolanaSwapData): Promise<string> {
344
345
  const accounts: PublicKey[] = [signer];
345
346
  if(swapData.payOut) {
346
- if(swapData.token!=null) accounts.push(this.root.SwapVault(swapData.token));
347
+ if(swapData.token!=null) accounts.push(this.program.SwapVault(swapData.token));
347
348
  if(swapData.payIn) {
348
349
  if(swapData.offerer!=null) accounts.push(swapData.offerer);
349
350
  } else {
@@ -351,7 +352,7 @@ export class SwapClaim extends SolanaSwapModule {
351
352
  }
352
353
  if(swapData.claimerAta!=null && !swapData.claimerAta.equals(PublicKey.default)) accounts.push(swapData.claimerAta);
353
354
  } else {
354
- if(swapData.claimer!=null && swapData.token!=null) accounts.push(this.root.SwapUserVault(swapData.claimer, swapData.token));
355
+ if(swapData.claimer!=null && swapData.token!=null) accounts.push(this.program.SwapUserVault(swapData.claimer, swapData.token));
355
356
 
356
357
  if(swapData.payIn) {
357
358
  if(swapData.offerer!=null) accounts.push(swapData.offerer);
@@ -360,7 +361,7 @@ export class SwapClaim extends SolanaSwapModule {
360
361
  }
361
362
  }
362
363
 
363
- if(swapData.paymentHash!=null) accounts.push(this.root.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")));
364
+ if(swapData.paymentHash!=null) accounts.push(this.program.SwapEscrowState(Buffer.from(swapData.paymentHash, "hex")));
364
365
 
365
366
  return this.root.Fees.getFeeRate(accounts);
366
367
  }