Namespaces
business
The business namespace provides methods to interact with the Otmoic business service. It allows you to sign, send, confirm and refund assets, and submit complaints.
signQuote
signQuote(
network: NetworkType,
quote: Quote,
amount: string,
swapToNative: number,
receivingAddress: string,
expectedSingleStepTime?: number,
tolerantSingleStepTime?: number,
earliestRefundTime?: number,
rpcSrc?: string,
rpcDst?: string,
option: SignSwapOption
): Promise<SwapSignData | SwapSignedData>Signs a quote for a swap operation, supporting both EVM and Solana networks.
- Parameters:
network(NetworkType): The network typequote(Quote): The quote data to be signedamount(string): The amount to be swappedswapToNative(number): Percentage to swap to native tokenreceivingAddress(string): The address to receive the swapped tokensexpectedSingleStepTime(number, optional): Expected time for a single steptolerantSingleStepTime(number, optional): Tolerant time for a single stepearliestRefundTime(number, optional): Earliest refund timerpcSrc(string, optional): Source RPC endpointrpcDst(string, optional): Destination RPC endpointoption(SignSwapOption): Options for signing the quote
- Returns:
- Promise<SwapSignData | SwapSignedData>: The signed data and signature
transferOut
transferOut(
preBusiness: PreBusiness,
network: NetworkType,
rpc?: string,
option: SwapTransactionOption
): Promise<ContractTransaction | ResponseTransferOut | Transaction | ResponseSolana>Initiates a transfer out operation, supporting both EVM and Solana networks.
- Parameters:
preBusiness(PreBusiness): Pre-business datanetwork(NetworkType): The network typerpc(string, optional): RPC endpointoption(SwapTransactionOption): Options for the transfer out operation
- Returns:
- Promise<ContractTransaction | ResponseTransferOut | Transaction | ResponseSolana>: Response of the transfer out operation
transferOutConfirm
transferOutConfirm(
preBusiness: PreBusiness,
network: NetworkType,
rpc?: string,
option: SwapTransactionOption
): Promise<ContractTransaction | ContractTransactionResponse | Transaction | ResponseSolana>Confirms a transfer out operation, supporting both EVM and Solana networks.
- Parameters:
preBusiness(PreBusiness): Pre-business datanetwork(NetworkType): The network typerpc(string, optional): RPC endpointoption(SwapTransactionOption): Options for the transfer out confirmation
- Returns:
- Promise<ContractTransaction | ContractTransactionResponse | Transaction | ResponseSolana>: Response of the transfer out confirmation
transferInConfirm
transferInConfirm(
preBusiness: PreBusiness,
network: NetworkType,
rpc?: string,
sender: string,
option: SwapTransactionOption
): Promise<ContractTransaction | ContractTransactionResponse | Transaction | ResponseSolana>Confirms a transfer in operation, supporting both EVM and Solana networks.
- Parameters:
preBusiness(PreBusiness): Pre-business datanetwork(NetworkType): The network typerpc(string, optional): RPC endpointsender(string): The sender addressoption(SwapTransactionOption): Options for the transfer in confirmation
- Returns:
- Promise<ContractTransaction | ContractTransactionResponse | Transaction | ResponseSolana>: Response of the transfer in confirmation
transferOutRefund
transferOutRefund(
preBusiness: PreBusiness,
network: NetworkType,
rpc?: string,
option: SwapTransactionOption
): Promise<ContractTransaction | ContractTransactionResponse | Transaction | ResponseSolana>Refunds a transfer out operation, supporting both EVM and Solana networks.
- Parameters:
preBusiness(PreBusiness): Pre-business datanetwork(NetworkType): The network typerpc(string, optional): RPC endpointoption(SwapTransactionOption): Options for the transfer out refund
- Returns:
- Promise<ContractTransaction | ContractTransactionResponse | Transaction | ResponseSolana>: Response of the transfer out refund
complain
complain(
preBusiness: PreBusiness,
privateKey: string,
network: NetworkType
): Promise<string | boolean>Submits a complaint using a private key, supporting EVM networks.
- Parameters:
preBusiness(PreBusiness): Pre-business dataprivateKey(string): The private key for signingnetwork(NetworkType): The network type
- Returns:
Promise<string | boolean>: Result of the complaint submission
signComplainEIP712
signComplainEIP712(
preBusiness: PreBusiness,
network: NetworkType,
option: SignComplainEIP712Option
): Promise<ComplainSignedData | ComplainSignData>Signs a complaint using EIP-712, supporting EVM networks.
- Parameters:
preBusiness(PreBusiness): Pre-business datanetwork(NetworkType): The network typeoption(SignComplainEIP712Option): Options for signing the complaint
- Returns:
- Promise<ComplainSignedData | ComplainSignData>: The signed data and signature
utils
Collection of utility functions for chain operations and calculations.
GetChainName
GetChainName(systemChainId: ChainId): stringConverts a system chain ID to its human-readable name.
- Parameters:
systemChainId(ChainId): The system chain ID
- Returns:
string: Human-readable chain name (e.g., "ETH", "Solana")
GetNativeTokenName
GetNativeTokenName(systemChainId: ChainId): stringRetrieves the native token name for a given blockchain.
- Parameters:
systemChainId(ChainId): The system chain ID
- Returns:
string: Native token name (e.g., "ETH", "SOL")
GetChainId
GetChainId(systemChainId: ChainId, network: NetworkType): number | undefinedConverts a system chain ID to the network-specific chain ID.
- Parameters:
systemChainId(ChainId): The system chain IDnetwork(NetworkType): Network type ('mainnet' or 'testnet')
- Returns:
number | undefined: Network-specific chain ID
GetNativeTokenDecimals
GetNativeTokenDecimals(systemChainId: ChainId): numberRetrieves the number of decimals for the native token of a chain.
- Parameters:
systemChainId(ChainId): The system chain ID
- Returns:
number: Number of decimals for the native token
GetTokenDecimals
GetTokenDecimals(systemChainId: ChainId, tokenAddress: string, network: NetworkType, rpc: string | undefined): Promise<number>Retrieves the number of decimals for a token on any chain.
- Parameters:
systemChainId(ChainId): The system chain IDtokenAddress(string): The token addressnetwork(NetworkType): Network type ('mainnet' or 'testnet')rpc(string | undefined): The RPC endpoint, if omitted, the default will be provided
- Returns:
Promise<number>: Number of decimals for the token
GetChainType
GetChainType(systemChainId: ChainId): stringDetermines the type of blockchain (e.g., 'evm', 'solana') based on the system chain ID.
- Parameters:
systemChainId(ChainId): The system chain ID
- Returns:
string: Type of blockchain
MathReceived
MathReceived(quote: Quote, amount: string, swapToNative: number): DstAmountSetCalculates the received token amounts and native token amounts, considering fees and percentage swapping to native token.
- Parameters:
quote(Quote): The quote dataamount(string): Amount to be swappedswapToNative(number): Percentage to swap to native token
- Returns:
DstAmountSet(DstAmountSet): Object containing destination amounts
GetTokenAddress
GetTokenAddress(contractAddress: string, systemChainId: ChainId): stringRetrieves the standardized token address (Hex string) for a given chain.
- Parameters:
contractAddress(string): The contract addresssystemChainId(ChainId): The system chain ID
- Returns:
string: Standardized token address (Hex string)
Sleep
Sleep(ms: number): Promise<void>Pauses execution for a specified duration.
- Parameters:
ms(number): Duration in milliseconds
- Returns:
Promise<void>: Resolves after the specified duration
IsNeedApprove
IsNeedApprove(preBusiness: PreBusiness, userWallet: string, rpc?: string, network: NetworkType): Promise<boolean>Checks if an approval is needed for a evm token transfer.
- Parameters:
preBusiness(PreBusiness): Pre-business datauserWallet(string): The user's wallet addressrpc(string, optional): The RPC endpointnetwork(NetworkType): The network type
- Returns:
Promise<boolean>: True if approval is needed, false otherwise
GetApproveTransfer
GetApproveTransfer(preBusiness: PreBusiness, network: NetworkType): Promise<ContractTransaction>Constructs a raw transaction for approving a token transfer on the evm blockchain.
- Parameters:
preBusiness(PreBusiness): Pre-business datanetwork(NetworkType): Network type
- Returns:
- Promise<ContractTransaction>: Raw transaction data for the approval
GetGasPrice
GetGasPrice(provider: JsonRpcProvider, systemChainId: ChainId, network: NetworkType): Promise<GasPrice>Retrieves the current gas price for a network used in Otmoic.
- Parameters:
provider(JsonRpcProvider): The JSON RPC providersystemChainId(ChainId): The system chain IDnetwork(NetworkType): Network type
- Returns:
- Promise<GasPrice>: Current gas price
GetOnChainGasPrice
GetOnChainGasPrice(systemChainId: ChainId, network: NetworkType): Promise<bigint>Retrieves the on-chain gas price for an evm network.
- Parameters:
systemChainId(ChainId): The system chain IDnetwork(NetworkType): Network type
- Returns:
Promise<bigint>: On-chain gas price
GetBalance
GetBalance(bridge: Bridge, address: string, network: NetworkType, rpc?: string): Promise<string>Retrieves the balance of the src token on a bridge for a given address.
- Parameters:
bridge(Bridge): The bridge configurationaddress(string): The address to check the balance fornetwork(NetworkType): The network typerpc(string, optional): The RPC endpoint
- Returns:
Promise<string>: The balance of the token