@cryptorubic/web3 1.0.0-alpha.no-sdk.30 → 1.0.0-alpha.no-sdk.32
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/adapter-bitcoin/bitcoin-adapter.d.ts +1 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.js +3 -0
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +5 -2
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.js +6 -2
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.js +4 -1
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.js +4 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.js +4 -0
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.js +5 -2
- package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +7 -0
- package/src/lib/adapter/adapters/common/abstract-adapter.js +3 -0
- package/src/lib/adapter/adapters/common/signer/abstract-adapter-signer.js +3 -3
- package/src/lib/adapter/blockchain-adapter-factory.service.js +5 -0
- package/src/lib/adapter/constants/viem-blockchain-mapping.js +0 -1
- package/src/lib/adapter/models/create-factory-params.d.ts +3 -0
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ export declare class BitcoinAdapter extends AbstractAdapter<BtcWallet, BtcWallet
|
|
|
15
15
|
readonly signer: BitcoinAdapterSigner;
|
|
16
16
|
get public(): BtcWallet;
|
|
17
17
|
constructor(httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
18
|
+
initWeb3Client(): void;
|
|
18
19
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
19
20
|
read<T>(args: unknown): Promise<T>;
|
|
20
21
|
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
@@ -15,6 +15,9 @@ class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
15
15
|
this.httpClient = httpClient;
|
|
16
16
|
this.signer = new bitcoin_adapter_signer_1.BitcoinAdapterSigner(httpClient, logger, clientParams);
|
|
17
17
|
}
|
|
18
|
+
initWeb3Client() {
|
|
19
|
+
super.public = null;
|
|
20
|
+
}
|
|
18
21
|
callContractMethod() {
|
|
19
22
|
throw new Error('Method not implemented.');
|
|
20
23
|
}
|
|
@@ -15,10 +15,13 @@ import { ApprovableAdapter } from '../models/approve-adapter';
|
|
|
15
15
|
import { AllowanceInfo } from '../models/common-types';
|
|
16
16
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
17
17
|
export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> implements ApprovableAdapter<EvmTransactionConfig> {
|
|
18
|
+
private readonly adapterOptions;
|
|
19
|
+
private readonly clientParams?;
|
|
18
20
|
readonly signer: EvmAdapterSigner;
|
|
19
21
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
20
22
|
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
21
|
-
constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
23
|
+
constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams | undefined);
|
|
24
|
+
initWeb3Client(): void;
|
|
22
25
|
callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[], options?: {
|
|
23
26
|
from?: string;
|
|
24
27
|
value?: string;
|
|
@@ -40,7 +43,7 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
|
|
|
40
43
|
blockNumber: number;
|
|
41
44
|
workchain: number;
|
|
42
45
|
}>;
|
|
43
|
-
|
|
46
|
+
private createPublicClient;
|
|
44
47
|
multicallByContract<T>(contracts: MulticallParameters, allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
45
48
|
multicallByAddress<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[][], allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
46
49
|
static encodeMethodCall(contractAddress: string, contractAbi: Abi, method: string, parameters?: unknown[], value?: string): EvmTransactionConfig;
|
|
@@ -31,9 +31,13 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
31
31
|
}
|
|
32
32
|
constructor(httpClient, adapterOptions, logger, clientParams) {
|
|
33
33
|
super(adapterOptions.blockchain, logger);
|
|
34
|
-
this.
|
|
34
|
+
this.adapterOptions = adapterOptions;
|
|
35
|
+
this.clientParams = clientParams;
|
|
35
36
|
this.signer = new evm_adapter_signer_1.EvmAdapterSigner(this.public, httpClient, logger, clientParams);
|
|
36
37
|
}
|
|
38
|
+
initWeb3Client() {
|
|
39
|
+
this.public = this.createPublicClient(this.adapterOptions.rpcList);
|
|
40
|
+
}
|
|
37
41
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = [], options = {}) {
|
|
38
42
|
return this.public.readContract({
|
|
39
43
|
abi: contractAbi,
|
|
@@ -134,7 +138,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
134
138
|
retryDelay: 100,
|
|
135
139
|
timeout: 5000
|
|
136
140
|
}));
|
|
137
|
-
const chain = viem_blockchain_mapping_1.viemBlockchainMapping[this.blockchain];
|
|
141
|
+
const chain = this.clientParams?.viemConfig?.[this.blockchain] || viem_blockchain_mapping_1.viemBlockchainMapping[this.blockchain];
|
|
138
142
|
return (0, viem_1.createPublicClient)({
|
|
139
143
|
// @ts-ignore
|
|
140
144
|
chain,
|
|
@@ -10,9 +10,11 @@ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
|
10
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
11
11
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
12
12
|
export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
|
|
13
|
+
private readonly rpcList;
|
|
13
14
|
private readonly httpClient;
|
|
14
15
|
readonly signer: SolanaAdapterSigner;
|
|
15
16
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
17
|
+
initWeb3Client(): void;
|
|
16
18
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
17
19
|
read<T>(): Promise<T>;
|
|
18
20
|
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
@@ -15,10 +15,13 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
|
15
15
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
16
16
|
constructor(rpcList, httpClient, logger, clientParams) {
|
|
17
17
|
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
18
|
+
this.rpcList = rpcList;
|
|
18
19
|
this.httpClient = httpClient;
|
|
19
|
-
this.public = this.createConection(rpcList);
|
|
20
20
|
this.signer = new solana_adapter_signer_1.SolanaAdapterSigner(this.public, httpClient, logger, clientParams);
|
|
21
21
|
}
|
|
22
|
+
initWeb3Client() {
|
|
23
|
+
this.public = this.createConection(this.rpcList);
|
|
24
|
+
}
|
|
22
25
|
async callContractMethod() {
|
|
23
26
|
throw new Error('Method call is not supported');
|
|
24
27
|
}
|
|
@@ -10,8 +10,10 @@ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
|
10
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
11
11
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
12
12
|
export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter, SuiBlockchainName> {
|
|
13
|
+
private readonly rpcList;
|
|
13
14
|
readonly signer: SuiAdapterSigner;
|
|
14
15
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
16
|
+
initWeb3Client(): void;
|
|
15
17
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
16
18
|
read<T>(): Promise<T>;
|
|
17
19
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
@@ -11,9 +11,13 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
|
11
11
|
class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
12
12
|
constructor(rpcList, httpClient, logger, clientParams) {
|
|
13
13
|
super(core_1.BLOCKCHAIN_NAME.SUI, logger);
|
|
14
|
+
this.rpcList = rpcList;
|
|
14
15
|
this.public = new client_1.SuiClient({ url: rpcList[0] });
|
|
15
16
|
this.signer = new sui_adapter_signer_1.SuiAdapterSigner(this.public, httpClient, logger, clientParams);
|
|
16
17
|
}
|
|
18
|
+
initWeb3Client() {
|
|
19
|
+
this.public = new client_1.SuiClient({ url: this.rpcList[0] });
|
|
20
|
+
}
|
|
17
21
|
async callContractMethod() {
|
|
18
22
|
throw new Error('Method call is not supported');
|
|
19
23
|
}
|
|
@@ -11,9 +11,11 @@ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
|
11
11
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
12
12
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
13
13
|
export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI, TonBlockchainName> {
|
|
14
|
+
private readonly config;
|
|
14
15
|
readonly signer: TonAdapterSigner;
|
|
15
16
|
private readonly tonApi;
|
|
16
17
|
constructor(httpClient: HttpClient, config: TonAdapterConfig, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
18
|
+
initWeb3Client(): void;
|
|
17
19
|
read<T>(): Promise<T>;
|
|
18
20
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
19
21
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
@@ -12,10 +12,14 @@ const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
|
12
12
|
class TonAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
13
13
|
constructor(httpClient, config, logger, clientParams) {
|
|
14
14
|
super(core_1.BLOCKCHAIN_NAME.TON, logger);
|
|
15
|
+
this.config = config;
|
|
15
16
|
this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig, logger);
|
|
16
17
|
this.public = new ton_1.TonClient(config.tonClientConfig);
|
|
17
18
|
this.signer = new ton_adapter_signer_1.TonAdapterSigner(this.tonApi, this.public, httpClient, logger, clientParams);
|
|
18
19
|
}
|
|
20
|
+
initWeb3Client() {
|
|
21
|
+
this.public = new ton_1.TonClient(this.config.tonClientConfig);
|
|
22
|
+
}
|
|
19
23
|
async read() {
|
|
20
24
|
throw new Error('Method read is not supported');
|
|
21
25
|
}
|
|
@@ -15,12 +15,14 @@ import { AllowanceInfo } from '../models/common-types';
|
|
|
15
15
|
import { ApprovableAdapter } from '../models/approve-adapter';
|
|
16
16
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
17
17
|
export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> implements ApprovableAdapter<TronTransactionConfig> {
|
|
18
|
+
private readonly rpcList;
|
|
18
19
|
readonly signer: TronAdapterSigner;
|
|
19
20
|
private readonly multicallAddress;
|
|
20
21
|
needPreswapAction(): Promise<boolean>;
|
|
21
22
|
constructor(rpcList: (string | {
|
|
22
23
|
fullHost: string;
|
|
23
24
|
})[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
25
|
+
initWeb3Client(): void;
|
|
24
26
|
callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
25
27
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
26
28
|
/**
|
|
@@ -19,11 +19,14 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
19
19
|
}
|
|
20
20
|
constructor(rpcList, httpClient, logger, clientParams) {
|
|
21
21
|
super(core_1.BLOCKCHAIN_NAME.TRON, logger);
|
|
22
|
+
this.rpcList = rpcList;
|
|
22
23
|
this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
23
|
-
const rpc = typeof rpcList[0] === 'string' ? rpcList[0] : rpcList[0].fullHost;
|
|
24
|
-
this.public = new tronweb_1.TronWeb({ fullHost: rpc });
|
|
25
24
|
this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.public, httpClient, logger, clientParams);
|
|
26
25
|
}
|
|
26
|
+
initWeb3Client() {
|
|
27
|
+
const rpc = typeof this.rpcList[0] === 'string' ? this.rpcList[0] : this.rpcList[0].fullHost;
|
|
28
|
+
this.public = new tronweb_1.TronWeb({ fullHost: rpc });
|
|
29
|
+
}
|
|
27
30
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
28
31
|
this.public.setAddress(contractAddress);
|
|
29
32
|
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
@@ -13,7 +13,14 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, Se
|
|
|
13
13
|
private _public;
|
|
14
14
|
protected set public(value: P | null);
|
|
15
15
|
get public(): P;
|
|
16
|
+
get connected(): boolean;
|
|
16
17
|
protected constructor(blockchain: B, logger?: ICustomLogger);
|
|
18
|
+
/**
|
|
19
|
+
* Used to set this.public property, if it's not set - you can't send rpc requests to blockchain.
|
|
20
|
+
* Mostly you need to instantiate it at the same time as BlockchainAdapterFactoryService.createAdapter() called.
|
|
21
|
+
* In rubic-app it's called on wallet connection to prevent unnecessary rpc requests `net_listening` from viem library.
|
|
22
|
+
*/
|
|
23
|
+
abstract initWeb3Client(): void;
|
|
17
24
|
/**
|
|
18
25
|
* Gets account native or token balance in wei.
|
|
19
26
|
* @param userAddress Wallet address, whose balance you want to find out.
|
|
@@ -5,9 +5,9 @@ const rubic_api_link_mapping_1 = require("../../../constants/rubic-api-link-mapp
|
|
|
5
5
|
const wrong_network_error_1 = require("../../../../errors/swap/wrong-network.error");
|
|
6
6
|
class AbstractAdapterSigner {
|
|
7
7
|
get apiUrl() {
|
|
8
|
-
if (!this.clientParams) {
|
|
9
|
-
this.logger?.customError('clientParams is not set for apiUrl call.');
|
|
10
|
-
throw new Error('clientParams is not set for apiUrl call.');
|
|
8
|
+
if (!this.clientParams?.envType) {
|
|
9
|
+
this.logger?.customError('clientParams.envType is not set for apiUrl call.');
|
|
10
|
+
throw new Error('clientParams.envType is not set for apiUrl call.');
|
|
11
11
|
}
|
|
12
12
|
const rubicApiLink = rubic_api_link_mapping_1.rubicApiLinkMapping[this.clientParams.envType];
|
|
13
13
|
return rubicApiLink ? rubicApiLink : 'https://dev1-api-v2.rubic.exchange';
|
|
@@ -55,6 +55,9 @@ class BlockchainAdapterFactoryService {
|
|
|
55
55
|
});
|
|
56
56
|
const store = Object.fromEntries(activeAdapters);
|
|
57
57
|
this.logger?.customLog('Adapters store created');
|
|
58
|
+
if (!this.clientParams?.lazyLoadWeb3) {
|
|
59
|
+
Object.values(store).forEach((adapter) => adapter.initWeb3Client());
|
|
60
|
+
}
|
|
58
61
|
return store;
|
|
59
62
|
}
|
|
60
63
|
createAdapter(blockchain, rpcs) {
|
|
@@ -90,6 +93,8 @@ class BlockchainAdapterFactoryService {
|
|
|
90
93
|
const adapter = this.adapterStore[blockchain];
|
|
91
94
|
adapter.signer.setWalletAddress(wallet.address);
|
|
92
95
|
adapter.signer.setWallet(wallet.core);
|
|
96
|
+
if (!adapter.connected)
|
|
97
|
+
adapter.initWeb3Client();
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
exports.BlockchainAdapterFactoryService = BlockchainAdapterFactoryService;
|
|
@@ -73,7 +73,6 @@ exports.viemBlockchainMapping = {
|
|
|
73
73
|
[core_1.BLOCKCHAIN_NAME.CORE]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.CORE],
|
|
74
74
|
[core_1.BLOCKCHAIN_NAME.BERACHAIN]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.BERACHAIN],
|
|
75
75
|
[core_1.BLOCKCHAIN_NAME.SONEIUM]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.SONEIUM],
|
|
76
|
-
[core_1.BLOCKCHAIN_NAME.WANCHAIN]: chains_1.wanchain,
|
|
77
76
|
[core_1.BLOCKCHAIN_NAME.UNICHAIN]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.UNICHAIN],
|
|
78
77
|
[core_1.BLOCKCHAIN_NAME.MORPH]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.MORPH], // viem Morph config without multicall address
|
|
79
78
|
[core_1.BLOCKCHAIN_NAME.HEMI]: chain_configs_1.viemConfig[core_1.BLOCKCHAIN_NAME.HEMI],
|
|
@@ -2,6 +2,7 @@ import { EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName, Sui
|
|
|
2
2
|
import { EnvType } from '../constants/models/env-type';
|
|
3
3
|
import { TronWebProvider } from '../adapters/adapter-tron/models/tron-web-provider';
|
|
4
4
|
import { TonAdapterConfig } from '../adapters/models/ton-adapter-config';
|
|
5
|
+
import { ViemChain } from '../constants/models/viem-chain-type';
|
|
5
6
|
export type RpcListType = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<SuiBlockchainName, string[]>;
|
|
6
7
|
export interface AdapterFactoryParams {
|
|
7
8
|
rpcList: RpcListType;
|
|
@@ -12,4 +13,6 @@ export interface AdapterFactoryParams {
|
|
|
12
13
|
}
|
|
13
14
|
export interface ClientAdaptersFactoryParams {
|
|
14
15
|
envType: EnvType;
|
|
16
|
+
viemConfig?: Partial<Record<EvmBlockchainName, ViemChain>>;
|
|
17
|
+
lazyLoadWeb3?: boolean;
|
|
15
18
|
}
|