@indigo-labs/indigo-sdk 0.4.4 → 0.5.0

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 (49) hide show
  1. package/dist/index.d.mts +102 -40
  2. package/dist/index.d.ts +102 -40
  3. package/dist/index.js +900 -801
  4. package/dist/index.mjs +339 -256
  5. package/package.json +2 -2
  6. package/src/contracts/cdp/helpers.ts +7 -6
  7. package/src/contracts/cdp/transactions.ts +8 -29
  8. package/src/contracts/gov/transactions.ts +12 -16
  9. package/src/contracts/iasset/helpers.ts +2 -7
  10. package/src/contracts/initialize/actions.ts +0 -2
  11. package/src/contracts/initialize/helpers.ts +0 -4
  12. package/src/contracts/interest-collection/transactions.ts +2 -5
  13. package/src/contracts/interest-oracle/helpers.ts +4 -0
  14. package/src/contracts/interest-oracle/transactions.ts +1 -4
  15. package/src/contracts/price-oracle/helpers.ts +5 -11
  16. package/src/contracts/price-oracle/transactions.ts +2 -7
  17. package/src/contracts/rob/transactions.ts +0 -2
  18. package/src/contracts/rob-leverage/transactions.ts +1 -4
  19. package/src/contracts/stability-pool/transactions.ts +2 -8
  20. package/src/contracts/stableswap/helpers.ts +369 -1
  21. package/src/contracts/stableswap/transactions.ts +43 -191
  22. package/src/contracts/staking/transactions.ts +2 -7
  23. package/tests/cdp/actions.ts +0 -11
  24. package/tests/cdp/cdp-helpers.ts +2 -2
  25. package/tests/cdp/cdp-queries.ts +1 -3
  26. package/tests/cdp/cdp.test.ts +409 -620
  27. package/tests/cdp/transactions-mutated.ts +30 -25
  28. package/tests/endpoints/initialize.ts +0 -2
  29. package/tests/gov/actions.ts +7 -32
  30. package/tests/gov/gov.test.ts +169 -401
  31. package/tests/indigo-test-helpers.ts +0 -1
  32. package/tests/initialize.test.ts +15 -20
  33. package/tests/interest-collection/interest-collection.test.ts +0 -4
  34. package/tests/interest-oracle.test.ts +1 -8
  35. package/tests/price-oracle/actions.ts +6 -8
  36. package/tests/price-oracle/price-oracle.test.ts +1 -13
  37. package/tests/price-oracle/transactions-mutated.ts +1 -4
  38. package/tests/pyth/pyth-indigo.test.ts +8 -12
  39. package/tests/pyth/pyth.test.ts +1 -2
  40. package/tests/rob/actions.ts +0 -2
  41. package/tests/rob/rob-leverage.test.ts +164 -220
  42. package/tests/rob/rob.test.ts +158 -263
  43. package/tests/rob/transactions-mutated.ts +7 -18
  44. package/tests/stability-pool/actions.ts +4 -8
  45. package/tests/stability-pool.test.ts +164 -255
  46. package/tests/stableswap/stableswap-actions.ts +0 -1
  47. package/tests/stableswap/stableswap.test.ts +226 -4
  48. package/tests/staking.test.ts +2 -13
  49. package/tests/treasury/treasury.test.ts +6 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,7 +31,7 @@
31
31
  "@3rd-eye-labs/cardano-offchain-common": "1.4.7",
32
32
  "@evolution-sdk/evolution": "^0.3.22",
33
33
  "@harmoniclabs/crypto": "^0.3.0",
34
- "@lucid-evolution/lucid": "0.5.5",
34
+ "@lucid-evolution/lucid": "0.6.0",
35
35
  "@noble/ed25519": "^3.0.0",
36
36
  "@pythnetwork/pyth-lazer-sdk": "^6.0.0",
37
37
  "decimal.js": "^10.6.0",
@@ -1,4 +1,4 @@
1
- import { Assets, Network, slotToUnixTime } from '@lucid-evolution/lucid';
1
+ import { Assets } from '@lucid-evolution/lucid';
2
2
  import { calculateAccruedInterest } from '../interest-oracle/helpers';
3
3
  import { match, P } from 'ts-pattern';
4
4
  import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
@@ -30,19 +30,20 @@ export function iassetValueOfCollateral(
30
30
  }
31
31
 
32
32
  export function cdpCollateralRatioPercentage(
33
- currentSlot: number,
33
+ /**
34
+ * Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
35
+ * Otherwise, the unix timestamp should suffice, but might not be 100% precise as on-chain.
36
+ */
37
+ now: bigint,
34
38
  iassetPrice: Rational,
35
39
  cdpUtxoAssets: Assets,
36
40
  cdpContent: CDPContent,
37
41
  interestOracleDatum: InterestOracleDatum,
38
- network: Network,
39
42
  ): number {
40
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
41
-
42
43
  return match(cdpContent.cdpFees)
43
44
  .with({ ActiveCDPInterestTracking: P.select() }, (interest) => {
44
45
  const interestAmt = calculateAccruedInterest(
45
- currentTime,
46
+ now,
46
47
  interest.unitaryInterestSnapshot,
47
48
  cdpContent.mintedAmt,
48
49
  interest.lastSettled,
@@ -8,7 +8,6 @@ import {
8
8
  LucidEvolution,
9
9
  OutRef,
10
10
  scriptHashToCredential,
11
- slotToUnixTime,
12
11
  toHex,
13
12
  TxBuilder,
14
13
  UTxO,
@@ -89,12 +88,11 @@ export async function openCdp(
89
88
  */
90
89
  treasuryOref: OutRef | undefined,
91
90
  lucid: LucidEvolution,
92
- currentSlot: number,
93
91
  pythMessage: string | undefined = undefined,
94
92
  pythStateOref: OutRef | undefined = undefined,
95
93
  ): Promise<TxBuilder> {
96
94
  const network = lucid.config().network!;
97
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
95
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
98
96
 
99
97
  const [pkh, skh] = await addrDetails(lucid);
100
98
 
@@ -239,7 +237,6 @@ export async function openCdp(
239
237
  pythMessage,
240
238
  sysParams.pythConfig,
241
239
  sysParams.cdpCreatorParams.biasTime,
242
- currentSlot,
243
240
  lucid,
244
241
  tx,
245
242
  );
@@ -320,12 +317,10 @@ export async function adjustCdp(
320
317
  interestCollectorOref: OutRef,
321
318
  sysParams: SystemParams,
322
319
  lucid: LucidEvolution,
323
- currentSlot: number,
324
320
  pythMessage: string | undefined = undefined,
325
321
  pythStateOref: OutRef | undefined = undefined,
326
322
  ): Promise<TxBuilder> {
327
- const network = lucid.config().network!;
328
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
323
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
329
324
 
330
325
  const cdpRefScriptUtxo = matchSingle(
331
326
  await lucid.utxosByOutRef([
@@ -408,7 +403,6 @@ export async function adjustCdp(
408
403
  pythMessage,
409
404
  sysParams.pythConfig,
410
405
  sysParams.cdpParams.biasTime,
411
- currentSlot,
412
406
  lucid,
413
407
  tx,
414
408
  );
@@ -555,7 +549,6 @@ export async function depositCdp(
555
549
  interestCollectorOref: OutRef,
556
550
  params: SystemParams,
557
551
  lucid: LucidEvolution,
558
- currentSlot: number,
559
552
  ): Promise<TxBuilder> {
560
553
  return adjustCdp(
561
554
  amount,
@@ -569,7 +562,6 @@ export async function depositCdp(
569
562
  interestCollectorOref,
570
563
  params,
571
564
  lucid,
572
- currentSlot,
573
565
  );
574
566
  }
575
567
 
@@ -587,7 +579,6 @@ export async function withdrawCdp(
587
579
  interestCollectorOref: OutRef,
588
580
  params: SystemParams,
589
581
  lucid: LucidEvolution,
590
- currentSlot: number,
591
582
  pythMessage: string | undefined = undefined,
592
583
  pythStateOref: OutRef | undefined = undefined,
593
584
  ): Promise<TxBuilder> {
@@ -603,7 +594,6 @@ export async function withdrawCdp(
603
594
  interestCollectorOref,
604
595
  params,
605
596
  lucid,
606
- currentSlot,
607
597
  pythMessage,
608
598
  pythStateOref,
609
599
  );
@@ -623,7 +613,6 @@ export async function mintCdp(
623
613
  interestCollectorOref: OutRef,
624
614
  params: SystemParams,
625
615
  lucid: LucidEvolution,
626
- currentSlot: number,
627
616
  pythMessage: string | undefined = undefined,
628
617
  pythStateOref: OutRef | undefined = undefined,
629
618
  ): Promise<TxBuilder> {
@@ -639,7 +628,6 @@ export async function mintCdp(
639
628
  interestCollectorOref,
640
629
  params,
641
630
  lucid,
642
- currentSlot,
643
631
  pythMessage,
644
632
  pythStateOref,
645
633
  );
@@ -658,7 +646,6 @@ export async function burnCdp(
658
646
  interestCollectorOref: OutRef,
659
647
  params: SystemParams,
660
648
  lucid: LucidEvolution,
661
- currentSlot: number,
662
649
  ): Promise<TxBuilder> {
663
650
  return adjustCdp(
664
651
  0n,
@@ -672,7 +659,6 @@ export async function burnCdp(
672
659
  interestCollectorOref,
673
660
  params,
674
661
  lucid,
675
- currentSlot,
676
662
  );
677
663
  }
678
664
 
@@ -683,10 +669,8 @@ export async function closeCdp(
683
669
  interestCollectorOref: OutRef,
684
670
  sysParams: SystemParams,
685
671
  lucid: LucidEvolution,
686
- currentSlot: number,
687
672
  ): Promise<TxBuilder> {
688
- const network = lucid.config().network!;
689
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
673
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
690
674
 
691
675
  const cdpRefScriptUtxo = matchSingle(
692
676
  await lucid.utxosByOutRef([
@@ -735,7 +719,7 @@ export async function closeCdp(
735
719
  getInlineDatumOrThrow(interestOracleUtxo),
736
720
  );
737
721
 
738
- const validateFrom = slotToUnixTime(network, currentSlot - 1);
722
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
739
723
  const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
740
724
 
741
725
  const tx = lucid
@@ -830,12 +814,10 @@ export async function redeemCdp(
830
814
  govOref: OutRef,
831
815
  sysParams: SystemParams,
832
816
  lucid: LucidEvolution,
833
- currentSlot: number,
834
817
  pythMessage: string | undefined = undefined,
835
818
  _pythStateOref: OutRef | undefined = undefined,
836
819
  ): Promise<TxBuilder> {
837
- const network = lucid.config().network!;
838
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
820
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
839
821
 
840
822
  const cdpRefScriptUtxo = matchSingle(
841
823
  await lucid.utxosByOutRef([
@@ -996,17 +978,16 @@ export async function redeemCdp(
996
978
  );
997
979
 
998
980
  const txValidity = oracleExpirationAwareValidity(
999
- currentSlot,
981
+ lucid,
1000
982
  Number(sysParams.cdpCreatorParams.biasTime),
1001
983
  Number(priceOracleDatum.expirationTime),
1002
- network,
1003
984
  );
1004
985
 
1005
986
  referenceInputs.push(priceOracleUtxo);
1006
987
 
1007
988
  tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
1008
989
  } else {
1009
- const validateFrom = slotToUnixTime(network, currentSlot - 1);
990
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
1010
991
  const validateTo =
1011
992
  validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
1012
993
 
@@ -1160,12 +1141,11 @@ export async function freezeCdp(
1160
1141
  interestOracleOref: OutRef,
1161
1142
  sysParams: SystemParams,
1162
1143
  lucid: LucidEvolution,
1163
- currentSlot: number,
1164
1144
  pythMessage: string | undefined = undefined,
1165
1145
  pythStateOref: OutRef | undefined = undefined,
1166
1146
  ): Promise<TxBuilder> {
1167
1147
  const network = lucid.config().network!;
1168
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
1148
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
1169
1149
 
1170
1150
  const cdpRefScriptUtxo = matchSingle(
1171
1151
  await lucid.utxosByOutRef([
@@ -1262,7 +1242,6 @@ export async function freezeCdp(
1262
1242
  pythMessage,
1263
1243
  sysParams.pythConfig,
1264
1244
  sysParams.cdpParams.biasTime,
1265
- currentSlot,
1266
1245
  lucid,
1267
1246
  tx,
1268
1247
  );
@@ -7,7 +7,6 @@ import {
7
7
  LucidEvolution,
8
8
  OutRef,
9
9
  paymentCredentialOf,
10
- slotToUnixTime,
11
10
  toHex,
12
11
  TxBuilder,
13
12
  UTxO,
@@ -109,7 +108,6 @@ export async function createProposal(
109
108
  treasuryWithdrawal: TreasuryWithdrawal | null,
110
109
  sysParams: SystemParams,
111
110
  lucid: LucidEvolution,
112
- currentSlot: number,
113
111
  govOref: OutRef,
114
112
  /**
115
113
  * This has to be passed only in case of createAsset proposal
@@ -117,7 +115,7 @@ export async function createProposal(
117
115
  allIAssetOrefs: OutRef[] | undefined,
118
116
  ): Promise<[TxBuilder, bigint]> {
119
117
  const network = lucid.config().network!;
120
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
118
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
121
119
 
122
120
  const ownAddr = await lucid.wallet().address();
123
121
  const pkh = paymentCredentialOf(ownAddr);
@@ -274,11 +272,10 @@ export async function createShardsChunks(
274
272
  chunkSize: bigint,
275
273
  pollManagerOref: OutRef,
276
274
  sysParams: SystemParams,
277
- currentSlot: number,
278
275
  lucid: LucidEvolution,
279
276
  ): Promise<TxBuilder> {
280
277
  const network = lucid.config().network!;
281
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
278
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
282
279
 
283
280
  const ownAddr = await lucid.wallet().address();
284
281
 
@@ -413,10 +410,8 @@ export async function vote(
413
410
  stakingPositionOref: OutRef,
414
411
  sysParams: SystemParams,
415
412
  lucid: LucidEvolution,
416
- currentSlot: number,
417
413
  ): Promise<TxBuilder> {
418
- const network = lucid.config().network!;
419
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
414
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
420
415
 
421
416
  const ownAddr = await lucid.wallet().address();
422
417
 
@@ -477,7 +472,12 @@ export async function vote(
477
472
  .newTx()
478
473
  .validFrom(validityFrom)
479
474
  .validTo(
480
- validityFrom + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND,
475
+ Math.min(
476
+ validityFrom +
477
+ Number(sysParams.pollManagerParams.pBiasTime) -
478
+ ONE_SECOND,
479
+ Number(pollShardDatum.votingEndTime) - ONE_SECOND,
480
+ ),
481
481
  )
482
482
  .readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo])
483
483
  .collectFrom([stakingPosUtxo], serialiseStakingRedeemer('Lock'))
@@ -517,10 +517,8 @@ export async function mergeShards(
517
517
  shardsOutRefs: OutRef[],
518
518
  sysParams: SystemParams,
519
519
  lucid: LucidEvolution,
520
- currentSlot: number,
521
520
  ): Promise<TxBuilder> {
522
- const network = lucid.config().network!;
523
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
521
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
524
522
 
525
523
  const ownAddr = await lucid.wallet().address();
526
524
 
@@ -636,10 +634,9 @@ export async function endProposal(
636
634
  govOref: OutRef,
637
635
  sysParams: SystemParams,
638
636
  lucid: LucidEvolution,
639
- currentSlot: number,
640
637
  ): Promise<TxBuilder> {
641
638
  const network = lucid.config().network!;
642
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
639
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
643
640
 
644
641
  const ownAddr = await lucid.wallet().address();
645
642
 
@@ -797,10 +794,9 @@ export async function executeProposal(
797
794
  stableswapPoolOrCdpCreatorOref: OutRef | null,
798
795
  sysParams: SystemParams,
799
796
  lucid: LucidEvolution,
800
- currentSlot: number,
801
797
  ): Promise<TxBuilder> {
802
798
  const network = lucid.config().network!;
803
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
799
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
804
800
 
805
801
  const ownAddr = await lucid.wallet().address();
806
802
 
@@ -5,7 +5,6 @@ import {
5
5
  LucidEvolution,
6
6
  OutRef,
7
7
  scriptHashToCredential,
8
- slotToUnixTime,
9
8
  toHex,
10
9
  TxBuilder,
11
10
  UTxO,
@@ -48,16 +47,13 @@ export function attachOracle(
48
47
  pythMessage: string | undefined,
49
48
  pythConfig: PythConfig,
50
49
  biasTime: bigint,
51
- currentSlot: number,
52
50
  lucid: LucidEvolution,
53
51
  tx: TxBuilder,
54
52
  ): Promise<{ interval: Interval; referenceInputs: UTxO[] }> {
55
53
  return match(priceInfo)
56
54
  .returnType<Promise<{ interval: Interval; referenceInputs: UTxO[] }>>()
57
55
  .with({ Delisted: P.any }, () => {
58
- const currentTime = BigInt(
59
- slotToUnixTime(lucid.config().network!, currentSlot),
60
- );
56
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
61
57
 
62
58
  // We want to make sure the transaction is valid within the bias time for interest tracking AND Pyth
63
59
  // For validFrom, we take the higher of the two bias times
@@ -86,10 +82,9 @@ export function attachOracle(
86
82
 
87
83
  return {
88
84
  interval: oracleExpirationAwareValidity(
89
- currentSlot,
85
+ lucid,
90
86
  Number(biasTime),
91
87
  Number(priceOracleDatum.expirationTime),
92
- lucid.config().network!,
93
88
  ),
94
89
  referenceInputs: [priceOracleUtxo],
95
90
  };
@@ -168,7 +168,6 @@ export async function initPythConfig(
168
168
  export async function init(
169
169
  lucid: LucidEvolution,
170
170
  defaultInitialAssets: InitialAssetParam[],
171
- currentSlot: number,
172
171
  mkPythBasedAssets: (
173
172
  pythStateNft: AssetClass,
174
173
  ) => InitialAssetParam[] = () => [],
@@ -527,7 +526,6 @@ export async function init(
527
526
  stabilityPoolToken,
528
527
  asset,
529
528
  pythConfig,
530
- currentSlot,
531
529
  );
532
530
 
533
531
  assetInfos.push(assetInfo);
@@ -346,7 +346,6 @@ export async function handleOracleForCollateralAsset(
346
346
  iasset: InitialAssetParam,
347
347
  collateralAsset: InitialCollateralAssetParam,
348
348
  pythConfig: PythConfig,
349
- currentSlot: number,
350
349
  ): Promise<{ info: IAssetPriceInfo; params: PriceOracleParams | undefined }> {
351
350
  return match(collateralAsset.priceOracle)
352
351
  .returnType<
@@ -366,7 +365,6 @@ export async function handleOracleForCollateralAsset(
366
365
  val.tokenName,
367
366
  val.startPrice,
368
367
  priceOracleParams,
369
- currentSlot,
370
368
  );
371
369
  await runAndAwaitTxBuilder(lucid, priceOracleStartTx);
372
370
 
@@ -403,7 +401,6 @@ export async function initializeAsset(
403
401
  stabilityPoolToken: AssetClass,
404
402
  asset: InitialAssetParam,
405
403
  pythConfig: PythConfig,
406
- currentSlot: number,
407
404
  ): Promise<AssetInfo> {
408
405
  const iassetName = fromHex(fromText(asset.name));
409
406
 
@@ -431,7 +428,6 @@ export async function initializeAsset(
431
428
  asset,
432
429
  collateralAsset,
433
430
  pythConfig,
434
- currentSlot,
435
431
  );
436
432
 
437
433
  const collateralAssetContent: CollateralAssetContent = {
@@ -8,7 +8,6 @@ import {
8
8
  addAssets,
9
9
  Assets,
10
10
  fromHex,
11
- slotToUnixTime,
12
11
  sortUTxOs,
13
12
  getInputIndices,
14
13
  } from '@lucid-evolution/lucid';
@@ -58,10 +57,8 @@ export async function batchCollectInterest(
58
57
  cdpOutRefs: OutRef[],
59
58
  params: SystemParams,
60
59
  lucid: LucidEvolution,
61
- currentSlot: number,
62
60
  ): Promise<TxBuilder> {
63
- const network = lucid.config().network!;
64
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
61
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
65
62
 
66
63
  const interestCollectionRefScriptUtxo = matchSingle(
67
64
  await lucid.utxosByOutRef([
@@ -183,7 +180,7 @@ export async function batchCollectInterest(
183
180
  false,
184
181
  );
185
182
 
186
- const validateFrom = slotToUnixTime(network, currentSlot - 1);
183
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
187
184
  const validateTo = validateFrom + Number(params.cdpParams.biasTime);
188
185
 
189
186
  const tx = lucid
@@ -26,6 +26,10 @@ export function calculateUnitaryInterestSinceOracleLastUpdated(
26
26
  }
27
27
 
28
28
  export function calculateAccruedInterest(
29
+ /**
30
+ * Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
31
+ * Otherwise, the unix timestamp should suffice, but might not be 100% precise as on-chain.
32
+ */
29
33
  now: bigint,
30
34
  unitaryInterestSnapshot: bigint,
31
35
  mintedAmount: bigint,
@@ -3,7 +3,6 @@ import {
3
3
  fromText,
4
4
  LucidEvolution,
5
5
  OutRef,
6
- slotToUnixTime,
7
6
  toUnit,
8
7
  TxBuilder,
9
8
  UTxO,
@@ -95,7 +94,6 @@ export async function feedInterestOracle(
95
94
  params: InterestOracleParams,
96
95
  newInterestRate: bigint,
97
96
  lucid: LucidEvolution,
98
- currentSlot: number,
99
97
  assetClass?: AssetClass,
100
98
  utxo?: UTxO,
101
99
  scriptRef?: UTxO,
@@ -106,8 +104,7 @@ export async function feedInterestOracle(
106
104
  utxo = await findInterestOracle(lucid, assetClass);
107
105
  }
108
106
 
109
- const network = lucid.config().network!;
110
- const now = BigInt(slotToUnixTime(network, currentSlot));
107
+ const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
111
108
 
112
109
  const tx = lucid.newTx();
113
110
  const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo!));
@@ -1,29 +1,23 @@
1
- import {
2
- Network,
3
- slotToUnixTime,
4
- unixTimeToSlot,
5
- } from '@lucid-evolution/lucid';
1
+ import { LucidEvolution } from '@lucid-evolution/lucid';
6
2
 
7
3
  /**
8
4
  * Calculates the validity range based on the oracle expiration,
9
5
  * and caps the upper bound when necessary.
10
6
  */
11
7
  export function oracleExpirationAwareValidity(
12
- currentSlot: number,
8
+ lucid: LucidEvolution,
13
9
  biasTime: number,
14
10
  oracleExpiration: number,
15
- network: Network,
16
11
  ): {
17
12
  validFrom: number;
18
13
  validTo: number;
19
14
  } {
20
- const validateFrom = slotToUnixTime(network, currentSlot - 1);
15
+ const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
21
16
  const defaultValidateTo = validateFrom + biasTime;
22
17
  /// Take the oracle expiration time - 1 slot which is the last acceptable non-expired valid_to time
23
18
  /// for the current oracle.
24
- const cappedValidateTo = slotToUnixTime(
25
- network,
26
- unixTimeToSlot(network, oracleExpiration) - 1,
19
+ const cappedValidateTo = lucid.slotToUnixTime(
20
+ lucid.unixTimeToSlot(oracleExpiration) - 1,
27
21
  );
28
22
  const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
29
23
 
@@ -5,7 +5,6 @@ import {
5
5
  fromText,
6
6
  LucidEvolution,
7
7
  OutRef,
8
- slotToUnixTime,
9
8
  TxBuilder,
10
9
  validatorToAddress,
11
10
  } from '@lucid-evolution/lucid';
@@ -28,12 +27,10 @@ export async function startPriceOracleTx(
28
27
  assetName: string,
29
28
  startPrice: Rational,
30
29
  oracleParams: PriceOracleParams,
31
- currentSlot: number,
32
30
  refOutRef?: OutRef,
33
31
  auxiliaryData?: Core.Data.Data,
34
32
  ): Promise<[TxBuilder, AssetClass]> {
35
- const network = lucid.config().network!;
36
- const now = BigInt(slotToUnixTime(network, currentSlot));
33
+ const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
37
34
 
38
35
  if (!refOutRef) {
39
36
  refOutRef = (await lucid.wallet().getUtxos())[0];
@@ -79,11 +76,9 @@ export async function feedPriceOracleTx(
79
76
  oracleOref: OutRef,
80
77
  newPrice: Rational,
81
78
  oracleParams: PriceOracleParams,
82
- currentSlot: number,
83
79
  auxiliaryData?: Core.Data.Data,
84
80
  ): Promise<TxBuilder> {
85
- const network = lucid.config().network!;
86
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
81
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
87
82
 
88
83
  const priceOracleUtxo = matchSingle(
89
84
  await lucid.utxosByOutRef([oracleOref]),
@@ -149,7 +149,6 @@ export async function redeemRob(
149
149
  collateralAssetOutRef: OutRef,
150
150
  lucid: LucidEvolution,
151
151
  sysParams: SystemParams,
152
- currentSlot: number,
153
152
  pythMessage: string | undefined = undefined,
154
153
  pythStateOutRef: OutRef | undefined = undefined,
155
154
  ): Promise<TxBuilder> {
@@ -208,7 +207,6 @@ export async function redeemRob(
208
207
  pythMessage,
209
208
  sysParams.pythConfig,
210
209
  sysParams.cdpParams.biasTime,
211
- currentSlot,
212
210
  lucid,
213
211
  tx,
214
212
  );
@@ -4,7 +4,6 @@ import {
4
4
  OutRef,
5
5
  UTxO,
6
6
  addAssets,
7
- slotToUnixTime,
8
7
  Data,
9
8
  fromHex,
10
9
  getInputIndices,
@@ -65,12 +64,11 @@ export async function leverageCdpWithRob(
65
64
  sysParams: SystemParams,
66
65
  lucid: LucidEvolution,
67
66
  allRobs: [UTxO, RobDatum][],
68
- currentSlot: number,
69
67
  pythMessage: string | undefined = undefined,
70
68
  pythStateOref: OutRef | undefined = undefined,
71
69
  ): Promise<TxBuilder> {
72
70
  const network = lucid.config().network!;
73
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
71
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
74
72
 
75
73
  const [pkh, skh] = await addrDetails(lucid);
76
74
 
@@ -306,7 +304,6 @@ export async function leverageCdpWithRob(
306
304
  pythMessage,
307
305
  sysParams.pythConfig,
308
306
  sysParams.cdpCreatorParams.biasTime,
309
- currentSlot,
310
307
  lucid,
311
308
  tx,
312
309
  );
@@ -8,7 +8,6 @@ import {
8
8
  toHex,
9
9
  addAssets,
10
10
  OutRef,
11
- slotToUnixTime,
12
11
  credentialToAddress,
13
12
  } from '@lucid-evolution/lucid';
14
13
  import {
@@ -267,11 +266,9 @@ async function processSpRequestAuxiliary(
267
266
  allE2s2sSnapshotOrefs: OutRef[],
268
267
  sysParams: SystemParams,
269
268
  lucid: LucidEvolution,
270
- currentSlot: number,
271
269
  txFee: bigint,
272
270
  ): Promise<TxBuilder> {
273
- const network = lucid.config().network!;
274
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
271
+ const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
275
272
 
276
273
  const stabilityPoolScriptRef = matchSingle(
277
274
  await lucid.utxosByOutRef([
@@ -292,7 +289,7 @@ async function processSpRequestAuxiliary(
292
289
 
293
290
  const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
294
291
 
295
- const validFrom = slotToUnixTime(network, currentSlot - 1);
292
+ const validFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
296
293
  const tx = lucid
297
294
  .newTx()
298
295
  .validFrom(validFrom)
@@ -770,7 +767,6 @@ export async function processSpRequest(
770
767
  allE2s2sSnapshotOrefs: OutRef[],
771
768
  sysParams: SystemParams,
772
769
  lucid: LucidEvolution,
773
- currentSlot: number,
774
770
  ): Promise<TxBuilder> {
775
771
  const draftTx = processSpRequestAuxiliary(
776
772
  stabilityPoolUtxo,
@@ -779,7 +775,6 @@ export async function processSpRequest(
779
775
  allE2s2sSnapshotOrefs,
780
776
  sysParams,
781
777
  lucid,
782
- currentSlot,
783
778
  // Placeholder transation fee
784
779
  1n,
785
780
  );
@@ -793,7 +788,6 @@ export async function processSpRequest(
793
788
  allE2s2sSnapshotOrefs,
794
789
  sysParams,
795
790
  lucid,
796
- currentSlot,
797
791
  fee,
798
792
  );
799
793
  }