@node-dlc/core
Version:
47 lines • 2.23 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoveredCall = void 0;
const messaging_1 = require("@node-dlc/messaging");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const BigIntUtils_1 = require("../../utils/BigIntUtils");
const HyperbolaPayoutCurve_1 = require("../HyperbolaPayoutCurve");
const buildCurve = (strikePrice, contractSize, 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(0);
const _tempHyperbolaPayoutCurve = 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));
const maxOutcomePayout = _tempHyperbolaPayoutCurve
.getPayout(maxOutcome)
.integerValue();
return {
maxOutcome,
totalCollateral: contractSize - (0, BigIntUtils_1.toBigInt)(maxOutcomePayout),
payoutCurve: new HyperbolaPayoutCurve_1.HyperbolaPayoutCurve(a, b, c, d, f_1, maxOutcomePayout.negated()),
};
};
const buildPayoutFunction = (strikePrice, contractSize, oracleBase, oracleDigits) => {
const { maxOutcome, totalCollateral, payoutCurve } = buildCurve(strikePrice, contractSize, oracleBase, oracleDigits);
const payoutFunction = new messaging_1.PayoutFunctionV0();
payoutFunction.endpoint0 = BigInt(0);
payoutFunction.endpointPayout0 = totalCollateral;
payoutFunction.extraPrecision0 = 0;
payoutFunction.pieces.push({
payoutCurvePiece: payoutCurve.toPayoutCurvePiece(),
endpoint: maxOutcome,
endpointPayout: BigInt(0),
extraPrecision: 0,
});
return {
payoutFunction,
totalCollateral,
};
};
exports.CoveredCall = { buildCurve, buildPayoutFunction };
//# sourceMappingURL=CoveredCall.js.map