@cryptorubic/web3 0.8.17-alpha.solana.5 → 0.8.17-alpha.solana.7
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 +3 -3
- package/src/lib/adapter/adapters/evm-adapter.js +5 -5
- package/src/lib/adapter/adapters/solana-adapter.d.ts +2 -2
- package/src/lib/adapter/adapters/solana-adapter.js +4 -4
- package/src/lib/adapter/adapters/utils/solana-utils/{solana-api-service.d.ts → solana-gas-service.d.ts} +4 -1
- package/src/lib/adapter/adapters/utils/solana-utils/{solana-api-service.js → solana-gas-service.js} +18 -5
- package/src/lib/adapter/adapters/utils/solana-utils/solana-tokens-service.js +1 -1
- package/src/lib/adapter/adapters/utils/solana-utils/utility-funcs.d.ts +1 -1
- package/src/lib/adapter/adapters/utils/solana-utils/utility-funcs.js +2 -2
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptorubic/web3",
|
|
3
|
-
"version": "0.8.17-alpha.solana.
|
|
3
|
+
"version": "0.8.17-alpha.solana.7",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.0",
|
|
6
6
|
"bignumber.js": "9.1.2",
|
|
7
|
-
"@cryptorubic/core": "0.8.17-alpha.solana.
|
|
7
|
+
"@cryptorubic/core": "0.8.17-alpha.solana.7",
|
|
8
8
|
"viem": "^2.19.1",
|
|
9
9
|
"web3-utils": "^4.3.1",
|
|
10
10
|
"@ton/ton": "^15.1.0",
|
|
11
11
|
"@solana/web3.js": "1.95.3",
|
|
12
12
|
"@solflare-wallet/utl-sdk": "^1.4.0",
|
|
13
13
|
"@ethersproject/bignumber": "^5.7.0",
|
|
14
|
-
"@cryptorubic/tron-types": "0.8.17-alpha.solana.
|
|
14
|
+
"@cryptorubic/tron-types": "0.8.17-alpha.solana.7",
|
|
15
15
|
"bitcoin-address-validation": "^2.2.3",
|
|
16
16
|
"axios": "0.27.2",
|
|
17
17
|
"crc-32": "^1.2.2",
|
|
@@ -34,13 +34,13 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
36
|
const transports = rpcList.map((rpc) => (0, viem_1.http)(rpc, {
|
|
37
|
-
batch: { batchSize:
|
|
37
|
+
batch: { batchSize: 2_000, wait: 16 },
|
|
38
38
|
onFetchResponse: (response) => {
|
|
39
39
|
this.handlePossibleError(response);
|
|
40
40
|
},
|
|
41
41
|
retryCount: 2,
|
|
42
42
|
retryDelay: 100,
|
|
43
|
-
timeout:
|
|
43
|
+
timeout: 5_000
|
|
44
44
|
}));
|
|
45
45
|
const chain = viem_blockchain_mapping_1.viemBlockchainMapping[this.blockchain];
|
|
46
46
|
return (0, viem_1.createPublicClient)({
|
|
@@ -48,7 +48,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
48
48
|
chain,
|
|
49
49
|
transport: (0, viem_1.fallback)(transports, {
|
|
50
50
|
rank: {
|
|
51
|
-
interval:
|
|
51
|
+
interval: 1_800_000
|
|
52
52
|
}
|
|
53
53
|
})
|
|
54
54
|
});
|
|
@@ -135,7 +135,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
135
135
|
throw err;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
async simulateTransaction(config, from, timeout =
|
|
138
|
+
async simulateTransaction(config, from, timeout = 15_000) {
|
|
139
139
|
try {
|
|
140
140
|
const callParams = {
|
|
141
141
|
account: from,
|
|
@@ -278,7 +278,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
278
278
|
to: tx.to
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
|
-
async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(
|
|
281
|
+
async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(1_000_000), amount) {
|
|
282
282
|
const approveAmount = amount ? amount : new bignumber_js_1.default(2).pow(256).minus(1);
|
|
283
283
|
const expiration = new bignumber_js_1.default(Date.now()).plus(deadline).toFixed();
|
|
284
284
|
const tx = this.encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, approveAmount.toFixed());
|
|
@@ -6,12 +6,12 @@ import BigNumber from 'bignumber.js';
|
|
|
6
6
|
import { SolanaRawInstruction } from './models/solana-web3-types';
|
|
7
7
|
import { SolanaTxConfig } from '../../utils/models/solana-transaction-config';
|
|
8
8
|
import { SolanaAdapterConfig } from './models/solana-adapter-config';
|
|
9
|
-
import {
|
|
9
|
+
import { SolanaGasService } from './utils/solana-utils/solana-gas-service';
|
|
10
10
|
export declare const NATIVE_SOLANA_MINT_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
11
11
|
export declare const DEFAULT_CU_LIMIT = 600000;
|
|
12
12
|
export declare class SolanaAdapter extends AbstractAdapter<Connection, Connection, SolanaBlockchainName> {
|
|
13
13
|
private readonly httpClient;
|
|
14
|
-
readonly
|
|
14
|
+
readonly gasService: SolanaGasService;
|
|
15
15
|
constructor(rpcList: string[], httpClient: HttpClient, solanaConfig: SolanaAdapterConfig, logger?: ICustomLogger);
|
|
16
16
|
private createPublicClient;
|
|
17
17
|
read<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
@@ -9,16 +9,16 @@ const web3_pure_1 = require("../../utils/web3-pure");
|
|
|
9
9
|
const bignumber_js_1 = require("bignumber.js");
|
|
10
10
|
const bs58_1 = require("bs58");
|
|
11
11
|
const utils_1 = require("ethers/lib/utils");
|
|
12
|
-
const
|
|
12
|
+
const solana_gas_service_1 = require("./utils/solana-utils/solana-gas-service");
|
|
13
13
|
const solana_tokens_service_1 = require("./utils/solana-utils/solana-tokens-service");
|
|
14
14
|
exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
|
|
15
|
-
exports.DEFAULT_CU_LIMIT =
|
|
15
|
+
exports.DEFAULT_CU_LIMIT = 600_000;
|
|
16
16
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
17
17
|
constructor(rpcList, httpClient, solanaConfig, logger) {
|
|
18
18
|
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
19
19
|
this.httpClient = httpClient;
|
|
20
20
|
this.public = this.createPublicClient(rpcList);
|
|
21
|
-
this.
|
|
21
|
+
this.gasService = new solana_gas_service_1.SolanaGasService(httpClient, this.public, solanaConfig);
|
|
22
22
|
}
|
|
23
23
|
createPublicClient(rpcList) {
|
|
24
24
|
if (!rpcList?.[0]) {
|
|
@@ -41,7 +41,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
41
41
|
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
42
42
|
throw new Error('Method multicall is not supported');
|
|
43
43
|
}
|
|
44
|
-
async simulateTransaction(config, timeout =
|
|
44
|
+
async simulateTransaction(config, timeout = 15_000) {
|
|
45
45
|
try {
|
|
46
46
|
const bufferData = config.data.startsWith('0x') ? Buffer.from(config.data.slice(2), 'hex') : Buffer.from(config.data, 'base64');
|
|
47
47
|
const { blockhash } = await this.public.getLatestBlockhash();
|
|
@@ -2,7 +2,7 @@ import { HttpClient } from '@cryptorubic/core';
|
|
|
2
2
|
import { Connection } from '@solana/web3.js';
|
|
3
3
|
import { SolanaAdapterConfig } from '../../models/solana-adapter-config';
|
|
4
4
|
import BigNumber from 'bignumber.js';
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class SolanaGasService {
|
|
6
6
|
private httpClient;
|
|
7
7
|
private readonly connection;
|
|
8
8
|
private readonly HELIUS_API_URL;
|
|
@@ -13,7 +13,10 @@ export declare class SolanaApiService {
|
|
|
13
13
|
*/
|
|
14
14
|
getConsumedUnitsLimit(txData: string): Promise<BigNumber>;
|
|
15
15
|
/**
|
|
16
|
+
* @param txData base64 or hex string
|
|
16
17
|
* @returns wei ComputedUnitsPrice - like gasPrice in evm
|
|
17
18
|
*/
|
|
18
19
|
getConsumedUnitsPrice(txData: string): Promise<BigNumber>;
|
|
20
|
+
private calculateCUPriceHelius;
|
|
21
|
+
private calculateCUPriceSolWeb3;
|
|
19
22
|
}
|
package/src/lib/adapter/adapters/utils/solana-utils/{solana-api-service.js → solana-gas-service.js}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SolanaGasService = void 0;
|
|
4
4
|
const utils_1 = require("ethers/lib/utils");
|
|
5
5
|
const utility_funcs_1 = require("./utility-funcs");
|
|
6
6
|
const bignumber_js_1 = require("bignumber.js");
|
|
7
|
-
class
|
|
7
|
+
class SolanaGasService {
|
|
8
8
|
constructor(httpClient, connection, solanaConfig) {
|
|
9
9
|
this.httpClient = httpClient;
|
|
10
10
|
this.connection = connection;
|
|
@@ -15,7 +15,7 @@ class SolanaApiService {
|
|
|
15
15
|
* @returns wei ComputedUnitsLimit - like gasLimit in evm
|
|
16
16
|
*/
|
|
17
17
|
async getConsumedUnitsLimit(txData) {
|
|
18
|
-
const DEFAULT_CU_LIMIT =
|
|
18
|
+
const DEFAULT_CU_LIMIT = 600_000;
|
|
19
19
|
try {
|
|
20
20
|
const tx = (0, utility_funcs_1.convertB64DataToTx)(txData);
|
|
21
21
|
const resp = await this.connection.simulateTransaction(tx, {
|
|
@@ -29,12 +29,17 @@ class SolanaApiService {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
+
* @param txData base64 or hex string
|
|
32
33
|
* @returns wei ComputedUnitsPrice - like gasPrice in evm
|
|
33
34
|
*/
|
|
34
35
|
async getConsumedUnitsPrice(txData) {
|
|
35
36
|
if (!this.HELIUS_API_KEY) {
|
|
36
|
-
|
|
37
|
+
console.warn('[SolanaApiService_getConsumedUnitsPrice] heliusApiKey is not provided in "createFactory"');
|
|
37
38
|
}
|
|
39
|
+
const cuPrice = await Promise.any([this.calculateCUPriceHelius(txData), this.calculateCUPriceSolWeb3()]);
|
|
40
|
+
return cuPrice;
|
|
41
|
+
}
|
|
42
|
+
async calculateCUPriceHelius(txData) {
|
|
38
43
|
const tx = (0, utility_funcs_1.convertB64DataToTx)(txData);
|
|
39
44
|
const resp = await this.httpClient.post(`${this.HELIUS_API_URL}/?api-key=${this.HELIUS_API_KEY}`, {
|
|
40
45
|
jsonrpc: '2.0',
|
|
@@ -49,5 +54,13 @@ class SolanaApiService {
|
|
|
49
54
|
});
|
|
50
55
|
return new bignumber_js_1.default(resp.result.priorityFeeEstimate);
|
|
51
56
|
}
|
|
57
|
+
async calculateCUPriceSolWeb3() {
|
|
58
|
+
const resp = await this.connection.getRecentPrioritizationFees();
|
|
59
|
+
const cuPriceSum = resp
|
|
60
|
+
.reduce((acc, tx) => acc.plus(tx.prioritizationFee), new bignumber_js_1.default(0))
|
|
61
|
+
.div(resp.length)
|
|
62
|
+
.dp(0, bignumber_js_1.default.ROUND_CEIL);
|
|
63
|
+
return cuPriceSum;
|
|
64
|
+
}
|
|
52
65
|
}
|
|
53
|
-
exports.
|
|
66
|
+
exports.SolanaGasService = SolanaGasService;
|
|
@@ -57,7 +57,7 @@ class SolanaTokensService {
|
|
|
57
57
|
}
|
|
58
58
|
async fetchTokensFromOldBackend(mints, prevFetchedTokens) {
|
|
59
59
|
const tokensAddresses = mints.map((mint) => mint.toString());
|
|
60
|
-
const { content: tokensFromOlbBackend } = await (0, timeout_1.withTimeout)(this.getTokensListOld(tokensAddresses),
|
|
60
|
+
const { content: tokensFromOlbBackend } = await (0, timeout_1.withTimeout)(this.getTokensListOld(tokensAddresses), 3_000, 'Api Timeout!').catch(() => ({ content: [] }));
|
|
61
61
|
const notSortedTokensList = [...prevFetchedTokens, ...tokensFromOlbBackend];
|
|
62
62
|
const notFetchedMints = this.getNotFetchedTokensList(notSortedTokensList);
|
|
63
63
|
return {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { VersionedTransaction } from '@solana/web3.js';
|
|
2
|
-
export declare function convertB64DataToTx(
|
|
2
|
+
export declare function convertB64DataToTx(txData: string): VersionedTransaction;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertB64DataToTx = convertB64DataToTx;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
function convertB64DataToTx(
|
|
6
|
-
const bufferData =
|
|
5
|
+
function convertB64DataToTx(txData) {
|
|
6
|
+
const bufferData = txData.startsWith('0x') ? Buffer.from(txData.slice(2), 'hex') : Buffer.from(txData, 'base64');
|
|
7
7
|
const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
|
|
8
8
|
return tx;
|
|
9
9
|
}
|