@atomiqlabs/chain-solana 13.5.13 → 13.5.14

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 (131) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +73 -73
  3. package/dist/index.d.ts +81 -81
  4. package/dist/index.js +102 -102
  5. package/dist/node/index.d.ts +9 -9
  6. package/dist/node/index.js +13 -13
  7. package/dist/solana/SolanaChainType.d.ts +15 -15
  8. package/dist/solana/SolanaChainType.js +2 -2
  9. package/dist/solana/SolanaChains.d.ts +12 -12
  10. package/dist/solana/SolanaChains.js +45 -45
  11. package/dist/solana/SolanaInitializer.d.ts +94 -94
  12. package/dist/solana/SolanaInitializer.js +174 -174
  13. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +222 -222
  14. package/dist/solana/btcrelay/SolanaBtcRelay.js +455 -455
  15. package/dist/solana/btcrelay/headers/SolanaBtcHeader.d.ts +84 -84
  16. package/dist/solana/btcrelay/headers/SolanaBtcHeader.js +70 -70
  17. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.d.ts +92 -92
  18. package/dist/solana/btcrelay/headers/SolanaBtcStoredHeader.js +109 -109
  19. package/dist/solana/btcrelay/program/programIdl.json +671 -671
  20. package/dist/solana/chain/SolanaAction.d.ts +26 -26
  21. package/dist/solana/chain/SolanaAction.js +87 -87
  22. package/dist/solana/chain/SolanaChainInterface.d.ts +224 -224
  23. package/dist/solana/chain/SolanaChainInterface.js +275 -275
  24. package/dist/solana/chain/SolanaModule.d.ts +14 -14
  25. package/dist/solana/chain/SolanaModule.js +13 -13
  26. package/dist/solana/chain/modules/SolanaAddresses.d.ts +8 -8
  27. package/dist/solana/chain/modules/SolanaAddresses.js +22 -22
  28. package/dist/solana/chain/modules/SolanaBlocks.d.ts +32 -32
  29. package/dist/solana/chain/modules/SolanaBlocks.js +78 -78
  30. package/dist/solana/chain/modules/SolanaEvents.d.ts +68 -68
  31. package/dist/solana/chain/modules/SolanaEvents.js +238 -238
  32. package/dist/solana/chain/modules/SolanaFees.d.ts +189 -189
  33. package/dist/solana/chain/modules/SolanaFees.js +434 -434
  34. package/dist/solana/chain/modules/SolanaSignatures.d.ts +24 -24
  35. package/dist/solana/chain/modules/SolanaSignatures.js +39 -39
  36. package/dist/solana/chain/modules/SolanaSlots.d.ts +33 -33
  37. package/dist/solana/chain/modules/SolanaSlots.js +72 -72
  38. package/dist/solana/chain/modules/SolanaTokens.d.ts +123 -123
  39. package/dist/solana/chain/modules/SolanaTokens.js +242 -242
  40. package/dist/solana/chain/modules/SolanaTransactions.d.ts +149 -149
  41. package/dist/solana/chain/modules/SolanaTransactions.js +445 -445
  42. package/dist/solana/connection/ConnectionWithRetries.d.ts +35 -35
  43. package/dist/solana/connection/ConnectionWithRetries.js +86 -71
  44. package/dist/solana/events/SolanaChainEvents.d.ts +45 -45
  45. package/dist/solana/events/SolanaChainEvents.js +108 -108
  46. package/dist/solana/events/SolanaChainEventsBrowser.d.ts +205 -205
  47. package/dist/solana/events/SolanaChainEventsBrowser.js +404 -404
  48. package/dist/solana/program/SolanaProgramBase.d.ts +73 -73
  49. package/dist/solana/program/SolanaProgramBase.js +54 -54
  50. package/dist/solana/program/SolanaProgramModule.d.ts +8 -8
  51. package/dist/solana/program/SolanaProgramModule.js +11 -11
  52. package/dist/solana/program/modules/SolanaProgramEvents.d.ts +53 -53
  53. package/dist/solana/program/modules/SolanaProgramEvents.js +117 -117
  54. package/dist/solana/swaps/SolanaSwapData.d.ts +333 -333
  55. package/dist/solana/swaps/SolanaSwapData.js +535 -535
  56. package/dist/solana/swaps/SolanaSwapModule.d.ts +11 -11
  57. package/dist/solana/swaps/SolanaSwapModule.js +12 -12
  58. package/dist/solana/swaps/SolanaSwapProgram.d.ts +376 -376
  59. package/dist/solana/swaps/SolanaSwapProgram.js +769 -769
  60. package/dist/solana/swaps/SwapTypeEnum.d.ts +11 -11
  61. package/dist/solana/swaps/SwapTypeEnum.js +43 -43
  62. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +95 -95
  63. package/dist/solana/swaps/modules/SolanaDataAccount.js +232 -232
  64. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +69 -69
  65. package/dist/solana/swaps/modules/SolanaLpVault.js +171 -171
  66. package/dist/solana/swaps/modules/SwapClaim.d.ts +126 -126
  67. package/dist/solana/swaps/modules/SwapClaim.js +294 -294
  68. package/dist/solana/swaps/modules/SwapInit.d.ts +213 -213
  69. package/dist/solana/swaps/modules/SwapInit.js +658 -658
  70. package/dist/solana/swaps/modules/SwapRefund.d.ts +87 -87
  71. package/dist/solana/swaps/modules/SwapRefund.js +293 -293
  72. package/dist/solana/swaps/programIdl.json +945 -945
  73. package/dist/solana/swaps/programTypes.d.ts +943 -943
  74. package/dist/solana/swaps/programTypes.js +945 -945
  75. package/dist/solana/swaps/v1/programIdl.json +945 -945
  76. package/dist/solana/swaps/v1/programTypes.d.ts +943 -943
  77. package/dist/solana/swaps/v1/programTypes.js +945 -945
  78. package/dist/solana/swaps/v2/programIdl.json +952 -952
  79. package/dist/solana/swaps/v2/programTypes.d.ts +950 -950
  80. package/dist/solana/swaps/v2/programTypes.js +952 -952
  81. package/dist/solana/wallet/SolanaKeypairWallet.d.ts +29 -29
  82. package/dist/solana/wallet/SolanaKeypairWallet.js +50 -50
  83. package/dist/solana/wallet/SolanaSigner.d.ts +30 -30
  84. package/dist/solana/wallet/SolanaSigner.js +30 -30
  85. package/dist/utils/Utils.d.ts +58 -58
  86. package/dist/utils/Utils.js +170 -170
  87. package/node/index.d.ts +1 -1
  88. package/node/index.js +3 -3
  89. package/package.json +46 -46
  90. package/src/index.ts +87 -87
  91. package/src/node/index.ts +9 -9
  92. package/src/solana/SolanaChainType.ts +32 -32
  93. package/src/solana/SolanaChains.ts +46 -46
  94. package/src/solana/SolanaInitializer.ts +278 -278
  95. package/src/solana/btcrelay/SolanaBtcRelay.ts +615 -615
  96. package/src/solana/btcrelay/headers/SolanaBtcHeader.ts +116 -116
  97. package/src/solana/btcrelay/headers/SolanaBtcStoredHeader.ts +148 -148
  98. package/src/solana/btcrelay/program/programIdl.json +670 -670
  99. package/src/solana/chain/SolanaAction.ts +109 -109
  100. package/src/solana/chain/SolanaChainInterface.ts +404 -404
  101. package/src/solana/chain/SolanaModule.ts +20 -20
  102. package/src/solana/chain/modules/SolanaAddresses.ts +20 -20
  103. package/src/solana/chain/modules/SolanaBlocks.ts +89 -89
  104. package/src/solana/chain/modules/SolanaEvents.ts +271 -271
  105. package/src/solana/chain/modules/SolanaFees.ts +522 -522
  106. package/src/solana/chain/modules/SolanaSignatures.ts +39 -39
  107. package/src/solana/chain/modules/SolanaSlots.ts +85 -85
  108. package/src/solana/chain/modules/SolanaTokens.ts +300 -300
  109. package/src/solana/chain/modules/SolanaTransactions.ts +503 -503
  110. package/src/solana/connection/ConnectionWithRetries.ts +113 -96
  111. package/src/solana/events/SolanaChainEvents.ts +127 -127
  112. package/src/solana/events/SolanaChainEventsBrowser.ts +495 -495
  113. package/src/solana/program/SolanaProgramBase.ts +119 -119
  114. package/src/solana/program/SolanaProgramModule.ts +15 -15
  115. package/src/solana/program/modules/SolanaProgramEvents.ts +157 -157
  116. package/src/solana/swaps/SolanaSwapData.ts +735 -735
  117. package/src/solana/swaps/SolanaSwapModule.ts +19 -19
  118. package/src/solana/swaps/SolanaSwapProgram.ts +1074 -1074
  119. package/src/solana/swaps/SwapTypeEnum.ts +30 -30
  120. package/src/solana/swaps/modules/SolanaDataAccount.ts +302 -302
  121. package/src/solana/swaps/modules/SolanaLpVault.ts +208 -208
  122. package/src/solana/swaps/modules/SwapClaim.ts +387 -387
  123. package/src/solana/swaps/modules/SwapInit.ts +785 -785
  124. package/src/solana/swaps/modules/SwapRefund.ts +353 -353
  125. package/src/solana/swaps/v1/programIdl.json +944 -944
  126. package/src/solana/swaps/v1/programTypes.ts +1885 -1885
  127. package/src/solana/swaps/v2/programIdl.json +951 -951
  128. package/src/solana/swaps/v2/programTypes.ts +1899 -1899
  129. package/src/solana/wallet/SolanaKeypairWallet.ts +56 -56
  130. package/src/solana/wallet/SolanaSigner.ts +43 -43
  131. package/src/utils/Utils.ts +194 -194
@@ -1,238 +1,238 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaEvents = void 0;
4
- const SolanaModule_1 = require("../SolanaModule");
5
- const web3_js_1 = require("@solana/web3.js");
6
- const Utils_1 = require("../../../utils/Utils");
7
- class SolanaEvents extends SolanaModule_1.SolanaModule {
8
- constructor() {
9
- super(...arguments);
10
- this.LOG_FETCH_LIMIT = 500;
11
- this.usingHeliusTFA = "auto";
12
- }
13
- /**
14
- * Gets the signatures for a given topicKey public key, if lastProcessedSignature is specified, it fetches only
15
- * the signatures before this signature
16
- *
17
- * @param topicKey
18
- * @param logFetchLimit
19
- * @param lastProcessedSignature
20
- * @private
21
- */
22
- getSignatures(topicKey, logFetchLimit, lastProcessedSignature) {
23
- if (lastProcessedSignature == null) {
24
- return this.connection.getSignaturesForAddress(topicKey, {
25
- limit: logFetchLimit,
26
- }, "confirmed");
27
- }
28
- else {
29
- return this.connection.getSignaturesForAddress(topicKey, {
30
- before: lastProcessedSignature,
31
- limit: logFetchLimit
32
- }, "confirmed");
33
- }
34
- }
35
- /**
36
- * Implements Helius getTransactionsForAddress RPC API
37
- *
38
- * @param account
39
- * @param options
40
- * @param commitment
41
- */
42
- async getTransactionsForAddress(account, options, commitment) {
43
- const limit = 100;
44
- //Try to use getPriorityFeeEstimate api of Helius
45
- const response = await this.connection._rpcRequest("getTransactionsForAddress", [
46
- account.toString(),
47
- {
48
- ...options,
49
- transactionDetails: "full",
50
- sortOrder: "desc",
51
- limit,
52
- commitment: commitment ?? "confirmed",
53
- encoding: "jsonParsed",
54
- maxSupportedTransactionVersion: 0
55
- }
56
- ]).catch((e) => {
57
- //Catching not supported errors
58
- if (e.message != null && (e.message.includes("-32601") || e.message.includes("-32600") || e.message.includes("-32403"))) {
59
- return {
60
- error: {
61
- code: -32601,
62
- message: e.message
63
- }
64
- };
65
- }
66
- throw e;
67
- });
68
- if (response.error != null) {
69
- //Catching not supported errors
70
- if (response.error.code !== -32601 && response.error.code !== -32600 && response.error.code !== -32403)
71
- throw new Error(response.error.message);
72
- return null;
73
- }
74
- return {
75
- data: response.result.data.map((val) => {
76
- return {
77
- ...val,
78
- meta: val.meta == null ? undefined : {
79
- //ParsedTransactionMeta
80
- ...val.meta,
81
- innerInstructions: val.meta.innerInstructions == null ? undefined : val.meta.innerInstructions.map((innerIx) => ({
82
- //ParsedInnerInstruction
83
- ...innerIx,
84
- instructions: innerIx.instructions.map((ix) => {
85
- if (ix.program != null && ix.programId != null) {
86
- return {
87
- //ParsedInstruction
88
- ...ix,
89
- programId: new web3_js_1.PublicKey(ix.programId)
90
- };
91
- }
92
- else {
93
- return {
94
- //PartiallyDecodedInstruction
95
- data: ix.data,
96
- programId: new web3_js_1.PublicKey(ix.programId),
97
- accounts: ix.accounts.map((pubkey) => new web3_js_1.PublicKey(pubkey))
98
- };
99
- }
100
- })
101
- })),
102
- loadedAddresses: val.meta.loadedAddresses == null ? undefined : {
103
- writable: val.meta.loadedAddresses.writable.map((pubkey) => new web3_js_1.PublicKey(pubkey)),
104
- readonly: val.meta.loadedAddresses.readonly.map((pubkey) => new web3_js_1.PublicKey(pubkey)),
105
- }
106
- },
107
- transaction: {
108
- //ParsedTransaction
109
- ...val.transaction,
110
- message: {
111
- //ParsedMessage
112
- ...val.transaction.message,
113
- accountKeys: val.transaction.message.accountKeys.map((accountKey) => ({
114
- //ParsedMessageAccount
115
- ...accountKey,
116
- pubkey: new web3_js_1.PublicKey(accountKey.pubkey)
117
- })),
118
- instructions: val.transaction.message.instructions.map((ix) => {
119
- if (ix.program != null && ix.programId != null) {
120
- return {
121
- //ParsedInstruction
122
- ...ix,
123
- programId: new web3_js_1.PublicKey(ix.programId)
124
- };
125
- }
126
- else {
127
- return {
128
- //PartiallyDecodedInstruction
129
- data: ix.data,
130
- programId: new web3_js_1.PublicKey(ix.programId),
131
- accounts: ix.accounts.map((pubkey) => new web3_js_1.PublicKey(pubkey))
132
- };
133
- }
134
- }),
135
- addressTableLookups: val.transaction.message.addressTableLookups == null
136
- ? undefined
137
- : val.transaction.message.addressTableLookups.map((addressTableLookup) => ({
138
- //ParsedAddressTableLookup
139
- ...addressTableLookup,
140
- accountKey: new web3_js_1.PublicKey(addressTableLookup.accountKey)
141
- }))
142
- }
143
- }
144
- };
145
- }),
146
- paginationToken: response.result.paginationToken
147
- };
148
- }
149
- async _findInTxsTFA(topicKey, processor, abortSignal, startBlockheight) {
150
- let paginationToken;
151
- let txs;
152
- while (txs == null || txs.length > 0) {
153
- let filters = startBlockheight != null ? {
154
- slot: { gte: startBlockheight }
155
- } : {};
156
- const tfaResult = await (0, Utils_1.tryWithRetries)(() => this.getTransactionsForAddress(topicKey, {
157
- paginationToken,
158
- filters: {
159
- ...filters,
160
- status: "succeeded"
161
- }
162
- }, "confirmed"), undefined, undefined, abortSignal);
163
- if (tfaResult == null) {
164
- //Not supported
165
- return undefined;
166
- }
167
- txs = tfaResult.data;
168
- paginationToken = tfaResult.paginationToken;
169
- if (txs.length === 0) {
170
- this.logger.debug(`_findInTxsTFA(): Got ${txs.length} txns (empty response), paginationToken: ${paginationToken}`);
171
- }
172
- else {
173
- this.logger.debug(`_findInTxsTFA(): Got ${txs.length} txns (${txs[0].transaction.signatures[0]}..${txs[txs.length - 1].transaction.signatures[0]}), paginationToken: ${paginationToken}`);
174
- }
175
- if (abortSignal != null)
176
- abortSignal.throwIfAborted();
177
- const result = await processor({ txs });
178
- if (result != null)
179
- return result;
180
- if (paginationToken == null)
181
- break;
182
- }
183
- return null;
184
- }
185
- /**
186
- * Runs a search backwards in time, processing transaction signatures for a specific topic public key
187
- *
188
- * @param topicKey
189
- * @param processor called for every batch of returned signatures, should return a value if the correct signature
190
- * was found, or null if the search should continue
191
- * @param abortSignal
192
- * @param logFetchLimit
193
- * @param startBlockheight
194
- */
195
- async _findInSignatures(topicKey, processor, abortSignal, logFetchLimit, startBlockheight) {
196
- if (logFetchLimit == null || logFetchLimit > this.LOG_FETCH_LIMIT)
197
- logFetchLimit = this.LOG_FETCH_LIMIT;
198
- let signatures;
199
- do {
200
- signatures = await this.getSignatures(topicKey, logFetchLimit, signatures != null ? signatures?.[signatures.length - 1].signature : undefined);
201
- if (startBlockheight != null) {
202
- const endIndex = signatures.findIndex(val => val.slot < startBlockheight);
203
- if (endIndex === 0)
204
- return null;
205
- if (endIndex !== -1)
206
- signatures = signatures.slice(0, endIndex - 1);
207
- }
208
- if (signatures.length === 0) {
209
- this.logger.debug(`_findInSignatures(): Got ${signatures.length} txns (empty response)`);
210
- }
211
- else {
212
- this.logger.debug(`_findInSignatures(): Got ${signatures.length} txns (${signatures[0].signature}..${signatures[signatures.length - 1].signature})`);
213
- }
214
- if (abortSignal != null)
215
- abortSignal.throwIfAborted();
216
- const result = await processor({ signatures });
217
- if (result != null)
218
- return result;
219
- } while (signatures.length >= logFetchLimit); //Only fetch next one if this response is full
220
- return null;
221
- }
222
- async findInSignatures(topicKey, processor, abortSignal, logFetchLimit, startBlockheight) {
223
- if (this.usingHeliusTFA !== "no") {
224
- //Attempt to use Helius's gTFA
225
- const result = await this._findInTxsTFA(topicKey, processor, abortSignal, startBlockheight);
226
- if (result !== undefined)
227
- return result;
228
- //Not supported
229
- if (this.usingHeliusTFA === "yes")
230
- throw new Error("Helius gTFA is not supported with current provider!");
231
- //If set to auto, we can manually set to "no"
232
- this.usingHeliusTFA = "no";
233
- this.logger.warn("findInSignatures(): Helius gTFA is not supported, switching back to using gSFA!");
234
- }
235
- return await this._findInSignatures(topicKey, processor, abortSignal, logFetchLimit, startBlockheight);
236
- }
237
- }
238
- exports.SolanaEvents = SolanaEvents;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaEvents = void 0;
4
+ const SolanaModule_1 = require("../SolanaModule");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const Utils_1 = require("../../../utils/Utils");
7
+ class SolanaEvents extends SolanaModule_1.SolanaModule {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.LOG_FETCH_LIMIT = 500;
11
+ this.usingHeliusTFA = "auto";
12
+ }
13
+ /**
14
+ * Gets the signatures for a given topicKey public key, if lastProcessedSignature is specified, it fetches only
15
+ * the signatures before this signature
16
+ *
17
+ * @param topicKey
18
+ * @param logFetchLimit
19
+ * @param lastProcessedSignature
20
+ * @private
21
+ */
22
+ getSignatures(topicKey, logFetchLimit, lastProcessedSignature) {
23
+ if (lastProcessedSignature == null) {
24
+ return this.connection.getSignaturesForAddress(topicKey, {
25
+ limit: logFetchLimit,
26
+ }, "confirmed");
27
+ }
28
+ else {
29
+ return this.connection.getSignaturesForAddress(topicKey, {
30
+ before: lastProcessedSignature,
31
+ limit: logFetchLimit
32
+ }, "confirmed");
33
+ }
34
+ }
35
+ /**
36
+ * Implements Helius getTransactionsForAddress RPC API
37
+ *
38
+ * @param account
39
+ * @param options
40
+ * @param commitment
41
+ */
42
+ async getTransactionsForAddress(account, options, commitment) {
43
+ const limit = 100;
44
+ //Try to use getPriorityFeeEstimate api of Helius
45
+ const response = await this.connection._rpcRequest("getTransactionsForAddress", [
46
+ account.toString(),
47
+ {
48
+ ...options,
49
+ transactionDetails: "full",
50
+ sortOrder: "desc",
51
+ limit,
52
+ commitment: commitment ?? "confirmed",
53
+ encoding: "jsonParsed",
54
+ maxSupportedTransactionVersion: 0
55
+ }
56
+ ]).catch((e) => {
57
+ //Catching not supported errors
58
+ if (e.message != null && (e.message.includes("-32601") || e.message.includes("-32600") || e.message.includes("-32403"))) {
59
+ return {
60
+ error: {
61
+ code: -32601,
62
+ message: e.message
63
+ }
64
+ };
65
+ }
66
+ throw e;
67
+ });
68
+ if (response.error != null) {
69
+ //Catching not supported errors
70
+ if (response.error.code !== -32601 && response.error.code !== -32600 && response.error.code !== -32403)
71
+ throw new Error(response.error.message);
72
+ return null;
73
+ }
74
+ return {
75
+ data: response.result.data.map((val) => {
76
+ return {
77
+ ...val,
78
+ meta: val.meta == null ? undefined : {
79
+ //ParsedTransactionMeta
80
+ ...val.meta,
81
+ innerInstructions: val.meta.innerInstructions == null ? undefined : val.meta.innerInstructions.map((innerIx) => ({
82
+ //ParsedInnerInstruction
83
+ ...innerIx,
84
+ instructions: innerIx.instructions.map((ix) => {
85
+ if (ix.program != null && ix.programId != null) {
86
+ return {
87
+ //ParsedInstruction
88
+ ...ix,
89
+ programId: new web3_js_1.PublicKey(ix.programId)
90
+ };
91
+ }
92
+ else {
93
+ return {
94
+ //PartiallyDecodedInstruction
95
+ data: ix.data,
96
+ programId: new web3_js_1.PublicKey(ix.programId),
97
+ accounts: ix.accounts.map((pubkey) => new web3_js_1.PublicKey(pubkey))
98
+ };
99
+ }
100
+ })
101
+ })),
102
+ loadedAddresses: val.meta.loadedAddresses == null ? undefined : {
103
+ writable: val.meta.loadedAddresses.writable.map((pubkey) => new web3_js_1.PublicKey(pubkey)),
104
+ readonly: val.meta.loadedAddresses.readonly.map((pubkey) => new web3_js_1.PublicKey(pubkey)),
105
+ }
106
+ },
107
+ transaction: {
108
+ //ParsedTransaction
109
+ ...val.transaction,
110
+ message: {
111
+ //ParsedMessage
112
+ ...val.transaction.message,
113
+ accountKeys: val.transaction.message.accountKeys.map((accountKey) => ({
114
+ //ParsedMessageAccount
115
+ ...accountKey,
116
+ pubkey: new web3_js_1.PublicKey(accountKey.pubkey)
117
+ })),
118
+ instructions: val.transaction.message.instructions.map((ix) => {
119
+ if (ix.program != null && ix.programId != null) {
120
+ return {
121
+ //ParsedInstruction
122
+ ...ix,
123
+ programId: new web3_js_1.PublicKey(ix.programId)
124
+ };
125
+ }
126
+ else {
127
+ return {
128
+ //PartiallyDecodedInstruction
129
+ data: ix.data,
130
+ programId: new web3_js_1.PublicKey(ix.programId),
131
+ accounts: ix.accounts.map((pubkey) => new web3_js_1.PublicKey(pubkey))
132
+ };
133
+ }
134
+ }),
135
+ addressTableLookups: val.transaction.message.addressTableLookups == null
136
+ ? undefined
137
+ : val.transaction.message.addressTableLookups.map((addressTableLookup) => ({
138
+ //ParsedAddressTableLookup
139
+ ...addressTableLookup,
140
+ accountKey: new web3_js_1.PublicKey(addressTableLookup.accountKey)
141
+ }))
142
+ }
143
+ }
144
+ };
145
+ }),
146
+ paginationToken: response.result.paginationToken
147
+ };
148
+ }
149
+ async _findInTxsTFA(topicKey, processor, abortSignal, startBlockheight) {
150
+ let paginationToken;
151
+ let txs;
152
+ while (txs == null || txs.length > 0) {
153
+ let filters = startBlockheight != null ? {
154
+ slot: { gte: startBlockheight }
155
+ } : {};
156
+ const tfaResult = await (0, Utils_1.tryWithRetries)(() => this.getTransactionsForAddress(topicKey, {
157
+ paginationToken,
158
+ filters: {
159
+ ...filters,
160
+ status: "succeeded"
161
+ }
162
+ }, "confirmed"), undefined, undefined, abortSignal);
163
+ if (tfaResult == null) {
164
+ //Not supported
165
+ return undefined;
166
+ }
167
+ txs = tfaResult.data;
168
+ paginationToken = tfaResult.paginationToken;
169
+ if (txs.length === 0) {
170
+ this.logger.debug(`_findInTxsTFA(): Got ${txs.length} txns (empty response), paginationToken: ${paginationToken}`);
171
+ }
172
+ else {
173
+ this.logger.debug(`_findInTxsTFA(): Got ${txs.length} txns (${txs[0].transaction.signatures[0]}..${txs[txs.length - 1].transaction.signatures[0]}), paginationToken: ${paginationToken}`);
174
+ }
175
+ if (abortSignal != null)
176
+ abortSignal.throwIfAborted();
177
+ const result = await processor({ txs });
178
+ if (result != null)
179
+ return result;
180
+ if (paginationToken == null)
181
+ break;
182
+ }
183
+ return null;
184
+ }
185
+ /**
186
+ * Runs a search backwards in time, processing transaction signatures for a specific topic public key
187
+ *
188
+ * @param topicKey
189
+ * @param processor called for every batch of returned signatures, should return a value if the correct signature
190
+ * was found, or null if the search should continue
191
+ * @param abortSignal
192
+ * @param logFetchLimit
193
+ * @param startBlockheight
194
+ */
195
+ async _findInSignatures(topicKey, processor, abortSignal, logFetchLimit, startBlockheight) {
196
+ if (logFetchLimit == null || logFetchLimit > this.LOG_FETCH_LIMIT)
197
+ logFetchLimit = this.LOG_FETCH_LIMIT;
198
+ let signatures;
199
+ do {
200
+ signatures = await this.getSignatures(topicKey, logFetchLimit, signatures != null ? signatures?.[signatures.length - 1].signature : undefined);
201
+ if (startBlockheight != null) {
202
+ const endIndex = signatures.findIndex(val => val.slot < startBlockheight);
203
+ if (endIndex === 0)
204
+ return null;
205
+ if (endIndex !== -1)
206
+ signatures = signatures.slice(0, endIndex - 1);
207
+ }
208
+ if (signatures.length === 0) {
209
+ this.logger.debug(`_findInSignatures(): Got ${signatures.length} txns (empty response)`);
210
+ }
211
+ else {
212
+ this.logger.debug(`_findInSignatures(): Got ${signatures.length} txns (${signatures[0].signature}..${signatures[signatures.length - 1].signature})`);
213
+ }
214
+ if (abortSignal != null)
215
+ abortSignal.throwIfAborted();
216
+ const result = await processor({ signatures });
217
+ if (result != null)
218
+ return result;
219
+ } while (signatures.length >= logFetchLimit); //Only fetch next one if this response is full
220
+ return null;
221
+ }
222
+ async findInSignatures(topicKey, processor, abortSignal, logFetchLimit, startBlockheight) {
223
+ if (this.usingHeliusTFA !== "no") {
224
+ //Attempt to use Helius's gTFA
225
+ const result = await this._findInTxsTFA(topicKey, processor, abortSignal, startBlockheight);
226
+ if (result !== undefined)
227
+ return result;
228
+ //Not supported
229
+ if (this.usingHeliusTFA === "yes")
230
+ throw new Error("Helius gTFA is not supported with current provider!");
231
+ //If set to auto, we can manually set to "no"
232
+ this.usingHeliusTFA = "no";
233
+ this.logger.warn("findInSignatures(): Helius gTFA is not supported, switching back to using gSFA!");
234
+ }
235
+ return await this._findInSignatures(topicKey, processor, abortSignal, logFetchLimit, startBlockheight);
236
+ }
237
+ }
238
+ exports.SolanaEvents = SolanaEvents;