@cryptorubic/web3 0.8.17-alpha.solana.2 → 0.8.17-alpha.solana.20
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 +21 -15
- package/src/lib/adapter/adapters/abstract-adapter.js +5 -3
- package/src/lib/adapter/adapters/bitcoin-adapter.js +1 -0
- package/src/lib/adapter/adapters/constants/tron-multicall-abi.d.ts +1 -1
- package/src/lib/adapter/adapters/evm-adapter.js +8 -6
- package/src/lib/adapter/adapters/models/approve-adapter.d.ts +1 -1
- package/src/lib/adapter/adapters/solana-adapter.d.ts +7 -3
- package/src/lib/adapter/adapters/solana-adapter.js +55 -18
- package/src/lib/adapter/adapters/ton-adapter.js +2 -0
- package/src/lib/adapter/adapters/tron-adapter.d.ts +6 -5
- package/src/lib/adapter/adapters/tron-adapter.js +1 -1
- package/src/lib/adapter/adapters/utils/solana-utils/solana-gas-service.d.ts +27 -0
- package/src/lib/adapter/adapters/utils/solana-utils/solana-gas-service.js +106 -0
- package/src/lib/adapter/adapters/utils/{solana-tokens-service.d.ts → solana-utils/solana-tokens-service.d.ts} +1 -1
- package/src/lib/adapter/adapters/utils/{solana-tokens-service.js → solana-utils/solana-tokens-service.js} +10 -8
- package/src/lib/adapter/adapters/utils/solana-utils/utility-funcs.d.ts +2 -0
- package/src/lib/adapter/adapters/utils/solana-utils/utility-funcs.js +9 -0
- package/src/lib/adapter/adapters/utils/ton-api.service.js +4 -0
- package/src/lib/adapter/blockchain-adapter-factory.service.js +4 -1
- package/src/lib/utils/models/solana-transaction-config.d.ts +0 -6
- package/src/lib/utils/web3-types/common-web3-pure.js +4 -2
- package/src/lib/utils/web3-types/solana-web3-pure.js +1 -1
- package/src/lib/utils/web3-types/sui-web3-pure.js +2 -2
- package/src/lib/utils/web3-types/tron-web3-pure.d.ts +2 -3
- package/src/lib/adapter/adapters/utils/solana-api-service.d.ts +0 -18
- package/src/lib/adapter/adapters/utils/solana-api-service.js +0 -49
package/package.json
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptorubic/web3",
|
|
3
|
-
"version": "0.8.17-alpha.solana.
|
|
3
|
+
"version": "0.8.17-alpha.solana.20",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"@
|
|
8
|
-
"viem": "^2.19.1",
|
|
9
|
-
"web3-utils": "^4.3.1",
|
|
10
|
-
"@ton/ton": "^15.1.0",
|
|
5
|
+
"@ethersproject/bignumber": "^5.8.0",
|
|
6
|
+
"@mysten/sui": "^1.24.0",
|
|
7
|
+
"@solana/spl-token": "*",
|
|
11
8
|
"@solana/web3.js": "1.95.3",
|
|
12
9
|
"@solflare-wallet/utl-sdk": "^1.4.0",
|
|
13
|
-
"@
|
|
14
|
-
"@
|
|
10
|
+
"@suiet/wallet-sdk": "^0.3.3",
|
|
11
|
+
"@ton/ton": "^15.1.0",
|
|
12
|
+
"axios": "*",
|
|
13
|
+
"bignumber.js": "9.1.2",
|
|
15
14
|
"bitcoin-address-validation": "^2.2.3",
|
|
16
|
-
"
|
|
15
|
+
"bs58": "^6.0.0",
|
|
17
16
|
"crc-32": "^1.2.2",
|
|
17
|
+
"ethers": "*",
|
|
18
|
+
"js-base64": "^3.7.8",
|
|
18
19
|
"tronweb": "^6.0.0-beta.4",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"@suiet/wallet-sdk": "^0.3.3",
|
|
22
|
-
"bs58": "^6.0.0",
|
|
23
|
-
"ethers": "5.7.2"
|
|
20
|
+
"tslib": "*",
|
|
21
|
+
"viem": "^2.33.1"
|
|
24
22
|
},
|
|
23
|
+
"peerDependencies": {},
|
|
25
24
|
"type": "commonjs",
|
|
26
25
|
"main": "./src/index.js",
|
|
27
26
|
"typings": "./src/index.d.ts",
|
|
@@ -31,5 +30,12 @@
|
|
|
31
30
|
"author": {
|
|
32
31
|
"name": "Sleta Dmitrii"
|
|
33
32
|
},
|
|
33
|
+
"exports": {
|
|
34
|
+
"./package.json": "./package.json",
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./src/index.d.ts",
|
|
37
|
+
"default": "./src/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
34
40
|
"types": "./src/index.d.ts"
|
|
35
41
|
}
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AbstractAdapter = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
class AbstractAdapter {
|
|
6
|
+
logger;
|
|
7
|
+
blockchain;
|
|
8
|
+
_public = null;
|
|
6
9
|
set public(value) {
|
|
7
10
|
this._public = value;
|
|
8
11
|
}
|
|
@@ -14,6 +17,7 @@ class AbstractAdapter {
|
|
|
14
17
|
}
|
|
15
18
|
return this._public;
|
|
16
19
|
}
|
|
20
|
+
_wallet = null;
|
|
17
21
|
set wallet(value) {
|
|
18
22
|
this._wallet = value;
|
|
19
23
|
}
|
|
@@ -25,6 +29,7 @@ class AbstractAdapter {
|
|
|
25
29
|
}
|
|
26
30
|
return this._wallet;
|
|
27
31
|
}
|
|
32
|
+
_walletAddress = null;
|
|
28
33
|
set walletAddress(value) {
|
|
29
34
|
this._walletAddress = value;
|
|
30
35
|
}
|
|
@@ -37,9 +42,6 @@ class AbstractAdapter {
|
|
|
37
42
|
return this._walletAddress;
|
|
38
43
|
}
|
|
39
44
|
constructor(blockchain, logger) {
|
|
40
|
-
this._public = null;
|
|
41
|
-
this._wallet = null;
|
|
42
|
-
this._walletAddress = null;
|
|
43
45
|
this.blockchain = blockchain;
|
|
44
46
|
if (logger) {
|
|
45
47
|
this.logger = logger;
|
|
@@ -5,6 +5,7 @@ const core_1 = require("@cryptorubic/core");
|
|
|
5
5
|
const bignumber_js_1 = require("bignumber.js");
|
|
6
6
|
const abstract_adapter_1 = require("./abstract-adapter");
|
|
7
7
|
class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
8
|
+
httpClient;
|
|
8
9
|
constructor(httpClient, logger) {
|
|
9
10
|
super(core_1.BLOCKCHAIN_NAME.BITCOIN, logger);
|
|
10
11
|
this.httpClient = httpClient;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AbiItem } from '
|
|
1
|
+
import { AbiItem } from '../../../utils/models/abi-types';
|
|
2
2
|
export declare const TRON_MULTICALL_ABI: AbiItem[];
|
|
@@ -34,21 +34,22 @@ 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
|
+
// @ts-ignore
|
|
46
47
|
return (0, viem_1.createPublicClient)({
|
|
47
48
|
// @ts-ignore
|
|
48
49
|
chain,
|
|
49
50
|
transport: (0, viem_1.fallback)(transports, {
|
|
50
51
|
rank: {
|
|
51
|
-
interval:
|
|
52
|
+
interval: 1_800_000
|
|
52
53
|
}
|
|
53
54
|
})
|
|
54
55
|
});
|
|
@@ -80,7 +81,8 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
80
81
|
to: to,
|
|
81
82
|
value: (0, viem_1.parseEther)(value),
|
|
82
83
|
data: data,
|
|
83
|
-
chain: this.public.chain
|
|
84
|
+
chain: this.public.chain,
|
|
85
|
+
kzg: undefined
|
|
84
86
|
});
|
|
85
87
|
return result;
|
|
86
88
|
}
|
|
@@ -135,7 +137,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
135
137
|
throw err;
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
|
-
async simulateTransaction(config, from, timeout =
|
|
140
|
+
async simulateTransaction(config, from, timeout = 15_000) {
|
|
139
141
|
try {
|
|
140
142
|
const callParams = {
|
|
141
143
|
account: from,
|
|
@@ -278,7 +280,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
278
280
|
to: tx.to
|
|
279
281
|
};
|
|
280
282
|
}
|
|
281
|
-
async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(
|
|
283
|
+
async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(1_000_000), amount) {
|
|
282
284
|
const approveAmount = amount ? amount : new bignumber_js_1.default(2).pow(256).minus(1);
|
|
283
285
|
const expiration = new bignumber_js_1.default(Date.now()).plus(deadline).toFixed();
|
|
284
286
|
const tx = this.encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, approveAmount.toFixed());
|
|
@@ -2,7 +2,7 @@ import { BlockchainName, TokenAmount } from '@cryptorubic/core';
|
|
|
2
2
|
import { AllowanceInfo } from './common-types';
|
|
3
3
|
import { AbstractAdapter } from '../abstract-adapter';
|
|
4
4
|
import { EvmTransactionConfig } from '../../../utils/models/evm-transaction-config';
|
|
5
|
-
import { TronTransactionConfig } from '
|
|
5
|
+
import { TronTransactionConfig } from '../../../utils/models/tron-transaction-config';
|
|
6
6
|
export interface ApproveAdapter<T> extends AbstractAdapter<any, any, BlockchainName> {
|
|
7
7
|
/**
|
|
8
8
|
* @param fromTokenAddress erc20 address of checked token
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Abi, MulticallResponse, MulticallParameters } from 'viem';
|
|
2
2
|
import { AbstractAdapter } from './abstract-adapter';
|
|
3
|
-
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
4
4
|
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
5
5
|
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
|
-
import { SolanaApiService } from './utils/solana-api-service';
|
|
9
8
|
import { SolanaAdapterConfig } from './models/solana-adapter-config';
|
|
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>;
|
|
@@ -36,4 +36,8 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, Connectio
|
|
|
36
36
|
getTxWithPayer(tx: VersionedTransaction, feePayer: string): Promise<VersionedTransaction>;
|
|
37
37
|
deserializeTransaction(data: string): VersionedTransaction;
|
|
38
38
|
serializeTransactionToBase58(tx: VersionedTransaction): string;
|
|
39
|
+
createTransferData(fromToken: PriceTokenAmount, walletAddress: string, receiver: string, convertToVersionedTx: boolean): Promise<Transaction | VersionedTransaction>;
|
|
40
|
+
createNativeTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromWeiAmount: string): Transaction;
|
|
41
|
+
createTokenTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromTokenAddress: string, fromWeiAmount: string): Promise<Transaction>;
|
|
42
|
+
getLatestBlockhash(): Promise<string>;
|
|
39
43
|
}
|
|
@@ -7,18 +7,21 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
7
7
|
const core_1 = require("@cryptorubic/core");
|
|
8
8
|
const web3_pure_1 = require("../../utils/web3-pure");
|
|
9
9
|
const bignumber_js_1 = require("bignumber.js");
|
|
10
|
-
const solana_tokens_service_1 = require("./utils/solana-tokens-service");
|
|
11
10
|
const bs58_1 = require("bs58");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const js_base64_1 = require("js-base64");
|
|
12
|
+
const solana_gas_service_1 = require("./utils/solana-utils/solana-gas-service");
|
|
13
|
+
const solana_tokens_service_1 = require("./utils/solana-utils/solana-tokens-service");
|
|
14
|
+
const timeout_1 = require("./utils/timeout");
|
|
14
15
|
exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
|
|
15
|
-
exports.DEFAULT_CU_LIMIT =
|
|
16
|
+
exports.DEFAULT_CU_LIMIT = 600_000;
|
|
16
17
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
18
|
+
httpClient;
|
|
19
|
+
gasService;
|
|
17
20
|
constructor(rpcList, httpClient, solanaConfig, logger) {
|
|
18
21
|
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
19
22
|
this.httpClient = httpClient;
|
|
20
23
|
this.public = this.createPublicClient(rpcList);
|
|
21
|
-
this.
|
|
24
|
+
this.gasService = new solana_gas_service_1.SolanaGasService(httpClient, this.public, logger, solanaConfig);
|
|
22
25
|
}
|
|
23
26
|
createPublicClient(rpcList) {
|
|
24
27
|
if (!rpcList?.[0]) {
|
|
@@ -41,22 +44,14 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
41
44
|
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
42
45
|
throw new Error('Method multicall is not supported');
|
|
43
46
|
}
|
|
44
|
-
async simulateTransaction(config, timeout =
|
|
47
|
+
async simulateTransaction(config, timeout = 15_000) {
|
|
45
48
|
try {
|
|
46
49
|
const bufferData = config.data.startsWith('0x') ? Buffer.from(config.data.slice(2), 'hex') : Buffer.from(config.data, 'base64');
|
|
47
50
|
const { blockhash } = await this.public.getLatestBlockhash();
|
|
48
51
|
const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
|
|
49
52
|
tx.message.recentBlockhash = blockhash;
|
|
50
|
-
const simulation = this.public.simulateTransaction(tx, {
|
|
51
|
-
|
|
52
|
-
replaceRecentBlockhash: false,
|
|
53
|
-
sigVerify: true,
|
|
54
|
-
accounts: { encoding: 'base64', addresses: [...Object.values(config.accounts)] }
|
|
55
|
-
});
|
|
56
|
-
const resp = await Promise.race([
|
|
57
|
-
simulation,
|
|
58
|
-
new Promise((_, reject) => setTimeout(() => reject('Timeout'), timeout))
|
|
59
|
-
]);
|
|
53
|
+
const simulation = this.public.simulateTransaction(tx, { replaceRecentBlockhash: true });
|
|
54
|
+
const resp = await (0, timeout_1.withTimeout)(simulation, timeout, 'Solana Simulation Timeout!');
|
|
60
55
|
return new bignumber_js_1.default(resp.value.unitsConsumed || exports.DEFAULT_CU_LIMIT).toFixed(0);
|
|
61
56
|
}
|
|
62
57
|
catch (err) {
|
|
@@ -139,7 +134,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
139
134
|
return accounts.filter((v) => !!v);
|
|
140
135
|
}
|
|
141
136
|
async createVersionedTransaction(instructions, walletAddress, addressLookupTableAccounts = []) {
|
|
142
|
-
const
|
|
137
|
+
const blockhash = await this.getLatestBlockhash();
|
|
143
138
|
const message = new web3_js_1.TransactionMessage({
|
|
144
139
|
instructions,
|
|
145
140
|
payerKey: new web3_js_1.PublicKey(walletAddress),
|
|
@@ -181,11 +176,53 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
181
176
|
return new web3_js_1.VersionedTransaction(newMsg);
|
|
182
177
|
}
|
|
183
178
|
deserializeTransaction(data) {
|
|
184
|
-
const decodedData = data.startsWith('0x') ? Buffer.from(data.slice(2), 'hex') :
|
|
179
|
+
const decodedData = data.startsWith('0x') ? Buffer.from(data.slice(2), 'hex') : js_base64_1.Base64.toUint8Array(data);
|
|
185
180
|
return web3_js_1.VersionedTransaction.deserialize(decodedData);
|
|
186
181
|
}
|
|
187
182
|
serializeTransactionToBase58(tx) {
|
|
188
183
|
return bs58_1.default.encode(tx.serialize());
|
|
189
184
|
}
|
|
185
|
+
async createTransferData(fromToken, walletAddress, receiver, convertToVersionedTx) {
|
|
186
|
+
const fromAddress = new web3_js_1.PublicKey(walletAddress);
|
|
187
|
+
const toAddress = new web3_js_1.PublicKey(receiver);
|
|
188
|
+
const transaction = fromToken.isNative
|
|
189
|
+
? this.createNativeTransfer(fromAddress, toAddress, fromToken.stringWeiAmount)
|
|
190
|
+
: await this.createTokenTransfer(fromAddress, toAddress, fromToken.address, fromToken.stringWeiAmount);
|
|
191
|
+
if (convertToVersionedTx) {
|
|
192
|
+
const blockhash = await this.getLatestBlockhash();
|
|
193
|
+
const message = new web3_js_1.TransactionMessage({
|
|
194
|
+
payerKey: fromAddress,
|
|
195
|
+
recentBlockhash: blockhash,
|
|
196
|
+
instructions: transaction.instructions
|
|
197
|
+
}).compileToV0Message();
|
|
198
|
+
return new web3_js_1.VersionedTransaction(message);
|
|
199
|
+
}
|
|
200
|
+
return transaction;
|
|
201
|
+
}
|
|
202
|
+
createNativeTransfer(fromAddress, toAddress, fromWeiAmount) {
|
|
203
|
+
return new web3_js_1.Transaction().add(web3_js_1.SystemProgram.transfer({
|
|
204
|
+
fromPubkey: fromAddress,
|
|
205
|
+
toPubkey: toAddress,
|
|
206
|
+
lamports: BigInt(fromWeiAmount)
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
async createTokenTransfer(fromAddress, toAddress, fromTokenAddress, fromWeiAmount) {
|
|
210
|
+
const mintTokenAccount = new web3_js_1.PublicKey(fromTokenAddress);
|
|
211
|
+
const [fromATA, toATA] = await Promise.all([
|
|
212
|
+
(0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, fromAddress),
|
|
213
|
+
(0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, toAddress)
|
|
214
|
+
]);
|
|
215
|
+
const transaction = new web3_js_1.Transaction();
|
|
216
|
+
const receiverAccountInfo = await this.public.getAccountInfo(toATA);
|
|
217
|
+
if (!receiverAccountInfo) {
|
|
218
|
+
transaction.add((0, spl_token_1.createAssociatedTokenAccountInstruction)(fromAddress, toATA, toAddress, mintTokenAccount));
|
|
219
|
+
}
|
|
220
|
+
transaction.add((0, spl_token_1.createTransferInstruction)(fromATA, toATA, fromAddress, BigInt(fromWeiAmount)));
|
|
221
|
+
return transaction;
|
|
222
|
+
}
|
|
223
|
+
async getLatestBlockhash() {
|
|
224
|
+
const { blockhash } = await this.public.getLatestBlockhash();
|
|
225
|
+
return blockhash;
|
|
226
|
+
}
|
|
190
227
|
}
|
|
191
228
|
exports.SolanaAdapter = SolanaAdapter;
|
|
@@ -8,6 +8,8 @@ const bignumber_js_1 = require("bignumber.js");
|
|
|
8
8
|
const abstract_adapter_1 = require("./abstract-adapter");
|
|
9
9
|
const web3_pure_1 = require("../../utils/web3-pure");
|
|
10
10
|
class TonAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
11
|
+
tonApi;
|
|
12
|
+
tonClient;
|
|
11
13
|
constructor(httpClient, config, logger) {
|
|
12
14
|
super(core_1.BLOCKCHAIN_NAME.TON, logger);
|
|
13
15
|
this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig);
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { AbstractAdapter } from './abstract-adapter';
|
|
3
|
-
import { ContractMulticallResponse, MethodData, TronWeb3PrimitiveType } from '@cryptorubic/tron-types';
|
|
4
3
|
import { TronWeb } from 'tronweb';
|
|
5
|
-
import { AbiFragment } from 'tronweb/lib/commonjs/types';
|
|
6
4
|
import { ICustomLogger, PriceTokenAmount, Token, TokenAmount, TronBlockchainName } from '@cryptorubic/core';
|
|
7
5
|
import { TronTransactionConfig } from '../../utils/models/tron-transaction-config';
|
|
8
6
|
import { TronParameters } from '../../utils/models/tron-parameters';
|
|
9
7
|
import { Abi } from 'viem';
|
|
10
8
|
import { ApproveAdapter } from './models/approve-adapter';
|
|
11
9
|
import { AllowanceInfo } from './models/common-types';
|
|
10
|
+
import { ContractMulticallResponse } from '../../utils/models/contract-multicall-response';
|
|
11
|
+
import { TronWeb3PrimitiveType } from '../../utils/models/primitive-types';
|
|
12
|
+
import { MethodData } from '../../utils/models/method-data';
|
|
12
13
|
export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> implements ApproveAdapter<TronTransactionConfig> {
|
|
13
14
|
private readonly multicallAddress;
|
|
14
15
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
15
16
|
constructor(rpcList: string[], logger?: ICustomLogger);
|
|
16
17
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
17
|
-
multicallContractsMethods<Output extends TronWeb3PrimitiveType>(contractAbi:
|
|
18
|
+
multicallContractsMethods<Output extends TronWeb3PrimitiveType>(contractAbi: any, contractsData: {
|
|
18
19
|
contractAddress: string;
|
|
19
20
|
methodsData: MethodData[];
|
|
20
|
-
}[]): Promise<ContractMulticallResponse<
|
|
21
|
+
}[]): Promise<ContractMulticallResponse<any>[][]>;
|
|
21
22
|
private multicall;
|
|
22
|
-
read<T>(contractAddress: string, contractAbi:
|
|
23
|
+
read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
23
24
|
private multicallContractsMethodsByOne;
|
|
24
25
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
25
26
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token[]>;
|
|
@@ -10,13 +10,13 @@ const core_1 = require("@cryptorubic/core");
|
|
|
10
10
|
const web3_pure_1 = require("../../utils/web3-pure");
|
|
11
11
|
const tron_web3_pure_1 = require("../../utils/web3-types/tron-web3-pure");
|
|
12
12
|
class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
13
|
+
multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
13
14
|
async needPreswapAction(token, contractAddress, walletAddress, amount) {
|
|
14
15
|
// return this.needApprove()
|
|
15
16
|
return false;
|
|
16
17
|
}
|
|
17
18
|
constructor(rpcList, logger) {
|
|
18
19
|
super(core_1.BLOCKCHAIN_NAME.TRON, logger);
|
|
19
|
-
this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
20
20
|
this.public = new tronweb_1.TronWeb({ fullHost: rpcList[0] });
|
|
21
21
|
}
|
|
22
22
|
async checkEnoughBalance(token, walletAddress) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
+
import { Connection } from '@solana/web3.js';
|
|
3
|
+
import { SolanaAdapterConfig } from '../../models/solana-adapter-config';
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
export declare class SolanaGasService {
|
|
6
|
+
private httpClient;
|
|
7
|
+
private readonly connection;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly HELIUS_API_URL;
|
|
10
|
+
private readonly HELIUS_API_KEY;
|
|
11
|
+
readonly DEFAULT_CU_LIMIT = 200000;
|
|
12
|
+
constructor(httpClient: HttpClient, connection: Connection, logger: ICustomLogger | undefined, solanaConfig: SolanaAdapterConfig);
|
|
13
|
+
/**
|
|
14
|
+
* @returns wei ComputedUnitsLimit - like gasLimit in evm
|
|
15
|
+
*/
|
|
16
|
+
getConsumedUnitsLimit(txData: string): Promise<BigNumber>;
|
|
17
|
+
/**
|
|
18
|
+
* @param txData base64 or hex string
|
|
19
|
+
* @returns prioritizationFee in micro-lamports (lamport = 1_000_000 microlamports)
|
|
20
|
+
*/
|
|
21
|
+
getPriorityFee(txData: string): Promise<BigNumber>;
|
|
22
|
+
/**
|
|
23
|
+
* @returns consumedUnitsPrice in micro-lamports(lamport * 10^-6)
|
|
24
|
+
*/
|
|
25
|
+
private calculatePriorityFeeHelius;
|
|
26
|
+
private getRecentPriorityFeeSolWeb3;
|
|
27
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaGasService = void 0;
|
|
4
|
+
const utils_1 = require("ethers/lib/utils");
|
|
5
|
+
const utility_funcs_1 = require("./utility-funcs");
|
|
6
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
7
|
+
// solana gas fee FORMULA: 200_000 CU * 0.02 Lamports/CU = 4000 Lamports = 0.000004 SOL
|
|
8
|
+
class SolanaGasService {
|
|
9
|
+
httpClient;
|
|
10
|
+
connection;
|
|
11
|
+
logger;
|
|
12
|
+
HELIUS_API_URL = 'https://mainnet.helius-rpc.com';
|
|
13
|
+
HELIUS_API_KEY;
|
|
14
|
+
DEFAULT_CU_LIMIT = 200_000; //in CU
|
|
15
|
+
constructor(httpClient, connection, logger, solanaConfig) {
|
|
16
|
+
this.httpClient = httpClient;
|
|
17
|
+
this.connection = connection;
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
this.HELIUS_API_KEY = solanaConfig.heliusApiKey;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns wei ComputedUnitsLimit - like gasLimit in evm
|
|
23
|
+
*/
|
|
24
|
+
async getConsumedUnitsLimit(txData) {
|
|
25
|
+
try {
|
|
26
|
+
const tx = (0, utility_funcs_1.convertB64DataToTx)(txData);
|
|
27
|
+
const resp = await this.connection.simulateTransaction(tx, {
|
|
28
|
+
replaceRecentBlockhash: true
|
|
29
|
+
});
|
|
30
|
+
return resp.value.unitsConsumed ? new bignumber_js_1.default(resp.value.unitsConsumed * 1.2) : new bignumber_js_1.default(this.DEFAULT_CU_LIMIT);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error('[SolanaApiService_getConsumedUnitsLimit] err ==> ', err);
|
|
34
|
+
return new bignumber_js_1.default(this.DEFAULT_CU_LIMIT);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @param txData base64 or hex string
|
|
39
|
+
* @returns prioritizationFee in micro-lamports (lamport = 1_000_000 microlamports)
|
|
40
|
+
*/
|
|
41
|
+
async getPriorityFee(txData) {
|
|
42
|
+
if (!this.HELIUS_API_KEY) {
|
|
43
|
+
console.warn('[SolanaApiService_getConsumedUnitsPrice] heliusApiKey is not provided in "createFactory"');
|
|
44
|
+
}
|
|
45
|
+
const resp = await Promise.allSettled([this.calculatePriorityFeeHelius(txData), this.getRecentPriorityFeeSolWeb3()]);
|
|
46
|
+
const cuPrice = resp
|
|
47
|
+
.filter((r) => r.status === 'fulfilled')
|
|
48
|
+
.map((r) => r.value)
|
|
49
|
+
.reduce((acc, price) => (acc.gt(price) ? acc : price), new bignumber_js_1.default(0));
|
|
50
|
+
return cuPrice;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @returns consumedUnitsPrice in micro-lamports(lamport * 10^-6)
|
|
54
|
+
*/
|
|
55
|
+
async calculatePriorityFeeHelius(txData) {
|
|
56
|
+
try {
|
|
57
|
+
const tx = (0, utility_funcs_1.convertB64DataToTx)(txData);
|
|
58
|
+
const resp = await this.httpClient.post(`${this.HELIUS_API_URL}/?api-key=${this.HELIUS_API_KEY}`, {
|
|
59
|
+
jsonrpc: '2.0',
|
|
60
|
+
id: '1',
|
|
61
|
+
method: 'getPriorityFeeEstimate',
|
|
62
|
+
params: [
|
|
63
|
+
{
|
|
64
|
+
transaction: utils_1.base58.encode(tx.serialize()), // Pass the serialized transaction in Base58
|
|
65
|
+
options: { priorityLevel: 'Medium' }
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
this.logger?.customLog('HELIUS PRIORITY_FEE SUCCESS', { priorityFeeEstimate: resp.result.priorityFeeEstimate });
|
|
70
|
+
return new bignumber_js_1.default(resp.result.priorityFeeEstimate);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
this.logger?.customLog('HELIUS PRIORITY_FEE ERROR', err);
|
|
74
|
+
return new bignumber_js_1.default(0);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async getRecentPriorityFeeSolWeb3() {
|
|
78
|
+
const BASE_FEE_MICROLAMPORTS = 5_000;
|
|
79
|
+
const lastSlot = await this.connection.getSlot();
|
|
80
|
+
// last slots array [1000, 1001, 1002 ...]
|
|
81
|
+
const last10Slots = Array.from({ length: 10 }, (_, idx) => lastSlot - idx).reverse();
|
|
82
|
+
const getPriorityFeesFromBlock = async (slotNum) => {
|
|
83
|
+
const block = await this.connection.getBlock(slotNum, { maxSupportedTransactionVersion: 0, commitment: 'confirmed' });
|
|
84
|
+
if (!block)
|
|
85
|
+
return [];
|
|
86
|
+
return block.transactions.map((tx) => (tx.meta && tx.meta.fee ? tx.meta.fee : BASE_FEE_MICROLAMPORTS));
|
|
87
|
+
};
|
|
88
|
+
const resp = await Promise.all(last10Slots.map((slotNum) => getPriorityFeesFromBlock(slotNum)));
|
|
89
|
+
const flattenPriorityFees = resp.flat();
|
|
90
|
+
const avgProrityFee = flattenPriorityFees
|
|
91
|
+
.reduce((acc, fee) => acc.plus(fee), new bignumber_js_1.default(0))
|
|
92
|
+
.div(flattenPriorityFees.length)
|
|
93
|
+
.dp(0, bignumber_js_1.default.ROUND_CEIL);
|
|
94
|
+
// const resp = await this.connection.getRecentPrioritizationFees();
|
|
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 });
|
|
103
|
+
return avgProrityFee;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.SolanaGasService = SolanaGasService;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { HttpClient } from '@cryptorubic/core';
|
|
3
|
-
import { SolanaToken } from '
|
|
3
|
+
import { SolanaToken } from '../../models/solana-web3-types';
|
|
4
4
|
export declare class SolanaTokensService {
|
|
5
5
|
private readonly httpClient;
|
|
6
6
|
private connection;
|
|
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SolanaTokensService = void 0;
|
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
|
5
5
|
const utl_sdk_1 = require("@solflare-wallet/utl-sdk");
|
|
6
|
-
const timeout_1 = require("
|
|
6
|
+
const timeout_1 = require("../timeout");
|
|
7
7
|
class SolanaTokensService {
|
|
8
|
+
httpClient;
|
|
9
|
+
connection;
|
|
10
|
+
// key - address of token, value - idx of token in initial tokensAddress
|
|
11
|
+
tokensOrder = {};
|
|
12
|
+
initialMints = [];
|
|
13
|
+
apiEndpoint = 'https://x-api.rubic.exchange/sol_token_list';
|
|
14
|
+
newTokensEndpoint = 'https://api.rubic.exchange/api/v2';
|
|
15
|
+
xApiKey = 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4';
|
|
8
16
|
constructor(connection, httpClient) {
|
|
9
17
|
this.httpClient = httpClient;
|
|
10
|
-
// key - address of token, value - idx of token in initial tokensAddress
|
|
11
|
-
this.tokensOrder = {};
|
|
12
|
-
this.initialMints = [];
|
|
13
|
-
this.apiEndpoint = 'https://x-api.rubic.exchange/sol_token_list';
|
|
14
|
-
this.newTokensEndpoint = 'https://api.rubic.exchange/api/v2';
|
|
15
|
-
this.xApiKey = 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4';
|
|
16
18
|
this.connection = connection;
|
|
17
19
|
}
|
|
18
20
|
async fetchTokensData(mints) {
|
|
@@ -57,7 +59,7 @@ class SolanaTokensService {
|
|
|
57
59
|
}
|
|
58
60
|
async fetchTokensFromOldBackend(mints, prevFetchedTokens) {
|
|
59
61
|
const tokensAddresses = mints.map((mint) => mint.toString());
|
|
60
|
-
const { content: tokensFromOlbBackend } = await (0, timeout_1.withTimeout)(this.getTokensListOld(tokensAddresses),
|
|
62
|
+
const { content: tokensFromOlbBackend } = await (0, timeout_1.withTimeout)(this.getTokensListOld(tokensAddresses), 3_000, 'Api Timeout!').catch(() => ({ content: [] }));
|
|
61
63
|
const notSortedTokensList = [...prevFetchedTokens, ...tokensFromOlbBackend];
|
|
62
64
|
const notFetchedMints = this.getNotFetchedTokensList(notSortedTokensList);
|
|
63
65
|
return {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertB64DataToTx = convertB64DataToTx;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
function convertB64DataToTx(txData) {
|
|
6
|
+
const bufferData = txData.startsWith('0x') ? Buffer.from(txData.slice(2), 'hex') : Buffer.from(txData, 'base64');
|
|
7
|
+
const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
|
|
8
|
+
return tx;
|
|
9
|
+
}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TonApiService = void 0;
|
|
4
4
|
class TonApiService {
|
|
5
|
+
httpClient;
|
|
6
|
+
tonApiUrl;
|
|
7
|
+
apiKey;
|
|
8
|
+
tonCenterV3Url;
|
|
5
9
|
constructor(httpClient, params) {
|
|
6
10
|
this.httpClient = httpClient;
|
|
7
11
|
this.apiKey = params.tonApiKey;
|
|
@@ -11,10 +11,13 @@ const evm_adapter_1 = require("./adapters/evm-adapter");
|
|
|
11
11
|
const bitcoin_adapter_1 = require("./adapters/bitcoin-adapter");
|
|
12
12
|
const sui_adapter_1 = require("./adapters/sui-adapter");
|
|
13
13
|
class BlockchainAdapterFactoryService {
|
|
14
|
+
rpcList;
|
|
15
|
+
params;
|
|
16
|
+
adapterStore = {};
|
|
17
|
+
logger;
|
|
14
18
|
constructor(rpcList, params) {
|
|
15
19
|
this.rpcList = rpcList;
|
|
16
20
|
this.params = params;
|
|
17
|
-
this.adapterStore = {};
|
|
18
21
|
this.adapterStore = this.createStorage();
|
|
19
22
|
if (this.params.createLogger) {
|
|
20
23
|
this.logger = this.params.createLogger('BlockchainAdapterFactory');
|
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CommonWeb3Pure = void 0;
|
|
4
4
|
const axios_1 = require("axios");
|
|
5
5
|
class CommonWeb3Pure {
|
|
6
|
+
nativeTokenAddress = '0x0000000000000000000000000000000000000000';
|
|
7
|
+
emptyAddress = '0x0000000000000000000000000000000000000000';
|
|
8
|
+
cnApiKey;
|
|
9
|
+
regEx;
|
|
6
10
|
constructor(commonParams) {
|
|
7
|
-
this.nativeTokenAddress = '0x0000000000000000000000000000000000000000';
|
|
8
|
-
this.emptyAddress = '0x0000000000000000000000000000000000000000';
|
|
9
11
|
this.cnApiKey = commonParams?.cnApiKey || undefined;
|
|
10
12
|
this.regEx = commonParams?.regex || undefined;
|
|
11
13
|
}
|
|
@@ -5,12 +5,12 @@ const changenow_api_blockchain_1 = require("../constants/changenow-api-blockchai
|
|
|
5
5
|
const common_web3_pure_1 = require("./common-web3-pure");
|
|
6
6
|
const core_1 = require("@cryptorubic/core");
|
|
7
7
|
class SolanaWeb3Pure extends common_web3_pure_1.CommonWeb3Pure {
|
|
8
|
+
nativeTokenAddress = 'So11111111111111111111111111111111111111111';
|
|
8
9
|
constructor() {
|
|
9
10
|
super({
|
|
10
11
|
cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.SOLANA,
|
|
11
12
|
regex: /^(?!.*([1-9A-HJ-NP-Za-km-z])\1{31,43}$)[1-9A-HJ-NP-Za-km-z]{32,44}$/
|
|
12
13
|
});
|
|
13
|
-
this.nativeTokenAddress = 'So11111111111111111111111111111111111111111';
|
|
14
14
|
}
|
|
15
15
|
async isAddressCorrect(address) {
|
|
16
16
|
if ((0, core_1.compareAddresses)(address, this.nativeTokenAddress)) {
|
|
@@ -5,6 +5,8 @@ const common_web3_pure_1 = require("./common-web3-pure");
|
|
|
5
5
|
const core_1 = require("@cryptorubic/core");
|
|
6
6
|
const bignumber_js_1 = require("bignumber.js");
|
|
7
7
|
class SuiWeb3Pure extends common_web3_pure_1.CommonWeb3Pure {
|
|
8
|
+
nativeTokenAddress = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI';
|
|
9
|
+
emptyAddress = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI';
|
|
8
10
|
static compareAddress(addressA, addressB) {
|
|
9
11
|
const pureAddressA = addressA.split(':')[0];
|
|
10
12
|
const pureAddressB = addressB.split(':')[0];
|
|
@@ -20,8 +22,6 @@ class SuiWeb3Pure extends common_web3_pure_1.CommonWeb3Pure {
|
|
|
20
22
|
super({
|
|
21
23
|
regex: /(^0[xX][a-fA-F0-9]{0,64}::[a-zA-Z0-9_]*::[A-Z0-9_]*$)|(^0[xX][a-fA-F0-9]{64}$)/
|
|
22
24
|
});
|
|
23
|
-
this.nativeTokenAddress = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI';
|
|
24
|
-
this.emptyAddress = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI';
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.SuiWeb3Pure = SuiWeb3Pure;
|
|
@@ -2,7 +2,6 @@ import { CommonWeb3Pure } from './common-web3-pure';
|
|
|
2
2
|
import { TronTransactionConfig } from '../models/tron-transaction-config';
|
|
3
3
|
import { TronParameters } from '../models/tron-parameters';
|
|
4
4
|
import { TronWeb3PrimitiveType, Web3PrimitiveType } from '../models/primitive-types';
|
|
5
|
-
import { FunctionFragment } from 'tronweb/src/types/ABI';
|
|
6
5
|
import { AbiItem } from '../models/abi-types';
|
|
7
6
|
export declare class TronWeb3Pure extends CommonWeb3Pure {
|
|
8
7
|
constructor();
|
|
@@ -16,7 +15,7 @@ export declare class TronWeb3Pure extends CommonWeb3Pure {
|
|
|
16
15
|
* @param methodArguments Parameters to encode.
|
|
17
16
|
* @returns An ABI encoded function call. Means function signature + parameters.
|
|
18
17
|
*/
|
|
19
|
-
static encodeFunctionCall(contractAbi:
|
|
18
|
+
static encodeFunctionCall(contractAbi: any[], methodName: string, methodArguments: unknown[]): string;
|
|
20
19
|
static encodeMethodSignature(methodSignature: string, parameters: TronParameters): string;
|
|
21
20
|
/**
|
|
22
21
|
* Decodes method result using its JSON interface object and given parameters.
|
|
@@ -24,7 +23,7 @@ export declare class TronWeb3Pure extends CommonWeb3Pure {
|
|
|
24
23
|
* @param response Bytes code returned after method call.
|
|
25
24
|
* @returns Parsed method output.
|
|
26
25
|
*/
|
|
27
|
-
static decodeMethodOutput(outputAbi:
|
|
26
|
+
static decodeMethodOutput(outputAbi: any[], response: string): Web3PrimitiveType;
|
|
28
27
|
private static flattenTypesToString;
|
|
29
28
|
private static flattenTypesToArray;
|
|
30
29
|
private static flattenParameters;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from '@cryptorubic/core';
|
|
2
|
-
import { Connection, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
-
import { SolanaAdapterConfig } from '../models/solana-adapter-config';
|
|
4
|
-
export declare class SolanaApiService {
|
|
5
|
-
private httpClient;
|
|
6
|
-
private readonly connection;
|
|
7
|
-
private readonly HELIUS_API_URL;
|
|
8
|
-
private readonly HELIUS_API_KEY;
|
|
9
|
-
constructor(httpClient: HttpClient, connection: Connection, solanaConfig: SolanaAdapterConfig);
|
|
10
|
-
/**
|
|
11
|
-
* @returns ComputedUnitsLimit - like gasLimit in evm
|
|
12
|
-
*/
|
|
13
|
-
getConsumedUnitsLimit(tx: VersionedTransaction): Promise<number>;
|
|
14
|
-
/**
|
|
15
|
-
* @returns ComputedUnitsPrice - like gasPrice in evm
|
|
16
|
-
*/
|
|
17
|
-
getConsumedUnitsPrice(tx: VersionedTransaction): Promise<number>;
|
|
18
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaApiService = void 0;
|
|
4
|
-
const utils_1 = require("ethers/lib/utils");
|
|
5
|
-
class SolanaApiService {
|
|
6
|
-
constructor(httpClient, connection, solanaConfig) {
|
|
7
|
-
this.httpClient = httpClient;
|
|
8
|
-
this.connection = connection;
|
|
9
|
-
this.HELIUS_API_URL = 'https://mainnet.helius-rpc.com';
|
|
10
|
-
this.HELIUS_API_KEY = solanaConfig.heliusApiKey;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @returns ComputedUnitsLimit - like gasLimit in evm
|
|
14
|
-
*/
|
|
15
|
-
async getConsumedUnitsLimit(tx) {
|
|
16
|
-
const DEFAULT_CU_LIMIT = 600000;
|
|
17
|
-
try {
|
|
18
|
-
const resp = await this.connection.simulateTransaction(tx, {
|
|
19
|
-
replaceRecentBlockhash: true
|
|
20
|
-
});
|
|
21
|
-
return resp.value.unitsConsumed ? resp.value.unitsConsumed * 1.2 : DEFAULT_CU_LIMIT;
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
console.error('Solana_simulateTransaction_Error ==> ', err);
|
|
25
|
-
return DEFAULT_CU_LIMIT;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @returns ComputedUnitsPrice - like gasPrice in evm
|
|
30
|
-
*/
|
|
31
|
-
async getConsumedUnitsPrice(tx) {
|
|
32
|
-
if (!this.HELIUS_API_KEY) {
|
|
33
|
-
throw new Error('[SolanaApiService_getConsumedUnitsPrice] params.solanaParams.heliusApiKey is not provided in "createFactory" method to use this method');
|
|
34
|
-
}
|
|
35
|
-
const resp = await this.httpClient.post(`${this.HELIUS_API_URL}/?api-key=${this.HELIUS_API_KEY}`, {
|
|
36
|
-
jsonrpc: '2.0',
|
|
37
|
-
id: '1',
|
|
38
|
-
method: 'getPriorityFeeEstimate',
|
|
39
|
-
params: [
|
|
40
|
-
{
|
|
41
|
-
transaction: utils_1.base58.encode(tx.serialize()), // Pass the serialized transaction in Base58
|
|
42
|
-
options: { priorityLevel: 'Medium' }
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
});
|
|
46
|
-
return resp.result.priorityFeeEstimate;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.SolanaApiService = SolanaApiService;
|