@xswap-link/sdk
Version:
JavaScript SDK for XSwap platform
520 lines (487 loc) • 16.8 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import { BigNumber, ContractReceipt, ContractTransaction } from 'ethers';
import { TransactionResponse } from '@ethersproject/providers';
import { VersionedTransaction } from '@solana/web3.js';
import { Dispatch, SetStateAction } from 'react';
type Addresses = {
[chainId: string]: Contracts;
};
type Contracts = Partial<{
[contractName in ContractName]: string;
}>;
declare enum ContractName {
USDC = "USDC",
BatchQuery = "BatchQuery",
CustomXSwapRouter = "CustomXSwapRouter",
FeeCollector = "FeeCollector",
StakingCosmicCadets = "StakingCosmicCadets",
StakingSolarDivision = "StakingSolarDivision",
StakingIntergalacticCommand = "StakingIntergalacticCommand",
XSwapRouter = "XSwapRouter",
XSwapToken = "XSwapToken",
XSwapRouterSingleChain = "XSwapRouterSingleChain"
}
type BridgeToken = {
[chainId: string]: string;
};
type BridgeTokensDictionary = {
[chainId0: string]: {
[tokenAddress0: string]: {
[chainId1: string]: string;
};
};
};
type CoinTypeAddress = {
coinType: number;
address: string;
};
type CollectFees = {
integratorAddress: string;
fee: number;
};
declare enum XSwapCallType {
DEFAULT = 0,
FULL_TOKEN_BALANCE = 1,
FULL_NATIVE_BALANCE = 2,
COLLECT_TOKEN_BALANCE = 3
}
type ContractCall = {
callType: XSwapCallType;
target: string;
value: string;
callData: string;
payload: string;
estimatedGas?: string;
};
declare enum Ecosystem {
EVM = "evm",
SOLANA = "solana"
}
declare enum Environment {
PROD = "production",
DEV = "develop",
LOCAL = "local"
}
type TxConfigFormData = {
srcChain: string;
srcToken: string;
amountIn: string;
paymentToken: string;
slippage: number;
expressDelivery: boolean;
};
type GenerateStakingCallsParams = {
token: string;
staking: string;
stakingAbi: string;
stakingFunName: string;
stakingFunParams: any[];
};
type GetTokenBalancesPayload = {
walletAddress?: string;
solanaWalletAddress?: string;
};
type GetLeaderboardChangePayload = {
walletAddress: string;
additionalPoints: number;
};
type GetPricesPayload = {
chainId: string[];
currency?: string;
};
type GetRoutePayload = {
integratorId: string;
fromChain: string;
toChain: string;
fromToken: string;
toToken: string;
fromAmount: string;
fromAddress: string;
toAddress: string;
paymentToken: string;
slippage: number;
expressDelivery: boolean;
quoteOnly?: boolean;
enableExpress?: boolean;
customContractCalls?: ContractCall[];
sourceChainDexes?: string[];
destinationChainDexes?: string[];
receiveGasOnDestination?: boolean;
collectFees?: CollectFees;
fallbackAddresses?: CoinTypeAddress[];
infiniteApproval: boolean;
integratorFee?: number;
integratorFeeReceiverAddress?: string;
};
type GetSolanaRoutePayload = {
integratorId: string;
fromToken: string;
toToken: string;
fromAmount: string;
fromAddress: string;
slippage: number;
};
type ModalIntegrationThemeStyles = {
mainAccentLight?: string;
mainAccentDark?: string;
bgPrimary?: string;
bgSecondary?: string;
bgTertiary?: string;
textPrimary?: string;
textSecondary?: string;
textTertiary?: string;
textRed?: string;
textOrange?: string;
textGreen?: string;
clickPrimary?: string;
clickSecondary?: string;
clickTertiary?: string;
buttonPrBg?: string;
buttonPrText?: string;
buttonPrOffBg?: string;
buttonPrOffText?: string;
labelBg?: string;
labelText?: string;
successDark?: string;
successLight?: string;
infoDark?: string;
infoLight?: string;
warningDark?: string;
warningLight?: string;
errorDark?: string;
errorLight?: string;
chainlinkLogo?: string;
fontFamily?: string;
};
type ModalIntegrationStyles = Pick<ModalIntegrationThemeStyles, "mainAccentLight" | "mainAccentDark" | "textSecondary" | "fontFamily"> & {
width?: string;
};
type ModalIntegrationPayload = {
integratorId: string;
dstChain?: string;
dstToken?: string;
srcChain?: string;
srcToken?: string;
customContractCalls?: ContractCall[];
desc?: string;
dstDisplayToken?: string;
lightTheme?: boolean;
defaultWalletPicker?: boolean;
styles?: ModalIntegrationStyles;
onPendingTransactionsChange?: (transactions: Transaction[]) => void;
dstTokenLocked?: boolean;
dstChainLocked?: boolean;
srcTokenLocked?: boolean;
srcChainLocked?: boolean;
onDstTokenChange?: (token: {
address: string;
symbol: string;
} | undefined) => void;
onDstChainChange?: (chain: string | undefined) => void;
onSrcTokenChange?: (token: {
address: string;
symbol: string;
} | undefined) => void;
onSrcChainChange?: (chain: string | undefined) => void;
onConnectWallet?: () => void;
bridge?: boolean;
override?: {
apiUrl?: string;
};
integratorFee?: number;
integratorFeeReceiverAddress?: string;
highlightedDstTokens?: string[];
};
type WidgetIntegrationPayload = {
integratorId: string;
dstChain?: string;
dstToken?: string;
srcChain?: string;
srcToken?: string;
customContractCalls?: ContractCall[];
desc?: string;
dstDisplayToken?: string;
lightTheme?: boolean;
defaultWalletPicker?: boolean;
styles?: ModalIntegrationStyles | string;
onPendingTransactionsChange?: (transactions: Transaction[]) => void;
dstTokenLocked?: boolean;
dstChainLocked?: boolean;
srcTokenLocked?: boolean;
srcChainLocked?: boolean;
onDstTokenChange?: (token: {
address: string;
symbol: string;
} | undefined) => void;
onDstChainChange?: (chain: string | undefined) => void;
onSrcTokenChange?: (token: {
address: string;
symbol: string;
} | undefined) => void;
onSrcChainChange?: (chain: string | undefined) => void;
onConnectWallet?: () => void;
bridge?: boolean;
override?: {
apiUrl?: string;
};
integratorFee?: number;
integratorFeeReceiverAddress?: string;
highlightedDstTokens?: string[];
};
type Protocol = {
name: string;
part: number;
fromTokenAddress: string;
toTokenAddress: string;
};
interface BaseRoute {
estAmountOut: string;
minAmountOut: string;
xSwapFees: XSwapFees;
message?: string;
}
interface EVMRoute extends BaseRoute {
ecosystem: "evm";
transactions: Transactions;
}
interface SolanaRoute extends BaseRoute {
ecosystem: "solana";
swapTransaction: string;
}
type UnifiedRoute = EVMRoute | SolanaRoute;
type Transactions = {
approve?: TransactionRequest;
swap: TransactionRequest;
};
type TransactionRequest = {
to: string;
data: string;
value: string;
};
type XSwapFees = {
ccipFee?: string;
xSwapFee: XSwapFee;
expressDeliveryFee?: string;
};
type XSwapFee = {
tokenFee: string;
nativeFee: string;
};
declare enum SolanaWeb3Network {
DEVNET = "devnet",
TESTNET = "testnet",
MAINNET = "mainnet-beta"
}
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;
defaultDstChain?: string;
disabledForDestination?: string[];
supportedDstForBridge?: string[];
supportedDstForSwap?: 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 = {
[chainId: string]: {
[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 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 MonitoredTransaction = {
srcChain: string | undefined;
srcChainImage: string | undefined;
srcToken: string | undefined;
srcTokenImage: string | undefined;
srcAmount: string | undefined;
dstChain: string | undefined;
dstChainImage: string | undefined;
isDone: boolean;
txHash: string;
explorer: string | undefined;
};
type TxWidgetWCAttributes = {
"integrator-id": WidgetIntegrationPayload["integratorId"];
"dst-chain": WidgetIntegrationPayload["dstChain"];
"dst-token": WidgetIntegrationPayload["dstToken"];
"src-chain": WidgetIntegrationPayload["srcChain"];
"src-token": WidgetIntegrationPayload["srcToken"];
"custom-contract-calls": string | undefined;
desc: WidgetIntegrationPayload["desc"];
"dst-display-token": WidgetIntegrationPayload["dstDisplayToken"];
"light-theme": WidgetIntegrationPayload["lightTheme"];
"default-wallet-picker": WidgetIntegrationPayload["defaultWalletPicker"];
styles: string | undefined;
"on-pending-transactions-change"?: WidgetIntegrationPayload["onPendingTransactionsChange"];
"dst-token-locked": WidgetIntegrationPayload["dstTokenLocked"] | undefined;
"dst-chain-locked": WidgetIntegrationPayload["dstChainLocked"] | undefined;
"src-token-locked": WidgetIntegrationPayload["srcTokenLocked"] | undefined;
"src-chain-locked": WidgetIntegrationPayload["srcChainLocked"] | undefined;
"on-dst-token-change"?: WidgetIntegrationPayload["onDstTokenChange"];
"on-dst-chain-change"?: WidgetIntegrationPayload["onDstChainChange"];
"on-src-token-change"?: WidgetIntegrationPayload["onSrcTokenChange"];
"on-src-chain-change"?: WidgetIntegrationPayload["onSrcChainChange"];
bridge: WidgetIntegrationPayload["bridge"] | undefined;
override: string | undefined;
"integrator-fee": WidgetIntegrationPayload["integratorFee"] | undefined;
"integrator-fee-receiver-address": WidgetIntegrationPayload["integratorFeeReceiverAddress"] | undefined;
"highlighted-dst-tokens": string | undefined;
};
declare global {
namespace JSX {
interface IntrinsicElements {
"xpay-widget": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & TxWidgetWCAttributes;
}
}
}
declare const TxWidgetWCWrapped: ({ integratorId, dstChain, dstToken, srcChain, srcToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, onPendingTransactionsChange, dstTokenLocked, dstChainLocked, srcTokenLocked, srcChainLocked, onDstTokenChange, onDstChainChange, onSrcTokenChange, onSrcChainChange, onConnectWallet, bridge, override, integratorFee, integratorFeeReceiverAddress, highlightedDstTokens, }: WidgetIntegrationPayload) => react_jsx_runtime.JSX.Element;
interface EvmHandlers {
onSuccess?: (data: ContractReceipt) => void;
onError?: <T>(data: T) => void;
onConfirm?: (data?: ContractTransaction) => void;
}
interface SolanaHandlers {
onSuccess?: (data: string) => void;
onError?: <T>(data: T) => void;
onConfirm?: (txHash?: string) => void;
}
type EnqueueTxProps = {
executeTransaction: () => Promise<TransactionResponse | undefined> | Promise<VersionedTransaction | undefined> | undefined;
txStatus: TxStatus;
txMsg?: string;
handlers?: EvmHandlers | SolanaHandlers;
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, srcChain, srcToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, onPendingTransactionsChange, dstTokenLocked, dstChainLocked, srcTokenLocked, srcChainLocked, onDstTokenChange, onDstChainChange, onSrcTokenChange, onSrcChainChange, bridge, highlightedDstTokens, }: ModalIntegrationPayload) => Promise<void>;
declare const TxWidgetWC: CustomElementConstructor;
declare const XPay: {
openTransactionModal: ({ integratorId, dstChain, dstToken, srcChain, srcToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, onPendingTransactionsChange, dstTokenLocked, dstChainLocked, srcTokenLocked, srcChainLocked, onDstTokenChange, onDstChainChange, onSrcTokenChange, onSrcChainChange, bridge, highlightedDstTokens, }: ModalIntegrationPayload) => Promise<void>;
TxWidget: ({ integratorId, dstChain, dstToken, srcChain, srcToken, customContractCalls, desc, dstDisplayToken, lightTheme, defaultWalletPicker, styles, onPendingTransactionsChange, dstTokenLocked, dstChainLocked, srcTokenLocked, srcChainLocked, onDstTokenChange, onDstChainChange, onSrcTokenChange, onSrcChainChange, onConnectWallet, bridge, override, integratorFee, integratorFeeReceiverAddress, highlightedDstTokens, }: WidgetIntegrationPayload) => react_jsx_runtime.JSX.Element;
TxWidgetWC: CustomElementConstructor;
};
export { type Addresses, type BridgeToken, type BridgeTokensDictionary, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, type EVMRoute, Ecosystem, type EnqueueTxProps, Environment, type GenerateStakingCallsParams, type GetLeaderboardChangePayload, type GetPricesPayload, type GetRoutePayload, type GetSolanaRoutePayload, type GetTokenBalancesPayload, type HistoryTransaction, type ImportedTokenData, type ModalIntegrationPayload, type ModalIntegrationStyles, type ModalIntegrationThemeStyles, type MonitoredTransaction, type Prices, type Protocol, type SolanaRoute, SolanaWeb3Network, type Token, type TokenBalances, type TokenOption, type TokenPrices, type Transaction, type TransactionHistory, type TransactionRequest, type TransactionStatus, type Transactions, type TxConfigFormData, type TxStats, TxStatus, type TxUIWrapperState, TxWidgetWCWrapped as TxWidget, TxWidgetWC, type UnifiedRoute, Web3Environment, type WidgetIntegrationPayload, XSwapCallType, type XSwapFee, type XSwapFees, XPay as default, openTransactionModal };