@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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/solana/SolanaChains.d.ts +14 -0
- package/dist/solana/SolanaChains.js +18 -0
- package/dist/solana/SolanaInitializer.d.ts +18 -0
- package/dist/solana/SolanaInitializer.js +59 -0
- package/dist/solana/base/SolanaAction.js +25 -38
- package/dist/solana/base/modules/SolanaBlocks.js +18 -29
- package/dist/solana/base/modules/SolanaEvents.js +15 -26
- package/dist/solana/base/modules/SolanaFees.d.ts +4 -5
- package/dist/solana/base/modules/SolanaFees.js +168 -182
- package/dist/solana/base/modules/SolanaSlots.js +16 -29
- package/dist/solana/base/modules/SolanaTokens.d.ts +6 -7
- package/dist/solana/base/modules/SolanaTokens.js +63 -84
- package/dist/solana/base/modules/SolanaTransactions.d.ts +2 -2
- package/dist/solana/base/modules/SolanaTransactions.js +143 -165
- package/dist/solana/btcrelay/SolanaBtcRelay.d.ts +2 -3
- package/dist/solana/btcrelay/SolanaBtcRelay.js +185 -221
- package/dist/solana/events/SolanaChainEvents.js +113 -138
- package/dist/solana/events/SolanaChainEventsBrowser.js +56 -65
- package/dist/solana/program/modules/SolanaProgramEvents.js +13 -24
- package/dist/solana/swaps/SolanaSwapData.d.ts +15 -11
- package/dist/solana/swaps/SolanaSwapData.js +29 -13
- package/dist/solana/swaps/SolanaSwapProgram.d.ts +40 -41
- package/dist/solana/swaps/SolanaSwapProgram.js +214 -223
- package/dist/solana/swaps/modules/SolanaDataAccount.d.ts +2 -3
- package/dist/solana/swaps/modules/SolanaDataAccount.js +117 -141
- package/dist/solana/swaps/modules/SolanaLpVault.d.ts +4 -5
- package/dist/solana/swaps/modules/SolanaLpVault.js +87 -110
- package/dist/solana/swaps/modules/SwapClaim.d.ts +4 -4
- package/dist/solana/swaps/modules/SwapClaim.js +122 -134
- package/dist/solana/swaps/modules/SwapInit.d.ts +2 -3
- package/dist/solana/swaps/modules/SwapInit.js +254 -285
- package/dist/solana/swaps/modules/SwapRefund.d.ts +2 -3
- package/dist/solana/swaps/modules/SwapRefund.js +103 -113
- package/dist/utils/Utils.d.ts +10 -0
- package/dist/utils/Utils.js +62 -35
- package/package.json +9 -6
- package/src/index.ts +1 -0
- package/src/solana/SolanaChains.ts +16 -0
- package/src/solana/SolanaInitializer.ts +98 -0
- package/src/solana/base/SolanaBase.ts +1 -2
- package/src/solana/base/modules/SolanaEvents.ts +0 -1
- package/src/solana/base/modules/SolanaFees.ts +35 -31
- package/src/solana/base/modules/SolanaTokens.ts +26 -27
- package/src/solana/base/modules/SolanaTransactions.ts +33 -28
- package/src/solana/btcrelay/SolanaBtcRelay.ts +6 -10
- package/src/solana/events/SolanaChainEventsBrowser.ts +14 -10
- package/src/solana/program/modules/SolanaProgramEvents.ts +1 -1
- package/src/solana/swaps/SolanaSwapData.ts +38 -19
- package/src/solana/swaps/SolanaSwapProgram.ts +135 -107
- package/src/solana/swaps/modules/SolanaDataAccount.ts +4 -6
- package/src/solana/swaps/modules/SolanaLpVault.ts +18 -18
- package/src/solana/swaps/modules/SwapClaim.ts +14 -17
- package/src/solana/swaps/modules/SwapInit.ts +35 -38
- package/src/solana/swaps/modules/SwapRefund.ts +20 -23
- 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 =
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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() !==
|
|
129
|
+
if (decodedIxData.toPubkey.toBase58() !== this.bribeData?.address)
|
|
145
130
|
return null;
|
|
146
|
-
return
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
|
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 =
|
|
309
|
-
const staticFee = includeStaticFee ?
|
|
310
|
-
return staticFee
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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:
|
|
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<
|
|
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:
|
|
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:
|
|
135
|
+
txsTransfer(signer: PublicKey, token: PublicKey, amount: bigint, dstAddress: PublicKey, feeRate?: string): Promise<SolanaTx[]>;
|
|
137
136
|
}
|