@atomiqlabs/chain-solana 12.0.11 → 12.0.13

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 +11 -11
  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 +65 -65
  20. package/dist/solana/chain/SolanaChainInterface.js +125 -125
  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 +68 -68
  28. package/dist/solana/chain/modules/SolanaEvents.js +225 -225
  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 +323 -323
  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 +75 -75
  42. package/dist/solana/events/SolanaChainEventsBrowser.js +172 -172
  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 +53 -53
  48. package/dist/solana/program/modules/SolanaProgramEvents.js +114 -114
  49. package/dist/solana/swaps/SolanaSwapData.d.ts +71 -71
  50. package/dist/solana/swaps/SolanaSwapData.js +292 -292
  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 +224 -224
  54. package/dist/solana/swaps/SolanaSwapProgram.js +570 -567
  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 +262 -262
  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 +11 -11
  73. package/dist/solana/wallet/SolanaSigner.js +17 -17
  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 +27 -27
  79. package/src/solana/SolanaChains.ts +23 -23
  80. package/src/solana/SolanaInitializer.ts +102 -102
  81. package/src/solana/btcrelay/SolanaBtcRelay.ts +589 -589
  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 +192 -192
  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 +256 -256
  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 +365 -365
  96. package/src/solana/events/SolanaChainEvents.ts +299 -299
  97. package/src/solana/events/SolanaChainEventsBrowser.ts +209 -209
  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 +155 -155
  101. package/src/solana/swaps/SolanaSwapData.ts +430 -430
  102. package/src/solana/swaps/SolanaSwapModule.ts +16 -16
  103. package/src/solana/swaps/SolanaSwapProgram.ts +854 -849
  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 +323 -323
  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 +24 -24
  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,65 +1,65 @@
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
- import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
14
- export type SolanaRetryPolicy = {
15
- maxRetries?: number;
16
- delay?: number;
17
- exponential?: boolean;
18
- transactionResendInterval?: number;
19
- };
20
- export declare class SolanaChainInterface implements ChainInterface<SolanaTx, SolanaSigner, "SOLANA", Wallet> {
21
- readonly chainId = "SOLANA";
22
- readonly SLOT_TIME = 400;
23
- readonly TX_SLOT_VALIDITY = 151;
24
- readonly connection: Connection;
25
- readonly retryPolicy: SolanaRetryPolicy;
26
- readonly Blocks: SolanaBlocks;
27
- Fees: SolanaFees;
28
- readonly Slots: SolanaSlots;
29
- readonly Tokens: SolanaTokens;
30
- readonly Transactions: SolanaTransactions;
31
- readonly Signatures: SolanaSignatures;
32
- readonly Events: SolanaEvents;
33
- protected readonly logger: {
34
- debug: (msg: any, ...args: any[]) => void;
35
- info: (msg: any, ...args: any[]) => void;
36
- warn: (msg: any, ...args: any[]) => void;
37
- error: (msg: any, ...args: any[]) => void;
38
- };
39
- constructor(connection: Connection, retryPolicy?: SolanaRetryPolicy, solanaFeeEstimator?: SolanaFees);
40
- getBalance(signer: string, tokenAddress: string): Promise<bigint>;
41
- isValidAddress(address: string): boolean;
42
- normalizeAddress(address: string): string;
43
- getNativeCurrencyAddress(): string;
44
- txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
45
- transfer(signer: SolanaSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
46
- sendAndConfirm(signer: SolanaSigner, txs: SolanaTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
47
- serializeTx(tx: SolanaTx): Promise<string>;
48
- deserializeTx(txData: string): Promise<SolanaTx>;
49
- getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
50
- getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
51
- getFinalizedBlock(): Promise<{
52
- height: number;
53
- blockHash: string;
54
- }>;
55
- offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
56
- onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
57
- onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
58
- offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean;
59
- onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void;
60
- offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean;
61
- isValidToken(tokenIdentifier: string): boolean;
62
- randomAddress(): string;
63
- randomSigner(): SolanaSigner;
64
- wrapSigner(signer: Wallet): Promise<SolanaSigner>;
65
- }
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
+ import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
14
+ export type SolanaRetryPolicy = {
15
+ maxRetries?: number;
16
+ delay?: number;
17
+ exponential?: boolean;
18
+ transactionResendInterval?: number;
19
+ };
20
+ export declare class SolanaChainInterface implements ChainInterface<SolanaTx, SolanaSigner, "SOLANA", Wallet> {
21
+ readonly chainId = "SOLANA";
22
+ readonly SLOT_TIME = 400;
23
+ readonly TX_SLOT_VALIDITY = 151;
24
+ readonly connection: Connection;
25
+ readonly retryPolicy: SolanaRetryPolicy;
26
+ readonly Blocks: SolanaBlocks;
27
+ Fees: SolanaFees;
28
+ readonly Slots: SolanaSlots;
29
+ readonly Tokens: SolanaTokens;
30
+ readonly Transactions: SolanaTransactions;
31
+ readonly Signatures: SolanaSignatures;
32
+ readonly Events: SolanaEvents;
33
+ protected readonly logger: {
34
+ debug: (msg: any, ...args: any[]) => void;
35
+ info: (msg: any, ...args: any[]) => void;
36
+ warn: (msg: any, ...args: any[]) => void;
37
+ error: (msg: any, ...args: any[]) => void;
38
+ };
39
+ constructor(connection: Connection, retryPolicy?: SolanaRetryPolicy, solanaFeeEstimator?: SolanaFees);
40
+ getBalance(signer: string, tokenAddress: string): Promise<bigint>;
41
+ isValidAddress(address: string): boolean;
42
+ normalizeAddress(address: string): string;
43
+ getNativeCurrencyAddress(): string;
44
+ txsTransfer(signer: string, token: string, amount: bigint, dstAddress: string, feeRate?: string): Promise<SolanaTx[]>;
45
+ transfer(signer: SolanaSigner, token: string, amount: bigint, dstAddress: string, txOptions?: TransactionConfirmationOptions): Promise<string>;
46
+ sendAndConfirm(signer: SolanaSigner, txs: SolanaTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
47
+ serializeTx(tx: SolanaTx): Promise<string>;
48
+ deserializeTx(txData: string): Promise<SolanaTx>;
49
+ getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
50
+ getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
51
+ getFinalizedBlock(): Promise<{
52
+ height: number;
53
+ blockHash: string;
54
+ }>;
55
+ offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
56
+ onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
57
+ onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
58
+ offBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): boolean;
59
+ onSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): void;
60
+ offSendTransaction(callback: (tx: Buffer, options?: SendOptions) => Promise<string>): boolean;
61
+ isValidToken(tokenIdentifier: string): boolean;
62
+ randomAddress(): string;
63
+ randomSigner(): SolanaSigner;
64
+ wrapSigner(signer: Wallet): Promise<SolanaSigner>;
65
+ }
@@ -1,125 +1,125 @@
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
- normalizeAddress(address) {
49
- return address;
50
- }
51
- getNativeCurrencyAddress() {
52
- return this.Tokens.getNativeCurrencyAddress().toString();
53
- }
54
- txsTransfer(signer, token, amount, dstAddress, feeRate) {
55
- return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
56
- }
57
- async transfer(signer, token, amount, dstAddress, txOptions) {
58
- const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
59
- const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
60
- return txId;
61
- }
62
- ////////////////////////////////////////////
63
- //// Transactions
64
- sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
65
- return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
66
- }
67
- serializeTx(tx) {
68
- return this.Transactions.serializeTx(tx);
69
- }
70
- deserializeTx(txData) {
71
- return this.Transactions.deserializeTx(txData);
72
- }
73
- getTxIdStatus(txId) {
74
- return this.Transactions.getTxIdStatus(txId);
75
- }
76
- getTxStatus(tx) {
77
- return this.Transactions.getTxStatus(tx);
78
- }
79
- async getFinalizedBlock() {
80
- const { block } = await this.Blocks.findLatestParsedBlock("finalized");
81
- return {
82
- height: block.blockHeight,
83
- blockHash: block.blockhash
84
- };
85
- }
86
- ///////////////////////////////////
87
- //// Callbacks & handlers
88
- offBeforeTxReplace(callback) {
89
- return true;
90
- }
91
- onBeforeTxReplace(callback) { }
92
- onBeforeTxSigned(callback) {
93
- this.Transactions.onBeforeTxSigned(callback);
94
- }
95
- offBeforeTxSigned(callback) {
96
- return this.Transactions.offBeforeTxSigned(callback);
97
- }
98
- onSendTransaction(callback) {
99
- this.Transactions.onSendTransaction(callback);
100
- }
101
- offSendTransaction(callback) {
102
- return this.Transactions.offSendTransaction(callback);
103
- }
104
- isValidToken(tokenIdentifier) {
105
- try {
106
- new web3_js_1.PublicKey(tokenIdentifier);
107
- return true;
108
- }
109
- catch (e) {
110
- return false;
111
- }
112
- }
113
- randomAddress() {
114
- return web3_js_1.Keypair.generate().publicKey.toString();
115
- }
116
- randomSigner() {
117
- const keypair = web3_js_1.Keypair.generate();
118
- const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
119
- return new SolanaSigner_1.SolanaSigner(wallet, keypair);
120
- }
121
- wrapSigner(signer) {
122
- return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
123
- }
124
- }
125
- 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
+ normalizeAddress(address) {
49
+ return address;
50
+ }
51
+ getNativeCurrencyAddress() {
52
+ return this.Tokens.getNativeCurrencyAddress().toString();
53
+ }
54
+ txsTransfer(signer, token, amount, dstAddress, feeRate) {
55
+ return this.Tokens.txsTransfer(new web3_js_1.PublicKey(signer), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), feeRate);
56
+ }
57
+ async transfer(signer, token, amount, dstAddress, txOptions) {
58
+ const txs = await this.Tokens.txsTransfer(signer.getPublicKey(), new web3_js_1.PublicKey(token), amount, new web3_js_1.PublicKey(dstAddress), txOptions?.feeRate);
59
+ const [txId] = await this.Transactions.sendAndConfirm(signer, txs, txOptions?.waitForConfirmation, txOptions?.abortSignal, false);
60
+ return txId;
61
+ }
62
+ ////////////////////////////////////////////
63
+ //// Transactions
64
+ sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
65
+ return this.Transactions.sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
66
+ }
67
+ serializeTx(tx) {
68
+ return this.Transactions.serializeTx(tx);
69
+ }
70
+ deserializeTx(txData) {
71
+ return this.Transactions.deserializeTx(txData);
72
+ }
73
+ getTxIdStatus(txId) {
74
+ return this.Transactions.getTxIdStatus(txId);
75
+ }
76
+ getTxStatus(tx) {
77
+ return this.Transactions.getTxStatus(tx);
78
+ }
79
+ async getFinalizedBlock() {
80
+ const { block } = await this.Blocks.findLatestParsedBlock("finalized");
81
+ return {
82
+ height: block.blockHeight,
83
+ blockHash: block.blockhash
84
+ };
85
+ }
86
+ ///////////////////////////////////
87
+ //// Callbacks & handlers
88
+ offBeforeTxReplace(callback) {
89
+ return true;
90
+ }
91
+ onBeforeTxReplace(callback) { }
92
+ onBeforeTxSigned(callback) {
93
+ this.Transactions.onBeforeTxSigned(callback);
94
+ }
95
+ offBeforeTxSigned(callback) {
96
+ return this.Transactions.offBeforeTxSigned(callback);
97
+ }
98
+ onSendTransaction(callback) {
99
+ this.Transactions.onSendTransaction(callback);
100
+ }
101
+ offSendTransaction(callback) {
102
+ return this.Transactions.offSendTransaction(callback);
103
+ }
104
+ isValidToken(tokenIdentifier) {
105
+ try {
106
+ new web3_js_1.PublicKey(tokenIdentifier);
107
+ return true;
108
+ }
109
+ catch (e) {
110
+ return false;
111
+ }
112
+ }
113
+ randomAddress() {
114
+ return web3_js_1.Keypair.generate().publicKey.toString();
115
+ }
116
+ randomSigner() {
117
+ const keypair = web3_js_1.Keypair.generate();
118
+ const wallet = new SolanaKeypairWallet_1.SolanaKeypairWallet(keypair);
119
+ return new SolanaSigner_1.SolanaSigner(wallet, keypair);
120
+ }
121
+ wrapSigner(signer) {
122
+ return Promise.resolve(new SolanaSigner_1.SolanaSigner(signer));
123
+ }
124
+ }
125
+ 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
+ }