UNPKG

@node-dlc/core

Version:
79 lines 3.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LinearPayout = void 0; const messaging_1 = require("@node-dlc/messaging"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const PolynomialPayoutCurve_1 = require("../PolynomialPayoutCurve"); const buildPayoutFunction = (minPayout, maxPayout, startOutcome, endOutcome, oracleBase, oracleDigits) => { // Max outcome limited by the oracle const maxOutcome = BigInt(new bignumber_js_1.default(oracleBase).pow(oracleDigits).minus(1).toString(10)); // max loss line const payoutCurveMaxLoss = new PolynomialPayoutCurve_1.PolynomialPayoutCurve([ { outcome: new bignumber_js_1.default(0), payout: new bignumber_js_1.default(Number(minPayout)) }, { outcome: new bignumber_js_1.default(Number(startOutcome)), payout: new bignumber_js_1.default(Number(minPayout)), }, ]); // payout line const payoutCurve = new PolynomialPayoutCurve_1.PolynomialPayoutCurve([ { outcome: new bignumber_js_1.default(Number(startOutcome)), payout: new bignumber_js_1.default(Number(minPayout)), }, { outcome: new bignumber_js_1.default(Number(endOutcome)), payout: new bignumber_js_1.default(Number(maxPayout)), }, ]); // max gain line const payoutCurveMaxGain = new PolynomialPayoutCurve_1.PolynomialPayoutCurve([ { outcome: new bignumber_js_1.default(Number(endOutcome)), payout: new bignumber_js_1.default(Number(maxPayout)) }, { outcome: new bignumber_js_1.default(Number(maxOutcome)), payout: new bignumber_js_1.default(Number(maxPayout)), }, ]); const payoutFunction = new messaging_1.PayoutFunction(); // Defensive fix: ensure payoutFunctionPieces is initialized as an array if (!payoutFunction.payoutFunctionPieces) { payoutFunction.payoutFunctionPieces = []; } payoutFunction.payoutFunctionPieces.push({ endPoint: { eventOutcome: startOutcome, outcomePayout: minPayout, extraPrecision: 0, }, payoutCurvePiece: payoutCurveMaxLoss.toPayoutCurvePiece(), }); payoutFunction.payoutFunctionPieces.push({ endPoint: { eventOutcome: endOutcome, outcomePayout: maxPayout, extraPrecision: 0, }, payoutCurvePiece: payoutCurve.toPayoutCurvePiece(), }); payoutFunction.payoutFunctionPieces.push({ endPoint: { eventOutcome: maxOutcome, outcomePayout: maxPayout, extraPrecision: 0, }, payoutCurvePiece: payoutCurveMaxGain.toPayoutCurvePiece(), }); payoutFunction.lastEndpoint = { eventOutcome: maxOutcome, outcomePayout: maxPayout, extraPrecision: 0, }; return { payoutFunction, }; }; exports.LinearPayout = { buildPayoutFunction }; //# sourceMappingURL=LinearPayout.js.map