@cryptorubic/web3 0.8.16-alpha-usdt-zero-bridge.0 → 0.8.16-alpha-usdt-zero-bridge.2
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 +22 -15
- package/src/index.d.ts +130 -22
- package/src/index.js +130 -20
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +38 -0
- package/src/lib/adapter/adapters/{bitcoin-adapter.js → adapter-bitcoin/bitcoin-adapter.js} +35 -13
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-send-tx-params.d.ts +5 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.d.ts +5 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.js +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.d.ts +7 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.js +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-transfer-encoded-config.d.ts +6 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-transfer-encoded-config.js +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/signer/bitcoin-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/signer/bitcoin-adapter-signer.js +131 -0
- package/src/lib/adapter/adapters/adapter-evm/constants/proxy-hash-errors.d.ts +4 -0
- package/src/lib/adapter/adapters/adapter-evm/constants/proxy-hash-errors.js +705 -0
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +120 -0
- package/src/lib/adapter/adapters/{evm-adapter.js → adapter-evm/evm-adapter.js} +215 -87
- package/src/lib/adapter/adapters/adapter-evm/models/evm-send-tx-params.d.ts +38 -0
- package/src/lib/adapter/adapters/adapter-evm/models/evm-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-evm/signer/evm-adapter-signer.d.ts +53 -0
- package/src/lib/adapter/adapters/adapter-evm/signer/evm-adapter-signer.js +268 -0
- package/src/lib/adapter/adapters/adapter-evm/utils/parse-evm-error.d.ts +12 -0
- package/src/lib/adapter/adapters/adapter-evm/utils/parse-evm-error.js +70 -0
- package/src/lib/adapter/adapters/adapter-solana/models/solana-send-tx-params.d.ts +16 -0
- package/src/lib/adapter/adapters/adapter-solana/models/solana-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/{utils → adapter-solana/services}/solana-tokens-service.d.ts +1 -1
- package/src/lib/adapter/adapters/{utils → adapter-solana/services}/solana-tokens-service.js +2 -2
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.js +87 -0
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +49 -0
- package/src/lib/adapter/adapters/{solana-adapter.js → adapter-solana/solana-adapter.js} +105 -41
- package/src/lib/adapter/adapters/adapter-sui/models/sui-send-tx-params.d.ts +8 -0
- package/src/lib/adapter/adapters/adapter-sui/models/sui-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-sui/signer/sui-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-sui/signer/sui-adapter-signer.js +55 -0
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +32 -0
- package/src/lib/adapter/adapters/{sui-adapter.js → adapter-sui/sui-adapter.js} +45 -9
- package/src/lib/adapter/adapters/adapter-ton/models/ton-send-tx-params.d.ts +26 -0
- package/src/lib/adapter/adapters/adapter-ton/models/ton-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.d.ts +7 -6
- package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.js +17 -9
- package/src/lib/adapter/adapters/adapter-ton/signer/ton-adapter-signer.d.ts +43 -0
- package/src/lib/adapter/adapters/adapter-ton/signer/ton-adapter-signer.js +166 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +32 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.js +104 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-send-tx-params.d.ts +13 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-web-provider.d.ts +4 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-web-provider.js +2 -0
- package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.js +57 -0
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +57 -0
- package/src/lib/adapter/adapters/{tron-adapter.js → adapter-tron/tron-adapter.js} +131 -66
- package/src/lib/adapter/adapters/adapter-tron/utils/parse-tron-error.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-tron/utils/parse-tron-error.js +20 -0
- package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +84 -0
- package/src/lib/adapter/adapters/common/abstract-adapter.js +82 -0
- package/src/lib/adapter/adapters/common/signer/abstract-adapter-signer.d.ts +22 -0
- package/src/lib/adapter/adapters/common/signer/abstract-adapter-signer.js +42 -0
- package/src/lib/adapter/adapters/constants/tron-multicall-abi.d.ts +1 -1
- package/src/lib/adapter/adapters/models/approve-adapter.d.ts +13 -9
- package/src/lib/adapter/adapters/models/approve-adapter.js +1 -1
- package/src/lib/adapter/adapters/models/basic-transaction-options.d.ts +1 -1
- package/src/lib/adapter/adapters/models/evm-web3-public-models/batch-call.d.ts +5 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/batch-call.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-call.d.ts +4 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-call.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-multicall-response.d.ts +4 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-multicall-response.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price-viem.d.ts +18 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price-viem.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/permit2-contract-types.d.ts +10 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/permit2-contract-types.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/rpc-response.d.ts +5 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/rpc-response.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/contract-params.d.ts +23 -0
- package/src/lib/adapter/adapters/models/old-features-models/contract-params.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/encode-transaction-options.d.ts +32 -0
- package/src/lib/adapter/adapters/models/old-features-models/encode-transaction-options.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/is-deflation-token.d.ts +6 -0
- package/src/lib/adapter/adapters/models/old-features-models/is-deflation-token.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/non-evm-chain-address-correct-response.d.ts +5 -0
- package/src/lib/adapter/adapters/models/old-features-models/non-evm-chain-address-correct-response.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/swap-transaction-options.d.ts +65 -0
- package/src/lib/adapter/adapters/models/old-features-models/swap-transaction-options.js +2 -0
- package/src/lib/adapter/adapters/models/status-manager-models/tx-status-data.d.ts +8 -0
- package/src/lib/adapter/adapters/models/status-manager-models/tx-status-data.js +2 -0
- package/src/lib/adapter/adapters/models/tonapi-models.d.ts +2 -2
- package/src/lib/adapter/adapters/models/web3-public-models/contract-multicall-response.d.ts +5 -0
- package/src/lib/adapter/adapters/models/web3-public-models/contract-multicall-response.js +2 -0
- package/src/lib/adapter/adapters/models/web3-public-models/method-data.d.ts +4 -0
- package/src/lib/adapter/adapters/models/web3-public-models/method-data.js +2 -0
- package/src/lib/adapter/adapters/models/web3-public-models/supported-token-field.d.ts +1 -0
- package/src/lib/adapter/adapters/models/web3-public-models/supported-token-field.js +2 -0
- package/src/lib/adapter/adapters/models/web3-public-models/tx-status.d.ts +10 -0
- package/src/lib/adapter/adapters/models/web3-public-models/tx-status.js +12 -0
- package/src/lib/adapter/adapters/utils/errors.d.ts +2 -0
- package/src/lib/adapter/adapters/utils/errors.js +10 -0
- package/src/lib/adapter/adapters/utils/options.d.ts +10 -0
- package/src/lib/adapter/adapters/utils/options.js +59 -0
- package/src/lib/adapter/adapters/utils/waitFor.d.ts +1 -0
- package/src/lib/adapter/adapters/utils/waitFor.js +6 -0
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +15 -13
- package/src/lib/adapter/blockchain-adapter-factory.service.js +44 -61
- package/src/lib/adapter/constants/chain-configs/chain-configs.d.ts +1 -1
- package/src/lib/adapter/constants/chain-configs/chain-configs.js +92 -56
- package/src/lib/adapter/constants/models/env-type.d.ts +1 -0
- package/src/lib/adapter/constants/models/env-type.js +2 -0
- package/src/lib/adapter/constants/models/solana-web3.d.ts +1 -1
- package/src/lib/adapter/constants/rubic-api-link-mapping.d.ts +2 -0
- package/src/lib/adapter/constants/rubic-api-link-mapping.js +16 -0
- package/src/lib/adapter/constants/viem-blockchain-mapping.d.ts +1 -1
- package/src/lib/adapter/constants/viem-blockchain-mapping.js +4 -3
- package/src/lib/adapter/models/create-factory-params.d.ts +23 -0
- package/src/lib/adapter/models/create-factory-params.js +2 -0
- package/src/lib/errors/blockchain/deflation-token.error.d.ts +11 -0
- package/src/lib/errors/blockchain/deflation-token.error.js +16 -0
- package/src/lib/errors/blockchain/healthcheck.error.d.ts +8 -0
- package/src/lib/errors/blockchain/healthcheck.error.js +15 -0
- package/src/lib/errors/blockchain/invalid-address.error.d.ts +8 -0
- package/src/lib/errors/blockchain/invalid-address.error.js +15 -0
- package/src/lib/errors/blockchain/low-gas.error.d.ts +7 -0
- package/src/lib/errors/blockchain/low-gas.error.js +14 -0
- package/src/lib/errors/blockchain/transaction-reverted.error.d.ts +7 -0
- package/src/lib/errors/blockchain/transaction-reverted.error.js +14 -0
- package/src/lib/errors/blockchain/tron-insufficient-native-balance.d.ts +7 -0
- package/src/lib/errors/blockchain/tron-insufficient-native-balance.js +14 -0
- package/src/lib/errors/blockchain/tron-transaction-expired.d.ts +7 -0
- package/src/lib/errors/blockchain/tron-transaction-expired.js +14 -0
- package/src/lib/errors/blockchain/user-reject.error.d.ts +7 -0
- package/src/lib/errors/blockchain/user-reject.error.js +14 -0
- package/src/lib/errors/blockchain/wrong-from-address.error.d.ts +7 -0
- package/src/lib/errors/blockchain/wrong-from-address.error.js +14 -0
- package/src/lib/errors/blockchain/wrong-receiver-address.error.d.ts +7 -0
- package/src/lib/errors/blockchain/wrong-receiver-address.error.js +14 -0
- package/src/lib/errors/common/timeout.error.d.ts +4 -0
- package/src/lib/errors/common/timeout.error.js +12 -0
- package/src/lib/errors/common/tx-reverted-in-chain.error.d.ts +4 -0
- package/src/lib/errors/common/tx-reverted-in-chain.error.js +11 -0
- package/src/lib/errors/cross-chain/cross-chain-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/cross-chain/cross-chain-is-unavailable.error.js +14 -0
- package/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error.d.ts +7 -0
- package/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error.js +14 -0
- package/src/lib/errors/cross-chain/low-to-slippage.error.d.ts +6 -0
- package/src/lib/errors/cross-chain/low-to-slippage.error.js +10 -0
- package/src/lib/errors/cross-chain/max-gas-price-overflow.error.d.ts +8 -0
- package/src/lib/errors/cross-chain/max-gas-price-overflow.error.js +15 -0
- package/src/lib/errors/cross-chain/too-low-amount.error.d.ts +7 -0
- package/src/lib/errors/cross-chain/too-low-amount.error.js +14 -0
- package/src/lib/errors/cross-chain/unsupported-receiver-address.error.d.ts +4 -0
- package/src/lib/errors/cross-chain/unsupported-receiver-address.error.js +11 -0
- package/src/lib/errors/cross-chain/updated-rates-error.d.ts +10 -0
- package/src/lib/errors/cross-chain/updated-rates-error.js +17 -0
- package/src/lib/errors/models/rubic-api-error.d.ts +21 -0
- package/src/lib/errors/models/rubic-api-error.js +2 -0
- package/src/lib/errors/on-chain/on-chain-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/on-chain/on-chain-is-unavailable.error.js +14 -0
- package/src/lib/errors/proxy/unapproved-contract-error.d.ts +8 -0
- package/src/lib/errors/proxy/unapproved-contract-error.js +15 -0
- package/src/lib/errors/proxy/unapproved-method-error.d.ts +8 -0
- package/src/lib/errors/proxy/unapproved-method-error.js +15 -0
- package/src/lib/errors/proxy/unlisted-error.d.ts +9 -0
- package/src/lib/errors/proxy/unlisted-error.js +16 -0
- package/src/lib/errors/rubic-sdk.error.d.ts +6 -0
- package/src/lib/errors/rubic-sdk.error.js +13 -0
- package/src/lib/errors/swap/bridgers-pair-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/swap/bridgers-pair-is-unavailable.error.js +14 -0
- package/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error.d.ts +8 -0
- package/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error.js +15 -0
- package/src/lib/errors/swap/insufficient-funds-oneinch.error.d.ts +9 -0
- package/src/lib/errors/swap/insufficient-funds-oneinch.error.js +15 -0
- package/src/lib/errors/swap/insufficient-funds.error.d.ts +11 -0
- package/src/lib/errors/swap/insufficient-funds.error.js +18 -0
- package/src/lib/errors/swap/insufficient-liquidity.error.d.ts +7 -0
- package/src/lib/errors/swap/insufficient-liquidity.error.js +14 -0
- package/src/lib/errors/swap/lifi-pair-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/swap/lifi-pair-is-unavailable.error.js +14 -0
- package/src/lib/errors/swap/low-slippage-deflationary-token.error.d.ts +7 -0
- package/src/lib/errors/swap/low-slippage-deflationary-token.error.js +14 -0
- package/src/lib/errors/swap/low-slippage.error.d.ts +8 -0
- package/src/lib/errors/swap/low-slippage.error.js +15 -0
- package/src/lib/errors/swap/max-amount.error.d.ts +7 -0
- package/src/lib/errors/swap/max-amount.error.js +14 -0
- package/src/lib/errors/swap/max-decimals.error.d.ts +5 -0
- package/src/lib/errors/swap/max-decimals.error.js +12 -0
- package/src/lib/errors/swap/min-amount.error.d.ts +7 -0
- package/src/lib/errors/swap/min-amount.error.js +14 -0
- package/src/lib/errors/swap/no-linked-account-erros.d.ts +4 -0
- package/src/lib/errors/swap/no-linked-account-erros.js +11 -0
- package/src/lib/errors/swap/not-supported-blockchain.d.ts +8 -0
- package/src/lib/errors/swap/not-supported-blockchain.js +15 -0
- package/src/lib/errors/swap/not-supported-region.d.ts +7 -0
- package/src/lib/errors/swap/not-supported-region.js +14 -0
- package/src/lib/errors/swap/not-supported-tokens.error.d.ts +7 -0
- package/src/lib/errors/swap/not-supported-tokens.error.js +14 -0
- package/src/lib/errors/swap/not-whitelisted-provider.error.d.ts +10 -0
- package/src/lib/errors/swap/not-whitelisted-provider.error.js +17 -0
- package/src/lib/errors/swap/simulation-failed.error.d.ts +6 -0
- package/src/lib/errors/swap/simulation-failed.error.js +12 -0
- package/src/lib/errors/swap/swap-error-on-provider-side.d.ts +7 -0
- package/src/lib/errors/swap/swap-error-on-provider-side.js +14 -0
- package/src/lib/errors/swap/swap-request.error.d.ts +7 -0
- package/src/lib/errors/swap/swap-request.error.js +14 -0
- package/src/lib/errors/swap/trade-expired.error.d.ts +4 -0
- package/src/lib/errors/swap/trade-expired.error.js +11 -0
- package/src/lib/errors/swap/unnecessary-approve.error.d.ts +7 -0
- package/src/lib/errors/swap/unnecessary-approve.error.js +14 -0
- package/src/lib/errors/swap/wallet-not-connected.error.d.ts +8 -0
- package/src/lib/errors/swap/wallet-not-connected.error.js +15 -0
- package/src/lib/errors/swap/wrong-network.error.d.ts +10 -0
- package/src/lib/errors/swap/wrong-network.error.js +16 -0
- package/src/lib/utils/constants/web3-pure-store.js +17 -15
- package/src/lib/utils/models/evm-transaction-config.d.ts +2 -0
- package/src/lib/utils/web3-types/near-web3-pure.d.ts +6 -0
- package/src/lib/utils/web3-types/near-web3-pure.js +24 -0
- package/src/lib/utils/web3-types/tron-web3-pure.d.ts +2 -3
- package/src/lib/utils/web3-types/zcash-web3-pure.d.ts +5 -0
- package/src/lib/utils/web3-types/zcash-web3-pure.js +17 -0
- package/src/lib/adapter/adapters/abstract-adapter.d.ts +0 -23
- package/src/lib/adapter/adapters/abstract-adapter.js +0 -59
- package/src/lib/adapter/adapters/bitcoin-adapter.d.ts +0 -18
- package/src/lib/adapter/adapters/evm-adapter.d.ts +0 -59
- package/src/lib/adapter/adapters/solana-adapter.d.ts +0 -35
- package/src/lib/adapter/adapters/sui-adapter.d.ts +0 -17
- package/src/lib/adapter/adapters/ton-adapter.d.ts +0 -22
- package/src/lib/adapter/adapters/ton-adapter.js +0 -100
- package/src/lib/adapter/adapters/tron-adapter.d.ts +0 -36
- /package/src/lib/adapter/adapters/{models/gas-price.js → adapter-bitcoin/models/btc-send-tx-params.js} +0 -0
- /package/src/lib/adapter/adapters/models/{gas-price.d.ts → evm-web3-public-models/gas-price.d.ts} +0 -0
|
@@ -2,26 +2,99 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TronAdapter = void 0;
|
|
4
4
|
const bignumber_js_1 = require("bignumber.js");
|
|
5
|
-
const trc_20_contract_abi_1 = require("
|
|
6
|
-
const tron_multicall_abi_1 = require("
|
|
7
|
-
const abstract_adapter_1 = require("
|
|
5
|
+
const trc_20_contract_abi_1 = require("../constants/trc-20-contract-abi");
|
|
6
|
+
const tron_multicall_abi_1 = require("../constants/tron-multicall-abi");
|
|
7
|
+
const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
8
8
|
const tronweb_1 = require("tronweb");
|
|
9
9
|
const core_1 = require("@cryptorubic/core");
|
|
10
|
-
const web3_pure_1 = require("
|
|
11
|
-
const tron_web3_pure_1 = require("
|
|
10
|
+
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
11
|
+
const tron_web3_pure_1 = require("../../../utils/web3-types/tron-web3-pure");
|
|
12
|
+
const tron_adapter_signer_1 = require("./signer/tron-adapter-signer");
|
|
13
|
+
const options_1 = require("../utils/options");
|
|
14
|
+
const parse_tron_error_1 = require("./utils/parse-tron-error");
|
|
15
|
+
const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
12
16
|
class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
13
|
-
async needPreswapAction(
|
|
14
|
-
// return this.needApprove()
|
|
17
|
+
async needPreswapAction() {
|
|
15
18
|
return false;
|
|
16
19
|
}
|
|
17
|
-
constructor(rpcList, logger) {
|
|
20
|
+
constructor(rpcList, httpClient, logger, clientParams) {
|
|
18
21
|
super(core_1.BLOCKCHAIN_NAME.TRON, logger);
|
|
22
|
+
this.rpcList = rpcList;
|
|
19
23
|
this.multicallAddress = 'T9ziQU4EBteJzjzMzhHELdhgWFqwzS5Vki';
|
|
20
|
-
this.
|
|
24
|
+
this.signer = new tron_adapter_signer_1.TronAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
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
|
+
}
|
|
30
|
+
async callContractMethod(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
31
|
+
this.public.setAddress(contractAddress);
|
|
32
|
+
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
33
|
+
const response = await contract[methodName](...methodArguments).call();
|
|
34
|
+
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
35
|
+
}
|
|
36
|
+
async getTransactionStatus(srcTxHash) {
|
|
37
|
+
const txReceipt = await this.getTransactionInfo(srcTxHash);
|
|
38
|
+
if (txReceipt?.receipt) {
|
|
39
|
+
if (txReceipt.result === 'FAILED') {
|
|
40
|
+
return tx_status_1.TX_STATUS.FAIL;
|
|
41
|
+
}
|
|
42
|
+
return tx_status_1.TX_STATUS.SUCCESS;
|
|
43
|
+
}
|
|
44
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets mined transaction info.
|
|
48
|
+
* @param hash Transaction hash.
|
|
49
|
+
*/
|
|
50
|
+
async getTransactionInfo(hash) {
|
|
51
|
+
return this.public.trx.getTransactionInfo(hash);
|
|
52
|
+
}
|
|
53
|
+
async getTokensBalances(userAddress, tokensAddresses) {
|
|
54
|
+
const indexOfNativeCoin = tokensAddresses.findIndex((tokenAddress) => web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.TRON, tokenAddress));
|
|
55
|
+
const promises = [];
|
|
56
|
+
if (indexOfNativeCoin !== -1) {
|
|
57
|
+
tokensAddresses.splice(indexOfNativeCoin, 1);
|
|
58
|
+
promises[1] = this.getBalance(userAddress);
|
|
59
|
+
}
|
|
60
|
+
promises[0] = this.batchMulticallTokenBalance(userAddress, tokensAddresses, 50);
|
|
61
|
+
const results = await Promise.all(promises);
|
|
62
|
+
const tokensBalances = results[0].map((tokenResults) => {
|
|
63
|
+
const { success, output } = tokenResults[0];
|
|
64
|
+
return success ? new bignumber_js_1.default(output) : new bignumber_js_1.default(0);
|
|
65
|
+
});
|
|
66
|
+
if (indexOfNativeCoin !== -1) {
|
|
67
|
+
tokensBalances.splice(indexOfNativeCoin, 0, results[1]);
|
|
68
|
+
}
|
|
69
|
+
return tokensBalances;
|
|
70
|
+
}
|
|
71
|
+
async batchMulticallTokenBalance(userAddress, tokensAddresses, batchSize) {
|
|
72
|
+
if (tokensAddresses.length > 100) {
|
|
73
|
+
const balances = [];
|
|
74
|
+
for (let i = 0; i < tokensAddresses.length; i += batchSize) {
|
|
75
|
+
const batchRequest = tokensAddresses.slice(i, i + batchSize);
|
|
76
|
+
const batchResult = await this.multicallContractsMethods(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, batchRequest.map((tokenAddress) => ({
|
|
77
|
+
contractAddress: tokenAddress,
|
|
78
|
+
methodsData: [
|
|
79
|
+
{
|
|
80
|
+
methodName: 'balanceOf',
|
|
81
|
+
methodArguments: [userAddress]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
})));
|
|
85
|
+
balances.push(...batchResult);
|
|
86
|
+
}
|
|
87
|
+
return balances;
|
|
88
|
+
}
|
|
89
|
+
return this.multicallContractsMethods(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, tokensAddresses.map((tokenAddress) => ({
|
|
90
|
+
contractAddress: tokenAddress,
|
|
91
|
+
methodsData: [
|
|
92
|
+
{
|
|
93
|
+
methodName: 'balanceOf',
|
|
94
|
+
methodArguments: [userAddress]
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
})));
|
|
25
98
|
}
|
|
26
99
|
async multicallContractsMethods(contractAbi, contractsData) {
|
|
27
100
|
const calls = contractsData.map(({ contractAddress, methodsData }) => {
|
|
@@ -48,22 +121,26 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
48
121
|
};
|
|
49
122
|
}));
|
|
50
123
|
}
|
|
51
|
-
catch {
|
|
124
|
+
catch (err) {
|
|
125
|
+
this.logger
|
|
126
|
+
? this.logger.customError('[TronAdapter_multicallContractsMethods] Error: ', err)
|
|
127
|
+
: console.debug('[TronAdapter_multicallContractsMethods] Error:', err);
|
|
52
128
|
return this.multicallContractsMethodsByOne(contractAbi, contractsData);
|
|
53
129
|
}
|
|
54
130
|
}
|
|
131
|
+
async getBlockNumber() {
|
|
132
|
+
return (await this.public.trx.getCurrentBlock()).block_header.raw_data.number;
|
|
133
|
+
}
|
|
134
|
+
async checkEnoughBalance(token, walletAddress) {
|
|
135
|
+
const balance = await this.getBalance(walletAddress, token.address);
|
|
136
|
+
return balance.gte(token.tokenAmount);
|
|
137
|
+
}
|
|
55
138
|
async multicall(calls) {
|
|
56
139
|
this.public.setAddress(this.multicallAddress);
|
|
57
140
|
const contract = await this.public.contract(tron_multicall_abi_1.TRON_MULTICALL_ABI, this.multicallAddress);
|
|
58
141
|
// @ts-ignore
|
|
59
142
|
return contract.aggregateViewCalls(calls).call();
|
|
60
143
|
}
|
|
61
|
-
async read(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
62
|
-
this.public.setAddress(contractAddress);
|
|
63
|
-
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
64
|
-
const response = await contract[methodName](...methodArguments).call();
|
|
65
|
-
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
66
|
-
}
|
|
67
144
|
multicallContractsMethodsByOne(contractAbi, contractsData) {
|
|
68
145
|
return Promise.all(contractsData.map((contractData) => {
|
|
69
146
|
return Promise.all(contractData.methodsData.map(async (methodData) => {
|
|
@@ -83,32 +160,6 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
83
160
|
}));
|
|
84
161
|
}));
|
|
85
162
|
}
|
|
86
|
-
async getTokensBalances(userAddress, tokensAddresses) {
|
|
87
|
-
const indexOfNativeCoin = tokensAddresses.findIndex((address) => web3_pure_1.Web3Pure.isNativeAddress(core_1.CHAIN_TYPE.TRON, address));
|
|
88
|
-
const promises = [];
|
|
89
|
-
if (indexOfNativeCoin !== -1) {
|
|
90
|
-
tokensAddresses.splice(indexOfNativeCoin, 1);
|
|
91
|
-
promises[1] = this.getBalance(userAddress);
|
|
92
|
-
}
|
|
93
|
-
promises[0] = this.multicallContractsMethods(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, tokensAddresses.map((tokenAddress) => ({
|
|
94
|
-
contractAddress: tokenAddress,
|
|
95
|
-
methodsData: [
|
|
96
|
-
{
|
|
97
|
-
methodArguments: [userAddress],
|
|
98
|
-
methodName: 'balanceOf'
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
})));
|
|
102
|
-
const results = await Promise.all(promises);
|
|
103
|
-
const tokensBalances = results[0].map((tokenResults) => {
|
|
104
|
-
const { success, output } = tokenResults[0];
|
|
105
|
-
return success ? new bignumber_js_1.default(output) : new bignumber_js_1.default(0);
|
|
106
|
-
});
|
|
107
|
-
if (indexOfNativeCoin !== -1) {
|
|
108
|
-
tokensBalances.splice(indexOfNativeCoin, 0, results[1]);
|
|
109
|
-
}
|
|
110
|
-
return tokensBalances;
|
|
111
|
-
}
|
|
112
163
|
async callForTokensInfo(tokenAddresses) {
|
|
113
164
|
const tokenFields = ['decimals', 'symbol', 'name'];
|
|
114
165
|
const nativeTokenIndex = tokenAddresses.findIndex((address) => web3_pure_1.Web3Pure.isNativeAddress(core_1.CHAIN_TYPE.TRON, address));
|
|
@@ -184,6 +235,12 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
184
235
|
...(feeLimit && { feeLimit })
|
|
185
236
|
};
|
|
186
237
|
}
|
|
238
|
+
async read(contractAddress, contractAbi, methodName, methodArguments = []) {
|
|
239
|
+
this.public.setAddress(contractAddress);
|
|
240
|
+
const contract = await this.public.contract(contractAbi, contractAddress);
|
|
241
|
+
const response = await contract[methodName](...methodArguments).call();
|
|
242
|
+
return tron_web3_pure_1.TronWeb3Pure.flattenParameterToPrimitive(response);
|
|
243
|
+
}
|
|
187
244
|
static flattenTypesToString(abiInputs) {
|
|
188
245
|
return (abiInputs?.map((abiInput) => {
|
|
189
246
|
if (abiInput.type === 'tuple' || abiInput.type.includes('tuple')) {
|
|
@@ -195,38 +252,46 @@ class TronAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
195
252
|
return abiInput.type;
|
|
196
253
|
}) || []);
|
|
197
254
|
}
|
|
255
|
+
async getAllowance(fromTokenAddress, ownerAddress, spenderAddress) {
|
|
256
|
+
const [decimals, allowance] = await Promise.all([
|
|
257
|
+
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'decimals'),
|
|
258
|
+
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'allowance', [ownerAddress, spenderAddress])
|
|
259
|
+
]);
|
|
260
|
+
const allowanceWeiBN = new bignumber_js_1.default(allowance);
|
|
261
|
+
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
262
|
+
return { allowanceNonWei, allowanceWei: allowanceWeiBN };
|
|
263
|
+
}
|
|
198
264
|
async needApprove(from, walletAddress, spender) {
|
|
199
265
|
if (from.isNative)
|
|
200
266
|
return false;
|
|
201
267
|
const { allowanceWei } = await this.getAllowance(from.address, walletAddress, spender);
|
|
202
268
|
return allowanceWei.lt(from.weiAmount);
|
|
203
269
|
}
|
|
270
|
+
async approveTokens(tokenAddress, spenderAddress, amount = 'infinity', options = {}) {
|
|
271
|
+
try {
|
|
272
|
+
const contract = await this.signer.wallet.contract(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, tokenAddress);
|
|
273
|
+
const rawValue = amount === 'infinity' ? new bignumber_js_1.default(2).pow(256).minus(1) : amount;
|
|
274
|
+
const transactionHash = await contract.approve(spenderAddress, rawValue.toFixed(0)).send({
|
|
275
|
+
...(options.feeLimit && {
|
|
276
|
+
feeLimit: (0, options_1.stringifyAmount)(options.feeLimit)
|
|
277
|
+
})
|
|
278
|
+
});
|
|
279
|
+
if (options.onTransactionHash) {
|
|
280
|
+
options.onTransactionHash(transactionHash);
|
|
281
|
+
}
|
|
282
|
+
return transactionHash;
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
console.error('Approve execution error: ', err);
|
|
286
|
+
throw (0, parse_tron_error_1.parseTronError)(err);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
204
289
|
encodeApprove(tokenAddress, spenderAddress, amount) {
|
|
205
290
|
const amountWei = amount ?? new bignumber_js_1.default(2).pow(256).minus(1).toFixed();
|
|
206
|
-
return
|
|
291
|
+
return TronAdapter.encodeMethodCall(tokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'approve', [
|
|
207
292
|
{ type: 'address', value: spenderAddress },
|
|
208
293
|
{ type: 'uint256', value: amountWei }
|
|
209
294
|
]);
|
|
210
295
|
}
|
|
211
|
-
async getAllowance(fromTokenAddress, walletAddress, spender) {
|
|
212
|
-
const [contract, decimals, allowance] = await Promise.all([
|
|
213
|
-
this.public.contract(trc_20_contract_abi_1.TRC20_CONTRACT_ABI, fromTokenAddress),
|
|
214
|
-
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'decimals'),
|
|
215
|
-
this.read(fromTokenAddress, trc_20_contract_abi_1.TRC20_CONTRACT_ABI, 'allowance', [spender])
|
|
216
|
-
]);
|
|
217
|
-
const allowanceWeiBN = new bignumber_js_1.default(allowance);
|
|
218
|
-
const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
|
|
219
|
-
return { allowanceNonWei, allowanceWei: allowanceWeiBN };
|
|
220
|
-
}
|
|
221
|
-
async write(contractAddress, methodSignature, parameters) {
|
|
222
|
-
const transaction = await this.wallet.transactionBuilder.triggerSmartContract(contractAddress, methodSignature, {}, parameters, this.walletAddress);
|
|
223
|
-
const signedTransaction = await this.wallet.trx.sign(transaction.transaction);
|
|
224
|
-
const receipt = await this.wallet.trx.sendRawTransaction(signedTransaction);
|
|
225
|
-
return receipt.transaction.txID;
|
|
226
|
-
}
|
|
227
|
-
async approve(fromAddress, tokenAddress, spenderAddress, amount) {
|
|
228
|
-
const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
|
|
229
|
-
return this.write(config.to, config.signature, config.arguments);
|
|
230
|
-
}
|
|
231
296
|
}
|
|
232
297
|
exports.TronAdapter = TronAdapter;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTronError = parseTronError;
|
|
4
|
+
const tron_insufficient_native_balance_1 = require("../../../../errors/blockchain/tron-insufficient-native-balance");
|
|
5
|
+
const tron_transaction_expired_1 = require("../../../../errors/blockchain/tron-transaction-expired");
|
|
6
|
+
const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
|
|
7
|
+
const errors_1 = require("../../utils/errors");
|
|
8
|
+
function parseTronError(err) {
|
|
9
|
+
if (err?.includes?.('Confirmation declined by user')) {
|
|
10
|
+
throw new user_reject_error_1.UserRejectError();
|
|
11
|
+
}
|
|
12
|
+
const message = err?.message;
|
|
13
|
+
if (message?.includes('balance is not sufficient')) {
|
|
14
|
+
throw new tron_insufficient_native_balance_1.TronInsufficientNativeBalance();
|
|
15
|
+
}
|
|
16
|
+
if (message?.includes('Transaction expired')) {
|
|
17
|
+
throw new tron_transaction_expired_1.TronTransactionExpired();
|
|
18
|
+
}
|
|
19
|
+
return (0, errors_1.parseError)(err);
|
|
20
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Abi } from 'viem';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { ICustomLogger, Token, TokenAmount, BlockchainName } from '@cryptorubic/core';
|
|
4
|
+
import { AbstractAdapterSigner } from './signer/abstract-adapter-signer';
|
|
5
|
+
import { MethodData } from '../models/web3-public-models/method-data';
|
|
6
|
+
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
7
|
+
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
8
|
+
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
9
|
+
export declare abstract class AbstractAdapter<P, W, B extends BlockchainName, SendTxParams extends object = {}, SendTxResponse = {}> {
|
|
10
|
+
abstract signer: AbstractAdapterSigner<W, SendTxParams, SendTxResponse>;
|
|
11
|
+
protected readonly logger?: ICustomLogger;
|
|
12
|
+
readonly blockchain: B;
|
|
13
|
+
/**
|
|
14
|
+
* used to pass public pointer in signer constructor
|
|
15
|
+
*/
|
|
16
|
+
private _publicRef;
|
|
17
|
+
protected set public(value: P | null);
|
|
18
|
+
get public(): P;
|
|
19
|
+
get publicRef(): {
|
|
20
|
+
public: P | null;
|
|
21
|
+
};
|
|
22
|
+
get connected(): boolean;
|
|
23
|
+
protected constructor(blockchain: B, logger?: ICustomLogger);
|
|
24
|
+
/**
|
|
25
|
+
* Used to set this.public property, if it's not set - you can't send rpc requests to blockchain.
|
|
26
|
+
* Mostly you need to instantiate it at the same time as BlockchainAdapterFactoryService.createAdapter() called.
|
|
27
|
+
* In rubic-app it's called on wallet connection to prevent unnecessary rpc requests `net_listening` from viem library.
|
|
28
|
+
*/
|
|
29
|
+
abstract initWeb3Client(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Gets account native or token balance in wei.
|
|
32
|
+
* @param userAddress Wallet address, whose balance you want to find out.
|
|
33
|
+
* @param tokenAddress Address of the smart-contract corresponding to the token,
|
|
34
|
+
*/
|
|
35
|
+
abstract getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
36
|
+
abstract getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
37
|
+
abstract checkEnoughBalance(token: TokenAmount, walletAddress: string): Promise<boolean>;
|
|
38
|
+
abstract callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Calls pure method of smart-contract and returns its output value.
|
|
41
|
+
* @param contractAddress Address of smart-contract which method is to be executed.
|
|
42
|
+
* @param contractAbi Abi of smart-contract which method is to be executed.
|
|
43
|
+
* @param methodName Called method name.
|
|
44
|
+
* @param methodArguments Method arguments.
|
|
45
|
+
* @param options Transaction options.
|
|
46
|
+
*/
|
|
47
|
+
abstract callContractMethod<T extends Web3PrimitiveType = string>(contractAddress: string, contractAbi: Abi, methodName: string, methodArguments?: unknown[], options?: object): Promise<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets token info by address.
|
|
50
|
+
* @param tokenAddress Address of token.
|
|
51
|
+
* @param tokenFields Token's fields to get.
|
|
52
|
+
*/
|
|
53
|
+
callForTokenInfo(tokenAddress: string): Promise<Token<BlockchainName>>;
|
|
54
|
+
/**
|
|
55
|
+
* Checks that user has enough balance.
|
|
56
|
+
* @param userAddress Wallet address, which contains tokens.
|
|
57
|
+
* @param token Token to check balance of.
|
|
58
|
+
* @param requiredAmount Required user balance in Eth units.
|
|
59
|
+
*/
|
|
60
|
+
checkBalance(token: Token, requiredAmount: BigNumber, userAddress: string): Promise<void | never>;
|
|
61
|
+
/**
|
|
62
|
+
* Uses multicall to make many methods calls in several contracts.
|
|
63
|
+
* @param contractAbi Target contract abi.
|
|
64
|
+
* @param contractsData Contract addresses and methods data, containing methods' names and arguments.
|
|
65
|
+
*/
|
|
66
|
+
abstract multicallContractsMethods<Output extends Web3PrimitiveType>(contractAbi: Abi, contractsData: {
|
|
67
|
+
contractAddress: string;
|
|
68
|
+
methodsData: MethodData[];
|
|
69
|
+
}[]): Promise<ContractMulticallResponse<Output>[][]>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets last block number.
|
|
72
|
+
* @returns Block number.
|
|
73
|
+
*/
|
|
74
|
+
abstract getBlockNumber(): Promise<number | {
|
|
75
|
+
blockNumber: number;
|
|
76
|
+
workchain: number;
|
|
77
|
+
}>;
|
|
78
|
+
needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string | BigNumber): Promise<boolean>;
|
|
79
|
+
handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
|
|
80
|
+
static getRandomBytes(bytes: number): string;
|
|
81
|
+
abstract read<T>(...args: unknown[]): Promise<T>;
|
|
82
|
+
abstract getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
83
|
+
getSrcTxStatus(blockchain: BlockchainName, srcTxHash: string): Promise<TxStatus>;
|
|
84
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAdapter = void 0;
|
|
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");
|
|
7
|
+
const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
8
|
+
const waitFor_1 = require("../utils/waitFor");
|
|
9
|
+
class AbstractAdapter {
|
|
10
|
+
set public(value) {
|
|
11
|
+
this._publicRef.public = value;
|
|
12
|
+
}
|
|
13
|
+
get public() {
|
|
14
|
+
if (!this._publicRef.public) {
|
|
15
|
+
const msg = `Trying to access undefined public client in ${this.blockchain} adapter.`;
|
|
16
|
+
this.logger?.customLog(msg);
|
|
17
|
+
throw new Error(msg);
|
|
18
|
+
}
|
|
19
|
+
return this._publicRef.public;
|
|
20
|
+
}
|
|
21
|
+
get publicRef() {
|
|
22
|
+
return this._publicRef;
|
|
23
|
+
}
|
|
24
|
+
get connected() {
|
|
25
|
+
return !!this._publicRef.public;
|
|
26
|
+
}
|
|
27
|
+
constructor(blockchain, logger) {
|
|
28
|
+
/**
|
|
29
|
+
* used to pass public pointer in signer constructor
|
|
30
|
+
*/
|
|
31
|
+
this._publicRef = { public: null };
|
|
32
|
+
this.blockchain = blockchain;
|
|
33
|
+
if (logger) {
|
|
34
|
+
this.logger = logger;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets token info by address.
|
|
39
|
+
* @param tokenAddress Address of token.
|
|
40
|
+
* @param tokenFields Token's fields to get.
|
|
41
|
+
*/
|
|
42
|
+
async callForTokenInfo(tokenAddress) {
|
|
43
|
+
return (await this.callForTokensInfo([tokenAddress]))[0];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks that user has enough balance.
|
|
47
|
+
* @param userAddress Wallet address, which contains tokens.
|
|
48
|
+
* @param token Token to check balance of.
|
|
49
|
+
* @param requiredAmount Required user balance in Eth units.
|
|
50
|
+
*/
|
|
51
|
+
async checkBalance(token, requiredAmount, userAddress) {
|
|
52
|
+
const enoughBalance = await this.checkEnoughBalance(new core_1.TokenAmount({ ...token, tokenAmount: requiredAmount }), userAddress);
|
|
53
|
+
if (!enoughBalance) {
|
|
54
|
+
throw new insufficient_funds_error_1.InsufficientFundsError(token.symbol);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
needPreswapAction(token, contractAddress, walletAddress, amount) {
|
|
58
|
+
return Promise.resolve(false);
|
|
59
|
+
}
|
|
60
|
+
handlePreswap(contractAddress, walletAddress, tokenAmount) {
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
}
|
|
63
|
+
static getRandomBytes(bytes) {
|
|
64
|
+
const randomBytes = crypto.getRandomValues(new Uint8Array(bytes));
|
|
65
|
+
return (0, viem_1.bytesToHex)(randomBytes);
|
|
66
|
+
}
|
|
67
|
+
async getSrcTxStatus(blockchain, srcTxHash) {
|
|
68
|
+
try {
|
|
69
|
+
const status = await this.getTransactionStatus(srcTxHash);
|
|
70
|
+
if (status === tx_status_1.TX_STATUS.FAIL && blockchain === core_1.BLOCKCHAIN_NAME.ZK_SYNC) {
|
|
71
|
+
const zkSyncAwarenessTime = 4000;
|
|
72
|
+
await (0, waitFor_1.waitFor)(zkSyncAwarenessTime);
|
|
73
|
+
return this.getTransactionStatus(srcTxHash);
|
|
74
|
+
}
|
|
75
|
+
return status;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.AbstractAdapter = AbstractAdapter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
3
|
+
export declare abstract class AbstractAdapterSigner<ClientWallet, SendTxParams, SendTxResponse> {
|
|
4
|
+
protected readonly httpClient: HttpClient;
|
|
5
|
+
protected readonly logger?: ICustomLogger | undefined;
|
|
6
|
+
protected readonly clientParams?: ClientAdaptersFactoryParams | undefined;
|
|
7
|
+
protected get apiUrl(): string;
|
|
8
|
+
private _walletAddress;
|
|
9
|
+
get walletAddress(): string;
|
|
10
|
+
private _wallet;
|
|
11
|
+
get wallet(): ClientWallet;
|
|
12
|
+
constructor(httpClient: HttpClient, logger?: ICustomLogger | undefined, clientParams?: ClientAdaptersFactoryParams | undefined);
|
|
13
|
+
abstract getBlockchainName(): Promise<BlockchainName | undefined>;
|
|
14
|
+
abstract sendTransaction(params: SendTxParams): Promise<SendTxResponse>;
|
|
15
|
+
abstract write(...args: unknown[]): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks, that selected blockchain in wallet is equal to passed blockchain.
|
|
18
|
+
*/
|
|
19
|
+
checkBlockchainCorrect(blockchainName: BlockchainName): Promise<void | never>;
|
|
20
|
+
setWalletAddress(newWalletAddress: string): void;
|
|
21
|
+
setWallet(wallet: ClientWallet): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractAdapterSigner = void 0;
|
|
4
|
+
const rubic_api_link_mapping_1 = require("../../../constants/rubic-api-link-mapping");
|
|
5
|
+
const wrong_network_error_1 = require("../../../../errors/swap/wrong-network.error");
|
|
6
|
+
class AbstractAdapterSigner {
|
|
7
|
+
get apiUrl() {
|
|
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
|
+
}
|
|
12
|
+
const rubicApiLink = rubic_api_link_mapping_1.rubicApiLinkMapping[this.clientParams.envType];
|
|
13
|
+
return rubicApiLink ? rubicApiLink : 'https://dev1-api-v2.rubic.exchange';
|
|
14
|
+
}
|
|
15
|
+
get walletAddress() {
|
|
16
|
+
return this._walletAddress;
|
|
17
|
+
}
|
|
18
|
+
get wallet() {
|
|
19
|
+
return this._wallet;
|
|
20
|
+
}
|
|
21
|
+
constructor(httpClient, logger, clientParams) {
|
|
22
|
+
this.httpClient = httpClient;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
this.clientParams = clientParams;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks, that selected blockchain in wallet is equal to passed blockchain.
|
|
28
|
+
*/
|
|
29
|
+
async checkBlockchainCorrect(blockchainName) {
|
|
30
|
+
const userBlockchainName = await this.getBlockchainName();
|
|
31
|
+
if (userBlockchainName !== blockchainName) {
|
|
32
|
+
throw new wrong_network_error_1.WrongNetworkError(blockchainName);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
setWalletAddress(newWalletAddress) {
|
|
36
|
+
this._walletAddress = newWalletAddress;
|
|
37
|
+
}
|
|
38
|
+
setWallet(wallet) {
|
|
39
|
+
this._wallet = wallet;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.AbstractAdapterSigner = AbstractAdapterSigner;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AbiItem } from '
|
|
1
|
+
import { AbiItem } from '../../../utils/models/abi-types';
|
|
2
2
|
export declare const TRON_MULTICALL_ABI: AbiItem[];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { BlockchainName, TokenAmount } from '@cryptorubic/core';
|
|
2
2
|
import { AllowanceInfo } from './common-types';
|
|
3
|
-
import { AbstractAdapter } from '../abstract-adapter';
|
|
4
3
|
import { EvmTransactionConfig } from '../../../utils/models/evm-transaction-config';
|
|
5
|
-
import { TronTransactionConfig } from '
|
|
6
|
-
|
|
4
|
+
import { TronTransactionConfig } from '../../../utils/models/tron-transaction-config';
|
|
5
|
+
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
7
|
+
import { BasicSendTransactionOptions } from './basic-transaction-options';
|
|
8
|
+
export interface ApprovableAdapter<T> extends AbstractAdapter<any, any, BlockchainName, {}> {
|
|
7
9
|
/**
|
|
8
10
|
* @param fromTokenAddress erc20 address of checked token
|
|
9
11
|
* @param walletAddress owner wallet address
|
|
@@ -27,11 +29,13 @@ export interface ApproveAdapter<T> extends AbstractAdapter<any, any, BlockchainN
|
|
|
27
29
|
*/
|
|
28
30
|
needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
|
|
29
31
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param tokenAddress
|
|
32
|
-
* @param spenderAddress
|
|
33
|
-
* @param amount amount in
|
|
32
|
+
* Executes approve method in ERC-20 token contract.
|
|
33
|
+
* @param tokenAddress Address of the smart-contract corresponding to the token.
|
|
34
|
+
* @param spenderAddress Wallet or contract address to approve.
|
|
35
|
+
* @param amount Token amount to approve in wei.
|
|
36
|
+
* @param [options] Additional options.
|
|
37
|
+
* @returns Approval transaction receipt.
|
|
34
38
|
*/
|
|
35
|
-
|
|
39
|
+
approveTokens(tokenAddress: string, spenderAddress: string, amount: BigNumber | 'infinity', options: BasicSendTransactionOptions): Promise<string>;
|
|
36
40
|
}
|
|
37
|
-
export declare function isApprovableAdapter(adapter: AbstractAdapter<any, any, BlockchainName>): adapter is
|
|
41
|
+
export declare function isApprovableAdapter(adapter: AbstractAdapter<any, any, BlockchainName, {}>): adapter is ApprovableAdapter<EvmTransactionConfig | TronTransactionConfig>;
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isApprovableAdapter = isApprovableAdapter;
|
|
4
4
|
function isApprovableAdapter(adapter) {
|
|
5
|
-
return 'needApprove' in adapter && '
|
|
5
|
+
return 'needApprove' in adapter && 'approveTokens' in adapter && 'getAllowance' in adapter && 'encodeApprove' in adapter;
|
|
6
6
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ViemGasPrice = EIP1559ViemGas & SingleViemGasPrice;
|
|
2
|
+
export interface EIP1559ViemGas {
|
|
3
|
+
/**
|
|
4
|
+
* EIP-1559 Block base fee.
|
|
5
|
+
*/
|
|
6
|
+
baseFee?: bigint;
|
|
7
|
+
/**
|
|
8
|
+
* EIP-1559 Transaction maximum fee.
|
|
9
|
+
*/
|
|
10
|
+
maxFeePerGas?: bigint;
|
|
11
|
+
/**
|
|
12
|
+
* EIP-1559 Transaction miner's tip.
|
|
13
|
+
*/
|
|
14
|
+
maxPriorityFeePerGas?: bigint;
|
|
15
|
+
}
|
|
16
|
+
export interface SingleViemGasPrice {
|
|
17
|
+
gasPrice?: bigint;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
export interface Permit2AllowanceContractResponse {
|
|
3
|
+
amount: string;
|
|
4
|
+
expiration: string;
|
|
5
|
+
nonce: string;
|
|
6
|
+
}
|
|
7
|
+
type AllowanceBN = BigNumber;
|
|
8
|
+
type ExpirationMS = string;
|
|
9
|
+
export type Permit2AllowanceData = [AllowanceBN, ExpirationMS];
|
|
10
|
+
export {};
|