@cashlab/cauldron
    Preparing search index...

    Class ExchangeLab

    Cauldron pool selector & transaction generator tool. Features:

    • Exchange bch/token pairs with cauldron's pool selectors.
    • Generate & verify exchange transactions
    Index

    Constructors

    Properties

    _compiler: CompilerBch
    _default_preferred_token_output_bch_amount: null | bigint
    _rate_denominator: bigint
    _template: WalletTemplate

    Methods

    • Construct a trade from a set of input_pools with the following condition, Demands offers below the target rate. Meaning the differential rate of the demand at the highest rate is below the provided rate. This function does not consider pool fees, Assumes all pools have zero fee.

      Parameters

      • supply_token_id: string

        the supply token of the trade

      • demand_token_id: string

        the demand token of the trade

      • rate: Fraction

        the target rate

      • input_pools: PoolV0[]

        a list of input cauldron pools

      Returns null | TradeResult

      the constructed trade result or null if no trade can be generated with the given condition

      ValueError

    • Construct a trade from a set of input_pools with the following condition, Demands as much possible with a target average rate. Meaning the differential rate of the demand at the highest rate is below the provided rate.

      Parameters

      • supply_token_id: string

        the supply token of the trade

      • demand_token_id: string

        the demand token of the trade

      • rate: Fraction

        the target rate

      • input_pools: PoolV0[]

        a list of input cauldron pools

      Returns null | TradeResult

      the constructed trade result or null

      ValueError

    • Construct a trade from a set of input_pools with the following condition, Demands at least the target amount at the best rate. The best rate is estimated based on the state of input_pools and the fixed cost of network transaction fee.

      Parameters

      • supply_token_id: string

        the supply token of the trade

      • demand_token_id: string

        the demand token of the trade

      • amount: bigint

        the order's target demand

      • input_pools: PoolV0[]

        a list of input cauldron pools

      • txfee_per_byte: bigint

        the network fee to be paid per byte

      Returns TradeResult

      the constructed trade result

      InsufficientCapitalInPools

      ValueError

    • Construct a trade from a set of input_pools with the following condition, Supply at most the target amount at the best rate. The best rate is estimated based on the state of input_pools and the fixed cost of network transaction fee.

      Parameters

      • supply_token_id: string

        the supply token of the trade

      • demand_token_id: string

        the demand token of the trade

      • amount: bigint

        the order's target demand

      • input_pools: PoolV0[]

        a list of input cauldron pools

      • txfee_per_byte: bigint

        the network fee to be paid per byte

      Returns TradeResult

      the constructed trade result

      InsufficientCapitalInPools

      ValueError

    • Create a chain of transactions from constructed trade.

      Parameters

      • input_pool_trade_list: PoolTrade[]

        a list of trades with pools.

      • input_coins: SpendableCoin[]

        a set of spendable coins used provide the supply side of the trade

      • payout_rules: PayoutRule[]

        a set of rules for the trade's payout + a pocket change

      • data_locking_bytecode: null | Uint8Array<ArrayBufferLike>

        an optional message to insert in the transaction as an OP_RETURN output

      • txfee_per_byte: number | bigint

        the rate of network fee (sat/byte)

      • Optionalcontroller: CreateChainedTradeTxController

        an optional controller used when generating the transactions

      Returns Promise<TradeTxResult[]>

      the trade's transaction result.

      ValueError

      InsufficientFunds

    • Create a transaction from constructed trade.

      Parameters

      • input_pool_trade_list: PoolTrade[]

        a list of trades with pools.

      • input_coins: SpendableCoin[]

        a set of spendable coins used provide the supply side of the trade

      • payout_rules: PayoutRule[]

        a set of rules for the trade's payout + a pocket change

      • data_locking_bytecode: null | Uint8Array<ArrayBufferLike>

        an optional message to insert in the transaction as an OP_RETURN output

      • txfee_per_byte: number | bigint

        the rate of network fee (sat/byte)

      Returns TradeTxResult

      the trade's transaction result.

      ValueError

      InsufficientFunds

    • Parameters

      • token_id: string

        the subject token_id

      Returns bigint

      the min token in reserve needed for any cauldron pool.

    • Parameters

      • output: Output

        the subject output

      Returns bigint

      the min bch amount required for the output to meet the network threshold

    • Parameters

      • output: Output

        the subject output

      Returns null | bigint

      the preferred bch amount for a token output

    • Get the default exchange rate's denominator

      Returns bigint

      the default denominator value of the rate

    • Reduce the supply of a constructed trade.

      Parameters

      • pool_trade_list: PoolTrade[]

        a pre-constructed list of trades with pools.

      • reduce_supply: bigint

        the amount to reduce the supply.

      Returns PoolTrade[]

      the reconstructed trades, represented in a list pools with the trade details

      ValueError

    • Parameters

      • value: null | bigint

        the default preferred token bch amount

      Returns void

    • Set the default exchange rate's denominator. A higher value will increase the rate's percision, A lower value reduces it. initial value: 10000000000000n

      Parameters

      • denominator: bigint

        the default rate's denominator

      Returns void

    • Verify the validity of a TradeTxResult, Expecting all generated transactions should be valid.

      Parameters

      • trade_tx_result: TradeTxResult

        the result of createTradeTx or createChainedTradeTx

      Returns void

      InvalidProgramState