@indigo-labs/indigo-sdk 0.3.8 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ __export(index_exports, {
53
53
  InterestOracleDatumSchema: () => InterestOracleDatumSchema,
54
54
  InterestOracleParamsSchema: () => InterestOracleParamsSchema,
55
55
  MAX_E2S2S_ENTRIES_COUNT: () => MAX_E2S2S_ENTRIES_COUNT,
56
+ MAX_REDEMPTIONS_WITH_CDP_OPEN: () => MAX_REDEMPTIONS_WITH_CDP_OPEN,
56
57
  MIN_ROB_COLLATERAL_AMT: () => MIN_ROB_COLLATERAL_AMT,
57
58
  ONE_DAY: () => ONE_DAY,
58
59
  ONE_HOUR: () => ONE_HOUR,
@@ -87,6 +88,7 @@ __export(index_exports, {
87
88
  adjustStakingPosition: () => adjustStakingPosition,
88
89
  alwaysFailValidator: () => alwaysFailValidator,
89
90
  annulRequest: () => annulRequest,
91
+ approximateLeverageRedemptions: () => approximateLeverageRedemptions,
90
92
  attachOracle: () => attachOracle,
91
93
  balance: () => balance,
92
94
  batchCollectInterest: () => batchCollectInterest,
@@ -97,8 +99,11 @@ __export(index_exports, {
97
99
  burnCdp: () => burnCdp,
98
100
  calculateAccruedInterest: () => calculateAccruedInterest,
99
101
  calculateAdaReward: () => calculateAdaReward,
102
+ calculateCollateralRatioFromLeverage: () => calculateCollateralRatioFromLeverage,
100
103
  calculateIAssetRedemptionAmt: () => calculateIAssetRedemptionAmt,
104
+ calculateLeverageFromCollateralRatio: () => calculateLeverageFromCollateralRatio,
101
105
  calculateMinCollateralCappedIAssetRedemptionAmt: () => calculateMinCollateralCappedIAssetRedemptionAmt,
106
+ calculateTotalCollateralForRedemption: () => calculateTotalCollateralForRedemption,
102
107
  calculateUnitaryInterest: () => calculateUnitaryInterest,
103
108
  calculateUnitaryInterestSinceOracleLastUpdated: () => calculateUnitaryInterestSinceOracleLastUpdated,
104
109
  cancelRob: () => cancelRob,
@@ -164,9 +169,9 @@ __export(index_exports, {
164
169
  getAssetClassComparisonStr: () => getAssetClassComparisonStr,
165
170
  getInlineDatumOrThrow: () => getInlineDatumOrThrow,
166
171
  getPythFeedConfig: () => getPythFeedConfig,
167
- getRandomElement: () => getRandomElement,
168
172
  getUpdatedAccountDeposit: () => getUpdatedAccountDeposit,
169
173
  handleOracleForCollateralAsset: () => handleOracleForCollateralAsset,
174
+ iassetValueOfCollateral: () => iassetValueOfCollateral,
170
175
  init: () => init,
171
176
  initCDPCreator: () => initCDPCreator,
172
177
  initCollector: () => initCollector,
@@ -180,8 +185,10 @@ __export(index_exports, {
180
185
  initTreasury: () => initTreasury,
181
186
  initializeAsset: () => initializeAsset,
182
187
  insertSorted: () => insertSorted,
188
+ isBuyOrderFullyRedeemed: () => isBuyOrderFullyRedeemed,
183
189
  isFullyRedeemed: () => isFullyRedeemed,
184
190
  isSameEpochToScaleKey: () => isSameEpochToScaleKey,
191
+ leverageCdpWithRob: () => leverageCdpWithRob,
185
192
  liquidateCdp: () => liquidateCdp,
186
193
  liquidationHelper: () => liquidationHelper,
187
194
  loadSystemParamsFromFile: () => loadSystemParamsFromFile,
@@ -266,6 +273,7 @@ __export(index_exports, {
266
273
  parseStakingPositionOrThrow: () => parseStakingPositionOrThrow,
267
274
  partitionEpochToScaleToSums: () => partitionEpochToScaleToSums,
268
275
  processSpRequest: () => processSpRequest,
276
+ randomRobsSubsetSatisfyingTargetCollateral: () => randomRobsSubsetSatisfyingTargetCollateral,
269
277
  rationalAdd: () => rationalAdd,
270
278
  rationalCeil: () => rationalCeil,
271
279
  rationalDiv: () => rationalDiv,
@@ -284,7 +292,10 @@ __export(index_exports, {
284
292
  requestSpAccountClosure: () => requestSpAccountClosure,
285
293
  requestSpAccountCreation: () => requestSpAccountCreation,
286
294
  rewardSnapshotPrecision: () => rewardSnapshotPrecision,
287
- robAmountToSpend: () => robAmountToSpend,
295
+ robAmtToSpend: () => robAmtToSpend,
296
+ robBuyOrderSummary: () => robBuyOrderSummary,
297
+ robCollateralAmtToSpend: () => robCollateralAmtToSpend,
298
+ robIAssetAmtToSpend: () => robIAssetAmtToSpend,
288
299
  runCreateScriptRefTx: () => runCreateScriptRefTx,
289
300
  runOneShotMintTx: () => runOneShotMintTx,
290
301
  scriptRef: () => scriptRef,
@@ -329,6 +340,7 @@ __export(index_exports, {
329
340
  startPriceOracleTx: () => startPriceOracleTx,
330
341
  submitTx: () => submitTx,
331
342
  sum: () => sum,
343
+ summarizeActualLeverageRedemptions: () => summarizeActualLeverageRedemptions,
332
344
  toAssetClassFromLucid: () => toAssetClassFromLucid,
333
345
  toDataDerivedPythPrice: () => toDataDerivedPythPrice,
334
346
  toSystemParamsAsset: () => toSystemParamsAsset,
@@ -715,7 +727,6 @@ function loadSystemParamsFromFile(file) {
715
727
  function loadSystemParamsFromUrl(url) {
716
728
  return fetch(url).then((res) => res.json()).then((data) => data);
717
729
  }
718
- var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
719
730
 
720
731
  // src/utils/time-helpers.ts
721
732
  var ONE_SECOND = 1e3;
@@ -792,6 +803,11 @@ function calculateFeeFromRatio(feeRatio, amount) {
792
803
 
793
804
  // src/contracts/cdp/helpers.ts
794
805
  var import_cardano_offchain_common = require("@3rd-eye-labs/cardano-offchain-common");
806
+ function iassetValueOfCollateral(collateralAmt, oraclePrice) {
807
+ return rationalFloor(
808
+ rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
809
+ );
810
+ }
795
811
  function cdpCollateralRatioPercentage(currentSlot, iassetPrice, cdpUtxo, cdpContent, interestOracleDatum, network) {
796
812
  const currentTime = BigInt((0, import_lucid4.slotToUnixTime)(network, currentSlot));
797
813
  return (0, import_ts_pattern5.match)(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: import_ts_pattern5.P.select() }, (interest) => {
@@ -3901,6 +3917,7 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
3901
3917
  }).with(
3902
3918
  { DeferredValidation: { feedValHash: import_ts_pattern12.P.select() } },
3903
3919
  async (feedValHash) => {
3920
+ if (priceOracleOref) throw new Error("Cannot pass price oracle oref");
3904
3921
  if (!pythMessage) throw new Error("Missing Pyth message");
3905
3922
  if (!pythStateOref) throw new Error("Missing pyth state out ref");
3906
3923
  const pythStateUtxo = matchSingle(
@@ -5906,7 +5923,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
5906
5923
  )
5907
5924
  )
5908
5925
  )
5909
- ).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND).addSigner(ownAddr),
5926
+ ).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).addSigner(ownAddr),
5910
5927
  newPollId
5911
5928
  ];
5912
5929
  }
@@ -5948,7 +5965,7 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
5948
5965
  );
5949
5966
  const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
5950
5967
  const tx = lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
5951
- Number(currentTime) + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
5968
+ Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
5952
5969
  ).mintAssets((0, import_cardano_offchain_common16.mkAssetsOf)(pollNft, shardsCount), import_lucid26.Data.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
5953
5970
  [pollManagerUtxo],
5954
5971
  serialisePollManagerRedeemer({ CreateShards: { currentTime } })
@@ -6128,7 +6145,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
6128
6145
  )(shardUtxos);
6129
6146
  const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
6130
6147
  return lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
6131
- Number(currentTime) + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
6148
+ Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
6132
6149
  ).readFrom([
6133
6150
  pollShardRefScriptUtxo,
6134
6151
  pollManagerRefScriptUtxo,
@@ -6915,7 +6932,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6915
6932
  );
6916
6933
  }).otherwise(() => {
6917
6934
  });
6918
- tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND).collectFrom([executeUtxo], import_lucid26.Data.void()).mintAssets(
6935
+ tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).collectFrom([executeUtxo], import_lucid26.Data.void()).mintAssets(
6919
6936
  (0, import_cardano_offchain_common16.mkAssetsOf)(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
6920
6937
  import_lucid26.Data.void()
6921
6938
  ).addSigner(ownAddr).setMinFee(922932n);
@@ -8436,7 +8453,7 @@ var import_fp_ts17 = require("fp-ts");
8436
8453
  var import_ts_pattern19 = require("ts-pattern");
8437
8454
  var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
8438
8455
  var MIN_ROB_COLLATERAL_AMT = 3000000n;
8439
- function robAmountToSpend(utxo, datum, sysParams) {
8456
+ function robCollateralAmtToSpend(utxo, datum) {
8440
8457
  return (0, import_ts_pattern19.match)(datum.orderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
8441
8458
  if ((0, import_cardano_offchain_common22.isSameAssetClass)(import_cardano_offchain_common22.adaAssetClass, content.collateralAsset)) {
8442
8459
  return zeroNegatives(
@@ -8445,24 +8462,61 @@ function robAmountToSpend(utxo, datum, sysParams) {
8445
8462
  } else {
8446
8463
  return (0, import_cardano_offchain_common22.assetClassValueOf)(utxo.assets, content.collateralAsset);
8447
8464
  }
8448
- }).with({ SellIAssetOrder: import_ts_pattern19.P.any }, (_) => {
8465
+ }).otherwise(() => {
8466
+ throw new Error("Collateral to spend is relevant only for Buy orders.");
8467
+ });
8468
+ }
8469
+ function robIAssetAmtToSpend(utxo, datum, iassetCurrencySymbol) {
8470
+ return (0, import_ts_pattern19.match)(datum.orderType).returnType().with({ SellIAssetOrder: import_ts_pattern19.P.any }, (_) => {
8449
8471
  return (0, import_cardano_offchain_common22.assetClassValueOf)(utxo.assets, {
8450
- currencySymbol: (0, import_lucid49.fromHex)(
8451
- sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
8452
- ),
8472
+ currencySymbol: (0, import_lucid49.fromHex)(iassetCurrencySymbol.unCurrencySymbol),
8453
8473
  tokenName: datum.iasset
8454
8474
  });
8455
- }).exhaustive();
8475
+ }).otherwise(() => {
8476
+ throw new Error("IAssets to spend is relevant only for Sell orders.");
8477
+ });
8456
8478
  }
8457
- function isFullyRedeemed(utxo, datum, sysParams) {
8458
- return robAmountToSpend(utxo, datum, sysParams) === 0n;
8479
+ function robAmtToSpend(utxo, datum, iassetCurrencySymbol) {
8480
+ return (0, import_ts_pattern19.match)(datum.orderType).with({ BuyIAssetOrder: import_ts_pattern19.P.any }, () => robCollateralAmtToSpend(utxo, datum)).with(
8481
+ { SellIAssetOrder: import_ts_pattern19.P.any },
8482
+ () => robIAssetAmtToSpend(utxo, datum, iassetCurrencySymbol)
8483
+ ).exhaustive();
8484
+ }
8485
+ function robBuyOrderSummary(utxo, datum, oraclePrice) {
8486
+ const redeemable = robCollateralAmtToSpend(utxo, datum);
8487
+ const payoutAmt = iassetValueOfCollateral(redeemable, oraclePrice);
8488
+ return {
8489
+ redeemableCollateral: redeemable,
8490
+ payoutIAsset: payoutAmt
8491
+ };
8492
+ }
8493
+ function isBuyOrderFullyRedeemed(utxo, datum, oraclePrice) {
8494
+ const summary = robBuyOrderSummary(utxo, datum, oraclePrice);
8495
+ return summary.redeemableCollateral <= 0n || summary.payoutIAsset <= 0n;
8496
+ }
8497
+ function isFullyRedeemed(utxo, datum, iassetCurrencySymbol) {
8498
+ return (0, import_ts_pattern19.match)(datum.orderType).returnType().with(
8499
+ { BuyIAssetOrder: import_ts_pattern19.P.select() },
8500
+ (content) => isBuyOrderFullyRedeemed(utxo, datum, content.maxPrice)
8501
+ ).with({ SellIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
8502
+ const iassetToSpend = robIAssetAmtToSpend(
8503
+ utxo,
8504
+ datum,
8505
+ iassetCurrencySymbol
8506
+ );
8507
+ const payoutAmts = content.allowedCollateralAssets.map(
8508
+ (c) => rationalFloor(rationalMul(rationalFromInt(iassetToSpend), c[1]))
8509
+ );
8510
+ return iassetToSpend <= 0n || // When for every allowed collateral asset the payout would be 0
8511
+ payoutAmts.every((amt) => amt <= 0n);
8512
+ }).exhaustive();
8459
8513
  }
8460
8514
  function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
8461
8515
  return import_fp_ts17.function.pipe(
8462
8516
  redemptions,
8463
8517
  import_fp_ts17.array.reduceWithIndex(
8464
8518
  tx,
8465
- (idx, acc, [robUtxo, spendAmt]) => {
8519
+ (idx, acc, [robUtxo, payoutAmt]) => {
8466
8520
  const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
8467
8521
  if ((0, import_lucid49.toHex)(robDatum.iasset) !== (0, import_lucid49.toHex)(iasset)) {
8468
8522
  throw new Error("Only same iAsset");
@@ -8473,7 +8527,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8473
8527
  if (!(0, import_cardano_offchain_common22.isSameAssetClass)(content.collateralAsset, collateralAsset)) {
8474
8528
  throw new Error("Only same collateral asset");
8475
8529
  }
8476
- const payoutIAssetAmt = spendAmt;
8530
+ const payoutIAssetAmt = payoutAmt;
8477
8531
  const reimburstmentIAsset = calculateFeeFromRatio(
8478
8532
  redemptionReimbursementRatio,
8479
8533
  payoutIAssetAmt
@@ -8508,16 +8562,14 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8508
8562
  throw new Error("Doesn't allow required collateral asset.");
8509
8563
  })
8510
8564
  );
8511
- const payoutCollateralAmt = spendAmt;
8565
+ const payoutCollateralAmt = payoutAmt;
8512
8566
  const reimbursementCollateral = calculateFeeFromRatio(
8513
8567
  redemptionReimbursementRatio,
8514
8568
  payoutCollateralAmt
8515
8569
  );
8516
- const redeemedIAssetAmt = rationalFloor(
8517
- rationalDiv(
8518
- rationalFromInt(payoutCollateralAmt - reimbursementCollateral),
8519
- price
8520
- )
8570
+ const redeemedIAssetAmt = iassetValueOfCollateral(
8571
+ payoutCollateralAmt - reimbursementCollateral,
8572
+ price
8521
8573
  );
8522
8574
  const resultVal = (0, import_lucid49.addAssets)(
8523
8575
  robUtxo.assets,
@@ -8535,7 +8587,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8535
8587
  return [resultVal, BigInt(allowedAssetIdx)];
8536
8588
  }).exhaustive();
8537
8589
  if ((0, import_cardano_offchain_common22.lovelacesAmt)(robOutputVal) < MIN_ROB_COLLATERAL_AMT) {
8538
- throw new Error("ROB was incorrectly initialised.");
8590
+ throw new Error(
8591
+ "Redeeming more than available or selected ROB was incorrectly initialised."
8592
+ );
8539
8593
  }
8540
8594
  return acc.collectFrom([robUtxo], {
8541
8595
  kind: "self",
@@ -8546,7 +8600,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8546
8600
  iassetRefInputIdx,
8547
8601
  continuingOutputIdx: txOutputsBeforeCount + BigInt(idx),
8548
8602
  sellOrderAllowedAssetsIdx,
8549
- priceOracleIdx: oracleIdx != null ? { OracleRefInputIdx: oracleIdx } : "OracleVoid"
8603
+ priceOracleIdx: oracleIdx
8550
8604
  }
8551
8605
  })
8552
8606
  }).pay.ToContract(
@@ -8567,6 +8621,85 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8567
8621
  )
8568
8622
  );
8569
8623
  }
8624
+ function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
8625
+ return import_fp_ts17.function.pipe(
8626
+ allRobs,
8627
+ import_fp_ts17.array.filterMap(([utxo, datum]) => {
8628
+ const isCorrectOrder = (0, import_ts_pattern19.match)(datum.orderType).returnType().with(
8629
+ { BuyIAssetOrder: import_ts_pattern19.P.select() },
8630
+ (content) => (0, import_cardano_offchain_common22.isSameAssetClass)(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo, datum, iassetPrice)
8631
+ ).otherwise(() => false);
8632
+ if ((0, import_lucid49.toHex)(datum.iasset) !== (0, import_lucid49.toHex)(iasset) || !isCorrectOrder) {
8633
+ return import_fp_ts17.option.none;
8634
+ }
8635
+ const collateralToSpend = robCollateralAmtToSpend(utxo, datum);
8636
+ return import_fp_ts17.option.some(collateralToSpend);
8637
+ }),
8638
+ // From largest to smallest
8639
+ import_fp_ts17.array.sort(import_fp_ts17.ord.reverse(BigIntOrd)),
8640
+ // We can fit only this number of redemptions with CDP open into a single Tx.
8641
+ import_fp_ts17.array.takeLeft(maxRobsInTx),
8642
+ sum
8643
+ );
8644
+ }
8645
+ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, targetCollateralToSpend, iassetPrice, allLrps, maxLrpsInTx, randomiseFn = shuffle) {
8646
+ if (targetCollateralToSpend <= 0n || iassetValueOfCollateral(targetCollateralToSpend, iassetPrice) <= 0n) {
8647
+ throw new Error("Must redeem and payout more than 0.");
8648
+ }
8649
+ const shuffled = randomiseFn(
8650
+ import_fp_ts17.function.pipe(
8651
+ allLrps,
8652
+ import_fp_ts17.array.filter(
8653
+ ([utxo, datum]) => (0, import_lucid49.toHex)(datum.iasset) === (0, import_lucid49.toHex)(iasset) && (0, import_ts_pattern19.match)(datum.orderType).with(
8654
+ { BuyIAssetOrder: import_ts_pattern19.P.select() },
8655
+ (content) => (0, import_cardano_offchain_common22.isSameAssetClass)(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
8656
+ ).otherwise(() => false) && !isBuyOrderFullyRedeemed(utxo, datum, iassetPrice)
8657
+ )
8658
+ )
8659
+ );
8660
+ let result = [];
8661
+ let runningSum = 0n;
8662
+ for (let i = 0; i < shuffled.length; i++) {
8663
+ const element = shuffled[i];
8664
+ const lovelacesToSpend = robCollateralAmtToSpend(element[0], element[1]);
8665
+ const remainingToRedeem = targetCollateralToSpend - runningSum;
8666
+ const remainingToPayout = iassetValueOfCollateral(
8667
+ remainingToRedeem,
8668
+ iassetPrice
8669
+ );
8670
+ if (result.length > 0 && remainingToPayout <= 0n) {
8671
+ const last = result[result.length - 1];
8672
+ const lastSummary = robBuyOrderSummary(last[0], last[1], iassetPrice);
8673
+ if (lastSummary.redeemableCollateral < lovelacesToSpend) {
8674
+ result.pop();
8675
+ runningSum -= lastSummary.redeemableCollateral;
8676
+ } else {
8677
+ continue;
8678
+ }
8679
+ }
8680
+ result = insertSorted(
8681
+ result,
8682
+ element,
8683
+ import_fp_ts17.ord.contramap(
8684
+ ([utxo, dat]) => robCollateralAmtToSpend(utxo, dat)
8685
+ // From highest to lowest
8686
+ )(import_fp_ts17.ord.reverse(BigIntOrd))
8687
+ );
8688
+ runningSum += lovelacesToSpend;
8689
+ if (result.length > maxLrpsInTx) {
8690
+ const popped = result.pop();
8691
+ runningSum -= robCollateralAmtToSpend(popped[0], popped[1]);
8692
+ }
8693
+ if (runningSum >= targetCollateralToSpend) {
8694
+ return result;
8695
+ }
8696
+ }
8697
+ const remainingToSpend = targetCollateralToSpend - runningSum;
8698
+ if (remainingToSpend > 0n && iassetValueOfCollateral(remainingToSpend, iassetPrice) > 0n) {
8699
+ throw new Error("Couldn't achieve target lovelaces");
8700
+ }
8701
+ return result;
8702
+ }
8570
8703
 
8571
8704
  // src/contracts/rob/types.ts
8572
8705
  var import_lucid50 = require("@lucid-evolution/lucid");
@@ -8706,7 +8839,7 @@ async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, co
8706
8839
  0n,
8707
8840
  refInputIdxs[2],
8708
8841
  refInputIdxs[1],
8709
- priceOracleOutRef !== void 0 ? refInputIdxs[3] : null
8842
+ priceOracleOutRef !== void 0 ? { OracleRefInputIdx: refInputIdxs[3] } : "OracleVoid"
8710
8843
  );
8711
8844
  tx.readFrom(allRefInputs);
8712
8845
  return tx;
@@ -8723,12 +8856,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
8723
8856
  (_) => new Error("Expected a single ROB UTXO.")
8724
8857
  );
8725
8858
  const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
8726
- if (adjustmentAmt === 0n && isFullyRedeemed(robUtxo, robDatum, sysParams)) {
8859
+ if (adjustmentAmt === 0n && isFullyRedeemed(robUtxo, robDatum, sysParams.cdpParams.cdpAssetSymbol)) {
8727
8860
  throw new Error(
8728
8861
  "When there's no more lovelaces to spend, use close instead of claim."
8729
8862
  );
8730
8863
  }
8731
- if (adjustmentAmt < 0 && robAmountToSpend(robUtxo, robDatum, sysParams) <= -adjustmentAmt) {
8864
+ if (adjustmentAmt < 0 && robAmtToSpend(robUtxo, robDatum, sysParams.cdpParams.cdpAssetSymbol) <= -adjustmentAmt) {
8732
8865
  throw new Error(
8733
8866
  "Can't adjust negatively by more than available. Also, for adjusting by exactly the amount deposited, a close action should be used instead."
8734
8867
  );
@@ -8849,11 +8982,443 @@ var mkRobValidatorFromSP = (params) => {
8849
8982
  };
8850
8983
  };
8851
8984
 
8985
+ // src/contracts/rob-leverage/transactions.ts
8986
+ var import_lucid53 = require("@lucid-evolution/lucid");
8987
+
8988
+ // src/contracts/rob-leverage/helpers.ts
8989
+ var import_fp_ts19 = require("fp-ts");
8990
+ var import_decimal = require("decimal.js");
8991
+ var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
8992
+ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
8993
+ const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(debtMintingFeeRatio.numerator).div(
8994
+ debtMintingFeeRatio.denominator
8995
+ );
8996
+ const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
8997
+ redemptionReimbursementRatio.numerator
8998
+ ).div(redemptionReimbursementRatio.denominator);
8999
+ const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9000
+ redemptionReimbursementRatioDecimal
9001
+ );
9002
+ const bExFees = (0, import_decimal.Decimal)(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
9003
+ const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9004
+ const collateralRatio = {
9005
+ numerator: fromDecimal((0, import_decimal.Decimal)(baseCollateral).add(bExFees)),
9006
+ denominator: fromDecimal(b)
9007
+ };
9008
+ return {
9009
+ leverage: targetLeverage,
9010
+ collateralRatio,
9011
+ redeemedCollateral: fromDecimal(bExFees)
9012
+ };
9013
+ }
9014
+ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
9015
+ const priceDecimal = (0, import_decimal.Decimal)(iassetPrice.numerator).div(
9016
+ iassetPrice.denominator
9017
+ );
9018
+ const reimbRatio = (0, import_decimal.Decimal)(redemptionReimbursementRatio.numerator).div(
9019
+ redemptionReimbursementRatio.denominator
9020
+ );
9021
+ const redemptionDetails = import_fp_ts19.function.pipe(
9022
+ redemptionLrps,
9023
+ import_fp_ts19.array.reduce(
9024
+ {
9025
+ remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
9026
+ redemptions: []
9027
+ },
9028
+ (acc, lrp) => {
9029
+ if (acc.remainingCollateralToSpend <= 0n || iassetValueOfCollateral(
9030
+ acc.remainingCollateralToSpend,
9031
+ iassetPrice
9032
+ ) <= 0n) {
9033
+ return acc;
9034
+ }
9035
+ const collateralToSpend = robCollateralAmtToSpend(lrp[0], lrp[1]);
9036
+ if (collateralToSpend === 0n) {
9037
+ return acc;
9038
+ }
9039
+ const newRemainingCollateral = bigintMax(
9040
+ acc.remainingCollateralToSpend - collateralToSpend,
9041
+ 0n
9042
+ );
9043
+ const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
9044
+ const finalPayoutIAssets = fromDecimal(
9045
+ (0, import_decimal.Decimal)(collateralToSpendInitial).div(priceDecimal).floor().div((0, import_decimal.Decimal)(1).minus(reimbRatio)).floor()
9046
+ );
9047
+ const feeIAssetAmt = calculateFeeFromRatio(
9048
+ redemptionReimbursementRatio,
9049
+ finalPayoutIAssets
9050
+ );
9051
+ const finalCollateralToSpend = rationalFloor(
9052
+ rationalMul(
9053
+ rationalFromInt(finalPayoutIAssets - feeIAssetAmt),
9054
+ iassetPrice
9055
+ )
9056
+ );
9057
+ return {
9058
+ remainingCollateralToSpend: acc.remainingCollateralToSpend - finalCollateralToSpend,
9059
+ redemptions: [
9060
+ ...acc.redemptions,
9061
+ {
9062
+ utxo: lrp[0],
9063
+ iassetsPayoutAmt: finalPayoutIAssets,
9064
+ redeemedCollateral: finalCollateralToSpend,
9065
+ reimbursementIAssetAmt: feeIAssetAmt
9066
+ }
9067
+ ]
9068
+ };
9069
+ }
9070
+ )
9071
+ );
9072
+ const res = import_fp_ts19.function.pipe(
9073
+ redemptionDetails.redemptions,
9074
+ import_fp_ts19.array.reduce(
9075
+ {
9076
+ redeemedCollateral: 0n,
9077
+ payoutIAssets: 0n,
9078
+ reimbursementIAssets: 0n
9079
+ },
9080
+ (acc, details) => {
9081
+ return {
9082
+ redeemedCollateral: acc.redeemedCollateral + details.redeemedCollateral,
9083
+ reimbursementIAssets: acc.reimbursementIAssets + details.reimbursementIAssetAmt,
9084
+ payoutIAssets: acc.payoutIAssets + details.iassetsPayoutAmt
9085
+ };
9086
+ }
9087
+ )
9088
+ );
9089
+ return {
9090
+ redemptions: redemptionDetails.redemptions,
9091
+ totalRedeemedCollateral: res.redeemedCollateral,
9092
+ totalReimbursedIAsset: res.reimbursementIAssets,
9093
+ totalIAssetPayout: res.payoutIAssets
9094
+ };
9095
+ }
9096
+ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
9097
+ const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(
9098
+ debtMintingFeePercentage.getOnChainInt
9099
+ ).div(OCD_DECIMAL_UNIT).div(100);
9100
+ const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
9101
+ redemptionReimbursementPercentage.getOnChainInt
9102
+ ).div(OCD_DECIMAL_UNIT).div(100);
9103
+ const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9104
+ redemptionReimbursementRatioDecimal
9105
+ );
9106
+ const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
9107
+ iasset,
9108
+ collateralAsset,
9109
+ iassetPrice,
9110
+ allLrps,
9111
+ MAX_REDEMPTIONS_WITH_CDP_OPEN
9112
+ );
9113
+ if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
9114
+ return void 0;
9115
+ }
9116
+ const bExFees = (0, import_decimal.Decimal)(baseCollateral).mul(leverage).minus(baseCollateral).floor();
9117
+ const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9118
+ const cappedB = bigintMin(
9119
+ maxAvailableCollateralForRedemption,
9120
+ fromDecimal(b)
9121
+ );
9122
+ const cappedBExFees = (0, import_decimal.Decimal)(cappedB).mul((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9123
+ const collateralRatio = (0, import_decimal.Decimal)(
9124
+ (0, import_decimal.Decimal)(baseCollateral).add(cappedBExFees)
9125
+ ).div(cappedB);
9126
+ return {
9127
+ getOnChainInt: fromDecimal(
9128
+ collateralRatio.mul(100n * OCD_DECIMAL_UNIT).floor()
9129
+ )
9130
+ };
9131
+ }
9132
+ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
9133
+ const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(debtMintingFeeRatio.numerator).div(
9134
+ debtMintingFeeRatio.denominator
9135
+ );
9136
+ const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
9137
+ redemptionReimbursementRatio.numerator
9138
+ ).div(redemptionReimbursementRatio.denominator);
9139
+ const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9140
+ redemptionReimbursementRatioDecimal
9141
+ );
9142
+ const collateralRatioDecimal = (0, import_decimal.Decimal)(collateralRatio.numerator).div(
9143
+ collateralRatio.denominator
9144
+ );
9145
+ const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
9146
+ iasset,
9147
+ collateralAsset,
9148
+ iassetPrice,
9149
+ allLrps,
9150
+ MAX_REDEMPTIONS_WITH_CDP_OPEN
9151
+ );
9152
+ if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
9153
+ return void 0;
9154
+ }
9155
+ const theoreticalMaxLeverage = (0, import_decimal.Decimal)((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
9156
+ const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
9157
+ const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9158
+ const cappedB = bigintMin(
9159
+ maxAvailableCollateralForRedemption,
9160
+ fromDecimal(b)
9161
+ );
9162
+ const cappedBExFees = (0, import_decimal.Decimal)(cappedB).mul((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9163
+ return (0, import_decimal.Decimal)(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
9164
+ }
9165
+
9166
+ // src/contracts/rob-leverage/transactions.ts
9167
+ var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
9168
+ var import_decimal2 = __toESM(require("decimal.js"));
9169
+ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
9170
+ const network = lucid.config().network;
9171
+ const currentTime = BigInt((0, import_lucid53.slotToUnixTime)(network, currentSlot));
9172
+ const [pkh, skh] = await addrDetails(lucid);
9173
+ const robScriptRefUtxo = matchSingle(
9174
+ await lucid.utxosByOutRef([
9175
+ fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef)
9176
+ ]),
9177
+ (_2) => new Error("Expected a single ROB Ref Script UTXO")
9178
+ );
9179
+ const cdpCreatorRefScriptUtxo = matchSingle(
9180
+ await lucid.utxosByOutRef([
9181
+ fromSystemParamsScriptRef(
9182
+ sysParams.scriptReferences.cdpCreatorValidatorRef
9183
+ )
9184
+ ]),
9185
+ (_2) => new Error("Expected a single cdp creator Ref Script UTXO")
9186
+ );
9187
+ const cdpAuthTokenPolicyRefScriptUtxo = matchSingle(
9188
+ await lucid.utxosByOutRef([
9189
+ fromSystemParamsScriptRef(
9190
+ sysParams.scriptReferences.authTokenPolicies.cdpAuthTokenRef
9191
+ )
9192
+ ]),
9193
+ (_2) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
9194
+ );
9195
+ const iAssetTokenPolicyRefScriptUtxo = matchSingle(
9196
+ await lucid.utxosByOutRef([
9197
+ fromSystemParamsScriptRef(
9198
+ sysParams.scriptReferences.iAssetTokenPolicyRef
9199
+ )
9200
+ ]),
9201
+ (_2) => new Error("Expected a single iasset token policy Ref Script UTXO")
9202
+ );
9203
+ const cdpCreatorUtxo = matchSingle(
9204
+ await lucid.utxosByOutRef([cdpCreatorOref]),
9205
+ (_2) => new Error("Expected a single CDP creator UTXO")
9206
+ );
9207
+ const interestOracleUtxo = matchSingle(
9208
+ await lucid.utxosByOutRef([interestOracleOref]),
9209
+ (_2) => new Error("Expected a single interest oracle UTXO")
9210
+ );
9211
+ const interestOracleDatum = parseInterestOracleDatum(
9212
+ getInlineDatumOrThrow(interestOracleUtxo)
9213
+ );
9214
+ const iassetUtxo = matchSingle(
9215
+ await lucid.utxosByOutRef([iassetOutRef]),
9216
+ (_2) => new Error("Expected a single IAsset UTXO")
9217
+ );
9218
+ const iassetDatum = parseIAssetDatumOrThrow(
9219
+ getInlineDatumOrThrow(iassetUtxo)
9220
+ );
9221
+ const collateralAssetUtxo = matchSingle(
9222
+ await lucid.utxosByOutRef([collateralAssetOutRef]),
9223
+ (_2) => new Error("Expected a single collateral asset UTXO")
9224
+ );
9225
+ const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
9226
+ getInlineDatumOrThrow(collateralAssetUtxo)
9227
+ );
9228
+ const [price, _] = await retrieveAdjustedPrice(
9229
+ iassetDatum.assetName,
9230
+ collateralAssetDatum.collateralAsset,
9231
+ collateralAssetDatum.priceInfo,
9232
+ collateralAssetDatum.extraDecimals,
9233
+ priceOracleOutRef,
9234
+ pythMessage,
9235
+ sysParams.pythConfig,
9236
+ lucid
9237
+ );
9238
+ const maxLeverage = calculateLeverageFromCollateralRatio(
9239
+ collateralAssetDatum.iasset,
9240
+ collateralAssetDatum.collateralAsset,
9241
+ collateralAssetDatum.maintenanceRatio,
9242
+ baseCollateral,
9243
+ price,
9244
+ iassetDatum.debtMintingFeeRatio,
9245
+ iassetDatum.redemptionReimbursementRatio,
9246
+ allRobs
9247
+ );
9248
+ if (!maxLeverage) {
9249
+ throw new Error("Can't calculate max leverage with those parameters.");
9250
+ }
9251
+ const leverageSummary = approximateLeverageRedemptions(
9252
+ baseCollateral,
9253
+ leverage,
9254
+ iassetDatum.redemptionProcessingFeeRatio,
9255
+ iassetDatum.debtMintingFeeRatio
9256
+ );
9257
+ if (maxLeverage < leverageSummary.leverage) {
9258
+ throw new Error("Can't use more leverage than max.");
9259
+ }
9260
+ if (rationalToFloat(leverageSummary.collateralRatio) < rationalToFloat(collateralAssetDatum.maintenanceRatio)) {
9261
+ throw new Error(
9262
+ "Can't have collateral ratio smaller than maintenance ratio"
9263
+ );
9264
+ }
9265
+ const redemptionDetails = summarizeActualLeverageRedemptions(
9266
+ leverageSummary.redeemedCollateral,
9267
+ iassetDatum.redemptionReimbursementRatio,
9268
+ price,
9269
+ randomRobsSubsetSatisfyingTargetCollateral(
9270
+ iassetDatum.assetName,
9271
+ collateralAssetDatum.collateralAsset,
9272
+ leverageSummary.redeemedCollateral,
9273
+ price,
9274
+ allRobs,
9275
+ MAX_REDEMPTIONS_WITH_CDP_OPEN
9276
+ )
9277
+ );
9278
+ const mintedAmt = fromDecimal(
9279
+ (0, import_decimal2.default)(redemptionDetails.totalIAssetPayout).div(
9280
+ (0, import_decimal2.default)(1).minus(
9281
+ (0, import_decimal2.default)(iassetDatum.debtMintingFeeRatio.numerator).div(
9282
+ iassetDatum.debtMintingFeeRatio.denominator
9283
+ )
9284
+ )
9285
+ ).floor()
9286
+ );
9287
+ const debtMintingFee = calculateFeeFromRatio(
9288
+ iassetDatum.debtMintingFeeRatio,
9289
+ mintedAmt
9290
+ );
9291
+ const collateralAmt = redemptionDetails.totalRedeemedCollateral + baseCollateral;
9292
+ const cdpNftVal = (0, import_cardano_offchain_common24.mkAssetsOf)(
9293
+ fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
9294
+ 1n
9295
+ );
9296
+ const iassetClass = {
9297
+ currencySymbol: (0, import_lucid53.fromHex)(
9298
+ sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
9299
+ ),
9300
+ tokenName: iassetDatum.assetName
9301
+ };
9302
+ const iassetTokensVal = (0, import_cardano_offchain_common24.mkAssetsOf)(iassetClass, mintedAmt);
9303
+ const refScripts = [
9304
+ cdpCreatorRefScriptUtxo,
9305
+ cdpAuthTokenPolicyRefScriptUtxo,
9306
+ iAssetTokenPolicyRefScriptUtxo,
9307
+ robScriptRefUtxo
9308
+ ];
9309
+ const tx = lucid.newTx().readFrom(refScripts).mintAssets(cdpNftVal, import_lucid53.Data.void()).mintAssets(iassetTokensVal, import_lucid53.Data.void()).pay.ToContract(
9310
+ createScriptAddress(network, sysParams.validatorHashes.cdpHash, skh),
9311
+ {
9312
+ kind: "inline",
9313
+ value: serialiseCdpDatum({
9314
+ cdpOwner: (0, import_lucid53.fromHex)(pkh.hash),
9315
+ iasset: iassetDatum.assetName,
9316
+ collateralAsset: collateralAssetDatum.collateralAsset,
9317
+ mintedAmt,
9318
+ cdpFees: {
9319
+ ActiveCDPInterestTracking: {
9320
+ lastSettled: currentTime,
9321
+ unitaryInterestSnapshot: calculateUnitaryInterestSinceOracleLastUpdated(
9322
+ currentTime,
9323
+ interestOracleDatum
9324
+ ) + interestOracleDatum.unitaryInterest
9325
+ }
9326
+ }
9327
+ })
9328
+ },
9329
+ (0, import_lucid53.addAssets)(
9330
+ cdpNftVal,
9331
+ (0, import_cardano_offchain_common24.mkAssetsOf)(collateralAssetDatum.collateralAsset, collateralAmt)
9332
+ )
9333
+ ).pay.ToContract(
9334
+ cdpCreatorUtxo.address,
9335
+ {
9336
+ kind: "inline",
9337
+ value: serialiseCDPCreatorDatum({
9338
+ creatorInputOref: {
9339
+ outputIndex: BigInt(cdpCreatorUtxo.outputIndex),
9340
+ txHash: (0, import_lucid53.fromHex)(cdpCreatorUtxo.txHash)
9341
+ }
9342
+ })
9343
+ },
9344
+ cdpCreatorUtxo.assets
9345
+ );
9346
+ const treasuryRefScriptUtxo = debtMintingFee > 0n ? await treasuryFeeTx(
9347
+ iassetClass,
9348
+ debtMintingFee,
9349
+ 0n,
9350
+ lucid,
9351
+ sysParams,
9352
+ tx,
9353
+ cdpCreatorUtxo,
9354
+ treasuryOref
9355
+ ) : void 0;
9356
+ const { interval, referenceInputs: refInputs } = await attachOracle(
9357
+ iassetDatum.assetName,
9358
+ collateralAssetDatum.collateralAsset,
9359
+ collateralAssetDatum.priceInfo,
9360
+ priceOracleOutRef,
9361
+ pythStateOref,
9362
+ pythMessage,
9363
+ sysParams.pythConfig,
9364
+ sysParams.cdpCreatorParams.biasTime,
9365
+ currentSlot,
9366
+ lucid,
9367
+ tx
9368
+ );
9369
+ const referenceInputs = [
9370
+ interestOracleUtxo,
9371
+ iassetUtxo,
9372
+ collateralAssetUtxo,
9373
+ ...refInputs
9374
+ ];
9375
+ const refInputsIndices = (0, import_lucid53.getInputIndices)(referenceInputs, [
9376
+ ...referenceInputs,
9377
+ ...refScripts,
9378
+ ...treasuryRefScriptUtxo != null ? [treasuryRefScriptUtxo] : []
9379
+ ]);
9380
+ const oracleIdx = priceOracleOutRef !== void 0 ? { OracleRefInputIdx: refInputsIndices[3] } : "OracleVoid";
9381
+ tx.validFrom(interval.validFrom).validTo(interval.validTo).readFrom(referenceInputs).collectFrom([cdpCreatorUtxo], {
9382
+ kind: "self",
9383
+ makeRedeemer: (inputIdx) => {
9384
+ return serialiseCDPCreatorRedeemer({
9385
+ CreateCDP: {
9386
+ cdpOwner: (0, import_lucid53.fromHex)(pkh.hash),
9387
+ minted: mintedAmt,
9388
+ collateralAmt,
9389
+ currentTime,
9390
+ creatorInputIdx: inputIdx,
9391
+ creatorOutputIdx: 1n,
9392
+ cdpOutputIdx: 0n,
9393
+ iassetRefInputIdx: refInputsIndices[1],
9394
+ collateralAssetRefInputIdx: refInputsIndices[2],
9395
+ interestOracleRefInputIdx: refInputsIndices[0],
9396
+ priceOracleIdx: oracleIdx
9397
+ }
9398
+ });
9399
+ }
9400
+ });
9401
+ buildRedemptionsTx(
9402
+ redemptionDetails.redemptions.map((r) => [r.utxo, r.iassetsPayoutAmt]),
9403
+ iassetDatum.assetName,
9404
+ collateralAssetDatum.collateralAsset,
9405
+ price,
9406
+ iassetDatum.redemptionReimbursementRatio,
9407
+ sysParams,
9408
+ tx,
9409
+ 2n + (debtMintingFee > 0n ? 1n : 0n),
9410
+ refInputsIndices[2],
9411
+ refInputsIndices[1],
9412
+ oracleIdx
9413
+ );
9414
+ return tx;
9415
+ }
9416
+
8852
9417
  // src/contracts/price-oracle/transactions.ts
8853
- var import_lucid54 = require("@lucid-evolution/lucid");
9418
+ var import_lucid55 = require("@lucid-evolution/lucid");
8854
9419
 
8855
9420
  // src/contracts/price-oracle/scripts.ts
8856
- var import_lucid53 = require("@lucid-evolution/lucid");
9421
+ var import_lucid54 = require("@lucid-evolution/lucid");
8857
9422
 
8858
9423
  // src/validators/price-oracle-validator.ts
8859
9424
  var _priceOracleValidator = {
@@ -8866,18 +9431,18 @@ var _priceOracleValidator = {
8866
9431
  function mkPriceOracleValidator(params) {
8867
9432
  return {
8868
9433
  type: "PlutusV3",
8869
- script: (0, import_lucid53.applyParamsToScript)(_priceOracleValidator.cborHex, [
9434
+ script: (0, import_lucid54.applyParamsToScript)(_priceOracleValidator.cborHex, [
8870
9435
  castPriceOracleParams(params)
8871
9436
  ])
8872
9437
  };
8873
9438
  }
8874
9439
 
8875
9440
  // src/contracts/price-oracle/transactions.ts
8876
- var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
9441
+ var import_cardano_offchain_common25 = require("@3rd-eye-labs/cardano-offchain-common");
8877
9442
  var Core2 = __toESM(require("@evolution-sdk/evolution"));
8878
9443
  async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, currentSlot, refOutRef, auxiliaryData) {
8879
9444
  const network = lucid.config().network;
8880
- const now = BigInt((0, import_lucid54.slotToUnixTime)(network, currentSlot));
9445
+ const now = BigInt((0, import_lucid55.slotToUnixTime)(network, currentSlot));
8881
9446
  if (!refOutRef) {
8882
9447
  refOutRef = (await lucid.wallet().getUtxos())[0];
8883
9448
  }
@@ -8888,31 +9453,31 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
8888
9453
  },
8889
9454
  mintAmounts: [
8890
9455
  {
8891
- tokenName: (0, import_lucid54.fromText)(assetName),
9456
+ tokenName: (0, import_lucid55.fromText)(assetName),
8892
9457
  amount: 1n
8893
9458
  }
8894
9459
  ]
8895
9460
  });
8896
9461
  const priceOracleNft = {
8897
- currencySymbol: (0, import_lucid54.fromHex)(oracleNftPolicyId),
8898
- tokenName: (0, import_lucid54.fromHex)((0, import_lucid54.fromText)(assetName))
9462
+ currencySymbol: (0, import_lucid55.fromHex)(oracleNftPolicyId),
9463
+ tokenName: (0, import_lucid55.fromHex)((0, import_lucid55.fromText)(assetName))
8899
9464
  };
8900
9465
  const oracleValidator = mkPriceOracleValidator(oracleParams);
8901
9466
  const oracleDatum = {
8902
9467
  price: startPrice,
8903
9468
  expirationTime: BigInt(now) + oracleParams.expirationPeriod,
8904
- auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(import_lucid54.Data.void())
9469
+ auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(import_lucid55.Data.void())
8905
9470
  };
8906
9471
  tx.pay.ToContract(
8907
- (0, import_lucid54.validatorToAddress)(lucid.config().network, oracleValidator),
9472
+ (0, import_lucid55.validatorToAddress)(lucid.config().network, oracleValidator),
8908
9473
  { kind: "inline", value: serialisePriceOracleDatum(oracleDatum) },
8909
- (0, import_lucid54.addAssets)((0, import_cardano_offchain_common24.mkAssetsOf)(priceOracleNft, 1n))
9474
+ (0, import_lucid55.addAssets)((0, import_cardano_offchain_common25.mkAssetsOf)(priceOracleNft, 1n))
8910
9475
  );
8911
9476
  return [tx, priceOracleNft];
8912
9477
  }
8913
9478
  async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, currentSlot, auxiliaryData) {
8914
9479
  const network = lucid.config().network;
8915
- const currentTime = BigInt((0, import_lucid54.slotToUnixTime)(network, currentSlot));
9480
+ const currentTime = BigInt((0, import_lucid55.slotToUnixTime)(network, currentSlot));
8916
9481
  const priceOracleUtxo = matchSingle(
8917
9482
  await lucid.utxosByOutRef([oracleOref]),
8918
9483
  (_) => new Error("Expected a single price oracle UTXO")
@@ -8931,7 +9496,7 @@ async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, curr
8931
9496
  value: serialisePriceOracleDatum({
8932
9497
  price: newPrice,
8933
9498
  expirationTime: currentTime + oracleParams.expirationPeriod,
8934
- auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(import_lucid54.Data.void())
9499
+ auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(import_lucid55.Data.void())
8935
9500
  })
8936
9501
  },
8937
9502
  priceOracleUtxo.assets
@@ -8939,7 +9504,7 @@ async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, curr
8939
9504
  }
8940
9505
 
8941
9506
  // src/utils/helper-txs.ts
8942
- var import_lucid55 = require("@lucid-evolution/lucid");
9507
+ var import_lucid56 = require("@lucid-evolution/lucid");
8943
9508
 
8944
9509
  // src/scripts/always-fail-validator.ts
8945
9510
  var alwaysFailValidator = {
@@ -8949,18 +9514,18 @@ var alwaysFailValidator = {
8949
9514
 
8950
9515
  // src/utils/helper-txs.ts
8951
9516
  async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
8952
- const scriptAddr = (0, import_lucid55.validatorToAddress)(network, alwaysFailValidator);
9517
+ const scriptAddr = (0, import_lucid56.validatorToAddress)(network, alwaysFailValidator);
8953
9518
  const txHash = await lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator).complete().then((tx) => tx.sign.withWallet().complete()).then((tx) => tx.submit());
8954
9519
  await lucid.awaitTx(txHash);
8955
9520
  return { txHash, outputIndex: 0 };
8956
9521
  }
8957
9522
 
8958
9523
  // src/contracts/initialize/helpers.ts
8959
- var import_lucid59 = require("@lucid-evolution/lucid");
8960
- var import_cardano_offchain_common25 = require("@3rd-eye-labs/cardano-offchain-common");
9524
+ var import_lucid60 = require("@lucid-evolution/lucid");
9525
+ var import_cardano_offchain_common26 = require("@3rd-eye-labs/cardano-offchain-common");
8961
9526
 
8962
9527
  // src/scripts/auth-token-policy.ts
8963
- var import_lucid56 = require("@lucid-evolution/lucid");
9528
+ var import_lucid57 = require("@lucid-evolution/lucid");
8964
9529
  var authPolicyData = {
8965
9530
  type: "PlutusV2",
8966
9531
  cborHex: "5904d95904d60100003232323232323232323232323232323232323232323232323232223232223232323253355335533357346042660166018a00200e03026464666ae68cdc419806980728019980b9999aa999ab9a3370e90030008990911118020029aba1302400215333573466e1d20040011321222230020053574260480042a666ae68c08c0044c848888c004014d5d098120010a999ab9a30220011321222230030053574260480040424c40024c4c016900100a80d98120009baa3500201d01813357389213d4d75737420636f6e73756d65204e4654206f7220746f6b656e2070726576696f75736c79206d696e746564207573696e67207468697320706f6c6963790001301415335738920103505435001613253335734604060460022646464646464646464646464646464646464646464642466666666666600202e02a02602201e01a01601200e00a0060046ae84d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d118118011aba1302200101f37546a002036a666ae68c078c0840084c8c848cc00400c008d5d09aba2302100335742604000403aa666ae68c074c080dd500180880e1baa00153335734603260380022646601e6ae84004d5d09aba2001301b00101837540044464646603a4466a0029000111a801112999ab9a3375e0040102660464466a0029000111a801112999ab9a3375e00401a20022600c0060022600c0060086a00402a6a0020264666aa6020026660144466aa601c02a46a002446601e00466aa602203046a0024466024004666a0026e012000700466e0000520000013355300e015235001223300f00233350012335530120192350012233013002300e0010012233300a0090020012335530120192350012233013002301000100133300500400200100e232333008200133008200175a6aa666ae68c05cc0680044c8c8c8c8c8c848cccc00401c01400c008d5d09aba2002357420026ae88008d5d08009aba2301a00235742603200202c44440066ea8d400404ccc06488cccd55cf800900891919809a999ab9a3019301c001132321233001003002357426ae88c070008d5d0980d80080c18021aba200337546ae84008054dd61a80091111111111100611199ab9a3375e00400201c010444666aa601602601e66aa601802646a002446601a0046010002666aa6016026446a00444a66a666aa602802e6601c4466601402e004002601002c46a002446601400400a00c200626602600800601c00266aa601802646a002446601a0046603844a66a002260180064426a00444a66a6601800401022444660040140082600c00600800446600244a66a004018200200a4244460060084446602c446666aae7c00480388c8cc040cc02cc01cc064004c018c060004c010d5d10019aba1002012375600242444600200820142014442466002006004601c4422444a66a00220044426600a004666aa600e01e00a008002601a442244a66a00200a44266012600800466aa600c01a00800220022006442446600200800660124422444a66a00226a00600e442666a00a0106008004666aa600e01400a0080024400444002240022a66ae71241035054310016370e90001b874800955cf2ab9d2323001001223300330020020011"
@@ -8968,15 +9533,15 @@ var authPolicyData = {
8968
9533
  function mkAuthTokenPolicy(ac, tn) {
8969
9534
  return {
8970
9535
  type: authPolicyData.type,
8971
- script: (0, import_lucid56.applyParamsToScript)(authPolicyData.cborHex, [
8972
- new import_lucid56.Constr(0, [(0, import_lucid56.toHex)(ac.currencySymbol), (0, import_lucid56.toHex)(ac.tokenName)]),
9536
+ script: (0, import_lucid57.applyParamsToScript)(authPolicyData.cborHex, [
9537
+ new import_lucid57.Constr(0, [(0, import_lucid57.toHex)(ac.currencySymbol), (0, import_lucid57.toHex)(ac.tokenName)]),
8973
9538
  tn
8974
9539
  ])
8975
9540
  };
8976
9541
  }
8977
9542
 
8978
9543
  // src/contracts/iasset/scripts.ts
8979
- var import_lucid57 = require("@lucid-evolution/lucid");
9544
+ var import_lucid58 = require("@lucid-evolution/lucid");
8980
9545
 
8981
9546
  // src/validators/iasset-validator.ts
8982
9547
  var _iassetValidator = {
@@ -8986,8 +9551,8 @@ var _iassetValidator = {
8986
9551
  };
8987
9552
 
8988
9553
  // src/contracts/iasset/scripts.ts
8989
- var import_lucid58 = require("@lucid-evolution/lucid");
8990
- var IAssetScriptParamsSchema = import_lucid58.Data.Object({
9554
+ var import_lucid59 = require("@lucid-evolution/lucid");
9555
+ var IAssetScriptParamsSchema = import_lucid59.Data.Object({
8991
9556
  upgradeToken: AssetClassSchema2,
8992
9557
  versionRecordToken: AssetClassSchema2
8993
9558
  });
@@ -8995,8 +9560,8 @@ var IAssetScriptParams = IAssetScriptParamsSchema;
8995
9560
  var mkIAssetValidatorFromSP = (params) => {
8996
9561
  return {
8997
9562
  type: "PlutusV3",
8998
- script: (0, import_lucid57.applyParamsToScript)(_iassetValidator.cborHex, [
8999
- import_lucid58.Data.castTo(
9563
+ script: (0, import_lucid58.applyParamsToScript)(_iassetValidator.cborHex, [
9564
+ import_lucid59.Data.castTo(
9000
9565
  {
9001
9566
  upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
9002
9567
  versionRecordToken: fromSystemParamsAssetLucid(
@@ -9013,7 +9578,7 @@ var mkIAssetValidatorFromSP = (params) => {
9013
9578
  var import_ts_pattern21 = require("ts-pattern");
9014
9579
 
9015
9580
  // tests/test-helpers.ts
9016
- var import_fp_ts19 = require("fp-ts");
9581
+ var import_fp_ts20 = require("fp-ts");
9017
9582
  async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
9018
9583
  const bTx = await transaction.complete();
9019
9584
  const signatures = [await bTx.partialSign.withWallet()];
@@ -9074,22 +9639,22 @@ async function mintOneTimeToken(lucid, tokenName, amount) {
9074
9639
  });
9075
9640
  }
9076
9641
  async function mintOneTimeAsset(lucid, tokenName, amount) {
9077
- const policyId = await mintOneTimeToken(lucid, (0, import_lucid59.fromText)(tokenName), amount);
9642
+ const policyId = await mintOneTimeToken(lucid, (0, import_lucid60.fromText)(tokenName), amount);
9078
9643
  return {
9079
- currencySymbol: (0, import_lucid59.fromHex)(policyId),
9080
- tokenName: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(tokenName))
9644
+ currencySymbol: (0, import_lucid60.fromHex)(policyId),
9645
+ tokenName: (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(tokenName))
9081
9646
  };
9082
9647
  }
9083
9648
  function deriveAuthToken(parent, tokenName) {
9084
- const policy = mkAuthTokenPolicy(parent, (0, import_lucid59.fromText)(tokenName));
9649
+ const policy = mkAuthTokenPolicy(parent, (0, import_lucid60.fromText)(tokenName));
9085
9650
  return {
9086
- currencySymbol: (0, import_lucid59.fromHex)((0, import_lucid59.mintingPolicyToId)(policy)),
9087
- tokenName: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(tokenName))
9651
+ currencySymbol: (0, import_lucid60.fromHex)((0, import_lucid60.mintingPolicyToId)(policy)),
9652
+ tokenName: (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(tokenName))
9088
9653
  };
9089
9654
  }
9090
9655
  async function initScriptRef(lucid, validator) {
9091
9656
  const tx = lucid.newTx().pay.ToContract(
9092
- (0, import_lucid59.credentialToAddress)(lucid.config().network, {
9657
+ (0, import_lucid60.credentialToAddress)(lucid.config().network, {
9093
9658
  hash: alwaysFailValidatorHash,
9094
9659
  type: "Script"
9095
9660
  }),
@@ -9107,11 +9672,11 @@ async function initCollector(lucid, collectorParams, numCollectors) {
9107
9672
  tx.pay.ToContract(
9108
9673
  createScriptAddress(
9109
9674
  lucid.config().network,
9110
- (0, import_lucid59.validatorToScriptHash)(mkCollectorValidatorFromSP(collectorParams))
9675
+ (0, import_lucid60.validatorToScriptHash)(mkCollectorValidatorFromSP(collectorParams))
9111
9676
  ),
9112
9677
  {
9113
9678
  kind: "inline",
9114
- value: import_lucid59.Data.void()
9679
+ value: import_lucid60.Data.void()
9115
9680
  }
9116
9681
  );
9117
9682
  }
@@ -9122,7 +9687,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
9122
9687
  const interestCollectionAdminDatum = {
9123
9688
  admin_permissions: {
9124
9689
  Signature: {
9125
- keyHash: (0, import_lucid59.fromHex)(pkh.hash)
9690
+ keyHash: (0, import_lucid60.fromHex)(pkh.hash)
9126
9691
  }
9127
9692
  }
9128
9693
  };
@@ -9134,7 +9699,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
9134
9699
  kind: "inline",
9135
9700
  value: serialiseInterestCollectionDatum(interestCollectionAdminDatum)
9136
9701
  },
9137
- (0, import_cardano_offchain_common25.mkAssetsOf)(multisigUtxoNft, 1n)
9702
+ (0, import_cardano_offchain_common26.mkAssetsOf)(multisigUtxoNft, 1n)
9138
9703
  )
9139
9704
  );
9140
9705
  const interestCollectionUtxoDeploymentTx = lucid.newTx();
@@ -9142,7 +9707,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
9142
9707
  interestCollectionUtxoDeploymentTx.pay.ToContract(
9143
9708
  createScriptAddress(lucid.config().network, interestCollectionValHash),
9144
9709
  void 0,
9145
- (0, import_cardano_offchain_common25.mkLovelacesOf)(interestCollectorUtxoLovelaces)
9710
+ (0, import_cardano_offchain_common26.mkLovelacesOf)(interestCollectorUtxoLovelaces)
9146
9711
  );
9147
9712
  }
9148
9713
  await submitTx(lucid, interestCollectionUtxoDeploymentTx);
@@ -9151,15 +9716,15 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
9151
9716
  const tx = lucid.newTx();
9152
9717
  for (let i = 0; i < Number(numCdpCreators); i++) {
9153
9718
  tx.pay.ToContract(
9154
- (0, import_lucid59.credentialToAddress)(lucid.config().network, {
9155
- hash: (0, import_lucid59.validatorToScriptHash)(
9719
+ (0, import_lucid60.credentialToAddress)(lucid.config().network, {
9720
+ hash: (0, import_lucid60.validatorToScriptHash)(
9156
9721
  mkCDPCreatorValidatorFromSP(cdpCreatorParams)
9157
9722
  ),
9158
9723
  type: "Script"
9159
9724
  }),
9160
- { kind: "inline", value: import_lucid59.Data.void() },
9725
+ { kind: "inline", value: import_lucid60.Data.void() },
9161
9726
  {
9162
- [cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + (0, import_lucid59.fromText)(cdpCreatorParams.cdpCreatorNft[1].unTokenName)]: 1n
9727
+ [cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + (0, import_lucid60.fromText)(cdpCreatorParams.cdpCreatorNft[1].unTokenName)]: 1n
9163
9728
  }
9164
9729
  );
9165
9730
  }
@@ -9168,21 +9733,21 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
9168
9733
  async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasuryIndyAmount, numTreasuryCollectors) {
9169
9734
  const treasuryAddr = createScriptAddress(
9170
9735
  lucid.config().network,
9171
- (0, import_lucid59.validatorToScriptHash)(mkTreasuryValidatorFromSP(treasuryParams)),
9736
+ (0, import_lucid60.validatorToScriptHash)(mkTreasuryValidatorFromSP(treasuryParams)),
9172
9737
  treasuryParams.treasuryUtxosStakeCredential != null ? fromSysParamsCredential(treasuryParams.treasuryUtxosStakeCredential) : void 0
9173
9738
  );
9174
9739
  const tx = lucid.newTx().pay.ToContract(
9175
9740
  treasuryAddr,
9176
- { kind: "inline", value: import_lucid59.Data.void() },
9177
- (0, import_lucid59.addAssets)(
9178
- (0, import_cardano_offchain_common25.mkAssetsOf)(daoAsset, 1n),
9179
- (0, import_cardano_offchain_common25.mkAssetsOf)(indyAsset, treasuryIndyAmount)
9741
+ { kind: "inline", value: import_lucid60.Data.void() },
9742
+ (0, import_lucid60.addAssets)(
9743
+ (0, import_cardano_offchain_common26.mkAssetsOf)(daoAsset, 1n),
9744
+ (0, import_cardano_offchain_common26.mkAssetsOf)(indyAsset, treasuryIndyAmount)
9180
9745
  )
9181
9746
  );
9182
9747
  for (let i = 0; i < Number(numTreasuryCollectors); i++) {
9183
9748
  tx.pay.ToContract(treasuryAddr, {
9184
9749
  kind: "inline",
9185
- value: import_lucid59.Data.void()
9750
+ value: import_lucid60.Data.void()
9186
9751
  });
9187
9752
  }
9188
9753
  await submitTx(lucid, tx);
@@ -9191,7 +9756,7 @@ async function initStakingManager(lucid, stakingParams) {
9191
9756
  const tx = lucid.newTx().pay.ToContract(
9192
9757
  createScriptAddress(
9193
9758
  lucid.config().network,
9194
- (0, import_lucid59.validatorToScriptHash)(mkStakingValidatorFromSP(stakingParams))
9759
+ (0, import_lucid60.validatorToScriptHash)(mkStakingValidatorFromSP(stakingParams))
9195
9760
  ),
9196
9761
  {
9197
9762
  kind: "inline",
@@ -9201,7 +9766,7 @@ async function initStakingManager(lucid, stakingParams) {
9201
9766
  })
9202
9767
  },
9203
9768
  {
9204
- [stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid59.fromText)(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
9769
+ [stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid60.fromText)(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
9205
9770
  }
9206
9771
  );
9207
9772
  await submitTx(lucid, tx);
@@ -9227,10 +9792,10 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
9227
9792
  return Promise.resolve({
9228
9793
  info: {
9229
9794
  DeferredValidation: {
9230
- feedValHash: (0, import_lucid59.fromHex)(
9795
+ feedValHash: (0, import_lucid60.fromHex)(
9231
9796
  getPythFeedConfig(
9232
9797
  pythConfig,
9233
- (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(iasset.name)),
9798
+ (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(iasset.name)),
9234
9799
  collateralAsset.collateralAsset
9235
9800
  ).pythFeedValHash
9236
9801
  )
@@ -9241,7 +9806,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
9241
9806
  }).exhaustive();
9242
9807
  }
9243
9808
  async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig, currentSlot) {
9244
- const iassetName = (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(asset.name));
9809
+ const iassetName = (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(asset.name));
9245
9810
  const collateralAssetInfos = [];
9246
9811
  for (const collateralAsset of asset.collateralAssets) {
9247
9812
  const [pkh, _] = await addrDetails(lucid);
@@ -9281,7 +9846,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
9281
9846
  const collateralAssetTx = lucid.newTx().pay.ToContract(
9282
9847
  createScriptAddress(
9283
9848
  lucid.config().network,
9284
- (0, import_lucid59.validatorToScriptHash)(mkIAssetValidatorFromSP(iassetParams))
9849
+ (0, import_lucid60.validatorToScriptHash)(mkIAssetValidatorFromSP(iassetParams))
9285
9850
  ),
9286
9851
  {
9287
9852
  kind: "inline",
@@ -9289,7 +9854,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
9289
9854
  CollateralAssetContent: collateralAssetContent
9290
9855
  })
9291
9856
  },
9292
- (0, import_cardano_offchain_common25.mkAssetsOf)(collateralAssetAuthToken, 1n)
9857
+ (0, import_cardano_offchain_common26.mkAssetsOf)(collateralAssetAuthToken, 1n)
9293
9858
  );
9294
9859
  await submitTx(lucid, collateralAssetTx);
9295
9860
  collateralAssetInfos.push({
@@ -9307,24 +9872,24 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
9307
9872
  redemptionFeeRatio: stableswapPool.redemptionFeeRatio,
9308
9873
  mintingEnabled: stableswapPool.mintingEnabled,
9309
9874
  redemptionEnabled: stableswapPool.redemptionEnabled,
9310
- feeManager: stableswapPool.feeManager ? (0, import_lucid59.fromHex)(stableswapPool.feeManager) : null,
9875
+ feeManager: stableswapPool.feeManager ? (0, import_lucid60.fromHex)(stableswapPool.feeManager) : null,
9311
9876
  minMintOrderAmount: stableswapPool.minMintOrderAmount,
9312
9877
  minRedemptionOrderAmount: stableswapPool.minRedemptionOrderAmount,
9313
9878
  iasset: iassetName,
9314
- stableswapValHash: (0, import_lucid59.fromHex)(stableswapValidatorHash)
9879
+ stableswapValHash: (0, import_lucid60.fromHex)(stableswapValidatorHash)
9315
9880
  };
9316
9881
  await submitTx(
9317
9882
  lucid,
9318
9883
  lucid.newTx().pay.ToContract(
9319
9884
  createScriptAddress(
9320
9885
  lucid.config().network,
9321
- (0, import_lucid59.validatorToScriptHash)(mkCdpValidatorFromSP(cdpParams))
9886
+ (0, import_lucid60.validatorToScriptHash)(mkCdpValidatorFromSP(cdpParams))
9322
9887
  ),
9323
9888
  {
9324
9889
  kind: "inline",
9325
9890
  value: serialiseStableswapPoolDatum(stableswapPoolDatum)
9326
9891
  },
9327
- (0, import_cardano_offchain_common25.mkAssetsOf)(cdpAuthToken, 1n)
9892
+ (0, import_cardano_offchain_common26.mkAssetsOf)(cdpAuthToken, 1n)
9328
9893
  )
9329
9894
  );
9330
9895
  }
@@ -9337,28 +9902,28 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
9337
9902
  redemptionReimbursementRatio: asset.redemptionReimbursementRatio,
9338
9903
  redemptionProcessingFeeRatio: asset.redemptionProcessingFeeRatio,
9339
9904
  firstIAsset: asset.firstAsset,
9340
- nextIAsset: asset.nextAsset ? (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(asset.nextAsset)) : null
9905
+ nextIAsset: asset.nextAsset ? (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(asset.nextAsset)) : null
9341
9906
  };
9342
9907
  const assetTx = lucid.newTx().pay.ToContract(
9343
9908
  createScriptAddress(
9344
9909
  lucid.config().network,
9345
- (0, import_lucid59.validatorToScriptHash)(mkIAssetValidatorFromSP(iassetParams))
9910
+ (0, import_lucid60.validatorToScriptHash)(mkIAssetValidatorFromSP(iassetParams))
9346
9911
  ),
9347
9912
  {
9348
9913
  kind: "inline",
9349
9914
  value: serialiseIAssetDatum({ IAssetContent: iassetDatum })
9350
9915
  },
9351
- (0, import_cardano_offchain_common25.mkAssetsOf)(iassetToken, 1n)
9916
+ (0, import_cardano_offchain_common26.mkAssetsOf)(iassetToken, 1n)
9352
9917
  );
9353
9918
  await submitTx(lucid, assetTx);
9354
9919
  const stabilityPoolDatum = {
9355
- iasset: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(asset.name)),
9920
+ iasset: (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(asset.name)),
9356
9921
  state: initSpState,
9357
9922
  assetStates: []
9358
9923
  };
9359
9924
  const spTx = lucid.newTx().pay.ToContract(
9360
- (0, import_lucid59.credentialToAddress)(lucid.config().network, {
9361
- hash: (0, import_lucid59.validatorToScriptHash)(
9925
+ (0, import_lucid60.credentialToAddress)(lucid.config().network, {
9926
+ hash: (0, import_lucid60.validatorToScriptHash)(
9362
9927
  mkStabilityPoolValidatorFromSP(stabilityPoolParams)
9363
9928
  ),
9364
9929
  type: "Script"
@@ -9367,7 +9932,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
9367
9932
  kind: "inline",
9368
9933
  value: serialiseStabilityPoolDatum({ StabilityPool: stabilityPoolDatum })
9369
9934
  },
9370
- (0, import_cardano_offchain_common25.mkAssetsOf)(stabilityPoolToken, 1n)
9935
+ (0, import_cardano_offchain_common26.mkAssetsOf)(stabilityPoolToken, 1n)
9371
9936
  );
9372
9937
  await submitTx(lucid, spTx);
9373
9938
  return {
@@ -9384,39 +9949,39 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
9384
9949
  iassetsCount: BigInt(initialAssets.length)
9385
9950
  };
9386
9951
  const tx = lucid.newTx().pay.ToContract(
9387
- (0, import_lucid59.credentialToAddress)(lucid.config().network, {
9388
- hash: (0, import_lucid59.validatorToScriptHash)(mkGovValidatorFromSP(governanceParams)),
9952
+ (0, import_lucid60.credentialToAddress)(lucid.config().network, {
9953
+ hash: (0, import_lucid60.validatorToScriptHash)(mkGovValidatorFromSP(governanceParams)),
9389
9954
  type: "Script"
9390
9955
  }),
9391
9956
  { kind: "inline", value: serialiseGovDatum(datum) },
9392
- (0, import_cardano_offchain_common25.mkAssetsOf)(govToken, 1n)
9957
+ (0, import_cardano_offchain_common26.mkAssetsOf)(govToken, 1n)
9393
9958
  );
9394
9959
  await submitTx(lucid, tx);
9395
9960
  }
9396
9961
  async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
9397
- const script = mkAuthTokenPolicy(asset, (0, import_lucid59.fromText)(tokenName));
9398
- const policyId = (0, import_lucid59.mintingPolicyToId)(script);
9962
+ const script = mkAuthTokenPolicy(asset, (0, import_lucid60.fromText)(tokenName));
9963
+ const policyId = (0, import_lucid60.mintingPolicyToId)(script);
9399
9964
  const address = await lucid.wallet().address();
9400
- const utxos = (await lucid.utxosAtWithUnit(address, (0, import_cardano_offchain_common25.assetClassToUnit)(asset))).filter((utxo2) => (0, import_cardano_offchain_common25.assetClassValueOf)(utxo2.assets, asset) === 1n).sort((a, b) => Number((0, import_cardano_offchain_common25.lovelacesAmt)(b.assets) - (0, import_cardano_offchain_common25.lovelacesAmt)(a.assets)));
9965
+ const utxos = (await lucid.utxosAtWithUnit(address, (0, import_cardano_offchain_common26.assetClassToUnit)(asset))).filter((utxo2) => (0, import_cardano_offchain_common26.assetClassValueOf)(utxo2.assets, asset) === 1n).sort((a, b) => Number((0, import_cardano_offchain_common26.lovelacesAmt)(b.assets) - (0, import_cardano_offchain_common26.lovelacesAmt)(a.assets)));
9401
9966
  if (utxos.length === 0) {
9402
9967
  throw new Error("No utxos found");
9403
9968
  }
9404
9969
  const utxo = utxos[0];
9405
9970
  const tx = lucid.newTx().attach.MintingPolicy(script).collectFrom([utxo]).mintAssets(
9406
9971
  {
9407
- [policyId + (0, import_lucid59.fromText)(tokenName)]: amount
9972
+ [policyId + (0, import_lucid60.fromText)(tokenName)]: amount
9408
9973
  },
9409
- import_lucid59.Data.void()
9974
+ import_lucid60.Data.void()
9410
9975
  );
9411
9976
  await submitTx(lucid, tx);
9412
9977
  }
9413
9978
 
9414
9979
  // src/contracts/initialize/actions.ts
9415
- var import_lucid64 = require("@lucid-evolution/lucid");
9416
- var import_cardano_offchain_common27 = require("@3rd-eye-labs/cardano-offchain-common");
9980
+ var import_lucid65 = require("@lucid-evolution/lucid");
9981
+ var import_cardano_offchain_common28 = require("@3rd-eye-labs/cardano-offchain-common");
9417
9982
 
9418
9983
  // src/scripts/iasset-policy.ts
9419
- var import_lucid60 = require("@lucid-evolution/lucid");
9984
+ var import_lucid61 = require("@lucid-evolution/lucid");
9420
9985
  var iassetPolicyData = {
9421
9986
  type: "PlutusV2",
9422
9987
  cborHex: "59047b590478010000323232323232323232323232323232323232323232323232323232323232330102223253353300453335734603e60426ea800c04c0794ccd5cd180f98108008991909198008018011aba13574460420046ae84c08000407804c54cd5ce248103505435001637540026602044464a66aa666ae68cdc419803199aa980d00e803919980810008079a98071a80080e9003998089192999ab9a30213023001132321233001003002357426ae88c08c008d5d098110008101baa00135500122222222222200c004480084ccd5cd19b8748008cc018ccd54c06807401c8ccc040800403cd4004801ccc044034d5400488888888888802801006004805c05c4cd5ce24910434450546f6b656e206d697373696e670001213253335734603e60420022646464646464646464646464646464646464646464642466666666666600202e02a02602201e01a01601200e00a0060046ae84d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d118108011aba1302000101e37546a002034464a666ae68c074c07c0044c8c848cc00400c008d5d09aba2301f00235742603c0020386ea800488800c88c8c8cc08088cd400520002235002225333573466ebc0080204cc09888cd400520002235002225333573466ebc00803440044c01800c0044c01800c010d4008064d400405ccc02488cd54c0440608d400488cc038008cd54c05006c8d400488cc044008ccd4004dc024000e008cdc0000a400000266aa602203046a002446601c004666a002466aa602a03846a0024466024004601a00200244666012010004002466aa602a03846a0024466024004601c00200266600800600400202244666ae68cdd7801000809006111199aa980780b80999aa980800b91a80091198068011804000999aa980780b911a80111299a999aa980c00d998071119980500d801000980400d11a8009119805001002803080189980b80200180900099aa980800b91a80091198068011980f91299a800898058019109a80111299a9980600100408911198010050020980300180200111980091299a80100808008049091118018021091118008021192999ab9a301430160011323232323232123333001007005003002357426ae88008d5d08009aba2002357420026ae88c058008d5d0980a8008099baa00133001200175a4446602c446666aae7c004803c8c8cc044cc020c01cc064004c018c060004c010d5d10019aba100201337560024424660020060044466026446666aae7c00480308cc034c014d5d080118019aba200201037580022014201444460066004002601a4422444a66a00220044426600a004666aa600e01e00a0080026018442244a66a00200a44266012600800466aa600c01a00800220022006442446600200800660104422444a66a00226a00600e442666a00a0106008004666aa600e01400a0080024400444002240022a66ae71241035054310016370e90002ab9e5573a4646002002446600660040040021"
@@ -9424,27 +9989,27 @@ var iassetPolicyData = {
9424
9989
  function mkIAssetTokenPolicy(ac) {
9425
9990
  return {
9426
9991
  type: iassetPolicyData.type,
9427
- script: (0, import_lucid60.applyParamsToScript)(iassetPolicyData.cborHex, [
9428
- new import_lucid60.Constr(0, [(0, import_lucid60.toHex)(ac.currencySymbol), (0, import_lucid60.toHex)(ac.tokenName)])
9992
+ script: (0, import_lucid61.applyParamsToScript)(iassetPolicyData.cborHex, [
9993
+ new import_lucid61.Constr(0, [(0, import_lucid61.toHex)(ac.currencySymbol), (0, import_lucid61.toHex)(ac.tokenName)])
9429
9994
  ])
9430
9995
  };
9431
9996
  }
9432
9997
 
9433
9998
  // src/contracts/stableswap/scripts.ts
9434
- var import_lucid62 = require("@lucid-evolution/lucid");
9999
+ var import_lucid63 = require("@lucid-evolution/lucid");
9435
10000
 
9436
10001
  // src/contracts/stableswap/types.ts
9437
- var import_lucid61 = require("@lucid-evolution/lucid");
9438
- var StableswapParamsSchema = import_lucid61.Data.Object({
9439
- iassetSymbol: import_lucid61.Data.Bytes(),
10002
+ var import_lucid62 = require("@lucid-evolution/lucid");
10003
+ var StableswapParamsSchema = import_lucid62.Data.Object({
10004
+ iassetSymbol: import_lucid62.Data.Bytes(),
9440
10005
  cdpToken: AssetClassSchema2,
9441
10006
  versionRecordToken: AssetClassSchema2,
9442
- cdpValHash: import_lucid61.Data.Bytes(),
9443
- treasuryValHash: import_lucid61.Data.Bytes()
10007
+ cdpValHash: import_lucid62.Data.Bytes(),
10008
+ treasuryValHash: import_lucid62.Data.Bytes()
9444
10009
  });
9445
10010
  var StableswapParams = StableswapParamsSchema;
9446
10011
  function castStableswapParams(params) {
9447
- return import_lucid61.Data.castTo(params, StableswapParams);
10012
+ return import_lucid62.Data.castTo(params, StableswapParams);
9448
10013
  }
9449
10014
 
9450
10015
  // src/validators/stableswap-validator.ts
@@ -9458,7 +10023,7 @@ var _stableswapValidator = {
9458
10023
  var mkStableswapValidator = (params) => {
9459
10024
  return {
9460
10025
  type: "PlutusV3",
9461
- script: (0, import_lucid62.applyParamsToScript)(_stableswapValidator.cborHex, [
10026
+ script: (0, import_lucid63.applyParamsToScript)(_stableswapValidator.cborHex, [
9462
10027
  castStableswapParams(params)
9463
10028
  ])
9464
10029
  };
@@ -9466,7 +10031,7 @@ var mkStableswapValidator = (params) => {
9466
10031
  var mkStableswapValidatorFromSP = (params) => {
9467
10032
  return {
9468
10033
  type: "PlutusV3",
9469
- script: (0, import_lucid62.applyParamsToScript)(_stableswapValidator.cborHex, [
10034
+ script: (0, import_lucid63.applyParamsToScript)(_stableswapValidator.cborHex, [
9470
10035
  castStableswapParams({
9471
10036
  iassetSymbol: params.iassetSymbol.unCurrencySymbol,
9472
10037
  cdpToken: fromSystemParamsAssetLucid(params.cdpToken),
@@ -9502,7 +10067,7 @@ var mkPythFeedValidator = (params) => {
9502
10067
  var import_ts_pattern22 = require("ts-pattern");
9503
10068
 
9504
10069
  // tests/pyth/endpoints.ts
9505
- var import_lucid63 = require("@lucid-evolution/lucid");
10070
+ var import_lucid64 = require("@lucid-evolution/lucid");
9506
10071
 
9507
10072
  // src/validators/always-succeed-validator.ts
9508
10073
  var _alwaysSucceedValidator = {
@@ -9518,29 +10083,29 @@ var alwaysSucceedValidator = {
9518
10083
  };
9519
10084
 
9520
10085
  // tests/pyth/endpoints.ts
9521
- var import_cardano_offchain_common26 = require("@3rd-eye-labs/cardano-offchain-common");
10086
+ var import_cardano_offchain_common27 = require("@3rd-eye-labs/cardano-offchain-common");
9522
10087
  var TEST_TRUSTED_SIGNER_PUB_KEY = "4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f";
9523
10088
  async function initPyth(lucid) {
9524
- const pythStateName = (0, import_lucid63.fromText)("Pyth State");
10089
+ const pythStateName = (0, import_lucid64.fromText)("Pyth State");
9525
10090
  const pythStatePolicyId = await mintOneTimeToken(lucid, pythStateName, 1n);
9526
10091
  const pythStateAsset = {
9527
- currencySymbol: (0, import_lucid63.fromHex)(pythStatePolicyId),
9528
- tokenName: (0, import_lucid63.fromHex)(pythStateName)
10092
+ currencySymbol: (0, import_lucid64.fromHex)(pythStatePolicyId),
10093
+ tokenName: (0, import_lucid64.fromHex)(pythStateName)
9529
10094
  };
9530
- const alwaysSucceedsValidatorHash = (0, import_lucid63.validatorToScriptHash)(
10095
+ const alwaysSucceedsValidatorHash = (0, import_lucid64.validatorToScriptHash)(
9531
10096
  alwaysSucceedValidator
9532
10097
  );
9533
10098
  const pythStateDatum = {
9534
10099
  // The governance doesn't matter for the purpose of testing, so we can use any values
9535
10100
  governance: {
9536
- wormhole: (0, import_lucid63.fromHex)(""),
10101
+ wormhole: (0, import_lucid64.fromHex)(""),
9537
10102
  emitterChain: 0n,
9538
- emitterAddress: (0, import_lucid63.fromHex)(""),
10103
+ emitterAddress: (0, import_lucid64.fromHex)(""),
9539
10104
  seenSequence: 0n
9540
10105
  },
9541
10106
  trustedSigners: /* @__PURE__ */ new Map([
9542
10107
  [
9543
- (0, import_lucid63.fromHex)(TEST_TRUSTED_SIGNER_PUB_KEY),
10108
+ (0, import_lucid64.fromHex)(TEST_TRUSTED_SIGNER_PUB_KEY),
9544
10109
  {
9545
10110
  lower_bound: {
9546
10111
  bound_type: {
@@ -9560,25 +10125,25 @@ async function initPyth(lucid) {
9560
10125
  deprecatedWithdrawScripts: /* @__PURE__ */ new Map(),
9561
10126
  // For the purpose of testing, we use the always succeeds validator to validate the Pyth Messages.
9562
10127
  // This means the message signature checking will always succeed for the purpose of emulation testing.
9563
- withdraw_script: (0, import_lucid63.fromHex)(alwaysSucceedsValidatorHash)
10128
+ withdraw_script: (0, import_lucid64.fromHex)(alwaysSucceedsValidatorHash)
9564
10129
  };
9565
10130
  await runAndAwaitTxBuilder(
9566
10131
  lucid,
9567
10132
  lucid.newTx().pay.ToContract(
9568
- (0, import_lucid63.credentialToAddress)(lucid.config().network, {
9569
- hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator),
10133
+ (0, import_lucid64.credentialToAddress)(lucid.config().network, {
10134
+ hash: (0, import_lucid64.validatorToScriptHash)(alwaysSucceedValidator),
9570
10135
  type: "Script"
9571
10136
  }),
9572
10137
  { kind: "inline", value: serialisePythStateDatum(pythStateDatum) },
9573
- (0, import_cardano_offchain_common26.mkAssetsOf)(pythStateAsset, 1n),
10138
+ (0, import_cardano_offchain_common27.mkAssetsOf)(pythStateAsset, 1n),
9574
10139
  alwaysSucceedValidator
9575
10140
  )
9576
10141
  );
9577
10142
  await runAndAwaitTxBuilder(
9578
10143
  lucid,
9579
10144
  lucid.newTx().register.Stake(
9580
- (0, import_lucid63.credentialToRewardAddress)(lucid.config().network, {
9581
- hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator),
10145
+ (0, import_lucid64.credentialToRewardAddress)(lucid.config().network, {
10146
+ hash: (0, import_lucid64.validatorToScriptHash)(alwaysSucceedValidator),
9582
10147
  type: "Script"
9583
10148
  })
9584
10149
  )
@@ -9602,7 +10167,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
9602
10167
  const pythFeedValidator = mkPythFeedValidator(
9603
10168
  fromSysParamsPythFeedParams(val.pythFeedParams)
9604
10169
  );
9605
- const pythFeedValHash = (0, import_lucid64.validatorToScriptHash)(pythFeedValidator);
10170
+ const pythFeedValHash = (0, import_lucid65.validatorToScriptHash)(pythFeedValidator);
9606
10171
  const pythFeedValScriptRef = await initScriptRef(
9607
10172
  lucid,
9608
10173
  pythFeedValidator
@@ -9610,13 +10175,13 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
9610
10175
  await runAndAwaitTxBuilder(
9611
10176
  lucid,
9612
10177
  lucid.newTx().register.Stake(
9613
- (0, import_lucid64.credentialToRewardAddress)(lucid.config().network, {
9614
- hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator),
10178
+ (0, import_lucid65.credentialToRewardAddress)(lucid.config().network, {
10179
+ hash: (0, import_lucid65.validatorToScriptHash)(pythFeedValidator),
9615
10180
  type: "Script"
9616
10181
  })
9617
10182
  )
9618
10183
  );
9619
- const key = `${asset.name}/${(0, import_lucid64.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid64.toHex)(collateral.collateralAsset.tokenName)}`;
10184
+ const key = `${asset.name}/${(0, import_lucid65.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid65.toHex)(collateral.collateralAsset.tokenName)}`;
9620
10185
  return {
9621
10186
  [key]: {
9622
10187
  params: val.pythFeedParams,
@@ -9668,16 +10233,16 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9668
10233
  };
9669
10234
  const versionRecordTokenPolicy = mkVersionRecordTokenPolicy({
9670
10235
  upgradeToken: {
9671
- currencySymbol: (0, import_lucid64.toHex)(upgradeToken.currencySymbol),
9672
- tokenName: (0, import_lucid64.toHex)(upgradeToken.tokenName)
10236
+ currencySymbol: (0, import_lucid65.toHex)(upgradeToken.currencySymbol),
10237
+ tokenName: (0, import_lucid65.toHex)(upgradeToken.tokenName)
9673
10238
  }
9674
10239
  });
9675
10240
  const versionRecordToken = {
9676
- currencySymbol: (0, import_lucid64.fromHex)((0, import_lucid64.mintingPolicyToId)(versionRecordTokenPolicy)),
9677
- tokenName: (0, import_lucid64.fromHex)((0, import_lucid64.fromText)(tn.versionRecord))
10241
+ currencySymbol: (0, import_lucid65.fromHex)((0, import_lucid65.mintingPolicyToId)(versionRecordTokenPolicy)),
10242
+ tokenName: (0, import_lucid65.fromHex)((0, import_lucid65.fromText)(tn.versionRecord))
9678
10243
  };
9679
10244
  const versionRegistryValidator = mkVersionRegistryValidator();
9680
- const versionRegistryValHash = (0, import_lucid64.validatorToScriptHash)(
10245
+ const versionRegistryValHash = (0, import_lucid65.validatorToScriptHash)(
9681
10246
  versionRegistryValidator
9682
10247
  );
9683
10248
  const cdpCreatorAsset = await mintOneTimeAsset(
@@ -9698,7 +10263,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9698
10263
  versionRecordToken: toSystemParamsAsset(versionRecordToken)
9699
10264
  };
9700
10265
  const collectorValidator = mkCollectorValidatorFromSP(collectorParams);
9701
- const collectorValHash = (0, import_lucid64.validatorToScriptHash)(collectorValidator);
10266
+ const collectorValHash = (0, import_lucid65.validatorToScriptHash)(collectorValidator);
9702
10267
  const stakingParams = {
9703
10268
  stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
9704
10269
  stakingToken: toSystemParamsAsset(stakingToken),
@@ -9707,7 +10272,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9707
10272
  indyToken: toSystemParamsAsset(indyAsset),
9708
10273
  collectorValHash
9709
10274
  };
9710
- const stakingValHash = (0, import_lucid64.validatorToScriptHash)(
10275
+ const stakingValHash = (0, import_lucid65.validatorToScriptHash)(
9711
10276
  mkStakingValidatorFromSP(stakingParams)
9712
10277
  );
9713
10278
  await initStakingManager(lucid, stakingParams);
@@ -9716,9 +10281,9 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9716
10281
  versionRecordToken: toSystemParamsAsset(versionRecordToken)
9717
10282
  };
9718
10283
  const iassetValidator = mkIAssetValidatorFromSP(iassetParams);
9719
- const iassetValHash = (0, import_lucid64.validatorToScriptHash)(iassetValidator);
10284
+ const iassetValHash = (0, import_lucid65.validatorToScriptHash)(iassetValidator);
9720
10285
  const assetSymbolPolicy = mkIAssetTokenPolicy(cdpToken);
9721
- const assetSymbol = (0, import_lucid64.mintingPolicyToId)(assetSymbolPolicy);
10286
+ const assetSymbol = (0, import_lucid65.mintingPolicyToId)(assetSymbolPolicy);
9722
10287
  const snapshotEpochToScaleToSumToken = deriveAuthToken(
9723
10288
  stabilityPoolToken,
9724
10289
  tn.snapshotEpochToScaleToSum
@@ -9741,14 +10306,14 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9741
10306
  stakeCredential: spStakingCred
9742
10307
  };
9743
10308
  const stabilityPoolValidator = mkStabilityPoolValidatorFromSP(stabilityPoolParams);
9744
- const stabilityPoolValHash = (0, import_lucid64.validatorToScriptHash)(stabilityPoolValidator);
10309
+ const stabilityPoolValHash = (0, import_lucid65.validatorToScriptHash)(stabilityPoolValidator);
9745
10310
  const treasuryParams = {
9746
10311
  upgradeToken: toSystemParamsAsset(upgradeToken),
9747
10312
  versionRecordToken: toSystemParamsAsset(versionRecordToken),
9748
10313
  treasuryUtxosStakeCredential: treasuryStakingCred
9749
10314
  };
9750
10315
  const treasuryValidator = mkTreasuryValidatorFromSP(treasuryParams);
9751
- const treasuryValHash = (0, import_lucid64.validatorToScriptHash)(treasuryValidator);
10316
+ const treasuryValHash = (0, import_lucid65.validatorToScriptHash)(treasuryValidator);
9752
10317
  await initTreasury(
9753
10318
  lucid,
9754
10319
  treasuryParams,
@@ -9771,7 +10336,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9771
10336
  const interestCollectionValidator = mkInterestCollectionValidatorFromSP(
9772
10337
  interestCollectionParams
9773
10338
  );
9774
- const interestCollectionValHash = (0, import_lucid64.validatorToScriptHash)(
10339
+ const interestCollectionValHash = (0, import_lucid65.validatorToScriptHash)(
9775
10340
  interestCollectionValidator
9776
10341
  );
9777
10342
  await initInterestCollector(
@@ -9800,10 +10365,10 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9800
10365
  biasTime
9801
10366
  };
9802
10367
  const cdpRedeemValidator = mkCdpRedeemValidatorFromSP(cdpRedeemParams);
9803
- const cdpRedeemValHash = (0, import_lucid64.validatorToScriptHash)(cdpRedeemValidator);
9804
- const cdpRedeemRewardAddr = (0, import_lucid64.credentialToRewardAddress)(
10368
+ const cdpRedeemValHash = (0, import_lucid65.validatorToScriptHash)(cdpRedeemValidator);
10369
+ const cdpRedeemRewardAddr = (0, import_lucid65.credentialToRewardAddress)(
9805
10370
  lucid.config().network,
9806
- (0, import_lucid64.scriptHashToCredential)(cdpRedeemValHash)
10371
+ (0, import_lucid65.scriptHashToCredential)(cdpRedeemValHash)
9807
10372
  );
9808
10373
  await submitTx(lucid, lucid.newTx().register.Stake(cdpRedeemRewardAddr));
9809
10374
  const cdpParams = {
@@ -9822,7 +10387,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9822
10387
  biasTime
9823
10388
  };
9824
10389
  const cdpValidator = mkCdpValidatorFromSP(cdpParams);
9825
- const cdpValHash = (0, import_lucid64.validatorToScriptHash)(cdpValidator);
10390
+ const cdpValHash = (0, import_lucid65.validatorToScriptHash)(cdpValidator);
9826
10391
  const cdpCreatorParams = {
9827
10392
  cdpCreatorNft: toSystemParamsAsset(cdpCreatorAsset),
9828
10393
  cdpAssetCs: { unCurrencySymbol: assetSymbol },
@@ -9837,7 +10402,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9837
10402
  biasTime: cdpParams.biasTime
9838
10403
  };
9839
10404
  const cdpCreatorValidator = mkCDPCreatorValidatorFromSP(cdpCreatorParams);
9840
- const cdpCreatorValHash = (0, import_lucid64.validatorToScriptHash)(cdpCreatorValidator);
10405
+ const cdpCreatorValHash = (0, import_lucid65.validatorToScriptHash)(cdpCreatorValidator);
9841
10406
  const stableswapParams = {
9842
10407
  iassetSymbol: { unCurrencySymbol: assetSymbol },
9843
10408
  cdpToken: toSystemParamsAsset(cdpToken),
@@ -9846,7 +10411,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9846
10411
  treasuryValHash
9847
10412
  };
9848
10413
  const stableswapValidator = mkStableswapValidatorFromSP(stableswapParams);
9849
- const stableswapValHash = (0, import_lucid64.validatorToScriptHash)(stableswapValidator);
10414
+ const stableswapValHash = (0, import_lucid65.validatorToScriptHash)(stableswapValidator);
9850
10415
  await initCollector(lucid, collectorParams, numCollectors);
9851
10416
  const assetInfos = [];
9852
10417
  if (initialAssets.length > 0) {
@@ -9873,9 +10438,9 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9873
10438
  lucid,
9874
10439
  lucid.newTx().pay.ToAddress(
9875
10440
  await lucid.wallet().address(),
9876
- (0, import_lucid64.addAssets)(
9877
- (0, import_cardano_offchain_common27.mkAssetsOf)(iassetToken, 1n),
9878
- (0, import_cardano_offchain_common27.mkLovelacesOf)(BigInt(totalCollateralAssetsCount) * 5000000n)
10441
+ (0, import_lucid65.addAssets)(
10442
+ (0, import_cardano_offchain_common28.mkAssetsOf)(iassetToken, 1n),
10443
+ (0, import_cardano_offchain_common28.mkLovelacesOf)(BigInt(totalCollateralAssetsCount) * 5000000n)
9879
10444
  )
9880
10445
  )
9881
10446
  );
@@ -9891,9 +10456,9 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9891
10456
  lucid,
9892
10457
  lucid.newTx().pay.ToAddress(
9893
10458
  await lucid.wallet().address(),
9894
- (0, import_lucid64.addAssets)(
9895
- (0, import_cardano_offchain_common27.mkAssetsOf)(cdpCreatorAsset, 1n),
9896
- (0, import_cardano_offchain_common27.mkLovelacesOf)(BigInt(totalStablePoolsCount) * 5000000n)
10459
+ (0, import_lucid65.addAssets)(
10460
+ (0, import_cardano_offchain_common28.mkAssetsOf)(cdpCreatorAsset, 1n),
10461
+ (0, import_cardano_offchain_common28.mkLovelacesOf)(BigInt(totalStablePoolsCount) * 5000000n)
9897
10462
  )
9898
10463
  )
9899
10464
  );
@@ -9949,7 +10514,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9949
10514
  treasuryValHash
9950
10515
  };
9951
10516
  const executeValidator = mkExecuteValidatorFromSP(executeParams);
9952
- const executeValHash = (0, import_lucid64.validatorToScriptHash)(executeValidator);
10517
+ const executeValHash = (0, import_lucid65.validatorToScriptHash)(executeValidator);
9953
10518
  const pollShardParams = {
9954
10519
  pollToken: toSystemParamsAsset(pollToken),
9955
10520
  stakingToken: toSystemParamsAsset(stakingToken),
@@ -9957,7 +10522,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9957
10522
  stakingValHash
9958
10523
  };
9959
10524
  const pollShardValidator = mkPollShardValidatorFromSP(pollShardParams);
9960
- const pollShardValHash = (0, import_lucid64.validatorToScriptHash)(pollShardValidator);
10525
+ const pollShardValHash = (0, import_lucid65.validatorToScriptHash)(pollShardValidator);
9961
10526
  const pollManagerParams = {
9962
10527
  govNFT: toSystemParamsAsset(govNftAsset),
9963
10528
  pollToken: toSystemParamsAsset(pollToken),
@@ -9969,7 +10534,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9969
10534
  treasuryValHash
9970
10535
  };
9971
10536
  const pollManagerValidator = mkPollManagerValidatorFromSP(pollManagerParams);
9972
- const pollManagerValHash = (0, import_lucid64.validatorToScriptHash)(pollManagerValidator);
10537
+ const pollManagerValHash = (0, import_lucid65.validatorToScriptHash)(pollManagerValidator);
9973
10538
  const govParams = {
9974
10539
  gBiasTime: gBiasTime ? BigInt(gBiasTime) : BigInt(biasTime),
9975
10540
  govNFT: toSystemParamsAsset(govNftAsset),
@@ -9984,7 +10549,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
9984
10549
  iassetSymbol: { unCurrencySymbol: assetSymbol }
9985
10550
  };
9986
10551
  const govValidator = mkGovValidatorFromSP(govParams);
9987
- const govValHash = (0, import_lucid64.validatorToScriptHash)(govValidator);
10552
+ const govValHash = (0, import_lucid65.validatorToScriptHash)(govValidator);
9988
10553
  await initGovernance(
9989
10554
  lucid,
9990
10555
  govParams,
@@ -10000,36 +10565,36 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10000
10565
  versionRecordToken: cdpParams.versionRecordToken
10001
10566
  };
10002
10567
  const robValidator = mkRobValidatorFromSP(robParams);
10003
- const robValHash = (0, import_lucid64.validatorToScriptHash)(robValidator);
10004
- const cdpTokenPolicy = mkAuthTokenPolicy(cdpCreatorAsset, (0, import_lucid64.fromText)(tn.cdp));
10568
+ const robValHash = (0, import_lucid65.validatorToScriptHash)(robValidator);
10569
+ const cdpTokenPolicy = mkAuthTokenPolicy(cdpCreatorAsset, (0, import_lucid65.fromText)(tn.cdp));
10005
10570
  const iassetTokenPolicy = mkAuthTokenPolicy(
10006
10571
  upgradeToken,
10007
- (0, import_lucid64.fromText)(tn.iasset)
10572
+ (0, import_lucid65.fromText)(tn.iasset)
10008
10573
  );
10009
10574
  const accountTokenPolicy = mkAuthTokenPolicy(
10010
10575
  stabilityPoolToken,
10011
- (0, import_lucid64.fromText)(tn.account)
10576
+ (0, import_lucid65.fromText)(tn.account)
10012
10577
  );
10013
10578
  const stabilityPoolTokenPolicy = mkAuthTokenPolicy(
10014
10579
  upgradeToken,
10015
- (0, import_lucid64.fromText)(tn.stabilityPool)
10580
+ (0, import_lucid65.fromText)(tn.stabilityPool)
10016
10581
  );
10017
10582
  const pollTokenPolicy = mkAuthTokenPolicy(
10018
10583
  govNftAsset,
10019
- (0, import_lucid64.fromText)(tn.pollManager)
10584
+ (0, import_lucid65.fromText)(tn.pollManager)
10020
10585
  );
10021
10586
  const stakingTokenPolicy = mkAuthTokenPolicy(
10022
10587
  stakingManagerAsset,
10023
- (0, import_lucid64.fromText)(tn.staking)
10588
+ (0, import_lucid65.fromText)(tn.staking)
10024
10589
  );
10025
10590
  const collateralAssetAuthTokenPolicy = mkAuthTokenPolicy(
10026
10591
  iassetToken,
10027
- (0, import_lucid64.fromText)(tn.collateralAsset)
10592
+ (0, import_lucid65.fromText)(tn.collateralAsset)
10028
10593
  );
10029
- const upgradeTokenPolicy = mkAuthTokenPolicy(pollToken, (0, import_lucid64.fromText)(tn.upgrade));
10594
+ const upgradeTokenPolicy = mkAuthTokenPolicy(pollToken, (0, import_lucid65.fromText)(tn.upgrade));
10030
10595
  const snapshotEpochToScaleToSumTokenPolicy = mkAuthTokenPolicy(
10031
10596
  stabilityPoolToken,
10032
- (0, import_lucid64.fromText)(tn.snapshotEpochToScaleToSum)
10597
+ (0, import_lucid65.fromText)(tn.snapshotEpochToScaleToSum)
10033
10598
  );
10034
10599
  const sysParams = {
10035
10600
  cdpParams,
@@ -10173,19 +10738,19 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10173
10738
  }
10174
10739
 
10175
10740
  // src/contracts/stableswap/helpers.ts
10176
- var import_lucid65 = require("@lucid-evolution/lucid");
10741
+ var import_lucid66 = require("@lucid-evolution/lucid");
10177
10742
 
10178
10743
  // src/contracts/stableswap/types-new.ts
10179
- var import_cardano_offchain_common28 = require("@3rd-eye-labs/cardano-offchain-common");
10744
+ var import_cardano_offchain_common29 = require("@3rd-eye-labs/cardano-offchain-common");
10180
10745
  var import_evolution20 = require("@evolution-sdk/evolution");
10181
- var import_fp_ts20 = require("fp-ts");
10746
+ var import_fp_ts21 = require("fp-ts");
10182
10747
  var import_effect3 = require("effect");
10183
10748
  var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
10184
10749
  var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
10185
10750
  iasset: import_evolution20.TSchema.ByteArray,
10186
- collateralAsset: import_cardano_offchain_common28.AssetClassSchema,
10751
+ collateralAsset: import_cardano_offchain_common29.AssetClassSchema,
10187
10752
  owner: import_evolution20.TSchema.ByteArray,
10188
- destination: import_cardano_offchain_common28.AddressSchema,
10753
+ destination: import_cardano_offchain_common29.AddressSchema,
10189
10754
  destinationInlineDatum: import_evolution20.TSchema.NullOr(OpaqueData4),
10190
10755
  maxExecutionFee: import_evolution20.TSchema.Integer,
10191
10756
  maxFeeRatio: RationalSchema
@@ -10210,7 +10775,7 @@ var StableswapOrderRedeemerSchema = import_evolution20.TSchema.Union(
10210
10775
  );
10211
10776
  var StableswapOutputDatumSchema = import_evolution20.TSchema.Tuple([
10212
10777
  import_evolution20.TSchema.ByteArray,
10213
- import_cardano_offchain_common28.OutputReferenceSchema
10778
+ import_cardano_offchain_common29.OutputReferenceSchema
10214
10779
  ]);
10215
10780
  function serialiseStableswapOrderDatum(d) {
10216
10781
  return import_evolution20.Data.withSchema(
@@ -10220,22 +10785,22 @@ function serialiseStableswapOrderDatum(d) {
10220
10785
  }
10221
10786
  function parseStableswapOrderDatum(datum) {
10222
10787
  try {
10223
- return import_fp_ts20.option.some(
10788
+ return import_fp_ts21.option.some(
10224
10789
  import_evolution20.Data.withSchema(
10225
10790
  StableswapOrderDatumSchema,
10226
10791
  DEFAULT_SCHEMA_OPTIONS
10227
10792
  ).fromCBORHex(datum)
10228
10793
  );
10229
10794
  } catch (_) {
10230
- return import_fp_ts20.option.none;
10795
+ return import_fp_ts21.option.none;
10231
10796
  }
10232
10797
  }
10233
10798
  function parseStableswapOrderDatumOrThrow(datum) {
10234
- return import_fp_ts20.function.pipe(
10799
+ return import_fp_ts21.function.pipe(
10235
10800
  parseStableswapOrderDatum(datum),
10236
- import_fp_ts20.option.match(() => {
10801
+ import_fp_ts21.option.match(() => {
10237
10802
  throw new Error("Expected a Stableswap Order datum.");
10238
- }, import_fp_ts20.function.identity)
10803
+ }, import_fp_ts21.function.identity)
10239
10804
  );
10240
10805
  }
10241
10806
  function serialiseStableswapOutputDatum(d) {
@@ -10252,22 +10817,22 @@ function serialiseStableswapOrderRedeemer(r) {
10252
10817
  }
10253
10818
  function parseStableswapOrderRedeemer(redeemerCborHex) {
10254
10819
  try {
10255
- return import_fp_ts20.option.some(
10820
+ return import_fp_ts21.option.some(
10256
10821
  import_evolution20.Data.withSchema(
10257
10822
  StableswapOrderRedeemerSchema,
10258
10823
  DEFAULT_SCHEMA_OPTIONS
10259
10824
  ).fromCBORHex(redeemerCborHex)
10260
10825
  );
10261
10826
  } catch (_) {
10262
- return import_fp_ts20.option.none;
10827
+ return import_fp_ts21.option.none;
10263
10828
  }
10264
10829
  }
10265
10830
  function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
10266
- return import_fp_ts20.function.pipe(
10831
+ return import_fp_ts21.function.pipe(
10267
10832
  parseStableswapOrderRedeemer(redeemerCborHex),
10268
- import_fp_ts20.option.match(() => {
10833
+ import_fp_ts21.option.match(() => {
10269
10834
  throw new Error("Expected a Stableswap Order redeemer.");
10270
- }, import_fp_ts20.function.identity)
10835
+ }, import_fp_ts21.function.identity)
10271
10836
  );
10272
10837
  }
10273
10838
 
@@ -10277,9 +10842,9 @@ var BASE_MAX_EXECUTION_FEE = 1000000n;
10277
10842
  function createDestinationDatum(datum, outRef) {
10278
10843
  if (!datum) {
10279
10844
  return serialiseStableswapOutputDatum([
10280
- (0, import_lucid65.fromHex)((0, import_lucid65.fromText)("IndigoStableswap")),
10845
+ (0, import_lucid66.fromHex)((0, import_lucid66.fromText)("IndigoStableswap")),
10281
10846
  {
10282
- txHash: (0, import_lucid65.fromHex)(outRef.txHash),
10847
+ txHash: (0, import_lucid66.fromHex)(outRef.txHash),
10283
10848
  outputIndex: BigInt(outRef.outputIndex)
10284
10849
  }
10285
10850
  ]);
@@ -10288,28 +10853,28 @@ function createDestinationDatum(datum, outRef) {
10288
10853
  }
10289
10854
 
10290
10855
  // src/contracts/stableswap/transactions.ts
10291
- var import_lucid66 = require("@lucid-evolution/lucid");
10292
- var import_cardano_offchain_common29 = require("@3rd-eye-labs/cardano-offchain-common");
10293
- var import_fp_ts21 = require("fp-ts");
10856
+ var import_lucid67 = require("@lucid-evolution/lucid");
10857
+ var import_cardano_offchain_common30 = require("@3rd-eye-labs/cardano-offchain-common");
10858
+ var import_fp_ts22 = require("fp-ts");
10294
10859
  var import_Array3 = require("fp-ts/lib/Array");
10295
10860
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
10296
10861
  const myAddress = await lucid.wallet().address();
10297
- const pkh = (0, import_lucid66.paymentCredentialOf)(myAddress);
10862
+ const pkh = (0, import_lucid67.paymentCredentialOf)(myAddress);
10298
10863
  const datum = {
10299
- iasset: (0, import_lucid66.fromHex)((0, import_lucid66.fromText)(iasset)),
10864
+ iasset: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset)),
10300
10865
  collateralAsset,
10301
- owner: (0, import_lucid66.fromHex)(pkh.hash),
10302
- destination: (0, import_cardano_offchain_common29.addressFromBech32)(destinationAddress ?? myAddress),
10866
+ owner: (0, import_lucid67.fromHex)(pkh.hash),
10867
+ destination: (0, import_cardano_offchain_common30.addressFromBech32)(destinationAddress ?? myAddress),
10303
10868
  destinationInlineDatum: destinationInlineDatum ?? null,
10304
10869
  maxExecutionFee,
10305
10870
  maxFeeRatio: maxFeeRatio ?? (minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio)
10306
10871
  };
10307
- const assetsToSwap = minting ? (0, import_cardano_offchain_common29.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common29.mkAssetsOf)(
10872
+ const assetsToSwap = minting ? (0, import_cardano_offchain_common30.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common30.mkAssetsOf)(
10308
10873
  {
10309
- currencySymbol: (0, import_lucid66.fromHex)(
10874
+ currencySymbol: (0, import_lucid67.fromHex)(
10310
10875
  params.stableswapParams.iassetSymbol.unCurrencySymbol
10311
10876
  ),
10312
- tokenName: (0, import_lucid66.fromHex)((0, import_lucid66.fromText)(iasset))
10877
+ tokenName: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset))
10313
10878
  },
10314
10879
  amount
10315
10880
  );
@@ -10327,8 +10892,8 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
10327
10892
  );
10328
10893
  const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
10329
10894
  return lucid.newTx().pay.ToContract(
10330
- (0, import_lucid66.credentialToAddress)(lucid.config().network, {
10331
- hash: (0, import_lucid66.validatorToScriptHash)(
10895
+ (0, import_lucid67.credentialToAddress)(lucid.config().network, {
10896
+ hash: (0, import_lucid67.validatorToScriptHash)(
10332
10897
  mkStableswapValidatorFromSP(params.stableswapParams)
10333
10898
  ),
10334
10899
  type: "Script"
@@ -10337,16 +10902,16 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
10337
10902
  kind: "inline",
10338
10903
  value: serialiseStableswapOrderDatum(datum)
10339
10904
  },
10340
- (0, import_lucid66.addAssets)(
10905
+ (0, import_lucid67.addAssets)(
10341
10906
  assetsToSwap,
10342
- (0, import_cardano_offchain_common29.mkLovelacesOf)(
10907
+ (0, import_cardano_offchain_common30.mkLovelacesOf)(
10343
10908
  roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
10344
10909
  )
10345
10910
  )
10346
10911
  );
10347
10912
  }
10348
10913
  async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
10349
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common29.matchSingle)(
10914
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10350
10915
  await lucid.utxosByOutRef([
10351
10916
  fromSystemParamsScriptRef(
10352
10917
  sysParams.scriptReferences.stableswapValidatorRef
@@ -10354,20 +10919,20 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
10354
10919
  ]),
10355
10920
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
10356
10921
  );
10357
- const stableswapOrderUtxo = (0, import_cardano_offchain_common29.matchSingle)(
10922
+ const stableswapOrderUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10358
10923
  await lucid.utxosByOutRef([stableswapOrderOref]),
10359
10924
  (_) => new Error("Expected a single Stableswap Order UTXO.")
10360
10925
  );
10361
10926
  const stableswapOrderDatum = parseStableswapOrderDatumOrThrow(
10362
- (0, import_cardano_offchain_common29.getInlineDatumOrThrow)(stableswapOrderUtxo)
10927
+ (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapOrderUtxo)
10363
10928
  );
10364
10929
  return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
10365
10930
  [stableswapOrderUtxo],
10366
10931
  serialiseStableswapOrderRedeemer("CancelStableswapOrder")
10367
- ).addSignerKey((0, import_lucid66.toHex)(stableswapOrderDatum.owner));
10932
+ ).addSignerKey((0, import_lucid67.toHex)(stableswapOrderDatum.owner));
10368
10933
  }
10369
10934
  async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
10370
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common29.matchSingle)(
10935
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10371
10936
  await lucid.utxosByOutRef([
10372
10937
  fromSystemParamsScriptRef(
10373
10938
  sysParams.scriptReferences.stableswapValidatorRef
@@ -10375,13 +10940,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10375
10940
  ]),
10376
10941
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
10377
10942
  );
10378
- const cdpScriptRefUtxo = (0, import_cardano_offchain_common29.matchSingle)(
10943
+ const cdpScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10379
10944
  await lucid.utxosByOutRef([
10380
10945
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
10381
10946
  ]),
10382
10947
  (_) => new Error("Expected a single CDP Ref Script UTXO")
10383
10948
  );
10384
- const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common29.matchSingle)(
10949
+ const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10385
10950
  await lucid.utxosByOutRef([
10386
10951
  fromSystemParamsScriptRef(
10387
10952
  sysParams.scriptReferences.iAssetTokenPolicyRef
@@ -10393,7 +10958,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10393
10958
  throw new Error("At least one order must be provided.");
10394
10959
  }
10395
10960
  const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
10396
- const sortedStableswapOrderUtxos = (0, import_lucid66.sortUTxOs)(
10961
+ const sortedStableswapOrderUtxos = (0, import_lucid67.sortUTxOs)(
10397
10962
  stableswapOrderUtxos,
10398
10963
  "Canonical"
10399
10964
  );
@@ -10402,32 +10967,32 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10402
10967
  }
10403
10968
  const mainOrderUtxo = sortedStableswapOrderUtxos[0];
10404
10969
  const mainOrderDatum = parseStableswapOrderDatumOrThrow(
10405
- (0, import_cardano_offchain_common29.getInlineDatumOrThrow)(mainOrderUtxo)
10970
+ (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(mainOrderUtxo)
10406
10971
  );
10407
10972
  const iassetAc = {
10408
- currencySymbol: (0, import_lucid66.fromHex)(
10973
+ currencySymbol: (0, import_lucid67.fromHex)(
10409
10974
  sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
10410
10975
  ),
10411
10976
  tokenName: mainOrderDatum.iasset
10412
10977
  };
10413
10978
  const collateralAc = mainOrderDatum.collateralAsset;
10414
- const stableswapPoolUtxo = (0, import_cardano_offchain_common29.matchSingle)(
10979
+ const stableswapPoolUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10415
10980
  await lucid.utxosByOutRef([stableswapPoolOref]),
10416
10981
  (_) => new Error("Expected a single cdp UTXO")
10417
10982
  );
10418
10983
  const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
10419
- (0, import_cardano_offchain_common29.getInlineDatumOrThrow)(stableswapPoolUtxo)
10984
+ (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapPoolUtxo)
10420
10985
  );
10421
10986
  const ordersInfo = sortedStableswapOrderUtxos.map(
10422
10987
  (orderUtxo) => {
10423
10988
  const orderDatum = parseStableswapOrderDatumOrThrow(
10424
- (0, import_cardano_offchain_common29.getInlineDatumOrThrow)(orderUtxo)
10989
+ (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(orderUtxo)
10425
10990
  );
10426
- if ((0, import_lucid66.toHex)(orderDatum.iasset) != (0, import_lucid66.toHex)(mainOrderDatum.iasset) || (0, import_lucid66.toHex)(orderDatum.collateralAsset.currencySymbol) != (0, import_lucid66.toHex)(mainOrderDatum.collateralAsset.currencySymbol) || (0, import_lucid66.toHex)(orderDatum.collateralAsset.tokenName) != (0, import_lucid66.toHex)(mainOrderDatum.collateralAsset.tokenName)) {
10991
+ if ((0, import_lucid67.toHex)(orderDatum.iasset) != (0, import_lucid67.toHex)(mainOrderDatum.iasset) || (0, import_lucid67.toHex)(orderDatum.collateralAsset.currencySymbol) != (0, import_lucid67.toHex)(mainOrderDatum.collateralAsset.currencySymbol) || (0, import_lucid67.toHex)(orderDatum.collateralAsset.tokenName) != (0, import_lucid67.toHex)(mainOrderDatum.collateralAsset.tokenName)) {
10427
10992
  throw new Error("Wrong batch of orders");
10428
10993
  }
10429
- const suppliedIasset = (0, import_cardano_offchain_common29.assetClassValueOf)(orderUtxo.assets, iassetAc);
10430
- const suppliedCollateralAsset = (0, import_cardano_offchain_common29.assetClassValueOf)(
10994
+ const suppliedIasset = (0, import_cardano_offchain_common30.assetClassValueOf)(orderUtxo.assets, iassetAc);
10995
+ const suppliedCollateralAsset = (0, import_cardano_offchain_common30.assetClassValueOf)(
10431
10996
  orderUtxo.assets,
10432
10997
  collateralAc
10433
10998
  );
@@ -10551,9 +11116,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10551
11116
  }
10552
11117
  }
10553
11118
  );
10554
- const totalSwapInfo = import_fp_ts21.function.pipe(
11119
+ const totalSwapInfo = import_fp_ts22.function.pipe(
10555
11120
  ordersInfo,
10556
- import_fp_ts21.array.reduce(
11121
+ import_fp_ts22.array.reduce(
10557
11122
  {
10558
11123
  suppliedCollateralAsset: 0n,
10559
11124
  suppliedIasset: 0n,
@@ -10595,20 +11160,20 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10595
11160
  kind: "inline",
10596
11161
  value: serialiseStableswapPoolDatum(stableswapPoolDatum)
10597
11162
  },
10598
- collateralAmtChangePool != 0n ? (0, import_lucid66.addAssets)(
11163
+ collateralAmtChangePool != 0n ? (0, import_lucid67.addAssets)(
10599
11164
  stableswapPoolUtxo.assets,
10600
- (0, import_cardano_offchain_common29.mkAssetsOf)(collateralAc, collateralAmtChangePool)
11165
+ (0, import_cardano_offchain_common30.mkAssetsOf)(collateralAc, collateralAmtChangePool)
10601
11166
  ) : stableswapPoolUtxo.assets
10602
11167
  ).setMinFee(2055720n);
10603
11168
  if (amountToMint !== 0n) {
10604
- tx.mintAssets((0, import_cardano_offchain_common29.mkAssetsOf)(iassetAc, amountToMint), import_lucid66.Data.void());
11169
+ tx.mintAssets((0, import_cardano_offchain_common30.mkAssetsOf)(iassetAc, amountToMint), import_lucid67.Data.void());
10605
11170
  }
10606
- import_fp_ts21.function.pipe(
11171
+ import_fp_ts22.function.pipe(
10607
11172
  ordersInfo,
10608
- import_fp_ts21.array.reduce(tx, (acc, orderInfo) => {
11173
+ import_fp_ts22.array.reduce(tx, (acc, orderInfo) => {
10609
11174
  return acc.collectFrom(
10610
11175
  [orderInfo.utxo],
10611
- (0, import_cardano_offchain_common29.isSameOutRef)(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
11176
+ (0, import_cardano_offchain_common30.isSameOutRef)(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
10612
11177
  kind: "selected",
10613
11178
  makeRedeemer: (inputIndices) => {
10614
11179
  return serialiseStableswapOrderRedeemer({
@@ -10621,7 +11186,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10621
11186
  inputs: [orderInfo.utxo, mainOrderUtxo]
10622
11187
  }
10623
11188
  ).pay.ToAddressWithData(
10624
- (0, import_cardano_offchain_common29.addressToBech32)(orderInfo.datum.destination, lucid.config().network),
11189
+ (0, import_cardano_offchain_common30.addressToBech32)(orderInfo.datum.destination, lucid.config().network),
10625
11190
  {
10626
11191
  kind: "inline",
10627
11192
  value: createDestinationDatum(
@@ -10629,13 +11194,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10629
11194
  orderInfo.utxo
10630
11195
  )
10631
11196
  },
10632
- (0, import_lucid66.addAssets)(
11197
+ (0, import_lucid67.addAssets)(
10633
11198
  // Currently, we always take the max execution fee from the order utxo.
10634
11199
  // This can be improved so that we take the actual execution fee.
10635
- (0, import_cardano_offchain_common29.mkLovelacesOf)(
10636
- (0, import_cardano_offchain_common29.lovelacesAmt)(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
11200
+ (0, import_cardano_offchain_common30.mkLovelacesOf)(
11201
+ (0, import_cardano_offchain_common30.lovelacesAmt)(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
10637
11202
  ),
10638
- orderInfo.swapInfo.owedIasset > 0 ? (0, import_cardano_offchain_common29.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common29.mkAssetsOf)(
11203
+ orderInfo.swapInfo.owedIasset > 0 ? (0, import_cardano_offchain_common30.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common30.mkAssetsOf)(
10639
11204
  collateralAc,
10640
11205
  orderInfo.swapInfo.owedCollateralAsset
10641
11206
  )
@@ -10658,7 +11223,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
10658
11223
  return tx;
10659
11224
  }
10660
11225
  async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
10661
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common29.matchSingle)(
11226
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10662
11227
  await lucid.utxosByOutRef([
10663
11228
  fromSystemParamsScriptRef(
10664
11229
  sysParams.scriptReferences.stableswapValidatorRef
@@ -10666,22 +11231,22 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10666
11231
  ]),
10667
11232
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
10668
11233
  );
10669
- const cdpScriptRefUtxo = (0, import_cardano_offchain_common29.matchSingle)(
11234
+ const cdpScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10670
11235
  await lucid.utxosByOutRef([
10671
11236
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
10672
11237
  ]),
10673
11238
  (_) => new Error("Expected a single CDP Ref Script UTXO")
10674
11239
  );
10675
- const stableswapPool = (0, import_cardano_offchain_common29.matchSingle)(
11240
+ const stableswapPool = (0, import_cardano_offchain_common30.matchSingle)(
10676
11241
  await lucid.utxosByOutRef([stableswapPoolOutRef]),
10677
11242
  (_) => new Error("Expected a single Stableswap Pool UTXO.")
10678
11243
  );
10679
- const stableswapFeeUtxo = (0, import_cardano_offchain_common29.matchSingle)(
11244
+ const stableswapFeeUtxo = (0, import_cardano_offchain_common30.matchSingle)(
10680
11245
  await lucid.utxosByOutRef([stableswapFeeOutRef]),
10681
11246
  (_) => new Error("Expected a single Stableswap Fee UTXO.")
10682
11247
  );
10683
11248
  const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
10684
- (0, import_cardano_offchain_common29.getInlineDatumOrThrow)(stableswapPool)
11249
+ (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapPool)
10685
11250
  );
10686
11251
  const newStableswapPoolDatum = {
10687
11252
  ...stableswapPoolDatum,
@@ -10709,7 +11274,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10709
11274
  value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
10710
11275
  },
10711
11276
  stableswapPool.assets
10712
- ).addSignerKey((0, import_lucid66.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
11277
+ ).addSignerKey((0, import_lucid67.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
10713
11278
  }
10714
11279
  // Annotate the CommonJS export names for ESM import in node:
10715
11280
  0 && (module.exports = {
@@ -10736,6 +11301,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10736
11301
  InterestOracleDatumSchema,
10737
11302
  InterestOracleParamsSchema,
10738
11303
  MAX_E2S2S_ENTRIES_COUNT,
11304
+ MAX_REDEMPTIONS_WITH_CDP_OPEN,
10739
11305
  MIN_ROB_COLLATERAL_AMT,
10740
11306
  ONE_DAY,
10741
11307
  ONE_HOUR,
@@ -10770,6 +11336,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10770
11336
  adjustStakingPosition,
10771
11337
  alwaysFailValidator,
10772
11338
  annulRequest,
11339
+ approximateLeverageRedemptions,
10773
11340
  attachOracle,
10774
11341
  balance,
10775
11342
  batchCollectInterest,
@@ -10780,8 +11347,11 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10780
11347
  burnCdp,
10781
11348
  calculateAccruedInterest,
10782
11349
  calculateAdaReward,
11350
+ calculateCollateralRatioFromLeverage,
10783
11351
  calculateIAssetRedemptionAmt,
11352
+ calculateLeverageFromCollateralRatio,
10784
11353
  calculateMinCollateralCappedIAssetRedemptionAmt,
11354
+ calculateTotalCollateralForRedemption,
10785
11355
  calculateUnitaryInterest,
10786
11356
  calculateUnitaryInterestSinceOracleLastUpdated,
10787
11357
  cancelRob,
@@ -10847,9 +11417,9 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10847
11417
  getAssetClassComparisonStr,
10848
11418
  getInlineDatumOrThrow,
10849
11419
  getPythFeedConfig,
10850
- getRandomElement,
10851
11420
  getUpdatedAccountDeposit,
10852
11421
  handleOracleForCollateralAsset,
11422
+ iassetValueOfCollateral,
10853
11423
  init,
10854
11424
  initCDPCreator,
10855
11425
  initCollector,
@@ -10863,8 +11433,10 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10863
11433
  initTreasury,
10864
11434
  initializeAsset,
10865
11435
  insertSorted,
11436
+ isBuyOrderFullyRedeemed,
10866
11437
  isFullyRedeemed,
10867
11438
  isSameEpochToScaleKey,
11439
+ leverageCdpWithRob,
10868
11440
  liquidateCdp,
10869
11441
  liquidationHelper,
10870
11442
  loadSystemParamsFromFile,
@@ -10949,6 +11521,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10949
11521
  parseStakingPositionOrThrow,
10950
11522
  partitionEpochToScaleToSums,
10951
11523
  processSpRequest,
11524
+ randomRobsSubsetSatisfyingTargetCollateral,
10952
11525
  rationalAdd,
10953
11526
  rationalCeil,
10954
11527
  rationalDiv,
@@ -10967,7 +11540,10 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
10967
11540
  requestSpAccountClosure,
10968
11541
  requestSpAccountCreation,
10969
11542
  rewardSnapshotPrecision,
10970
- robAmountToSpend,
11543
+ robAmtToSpend,
11544
+ robBuyOrderSummary,
11545
+ robCollateralAmtToSpend,
11546
+ robIAssetAmtToSpend,
10971
11547
  runCreateScriptRefTx,
10972
11548
  runOneShotMintTx,
10973
11549
  scriptRef,
@@ -11012,6 +11588,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11012
11588
  startPriceOracleTx,
11013
11589
  submitTx,
11014
11590
  sum,
11591
+ summarizeActualLeverageRedemptions,
11015
11592
  toAssetClassFromLucid,
11016
11593
  toDataDerivedPythPrice,
11017
11594
  toSystemParamsAsset,