UNPKG

@node-dlc/core

Version:
67 lines 2.81 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.PayoutFunctionV0(); payoutFunction.endpoint0 = BigInt(0); payoutFunction.endpointPayout0 = minPayout; payoutFunction.extraPrecision0 = 0; payoutFunction.pieces.push({ payoutCurvePiece: payoutCurveMaxLoss.toPayoutCurvePiece(), endpoint: startOutcome, endpointPayout: minPayout, extraPrecision: 0, }); payoutFunction.pieces.push({ payoutCurvePiece: payoutCurve.toPayoutCurvePiece(), endpoint: endOutcome, endpointPayout: maxPayout, extraPrecision: 0, }); payoutFunction.pieces.push({ payoutCurvePiece: payoutCurveMaxGain.toPayoutCurvePiece(), endpoint: maxOutcome, endpointPayout: maxPayout, extraPrecision: 0, }); return { payoutFunction, }; }; exports.LinearPayout = { buildPayoutFunction }; //# sourceMappingURL=LinearPayout.js.map