@indigo-labs/indigo-sdk 0.4.4 → 0.5.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.
Files changed (51) hide show
  1. package/dist/index.d.mts +121 -40
  2. package/dist/index.d.ts +121 -40
  3. package/dist/index.js +962 -818
  4. package/dist/index.mjs +418 -282
  5. package/package.json +2 -2
  6. package/scripts/run-repeat.sh +22 -0
  7. package/src/contracts/cdp/helpers.ts +7 -6
  8. package/src/contracts/cdp/transactions.ts +8 -29
  9. package/src/contracts/gov/transactions.ts +12 -16
  10. package/src/contracts/iasset/helpers.ts +2 -7
  11. package/src/contracts/initialize/actions.ts +0 -2
  12. package/src/contracts/initialize/helpers.ts +0 -4
  13. package/src/contracts/interest-collection/transactions.ts +2 -5
  14. package/src/contracts/interest-oracle/helpers.ts +4 -0
  15. package/src/contracts/interest-oracle/transactions.ts +1 -4
  16. package/src/contracts/price-oracle/helpers.ts +5 -11
  17. package/src/contracts/price-oracle/transactions.ts +2 -7
  18. package/src/contracts/rob/transactions.ts +0 -2
  19. package/src/contracts/rob-leverage/transactions.ts +1 -4
  20. package/src/contracts/stability-pool/transactions.ts +2 -8
  21. package/src/contracts/stableswap/helpers.ts +487 -2
  22. package/src/contracts/stableswap/transactions.ts +53 -222
  23. package/src/contracts/staking/transactions.ts +2 -7
  24. package/tests/cdp/actions.ts +0 -11
  25. package/tests/cdp/cdp-helpers.ts +2 -2
  26. package/tests/cdp/cdp-queries.ts +1 -3
  27. package/tests/cdp/cdp.test.ts +407 -619
  28. package/tests/cdp/transactions-mutated.ts +30 -25
  29. package/tests/endpoints/initialize.ts +0 -2
  30. package/tests/gov/actions.ts +7 -32
  31. package/tests/gov/gov.test.ts +169 -401
  32. package/tests/indigo-test-helpers.ts +2 -3
  33. package/tests/initialize.test.ts +15 -20
  34. package/tests/interest-collection/interest-collection.test.ts +0 -4
  35. package/tests/interest-oracle.test.ts +1 -8
  36. package/tests/price-oracle/actions.ts +6 -8
  37. package/tests/price-oracle/price-oracle.test.ts +1 -13
  38. package/tests/price-oracle/transactions-mutated.ts +1 -4
  39. package/tests/pyth/pyth-indigo.test.ts +8 -12
  40. package/tests/pyth/pyth.test.ts +1 -2
  41. package/tests/rob/actions.ts +0 -2
  42. package/tests/rob/rob-leverage.test.ts +164 -220
  43. package/tests/rob/rob.test.ts +158 -263
  44. package/tests/rob/transactions-mutated.ts +7 -18
  45. package/tests/stability-pool/actions.ts +4 -8
  46. package/tests/stability-pool.test.ts +164 -255
  47. package/tests/stableswap/stableswap-actions.ts +0 -1
  48. package/tests/stableswap/stableswap-queries.ts +26 -17
  49. package/tests/stableswap/stableswap.test.ts +338 -4
  50. package/tests/staking.test.ts +2 -13
  51. package/tests/treasury/treasury.test.ts +6 -30
package/dist/index.mjs CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  fromHex as fromHex7,
7
7
  getInputIndices as getInputIndices3,
8
8
  scriptHashToCredential as scriptHashToCredential3,
9
- slotToUnixTime as slotToUnixTime5,
10
9
  toHex as toHex7
11
10
  } from "@lucid-evolution/lucid";
12
11
 
@@ -431,16 +430,11 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
431
430
  }
432
431
 
433
432
  // src/contracts/price-oracle/helpers.ts
434
- import {
435
- slotToUnixTime,
436
- unixTimeToSlot
437
- } from "@lucid-evolution/lucid";
438
- function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
439
- const validateFrom = slotToUnixTime(network, currentSlot - 1);
433
+ function oracleExpirationAwareValidity(lucid, biasTime, oracleExpiration) {
434
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
440
435
  const defaultValidateTo = validateFrom + biasTime;
441
- const cappedValidateTo = slotToUnixTime(
442
- network,
443
- unixTimeToSlot(network, oracleExpiration) - 1
436
+ const cappedValidateTo = lucid.slotToUnixTime(
437
+ lucid.unixTimeToSlot(oracleExpiration) - 1
444
438
  );
445
439
  const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
446
440
  return {
@@ -453,7 +447,6 @@ function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration,
453
447
  import { match as match13, P as P13 } from "ts-pattern";
454
448
 
455
449
  // src/contracts/cdp/helpers.ts
456
- import { slotToUnixTime as slotToUnixTime2 } from "@lucid-evolution/lucid";
457
450
  import { match as match4, P as P4 } from "ts-pattern";
458
451
 
459
452
  // src/utils/indigo-helpers.ts
@@ -471,11 +464,10 @@ function iassetValueOfCollateral(collateralAmt, oraclePrice) {
471
464
  rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
472
465
  );
473
466
  }
474
- function cdpCollateralRatioPercentage(currentSlot, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum, network) {
475
- const currentTime = BigInt(slotToUnixTime2(network, currentSlot));
467
+ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
476
468
  return match4(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: P4.select() }, (interest) => {
477
469
  const interestAmt = calculateAccruedInterest(
478
- currentTime,
470
+ now,
479
471
  interest.unitaryInterestSnapshot,
480
472
  cdpContent.mintedAmt,
481
473
  interest.lastSettled,
@@ -1606,7 +1598,6 @@ import {
1606
1598
  toHex as toHex4,
1607
1599
  addAssets as addAssets3,
1608
1600
  fromHex as fromHex3,
1609
- slotToUnixTime as slotToUnixTime3,
1610
1601
  sortUTxOs,
1611
1602
  getInputIndices as getInputIndices2
1612
1603
  } from "@lucid-evolution/lucid";
@@ -2098,9 +2089,8 @@ function parseCollateralAssetDatumOrThrow(datum) {
2098
2089
  }
2099
2090
 
2100
2091
  // src/contracts/interest-collection/transactions.ts
2101
- async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef, interestOracleOutRef, cdpOutRefs, params, lucid, currentSlot) {
2102
- const network = lucid.config().network;
2103
- const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
2092
+ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef, interestOracleOutRef, cdpOutRefs, params, lucid) {
2093
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
2104
2094
  const interestCollectionRefScriptUtxo = matchSingle(
2105
2095
  await lucid.utxosByOutRef([
2106
2096
  fromSystemParamsScriptRef(
@@ -2196,7 +2186,7 @@ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef
2196
2186
  referenceInputs,
2197
2187
  false
2198
2188
  );
2199
- const validateFrom = slotToUnixTime3(network, currentSlot - 1);
2189
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
2200
2190
  const validateTo = validateFrom + Number(params.cdpParams.biasTime);
2201
2191
  const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(referenceInputs).collectFrom([interestCollectorUtxo], {
2202
2192
  kind: "selected",
@@ -3246,7 +3236,6 @@ import {
3246
3236
  Data as Data18,
3247
3237
  fromHex as fromHex6,
3248
3238
  scriptHashToCredential as scriptHashToCredential2,
3249
- slotToUnixTime as slotToUnixTime4,
3250
3239
  toHex as toHex6
3251
3240
  } from "@lucid-evolution/lucid";
3252
3241
  import { match as match11, P as P11 } from "ts-pattern";
@@ -3743,11 +3732,9 @@ function derivePythPrice(derivedPythPrice, messageHex) {
3743
3732
  // src/contracts/iasset/helpers.ts
3744
3733
  import * as Core from "@evolution-sdk/evolution";
3745
3734
  var MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
3746
- function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, currentSlot, lucid, tx) {
3735
+ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, lucid, tx) {
3747
3736
  return match11(priceInfo).returnType().with({ Delisted: P11.any }, () => {
3748
- const currentTime = BigInt(
3749
- slotToUnixTime4(lucid.config().network, currentSlot)
3750
- );
3737
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
3751
3738
  const validFrom = Number(currentTime - BigInt(biasTime / 2n));
3752
3739
  const validTo = Number(currentTime + BigInt(biasTime / 2n));
3753
3740
  return Promise.resolve({
@@ -3768,10 +3755,9 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
3768
3755
  );
3769
3756
  return {
3770
3757
  interval: oracleExpirationAwareValidity(
3771
- currentSlot,
3758
+ lucid,
3772
3759
  Number(biasTime),
3773
- Number(priceOracleDatum.expirationTime),
3774
- lucid.config().network
3760
+ Number(priceOracleDatum.expirationTime)
3775
3761
  ),
3776
3762
  referenceInputs: [priceOracleUtxo]
3777
3763
  };
@@ -3875,9 +3861,9 @@ async function retrieveAdjustedPrice(iasset, collateralAsset, priceInfo, extraDe
3875
3861
  }
3876
3862
 
3877
3863
  // src/contracts/cdp/transactions.ts
3878
- async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, lucid, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
3864
+ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, lucid, pythMessage = void 0, pythStateOref = void 0) {
3879
3865
  const network = lucid.config().network;
3880
- const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
3866
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
3881
3867
  const [pkh, skh] = await addrDetails(lucid);
3882
3868
  const cdpCreatorRefScriptUtxo = matchSingle(
3883
3869
  await lucid.utxosByOutRef([
@@ -3999,7 +3985,6 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
3999
3985
  pythMessage,
4000
3986
  sysParams.pythConfig,
4001
3987
  sysParams.cdpCreatorParams.biasTime,
4002
- currentSlot,
4003
3988
  lucid,
4004
3989
  tx
4005
3990
  );
@@ -4047,9 +4032,8 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
4047
4032
  });
4048
4033
  return tx;
4049
4034
  }
4050
- async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, sysParams, lucid, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
4051
- const network = lucid.config().network;
4052
- const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
4035
+ async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, sysParams, lucid, pythMessage = void 0, pythStateOref = void 0) {
4036
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
4053
4037
  const cdpRefScriptUtxo = matchSingle(
4054
4038
  await lucid.utxosByOutRef([
4055
4039
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
@@ -4115,7 +4099,6 @@ async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOr
4115
4099
  pythMessage,
4116
4100
  sysParams.pythConfig,
4117
4101
  sysParams.cdpParams.biasTime,
4118
- currentSlot,
4119
4102
  lucid,
4120
4103
  tx
4121
4104
  );
@@ -4210,7 +4193,7 @@ async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOr
4210
4193
  tx.addSignerKey(toHex7(cdpDatum.cdpOwner));
4211
4194
  return tx;
4212
4195
  }
4213
- async function depositCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, currentSlot) {
4196
+ async function depositCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid) {
4214
4197
  return adjustCdp(
4215
4198
  amount,
4216
4199
  0n,
@@ -4222,11 +4205,10 @@ async function depositCdp(amount, cdpOref, iassetOref, collateralAssetOref, inte
4222
4205
  treasuryOref,
4223
4206
  interestCollectorOref,
4224
4207
  params,
4225
- lucid,
4226
- currentSlot
4208
+ lucid
4227
4209
  );
4228
4210
  }
4229
- async function withdrawCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
4211
+ async function withdrawCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, pythMessage = void 0, pythStateOref = void 0) {
4230
4212
  return adjustCdp(
4231
4213
  -amount,
4232
4214
  0n,
@@ -4239,12 +4221,11 @@ async function withdrawCdp(amount, cdpOref, iassetOref, collateralAssetOref, pri
4239
4221
  interestCollectorOref,
4240
4222
  params,
4241
4223
  lucid,
4242
- currentSlot,
4243
4224
  pythMessage,
4244
4225
  pythStateOref
4245
4226
  );
4246
4227
  }
4247
- async function mintCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
4228
+ async function mintCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, pythMessage = void 0, pythStateOref = void 0) {
4248
4229
  return adjustCdp(
4249
4230
  0n,
4250
4231
  amount,
@@ -4257,12 +4238,11 @@ async function mintCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOr
4257
4238
  interestCollectorOref,
4258
4239
  params,
4259
4240
  lucid,
4260
- currentSlot,
4261
4241
  pythMessage,
4262
4242
  pythStateOref
4263
4243
  );
4264
4244
  }
4265
- async function burnCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, currentSlot) {
4245
+ async function burnCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid) {
4266
4246
  return adjustCdp(
4267
4247
  0n,
4268
4248
  -amount,
@@ -4274,13 +4254,11 @@ async function burnCdp(amount, cdpOref, iassetOref, collateralAssetOref, interes
4274
4254
  treasuryOref,
4275
4255
  interestCollectorOref,
4276
4256
  params,
4277
- lucid,
4278
- currentSlot
4257
+ lucid
4279
4258
  );
4280
4259
  }
4281
- async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, interestCollectorOref, sysParams, lucid, currentSlot) {
4282
- const network = lucid.config().network;
4283
- const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
4260
+ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, interestCollectorOref, sysParams, lucid) {
4261
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
4284
4262
  const cdpRefScriptUtxo = matchSingle(
4285
4263
  await lucid.utxosByOutRef([
4286
4264
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
@@ -4322,7 +4300,7 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
4322
4300
  const interestOracleDatum = parseInterestOracleDatum(
4323
4301
  getInlineDatumOrThrow(interestOracleUtxo)
4324
4302
  );
4325
- const validateFrom = slotToUnixTime5(network, currentSlot - 1);
4303
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4326
4304
  const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4327
4305
  const tx = lucid.newTx().readFrom([
4328
4306
  cdpRefScriptUtxo,
@@ -4380,9 +4358,8 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
4380
4358
  }
4381
4359
  return tx;
4382
4360
  }
4383
- async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, interestCollectorOref, treasuryOref, govOref, sysParams, lucid, currentSlot, pythMessage = void 0, _pythStateOref = void 0) {
4384
- const network = lucid.config().network;
4385
- const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
4361
+ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, interestCollectorOref, treasuryOref, govOref, sysParams, lucid, pythMessage = void 0, _pythStateOref = void 0) {
4362
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
4386
4363
  const cdpRefScriptUtxo = matchSingle(
4387
4364
  await lucid.utxosByOutRef([
4388
4365
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
@@ -4512,15 +4489,14 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
4512
4489
  getInlineDatumOrThrow(priceOracleUtxo)
4513
4490
  );
4514
4491
  const txValidity = oracleExpirationAwareValidity(
4515
- currentSlot,
4492
+ lucid,
4516
4493
  Number(sysParams.cdpCreatorParams.biasTime),
4517
- Number(priceOracleDatum.expirationTime),
4518
- network
4494
+ Number(priceOracleDatum.expirationTime)
4519
4495
  );
4520
4496
  referenceInputs.push(priceOracleUtxo);
4521
4497
  tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
4522
4498
  } else {
4523
- const validateFrom = slotToUnixTime5(network, currentSlot - 1);
4499
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4524
4500
  const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4525
4501
  tx.validFrom(validateFrom).validTo(validateTo);
4526
4502
  }
@@ -4632,9 +4608,9 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
4632
4608
  );
4633
4609
  return tx;
4634
4610
  }
4635
- async function freezeCdp(cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, sysParams, lucid, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
4611
+ async function freezeCdp(cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, sysParams, lucid, pythMessage = void 0, pythStateOref = void 0) {
4636
4612
  const network = lucid.config().network;
4637
- const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
4613
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
4638
4614
  const cdpRefScriptUtxo = matchSingle(
4639
4615
  await lucid.utxosByOutRef([
4640
4616
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
@@ -4717,7 +4693,6 @@ async function freezeCdp(cdpOref, iassetOref, collateralAssetOref, priceOracleOr
4717
4693
  pythMessage,
4718
4694
  sysParams.pythConfig,
4719
4695
  sysParams.cdpParams.biasTime,
4720
- currentSlot,
4721
4696
  lucid,
4722
4697
  tx
4723
4698
  );
@@ -5317,7 +5292,6 @@ import {
5317
5292
  fromHex as fromHex8,
5318
5293
  fromText as fromText4,
5319
5294
  paymentCredentialOf as paymentCredentialOf2,
5320
- slotToUnixTime as slotToUnixTime6,
5321
5295
  toHex as toHex8
5322
5296
  } from "@lucid-evolution/lucid";
5323
5297
  import {
@@ -5770,9 +5744,9 @@ import {
5770
5744
  addressFromBech32,
5771
5745
  addressToBech32
5772
5746
  } from "@3rd-eye-labs/cardano-offchain-common";
5773
- async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, govOref, allIAssetOrefs) {
5747
+ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, govOref, allIAssetOrefs) {
5774
5748
  const network = lucid.config().network;
5775
- const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
5749
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
5776
5750
  const ownAddr = await lucid.wallet().address();
5777
5751
  const pkh = paymentCredentialOf2(ownAddr);
5778
5752
  const govRefScriptUtxo = matchSingle(
@@ -5891,9 +5865,9 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
5891
5865
  newPollId
5892
5866
  ];
5893
5867
  }
5894
- async function createShardsChunks(chunkSize, pollManagerOref, sysParams, currentSlot, lucid) {
5868
+ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, lucid) {
5895
5869
  const network = lucid.config().network;
5896
- const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
5870
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
5897
5871
  const ownAddr = await lucid.wallet().address();
5898
5872
  const pollManagerUtxo = matchSingle(
5899
5873
  await lucid.utxosByOutRef([pollManagerOref]),
@@ -5982,9 +5956,8 @@ function voteHelper(stakingPosLockedAmt, pollShard, voteOption, currentTime, ind
5982
5956
  ];
5983
5957
  return [newLockedAmt, newPollStatus];
5984
5958
  }
5985
- async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, lucid, currentSlot) {
5986
- const network = lucid.config().network;
5987
- const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
5959
+ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, lucid) {
5960
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
5988
5961
  const ownAddr = await lucid.wallet().address();
5989
5962
  const pollShardRefScriptUtxo = matchSingle(
5990
5963
  await lucid.utxosByOutRef([
@@ -6030,7 +6003,10 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
6030
6003
  indyStakedAmt
6031
6004
  );
6032
6005
  return lucid.newTx().validFrom(validityFrom).validTo(
6033
- validityFrom + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
6006
+ Math.min(
6007
+ validityFrom + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND,
6008
+ Number(pollShardDatum.votingEndTime) - ONE_SECOND
6009
+ )
6034
6010
  ).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
6035
6011
  [pollShardUtxo],
6036
6012
  serialisePollShardRedeemer({ Vote: voteOption })
@@ -6058,9 +6034,8 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
6058
6034
  stakingPosUtxo.assets
6059
6035
  ).addSigner(ownAddr);
6060
6036
  }
6061
- async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, currentSlot) {
6062
- const network = lucid.config().network;
6063
- const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
6037
+ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid) {
6038
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
6064
6039
  const ownAddr = await lucid.wallet().address();
6065
6040
  const pollShardRefScriptUtxo = matchSingle(
6066
6041
  await lucid.utxosByOutRef([
@@ -6147,9 +6122,9 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
6147
6122
  addAssets8(pollManagerUtxo.assets, shardsAggregatedAda)
6148
6123
  ).addSigner(ownAddr);
6149
6124
  }
6150
- async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSlot) {
6125
+ async function endProposal(pollManagerOref, govOref, sysParams, lucid) {
6151
6126
  const network = lucid.config().network;
6152
- const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
6127
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
6153
6128
  const ownAddr = await lucid.wallet().address();
6154
6129
  const pollManagerRefScriptUtxo = matchSingle(
6155
6130
  await lucid.utxosByOutRef([
@@ -6261,9 +6236,9 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
6261
6236
  }
6262
6237
  return tx;
6263
6238
  }
6264
- async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, allIAssetOrefs, iAssetOref, allCollateralAssetsOrefsOfIAsset, collateralAssetOref, stableswapPoolOrCdpCreatorOref, sysParams, lucid, currentSlot) {
6239
+ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, allIAssetOrefs, iAssetOref, allCollateralAssetsOrefsOfIAsset, collateralAssetOref, stableswapPoolOrCdpCreatorOref, sysParams, lucid) {
6265
6240
  const network = lucid.config().network;
6266
- const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
6241
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
6267
6242
  const ownAddr = await lucid.wallet().address();
6268
6243
  const govUtxo = matchSingle(
6269
6244
  await lucid.utxosByOutRef([govOref]),
@@ -6998,7 +6973,6 @@ import {
6998
6973
  Data as Data32,
6999
6974
  fromHex as fromHex9,
7000
6975
  fromText as fromText5,
7001
- slotToUnixTime as slotToUnixTime7,
7002
6976
  toHex as toHex9
7003
6977
  } from "@lucid-evolution/lucid";
7004
6978
  import {
@@ -7068,9 +7042,8 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
7068
7042
  }
7069
7043
  ).addSignerKey(pkh.hash);
7070
7044
  }
7071
- async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, currentSlot, stakingManagerRef) {
7072
- const network = lucid.config().network;
7073
- const now = BigInt(slotToUnixTime7(network, currentSlot));
7045
+ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, stakingManagerRef) {
7046
+ const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
7074
7047
  const stakingPositionOut = await findStakingPositionByOutRef(
7075
7048
  stakingPositionRef,
7076
7049
  lucid
@@ -7125,9 +7098,8 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
7125
7098
  addAssets9(stakingPositionOut.utxo.assets, mkAssetsOf7(indyToken, amount))
7126
7099
  ).addSignerKey(toHex9(stakingPositionOut.datum.owner));
7127
7100
  }
7128
- async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
7129
- const network = lucid.config().network;
7130
- const now = BigInt(slotToUnixTime7(network, currentSlot));
7101
+ async function closeStakingPosition(stakingPositionRef, params, lucid, stakingManagerRef) {
7102
+ const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
7131
7103
  const stakingPositionOut = await findStakingPositionByOutRef(
7132
7104
  stakingPositionRef,
7133
7105
  lucid
@@ -7249,7 +7221,6 @@ function castStakingParams(params) {
7249
7221
  import {
7250
7222
  fromHex as fromHex10,
7251
7223
  fromText as fromText6,
7252
- slotToUnixTime as slotToUnixTime8,
7253
7224
  toUnit as toUnit2,
7254
7225
  validatorToAddress
7255
7226
  } from "@lucid-evolution/lucid";
@@ -7431,14 +7402,13 @@ async function startInterestOracle(initialUnitaryInterest, initialInterestRate,
7431
7402
  }
7432
7403
  ];
7433
7404
  }
7434
- async function feedInterestOracle(params, newInterestRate, lucid, currentSlot, assetClass, utxo, scriptRef2) {
7405
+ async function feedInterestOracle(params, newInterestRate, lucid, assetClass, utxo, scriptRef2) {
7435
7406
  if (!assetClass && !utxo)
7436
7407
  throw new Error("Either interest oracle nft or utxo must be provided");
7437
7408
  if (assetClass && !utxo) {
7438
7409
  utxo = await findInterestOracle(lucid, assetClass);
7439
7410
  }
7440
- const network = lucid.config().network;
7441
- const now = BigInt(slotToUnixTime8(network, currentSlot));
7411
+ const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
7442
7412
  const tx = lucid.newTx();
7443
7413
  const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo));
7444
7414
  if (scriptRef2) {
@@ -7962,7 +7932,6 @@ import {
7962
7932
  fromHex as fromHex11,
7963
7933
  toHex as toHex12,
7964
7934
  addAssets as addAssets11,
7965
- slotToUnixTime as slotToUnixTime9,
7966
7935
  credentialToAddress as credentialToAddress3
7967
7936
  } from "@lucid-evolution/lucid";
7968
7937
  import {
@@ -8129,9 +8098,8 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
8129
8098
  )
8130
8099
  ).addSignerKey(toHex12(oldAccountDatum.owner));
8131
8100
  }
8132
- async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot, txFee) {
8133
- const network = lucid.config().network;
8134
- const currentTime = BigInt(slotToUnixTime9(network, currentSlot));
8101
+ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee) {
8102
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
8135
8103
  const stabilityPoolScriptRef = matchSingle5(
8136
8104
  await lucid.utxosByOutRef([
8137
8105
  fromSystemParamsScriptRef(
@@ -8147,7 +8115,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8147
8115
  getInlineDatumOrThrow(stabilityPoolUtxo)
8148
8116
  );
8149
8117
  const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
8150
- const validFrom = slotToUnixTime9(network, currentSlot - 1);
8118
+ const validFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
8151
8119
  const tx = lucid.newTx().validFrom(validFrom).validTo(validFrom + sysParams.stabilityPoolParams.accountProcessingBiasMs).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8152
8120
  kind: "selected",
8153
8121
  inputs: [stabilityPoolUtxo, accountUtxo],
@@ -8519,7 +8487,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8519
8487
  }).exhaustive();
8520
8488
  return tx;
8521
8489
  }
8522
- async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot) {
8490
+ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid) {
8523
8491
  const draftTx = processSpRequestAuxiliary(
8524
8492
  stabilityPoolUtxo,
8525
8493
  accountUtxo,
@@ -8527,7 +8495,6 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8527
8495
  allE2s2sSnapshotOrefs,
8528
8496
  sysParams,
8529
8497
  lucid,
8530
- currentSlot,
8531
8498
  // Placeholder transation fee
8532
8499
  1n
8533
8500
  );
@@ -8539,7 +8506,6 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8539
8506
  allE2s2sSnapshotOrefs,
8540
8507
  sysParams,
8541
8508
  lucid,
8542
- currentSlot,
8543
8509
  fee
8544
8510
  );
8545
8511
  }
@@ -9176,7 +9142,7 @@ async function cancelRob(robOutRef, sysParams, lucid) {
9176
9142
  const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
9177
9143
  return lucid.newTx().readFrom([robScriptRefUtxo]).collectFrom([robUtxo], serialiseRobRedeemer("Cancel")).addSignerKey(toHex14(robDatum.owner));
9178
9144
  }
9179
- async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, lucid, sysParams, currentSlot, pythMessage = void 0, pythStateOutRef = void 0) {
9145
+ async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, lucid, sysParams, pythMessage = void 0, pythStateOutRef = void 0) {
9180
9146
  const robScriptRefUtxo = matchSingle(
9181
9147
  await lucid.utxosByOutRef([
9182
9148
  fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef)
@@ -9220,7 +9186,6 @@ async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, co
9220
9186
  pythMessage,
9221
9187
  sysParams.pythConfig,
9222
9188
  sysParams.cdpParams.biasTime,
9223
- currentSlot,
9224
9189
  lucid,
9225
9190
  tx
9226
9191
  );
@@ -9394,7 +9359,6 @@ var mkRobValidatorFromSP = (params) => {
9394
9359
  // src/contracts/rob-leverage/transactions.ts
9395
9360
  import {
9396
9361
  addAssets as addAssets14,
9397
- slotToUnixTime as slotToUnixTime10,
9398
9362
  Data as Data45,
9399
9363
  fromHex as fromHex14,
9400
9364
  getInputIndices as getInputIndices5
@@ -9580,9 +9544,9 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
9580
9544
  // src/contracts/rob-leverage/transactions.ts
9581
9545
  import { mkAssetsOf as mkAssetsOf11 } from "@3rd-eye-labs/cardano-offchain-common";
9582
9546
  import Decimal3 from "decimal.js";
9583
- async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
9547
+ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, pythMessage = void 0, pythStateOref = void 0) {
9584
9548
  const network = lucid.config().network;
9585
- const currentTime = BigInt(slotToUnixTime10(network, currentSlot));
9549
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
9586
9550
  const [pkh, skh] = await addrDetails(lucid);
9587
9551
  const robScriptRefUtxo = matchSingle(
9588
9552
  await lucid.utxosByOutRef([
@@ -9776,7 +9740,6 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
9776
9740
  pythMessage,
9777
9741
  sysParams.pythConfig,
9778
9742
  sysParams.cdpCreatorParams.biasTime,
9779
- currentSlot,
9780
9743
  lucid,
9781
9744
  tx
9782
9745
  );
@@ -9834,7 +9797,6 @@ import {
9834
9797
  Data as Data46,
9835
9798
  fromHex as fromHex15,
9836
9799
  fromText as fromText10,
9837
- slotToUnixTime as slotToUnixTime11,
9838
9800
  validatorToAddress as validatorToAddress2
9839
9801
  } from "@lucid-evolution/lucid";
9840
9802
 
@@ -9863,9 +9825,8 @@ function mkPriceOracleValidator(params) {
9863
9825
  // src/contracts/price-oracle/transactions.ts
9864
9826
  import { mkAssetsOf as mkAssetsOf12 } from "@3rd-eye-labs/cardano-offchain-common";
9865
9827
  import * as Core2 from "@evolution-sdk/evolution";
9866
- async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, currentSlot, refOutRef, auxiliaryData) {
9867
- const network = lucid.config().network;
9868
- const now = BigInt(slotToUnixTime11(network, currentSlot));
9828
+ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, refOutRef, auxiliaryData) {
9829
+ const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
9869
9830
  if (!refOutRef) {
9870
9831
  refOutRef = (await lucid.wallet().getUtxos())[0];
9871
9832
  }
@@ -9898,9 +9859,8 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
9898
9859
  );
9899
9860
  return [tx, priceOracleNft];
9900
9861
  }
9901
- async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, currentSlot, auxiliaryData) {
9902
- const network = lucid.config().network;
9903
- const currentTime = BigInt(slotToUnixTime11(network, currentSlot));
9862
+ async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, auxiliaryData) {
9863
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
9904
9864
  const priceOracleUtxo = matchSingle(
9905
9865
  await lucid.utxosByOutRef([oracleOref]),
9906
9866
  (_) => new Error("Expected a single price oracle UTXO")
@@ -10214,7 +10174,7 @@ async function initStakingManager(lucid, stakingParams) {
10214
10174
  );
10215
10175
  await submitTx(lucid, tx);
10216
10176
  }
10217
- async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig, currentSlot) {
10177
+ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig) {
10218
10178
  return match20(collateralAsset.priceOracle).returnType().with({ tag: "_indigo_oracle_nft" }, async (val) => {
10219
10179
  const [pkh, _] = await addrDetails(lucid);
10220
10180
  const priceOracleParams = {
@@ -10226,8 +10186,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
10226
10186
  lucid,
10227
10187
  val.tokenName,
10228
10188
  val.startPrice,
10229
- priceOracleParams,
10230
- currentSlot
10189
+ priceOracleParams
10231
10190
  );
10232
10191
  await runAndAwaitTxBuilder(lucid, priceOracleStartTx);
10233
10192
  return { info: { OracleNft: priceOracleNft }, params: priceOracleParams };
@@ -10248,7 +10207,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
10248
10207
  });
10249
10208
  }).exhaustive();
10250
10209
  }
10251
- async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig, currentSlot) {
10210
+ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig) {
10252
10211
  const iassetName = fromHex16(fromText11(asset.name));
10253
10212
  const collateralAssetInfos = [];
10254
10213
  for (const collateralAsset of asset.collateralAssets) {
@@ -10270,8 +10229,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10270
10229
  lucid,
10271
10230
  asset,
10272
10231
  collateralAsset,
10273
- pythConfig,
10274
- currentSlot
10232
+ pythConfig
10275
10233
  );
10276
10234
  const collateralAssetContent = {
10277
10235
  iasset: iassetName,
@@ -10672,7 +10630,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10672
10630
  pythFeeds: allPythFeeds
10673
10631
  };
10674
10632
  }
10675
- async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets = () => [], protocolParams, initOptions, spStakingCred = DEFAULT_STAKING_CRED, treasuryStakingCred = DEFAULT_STAKING_CRED) {
10633
+ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], protocolParams, initOptions, spStakingCred = DEFAULT_STAKING_CRED, treasuryStakingCred = DEFAULT_STAKING_CRED) {
10676
10634
  const startSlot = lucid.currentSlot();
10677
10635
  const {
10678
10636
  totalIndySupply,
@@ -10972,8 +10930,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
10972
10930
  stabilityPoolParams,
10973
10931
  stabilityPoolToken,
10974
10932
  asset,
10975
- pythConfig,
10976
- currentSlot
10933
+ pythConfig
10977
10934
  );
10978
10935
  assetInfos.push(assetInfo);
10979
10936
  }
@@ -11293,7 +11250,12 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
11293
11250
  }
11294
11251
 
11295
11252
  // src/contracts/stableswap/helpers.ts
11296
- import { fromHex as fromHex19, fromText as fromText14 } from "@lucid-evolution/lucid";
11253
+ import {
11254
+ fromHex as fromHex19,
11255
+ fromText as fromText14,
11256
+ toHex as toHex19
11257
+ } from "@lucid-evolution/lucid";
11258
+ import { array as A16, ord as Ord5, function as F27 } from "fp-ts";
11297
11259
 
11298
11260
  // src/contracts/stableswap/types-new.ts
11299
11261
  import {
@@ -11397,7 +11359,16 @@ function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
11397
11359
 
11398
11360
  // src/contracts/stableswap/helpers.ts
11399
11361
  import { Data as Data52 } from "@evolution-sdk/evolution";
11362
+ import {
11363
+ addressToBech32 as addressToBech323,
11364
+ assetClassValueOf as assetClassValueOf12,
11365
+ lovelacesAmt as lovelacesAmt5
11366
+ } from "@3rd-eye-labs/cardano-offchain-common";
11400
11367
  var BASE_MAX_EXECUTION_FEE = 1620000n;
11368
+ var defaultPSMProcessingConfig = {
11369
+ enforceMaxExecutionFeeConstraint: true,
11370
+ enforceMinLovelaceConstraint: true
11371
+ };
11401
11372
  function createDestinationDatum(datum, outRef) {
11402
11373
  if (!datum) {
11403
11374
  return serialiseStableswapOutputDatum([
@@ -11410,6 +11381,283 @@ function createDestinationDatum(datum, outRef) {
11410
11381
  }
11411
11382
  return Data52.toCBORHex(datum);
11412
11383
  }
11384
+ function estimateMinOrderOutputLovelaces(lucid, orderDatum, orderAssets) {
11385
+ const expectedOutputLovelaces = estimateUtxoMinLovelace(
11386
+ lucid.config().protocolParameters,
11387
+ addressToBech323(orderDatum.destination, lucid.config().network),
11388
+ orderAssets,
11389
+ {
11390
+ kind: "inline",
11391
+ value: createDestinationDatum(orderDatum.destinationInlineDatum ?? null, {
11392
+ txHash: "0000000000000000000000000000000000000000000000000000000000000000",
11393
+ outputIndex: 0
11394
+ })
11395
+ }
11396
+ );
11397
+ const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
11398
+ return roundedExpectedOutputLovelaces;
11399
+ }
11400
+ function psmOrderType(order, sysParams) {
11401
+ const iassetAc = {
11402
+ currencySymbol: fromHex19(
11403
+ sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
11404
+ ),
11405
+ tokenName: order.datum.iasset
11406
+ };
11407
+ const suppliedIasset = assetClassValueOf12(order.utxo.assets, iassetAc);
11408
+ const suppliedCollateralAsset = assetClassValueOf12(
11409
+ order.utxo.assets,
11410
+ order.datum.collateralAsset
11411
+ );
11412
+ if (suppliedIasset != 0n && suppliedCollateralAsset != 0n || suppliedIasset == 0n && suppliedCollateralAsset == 0n) {
11413
+ return {
11414
+ type: "ERROR",
11415
+ errorTag: "VALUE_ERROR",
11416
+ reason: "An order must supply either iAsset or collateral asset"
11417
+ };
11418
+ }
11419
+ const isMinting = suppliedCollateralAsset > 0n;
11420
+ return isMinting ? { type: "MINTING", suppliedCollateral: suppliedCollateralAsset } : { type: "REDEEMING", suppliedIassets: suppliedIasset };
11421
+ }
11422
+ function summariseOrder(lucid, order, psmPool, sysParams, psmProcessingConfig) {
11423
+ const config = {
11424
+ ...defaultPSMProcessingConfig,
11425
+ ...psmProcessingConfig
11426
+ };
11427
+ const orderType = psmOrderType(order, sysParams);
11428
+ if (orderType.type === "ERROR") {
11429
+ return {
11430
+ _tag: "ERROR",
11431
+ errorTag: orderType.errorTag,
11432
+ description: orderType.reason
11433
+ };
11434
+ }
11435
+ if (toHex19(order.datum.iasset) !== toHex19(psmPool.datum.iasset) || toHex19(order.datum.collateralAsset.currencySymbol) !== toHex19(psmPool.datum.collateralAsset.currencySymbol) || toHex19(order.datum.collateralAsset.tokenName) !== toHex19(psmPool.datum.collateralAsset.tokenName)) {
11436
+ return {
11437
+ _tag: "ERROR",
11438
+ errorTag: "ASSET_MISMATCH",
11439
+ description: "Order - PSM assets mismatch"
11440
+ };
11441
+ }
11442
+ const isOneToOne = psmPool.datum.collateralToIassetRatio.numerator === psmPool.datum.collateralToIassetRatio.denominator;
11443
+ if (config.enforceMaxExecutionFeeConstraint && order.datum.maxExecutionFee < BASE_MAX_EXECUTION_FEE) {
11444
+ return {
11445
+ _tag: "ERROR",
11446
+ errorTag: "EXECUTION_FEE",
11447
+ description: `Max execution fee is too low. Minimum: ${BASE_MAX_EXECUTION_FEE}`
11448
+ };
11449
+ }
11450
+ if (config.enforceMinLovelaceConstraint && lovelacesAmt5(order.utxo.assets) < estimateMinOrderOutputLovelaces(lucid, order.datum, order.utxo.assets) + order.datum.maxExecutionFee) {
11451
+ return {
11452
+ _tag: "ERROR",
11453
+ errorTag: "INSUFFICIENT_LOVELACES",
11454
+ description: "Order has insufficient lovelaces to cover execution fee and order output."
11455
+ };
11456
+ }
11457
+ if (orderType.type === "MINTING") {
11458
+ const suppliedCollateralAsset = orderType.suppliedCollateral;
11459
+ if (rationalToFloat(order.datum.maxFeeRatio) < rationalToFloat(psmPool.datum.mintingFeeRatio)) {
11460
+ return {
11461
+ _tag: "ERROR",
11462
+ errorTag: "MAX_FEE",
11463
+ description: "Max fee ratio not satisfied"
11464
+ };
11465
+ }
11466
+ if (isOneToOne) {
11467
+ const fee = calculateFeeFromRatio(
11468
+ psmPool.datum.mintingFeeRatio,
11469
+ suppliedCollateralAsset
11470
+ );
11471
+ return {
11472
+ _tag: "SUCCESS",
11473
+ result: {
11474
+ order,
11475
+ orderType: "MINTING",
11476
+ swapInfo: {
11477
+ suppliedCollateralAsset,
11478
+ suppliedIasset: 0n,
11479
+ owedCollateralAsset: 0n,
11480
+ owedIasset: suppliedCollateralAsset - fee,
11481
+ mintingFee: fee,
11482
+ redemptionFee: 0n
11483
+ }
11484
+ }
11485
+ };
11486
+ } else {
11487
+ const iAssetConversion = rationalFloor(
11488
+ rationalDiv(
11489
+ rationalFromInt(suppliedCollateralAsset),
11490
+ psmPool.datum.collateralToIassetRatio
11491
+ )
11492
+ );
11493
+ const attemptedNormalizedCollateral = rationalFloor(
11494
+ rationalMul(
11495
+ rationalFromInt(iAssetConversion),
11496
+ psmPool.datum.collateralToIassetRatio
11497
+ )
11498
+ );
11499
+ const normalizedCollateralSupplied = rationalFloor(
11500
+ rationalDiv(
11501
+ rationalFromInt(attemptedNormalizedCollateral),
11502
+ psmPool.datum.collateralToIassetRatio
11503
+ )
11504
+ ) != iAssetConversion ? suppliedCollateralAsset : attemptedNormalizedCollateral;
11505
+ const fee = calculateFeeFromRatio(
11506
+ psmPool.datum.mintingFeeRatio,
11507
+ iAssetConversion
11508
+ );
11509
+ return {
11510
+ _tag: "SUCCESS",
11511
+ result: {
11512
+ order,
11513
+ orderType: "MINTING",
11514
+ swapInfo: {
11515
+ suppliedCollateralAsset: normalizedCollateralSupplied,
11516
+ suppliedIasset: 0n,
11517
+ owedIasset: iAssetConversion - fee,
11518
+ owedCollateralAsset: 0n,
11519
+ mintingFee: fee,
11520
+ redemptionFee: 0n
11521
+ }
11522
+ }
11523
+ };
11524
+ }
11525
+ } else {
11526
+ const suppliedIasset = orderType.suppliedIassets;
11527
+ if (rationalToFloat(order.datum.maxFeeRatio) < rationalToFloat(psmPool.datum.redemptionFeeRatio)) {
11528
+ return {
11529
+ _tag: "ERROR",
11530
+ errorTag: "MAX_FEE",
11531
+ description: "Max fee ratio not satisfied"
11532
+ };
11533
+ }
11534
+ const fee = calculateFeeFromRatio(
11535
+ psmPool.datum.redemptionFeeRatio,
11536
+ suppliedIasset
11537
+ );
11538
+ const effectiveSuppliedIasset = suppliedIasset - fee;
11539
+ if (isOneToOne) {
11540
+ return {
11541
+ _tag: "SUCCESS",
11542
+ result: {
11543
+ order,
11544
+ orderType: "REDEEMING",
11545
+ swapInfo: {
11546
+ suppliedIasset: effectiveSuppliedIasset,
11547
+ suppliedCollateralAsset: 0n,
11548
+ owedCollateralAsset: effectiveSuppliedIasset,
11549
+ owedIasset: 0n,
11550
+ redemptionFee: fee,
11551
+ mintingFee: 0n
11552
+ }
11553
+ }
11554
+ };
11555
+ } else {
11556
+ const collateralConversion = rationalFloor(
11557
+ rationalMul(
11558
+ rationalFromInt(effectiveSuppliedIasset),
11559
+ psmPool.datum.collateralToIassetRatio
11560
+ )
11561
+ );
11562
+ const attemptedNormalizedEffectiveIasset = rationalFloor(
11563
+ rationalDiv(
11564
+ rationalFromInt(collateralConversion),
11565
+ psmPool.datum.collateralToIassetRatio
11566
+ )
11567
+ );
11568
+ const normalizedEffectiveIasset = rationalFloor(
11569
+ rationalMul(
11570
+ rationalFromInt(attemptedNormalizedEffectiveIasset),
11571
+ psmPool.datum.collateralToIassetRatio
11572
+ )
11573
+ ) != collateralConversion ? effectiveSuppliedIasset : attemptedNormalizedEffectiveIasset;
11574
+ return {
11575
+ _tag: "SUCCESS",
11576
+ result: {
11577
+ order,
11578
+ orderType: "REDEEMING",
11579
+ swapInfo: {
11580
+ suppliedIasset: normalizedEffectiveIasset,
11581
+ suppliedCollateralAsset: 0n,
11582
+ owedCollateralAsset: rationalFloor(
11583
+ rationalMul(
11584
+ rationalFromInt(effectiveSuppliedIasset),
11585
+ psmPool.datum.collateralToIassetRatio
11586
+ )
11587
+ ),
11588
+ owedIasset: 0n,
11589
+ redemptionFee: fee,
11590
+ mintingFee: 0n
11591
+ }
11592
+ }
11593
+ };
11594
+ }
11595
+ }
11596
+ }
11597
+ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessingConfig) {
11598
+ const psmAvailableLiq = assetClassValueOf12(
11599
+ pool.utxo.assets,
11600
+ pool.datum.collateralAsset
11601
+ );
11602
+ const validOrders = orders.flatMap((order) => {
11603
+ try {
11604
+ const res = summariseOrder(
11605
+ lucid,
11606
+ order,
11607
+ pool,
11608
+ sysParams,
11609
+ psmProcessingConfig
11610
+ );
11611
+ return res._tag === "SUCCESS" ? [res.result] : [];
11612
+ } catch (_) {
11613
+ return [];
11614
+ }
11615
+ });
11616
+ const { left: mintingOrders, right: redeemingOrdersSortedDesc } = F27.pipe(
11617
+ validOrders,
11618
+ A16.partition((o) => o.orderType === "REDEEMING"),
11619
+ ({ left, right }) => ({
11620
+ left,
11621
+ // Sort the redeeming orders descending.
11622
+ right: F27.pipe(
11623
+ right,
11624
+ A16.sort(
11625
+ Ord5.contramap(
11626
+ (o) => o.swapInfo.owedCollateralAsset
11627
+ )(Ord5.reverse(BigIntOrd))
11628
+ )
11629
+ )
11630
+ })
11631
+ );
11632
+ const totalCollateralDiff = F27.pipe(
11633
+ validOrders,
11634
+ A16.reduce(
11635
+ 0n,
11636
+ (acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
11637
+ )
11638
+ );
11639
+ if (psmAvailableLiq + totalCollateralDiff >= 0n) {
11640
+ return validOrders.map((o) => o.order);
11641
+ }
11642
+ const collateralFromMinting = F27.pipe(
11643
+ mintingOrders,
11644
+ A16.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
11645
+ );
11646
+ const { selected } = F27.pipe(
11647
+ redeemingOrdersSortedDesc,
11648
+ A16.reduce(
11649
+ {
11650
+ intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
11651
+ selected: []
11652
+ },
11653
+ ({ intermediateCollateralAmt, selected: selected2 }, order) => intermediateCollateralAmt >= order.swapInfo.owedCollateralAsset ? {
11654
+ intermediateCollateralAmt: intermediateCollateralAmt - order.swapInfo.owedCollateralAsset,
11655
+ selected: [...selected2, order]
11656
+ } : { intermediateCollateralAmt, selected: selected2 }
11657
+ )
11658
+ );
11659
+ return [...mintingOrders, ...selected].map((o) => o.order);
11660
+ }
11413
11661
 
11414
11662
  // src/contracts/stableswap/transactions.ts
11415
11663
  import {
@@ -11420,20 +11668,20 @@ import {
11420
11668
  fromText as fromText15,
11421
11669
  paymentCredentialOf as paymentCredentialOf3,
11422
11670
  sortUTxOs as sortUTxOs2,
11423
- toHex as toHex19
11671
+ toHex as toHex20
11424
11672
  } from "@lucid-evolution/lucid";
11425
11673
  import {
11426
11674
  addressFromBech32 as addressFromBech323,
11427
- addressToBech32 as addressToBech323,
11675
+ addressToBech32 as addressToBech324,
11428
11676
  getInlineDatumOrThrow as getInlineDatumOrThrow6,
11429
11677
  matchSingle as matchSingle7,
11430
11678
  mkAssetsOf as mkAssetsOf16,
11431
11679
  mkLovelacesOf as mkLovelacesOf9,
11432
- lovelacesAmt as lovelacesAmt5,
11680
+ lovelacesAmt as lovelacesAmt6,
11433
11681
  isSameOutRef as isSameOutRef2,
11434
- assetClassValueOf as assetClassValueOf12
11682
+ assetClassValueOf as assetClassValueOf13
11435
11683
  } from "@3rd-eye-labs/cardano-offchain-common";
11436
- import { array as A16, function as F27 } from "fp-ts";
11684
+ import { array as A17, function as F28 } from "fp-ts";
11437
11685
  import { isEmpty } from "fp-ts/lib/Array";
11438
11686
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
11439
11687
  const myAddress = await lucid.wallet().address();
@@ -11456,19 +11704,16 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11456
11704
  },
11457
11705
  amount
11458
11706
  );
11459
- const expectedOutputLovelaces = estimateUtxoMinLovelace(
11460
- lucid.config().protocolParameters,
11461
- myAddress,
11707
+ const orderAssetsPlusFees = addAssets18(
11462
11708
  assetsToSwap,
11463
- {
11464
- kind: "inline",
11465
- value: createDestinationDatum(destinationInlineDatum ?? null, {
11466
- txHash: "0000000000000000000000000000000000000000000000000000000000000000",
11467
- outputIndex: 0
11468
- })
11469
- }
11709
+ mkLovelacesOf9(maxExecutionFee),
11710
+ mkLovelacesOf9(additionalLovelaces)
11711
+ );
11712
+ const expectedMinOutputLovelaces = estimateMinOrderOutputLovelaces(
11713
+ lucid,
11714
+ datum,
11715
+ orderAssetsPlusFees
11470
11716
  );
11471
- const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
11472
11717
  return lucid.newTx().pay.ToContract(
11473
11718
  credentialToAddress6(lucid.config().network, {
11474
11719
  hash: params.validatorHashes.stableswapHash,
@@ -11478,12 +11723,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11478
11723
  kind: "inline",
11479
11724
  value: serialiseStableswapOrderDatum(datum)
11480
11725
  },
11481
- addAssets18(
11482
- assetsToSwap,
11483
- mkLovelacesOf9(
11484
- roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
11485
- )
11486
- )
11726
+ addAssets18(orderAssetsPlusFees, mkLovelacesOf9(expectedMinOutputLovelaces))
11487
11727
  );
11488
11728
  }
11489
11729
  async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
@@ -11505,9 +11745,9 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11505
11745
  return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
11506
11746
  [stableswapOrderUtxo],
11507
11747
  serialiseStableswapOrderRedeemer("CancelStableswapOrder")
11508
- ).addSignerKey(toHex19(stableswapOrderDatum.owner));
11748
+ ).addSignerKey(toHex20(stableswapOrderDatum.owner));
11509
11749
  }
11510
- async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
11750
+ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid, psmProcessingConfig) {
11511
11751
  const stableswapScriptRefUtxo = matchSingle7(
11512
11752
  await lucid.utxosByOutRef([
11513
11753
  fromSystemParamsScriptRef(
@@ -11564,137 +11804,22 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11564
11804
  const orderDatum = parseStableswapOrderDatumOrThrow(
11565
11805
  getInlineDatumOrThrow6(orderUtxo)
11566
11806
  );
11567
- if (toHex19(orderDatum.iasset) != toHex19(mainOrderDatum.iasset) || toHex19(orderDatum.collateralAsset.currencySymbol) != toHex19(mainOrderDatum.collateralAsset.currencySymbol) || toHex19(orderDatum.collateralAsset.tokenName) != toHex19(mainOrderDatum.collateralAsset.tokenName)) {
11568
- throw new Error("Wrong batch of orders");
11569
- }
11570
- const suppliedIasset = assetClassValueOf12(orderUtxo.assets, iassetAc);
11571
- const suppliedCollateralAsset = assetClassValueOf12(
11572
- orderUtxo.assets,
11573
- collateralAc
11807
+ const res = summariseOrder(
11808
+ lucid,
11809
+ { utxo: orderUtxo, datum: orderDatum },
11810
+ { utxo: stableswapPoolUtxo, datum: stableswapPoolDatum },
11811
+ sysParams,
11812
+ psmProcessingConfig
11574
11813
  );
11575
- if (suppliedIasset != 0n && suppliedCollateralAsset != 0n || suppliedIasset == 0n && suppliedCollateralAsset == 0n) {
11576
- throw new Error(
11577
- "An order must supply either iAsset or collateral asset"
11578
- );
11579
- }
11580
- const isMinting = suppliedCollateralAsset > 0n;
11581
- const isOneToOne = stableswapPoolDatum.collateralToIassetRatio.numerator === stableswapPoolDatum.collateralToIassetRatio.denominator;
11582
- if (isMinting) {
11583
- if (isOneToOne) {
11584
- const fee2 = calculateFeeFromRatio(
11585
- stableswapPoolDatum.mintingFeeRatio,
11586
- suppliedCollateralAsset
11587
- );
11588
- return {
11589
- utxo: orderUtxo,
11590
- datum: orderDatum,
11591
- swapInfo: {
11592
- suppliedCollateralAsset,
11593
- suppliedIasset: 0n,
11594
- owedCollateralAsset: 0n,
11595
- owedIasset: suppliedCollateralAsset - fee2,
11596
- mintingFee: fee2,
11597
- redemptionFee: 0n
11598
- }
11599
- };
11600
- } else {
11601
- const iAssetConversion = rationalFloor(
11602
- rationalDiv(
11603
- rationalFromInt(suppliedCollateralAsset),
11604
- stableswapPoolDatum.collateralToIassetRatio
11605
- )
11606
- );
11607
- const attemptedNormalizedCollateral = rationalFloor(
11608
- rationalMul(
11609
- rationalFromInt(iAssetConversion),
11610
- stableswapPoolDatum.collateralToIassetRatio
11611
- )
11612
- );
11613
- const normalizedCollateralSupplied = rationalFloor(
11614
- rationalDiv(
11615
- rationalFromInt(attemptedNormalizedCollateral),
11616
- stableswapPoolDatum.collateralToIassetRatio
11617
- )
11618
- ) != iAssetConversion ? suppliedCollateralAsset : attemptedNormalizedCollateral;
11619
- const fee2 = calculateFeeFromRatio(
11620
- stableswapPoolDatum.mintingFeeRatio,
11621
- iAssetConversion
11622
- );
11623
- return {
11624
- utxo: orderUtxo,
11625
- datum: orderDatum,
11626
- swapInfo: {
11627
- suppliedCollateralAsset: normalizedCollateralSupplied,
11628
- suppliedIasset: 0n,
11629
- owedCollateralAsset: 0n,
11630
- owedIasset: iAssetConversion - fee2,
11631
- mintingFee: fee2,
11632
- redemptionFee: 0n
11633
- }
11634
- };
11635
- }
11636
- } else {
11637
- const fee2 = calculateFeeFromRatio(
11638
- stableswapPoolDatum.redemptionFeeRatio,
11639
- suppliedIasset
11640
- );
11641
- const effectiveSuppliedIasset = suppliedIasset - fee2;
11642
- if (isOneToOne) {
11643
- return {
11644
- utxo: orderUtxo,
11645
- datum: orderDatum,
11646
- swapInfo: {
11647
- suppliedCollateralAsset: 0n,
11648
- suppliedIasset: effectiveSuppliedIasset,
11649
- owedCollateralAsset: effectiveSuppliedIasset,
11650
- owedIasset: 0n,
11651
- mintingFee: 0n,
11652
- redemptionFee: fee2
11653
- }
11654
- };
11655
- } else {
11656
- const collateralConversion = rationalFloor(
11657
- rationalMul(
11658
- rationalFromInt(effectiveSuppliedIasset),
11659
- stableswapPoolDatum.collateralToIassetRatio
11660
- )
11661
- );
11662
- const attemptedNormalizedEffectiveIasset = rationalFloor(
11663
- rationalDiv(
11664
- rationalFromInt(collateralConversion),
11665
- stableswapPoolDatum.collateralToIassetRatio
11666
- )
11667
- );
11668
- const normalizedEffectiveIasset = rationalFloor(
11669
- rationalMul(
11670
- rationalFromInt(attemptedNormalizedEffectiveIasset),
11671
- stableswapPoolDatum.collateralToIassetRatio
11672
- )
11673
- ) != collateralConversion ? effectiveSuppliedIasset : attemptedNormalizedEffectiveIasset;
11674
- return {
11675
- utxo: orderUtxo,
11676
- datum: orderDatum,
11677
- swapInfo: {
11678
- suppliedCollateralAsset: 0n,
11679
- suppliedIasset: normalizedEffectiveIasset,
11680
- owedCollateralAsset: rationalFloor(
11681
- rationalMul(
11682
- rationalFromInt(effectiveSuppliedIasset),
11683
- stableswapPoolDatum.collateralToIassetRatio
11684
- )
11685
- ),
11686
- owedIasset: 0n,
11687
- mintingFee: 0n,
11688
- redemptionFee: fee2
11689
- }
11690
- };
11691
- }
11814
+ if (res._tag === "ERROR") {
11815
+ throw new Error(res.description);
11692
11816
  }
11817
+ return res.result;
11693
11818
  }
11694
11819
  );
11695
- const totalSwapInfo = F27.pipe(
11820
+ const totalSwapInfo = F28.pipe(
11696
11821
  ordersInfo,
11697
- A16.reduce(
11822
+ A17.reduce(
11698
11823
  {
11699
11824
  suppliedCollateralAsset: 0n,
11700
11825
  suppliedIasset: 0n,
@@ -11716,6 +11841,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11716
11841
  )
11717
11842
  );
11718
11843
  const collateralAmtChangePool = totalSwapInfo.suppliedCollateralAsset - totalSwapInfo.owedCollateralAsset;
11844
+ const newPsmPoolValue = addAssets18(
11845
+ stableswapPoolUtxo.assets,
11846
+ mkAssetsOf16(collateralAc, collateralAmtChangePool)
11847
+ );
11848
+ if (assetClassValueOf13(newPsmPoolValue, collateralAc) < 0n) {
11849
+ throw new Error("Cannot batch more than liquidity allows");
11850
+ }
11719
11851
  const amountToMint = totalSwapInfo.owedIasset - totalSwapInfo.suppliedIasset + totalSwapInfo.mintingFee;
11720
11852
  const fee = totalSwapInfo.mintingFee + totalSwapInfo.redemptionFee;
11721
11853
  const tx = lucid.newTx().readFrom([
@@ -11736,20 +11868,17 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11736
11868
  kind: "inline",
11737
11869
  value: serialiseStableswapPoolDatum(stableswapPoolDatum)
11738
11870
  },
11739
- collateralAmtChangePool != 0n ? addAssets18(
11740
- stableswapPoolUtxo.assets,
11741
- mkAssetsOf16(collateralAc, collateralAmtChangePool)
11742
- ) : stableswapPoolUtxo.assets
11871
+ newPsmPoolValue
11743
11872
  ).setMinFee(stableswapOrderOrefs.length > 1 ? 1498875n : 1030000n);
11744
11873
  if (amountToMint !== 0n) {
11745
11874
  tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
11746
11875
  }
11747
- F27.pipe(
11876
+ F28.pipe(
11748
11877
  ordersInfo,
11749
- A16.reduce(tx, (acc, orderInfo) => {
11878
+ A17.reduce(tx, (acc, orderInfo) => {
11750
11879
  return acc.collectFrom(
11751
- [orderInfo.utxo],
11752
- isSameOutRef2(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
11880
+ [orderInfo.order.utxo],
11881
+ isSameOutRef2(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
11753
11882
  kind: "selected",
11754
11883
  makeRedeemer: (inputIndices) => {
11755
11884
  return serialiseStableswapOrderRedeemer({
@@ -11759,24 +11888,27 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11759
11888
  }
11760
11889
  });
11761
11890
  },
11762
- inputs: [orderInfo.utxo, mainOrderUtxo]
11891
+ inputs: [orderInfo.order.utxo, mainOrderUtxo]
11763
11892
  }
11764
11893
  ).pay.ToAddressWithData(
11765
- addressToBech323(orderInfo.datum.destination, lucid.config().network),
11894
+ addressToBech324(
11895
+ orderInfo.order.datum.destination,
11896
+ lucid.config().network
11897
+ ),
11766
11898
  {
11767
11899
  kind: "inline",
11768
11900
  value: createDestinationDatum(
11769
- orderInfo.datum.destinationInlineDatum ?? null,
11770
- orderInfo.utxo
11901
+ orderInfo.order.datum.destinationInlineDatum ?? null,
11902
+ orderInfo.order.utxo
11771
11903
  )
11772
11904
  },
11773
11905
  addAssets18(
11774
- // Currently, we always take the max execution fee from the order utxo.
11906
+ // NOTICE: Currently, we always take the max execution fee from the order utxo.
11775
11907
  // This can be improved so that we take the actual execution fee.
11776
11908
  mkLovelacesOf9(
11777
- lovelacesAmt5(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
11909
+ lovelacesAmt6(orderInfo.order.utxo.assets) - orderInfo.order.datum.maxExecutionFee
11778
11910
  ),
11779
- orderInfo.swapInfo.owedIasset > 0 ? mkAssetsOf16(iassetAc, orderInfo.swapInfo.owedIasset) : mkAssetsOf16(
11911
+ orderInfo.orderType === "MINTING" ? mkAssetsOf16(iassetAc, orderInfo.swapInfo.owedIasset) : mkAssetsOf16(
11780
11912
  collateralAc,
11781
11913
  orderInfo.swapInfo.owedCollateralAsset
11782
11914
  )
@@ -11850,7 +11982,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11850
11982
  value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
11851
11983
  },
11852
11984
  stableswapPool.assets
11853
- ).addSignerKey(toHex19(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
11985
+ ).addSignerKey(toHex20(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
11854
11986
  }
11855
11987
  export {
11856
11988
  AccountContentSchema,
@@ -11981,6 +12113,7 @@ export {
11981
12113
  encodePythMessage,
11982
12114
  encodeSignedPythMessage,
11983
12115
  endProposal,
12116
+ estimateMinOrderOutputLovelaces,
11984
12117
  estimateUtxoMinLovelace,
11985
12118
  executeProposal,
11986
12119
  feedInterestOracle,
@@ -12133,7 +12266,9 @@ export {
12133
12266
  parseStakingRedeemer,
12134
12267
  parseStakingRedeemerOrThrow,
12135
12268
  partitionEpochToScaleToSums,
12269
+ pickValidSatisfiableOrders,
12136
12270
  processSpRequest,
12271
+ psmOrderType,
12137
12272
  randomRobsSubsetSatisfyingTargetCollateral,
12138
12273
  rationalAdd,
12139
12274
  rationalCeil,
@@ -12207,6 +12342,7 @@ export {
12207
12342
  startPriceOracleTx,
12208
12343
  submitTx,
12209
12344
  sum,
12345
+ summariseOrder,
12210
12346
  summarizeActualLeverageRedemptions,
12211
12347
  toAssetClassFromLucid,
12212
12348
  toDataDerivedPythPrice,