@cryptorubic/web3 1.0.0-alpha.no-sdk.7 → 1.0.0-alpha.no-sdk.9
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/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +2 -4
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.js +2 -8
- package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.d.ts +4 -2
- package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.js +8 -2
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.d.ts +8 -6
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.js +45 -13
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +2 -5
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.js +4 -35
- package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.d.ts +4 -2
- package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.js +8 -2
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +2 -5
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.js +2 -8
- package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.d.ts +4 -2
- package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.js +8 -2
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +2 -4
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.js +2 -8
- package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.d.ts +4 -2
- package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.js +8 -2
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +2 -4
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.js +2 -8
- package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.d.ts +6 -4
- package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.js +25 -12
- package/src/lib/adapter/adapters/adapter-tron/models/tron-web-provider.d.ts +4 -0
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +2 -4
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.js +3 -15
- package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +0 -2
- package/src/lib/adapter/adapters/common/client/abstract-adapter-client.d.ts +5 -3
- package/src/lib/adapter/adapters/common/client/abstract-adapter-client.js +6 -6
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +4 -5
- package/src/lib/adapter/blockchain-adapter-factory.service.js +12 -12
- package/src/lib/adapter/models/create-factory-params.d.ts +15 -0
- package/src/lib/adapter/models/create-factory-params.js +2 -0
- package/src/lib/adapter/constants/models/create-factory-params.d.ts +0 -8
- /package/src/lib/adapter/{constants/models/create-factory-params.js → adapters/adapter-tron/models/tron-web-provider.js} +0 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export * from './lib/adapter/adapters/utils/timeout';
|
|
|
66
66
|
export * from './lib/adapter/adapters/utils/waitFor';
|
|
67
67
|
export * from './lib/adapter/blockchain-adapter-factory.service';
|
|
68
68
|
export * from './lib/adapter/constants/chain-configs/chain-configs';
|
|
69
|
-
export * from './lib/adapter/
|
|
69
|
+
export * from './lib/adapter/models/create-factory-params';
|
|
70
70
|
export * from './lib/adapter/constants/models/env-type';
|
|
71
71
|
export * from './lib/adapter/constants/models/solana-web3';
|
|
72
72
|
export * from './lib/adapter/constants/models/viem-chain-type';
|
package/src/index.js
CHANGED
|
@@ -69,7 +69,7 @@ tslib_1.__exportStar(require("./lib/adapter/adapters/utils/timeout"), exports);
|
|
|
69
69
|
tslib_1.__exportStar(require("./lib/adapter/adapters/utils/waitFor"), exports);
|
|
70
70
|
tslib_1.__exportStar(require("./lib/adapter/blockchain-adapter-factory.service"), exports);
|
|
71
71
|
tslib_1.__exportStar(require("./lib/adapter/constants/chain-configs/chain-configs"), exports);
|
|
72
|
-
tslib_1.__exportStar(require("./lib/adapter/
|
|
72
|
+
tslib_1.__exportStar(require("./lib/adapter/models/create-factory-params"), exports);
|
|
73
73
|
tslib_1.__exportStar(require("./lib/adapter/constants/models/env-type"), exports);
|
|
74
74
|
tslib_1.__exportStar(require("./lib/adapter/constants/models/solana-web3"), exports);
|
|
75
75
|
tslib_1.__exportStar(require("./lib/adapter/constants/models/viem-chain-type"), exports);
|
|
@@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js';
|
|
|
3
3
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
4
4
|
import { BtcWallet } from '../models/btc-wallet-provider';
|
|
5
5
|
import { BasicSendTransactionOptions } from '../models/basic-transaction-options';
|
|
6
|
-
import {
|
|
6
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
7
7
|
import { BitcoinAdapterClient } from './client/bitcoin-adapter-client';
|
|
8
8
|
import { Abi } from 'viem';
|
|
9
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
@@ -12,7 +12,7 @@ import { MethodData } from '../models/web3-public-models/method-data';
|
|
|
12
12
|
export declare class BitcoinAdapter extends AbstractAdapter<BtcWallet, BtcWallet, BitcoinBlockchainName> {
|
|
13
13
|
private readonly httpClient;
|
|
14
14
|
readonly client: BitcoinAdapterClient;
|
|
15
|
-
constructor(httpClient: HttpClient, logger?: ICustomLogger,
|
|
15
|
+
constructor(httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
16
16
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
17
17
|
getBalance(userAddress: string): Promise<BigNumber>;
|
|
18
18
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
@@ -27,8 +27,6 @@ export declare class BitcoinAdapter extends AbstractAdapter<BtcWallet, BtcWallet
|
|
|
27
27
|
getPublicKey(userAddress: string): Promise<string | null>;
|
|
28
28
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
29
29
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
30
|
-
read<T>(args: unknown): Promise<T>;
|
|
31
|
-
write(args: unknown): Promise<string>;
|
|
32
30
|
getPublicKeyFromWallet(): Promise<string>;
|
|
33
31
|
transfer(recipient: string, amount: string, fromAddress: string, memo?: string, options?: BasicSendTransactionOptions): Promise<string>;
|
|
34
32
|
sendPsbtTransaction(psbt: string, userAddress: string, inputIndexes: number[], options?: BasicSendTransactionOptions): Promise<string>;
|
|
@@ -6,10 +6,10 @@ const bignumber_js_1 = require("bignumber.js");
|
|
|
6
6
|
const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
7
7
|
const bitcoin_adapter_client_1 = require("./client/bitcoin-adapter-client");
|
|
8
8
|
class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
9
|
-
constructor(httpClient, logger,
|
|
9
|
+
constructor(httpClient, logger, clientParams) {
|
|
10
10
|
super(core_1.BLOCKCHAIN_NAME.BITCOIN, logger);
|
|
11
11
|
this.httpClient = httpClient;
|
|
12
|
-
this.client = new bitcoin_adapter_client_1.BitcoinAdapterClient(httpClient, logger,
|
|
12
|
+
this.client = new bitcoin_adapter_client_1.BitcoinAdapterClient(httpClient, logger, clientParams);
|
|
13
13
|
}
|
|
14
14
|
callContractMethod() {
|
|
15
15
|
throw new Error('Method not implemented.');
|
|
@@ -61,12 +61,6 @@ class BitcoinAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
61
61
|
async callForTokensInfo(tokenAddresses) {
|
|
62
62
|
return [core_1.nativeTokensList[core_1.BLOCKCHAIN_NAME.BITCOIN]];
|
|
63
63
|
}
|
|
64
|
-
read(args) {
|
|
65
|
-
throw new Error('Not implemented');
|
|
66
|
-
}
|
|
67
|
-
write(args) {
|
|
68
|
-
throw new Error('Not implemented');
|
|
69
|
-
}
|
|
70
64
|
async getPublicKeyFromWallet() {
|
|
71
65
|
const res = await this.client.clientWallet.request({
|
|
72
66
|
method: 'request_accounts_and_keys',
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
3
3
|
import { BitconSendTxParams } from '../models/btc-send-tx-params';
|
|
4
4
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
5
5
|
import { BtcWallet } from '../../models/btc-wallet-provider';
|
|
6
6
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
7
7
|
export declare class BitcoinAdapterClient extends AbstractAdapterClient<BtcWallet, BitconSendTxParams, string> {
|
|
8
|
-
constructor(httpClient: HttpClient, logger?: ICustomLogger,
|
|
8
|
+
constructor(httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
9
|
+
read<T>(args: unknown): Promise<T>;
|
|
10
|
+
write(args: unknown): Promise<string>;
|
|
9
11
|
getBlockchainName(): Promise<BlockchainName>;
|
|
10
12
|
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
11
13
|
sendTransaction(params: BitconSendTxParams): Promise<string>;
|
|
@@ -6,8 +6,14 @@ const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-
|
|
|
6
6
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
7
7
|
const waitFor_1 = require("../../utils/waitFor");
|
|
8
8
|
class BitcoinAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
9
|
-
constructor(httpClient, logger,
|
|
10
|
-
super(httpClient, logger,
|
|
9
|
+
constructor(httpClient, logger, clientParams) {
|
|
10
|
+
super(httpClient, logger, clientParams);
|
|
11
|
+
}
|
|
12
|
+
read(args) {
|
|
13
|
+
throw new Error('Not implemented');
|
|
14
|
+
}
|
|
15
|
+
write(args) {
|
|
16
|
+
throw new Error('Not implemented');
|
|
11
17
|
}
|
|
12
18
|
getBlockchainName() {
|
|
13
19
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.BITCOIN);
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger, TokenAmount } from '@cryptorubic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
3
3
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
4
|
-
import { Abi, TransactionReceipt, WalletActions, WalletClient } from 'viem';
|
|
4
|
+
import { Abi, PublicActions, PublicClient, TransactionReceipt, WalletActions, WalletClient } from 'viem';
|
|
5
5
|
import { EvmSendTxParams, EvmTransactionOptions } from '../models/evm-send-tx-params';
|
|
6
6
|
import BigNumber from 'bignumber.js';
|
|
7
7
|
import { Web3Error } from '../utils/parse-evm-error';
|
|
8
8
|
import { EvmTransactionConfig } from 'packages/web3/src/lib/utils/models/evm-transaction-config';
|
|
9
|
-
import { EvmAdapter } from '../evm-adapter';
|
|
10
9
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
11
10
|
import { ApproveAdapterClient } from '../../models/approve-adapter';
|
|
12
11
|
import { AllowanceInfo } from '../../models/common-types';
|
|
13
12
|
export declare class EvmAdapterClient extends AbstractAdapterClient<WalletClient & WalletActions, EvmSendTxParams, TransactionReceipt> implements ApproveAdapterClient<EvmTransactionConfig> {
|
|
14
|
-
private readonly
|
|
15
|
-
constructor(
|
|
13
|
+
private readonly evmPublic;
|
|
14
|
+
constructor(evmPublic: PublicActions & PublicClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
16
15
|
getBlockchainName(): Promise<BlockchainName | undefined>;
|
|
17
16
|
getAllowance(fromTokenAddress: string, walletAddress: string, spenderAddress: string): Promise<AllowanceInfo>;
|
|
18
17
|
needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
@@ -21,7 +20,7 @@ export declare class EvmAdapterClient extends AbstractAdapterClient<WalletClient
|
|
|
21
20
|
* Build encoded approve transaction config.
|
|
22
21
|
* @param tokenAddress Address of the smart-contract corresponding to the token.
|
|
23
22
|
* @param spenderAddress Wallet or contract address to approve.
|
|
24
|
-
* @param amount
|
|
23
|
+
* @param amount wei amount of tokens in approval window in spending cap field
|
|
25
24
|
* @returns Encoded approve transaction config.
|
|
26
25
|
*/
|
|
27
26
|
encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig;
|
|
@@ -77,4 +76,7 @@ export declare class EvmAdapterClient extends AbstractAdapterClient<WalletClient
|
|
|
77
76
|
private shouldIgnoreError;
|
|
78
77
|
signMessage(message: string): Promise<string>;
|
|
79
78
|
private getChainAndAccount;
|
|
79
|
+
read<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[]): Promise<T>;
|
|
80
|
+
writeContract(address: string, abi: Abi, method: string, value?: string, methodArgs?: unknown[]): Promise<string>;
|
|
81
|
+
write(address: string, to: string, value: string, data: string): Promise<string>;
|
|
80
82
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EvmAdapterClient = void 0;
|
|
4
4
|
const core_1 = require("@cryptorubic/core");
|
|
5
5
|
const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const waitForTransactionReceipt_1 = require("viem/_types/actions/public/waitForTransactionReceipt");
|
|
7
8
|
const options_1 = require("../../utils/options");
|
|
8
9
|
const viem_blockchain_mapping_1 = require("../../../constants/viem-blockchain-mapping");
|
|
@@ -14,9 +15,9 @@ const rubic_sdk_error_1 = require("packages/web3/src/lib/errors/rubic-sdk.error"
|
|
|
14
15
|
const evm_adapter_1 = require("../evm-adapter");
|
|
15
16
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
16
17
|
class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
17
|
-
constructor(
|
|
18
|
-
super(httpClient, logger,
|
|
19
|
-
this.
|
|
18
|
+
constructor(evmPublic, httpClient, logger, clientParams) {
|
|
19
|
+
super(httpClient, logger, clientParams);
|
|
20
|
+
this.evmPublic = evmPublic;
|
|
20
21
|
}
|
|
21
22
|
async getBlockchainName() {
|
|
22
23
|
const userChainId = await this.clientWallet.getChainId();
|
|
@@ -24,8 +25,8 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
24
25
|
}
|
|
25
26
|
async getAllowance(fromTokenAddress, walletAddress, spenderAddress) {
|
|
26
27
|
const [decimals, allowance] = await Promise.all([
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
28
|
+
this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'decimals'),
|
|
29
|
+
this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'allowance', [walletAddress, spenderAddress])
|
|
29
30
|
]);
|
|
30
31
|
const allowanceWeiBN = new bignumber_js_1.default(allowance);
|
|
31
32
|
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
@@ -43,13 +44,13 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
43
44
|
}
|
|
44
45
|
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
45
46
|
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
46
|
-
return this.
|
|
47
|
+
return this.write(fromAddress, config.to, config.value, config.data);
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* Build encoded approve transaction config.
|
|
50
51
|
* @param tokenAddress Address of the smart-contract corresponding to the token.
|
|
51
52
|
* @param spenderAddress Wallet or contract address to approve.
|
|
52
|
-
* @param amount
|
|
53
|
+
* @param amount wei amount of tokens in approval window in spending cap field
|
|
53
54
|
* @returns Encoded approve transaction config.
|
|
54
55
|
*/
|
|
55
56
|
encodeApprove(tokenAddress, spenderAddress, amount) {
|
|
@@ -62,7 +63,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
async needPermit2Approve(token, permit2Address, walletAddress, spenderAddress) {
|
|
65
|
-
const res = await this.
|
|
66
|
+
const res = await this.read(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'allowance', [
|
|
66
67
|
walletAddress,
|
|
67
68
|
token.address,
|
|
68
69
|
spenderAddress
|
|
@@ -96,7 +97,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
96
97
|
* @param hash Transaction hash
|
|
97
98
|
*/
|
|
98
99
|
async getTransactionReceipt(hash) {
|
|
99
|
-
return this.
|
|
100
|
+
return this.evmPublic.getTransactionReceipt({ hash: hash });
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
103
|
* Sends Eth in transaction and resolve the promise when the transaction is included in the block.
|
|
@@ -144,7 +145,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
144
145
|
value,
|
|
145
146
|
...(params.txOptions.data && { data: params.txOptions.data })
|
|
146
147
|
};
|
|
147
|
-
const gas = await this.
|
|
148
|
+
const gas = await this.evmPublic.estimateGas(gaslessParams);
|
|
148
149
|
const gasfulParams = {
|
|
149
150
|
...gaslessParams,
|
|
150
151
|
...(0, options_1.getGasOptions)(params.txOptions),
|
|
@@ -156,7 +157,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
156
157
|
gas
|
|
157
158
|
};
|
|
158
159
|
try {
|
|
159
|
-
await this.
|
|
160
|
+
await this.evmPublic.estimateGas(gasfulViemParams);
|
|
160
161
|
}
|
|
161
162
|
catch {
|
|
162
163
|
throw new rubic_sdk_error_1.RubicSdkError('Low native value');
|
|
@@ -237,7 +238,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
237
238
|
}),
|
|
238
239
|
account: this.walletAddress
|
|
239
240
|
};
|
|
240
|
-
const gas = await this.
|
|
241
|
+
const gas = await this.evmPublic.estimateContractGas(gaslessParams);
|
|
241
242
|
const gasfulParams = {
|
|
242
243
|
...gaslessParams,
|
|
243
244
|
...(0, options_1.getGasOptions)(options),
|
|
@@ -249,7 +250,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
249
250
|
gas
|
|
250
251
|
};
|
|
251
252
|
try {
|
|
252
|
-
await this.
|
|
253
|
+
await this.evmPublic.estimateContractGas(gasfulViemParams);
|
|
253
254
|
}
|
|
254
255
|
catch {
|
|
255
256
|
throw new rubic_sdk_error_1.RubicSdkError('Low native value');
|
|
@@ -305,5 +306,36 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
305
306
|
}
|
|
306
307
|
return { account, chain };
|
|
307
308
|
}
|
|
309
|
+
async read(address, abi, method, methodArgs = []) {
|
|
310
|
+
const result = await this.evmPublic.readContract({
|
|
311
|
+
abi,
|
|
312
|
+
address: address,
|
|
313
|
+
args: methodArgs,
|
|
314
|
+
functionName: method
|
|
315
|
+
});
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
async writeContract(address, abi, method, value = '0', methodArgs = []) {
|
|
319
|
+
const result = await this.clientWallet.writeContract({
|
|
320
|
+
abi,
|
|
321
|
+
address: address,
|
|
322
|
+
account: address,
|
|
323
|
+
args: methodArgs,
|
|
324
|
+
functionName: method,
|
|
325
|
+
chain: this.evmPublic.chain,
|
|
326
|
+
value: (0, viem_1.parseEther)(value)
|
|
327
|
+
});
|
|
328
|
+
return result;
|
|
329
|
+
}
|
|
330
|
+
async write(address, to, value, data) {
|
|
331
|
+
const result = await this.clientWallet.sendTransaction({
|
|
332
|
+
account: address,
|
|
333
|
+
to: to,
|
|
334
|
+
value: (0, viem_1.parseEther)(value),
|
|
335
|
+
data: data,
|
|
336
|
+
chain: this.evmPublic.chain
|
|
337
|
+
});
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
308
340
|
}
|
|
309
341
|
exports.EvmAdapterClient = EvmAdapterClient;
|
|
@@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js';
|
|
|
5
5
|
import { EvmAdapterOptions } from '../models/evm-adapter-options';
|
|
6
6
|
import { EvmTransactionConfig } from '../../../utils/models/evm-transaction-config';
|
|
7
7
|
import { EvmAdapterClient } from './client/evm-adapter-client';
|
|
8
|
-
import {
|
|
8
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
9
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
10
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
11
11
|
import { MethodData } from '../models/web3-public-models/method-data';
|
|
@@ -14,7 +14,7 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
|
|
|
14
14
|
readonly client: EvmAdapterClient;
|
|
15
15
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
16
16
|
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
17
|
-
constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger,
|
|
17
|
+
constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
18
18
|
callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[], options?: {
|
|
19
19
|
from?: string;
|
|
20
20
|
value?: string;
|
|
@@ -31,9 +31,6 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
|
|
|
31
31
|
workchain: number;
|
|
32
32
|
}>;
|
|
33
33
|
protected createPublicClient(rpcList: string[]): (PublicActions & PublicClient) | null;
|
|
34
|
-
read<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[]): Promise<T>;
|
|
35
|
-
writeContract(address: string, abi: Abi, method: string, value?: string, methodArgs?: unknown[]): Promise<string>;
|
|
36
|
-
write(address: string, to: string, value: string, data: string): Promise<string>;
|
|
37
34
|
multicallByContract<T>(contracts: MulticallParameters, allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
38
35
|
multicallByAddress<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[][], allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
39
36
|
static encodeMethodCall(contractAddress: string, contractAbi: Abi, method: string, parameters?: unknown[], value?: string): EvmTransactionConfig;
|
|
@@ -23,12 +23,12 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
23
23
|
const fromTokenAddress = isNative && tokenAmount.blockchain === core_1.BLOCKCHAIN_NAME.METIS
|
|
24
24
|
? '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'
|
|
25
25
|
: tokenAmount.blockchain;
|
|
26
|
-
await this.writeContract(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', '0', [approveAmount]);
|
|
26
|
+
await this.client.writeContract(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', '0', [approveAmount]);
|
|
27
27
|
}
|
|
28
|
-
constructor(httpClient, adapterOptions, logger,
|
|
28
|
+
constructor(httpClient, adapterOptions, logger, clientParams) {
|
|
29
29
|
super(adapterOptions.blockchain, logger);
|
|
30
30
|
this.public = this.createPublicClient(adapterOptions.rpcList);
|
|
31
|
-
this.client = new evm_adapter_client_1.EvmAdapterClient(this, httpClient, logger,
|
|
31
|
+
this.client = new evm_adapter_client_1.EvmAdapterClient(this.public, httpClient, logger, clientParams);
|
|
32
32
|
}
|
|
33
33
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = [], options = {}) {
|
|
34
34
|
return this.public.readContract({
|
|
@@ -124,37 +124,6 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
124
124
|
})
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
async read(address, abi, method, methodArgs = []) {
|
|
128
|
-
const result = await this.public.readContract({
|
|
129
|
-
abi,
|
|
130
|
-
address: address,
|
|
131
|
-
args: methodArgs,
|
|
132
|
-
functionName: method
|
|
133
|
-
});
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
async writeContract(address, abi, method, value = '0', methodArgs = []) {
|
|
137
|
-
const result = await this.client.clientWallet.writeContract({
|
|
138
|
-
abi,
|
|
139
|
-
address: address,
|
|
140
|
-
account: address,
|
|
141
|
-
args: methodArgs,
|
|
142
|
-
functionName: method,
|
|
143
|
-
chain: this.public.chain,
|
|
144
|
-
value: (0, viem_1.parseEther)(value)
|
|
145
|
-
});
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
async write(address, to, value, data) {
|
|
149
|
-
const result = await this.client.clientWallet.sendTransaction({
|
|
150
|
-
account: address,
|
|
151
|
-
to: to,
|
|
152
|
-
value: (0, viem_1.parseEther)(value),
|
|
153
|
-
data: data,
|
|
154
|
-
chain: this.public.chain
|
|
155
|
-
});
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
127
|
async multicallByContract(contracts, allowErrors = true) {
|
|
159
128
|
const results = await this.public.multicall(contracts);
|
|
160
129
|
const rpcRequestFail = results.every((result) => result?.status === 'failure');
|
|
@@ -295,7 +264,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
295
264
|
});
|
|
296
265
|
return new bignumber_js_1.default(nativeBalance.toString());
|
|
297
266
|
}
|
|
298
|
-
const tokenBalance = await this.read(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'balanceOf', [walletAddress]);
|
|
267
|
+
const tokenBalance = await this.client.read(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'balanceOf', [walletAddress]);
|
|
299
268
|
return new bignumber_js_1.default(tokenBalance);
|
|
300
269
|
}
|
|
301
270
|
async getTransactionCount(walletAddress) {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
2
|
import { SolanaWeb3 } from '../../../constants/models/solana-web3';
|
|
3
|
-
import {
|
|
3
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
4
4
|
import { SolanaSendTxParams } from '../models/solana-send-tx-params';
|
|
5
5
|
import { Connection } from '@solana/web3.js';
|
|
6
6
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
7
7
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
8
8
|
export declare class SolanaAdapterClient extends AbstractAdapterClient<SolanaWeb3, SolanaSendTxParams, string> {
|
|
9
9
|
private readonly connection;
|
|
10
|
-
constructor(connection: Connection, httpClient: HttpClient, logger?: ICustomLogger,
|
|
10
|
+
constructor(connection: Connection, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
11
|
+
read<T>(): Promise<T>;
|
|
12
|
+
write<T>(): Promise<T>;
|
|
11
13
|
getBlockchainName(): Promise<BlockchainName>;
|
|
12
14
|
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
13
15
|
sendTransaction(params: SolanaSendTxParams): Promise<string>;
|
|
@@ -11,10 +11,16 @@ const errors_1 = require("../../utils/errors");
|
|
|
11
11
|
const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
|
|
12
12
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
13
13
|
class SolanaAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
14
|
-
constructor(connection, httpClient, logger,
|
|
15
|
-
super(httpClient, logger,
|
|
14
|
+
constructor(connection, httpClient, logger, clientParams) {
|
|
15
|
+
super(httpClient, logger, clientParams);
|
|
16
16
|
this.connection = connection;
|
|
17
17
|
}
|
|
18
|
+
async read() {
|
|
19
|
+
throw new Error('Method read is not supported');
|
|
20
|
+
}
|
|
21
|
+
async write() {
|
|
22
|
+
throw new Error('Method write is not supported');
|
|
23
|
+
}
|
|
18
24
|
getBlockchainName() {
|
|
19
25
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.SOLANA);
|
|
20
26
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Abi } from 'viem';
|
|
2
1
|
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
3
2
|
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
4
3
|
import BigNumber from 'bignumber.js';
|
|
5
4
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
5
|
import { SolanaRawInstruction } from '../models/solana-web3-types';
|
|
7
|
-
import {
|
|
6
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
8
7
|
import { SolanaWeb3 } from '../../constants/models/solana-web3';
|
|
9
8
|
import { SolanaAdapterClient } from './client/solana-adapter-client';
|
|
10
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
@@ -13,7 +12,7 @@ export declare const NATIVE_SOLANA_MINT_ADDRESS = "So111111111111111111111111111
|
|
|
13
12
|
export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
|
|
14
13
|
private readonly httpClient;
|
|
15
14
|
readonly client: SolanaAdapterClient;
|
|
16
|
-
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger,
|
|
15
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
17
16
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
18
17
|
/**
|
|
19
18
|
* Gets balance of multiple tokens.
|
|
@@ -27,8 +26,6 @@ export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb
|
|
|
27
26
|
workchain: number;
|
|
28
27
|
}>;
|
|
29
28
|
private createConection;
|
|
30
|
-
read<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
31
|
-
write<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
32
29
|
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
33
30
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
34
31
|
getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
@@ -13,11 +13,11 @@ const solana_tokens_service_1 = require("./services/solana-tokens-service");
|
|
|
13
13
|
const solana_adapter_client_1 = require("./client/solana-adapter-client");
|
|
14
14
|
exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
|
|
15
15
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
16
|
-
constructor(rpcList, httpClient, logger,
|
|
16
|
+
constructor(rpcList, httpClient, logger, clientParams) {
|
|
17
17
|
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
18
18
|
this.httpClient = httpClient;
|
|
19
19
|
this.public = this.createConection(rpcList);
|
|
20
|
-
this.client = new solana_adapter_client_1.SolanaAdapterClient(this.public, httpClient, logger,
|
|
20
|
+
this.client = new solana_adapter_client_1.SolanaAdapterClient(this.public, httpClient, logger, clientParams);
|
|
21
21
|
}
|
|
22
22
|
async callContractMethod() {
|
|
23
23
|
throw new Error('Method call is not supported');
|
|
@@ -57,12 +57,6 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
57
57
|
return new web3_js_1.Connection(rpcList[0], 'confirmed');
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
async read(_address, _abi, _method, _methodArgs = []) {
|
|
61
|
-
throw new Error('Method multicall is not supported');
|
|
62
|
-
}
|
|
63
|
-
async write(_address, _abi, _method, _methodArgs = []) {
|
|
64
|
-
throw new Error('Method multicall is not supported');
|
|
65
|
-
}
|
|
66
60
|
async simulateTransaction(_config, _from) { }
|
|
67
61
|
async checkEnoughBalance(token, walletAddress) {
|
|
68
62
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
2
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
3
|
-
import {
|
|
3
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
4
4
|
import { SuiSendTxParams } from '../models/sui-send-tx-params';
|
|
5
5
|
import { WalletAdapter } from '@suiet/wallet-sdk';
|
|
6
6
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
7
7
|
import { ExecuteTransactionBlockParams, SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/dist/cjs/client';
|
|
8
8
|
export declare class SuiAdapterClient extends AbstractAdapterClient<WalletAdapter, SuiSendTxParams, string> {
|
|
9
9
|
private readonly suiClient;
|
|
10
|
-
constructor(suiClient: SuiClient, httpClient: HttpClient, logger?: ICustomLogger,
|
|
10
|
+
constructor(suiClient: SuiClient, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
11
|
+
read<T>(): Promise<T>;
|
|
12
|
+
write<T>(): Promise<T>;
|
|
11
13
|
getBlockchainName(): Promise<BlockchainName>;
|
|
12
14
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
13
15
|
sendTransaction(params: SuiSendTxParams): Promise<string>;
|
|
@@ -7,10 +7,16 @@ const user_reject_error_1 = require("packages/web3/src/lib/errors/blockchain/use
|
|
|
7
7
|
const parse_evm_error_1 = require("../../adapter-evm/utils/parse-evm-error");
|
|
8
8
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
9
9
|
class SuiAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
10
|
-
constructor(suiClient, httpClient, logger,
|
|
11
|
-
super(httpClient, logger,
|
|
10
|
+
constructor(suiClient, httpClient, logger, clientParams) {
|
|
11
|
+
super(httpClient, logger, clientParams);
|
|
12
12
|
this.suiClient = suiClient;
|
|
13
13
|
}
|
|
14
|
+
async read() {
|
|
15
|
+
throw new Error('Method read is not supported');
|
|
16
|
+
}
|
|
17
|
+
async write() {
|
|
18
|
+
throw new Error('Method write is not supported');
|
|
19
|
+
}
|
|
14
20
|
getBlockchainName() {
|
|
15
21
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.SUI);
|
|
16
22
|
}
|
|
@@ -5,12 +5,12 @@ import BigNumber from 'bignumber.js';
|
|
|
5
5
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
6
|
import { WalletAdapter } from '@suiet/wallet-sdk';
|
|
7
7
|
import { SuiAdapterClient } from './client/sui-adapter-client';
|
|
8
|
-
import {
|
|
8
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
9
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
10
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
11
11
|
export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter, SuiBlockchainName> {
|
|
12
12
|
readonly client: SuiAdapterClient;
|
|
13
|
-
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger,
|
|
13
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
14
14
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
15
15
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
16
16
|
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
@@ -18,8 +18,6 @@ export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter
|
|
|
18
18
|
blockNumber: number;
|
|
19
19
|
workchain: number;
|
|
20
20
|
}>;
|
|
21
|
-
read<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
22
|
-
write<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
23
21
|
multicallByAddress<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[][], _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
24
22
|
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
25
23
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<SuiBlockchainName>[]>;
|
|
@@ -8,10 +8,10 @@ const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
|
8
8
|
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
9
9
|
const sui_adapter_client_1 = require("./client/sui-adapter-client");
|
|
10
10
|
class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
11
|
-
constructor(rpcList, httpClient, logger,
|
|
11
|
+
constructor(rpcList, httpClient, logger, clientParams) {
|
|
12
12
|
super(core_1.BLOCKCHAIN_NAME.SUI, logger);
|
|
13
13
|
this.public = new client_1.SuiClient({ url: rpcList[0] });
|
|
14
|
-
this.client = new sui_adapter_client_1.SuiAdapterClient(this.public, httpClient, logger,
|
|
14
|
+
this.client = new sui_adapter_client_1.SuiAdapterClient(this.public, httpClient, logger, clientParams);
|
|
15
15
|
}
|
|
16
16
|
async callContractMethod() {
|
|
17
17
|
throw new Error('Method call is not supported');
|
|
@@ -31,12 +31,6 @@ class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
31
31
|
const stringEpoch = epochInfo.data[0].epoch;
|
|
32
32
|
return Number(stringEpoch);
|
|
33
33
|
}
|
|
34
|
-
async read(_address, _abi, _method, _methodArgs = []) {
|
|
35
|
-
throw new Error('Method read is not supported');
|
|
36
|
-
}
|
|
37
|
-
async write(_address, _abi, _method, _methodArgs = []) {
|
|
38
|
-
throw new Error('Method write is not supported');
|
|
39
|
-
}
|
|
40
34
|
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
41
35
|
throw new Error('Method multicall is not supported');
|
|
42
36
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
2
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
3
|
-
import {
|
|
3
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
4
4
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
5
5
|
import { TonSendTxParams } from '../models/ton-send-tx-params';
|
|
6
6
|
import { TonConnectUI } from '@tonconnect/ui';
|
|
@@ -12,7 +12,9 @@ import { TonTransactionConfig } from 'packages/web3/src/lib/utils/models/ton-tra
|
|
|
12
12
|
export declare class TonAdapterClient extends AbstractAdapterClient<TonConnectUI, TonSendTxParams, string> {
|
|
13
13
|
private readonly tonApi;
|
|
14
14
|
private readonly tonClient;
|
|
15
|
-
constructor(tonApi: TonApiService, config: TonAdapterConfig, httpClient: HttpClient, logger?: ICustomLogger,
|
|
15
|
+
constructor(tonApi: TonApiService, config: TonAdapterConfig, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
16
|
+
read<T>(): Promise<T>;
|
|
17
|
+
write<T>(): Promise<T>;
|
|
16
18
|
getBlockchainName(): Promise<BlockchainName>;
|
|
17
19
|
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
18
20
|
sendTransaction(params: TonSendTxParams): Promise<string>;
|
|
@@ -11,11 +11,17 @@ const core_2 = require("@ton/core");
|
|
|
11
11
|
const waitFor_1 = require("../../utils/waitFor");
|
|
12
12
|
const ton_1 = require("@ton/ton");
|
|
13
13
|
class TonAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
14
|
-
constructor(tonApi, config, httpClient, logger,
|
|
15
|
-
super(httpClient, logger,
|
|
14
|
+
constructor(tonApi, config, httpClient, logger, clientParams) {
|
|
15
|
+
super(httpClient, logger, clientParams);
|
|
16
16
|
this.tonApi = tonApi;
|
|
17
17
|
this.tonClient = new ton_1.TonClient(config.tonClientConfig);
|
|
18
18
|
}
|
|
19
|
+
async read() {
|
|
20
|
+
throw new Error('Method read is not supported');
|
|
21
|
+
}
|
|
22
|
+
async write() {
|
|
23
|
+
throw new Error('Method write is not supported');
|
|
24
|
+
}
|
|
19
25
|
getBlockchainName() {
|
|
20
26
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.TON);
|
|
21
27
|
}
|
|
@@ -6,13 +6,13 @@ import BigNumber from 'bignumber.js';
|
|
|
6
6
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
7
7
|
import { TonConnectUI } from '@tonconnect/ui';
|
|
8
8
|
import { TonAdapterClient } from './client/ton-adapter-client';
|
|
9
|
-
import {
|
|
9
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
10
10
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
11
11
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
12
12
|
export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI, TonBlockchainName> {
|
|
13
13
|
readonly client: TonAdapterClient;
|
|
14
14
|
private readonly tonApi;
|
|
15
|
-
constructor(httpClient: HttpClient, config: TonAdapterConfig, logger?: ICustomLogger,
|
|
15
|
+
constructor(httpClient: HttpClient, config: TonAdapterConfig, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
16
16
|
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
17
17
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
18
18
|
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
@@ -21,8 +21,6 @@ export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI,
|
|
|
21
21
|
workchain: number;
|
|
22
22
|
}>;
|
|
23
23
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
24
|
-
read<T>(args: unknown): Promise<T>;
|
|
25
|
-
write(args: unknown): Promise<string>;
|
|
26
24
|
getAllFormatsOfAddress(walletAddress: string): Promise<TonApiParseAddressResp>;
|
|
27
25
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
28
26
|
getBalance(walletAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
@@ -9,10 +9,10 @@ const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
|
9
9
|
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
10
10
|
const ton_adapter_client_1 = require("./client/ton-adapter-client");
|
|
11
11
|
class TonAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
12
|
-
constructor(httpClient, config, logger,
|
|
12
|
+
constructor(httpClient, config, logger, clientParams) {
|
|
13
13
|
super(core_1.BLOCKCHAIN_NAME.TON, logger);
|
|
14
14
|
this.tonApi = new ton_api_service_1.TonApiService(httpClient, config.tonApiConfig, logger);
|
|
15
|
-
this.client = new ton_adapter_client_1.TonAdapterClient(this.tonApi, config, httpClient, logger,
|
|
15
|
+
this.client = new ton_adapter_client_1.TonAdapterClient(this.tonApi, config, httpClient, logger, clientParams);
|
|
16
16
|
}
|
|
17
17
|
async callContractMethod() {
|
|
18
18
|
throw new Error('Method call is not supported');
|
|
@@ -70,12 +70,6 @@ class TonAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
70
70
|
}));
|
|
71
71
|
return necessaryInfo;
|
|
72
72
|
}
|
|
73
|
-
read(args) {
|
|
74
|
-
throw new Error('Not implemented');
|
|
75
|
-
}
|
|
76
|
-
write(args) {
|
|
77
|
-
throw new Error('Not implemented');
|
|
78
|
-
}
|
|
79
73
|
async getAllFormatsOfAddress(walletAddress) {
|
|
80
74
|
return this.tonApi.getAllFormatsOfAddress(walletAddress);
|
|
81
75
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { TronWeb } from 'tronweb';
|
|
2
2
|
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
3
3
|
import { BlockchainName, HttpClient, ICustomLogger, TokenAmount } from '@cryptorubic/core';
|
|
4
|
-
import {
|
|
4
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
5
5
|
import { TronSendTxParams } from '../models/tron-send-tx-params';
|
|
6
6
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
7
7
|
import { TronTransactionConfig } from 'packages/web3/src/lib/utils/models/tron-transaction-config';
|
|
8
|
-
import { TronAdapter } from '../tron-adapter';
|
|
9
8
|
import { ApproveAdapterClient } from '../../models/approve-adapter';
|
|
10
9
|
import { AllowanceInfo } from '../../models/common-types';
|
|
10
|
+
import { TronParameters } from 'packages/web3/src/lib/utils/models/tron-parameters';
|
|
11
11
|
export declare class TronAdapterClient extends AbstractAdapterClient<TronWeb, TronSendTxParams, string> implements ApproveAdapterClient<TronTransactionConfig> {
|
|
12
|
-
private readonly
|
|
13
|
-
constructor(
|
|
12
|
+
private readonly tronWeb;
|
|
13
|
+
constructor(tronWeb: TronWeb, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
14
|
+
read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
15
|
+
write(contractAddress: string, methodSignature: string, parameters: TronParameters): Promise<string>;
|
|
14
16
|
getBlockchainName(): Promise<BlockchainName>;
|
|
15
17
|
getAllowance(fromTokenAddress: string, walletAddress: string, spender: string): Promise<AllowanceInfo>;
|
|
16
18
|
needApprove(from: TokenAmount, walletAddress: string, spender: string): Promise<boolean>;
|
|
@@ -8,19 +8,32 @@ const trc_20_contract_abi_1 = require("../../constants/trc-20-contract-abi");
|
|
|
8
8
|
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
9
9
|
const parse_tron_error_1 = require("../utils/parse-tron-error");
|
|
10
10
|
const tron_adapter_1 = require("../tron-adapter");
|
|
11
|
+
const tron_web3_pure_1 = require("packages/web3/src/lib/utils/web3-types/tron-web3-pure");
|
|
11
12
|
class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
12
|
-
constructor(
|
|
13
|
-
super(httpClient, logger,
|
|
14
|
-
this.
|
|
13
|
+
constructor(tronWeb, httpClient, logger, clientParams) {
|
|
14
|
+
super(httpClient, logger, clientParams);
|
|
15
|
+
this.tronWeb = tronWeb;
|
|
16
|
+
}
|
|
17
|
+
async read(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
18
|
+
this.tronWeb.setAddress(contractAddress);
|
|
19
|
+
const contract = await this.tronWeb.contract(contractAbi, contractAddress);
|
|
20
|
+
const response = await contract[methodName](...methodArguments).call();
|
|
21
|
+
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
22
|
+
}
|
|
23
|
+
async write(contractAddress, methodSignature, parameters) {
|
|
24
|
+
const transaction = await this.clientWallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.walletAddress);
|
|
25
|
+
const signedTransaction = await this.clientWallet.trx.sign(transaction.transaction);
|
|
26
|
+
const receipt = await this.clientWallet.trx.sendRawTransaction(signedTransaction);
|
|
27
|
+
return receipt.transaction.txID;
|
|
15
28
|
}
|
|
16
29
|
getBlockchainName() {
|
|
17
30
|
return Promise.resolve(core_1.BLOCKCHAIN_NAME.TRON);
|
|
18
31
|
}
|
|
19
32
|
async getAllowance(fromTokenAddress, walletAddress, spender) {
|
|
20
33
|
const [contract, decimals, allowance] = await Promise.all([
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
34
|
+
this.tronWeb.contract(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, fromTokenAddress),
|
|
35
|
+
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'decimals'),
|
|
36
|
+
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'allowance', [spender])
|
|
24
37
|
]);
|
|
25
38
|
const allowanceWeiBN = new bignumber_js_1.default(allowance);
|
|
26
39
|
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
@@ -34,7 +47,7 @@ class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient
|
|
|
34
47
|
}
|
|
35
48
|
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
36
49
|
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
37
|
-
return this.
|
|
50
|
+
return this.write(config.to, config.signature, config.arguments);
|
|
38
51
|
}
|
|
39
52
|
encodeApprove(tokenAddress, spenderAddress, amount) {
|
|
40
53
|
const amountWei = amount ?? new bignumber_js_1.default(2).pow(256).minus(1).toFixed();
|
|
@@ -58,13 +71,13 @@ class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient
|
|
|
58
71
|
* @param hash Transaction hash.
|
|
59
72
|
*/
|
|
60
73
|
async getTransactionInfo(hash) {
|
|
61
|
-
return this.
|
|
74
|
+
return this.tronWeb.trx.getTransactionInfo(hash);
|
|
62
75
|
}
|
|
63
76
|
async sendTransaction(params) {
|
|
64
77
|
try {
|
|
65
|
-
const transaction = await this.
|
|
66
|
-
const signedTransaction = await this.
|
|
67
|
-
const receipt = await this.
|
|
78
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerSmartContract(params.contractAddress, params.methodSignature, params.txOptions, params.parameters, this.walletAddress);
|
|
79
|
+
const signedTransaction = await this.tronWeb.trx.sign(transaction.transaction);
|
|
80
|
+
const receipt = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
|
|
68
81
|
if (params.txOptions.onTransactionHash) {
|
|
69
82
|
params.txOptions.onTransactionHash(receipt.transaction.txID);
|
|
70
83
|
}
|
|
@@ -77,7 +90,7 @@ class TronAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient
|
|
|
77
90
|
}
|
|
78
91
|
async trySendTransaction(params) {
|
|
79
92
|
try {
|
|
80
|
-
await this.
|
|
93
|
+
await this.tronWeb.transactionBuilder.estimateEnergy(params.contractAddress, params.methodSignature, {}, params.parameters, this.walletAddress);
|
|
81
94
|
}
|
|
82
95
|
catch (err) {
|
|
83
96
|
const errMessage = typeof err === 'object' ? err.message : err;
|
|
@@ -8,13 +8,13 @@ import { Abi } from 'viem';
|
|
|
8
8
|
import { ContractMulticallResponse } from '../../../utils/models/contract-multicall-response';
|
|
9
9
|
import { TronWeb3PrimitiveType, Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
10
10
|
import { MethodData } from '../../../utils/models/method-data';
|
|
11
|
-
import {
|
|
11
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
12
12
|
import { TronAdapterClient } from './client/tron-adapter-client';
|
|
13
13
|
export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> {
|
|
14
14
|
readonly client: TronAdapterClient;
|
|
15
15
|
private readonly multicallAddress;
|
|
16
16
|
needPreswapAction(): Promise<boolean>;
|
|
17
|
-
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger,
|
|
17
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
18
18
|
callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
19
19
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
20
20
|
multicallContractsMethods<Output extends TronWeb3PrimitiveType>(contractAbi: any, contractsData: {
|
|
@@ -27,7 +27,6 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
|
|
|
27
27
|
}>;
|
|
28
28
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
29
29
|
private multicall;
|
|
30
|
-
read<T>(contractAddress: string, contractAbi: any, methodName: string, methodArguments?: unknown[]): Promise<T>;
|
|
31
30
|
private multicallContractsMethodsByOne;
|
|
32
31
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token[]>;
|
|
33
32
|
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
@@ -35,5 +34,4 @@ export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronB
|
|
|
35
34
|
convertTronAddressToHex(address: string): Promise<string>;
|
|
36
35
|
static encodeMethodCall(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments: TronParameters, callValue?: string, feeLimit?: number): TronTransactionConfig;
|
|
37
36
|
private static flattenTypesToString;
|
|
38
|
-
write(contractAddress: string, methodSignature: string, parameters: TronParameters): Promise<string>;
|
|
39
37
|
}
|
|
@@ -14,11 +14,11 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
14
14
|
async needPreswapAction() {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
-
constructor(rpcList, httpClient, logger,
|
|
17
|
+
constructor(rpcList, httpClient, logger, clientParams) {
|
|
18
18
|
super(core_1.BLOCKCHAIN_NAME.TRON, logger);
|
|
19
19
|
this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
20
20
|
this.public = new tronweb_1.TronWeb({ fullHost: rpcList[0] });
|
|
21
|
-
this.client = new tron_adapter_client_1.TronAdapterClient(this, httpClient, logger,
|
|
21
|
+
this.client = new tron_adapter_client_1.TronAdapterClient(this.public, httpClient, logger, clientParams);
|
|
22
22
|
}
|
|
23
23
|
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
24
24
|
this.public.setAddress(contractAddress);
|
|
@@ -94,17 +94,11 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
94
94
|
// @ts-ignore
|
|
95
95
|
return contract.aggregateViewCalls(calls).call();
|
|
96
96
|
}
|
|
97
|
-
async read(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
98
|
-
this.public.setAddress(contractAddress);
|
|
99
|
-
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
100
|
-
const response = await contract[methodName](...methodArguments).call();
|
|
101
|
-
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
102
|
-
}
|
|
103
97
|
multicallContractsMethodsByOne(contractAbi, contractsData) {
|
|
104
98
|
return Promise.all(contractsData.map((contractData) => {
|
|
105
99
|
return Promise.all(contractData.methodsData.map(async (methodData) => {
|
|
106
100
|
try {
|
|
107
|
-
const output = (await this.read(contractData.contractAddress, contractAbi, methodData.methodName, methodData.methodArguments));
|
|
101
|
+
const output = (await this.client.read(contractData.contractAddress, contractAbi, methodData.methodName, methodData.methodArguments));
|
|
108
102
|
return {
|
|
109
103
|
output,
|
|
110
104
|
success: true
|
|
@@ -205,11 +199,5 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
205
199
|
return abiInput.type;
|
|
206
200
|
}) || []);
|
|
207
201
|
}
|
|
208
|
-
async write(contractAddress, methodSignature, parameters) {
|
|
209
|
-
const transaction = await this.client.clientWallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.client.walletAddress);
|
|
210
|
-
const signedTransaction = await this.client.clientWallet.trx.sign(transaction.transaction);
|
|
211
|
-
const receipt = await this.client.clientWallet.trx.sendRawTransaction(signedTransaction);
|
|
212
|
-
return receipt.transaction.txID;
|
|
213
|
-
}
|
|
214
202
|
}
|
|
215
203
|
exports.TronAdapter = TronAdapter;
|
|
@@ -57,7 +57,5 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, Se
|
|
|
57
57
|
}>;
|
|
58
58
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string | BigNumber): Promise<boolean>;
|
|
59
59
|
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
60
|
-
abstract read<T>(...args: unknown[]): Promise<T>;
|
|
61
|
-
abstract write(...args: unknown[]): Promise<string>;
|
|
62
60
|
static getRandomBytes(bytes: number): string;
|
|
63
61
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
3
3
|
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
4
4
|
export declare abstract class AbstractAdapterClient<ClientWallet, SendTxParams, SendTxResponse> {
|
|
5
5
|
protected readonly httpClient: HttpClient;
|
|
6
6
|
protected readonly logger?: ICustomLogger | undefined;
|
|
7
|
-
protected readonly
|
|
7
|
+
protected readonly clientParams?: ClientAdaptersFactoryParams | undefined;
|
|
8
8
|
protected get apiUrl(): string;
|
|
9
9
|
private _walletAddress;
|
|
10
10
|
get walletAddress(): string;
|
|
11
11
|
private _clientWallet;
|
|
12
12
|
get clientWallet(): ClientWallet;
|
|
13
|
-
constructor(httpClient: HttpClient, logger?: ICustomLogger | undefined,
|
|
13
|
+
constructor(httpClient: HttpClient, logger?: ICustomLogger | undefined, clientParams?: ClientAdaptersFactoryParams | undefined);
|
|
14
14
|
abstract getBlockchainName(): Promise<BlockchainName | undefined>;
|
|
15
15
|
abstract sendTransaction(params: SendTxParams): Promise<SendTxResponse>;
|
|
16
16
|
abstract getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
17
|
+
abstract read<T>(...args: unknown[]): Promise<T>;
|
|
18
|
+
abstract write(...args: unknown[]): Promise<string>;
|
|
17
19
|
/**
|
|
18
20
|
* Checks, that selected blockchain in wallet is equal to passed blockchain.
|
|
19
21
|
*/
|
|
@@ -8,11 +8,11 @@ const waitFor_1 = require("../../utils/waitFor");
|
|
|
8
8
|
const wrong_network_error_1 = require("../../../../errors/swap/wrong-network.error");
|
|
9
9
|
class AbstractAdapterClient {
|
|
10
10
|
get apiUrl() {
|
|
11
|
-
if (!this.
|
|
12
|
-
this.logger?.customError('
|
|
13
|
-
throw new Error('
|
|
11
|
+
if (!this.clientParams) {
|
|
12
|
+
this.logger?.customError('clientParams is not set for apiUrl call.');
|
|
13
|
+
throw new Error('clientParams is not set for apiUrl call.');
|
|
14
14
|
}
|
|
15
|
-
const rubicApiLink = rubic_api_link_mapping_1.rubicApiLinkMapping[this.
|
|
15
|
+
const rubicApiLink = rubic_api_link_mapping_1.rubicApiLinkMapping[this.clientParams.envType];
|
|
16
16
|
return rubicApiLink ? rubicApiLink : 'https://dev1-api-v2.rubic.exchange';
|
|
17
17
|
}
|
|
18
18
|
get walletAddress() {
|
|
@@ -21,10 +21,10 @@ class AbstractAdapterClient {
|
|
|
21
21
|
get clientWallet() {
|
|
22
22
|
return this._clientWallet;
|
|
23
23
|
}
|
|
24
|
-
constructor(httpClient, logger,
|
|
24
|
+
constructor(httpClient, logger, clientParams) {
|
|
25
25
|
this.httpClient = httpClient;
|
|
26
26
|
this.logger = logger;
|
|
27
|
-
this.
|
|
27
|
+
this.clientParams = clientParams;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Checks, that selected blockchain in wallet is equal to passed blockchain.
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { AbstractAdapter } from './adapters/common/abstract-adapter';
|
|
2
2
|
import { WalletProviderCore } from './constants/models/wallet-provider';
|
|
3
|
-
import { BlockchainName, EvmBlockchainName, SolanaBlockchainName, TronBlockchainName, ICustomLogger,
|
|
3
|
+
import { BlockchainName, EvmBlockchainName, SolanaBlockchainName, TronBlockchainName, ICustomLogger, TonBlockchainName, BitcoinBlockchainName, SuiBlockchainName } from '@cryptorubic/core';
|
|
4
4
|
import { TonAdapter } from './adapters/adapter-ton/ton-adapter';
|
|
5
|
-
import { TonAdapterConfig } from './adapters/models/ton-adapter-config';
|
|
6
5
|
import { EvmAdapter } from './adapters/adapter-evm/evm-adapter';
|
|
7
6
|
import { BitcoinAdapter } from './adapters/adapter-bitcoin/bitcoin-adapter';
|
|
8
7
|
import { SolanaAdapter } from './adapters/adapter-solana/solana-adapter';
|
|
9
8
|
import { TronAdapter } from './adapters/adapter-tron/tron-adapter';
|
|
10
9
|
import { SuiAdapter } from './adapters/adapter-sui/sui-adapter';
|
|
11
|
-
import {
|
|
10
|
+
import { AdapterFactoryParams } from './models/create-factory-params';
|
|
12
11
|
export declare class BlockchainAdapterFactoryService {
|
|
13
12
|
private readonly rpcList;
|
|
14
13
|
private readonly httpClient;
|
|
15
14
|
private readonly createLogger?;
|
|
16
15
|
private readonly tonParams?;
|
|
17
|
-
private readonly
|
|
16
|
+
private readonly clientParams?;
|
|
18
17
|
readonly adapterStore: Partial<Record<BlockchainName, AbstractAdapter<unknown, unknown, BlockchainName>>>;
|
|
19
18
|
protected readonly logger?: ICustomLogger;
|
|
20
19
|
private constructor();
|
|
21
20
|
hasAdapterFor(blockchain: BlockchainName): boolean;
|
|
22
|
-
static createFactory(
|
|
21
|
+
static createFactory(params: AdapterFactoryParams): Promise<BlockchainAdapterFactoryService>;
|
|
23
22
|
getAdapter(blockchain: SolanaBlockchainName): SolanaAdapter;
|
|
24
23
|
getAdapter(blockchain: EvmBlockchainName): EvmAdapter;
|
|
25
24
|
getAdapter(blockchain: TronBlockchainName): TronAdapter;
|
|
@@ -10,12 +10,12 @@ const solana_adapter_1 = require("./adapters/adapter-solana/solana-adapter");
|
|
|
10
10
|
const tron_adapter_1 = require("./adapters/adapter-tron/tron-adapter");
|
|
11
11
|
const sui_adapter_1 = require("./adapters/adapter-sui/sui-adapter");
|
|
12
12
|
class BlockchainAdapterFactoryService {
|
|
13
|
-
constructor(rpcList, httpClient, createLogger, tonParams,
|
|
13
|
+
constructor(rpcList, httpClient, createLogger, tonParams, clientParams) {
|
|
14
14
|
this.rpcList = rpcList;
|
|
15
15
|
this.httpClient = httpClient;
|
|
16
16
|
this.createLogger = createLogger;
|
|
17
17
|
this.tonParams = tonParams;
|
|
18
|
-
this.
|
|
18
|
+
this.clientParams = clientParams;
|
|
19
19
|
this.adapterStore = {};
|
|
20
20
|
this.adapterStore = this.createStorage();
|
|
21
21
|
if (this.createLogger) {
|
|
@@ -26,11 +26,11 @@ class BlockchainAdapterFactoryService {
|
|
|
26
26
|
const adapter = this.adapterStore?.[blockchain];
|
|
27
27
|
return !!adapter;
|
|
28
28
|
}
|
|
29
|
-
static async createFactory(
|
|
29
|
+
static async createFactory(params) {
|
|
30
30
|
// @TODO Add default logger
|
|
31
|
-
const loggerFn = createLogger || undefined;
|
|
32
|
-
const resolvedHttpClient = httpClient ?? (await Promise.resolve().then(() => require('axios')));
|
|
33
|
-
return new this(rpcList, resolvedHttpClient, createLogger, tonParams,
|
|
31
|
+
const loggerFn = params.createLogger || undefined;
|
|
32
|
+
const resolvedHttpClient = params.httpClient ?? (await Promise.resolve().then(() => require('axios')));
|
|
33
|
+
return new this(params.rpcList, resolvedHttpClient, params.createLogger, params.tonParams, params.clientParams);
|
|
34
34
|
}
|
|
35
35
|
getAdapter(blockchain) {
|
|
36
36
|
const adapter = this.adapterStore?.[blockchain];
|
|
@@ -68,24 +68,24 @@ class BlockchainAdapterFactoryService {
|
|
|
68
68
|
return new evm_adapter_1.EvmAdapter(this.httpClient, {
|
|
69
69
|
blockchain: blockchain,
|
|
70
70
|
rpcList: rpcs
|
|
71
|
-
}, this.createLogger?.(`EVM_ADAPTER_${blockchain}`), this.
|
|
71
|
+
}, this.createLogger?.(`EVM_ADAPTER_${blockchain}`), this.clientParams);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
if (blockchainType === core_1.CHAIN_TYPE.TRON) {
|
|
75
|
-
return new tron_adapter_1.TronAdapter(rpcs, this.httpClient, this.createLogger?.(`TRON_ADAPTER`), this.
|
|
75
|
+
return new tron_adapter_1.TronAdapter(rpcs, this.httpClient, this.createLogger?.(`TRON_ADAPTER`), this.clientParams);
|
|
76
76
|
}
|
|
77
77
|
if (blockchainType === core_1.CHAIN_TYPE.SUI) {
|
|
78
|
-
return new sui_adapter_1.SuiAdapter(rpcs, this.httpClient, this.createLogger?.(`SUI_ADAPTER`), this.
|
|
78
|
+
return new sui_adapter_1.SuiAdapter(rpcs, this.httpClient, this.createLogger?.(`SUI_ADAPTER`), this.clientParams);
|
|
79
79
|
}
|
|
80
80
|
if (blockchainType === core_1.CHAIN_TYPE.SOLANA) {
|
|
81
|
-
return new solana_adapter_1.SolanaAdapter(rpcs, this.httpClient, this.createLogger?.(`SOLANA_ADAPTER`), this.
|
|
81
|
+
return new solana_adapter_1.SolanaAdapter(rpcs, this.httpClient, this.createLogger?.(`SOLANA_ADAPTER`), this.clientParams);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if (blockchain === core_1.BLOCKCHAIN_NAME.TON && this.tonParams?.tonApiConfig && this.tonParams?.tonClientConfig) {
|
|
85
|
-
return new ton_adapter_1.TonAdapter(this.httpClient, this.tonParams, this.createLogger?.(`TON_ADAPTER`), this.
|
|
85
|
+
return new ton_adapter_1.TonAdapter(this.httpClient, this.tonParams, this.createLogger?.(`TON_ADAPTER`), this.clientParams);
|
|
86
86
|
}
|
|
87
87
|
if (blockchain === core_1.BLOCKCHAIN_NAME.BITCOIN && this.httpClient) {
|
|
88
|
-
return new bitcoin_adapter_1.BitcoinAdapter(this.httpClient, this.createLogger?.(`BTC_ADAPTER`), this.
|
|
88
|
+
return new bitcoin_adapter_1.BitcoinAdapter(this.httpClient, this.createLogger?.(`BTC_ADAPTER`), this.clientParams);
|
|
89
89
|
}
|
|
90
90
|
return null;
|
|
91
91
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BitcoinBlockchainName, EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName, SuiBlockchainName, TonBlockchainName, TronBlockchainName } from '@cryptorubic/core';
|
|
2
|
+
import { EnvType } from '../constants/models/env-type';
|
|
3
|
+
import { TronWebProvider } from '../adapters/adapter-tron/models/tron-web-provider';
|
|
4
|
+
import { TonAdapterConfig } from '../adapters/models/ton-adapter-config';
|
|
5
|
+
export type RpcSupportedBlockhainName = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<TonBlockchainName, string[]> & Record<BitcoinBlockchainName, string[]> & Record<SuiBlockchainName, string[]>;
|
|
6
|
+
export interface AdapterFactoryParams {
|
|
7
|
+
rpcList: RpcSupportedBlockhainName;
|
|
8
|
+
httpClient?: HttpClient;
|
|
9
|
+
tonParams?: TonAdapterConfig;
|
|
10
|
+
createLogger?: (label: string) => ICustomLogger;
|
|
11
|
+
clientParams?: ClientAdaptersFactoryParams;
|
|
12
|
+
}
|
|
13
|
+
export interface ClientAdaptersFactoryParams {
|
|
14
|
+
envType: EnvType;
|
|
15
|
+
}
|