@cryptorubic/web3 0.14.0-alpha.solana-gas.12 → 1.0.0-alpha.no-sdk.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +4 -7
- package/src/index.js +4 -7
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +35 -0
- package/src/lib/adapter/adapters/{bitcoin-adapter.js → adapter-bitcoin/bitcoin-adapter.js} +16 -6
- package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.d.ts +16 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.js +119 -0
- 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-trade-types.d.ts +7 -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-evm/client/evm-adapter-client.d.ts +80 -0
- package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.js +307 -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/{evm-adapter.d.ts → adapter-evm/evm-adapter.d.ts} +25 -17
- package/src/lib/adapter/adapters/{evm-adapter.js → adapter-evm/evm-adapter.js} +155 -75
- 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/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/client/solana-adapter-client.d.ts +15 -0
- package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.js +94 -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/solana-utils → adapter-solana/services}/solana-tokens-service.js +8 -10
- package/src/lib/adapter/adapters/{solana-adapter.d.ts → adapter-solana/solana-adapter.d.ts} +23 -17
- package/src/lib/adapter/adapters/{solana-adapter.js → adapter-solana/solana-adapter.js} +36 -98
- package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.d.ts +15 -0
- package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.js +58 -0
- 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/sui-adapter.d.ts +29 -0
- package/src/lib/adapter/adapters/{sui-adapter.js → adapter-sui/sui-adapter.js} +25 -6
- package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.d.ts +41 -0
- package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.js +164 -0
- 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 +4 -4
- package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.js +0 -5
- package/src/lib/adapter/adapters/adapter-ton/services/ton-client/ton-client.d.ts +6 -0
- package/src/lib/adapter/adapters/adapter-ton/services/ton-client/ton-client.js +18 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +29 -0
- package/src/lib/adapter/adapters/{ton-adapter.js → adapter-ton/ton-adapter.js} +40 -50
- package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.d.ts +27 -0
- package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.js +91 -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/{tron-adapter.d.ts → adapter-tron/tron-adapter.d.ts} +21 -18
- package/src/lib/adapter/adapters/{tron-adapter.js → adapter-tron/tron-adapter.js} +45 -68
- 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 +48 -0
- package/src/lib/adapter/adapters/common/abstract-adapter.js +67 -0
- package/src/lib/adapter/adapters/common/client/abstract-adapter-client.d.ts +24 -0
- package/src/lib/adapter/adapters/common/client/abstract-adapter-client.js +59 -0
- package/src/lib/adapter/adapters/models/approve-adapter.d.ts +4 -4
- package/src/lib/adapter/adapters/models/approve-adapter.js +3 -3
- 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 +61 -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/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 +18 -13
- package/src/lib/adapter/blockchain-adapter-factory.service.js +35 -66
- package/src/lib/adapter/constants/models/create-factory-params.d.ts +8 -0
- package/src/lib/adapter/constants/models/create-factory-params.js +2 -0
- 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/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/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/web3-types/common-web3-pure.js +2 -4
- package/src/lib/utils/web3-types/near-web3-pure.js +1 -1
- package/src/lib/utils/web3-types/solana-web3-pure.js +1 -1
- package/src/lib/utils/web3-types/sui-web3-pure.js +2 -2
- package/src/lib/adapter/adapters/abstract-adapter.d.ts +0 -23
- package/src/lib/adapter/adapters/abstract-adapter.js +0 -61
- package/src/lib/adapter/adapters/bitcoin-adapter.d.ts +0 -18
- package/src/lib/adapter/adapters/models/adapter-factory-params.d.ts +0 -7
- 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/utils/models/solana-transaction-config.d.ts +0 -6
- /package/src/lib/adapter/adapters/{models/adapter-factory-params.js → adapter-bitcoin/models/btc-send-tx-params.js} +0 -0
- /package/src/lib/adapter/adapters/{models/gas-price.js → adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.js} +0 -0
- /package/src/lib/{utils/models/solana-transaction-config.js → adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.js} +0 -0
- /package/src/lib/adapter/adapters/{utils/solana-utils → adapter-solana/services}/solana-tokens-service.d.ts +0 -0
- /package/src/lib/adapter/adapters/models/{gas-price.d.ts → evm-web3-public-models/gas-price.d.ts} +0 -0
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import { Abi
|
|
2
|
-
import { AbstractAdapter } from './abstract-adapter';
|
|
1
|
+
import { Abi } from 'viem';
|
|
3
2
|
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
4
3
|
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
5
4
|
import BigNumber from 'bignumber.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
|
+
import { SolanaRawInstruction } from '../models/solana-web3-types';
|
|
7
|
+
import { SolanaSendTxParams } from './models/solana-send-tx-params';
|
|
8
|
+
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
9
|
+
import { SolanaWeb3 } from '../../constants/models/solana-web3';
|
|
10
|
+
import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
11
|
+
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
12
|
+
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
8
13
|
export declare const NATIVE_SOLANA_MINT_ADDRESS = "So11111111111111111111111111111111111111111";
|
|
9
|
-
export declare
|
|
10
|
-
export declare class SolanaAdapter extends AbstractAdapter<Connection, Connection, SolanaBlockchainName> {
|
|
14
|
+
export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
|
|
11
15
|
private readonly httpClient;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
read<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
15
|
-
write<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[]): Promise<T>;
|
|
16
|
-
multicallByContract<T>(_contracts: MulticallParameters, _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
17
|
-
multicallByAddress<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[][], _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
18
|
-
simulateTransaction(config: SolanaTxConfig, timeout?: number): Promise<string>;
|
|
19
|
-
private getFailedIxProgramId;
|
|
20
|
-
private getAddressLookupTableAccounts;
|
|
21
|
-
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
22
|
-
getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
16
|
+
readonly client: AbstractAdapterClient<SolanaWeb3, SolanaSendTxParams, string>;
|
|
17
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
23
18
|
/**
|
|
24
19
|
* Gets balance of multiple tokens.
|
|
25
20
|
* @param address Wallet address.
|
|
26
21
|
* @param tokensAddresses Tokens addresses.
|
|
27
22
|
*/
|
|
28
23
|
getTokensBalances(address: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
24
|
+
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
25
|
+
getBlockNumber(): Promise<number | {
|
|
26
|
+
blockNumber: number;
|
|
27
|
+
workchain: number;
|
|
28
|
+
}>;
|
|
29
|
+
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
|
+
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
33
|
+
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
34
|
+
getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
29
35
|
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<SolanaBlockchainName>[]>;
|
|
30
36
|
parseRawInstruction(rawInstruction: SolanaRawInstruction[], dataFormat: BufferEncoding): TransactionInstruction[];
|
|
31
37
|
parseLUTAddresses(lookupTableAddresses: string[]): Promise<AddressLookupTableAccount[]>;
|
|
@@ -1,27 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaAdapter = exports.
|
|
3
|
+
exports.SolanaAdapter = exports.NATIVE_SOLANA_MINT_ADDRESS = void 0;
|
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const abstract_adapter_1 = require("./abstract-adapter");
|
|
6
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
7
6
|
const core_1 = require("@cryptorubic/core");
|
|
8
|
-
const web3_pure_1 = require("../../utils/web3-pure");
|
|
9
7
|
const bignumber_js_1 = require("bignumber.js");
|
|
10
8
|
const bs58_1 = require("bs58");
|
|
11
9
|
const js_base64_1 = require("js-base64");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
10
|
+
const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
11
|
+
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
12
|
+
const solana_tokens_service_1 = require("./services/solana-tokens-service");
|
|
13
|
+
const solana_adapter_client_1 = require("./client/solana-adapter-client");
|
|
14
14
|
exports.NATIVE_SOLANA_MINT_ADDRESS = 'So11111111111111111111111111111111111111111';
|
|
15
|
-
/* minimal amount for tx (in lamports) */
|
|
16
|
-
exports.DEFAULT_CU_LIMIT = 400_000;
|
|
17
15
|
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
18
|
-
httpClient
|
|
19
|
-
constructor(rpcList, httpClient, logger) {
|
|
16
|
+
constructor(rpcList, httpClient, logger, rubicAppParams) {
|
|
20
17
|
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
21
18
|
this.httpClient = httpClient;
|
|
22
|
-
this.public = this.
|
|
19
|
+
this.public = this.createConection(rpcList);
|
|
20
|
+
this.client = new solana_adapter_client_1.SolanaAdapterClient(this.public, httpClient, logger, rubicAppParams);
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Gets balance of multiple tokens.
|
|
24
|
+
* @param address Wallet address.
|
|
25
|
+
* @param tokensAddresses Tokens addresses.
|
|
26
|
+
*/
|
|
27
|
+
async getTokensBalances(address, tokensAddresses) {
|
|
28
|
+
const resp = await this.public._rpcRequest('getTokenAccountsByOwner', [address, { programId: spl_token_1.TOKEN_PROGRAM_ID }, { encoding: 'jsonParsed' }]);
|
|
29
|
+
const tokenInfo = new Map(resp.result.value.map((el) => {
|
|
30
|
+
const { mint, tokenAmount } = el.account.data.parsed.info;
|
|
31
|
+
return [mint, tokenAmount.amount];
|
|
32
|
+
}));
|
|
33
|
+
const nativeSolBalance = await this.public.getBalanceAndContext(new web3_js_1.PublicKey(address), 'confirmed');
|
|
34
|
+
return tokensAddresses.map((tokenAddress) => {
|
|
35
|
+
if (tokenAddress === exports.NATIVE_SOLANA_MINT_ADDRESS) {
|
|
36
|
+
return new bignumber_js_1.default(nativeSolBalance.value.toString());
|
|
37
|
+
}
|
|
38
|
+
const tokenWithBalance = tokenInfo.get(tokenAddress);
|
|
39
|
+
return new bignumber_js_1.default(tokenWithBalance || NaN);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
multicallContractsMethods() {
|
|
43
|
+
throw new Error('Method not implemented.');
|
|
44
|
+
}
|
|
45
|
+
getBlockNumber() {
|
|
46
|
+
return this.public.getBlockHeight('finalized');
|
|
47
|
+
}
|
|
48
|
+
createConection(rpcList) {
|
|
25
49
|
if (!rpcList?.[0]) {
|
|
26
50
|
this.logger?.customError('RPC list is empty');
|
|
27
51
|
return null;
|
|
@@ -36,73 +60,7 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
36
60
|
async write(_address, _abi, _method, _methodArgs = []) {
|
|
37
61
|
throw new Error('Method multicall is not supported');
|
|
38
62
|
}
|
|
39
|
-
async
|
|
40
|
-
throw new Error('Method multicall is not supported');
|
|
41
|
-
}
|
|
42
|
-
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
43
|
-
throw new Error('Method multicall is not supported');
|
|
44
|
-
}
|
|
45
|
-
async simulateTransaction(config, timeout = 15_000) {
|
|
46
|
-
try {
|
|
47
|
-
const bufferData = config.data.startsWith('0x') ? Buffer.from(config.data.slice(2), 'hex') : Buffer.from(config.data, 'base64');
|
|
48
|
-
const { blockhash } = await this.public.getLatestBlockhash();
|
|
49
|
-
const tx = web3_js_1.VersionedTransaction.deserialize(bufferData);
|
|
50
|
-
tx.message.recentBlockhash = blockhash;
|
|
51
|
-
const simulation = this.public.simulateTransaction(tx, {
|
|
52
|
-
replaceRecentBlockhash: true,
|
|
53
|
-
commitment: 'confirmed',
|
|
54
|
-
accounts: {
|
|
55
|
-
encoding: 'base64',
|
|
56
|
-
addresses: [config.walletAddress]
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const resp = await (0, timeout_1.withTimeout)(simulation, timeout, 'Solana Simulation Timeout!');
|
|
60
|
-
const err = resp.value.err;
|
|
61
|
-
const defineCuLimit = () => {
|
|
62
|
-
const cuLimit = resp.value.unitsConsumed || 0;
|
|
63
|
-
const defaultGreaterEstimated = new bignumber_js_1.default(exports.DEFAULT_CU_LIMIT).gt(cuLimit);
|
|
64
|
-
return new bignumber_js_1.default(defaultGreaterEstimated ? exports.DEFAULT_CU_LIMIT : cuLimit).toFixed(0);
|
|
65
|
-
};
|
|
66
|
-
if (err) {
|
|
67
|
-
if (Array.isArray(err['InstructionError'])) {
|
|
68
|
-
const [failedInstructionIdx, errorData] = err['InstructionError'];
|
|
69
|
-
const failedInstructionProgramId = await this.getFailedIxProgramId(tx, failedInstructionIdx);
|
|
70
|
-
this.logger?.customLog('FAILED INSTRUCTION INFO', { programId: failedInstructionProgramId, errorData });
|
|
71
|
-
const weirdError = errorData?.Custom === 1;
|
|
72
|
-
if (weirdError)
|
|
73
|
-
return defineCuLimit();
|
|
74
|
-
}
|
|
75
|
-
throw new Error('Transaction simulation failed.');
|
|
76
|
-
}
|
|
77
|
-
return defineCuLimit();
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
this.logger?.customError('Error while simulating transaction', err);
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async getFailedIxProgramId(tx, failedInstructionIdx) {
|
|
85
|
-
const lutKeys = (tx.message.addressTableLookups ?? []).map((l) => l.accountKey.toBase58());
|
|
86
|
-
const lutAccounts = lutKeys.length ? await this.getAddressLookupTableAccounts(lutKeys) : [];
|
|
87
|
-
const decompiled = web3_js_1.TransactionMessage.decompile(tx.message, { addressLookupTableAccounts: lutAccounts });
|
|
88
|
-
const programId = decompiled.instructions[failedInstructionIdx].programId;
|
|
89
|
-
return programId.toBase58();
|
|
90
|
-
}
|
|
91
|
-
async getAddressLookupTableAccounts(keys) {
|
|
92
|
-
const result = [];
|
|
93
|
-
const infos = await this.public.getMultipleAccountsInfo(keys.map((k) => new web3_js_1.PublicKey(k)));
|
|
94
|
-
keys.forEach((address, i) => {
|
|
95
|
-
const ai = infos[i];
|
|
96
|
-
if (ai) {
|
|
97
|
-
const alt = new web3_js_1.AddressLookupTableAccount({
|
|
98
|
-
key: new web3_js_1.PublicKey(address),
|
|
99
|
-
state: web3_js_1.AddressLookupTableAccount.deserialize(ai.data)
|
|
100
|
-
});
|
|
101
|
-
result.push(alt);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
63
|
+
async simulateTransaction(_config, _from) { }
|
|
106
64
|
async checkEnoughBalance(token, walletAddress) {
|
|
107
65
|
const balance = await this.getBalance(walletAddress, token.address);
|
|
108
66
|
return balance.gte(token.tokenAmount);
|
|
@@ -116,26 +74,6 @@ class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
116
74
|
const balance = await this.public.getBalanceAndContext(new web3_js_1.PublicKey(userAddress), 'confirmed');
|
|
117
75
|
return new bignumber_js_1.default(balance.value.toString());
|
|
118
76
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Gets balance of multiple tokens.
|
|
121
|
-
* @param address Wallet address.
|
|
122
|
-
* @param tokensAddresses Tokens addresses.
|
|
123
|
-
*/
|
|
124
|
-
async getTokensBalances(address, tokensAddresses) {
|
|
125
|
-
const resp = await this.public._rpcRequest('getTokenAccountsByOwner', [address, { programId: spl_token_1.TOKEN_PROGRAM_ID }, { encoding: 'jsonParsed' }]);
|
|
126
|
-
const tokenInfo = new Map(resp.result.value.map((el) => {
|
|
127
|
-
const { mint, tokenAmount } = el.account.data.parsed.info;
|
|
128
|
-
return [mint, tokenAmount.amount];
|
|
129
|
-
}));
|
|
130
|
-
const nativeSolBalance = await this.public.getBalanceAndContext(new web3_js_1.PublicKey(address), 'confirmed');
|
|
131
|
-
return tokensAddresses.map((tokenAddress) => {
|
|
132
|
-
if (tokenAddress === exports.NATIVE_SOLANA_MINT_ADDRESS) {
|
|
133
|
-
return new bignumber_js_1.default(nativeSolBalance.value.toString());
|
|
134
|
-
}
|
|
135
|
-
const tokenWithBalance = tokenInfo.get(tokenAddress);
|
|
136
|
-
return new bignumber_js_1.default(tokenWithBalance || NaN);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
77
|
async callForTokensInfo(tokenAddresses) {
|
|
140
78
|
const nativeToken = core_1.nativeTokensList[core_1.BLOCKCHAIN_NAME.SOLANA];
|
|
141
79
|
const nativeTokenIndex = tokenAddresses.findIndex((address) => web3_pure_1.Web3Pure.isNativeAddress(core_1.CHAIN_TYPE.SOLANA, address));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
+
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
3
|
+
import { RubicAppAdaptersFactoryParams } from '../../../constants/models/create-factory-params';
|
|
4
|
+
import { SuiSendTxParams } from '../models/sui-send-tx-params';
|
|
5
|
+
import { WalletAdapter } from '@suiet/wallet-sdk';
|
|
6
|
+
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
7
|
+
import { ExecuteTransactionBlockParams, SuiClient, SuiTransactionBlockResponse } from '@mysten/sui/dist/cjs/client';
|
|
8
|
+
export declare class SuiAdapterClient extends AbstractAdapterClient<WalletAdapter, SuiSendTxParams, string> {
|
|
9
|
+
private readonly suiClient;
|
|
10
|
+
constructor(suiClient: SuiClient, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
11
|
+
getBlockchainName(): Promise<BlockchainName>;
|
|
12
|
+
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
13
|
+
sendTransaction(params: SuiSendTxParams): Promise<string>;
|
|
14
|
+
executeTxBlock(params: ExecuteTransactionBlockParams): Promise<SuiTransactionBlockResponse>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiAdapterClient = void 0;
|
|
4
|
+
const core_1 = require("@cryptorubic/core");
|
|
5
|
+
const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
|
|
6
|
+
const user_reject_error_1 = require("packages/web3/src/lib/errors/blockchain/user-reject.error");
|
|
7
|
+
const parse_evm_error_1 = require("../../adapter-evm/utils/parse-evm-error");
|
|
8
|
+
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
9
|
+
class SuiAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
10
|
+
constructor(suiClient, httpClient, logger, rubicAppParams) {
|
|
11
|
+
super(httpClient, logger, rubicAppParams);
|
|
12
|
+
this.suiClient = suiClient;
|
|
13
|
+
}
|
|
14
|
+
getBlockchainName() {
|
|
15
|
+
return Promise.resolve(core_1.BLOCKCHAIN_NAME.SUI);
|
|
16
|
+
}
|
|
17
|
+
async getTransactionStatus(srcTxHash) {
|
|
18
|
+
try {
|
|
19
|
+
const txDetails = await this.suiClient.getTransactionBlock({ digest: srcTxHash });
|
|
20
|
+
const status = txDetails?.effects?.status.status;
|
|
21
|
+
if (!status) {
|
|
22
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
23
|
+
}
|
|
24
|
+
return status === 'success' ? tx_status_1.TX_STATUS.SUCCESS : tx_status_1.TX_STATUS.FAIL;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async sendTransaction(params) {
|
|
31
|
+
try {
|
|
32
|
+
const account = this.clientWallet.accounts[0];
|
|
33
|
+
const signedTx = await this.clientWallet.features['sui:signTransaction'].signTransaction({
|
|
34
|
+
account: account,
|
|
35
|
+
transaction: params.txOptions.transactionBlock,
|
|
36
|
+
chain: 'sui:mainnet'
|
|
37
|
+
});
|
|
38
|
+
const tx = await this.executeTxBlock({
|
|
39
|
+
transactionBlock: signedTx.bytes,
|
|
40
|
+
signature: signedTx.signature
|
|
41
|
+
});
|
|
42
|
+
params.txOptions.onTransactionHash?.(tx.digest);
|
|
43
|
+
return tx.digest;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (err?.message.includes('User rejected the request.') ||
|
|
47
|
+
err?.message.includes('User rejection | (UserRejectionError:-4005)')) {
|
|
48
|
+
throw new user_reject_error_1.UserRejectError();
|
|
49
|
+
}
|
|
50
|
+
console.error(`Send transaction error. ${err}`);
|
|
51
|
+
throw (0, parse_evm_error_1.parseEvmError)(err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
executeTxBlock(params) {
|
|
55
|
+
return this.suiClient.executeTransactionBlock(params);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.SuiAdapterClient = SuiAdapterClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
|
|
3
|
+
export interface SuiSendTxParams {
|
|
4
|
+
txOptions: SuiTransactionOptions;
|
|
5
|
+
}
|
|
6
|
+
export interface SuiTransactionOptions extends BasicSendTransactionOptions {
|
|
7
|
+
transactionBlock: Transaction;
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Abi, MulticallResponse } from 'viem';
|
|
2
|
+
import { HttpClient, ICustomLogger, PriceTokenAmount, SuiBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
3
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
6
|
+
import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
|
|
7
|
+
import { WalletAdapter } from '@suiet/wallet-sdk';
|
|
8
|
+
import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
|
|
9
|
+
import { SuiSendTxParams } from './models/sui-send-tx-params';
|
|
10
|
+
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
11
|
+
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
12
|
+
export declare class SuiAdapter extends AbstractAdapter<SuiClient, WalletAdapter, SuiBlockchainName> {
|
|
13
|
+
readonly client: AbstractAdapterClient<WalletAdapter, SuiSendTxParams, string>;
|
|
14
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
15
|
+
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
16
|
+
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
17
|
+
getBlockNumber(): Promise<number | {
|
|
18
|
+
blockNumber: number;
|
|
19
|
+
workchain: number;
|
|
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
|
+
multicallByAddress<T>(_address: string, _abi: Abi, _method: string, _methodArgs?: unknown[][], _allowErrors?: boolean): Promise<MulticallResponse<T>[]>;
|
|
24
|
+
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
25
|
+
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<SuiBlockchainName>[]>;
|
|
26
|
+
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
27
|
+
getBalance(userAddress: string, tokenAddress: string): Promise<BigNumber>;
|
|
28
|
+
compareSuiAddress(addressA: string, addressB: string): boolean;
|
|
29
|
+
}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SuiAdapter = void 0;
|
|
4
|
-
const abstract_adapter_1 = require("./abstract-adapter");
|
|
5
4
|
const core_1 = require("@cryptorubic/core");
|
|
6
|
-
const web3_pure_1 = require("../../utils/web3-pure");
|
|
7
5
|
const client_1 = require("@mysten/sui/client");
|
|
8
6
|
const bignumber_js_1 = require("bignumber.js");
|
|
7
|
+
const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
8
|
+
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
9
|
+
const sui_adapter_client_1 = require("./client/sui-adapter-client");
|
|
9
10
|
class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
10
|
-
constructor(rpcList, logger) {
|
|
11
|
+
constructor(rpcList, httpClient, logger, rubicAppParams) {
|
|
11
12
|
super(core_1.BLOCKCHAIN_NAME.SUI, logger);
|
|
12
13
|
this.public = new client_1.SuiClient({ url: rpcList[0] });
|
|
14
|
+
this.client = new sui_adapter_client_1.SuiAdapterClient(this.public, httpClient, logger, rubicAppParams);
|
|
15
|
+
}
|
|
16
|
+
async getTokensBalances(userAddress, tokensAddresses) {
|
|
17
|
+
const allUserTokens = await this.public.getAllBalances({ owner: userAddress });
|
|
18
|
+
return tokensAddresses.map((address) => {
|
|
19
|
+
const possibleBalance = allUserTokens.find((el) => (0, core_1.compareAddresses)(address, el.coinType) || this.compareSuiAddress(address, el.coinType));
|
|
20
|
+
return new bignumber_js_1.default(possibleBalance?.totalBalance || 0);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
multicallContractsMethods() {
|
|
24
|
+
throw new Error('Method not implemented.');
|
|
25
|
+
}
|
|
26
|
+
async getBlockNumber() {
|
|
27
|
+
const epochInfo = await this.public.getEpochs({ limit: 1 });
|
|
28
|
+
const stringEpoch = epochInfo.data[0].epoch;
|
|
29
|
+
return Number(stringEpoch);
|
|
13
30
|
}
|
|
14
31
|
async read(_address, _abi, _method, _methodArgs = []) {
|
|
15
32
|
throw new Error('Method read is not supported');
|
|
@@ -17,9 +34,6 @@ class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
17
34
|
async write(_address, _abi, _method, _methodArgs = []) {
|
|
18
35
|
throw new Error('Method write is not supported');
|
|
19
36
|
}
|
|
20
|
-
async multicallByContract(_contracts, _allowErrors = true) {
|
|
21
|
-
throw new Error('Method multicall is not supported');
|
|
22
|
-
}
|
|
23
37
|
async multicallByAddress(_address, _abi, _method, _methodArgs = [], _allowErrors = true) {
|
|
24
38
|
throw new Error('Method multicall is not supported');
|
|
25
39
|
}
|
|
@@ -71,5 +85,10 @@ class SuiAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
71
85
|
const balance = await this.public.getBalance({ owner: userAddress });
|
|
72
86
|
return new bignumber_js_1.default(balance.totalBalance);
|
|
73
87
|
}
|
|
88
|
+
compareSuiAddress(addressA, addressB) {
|
|
89
|
+
const pureAddressA = addressA.split(':')[0];
|
|
90
|
+
const pureAddressB = addressB.split(':')[0];
|
|
91
|
+
return (0, core_1.compareAddresses)(new bignumber_js_1.default(pureAddressA).toFixed(), new bignumber_js_1.default(pureAddressB).toFixed());
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
exports.SuiAdapter = SuiAdapter;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
+
import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
|
|
3
|
+
import { RubicAppAdaptersFactoryParams } from '../../../constants/models/create-factory-params';
|
|
4
|
+
import { TxStatus } from '../../models/web3-public-models/tx-status';
|
|
5
|
+
import { TonSendTxParams } from '../models/ton-send-tx-params';
|
|
6
|
+
import { TonConnectUI } from '@tonconnect/ui';
|
|
7
|
+
import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
|
|
8
|
+
import { Address } from '@ton/core';
|
|
9
|
+
import { TonApiService } from '../services/ton-api.service';
|
|
10
|
+
import { TonAdapterConfig } from '../../models/ton-adapter-config';
|
|
11
|
+
import { TonTransactionConfig } from 'packages/web3/src/lib/utils/models/ton-transaction-config';
|
|
12
|
+
export declare class TonAdapterClient extends AbstractAdapterClient<TonConnectUI, TonSendTxParams, string> {
|
|
13
|
+
private readonly tonApi;
|
|
14
|
+
private readonly tonClient;
|
|
15
|
+
constructor(tonApi: TonApiService, config: TonAdapterConfig, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
|
|
16
|
+
getBlockchainName(): Promise<BlockchainName>;
|
|
17
|
+
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
18
|
+
sendTransaction(params: TonSendTxParams): Promise<string>;
|
|
19
|
+
private waitForTransactionReceipt;
|
|
20
|
+
/**
|
|
21
|
+
* Transfer asset from on wallet to another
|
|
22
|
+
* @param tokenAddress Token address to transfer
|
|
23
|
+
* @param walletAddress Wallet address to transfer from
|
|
24
|
+
* @param receiver Receiver wallet address
|
|
25
|
+
* @param amount Transfer amount
|
|
26
|
+
* @param options Transaction options
|
|
27
|
+
*/
|
|
28
|
+
transferAsset(tokenAddress: string, walletAddress: string, receiver: string, amount: string, options?: BasicSendTransactionOptions): Promise<string>;
|
|
29
|
+
private transferNative;
|
|
30
|
+
private transferJetton;
|
|
31
|
+
getTransferEncodedConfig(tokenAddress: string, walletAddress: string, receiver: string, amount: string): Promise<TonTransactionConfig>;
|
|
32
|
+
private getTransferNativeConfig;
|
|
33
|
+
private getTransferJettonConfig;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param boc Boc returned in connector.sendTransaction
|
|
37
|
+
* @returns boc converter in base 64 string
|
|
38
|
+
*/
|
|
39
|
+
fromBocToBase64Hash(boc: string): string;
|
|
40
|
+
getJettonWalletAddress(address: Address, contractAddress: Address): Promise<Address>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TonAdapterClient = void 0;
|
|
4
|
+
const core_1 = require("@cryptorubic/core");
|
|
5
|
+
const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
|
|
6
|
+
const user_reject_error_1 = require("packages/web3/src/lib/errors/blockchain/user-reject.error");
|
|
7
|
+
const tx_status_1 = require("../../models/web3-public-models/tx-status");
|
|
8
|
+
const rubic_sdk_error_1 = require("packages/web3/src/lib/errors/rubic-sdk.error");
|
|
9
|
+
const errors_1 = require("../../utils/errors");
|
|
10
|
+
const core_2 = require("@ton/core");
|
|
11
|
+
const waitFor_1 = require("../../utils/waitFor");
|
|
12
|
+
const ton_1 = require("@ton/ton");
|
|
13
|
+
class TonAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
|
|
14
|
+
constructor(tonApi, config, httpClient, logger, rubicAppParams) {
|
|
15
|
+
super(httpClient, logger, rubicAppParams);
|
|
16
|
+
this.tonApi = tonApi;
|
|
17
|
+
this.tonClient = new ton_1.TonClient(config.tonClientConfig);
|
|
18
|
+
}
|
|
19
|
+
getBlockchainName() {
|
|
20
|
+
return Promise.resolve(core_1.BLOCKCHAIN_NAME.TON);
|
|
21
|
+
}
|
|
22
|
+
async getTransactionStatus(srcTxHash) {
|
|
23
|
+
const isCompleted = await this.tonApi.checkIsTxCompleted(srcTxHash);
|
|
24
|
+
if (isCompleted) {
|
|
25
|
+
return tx_status_1.TX_STATUS.SUCCESS;
|
|
26
|
+
}
|
|
27
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
28
|
+
}
|
|
29
|
+
async sendTransaction(params) {
|
|
30
|
+
try {
|
|
31
|
+
const { boc } = await this.clientWallet.sendTransaction({
|
|
32
|
+
validUntil: Math.floor(Date.now() / 1000) + 360,
|
|
33
|
+
messages: params.txOptions.messages
|
|
34
|
+
});
|
|
35
|
+
const txHash = this.fromBocToBase64Hash(boc);
|
|
36
|
+
params.txOptions.onTransactionHash?.(txHash);
|
|
37
|
+
const isCompleted = await this.waitForTransactionReceipt(txHash);
|
|
38
|
+
if (!isCompleted) {
|
|
39
|
+
throw new rubic_sdk_error_1.RubicSdkError('[BitcoinWeb3Private] TON transaction timeout expired!');
|
|
40
|
+
}
|
|
41
|
+
return boc;
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(`Send transaction error. ${err}`);
|
|
45
|
+
if (err.message.includes('Reject request')) {
|
|
46
|
+
throw new user_reject_error_1.UserRejectError();
|
|
47
|
+
}
|
|
48
|
+
throw (0, errors_1.parseError)(err);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async waitForTransactionReceipt(txHash) {
|
|
52
|
+
let isCompleted = false;
|
|
53
|
+
const startTimeMS = Date.now();
|
|
54
|
+
const timeLimitMS = 600 * 1000;
|
|
55
|
+
while (Date.now() < startTimeMS + timeLimitMS) {
|
|
56
|
+
if (isCompleted)
|
|
57
|
+
return true;
|
|
58
|
+
await (0, waitFor_1.waitFor)(30000);
|
|
59
|
+
isCompleted = await this.tonApi.checkIsTxCompleted(txHash);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Transfer asset from on wallet to another
|
|
65
|
+
* @param tokenAddress Token address to transfer
|
|
66
|
+
* @param walletAddress Wallet address to transfer from
|
|
67
|
+
* @param receiver Receiver wallet address
|
|
68
|
+
* @param amount Transfer amount
|
|
69
|
+
* @param options Transaction options
|
|
70
|
+
*/
|
|
71
|
+
transferAsset(tokenAddress, walletAddress, receiver, amount, options) {
|
|
72
|
+
if ((0, core_1.compareAddresses)(core_1.nativeTokensList.TON.address, tokenAddress)) {
|
|
73
|
+
return this.transferNative(receiver, amount, options);
|
|
74
|
+
}
|
|
75
|
+
return this.transferJetton(tokenAddress, walletAddress, receiver, amount, options);
|
|
76
|
+
}
|
|
77
|
+
transferNative(receiver, amount, options) {
|
|
78
|
+
const transferAmount = BigInt(amount);
|
|
79
|
+
const encodeConfig = {
|
|
80
|
+
address: receiver,
|
|
81
|
+
amount: transferAmount.toString()
|
|
82
|
+
};
|
|
83
|
+
return this.sendTransaction({ txOptions: { messages: [encodeConfig], onTransactionHash: options?.onTransactionHash } });
|
|
84
|
+
}
|
|
85
|
+
async transferJetton(tokenAddress, walletAddress, receiver, amount, options) {
|
|
86
|
+
const fromAddress = core_2.Address.parse(walletAddress);
|
|
87
|
+
const contractAddress = core_2.Address.parse(tokenAddress);
|
|
88
|
+
const transferAmount = BigInt(amount);
|
|
89
|
+
const receiverAddress = core_2.Address.parse(receiver);
|
|
90
|
+
const jettonWalletAddress = await this.getJettonWalletAddress(fromAddress, contractAddress);
|
|
91
|
+
const body = (0, core_2.beginCell)()
|
|
92
|
+
.storeUint(0xf8a7ea5, 32)
|
|
93
|
+
.storeUint(0, 64)
|
|
94
|
+
.storeCoins(transferAmount)
|
|
95
|
+
.storeAddress(receiverAddress)
|
|
96
|
+
.storeAddress(receiverAddress)
|
|
97
|
+
.storeBit(0)
|
|
98
|
+
.storeCoins((0, core_2.toNano)('0.02'))
|
|
99
|
+
.storeBit(0)
|
|
100
|
+
.endCell();
|
|
101
|
+
const encodeConfig = {
|
|
102
|
+
address: jettonWalletAddress.toRawString(),
|
|
103
|
+
amount: (0, core_2.toNano)('0.05').toString(),
|
|
104
|
+
payload: body.toBoc().toString('base64')
|
|
105
|
+
};
|
|
106
|
+
return this.sendTransaction({ txOptions: { messages: [encodeConfig], onTransactionHash: options?.onTransactionHash } });
|
|
107
|
+
}
|
|
108
|
+
getTransferEncodedConfig(tokenAddress, walletAddress, receiver, amount) {
|
|
109
|
+
if ((0, core_1.compareAddresses)(core_1.nativeTokensList.TON.address, tokenAddress)) {
|
|
110
|
+
return this.getTransferNativeConfig(receiver, amount);
|
|
111
|
+
}
|
|
112
|
+
return this.getTransferJettonConfig(tokenAddress, walletAddress, receiver, amount);
|
|
113
|
+
}
|
|
114
|
+
async getTransferNativeConfig(receiver, amount) {
|
|
115
|
+
const transferAmount = BigInt(amount);
|
|
116
|
+
const encodeConfig = {
|
|
117
|
+
address: receiver,
|
|
118
|
+
amount: transferAmount.toString()
|
|
119
|
+
};
|
|
120
|
+
return encodeConfig;
|
|
121
|
+
}
|
|
122
|
+
async getTransferJettonConfig(tokenAddress, walletAddress, receiver, amount) {
|
|
123
|
+
const fromAddress = core_2.Address.parse(walletAddress);
|
|
124
|
+
const contractAddress = core_2.Address.parse(tokenAddress);
|
|
125
|
+
const transferAmount = BigInt(amount);
|
|
126
|
+
const receiverAddress = core_2.Address.parse(receiver);
|
|
127
|
+
const jettonWalletAddress = await this.getJettonWalletAddress(fromAddress, contractAddress);
|
|
128
|
+
const body = (0, core_2.beginCell)()
|
|
129
|
+
.storeUint(0xf8a7ea5, 32)
|
|
130
|
+
.storeUint(0, 64)
|
|
131
|
+
.storeCoins(transferAmount)
|
|
132
|
+
.storeAddress(receiverAddress)
|
|
133
|
+
.storeAddress(receiverAddress)
|
|
134
|
+
.storeBit(0)
|
|
135
|
+
.storeCoins((0, core_2.toNano)('0.02'))
|
|
136
|
+
.storeBit(0)
|
|
137
|
+
.endCell();
|
|
138
|
+
const encodeConfig = {
|
|
139
|
+
address: jettonWalletAddress.toRawString(),
|
|
140
|
+
amount: (0, core_2.toNano)('0.05').toString(),
|
|
141
|
+
payload: body.toBoc().toString('base64')
|
|
142
|
+
};
|
|
143
|
+
return encodeConfig;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
* @param boc Boc returned in connector.sendTransaction
|
|
148
|
+
* @returns boc converter in base 64 string
|
|
149
|
+
*/
|
|
150
|
+
fromBocToBase64Hash(boc) {
|
|
151
|
+
const inMsgCell = core_2.Cell.fromBase64(boc);
|
|
152
|
+
const inMsgHash = inMsgCell.hash();
|
|
153
|
+
const inMsgHashBase64 = inMsgHash.toString('base64');
|
|
154
|
+
const inMsgHashBase64Url = inMsgHashBase64.replace(/\+/g, '-').replace(/\//g, '_');
|
|
155
|
+
return inMsgHashBase64Url;
|
|
156
|
+
}
|
|
157
|
+
async getJettonWalletAddress(address, contractAddress) {
|
|
158
|
+
const addressResult = await this.tonClient.runMethod(contractAddress, 'get_wallet_address', [
|
|
159
|
+
{ type: 'slice', cell: (0, core_2.beginCell)().storeAddress(address).endCell() }
|
|
160
|
+
]);
|
|
161
|
+
return addressResult.stack.readAddress();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.TonAdapterClient = TonAdapterClient;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
|
|
2
|
+
export interface TonSendTxParams {
|
|
3
|
+
txOptions: TonTransactionOptions;
|
|
4
|
+
}
|
|
5
|
+
export interface TonTransactionOptions extends BasicSendTransactionOptions {
|
|
6
|
+
messages: TonEncodedConfig[];
|
|
7
|
+
}
|
|
8
|
+
export interface TonEncodedConfig {
|
|
9
|
+
/**
|
|
10
|
+
* In default transfer - it's a receiverWalletAddress to send funds
|
|
11
|
+
* In tx using contracts - it's a jettonWalletAddress (like ERC-20, but in TON)
|
|
12
|
+
*/
|
|
13
|
+
address: string;
|
|
14
|
+
/**
|
|
15
|
+
* Amount to send in tx in nanotons
|
|
16
|
+
* In default trasfer - it's a transfered value
|
|
17
|
+
* In tx using contracts - it's static gasFee, by default toNano(0.05).toString()
|
|
18
|
+
*/
|
|
19
|
+
amount: string;
|
|
20
|
+
/**
|
|
21
|
+
* Data for contract.
|
|
22
|
+
* body.toBoc().toString('base64')
|
|
23
|
+
*/
|
|
24
|
+
payload?: string;
|
|
25
|
+
stateInit?: string;
|
|
26
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { TonApiAccountInfoResp, TonApiAllNonNullableTokenInfoForWalletResp, TonApiParseAddressResp, TonApiTokenInfoForWalletResp, TonApiTokenInfoResp, TonApiTxDataByBocResp } from '
|
|
2
|
-
import { TonCenterBlockInfo } from '
|
|
1
|
+
import { TonApiAccountInfoResp, TonApiAllNonNullableTokenInfoForWalletResp, TonApiParseAddressResp, TonApiTokenInfoForWalletResp, TonApiTokenInfoResp, TonApiTxDataByBocResp } from '../../models/tonapi-models';
|
|
2
|
+
import { TonCenterBlockInfo } from '../../models/toncenter-types';
|
|
3
3
|
import { HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
4
|
-
import { TonApiConfig } from '
|
|
5
|
-
import { Web3PrimitiveType } from '
|
|
4
|
+
import { TonApiConfig } from '../../models/ton-api-config';
|
|
5
|
+
import { Web3PrimitiveType } from '../../../../utils/models/primitive-types';
|
|
6
6
|
export declare class TonApiService {
|
|
7
7
|
private readonly httpClient;
|
|
8
8
|
private readonly logger?;
|