@okx-dex/okx-dex-sdk
Version:
OKX DEX SDK
323 lines (322 loc) • 7.66 kB
TypeScript
import { Wallet } from '../core/wallet';
import { EVMWallet } from '../core/evm-wallet';
export interface TokenInfo {
decimal: string;
isHoneyPot: boolean;
taxRate: string;
tokenContractAddress: string;
tokenSymbol: string;
tokenUnitPrice: string;
}
export type TokenInfoList = TokenInfo;
export type TokenListInfo = TokenListResponse;
export interface TokenListResponse {
decimals: string;
tokenContractAddress: string;
tokenLogoUrl?: string;
tokenName?: string;
tokenSymbol: string;
}
export interface RouterResult {
chainId: string;
dexRouterList: DexRouter[];
estimateGasFee: string;
fromToken: TokenInfo;
toToken: TokenInfo;
fromTokenAmount: string;
toTokenAmount: string;
priceImpactPercentage: string;
quoteCompareList: ComparisonQuote[];
tradeFee: string;
}
export interface DexProtocol {
dexName: string;
percent: string;
}
export interface SubRouterInfo {
dexProtocol: DexProtocol[];
fromToken: TokenInfo;
toToken: TokenInfo;
}
export interface DexRouter {
router: string;
routerPercent: string;
subRouterList: SubRouterInfo[];
}
export interface ComparisonQuote {
amountOut: string;
dexLogo: string;
dexName: string;
tradeFee: string;
}
export interface QuoteData {
chainId: string;
dexRouterList: DexRouter[];
estimateGasFee: string;
fromToken: TokenInfo;
toToken: TokenInfo;
fromTokenAmount: string;
toTokenAmount: string;
priceImpactPercentage: string;
quoteCompareList: ComparisonQuote[];
tradeFee: string;
routerResult?: RouterResult;
tx?: TransactionData;
}
export interface LiquidityData {
id: string;
name: string;
logo: string;
}
export interface TokenData {
decimals: string;
tokenContractAddress: string;
tokenLogoUrl: string;
tokenName: string;
tokenSymbol: string;
}
export interface ChainData {
chainId: string;
chainName: string;
dexTokenApproveAddress: string | null;
}
export interface SwapResponseData {
data: {
routerResult: {
chainId: string;
dexRouterList: DexRouter[];
estimateGasFee: string;
fromToken: TokenInfo;
toToken: TokenInfo;
fromTokenAmount: string;
toTokenAmount: string;
priceImpactPercentage: string;
quoteCompareList: ComparisonQuote[];
tradeFee: string;
};
tx?: TransactionData;
}[];
code: string;
msg: string;
}
export interface SwapExecutionData {
routerResult: {
chainId: string;
dexRouterList: DexRouter[];
estimateGasFee: string;
fromToken: TokenInfo;
toToken: TokenInfo;
fromTokenAmount: string;
toTokenAmount: string;
priceImpactPercentage: string;
quoteCompareList: ComparisonQuote[];
tradeFee: string;
};
tx?: TransactionData;
}
export interface TransactionData {
data: string;
from: string;
gas: string;
gasPrice: string;
maxPriorityFeePerGas: string;
minReceiveAmount: string;
signatureData: string[];
slippage: string;
to: string;
value: string;
}
export interface APIResponse<T> {
code: string;
msg: string;
data: T[];
}
export interface SolanaConfig {
wallet: Wallet;
computeUnits?: number;
maxRetries?: number;
}
export interface SuiConfig {
privateKey: string;
walletAddress: string;
connection?: {
rpcUrl: string;
wsEndpoint?: string;
};
}
export interface EVMConfig {
wallet?: EVMWallet;
}
export interface ChainConfig {
id: string;
explorer: string;
defaultSlippage: string;
maxSlippage: string;
computeUnits?: number;
confirmationTimeout?: number;
maxRetries?: number;
dexContractAddress?: string;
}
export interface NetworkConfigs {
[chainId: string]: ChainConfig;
}
export interface OKXConfig {
apiKey: string;
secretKey: string;
apiPassphrase: string;
projectId: string;
baseUrl?: string;
networks?: NetworkConfigs;
solana?: SolanaConfig;
sui?: SuiConfig;
evm?: EVMConfig;
timeout?: number;
maxRetries?: number;
}
export interface APIRequestParams {
[key: string]: string | undefined;
}
export interface SlippageOptions {
slippage?: string;
autoSlippage?: boolean;
maxAutoSlippage?: string;
}
export interface BaseParams {
chainId: string;
chainIndex?: string;
fromTokenAddress: string;
toTokenAddress: string;
amount: string;
userWalletAddress?: string;
dexIds?: string;
directRoute?: boolean;
priceImpactProtectionPercentage?: string;
feePercent?: string;
}
export interface SwapParams extends BaseParams {
slippage?: string;
autoSlippage?: boolean;
maxAutoSlippage?: string;
swapReceiverAddress?: string;
fromTokenReferrerWalletAddress?: string;
toTokenReferrerWalletAddress?: string;
positiveSlippagePercent?: string;
gasLimit?: string;
gasLevel?: string;
computeUnitPrice?: string;
computeUnitLimit?: string;
callDataMemo?: string;
}
export interface SwapSimulationParams {
fromAddress: string;
toAddress: string;
chainIndex: string;
txAmount: string;
extJson: {
inputData: string;
};
gasPrice: string;
includeDebug: boolean;
}
export interface QuoteParams extends BaseParams {
slippage: string;
}
export interface SwapResult {
success: boolean;
transactionId: string;
explorerUrl: string;
details?: {
fromToken: {
symbol: string;
amount: string;
decimal: string;
};
toToken: {
symbol: string;
amount: string;
decimal: string;
};
priceImpact: string;
};
}
export interface FormattedSwapResponse {
success: boolean;
quote: {
fromToken: {
symbol: string;
amount: string;
decimal: string;
unitPrice: string;
};
toToken: {
symbol: string;
amount: string;
decimal: string;
unitPrice: string;
};
priceImpact: string;
dexRoutes: {
dex: string;
amountOut: string;
fee: string;
}[];
};
summary: string;
tx?: {
data: string;
};
}
export interface ApproveTokenParams {
chainId: string;
tokenContractAddress: string;
approveAmount: string;
}
export interface ApproveTokenResult {
success: boolean;
transactionHash: string;
explorerUrl: string;
}
export interface GasLimitParams {
chainIndex: string;
fromAddress: string;
toAddress: string;
txAmount?: string;
extJson?: {
inputData?: string;
};
}
export interface GasLimitData {
gasLimit: string;
}
export interface BroadcastTransactionParams {
signedTx: string;
chainIndex: string;
address: string;
extraData?: string;
enableMevProtection?: boolean;
jitoSignedTx?: string;
}
export interface BroadcastTransactionData {
orderId: string;
txHash: string;
}
export interface TransactionOrdersParams {
address: string;
chainIndex: string;
txStatus?: string;
orderId?: string;
cursor?: string;
limit?: string;
}
export interface TransactionOrder {
chainIndex: string;
orderId: string;
address: string;
txHash: string;
txStatus: string;
failReason: string;
}
export interface TransactionOrdersData {
cursor: string;
orders: TransactionOrder[];
}