UNPKG

@node-dlc/core

Version:
194 lines (193 loc) 9.98 kB
import { Value } from '@node-dlc/bitcoin'; import { DigitDecompositionEventDescriptorV0, OracleAnnouncement, OrderOffer, PayoutFunction, RoundingIntervals } from '@node-dlc/messaging'; import { BitcoinNetwork } from 'bitcoin-networks'; export declare const UNIT_MULTIPLIER: { bits: bigint; sats: bigint; }; /** * Round a number to the nearest multiple of a given multiplier. * * @param num - The number to be rounded. * @param multiplier - The multiplier to round to. * @returns The number rounded to the nearest multiple of the multiplier. * * @example * ```typescript * // Example: rounding to nearest 100 * const number = BigInt(354); * const multiplier = BigInt(100); * const roundedNumber = roundToNearestMultiplier(number, multiplier); * console.log(roundedNumber); // Output: 300 * ``` */ export declare const roundToNearestMultiplier: (num: bigint, multiplier: bigint) => bigint; /** * Round a number up to the nearest multiple of a given multiplier. * * @param num - The number to be rounded. * @param multiplier - The multiplier to round to. * @returns The number rounded up to the nearest multiple of the multiplier. * * @example * ```typescript * // Example: rounding up to nearest 100 * const number = BigInt(354); * const multiplier = BigInt(100); * const roundedNumber = roundToNearestMultiplier(number, multiplier); * console.log(roundedNumber); // Output: 400 * ``` */ export declare const roundUpToNearestMultiplier: (num: bigint, multiplier: bigint) => bigint; export declare const roundDownToNearestMultiplier: (num: bigint, multiplier: bigint) => bigint; export type DlcParty = 'offeror' | 'acceptor' | 'neither'; /** * Compute rounding intervals for a linear or hyperbola payout curve * * @param {number | bigint | Value} rounding rounding interval in sats * @param {number | bigint | Value} contractSize contract size in sats * @returns rounding mod for contract size */ export declare const computeRoundingModulus: (rounding: number | bigint | Value, contractSize: number | bigint | Value) => bigint; /** * Get digit decomposition event descriptor from oracle announcement * * @param {OracleAnnouncement} announcement oracle announcement * @returns {DigitDecompositionEventDescriptorV0} event descriptor */ export declare const getDigitDecompositionEventDescriptor: (announcement: OracleAnnouncement) => DigitDecompositionEventDescriptorV0; /** * Build an orderoffer for ContractDescriptorV1 * * @param {OracleAnnouncement} announcement oracle announcement * @param {bigint} totalCollateral total collateral in satoshis * @param {bigint} offerCollateral offer collateral in satoshis * @param {PayoutFunction} payoutFunction * @param {RoundingIntervals} roundingIntervals * @param {bigint} feePerByte sats/vbyte * @param {NetworkName} network * @returns {OrderOffer} Returns order offer */ export declare const buildOrderOffer: (announcement: OracleAnnouncement, totalCollateral: bigint, offerCollateral: bigint, payoutFunction: PayoutFunction, roundingIntervals: RoundingIntervals, feePerByte: bigint, network: string) => OrderOffer; /** * Builds an order offer for a covered call or short put * * @param {OracleAnnouncement} announcement oracle announcement * @param {number} contractSize contract size in satoshis * @param {number} strikePrice strike price of contract * @param {number} premium premium of contract in satoshis * @param {number | bigint} feePerByte sats/vbyte * @param {number} rounding rounding interval * @param {string} network bitcoin network type * @param {string} type call or put * @param {number} _totalCollateral total collateral in satoshis (applicable only for short put) * @returns {OrderOffer} Returns order offer */ export declare const buildOptionOrderOffer: (announcement: OracleAnnouncement, contractSize: Value, strikePrice: number, premium: Value, feePerByte: number | bigint, rounding: number, network: string, type: 'call' | 'put', direction: 'long' | 'short', _totalCollateral?: Value) => OrderOffer; /** * Builds an order offer for a covered call * * @param {OracleAnnouncement} announcement oracle announcement * @param {number} contractSize contract size in satoshis * @param {number} strikePrice strike price of contract * @param {number} premium premium of contract in satoshis * @param {number} feePerByte sats/vbyte * @param {number} rounding rounding interval * @param {string} network bitcoin network type * @returns {OrderOffer} Returns order offer */ export declare const buildCoveredCallOrderOffer: (announcement: OracleAnnouncement, contractSize: Value, strikePrice: number, premium: Value, feePerByte: number, rounding: number, network: string) => OrderOffer; /** * Builds an order offer for a short put * * @param {OracleAnnouncement} announcement oracle announcement * @param {number} contractSize contract size in satoshis * @param {number} strikePrice strike price of contract * @param {number} totalCollateral total collateral in satoshis * @param {number} premium premium of contract in satoshis * @param {number} feePerByte sats/vbyte * @param {number} rounding rounding interval * @param {string} network bitcoin network type * @returns {OrderOffer} Returns order offer */ export declare const buildShortPutOrderOffer: (announcement: OracleAnnouncement, contractSize: Value, strikePrice: number, totalCollateral: Value, premium: Value, feePerByte: number, rounding: number, network: string) => OrderOffer; /** * Builds an order offer for a long call * * @param {OracleAnnouncement} announcement oracle announcement * @param {number} contractSize contract size in satoshis * @param {number} strikePrice strike price of contract * @param {number} maxGain maximum amount that can be gained (totalCollateral) * @param {number} premium premium of contract in satoshis * @param {number} feePerByte sats/vbyte * @param {number} rounding rounding interval * @param {string} network bitcoin network type * @returns {OrderOffer} Returns order offer */ export declare const buildLongCallOrderOffer: (announcement: OracleAnnouncement, contractSize: Value, strikePrice: number, maxGain: Value, premium: Value, feePerByte: number, rounding: number, network: string) => OrderOffer; /** * Builds an order offer for a long put * * @param {OracleAnnouncement} announcement oracle announcement * @param {number} contractSize contract size in satoshis * @param {number} strikePrice strike price of contract * @param {number} maxGain maximum amount that can be gained (totalCollateral) * @param {number} premium premium of contract in satoshis * @param {number} feePerByte sats/vbyte * @param {number} rounding rounding interval * @param {string} network bitcoin network type * @returns {OrderOffer} Returns order offer */ export declare const buildLongPutOrderOffer: (announcement: OracleAnnouncement, contractSize: Value, strikePrice: number, maxGain: Value, premium: Value, feePerByte: number, rounding: number, network: string) => OrderOffer; /** * Builds an order offer for a linear curve * * @param {OracleAnnouncement} announcement oracle announcement * @param {Value} offerCollateral offer collateral amount * @param {Value} minPayout minimum payout * @param {Value} maxPayout maximum payout (also total collateral) * @param {bigint} startOutcome oracle outcome (in bits or sats) * @param {bigint} endOutcome oracle outcome (in bits or sats) * @param {bigint} feePerByte sats/vbyte * @param {Value} rounding rounding mod for RoundingInterval * @param {BitcoinNetwork} network bitcoin, bitcoin_testnet or bitcoin_regtest * @param {DlcParty} [shiftForFees] shift for offerer, acceptor or neither (who should pay fees) * @param {Value} [fees] fees to shift * @returns {OrderOffer} */ export declare const buildLinearOrderOffer: (announcement: OracleAnnouncement, offerCollateral: Value, minPayout: Value, maxPayout: Value, startOutcome: bigint, endOutcome: bigint, feePerByte: bigint, roundingIntervals: RoundingIntervals, network: BitcoinNetwork, shiftForFees?: DlcParty, fees?: Value) => OrderOffer; /** * Builds a custom strategy order offer * * Calculates offer fees * calculates the minimum max gain * maxLoss and maxGain are normalized to 1 BTC contracts * * shiftForFees 'offeror' means 'offeror' pays network fees * shiftForFees 'acceptor' means 'acceptor' pays network fees * * numContracts refers to the number of DLCs in the funding transaction * if it's not a batch dlc funding transaction, then this is not relevant * * @param {OracleAnnouncement} announcement oracle announcement * @param {Value} contractSize contract size * @param {Value} normalizedMaxLoss maximum amount that can be lost based on 1 BTC contract * @param {Value} normalizedMaxGain maximum amount that can be gained based on 1 BTC contract * @param {bigint} feePerByte sats/vbyte * @param {Value} roundingIntervals rounding mod for RoundingInterval * @param {BitcoinNetwork} network bitcoin, bitcoin_testnet or bitcoin_regtest * @param {DlcParty} [shiftForFees] shift for offerer, acceptor or neither * @param {Value} [fees_] fees to shift * @param {Value} [collateral] collateral to use * @param {number} [numOfferInputs] number of inputs to use * @param {number} [numContracts] number of DLCs in the funding transaction * * @returns {OrderOffer} */ export declare const buildCustomStrategyOrderOffer: (announcement: OracleAnnouncement, contractSize: Value, normalizedMaxLoss: Value, normalizedMaxGain: Value, feePerByte: bigint, roundingIntervals: RoundingIntervals, network: BitcoinNetwork, shiftForFees?: DlcParty, fees_?: Value, collateral?: Value, numOfferInputs?: number, numContracts?: number, skipValidation?: boolean) => OrderOffer; interface IInterval { beginInterval: bigint; rounding: number | bigint | Value; } export declare const buildRoundingIntervalsFromIntervals: (contractSize: Value, intervals: IInterval[]) => RoundingIntervals; export {};