@cryptorubic/web3 0.8.16-alpha.1 → 0.8.17-alpha.solana.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/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptorubic/web3",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.17-alpha.solana.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.0",
|
|
6
6
|
"bignumber.js": "9.1.2",
|
|
7
|
-
"@cryptorubic/core": "0.8.
|
|
7
|
+
"@cryptorubic/core": "0.8.17-alpha.solana.1",
|
|
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.
|
|
14
|
+
"@cryptorubic/tron-types": "0.8.17-alpha.solana.1",
|
|
15
15
|
"bitcoin-address-validation": "^2.2.3",
|
|
16
16
|
"axios": "0.27.2",
|
|
17
17
|
"crc-32": "^1.2.2",
|
|
@@ -2,10 +2,11 @@ import { Abi, MulticallResponse, MulticallParameters } from 'viem';
|
|
|
2
2
|
import { AbstractAdapter } from './abstract-adapter';
|
|
3
3
|
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
4
4
|
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
5
|
-
import { EvmTransactionConfig } from '../../utils/models/evm-transaction-config';
|
|
6
5
|
import BigNumber from 'bignumber.js';
|
|
7
6
|
import { SolanaRawInstruction } from './models/solana-web3-types';
|
|
7
|
+
import { SolanaTxConfig } from '../../utils/models/solana-transaction-config';
|
|
8
8
|
export declare const NATIVE_SOLANA_MINT_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
9
|
+
export declare const DEFAULT_CU_LIMIT = 600000;
|
|
9
10
|
export declare class SolanaAdapter extends AbstractAdapter<Connection, Connection, SolanaBlockchainName> {
|
|
10
11
|
private readonly httpClient;
|
|
11
12
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger);
|
|
@@ -14,7 +15,7 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, Connectio
|
|
|
14
15
|
write<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
15
16
|
multicallByContract<T>(_contracts: MulticallParameters, _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
16
17
|
multicallByAddress<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[][], _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
17
|
-
simulateTransaction(
|
|
18
|
+
simulateTransaction(config: SolanaTxConfig, timeout?: number): Promise<string>;
|
|
18
19
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
19
20
|
getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
20
21
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaAdapter = exports.NATIVE_SOLANA_MINT_ADDRESS = void 0;
|
|
3
|
+
exports.SolanaAdapter = exports.DEFAULT_CU_LIMIT = exports.NATIVE_SOLANA_MINT_ADDRESS = void 0;
|
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
|
5
5
|
const abstract_adapter_1 = require("./abstract-adapter");
|
|
6
6
|
const web3_js_1 = require("@solana/web3.js");
|
|
@@ -11,6 +11,7 @@ const solana_tokens_service_1 = require("./utils/solana-tokens-service");
|
|
|
11
11
|
const bs58_1 = require("bs58");
|
|
12
12
|
const utils_1 = require("ethers/lib/utils");
|
|
13
13
|
exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
|
|
14
|
+
exports.DEFAULT_CU_LIMIT = 600000;
|
|
14
15
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
15
16
|
constructor(rpcList, httpClient, logger) {
|
|
16
17
|
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
@@ -38,7 +39,28 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
38
39
|
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
39
40
|
throw new Error('Method multicall is not supported');
|
|
40
41
|
}
|
|
41
|
-
async simulateTransaction(
|
|
42
|
+
async simulateTransaction(config, timeout = 15000) {
|
|
43
|
+
try {
|
|
44
|
+
const bufferData = config.data.startsWith('0x') ? Buffer.from(config.data.slice(2), 'hex') : Buffer.from(config.data, 'base64');
|
|
45
|
+
const { blockhash } = await this.public.getLatestBlockhash();
|
|
46
|
+
const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
|
|
47
|
+
tx.message.recentBlockhash = blockhash;
|
|
48
|
+
const simulation = this.public.simulateTransaction(tx, {
|
|
49
|
+
commitment: 'finalized',
|
|
50
|
+
replaceRecentBlockhash: false,
|
|
51
|
+
sigVerify: true,
|
|
52
|
+
accounts: { encoding: 'base64', addresses: [...Object.values(config.accounts)] }
|
|
53
|
+
});
|
|
54
|
+
const resp = await Promise.race([
|
|
55
|
+
simulation,
|
|
56
|
+
new Promise((_, reject) => setTimeout(() => reject('Timeout'), timeout))
|
|
57
|
+
]);
|
|
58
|
+
return new bignumber_js_1.default(resp.value.unitsConsumed || exports.DEFAULT_CU_LIMIT).toFixed(0);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
42
64
|
async checkEnoughBalance(token, walletAddress) {
|
|
43
65
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
44
66
|
return balance.gte(token.tokenAmount);
|