@indigo-labs/indigo-sdk 0.3.28 → 0.4.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
@@ -136,6 +136,7 @@ __export(index_exports, {
136
136
  closeCdp: () => closeCdp,
137
137
  closeStakingPosition: () => closeStakingPosition,
138
138
  collectInterestTx: () => collectInterestTx,
139
+ collectPriceFeedIds: () => collectPriceFeedIds,
139
140
  collectorFeeTx: () => collectorFeeTx,
140
141
  createDestinationDatum: () => createDestinationDatum,
141
142
  createE2s2sSnapshots: () => createE2s2sSnapshots,
@@ -148,6 +149,7 @@ __export(index_exports, {
148
149
  decodePythMessage: () => decodePythMessage,
149
150
  depositCdp: () => depositCdp,
150
151
  deriveAuthToken: () => deriveAuthToken,
152
+ derivePythPrice: () => derivePythPrice,
151
153
  distributeAda: () => distributeAda,
152
154
  distributeInterest: () => distributeInterest,
153
155
  distributeReward: () => distributeReward,
@@ -160,6 +162,17 @@ __export(index_exports, {
160
162
  executeProposal: () => executeProposal,
161
163
  feedInterestOracle: () => feedInterestOracle,
162
164
  feedPriceOracleTx: () => feedPriceOracleTx,
165
+ findAdminInterestCollectors: () => findAdminInterestCollectors,
166
+ findAllInterestCollectors: () => findAllInterestCollectors,
167
+ findAllTreasuryUtxos: () => findAllTreasuryUtxos,
168
+ findAllTreasuryUtxosWithNonAdaAsset: () => findAllTreasuryUtxosWithNonAdaAsset,
169
+ findCollateralAsset: () => findCollateralAsset,
170
+ findIAsset: () => findIAsset,
171
+ findRandomCdpCreator: () => findRandomCdpCreator,
172
+ findRandomNonAdminInterestCollector: () => findRandomNonAdminInterestCollector,
173
+ findRandomTreasuryUtxo: () => findRandomTreasuryUtxo,
174
+ findRandomTreasuryUtxoWithAsset: () => findRandomTreasuryUtxoWithAsset,
175
+ findRandomTreasuryUtxoWithOnlyAda: () => findRandomTreasuryUtxoWithOnlyAda,
163
176
  findRelevantE2s2sIdxs: () => findRelevantE2s2sIdxs,
164
177
  findStakingManager: () => findStakingManager,
165
178
  findStakingManagerByOutRef: () => findStakingManagerByOutRef,
@@ -1938,7 +1951,7 @@ function partitionEpochToScaleToSums(spContent) {
1938
1951
  }
1939
1952
 
1940
1953
  // src/contracts/cdp/transactions.ts
1941
- var import_fp_ts12 = require("fp-ts");
1954
+ var import_fp_ts13 = require("fp-ts");
1942
1955
 
1943
1956
  // src/contracts/interest-collection/transactions.ts
1944
1957
  var import_lucid9 = require("@lucid-evolution/lucid");
@@ -3975,6 +3988,19 @@ async function encodeSignedPythMessage(update, secretKey) {
3975
3988
 
3976
3989
  // src/contracts/pyth-feed/helpers.ts
3977
3990
  var import_lucid12 = require("@lucid-evolution/lucid");
3991
+ var import_fp_ts12 = require("fp-ts");
3992
+ function collectPriceFeedIds(derivedPythPrice) {
3993
+ const ids = (0, import_ts_pattern11.match)(derivedPythPrice).with({ Value: import_ts_pattern11.P.select() }, (value) => [
3994
+ BigInt(value.configuration.priceFeedId)
3995
+ ]).with(
3996
+ { Inverse: import_ts_pattern11.P.select() },
3997
+ (inverse) => collectPriceFeedIds(fromDataDerivedPythPrice(inverse.value))
3998
+ ).with({ Divide: import_ts_pattern11.P.select() }, (divide) => [
3999
+ ...collectPriceFeedIds(fromDataDerivedPythPrice(divide.x)),
4000
+ ...collectPriceFeedIds(fromDataDerivedPythPrice(divide.y))
4001
+ ]).exhaustive();
4002
+ return import_fp_ts12.function.pipe(ids, import_fp_ts12.array.uniq(BigIntOrd), import_fp_ts12.array.sort(BigIntOrd));
4003
+ }
3978
4004
  function derivePythPrice(derivedPythPrice, messageHex) {
3979
4005
  const decodedMessage = decodePythMessage((0, import_lucid12.fromHex)(messageHex));
3980
4006
  const pricePayload = decodePriceUpdate(decodedMessage.payload);
@@ -4795,10 +4821,10 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
4795
4821
  const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4796
4822
  tx.validFrom(validateFrom).validTo(validateTo);
4797
4823
  }
4798
- const partialRedemptionFee = import_fp_ts12.function.pipe(
4824
+ const partialRedemptionFee = import_fp_ts13.function.pipe(
4799
4825
  govDatum.protocolParams.cdpRedemptionRequiredSignature,
4800
- import_fp_ts12.option.fromNullable,
4801
- import_fp_ts12.option.match(
4826
+ import_fp_ts13.option.fromNullable,
4827
+ import_fp_ts13.option.match(
4802
4828
  // When public redemptions
4803
4829
  () => {
4804
4830
  return isPartial ? BigInt(sysParams.cdpRedeemParams.partialRedemptionExtraFeeLovelace) : 0n;
@@ -5191,17 +5217,17 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
5191
5217
  if (cdpUtxos.length !== cdpsToMergeUtxos.length) {
5192
5218
  throw new Error("Expected certain number of CDPs");
5193
5219
  }
5194
- const aggregatedVal = import_fp_ts12.function.pipe(
5220
+ const aggregatedVal = import_fp_ts13.function.pipe(
5195
5221
  cdpUtxos,
5196
- import_fp_ts12.array.reduce({}, (acc, utxo) => (0, import_lucid14.addAssets)(acc, utxo.assets))
5222
+ import_fp_ts13.array.reduce({}, (acc, utxo) => (0, import_lucid14.addAssets)(acc, utxo.assets))
5197
5223
  );
5198
- const aggregatedMintedAmt = import_fp_ts12.function.pipe(
5224
+ const aggregatedMintedAmt = import_fp_ts13.function.pipe(
5199
5225
  cdpDatums,
5200
- import_fp_ts12.array.reduce(0n, (acc, cdpDat) => acc + cdpDat.mintedAmt)
5226
+ import_fp_ts13.array.reduce(0n, (acc, cdpDat) => acc + cdpDat.mintedAmt)
5201
5227
  );
5202
- const { aggregatedInterest, aggregatedCollateralTreasury } = import_fp_ts12.function.pipe(
5228
+ const { aggregatedInterest, aggregatedCollateralTreasury } = import_fp_ts13.function.pipe(
5203
5229
  cdpDatums,
5204
- import_fp_ts12.array.reduce(
5230
+ import_fp_ts13.array.reduce(
5205
5231
  { aggregatedCollateralTreasury: 0n, aggregatedInterest: 0n },
5206
5232
  (acc, cdpDat) => (0, import_ts_pattern14.match)(cdpDat.cdpFees).returnType().with({ FrozenCDPAccumulatedFees: import_ts_pattern14.P.select() }, (fees) => ({
5207
5233
  aggregatedCollateralTreasury: acc.aggregatedCollateralTreasury + fees.collateralTreasury,
@@ -5210,7 +5236,7 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
5210
5236
  )
5211
5237
  );
5212
5238
  const [[mainMergeUtxo, mainCdpDatum], otherMergeUtxos] = (0, import_ts_pattern14.match)(
5213
- import_fp_ts12.array.zip(cdpUtxos, cdpDatums)
5239
+ import_fp_ts13.array.zip(cdpUtxos, cdpDatums)
5214
5240
  ).returnType().with([import_ts_pattern14.P._, ...import_ts_pattern14.P.array()], ([main, ...other]) => [
5215
5241
  main,
5216
5242
  other.map((a) => a[0])
@@ -5420,6 +5446,27 @@ var mkCDPCreatorValidatorFromSP = (params) => {
5420
5446
  };
5421
5447
  };
5422
5448
 
5449
+ // src/contracts/cdp-creator/queries.ts
5450
+ var import_cardano_offchain_common14 = require("@3rd-eye-labs/cardano-offchain-common");
5451
+ var import_fp_ts14 = require("fp-ts");
5452
+ async function findRandomCdpCreator(lucid, sysParams) {
5453
+ const cdpCreatorUtxos = await lucid.utxosAtWithUnit(
5454
+ createScriptAddress(
5455
+ lucid.config().network,
5456
+ sysParams.validatorHashes.cdpCreatorHash
5457
+ ),
5458
+ (0, import_cardano_offchain_common14.assetClassToUnit)(
5459
+ fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft)
5460
+ )
5461
+ );
5462
+ return import_fp_ts14.function.pipe(
5463
+ import_fp_ts14.option.fromNullable((0, import_cardano_offchain_common14.getRandomElement)(cdpCreatorUtxos)),
5464
+ import_fp_ts14.option.match(() => {
5465
+ throw new Error("Expected some cdp creator UTXOs.");
5466
+ }, import_fp_ts14.function.identity)
5467
+ );
5468
+ }
5469
+
5423
5470
  // src/contracts/poll/scripts.ts
5424
5471
  var import_lucid21 = require("@lucid-evolution/lucid");
5425
5472
 
@@ -5533,7 +5580,7 @@ function serialiseCollectorRedeemer(r) {
5533
5580
  }
5534
5581
 
5535
5582
  // src/contracts/collector/transactions.ts
5536
- var import_cardano_offchain_common14 = require("@3rd-eye-labs/cardano-offchain-common");
5583
+ var import_cardano_offchain_common15 = require("@3rd-eye-labs/cardano-offchain-common");
5537
5584
  async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
5538
5585
  const collectorUtxo = matchSingle(
5539
5586
  await lucid.utxosByOutRef([collectorOref]),
@@ -5548,22 +5595,22 @@ async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
5548
5595
  tx.collectFrom([collectorUtxo], serialiseCollectorRedeemer("Collect")).pay.ToContract(
5549
5596
  collectorUtxo.address,
5550
5597
  { kind: "inline", value: import_lucid22.Data.void() },
5551
- (0, import_lucid22.addAssets)(collectorUtxo.assets, (0, import_cardano_offchain_common14.mkLovelacesOf)(fee))
5598
+ (0, import_lucid22.addAssets)(collectorUtxo.assets, (0, import_cardano_offchain_common15.mkLovelacesOf)(fee))
5552
5599
  ).readFrom([collectorRefScriptUtxo]);
5553
5600
  return collectorRefScriptUtxo;
5554
5601
  }
5555
5602
 
5556
5603
  // src/contracts/gov/transactions.ts
5557
5604
  var import_lucid25 = require("@lucid-evolution/lucid");
5558
- var import_cardano_offchain_common16 = require("@3rd-eye-labs/cardano-offchain-common");
5605
+ var import_cardano_offchain_common17 = require("@3rd-eye-labs/cardano-offchain-common");
5559
5606
  var import_lucid26 = require("@lucid-evolution/lucid");
5560
5607
  var import_function2 = require("fp-ts/lib/function");
5561
- var import_fp_ts15 = require("fp-ts");
5608
+ var import_fp_ts17 = require("fp-ts");
5562
5609
  var import_ts_pattern17 = require("ts-pattern");
5563
5610
 
5564
5611
  // src/contracts/staking/types-new.ts
5565
5612
  var import_evolution16 = require("@evolution-sdk/evolution");
5566
- var import_fp_ts13 = require("fp-ts");
5613
+ var import_fp_ts15 = require("fp-ts");
5567
5614
  var import_ts_pattern15 = require("ts-pattern");
5568
5615
  var StakingPosLockedAmtSchema = import_evolution16.TSchema.Array(
5569
5616
  import_evolution16.TSchema.Tuple([
@@ -5623,22 +5670,22 @@ function serialiseStakingRedeemer(r) {
5623
5670
  }
5624
5671
  function parseStakingRedeemer(datum) {
5625
5672
  try {
5626
- return import_fp_ts13.option.some(
5673
+ return import_fp_ts15.option.some(
5627
5674
  import_evolution16.Data.withSchema(
5628
5675
  StakingRedeemerSchema,
5629
5676
  DEFAULT_SCHEMA_OPTIONS
5630
5677
  ).fromCBORHex(datum)
5631
5678
  );
5632
5679
  } catch (_) {
5633
- return import_fp_ts13.option.none;
5680
+ return import_fp_ts15.option.none;
5634
5681
  }
5635
5682
  }
5636
5683
  function parseStakingRedeemerOrThrow(datum) {
5637
- return import_fp_ts13.function.pipe(
5684
+ return import_fp_ts15.function.pipe(
5638
5685
  parseStakingRedeemer(datum),
5639
- import_fp_ts13.option.match(() => {
5686
+ import_fp_ts15.option.match(() => {
5640
5687
  throw new Error("Expected a StakingRedeemer datum.");
5641
- }, import_fp_ts13.function.identity)
5688
+ }, import_fp_ts15.function.identity)
5642
5689
  );
5643
5690
  }
5644
5691
  function parseStakingPosition(datum) {
@@ -5647,17 +5694,17 @@ function parseStakingPosition(datum) {
5647
5694
  import_evolution16.Data.withSchema(StakingDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
5648
5695
  datum
5649
5696
  )
5650
- ).with({ owner: import_ts_pattern15.P.any }, (res) => import_fp_ts13.option.some(res)).otherwise(() => import_fp_ts13.option.none);
5697
+ ).with({ owner: import_ts_pattern15.P.any }, (res) => import_fp_ts15.option.some(res)).otherwise(() => import_fp_ts15.option.none);
5651
5698
  } catch (_) {
5652
- return import_fp_ts13.option.none;
5699
+ return import_fp_ts15.option.none;
5653
5700
  }
5654
5701
  }
5655
5702
  function parseStakingPositionOrThrow(datum) {
5656
- return import_fp_ts13.function.pipe(
5703
+ return import_fp_ts15.function.pipe(
5657
5704
  parseStakingPosition(datum),
5658
- import_fp_ts13.option.match(() => {
5705
+ import_fp_ts15.option.match(() => {
5659
5706
  throw new Error("Expected a StakingPosition datum.");
5660
- }, import_fp_ts13.function.identity)
5707
+ }, import_fp_ts15.function.identity)
5661
5708
  );
5662
5709
  }
5663
5710
  function parseStakingManagerDatum(datum) {
@@ -5828,8 +5875,8 @@ function serialiseVersionRecordDatum(d) {
5828
5875
 
5829
5876
  // src/contracts/poll/types-poll-new.ts
5830
5877
  var import_evolution18 = require("@evolution-sdk/evolution");
5831
- var import_cardano_offchain_common15 = require("@3rd-eye-labs/cardano-offchain-common");
5832
- var import_fp_ts14 = require("fp-ts");
5878
+ var import_cardano_offchain_common16 = require("@3rd-eye-labs/cardano-offchain-common");
5879
+ var import_fp_ts16 = require("fp-ts");
5833
5880
  var import_ts_pattern16 = require("ts-pattern");
5834
5881
  var PollStatusSchema = import_evolution18.TSchema.Struct({
5835
5882
  yesVotes: import_evolution18.TSchema.Integer,
@@ -5854,7 +5901,7 @@ var PollShardContentSchema = import_evolution18.TSchema.Struct({
5854
5901
  pollId: import_evolution18.TSchema.Integer,
5855
5902
  status: PollStatusSchema,
5856
5903
  votingEndTime: import_evolution18.TSchema.Integer,
5857
- managerAddress: import_cardano_offchain_common15.AddressSchema
5904
+ managerAddress: import_cardano_offchain_common16.AddressSchema
5858
5905
  });
5859
5906
  var PollDatumSchema = import_evolution18.TSchema.Union(
5860
5907
  import_evolution18.TSchema.Struct(
@@ -5876,7 +5923,7 @@ var PollShardRedeemerSchema = import_evolution18.TSchema.Union(
5876
5923
  MergeShards: import_evolution18.TSchema.Struct(
5877
5924
  {
5878
5925
  currentTime: import_evolution18.TSchema.Integer,
5879
- pollManagerRef: import_cardano_offchain_common15.OutputReferenceSchema
5926
+ pollManagerRef: import_cardano_offchain_common16.OutputReferenceSchema
5880
5927
  },
5881
5928
  { flatFields: true }
5882
5929
  )
@@ -5921,22 +5968,22 @@ function serialisePollShardRedeemer(r) {
5921
5968
  }
5922
5969
  function parsePollShardRedeemer(datum) {
5923
5970
  try {
5924
- return import_fp_ts14.option.some(
5971
+ return import_fp_ts16.option.some(
5925
5972
  import_evolution18.Data.withSchema(
5926
5973
  PollShardRedeemerSchema,
5927
5974
  DEFAULT_SCHEMA_OPTIONS
5928
5975
  ).fromCBORHex(datum)
5929
5976
  );
5930
5977
  } catch (_) {
5931
- return import_fp_ts14.option.none;
5978
+ return import_fp_ts16.option.none;
5932
5979
  }
5933
5980
  }
5934
5981
  function parsePollShardRedeemerOrThrow(datum) {
5935
- return import_fp_ts14.function.pipe(
5982
+ return import_fp_ts16.function.pipe(
5936
5983
  parsePollShardRedeemer(datum),
5937
- import_fp_ts14.option.match(() => {
5984
+ import_fp_ts16.option.match(() => {
5938
5985
  throw new Error("Expected a poll shard redeemer.");
5939
- }, import_fp_ts14.function.identity)
5986
+ }, import_fp_ts16.function.identity)
5940
5987
  );
5941
5988
  }
5942
5989
  function parsePollManager(datum) {
@@ -5945,17 +5992,17 @@ function parsePollManager(datum) {
5945
5992
  import_evolution18.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
5946
5993
  datum
5947
5994
  )
5948
- ).with({ PollManager: import_ts_pattern16.P.select() }, (res) => import_fp_ts14.option.some(res)).otherwise(() => import_fp_ts14.option.none);
5995
+ ).with({ PollManager: import_ts_pattern16.P.select() }, (res) => import_fp_ts16.option.some(res)).otherwise(() => import_fp_ts16.option.none);
5949
5996
  } catch (_) {
5950
- return import_fp_ts14.option.none;
5997
+ return import_fp_ts16.option.none;
5951
5998
  }
5952
5999
  }
5953
6000
  function parsePollManagerOrThrow(datum) {
5954
- return import_fp_ts14.function.pipe(
6001
+ return import_fp_ts16.function.pipe(
5955
6002
  parsePollManager(datum),
5956
- import_fp_ts14.option.match(() => {
6003
+ import_fp_ts16.option.match(() => {
5957
6004
  throw new Error("Expected a poll manager datum.");
5958
- }, import_fp_ts14.function.identity)
6005
+ }, import_fp_ts16.function.identity)
5959
6006
  );
5960
6007
  }
5961
6008
  function parsePollShard(datum) {
@@ -5964,17 +6011,17 @@ function parsePollShard(datum) {
5964
6011
  import_evolution18.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
5965
6012
  datum
5966
6013
  )
5967
- ).with({ PollShard: import_ts_pattern16.P.select() }, (res) => import_fp_ts14.option.some(res)).otherwise(() => import_fp_ts14.option.none);
6014
+ ).with({ PollShard: import_ts_pattern16.P.select() }, (res) => import_fp_ts16.option.some(res)).otherwise(() => import_fp_ts16.option.none);
5968
6015
  } catch (_) {
5969
- return import_fp_ts14.option.none;
6016
+ return import_fp_ts16.option.none;
5970
6017
  }
5971
6018
  }
5972
6019
  function parsePollShardOrThrow(datum) {
5973
- return import_fp_ts14.function.pipe(
6020
+ return import_fp_ts16.function.pipe(
5974
6021
  parsePollShard(datum),
5975
- import_fp_ts14.option.match(() => {
6022
+ import_fp_ts16.option.match(() => {
5976
6023
  throw new Error("Expected a poll shard datum.");
5977
- }, import_fp_ts14.function.identity)
6024
+ }, import_fp_ts16.function.identity)
5978
6025
  );
5979
6026
  }
5980
6027
  function serialisePollDatum(d) {
@@ -5982,7 +6029,7 @@ function serialisePollDatum(d) {
5982
6029
  }
5983
6030
 
5984
6031
  // src/contracts/gov/transactions.ts
5985
- var import_cardano_offchain_common17 = require("@3rd-eye-labs/cardano-offchain-common");
6032
+ var import_cardano_offchain_common18 = require("@3rd-eye-labs/cardano-offchain-common");
5986
6033
  async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, govOref, allIAssetOrefs) {
5987
6034
  const network = lucid.config().network;
5988
6035
  const currentTime = BigInt((0, import_lucid25.slotToUnixTime)(network, currentSlot));
@@ -6012,7 +6059,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
6012
6059
  const votingEndTime = currentTime + govDatum.protocolParams.votingPeriod;
6013
6060
  const expirationTime = votingEndTime + govDatum.protocolParams.expirationPeriod;
6014
6061
  const proposingEndTime = currentTime + govDatum.protocolParams.proposingPeriod;
6015
- const pollNftValue = (0, import_cardano_offchain_common16.mkAssetsOf)(
6062
+ const pollNftValue = (0, import_cardano_offchain_common17.mkAssetsOf)(
6016
6063
  fromSystemParamsAsset(sysParams.govParams.pollToken),
6017
6064
  1n
6018
6065
  );
@@ -6029,7 +6076,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
6029
6076
  );
6030
6077
  (0, import_function2.pipe)(
6031
6078
  relativeIAsset,
6032
- import_fp_ts15.option.match(
6079
+ import_fp_ts17.option.match(
6033
6080
  () => {
6034
6081
  if (govDatum.iassetsCount !== 0n) {
6035
6082
  throw new Error(
@@ -6090,7 +6137,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
6090
6137
  },
6091
6138
  (0, import_lucid25.addAssets)(
6092
6139
  pollNftValue,
6093
- (0, import_cardano_offchain_common16.mkAssetsOf)(
6140
+ (0, import_cardano_offchain_common17.mkAssetsOf)(
6094
6141
  fromSystemParamsAsset(sysParams.govParams.indyAsset),
6095
6142
  proposalDeposit(
6096
6143
  govDatum.protocolParams.proposalDeposit,
@@ -6143,7 +6190,7 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
6143
6190
  const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
6144
6191
  const tx = lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
6145
6192
  Number(currentTime) + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
6146
- ).mintAssets((0, import_cardano_offchain_common16.mkAssetsOf)(pollNft, shardsCount), import_lucid26.Data.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
6193
+ ).mintAssets((0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, shardsCount), import_lucid26.Data.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
6147
6194
  [pollManagerUtxo],
6148
6195
  serialisePollManagerRedeemer({ CreateShards: { currentTime } })
6149
6196
  ).pay.ToContract(
@@ -6169,11 +6216,11 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
6169
6216
  pollId: pollManager.pollId,
6170
6217
  status: { yesVotes: 0n, noVotes: 0n },
6171
6218
  votingEndTime: pollManager.votingEndTime,
6172
- managerAddress: (0, import_cardano_offchain_common17.addressFromBech32)(pollManagerUtxo.address)
6219
+ managerAddress: (0, import_cardano_offchain_common18.addressFromBech32)(pollManagerUtxo.address)
6173
6220
  }
6174
6221
  })
6175
6222
  },
6176
- (0, import_cardano_offchain_common16.mkAssetsOf)(pollNft, 1n)
6223
+ (0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, 1n)
6177
6224
  );
6178
6225
  }
6179
6226
  return tx;
@@ -6227,7 +6274,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
6227
6274
  const stakingPosDatum = parseStakingPositionOrThrow(
6228
6275
  getInlineDatumOrThrow(stakingPosUtxo)
6229
6276
  );
6230
- const indyStakedAmt = (0, import_cardano_offchain_common16.assetClassValueOf)(
6277
+ const indyStakedAmt = (0, import_cardano_offchain_common17.assetClassValueOf)(
6231
6278
  stakingPosUtxo.assets,
6232
6279
  fromSystemParamsAsset(sysParams.govParams.indyAsset)
6233
6280
  );
@@ -6305,10 +6352,10 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
6305
6352
  getInlineDatumOrThrow(pollManagerUtxo)
6306
6353
  );
6307
6354
  const shardUtxos = await lucid.utxosByOutRef(shardsOutRefs);
6308
- const aggregatedStatus = import_fp_ts15.function.pipe(
6355
+ const aggregatedStatus = import_fp_ts17.function.pipe(
6309
6356
  shardUtxos,
6310
- import_fp_ts15.array.map((utxo) => parsePollShardOrThrow(getInlineDatumOrThrow(utxo))),
6311
- import_fp_ts15.array.reduce(
6357
+ import_fp_ts17.array.map((utxo) => parsePollShardOrThrow(getInlineDatumOrThrow(utxo))),
6358
+ import_fp_ts17.array.reduce(
6312
6359
  pollManagerDatum.status,
6313
6360
  (acc, shard) => ({
6314
6361
  yesVotes: acc.yesVotes + shard.status.yesVotes,
@@ -6316,9 +6363,9 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
6316
6363
  })
6317
6364
  )
6318
6365
  );
6319
- const shardsAggregatedAda = import_fp_ts15.array.reduce(
6366
+ const shardsAggregatedAda = import_fp_ts17.array.reduce(
6320
6367
  {},
6321
- (acc, utxo) => (0, import_lucid25.addAssets)(acc, (0, import_cardano_offchain_common16.mkLovelacesOf)((0, import_cardano_offchain_common16.lovelacesAmt)(utxo.assets)))
6368
+ (acc, utxo) => (0, import_lucid25.addAssets)(acc, (0, import_cardano_offchain_common17.mkLovelacesOf)((0, import_cardano_offchain_common17.lovelacesAmt)(utxo.assets)))
6322
6369
  )(shardUtxos);
6323
6370
  const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
6324
6371
  return lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
@@ -6327,7 +6374,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
6327
6374
  pollShardRefScriptUtxo,
6328
6375
  pollManagerRefScriptUtxo,
6329
6376
  pollAuthTokenPolicyRefScriptUtxo
6330
- ]).mintAssets((0, import_cardano_offchain_common16.mkAssetsOf)(pollNft, -BigInt(shardsOutRefs.length)), import_lucid26.Data.void()).collectFrom(
6377
+ ]).mintAssets((0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, -BigInt(shardsOutRefs.length)), import_lucid26.Data.void()).collectFrom(
6331
6378
  [pollManagerUtxo],
6332
6379
  serialisePollManagerRedeemer({
6333
6380
  MergeShardsManager: { currentTime }
@@ -6416,7 +6463,7 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
6416
6463
  govDatum.protocolParams.electorate,
6417
6464
  pollManager.minimumQuorum
6418
6465
  );
6419
- const upgradeTokenVal = (0, import_cardano_offchain_common16.mkAssetsOf)(
6466
+ const upgradeTokenVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
6420
6467
  fromSystemParamsAsset(sysParams.govParams.upgradeToken),
6421
6468
  1n
6422
6469
  );
@@ -6433,7 +6480,7 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
6433
6480
  ).collectFrom(
6434
6481
  [govUtxo],
6435
6482
  serialiseGovRedeemer({ WitnessEndPoll: { currentTime } })
6436
- ).mintAssets((0, import_cardano_offchain_common16.mkAssetsOf)(pollNft, -1n), import_lucid26.Data.void()).pay.ToContract(
6483
+ ).mintAssets((0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, -1n), import_lucid26.Data.void()).pay.ToContract(
6437
6484
  govUtxo.address,
6438
6485
  {
6439
6486
  kind: "inline",
@@ -6464,9 +6511,9 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
6464
6511
  tx.pay.ToContract(
6465
6512
  createScriptAddress(network, sysParams.validatorHashes.treasuryHash),
6466
6513
  { kind: "inline", value: import_lucid26.Data.void() },
6467
- (0, import_cardano_offchain_common16.mkAssetsOf)(
6514
+ (0, import_cardano_offchain_common17.mkAssetsOf)(
6468
6515
  indyAsset,
6469
- (0, import_cardano_offchain_common16.assetClassValueOf)(pollManagerUtxo.assets, indyAsset)
6516
+ (0, import_cardano_offchain_common17.assetClassValueOf)(pollManagerUtxo.assets, indyAsset)
6470
6517
  )
6471
6518
  );
6472
6519
  }
@@ -6512,8 +6559,8 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6512
6559
  );
6513
6560
  const tx = lucid.newTx();
6514
6561
  await (0, import_function2.pipe)(
6515
- import_fp_ts15.option.fromNullable(executeDatum.treasuryWithdrawal),
6516
- import_fp_ts15.option.match(
6562
+ import_fp_ts17.option.fromNullable(executeDatum.treasuryWithdrawal),
6563
+ import_fp_ts17.option.match(
6517
6564
  () => {
6518
6565
  if (treasuryWithdrawalOref) {
6519
6566
  throw new Error("Cannot provide withdrawal oref when no withdrawal.");
@@ -6539,9 +6586,9 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6539
6586
  const withdrawalVal = createValueFromWithdrawal(withdrawal);
6540
6587
  const withdrawalChangeVal = (0, import_lucid25.addAssets)(
6541
6588
  treasuryWithdrawalUtxo.assets,
6542
- (0, import_cardano_offchain_common16.negateAssets)(withdrawalVal)
6589
+ (0, import_cardano_offchain_common17.negateAssets)(withdrawalVal)
6543
6590
  );
6544
- if (!(0, import_cardano_offchain_common16.isAssetsZero)(withdrawalChangeVal)) {
6591
+ if (!(0, import_cardano_offchain_common17.isAssetsZero)(withdrawalChangeVal)) {
6545
6592
  tx.pay.ToContract(
6546
6593
  createScriptAddress(
6547
6594
  network,
@@ -6558,7 +6605,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6558
6605
  [treasuryWithdrawalUtxo],
6559
6606
  serialiseTreasuryRedeemer("Withdraw")
6560
6607
  ).pay.ToAddressWithData(
6561
- (0, import_cardano_offchain_common17.addressToBech32)(withdrawal.destination, lucid.config().network),
6608
+ (0, import_cardano_offchain_common18.addressToBech32)(withdrawal.destination, lucid.config().network),
6562
6609
  {
6563
6610
  kind: "inline",
6564
6611
  value: serialiseWithdrawalOutputDatum([
@@ -6611,16 +6658,16 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6611
6658
  );
6612
6659
  const { newIAsset, newReferencedIAsset } = iassetCreationDatumHelper(
6613
6660
  proposeContent,
6614
- import_fp_ts15.function.pipe(
6661
+ import_fp_ts17.function.pipe(
6615
6662
  iassetToReference,
6616
- import_fp_ts15.option.map((i) => i.datum)
6663
+ import_fp_ts17.option.map((i) => i.datum)
6617
6664
  )
6618
6665
  );
6619
- const iassetAuthVal = (0, import_cardano_offchain_common16.mkAssetsOf)(
6666
+ const iassetAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
6620
6667
  fromSystemParamsAsset(sysParams.executeParams.iAssetToken),
6621
6668
  1n
6622
6669
  );
6623
- const spAuthVal = (0, import_cardano_offchain_common16.mkAssetsOf)(
6670
+ const spAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
6624
6671
  fromSystemParamsAsset(sysParams.executeParams.stabilityPoolToken),
6625
6672
  1n
6626
6673
  );
@@ -6666,14 +6713,14 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6666
6713
  },
6667
6714
  spAuthVal
6668
6715
  );
6669
- import_fp_ts15.function.pipe(
6716
+ import_fp_ts17.function.pipe(
6670
6717
  iassetToReference,
6671
- import_fp_ts15.option.match(
6718
+ import_fp_ts17.option.match(
6672
6719
  () => {
6673
6720
  },
6674
- (i) => import_fp_ts15.function.pipe(
6721
+ (i) => import_fp_ts17.function.pipe(
6675
6722
  newReferencedIAsset,
6676
- import_fp_ts15.option.match(
6723
+ import_fp_ts17.option.match(
6677
6724
  () => {
6678
6725
  throw new Error("Expected some referenced iasset.");
6679
6726
  },
@@ -6791,12 +6838,12 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6791
6838
  );
6792
6839
  const { newCollateralAsset, newReferencedCollateralAsset } = collateralAssetCreationDatumHelper(
6793
6840
  addCollateralContent,
6794
- import_fp_ts15.function.pipe(
6841
+ import_fp_ts17.function.pipe(
6795
6842
  collateralAssetToReference,
6796
- import_fp_ts15.option.map((i) => i.datum)
6843
+ import_fp_ts17.option.map((i) => i.datum)
6797
6844
  )
6798
6845
  );
6799
- const collateralAssetAuthVal = (0, import_cardano_offchain_common16.mkAssetsOf)(
6846
+ const collateralAssetAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
6800
6847
  fromSystemParamsAsset(sysParams.executeParams.collateralAssetToken),
6801
6848
  1n
6802
6849
  );
@@ -6838,15 +6885,15 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6838
6885
  },
6839
6886
  collateralAssetAuthVal
6840
6887
  );
6841
- import_fp_ts15.function.pipe(
6888
+ import_fp_ts17.function.pipe(
6842
6889
  collateralAssetToReference,
6843
- import_fp_ts15.option.match(
6890
+ import_fp_ts17.option.match(
6844
6891
  () => {
6845
6892
  },
6846
6893
  (i) => {
6847
- import_fp_ts15.function.pipe(
6894
+ import_fp_ts17.function.pipe(
6848
6895
  newReferencedCollateralAsset,
6849
- import_fp_ts15.option.match(
6896
+ import_fp_ts17.option.match(
6850
6897
  () => {
6851
6898
  throw new Error("Expected some referenced collateral asset");
6852
6899
  },
@@ -6878,15 +6925,15 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6878
6925
  }
6879
6926
  )
6880
6927
  );
6881
- if (!(0, import_cardano_offchain_common16.isSameAssetClass)(newCollateralAsset.collateralAsset, import_cardano_offchain_common16.adaAssetClass)) {
6882
- import_fp_ts15.function.pipe(
6928
+ if (!(0, import_cardano_offchain_common17.isSameAssetClass)(newCollateralAsset.collateralAsset, import_cardano_offchain_common17.adaAssetClass)) {
6929
+ import_fp_ts17.function.pipe(
6883
6930
  newReferencedCollateralAsset,
6884
- import_fp_ts15.option.match(
6931
+ import_fp_ts17.option.match(
6885
6932
  () => {
6886
6933
  },
6887
- (referencedAsset) => referencedAsset.firstCollateralAsset ? {} : import_fp_ts15.function.pipe(
6934
+ (referencedAsset) => referencedAsset.firstCollateralAsset ? {} : import_fp_ts17.function.pipe(
6888
6935
  firstCollateralAsset,
6889
- import_fp_ts15.option.match(
6936
+ import_fp_ts17.option.match(
6890
6937
  () => {
6891
6938
  },
6892
6939
  (firstAsset) => {
@@ -6920,7 +6967,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6920
6967
  const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
6921
6968
  getInlineDatumOrThrow(collateralAssetUtxo)
6922
6969
  );
6923
- if (!(0, import_cardano_offchain_common16.isSameAssetClass)(
6970
+ if (!(0, import_cardano_offchain_common17.isSameAssetClass)(
6924
6971
  collateralAssetDatum.collateralAsset,
6925
6972
  updateCollateralContent.collateralAsset
6926
6973
  ) || (0, import_lucid25.toHex)(collateralAssetDatum.iasset) !== (0, import_lucid25.toHex)(updateCollateralContent.correspondingIAsset)) {
@@ -6981,7 +7028,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
6981
7028
  await lucid.utxosByOutRef([iAssetOref]),
6982
7029
  (_) => new Error("Expected a single iasset UTXO")
6983
7030
  );
6984
- const cdpAuthVal = (0, import_cardano_offchain_common16.mkAssetsOf)(
7031
+ const cdpAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
6985
7032
  fromSystemParamsAsset(sysParams.executeParams.cdpToken),
6986
7033
  1n
6987
7034
  );
@@ -7099,7 +7146,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
7099
7146
  "Expected a single version record token policy ref Script UTXO"
7100
7147
  )
7101
7148
  );
7102
- const versionRecordNftVal = (0, import_cardano_offchain_common16.mkAssetsOf)(
7149
+ const versionRecordNftVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
7103
7150
  fromSystemParamsAsset(sysParams.executeParams.versionRecordToken),
7104
7151
  1n
7105
7152
  );
@@ -7135,7 +7182,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
7135
7182
  tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(
7136
7183
  Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
7137
7184
  ).collectFrom([executeUtxo], import_lucid26.Data.void()).mintAssets(
7138
- (0, import_cardano_offchain_common16.mkAssetsOf)(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
7185
+ (0, import_cardano_offchain_common17.mkAssetsOf)(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
7139
7186
  import_lucid26.Data.void()
7140
7187
  ).addSigner(ownAddr).setMinFee(922932n);
7141
7188
  return tx;
@@ -7205,7 +7252,7 @@ var mkGovValidatorFromSP = (params) => {
7205
7252
 
7206
7253
  // src/contracts/stability-pool/transactions.ts
7207
7254
  var import_lucid29 = require("@lucid-evolution/lucid");
7208
- var import_cardano_offchain_common18 = require("@3rd-eye-labs/cardano-offchain-common");
7255
+ var import_cardano_offchain_common19 = require("@3rd-eye-labs/cardano-offchain-common");
7209
7256
  var import_ts_pattern18 = require("ts-pattern");
7210
7257
  async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
7211
7258
  const [pkh, _skh] = await addrDetails(lucid);
@@ -7240,8 +7287,8 @@ async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
7240
7287
  value: serialiseStabilityPoolDatum({ Account: datum })
7241
7288
  },
7242
7289
  (0, import_lucid29.addAssets)(
7243
- (0, import_cardano_offchain_common18.mkAssetsOf)(iassetAssetClass, amount),
7244
- (0, import_cardano_offchain_common18.mkLovelacesOf)(
7290
+ (0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, amount),
7291
+ (0, import_cardano_offchain_common19.mkLovelacesOf)(
7245
7292
  // TODO: Calculate a more accurate amount to just cover costs.
7246
7293
  // This should cover the account creation fee,
7247
7294
  // the minimum ADA for the account UTxO and the transaction fee.
@@ -7252,7 +7299,7 @@ async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
7252
7299
  }
7253
7300
  async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid) {
7254
7301
  const myAddress = await lucid.wallet().address();
7255
- const stabilityPoolScriptRef = (0, import_cardano_offchain_common18.matchSingle)(
7302
+ const stabilityPoolScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
7256
7303
  await lucid.utxosByOutRef([
7257
7304
  fromSystemParamsScriptRef(
7258
7305
  sysParams.scriptReferences.stabilityPoolValidatorRef
@@ -7268,7 +7315,7 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
7268
7315
  request: {
7269
7316
  Adjust: {
7270
7317
  amount,
7271
- outputAddress: (0, import_cardano_offchain_common18.addressFromBech32)(myAddress)
7318
+ outputAddress: (0, import_cardano_offchain_common19.addressFromBech32)(myAddress)
7272
7319
  }
7273
7320
  }
7274
7321
  };
@@ -7278,7 +7325,7 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
7278
7325
  RequestAction: {
7279
7326
  Adjust: {
7280
7327
  amount,
7281
- outputAddress: (0, import_cardano_offchain_common18.addressFromBech32)(myAddress)
7328
+ outputAddress: (0, import_cardano_offchain_common19.addressFromBech32)(myAddress)
7282
7329
  }
7283
7330
  }
7284
7331
  })
@@ -7291,17 +7338,17 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
7291
7338
  })
7292
7339
  },
7293
7340
  (0, import_lucid29.addAssets)(
7294
- (0, import_cardano_offchain_common18.mkLovelacesOf)(
7341
+ (0, import_cardano_offchain_common19.mkLovelacesOf)(
7295
7342
  // TODO: Calculate a more accurate amount to just cover costs.
7296
7343
  // This should cover the minimum ADA for 2 UTxOs (account and
7297
7344
  // rewards withdrawal) and the transaction fee.
7298
7345
  5000000n
7299
7346
  ),
7300
- (0, import_cardano_offchain_common18.mkAssetsOf)(
7347
+ (0, import_cardano_offchain_common19.mkAssetsOf)(
7301
7348
  fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
7302
7349
  1n
7303
7350
  ),
7304
- amount > 0n ? (0, import_cardano_offchain_common18.mkAssetsOf)(
7351
+ amount > 0n ? (0, import_cardano_offchain_common19.mkAssetsOf)(
7305
7352
  {
7306
7353
  currencySymbol: (0, import_lucid29.fromHex)(
7307
7354
  sysParams.stabilityPoolParams.assetSymbol.unCurrencySymbol
@@ -7315,7 +7362,7 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
7315
7362
  }
7316
7363
  async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee = BASE_MAX_TX_FEE) {
7317
7364
  const myAddress = await lucid.wallet().address();
7318
- const stabilityPoolScriptRef = (0, import_cardano_offchain_common18.matchSingle)(
7365
+ const stabilityPoolScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
7319
7366
  await lucid.utxosByOutRef([
7320
7367
  fromSystemParamsScriptRef(
7321
7368
  sysParams.scriptReferences.stabilityPoolValidatorRef
@@ -7325,7 +7372,7 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
7325
7372
  );
7326
7373
  const request = {
7327
7374
  Close: {
7328
- outputAddress: (0, import_cardano_offchain_common18.addressFromBech32)(myAddress),
7375
+ outputAddress: (0, import_cardano_offchain_common19.addressFromBech32)(myAddress),
7329
7376
  maxTxFee
7330
7377
  }
7331
7378
  };
@@ -7346,12 +7393,12 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
7346
7393
  value: serialiseStabilityPoolDatum({ Account: newAccountDatum })
7347
7394
  },
7348
7395
  (0, import_lucid29.addAssets)(
7349
- (0, import_cardano_offchain_common18.mkLovelacesOf)(
7396
+ (0, import_cardano_offchain_common19.mkLovelacesOf)(
7350
7397
  // TODO: Calculate a more accurate amount to just cover costs.
7351
7398
  // This should cover the minimum ADA for the rewards UTxO and the transaction fee.
7352
7399
  3000000n
7353
7400
  ),
7354
- (0, import_cardano_offchain_common18.mkAssetsOf)(
7401
+ (0, import_cardano_offchain_common19.mkAssetsOf)(
7355
7402
  fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
7356
7403
  1n
7357
7404
  )
@@ -7361,7 +7408,7 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
7361
7408
  async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot, txFee) {
7362
7409
  const network = lucid.config().network;
7363
7410
  const currentTime = BigInt((0, import_lucid29.slotToUnixTime)(network, currentSlot));
7364
- const stabilityPoolScriptRef = (0, import_cardano_offchain_common18.matchSingle)(
7411
+ const stabilityPoolScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
7365
7412
  await lucid.utxosByOutRef([
7366
7413
  fromSystemParamsScriptRef(
7367
7414
  sysParams.scriptReferences.stabilityPoolValidatorRef
@@ -7395,7 +7442,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7395
7442
  tokenName: stabilityPoolDatum.iasset
7396
7443
  };
7397
7444
  await (0, import_ts_pattern18.match)(accountDatum.request).with("Create", async (_) => {
7398
- const accountTokenScriptRef = (0, import_cardano_offchain_common18.matchSingle)(
7445
+ const accountTokenScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
7399
7446
  await lucid.utxosByOutRef([
7400
7447
  fromSystemParamsScriptRef(
7401
7448
  sysParams.scriptReferences.authTokenPolicies.accountTokenRef
@@ -7403,7 +7450,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7403
7450
  ]),
7404
7451
  (_2) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
7405
7452
  );
7406
- const requestDepositAmt = (0, import_cardano_offchain_common18.assetClassValueOf)(
7453
+ const requestDepositAmt = (0, import_cardano_offchain_common19.assetClassValueOf)(
7407
7454
  accountUtxo.assets,
7408
7455
  iassetAssetClass
7409
7456
  );
@@ -7417,8 +7464,8 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7417
7464
  sysParams.stabilityPoolParams.stakeCredential
7418
7465
  ) : void 0
7419
7466
  );
7420
- const accountOutputAdaAmt = (0, import_cardano_offchain_common18.lovelacesAmt)(accountUtxo.assets) - BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces) - txFee;
7421
- const accountTokenVal = (0, import_cardano_offchain_common18.mkAssetsOf)(
7467
+ const accountOutputAdaAmt = (0, import_cardano_offchain_common19.lovelacesAmt)(accountUtxo.assets) - BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces) - txFee;
7468
+ const accountTokenVal = (0, import_cardano_offchain_common19.mkAssetsOf)(
7422
7469
  fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
7423
7470
  1n
7424
7471
  );
@@ -7438,7 +7485,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7438
7485
  lastRequestProcessingTime: currentTime
7439
7486
  }
7440
7487
  });
7441
- const accountOutMinUtxoLovelace = (0, import_cardano_offchain_common18.estimateUtxoMinLovelace)(
7488
+ const accountOutMinUtxoLovelace = (0, import_cardano_offchain_common19.estimateUtxoMinLovelace)(
7442
7489
  lucid.config().protocolParameters,
7443
7490
  poolAddr,
7444
7491
  accountTokenVal,
@@ -7474,7 +7521,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7474
7521
  )
7475
7522
  }
7476
7523
  },
7477
- import_cardano_offchain_common18.adaAssetClass,
7524
+ import_cardano_offchain_common19.adaAssetClass,
7478
7525
  0n,
7479
7526
  BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
7480
7527
  )
@@ -7482,8 +7529,8 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7482
7529
  },
7483
7530
  (0, import_lucid29.addAssets)(
7484
7531
  stabilityPoolUtxo.assets,
7485
- (0, import_cardano_offchain_common18.mkAssetsOf)(iassetAssetClass, requestDepositAmt),
7486
- (0, import_cardano_offchain_common18.mkLovelacesOf)(
7532
+ (0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, requestDepositAmt),
7533
+ (0, import_cardano_offchain_common19.mkLovelacesOf)(
7487
7534
  BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
7488
7535
  )
7489
7536
  )
@@ -7493,14 +7540,14 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7493
7540
  kind: "inline",
7494
7541
  value: accountOutputDatum
7495
7542
  },
7496
- (0, import_lucid29.addAssets)(accountTokenVal, (0, import_cardano_offchain_common18.mkLovelacesOf)(accountOutputAdaAmt))
7543
+ (0, import_lucid29.addAssets)(accountTokenVal, (0, import_cardano_offchain_common19.mkLovelacesOf)(accountOutputAdaAmt))
7497
7544
  ).setMinFee(txFee);
7498
7545
  }).with({ Adjust: import_ts_pattern18.P.select() }, async (adjustContent) => {
7499
7546
  const iassetDatum = parseIAssetDatumOrThrow(
7500
7547
  getInlineDatumOrThrow(iAssetUtxo)
7501
7548
  );
7502
7549
  const accountDepositChange = adjustContent.amount;
7503
- const outputAddress = (0, import_cardano_offchain_common18.addressToBech32)(
7550
+ const outputAddress = (0, import_cardano_offchain_common19.addressToBech32)(
7504
7551
  adjustContent.outputAddress,
7505
7552
  lucid.config().network
7506
7553
  );
@@ -7566,13 +7613,13 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7566
7613
  },
7567
7614
  (0, import_lucid29.addAssets)(
7568
7615
  stabilityPoolUtxo.assets,
7569
- (0, import_cardano_offchain_common18.negateAssets)(reward),
7570
- (0, import_cardano_offchain_common18.mkAssetsOf)(iassetAssetClass, accountBalanceChange + withdrawalFeeAmt)
7616
+ (0, import_cardano_offchain_common19.negateAssets)(reward),
7617
+ (0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, accountBalanceChange + withdrawalFeeAmt)
7571
7618
  )
7572
7619
  );
7573
7620
  const theoreticalOwnerOutputVal = (0, import_lucid29.addAssets)(
7574
7621
  reward,
7575
- isDepositOrRewardWithdrawal ? {} : (0, import_cardano_offchain_common18.mkAssetsOf)(
7622
+ isDepositOrRewardWithdrawal ? {} : (0, import_cardano_offchain_common19.mkAssetsOf)(
7576
7623
  iassetAssetClass,
7577
7624
  -accountBalanceChange - withdrawalFeeAmt
7578
7625
  )
@@ -7583,16 +7630,16 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7583
7630
  outputIndex: BigInt(accountUtxo.outputIndex)
7584
7631
  }
7585
7632
  });
7586
- const ownerOutputMinUtxoLovelace = (0, import_cardano_offchain_common18.estimateUtxoMinLovelace)(
7633
+ const ownerOutputMinUtxoLovelace = (0, import_cardano_offchain_common19.estimateUtxoMinLovelace)(
7587
7634
  lucid.config().protocolParameters,
7588
7635
  outputAddress,
7589
7636
  theoreticalOwnerOutputVal,
7590
7637
  { InlineDatum: { datum: ownerOutputDat } }
7591
7638
  );
7592
- const extraOwnerOutputLovelacesAmt = (0, import_cardano_offchain_common18.lovelacesAmt)(theoreticalOwnerOutputVal) >= ownerOutputMinUtxoLovelace ? 0n : ownerOutputMinUtxoLovelace - (0, import_cardano_offchain_common18.lovelacesAmt)(theoreticalOwnerOutputVal);
7639
+ const extraOwnerOutputLovelacesAmt = (0, import_cardano_offchain_common19.lovelacesAmt)(theoreticalOwnerOutputVal) >= ownerOutputMinUtxoLovelace ? 0n : ownerOutputMinUtxoLovelace - (0, import_cardano_offchain_common19.lovelacesAmt)(theoreticalOwnerOutputVal);
7593
7640
  const actualOwnerOutputVal = (0, import_lucid29.addAssets)(
7594
7641
  theoreticalOwnerOutputVal,
7595
- (0, import_cardano_offchain_common18.mkLovelacesOf)(extraOwnerOutputLovelacesAmt)
7642
+ (0, import_cardano_offchain_common19.mkLovelacesOf)(extraOwnerOutputLovelacesAmt)
7596
7643
  );
7597
7644
  const accountOutputDat = serialiseStabilityPoolDatum({
7598
7645
  Account: {
@@ -7608,17 +7655,17 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7608
7655
  lastRequestProcessingTime: currentTime
7609
7656
  }
7610
7657
  });
7611
- const accountOutputValWithoutAda = (0, import_cardano_offchain_common18.mkAssetsOf)(
7658
+ const accountOutputValWithoutAda = (0, import_cardano_offchain_common19.mkAssetsOf)(
7612
7659
  fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
7613
7660
  1n
7614
7661
  );
7615
- const accountOutMinUtxoLovelace = (0, import_cardano_offchain_common18.estimateUtxoMinLovelace)(
7662
+ const accountOutMinUtxoLovelace = (0, import_cardano_offchain_common19.estimateUtxoMinLovelace)(
7616
7663
  lucid.config().protocolParameters,
7617
7664
  stabilityPoolUtxo.address,
7618
7665
  accountOutputValWithoutAda,
7619
7666
  { InlineDatum: { datum: accountOutputDat } }
7620
7667
  );
7621
- const accountOutputAdaAmt = (0, import_cardano_offchain_common18.lovelacesAmt)(accountUtxo.assets) - extraOwnerOutputLovelacesAmt - txFee;
7668
+ const accountOutputAdaAmt = (0, import_cardano_offchain_common19.lovelacesAmt)(accountUtxo.assets) - extraOwnerOutputLovelacesAmt - txFee;
7622
7669
  if (accountOutputAdaAmt < accountOutMinUtxoLovelace) {
7623
7670
  throw new Error("Account doesn't have enough ADA to be processed.");
7624
7671
  }
@@ -7630,7 +7677,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7630
7677
  },
7631
7678
  (0, import_lucid29.addAssets)(
7632
7679
  accountOutputValWithoutAda,
7633
- (0, import_cardano_offchain_common18.mkLovelacesOf)(accountOutputAdaAmt)
7680
+ (0, import_cardano_offchain_common19.mkLovelacesOf)(accountOutputAdaAmt)
7634
7681
  )
7635
7682
  ).pay.ToAddressWithData(
7636
7683
  outputAddress,
@@ -7644,7 +7691,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7644
7691
  if (txFee > closeContent.maxTxFee) {
7645
7692
  throw new Error("Account doesn't allow current transaction fee.");
7646
7693
  }
7647
- const accountTokenScriptRef = (0, import_cardano_offchain_common18.matchSingle)(
7694
+ const accountTokenScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
7648
7695
  await lucid.utxosByOutRef([
7649
7696
  fromSystemParamsScriptRef(
7650
7697
  sysParams.scriptReferences.authTokenPolicies.accountTokenRef
@@ -7655,7 +7702,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7655
7702
  const iassetDatum = parseIAssetDatumOrThrow(
7656
7703
  getInlineDatumOrThrow(iAssetUtxo)
7657
7704
  );
7658
- const outputAddress = (0, import_cardano_offchain_common18.addressToBech32)(
7705
+ const outputAddress = (0, import_cardano_offchain_common19.addressToBech32)(
7659
7706
  closeContent.outputAddress,
7660
7707
  lucid.config().network
7661
7708
  );
@@ -7707,7 +7754,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7707
7754
  });
7708
7755
  }
7709
7756
  }).mintAssets(
7710
- (0, import_cardano_offchain_common18.mkAssetsOf)(
7757
+ (0, import_cardano_offchain_common19.mkAssetsOf)(
7711
7758
  fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
7712
7759
  -1n
7713
7760
  ),
@@ -7725,8 +7772,8 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7725
7772
  },
7726
7773
  (0, import_lucid29.addAssets)(
7727
7774
  stabilityPoolUtxo.assets,
7728
- (0, import_cardano_offchain_common18.negateAssets)(reward),
7729
- (0, import_cardano_offchain_common18.mkAssetsOf)(iassetAssetClass, -withdrawnAmt + withdrawalFeeAmt)
7775
+ (0, import_cardano_offchain_common19.negateAssets)(reward),
7776
+ (0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, -withdrawnAmt + withdrawalFeeAmt)
7730
7777
  )
7731
7778
  ).pay.ToAddressWithData(
7732
7779
  outputAddress,
@@ -7740,9 +7787,9 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
7740
7787
  })
7741
7788
  },
7742
7789
  (0, import_lucid29.addAssets)(
7743
- (0, import_cardano_offchain_common18.mkLovelacesOf)((0, import_cardano_offchain_common18.lovelacesAmt)(accountUtxo.assets) - txFee),
7790
+ (0, import_cardano_offchain_common19.mkLovelacesOf)((0, import_cardano_offchain_common19.lovelacesAmt)(accountUtxo.assets) - txFee),
7744
7791
  reward,
7745
- (0, import_cardano_offchain_common18.mkAssetsOf)(iassetAssetClass, withdrawnAmt - withdrawalFeeAmt)
7792
+ (0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, withdrawnAmt - withdrawalFeeAmt)
7746
7793
  )
7747
7794
  ).setMinFee(txFee);
7748
7795
  }).exhaustive();
@@ -7773,7 +7820,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
7773
7820
  );
7774
7821
  }
7775
7822
  async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
7776
- const stabilityPoolRefScriptUtxo = (0, import_cardano_offchain_common18.matchSingle)(
7823
+ const stabilityPoolRefScriptUtxo = (0, import_cardano_offchain_common19.matchSingle)(
7777
7824
  await lucid.utxosByOutRef([
7778
7825
  fromSystemParamsScriptRef(
7779
7826
  sysParams.scriptReferences.stabilityPoolValidatorRef
@@ -7781,7 +7828,7 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
7781
7828
  ]),
7782
7829
  (_) => new Error("Expected a single stability pool Ref Script UTXO")
7783
7830
  );
7784
- const snapshotE2s2sPolicyRefScriptUtxo = (0, import_cardano_offchain_common18.matchSingle)(
7831
+ const snapshotE2s2sPolicyRefScriptUtxo = (0, import_cardano_offchain_common19.matchSingle)(
7785
7832
  await lucid.utxosByOutRef([
7786
7833
  fromSystemParamsScriptRef(
7787
7834
  sysParams.scriptReferences.authTokenPolicies.snapshotEpochToScaleToSumTokenRef
@@ -7789,7 +7836,7 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
7789
7836
  ]),
7790
7837
  (_) => new Error("Expected a single snapshot e2s2s policy Ref Script UTXO")
7791
7838
  );
7792
- const spUtxo = (0, import_cardano_offchain_common18.matchSingle)(
7839
+ const spUtxo = (0, import_cardano_offchain_common19.matchSingle)(
7793
7840
  await lucid.utxosByOutRef([stabilityPoolOref]),
7794
7841
  (_) => new Error("Expected a single stability pool UTXO")
7795
7842
  );
@@ -7805,7 +7852,7 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
7805
7852
  [spUtxo],
7806
7853
  serialiseStabilityPoolRedeemer("RecordEpochToScaleToSum")
7807
7854
  ).mintAssets(
7808
- (0, import_cardano_offchain_common18.mkAssetsOf)(snapshotAc, BigInt(newSnapshotDatums.length)),
7855
+ (0, import_cardano_offchain_common19.mkAssetsOf)(snapshotAc, BigInt(newSnapshotDatums.length)),
7809
7856
  import_lucid29.Data.void()
7810
7857
  ).pay.ToContract(
7811
7858
  spUtxo.address,
@@ -7826,13 +7873,13 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
7826
7873
  SnapshotEpochToScaleToSum: newDatum
7827
7874
  })
7828
7875
  },
7829
- (0, import_cardano_offchain_common18.mkAssetsOf)(snapshotAc, 1n)
7876
+ (0, import_cardano_offchain_common19.mkAssetsOf)(snapshotAc, 1n)
7830
7877
  );
7831
7878
  }
7832
7879
  return tx;
7833
7880
  }
7834
7881
  async function annulRequest(accountUtxo, params, lucid) {
7835
- const stabilityPoolRefScriptUtxo = (0, import_cardano_offchain_common18.matchSingle)(
7882
+ const stabilityPoolRefScriptUtxo = (0, import_cardano_offchain_common19.matchSingle)(
7836
7883
  await lucid.utxosByOutRef([
7837
7884
  fromSystemParamsScriptRef(
7838
7885
  params.scriptReferences.stabilityPoolValidatorRef
@@ -7856,7 +7903,7 @@ async function annulRequest(accountUtxo, params, lucid) {
7856
7903
  }
7857
7904
  })
7858
7905
  },
7859
- (0, import_cardano_offchain_common18.mkAssetsOf)(
7906
+ (0, import_cardano_offchain_common19.mkAssetsOf)(
7860
7907
  fromSystemParamsAsset(params.stabilityPoolParams.accountToken),
7861
7908
  1n
7862
7909
  )
@@ -7867,7 +7914,7 @@ async function annulRequest(accountUtxo, params, lucid) {
7867
7914
 
7868
7915
  // src/contracts/staking/transactions.ts
7869
7916
  var import_lucid30 = require("@lucid-evolution/lucid");
7870
- var import_cardano_offchain_common19 = require("@3rd-eye-labs/cardano-offchain-common");
7917
+ var import_cardano_offchain_common20 = require("@3rd-eye-labs/cardano-offchain-common");
7871
7918
  async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
7872
7919
  const [pkh, _] = await addrDetails(lucid);
7873
7920
  const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
@@ -7947,7 +7994,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
7947
7994
  const adaReward = calculateAdaReward(
7948
7995
  stakingManagerOut.datum.managerSnapshot.snapshotAda,
7949
7996
  stakingPositionOut.datum.positionSnapshot.snapshotAda,
7950
- (0, import_cardano_offchain_common19.assetClassValueOf)(stakingPositionOut.utxo.assets, indyToken)
7997
+ (0, import_cardano_offchain_common20.assetClassValueOf)(stakingPositionOut.utxo.assets, indyToken)
7951
7998
  );
7952
7999
  const newLockedAmount = updateStakingLockedAmount(
7953
8000
  stakingPositionOut.datum.lockedAmount,
@@ -7970,7 +8017,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
7970
8017
  totalStake: stakingManagerOut.datum.totalStake + amount
7971
8018
  })
7972
8019
  },
7973
- (0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0, import_cardano_offchain_common19.mkLovelacesOf)(-adaReward))
8020
+ (0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0, import_cardano_offchain_common20.mkLovelacesOf)(-adaReward))
7974
8021
  ).pay.ToContract(
7975
8022
  stakingPositionOut.utxo.address,
7976
8023
  {
@@ -7983,7 +8030,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
7983
8030
  lockedAmount: newLockedAmount
7984
8031
  })
7985
8032
  },
7986
- (0, import_lucid30.addAssets)(stakingPositionOut.utxo.assets, (0, import_cardano_offchain_common19.mkAssetsOf)(indyToken, amount))
8033
+ (0, import_lucid30.addAssets)(stakingPositionOut.utxo.assets, (0, import_cardano_offchain_common20.mkAssetsOf)(indyToken, amount))
7987
8034
  ).addSignerKey((0, import_lucid30.toHex)(stakingPositionOut.datum.owner));
7988
8035
  }
7989
8036
  async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
@@ -8009,14 +8056,14 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
8009
8056
  (_) => new Error("Expected a single staking token policy Ref Script UTXO")
8010
8057
  );
8011
8058
  const indyToken = fromSystemParamsAsset(params.stakingParams.indyToken);
8012
- const existingIndyAmount = (0, import_cardano_offchain_common19.assetClassValueOf)(
8059
+ const existingIndyAmount = (0, import_cardano_offchain_common20.assetClassValueOf)(
8013
8060
  stakingPositionOut.utxo.assets,
8014
8061
  indyToken
8015
8062
  );
8016
8063
  const adaReward = calculateAdaReward(
8017
8064
  stakingManagerOut.datum.managerSnapshot.snapshotAda,
8018
8065
  stakingPositionOut.datum.positionSnapshot.snapshotAda,
8019
- (0, import_cardano_offchain_common19.assetClassValueOf)(stakingPositionOut.utxo.assets, indyToken)
8066
+ (0, import_cardano_offchain_common20.assetClassValueOf)(stakingPositionOut.utxo.assets, indyToken)
8020
8067
  );
8021
8068
  return lucid.newTx().validFrom(Number(now)).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
8022
8069
  [stakingManagerOut.utxo],
@@ -8030,9 +8077,9 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
8030
8077
  totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
8031
8078
  })
8032
8079
  },
8033
- (0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0, import_cardano_offchain_common19.mkLovelacesOf)(-adaReward))
8080
+ (0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0, import_cardano_offchain_common20.mkLovelacesOf)(-adaReward))
8034
8081
  ).mintAssets(
8035
- (0, import_cardano_offchain_common19.mkAssetsOf)(fromSystemParamsAsset(params.stakingParams.stakingToken), -1n),
8082
+ (0, import_cardano_offchain_common20.mkAssetsOf)(fromSystemParamsAsset(params.stakingParams.stakingToken), -1n),
8036
8083
  import_lucid30.Data.void()
8037
8084
  ).addSignerKey((0, import_lucid30.toHex)(stakingPositionOut.datum.owner));
8038
8085
  }
@@ -8040,7 +8087,7 @@ var MIN_UTXO_AMOUNT = 2000000n;
8040
8087
  async function distributeAda(stakingManagerRef, collectorRefs, params, lucid) {
8041
8088
  const [stakingManagerUtxo] = await lucid.utxosByOutRef([stakingManagerRef]);
8042
8089
  const stakingManagerDatum = parseStakingManagerDatum(
8043
- (0, import_cardano_offchain_common19.getInlineDatumOrThrow)(stakingManagerUtxo)
8090
+ (0, import_cardano_offchain_common20.getInlineDatumOrThrow)(stakingManagerUtxo)
8044
8091
  );
8045
8092
  const collectorUtxos = (await lucid.utxosByOutRef(collectorRefs)).filter((utxo) => utxo.datum && utxo.datum === import_lucid30.Data.void()).filter((utxo) => utxo.assets["lovelace"] > MIN_UTXO_AMOUNT);
8046
8093
  if (collectorUtxos.length === 0) {
@@ -8079,13 +8126,13 @@ async function distributeAda(stakingManagerRef, collectorRefs, params, lucid) {
8079
8126
  managerSnapshot: { snapshotAda: newSnapshot }
8080
8127
  })
8081
8128
  },
8082
- (0, import_lucid30.addAssets)(stakingManagerUtxo.assets, (0, import_cardano_offchain_common19.mkLovelacesOf)(adaRewardCollected))
8129
+ (0, import_lucid30.addAssets)(stakingManagerUtxo.assets, (0, import_cardano_offchain_common20.mkLovelacesOf)(adaRewardCollected))
8083
8130
  );
8084
8131
  for (const collectorUtxo of collectorUtxos) {
8085
8132
  tx.pay.ToContract(
8086
8133
  collectorUtxo.address,
8087
8134
  { kind: "inline", value: import_lucid30.Data.void() },
8088
- (0, import_cardano_offchain_common19.mkLovelacesOf)(MIN_UTXO_AMOUNT)
8135
+ (0, import_cardano_offchain_common20.mkLovelacesOf)(MIN_UTXO_AMOUNT)
8089
8136
  );
8090
8137
  }
8091
8138
  return tx;
@@ -8221,9 +8268,9 @@ function mkInterestOracleValidator(params) {
8221
8268
  }
8222
8269
 
8223
8270
  // tests/queries/interest-oracle-queries.ts
8224
- var import_cardano_offchain_common20 = require("@3rd-eye-labs/cardano-offchain-common");
8271
+ var import_cardano_offchain_common21 = require("@3rd-eye-labs/cardano-offchain-common");
8225
8272
  async function findInterestOracle(lucid, interestNft) {
8226
- return lucid.utxoByUnit((0, import_cardano_offchain_common20.assetClassToUnit)(interestNft));
8273
+ return lucid.utxoByUnit((0, import_cardano_offchain_common21.assetClassToUnit)(interestNft));
8227
8274
  }
8228
8275
 
8229
8276
  // src/contracts/interest-oracle/transactions.ts
@@ -8395,6 +8442,50 @@ var mkInterestCollectionValidatorFromSP = (params) => {
8395
8442
  };
8396
8443
  };
8397
8444
 
8445
+ // src/contracts/interest-collection/queries.ts
8446
+ var import_fp_ts18 = require("fp-ts");
8447
+ var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
8448
+ async function findAllInterestCollectors(lucid, sysParams) {
8449
+ return lucid.utxosAt(
8450
+ createScriptAddress(
8451
+ lucid.config().network,
8452
+ sysParams.validatorHashes.interestCollectionHash
8453
+ )
8454
+ );
8455
+ }
8456
+ async function findAdminInterestCollectors(lucid, sysParams) {
8457
+ return (0, import_cardano_offchain_common22.matchSingle)(
8458
+ await lucid.utxosAtWithUnit(
8459
+ createScriptAddress(
8460
+ lucid.config().network,
8461
+ sysParams.validatorHashes.interestCollectionHash
8462
+ ),
8463
+ (0, import_cardano_offchain_common22.assetClassToUnit)(
8464
+ fromSystemParamsAsset(
8465
+ sysParams.interestCollectionParams.multisigUtxoNft
8466
+ )
8467
+ )
8468
+ ),
8469
+ (_) => new Error("Expected a single admin interest collector UTXO")
8470
+ );
8471
+ }
8472
+ async function findRandomNonAdminInterestCollector(lucid, sysParams) {
8473
+ const allCollectors = (await findAllInterestCollectors(lucid, sysParams)).filter(
8474
+ (utxo) => !(0, import_cardano_offchain_common22.assetClassValueOf)(
8475
+ utxo.assets,
8476
+ fromSystemParamsAsset(
8477
+ sysParams.interestCollectionParams.multisigUtxoNft
8478
+ )
8479
+ )
8480
+ );
8481
+ return import_fp_ts18.function.pipe(
8482
+ import_fp_ts18.option.fromNullable((0, import_cardano_offchain_common22.getRandomElement)(allCollectors)),
8483
+ import_fp_ts18.option.match(() => {
8484
+ throw new Error("Expected some non-admin interest collector UTXOs.");
8485
+ }, import_fp_ts18.function.identity)
8486
+ );
8487
+ }
8488
+
8398
8489
  // src/contracts/version-registry/types.ts
8399
8490
  var import_lucid41 = require("@lucid-evolution/lucid");
8400
8491
  var VersionRecordTokenParamsSchema = import_lucid41.Data.Object({
@@ -8438,41 +8529,8 @@ var mkVersionRegistryValidator = () => {
8438
8529
  };
8439
8530
  };
8440
8531
 
8441
- // src/contracts/collector/scripts.ts
8442
- var import_lucid43 = require("@lucid-evolution/lucid");
8443
-
8444
- // src/validators/collector-validator.ts
8445
- var _collectorValidator = {
8446
- type: "PlutusScriptV3",
8447
- description: "Generated by Aiken",
8448
- cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
8449
- };
8450
-
8451
- // src/contracts/collector/scripts.ts
8452
- var mkCollectorValidatorFromSP = (params) => {
8453
- return {
8454
- type: "PlutusV3",
8455
- script: (0, import_lucid43.applyParamsToScript)(_collectorValidator.cborHex, [
8456
- new import_lucid43.Constr(0, [
8457
- new import_lucid43.Constr(0, [
8458
- params.stakingManagerNFT[0].unCurrencySymbol,
8459
- (0, import_lucid43.fromText)(params.stakingManagerNFT[1].unTokenName)
8460
- ]),
8461
- new import_lucid43.Constr(0, [
8462
- params.stakingToken[0].unCurrencySymbol,
8463
- (0, import_lucid43.fromText)(params.stakingToken[1].unTokenName)
8464
- ]),
8465
- new import_lucid43.Constr(0, [
8466
- params.versionRecordToken[0].unCurrencySymbol,
8467
- (0, import_lucid43.fromText)(params.versionRecordToken[1].unTokenName)
8468
- ])
8469
- ])
8470
- ])
8471
- };
8472
- };
8473
-
8474
8532
  // src/contracts/treasury/scripts.ts
8475
- var import_lucid45 = require("@lucid-evolution/lucid");
8533
+ var import_lucid44 = require("@lucid-evolution/lucid");
8476
8534
 
8477
8535
  // src/validators/treasury-validator.ts
8478
8536
  var _treasuryValidator = {
@@ -8482,22 +8540,22 @@ var _treasuryValidator = {
8482
8540
  };
8483
8541
 
8484
8542
  // src/contracts/treasury/types.ts
8485
- var import_lucid44 = require("@lucid-evolution/lucid");
8486
- var TreasuryParamsSchema = import_lucid44.Data.Object({
8543
+ var import_lucid43 = require("@lucid-evolution/lucid");
8544
+ var TreasuryParamsSchema = import_lucid43.Data.Object({
8487
8545
  upgradeToken: AssetClassSchema2,
8488
8546
  versionRecordToken: AssetClassSchema2,
8489
- treasuryUtxosStakeCredential: import_lucid44.Data.Nullable(StakeCredentialSchema)
8547
+ treasuryUtxosStakeCredential: import_lucid43.Data.Nullable(StakeCredentialSchema)
8490
8548
  });
8491
8549
  var TreasuryParams = TreasuryParamsSchema;
8492
8550
  function castTreasuryParams(params) {
8493
- return import_lucid44.Data.castTo(params, TreasuryParams);
8551
+ return import_lucid43.Data.castTo(params, TreasuryParams);
8494
8552
  }
8495
8553
 
8496
8554
  // src/contracts/treasury/scripts.ts
8497
8555
  var mkTreasuryValidatorFromSP = (params) => {
8498
8556
  return {
8499
8557
  type: "PlutusV3",
8500
- script: (0, import_lucid45.applyParamsToScript)(_treasuryValidator.cborHex, [
8558
+ script: (0, import_lucid44.applyParamsToScript)(_treasuryValidator.cborHex, [
8501
8559
  castTreasuryParams({
8502
8560
  upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
8503
8561
  versionRecordToken: fromSystemParamsAssetLucid(
@@ -8509,6 +8567,95 @@ var mkTreasuryValidatorFromSP = (params) => {
8509
8567
  };
8510
8568
  };
8511
8569
 
8570
+ // src/contracts/treasury/queries.ts
8571
+ var import_fp_ts19 = require("fp-ts");
8572
+ var import_cardano_offchain_common23 = require("@3rd-eye-labs/cardano-offchain-common");
8573
+ async function findAllTreasuryUtxos(lucid, sysParams) {
8574
+ return lucid.utxosAt({
8575
+ type: "Script",
8576
+ hash: sysParams.validatorHashes.treasuryHash
8577
+ });
8578
+ }
8579
+ async function findRandomTreasuryUtxo(lucid, sysParams) {
8580
+ const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
8581
+ return import_fp_ts19.function.pipe(
8582
+ import_fp_ts19.option.fromNullable((0, import_cardano_offchain_common23.getRandomElement)(treasuryUtxos)),
8583
+ import_fp_ts19.option.match(() => {
8584
+ throw new Error("Expected some treasury UTXOs.");
8585
+ }, import_fp_ts19.function.identity)
8586
+ );
8587
+ }
8588
+ async function findRandomTreasuryUtxoWithOnlyAda(lucid, sysParams) {
8589
+ const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
8590
+ const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
8591
+ (utxo) => Object.keys(utxo.assets).length == 1
8592
+ );
8593
+ return import_fp_ts19.function.pipe(
8594
+ import_fp_ts19.option.fromNullable((0, import_cardano_offchain_common23.getRandomElement)(adaOnlyTreasuryUtxos)),
8595
+ import_fp_ts19.option.match(() => {
8596
+ throw new Error("Expected some treasury UTXOs.");
8597
+ }, import_fp_ts19.function.identity)
8598
+ );
8599
+ }
8600
+ async function findRandomTreasuryUtxoWithAsset(lucid, sysParams, asset, max_number_of_assets = 2n) {
8601
+ const treasuryUtxos = await lucid.utxosAtWithUnit(
8602
+ { hash: sysParams.validatorHashes.treasuryHash, type: "Script" },
8603
+ (0, import_cardano_offchain_common23.assetClassToUnit)(asset)
8604
+ );
8605
+ const validTreasuryUtxos = treasuryUtxos.filter(
8606
+ (utxo) => Object.keys(utxo.assets).length <= max_number_of_assets
8607
+ );
8608
+ return import_fp_ts19.function.pipe(
8609
+ import_fp_ts19.option.fromNullable((0, import_cardano_offchain_common23.getRandomElement)(validTreasuryUtxos)),
8610
+ import_fp_ts19.option.match(() => {
8611
+ throw new Error("Expected some treasury UTXOs.");
8612
+ }, import_fp_ts19.function.identity)
8613
+ );
8614
+ }
8615
+ async function findAllTreasuryUtxosWithNonAdaAsset(lucid, sysParams, includeDaoToken = true) {
8616
+ const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
8617
+ const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
8618
+ (utxo) => Object.keys(utxo.assets).length !== 1 && (includeDaoToken ? true : (0, import_cardano_offchain_common23.assetClassValueOf)(
8619
+ utxo.assets,
8620
+ fromSystemParamsAsset(sysParams.govParams.daoIdentityToken)
8621
+ ) === 0n)
8622
+ );
8623
+ return treasuryUtxosWithNonAdaAsset;
8624
+ }
8625
+
8626
+ // src/contracts/collector/scripts.ts
8627
+ var import_lucid45 = require("@lucid-evolution/lucid");
8628
+
8629
+ // src/validators/collector-validator.ts
8630
+ var _collectorValidator = {
8631
+ type: "PlutusScriptV3",
8632
+ description: "Generated by Aiken",
8633
+ cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
8634
+ };
8635
+
8636
+ // src/contracts/collector/scripts.ts
8637
+ var mkCollectorValidatorFromSP = (params) => {
8638
+ return {
8639
+ type: "PlutusV3",
8640
+ script: (0, import_lucid45.applyParamsToScript)(_collectorValidator.cborHex, [
8641
+ new import_lucid45.Constr(0, [
8642
+ new import_lucid45.Constr(0, [
8643
+ params.stakingManagerNFT[0].unCurrencySymbol,
8644
+ (0, import_lucid45.fromText)(params.stakingManagerNFT[1].unTokenName)
8645
+ ]),
8646
+ new import_lucid45.Constr(0, [
8647
+ params.stakingToken[0].unCurrencySymbol,
8648
+ (0, import_lucid45.fromText)(params.stakingToken[1].unTokenName)
8649
+ ]),
8650
+ new import_lucid45.Constr(0, [
8651
+ params.versionRecordToken[0].unCurrencySymbol,
8652
+ (0, import_lucid45.fromText)(params.versionRecordToken[1].unTokenName)
8653
+ ])
8654
+ ])
8655
+ ])
8656
+ };
8657
+ };
8658
+
8512
8659
  // src/contracts/execute/types.ts
8513
8660
  var import_lucid46 = require("@lucid-evolution/lucid");
8514
8661
  var ExecuteParamsSchema = import_lucid46.Data.Object({
@@ -8602,14 +8749,14 @@ var import_lucid49 = require("@lucid-evolution/lucid");
8602
8749
 
8603
8750
  // src/contracts/rob/types-new.ts
8604
8751
  var import_evolution19 = require("@evolution-sdk/evolution");
8605
- var import_cardano_offchain_common21 = require("@3rd-eye-labs/cardano-offchain-common");
8606
- var import_fp_ts16 = require("fp-ts");
8752
+ var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
8753
+ var import_fp_ts20 = require("fp-ts");
8607
8754
  var RobOrderTypeSchema = import_evolution19.TSchema.Union(
8608
8755
  import_evolution19.TSchema.Struct(
8609
8756
  {
8610
8757
  BuyIAssetOrder: import_evolution19.TSchema.Struct(
8611
8758
  {
8612
- collateralAsset: import_cardano_offchain_common21.AssetClassSchema,
8759
+ collateralAsset: import_cardano_offchain_common24.AssetClassSchema,
8613
8760
  maxPrice: RationalSchema
8614
8761
  },
8615
8762
  { flatFields: true }
@@ -8622,7 +8769,7 @@ var RobOrderTypeSchema = import_evolution19.TSchema.Union(
8622
8769
  SellIAssetOrder: import_evolution19.TSchema.Struct(
8623
8770
  {
8624
8771
  allowedCollateralAssets: import_evolution19.TSchema.Array(
8625
- import_evolution19.TSchema.Tuple([import_cardano_offchain_common21.AssetClassSchema, RationalSchema])
8772
+ import_evolution19.TSchema.Tuple([import_cardano_offchain_common24.AssetClassSchema, RationalSchema])
8626
8773
  )
8627
8774
  },
8628
8775
  { flatFields: true }
@@ -8635,7 +8782,7 @@ var RobDatumSchema = import_evolution19.TSchema.Struct({
8635
8782
  owner: import_evolution19.TSchema.ByteArray,
8636
8783
  iasset: import_evolution19.TSchema.ByteArray,
8637
8784
  orderType: RobOrderTypeSchema,
8638
- robRefInput: import_cardano_offchain_common21.OutputReferenceSchema
8785
+ robRefInput: import_cardano_offchain_common24.OutputReferenceSchema
8639
8786
  });
8640
8787
  var RobRedeemerSchema = import_evolution19.TSchema.Union(
8641
8788
  import_evolution19.TSchema.Struct(
@@ -8659,21 +8806,21 @@ var RobRedeemerSchema = import_evolution19.TSchema.Union(
8659
8806
  );
8660
8807
  function parseRobDatum(datum) {
8661
8808
  try {
8662
- return import_fp_ts16.option.some(
8809
+ return import_fp_ts20.option.some(
8663
8810
  import_evolution19.Data.withSchema(RobDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
8664
8811
  datum
8665
8812
  )
8666
8813
  );
8667
8814
  } catch (_) {
8668
- return import_fp_ts16.option.none;
8815
+ return import_fp_ts20.option.none;
8669
8816
  }
8670
8817
  }
8671
8818
  function parseRobDatumOrThrow(datum) {
8672
- return import_fp_ts16.function.pipe(
8819
+ return import_fp_ts20.function.pipe(
8673
8820
  parseRobDatum(datum),
8674
- import_fp_ts16.option.match(() => {
8821
+ import_fp_ts20.option.match(() => {
8675
8822
  throw new Error("Expected an ROB datum.");
8676
- }, import_fp_ts16.function.identity)
8823
+ }, import_fp_ts20.function.identity)
8677
8824
  );
8678
8825
  }
8679
8826
  function serialiseRobDatum(d) {
@@ -8686,28 +8833,28 @@ function serialiseRobRedeemer(r) {
8686
8833
  }
8687
8834
  function parseRobRedeemer(redeemerCborHex) {
8688
8835
  try {
8689
- return import_fp_ts16.option.some(
8836
+ return import_fp_ts20.option.some(
8690
8837
  import_evolution19.Data.withSchema(RobRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
8691
8838
  redeemerCborHex
8692
8839
  )
8693
8840
  );
8694
8841
  } catch (_) {
8695
- return import_fp_ts16.option.none;
8842
+ return import_fp_ts20.option.none;
8696
8843
  }
8697
8844
  }
8698
8845
  function parseRobRedeemerOrThrow(redeemerCborHex) {
8699
- return import_fp_ts16.function.pipe(
8846
+ return import_fp_ts20.function.pipe(
8700
8847
  parseRobRedeemer(redeemerCborHex),
8701
- import_fp_ts16.option.match(() => {
8848
+ import_fp_ts20.option.match(() => {
8702
8849
  throw new Error("Expected an ROB redeemer.");
8703
- }, import_fp_ts16.function.identity)
8850
+ }, import_fp_ts20.function.identity)
8704
8851
  );
8705
8852
  }
8706
8853
 
8707
8854
  // src/contracts/rob/helpers.ts
8708
- var import_fp_ts17 = require("fp-ts");
8855
+ var import_fp_ts21 = require("fp-ts");
8709
8856
  var import_ts_pattern19 = require("ts-pattern");
8710
- var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
8857
+ var import_cardano_offchain_common25 = require("@3rd-eye-labs/cardano-offchain-common");
8711
8858
  var import_decimal = __toESM(require("decimal.js"));
8712
8859
  var MIN_ROB_COLLATERAL_AMT = 3000000n;
8713
8860
  var MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
@@ -8753,10 +8900,10 @@ function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt, redemptionReimburs
8753
8900
  }
8754
8901
  function robCollateralAmtToSpend(robAssets, robOrderType) {
8755
8902
  return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
8756
- if ((0, import_cardano_offchain_common22.isSameAssetClass)(import_cardano_offchain_common22.adaAssetClass, content.collateralAsset)) {
8757
- return zeroNegatives((0, import_cardano_offchain_common22.lovelacesAmt)(robAssets) - MIN_ROB_COLLATERAL_AMT);
8903
+ if ((0, import_cardano_offchain_common25.isSameAssetClass)(import_cardano_offchain_common25.adaAssetClass, content.collateralAsset)) {
8904
+ return zeroNegatives((0, import_cardano_offchain_common25.lovelacesAmt)(robAssets) - MIN_ROB_COLLATERAL_AMT);
8758
8905
  } else {
8759
- return (0, import_cardano_offchain_common22.assetClassValueOf)(robAssets, content.collateralAsset);
8906
+ return (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, content.collateralAsset);
8760
8907
  }
8761
8908
  }).otherwise(() => {
8762
8909
  throw new Error("Collateral to spend is relevant only for Buy orders.");
@@ -8764,7 +8911,7 @@ function robCollateralAmtToSpend(robAssets, robOrderType) {
8764
8911
  }
8765
8912
  function robIAssetAmtToSpend(robAssets, robOrderType, robIasset) {
8766
8913
  return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ SellIAssetOrder: import_ts_pattern19.P.any }, (_) => {
8767
- return (0, import_cardano_offchain_common22.assetClassValueOf)(robAssets, robIasset);
8914
+ return (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, robIasset);
8768
8915
  }).otherwise(() => {
8769
8916
  throw new Error("IAssets to spend is relevant only for Sell orders.");
8770
8917
  });
@@ -8782,7 +8929,7 @@ function robBuyOrderFilledAssets(robAssets, robOrderType, robIasset) {
8782
8929
  return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.any }, () => {
8783
8930
  return {
8784
8931
  asset: robIasset,
8785
- filledAmt: (0, import_cardano_offchain_common22.assetClassValueOf)(robAssets, robIasset)
8932
+ filledAmt: (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, robIasset)
8786
8933
  };
8787
8934
  }).otherwise(() => {
8788
8935
  throw new Error("Expected only buy order.");
@@ -8793,7 +8940,7 @@ function robSellOrderFilledAssets(robAssets, robOrderType) {
8793
8940
  return content.allowedCollateralAssets.map(([asset, _]) => {
8794
8941
  return {
8795
8942
  asset,
8796
- filledAmt: (0, import_cardano_offchain_common22.assetClassValueOf)(robAssets, asset) - ((0, import_cardano_offchain_common22.isSameAssetClass)(asset, import_cardano_offchain_common22.adaAssetClass) ? MIN_ROB_COLLATERAL_AMT : 0n)
8943
+ filledAmt: (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, asset) - ((0, import_cardano_offchain_common25.isSameAssetClass)(asset, import_cardano_offchain_common25.adaAssetClass) ? MIN_ROB_COLLATERAL_AMT : 0n)
8797
8944
  };
8798
8945
  });
8799
8946
  }).otherwise(() => {
@@ -8830,9 +8977,9 @@ function isFullyRedeemed(robAssets, robOrderType, robIasset) {
8830
8977
  }).exhaustive();
8831
8978
  }
8832
8979
  function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
8833
- return import_fp_ts17.function.pipe(
8980
+ return import_fp_ts21.function.pipe(
8834
8981
  redemptions,
8835
- import_fp_ts17.array.reduceWithIndex(
8982
+ import_fp_ts21.array.reduceWithIndex(
8836
8983
  tx,
8837
8984
  (idx, acc, [robUtxo, payoutAmt]) => {
8838
8985
  const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
@@ -8842,7 +8989,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8842
8989
  const [robOutputVal, sellOrderAllowedAssetsIdx] = (0, import_ts_pattern19.match)(
8843
8990
  robDatum.orderType
8844
8991
  ).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
8845
- if (!(0, import_cardano_offchain_common22.isSameAssetClass)(content.collateralAsset, collateralAsset)) {
8992
+ if (!(0, import_cardano_offchain_common25.isSameAssetClass)(content.collateralAsset, collateralAsset)) {
8846
8993
  throw new Error("Only same collateral asset");
8847
8994
  }
8848
8995
  const payoutIAssetAmt = payoutAmt;
@@ -8853,8 +9000,8 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8853
9000
  );
8854
9001
  const resultVal = (0, import_lucid49.addAssets)(
8855
9002
  robUtxo.assets,
8856
- (0, import_cardano_offchain_common22.mkAssetsOf)(collateralAsset, -collateralForRedemption),
8857
- (0, import_cardano_offchain_common22.mkAssetsOf)(
9003
+ (0, import_cardano_offchain_common25.mkAssetsOf)(collateralAsset, -collateralForRedemption),
9004
+ (0, import_cardano_offchain_common25.mkAssetsOf)(
8858
9005
  {
8859
9006
  currencySymbol: (0, import_lucid49.fromHex)(
8860
9007
  sysParams.robParams.iassetPolicyId.unCurrencySymbol
@@ -8866,12 +9013,12 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8866
9013
  );
8867
9014
  return [resultVal, 0n];
8868
9015
  }).with({ SellIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
8869
- const allowedAssetIdx = import_fp_ts17.function.pipe(
9016
+ const allowedAssetIdx = import_fp_ts21.function.pipe(
8870
9017
  content.allowedCollateralAssets,
8871
- import_fp_ts17.readonlyArray.findIndex(
8872
- ([asset, _]) => (0, import_cardano_offchain_common22.isSameAssetClass)(asset, collateralAsset)
9018
+ import_fp_ts21.readonlyArray.findIndex(
9019
+ ([asset, _]) => (0, import_cardano_offchain_common25.isSameAssetClass)(asset, collateralAsset)
8873
9020
  ),
8874
- import_fp_ts17.option.getOrElse(() => {
9021
+ import_fp_ts21.option.getOrElse(() => {
8875
9022
  throw new Error("Doesn't allow required collateral asset.");
8876
9023
  })
8877
9024
  );
@@ -8883,8 +9030,8 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8883
9030
  );
8884
9031
  const resultVal = (0, import_lucid49.addAssets)(
8885
9032
  robUtxo.assets,
8886
- (0, import_cardano_offchain_common22.mkAssetsOf)(collateralAsset, payoutCollateralAmt),
8887
- (0, import_cardano_offchain_common22.mkAssetsOf)(
9033
+ (0, import_cardano_offchain_common25.mkAssetsOf)(collateralAsset, payoutCollateralAmt),
9034
+ (0, import_cardano_offchain_common25.mkAssetsOf)(
8888
9035
  {
8889
9036
  currencySymbol: (0, import_lucid49.fromHex)(
8890
9037
  sysParams.robParams.iassetPolicyId.unCurrencySymbol
@@ -8896,7 +9043,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8896
9043
  );
8897
9044
  return [resultVal, BigInt(allowedAssetIdx)];
8898
9045
  }).exhaustive();
8899
- if ((0, import_cardano_offchain_common22.lovelacesAmt)(robOutputVal) < MIN_ROB_COLLATERAL_AMT) {
9046
+ if ((0, import_cardano_offchain_common25.lovelacesAmt)(robOutputVal) < MIN_ROB_COLLATERAL_AMT) {
8900
9047
  throw new Error(
8901
9048
  "Redeeming more than available or selected ROB was incorrectly initialised."
8902
9049
  );
@@ -8932,26 +9079,26 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8932
9079
  );
8933
9080
  }
8934
9081
  function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
8935
- return import_fp_ts17.function.pipe(
9082
+ return import_fp_ts21.function.pipe(
8936
9083
  allRobs,
8937
- import_fp_ts17.array.filterMap(([utxo, datum]) => {
9084
+ import_fp_ts21.array.filterMap(([utxo, datum]) => {
8938
9085
  const isCorrectOrder = (0, import_ts_pattern19.match)(datum.orderType).returnType().with(
8939
9086
  { BuyIAssetOrder: import_ts_pattern19.P.select() },
8940
- (content) => (0, import_cardano_offchain_common22.isSameAssetClass)(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
9087
+ (content) => (0, import_cardano_offchain_common25.isSameAssetClass)(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
8941
9088
  ).otherwise(() => false);
8942
9089
  if ((0, import_lucid49.toHex)(datum.iasset) !== (0, import_lucid49.toHex)(iasset) || !isCorrectOrder) {
8943
- return import_fp_ts17.option.none;
9090
+ return import_fp_ts21.option.none;
8944
9091
  }
8945
9092
  const collateralToSpend = robCollateralAmtToSpend(
8946
9093
  utxo.assets,
8947
9094
  datum.orderType
8948
9095
  );
8949
- return import_fp_ts17.option.some(collateralToSpend);
9096
+ return import_fp_ts21.option.some(collateralToSpend);
8950
9097
  }),
8951
9098
  // From largest to smallest
8952
- import_fp_ts17.array.sort(import_fp_ts17.ord.reverse(BigIntOrd)),
9099
+ import_fp_ts21.array.sort(import_fp_ts21.ord.reverse(BigIntOrd)),
8953
9100
  // We can fit only this number of redemptions with CDP open into a single Tx.
8954
- import_fp_ts17.array.takeLeft(maxRobsInTx),
9101
+ import_fp_ts21.array.takeLeft(maxRobsInTx),
8955
9102
  sum
8956
9103
  );
8957
9104
  }
@@ -8960,12 +9107,12 @@ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, tar
8960
9107
  throw new Error("Must redeem and payout more than 0.");
8961
9108
  }
8962
9109
  const shuffled = randomiseFn(
8963
- import_fp_ts17.function.pipe(
9110
+ import_fp_ts21.function.pipe(
8964
9111
  allLrps,
8965
- import_fp_ts17.array.filter(
9112
+ import_fp_ts21.array.filter(
8966
9113
  ([utxo, datum]) => (0, import_lucid49.toHex)(datum.iasset) === (0, import_lucid49.toHex)(iasset) && (0, import_ts_pattern19.match)(datum.orderType).with(
8967
9114
  { BuyIAssetOrder: import_ts_pattern19.P.select() },
8968
- (content) => (0, import_cardano_offchain_common22.isSameAssetClass)(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
9115
+ (content) => (0, import_cardano_offchain_common25.isSameAssetClass)(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
8969
9116
  ).otherwise(() => false) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
8970
9117
  )
8971
9118
  )
@@ -9000,10 +9147,10 @@ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, tar
9000
9147
  result = insertSorted(
9001
9148
  result,
9002
9149
  element,
9003
- import_fp_ts17.ord.contramap(
9150
+ import_fp_ts21.ord.contramap(
9004
9151
  ([utxo, dat]) => robCollateralAmtToSpend(utxo.assets, dat.orderType)
9005
9152
  // From highest to lowest
9006
- )(import_fp_ts17.ord.reverse(BigIntOrd))
9153
+ )(import_fp_ts21.ord.reverse(BigIntOrd))
9007
9154
  );
9008
9155
  runningSum += lovelacesToSpend;
9009
9156
  if (result.length > maxLrpsInTx) {
@@ -9040,9 +9187,9 @@ function castRobParams(params) {
9040
9187
 
9041
9188
  // src/contracts/rob/transactions.ts
9042
9189
  var import_lucid51 = require("@lucid-evolution/lucid");
9043
- var import_fp_ts18 = require("fp-ts");
9190
+ var import_fp_ts22 = require("fp-ts");
9044
9191
  var import_Array2 = require("fp-ts/lib/Array");
9045
- var import_cardano_offchain_common23 = require("@3rd-eye-labs/cardano-offchain-common");
9192
+ var import_cardano_offchain_common26 = require("@3rd-eye-labs/cardano-offchain-common");
9046
9193
  var import_ts_pattern20 = require("ts-pattern");
9047
9194
  async function openRob(assetTokenNameAscii, depositAmt, orderType, lucid, sysParams, robStakeCredential) {
9048
9195
  const network = lucid.config().network;
@@ -9060,10 +9207,10 @@ async function openRob(assetTokenNameAscii, depositAmt, orderType, lucid, sysPar
9060
9207
  };
9061
9208
  const depositVal = (0, import_ts_pattern20.match)(orderType).with(
9062
9209
  { BuyIAssetOrder: import_ts_pattern20.P.select() },
9063
- (buyContent) => (0, import_cardano_offchain_common23.mkAssetsOf)(buyContent.collateralAsset, depositAmt)
9210
+ (buyContent) => (0, import_cardano_offchain_common26.mkAssetsOf)(buyContent.collateralAsset, depositAmt)
9064
9211
  ).with(
9065
9212
  { SellIAssetOrder: import_ts_pattern20.P.any },
9066
- (_2) => (0, import_cardano_offchain_common23.mkAssetsOf)(
9213
+ (_2) => (0, import_cardano_offchain_common26.mkAssetsOf)(
9067
9214
  {
9068
9215
  currencySymbol: (0, import_lucid51.fromHex)(
9069
9216
  sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
@@ -9083,7 +9230,7 @@ async function openRob(assetTokenNameAscii, depositAmt, orderType, lucid, sysPar
9083
9230
  kind: "inline",
9084
9231
  value: serialiseRobDatum(newDatum)
9085
9232
  },
9086
- (0, import_lucid51.addAssets)(depositVal, (0, import_cardano_offchain_common23.mkLovelacesOf)(MIN_ROB_COLLATERAL_AMT))
9233
+ (0, import_lucid51.addAssets)(depositVal, (0, import_cardano_offchain_common26.mkLovelacesOf)(MIN_ROB_COLLATERAL_AMT))
9087
9234
  );
9088
9235
  }
9089
9236
  async function cancelRob(robOutRef, sysParams, lucid) {
@@ -9206,17 +9353,17 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
9206
9353
  tokenName: robDatum.iasset
9207
9354
  };
9208
9355
  const [depositAsset, rewardVal] = (0, import_ts_pattern20.match)(robDatum.orderType).returnType().with({ BuyIAssetOrder: import_ts_pattern20.P.select() }, (buyContent) => {
9209
- const reward = (0, import_cardano_offchain_common23.assetClassValueOf)(robUtxo.assets, iassetAc);
9210
- return [buyContent.collateralAsset, (0, import_cardano_offchain_common23.mkAssetsOf)(iassetAc, reward)];
9356
+ const reward = (0, import_cardano_offchain_common26.assetClassValueOf)(robUtxo.assets, iassetAc);
9357
+ return [buyContent.collateralAsset, (0, import_cardano_offchain_common26.mkAssetsOf)(iassetAc, reward)];
9211
9358
  }).with({ SellIAssetOrder: import_ts_pattern20.P.select() }, (content) => {
9212
- const reward = import_fp_ts18.function.pipe(
9359
+ const reward = import_fp_ts22.function.pipe(
9213
9360
  content.allowedCollateralAssets,
9214
- import_fp_ts18.readonlyArray.reduce(
9361
+ import_fp_ts22.readonlyArray.reduce(
9215
9362
  {},
9216
9363
  (acc, [asset, _]) => {
9217
- const amt = (0, import_cardano_offchain_common23.assetClassValueOf)(robUtxo.assets, asset) - // in case of ADA, the min has to stay.
9218
- ((0, import_cardano_offchain_common23.isSameAssetClass)(asset, import_cardano_offchain_common23.adaAssetClass) ? MIN_ROB_COLLATERAL_AMT : 0n);
9219
- return (0, import_lucid51.addAssets)(acc, (0, import_cardano_offchain_common23.mkAssetsOf)(asset, amt));
9364
+ const amt = (0, import_cardano_offchain_common26.assetClassValueOf)(robUtxo.assets, asset) - // in case of ADA, the min has to stay.
9365
+ ((0, import_cardano_offchain_common26.isSameAssetClass)(asset, import_cardano_offchain_common26.adaAssetClass) ? MIN_ROB_COLLATERAL_AMT : 0n);
9366
+ return (0, import_lucid51.addAssets)(acc, (0, import_cardano_offchain_common26.mkAssetsOf)(asset, amt));
9220
9367
  }
9221
9368
  )
9222
9369
  );
@@ -9249,12 +9396,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
9249
9396
  return {
9250
9397
  SellIAssetOrder: {
9251
9398
  allowedCollateralAssets: content.allowedCollateralAssets.map(
9252
- (entry) => import_fp_ts18.function.pipe(
9399
+ (entry) => import_fp_ts22.function.pipe(
9253
9400
  newPrices,
9254
- import_fp_ts18.array.findFirst(
9255
- (newPrice) => (0, import_cardano_offchain_common23.isSameAssetClass)(newPrice[0], entry[0])
9401
+ import_fp_ts22.array.findFirst(
9402
+ (newPrice) => (0, import_cardano_offchain_common26.isSameAssetClass)(newPrice[0], entry[0])
9256
9403
  ),
9257
- import_fp_ts18.option.match(
9404
+ import_fp_ts22.option.match(
9258
9405
  () => entry,
9259
9406
  (newPrice) => [
9260
9407
  entry[0],
@@ -9270,8 +9417,8 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
9270
9417
  },
9271
9418
  (0, import_lucid51.addAssets)(
9272
9419
  robUtxo.assets,
9273
- (0, import_cardano_offchain_common23.mkAssetsOf)(depositAsset, adjustmentAmt),
9274
- (0, import_cardano_offchain_common23.negateAssets)(rewardVal)
9420
+ (0, import_cardano_offchain_common26.mkAssetsOf)(depositAsset, adjustmentAmt),
9421
+ (0, import_cardano_offchain_common26.negateAssets)(rewardVal)
9275
9422
  )
9276
9423
  ).addSignerKey((0, import_lucid51.toHex)(robDatum.owner));
9277
9424
  }
@@ -9319,7 +9466,7 @@ var mkRobValidatorFromSP = (params) => {
9319
9466
  var import_lucid53 = require("@lucid-evolution/lucid");
9320
9467
 
9321
9468
  // src/contracts/rob-leverage/helpers.ts
9322
- var import_fp_ts19 = require("fp-ts");
9469
+ var import_fp_ts23 = require("fp-ts");
9323
9470
  var import_decimal2 = require("decimal.js");
9324
9471
  var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
9325
9472
  function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
@@ -9345,9 +9492,9 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
9345
9492
  };
9346
9493
  }
9347
9494
  function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
9348
- const redemptionDetails = import_fp_ts19.function.pipe(
9495
+ const redemptionDetails = import_fp_ts23.function.pipe(
9349
9496
  redemptionLrps,
9350
- import_fp_ts19.array.reduce(
9497
+ import_fp_ts23.array.reduce(
9351
9498
  {
9352
9499
  remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
9353
9500
  redemptions: []
@@ -9401,9 +9548,9 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
9401
9548
  }
9402
9549
  )
9403
9550
  );
9404
- const res = import_fp_ts19.function.pipe(
9551
+ const res = import_fp_ts23.function.pipe(
9405
9552
  redemptionDetails.redemptions,
9406
- import_fp_ts19.array.reduce(
9553
+ import_fp_ts23.array.reduce(
9407
9554
  {
9408
9555
  redeemedCollateral: 0n,
9409
9556
  payoutIAssets: 0n,
@@ -9496,7 +9643,7 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
9496
9643
  }
9497
9644
 
9498
9645
  // src/contracts/rob-leverage/transactions.ts
9499
- var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
9646
+ var import_cardano_offchain_common27 = require("@3rd-eye-labs/cardano-offchain-common");
9500
9647
  var import_decimal3 = __toESM(require("decimal.js"));
9501
9648
  async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
9502
9649
  const network = lucid.config().network;
@@ -9621,7 +9768,7 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
9621
9768
  mintedAmt
9622
9769
  );
9623
9770
  const collateralAmt = redemptionDetails.totalRedeemedCollateral + baseCollateral;
9624
- const cdpNftVal = (0, import_cardano_offchain_common24.mkAssetsOf)(
9771
+ const cdpNftVal = (0, import_cardano_offchain_common27.mkAssetsOf)(
9625
9772
  fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
9626
9773
  1n
9627
9774
  );
@@ -9631,7 +9778,7 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
9631
9778
  ),
9632
9779
  tokenName: iassetDatum.assetName
9633
9780
  };
9634
- const iassetTokensVal = (0, import_cardano_offchain_common24.mkAssetsOf)(iassetClass, mintedAmt);
9781
+ const iassetTokensVal = (0, import_cardano_offchain_common27.mkAssetsOf)(iassetClass, mintedAmt);
9635
9782
  const refScripts = [
9636
9783
  cdpCreatorRefScriptUtxo,
9637
9784
  cdpAuthTokenPolicyRefScriptUtxo,
@@ -9660,7 +9807,7 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
9660
9807
  },
9661
9808
  (0, import_lucid53.addAssets)(
9662
9809
  cdpNftVal,
9663
- (0, import_cardano_offchain_common24.mkAssetsOf)(collateralAssetDatum.collateralAsset, collateralAmt)
9810
+ (0, import_cardano_offchain_common27.mkAssetsOf)(collateralAssetDatum.collateralAsset, collateralAmt)
9664
9811
  )
9665
9812
  ).pay.ToContract(
9666
9813
  cdpCreatorUtxo.address,
@@ -9770,7 +9917,7 @@ function mkPriceOracleValidator(params) {
9770
9917
  }
9771
9918
 
9772
9919
  // src/contracts/price-oracle/transactions.ts
9773
- var import_cardano_offchain_common25 = require("@3rd-eye-labs/cardano-offchain-common");
9920
+ var import_cardano_offchain_common28 = require("@3rd-eye-labs/cardano-offchain-common");
9774
9921
  var Core2 = __toESM(require("@evolution-sdk/evolution"));
9775
9922
  async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, currentSlot, refOutRef, auxiliaryData) {
9776
9923
  const network = lucid.config().network;
@@ -9803,7 +9950,7 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
9803
9950
  tx.pay.ToContract(
9804
9951
  (0, import_lucid55.validatorToAddress)(lucid.config().network, oracleValidator),
9805
9952
  { kind: "inline", value: serialisePriceOracleDatum(oracleDatum) },
9806
- (0, import_lucid55.addAssets)((0, import_cardano_offchain_common25.mkAssetsOf)(priceOracleNft, 1n))
9953
+ (0, import_lucid55.addAssets)((0, import_cardano_offchain_common28.mkAssetsOf)(priceOracleNft, 1n))
9807
9954
  );
9808
9955
  return [tx, priceOracleNft];
9809
9956
  }
@@ -9854,7 +10001,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
9854
10001
 
9855
10002
  // src/contracts/initialize/helpers.ts
9856
10003
  var import_lucid60 = require("@lucid-evolution/lucid");
9857
- var import_cardano_offchain_common26 = require("@3rd-eye-labs/cardano-offchain-common");
10004
+ var import_cardano_offchain_common29 = require("@3rd-eye-labs/cardano-offchain-common");
9858
10005
 
9859
10006
  // src/scripts/auth-token-policy.ts
9860
10007
  var import_lucid57 = require("@lucid-evolution/lucid");
@@ -9910,7 +10057,7 @@ var mkIAssetValidatorFromSP = (params) => {
9910
10057
  var import_ts_pattern21 = require("ts-pattern");
9911
10058
 
9912
10059
  // tests/test-helpers.ts
9913
- var import_fp_ts20 = require("fp-ts");
10060
+ var import_fp_ts24 = require("fp-ts");
9914
10061
  async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
9915
10062
  const bTx = await transaction.complete();
9916
10063
  const signatures = [await bTx.partialSign.withWallet()];
@@ -10031,7 +10178,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
10031
10178
  kind: "inline",
10032
10179
  value: serialiseInterestCollectionDatum(interestCollectionAdminDatum)
10033
10180
  },
10034
- (0, import_cardano_offchain_common26.mkAssetsOf)(multisigUtxoNft, 1n)
10181
+ (0, import_cardano_offchain_common29.mkAssetsOf)(multisigUtxoNft, 1n)
10035
10182
  )
10036
10183
  );
10037
10184
  const interestCollectionUtxoDeploymentTx = lucid.newTx();
@@ -10039,7 +10186,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
10039
10186
  interestCollectionUtxoDeploymentTx.pay.ToContract(
10040
10187
  createScriptAddress(lucid.config().network, interestCollectionValHash),
10041
10188
  void 0,
10042
- (0, import_cardano_offchain_common26.mkLovelacesOf)(interestCollectorUtxoLovelaces)
10189
+ (0, import_cardano_offchain_common29.mkLovelacesOf)(interestCollectorUtxoLovelaces)
10043
10190
  );
10044
10191
  }
10045
10192
  await submitTx(lucid, interestCollectionUtxoDeploymentTx);
@@ -10072,8 +10219,8 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
10072
10219
  treasuryAddr,
10073
10220
  { kind: "inline", value: import_lucid60.Data.void() },
10074
10221
  (0, import_lucid60.addAssets)(
10075
- (0, import_cardano_offchain_common26.mkAssetsOf)(daoAsset, 1n),
10076
- (0, import_cardano_offchain_common26.mkAssetsOf)(indyAsset, treasuryIndyAmount)
10222
+ (0, import_cardano_offchain_common29.mkAssetsOf)(daoAsset, 1n),
10223
+ (0, import_cardano_offchain_common29.mkAssetsOf)(indyAsset, treasuryIndyAmount)
10077
10224
  )
10078
10225
  );
10079
10226
  for (let i = 0; i < Number(numTreasuryCollectors); i++) {
@@ -10186,7 +10333,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10186
10333
  CollateralAssetContent: collateralAssetContent
10187
10334
  })
10188
10335
  },
10189
- (0, import_cardano_offchain_common26.mkAssetsOf)(collateralAssetAuthToken, 1n)
10336
+ (0, import_cardano_offchain_common29.mkAssetsOf)(collateralAssetAuthToken, 1n)
10190
10337
  );
10191
10338
  await submitTx(lucid, collateralAssetTx);
10192
10339
  collateralAssetInfos.push({
@@ -10221,7 +10368,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10221
10368
  kind: "inline",
10222
10369
  value: serialiseStableswapPoolDatum(stableswapPoolDatum)
10223
10370
  },
10224
- (0, import_cardano_offchain_common26.mkAssetsOf)(cdpAuthToken, 1n)
10371
+ (0, import_cardano_offchain_common29.mkAssetsOf)(cdpAuthToken, 1n)
10225
10372
  )
10226
10373
  );
10227
10374
  }
@@ -10245,7 +10392,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10245
10392
  kind: "inline",
10246
10393
  value: serialiseIAssetDatum({ IAssetContent: iassetDatum })
10247
10394
  },
10248
- (0, import_cardano_offchain_common26.mkAssetsOf)(iassetToken, 1n)
10395
+ (0, import_cardano_offchain_common29.mkAssetsOf)(iassetToken, 1n)
10249
10396
  );
10250
10397
  await submitTx(lucid, assetTx);
10251
10398
  const stabilityPoolDatum = {
@@ -10264,7 +10411,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10264
10411
  kind: "inline",
10265
10412
  value: serialiseStabilityPoolDatum({ StabilityPool: stabilityPoolDatum })
10266
10413
  },
10267
- (0, import_cardano_offchain_common26.mkAssetsOf)(stabilityPoolToken, 1n)
10414
+ (0, import_cardano_offchain_common29.mkAssetsOf)(stabilityPoolToken, 1n)
10268
10415
  );
10269
10416
  await submitTx(lucid, spTx);
10270
10417
  return {
@@ -10286,7 +10433,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
10286
10433
  type: "Script"
10287
10434
  }),
10288
10435
  { kind: "inline", value: serialiseGovDatum(datum) },
10289
- (0, import_cardano_offchain_common26.mkAssetsOf)(govToken, 1n)
10436
+ (0, import_cardano_offchain_common29.mkAssetsOf)(govToken, 1n)
10290
10437
  );
10291
10438
  await submitTx(lucid, tx);
10292
10439
  }
@@ -10294,7 +10441,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
10294
10441
  const script = mkAuthTokenPolicy(asset, (0, import_lucid60.fromText)(tokenName));
10295
10442
  const policyId = (0, import_lucid60.mintingPolicyToId)(script);
10296
10443
  const address = await lucid.wallet().address();
10297
- 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)));
10444
+ const utxos = (await lucid.utxosAtWithUnit(address, (0, import_cardano_offchain_common29.assetClassToUnit)(asset))).filter((utxo2) => (0, import_cardano_offchain_common29.assetClassValueOf)(utxo2.assets, asset) === 1n).sort((a, b) => Number((0, import_cardano_offchain_common29.lovelacesAmt)(b.assets) - (0, import_cardano_offchain_common29.lovelacesAmt)(a.assets)));
10298
10445
  if (utxos.length === 0) {
10299
10446
  throw new Error("No utxos found");
10300
10447
  }
@@ -10310,7 +10457,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
10310
10457
 
10311
10458
  // src/contracts/initialize/actions.ts
10312
10459
  var import_lucid65 = require("@lucid-evolution/lucid");
10313
- var import_cardano_offchain_common28 = require("@3rd-eye-labs/cardano-offchain-common");
10460
+ var import_cardano_offchain_common31 = require("@3rd-eye-labs/cardano-offchain-common");
10314
10461
 
10315
10462
  // src/scripts/iasset-policy.ts
10316
10463
  var import_lucid61 = require("@lucid-evolution/lucid");
@@ -10415,7 +10562,7 @@ var alwaysSucceedValidator = {
10415
10562
  };
10416
10563
 
10417
10564
  // tests/pyth/endpoints.ts
10418
- var import_cardano_offchain_common27 = require("@3rd-eye-labs/cardano-offchain-common");
10565
+ var import_cardano_offchain_common30 = require("@3rd-eye-labs/cardano-offchain-common");
10419
10566
  var TEST_TRUSTED_SIGNER_PUB_KEY = "4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f";
10420
10567
  async function initPyth(lucid) {
10421
10568
  const pythStateName = (0, import_lucid64.fromText)("Pyth State");
@@ -10467,7 +10614,7 @@ async function initPyth(lucid) {
10467
10614
  type: "Script"
10468
10615
  }),
10469
10616
  { kind: "inline", value: serialisePythStateDatum(pythStateDatum) },
10470
- (0, import_cardano_offchain_common27.mkAssetsOf)(pythStateAsset, 1n),
10617
+ (0, import_cardano_offchain_common30.mkAssetsOf)(pythStateAsset, 1n),
10471
10618
  alwaysSucceedValidator
10472
10619
  )
10473
10620
  );
@@ -10504,15 +10651,24 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10504
10651
  lucid,
10505
10652
  pythFeedValidator
10506
10653
  );
10507
- await runAndAwaitTxBuilder(
10508
- lucid,
10509
- lucid.newTx().register.Stake(
10510
- (0, import_lucid65.credentialToRewardAddress)(lucid.config().network, {
10511
- hash: (0, import_lucid65.validatorToScriptHash)(pythFeedValidator),
10512
- type: "Script"
10513
- })
10514
- )
10515
- );
10654
+ try {
10655
+ await runAndAwaitTxBuilder(
10656
+ lucid,
10657
+ lucid.newTx().register.Stake(
10658
+ (0, import_lucid65.credentialToRewardAddress)(lucid.config().network, {
10659
+ hash: (0, import_lucid65.validatorToScriptHash)(pythFeedValidator),
10660
+ type: "Script"
10661
+ })
10662
+ )
10663
+ );
10664
+ } catch (error) {
10665
+ const message = error instanceof Error ? error.message : String(error);
10666
+ if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
10667
+ "Trying to re-register some already known credentials."
10668
+ )) {
10669
+ throw error;
10670
+ }
10671
+ }
10516
10672
  const key = `${asset.name}/${(0, import_lucid65.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid65.toHex)(collateral.collateralAsset.tokenName)}`;
10517
10673
  return {
10518
10674
  [key]: {
@@ -10702,7 +10858,17 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10702
10858
  lucid.config().network,
10703
10859
  (0, import_lucid65.scriptHashToCredential)(cdpRedeemValHash)
10704
10860
  );
10705
- await submitTx(lucid, lucid.newTx().register.Stake(cdpRedeemRewardAddr));
10861
+ try {
10862
+ await runAndAwaitTxBuilder(
10863
+ lucid,
10864
+ lucid.newTx().register.Stake(cdpRedeemRewardAddr)
10865
+ );
10866
+ } catch (error) {
10867
+ const message = error instanceof Error ? error.message : String(error);
10868
+ if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
10869
+ throw error;
10870
+ }
10871
+ }
10706
10872
  const cdpParams = {
10707
10873
  cdpAuthToken: toSystemParamsAsset(cdpToken),
10708
10874
  cdpAssetSymbol: { unCurrencySymbol: assetSymbol },
@@ -10771,8 +10937,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10771
10937
  lucid.newTx().pay.ToAddress(
10772
10938
  await lucid.wallet().address(),
10773
10939
  (0, import_lucid65.addAssets)(
10774
- (0, import_cardano_offchain_common28.mkAssetsOf)(iassetToken, 1n),
10775
- (0, import_cardano_offchain_common28.mkLovelacesOf)(BigInt(totalCollateralAssetsCount) * 5000000n)
10940
+ (0, import_cardano_offchain_common31.mkAssetsOf)(iassetToken, 1n),
10941
+ (0, import_cardano_offchain_common31.mkLovelacesOf)(BigInt(totalCollateralAssetsCount) * 5000000n)
10776
10942
  )
10777
10943
  )
10778
10944
  );
@@ -10789,8 +10955,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10789
10955
  lucid.newTx().pay.ToAddress(
10790
10956
  await lucid.wallet().address(),
10791
10957
  (0, import_lucid65.addAssets)(
10792
- (0, import_cardano_offchain_common28.mkAssetsOf)(cdpCreatorAsset, 1n),
10793
- (0, import_cardano_offchain_common28.mkLovelacesOf)(BigInt(totalStablePoolsCount) * 5000000n)
10958
+ (0, import_cardano_offchain_common31.mkAssetsOf)(cdpCreatorAsset, 1n),
10959
+ (0, import_cardano_offchain_common31.mkLovelacesOf)(BigInt(totalStablePoolsCount) * 5000000n)
10794
10960
  )
10795
10961
  )
10796
10962
  );
@@ -10886,7 +11052,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10886
11052
  lucid,
10887
11053
  govParams,
10888
11054
  govNftAsset,
10889
- defaultInitialAssets,
11055
+ initialAssets,
10890
11056
  protocolParams
10891
11057
  );
10892
11058
  const robParams = {
@@ -11069,20 +11235,87 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
11069
11235
  return [sysParams, assetInfos];
11070
11236
  }
11071
11237
 
11072
- // src/contracts/stableswap/helpers.ts
11238
+ // src/contracts/iasset/queries.ts
11073
11239
  var import_lucid66 = require("@lucid-evolution/lucid");
11240
+ var import_cardano_offchain_common32 = require("@3rd-eye-labs/cardano-offchain-common");
11241
+ var import_fp_ts25 = require("fp-ts");
11242
+ async function findIAsset(lucid, sysParams, iassetName) {
11243
+ const iassetUtxos = await lucid.utxosAtWithUnit(
11244
+ createScriptAddress(
11245
+ lucid.config().network,
11246
+ sysParams.validatorHashes.iassetHash
11247
+ ),
11248
+ (0, import_cardano_offchain_common32.assetClassToUnit)(
11249
+ fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken)
11250
+ )
11251
+ );
11252
+ return (0, import_cardano_offchain_common32.matchSingle)(
11253
+ import_fp_ts25.function.pipe(
11254
+ iassetUtxos.map(
11255
+ (utxo) => import_fp_ts25.function.pipe(
11256
+ import_fp_ts25.option.fromNullable(utxo.datum),
11257
+ import_fp_ts25.option.flatMap(parseIAssetDatum),
11258
+ import_fp_ts25.option.flatMap((datum) => {
11259
+ if ((0, import_lucid66.toHex)(datum.assetName) === (0, import_lucid66.toHex)(iassetName)) {
11260
+ return import_fp_ts25.option.some({ utxo, datum });
11261
+ } else {
11262
+ return import_fp_ts25.option.none;
11263
+ }
11264
+ })
11265
+ )
11266
+ ),
11267
+ import_fp_ts25.array.compact
11268
+ ),
11269
+ (res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
11270
+ );
11271
+ }
11272
+ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset) {
11273
+ const collateralAssetUtxos = await lucid.utxosAtWithUnit(
11274
+ createScriptAddress(
11275
+ lucid.config().network,
11276
+ sysParams.validatorHashes.iassetHash
11277
+ ),
11278
+ (0, import_cardano_offchain_common32.assetClassToUnit)(
11279
+ fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken)
11280
+ )
11281
+ );
11282
+ return (0, import_cardano_offchain_common32.matchSingle)(
11283
+ import_fp_ts25.function.pipe(
11284
+ collateralAssetUtxos.map(
11285
+ (utxo) => import_fp_ts25.function.pipe(
11286
+ import_fp_ts25.option.fromNullable(utxo.datum),
11287
+ import_fp_ts25.option.flatMap(parseCollateralAssetDatum),
11288
+ import_fp_ts25.option.flatMap((datum) => {
11289
+ if ((0, import_cardano_offchain_common32.isSameAssetClass)(datum.collateralAsset, collateralAsset) && (0, import_lucid66.toHex)(iassetName) === (0, import_lucid66.toHex)(datum.iasset)) {
11290
+ return import_fp_ts25.option.some({ utxo, datum });
11291
+ } else {
11292
+ return import_fp_ts25.option.none;
11293
+ }
11294
+ })
11295
+ )
11296
+ ),
11297
+ import_fp_ts25.array.compact
11298
+ ),
11299
+ (res) => new Error(
11300
+ "Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
11301
+ )
11302
+ );
11303
+ }
11304
+
11305
+ // src/contracts/stableswap/helpers.ts
11306
+ var import_lucid67 = require("@lucid-evolution/lucid");
11074
11307
 
11075
11308
  // src/contracts/stableswap/types-new.ts
11076
- var import_cardano_offchain_common29 = require("@3rd-eye-labs/cardano-offchain-common");
11309
+ var import_cardano_offchain_common33 = require("@3rd-eye-labs/cardano-offchain-common");
11077
11310
  var import_evolution20 = require("@evolution-sdk/evolution");
11078
- var import_fp_ts21 = require("fp-ts");
11311
+ var import_fp_ts26 = require("fp-ts");
11079
11312
  var import_effect3 = require("effect");
11080
11313
  var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
11081
11314
  var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
11082
11315
  iasset: import_evolution20.TSchema.ByteArray,
11083
- collateralAsset: import_cardano_offchain_common29.AssetClassSchema,
11316
+ collateralAsset: import_cardano_offchain_common33.AssetClassSchema,
11084
11317
  owner: import_evolution20.TSchema.ByteArray,
11085
- destination: import_cardano_offchain_common29.AddressSchema,
11318
+ destination: import_cardano_offchain_common33.AddressSchema,
11086
11319
  destinationInlineDatum: import_evolution20.TSchema.NullOr(OpaqueData4),
11087
11320
  maxExecutionFee: import_evolution20.TSchema.Integer,
11088
11321
  maxFeeRatio: RationalSchema
@@ -11107,7 +11340,7 @@ var StableswapOrderRedeemerSchema = import_evolution20.TSchema.Union(
11107
11340
  );
11108
11341
  var StableswapOutputDatumSchema = import_evolution20.TSchema.Tuple([
11109
11342
  import_evolution20.TSchema.ByteArray,
11110
- import_cardano_offchain_common29.OutputReferenceSchema
11343
+ import_cardano_offchain_common33.OutputReferenceSchema
11111
11344
  ]);
11112
11345
  function serialiseStableswapOrderDatum(d) {
11113
11346
  return import_evolution20.Data.withSchema(
@@ -11117,22 +11350,22 @@ function serialiseStableswapOrderDatum(d) {
11117
11350
  }
11118
11351
  function parseStableswapOrderDatum(datum) {
11119
11352
  try {
11120
- return import_fp_ts21.option.some(
11353
+ return import_fp_ts26.option.some(
11121
11354
  import_evolution20.Data.withSchema(
11122
11355
  StableswapOrderDatumSchema,
11123
11356
  DEFAULT_SCHEMA_OPTIONS
11124
11357
  ).fromCBORHex(datum)
11125
11358
  );
11126
11359
  } catch (_) {
11127
- return import_fp_ts21.option.none;
11360
+ return import_fp_ts26.option.none;
11128
11361
  }
11129
11362
  }
11130
11363
  function parseStableswapOrderDatumOrThrow(datum) {
11131
- return import_fp_ts21.function.pipe(
11364
+ return import_fp_ts26.function.pipe(
11132
11365
  parseStableswapOrderDatum(datum),
11133
- import_fp_ts21.option.match(() => {
11366
+ import_fp_ts26.option.match(() => {
11134
11367
  throw new Error("Expected a Stableswap Order datum.");
11135
- }, import_fp_ts21.function.identity)
11368
+ }, import_fp_ts26.function.identity)
11136
11369
  );
11137
11370
  }
11138
11371
  function serialiseStableswapOutputDatum(d) {
@@ -11149,22 +11382,22 @@ function serialiseStableswapOrderRedeemer(r) {
11149
11382
  }
11150
11383
  function parseStableswapOrderRedeemer(redeemerCborHex) {
11151
11384
  try {
11152
- return import_fp_ts21.option.some(
11385
+ return import_fp_ts26.option.some(
11153
11386
  import_evolution20.Data.withSchema(
11154
11387
  StableswapOrderRedeemerSchema,
11155
11388
  DEFAULT_SCHEMA_OPTIONS
11156
11389
  ).fromCBORHex(redeemerCborHex)
11157
11390
  );
11158
11391
  } catch (_) {
11159
- return import_fp_ts21.option.none;
11392
+ return import_fp_ts26.option.none;
11160
11393
  }
11161
11394
  }
11162
11395
  function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
11163
- return import_fp_ts21.function.pipe(
11396
+ return import_fp_ts26.function.pipe(
11164
11397
  parseStableswapOrderRedeemer(redeemerCborHex),
11165
- import_fp_ts21.option.match(() => {
11398
+ import_fp_ts26.option.match(() => {
11166
11399
  throw new Error("Expected a Stableswap Order redeemer.");
11167
- }, import_fp_ts21.function.identity)
11400
+ }, import_fp_ts26.function.identity)
11168
11401
  );
11169
11402
  }
11170
11403
 
@@ -11174,9 +11407,9 @@ var BASE_MAX_EXECUTION_FEE = 1620000n;
11174
11407
  function createDestinationDatum(datum, outRef) {
11175
11408
  if (!datum) {
11176
11409
  return serialiseStableswapOutputDatum([
11177
- (0, import_lucid66.fromHex)((0, import_lucid66.fromText)("IndigoStableswap")),
11410
+ (0, import_lucid67.fromHex)((0, import_lucid67.fromText)("IndigoStableswap")),
11178
11411
  {
11179
- txHash: (0, import_lucid66.fromHex)(outRef.txHash),
11412
+ txHash: (0, import_lucid67.fromHex)(outRef.txHash),
11180
11413
  outputIndex: BigInt(outRef.outputIndex)
11181
11414
  }
11182
11415
  ]);
@@ -11185,28 +11418,28 @@ function createDestinationDatum(datum, outRef) {
11185
11418
  }
11186
11419
 
11187
11420
  // src/contracts/stableswap/transactions.ts
11188
- var import_lucid67 = require("@lucid-evolution/lucid");
11189
- var import_cardano_offchain_common30 = require("@3rd-eye-labs/cardano-offchain-common");
11190
- var import_fp_ts22 = require("fp-ts");
11421
+ var import_lucid68 = require("@lucid-evolution/lucid");
11422
+ var import_cardano_offchain_common34 = require("@3rd-eye-labs/cardano-offchain-common");
11423
+ var import_fp_ts27 = require("fp-ts");
11191
11424
  var import_Array3 = require("fp-ts/lib/Array");
11192
11425
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
11193
11426
  const myAddress = await lucid.wallet().address();
11194
- const pkh = (0, import_lucid67.paymentCredentialOf)(myAddress);
11427
+ const pkh = (0, import_lucid68.paymentCredentialOf)(myAddress);
11195
11428
  const datum = {
11196
- iasset: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset)),
11429
+ iasset: (0, import_lucid68.fromHex)((0, import_lucid68.fromText)(iasset)),
11197
11430
  collateralAsset,
11198
- owner: (0, import_lucid67.fromHex)(pkh.hash),
11199
- destination: (0, import_cardano_offchain_common30.addressFromBech32)(destinationAddress ?? myAddress),
11431
+ owner: (0, import_lucid68.fromHex)(pkh.hash),
11432
+ destination: (0, import_cardano_offchain_common34.addressFromBech32)(destinationAddress ?? myAddress),
11200
11433
  destinationInlineDatum: destinationInlineDatum ?? null,
11201
11434
  maxExecutionFee,
11202
11435
  maxFeeRatio: maxFeeRatio ?? (minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio)
11203
11436
  };
11204
- const assetsToSwap = minting ? (0, import_cardano_offchain_common30.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common30.mkAssetsOf)(
11437
+ const assetsToSwap = minting ? (0, import_cardano_offchain_common34.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common34.mkAssetsOf)(
11205
11438
  {
11206
- currencySymbol: (0, import_lucid67.fromHex)(
11439
+ currencySymbol: (0, import_lucid68.fromHex)(
11207
11440
  params.stableswapParams.iassetSymbol.unCurrencySymbol
11208
11441
  ),
11209
- tokenName: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset))
11442
+ tokenName: (0, import_lucid68.fromHex)((0, import_lucid68.fromText)(iasset))
11210
11443
  },
11211
11444
  amount
11212
11445
  );
@@ -11224,7 +11457,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11224
11457
  );
11225
11458
  const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
11226
11459
  return lucid.newTx().pay.ToContract(
11227
- (0, import_lucid67.credentialToAddress)(lucid.config().network, {
11460
+ (0, import_lucid68.credentialToAddress)(lucid.config().network, {
11228
11461
  hash: params.validatorHashes.stableswapHash,
11229
11462
  type: "Script"
11230
11463
  }),
@@ -11232,16 +11465,16 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11232
11465
  kind: "inline",
11233
11466
  value: serialiseStableswapOrderDatum(datum)
11234
11467
  },
11235
- (0, import_lucid67.addAssets)(
11468
+ (0, import_lucid68.addAssets)(
11236
11469
  assetsToSwap,
11237
- (0, import_cardano_offchain_common30.mkLovelacesOf)(
11470
+ (0, import_cardano_offchain_common34.mkLovelacesOf)(
11238
11471
  roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
11239
11472
  )
11240
11473
  )
11241
11474
  );
11242
11475
  }
11243
11476
  async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11244
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11477
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11245
11478
  await lucid.utxosByOutRef([
11246
11479
  fromSystemParamsScriptRef(
11247
11480
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11249,20 +11482,20 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11249
11482
  ]),
11250
11483
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11251
11484
  );
11252
- const stableswapOrderUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11485
+ const stableswapOrderUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11253
11486
  await lucid.utxosByOutRef([stableswapOrderOref]),
11254
11487
  (_) => new Error("Expected a single Stableswap Order UTXO.")
11255
11488
  );
11256
11489
  const stableswapOrderDatum = parseStableswapOrderDatumOrThrow(
11257
- (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapOrderUtxo)
11490
+ (0, import_cardano_offchain_common34.getInlineDatumOrThrow)(stableswapOrderUtxo)
11258
11491
  );
11259
11492
  return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
11260
11493
  [stableswapOrderUtxo],
11261
11494
  serialiseStableswapOrderRedeemer("CancelStableswapOrder")
11262
- ).addSignerKey((0, import_lucid67.toHex)(stableswapOrderDatum.owner));
11495
+ ).addSignerKey((0, import_lucid68.toHex)(stableswapOrderDatum.owner));
11263
11496
  }
11264
11497
  async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
11265
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11498
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11266
11499
  await lucid.utxosByOutRef([
11267
11500
  fromSystemParamsScriptRef(
11268
11501
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11270,13 +11503,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11270
11503
  ]),
11271
11504
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11272
11505
  );
11273
- const cdpScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11506
+ const cdpScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11274
11507
  await lucid.utxosByOutRef([
11275
11508
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
11276
11509
  ]),
11277
11510
  (_) => new Error("Expected a single CDP Ref Script UTXO")
11278
11511
  );
11279
- const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11512
+ const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11280
11513
  await lucid.utxosByOutRef([
11281
11514
  fromSystemParamsScriptRef(
11282
11515
  sysParams.scriptReferences.iAssetTokenPolicyRef
@@ -11288,7 +11521,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11288
11521
  throw new Error("At least one order must be provided.");
11289
11522
  }
11290
11523
  const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
11291
- const sortedStableswapOrderUtxos = (0, import_lucid67.sortUTxOs)(
11524
+ const sortedStableswapOrderUtxos = (0, import_lucid68.sortUTxOs)(
11292
11525
  stableswapOrderUtxos,
11293
11526
  "Canonical"
11294
11527
  );
@@ -11297,32 +11530,32 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11297
11530
  }
11298
11531
  const mainOrderUtxo = sortedStableswapOrderUtxos[0];
11299
11532
  const mainOrderDatum = parseStableswapOrderDatumOrThrow(
11300
- (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(mainOrderUtxo)
11533
+ (0, import_cardano_offchain_common34.getInlineDatumOrThrow)(mainOrderUtxo)
11301
11534
  );
11302
11535
  const iassetAc = {
11303
- currencySymbol: (0, import_lucid67.fromHex)(
11536
+ currencySymbol: (0, import_lucid68.fromHex)(
11304
11537
  sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
11305
11538
  ),
11306
11539
  tokenName: mainOrderDatum.iasset
11307
11540
  };
11308
11541
  const collateralAc = mainOrderDatum.collateralAsset;
11309
- const stableswapPoolUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11542
+ const stableswapPoolUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11310
11543
  await lucid.utxosByOutRef([stableswapPoolOref]),
11311
11544
  (_) => new Error("Expected a single cdp UTXO")
11312
11545
  );
11313
11546
  const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
11314
- (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapPoolUtxo)
11547
+ (0, import_cardano_offchain_common34.getInlineDatumOrThrow)(stableswapPoolUtxo)
11315
11548
  );
11316
11549
  const ordersInfo = sortedStableswapOrderUtxos.map(
11317
11550
  (orderUtxo) => {
11318
11551
  const orderDatum = parseStableswapOrderDatumOrThrow(
11319
- (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(orderUtxo)
11552
+ (0, import_cardano_offchain_common34.getInlineDatumOrThrow)(orderUtxo)
11320
11553
  );
11321
- 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)) {
11554
+ if ((0, import_lucid68.toHex)(orderDatum.iasset) != (0, import_lucid68.toHex)(mainOrderDatum.iasset) || (0, import_lucid68.toHex)(orderDatum.collateralAsset.currencySymbol) != (0, import_lucid68.toHex)(mainOrderDatum.collateralAsset.currencySymbol) || (0, import_lucid68.toHex)(orderDatum.collateralAsset.tokenName) != (0, import_lucid68.toHex)(mainOrderDatum.collateralAsset.tokenName)) {
11322
11555
  throw new Error("Wrong batch of orders");
11323
11556
  }
11324
- const suppliedIasset = (0, import_cardano_offchain_common30.assetClassValueOf)(orderUtxo.assets, iassetAc);
11325
- const suppliedCollateralAsset = (0, import_cardano_offchain_common30.assetClassValueOf)(
11557
+ const suppliedIasset = (0, import_cardano_offchain_common34.assetClassValueOf)(orderUtxo.assets, iassetAc);
11558
+ const suppliedCollateralAsset = (0, import_cardano_offchain_common34.assetClassValueOf)(
11326
11559
  orderUtxo.assets,
11327
11560
  collateralAc
11328
11561
  );
@@ -11446,9 +11679,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11446
11679
  }
11447
11680
  }
11448
11681
  );
11449
- const totalSwapInfo = import_fp_ts22.function.pipe(
11682
+ const totalSwapInfo = import_fp_ts27.function.pipe(
11450
11683
  ordersInfo,
11451
- import_fp_ts22.array.reduce(
11684
+ import_fp_ts27.array.reduce(
11452
11685
  {
11453
11686
  suppliedCollateralAsset: 0n,
11454
11687
  suppliedIasset: 0n,
@@ -11490,20 +11723,20 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11490
11723
  kind: "inline",
11491
11724
  value: serialiseStableswapPoolDatum(stableswapPoolDatum)
11492
11725
  },
11493
- collateralAmtChangePool != 0n ? (0, import_lucid67.addAssets)(
11726
+ collateralAmtChangePool != 0n ? (0, import_lucid68.addAssets)(
11494
11727
  stableswapPoolUtxo.assets,
11495
- (0, import_cardano_offchain_common30.mkAssetsOf)(collateralAc, collateralAmtChangePool)
11728
+ (0, import_cardano_offchain_common34.mkAssetsOf)(collateralAc, collateralAmtChangePool)
11496
11729
  ) : stableswapPoolUtxo.assets
11497
11730
  ).setMinFee(stableswapOrderOrefs.length > 1 ? 1498875n : 1030000n);
11498
11731
  if (amountToMint !== 0n) {
11499
- tx.mintAssets((0, import_cardano_offchain_common30.mkAssetsOf)(iassetAc, amountToMint), import_lucid67.Data.void());
11732
+ tx.mintAssets((0, import_cardano_offchain_common34.mkAssetsOf)(iassetAc, amountToMint), import_lucid68.Data.void());
11500
11733
  }
11501
- import_fp_ts22.function.pipe(
11734
+ import_fp_ts27.function.pipe(
11502
11735
  ordersInfo,
11503
- import_fp_ts22.array.reduce(tx, (acc, orderInfo) => {
11736
+ import_fp_ts27.array.reduce(tx, (acc, orderInfo) => {
11504
11737
  return acc.collectFrom(
11505
11738
  [orderInfo.utxo],
11506
- (0, import_cardano_offchain_common30.isSameOutRef)(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
11739
+ (0, import_cardano_offchain_common34.isSameOutRef)(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
11507
11740
  kind: "selected",
11508
11741
  makeRedeemer: (inputIndices) => {
11509
11742
  return serialiseStableswapOrderRedeemer({
@@ -11516,7 +11749,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11516
11749
  inputs: [orderInfo.utxo, mainOrderUtxo]
11517
11750
  }
11518
11751
  ).pay.ToAddressWithData(
11519
- (0, import_cardano_offchain_common30.addressToBech32)(orderInfo.datum.destination, lucid.config().network),
11752
+ (0, import_cardano_offchain_common34.addressToBech32)(orderInfo.datum.destination, lucid.config().network),
11520
11753
  {
11521
11754
  kind: "inline",
11522
11755
  value: createDestinationDatum(
@@ -11524,13 +11757,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11524
11757
  orderInfo.utxo
11525
11758
  )
11526
11759
  },
11527
- (0, import_lucid67.addAssets)(
11760
+ (0, import_lucid68.addAssets)(
11528
11761
  // Currently, we always take the max execution fee from the order utxo.
11529
11762
  // This can be improved so that we take the actual execution fee.
11530
- (0, import_cardano_offchain_common30.mkLovelacesOf)(
11531
- (0, import_cardano_offchain_common30.lovelacesAmt)(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
11763
+ (0, import_cardano_offchain_common34.mkLovelacesOf)(
11764
+ (0, import_cardano_offchain_common34.lovelacesAmt)(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
11532
11765
  ),
11533
- orderInfo.swapInfo.owedIasset > 0 ? (0, import_cardano_offchain_common30.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common30.mkAssetsOf)(
11766
+ orderInfo.swapInfo.owedIasset > 0 ? (0, import_cardano_offchain_common34.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common34.mkAssetsOf)(
11534
11767
  collateralAc,
11535
11768
  orderInfo.swapInfo.owedCollateralAsset
11536
11769
  )
@@ -11553,7 +11786,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11553
11786
  return tx;
11554
11787
  }
11555
11788
  async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
11556
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11789
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11557
11790
  await lucid.utxosByOutRef([
11558
11791
  fromSystemParamsScriptRef(
11559
11792
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11561,22 +11794,22 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11561
11794
  ]),
11562
11795
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11563
11796
  );
11564
- const cdpScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11797
+ const cdpScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11565
11798
  await lucid.utxosByOutRef([
11566
11799
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
11567
11800
  ]),
11568
11801
  (_) => new Error("Expected a single CDP Ref Script UTXO")
11569
11802
  );
11570
- const stableswapPool = (0, import_cardano_offchain_common30.matchSingle)(
11803
+ const stableswapPool = (0, import_cardano_offchain_common34.matchSingle)(
11571
11804
  await lucid.utxosByOutRef([stableswapPoolOutRef]),
11572
11805
  (_) => new Error("Expected a single Stableswap Pool UTXO.")
11573
11806
  );
11574
- const stableswapFeeUtxo = (0, import_cardano_offchain_common30.matchSingle)(
11807
+ const stableswapFeeUtxo = (0, import_cardano_offchain_common34.matchSingle)(
11575
11808
  await lucid.utxosByOutRef([stableswapFeeOutRef]),
11576
11809
  (_) => new Error("Expected a single Stableswap Fee UTXO.")
11577
11810
  );
11578
11811
  const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
11579
- (0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapPool)
11812
+ (0, import_cardano_offchain_common34.getInlineDatumOrThrow)(stableswapPool)
11580
11813
  );
11581
11814
  const newStableswapPoolDatum = {
11582
11815
  ...stableswapPoolDatum,
@@ -11604,7 +11837,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11604
11837
  value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
11605
11838
  },
11606
11839
  stableswapPool.assets
11607
- ).addSignerKey((0, import_lucid67.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
11840
+ ).addSignerKey((0, import_lucid68.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
11608
11841
  }
11609
11842
  // Annotate the CommonJS export names for ESM import in node:
11610
11843
  0 && (module.exports = {
@@ -11714,6 +11947,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11714
11947
  closeCdp,
11715
11948
  closeStakingPosition,
11716
11949
  collectInterestTx,
11950
+ collectPriceFeedIds,
11717
11951
  collectorFeeTx,
11718
11952
  createDestinationDatum,
11719
11953
  createE2s2sSnapshots,
@@ -11726,6 +11960,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11726
11960
  decodePythMessage,
11727
11961
  depositCdp,
11728
11962
  deriveAuthToken,
11963
+ derivePythPrice,
11729
11964
  distributeAda,
11730
11965
  distributeInterest,
11731
11966
  distributeReward,
@@ -11738,6 +11973,17 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11738
11973
  executeProposal,
11739
11974
  feedInterestOracle,
11740
11975
  feedPriceOracleTx,
11976
+ findAdminInterestCollectors,
11977
+ findAllInterestCollectors,
11978
+ findAllTreasuryUtxos,
11979
+ findAllTreasuryUtxosWithNonAdaAsset,
11980
+ findCollateralAsset,
11981
+ findIAsset,
11982
+ findRandomCdpCreator,
11983
+ findRandomNonAdminInterestCollector,
11984
+ findRandomTreasuryUtxo,
11985
+ findRandomTreasuryUtxoWithAsset,
11986
+ findRandomTreasuryUtxoWithOnlyAda,
11741
11987
  findRelevantE2s2sIdxs,
11742
11988
  findStakingManager,
11743
11989
  findStakingManagerByOutRef,