@xchainjs/xchain-thorchain-amm
Version:
module that exposes estimating & swappping cryptocurrency assets on thorchain
217 lines (215 loc) • 11.3 kB
TypeScript
import { AddliquidityPosition, EstimateAddLP, EstimateAddSaver, EstimateWithdrawLP, EstimateWithdrawSaver, LoanCloseParams, LoanCloseQuote, LoanOpenParams, LoanOpenQuote, QuoteSwapParams, RegisterTHORName, SaversPosition, SaversWithdraw, ThorchainQuery, TxDetails, UpdateTHORName, WithdrawLiquidityPosition, getSaver } from '@xchainjs/xchain-thorchain-query';
import { Asset, CryptoAmount, TokenAsset } from '@xchainjs/xchain-util';
import { Wallet } from '@xchainjs/xchain-wallet';
import { AddToTradeAccount, AddToTradeAccountParams, ApproveParams, DepositToRunePoolParams, EstimateDepositToRunePool, EstimateWithdrawFromRunePool, IsApprovedParams, QuoteTHORName, TxSubmitted, WithdrawFromRunePoolParams, WithdrawFromTradeAccount, WithdrawFromTradeAccountParams } from './types';
/**
* THORChain Class for interacting with THORChain.
* Recommended main class to use for swapping with THORChain
* Has access to Midgard and THORNode data
*/
export declare class ThorchainAMM {
private thorchainQuery;
private wallet;
/**
* Constructor to create a ThorchainAMM instance
*
* @param thorchainQuery - an instance of the ThorchainQuery
* @returns ThorchainAMM
*/
constructor(thorchainQuery?: ThorchainQuery, wallet?: Wallet);
/**
* * Provides an estimate for a swap based on the given swap details.
* Checks the parameters for errors before attempting to retrieve the estimate.
* Utilizes current pool data to calculate inbound and outbound fees, affiliate fees,
* and the expected wait time for the swap (inbound and outbound).
* @param params Parameters for the swap, including the amount to swap.
* @returns The estimated swap details.
*/
estimateSwap({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, liquidityToleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxDetails>;
/**
* Validate swap params
* @param {QuoteSwapParams} quoteSwapParams Swap params
* @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
*/
validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<string[]>;
/**
* Conducts a swap with the given inputs. This method should be called after estimateSwap() to ensure the swap is valid.
*
* @param wallet - The wallet to use for the swap.
* @param params - The swap parameters.
* @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
*/
doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }: QuoteSwapParams): Promise<TxSubmitted>;
/**
* Approve the Thorchain router to spend a certain amount in the asset chain.
* @param {ApproveParams} approveParams Parameters for approving the router to spend
* @returns {Promise<TxSubmitted>} Transaction hash and URL
*/
approveRouterToSpend({ asset, amount }: ApproveParams): Promise<TxSubmitted>;
/**
* Validate if the asset router is allowed to spend the asset amount in name of the address
* @param {IsApprovedParams} isApprovedParams contains the asset and the amount the router is supposed to spend
* int name of address
* @returns {string[]} the reasons the router of the asset is not allowed to spend the amount. If it is empty, the asset router is allowed to spend the amount
*/
isRouterApprovedToSpend({ asset, amount, address }: IsApprovedParams): Promise<string[]>;
/**
* Wraps the estimate from ThorchainQuery for adding liquidity.
* @param params - The parameters for estimating adding liquidity.
* @returns - The estimated liquidity addition object.
*/
estimateAddLiquidity(params: AddliquidityPosition): Promise<EstimateAddLP>;
/**
* Wraps the estimate from ThorchainQuery for withdrawing liquidity.
* @param params - The parameters for estimating withdrawing liquidity.
* @returns - The estimated liquidity withdrawal object.
*/
estimateWithdrawLiquidity(params: WithdrawLiquidityPosition): Promise<EstimateWithdrawLP>;
/**
* If there is no existing liquidity position, it is created automatically.
* @param wallet - Wallet class
* @param params - Liquidity parameter
* @returns
*/
addLiquidityPosition(params: AddliquidityPosition): Promise<TxSubmitted[]>;
/**
* Withdraws liquidity from a position.
* @param params - The wallet to perform the transaction.
* @return - The array of transaction submissions.
*/
withdrawLiquidityPosition(params: WithdrawLiquidityPosition): Promise<TxSubmitted[]>;
/**
* Estimates adding to a saver.
* @param addAssetAmount The amount to add to the saver.
* @returns The estimated addition to the saver object.
*/
estimateAddSaver(addAssetAmount: CryptoAmount<Asset | TokenAsset>): Promise<EstimateAddSaver>;
/**
* Estimates withdrawing from a saver.
* @param withdrawParams The parameters for withdrawing from the saver.
* @returns The estimated withdrawal from the saver object.
*/
estimateWithdrawSaver(withdrawParams: SaversWithdraw): Promise<EstimateWithdrawSaver>;
/**
* Retrieves the position of a saver.
* @param getsaver The parameters to retrieve the saver position.
* @returns The saver position object.
*/
getSaverPosition(getsaver: getSaver): Promise<SaversPosition>;
/**
* Adds assets to a saver.
* @param wallet - wallet needed to execute tx
* @param addAssetAmount - The amount to add to the saver.
* @returns - The submitted transaction.
*/
addSaver(addAssetAmount: CryptoAmount<Asset | TokenAsset>): Promise<TxSubmitted>;
/**
* Withdraws assets from a saver.
* @param withdrawParams - The parameters for withdrawing from the saver.
* @returns The submitted transaction.
*/
withdrawSaver(withdrawParams: SaversWithdraw): Promise<TxSubmitted>;
/**
* Retrieves a quote for opening a loan.
* @param loanOpenParams The parameters for opening the loan.
* @returns The quote for opening the loan.
*/
getLoanQuoteOpen(loanOpenParams: LoanOpenParams): Promise<LoanOpenQuote>;
/**
* Retrieves a quote for closing a loan.
* @param loanCloseParams The parameters for closing the loan.
* @returns The quote for closing the loan.
*/
getLoanQuoteClose(loanCloseParams: LoanCloseParams): Promise<LoanCloseQuote>;
/**
* Opens a loan.
* @param loanOpenParams - The parameters for opening the loan.
* @returns - The submitted transaction.
*/
addLoan(loanOpenParams: LoanOpenParams): Promise<TxSubmitted>;
/**
* Withdraws assets from a loan.
* @param loanCloseParams - The parameters for withdrawing from the loan.
* @returns The submitted transaction.
*/
withdrawLoan(loanCloseParams: LoanCloseParams): Promise<TxSubmitted>;
/**
* Retrieves all Thornames and their associated data owned by an address.
* @param address - The address to retrieve Thornames for.
* @returns The Thornames data.
*/
getThornamesByAddress(address: string): Promise<import("@xchainjs/xchain-midgard/lib").ReverseTHORNames | undefined>;
/**
* Estimate the cost of a THORName registration
* @param {RegisterTHORName} params Params to make the registration
* @returns {QuoteTHORName} Memo to make the registration and the estimation of the operation
*/
estimateTHORNameRegistration(params: RegisterTHORName): Promise<QuoteTHORName>;
/**
* Estimate the cost of an update of a THORName
* @param {QuoteTHORNameParams} params Params to make the update
* @returns {QuoteTHORName} Memo to make the update and the estimation of the operation
*/
estimateTHORNameUpdate(params: UpdateTHORName): Promise<QuoteTHORName>;
/**
* Register a THORName
* @param {RegisterTHORName} params Params to make the registration
* @returns {TxSubmitted} Transaction made to register the THORName
*/
registerTHORName(params: RegisterTHORName): Promise<TxSubmitted>;
/**
* Update a THORName
* @param {UpdateTHORName} params Params to make the update
* @returns {TxSubmitted} Transaction made to update the THORName
*/
updateTHORName(params: UpdateTHORName): Promise<TxSubmitted>;
/**
* Estimate adding trade amount to account
* @param {AddToTradeAccountParams} param Add to trade account params
* @returns {AddToTradeAccount} Estimation to add amount to trade account
*/
estimateAddToTradeAccount({ amount, address }: AddToTradeAccountParams): Promise<AddToTradeAccount>;
/**
* Add trade amount to account
* @param {AddToTradeAccountParams} param Add to trade account params
* @returns {TxSubmitted} Transaction made to add the trade amount
*/
addToTradeAccount({ amount, address }: AddToTradeAccountParams): Promise<TxSubmitted>;
/**
* Estimate withdrawing trade amount from account
* @param {WithdrawFromTradeAccountParams} param Withdraw from trade account params
* @returns {WithdrawFromTradeAccount} Estimation to withdraw amount from trade account
*/
estimateWithdrawFromTradeAccount({ amount, address, }: WithdrawFromTradeAccountParams): Promise<WithdrawFromTradeAccount>;
/**
* Withdraw trade amount from account
* @param {WithdrawFromTradeAccountParams} param Withdraw from trade account params
* @returns {TxSubmitted} Estimation to withdraw amount from trade account
*/
withdrawFromTradeAccount({ amount, address }: WithdrawFromTradeAccountParams): Promise<TxSubmitted>;
/**
* Estimate Rune pool deposit
* @param {DepositToRunePoolParams} params Deposit to Rune pool params
* @returns {EstimateDepositToRunePool} Estimation to make the deposit
*/
estimateDepositToRunePool({ amount }: DepositToRunePoolParams): Promise<EstimateDepositToRunePool>;
/**
* Deposit amount to Rune pool
* @param {DepositToRunePoolParams} amount Amount to deposit to Rune pool
* @returns {TxSubmitted} Transaction made to deposit to Rune pool
*/
depositToRunePool(params: DepositToRunePoolParams): Promise<TxSubmitted>;
/**
* Estimate Rune pool withdraw
* @param {WithdrawFromRunePoolParams} params Withdraw from Rune pool params
* @returns {EstimateWithdrawFromRunePool} Estimation to make a withdraw from Rune pool
*/
estimateWithdrawFromRunePool({ withdrawBps, affiliate, feeBps, }: WithdrawFromRunePoolParams): Promise<EstimateWithdrawFromRunePool>;
/**
* Withdraw amount from Rune pool
* @param {WithdrawFromRunePoolParams} params Withdraw from Rune pool params
* @returns {TxSubmitted} Transaction made to withdraw from Rune pool
*/
withdrawFromRunePool(params: WithdrawFromRunePoolParams): Promise<TxSubmitted>;
private isTHORName;
}