UNPKG

rubic-sdk-next

Version:
134 lines (133 loc) 6.33 kB
import { QuoteRequestInterface, QuoteResponseInterface, SwapRequestInterface } from '@cryptorubic/core'; import { UniqueProviderInfoInterface } from '@cryptorubic/core/src/lib/models/api/unique-provider-info.interface'; import BigNumber from 'bignumber.js'; import { PriceTokenAmount } from '../../../../../common/tokens'; import { BasicTransactionOptions } from '../../../../../core/blockchain/web3-private-service/web3-private/models/basic-transaction-options'; import { Web3Private } from '../../../../../core/blockchain/web3-private-service/web3-private/web3-private'; import { Web3Public } from '../../../../../core/blockchain/web3-public-service/web3-public/web3-public'; import { HttpClient } from '../../../../../core/http-client/models/http-client'; import { EncodeTransactionOptions } from '../../../../common/models/encode-transaction-options'; import { SwapTransactionOptions } from '../../../../common/models/swap-transaction-options'; import { CrossChainTradeType } from '../../models/cross-chain-trade-type'; import { BridgeType } from './models/bridge-type'; import { FeeInfo } from './models/fee-info'; import { OnChainSubtype } from './models/on-chain-subtype'; import { RubicStep } from './models/rubicStep'; import { TradeInfo } from './models/trade-info'; import { TransferSwapRequestInterface } from '../../../../ws-api/chains/transfer-trade/models/transfer-swap-request-interface'; import { SwapResponseInterface } from '../../../../ws-api/models/swap-response-interface'; /** * Abstract class for all cross-chain providers' trades. */ export declare abstract class CrossChainTrade<T = unknown> { protected readonly providerAddress: string; protected readonly routePath: RubicStep[]; protected readonly apiQuote: QuoteRequestInterface; protected readonly apiResponse: QuoteResponseInterface; protected lastTransactionConfig: T | null; protected _uniqueInfo: UniqueProviderInfoInterface; get uniqueInfo(): UniqueProviderInfoInterface; /** * Type of calculated cross-chain trade. */ abstract readonly type: CrossChainTradeType; /** * Token to sell with input amount. */ abstract readonly from: PriceTokenAmount; /** * Token to get with output amount. */ abstract readonly to: PriceTokenAmount; /** * Minimum amount of output token user will get in Eth units. */ abstract readonly toTokenAmountMin: BigNumber; /** * Swap fee information. */ abstract readonly feeInfo: FeeInfo; /** * Contains on-chain providers' type used in route. */ abstract readonly onChainSubtype: OnChainSubtype; /** * @deprecated * Contains bridge provider's type used in route. */ abstract readonly bridgeType: BridgeType; /** * True, if provider is aggregator. */ abstract readonly isAggregator: boolean; /** * Promotions array. */ promotions: string[]; readonly contractSpender: string; protected get httpClient(): HttpClient; protected get fromWeb3Public(): Web3Public; protected get web3Private(): Web3Private; protected get walletAddress(): string; get networkFee(): BigNumber; get platformFee(): BigNumber; protected get amountToCheck(): string; get needAuthWallet(): boolean; private _apiFromAddress; set apiFromAddress(value: string | null); readonly rubicId: string; readonly useProxy: boolean; protected constructor(providerAddress: string, routePath: RubicStep[], apiQuote: QuoteRequestInterface, apiResponse: QuoteResponseInterface); /** * Returns true, if allowance is not enough. */ needApprove(): Promise<boolean>; /** * Sends approve transaction with connected wallet. * @param options Transaction options. * @param checkNeedApprove If true, first allowance is checked. * @param amount Amount of tokens in approval window in spending cap field */ approve(_options: BasicTransactionOptions, _checkNeedApprove?: boolean, _amount?: BigNumber | 'infinity'): Promise<unknown>; /** * Sends swap transaction with connected wallet. * If user has not enough allowance, then approve transaction will be called first. * * @example * ```ts * const onConfirm = (hash: string) => console.log(hash); * const receipt = await trade.swap({ onConfirm }); * ``` * * @param options Transaction options. */ abstract swap(options?: SwapTransactionOptions): Promise<string | never>; /** * Builds transaction config, with encoded data. * @param options Encode transaction options. */ abstract encode(options: EncodeTransactionOptions): Promise<unknown>; abstract authWallet(): Promise<string>; protected checkAmountChange(newWeiAmount: string, oldWeiAmount: string): void; protected checkTradeErrors(): Promise<void | never>; protected checkWalletConnected(): never | void; checkBlockchainRequirements(): Promise<boolean>; protected checkBlockchainCorrect(): Promise<void | never>; protected checkUserBalance(): Promise<void | never>; protected checkFromAddress(fromAddress: string | undefined, isRequired?: boolean, crossChainType?: CrossChainTradeType): Promise<void | never>; protected checkReceiverAddress(receiverAddress: string | undefined, isRequired?: boolean, crossChainType?: CrossChainTradeType): Promise<void | never>; /** * Calculates value for swap transaction. * @param providerValue Value, returned from cross-chain provider. Not '0' if from is native or provider has extranative */ protected getSwapValue(providerValue?: BigNumber | string | number | null): string; getUsdPrice(providerFeeToken?: BigNumber): BigNumber; abstract getTradeInfo(): TradeInfo; protected abstract getTransactionConfigAndAmount(testMode?: boolean, receiverAddress?: string, refundAddress?: string): Promise<{ config: T; amount: string; }>; protected setTransactionConfig(skipAmountChangeCheck: boolean, useCacheData: boolean, testMode?: boolean, receiverAddress?: string, refundAddress?: string): Promise<T>; protected fetchSwapData<T>(body: SwapRequestInterface | TransferSwapRequestInterface): Promise<SwapResponseInterface<T>>; private refetchTrade; }