UNPKG

@swapper-finance/sdk

Version:
320 lines (294 loc) 9.3 kB
import * as react_jsx_runtime from 'react/jsx-runtime'; import { BigNumber, ContractReceipt, ContractTransaction } from 'ethers'; import { TransactionResponse } from '@ethersproject/providers'; import { Dispatch, SetStateAction } from 'react'; type Addresses = { [chainId: string]: Contracts; }; type Contracts = Partial<{ [contractName in ContractName]: string; }>; declare enum ContractName { SwapperRouter = "SwapperRouter" } type SwapperConfig = { apiUrl: string; localCss: boolean; }; declare enum Web3Environment { DEVNET = "devnet", TESTNET = "testnet", MAINNET = "mainnet" } type Chain = { ecosystem: string; chainId: string; name: string; displayName: string; image: string; web3Environment: Web3Environment; tokenSymbol: string; ccipChainId: string; transactionExplorer: string; bridgeSupported: boolean; swapSupported: boolean; tokens: Token[]; publicRpcUrls: string[]; privateRpcUrls?: string[]; scanApiURL?: string; shift4Pk: string; }; type Token = { address: string; name: string; symbol: string; tokenId: string; decimals: number; image?: string; priority: number; quickPick?: boolean; supported?: boolean; }; type Prices = { blockchainId: string; updatedAt: Date; prices: TokenPrices; }; type TokenPrices = { [tokenAddress: string]: string; }; type TokenBalances = { [tokenAddress: string]: BigNumber | undefined; }; type TokenOption = Token & { chainId: string; disabled?: boolean; balance?: BigNumber; }; type ImportedTokenData = { address: string; symbol: string; name: string; decimals: number; }; type CoinTypeAddress = { coinType: number; address: string; }; declare enum SwapperCallType { DEFAULT = 0, FULL_TOKEN_BALANCE = 1, FULL_NATIVE_BALANCE = 2, COLLECT_TOKEN_BALANCE = 3 } type ContractCall = { callType: SwapperCallType; target: string; value: string; callData: string; payload: string; estimatedGas?: string; }; declare enum Ecosystem { EVM = "evm" } declare enum Environment { PROD = "production", DEV = "develop", LOCAL = "local" } type GetTokenBalancesPayload = { walletAddress: string; }; type GetPricesPayload = { chainId: string; currency?: string; }; type GenerateRoutePayload = { integratorId: string; chainId: string; fromToken: string; toToken: string; fromAmount: string; fromAddress?: string; toAddress?: string; slippage: number; customContractCalls?: ContractCall[]; sourceChainDexes?: string[]; }; type ModalIntegrationThemeStyles = { themeColor?: string; bgPrimary?: string; bgSecondary?: string; bgTertiary?: string; textPrimary?: string; textRed?: string; textOrange?: string; textGreen?: string; buttonPrText?: string; buttonPrOffBg?: string; buttonPrOffText?: string; successDark?: string; successLight?: string; warningDark?: string; warningLight?: string; errorDark?: string; errorLight?: string; }; type ModalIntegrationStyles = Pick<ModalIntegrationThemeStyles, "themeColor"> & { maxWidth?: string; borderRadius?: string; }; type ModalIntegrationPayload = { integratorId: string; dstChain: string; dstToken: string; customContractCalls?: ContractCall[]; desc?: string; dstDisplayToken?: string; lightTheme?: boolean; defaultWalletPicker?: boolean; styles?: ModalIntegrationStyles; }; type WidgetIntegrationPayload = { integratorId: string; dstChain?: string; dstToken?: string; customContractCalls?: ContractCall[]; desc?: string; dstDisplayToken?: string; lightTheme?: boolean; defaultWalletPicker?: boolean; styles?: string; }; type Protocol = { name: string; part: number; fromTokenAddress: string; toTokenAddress: string; }; type Route = { id: string; receiver: string; estAmountOut: string; minAmountOut: string; }; type TransferType = "CROSS_CHAIN" | "SINGLE_CHAIN"; type TransactionHistory = { history: HistoryTransaction[]; }; type HistoryTransaction = { transferId: string; transferType: TransferType; walletAddress: string; messageId: string; failed: boolean; source: { blockchainId: string; transactionHash: string; blockTime: Date; tokenAmount: string; tokenAddress: string; transferredTokenAddress: string; transferredTokenAmount: string; valueForInstantCcipRecieve: string; tokenOutAddress: string; estimatedAmountOut: string; targetBlockchainId: string; } | null; target: { blockchainId: string; transactionHash: string; blockTime: Date; tokenAmount: string; tokenAddress: string; } | null; }; type TransactionStatus = "IN_PROGRESS" | "DONE" | "REVERTED" | "NOT_FOUND"; type Transaction = { messageId?: string; hash: string; timestamp: number; sourceChainId: string; targetChainId: string; amountWei: string; tokenAddress: string; tokenOutAddress: string | undefined; tokenOutAmount: string | undefined; estimatedDeliveryTimestamp: number; status: TransactionStatus; }; type TxWidgetWCAttributes = { "integrator-id": WidgetIntegrationPayload["integratorId"]; "dst-chain": WidgetIntegrationPayload["dstChain"]; "dst-token": WidgetIntegrationPayload["dstToken"]; "custom-contract-calls": WidgetIntegrationPayload["customContractCalls"]; desc: WidgetIntegrationPayload["desc"]; "dst-display-token": WidgetIntegrationPayload["dstDisplayToken"]; "light-theme": WidgetIntegrationPayload["lightTheme"]; "default-wallet-picker": WidgetIntegrationPayload["defaultWalletPicker"]; styles: WidgetIntegrationPayload["styles"]; }; declare global { namespace JSX { interface IntrinsicElements { "swapper-sdk-widget": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & TxWidgetWCAttributes; } } } declare const TxWidgetWCWrapped: ({ integratorId, dstChain, dstToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, }: WidgetIntegrationPayload) => react_jsx_runtime.JSX.Element; interface EvmHandlers { onSuccess?: (data: ContractReceipt) => void; onError?: <T>(data: T) => void; onConfirm?: (data?: ContractTransaction) => void; } type EnqueueTxProps = { executeTransaction: () => Promise<TransactionResponse> | undefined; txStatus: TxStatus; txMsg?: string; handlers?: EvmHandlers; network?: Ecosystem; showDefaultSuccessMessage?: boolean; }; type TxUIWrapperState = { enqueueTransaction: (props: EnqueueTxProps) => number; closeTransactionModal: (nonce: number) => void; isTxModalOpen: boolean; setTxModalOpen: Dispatch<SetStateAction<boolean>>; loading: boolean; txStatus: TxStatus; setTxStatus: Dispatch<SetStateAction<TxStatus>>; txExplorerUrl: string; txHash: string; txError: string; txMsg: string; setTxMsg: Dispatch<SetStateAction<string>>; setTxError: Dispatch<SetStateAction<string>>; txNeedsApproval: boolean; setTxNeedsApproval: Dispatch<SetStateAction<boolean>>; }; /** * make sure there's always appropriate CONFIRMATION status following the SIGNING one * see setTxStatus((prevStatus) => prevStatus + 1) at TxUIWrapper.tsx -> addUILogicToHandlersEVM */ declare enum TxStatus { SWAP_INIT = 0, SIGNING_APPROVAL = 1, CONFIRMING_APPROVAL = 2, SIGNING_TX = 3, CONFIRMING_TX = 4, COMPLETED = 5 } type TxStats = { points?: string; rank?: string; cashback?: string; }; declare const openTransactionModal: ({ integratorId, dstChain, dstToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, }: ModalIntegrationPayload) => Promise<void>; declare const TxWidgetWC: CustomElementConstructor; declare const SwapperSDK: { openTransactionModal: ({ integratorId, dstChain, dstToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, }: ModalIntegrationPayload) => Promise<void>; TxWidget: ({ integratorId, dstChain, dstToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, }: WidgetIntegrationPayload) => react_jsx_runtime.JSX.Element; TxWidgetWC: CustomElementConstructor; }; export { type Addresses, type Chain, type CoinTypeAddress, type ContractCall, ContractName, type Contracts, Ecosystem, type EnqueueTxProps, Environment, type GenerateRoutePayload, type GetPricesPayload, type GetTokenBalancesPayload, type HistoryTransaction, type ImportedTokenData, type ModalIntegrationPayload, type ModalIntegrationStyles, type ModalIntegrationThemeStyles, type Prices, type Protocol, type Route, SwapperCallType, type SwapperConfig, type Token, type TokenBalances, type TokenOption, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type TxStats, TxStatus, type TxUIWrapperState, TxWidgetWCWrapped as TxWidget, TxWidgetWC, Web3Environment, type WidgetIntegrationPayload, SwapperSDK as default, openTransactionModal };