UNPKG

@node-dlc/core

Version:
42 lines 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShortPut = void 0; const messaging_1 = require("@node-dlc/messaging"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const HyperbolaPayoutCurve_1 = require("../HyperbolaPayoutCurve"); const buildCurve = (strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits) => { const a = new bignumber_js_1.default(-1); const b = new bignumber_js_1.default(0); const c = new bignumber_js_1.default(0); const d = new bignumber_js_1.default((strikePrice * contractSize).toString()); const f_1 = new bignumber_js_1.default(0); const f_2 = new bignumber_js_1.default(Number(contractSize)).plus(Number(totalCollateral)); const payoutCurve = new HyperbolaPayoutCurve_1.HyperbolaPayoutCurve(a, b, c, d, f_1, f_2); const maxOutcome = BigInt(new bignumber_js_1.default(oracleBase).pow(oracleDigits).minus(1).toString(10)); return { maxOutcome, totalCollateral, payoutCurve, }; }; const buildPayoutFunction = (strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits) => { const { maxOutcome, payoutCurve } = buildCurve(strikePrice, contractSize, totalCollateral, oracleBase, oracleDigits); const payoutFunction = new messaging_1.PayoutFunctionV0(); payoutFunction.endpoint0 = BigInt(0); payoutFunction.endpointPayout0 = BigInt(0); payoutFunction.extraPrecision0 = 0; payoutFunction.pieces.push({ payoutCurvePiece: payoutCurve.toPayoutCurvePiece(), endpoint: maxOutcome, endpointPayout: totalCollateral, extraPrecision: 0, }); return { payoutFunction, }; }; exports.ShortPut = { buildCurve, buildPayoutFunction }; //# sourceMappingURL=ShortPut.js.map