@cryptorubic/web3 0.8.17-alpha.solana.20 → 0.8.17-alpha.solana.22
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/package.json +1 -1
- package/src/lib/adapter/adapters/solana-adapter.js +7 -1
- package/src/lib/adapter/adapters/utils/solana-utils/solana-gas-service.d.ts +1 -1
- package/src/lib/adapter/adapters/utils/solana-utils/solana-gas-service.js +7 -16
- package/src/lib/utils/models/solana-transaction-config.d.ts +1 -0
package/package.json
CHANGED
|
@@ -50,7 +50,13 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
50
50
|
const { blockhash } = await this.public.getLatestBlockhash();
|
|
51
51
|
const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
|
|
52
52
|
tx.message.recentBlockhash = blockhash;
|
|
53
|
-
const simulation = this.public.simulateTransaction(tx, {
|
|
53
|
+
const simulation = this.public.simulateTransaction(tx, {
|
|
54
|
+
replaceRecentBlockhash: true,
|
|
55
|
+
accounts: {
|
|
56
|
+
encoding: 'base64',
|
|
57
|
+
addresses: [config.walletAddress]
|
|
58
|
+
}
|
|
59
|
+
});
|
|
54
60
|
const resp = await (0, timeout_1.withTimeout)(simulation, timeout, 'Solana Simulation Timeout!');
|
|
55
61
|
return new bignumber_js_1.default(resp.value.unitsConsumed || exports.DEFAULT_CU_LIMIT).toFixed(0);
|
|
56
62
|
}
|
|
@@ -20,7 +20,7 @@ export declare class SolanaGasService {
|
|
|
20
20
|
*/
|
|
21
21
|
getPriorityFee(txData: string): Promise<BigNumber>;
|
|
22
22
|
/**
|
|
23
|
-
* @returns
|
|
23
|
+
* @returns prioritizationFee in micro-lamports(lamport * 10^-6)
|
|
24
24
|
*/
|
|
25
25
|
private calculatePriorityFeeHelius;
|
|
26
26
|
private getRecentPriorityFeeSolWeb3;
|
|
@@ -40,7 +40,7 @@ class SolanaGasService {
|
|
|
40
40
|
*/
|
|
41
41
|
async getPriorityFee(txData) {
|
|
42
42
|
if (!this.HELIUS_API_KEY) {
|
|
43
|
-
console.warn('[
|
|
43
|
+
console.warn('[SolanaApiService_getPriorityFee] heliusApiKey is not provided in "createFactory"');
|
|
44
44
|
}
|
|
45
45
|
const resp = await Promise.allSettled([this.calculatePriorityFeeHelius(txData), this.getRecentPriorityFeeSolWeb3()]);
|
|
46
46
|
const cuPrice = resp
|
|
@@ -50,7 +50,7 @@ class SolanaGasService {
|
|
|
50
50
|
return cuPrice;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* @returns
|
|
53
|
+
* @returns prioritizationFee in micro-lamports(lamport * 10^-6)
|
|
54
54
|
*/
|
|
55
55
|
async calculatePriorityFeeHelius(txData) {
|
|
56
56
|
try {
|
|
@@ -75,7 +75,6 @@ class SolanaGasService {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
async getRecentPriorityFeeSolWeb3() {
|
|
78
|
-
const BASE_FEE_MICROLAMPORTS = 5_000;
|
|
79
78
|
const lastSlot = await this.connection.getSlot();
|
|
80
79
|
// last slots array [1000, 1001, 1002 ...]
|
|
81
80
|
const last10Slots = Array.from({ length: 10 }, (_, idx) => lastSlot - idx).reverse();
|
|
@@ -83,23 +82,15 @@ class SolanaGasService {
|
|
|
83
82
|
const block = await this.connection.getBlock(slotNum, { maxSupportedTransactionVersion: 0, commitment: 'confirmed' });
|
|
84
83
|
if (!block)
|
|
85
84
|
return [];
|
|
86
|
-
return block.transactions.map((tx) => (tx.meta && tx.meta.fee ? tx.meta.fee :
|
|
85
|
+
return block.transactions.map((tx) => (tx.meta && tx.meta.fee ? tx.meta.fee : 0));
|
|
87
86
|
};
|
|
88
87
|
const resp = await Promise.all(last10Slots.map((slotNum) => getPriorityFeesFromBlock(slotNum)));
|
|
89
|
-
const
|
|
90
|
-
const avgProrityFee =
|
|
88
|
+
const filteredPriorityFees = resp.flat().filter((fee) => fee > 0);
|
|
89
|
+
const avgProrityFee = filteredPriorityFees
|
|
91
90
|
.reduce((acc, fee) => acc.plus(fee), new bignumber_js_1.default(0))
|
|
92
|
-
.div(
|
|
91
|
+
.div(filteredPriorityFees.length)
|
|
93
92
|
.dp(0, bignumber_js_1.default.ROUND_CEIL);
|
|
94
|
-
|
|
95
|
-
// const avgPriorityFee = resp
|
|
96
|
-
// .reduce((acc, tx) => {
|
|
97
|
-
// const cuPrice = new BigNumber(tx.prioritizationFee).multipliedBy(1_000_000).div(this.DEFAULT_CU_LIMIT);
|
|
98
|
-
// return acc.gt(cuPrice) ? acc : cuPrice;
|
|
99
|
-
// }, new BigNumber(0))
|
|
100
|
-
// .div(resp.length)
|
|
101
|
-
// .dp(0, BigNumber.ROUND_CEIL);
|
|
102
|
-
this.logger?.customLog('SOLANA_WEB3 PRIORITY_FEE SUCCESS', { priorityFeeEstimate: avgProrityFee.toNumber(), flattenPriorityFees });
|
|
93
|
+
this.logger?.customLog('SOLANA_WEB3 PRIORITY_FEE SUCCESS', { priorityFeeEstimate: avgProrityFee.toNumber(), filteredPriorityFees });
|
|
103
94
|
return avgProrityFee;
|
|
104
95
|
}
|
|
105
96
|
}
|