Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 248x 1x 422x 1x 3x 1x 329x 329x 329x 1x 259x 259x 259x 1x 88x 88x 88x 88x 88x 88x 88x 88x 88x 88x 88x 88x 88x 88x 2816x 88x 88x 88x 88x 88x 88x 88x 1x 5x 5x 5x 5x 3x 1x 1x 1x 2x 2x 2x 2x 2x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 2x 1x 1x 1x 1x 1x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 1x 84x 1x 83x 75x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 5x 78x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 7x 7x 76x 67x 67x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 1x 77x 77x 308x 308x 77x | import { Value } from '@node-dlc/bitcoin';
import {
DigitDecompositionEventDescriptorV0,
MessageType,
NumericalDescriptor,
OracleAnnouncement,
OrderOffer,
OrderPositionInfo,
PayoutFunction,
RoundingIntervals,
SingleContractInfo,
SingleOracleInfo,
} from '@node-dlc/messaging';
import {
BitcoinNetwork,
BitcoinNetworks,
chainHashFromNetwork,
} from 'bitcoin-networks';
import Decimal from 'decimal.js';
import { dustThreshold } from '../CoinSelect';
import { getFinalizerByCount } from '../TxFinalizer';
import { CoveredCall } from './CoveredCall';
import { LinearPayout } from './LinearPayout';
import { LongCall } from './LongCall';
import { LongPut } from './LongPut';
import { ShortPut } from './ShortPut';
export const UNIT_MULTIPLIER = {
bits: BigInt(1e2),
sats: BigInt(1),
};
/**
* 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 const roundToNearestMultiplier = (
num: bigint,
multiplier: bigint,
): bigint => (num / multiplier) * multiplier;
/**
* 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 const roundUpToNearestMultiplier = (
num: bigint,
multiplier: bigint,
): bigint => ((num + multiplier - BigInt(1)) / multiplier) * multiplier;
export const roundDownToNearestMultiplier = (
num: bigint,
multiplier: bigint,
): bigint => num - (num % multiplier);
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 const computeRoundingModulus = (
rounding: number | bigint | Value,
contractSize: number | bigint | Value,
): bigint => {
const roundingInSats =
rounding instanceof Value
? rounding.sats
: typeof rounding === 'number'
? BigInt(Math.round(rounding * 1e8)) // Convert bitcoin amount to satoshis
: rounding;
const contractSizeInSats =
contractSize instanceof Value
? contractSize.sats
: typeof contractSize === 'number'
? BigInt(Math.round(contractSize * 1e8)) // Convert bitcoin amount to satoshis
: contractSize;
return (roundingInSats * contractSizeInSats) / BigInt(1e8);
};
/**
* Get digit decomposition event descriptor from oracle announcement
*
* @param {OracleAnnouncement} announcement oracle announcement
* @returns {DigitDecompositionEventDescriptorV0} event descriptor
*/
export const getDigitDecompositionEventDescriptor = (
announcement: OracleAnnouncement,
): DigitDecompositionEventDescriptorV0 => {
Iif (
announcement.oracleEvent.eventDescriptor.type !==
MessageType.DigitDecompositionEventDescriptorV0
)
throw Error('Only DigitDecompositionEventDescriptorV0 currently supported');
const eventDescriptor = announcement.oracleEvent
.eventDescriptor as DigitDecompositionEventDescriptorV0;
return eventDescriptor;
};
/**
* 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 const buildOrderOffer = (
announcement: OracleAnnouncement,
totalCollateral: bigint,
offerCollateral: bigint,
payoutFunction: PayoutFunction,
roundingIntervals: RoundingIntervals,
feePerByte: bigint,
network: string,
): OrderOffer => {
const eventDescriptor = getDigitDecompositionEventDescriptor(announcement);
const contractDescriptor = new NumericalDescriptor();
contractDescriptor.numDigits = eventDescriptor.nbDigits;
contractDescriptor.payoutFunction = payoutFunction;
contractDescriptor.roundingIntervals = roundingIntervals;
const oracleInfo = new SingleOracleInfo();
oracleInfo.announcement = announcement;
const contractInfo = new SingleContractInfo();
contractInfo.totalCollateral = totalCollateral;
contractInfo.contractDescriptor = contractDescriptor;
contractInfo.oracleInfo = oracleInfo;
const orderOffer = new OrderOffer();
// Set required fields for OrderOffer
orderOffer.contractFlags = Buffer.from('00', 'hex'); // Default contract flags
// Generate a random 32-byte temporary contract ID
orderOffer.temporaryContractId = Buffer.from(
Array.from({ length: 32 }, () => Math.floor(Math.random() * 256)),
);
orderOffer.chainHash = chainHashFromNetwork(BitcoinNetworks[network]);
orderOffer.contractInfo = contractInfo;
orderOffer.offerCollateral = offerCollateral; // Use correct property name
orderOffer.feeRatePerVb = feePerByte;
orderOffer.cetLocktime = Math.floor(new Date().getTime() / 1000); // set to current time
orderOffer.refundLocktime =
announcement.oracleEvent.eventMaturityEpoch + 2419200; // 4 weeks after maturity
return 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 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 => {
const eventDescriptor = getDigitDecompositionEventDescriptor(announcement);
let totalCollateral: bigint;
let payoutFunctionInfo: {
payoutFunction: PayoutFunction;
totalCollateral?: bigint;
};
const roundingIntervals = new RoundingIntervals();
const roundingMod = computeRoundingModulus(rounding, contractSize);
if (direction === 'short') {
if (type === 'call') {
payoutFunctionInfo = CoveredCall.buildPayoutFunction(
BigInt(strikePrice),
contractSize.sats,
eventDescriptor.base,
eventDescriptor.nbDigits,
);
totalCollateral = payoutFunctionInfo.totalCollateral;
roundingIntervals.intervals = [
{
beginInterval: BigInt(0),
roundingMod: BigInt(1),
},
{
beginInterval: BigInt(strikePrice),
roundingMod,
},
];
} else {
payoutFunctionInfo = ShortPut.buildPayoutFunction(
BigInt(strikePrice),
contractSize.sats,
_totalCollateral.sats,
eventDescriptor.base,
eventDescriptor.nbDigits,
);
totalCollateral = _totalCollateral.sats;
roundingIntervals.intervals = [
{
beginInterval: BigInt(0),
roundingMod,
},
{
beginInterval: BigInt(strikePrice),
roundingMod: BigInt(1),
},
];
}
} else {
totalCollateral = _totalCollateral.sats;
if (type === 'call') {
payoutFunctionInfo = LongCall.buildPayoutFunction(
BigInt(strikePrice),
contractSize.sats,
totalCollateral,
eventDescriptor.base,
eventDescriptor.nbDigits,
);
roundingIntervals.intervals = [
{
beginInterval: BigInt(0),
roundingMod: BigInt(1),
},
{
beginInterval: BigInt(strikePrice),
roundingMod,
},
];
} else {
payoutFunctionInfo = LongPut.buildPayoutFunction(
BigInt(strikePrice),
contractSize.sats,
totalCollateral,
eventDescriptor.base,
eventDescriptor.nbDigits,
);
roundingIntervals.intervals = [
{
beginInterval: BigInt(0),
roundingMod,
},
{
beginInterval: BigInt(strikePrice),
roundingMod: BigInt(1),
},
];
}
}
const payoutFunction = payoutFunctionInfo.payoutFunction;
const offerCollateral =
direction === 'short' ? totalCollateral - premium.sats : premium.sats;
return buildOrderOffer(
announcement,
totalCollateral,
offerCollateral,
payoutFunction,
roundingIntervals,
BigInt(feePerByte),
network,
);
};
/**
* 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 const buildCoveredCallOrderOffer = (
announcement: OracleAnnouncement,
contractSize: Value,
strikePrice: number,
premium: Value,
feePerByte: number,
rounding: number,
network: string,
): OrderOffer => {
return buildOptionOrderOffer(
announcement,
contractSize,
strikePrice,
premium,
feePerByte,
rounding,
network,
'call',
'short',
);
};
/**
* 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 const buildShortPutOrderOffer = (
announcement: OracleAnnouncement,
contractSize: Value,
strikePrice: number,
totalCollateral: Value,
premium: Value,
feePerByte: number,
rounding: number,
network: string,
): OrderOffer => {
return buildOptionOrderOffer(
announcement,
contractSize,
strikePrice,
premium,
feePerByte,
rounding,
network,
'put',
'short',
totalCollateral,
);
};
/**
* 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 const buildLongCallOrderOffer = (
announcement: OracleAnnouncement,
contractSize: Value,
strikePrice: number,
maxGain: Value,
premium: Value,
feePerByte: number,
rounding: number,
network: string,
): OrderOffer => {
return buildOptionOrderOffer(
announcement,
contractSize,
strikePrice,
premium,
feePerByte,
rounding,
network,
'call',
'long',
maxGain,
);
};
/**
* 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 const buildLongPutOrderOffer = (
announcement: OracleAnnouncement,
contractSize: Value,
strikePrice: number,
maxGain: Value,
premium: Value,
feePerByte: number,
rounding: number,
network: string,
): OrderOffer => {
return buildOptionOrderOffer(
announcement,
contractSize,
strikePrice,
premium,
feePerByte,
rounding,
network,
'put',
'long',
maxGain,
);
};
/**
* 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 const buildLinearOrderOffer = (
announcement: OracleAnnouncement,
offerCollateral: Value,
minPayout: Value,
maxPayout: Value,
startOutcome: bigint,
endOutcome: bigint,
feePerByte: bigint,
roundingIntervals: RoundingIntervals,
network: BitcoinNetwork,
shiftForFees: DlcParty = 'neither',
fees: Value = Value.fromSats(0),
): OrderOffer => {
Iif (maxPayout.lt(minPayout))
throw Error('maxPayout must be greater than minPayout');
Iif (endOutcome < startOutcome)
throw Error('endOutcome must be greater than startOutcome');
const eventDescriptor = getDigitDecompositionEventDescriptor(announcement);
const totalCollateral = maxPayout.sats;
const { payoutFunction } = LinearPayout.buildPayoutFunction(
minPayout.sats,
maxPayout.sats,
startOutcome,
endOutcome,
eventDescriptor.base,
eventDescriptor.nbDigits,
);
const orderOffer = buildOrderOffer(
announcement,
totalCollateral,
offerCollateral.sats,
payoutFunction,
roundingIntervals,
feePerByte,
network.name,
);
const positionInfo = new OrderPositionInfo();
positionInfo.shiftForFees = shiftForFees;
positionInfo.fees = shiftForFees === 'neither' ? BigInt(0) : fees.sats;
orderOffer.positionInfo = positionInfo;
return 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 const buildCustomStrategyOrderOffer = (
announcement: OracleAnnouncement,
contractSize: Value,
normalizedMaxLoss: Value,
normalizedMaxGain: Value,
feePerByte: bigint,
roundingIntervals: RoundingIntervals,
network: BitcoinNetwork,
shiftForFees: DlcParty = 'neither',
fees_: Value = Value.fromSats(0), // NOTE: fees should be divided before doing batch transaction
collateral: Value = Value.fromSats(0),
numOfferInputs = 1,
numContracts = 1,
skipValidation = false,
): OrderOffer => {
if (contractSize.eq(Value.zero())) {
throw Error('contractSize must be greater than 0');
}
if (collateral.eq(Value.zero())) {
collateral = contractSize.clone();
}
const eventDescriptor = getDigitDecompositionEventDescriptor(announcement);
const unit = eventDescriptor.unit;
const fees = Value.fromSats(
Number(new Decimal(Number(fees_.sats)).dividedBy(numContracts).toFixed(0)),
);
const finalizer = getFinalizerByCount(
feePerByte,
numOfferInputs,
1,
numContracts,
);
const offerFees = Value.fromSats(finalizer.offerFees);
// Use offerFees + dustThreshold for min max gain, to ensure in the case of
// 0 PnL the acceptor payout is not dust
const minMaxGainForContractSize_ = offerFees.addn(
Value.fromSats(dustThreshold(BigInt(feePerByte))),
);
const minMaxGainForContractSize = Value.fromSats(
roundUpToNearestMultiplier(
minMaxGainForContractSize_.sats,
BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
),
);
const maxLossForContractSize = Value.fromSats(
roundUpToNearestMultiplier(
(normalizedMaxLoss.sats * contractSize.sats) / BigInt(1e8),
BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
),
);
const tempMaxGainForContractSize = Value.fromSats(
roundUpToNearestMultiplier(
(normalizedMaxGain.sats * contractSize.sats) / BigInt(1e8),
BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
),
);
const maxGainForContractSize = Value.zero();
if (tempMaxGainForContractSize.lt(minMaxGainForContractSize)) {
maxGainForContractSize.add(minMaxGainForContractSize);
} else {
maxGainForContractSize.add(tempMaxGainForContractSize);
}
const maxGainAdjusted = Value.fromSats(
roundToNearestMultiplier(
(maxGainForContractSize.sats * BigInt(1e8)) / contractSize.sats,
BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
),
);
const feesAdjusted = Value.fromSats(
roundToNearestMultiplier(
(fees.sats * BigInt(1e8)) / contractSize.sats,
BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]),
),
);
const minPayout = collateral.clone();
Iif (minPayout.lt(maxLossForContractSize.addn(maxGainForContractSize))) {
throw new Error(
'Subtraction would result in a negative value for minPayout.',
);
}
minPayout.sub(maxLossForContractSize);
minPayout.sub(maxGainForContractSize);
const maxPayout = collateral.clone();
const startOutcomeValue = Value.fromBitcoin(1);
startOutcomeValue.sub(normalizedMaxLoss);
const endOutcomeValue = Value.fromBitcoin(1);
endOutcomeValue.add(maxGainAdjusted);
if (shiftForFees === 'offeror') {
startOutcomeValue.add(feesAdjusted);
endOutcomeValue.add(feesAdjusted);
} else if (shiftForFees === 'acceptor') {
startOutcomeValue.sub(feesAdjusted);
endOutcomeValue.sub(feesAdjusted);
}
const startOutcome =
startOutcomeValue.sats / BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]);
const endOutcome =
endOutcomeValue.sats / BigInt(UNIT_MULTIPLIER[unit.toLowerCase()]);
const offerCollateral = collateral.clone();
Iif (offerCollateral.lt(maxGainForContractSize)) {
throw new Error(
'Subtraction would result in a negative value for offerCollateral.',
);
}
offerCollateral.sub(maxGainForContractSize);
const orderOffer = buildLinearOrderOffer(
announcement,
offerCollateral,
minPayout,
maxPayout,
startOutcome,
endOutcome,
feePerByte,
roundingIntervals,
network,
shiftForFees,
fees,
);
(orderOffer.positionInfo as OrderPositionInfo).contractSize =
contractSize.sats;
(orderOffer.positionInfo as OrderPositionInfo).instrumentName = ((orderOffer.contractInfo as SingleContractInfo)
.oracleInfo as SingleOracleInfo).announcement.oracleEvent.eventId;
if (!skipValidation) orderOffer.validate();
return orderOffer;
};
interface IInterval {
beginInterval: bigint;
rounding: number | bigint | Value;
}
export const buildRoundingIntervalsFromIntervals = (
contractSize: Value,
intervals: IInterval[],
): RoundingIntervals => {
const roundingIntervals = new RoundingIntervals();
roundingIntervals.intervals = intervals.map((interval) => {
const roundingMod = computeRoundingModulus(interval.rounding, contractSize);
return {
beginInterval: interval.beginInterval,
roundingMod,
};
});
return roundingIntervals;
};
|