@bnb-chain/canonical-bridge-sdk
Version:
canonical bridge sdk
118 lines (116 loc) • 5.24 kB
TypeScript
import { IBaseBridgeConfig, IBaseBridgeConfigOptions } from '../../core/types';
import { ICBridgeChain, ICBridgeEstimateAmountRequest, ICBridgeEstimateAmountResponse, ICBridgePeggedPairConfig, ICBridgeSendRangeInput, ICBridgeTransferEstimatedTime, ICBridgeTokenValidateParams, IGetCBridgeABI, IGetCBridgeTransferAddressInput, IGetCBridgeTransferFunction, IGetCBridgeTransferParamsInput, ISendCBridgeToken } from './types';
import { Hash } from 'viem';
export declare function cBridgeConfig(options: IBaseBridgeConfigOptions): IBaseBridgeConfig;
export declare class CBridge {
private client?;
constructor(config: IBaseBridgeConfig);
getEstimatedAmount(params: ICBridgeEstimateAmountRequest): Promise<ICBridgeEstimateAmountResponse>;
/**
* Get estimated waiting time for cross-chain transfer
*
* @param number srcChainId source chain ID
* @param number dstChainId destination chain ID
*/
getEstimatedWaitingTime({ srcChainId, dstChainId, }: {
srcChainId: number;
dstChainId: number;
}): Promise<ICBridgeTransferEstimatedTime>;
/**
* Get minimum and maximum token transfer
* Only get minimum and maximum send amount
* @param {Address} bridgeAddress - Bridge address
* @param {Address} tokenAddress - Token address
* @param {PublicClient} client - Public client
* @returns {Object} min and max amount
*/
getSendRange({ bridgeAddress, tokenAddress, client, }: ICBridgeSendRangeInput): Promise<{
min: bigint;
max: bigint;
}>;
/**
* Send token through CBridge
* @param {WalletClient} walletClient Wallet client
* @param {PublicClient} publicClient Wallet client
* @param {Address} bridgeAddress Bridge address
* @param {Object[]} bridgeABI Bridge ABI
* @param {String} functionName Function name
* @param {Address} address wallet/account address
* @param {Object[]} args Function arguments
* @returns
*/
sendToken({ walletClient, publicClient, bridgeAddress, fromChainId, address, isPegged, peggedConfig, args, }: ISendCBridgeToken): Promise<Hash>;
/**
* Get cBridge contract address from cross chain transfer
*
* @param fromChainId Chain ID of the source chain
* @param isPegged Pool-based transfer(xLiquidity) - false
* Canonical Mapping Transfer(xAsset) - true
* @param peggedConfig Pegged pair configuration
* @param chainConfig Chain configuration
*/
getTransferAddress({ fromChainId, isPegged, peggedConfig, chainConfig, }: IGetCBridgeTransferAddressInput): string;
/**
* Get cBridge transfer parameters
*
* @param amount Send amount
* @param isPegged Pool-based transfer(xLiquidity) - false
* Canonical Mapping Transfer(xAsset) - true
* @param toChainId Chain ID of the destination chain
* @param tokenAddress Address of ERC20 token
* @param address User address
* @param maxSlippage Maximum slippage
* @param transferType Transfer type - deposit | withdraw
* @param peggedConfig Pegged pair configuration
* @param nonce Nonce current timestamp
*/
getTransferParams({ amount, isPegged, toChainId, tokenAddress, address, maxSlippage, transferType, peggedConfig, nonce, }: IGetCBridgeTransferParamsInput): (number | bigint | `0x${string}`)[] | null;
/**
* Get cross chain transfer ABI
*
* @param isPegged Pool-based transfer(xLiquidity) - false
* Canonical Mapping Transfer(xAsset) - true
* @param transferType Transfer type - deposit | withdraw
* @param peggedConfig Pegged pair configuration
*/
getABI({ isPegged, transferType, peggedConfig }: IGetCBridgeABI): any;
/**
* Get cross chain transfer function name
*
* @param isPegged
* @returns string
*/
getTransferFunction({ isPegged, transferType }: IGetCBridgeTransferFunction): "" | "deposit" | "burn" | "send";
/**
* Get transfer type
*/
getTransferType({ peggedConfig, fromChainId, }: {
fromChainId: number;
peggedConfig?: ICBridgePeggedPairConfig;
}): "deposit" | "withdraw" | undefined;
/**
* Generate cBridge transfer arguments
*/
getArguments({ isPegged, peggedConfig, chainConfig, amount, fromChainId, toChainId, tokenAddress, userAddress, maxSlippage, nonce, }: {
isPegged: boolean;
peggedConfig?: ICBridgePeggedPairConfig;
chainConfig?: ICBridgeChain;
amount: bigint;
fromChainId: number;
toChainId: number;
tokenAddress: `0x${string}`;
userAddress: `0x${string}`;
maxSlippage: number;
nonce: number;
}): {
address: `0x${string}`;
abi: any;
functionName: string;
account: `0x${string}`;
args: (number | bigint | `0x${string}`)[] | null;
};
/**
* validate token and contract information
*/
validateCBridgeToken: ({ isPegged, fromChainId, fromTokenAddress, fromTokenSymbol, fromTokenDecimals, bridgeAddress, toChainId, toTokenAddress, toTokenSymbol, toTokenDecimals, amount, cBridgeEndpoint, }: ICBridgeTokenValidateParams) => Promise<boolean>;
}