@fleupold/dex-contracts
Version:
Contracts for dFusion multi-token batch auction exchange
71 lines (70 loc) • 2.76 kB
TypeScript
import BN from "bn.js";
import { Order, Solution, ObjectiveValueComputation } from "./examples/model";
/**
* Converts the amount value to `ether` unit.
* @param value - - The amount to convert
* @returns The value in `ether` as a bignum
*/
export declare function toETH(value: number): BN;
/**
* Removes fees to the specified value `n` times.
* @param x - - The value to apply the fee to
* @param n - - The number of times to apply the fee, must be greater than 0
* @returns The value minus fees
*/
export declare function feeSubtracted(x: BN, n?: number): BN;
/**
* Adds fees to the specified.
* @param x - The value to apply the fee to
* @returns The value plus fees
*/
export declare function feeAdded(x: BN): BN;
/**
* The error epsilon required for buy/sell amounts to account for rounding
* errors.
*/
export declare const ERROR_EPSILON: BN;
/**
* Calculates the executed buy amout given a buy volume and the settled buy and
* sell prices.
* @param executedBuyAmount - The executed buy amount
* @param buyTokenPrice - The buy token price
* @param sellTokenPrice - The sell token price
* @returns The value plus fees
*/
export declare function getExecutedSellAmount(executedBuyAmount: BN, buyTokenPrice: BN, sellTokenPrice: BN): BN;
/**
* Calculates the utility of an order given an executed buy amount and settled
* solution prices.
* @param order - The order
* @param executedBuyAmount - The executed buy amount
* @param prices - The prices
* @returns The order's utility
*/
export declare function orderUtility(order: Order, executedBuyAmount: BN, prices: BN[]): BN;
/**
* Calculates the disregarded utility of an order given an executed buy amount
* and settled solution prices.
* @param order - The order
* @param executedBuyAmount - The executed buy amount
* @param prices - The prices
* @returns The order's disregarded utility
*/
export declare function orderDisregardedUtility(order: Order, executedBuyAmount: BN, prices: BN[]): BN;
/**
* Calculates the total objective value for the specified solution given the
* order book.
* @param orders - The orders
* @param solution - The solution
* @returns The solution's objective value
*/
export declare function solutionObjectiveValue(orders: Order[], solution: Solution): BN;
/**
* Calculates the solutions objective value returning a computation object with
* all the intermediate values - useful for debugging.
* @param orders - The orders
* @param solution - The solution
* @param strict - Throw when solution is determined to be invalid
* @returns The solution's objective value computation object
*/
export declare function solutionObjectiveValueComputation(orders: Order[], solution: Solution, strict?: boolean): ObjectiveValueComputation;