@cryptorubic/web3 1.0.0-alpha.no-sdk.3 → 1.0.0-alpha.no-sdk.5
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 +12 -0
- package/src/index.js +12 -1
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +2 -3
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.d.ts +1 -1
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.js +12 -10
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +3 -5
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +2 -3
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +2 -3
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +2 -3
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +2 -4
- package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +10 -4
- package/src/lib/adapter/adapters/common/abstract-adapter.js +15 -1
- package/src/lib/adapter/adapters/models/approve-adapter.d.ts +1 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -143,3 +143,15 @@ export * from './lib/utils/web3-types/solana-web3-pure';
|
|
|
143
143
|
export * from './lib/utils/web3-types/sui-web3-pure';
|
|
144
144
|
export * from './lib/utils/web3-types/ton-web3-pure';
|
|
145
145
|
export * from './lib/utils/web3-types/tron-web3-pure';
|
|
146
|
+
export * from './lib/utils/models/primitive-types';
|
|
147
|
+
export * from './lib/utils/models/tron-transaction-info';
|
|
148
|
+
export * from './lib/utils/models/tron-transaction-config';
|
|
149
|
+
export * from './lib/utils/models/tron-parameters';
|
|
150
|
+
export * from './lib/utils/models/tron-multicall-response';
|
|
151
|
+
export * from './lib/utils/models/tron-call';
|
|
152
|
+
export * from './lib/utils/models/tron-block';
|
|
153
|
+
export * from './lib/utils/models/abi-types';
|
|
154
|
+
export * from './lib/utils/models/evm-transaction-config';
|
|
155
|
+
export * from './lib/utils/models/cn-validation-response';
|
|
156
|
+
export * from './lib/utils/constants/changenow-api-blockchain';
|
|
157
|
+
export * from './lib/utils/models/ton-transaction-config';
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
// Auto-generated exports - do not edit manually
|
|
5
4
|
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-bitcoin/models/btc-send-tx-params"), exports);
|
|
@@ -147,3 +146,15 @@ tslib_1.__exportStar(require("./lib/utils/web3-types/solana-web3-pure"), exports
|
|
|
147
146
|
tslib_1.__exportStar(require("./lib/utils/web3-types/sui-web3-pure"), exports);
|
|
148
147
|
tslib_1.__exportStar(require("./lib/utils/web3-types/ton-web3-pure"), exports);
|
|
149
148
|
tslib_1.__exportStar(require("./lib/utils/web3-types/tron-web3-pure"), exports);
|
|
149
|
+
tslib_1.__exportStar(require("./lib/utils/models/primitive-types"), exports);
|
|
150
|
+
tslib_1.__exportStar(require("./lib/utils/models/tron-transaction-info"), exports);
|
|
151
|
+
tslib_1.__exportStar(require("./lib/utils/models/tron-transaction-config"), exports);
|
|
152
|
+
tslib_1.__exportStar(require("./lib/utils/models/tron-parameters"), exports);
|
|
153
|
+
tslib_1.__exportStar(require("./lib/utils/models/tron-multicall-response"), exports);
|
|
154
|
+
tslib_1.__exportStar(require("./lib/utils/models/tron-call"), exports);
|
|
155
|
+
tslib_1.__exportStar(require("./lib/utils/models/tron-block"), exports);
|
|
156
|
+
tslib_1.__exportStar(require("./lib/utils/models/abi-types"), exports);
|
|
157
|
+
tslib_1.__exportStar(require("./lib/utils/models/evm-transaction-config"), exports);
|
|
158
|
+
tslib_1.__exportStar(require("./lib/utils/models/cn-validation-response"), exports);
|
|
159
|
+
tslib_1.__exportStar(require("./lib/utils/constants/changenow-api-blockchain"), exports);
|
|
160
|
+
tslib_1.__exportStar(require("./lib/utils/models/ton-transaction-config"), exports);
|
|
@@ -3,16 +3,15 @@ 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 { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
7
6
|
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
8
|
-
import {
|
|
7
|
+
import { BitcoinAdapterClient } from './client/bitcoin-adapter-client';
|
|
9
8
|
import { Abi } from 'viem';
|
|
10
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
11
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
12
11
|
import { MethodData } from '../models/web3-public-models/method-data';
|
|
13
12
|
export declare class BitcoinAdapter extends AbstractAdapter<BtcWallet, BtcWallet, BitcoinBlockchainName> {
|
|
14
13
|
private readonly httpClient;
|
|
15
|
-
readonly client:
|
|
14
|
+
readonly client: BitcoinAdapterClient;
|
|
16
15
|
constructor(httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
17
16
|
getBalance(userAddress: string): Promise<BigNumber>;
|
|
18
17
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
@@ -53,7 +53,7 @@ export declare class EvmAdapterClient extends AbstractAdapterClient<WalletClient
|
|
|
53
53
|
* @param [options] Additional options.
|
|
54
54
|
* @returns Transaction receipt.
|
|
55
55
|
*/
|
|
56
|
-
trySendTransaction(
|
|
56
|
+
trySendTransaction(params: EvmSendTxParams): Promise<TransactionReceipt>;
|
|
57
57
|
/**
|
|
58
58
|
* Executes method of smart-contract and resolve the promise when the transaction is included in the block.
|
|
59
59
|
* @param contractAddress Address of smart-contract which method is to be executed.
|
|
@@ -134,23 +134,25 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
134
134
|
* @param [options] Additional options.
|
|
135
135
|
* @returns Transaction receipt.
|
|
136
136
|
*/
|
|
137
|
-
async trySendTransaction(
|
|
137
|
+
async trySendTransaction(params) {
|
|
138
138
|
try {
|
|
139
|
+
const to = params.txOptions.to;
|
|
140
|
+
const value = BigInt(params.txOptions.value?.toString() || '0');
|
|
139
141
|
const gaslessParams = {
|
|
140
142
|
account: this.walletAddress,
|
|
141
|
-
to
|
|
142
|
-
value
|
|
143
|
-
...(
|
|
143
|
+
to,
|
|
144
|
+
value,
|
|
145
|
+
...(params.txOptions.data && { data: params.txOptions.data })
|
|
144
146
|
};
|
|
145
147
|
const gas = await this.evmAdapter.public.estimateGas(gaslessParams);
|
|
146
148
|
const gasfulParams = {
|
|
147
149
|
...gaslessParams,
|
|
148
|
-
...(0, options_1.getGasOptions)(
|
|
150
|
+
...(0, options_1.getGasOptions)(params.txOptions),
|
|
149
151
|
gas: gas.toString()
|
|
150
152
|
};
|
|
151
153
|
const gasfulViemParams = {
|
|
152
154
|
...gaslessParams,
|
|
153
|
-
...(0, options_1.getViemGasOptions)(
|
|
155
|
+
...(0, options_1.getViemGasOptions)(params.txOptions),
|
|
154
156
|
gas
|
|
155
157
|
};
|
|
156
158
|
try {
|
|
@@ -161,9 +163,9 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
161
163
|
}
|
|
162
164
|
const sendParams = {
|
|
163
165
|
...gasfulParams,
|
|
164
|
-
...(
|
|
165
|
-
onTransactionHash:
|
|
166
|
-
gasPriceOptions:
|
|
166
|
+
...(params.txOptions.onTransactionHash && {
|
|
167
|
+
onTransactionHash: params.txOptions.onTransactionHash,
|
|
168
|
+
gasPriceOptions: params.txOptions?.gasPriceOptions
|
|
167
169
|
})
|
|
168
170
|
};
|
|
169
171
|
const receipt = await this.sendTransaction({ txOptions: sendParams });
|
|
@@ -173,7 +175,7 @@ class EvmAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
|
173
175
|
console.debug('Call tokens transfer error', err);
|
|
174
176
|
const shouldIgnore = await this.shouldIgnoreError(err);
|
|
175
177
|
if (shouldIgnore) {
|
|
176
|
-
return this.sendTransaction(
|
|
178
|
+
return this.sendTransaction(params);
|
|
177
179
|
}
|
|
178
180
|
throw (0, parse_evm_error_1.parseEvmError)(err);
|
|
179
181
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { Abi, MulticallResponse, MulticallParameters, PublicActions, PublicClient, WalletClient, WalletActions, BlockNumber, BlockTag, GetBlockReturnType
|
|
1
|
+
import { Abi, MulticallResponse, MulticallParameters, PublicActions, PublicClient, WalletClient, WalletActions, BlockNumber, BlockTag, GetBlockReturnType } from 'viem';
|
|
2
2
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
3
3
|
import { EvmBlockchainName, ICustomLogger, Token, TokenAmount, PriceTokenAmount, HttpClient } from '@cryptorubic/core';
|
|
4
4
|
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
|
-
import {
|
|
8
|
-
import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
7
|
+
import { EvmAdapterClient } from './client/evm-adapter-client';
|
|
9
8
|
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
10
|
-
import { ApproveAdapterClient } from '../models/approve-adapter';
|
|
11
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
12
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
13
11
|
import { MethodData } from '../models/web3-public-models/method-data';
|
|
14
12
|
import { GasPrice } from '../models/evm-web3-public-models/gas-price';
|
|
15
13
|
export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> {
|
|
16
|
-
readonly client:
|
|
14
|
+
readonly client: EvmAdapterClient;
|
|
17
15
|
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
18
16
|
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
19
17
|
constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
@@ -4,16 +4,15 @@ import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Toke
|
|
|
4
4
|
import BigNumber from 'bignumber.js';
|
|
5
5
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
6
|
import { SolanaRawInstruction } from '../models/solana-web3-types';
|
|
7
|
-
import { SolanaSendTxParams } from './models/solana-send-tx-params';
|
|
8
7
|
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
9
8
|
import { SolanaWeb3 } from '../../constants/models/solana-web3';
|
|
10
|
-
import {
|
|
9
|
+
import { SolanaAdapterClient } from './client/solana-adapter-client';
|
|
11
10
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
12
11
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
13
12
|
export declare const NATIVE_SOLANA_MINT_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
14
13
|
export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
|
|
15
14
|
private readonly httpClient;
|
|
16
|
-
readonly client:
|
|
15
|
+
readonly client: SolanaAdapterClient;
|
|
17
16
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
18
17
|
/**
|
|
19
18
|
* Gets balance of multiple tokens.
|
|
@@ -3,14 +3,13 @@ import { HttpClient, ICustomLogger, PriceTokenAmount, SuiBlockchainName, Token,
|
|
|
3
3
|
import { SuiClient } from '@mysten/sui/client';
|
|
4
4
|
import BigNumber from 'bignumber.js';
|
|
5
5
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
|
-
import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
7
6
|
import { WalletAdapter } from '@suiet/wallet-sdk';
|
|
7
|
+
import { SuiAdapterClient } from './client/sui-adapter-client';
|
|
8
8
|
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
9
|
-
import { SuiSendTxParams } from './models/sui-send-tx-params';
|
|
10
9
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
11
10
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
12
11
|
export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter, SuiBlockchainName> {
|
|
13
|
-
readonly client:
|
|
12
|
+
readonly client: SuiAdapterClient;
|
|
14
13
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
15
14
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
16
15
|
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
@@ -5,13 +5,12 @@ import { TonAdapterConfig } from '../models/ton-adapter-config';
|
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
7
7
|
import { TonConnectUI } from '@tonconnect/ui';
|
|
8
|
-
import {
|
|
9
|
-
import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
8
|
+
import { TonAdapterClient } from './client/ton-adapter-client';
|
|
10
9
|
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
11
10
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
12
11
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
13
12
|
export declare class TonAdapter extends AbstractAdapter<TonClient, TonConnectUI, TonBlockchainName> {
|
|
14
|
-
readonly client:
|
|
13
|
+
readonly client: TonAdapterClient;
|
|
15
14
|
private readonly tonApi;
|
|
16
15
|
constructor(httpClient: HttpClient, config: TonAdapterConfig, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
17
16
|
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
@@ -8,12 +8,10 @@ import { Abi } from 'viem';
|
|
|
8
8
|
import { ContractMulticallResponse } from '../../../utils/models/contract-multicall-response';
|
|
9
9
|
import { TronWeb3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
10
10
|
import { MethodData } from '../../../utils/models/method-data';
|
|
11
|
-
import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
12
|
-
import { TronSendTxParams } from './models/tron-send-tx-params';
|
|
13
11
|
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
14
|
-
import {
|
|
12
|
+
import { TronAdapterClient } from './client/tron-adapter-client';
|
|
15
13
|
export declare class TronAdapter extends AbstractAdapter<TronWeb, TronWeb, TronBlockchainName> {
|
|
16
|
-
readonly client:
|
|
14
|
+
readonly client: TronAdapterClient;
|
|
17
15
|
private readonly multicallAddress;
|
|
18
16
|
needPreswapAction(): Promise<boolean>;
|
|
19
17
|
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Abi } from 'viem';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { ICustomLogger, Token, TokenAmount, BlockchainName
|
|
3
|
+
import { ICustomLogger, Token, TokenAmount, BlockchainName } from '@cryptorubic/core';
|
|
4
4
|
import { AbstractAdapterClient } from './client/abstract-adapter-client';
|
|
5
|
-
import { SupportedTokenField } from '../models/token-models';
|
|
6
5
|
import { MethodData } from '../models/web3-public-models/method-data';
|
|
7
6
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
8
7
|
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
@@ -15,14 +14,21 @@ export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, Se
|
|
|
15
14
|
get public(): P;
|
|
16
15
|
protected constructor(blockchain: B, logger?: ICustomLogger);
|
|
17
16
|
abstract getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
18
|
-
abstract checkEnoughBalance(token: TokenAmount
|
|
17
|
+
abstract checkEnoughBalance(token: TokenAmount, walletAddress: string): Promise<boolean>;
|
|
19
18
|
abstract callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
20
19
|
/**
|
|
21
20
|
* Gets token info by address.
|
|
22
21
|
* @param tokenAddress Address of token.
|
|
23
22
|
* @param tokenFields Token's fields to get.
|
|
24
23
|
*/
|
|
25
|
-
callForTokenInfo(tokenAddress: string
|
|
24
|
+
callForTokenInfo(tokenAddress: string): Promise<Token<BlockchainName>>;
|
|
25
|
+
/**
|
|
26
|
+
* Checks that user has enough balance.
|
|
27
|
+
* @param userAddress Wallet address, which contains tokens.
|
|
28
|
+
* @param token Token to check balance of.
|
|
29
|
+
* @param requiredAmount Required user balance in Eth units.
|
|
30
|
+
*/
|
|
31
|
+
checkBalance(token: Token, requiredAmount: BigNumber, userAddress: string): Promise<void | never>;
|
|
26
32
|
/**
|
|
27
33
|
* Uses multicall to make many methods calls in several contracts.
|
|
28
34
|
* @param contractAbi Target contract abi.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractAdapter = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
+
const core_1 = require("@cryptorubic/core");
|
|
6
|
+
const insufficient_funds_error_1 = require("../../../errors/swap/insufficient-funds.error");
|
|
5
7
|
class AbstractAdapter {
|
|
6
8
|
set public(value) {
|
|
7
9
|
this._public = value;
|
|
@@ -50,9 +52,21 @@ class AbstractAdapter {
|
|
|
50
52
|
* @param tokenAddress Address of token.
|
|
51
53
|
* @param tokenFields Token's fields to get.
|
|
52
54
|
*/
|
|
53
|
-
async callForTokenInfo(tokenAddress
|
|
55
|
+
async callForTokenInfo(tokenAddress) {
|
|
54
56
|
return (await this.callForTokensInfo([tokenAddress]))[0];
|
|
55
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks that user has enough balance.
|
|
60
|
+
* @param userAddress Wallet address, which contains tokens.
|
|
61
|
+
* @param token Token to check balance of.
|
|
62
|
+
* @param requiredAmount Required user balance in Eth units.
|
|
63
|
+
*/
|
|
64
|
+
async checkBalance(token, requiredAmount, userAddress) {
|
|
65
|
+
const enoughBalance = await this.checkEnoughBalance(new core_1.TokenAmount({ ...token, tokenAmount: requiredAmount }), userAddress);
|
|
66
|
+
if (!enoughBalance) {
|
|
67
|
+
throw new insufficient_funds_error_1.InsufficientFundsError(token.symbol);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
56
70
|
needPreswapAction(token, contractAddress, walletAddress, amount) {
|
|
57
71
|
return Promise.resolve(false);
|
|
58
72
|
}
|
|
@@ -30,7 +30,7 @@ export interface ApproveAdapterClient<T> extends AbstractAdapterClient<{}, {}, {
|
|
|
30
30
|
* Get data for tokens approve
|
|
31
31
|
* @param tokenAddress erc20 token address
|
|
32
32
|
* @param spenderAddress spender address
|
|
33
|
-
* @param amount amount in
|
|
33
|
+
* @param amount amount in wei
|
|
34
34
|
*/
|
|
35
35
|
approve(walletAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string>;
|
|
36
36
|
}
|