@atomiqlabs/chain-solana 7.3.8 → 8.0.0-beta.1

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 (57) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/solana/SolanaChains.d.ts +14 -0
  4. package/dist/solana/SolanaChains.js +18 -0
  5. package/dist/solana/SolanaInitializer.d.ts +18 -0
  6. package/dist/solana/SolanaInitializer.js +59 -0
  7. package/dist/solana/base/SolanaAction.js +25 -38
  8. package/dist/solana/base/modules/SolanaBlocks.js +18 -29
  9. package/dist/solana/base/modules/SolanaEvents.js +15 -26
  10. package/dist/solana/base/modules/SolanaFees.d.ts +4 -5
  11. package/dist/solana/base/modules/SolanaFees.js +168 -182
  12. package/dist/solana/base/modules/SolanaSlots.js +16 -29
  13. package/dist/solana/base/modules/SolanaTokens.d.ts +6 -7
  14. package/dist/solana/base/modules/SolanaTokens.js +63 -84
  15. package/dist/solana/base/modules/SolanaTransactions.d.ts +2 -2
  16. package/dist/solana/base/modules/SolanaTransactions.js +143 -165
  17. package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +2 -3
  18. package/dist/solana/btcrelay/SolanaBtcRelay.js +185 -221
  19. package/dist/solana/events/SolanaChainEvents.js +113 -138
  20. package/dist/solana/events/SolanaChainEventsBrowser.js +56 -65
  21. package/dist/solana/program/modules/SolanaProgramEvents.js +13 -24
  22. package/dist/solana/swaps/SolanaSwapData.d.ts +15 -11
  23. package/dist/solana/swaps/SolanaSwapData.js +29 -13
  24. package/dist/solana/swaps/SolanaSwapProgram.d.ts +40 -41
  25. package/dist/solana/swaps/SolanaSwapProgram.js +214 -223
  26. package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +2 -3
  27. package/dist/solana/swaps/modules/SolanaDataAccount.js +117 -141
  28. package/dist/solana/swaps/modules/SolanaLpVault.d.ts +4 -5
  29. package/dist/solana/swaps/modules/SolanaLpVault.js +87 -110
  30. package/dist/solana/swaps/modules/SwapClaim.d.ts +4 -4
  31. package/dist/solana/swaps/modules/SwapClaim.js +122 -134
  32. package/dist/solana/swaps/modules/SwapInit.d.ts +2 -3
  33. package/dist/solana/swaps/modules/SwapInit.js +254 -285
  34. package/dist/solana/swaps/modules/SwapRefund.d.ts +2 -3
  35. package/dist/solana/swaps/modules/SwapRefund.js +103 -113
  36. package/dist/utils/Utils.d.ts +10 -0
  37. package/dist/utils/Utils.js +62 -35
  38. package/package.json +9 -6
  39. package/src/index.ts +1 -0
  40. package/src/solana/SolanaChains.ts +16 -0
  41. package/src/solana/SolanaInitializer.ts +98 -0
  42. package/src/solana/base/SolanaBase.ts +1 -2
  43. package/src/solana/base/modules/SolanaEvents.ts +0 -1
  44. package/src/solana/base/modules/SolanaFees.ts +35 -31
  45. package/src/solana/base/modules/SolanaTokens.ts +26 -27
  46. package/src/solana/base/modules/SolanaTransactions.ts +33 -28
  47. package/src/solana/btcrelay/SolanaBtcRelay.ts +6 -10
  48. package/src/solana/events/SolanaChainEventsBrowser.ts +14 -10
  49. package/src/solana/program/modules/SolanaProgramEvents.ts +1 -1
  50. package/src/solana/swaps/SolanaSwapData.ts +38 -19
  51. package/src/solana/swaps/SolanaSwapProgram.ts +135 -107
  52. package/src/solana/swaps/modules/SolanaDataAccount.ts +4 -6
  53. package/src/solana/swaps/modules/SolanaLpVault.ts +18 -18
  54. package/src/solana/swaps/modules/SwapClaim.ts +14 -17
  55. package/src/solana/swaps/modules/SwapInit.ts +35 -38
  56. package/src/solana/swaps/modules/SwapRefund.ts +20 -23
  57. package/src/utils/Utils.ts +35 -0
@@ -1,16 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SolanaFees = void 0;
13
- const BN = require("bn.js");
14
4
  const web3_js_1 = require("@solana/web3.js");
15
5
  const Utils_1 = require("../../../utils/Utils");
16
6
  const MAX_FEE_AGE = 5000;
@@ -20,7 +10,7 @@ class SolanaFees {
20
10
  this.logger = (0, Utils_1.getLogger)("SolanaFees: ");
21
11
  this.blockFeeCache = null;
22
12
  this.connection = connection;
23
- this.maxFeeMicroLamports = new BN(maxFeeMicroLamports);
13
+ this.maxFeeMicroLamports = BigInt(maxFeeMicroLamports);
24
14
  this.numSamples = numSamples;
25
15
  this.period = period;
26
16
  this.useHeliusApi = useHeliusApi;
@@ -34,25 +24,23 @@ class SolanaFees {
34
24
  * @param slot
35
25
  * @private
36
26
  */
37
- getBlockWithSignature(slot) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const response = yield this.connection._rpcRequest("getBlock", [
40
- slot,
41
- {
42
- encoding: "json",
43
- transactionDetails: "signatures",
44
- commitment: "confirmed",
45
- rewards: true
46
- }
47
- ]);
48
- if (response.error != null) {
49
- if (response.error.code === -32004 || response.error.code === -32007 || response.error.code === -32009 || response.error.code === -32014) {
50
- return null;
51
- }
52
- throw new Error(response.error.message);
27
+ async getBlockWithSignature(slot) {
28
+ const response = await this.connection._rpcRequest("getBlock", [
29
+ slot,
30
+ {
31
+ encoding: "json",
32
+ transactionDetails: "signatures",
33
+ commitment: "confirmed",
34
+ rewards: true
53
35
  }
54
- return response.result;
55
- });
36
+ ]);
37
+ if (response.error != null) {
38
+ if (response.error.code === -32004 || response.error.code === -32007 || response.error.code === -32009 || response.error.code === -32014) {
39
+ return null;
40
+ }
41
+ throw new Error(response.error.message);
42
+ }
43
+ return response.result;
56
44
  }
57
45
  /**
58
46
  * Returns fee estimate from Helius API - only works with Helius RPC, return null for all other RPC providers
@@ -60,36 +48,34 @@ class SolanaFees {
60
48
  * @param mutableAccounts
61
49
  * @private
62
50
  */
63
- getPriorityFeeEstimate(mutableAccounts) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- //Try to use getPriorityFeeEstimate api of Helius
66
- const response = yield this.connection._rpcRequest("getPriorityFeeEstimate", [
67
- {
68
- "accountKeys": mutableAccounts.map(e => e.toBase58()),
69
- "options": {
70
- "includeAllPriorityFeeLevels": true
71
- }
51
+ async getPriorityFeeEstimate(mutableAccounts) {
52
+ //Try to use getPriorityFeeEstimate api of Helius
53
+ const response = await this.connection._rpcRequest("getPriorityFeeEstimate", [
54
+ {
55
+ "accountKeys": mutableAccounts.map(e => e.toBase58()),
56
+ "options": {
57
+ "includeAllPriorityFeeLevels": true
72
58
  }
73
- ]).catch(e => {
74
- //Catching not supported errors
75
- if (e.message != null && (e.message.includes("-32601") || e.message.includes("-32600"))) {
76
- return {
77
- error: {
78
- code: -32601,
79
- message: e.message
80
- }
81
- };
82
- }
83
- throw e;
84
- });
85
- if (response.error != null) {
86
- //Catching not supported errors
87
- if (response.error.code !== -32601 && response.error.code !== -32600)
88
- throw new Error(response.error.message);
89
- return null;
90
59
  }
91
- return response.result.priorityFeeLevels;
60
+ ]).catch(e => {
61
+ //Catching not supported errors
62
+ if (e.message != null && (e.message.includes("-32601") || e.message.includes("-32600"))) {
63
+ return {
64
+ error: {
65
+ code: -32601,
66
+ message: e.message
67
+ }
68
+ };
69
+ }
70
+ throw e;
92
71
  });
72
+ if (response.error != null) {
73
+ //Catching not supported errors
74
+ if (response.error.code !== -32601 && response.error.code !== -32600)
75
+ throw new Error(response.error.message);
76
+ return null;
77
+ }
78
+ return response.result.priorityFeeLevels;
93
79
  }
94
80
  /**
95
81
  * Sends the transaction over Jito
@@ -99,32 +85,32 @@ class SolanaFees {
99
85
  * @private
100
86
  * @returns {Promise<string>} transaction signature
101
87
  */
102
- sendJitoTx(tx, options) {
103
- var _a;
104
- return __awaiter(this, void 0, void 0, function* () {
105
- if (((_a = this.bribeData) === null || _a === void 0 ? void 0 : _a.endpoint) == null)
106
- throw new Error("Jito endpoint not specified!");
107
- if (options == null)
108
- options = {};
109
- const request = yield fetch(this.bribeData.endpoint, {
110
- method: "POST",
111
- body: JSON.stringify({
112
- jsonrpc: "2.0",
113
- id: 1,
114
- method: "sendTransaction",
115
- params: [tx.toString("base64"), Object.assign(Object.assign({}, options), { encoding: "base64" })],
116
- }),
117
- headers: {
118
- "Content-Type": "application/json"
119
- }
120
- });
121
- if (request.ok) {
122
- const parsedResponse = yield request.json();
123
- // console.log(parsedResponse);
124
- return parsedResponse.result;
88
+ async sendJitoTx(tx, options) {
89
+ if (this.bribeData?.endpoint == null)
90
+ throw new Error("Jito endpoint not specified!");
91
+ if (options == null)
92
+ options = {};
93
+ const request = await fetch(this.bribeData.endpoint, {
94
+ method: "POST",
95
+ body: JSON.stringify({
96
+ jsonrpc: "2.0",
97
+ id: 1,
98
+ method: "sendTransaction",
99
+ params: [tx.toString("base64"), {
100
+ ...options,
101
+ encoding: "base64"
102
+ }],
103
+ }),
104
+ headers: {
105
+ "Content-Type": "application/json"
125
106
  }
126
- throw new Error(yield request.text());
127
107
  });
108
+ if (request.ok) {
109
+ const parsedResponse = await request.json();
110
+ // console.log(parsedResponse);
111
+ return parsedResponse.result;
112
+ }
113
+ throw new Error(await request.text());
128
114
  }
129
115
  /**
130
116
  * Checks whether the transaction should be sent over Jito, returns the fee paid to Jito in case the transaction
@@ -134,16 +120,15 @@ class SolanaFees {
134
120
  * @private
135
121
  */
136
122
  getJitoTxFee(parsedTx) {
137
- var _a;
138
123
  const lastIx = parsedTx.instructions[parsedTx.instructions.length - 1];
139
124
  if (!lastIx.programId.equals(web3_js_1.SystemProgram.programId))
140
125
  return null;
141
126
  if (web3_js_1.SystemInstruction.decodeInstructionType(lastIx) !== "Transfer")
142
127
  return null;
143
128
  const decodedIxData = web3_js_1.SystemInstruction.decodeTransfer(lastIx);
144
- if (decodedIxData.toPubkey.toBase58() !== ((_a = this.bribeData) === null || _a === void 0 ? void 0 : _a.address))
129
+ if (decodedIxData.toPubkey.toBase58() !== this.bribeData?.address)
145
130
  return null;
146
- return new BN(decodedIxData.lamports.toString(10));
131
+ return decodedIxData.lamports;
147
132
  }
148
133
  /**
149
134
  * Gets the mean microLamports/CU fee rate for the block at a specific slot
@@ -151,24 +136,22 @@ class SolanaFees {
151
136
  * @param slot
152
137
  * @private
153
138
  */
154
- getBlockMeanFeeRate(slot) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- const block = yield this.getBlockWithSignature(slot);
157
- if (block == null)
158
- return null;
159
- const blockComission = block.rewards.find(e => e.rewardType === "Fee");
160
- const totalBlockFees = new BN(blockComission.lamports).mul(new BN(2));
161
- //Subtract per-signature fees to get pure compute fees
162
- const totalTransactionBaseFees = new BN(block.signatures.length).mul(new BN(5000));
163
- const computeFees = totalBlockFees.sub(totalTransactionBaseFees);
164
- //Total compute fees in micro lamports
165
- const computeFeesMicroLamports = computeFees.mul(new BN(1000000));
166
- //micro lamports per CU considering block was full (48M compute units)
167
- const perCUMicroLamports = computeFeesMicroLamports.div(new BN(48000000));
168
- this.logger.debug("getBlockMeanFeeRate(): slot: " + slot + " total reward: " + totalBlockFees.toString(10) +
169
- " total transactions: " + block.signatures.length + " computed fee: " + perCUMicroLamports);
170
- return perCUMicroLamports;
171
- });
139
+ async getBlockMeanFeeRate(slot) {
140
+ const block = await this.getBlockWithSignature(slot);
141
+ if (block == null)
142
+ return null;
143
+ const blockComission = block.rewards.find(e => e.rewardType === "Fee");
144
+ const totalBlockFees = BigInt(blockComission.lamports) * 2n;
145
+ //Subtract per-signature fees to get pure compute fees
146
+ const totalTransactionBaseFees = BigInt(block.signatures.length) * 5000n;
147
+ const computeFees = totalBlockFees - totalTransactionBaseFees;
148
+ //Total compute fees in micro lamports
149
+ const computeFeesMicroLamports = computeFees * 1000000n;
150
+ //micro lamports per CU considering block was full (48M compute units)
151
+ const perCUMicroLamports = computeFeesMicroLamports / 48000000n;
152
+ this.logger.debug("getBlockMeanFeeRate(): slot: " + slot + " total reward: " + totalBlockFees.toString(10) +
153
+ " total transactions: " + block.signatures.length + " computed fee: " + perCUMicroLamports);
154
+ return perCUMicroLamports;
172
155
  }
173
156
  /**
174
157
  * Manually gets global fee rate by sampling random blocks over the last period
@@ -176,35 +159,33 @@ class SolanaFees {
176
159
  * @private
177
160
  * @returns {Promise<BN>} sampled mean microLamports/CU fee over the last period
178
161
  */
179
- _getGlobalFeeRate() {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- let slot = yield this.connection.getSlot();
182
- const slots = [];
183
- for (let i = 0; i < this.period; i++) {
184
- slots.push(slot - i);
185
- }
186
- const promises = [];
187
- for (let i = 0; i < this.numSamples; i++) {
188
- promises.push((() => __awaiter(this, void 0, void 0, function* () {
189
- let feeRate = null;
190
- while (feeRate == null) {
191
- if (slots.length === 0)
192
- throw new Error("Ran out of slots to check!");
193
- const index = Math.floor(Math.random() * slots.length);
194
- const slotNumber = slots[index];
195
- slots.splice(index, 1);
196
- feeRate = yield this.getBlockMeanFeeRate(slotNumber);
197
- }
198
- return feeRate;
199
- }))());
200
- }
201
- const meanFees = yield Promise.all(promises);
202
- let min = null;
203
- meanFees.forEach(e => min == null ? min = e : min = BN.min(min, e));
204
- if (min != null)
205
- this.logger.debug("_getGlobalFeeRate(): slot: " + slot + " global fee minimum: " + min.toString(10));
206
- return min;
207
- });
162
+ async _getGlobalFeeRate() {
163
+ let slot = await this.connection.getSlot();
164
+ const slots = [];
165
+ for (let i = 0; i < this.period; i++) {
166
+ slots.push(slot - i);
167
+ }
168
+ const promises = [];
169
+ for (let i = 0; i < this.numSamples; i++) {
170
+ promises.push((async () => {
171
+ let feeRate = null;
172
+ while (feeRate == null) {
173
+ if (slots.length === 0)
174
+ throw new Error("Ran out of slots to check!");
175
+ const index = Math.floor(Math.random() * slots.length);
176
+ const slotNumber = slots[index];
177
+ slots.splice(index, 1);
178
+ feeRate = await this.getBlockMeanFeeRate(slotNumber);
179
+ }
180
+ return feeRate;
181
+ })());
182
+ }
183
+ const meanFees = await Promise.all(promises);
184
+ let min = null;
185
+ meanFees.forEach(e => min == null || min > e ? min = e : 0);
186
+ if (min != null)
187
+ this.logger.debug("_getGlobalFeeRate(): slot: " + slot + " global fee minimum: " + min.toString(10));
188
+ return min;
208
189
  }
209
190
  /**
210
191
  * Gets the combined microLamports/CU fee rate (from localized & global fee market)
@@ -212,36 +193,44 @@ class SolanaFees {
212
193
  * @param mutableAccounts
213
194
  * @private
214
195
  */
215
- _getFeeRate(mutableAccounts) {
216
- return __awaiter(this, void 0, void 0, function* () {
217
- if (this.useHeliusApi === "yes" || (this.useHeliusApi === "auto" && this.heliusApiSupported)) {
218
- //Try to use getPriorityFeeEstimate api of Helius
219
- const fees = yield this.getPriorityFeeEstimate(mutableAccounts);
220
- if (fees != null) {
221
- const calculatedFee = BN.max(new BN(8000), new BN(fees[this.heliusFeeLevel]));
222
- return BN.min(calculatedFee, this.maxFeeMicroLamports);
223
- }
224
- this.logger.warn("_getFeeRate(): tried fetching fees from Helius API, not supported," +
225
- " falling back to client-side fee estimation");
226
- this.heliusApiSupported = false;
196
+ async _getFeeRate(mutableAccounts) {
197
+ if (this.useHeliusApi === "yes" || (this.useHeliusApi === "auto" && this.heliusApiSupported)) {
198
+ //Try to use getPriorityFeeEstimate api of Helius
199
+ const fees = await this.getPriorityFeeEstimate(mutableAccounts);
200
+ if (fees != null) {
201
+ let calculatedFee = BigInt(fees[this.heliusFeeLevel]);
202
+ if (calculatedFee < 8000n)
203
+ calculatedFee = 8000n;
204
+ if (calculatedFee > this.maxFeeMicroLamports)
205
+ calculatedFee = this.maxFeeMicroLamports;
206
+ return calculatedFee;
227
207
  }
228
- const [globalFeeRate, localFeeRate] = yield Promise.all([
229
- this.getGlobalFeeRate(),
230
- this.connection.getRecentPrioritizationFees({
231
- lockedWritableAccounts: mutableAccounts
232
- }).then(resp => {
233
- let lamports = 0;
234
- for (let i = 20; i >= 0; i--) {
235
- const data = resp[resp.length - i - 1];
236
- if (data != null)
237
- lamports = Math.min(lamports, data.prioritizationFee);
238
- }
239
- return new BN(lamports);
240
- })
241
- ]);
242
- const fee = BN.max(BN.max(globalFeeRate, localFeeRate), new BN(8000));
243
- return BN.min(fee, this.maxFeeMicroLamports);
244
- });
208
+ this.logger.warn("_getFeeRate(): tried fetching fees from Helius API, not supported," +
209
+ " falling back to client-side fee estimation");
210
+ this.heliusApiSupported = false;
211
+ }
212
+ const [globalFeeRate, localFeeRate] = await Promise.all([
213
+ this.getGlobalFeeRate(),
214
+ this.connection.getRecentPrioritizationFees({
215
+ lockedWritableAccounts: mutableAccounts
216
+ }).then(resp => {
217
+ let lamports = 0;
218
+ for (let i = 20; i >= 0; i--) {
219
+ const data = resp[resp.length - i - 1];
220
+ if (data != null)
221
+ lamports = Math.min(lamports, data.prioritizationFee);
222
+ }
223
+ return BigInt(lamports);
224
+ })
225
+ ]);
226
+ let fee = globalFeeRate;
227
+ if (fee < localFeeRate)
228
+ fee = localFeeRate;
229
+ if (fee < 8000n)
230
+ fee = 8000n;
231
+ if (fee > this.maxFeeMicroLamports)
232
+ fee = this.maxFeeMicroLamports;
233
+ return fee;
245
234
  }
246
235
  /**
247
236
  * Gets global fee rate, with caching
@@ -270,25 +259,22 @@ class SolanaFees {
270
259
  * @param mutableAccounts
271
260
  * @private
272
261
  */
273
- getFeeRate(mutableAccounts) {
274
- var _a, _b;
275
- return __awaiter(this, void 0, void 0, function* () {
276
- let feeMicroLamportPerCU = yield this._getFeeRate(mutableAccounts);
277
- if (((_a = this.bribeData) === null || _a === void 0 ? void 0 : _a.getBribeFee) != null)
278
- feeMicroLamportPerCU = this.bribeData.getBribeFee(feeMicroLamportPerCU);
279
- let fee = feeMicroLamportPerCU.toString(10);
280
- if (this.getStaticFee != null) {
281
- fee += ";" + this.getStaticFee(feeMicroLamportPerCU);
282
- }
283
- else {
284
- fee += ";0";
285
- }
286
- if ((_b = this.bribeData) === null || _b === void 0 ? void 0 : _b.address) {
287
- fee += ";" + this.bribeData.address;
288
- }
289
- this.logger.debug("getFeeRate(): calculated fee: " + fee);
290
- return fee;
291
- });
262
+ async getFeeRate(mutableAccounts) {
263
+ let feeMicroLamportPerCU = await this._getFeeRate(mutableAccounts);
264
+ if (this.bribeData?.getBribeFee != null)
265
+ feeMicroLamportPerCU = this.bribeData.getBribeFee(feeMicroLamportPerCU);
266
+ let fee = feeMicroLamportPerCU.toString(10);
267
+ if (this.getStaticFee != null) {
268
+ fee += ";" + this.getStaticFee(feeMicroLamportPerCU);
269
+ }
270
+ else {
271
+ fee += ";0";
272
+ }
273
+ if (this.bribeData?.address) {
274
+ fee += ";" + this.bribeData.address;
275
+ }
276
+ this.logger.debug("getFeeRate(): calculated fee: " + fee);
277
+ return fee;
292
278
  }
293
279
  /**
294
280
  * Calculates the total priority fee paid for a given compute budget at a given fee rate
@@ -299,15 +285,15 @@ class SolanaFees {
299
285
  */
300
286
  getPriorityFee(computeUnits, feeRate, includeStaticFee = true) {
301
287
  if (feeRate == null)
302
- return new BN(0);
288
+ return 0n;
303
289
  const hashArr = feeRate.split("#");
304
290
  if (hashArr.length > 1) {
305
291
  feeRate = hashArr[0];
306
292
  }
307
293
  const arr = feeRate.split(";");
308
- const cuPrice = new BN(arr[0]);
309
- const staticFee = includeStaticFee ? new BN(arr[1]) : new BN(0);
310
- return staticFee.add(cuPrice.mul(new BN(computeUnits)).div(new BN(1000000)));
294
+ const cuPrice = BigInt(arr[0]);
295
+ const staticFee = includeStaticFee ? BigInt(arr[1]) : 0n;
296
+ return staticFee + (cuPrice * BigInt(computeUnits) / 1000000n);
311
297
  }
312
298
  /**
313
299
  * Applies fee rate to a transaction at the beginning of the transaction (has to be called after
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SolanaSlots = void 0;
13
4
  const SolanaModule_1 = require("../SolanaModule");
@@ -49,17 +40,15 @@ class SolanaSlots extends SolanaModule_1.SolanaModule {
49
40
  *
50
41
  * @param commitment
51
42
  */
52
- getSlotAndTimestamp(commitment) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- let cachedSlotData = this.slotCache[commitment];
55
- if (cachedSlotData == null || Date.now() - cachedSlotData.timestamp > this.SLOT_CACHE_TIME) {
56
- cachedSlotData = this.fetchAndSaveSlot(commitment);
57
- }
58
- return {
59
- slot: yield cachedSlotData.slot,
60
- timestamp: cachedSlotData.timestamp
61
- };
62
- });
43
+ async getSlotAndTimestamp(commitment) {
44
+ let cachedSlotData = this.slotCache[commitment];
45
+ if (cachedSlotData == null || Date.now() - cachedSlotData.timestamp > this.SLOT_CACHE_TIME) {
46
+ cachedSlotData = this.fetchAndSaveSlot(commitment);
47
+ }
48
+ return {
49
+ slot: await cachedSlotData.slot,
50
+ timestamp: cachedSlotData.timestamp
51
+ };
63
52
  }
64
53
  /**
65
54
  * Gets the slot for a given commitment, uses slot cache & tries to estimate current slot based on the cached
@@ -67,15 +56,13 @@ class SolanaSlots extends SolanaModule_1.SolanaModule {
67
56
  *
68
57
  * @param commitment
69
58
  */
70
- getSlot(commitment) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- let cachedSlotData = this.slotCache[commitment];
73
- if (cachedSlotData != null && Date.now() - cachedSlotData.timestamp < this.SLOT_CACHE_TIME) {
74
- return (yield cachedSlotData.slot) + Math.floor((Date.now() - cachedSlotData.timestamp) / this.root.SLOT_TIME);
75
- }
76
- cachedSlotData = this.fetchAndSaveSlot(commitment);
77
- return yield cachedSlotData.slot;
78
- });
59
+ async getSlot(commitment) {
60
+ let cachedSlotData = this.slotCache[commitment];
61
+ if (cachedSlotData != null && Date.now() - cachedSlotData.timestamp < this.SLOT_CACHE_TIME) {
62
+ return (await cachedSlotData.slot) + Math.floor((Date.now() - cachedSlotData.timestamp) / this.root.SLOT_TIME);
63
+ }
64
+ cachedSlotData = this.fetchAndSaveSlot(commitment);
65
+ return await cachedSlotData.slot;
79
66
  }
80
67
  }
81
68
  exports.SolanaSlots = SolanaSlots;
@@ -1,7 +1,6 @@
1
1
  import { SolanaModule } from "../SolanaModule";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import { Account } from "@solana/spl-token";
4
- import * as BN from "bn.js";
5
4
  import { SolanaTx } from "./SolanaTransactions";
6
5
  import { SolanaAction } from "../SolanaAction";
7
6
  export declare class SolanaTokens extends SolanaModule {
@@ -31,7 +30,7 @@ export declare class SolanaTokens extends SolanaModule {
31
30
  * @param initAta whether we should also initialize the ATA before depositing SOL
32
31
  * @constructor
33
32
  */
34
- Wrap(publicKey: PublicKey, amount: BN, initAta: boolean): SolanaAction;
33
+ Wrap(publicKey: PublicKey, amount: bigint, initAta: boolean): SolanaAction;
35
34
  /**
36
35
  * Action for unwrapping WSOL to SOL for a specific public key
37
36
  *
@@ -39,8 +38,8 @@ export declare class SolanaTokens extends SolanaModule {
39
38
  * @constructor
40
39
  */
41
40
  Unwrap(publicKey: PublicKey): SolanaAction;
42
- readonly WSOL_ADDRESS: PublicKey;
43
- readonly SPL_ATA_RENT_EXEMPT = 2039280;
41
+ static readonly WSOL_ADDRESS: PublicKey;
42
+ static readonly SPL_ATA_RENT_EXEMPT = 2039280;
44
43
  /**
45
44
  * Action for transferring the native SOL token, uses provider's public key as a sender
46
45
  *
@@ -104,7 +103,7 @@ export declare class SolanaTokens extends SolanaModule {
104
103
  /**
105
104
  * Returns the rent exempt deposit required to initiate the ATA
106
105
  */
107
- getATARentExemptLamports(): Promise<BN>;
106
+ getATARentExemptLamports(): Promise<bigint>;
108
107
  /**
109
108
  * Returns the token balance of the public key
110
109
  *
@@ -112,7 +111,7 @@ export declare class SolanaTokens extends SolanaModule {
112
111
  * @param token
113
112
  */
114
113
  getTokenBalance(publicKey: PublicKey, token: PublicKey): Promise<{
115
- balance: BN;
114
+ balance: bigint;
116
115
  ataExists: boolean;
117
116
  }>;
118
117
  /**
@@ -133,5 +132,5 @@ export declare class SolanaTokens extends SolanaModule {
133
132
  * @param dstAddress destination address of the recipient
134
133
  * @param feeRate fee rate to use for the transaction
135
134
  */
136
- txsTransfer(signer: PublicKey, token: PublicKey, amount: BN, dstAddress: PublicKey, feeRate?: string): Promise<SolanaTx[]>;
135
+ txsTransfer(signer: PublicKey, token: PublicKey, amount: bigint, dstAddress: PublicKey, feeRate?: string): Promise<SolanaTx[]>;
137
136
  }