@indigo-labs/indigo-sdk 0.5.16 → 0.6.1

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
@@ -211,7 +211,6 @@ __export(index_exports, {
211
211
  initGovernance: () => initGovernance,
212
212
  initInterestCollector: () => initInterestCollector,
213
213
  initPythConfig: () => initPythConfig,
214
- initScriptRef: () => initScriptRef,
215
214
  initSpState: () => initSpState,
216
215
  initStakingManager: () => initStakingManager,
217
216
  initSumVal: () => initSumVal,
@@ -348,6 +347,7 @@ __export(index_exports, {
348
347
  robCollateralAmtToSpend: () => robCollateralAmtToSpend,
349
348
  robIAssetAmtToSpend: () => robIAssetAmtToSpend,
350
349
  robSellOrderFilledAssets: () => robSellOrderFilledAssets,
350
+ runAndAwaitTxBuilder: () => runAndAwaitTxBuilder,
351
351
  runCreateScriptRefTx: () => runCreateScriptRefTx,
352
352
  runOneShotMintTx: () => runOneShotMintTx,
353
353
  scriptRef: () => scriptRef,
@@ -393,13 +393,13 @@ __export(index_exports, {
393
393
  spZeroNegatives: () => spZeroNegatives,
394
394
  startInterestOracle: () => startInterestOracle,
395
395
  startPriceOracleTx: () => startPriceOracleTx,
396
- submitTx: () => submitTx,
397
396
  sum: () => sum,
398
397
  summariseOrder: () => summariseOrder,
399
398
  summarizeActualLeverageRedemptions: () => summarizeActualLeverageRedemptions,
400
399
  toAssetClassFromLucid: () => toAssetClassFromLucid,
401
400
  toDataDerivedPythPrice: () => toDataDerivedPythPrice,
402
401
  toSystemParamsAsset: () => toSystemParamsAsset,
402
+ toSystemParamsInput: () => toSystemParamsInput,
403
403
  treasuryCollect: () => treasuryCollect,
404
404
  treasuryFeeTx: () => treasuryFeeTx,
405
405
  treasuryMerge: () => treasuryMerge,
@@ -682,6 +682,12 @@ function getPythFeedConfig(cfg, iasset, collateralAsset) {
682
682
  throw new Error("No Pyth config known for such assets combination");
683
683
  return res;
684
684
  }
685
+ function toSystemParamsInput(outRef) {
686
+ return {
687
+ transactionId: outRef.txHash,
688
+ index: outRef.outputIndex
689
+ };
690
+ }
685
691
  function toSystemParamsAsset(asset) {
686
692
  return [
687
693
  { unCurrencySymbol: (0, import_lucid.toHex)(asset.currencySymbol) },
@@ -758,9 +764,26 @@ async function scriptRef(ref, lucid) {
758
764
  if (utxos.length === 0) throw Error("Unable to locate script ref.");
759
765
  return utxos[0];
760
766
  }
761
- async function submitTx(lucid, tx) {
762
- const txHash = await tx.complete().then((t) => t.sign.withWallet().complete()).then((t) => t.submit());
767
+ var defaultSubmissionConfig = {
768
+ extraSigners: [],
769
+ useLocalOverride: true
770
+ };
771
+ async function runAndAwaitTxBuilder(lucid, transaction, submissionConfig) {
772
+ const config = {
773
+ ...defaultSubmissionConfig,
774
+ ...submissionConfig
775
+ };
776
+ const [newWalletUTxOs, _, bTx] = await transaction.chain();
777
+ const signatures = [await bTx.partialSign.withWallet()];
778
+ for (const signer of config.extraSigners) {
779
+ lucid.selectWallet.fromSeed(signer);
780
+ signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
781
+ }
782
+ const signedTx = bTx.assemble(signatures);
783
+ const txHash = await signedTx.complete().then((tx) => tx.submit());
763
784
  await lucid.awaitTx(txHash);
785
+ lucid.overrideUTxOs(newWalletUTxOs);
786
+ return txHash;
764
787
  }
765
788
  function balance(utxos) {
766
789
  return utxos.reduce((acc, utxo) => (0, import_lucid2.addAssets)(acc, utxo.assets), {});
@@ -837,8 +860,9 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
837
860
 
838
861
  // src/contracts/price-oracle/helpers.ts
839
862
  function oracleExpirationAwareValidity(lucid, biasTime, oracleExpiration) {
840
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
841
- const defaultValidateTo = validateFrom + biasTime;
863
+ const currentTime = lucid.slotToUnixTime(lucid.currentSlot());
864
+ const validateFrom = currentTime - Math.floor(biasTime / 2);
865
+ const defaultValidateTo = currentTime + Math.floor(biasTime / 2);
842
866
  const cappedValidateTo = lucid.slotToUnixTime(
843
867
  lucid.unixTimeToSlot(oracleExpiration) - 1
844
868
  );
@@ -893,7 +917,15 @@ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracle
893
917
  collateralAmt
894
918
  };
895
919
  }
896
- function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
920
+ var defaultLoanAdjustments = {
921
+ collateralAdjustment: 0n,
922
+ debtAdjustment: 0n
923
+ };
924
+ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum, loanAdjustments) {
925
+ const adjustments = {
926
+ ...defaultLoanAdjustments,
927
+ ...loanAdjustments
928
+ };
897
929
  const cdpState = computeEffectiveCdpState(
898
930
  now,
899
931
  cdpUtxoAssets,
@@ -901,8 +933,11 @@ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpConten
901
933
  interestOracleDatum
902
934
  );
903
935
  const ratio = rationalDiv(
904
- rationalFromInt(cdpState.collateralAmt),
905
- rationalMul(rationalFromInt(cdpState.mintedAmt), iassetPrice)
936
+ rationalFromInt(cdpState.collateralAmt + adjustments.collateralAdjustment),
937
+ rationalMul(
938
+ rationalFromInt(cdpState.mintedAmt + adjustments.debtAdjustment),
939
+ iassetPrice
940
+ )
906
941
  );
907
942
  return Number(ratio.numerator) * 100 / Number(ratio.denominator);
908
943
  }
@@ -2566,8 +2601,12 @@ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef
2566
2601
  referenceInputs,
2567
2602
  false
2568
2603
  );
2569
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
2570
- const validateTo = validateFrom + Number(params.cdpParams.biasTime);
2604
+ const validateFrom = Number(
2605
+ currentTime - BigInt(params.cdpParams.biasTime) / 2n
2606
+ );
2607
+ const validateTo = Number(
2608
+ currentTime + BigInt(params.cdpParams.biasTime) / 2n
2609
+ );
2571
2610
  const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(referenceInputs).collectFrom([interestCollectorUtxo], {
2572
2611
  kind: "selected",
2573
2612
  makeRedeemer: (inputIndices) => {
@@ -4073,6 +4112,8 @@ function derivePythPrice(derivedPythPrice, messageHex) {
4073
4112
 
4074
4113
  // src/contracts/iasset/helpers.ts
4075
4114
  var Core = __toESM(require("@evolution-sdk/evolution"));
4115
+ var MAX_PYTH_FEED_DELAY = 280 * 1e3;
4116
+ var PYTH_FEED_LEDGER_TIME_BUFFER = 20 * 1e3;
4076
4117
  var MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
4077
4118
  function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, lucid, tx) {
4078
4119
  return (0, import_ts_pattern12.match)(priceInfo).returnType().with({ Delisted: import_ts_pattern12.P.any }, () => {
@@ -4153,9 +4194,8 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
4153
4194
  auxiliaryData: Core.Data.fromCBORHex(import_lucid11.Data.void())
4154
4195
  })
4155
4196
  );
4156
- const pythMaxDelay = 280 * 1e3;
4157
- const validFrom = Number(pythTimestamp);
4158
- const validTo = Number(pythTimestamp + pythMaxDelay);
4197
+ const validFrom = Number(pythTimestamp - PYTH_FEED_LEDGER_TIME_BUFFER);
4198
+ const validTo = Number(pythTimestamp + MAX_PYTH_FEED_DELAY);
4159
4199
  return {
4160
4200
  interval: {
4161
4201
  validFrom,
@@ -4639,8 +4679,12 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
4639
4679
  const interestOracleDatum = parseInterestOracleDatum(
4640
4680
  getInlineDatumOrThrow(interestOracleUtxo)
4641
4681
  );
4642
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4643
- const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4682
+ const validateFrom = Number(
4683
+ currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
4684
+ );
4685
+ const validateTo = Number(
4686
+ currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
4687
+ );
4644
4688
  const tx = lucid.newTx().readFrom([
4645
4689
  cdpRefScriptUtxo,
4646
4690
  iAssetTokenPolicyRefScriptUtxo,
@@ -4835,8 +4879,12 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
4835
4879
  referenceInputs.push(priceOracleUtxo);
4836
4880
  tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
4837
4881
  } else {
4838
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4839
- const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4882
+ const validateFrom = Number(
4883
+ currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
4884
+ );
4885
+ const validateTo = Number(
4886
+ currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
4887
+ );
4840
4888
  tx.validFrom(validateFrom).validTo(validateTo);
4841
4889
  }
4842
4890
  const partialRedemptionFee = import_fp_ts13.function.pipe(
@@ -7595,10 +7643,9 @@ async function oneShotMintTx(lucid, params) {
7595
7643
  policyId
7596
7644
  ];
7597
7645
  }
7598
- async function runOneShotMintTx(lucid, params) {
7646
+ async function runOneShotMintTx(lucid, params, submissionConfig) {
7599
7647
  const [tx, policyId] = await oneShotMintTx(lucid, params);
7600
- const txHash = await tx.complete().then((tx2) => tx2.sign.withWallet().complete()).then((tx2) => tx2.submit());
7601
- await lucid.awaitTx(txHash);
7648
+ await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
7602
7649
  return policyId;
7603
7650
  }
7604
7651
 
@@ -8344,9 +8391,8 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
8344
8391
  )
8345
8392
  ).addSignerKey((0, import_lucid47.toHex)(oldAccountDatum.owner));
8346
8393
  }
8347
- async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee, currentSlot) {
8348
- const slot = currentSlot !== void 0 ? currentSlot : lucid.currentSlot();
8349
- const currentTime = BigInt(lucid.slotToUnixTime(slot));
8394
+ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee) {
8395
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
8350
8396
  const stabilityPoolScriptRef = (0, import_cardano_offchain_common24.matchSingle)(
8351
8397
  await lucid.utxosByOutRef([
8352
8398
  fromSystemParamsScriptRef(
@@ -8362,8 +8408,13 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8362
8408
  getInlineDatumOrThrow(stabilityPoolUtxo)
8363
8409
  );
8364
8410
  const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
8365
- const validFrom = lucid.slotToUnixTime(slot - 1);
8366
- const tx = lucid.newTx().validFrom(validFrom).validTo(validFrom + sysParams.stabilityPoolParams.accountProcessingBiasMs).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8411
+ const validateFrom = Number(
8412
+ currentTime - BigInt(sysParams.stabilityPoolParams.accountProcessingBiasMs) / 2n
8413
+ );
8414
+ const validateTo = Number(
8415
+ currentTime + BigInt(sysParams.stabilityPoolParams.accountProcessingBiasMs) / 2n
8416
+ );
8417
+ const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8367
8418
  kind: "selected",
8368
8419
  inputs: [stabilityPoolUtxo, accountUtxo],
8369
8420
  makeRedeemer: (indices) => serialiseStabilityPoolRedeemer({
@@ -8734,7 +8785,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8734
8785
  }).exhaustive();
8735
8786
  return tx;
8736
8787
  }
8737
- async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot) {
8788
+ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid) {
8738
8789
  const draftTx = processSpRequestAuxiliary(
8739
8790
  stabilityPoolUtxo,
8740
8791
  accountUtxo,
@@ -8743,8 +8794,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8743
8794
  sysParams,
8744
8795
  lucid,
8745
8796
  // Placeholder transation fee
8746
- 1n,
8747
- currentSlot
8797
+ 1n
8748
8798
  );
8749
8799
  const fee = (await (await draftTx).complete()).toTransaction().body().fee();
8750
8800
  return processSpRequestAuxiliary(
@@ -8754,8 +8804,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8754
8804
  allE2s2sSnapshotOrefs,
8755
8805
  sysParams,
8756
8806
  lucid,
8757
- fee,
8758
- currentSlot
8807
+ fee
8759
8808
  );
8760
8809
  }
8761
8810
  async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
@@ -10094,10 +10143,13 @@ var alwaysFailValidator = {
10094
10143
  };
10095
10144
 
10096
10145
  // src/utils/helper-txs.ts
10097
- async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
10098
- const scriptAddr = (0, import_lucid55.validatorToAddress)(network, alwaysFailValidator);
10099
- const txHash = await lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator).complete().then((tx) => tx.sign.withWallet().complete()).then((tx) => tx.submit());
10100
- await lucid.awaitTx(txHash);
10146
+ async function runCreateScriptRefTx(lucid, scriptRefValidator, submissionConfig) {
10147
+ const scriptAddr = (0, import_lucid55.validatorToAddress)(
10148
+ lucid.config().network,
10149
+ alwaysFailValidator
10150
+ );
10151
+ const tx = lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator);
10152
+ const txHash = await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
10101
10153
  return { txHash, outputIndex: 0 };
10102
10154
  }
10103
10155
 
@@ -10157,24 +10209,6 @@ var mkIAssetValidatorFromSP = (params) => {
10157
10209
 
10158
10210
  // src/contracts/initialize/helpers.ts
10159
10211
  var import_ts_pattern21 = require("ts-pattern");
10160
-
10161
- // tests/test-helpers.ts
10162
- var import_fp_ts26 = require("fp-ts");
10163
- async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
10164
- const bTx = await transaction.complete();
10165
- const signatures = [await bTx.partialSign.withWallet()];
10166
- for (const signer of extraSigners) {
10167
- lucid.selectWallet.fromSeed(signer);
10168
- signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
10169
- }
10170
- const signedTx = bTx.assemble(signatures);
10171
- const txHash = await signedTx.complete().then((tx) => tx.submit());
10172
- await lucid.awaitTx(txHash);
10173
- return txHash;
10174
- }
10175
-
10176
- // src/contracts/initialize/helpers.ts
10177
- var alwaysFailValidatorHash = "ea84d625650d066e1645e3e81d9c70a73f9ed837bd96dc49850ae744";
10178
10212
  var DEFAULT_INIT_OPTIONS = {
10179
10213
  numCdpCreators: 2n,
10180
10214
  numCollectors: 2n,
@@ -10209,18 +10243,27 @@ var INIT_TOKEN_NAMES = {
10209
10243
  snapshotEpochToScaleToSum: "SNAPSHOT_EPOCH_TO_SCALE_TO_SUM",
10210
10244
  account: "SP_ACCOUNT"
10211
10245
  };
10212
- async function mintOneTimeToken(lucid, tokenName, amount) {
10246
+ async function mintOneTimeToken(lucid, tokenName, amount, submissionConfig) {
10213
10247
  const utxos = await lucid.wallet().getUtxos();
10214
- return await runOneShotMintTx(lucid, {
10215
- referenceOutRef: {
10216
- txHash: utxos[0].txHash,
10217
- outputIdx: BigInt(utxos[0].outputIndex)
10248
+ return await runOneShotMintTx(
10249
+ lucid,
10250
+ {
10251
+ referenceOutRef: {
10252
+ txHash: utxos[0].txHash,
10253
+ outputIdx: BigInt(utxos[0].outputIndex)
10254
+ },
10255
+ mintAmounts: [{ tokenName, amount }]
10218
10256
  },
10219
- mintAmounts: [{ tokenName, amount }]
10220
- });
10257
+ submissionConfig
10258
+ );
10221
10259
  }
10222
- async function mintOneTimeAsset(lucid, tokenName, amount) {
10223
- const policyId = await mintOneTimeToken(lucid, (0, import_lucid59.fromText)(tokenName), amount);
10260
+ async function mintOneTimeAsset(lucid, tokenName, amount, submissionConfig) {
10261
+ const policyId = await mintOneTimeToken(
10262
+ lucid,
10263
+ (0, import_lucid59.fromText)(tokenName),
10264
+ amount,
10265
+ submissionConfig
10266
+ );
10224
10267
  return {
10225
10268
  currencySymbol: (0, import_lucid59.fromHex)(policyId),
10226
10269
  tokenName: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(tokenName))
@@ -10233,20 +10276,6 @@ function deriveAuthToken(parent, tokenName) {
10233
10276
  tokenName: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(tokenName))
10234
10277
  };
10235
10278
  }
10236
- async function initScriptRef(lucid, validator) {
10237
- const tx = lucid.newTx().pay.ToContract(
10238
- (0, import_lucid59.credentialToAddress)(lucid.config().network, {
10239
- hash: alwaysFailValidatorHash,
10240
- type: "Script"
10241
- }),
10242
- void 0,
10243
- void 0,
10244
- validator
10245
- );
10246
- const txHash = await tx.complete().then((t) => t.sign.withWallet().complete()).then((t) => t.submit());
10247
- await lucid.awaitTx(txHash);
10248
- return { transactionId: txHash, index: 0 };
10249
- }
10250
10279
  async function initCollector(lucid, collectorParams, numCollectors) {
10251
10280
  const tx = lucid.newTx();
10252
10281
  for (let i = 0; i < Number(numCollectors); i++) {
@@ -10261,7 +10290,7 @@ async function initCollector(lucid, collectorParams, numCollectors) {
10261
10290
  }
10262
10291
  );
10263
10292
  }
10264
- await submitTx(lucid, tx);
10293
+ await runAndAwaitTxBuilder(lucid, tx);
10265
10294
  }
10266
10295
  async function initInterestCollector(lucid, interestCollectionValHash, multisigUtxoNft, numInterestCollectors, interestCollectorUtxoLovelaces) {
10267
10296
  const [pkh, _] = await addrDetails(lucid);
@@ -10272,7 +10301,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
10272
10301
  }
10273
10302
  }
10274
10303
  };
10275
- await submitTx(
10304
+ await runAndAwaitTxBuilder(
10276
10305
  lucid,
10277
10306
  lucid.newTx().pay.ToContract(
10278
10307
  createScriptAddress(lucid.config().network, interestCollectionValHash),
@@ -10291,7 +10320,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
10291
10320
  (0, import_cardano_offchain_common30.mkLovelacesOf)(interestCollectorUtxoLovelaces)
10292
10321
  );
10293
10322
  }
10294
- await submitTx(lucid, interestCollectionUtxoDeploymentTx);
10323
+ await runAndAwaitTxBuilder(lucid, interestCollectionUtxoDeploymentTx);
10295
10324
  }
10296
10325
  async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
10297
10326
  const tx = lucid.newTx();
@@ -10309,7 +10338,7 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
10309
10338
  }
10310
10339
  );
10311
10340
  }
10312
- await submitTx(lucid, tx);
10341
+ await runAndAwaitTxBuilder(lucid, tx);
10313
10342
  }
10314
10343
  async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasuryIndyAmount, numTreasuryCollectors) {
10315
10344
  const treasuryAddr = createScriptAddress(
@@ -10331,7 +10360,7 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
10331
10360
  value: import_lucid59.Data.void()
10332
10361
  });
10333
10362
  }
10334
- await submitTx(lucid, tx);
10363
+ await runAndAwaitTxBuilder(lucid, tx);
10335
10364
  }
10336
10365
  async function initStakingManager(lucid, stakingParams) {
10337
10366
  const tx = lucid.newTx().pay.ToContract(
@@ -10350,7 +10379,7 @@ async function initStakingManager(lucid, stakingParams) {
10350
10379
  [stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid59.fromText)(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
10351
10380
  }
10352
10381
  );
10353
- await submitTx(lucid, tx);
10382
+ await runAndAwaitTxBuilder(lucid, tx);
10354
10383
  }
10355
10384
  async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig) {
10356
10385
  return (0, import_ts_pattern21.match)(collateralAsset.priceOracle).returnType().with({ tag: "_indigo_oracle_nft" }, async (val) => {
@@ -10402,7 +10431,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10402
10431
  lucid,
10403
10432
  collateralAsset.interestOracle.tokenName
10404
10433
  );
10405
- await submitTx(lucid, startInterestOracleTx);
10434
+ await runAndAwaitTxBuilder(lucid, startInterestOracleTx);
10406
10435
  const priceInfo = await handleOracleForCollateralAsset(
10407
10436
  lucid,
10408
10437
  asset,
@@ -10435,7 +10464,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10435
10464
  },
10436
10465
  (0, import_cardano_offchain_common30.mkAssetsOf)(collateralAssetAuthToken, 1n)
10437
10466
  );
10438
- await submitTx(lucid, collateralAssetTx);
10467
+ await runAndAwaitTxBuilder(lucid, collateralAssetTx);
10439
10468
  collateralAssetInfos.push({
10440
10469
  collateralAsset: collateralAsset.collateralAsset,
10441
10470
  interestOracleNft,
@@ -10457,7 +10486,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10457
10486
  iasset: iassetName,
10458
10487
  stableswapValHash: (0, import_lucid59.fromHex)(stableswapValidatorHash)
10459
10488
  };
10460
- await submitTx(
10489
+ await runAndAwaitTxBuilder(
10461
10490
  lucid,
10462
10491
  lucid.newTx().pay.ToContract(
10463
10492
  createScriptAddress(
@@ -10494,7 +10523,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10494
10523
  },
10495
10524
  (0, import_cardano_offchain_common30.mkAssetsOf)(iassetToken, 1n)
10496
10525
  );
10497
- await submitTx(lucid, assetTx);
10526
+ await runAndAwaitTxBuilder(lucid, assetTx);
10498
10527
  const stabilityPoolDatum = {
10499
10528
  iasset: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(asset.name)),
10500
10529
  state: initSpState,
@@ -10513,7 +10542,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10513
10542
  },
10514
10543
  (0, import_cardano_offchain_common30.mkAssetsOf)(stabilityPoolToken, 1n)
10515
10544
  );
10516
- await submitTx(lucid, spTx);
10545
+ await runAndAwaitTxBuilder(lucid, spTx);
10517
10546
  return {
10518
10547
  iassetTokenNameAscii: asset.name,
10519
10548
  collateralAssets: collateralAssetInfos
@@ -10535,7 +10564,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
10535
10564
  { kind: "inline", value: serialiseGovDatum(datum) },
10536
10565
  (0, import_cardano_offchain_common30.mkAssetsOf)(govToken, 1n)
10537
10566
  );
10538
- await submitTx(lucid, tx);
10567
+ await runAndAwaitTxBuilder(lucid, tx);
10539
10568
  }
10540
10569
  async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
10541
10570
  const script = mkAuthTokenPolicy(asset, (0, import_lucid59.fromText)(tokenName));
@@ -10552,7 +10581,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
10552
10581
  },
10553
10582
  import_lucid59.Data.void()
10554
10583
  );
10555
- await submitTx(lucid, tx);
10584
+ await runAndAwaitTxBuilder(lucid, tx);
10556
10585
  }
10557
10586
 
10558
10587
  // src/contracts/initialize/actions.ts
@@ -10718,23 +10747,30 @@ async function initPyth(lucid) {
10718
10747
  alwaysSucceedValidator
10719
10748
  )
10720
10749
  );
10721
- const alwaysSucceedRewardAddress = (0, import_lucid63.credentialToRewardAddress)(
10722
- lucid.config().network,
10723
- { hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator), type: "Script" }
10724
- );
10725
- const { registered } = await lucid.rewardAccountAt(
10726
- alwaysSucceedRewardAddress
10727
- );
10728
- if (!registered) {
10750
+ try {
10729
10751
  await runAndAwaitTxBuilder(
10730
10752
  lucid,
10731
- lucid.newTx().register.Stake(alwaysSucceedRewardAddress)
10753
+ lucid.newTx().register.Stake(
10754
+ (0, import_lucid63.credentialToRewardAddress)(lucid.config().network, {
10755
+ hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator),
10756
+ type: "Script"
10757
+ })
10758
+ )
10732
10759
  );
10760
+ } catch (error) {
10761
+ const message = error instanceof Error ? error.message : String(error);
10762
+ if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
10763
+ throw error;
10764
+ }
10733
10765
  }
10734
10766
  return pythStateAsset;
10735
10767
  }
10736
10768
 
10737
10769
  // src/contracts/initialize/actions.ts
10770
+ function isAlreadyRegisteredError(error) {
10771
+ const message = error instanceof Error ? error.message : String(error);
10772
+ return message.includes("StakeKeyRegisteredDELEG") || message.includes("Trying to re-register some already known credentials.");
10773
+ }
10738
10774
  var DEFAULT_STAKING_CRED = {
10739
10775
  tag: "StakingHash",
10740
10776
  contents: {
@@ -10751,29 +10787,31 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10751
10787
  fromSysParamsPythFeedParams(val.pythFeedParams)
10752
10788
  );
10753
10789
  const pythFeedValHash = (0, import_lucid64.validatorToScriptHash)(pythFeedValidator);
10754
- const pythFeedValScriptRef = await initScriptRef(
10790
+ const pythFeedValScriptRef = await runCreateScriptRefTx(
10755
10791
  lucid,
10756
10792
  pythFeedValidator
10757
10793
  );
10758
- const pythFeedRewardAddress = (0, import_lucid64.credentialToRewardAddress)(
10759
- lucid.config().network,
10760
- { hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator), type: "Script" }
10761
- );
10762
- const { registered } = await lucid.rewardAccountAt(
10763
- pythFeedRewardAddress
10764
- );
10765
- if (!registered) {
10794
+ try {
10766
10795
  await runAndAwaitTxBuilder(
10767
10796
  lucid,
10768
- lucid.newTx().register.Stake(pythFeedRewardAddress)
10797
+ lucid.newTx().register.Stake(
10798
+ (0, import_lucid64.credentialToRewardAddress)(lucid.config().network, {
10799
+ hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator),
10800
+ type: "Script"
10801
+ })
10802
+ )
10769
10803
  );
10804
+ } catch (error) {
10805
+ if (!isAlreadyRegisteredError(error)) throw error;
10770
10806
  }
10771
10807
  const key = `${asset.name}/${(0, import_lucid64.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid64.toHex)(collateral.collateralAsset.tokenName)}`;
10772
10808
  return {
10773
10809
  [key]: {
10774
10810
  params: val.pythFeedParams,
10775
10811
  pythFeedValHash,
10776
- pythFeedValScriptRef: { input: pythFeedValScriptRef }
10812
+ pythFeedValScriptRef: {
10813
+ input: toSystemParamsInput(pythFeedValScriptRef)
10814
+ }
10777
10815
  }
10778
10816
  };
10779
10817
  }).otherwise(() => Promise.resolve({}));
@@ -10807,6 +10845,19 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10807
10845
  const indyAsset = await mintOneTimeAsset(lucid, tn.indy, totalIndySupply);
10808
10846
  const daoAsset = await mintOneTimeAsset(lucid, tn.dao, 1n);
10809
10847
  const govNftAsset = await mintOneTimeAsset(lucid, tn.govNft, 1n);
10848
+ const cdpCreatorAsset = await mintOneTimeAsset(
10849
+ lucid,
10850
+ tn.cdpCreator,
10851
+ numCdpCreators
10852
+ );
10853
+ const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
10854
+ const stakingManagerAsset = await mintOneTimeAsset(
10855
+ lucid,
10856
+ tn.stakingManager,
10857
+ 1n
10858
+ );
10859
+ const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
10860
+ const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
10810
10861
  const pollToken = deriveAuthToken(govNftAsset, tn.pollManager);
10811
10862
  const upgradeToken = deriveAuthToken(pollToken, tn.upgrade);
10812
10863
  const iassetToken = deriveAuthToken(upgradeToken, tn.iasset);
@@ -10832,18 +10883,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10832
10883
  const versionRegistryValHash = (0, import_lucid64.validatorToScriptHash)(
10833
10884
  versionRegistryValidator
10834
10885
  );
10835
- const cdpCreatorAsset = await mintOneTimeAsset(
10836
- lucid,
10837
- tn.cdpCreator,
10838
- numCdpCreators
10839
- );
10840
- const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
10841
- const stakingManagerAsset = await mintOneTimeAsset(
10842
- lucid,
10843
- tn.stakingManager,
10844
- 1n
10845
- );
10846
- const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
10847
10886
  const collectorParams = {
10848
10887
  stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
10849
10888
  stakingToken: toSystemParamsAsset(stakingToken),
@@ -10909,7 +10948,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10909
10948
  treasuryIndyAmount,
10910
10949
  numTreasuryUtxos
10911
10950
  );
10912
- const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
10913
10951
  const interestCollectionParams = {
10914
10952
  versionRecordNft: toSystemParamsAsset(versionRecordToken),
10915
10953
  multisigUtxoNft: toSystemParamsAsset(multisigUtxoNft),
@@ -10957,12 +10995,13 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10957
10995
  lucid.config().network,
10958
10996
  (0, import_lucid64.scriptHashToCredential)(cdpRedeemValHash)
10959
10997
  );
10960
- const { registered: cdpRedeemRegistered } = await lucid.rewardAccountAt(cdpRedeemRewardAddr);
10961
- if (!cdpRedeemRegistered) {
10998
+ try {
10962
10999
  await runAndAwaitTxBuilder(
10963
11000
  lucid,
10964
11001
  lucid.newTx().register.Stake(cdpRedeemRewardAddr)
10965
11002
  );
11003
+ } catch (error) {
11004
+ if (!isAlreadyRegisteredError(error)) throw error;
10966
11005
  }
10967
11006
  const cdpParams = {
10968
11007
  cdpAuthToken: toSystemParamsAsset(cdpToken),
@@ -11212,97 +11251,155 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
11212
11251
  },
11213
11252
  scriptReferences: {
11214
11253
  interestCollectionValidatorRef: {
11215
- input: await initScriptRef(lucid, interestCollectionValidator)
11254
+ input: toSystemParamsInput(
11255
+ await runCreateScriptRefTx(lucid, interestCollectionValidator)
11256
+ )
11216
11257
  },
11217
11258
  robValidatorRef: {
11218
- input: await initScriptRef(lucid, robValidator)
11259
+ input: toSystemParamsInput(
11260
+ await runCreateScriptRefTx(lucid, robValidator)
11261
+ )
11219
11262
  },
11220
11263
  cdpCreatorValidatorRef: {
11221
- input: await initScriptRef(lucid, cdpCreatorValidator)
11264
+ input: toSystemParamsInput(
11265
+ await runCreateScriptRefTx(lucid, cdpCreatorValidator)
11266
+ )
11222
11267
  },
11223
11268
  cdpValidatorRef: {
11224
- input: await initScriptRef(lucid, cdpValidator)
11269
+ input: toSystemParamsInput(
11270
+ await runCreateScriptRefTx(lucid, cdpValidator)
11271
+ )
11225
11272
  },
11226
11273
  cdpRedeemValidatorRef: {
11227
- input: await initScriptRef(lucid, cdpRedeemValidator)
11274
+ input: toSystemParamsInput(
11275
+ await runCreateScriptRefTx(lucid, cdpRedeemValidator)
11276
+ )
11228
11277
  },
11229
11278
  collectorValidatorRef: {
11230
- input: await initScriptRef(lucid, collectorValidator)
11279
+ input: toSystemParamsInput(
11280
+ await runCreateScriptRefTx(lucid, collectorValidator)
11281
+ )
11231
11282
  },
11232
11283
  executeValidatorRef: {
11233
- input: await initScriptRef(lucid, executeValidator)
11284
+ input: toSystemParamsInput(
11285
+ await runCreateScriptRefTx(lucid, executeValidator)
11286
+ )
11234
11287
  },
11235
11288
  pollShardValidatorRef: {
11236
- input: await initScriptRef(lucid, pollShardValidator)
11289
+ input: toSystemParamsInput(
11290
+ await runCreateScriptRefTx(lucid, pollShardValidator)
11291
+ )
11237
11292
  },
11238
11293
  pollManagerValidatorRef: {
11239
- input: await initScriptRef(lucid, pollManagerValidator)
11294
+ input: toSystemParamsInput(
11295
+ await runCreateScriptRefTx(lucid, pollManagerValidator)
11296
+ )
11240
11297
  },
11241
11298
  iAssetTokenPolicyRef: {
11242
- input: await initScriptRef(lucid, assetSymbolPolicy)
11299
+ input: toSystemParamsInput(
11300
+ await runCreateScriptRefTx(lucid, assetSymbolPolicy)
11301
+ )
11243
11302
  },
11244
11303
  stakingValidatorRef: {
11245
- input: await initScriptRef(
11246
- lucid,
11247
- mkStakingValidatorFromSP(stakingParams)
11304
+ input: toSystemParamsInput(
11305
+ await runCreateScriptRefTx(
11306
+ lucid,
11307
+ mkStakingValidatorFromSP(stakingParams)
11308
+ )
11248
11309
  )
11249
11310
  },
11250
11311
  stabilityPoolValidatorRef: {
11251
- input: await initScriptRef(lucid, stabilityPoolValidator)
11312
+ input: toSystemParamsInput(
11313
+ await runCreateScriptRefTx(lucid, stabilityPoolValidator)
11314
+ )
11252
11315
  },
11253
11316
  stableswapValidatorRef: {
11254
- input: await initScriptRef(lucid, stableswapValidator)
11317
+ input: toSystemParamsInput(
11318
+ await runCreateScriptRefTx(lucid, stableswapValidator)
11319
+ )
11255
11320
  },
11256
11321
  treasuryValidatorRef: {
11257
- input: await initScriptRef(lucid, treasuryValidator)
11322
+ input: toSystemParamsInput(
11323
+ await runCreateScriptRefTx(lucid, treasuryValidator)
11324
+ )
11258
11325
  },
11259
11326
  governanceValidatorRef: {
11260
- input: await initScriptRef(lucid, govValidator)
11327
+ input: toSystemParamsInput(
11328
+ await runCreateScriptRefTx(lucid, govValidator)
11329
+ )
11261
11330
  },
11262
11331
  versionRegistryValidatorRef: {
11263
- input: await initScriptRef(lucid, versionRegistryValidator)
11332
+ input: toSystemParamsInput(
11333
+ await runCreateScriptRefTx(lucid, versionRegistryValidator)
11334
+ )
11264
11335
  },
11265
11336
  iassetValidatorRef: {
11266
- input: await initScriptRef(lucid, iassetValidator)
11337
+ input: toSystemParamsInput(
11338
+ await runCreateScriptRefTx(lucid, iassetValidator)
11339
+ )
11267
11340
  },
11268
11341
  authTokenPolicies: {
11269
11342
  cdpAuthTokenRef: {
11270
- input: await initScriptRef(lucid, cdpTokenPolicy)
11343
+ input: toSystemParamsInput(
11344
+ await runCreateScriptRefTx(lucid, cdpTokenPolicy)
11345
+ )
11271
11346
  },
11272
11347
  iAssetAuthTokenRef: {
11273
- input: await initScriptRef(lucid, iassetTokenPolicy)
11348
+ input: toSystemParamsInput(
11349
+ await runCreateScriptRefTx(lucid, iassetTokenPolicy)
11350
+ )
11274
11351
  },
11275
11352
  accountTokenRef: {
11276
- input: await initScriptRef(lucid, accountTokenPolicy)
11353
+ input: toSystemParamsInput(
11354
+ await runCreateScriptRefTx(lucid, accountTokenPolicy)
11355
+ )
11277
11356
  },
11278
11357
  stabilityPoolAuthTokenRef: {
11279
- input: await initScriptRef(lucid, stabilityPoolTokenPolicy)
11358
+ input: toSystemParamsInput(
11359
+ await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
11360
+ )
11280
11361
  },
11281
11362
  pollManagerTokenRef: {
11282
- input: await initScriptRef(lucid, pollTokenPolicy)
11363
+ input: toSystemParamsInput(
11364
+ await runCreateScriptRefTx(lucid, pollTokenPolicy)
11365
+ )
11283
11366
  },
11284
11367
  stakingTokenRef: {
11285
- input: await initScriptRef(lucid, stakingTokenPolicy)
11368
+ input: toSystemParamsInput(
11369
+ await runCreateScriptRefTx(lucid, stakingTokenPolicy)
11370
+ )
11286
11371
  },
11287
11372
  versionRecordTokenPolicyRef: {
11288
- input: await initScriptRef(lucid, versionRecordTokenPolicy)
11373
+ input: toSystemParamsInput(
11374
+ await runCreateScriptRefTx(lucid, versionRecordTokenPolicy)
11375
+ )
11289
11376
  },
11290
11377
  iAssetTokenRef: {
11291
- input: await initScriptRef(lucid, assetSymbolPolicy)
11378
+ input: toSystemParamsInput(
11379
+ await runCreateScriptRefTx(lucid, assetSymbolPolicy)
11380
+ )
11292
11381
  },
11293
11382
  collateralAssetTokenRef: {
11294
- input: await initScriptRef(lucid, collateralAssetAuthTokenPolicy)
11383
+ input: toSystemParamsInput(
11384
+ await runCreateScriptRefTx(lucid, collateralAssetAuthTokenPolicy)
11385
+ )
11295
11386
  },
11296
11387
  upgradeTokenRef: {
11297
- input: await initScriptRef(lucid, upgradeTokenPolicy)
11388
+ input: toSystemParamsInput(
11389
+ await runCreateScriptRefTx(lucid, upgradeTokenPolicy)
11390
+ )
11298
11391
  },
11299
11392
  stabilityPoolTokenRef: {
11300
- input: await initScriptRef(lucid, stabilityPoolTokenPolicy)
11393
+ input: toSystemParamsInput(
11394
+ await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
11395
+ )
11301
11396
  },
11302
11397
  snapshotEpochToScaleToSumTokenRef: {
11303
- input: await initScriptRef(
11304
- lucid,
11305
- snapshotEpochToScaleToSumTokenPolicy
11398
+ input: toSystemParamsInput(
11399
+ await runCreateScriptRefTx(
11400
+ lucid,
11401
+ snapshotEpochToScaleToSumTokenPolicy
11402
+ )
11306
11403
  )
11307
11404
  }
11308
11405
  }
@@ -11332,7 +11429,7 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
11332
11429
  // src/contracts/iasset/queries.ts
11333
11430
  var import_lucid65 = require("@lucid-evolution/lucid");
11334
11431
  var import_cardano_offchain_common33 = require("@indigo-labs/cardano-offchain-common");
11335
- var import_fp_ts27 = require("fp-ts");
11432
+ var import_fp_ts26 = require("fp-ts");
11336
11433
  async function findIAsset(lucid, sysParams, iassetName) {
11337
11434
  const iassetUtxos = await lucid.utxosAtWithUnit(
11338
11435
  createScriptAddress(
@@ -11344,21 +11441,21 @@ async function findIAsset(lucid, sysParams, iassetName) {
11344
11441
  )
11345
11442
  );
11346
11443
  return (0, import_cardano_offchain_common33.matchSingle)(
11347
- import_fp_ts27.function.pipe(
11444
+ import_fp_ts26.function.pipe(
11348
11445
  iassetUtxos.map(
11349
- (utxo) => import_fp_ts27.function.pipe(
11350
- import_fp_ts27.option.fromNullable(utxo.datum),
11351
- import_fp_ts27.option.flatMap(parseIAssetDatum),
11352
- import_fp_ts27.option.flatMap((datum) => {
11446
+ (utxo) => import_fp_ts26.function.pipe(
11447
+ import_fp_ts26.option.fromNullable(utxo.datum),
11448
+ import_fp_ts26.option.flatMap(parseIAssetDatum),
11449
+ import_fp_ts26.option.flatMap((datum) => {
11353
11450
  if ((0, import_lucid65.toHex)(datum.assetName) === (0, import_lucid65.toHex)(iassetName)) {
11354
- return import_fp_ts27.option.some({ utxo, datum });
11451
+ return import_fp_ts26.option.some({ utxo, datum });
11355
11452
  } else {
11356
- return import_fp_ts27.option.none;
11453
+ return import_fp_ts26.option.none;
11357
11454
  }
11358
11455
  })
11359
11456
  )
11360
11457
  ),
11361
- import_fp_ts27.array.compact
11458
+ import_fp_ts26.array.compact
11362
11459
  ),
11363
11460
  (res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
11364
11461
  );
@@ -11374,21 +11471,21 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
11374
11471
  )
11375
11472
  );
11376
11473
  return (0, import_cardano_offchain_common33.matchSingle)(
11377
- import_fp_ts27.function.pipe(
11474
+ import_fp_ts26.function.pipe(
11378
11475
  collateralAssetUtxos.map(
11379
- (utxo) => import_fp_ts27.function.pipe(
11380
- import_fp_ts27.option.fromNullable(utxo.datum),
11381
- import_fp_ts27.option.flatMap(parseCollateralAssetDatum),
11382
- import_fp_ts27.option.flatMap((datum) => {
11476
+ (utxo) => import_fp_ts26.function.pipe(
11477
+ import_fp_ts26.option.fromNullable(utxo.datum),
11478
+ import_fp_ts26.option.flatMap(parseCollateralAssetDatum),
11479
+ import_fp_ts26.option.flatMap((datum) => {
11383
11480
  if ((0, import_cardano_offchain_common33.isSameAssetClass)(datum.collateralAsset, collateralAsset) && (0, import_lucid65.toHex)(iassetName) === (0, import_lucid65.toHex)(datum.iasset)) {
11384
- return import_fp_ts27.option.some({ utxo, datum });
11481
+ return import_fp_ts26.option.some({ utxo, datum });
11385
11482
  } else {
11386
- return import_fp_ts27.option.none;
11483
+ return import_fp_ts26.option.none;
11387
11484
  }
11388
11485
  })
11389
11486
  )
11390
11487
  ),
11391
- import_fp_ts27.array.compact
11488
+ import_fp_ts26.array.compact
11392
11489
  ),
11393
11490
  (res) => new Error(
11394
11491
  "Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
@@ -11398,12 +11495,12 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
11398
11495
 
11399
11496
  // src/contracts/stableswap/helpers.ts
11400
11497
  var import_lucid66 = require("@lucid-evolution/lucid");
11401
- var import_fp_ts29 = require("fp-ts");
11498
+ var import_fp_ts28 = require("fp-ts");
11402
11499
 
11403
11500
  // src/contracts/stableswap/types-new.ts
11404
11501
  var import_cardano_offchain_common34 = require("@indigo-labs/cardano-offchain-common");
11405
11502
  var import_evolution20 = require("@evolution-sdk/evolution");
11406
- var import_fp_ts28 = require("fp-ts");
11503
+ var import_fp_ts27 = require("fp-ts");
11407
11504
  var import_effect3 = require("effect");
11408
11505
  var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
11409
11506
  var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
@@ -11445,22 +11542,22 @@ function serialiseStableswapOrderDatum(d) {
11445
11542
  }
11446
11543
  function parseStableswapOrderDatum(datum) {
11447
11544
  try {
11448
- return import_fp_ts28.option.some(
11545
+ return import_fp_ts27.option.some(
11449
11546
  import_evolution20.Data.withSchema(
11450
11547
  StableswapOrderDatumSchema,
11451
11548
  DEFAULT_SCHEMA_OPTIONS
11452
11549
  ).fromCBORHex(datum)
11453
11550
  );
11454
11551
  } catch (_) {
11455
- return import_fp_ts28.option.none;
11552
+ return import_fp_ts27.option.none;
11456
11553
  }
11457
11554
  }
11458
11555
  function parseStableswapOrderDatumOrThrow(datum) {
11459
- return import_fp_ts28.function.pipe(
11556
+ return import_fp_ts27.function.pipe(
11460
11557
  parseStableswapOrderDatum(datum),
11461
- import_fp_ts28.option.match(() => {
11558
+ import_fp_ts27.option.match(() => {
11462
11559
  throw new Error("Expected a Stableswap Order datum.");
11463
- }, import_fp_ts28.function.identity)
11560
+ }, import_fp_ts27.function.identity)
11464
11561
  );
11465
11562
  }
11466
11563
  function serialiseStableswapOutputDatum(d) {
@@ -11477,22 +11574,22 @@ function serialiseStableswapOrderRedeemer(r) {
11477
11574
  }
11478
11575
  function parseStableswapOrderRedeemer(redeemerCborHex) {
11479
11576
  try {
11480
- return import_fp_ts28.option.some(
11577
+ return import_fp_ts27.option.some(
11481
11578
  import_evolution20.Data.withSchema(
11482
11579
  StableswapOrderRedeemerSchema,
11483
11580
  DEFAULT_SCHEMA_OPTIONS
11484
11581
  ).fromCBORHex(redeemerCborHex)
11485
11582
  );
11486
11583
  } catch (_) {
11487
- return import_fp_ts28.option.none;
11584
+ return import_fp_ts27.option.none;
11488
11585
  }
11489
11586
  }
11490
11587
  function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
11491
- return import_fp_ts28.function.pipe(
11588
+ return import_fp_ts27.function.pipe(
11492
11589
  parseStableswapOrderRedeemer(redeemerCborHex),
11493
- import_fp_ts28.option.match(() => {
11590
+ import_fp_ts27.option.match(() => {
11494
11591
  throw new Error("Expected a Stableswap Order redeemer.");
11495
- }, import_fp_ts28.function.identity)
11592
+ }, import_fp_ts27.function.identity)
11496
11593
  );
11497
11594
  }
11498
11595
 
@@ -11748,25 +11845,25 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11748
11845
  return [];
11749
11846
  }
11750
11847
  });
11751
- const { left: mintingOrders, right: redeemingOrdersSortedDesc } = import_fp_ts29.function.pipe(
11848
+ const { left: mintingOrders, right: redeemingOrdersSortedDesc } = import_fp_ts28.function.pipe(
11752
11849
  validOrders,
11753
- import_fp_ts29.array.partition((o) => o.orderType === "REDEEMING"),
11850
+ import_fp_ts28.array.partition((o) => o.orderType === "REDEEMING"),
11754
11851
  ({ left, right }) => ({
11755
11852
  left,
11756
11853
  // Sort the redeeming orders descending.
11757
- right: import_fp_ts29.function.pipe(
11854
+ right: import_fp_ts28.function.pipe(
11758
11855
  right,
11759
- import_fp_ts29.array.sort(
11760
- import_fp_ts29.ord.contramap(
11856
+ import_fp_ts28.array.sort(
11857
+ import_fp_ts28.ord.contramap(
11761
11858
  (o) => o.swapInfo.owedCollateralAsset
11762
- )(import_fp_ts29.ord.reverse(BigIntOrd))
11859
+ )(import_fp_ts28.ord.reverse(BigIntOrd))
11763
11860
  )
11764
11861
  )
11765
11862
  })
11766
11863
  );
11767
- const totalCollateralDiff = import_fp_ts29.function.pipe(
11864
+ const totalCollateralDiff = import_fp_ts28.function.pipe(
11768
11865
  validOrders,
11769
- import_fp_ts29.array.reduce(
11866
+ import_fp_ts28.array.reduce(
11770
11867
  0n,
11771
11868
  (acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
11772
11869
  )
@@ -11774,13 +11871,13 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11774
11871
  if (psmAvailableLiq + totalCollateralDiff >= 0n) {
11775
11872
  return validOrders.map((o) => o.order);
11776
11873
  }
11777
- const collateralFromMinting = import_fp_ts29.function.pipe(
11874
+ const collateralFromMinting = import_fp_ts28.function.pipe(
11778
11875
  mintingOrders,
11779
- import_fp_ts29.array.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
11876
+ import_fp_ts28.array.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
11780
11877
  );
11781
- const { selected } = import_fp_ts29.function.pipe(
11878
+ const { selected } = import_fp_ts28.function.pipe(
11782
11879
  redeemingOrdersSortedDesc,
11783
- import_fp_ts29.array.reduce(
11880
+ import_fp_ts28.array.reduce(
11784
11881
  {
11785
11882
  intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
11786
11883
  selected: []
@@ -11797,7 +11894,7 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11797
11894
  // src/contracts/stableswap/queries.ts
11798
11895
  var import_lucid67 = require("@lucid-evolution/lucid");
11799
11896
  var import_cardano_offchain_common36 = require("@indigo-labs/cardano-offchain-common");
11800
- var import_fp_ts30 = require("fp-ts");
11897
+ var import_fp_ts29 = require("fp-ts");
11801
11898
  async function findAllStableswapPools(lucid, sysParams) {
11802
11899
  const cdpUtxos = await lucid.utxosAtWithUnit(
11803
11900
  createScriptAddress(
@@ -11808,28 +11905,28 @@ async function findAllStableswapPools(lucid, sysParams) {
11808
11905
  fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
11809
11906
  )
11810
11907
  );
11811
- return import_fp_ts30.function.pipe(
11908
+ return import_fp_ts29.function.pipe(
11812
11909
  cdpUtxos.map(
11813
- (utxo) => import_fp_ts30.function.pipe(
11814
- import_fp_ts30.option.fromNullable(utxo.datum),
11815
- import_fp_ts30.option.flatMap(parseStableswapPoolDatum),
11816
- import_fp_ts30.option.map((datum) => ({ utxo, datum }))
11910
+ (utxo) => import_fp_ts29.function.pipe(
11911
+ import_fp_ts29.option.fromNullable(utxo.datum),
11912
+ import_fp_ts29.option.flatMap(parseStableswapPoolDatum),
11913
+ import_fp_ts29.option.map((datum) => ({ utxo, datum }))
11817
11914
  )
11818
11915
  ),
11819
- import_fp_ts30.array.compact
11916
+ import_fp_ts29.array.compact
11820
11917
  );
11821
11918
  }
11822
11919
  async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
11823
11920
  const stableswapPools = await findAllStableswapPools(lucid, sysParams);
11824
11921
  return (0, import_cardano_offchain_common36.matchSingle)(
11825
- import_fp_ts30.function.pipe(
11922
+ import_fp_ts29.function.pipe(
11826
11923
  stableswapPools.map((pool) => {
11827
11924
  if ((0, import_lucid67.toHex)(pool.datum.iasset) === iassetName && (0, import_cardano_offchain_common36.isSameAssetClass)(pool.datum.collateralAsset, collateralAsset)) {
11828
- return import_fp_ts30.option.some(pool);
11925
+ return import_fp_ts29.option.some(pool);
11829
11926
  }
11830
- return import_fp_ts30.option.none;
11927
+ return import_fp_ts29.option.none;
11831
11928
  }),
11832
- import_fp_ts30.array.compact
11929
+ import_fp_ts29.array.compact
11833
11930
  ),
11834
11931
  (res) => new Error(
11835
11932
  "Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
@@ -11840,7 +11937,7 @@ async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset)
11840
11937
  // src/contracts/stableswap/transactions.ts
11841
11938
  var import_lucid68 = require("@lucid-evolution/lucid");
11842
11939
  var import_cardano_offchain_common37 = require("@indigo-labs/cardano-offchain-common");
11843
- var import_fp_ts31 = require("fp-ts");
11940
+ var import_fp_ts30 = require("fp-ts");
11844
11941
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
11845
11942
  const myAddress = await lucid.wallet().address();
11846
11943
  const pkh = (0, import_lucid68.paymentCredentialOf)(myAddress);
@@ -11928,7 +12025,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11928
12025
  ]),
11929
12026
  (_) => new Error("Expected a single iasset token policy Ref Script UTXO")
11930
12027
  );
11931
- if (import_fp_ts31.array.isEmpty(stableswapOrderOrefs)) {
12028
+ if (import_fp_ts30.array.isEmpty(stableswapOrderOrefs)) {
11932
12029
  throw new Error("At least one order must be provided.");
11933
12030
  }
11934
12031
  const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
@@ -11975,9 +12072,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11975
12072
  return res.result;
11976
12073
  }
11977
12074
  );
11978
- const totalSwapInfo = import_fp_ts31.function.pipe(
12075
+ const totalSwapInfo = import_fp_ts30.function.pipe(
11979
12076
  ordersInfo,
11980
- import_fp_ts31.array.reduce(
12077
+ import_fp_ts30.array.reduce(
11981
12078
  {
11982
12079
  suppliedCollateralAsset: 0n,
11983
12080
  suppliedIasset: 0n,
@@ -12031,9 +12128,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
12031
12128
  if (amountToMint !== 0n) {
12032
12129
  tx.mintAssets((0, import_cardano_offchain_common37.mkAssetsOf)(iassetAc, amountToMint), import_lucid68.Data.void());
12033
12130
  }
12034
- import_fp_ts31.function.pipe(
12131
+ import_fp_ts30.function.pipe(
12035
12132
  ordersInfo,
12036
- import_fp_ts31.array.reduce(tx, (acc, orderInfo) => {
12133
+ import_fp_ts30.array.reduce(tx, (acc, orderInfo) => {
12037
12134
  return acc.collectFrom(
12038
12135
  [orderInfo.order.utxo],
12039
12136
  (0, import_cardano_offchain_common37.isSameOutRef)(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
@@ -12325,7 +12422,6 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12325
12422
  initGovernance,
12326
12423
  initInterestCollector,
12327
12424
  initPythConfig,
12328
- initScriptRef,
12329
12425
  initSpState,
12330
12426
  initStakingManager,
12331
12427
  initSumVal,
@@ -12462,6 +12558,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12462
12558
  robCollateralAmtToSpend,
12463
12559
  robIAssetAmtToSpend,
12464
12560
  robSellOrderFilledAssets,
12561
+ runAndAwaitTxBuilder,
12465
12562
  runCreateScriptRefTx,
12466
12563
  runOneShotMintTx,
12467
12564
  scriptRef,
@@ -12507,13 +12604,13 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12507
12604
  spZeroNegatives,
12508
12605
  startInterestOracle,
12509
12606
  startPriceOracleTx,
12510
- submitTx,
12511
12607
  sum,
12512
12608
  summariseOrder,
12513
12609
  summarizeActualLeverageRedemptions,
12514
12610
  toAssetClassFromLucid,
12515
12611
  toDataDerivedPythPrice,
12516
12612
  toSystemParamsAsset,
12613
+ toSystemParamsInput,
12517
12614
  treasuryCollect,
12518
12615
  treasuryFeeTx,
12519
12616
  treasuryMerge,