@atomiqlabs/chain-solana 10.0.0-dev.3 → 11.0.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 (114) hide show
  1. package/LICENSE +201 -201
  2. package/dist/index.d.ts +29 -29
  3. package/dist/index.js +45 -45
  4. package/dist/solana/SolanaChainType.d.ts +10 -10
  5. package/dist/solana/SolanaChainType.js +2 -2
  6. package/dist/solana/SolanaChains.d.ts +20 -20
  7. package/dist/solana/SolanaChains.js +25 -25
  8. package/dist/solana/SolanaInitializer.d.ts +18 -18
  9. package/dist/solana/SolanaInitializer.js +63 -63
  10. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +228 -228
  11. package/dist/solana/btcrelay/SolanaBtcRelay.js +441 -441
  12. package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +29 -29
  13. package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +34 -34
  14. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +46 -46
  15. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +78 -78
  16. package/dist/solana/btcrelay/program/programIdl.json +671 -671
  17. package/dist/solana/chain/SolanaAction.d.ts +26 -26
  18. package/dist/solana/chain/SolanaAction.js +86 -86
  19. package/dist/solana/chain/SolanaChainInterface.d.ts +58 -58
  20. package/dist/solana/chain/SolanaChainInterface.js +112 -112
  21. package/dist/solana/chain/SolanaModule.d.ts +14 -14
  22. package/dist/solana/chain/SolanaModule.js +13 -13
  23. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
  24. package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
  25. package/dist/solana/chain/modules/SolanaBlocks.d.ts +28 -28
  26. package/dist/solana/chain/modules/SolanaBlocks.js +72 -72
  27. package/dist/solana/chain/modules/SolanaEvents.d.ts +25 -25
  28. package/dist/solana/chain/modules/SolanaEvents.js +58 -58
  29. package/dist/solana/chain/modules/SolanaFees.d.ts +121 -121
  30. package/dist/solana/chain/modules/SolanaFees.js +379 -379
  31. package/dist/solana/chain/modules/SolanaSignatures.d.ts +23 -23
  32. package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
  33. package/dist/solana/chain/modules/SolanaSlots.d.ts +31 -31
  34. package/dist/solana/chain/modules/SolanaSlots.js +68 -68
  35. package/dist/solana/chain/modules/SolanaTokens.d.ts +136 -136
  36. package/dist/solana/chain/modules/SolanaTokens.js +248 -248
  37. package/dist/solana/chain/modules/SolanaTransactions.d.ts +124 -124
  38. package/dist/solana/chain/modules/SolanaTransactions.js +332 -332
  39. package/dist/solana/events/SolanaChainEvents.d.ts +88 -88
  40. package/dist/solana/events/SolanaChainEvents.js +256 -256
  41. package/dist/solana/events/SolanaChainEventsBrowser.d.ts +85 -85
  42. package/dist/solana/events/SolanaChainEventsBrowser.js +194 -194
  43. package/dist/solana/program/SolanaProgramBase.d.ts +40 -40
  44. package/dist/solana/program/SolanaProgramBase.js +43 -43
  45. package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
  46. package/dist/solana/program/SolanaProgramModule.js +11 -11
  47. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +59 -59
  48. package/dist/solana/program/modules/SolanaProgramEvents.js +103 -103
  49. package/dist/solana/swaps/SolanaSwapData.d.ts +59 -59
  50. package/dist/solana/swaps/SolanaSwapData.js +267 -267
  51. package/dist/solana/swaps/SolanaSwapModule.d.ts +10 -10
  52. package/dist/solana/swaps/SolanaSwapModule.js +11 -11
  53. package/dist/solana/swaps/SolanaSwapProgram.d.ts +202 -202
  54. package/dist/solana/swaps/SolanaSwapProgram.js +470 -463
  55. package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
  56. package/dist/solana/swaps/SwapTypeEnum.js +42 -42
  57. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +94 -94
  58. package/dist/solana/swaps/modules/SolanaDataAccount.js +231 -231
  59. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +71 -71
  60. package/dist/solana/swaps/modules/SolanaLpVault.js +173 -173
  61. package/dist/solana/swaps/modules/SwapClaim.d.ts +129 -129
  62. package/dist/solana/swaps/modules/SwapClaim.js +291 -291
  63. package/dist/solana/swaps/modules/SwapInit.d.ts +217 -217
  64. package/dist/solana/swaps/modules/SwapInit.js +519 -519
  65. package/dist/solana/swaps/modules/SwapRefund.d.ts +82 -82
  66. package/dist/solana/swaps/modules/SwapRefund.js +252 -252
  67. package/dist/solana/swaps/programIdl.json +945 -945
  68. package/dist/solana/swaps/programTypes.d.ts +943 -943
  69. package/dist/solana/swaps/programTypes.js +945 -945
  70. package/dist/solana/wallet/SolanaKeypairWallet.d.ts +9 -9
  71. package/dist/solana/wallet/SolanaKeypairWallet.js +33 -33
  72. package/dist/solana/wallet/SolanaSigner.d.ts +10 -10
  73. package/dist/solana/wallet/SolanaSigner.js +16 -16
  74. package/dist/utils/Utils.d.ts +53 -53
  75. package/dist/utils/Utils.js +170 -170
  76. package/package.json +41 -41
  77. package/src/index.ts +36 -36
  78. package/src/solana/SolanaChainType.ts +25 -25
  79. package/src/solana/SolanaChains.ts +23 -23
  80. package/src/solana/SolanaInitializer.ts +102 -102
  81. package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -588
  82. package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +57 -57
  83. package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +102 -102
  84. package/src/solana/btcrelay/program/programIdl.json +670 -670
  85. package/src/solana/chain/SolanaAction.ts +108 -108
  86. package/src/solana/chain/SolanaChainInterface.ts +174 -174
  87. package/src/solana/chain/SolanaModule.ts +20 -20
  88. package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
  89. package/src/solana/chain/modules/SolanaBlocks.ts +78 -78
  90. package/src/solana/chain/modules/SolanaEvents.ts +56 -56
  91. package/src/solana/chain/modules/SolanaFees.ts +450 -450
  92. package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
  93. package/src/solana/chain/modules/SolanaSlots.ts +82 -82
  94. package/src/solana/chain/modules/SolanaTokens.ts +307 -307
  95. package/src/solana/chain/modules/SolanaTransactions.ts +370 -370
  96. package/src/solana/events/SolanaChainEvents.ts +299 -299
  97. package/src/solana/events/SolanaChainEventsBrowser.ts +256 -256
  98. package/src/solana/program/SolanaProgramBase.ts +79 -79
  99. package/src/solana/program/SolanaProgramModule.ts +15 -15
  100. package/src/solana/program/modules/SolanaProgramEvents.ts +140 -140
  101. package/src/solana/swaps/SolanaSwapData.ts +379 -379
  102. package/src/solana/swaps/SolanaSwapModule.ts +16 -16
  103. package/src/solana/swaps/SolanaSwapProgram.ts +697 -692
  104. package/src/solana/swaps/SwapTypeEnum.ts +29 -29
  105. package/src/solana/swaps/modules/SolanaDataAccount.ts +307 -307
  106. package/src/solana/swaps/modules/SolanaLpVault.ts +215 -215
  107. package/src/solana/swaps/modules/SwapClaim.ts +389 -389
  108. package/src/solana/swaps/modules/SwapInit.ts +663 -663
  109. package/src/solana/swaps/modules/SwapRefund.ts +312 -312
  110. package/src/solana/swaps/programIdl.json +944 -944
  111. package/src/solana/swaps/programTypes.ts +1885 -1885
  112. package/src/solana/wallet/SolanaKeypairWallet.ts +36 -36
  113. package/src/solana/wallet/SolanaSigner.ts +23 -23
  114. package/src/utils/Utils.ts +180 -180
@@ -1,26 +1,26 @@
1
- import { PublicKey, Signer, TransactionInstruction } from "@solana/web3.js";
2
- import { SolanaTx } from "./modules/SolanaTransactions";
3
- import { SolanaChainInterface } from "./SolanaChainInterface";
4
- export declare class SolanaAction {
5
- computeBudget: number;
6
- readonly mainSigner: PublicKey;
7
- private readonly root;
8
- private readonly instructions;
9
- private feeRate;
10
- private readonly signers;
11
- private firstIxBeforeComputeBudget;
12
- constructor(mainSigner: PublicKey, root: SolanaChainInterface, instructions?: TransactionInstruction[] | TransactionInstruction, computeBudget?: number, feeRate?: string, signers?: Signer[], firstIxBeforeComputeBudget?: boolean);
13
- private estimateFee;
14
- addIx(instruction: TransactionInstruction, computeBudget?: number, signers?: Signer[]): void;
15
- add(action: SolanaAction): this;
16
- addAction(action: SolanaAction, index?: number): this;
17
- tx(feeRate?: string, block?: {
18
- blockhash: string;
19
- blockHeight: number;
20
- }): Promise<SolanaTx>;
21
- addToTxs(txs: SolanaTx[], feeRate?: string, block?: {
22
- blockhash: string;
23
- blockHeight: number;
24
- }): Promise<void>;
25
- ixsLength(): number;
26
- }
1
+ import { PublicKey, Signer, TransactionInstruction } from "@solana/web3.js";
2
+ import { SolanaTx } from "./modules/SolanaTransactions";
3
+ import { SolanaChainInterface } from "./SolanaChainInterface";
4
+ export declare class SolanaAction {
5
+ computeBudget: number;
6
+ readonly mainSigner: PublicKey;
7
+ private readonly root;
8
+ private readonly instructions;
9
+ private feeRate;
10
+ private readonly signers;
11
+ private firstIxBeforeComputeBudget;
12
+ constructor(mainSigner: PublicKey, root: SolanaChainInterface, instructions?: TransactionInstruction[] | TransactionInstruction, computeBudget?: number, feeRate?: string, signers?: Signer[], firstIxBeforeComputeBudget?: boolean);
13
+ private estimateFee;
14
+ addIx(instruction: TransactionInstruction, computeBudget?: number, signers?: Signer[]): void;
15
+ add(action: SolanaAction): this;
16
+ addAction(action: SolanaAction, index?: number): this;
17
+ tx(feeRate?: string, block?: {
18
+ blockhash: string;
19
+ blockHeight: number;
20
+ }): Promise<SolanaTx>;
21
+ addToTxs(txs: SolanaTx[], feeRate?: string, block?: {
22
+ blockhash: string;
23
+ blockHeight: number;
24
+ }): Promise<void>;
25
+ ixsLength(): number;
26
+ }
@@ -1,86 +1,86 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaAction = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- class SolanaAction {
6
- constructor(mainSigner, root, instructions = [], computeBudget = 0, feeRate, signers, firstIxBeforeComputeBudget) {
7
- this.firstIxBeforeComputeBudget = false;
8
- this.mainSigner = mainSigner;
9
- this.root = root;
10
- this.instructions = Array.isArray(instructions) ? instructions : [instructions];
11
- this.computeBudget = computeBudget;
12
- this.feeRate = feeRate;
13
- this.signers = signers || [];
14
- if (firstIxBeforeComputeBudget != null)
15
- this.firstIxBeforeComputeBudget = firstIxBeforeComputeBudget;
16
- }
17
- estimateFee() {
18
- const mutableAccounts = [];
19
- this.instructions.forEach(ix => ix.keys.forEach(key => key.isWritable && mutableAccounts.push(key.pubkey)));
20
- return this.root.Fees.getFeeRate(mutableAccounts);
21
- }
22
- addIx(instruction, computeBudget, signers) {
23
- this.instructions.push(instruction);
24
- if (this.computeBudget == null) {
25
- this.computeBudget = computeBudget;
26
- }
27
- else {
28
- if (computeBudget != null)
29
- this.computeBudget += computeBudget;
30
- }
31
- }
32
- add(action) {
33
- return this.addAction(action);
34
- }
35
- addAction(action, index = this.instructions.length) {
36
- if (action.firstIxBeforeComputeBudget) {
37
- if (this.instructions.length > 0)
38
- throw new Error("Tried to add firstIxBeforeComputeBudget action to existing action with instructions");
39
- this.firstIxBeforeComputeBudget = true;
40
- }
41
- if (this.firstIxBeforeComputeBudget && this.instructions.length > 0 && index === 0)
42
- throw new Error("Tried adding to firstIxBeforeComputeBudget action on 0th index");
43
- if (!action.mainSigner.equals(this.mainSigner))
44
- throw new Error("Actions need to have the same signer!");
45
- if (this.computeBudget == null && action.computeBudget != null)
46
- this.computeBudget = action.computeBudget;
47
- if (this.computeBudget != null && action.computeBudget != null)
48
- this.computeBudget += action.computeBudget;
49
- this.instructions.splice(index, 0, ...action.instructions);
50
- this.signers.push(...action.signers);
51
- if (this.feeRate == null)
52
- this.feeRate = action.feeRate;
53
- return this;
54
- }
55
- async tx(feeRate, block) {
56
- const tx = new web3_js_1.Transaction();
57
- tx.feePayer = this.mainSigner;
58
- if (feeRate == null)
59
- feeRate = this.feeRate;
60
- if (feeRate == null)
61
- feeRate = await this.estimateFee();
62
- let instructions = this.instructions;
63
- if (instructions.length > 0 && this.firstIxBeforeComputeBudget) {
64
- tx.add(this.instructions[0]);
65
- instructions = this.instructions.slice(1);
66
- }
67
- this.root.Fees.applyFeeRateBegin(tx, this.computeBudget, feeRate);
68
- instructions.forEach(ix => tx.add(ix));
69
- this.root.Fees.applyFeeRateEnd(tx, this.computeBudget, feeRate);
70
- if (block != null) {
71
- tx.recentBlockhash = block.blockhash;
72
- tx.lastValidBlockHeight = block.blockHeight + this.root.TX_SLOT_VALIDITY;
73
- }
74
- return {
75
- tx,
76
- signers: this.signers
77
- };
78
- }
79
- async addToTxs(txs, feeRate, block) {
80
- txs.push(await this.tx(feeRate, block));
81
- }
82
- ixsLength() {
83
- return this.instructions.length;
84
- }
85
- }
86
- exports.SolanaAction = SolanaAction;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaAction = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ class SolanaAction {
6
+ constructor(mainSigner, root, instructions = [], computeBudget = 0, feeRate, signers, firstIxBeforeComputeBudget) {
7
+ this.firstIxBeforeComputeBudget = false;
8
+ this.mainSigner = mainSigner;
9
+ this.root = root;
10
+ this.instructions = Array.isArray(instructions) ? instructions : [instructions];
11
+ this.computeBudget = computeBudget;
12
+ this.feeRate = feeRate;
13
+ this.signers = signers || [];
14
+ if (firstIxBeforeComputeBudget != null)
15
+ this.firstIxBeforeComputeBudget = firstIxBeforeComputeBudget;
16
+ }
17
+ estimateFee() {
18
+ const mutableAccounts = [];
19
+ this.instructions.forEach(ix => ix.keys.forEach(key => key.isWritable && mutableAccounts.push(key.pubkey)));
20
+ return this.root.Fees.getFeeRate(mutableAccounts);
21
+ }
22
+ addIx(instruction, computeBudget, signers) {
23
+ this.instructions.push(instruction);
24
+ if (this.computeBudget == null) {
25
+ this.computeBudget = computeBudget;
26
+ }
27
+ else {
28
+ if (computeBudget != null)
29
+ this.computeBudget += computeBudget;
30
+ }
31
+ }
32
+ add(action) {
33
+ return this.addAction(action);
34
+ }
35
+ addAction(action, index = this.instructions.length) {
36
+ if (action.firstIxBeforeComputeBudget) {
37
+ if (this.instructions.length > 0)
38
+ throw new Error("Tried to add firstIxBeforeComputeBudget action to existing action with instructions");
39
+ this.firstIxBeforeComputeBudget = true;
40
+ }
41
+ if (this.firstIxBeforeComputeBudget && this.instructions.length > 0 && index === 0)
42
+ throw new Error("Tried adding to firstIxBeforeComputeBudget action on 0th index");
43
+ if (!action.mainSigner.equals(this.mainSigner))
44
+ throw new Error("Actions need to have the same signer!");
45
+ if (this.computeBudget == null && action.computeBudget != null)
46
+ this.computeBudget = action.computeBudget;
47
+ if (this.computeBudget != null && action.computeBudget != null)
48
+ this.computeBudget += action.computeBudget;
49
+ this.instructions.splice(index, 0, ...action.instructions);
50
+ this.signers.push(...action.signers);
51
+ if (this.feeRate == null)
52
+ this.feeRate = action.feeRate;
53
+ return this;
54
+ }
55
+ async tx(feeRate, block) {
56
+ const tx = new web3_js_1.Transaction();
57
+ tx.feePayer = this.mainSigner;
58
+ if (feeRate == null)
59
+ feeRate = this.feeRate;
60
+ if (feeRate == null)
61
+ feeRate = await this.estimateFee();
62
+ let instructions = this.instructions;
63
+ if (instructions.length > 0 && this.firstIxBeforeComputeBudget) {
64
+ tx.add(this.instructions[0]);
65
+ instructions = this.instructions.slice(1);
66
+ }
67
+ this.root.Fees.applyFeeRateBegin(tx, this.computeBudget, feeRate);
68
+ instructions.forEach(ix => tx.add(ix));
69
+ this.root.Fees.applyFeeRateEnd(tx, this.computeBudget, feeRate);
70
+ if (block != null) {
71
+ tx.recentBlockhash = block.blockhash;
72
+ tx.lastValidBlockHeight = block.blockHeight + this.root.TX_SLOT_VALIDITY;
73
+ }
74
+ return {
75
+ tx,
76
+ signers: this.signers
77
+ };
78
+ }
79
+ async addToTxs(txs, feeRate, block) {
80
+ txs.push(await this.tx(feeRate, block));
81
+ }
82
+ ixsLength() {
83
+ return this.instructions.length;
84
+ }
85
+ }
86
+ exports.SolanaAction = SolanaAction;
@@ -1,58 +1,58 @@
1
- /// <reference types="node" />
2
- import { Connection, SendOptions } from "@solana/web3.js";
3
- import { SolanaFees } from "./modules/SolanaFees";
4
- import { SolanaBlocks } from "./modules/SolanaBlocks";
5
- import { SolanaSlots } from "./modules/SolanaSlots";
6
- import { SolanaTokens } from "./modules/SolanaTokens";
7
- import { SolanaTransactions, SolanaTx } from "./modules/SolanaTransactions";
8
- import { SolanaSignatures } from "./modules/SolanaSignatures";
9
- import { SolanaEvents } from "./modules/SolanaEvents";
10
- import { ChainInterface, TransactionConfirmationOptions } from "@atomiqlabs/base";
11
- import { SolanaSigner } from "../wallet/SolanaSigner";
12
- import { Buffer } from "buffer";
13
- export type SolanaRetryPolicy = {
14
- maxRetries?: number;
15
- delay?: number;
16
- exponential?: boolean;
17
- transactionResendInterval?: number;
18
- };
19
- export declare class SolanaChainInterface implements ChainInterface<SolanaTx, SolanaSigner, "SOLANA"> {
20
- readonly chainId = "SOLANA";
21
- readonly SLOT_TIME = 400;
22
- readonly TX_SLOT_VALIDITY = 151;
23
- readonly connection: Connection;
24
- readonly retryPolicy: SolanaRetryPolicy;
25
- readonly Blocks: SolanaBlocks;
26
- Fees: SolanaFees;
27
- readonly Slots: SolanaSlots;
28
- readonly Tokens: SolanaTokens;
29
- readonly Transactions: SolanaTransactions;
30
- readonly Signatures: SolanaSignatures;
31
- readonly Events: SolanaEvents;
32
- protected readonly logger: {
33
- debug: (msg: any, ...args: any[]) => void;
34
- info: (msg: any, ...args: any[]) => void;
35
- warn: (msg: any, ...args: any[]) => void;
36
- error: (msg: any, ...args: any[]) => void;
37
- };
38
- constructor(connection: Connection, retryPolicy?: SolanaRetryPolicy, solanaFeeEstimator?: SolanaFees);
39
- getBalance(signer: string, tokenAddress: string): Promise<bigint>;
40
- isValidAddress(address: string): boolean;
41
- getNativeCurrencyAddress(): string;
42
- txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
43
- transfer(signer: SolanaSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
44
- sendAndConfirm(signer: SolanaSigner, txs: SolanaTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
45
- serializeTx(tx: SolanaTx): Promise<string>;
46
- deserializeTx(txData: string): Promise<SolanaTx>;
47
- getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
48
- getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
49
- offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
50
- onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
51
- onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
52
- offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean;
53
- onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void;
54
- offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean;
55
- isValidToken(tokenIdentifier: string): boolean;
56
- randomAddress(): string;
57
- randomSigner(): SolanaSigner;
58
- }
1
+ /// <reference types="node" />
2
+ import { Connection, SendOptions } from "@solana/web3.js";
3
+ import { SolanaFees } from "./modules/SolanaFees";
4
+ import { SolanaBlocks } from "./modules/SolanaBlocks";
5
+ import { SolanaSlots } from "./modules/SolanaSlots";
6
+ import { SolanaTokens } from "./modules/SolanaTokens";
7
+ import { SolanaTransactions, SolanaTx } from "./modules/SolanaTransactions";
8
+ import { SolanaSignatures } from "./modules/SolanaSignatures";
9
+ import { SolanaEvents } from "./modules/SolanaEvents";
10
+ import { ChainInterface, TransactionConfirmationOptions } from "@atomiqlabs/base";
11
+ import { SolanaSigner } from "../wallet/SolanaSigner";
12
+ import { Buffer } from "buffer";
13
+ export type SolanaRetryPolicy = {
14
+ maxRetries?: number;
15
+ delay?: number;
16
+ exponential?: boolean;
17
+ transactionResendInterval?: number;
18
+ };
19
+ export declare class SolanaChainInterface implements ChainInterface<SolanaTx, SolanaSigner, "SOLANA"> {
20
+ readonly chainId = "SOLANA";
21
+ readonly SLOT_TIME = 400;
22
+ readonly TX_SLOT_VALIDITY = 151;
23
+ readonly connection: Connection;
24
+ readonly retryPolicy: SolanaRetryPolicy;
25
+ readonly Blocks: SolanaBlocks;
26
+ Fees: SolanaFees;
27
+ readonly Slots: SolanaSlots;
28
+ readonly Tokens: SolanaTokens;
29
+ readonly Transactions: SolanaTransactions;
30
+ readonly Signatures: SolanaSignatures;
31
+ readonly Events: SolanaEvents;
32
+ protected readonly logger: {
33
+ debug: (msg: any, ...args: any[]) => void;
34
+ info: (msg: any, ...args: any[]) => void;
35
+ warn: (msg: any, ...args: any[]) => void;
36
+ error: (msg: any, ...args: any[]) => void;
37
+ };
38
+ constructor(connection: Connection, retryPolicy?: SolanaRetryPolicy, solanaFeeEstimator?: SolanaFees);
39
+ getBalance(signer: string, tokenAddress: string): Promise<bigint>;
40
+ isValidAddress(address: string): boolean;
41
+ getNativeCurrencyAddress(): string;
42
+ txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
43
+ transfer(signer: SolanaSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
44
+ sendAndConfirm(signer: SolanaSigner, txs: SolanaTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
45
+ serializeTx(tx: SolanaTx): Promise<string>;
46
+ deserializeTx(txData: string): Promise<SolanaTx>;
47
+ getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
48
+ getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
49
+ offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
50
+ onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
51
+ onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
52
+ offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean;
53
+ onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void;
54
+ offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean;
55
+ isValidToken(tokenIdentifier: string): boolean;
56
+ randomAddress(): string;
57
+ randomSigner(): SolanaSigner;
58
+ }
@@ -1,112 +1,112 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaChainInterface = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const SolanaFees_1 = require("./modules/SolanaFees");
6
- const SolanaBlocks_1 = require("./modules/SolanaBlocks");
7
- const SolanaSlots_1 = require("./modules/SolanaSlots");
8
- const SolanaTokens_1 = require("./modules/SolanaTokens");
9
- const SolanaTransactions_1 = require("./modules/SolanaTransactions");
10
- const SolanaSignatures_1 = require("./modules/SolanaSignatures");
11
- const SolanaEvents_1 = require("./modules/SolanaEvents");
12
- const Utils_1 = require("../../utils/Utils");
13
- const SolanaAddresses_1 = require("./modules/SolanaAddresses");
14
- const SolanaSigner_1 = require("../wallet/SolanaSigner");
15
- const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
16
- class SolanaChainInterface {
17
- constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
18
- this.chainId = "SOLANA";
19
- this.SLOT_TIME = 400;
20
- this.TX_SLOT_VALIDITY = 151;
21
- this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
22
- this.connection = connection;
23
- this.retryPolicy = retryPolicy;
24
- this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
25
- this.Fees = solanaFeeEstimator;
26
- this.Slots = new SolanaSlots_1.SolanaSlots(this);
27
- this.Tokens = new SolanaTokens_1.SolanaTokens(this);
28
- this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
29
- this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
30
- this.Events = new SolanaEvents_1.SolanaEvents(this);
31
- }
32
- async getBalance(signer, tokenAddress) {
33
- const token = new web3_js_1.PublicKey(tokenAddress);
34
- const publicKey = new web3_js_1.PublicKey(signer);
35
- let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
36
- if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
37
- const accountRentExemptCost = 1000000n;
38
- balance = balance - accountRentExemptCost;
39
- if (balance < 0n)
40
- balance = 0n;
41
- }
42
- this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
43
- return balance;
44
- }
45
- isValidAddress(address) {
46
- return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
47
- }
48
- getNativeCurrencyAddress() {
49
- return this.Tokens.getNativeCurrencyAddress().toString();
50
- }
51
- txsTransfer(signer, token, amount, dstAddress, feeRate) {
52
- return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
53
- }
54
- async transfer(signer, token, amount, dstAddress, txOptions) {
55
- const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
56
- const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
57
- return txId;
58
- }
59
- ////////////////////////////////////////////
60
- //// Transactions
61
- sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
62
- return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
63
- }
64
- serializeTx(tx) {
65
- return this.Transactions.serializeTx(tx);
66
- }
67
- deserializeTx(txData) {
68
- return this.Transactions.deserializeTx(txData);
69
- }
70
- getTxIdStatus(txId) {
71
- return this.Transactions.getTxIdStatus(txId);
72
- }
73
- getTxStatus(tx) {
74
- return this.Transactions.getTxStatus(tx);
75
- }
76
- ///////////////////////////////////
77
- //// Callbacks & handlers
78
- offBeforeTxReplace(callback) {
79
- return true;
80
- }
81
- onBeforeTxReplace(callback) { }
82
- onBeforeTxSigned(callback) {
83
- this.Transactions.onBeforeTxSigned(callback);
84
- }
85
- offBeforeTxSigned(callback) {
86
- return this.Transactions.offBeforeTxSigned(callback);
87
- }
88
- onSendTransaction(callback) {
89
- this.Transactions.onSendTransaction(callback);
90
- }
91
- offSendTransaction(callback) {
92
- return this.Transactions.offSendTransaction(callback);
93
- }
94
- isValidToken(tokenIdentifier) {
95
- try {
96
- new web3_js_1.PublicKey(tokenIdentifier);
97
- return true;
98
- }
99
- catch (e) {
100
- return false;
101
- }
102
- }
103
- randomAddress() {
104
- return web3_js_1.Keypair.generate().publicKey.toString();
105
- }
106
- randomSigner() {
107
- const keypair = web3_js_1.Keypair.generate();
108
- const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
109
- return new SolanaSigner_1.SolanaSigner(wallet, keypair);
110
- }
111
- }
112
- exports.SolanaChainInterface = SolanaChainInterface;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaChainInterface = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const SolanaFees_1 = require("./modules/SolanaFees");
6
+ const SolanaBlocks_1 = require("./modules/SolanaBlocks");
7
+ const SolanaSlots_1 = require("./modules/SolanaSlots");
8
+ const SolanaTokens_1 = require("./modules/SolanaTokens");
9
+ const SolanaTransactions_1 = require("./modules/SolanaTransactions");
10
+ const SolanaSignatures_1 = require("./modules/SolanaSignatures");
11
+ const SolanaEvents_1 = require("./modules/SolanaEvents");
12
+ const Utils_1 = require("../../utils/Utils");
13
+ const SolanaAddresses_1 = require("./modules/SolanaAddresses");
14
+ const SolanaSigner_1 = require("../wallet/SolanaSigner");
15
+ const SolanaKeypairWallet_1 = require("../wallet/SolanaKeypairWallet");
16
+ class SolanaChainInterface {
17
+ constructor(connection, retryPolicy, solanaFeeEstimator = new SolanaFees_1.SolanaFees(connection)) {
18
+ this.chainId = "SOLANA";
19
+ this.SLOT_TIME = 400;
20
+ this.TX_SLOT_VALIDITY = 151;
21
+ this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
22
+ this.connection = connection;
23
+ this.retryPolicy = retryPolicy;
24
+ this.Blocks = new SolanaBlocks_1.SolanaBlocks(this);
25
+ this.Fees = solanaFeeEstimator;
26
+ this.Slots = new SolanaSlots_1.SolanaSlots(this);
27
+ this.Tokens = new SolanaTokens_1.SolanaTokens(this);
28
+ this.Transactions = new SolanaTransactions_1.SolanaTransactions(this);
29
+ this.Signatures = new SolanaSignatures_1.SolanaSignatures(this);
30
+ this.Events = new SolanaEvents_1.SolanaEvents(this);
31
+ }
32
+ async getBalance(signer, tokenAddress) {
33
+ const token = new web3_js_1.PublicKey(tokenAddress);
34
+ const publicKey = new web3_js_1.PublicKey(signer);
35
+ let { balance } = await this.Tokens.getTokenBalance(publicKey, token);
36
+ if (token.equals(SolanaTokens_1.SolanaTokens.WSOL_ADDRESS)) {
37
+ const accountRentExemptCost = 1000000n;
38
+ balance = balance - accountRentExemptCost;
39
+ if (balance < 0n)
40
+ balance = 0n;
41
+ }
42
+ this.logger.debug("getBalance(): token balance, token: " + token.toBase58() + " balance: " + balance.toString(10));
43
+ return balance;
44
+ }
45
+ isValidAddress(address) {
46
+ return SolanaAddresses_1.SolanaAddresses.isValidAddress(address);
47
+ }
48
+ getNativeCurrencyAddress() {
49
+ return this.Tokens.getNativeCurrencyAddress().toString();
50
+ }
51
+ txsTransfer(signer, token, amount, dstAddress, feeRate) {
52
+ return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
53
+ }
54
+ async transfer(signer, token, amount, dstAddress, txOptions) {
55
+ const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
56
+ const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
57
+ return txId;
58
+ }
59
+ ////////////////////////////////////////////
60
+ //// Transactions
61
+ sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
62
+ return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
63
+ }
64
+ serializeTx(tx) {
65
+ return this.Transactions.serializeTx(tx);
66
+ }
67
+ deserializeTx(txData) {
68
+ return this.Transactions.deserializeTx(txData);
69
+ }
70
+ getTxIdStatus(txId) {
71
+ return this.Transactions.getTxIdStatus(txId);
72
+ }
73
+ getTxStatus(tx) {
74
+ return this.Transactions.getTxStatus(tx);
75
+ }
76
+ ///////////////////////////////////
77
+ //// Callbacks & handlers
78
+ offBeforeTxReplace(callback) {
79
+ return true;
80
+ }
81
+ onBeforeTxReplace(callback) { }
82
+ onBeforeTxSigned(callback) {
83
+ this.Transactions.onBeforeTxSigned(callback);
84
+ }
85
+ offBeforeTxSigned(callback) {
86
+ return this.Transactions.offBeforeTxSigned(callback);
87
+ }
88
+ onSendTransaction(callback) {
89
+ this.Transactions.onSendTransaction(callback);
90
+ }
91
+ offSendTransaction(callback) {
92
+ return this.Transactions.offSendTransaction(callback);
93
+ }
94
+ isValidToken(tokenIdentifier) {
95
+ try {
96
+ new web3_js_1.PublicKey(tokenIdentifier);
97
+ return true;
98
+ }
99
+ catch (e) {
100
+ return false;
101
+ }
102
+ }
103
+ randomAddress() {
104
+ return web3_js_1.Keypair.generate().publicKey.toString();
105
+ }
106
+ randomSigner() {
107
+ const keypair = web3_js_1.Keypair.generate();
108
+ const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
109
+ return new SolanaSigner_1.SolanaSigner(wallet, keypair);
110
+ }
111
+ }
112
+ exports.SolanaChainInterface = SolanaChainInterface;
@@ -1,14 +1,14 @@
1
- import { Connection } from "@solana/web3.js";
2
- import { SolanaChainInterface, SolanaRetryPolicy } from "./SolanaChainInterface";
3
- export declare class SolanaModule {
4
- protected readonly connection: Connection;
5
- protected readonly retryPolicy: SolanaRetryPolicy;
6
- protected readonly root: SolanaChainInterface;
7
- protected readonly logger: {
8
- debug: (msg: any, ...args: any[]) => void;
9
- info: (msg: any, ...args: any[]) => void;
10
- warn: (msg: any, ...args: any[]) => void;
11
- error: (msg: any, ...args: any[]) => void;
12
- };
13
- constructor(root: SolanaChainInterface);
14
- }
1
+ import { Connection } from "@solana/web3.js";
2
+ import { SolanaChainInterface, SolanaRetryPolicy } from "./SolanaChainInterface";
3
+ export declare class SolanaModule {
4
+ protected readonly connection: Connection;
5
+ protected readonly retryPolicy: SolanaRetryPolicy;
6
+ protected readonly root: SolanaChainInterface;
7
+ protected readonly logger: {
8
+ debug: (msg: any, ...args: any[]) => void;
9
+ info: (msg: any, ...args: any[]) => void;
10
+ warn: (msg: any, ...args: any[]) => void;
11
+ error: (msg: any, ...args: any[]) => void;
12
+ };
13
+ constructor(root: SolanaChainInterface);
14
+ }
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaModule = void 0;
4
- const Utils_1 = require("../../utils/Utils");
5
- class SolanaModule {
6
- constructor(root) {
7
- this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
8
- this.connection = root.connection;
9
- this.retryPolicy = root.retryPolicy;
10
- this.root = root;
11
- }
12
- }
13
- exports.SolanaModule = SolanaModule;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaModule = void 0;
4
+ const Utils_1 = require("../../utils/Utils");
5
+ class SolanaModule {
6
+ constructor(root) {
7
+ this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
8
+ this.connection = root.connection;
9
+ this.retryPolicy = root.retryPolicy;
10
+ this.root = root;
11
+ }
12
+ }
13
+ exports.SolanaModule = SolanaModule;
@@ -1,8 +1,8 @@
1
- export declare class SolanaAddresses {
2
- /**
3
- * Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
4
- *
5
- * @param address
6
- */
7
- static isValidAddress(address: string): boolean;
8
- }
1
+ export declare class SolanaAddresses {
2
+ /**
3
+ * Checks whether an address is a valid Solana address (base58 encoded ed25519 public key)
4
+ *
5
+ * @param address
6
+ */
7
+ static isValidAddress(address: string): boolean;
8
+ }