@xchainjs/xchain-thorchain-amm
Version:
module that exposes estimating & swappping cryptocurrency assets on thorchain
274 lines (273 loc) • 6.54 kB
TypeScript
import { Balance, FeeOption } from '@xchainjs/xchain-client';
import { LiquidityPool, QuoteTHORName as BaseQuoteTHORName } from '@xchainjs/xchain-thorchain-query';
import { Address, Asset, AssetCryptoAmount, BaseAmount, Chain, CryptoAmount, SynthAsset, TokenAsset, TradeCryptoAmount } from '@xchainjs/xchain-util';
/**
* Represents the balance information for all assets on a particular chain.
*/
export type AllBalances = {
chain: Chain;
address: string;
balances: Balance[] | string;
};
/**
* Represents the parameters for executing a swap transaction.
*/
export type ExecuteSwap = {
input: CryptoAmount<Asset | TokenAsset | SynthAsset>;
destinationAsset: Asset | TokenAsset | SynthAsset;
destinationAddress?: Address;
memo: string;
feeOption?: FeeOption;
walletIndex: number;
};
/**
* Represents a submitted transaction.
*/
export type TxSubmitted = {
hash: string;
url: string;
};
/**
* Represents a liquidity position in a liquidity pool.
*/
export type LiquidityPosition = {
assetPool: LiquidityPool;
assetAmount: CryptoAmount<Asset | TokenAsset>;
runeAmount: AssetCryptoAmount;
impermanentLossProtection: number;
};
/**
* Represents the parameters for adding liquidity to a pool.
*/
export type AddLiquidity = {
asset: CryptoAmount<Asset | TokenAsset>;
rune: AssetCryptoAmount;
waitTimeSeconds: number;
assetPool: string;
};
/**
* Represents the parameters for withdrawing liquidity from a pool.
*/
export type WithdrawLiquidity = {
assetFee: CryptoAmount<Asset | TokenAsset>;
runeFee: AssetCryptoAmount;
waitTimeSeconds: number;
percentage: number;
assetPool: string;
assetAddress?: string;
runeAddress?: string;
};
/**
* Represents the parameters for depositing an asset.
*/
export type DepositParams = {
walletIndex?: number;
asset: Asset;
amount: BaseAmount;
feeOption: FeeOption;
memo: string;
};
/**
* Represents the parameters for opening a loan.
*/
export type LoanOpenParams = {
memo: string;
amount: CryptoAmount;
toAddress: Address;
};
/**
* Represents the parameters for closing a loan.
*/
export type LoanCloseParams = {
memo: string;
amount: CryptoAmount;
toAddress: Address;
};
/**
* Represents the parameters for registering a THORName.
*/
export type RegisterThornameParams = {
thorname: string;
owner?: string;
chain?: string;
chainAddress?: string;
preferredAsset?: Asset;
expirity?: Date;
};
/**
* Represents the parameters for updating a THORName.
*/
export type UpdateThornameParams = {
thorname: string;
owner?: string;
chain?: string;
chainAddress?: string;
preferredAsset?: Asset;
expirity?: Date;
};
export type IsApprovedParams = {
asset: TokenAsset;
amount: CryptoAmount<TokenAsset>;
address: Address;
};
export type ApproveParams = {
asset: TokenAsset;
amount?: CryptoAmount<TokenAsset>;
};
/**
* Estimation quote to register or update a THORName
*/
export type QuoteTHORName = BaseQuoteTHORName & {
/**
* If the action can be or not can be done
*/
allowed: boolean;
/**
* If any, list of errors with the reason the operation is not allowed
*/
errors: string[];
};
/**
* Add to trade account params
*/
export type AddToTradeAccountParams = {
/**
* Amount to add to the account
*/
amount: CryptoAmount<Asset | TokenAsset>;
/**
* Trade account address
*/
address: Address;
};
/**
* Estimation to add amount to trade account
*/
export type AddToTradeAccount = {
/**
* Address to send transaction
*/
toAddress: string;
/**
* Memo to add to the transaction to add the trade amount
*/
memo: string;
/**
* Amount to send to the address
*/
value: CryptoAmount<Asset | TokenAsset>;
/**
* If the action can be or not can be done
*/
allowed: boolean;
/**
* If any, list of errors with the reason the operation is not allowed
*/
errors: string[];
};
/**
* Withdraw from trade account params
*/
export type WithdrawFromTradeAccountParams = {
/**
* Amount to withdraw from the account
*/
amount: TradeCryptoAmount;
/**
* Address to make to the withdraw to
*/
address: Address;
};
/**
* Estimation to add amount to trade account
*/
export type WithdrawFromTradeAccount = {
/**
* Memo to add to the transaction to add the trade amount
*/
memo: string;
/**
* Amount to send to the address
*/
value: TradeCryptoAmount;
/**
* If the action can be or not can be done
*/
allowed: boolean;
/**
* If any, list of errors with the reason the operation is not allowed
*/
errors: string[];
};
/**
* Estimation to quote to deposit to Rune pool
*/
export type EstimateDepositToRunePool = {
/**
* Amount to send in the transaction to make the deposit
*/
amount: AssetCryptoAmount;
/**
* Memo to send in the transaction to make the deposit
*/
memo: string;
/**
* Number of blocks from the last deposit that a withdraw is allowed
*/
maturityBlocks: number;
/**
* If the action can be or not can be done
*/
allowed: boolean;
/**
* If any, list of errors with the reason the operation is not allowed
*/
errors: string[];
};
/**
* Deposit to Rune pool params
*/
export type DepositToRunePoolParams = {
/**
* Rune amount to deposit to the Rune pool
*/
amount: AssetCryptoAmount;
};
/**
* Estimation to quote to withdraw from Rune pool
*/
export type EstimateWithdrawFromRunePool = {
/**
* Amount to send in the transaction to make the withdraw
*/
amount: AssetCryptoAmount;
/**
* Memo to send in the transaction to make the withdraw
*/
memo: string;
/**
* If the action can be or not can be done
*/
allowed: boolean;
/**
* If any, list of errors with the reason the operation is not allowed
*/
errors: string[];
};
/**
* Withdraw from Rune pool params
*/
export type WithdrawFromRunePoolParams = {
/**
* Basis points to retrieve from the Rune pool position. Range 0-10000, where 10000 = 100%.
*/
withdrawBps: number;
/**
* Affiliate address
*/
affiliate?: Address;
/**
* Basis points to send to the affiliate address. Ranges from 0 to 1000 Basis Points.
*/
feeBps?: number;
};