@lucid-evolution/provider 0.1.42 → 0.1.44

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 (3) hide show
  1. package/dist/index.cjs +154 -124
  2. package/dist/index.js +80 -50
  3. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -45,14 +45,14 @@ module.exports = __toCommonJS(src_exports);
45
45
  // src/core.ts
46
46
  var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
47
47
 
48
- // src/blockfrost.ts
48
+ // src/blockfrost/blockfrost.ts
49
49
  var import_core_utils = require("@lucid-evolution/core-utils");
50
50
  var import_utils = require("@lucid-evolution/utils");
51
51
 
52
52
  // package.json
53
53
  var package_default = {
54
54
  name: "@lucid-evolution/provider",
55
- version: "0.1.42",
55
+ version: "0.1.44",
56
56
  description: "",
57
57
  main: "./dist/index.js",
58
58
  types: "./dist/index.d.ts",
@@ -100,7 +100,8 @@ var package_default = {
100
100
  }
101
101
  };
102
102
 
103
- // src/blockfrost.ts
103
+ // src/blockfrost/blockfrost.ts
104
+ var import_effect = require("effect");
104
105
  var Blockfrost = class {
105
106
  url;
106
107
  projectId;
@@ -309,17 +310,24 @@ var Blockfrost = class {
309
310
  headers: { project_id: this.projectId, lucid }
310
311
  }
311
312
  ).then((res) => res.json());
312
- if (type.toLowerCase() === "native") {
313
- throw new Error("Native script ref not implemented!");
314
- }
315
313
  const { cbor: script } = await fetch(
316
314
  `${this.url}/scripts/${r.reference_script_hash}/cbor`,
317
315
  { headers: { project_id: this.projectId, lucid } }
318
316
  ).then((res) => res.json());
319
- return {
320
- type: type === "plutusV1" ? "PlutusV1" : "PlutusV2",
321
- script: (0, import_utils.applyDoubleCborEncoding)(script)
322
- };
317
+ switch (type) {
318
+ case "timelock":
319
+ return void 0;
320
+ case "plutusV1":
321
+ return {
322
+ type: "PlutusV1",
323
+ script: (0, import_utils.applyDoubleCborEncoding)(script)
324
+ };
325
+ case "plutusV2":
326
+ return {
327
+ type: "PlutusV2",
328
+ script: (0, import_utils.applyDoubleCborEncoding)(script)
329
+ };
330
+ }
323
331
  })() : void 0
324
332
  };
325
333
  })
@@ -329,19 +337,9 @@ var Blockfrost = class {
329
337
  return utxos;
330
338
  }
331
339
  async evaluateTx(tx, additionalUTxOs) {
332
- const additionalUTxOSet = (additionalUTxOs || []).map((utxo) => [
333
- { txId: utxo.txHash, index: utxo.outputIndex },
334
- {
335
- address: utxo.address,
336
- value: { coins: utxo.assets.lovelace, assets: utxo.assets.restAssets },
337
- datum_hash: utxo.datumHash,
338
- datum: utxo.datum,
339
- script: utxo.scriptRef
340
- }
341
- ]);
342
340
  const payload = {
343
341
  cbor: tx,
344
- additionalUTxOSet
342
+ additionalUtxoSet: toAditionalUTXOs(additionalUTxOs)
345
343
  };
346
344
  const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
347
345
  method: "POST",
@@ -350,10 +348,7 @@ var Blockfrost = class {
350
348
  project_id: this.projectId,
351
349
  lucid
352
350
  },
353
- body: JSON.stringify(
354
- payload,
355
- (_, value) => typeof value === "bigint" ? value.toString() : value
356
- )
351
+ body: JSON.stringify(payload)
357
352
  }).then((res2) => res2.json());
358
353
  if (!res || res.error) {
359
354
  const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}`;
@@ -417,17 +412,41 @@ function datumJsonToCbor(json) {
417
412
  }
418
413
  var handleRateLimit = async (count) => {
419
414
  if (count % 100 === 0) {
420
- await (0, import_core_utils.sleep)(2e3);
415
+ await (0, import_core_utils.sleep)(5e3);
421
416
  } else if (count % 10 === 0) {
422
- await (0, import_core_utils.sleep)(200);
417
+ await (0, import_core_utils.sleep)(500);
423
418
  }
424
419
  };
425
420
  var lucid = package_default.version;
421
+ var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
422
+ {
423
+ txId: utxo.txHash,
424
+ index: utxo.outputIndex
425
+ },
426
+ {
427
+ address: utxo.address,
428
+ value: {
429
+ coins: Number(utxo.assets["lovelace"]),
430
+ assets: fromAssets(utxo.assets)
431
+ },
432
+ datumHash: utxo.datumHash,
433
+ datum: utxo.datum,
434
+ script: utxo.scriptRef ? utxo.scriptRef.type === "PlutusV1" ? { "plutus:v1": utxo.scriptRef.script } : { "plutus:v2": utxo.scriptRef.script } : void 0
435
+ }
436
+ ]);
437
+ var fromAssets = (assets) => (0, import_effect.pipe)(
438
+ import_effect.Record.remove(assets, "lovelace"),
439
+ import_effect.Record.mapEntries((amount, unit) => [
440
+ unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
441
+ Number(amount)
442
+ ]),
443
+ (r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
444
+ );
426
445
 
427
446
  // src/kupmios/kupmios.ts
428
447
  var import_utils2 = require("@lucid-evolution/utils");
429
448
  var S2 = __toESM(require("@effect/schema/Schema"), 1);
430
- var import_effect = require("effect");
449
+ var import_effect2 = require("effect");
431
450
 
432
451
  // src/kupmios/schema.ts
433
452
  var S = __toESM(require("@effect/schema/Schema"), 1);
@@ -497,7 +516,12 @@ var KupoUTxO = S.Struct({
497
516
  slot_no: S.Number,
498
517
  header_hash: S.String
499
518
  }),
500
- spent_at: S.NullOr(S.Number)
519
+ spent_at: S.NullOr(
520
+ S.Struct({
521
+ slot_no: S.Number,
522
+ header_hash: S.String
523
+ })
524
+ )
501
525
  });
502
526
  var KupoScriptSchema = S.NullOr(
503
527
  S.Struct({
@@ -519,7 +543,7 @@ var KupoDelegation = S.NullOr(
519
543
 
520
544
  // src/kupmios/kupmios.ts
521
545
  var import_platform = require("@effect/platform");
522
- var KupmiosError = class extends import_effect.Data.TaggedError("KupmiosError") {
546
+ var KupmiosError = class extends import_effect2.Data.TaggedError("KupmiosError") {
523
547
  get message() {
524
548
  return `${this.cause}`;
525
549
  }
@@ -549,13 +573,13 @@ var Kupmios = class {
549
573
  ProtocolParametersSchema
550
574
  );
551
575
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
552
- import_effect.Effect.flatMap(
553
- (response) => "error" in response ? kupmiosError(response.error) : import_effect.Effect.succeed(response.result)
576
+ import_effect2.Effect.flatMap(
577
+ (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
554
578
  ),
555
- import_effect.Effect.timeout(1e4),
556
- import_effect.Effect.catchAll(kupmiosError)
579
+ import_effect2.Effect.timeout(1e4),
580
+ import_effect2.Effect.catchAll(kupmiosError)
557
581
  );
558
- const result = await import_effect.Effect.runPromise(program);
582
+ const result = await import_effect2.Effect.runPromise(program);
559
583
  return toProtocolParameters(result);
560
584
  }
561
585
  async getUtxos(addressOrCredential) {
@@ -564,11 +588,11 @@ var Kupmios = class {
564
588
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
565
589
  const schema = S2.Array(KupoUTxO);
566
590
  const program = fetchKupoParse(pattern, schema).pipe(
567
- import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
568
- import_effect.Effect.timeout(1e4),
569
- import_effect.Effect.catchAll(kupmiosError)
591
+ import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
592
+ import_effect2.Effect.timeout(1e4),
593
+ import_effect2.Effect.catchAll(kupmiosError)
570
594
  );
571
- const utxos = await import_effect.Effect.runPromise(program);
595
+ const utxos = await import_effect2.Effect.runPromise(program);
572
596
  return utxos;
573
597
  }
574
598
  async getUtxosWithUnit(addressOrCredential, unit) {
@@ -578,11 +602,11 @@ var Kupmios = class {
578
602
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
579
603
  const schema = S2.Array(KupoUTxO);
580
604
  const program = fetchKupoParse(pattern, schema).pipe(
581
- import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
582
- import_effect.Effect.timeout(1e4),
583
- import_effect.Effect.catchAll(kupmiosError)
605
+ import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
606
+ import_effect2.Effect.timeout(1e4),
607
+ import_effect2.Effect.catchAll(kupmiosError)
584
608
  );
585
- const utxos = await import_effect.Effect.runPromise(program);
609
+ const utxos = await import_effect2.Effect.runPromise(program);
586
610
  return utxos;
587
611
  }
588
612
  async getUtxoByUnit(unit) {
@@ -590,11 +614,11 @@ var Kupmios = class {
590
614
  const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
591
615
  const schema = S2.Array(KupoUTxO);
592
616
  const program = fetchKupoParse(pattern, schema).pipe(
593
- import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
594
- import_effect.Effect.timeout(1e4),
595
- import_effect.Effect.catchAll(kupmiosError)
617
+ import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
618
+ import_effect2.Effect.timeout(1e4),
619
+ import_effect2.Effect.catchAll(kupmiosError)
596
620
  );
597
- const utxos = await import_effect.Effect.runPromise(program);
621
+ const utxos = await import_effect2.Effect.runPromise(program);
598
622
  if (utxos.length > 1) {
599
623
  throw new Error("Unit needs to be an NFT or only held by one address.");
600
624
  }
@@ -606,16 +630,16 @@ var Kupmios = class {
606
630
  ];
607
631
  const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
608
632
  const schema = S2.Array(KupoUTxO);
609
- const program = import_effect.Effect.forEach(
633
+ const program = import_effect2.Effect.forEach(
610
634
  queryHashes,
611
635
  (txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
612
- import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
613
- import_effect.Effect.timeout(1e4),
614
- import_effect.Effect.catchAll(kupmiosError)
636
+ import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
637
+ import_effect2.Effect.timeout(1e4),
638
+ import_effect2.Effect.catchAll(kupmiosError)
615
639
  )
616
640
  );
617
- const utxos = await import_effect.Effect.runPromise(program);
618
- return import_effect.Array.flatten(utxos).filter(
641
+ const utxos = await import_effect2.Effect.runPromise(program);
642
+ return import_effect2.Array.flatten(utxos).filter(
619
643
  (utxo) => outRefs.some(
620
644
  (outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
621
645
  )
@@ -630,13 +654,13 @@ var Kupmios = class {
630
654
  };
631
655
  const schema = JSONRPCSchema(KupoDelegation);
632
656
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
633
- import_effect.Effect.flatMap(
634
- (response) => "error" in response ? kupmiosError(response.error) : import_effect.Effect.succeed(response.result)
657
+ import_effect2.Effect.flatMap(
658
+ (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
635
659
  ),
636
- import_effect.Effect.timeout(1e4),
637
- import_effect.Effect.catchAll(kupmiosError)
660
+ import_effect2.Effect.timeout(1e4),
661
+ import_effect2.Effect.catchAll(kupmiosError)
638
662
  );
639
- const result = await import_effect.Effect.runPromise(program);
663
+ const result = await import_effect2.Effect.runPromise(program);
640
664
  const delegation = result ? Object.values(result)[0] : null;
641
665
  return {
642
666
  poolId: delegation?.delegate?.id || null,
@@ -647,28 +671,28 @@ var Kupmios = class {
647
671
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
648
672
  const schema = KupoDatumSchema;
649
673
  const program = fetchKupoParse(pattern, schema).pipe(
650
- import_effect.Effect.timeout(1e4),
651
- import_effect.Effect.flatMap(import_effect.Effect.fromNullable),
652
- import_effect.Effect.catchAll(kupmiosError)
674
+ import_effect2.Effect.timeout(1e4),
675
+ import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
676
+ import_effect2.Effect.catchAll(kupmiosError)
653
677
  );
654
- const result = await import_effect.Effect.runPromise(program);
678
+ const result = await import_effect2.Effect.runPromise(program);
655
679
  return result.datum;
656
680
  }
657
681
  async awaitTx(txHash, checkInterval = 2e4) {
658
- const pattern = `${this.kupoUrl}/matches/*@${txHash}?unspent`;
682
+ const pattern = `${this.kupoUrl}/matches/*@${txHash}?spent`;
659
683
  const schema = S2.Array(KupoUTxO).annotations({
660
684
  identifier: "Array<KupmiosSchema.KupoUTxO>"
661
685
  });
662
686
  const program = fetchKupoParse(pattern, schema).pipe(
663
- import_effect.Effect.repeat({
664
- schedule: import_effect.Schedule.exponential(checkInterval),
687
+ import_effect2.Effect.repeat({
688
+ schedule: import_effect2.Schedule.exponential(checkInterval),
665
689
  until: (result) => result.length > 0
666
690
  }),
667
- import_effect.Effect.timeout(16e4),
668
- import_effect.Effect.catchAll(kupmiosError),
669
- import_effect.Effect.as(true)
691
+ import_effect2.Effect.timeout(16e4),
692
+ import_effect2.Effect.catchAll(kupmiosError),
693
+ import_effect2.Effect.as(true)
670
694
  );
671
- return await import_effect.Effect.runPromise(program);
695
+ return await import_effect2.Effect.runPromise(program);
672
696
  }
673
697
  async submitTx(cbor) {
674
698
  const data = {
@@ -687,13 +711,13 @@ var Kupmios = class {
687
711
  })
688
712
  );
689
713
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
690
- import_effect.Effect.flatMap(
691
- (response) => "error" in response ? import_effect.Effect.fail(response.error) : import_effect.Effect.succeed(response)
714
+ import_effect2.Effect.flatMap(
715
+ (response) => "error" in response ? import_effect2.Effect.fail(response.error) : import_effect2.Effect.succeed(response)
692
716
  ),
693
- import_effect.Effect.timeout(1e4),
694
- import_effect.Effect.catchAll(kupmiosError)
717
+ import_effect2.Effect.timeout(1e4),
718
+ import_effect2.Effect.catchAll(kupmiosError)
695
719
  );
696
- const { result } = await import_effect.Effect.runPromise(program);
720
+ const { result } = await import_effect2.Effect.runPromise(program);
697
721
  return result.transaction.id;
698
722
  }
699
723
  async evaluateTx(tx, additionalUTxOs) {
@@ -739,13 +763,13 @@ var Kupmios = class {
739
763
  )
740
764
  );
741
765
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
742
- import_effect.Effect.flatMap(
743
- (response) => "error" in response ? kupmiosError(response.error) : import_effect.Effect.succeed(response.result)
766
+ import_effect2.Effect.flatMap(
767
+ (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
744
768
  ),
745
- import_effect.Effect.timeout(1e4),
746
- import_effect.Effect.catchAll(kupmiosError)
769
+ import_effect2.Effect.timeout(1e4),
770
+ import_effect2.Effect.catchAll(kupmiosError)
747
771
  );
748
- const result = await import_effect.Effect.runPromise(program);
772
+ const result = await import_effect2.Effect.runPromise(program);
749
773
  const evalRedeemers = result.map((item) => ({
750
774
  ex_units: {
751
775
  mem: item.budget.memory,
@@ -757,37 +781,43 @@ var Kupmios = class {
757
781
  return evalRedeemers;
758
782
  }
759
783
  };
760
- var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect.Effect.gen(function* () {
784
+ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.gen(function* () {
761
785
  if (datum_type === "inline" && datum_hash) {
762
786
  const pattern = `${kupoUrl}/datums/${datum_hash}`;
763
787
  const schema = KupoDatumSchema;
764
788
  return yield* fetchKupoParse(pattern, schema).pipe(
765
- import_effect.Effect.flatMap(import_effect.Effect.fromNullable),
766
- import_effect.Effect.map((result) => result.datum),
767
- import_effect.Effect.timeout(1e4)
789
+ import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
790
+ import_effect2.Effect.map((result) => result.datum),
791
+ import_effect2.Effect.timeout(1e4)
768
792
  );
769
- } else return null;
793
+ } else return void 0;
770
794
  });
771
- var getScriptEffect = (kupoUrl, script_hash) => import_effect.Effect.gen(function* () {
795
+ var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(function* () {
772
796
  if (script_hash) {
773
797
  const pattern = `${kupoUrl}/scripts/${script_hash}`;
774
798
  const schema = KupoScriptSchema;
775
- return yield* (0, import_effect.pipe)(
799
+ return yield* (0, import_effect2.pipe)(
776
800
  fetchKupoParse(pattern, schema),
777
- import_effect.Effect.flatMap(import_effect.Effect.fromNullable),
778
- import_effect.Effect.timeout(1e4),
779
- import_effect.Effect.map(({ language, script }) => {
801
+ import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
802
+ import_effect2.Effect.timeout(1e4),
803
+ import_effect2.Effect.map(({ language, script }) => {
780
804
  switch (language) {
781
805
  case "native":
782
- return { type: "Native", script };
806
+ return void 0;
783
807
  case "plutus:v1":
784
- return { type: "PlutusV1", script };
808
+ return {
809
+ type: "PlutusV1",
810
+ script: (0, import_utils2.applyDoubleCborEncoding)(script)
811
+ };
785
812
  case "plutus:v2":
786
- return { type: "PlutusV2", script };
813
+ return {
814
+ type: "PlutusV2",
815
+ script: (0, import_utils2.applyDoubleCborEncoding)(script)
816
+ };
787
817
  }
788
818
  })
789
819
  );
790
- } else return null;
820
+ } else return void 0;
791
821
  });
792
822
  var toAssets = (value) => {
793
823
  const assets = { lovelace: BigInt(value.coins) };
@@ -832,42 +862,42 @@ var toProtocolParameters = (result) => {
832
862
  }
833
863
  };
834
864
  };
835
- var fetchOgmiosParse = (url, data, schema) => (0, import_effect.pipe)(
865
+ var fetchOgmiosParse = (url, data, schema) => (0, import_effect2.pipe)(
836
866
  import_platform.HttpClientRequest.post(url),
837
867
  import_platform.HttpClientRequest.jsonBody(data),
838
- import_effect.Effect.flatMap(import_platform.HttpClient.fetch),
868
+ import_effect2.Effect.flatMap(import_platform.HttpClient.fetch),
839
869
  import_platform.HttpClientResponse.json,
840
- import_effect.Effect.flatMap(S2.decodeUnknown(schema))
870
+ import_effect2.Effect.flatMap(S2.decodeUnknown(schema))
841
871
  // Effect.catchTag("ParseError", (e) =>
842
872
  // Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
843
873
  // ),
844
874
  // Effect.scoped
845
875
  );
846
- var fetchKupoParse = (url, schema) => (0, import_effect.pipe)(
876
+ var fetchKupoParse = (url, schema) => (0, import_effect2.pipe)(
847
877
  import_platform.HttpClientRequest.get(url),
848
878
  import_platform.HttpClient.fetchOk,
849
879
  import_platform.HttpClientResponse.json,
850
- import_effect.Effect.flatMap(S2.decodeUnknown(schema))
880
+ import_effect2.Effect.flatMap(S2.decodeUnknown(schema))
851
881
  // Effect.catchTag("ParseError", (e) =>
852
882
  // Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
853
883
  // ),
854
884
  // Effect.scoped
855
885
  );
856
- var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect.Effect.forEach(
886
+ var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
857
887
  utxos,
858
888
  (utxo) => {
859
- return (0, import_effect.pipe)(
860
- import_effect.Effect.all([
889
+ return (0, import_effect2.pipe)(
890
+ import_effect2.Effect.all([
861
891
  getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
862
892
  getScriptEffect(kupoURL, utxo.script_hash)
863
893
  ]),
864
- import_effect.Effect.map(
894
+ import_effect2.Effect.map(
865
895
  ([datum, script]) => ({
866
896
  txHash: utxo.transaction_id,
867
897
  outputIndex: utxo.output_index,
868
898
  address: utxo.address,
869
899
  assets: toAssets(utxo.value),
870
- datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : null,
900
+ datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
871
901
  datum,
872
902
  scriptRef: script
873
903
  })
@@ -2085,7 +2115,7 @@ var KoiosTxInfoSchema = S3.Struct({
2085
2115
  });
2086
2116
 
2087
2117
  // src/koios/koios.ts
2088
- var import_effect3 = require("effect");
2118
+ var import_effect4 = require("effect");
2089
2119
  var import_schema2 = require("@effect/schema");
2090
2120
 
2091
2121
  // src/fetch.ts
@@ -2096,27 +2126,27 @@ __export(fetch_exports, {
2096
2126
  ResponseError: () => ResponseError,
2097
2127
  fetchEffect: () => fetchEffect
2098
2128
  });
2099
- var import_effect2 = require("effect");
2100
- var FetchError = class extends import_effect2.Data.TaggedError("FetchError") {
2129
+ var import_effect3 = require("effect");
2130
+ var FetchError = class extends import_effect3.Data.TaggedError("FetchError") {
2101
2131
  };
2102
- var ResponseError = class extends import_effect2.Data.TaggedError("ResponseError") {
2132
+ var ResponseError = class extends import_effect3.Data.TaggedError("ResponseError") {
2103
2133
  };
2104
- var JsonError = class extends import_effect2.Data.TaggedError("JsonError") {
2134
+ var JsonError = class extends import_effect3.Data.TaggedError("JsonError") {
2105
2135
  };
2106
- var fetchEffect = (input, requestInit) => (0, import_effect2.pipe)(
2107
- import_effect2.Effect.tryPromise({
2136
+ var fetchEffect = (input, requestInit) => (0, import_effect3.pipe)(
2137
+ import_effect3.Effect.tryPromise({
2108
2138
  try: () => fetch(input, requestInit),
2109
2139
  catch: (error) => new FetchError({
2110
2140
  message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
2111
2141
  })
2112
2142
  }),
2113
- import_effect2.Effect.flatMap(
2143
+ import_effect3.Effect.flatMap(
2114
2144
  (response) => !response.ok ? new ResponseError({
2115
2145
  message: `${response.status} ${response.statusText}`
2116
- }) : import_effect2.Effect.succeed(response)
2146
+ }) : import_effect3.Effect.succeed(response)
2117
2147
  ),
2118
- import_effect2.Effect.flatMap(
2119
- (response) => import_effect2.Effect.tryPromise({
2148
+ import_effect3.Effect.flatMap(
2149
+ (response) => import_effect3.Effect.tryPromise({
2120
2150
  try: () => response.json(),
2121
2151
  catch: (error) => new JsonError({ message: String(error) })
2122
2152
  })
@@ -2315,24 +2345,24 @@ var Koios = class {
2315
2345
  method: "POST",
2316
2346
  body: JSON.stringify(body)
2317
2347
  };
2318
- const program = (0, import_effect3.pipe)(
2348
+ const program = (0, import_effect4.pipe)(
2319
2349
  fetchEffect(`${this.baseUrl}/tx_info`, request),
2320
- import_effect3.Effect.flatMap(
2350
+ import_effect4.Effect.flatMap(
2321
2351
  (json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
2322
2352
  ),
2323
- import_effect3.Effect.catchTag(
2353
+ import_effect4.Effect.catchTag(
2324
2354
  "ParseError",
2325
- (e) => import_effect3.Effect.fail(import_schema2.ArrayFormatter.formatErrorSync(e))
2355
+ (e) => import_effect4.Effect.fail(import_schema2.ArrayFormatter.formatErrorSync(e))
2326
2356
  ),
2327
- import_effect3.Effect.repeat({
2328
- schedule: import_effect3.Schedule.exponential(checkInterval),
2357
+ import_effect4.Effect.repeat({
2358
+ schedule: import_effect4.Schedule.exponential(checkInterval),
2329
2359
  until: (result) => result.length > 0
2330
2360
  }),
2331
- import_effect3.Effect.timeout(16e4),
2332
- import_effect3.Effect.orDie,
2333
- import_effect3.Effect.as(true)
2361
+ import_effect4.Effect.timeout(16e4),
2362
+ import_effect4.Effect.orDie,
2363
+ import_effect4.Effect.as(true)
2334
2364
  );
2335
- return import_effect3.Effect.runPromise(program);
2365
+ return import_effect4.Effect.runPromise(program);
2336
2366
  }
2337
2367
  async submitTx(tx) {
2338
2368
  const result = await fetch(`${this.baseUrl}/submittx`, {
package/dist/index.js CHANGED
@@ -7,14 +7,14 @@ var __export = (target, all) => {
7
7
  // src/core.ts
8
8
  import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
9
9
 
10
- // src/blockfrost.ts
10
+ // src/blockfrost/blockfrost.ts
11
11
  import { fromHex, sleep } from "@lucid-evolution/core-utils";
12
12
  import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
13
13
 
14
14
  // package.json
15
15
  var package_default = {
16
16
  name: "@lucid-evolution/provider",
17
- version: "0.1.42",
17
+ version: "0.1.44",
18
18
  description: "",
19
19
  main: "./dist/index.js",
20
20
  types: "./dist/index.d.ts",
@@ -62,7 +62,8 @@ var package_default = {
62
62
  }
63
63
  };
64
64
 
65
- // src/blockfrost.ts
65
+ // src/blockfrost/blockfrost.ts
66
+ import { pipe, Record } from "effect";
66
67
  var Blockfrost = class {
67
68
  url;
68
69
  projectId;
@@ -271,17 +272,24 @@ var Blockfrost = class {
271
272
  headers: { project_id: this.projectId, lucid }
272
273
  }
273
274
  ).then((res) => res.json());
274
- if (type.toLowerCase() === "native") {
275
- throw new Error("Native script ref not implemented!");
276
- }
277
275
  const { cbor: script } = await fetch(
278
276
  `${this.url}/scripts/${r.reference_script_hash}/cbor`,
279
277
  { headers: { project_id: this.projectId, lucid } }
280
278
  ).then((res) => res.json());
281
- return {
282
- type: type === "plutusV1" ? "PlutusV1" : "PlutusV2",
283
- script: applyDoubleCborEncoding(script)
284
- };
279
+ switch (type) {
280
+ case "timelock":
281
+ return void 0;
282
+ case "plutusV1":
283
+ return {
284
+ type: "PlutusV1",
285
+ script: applyDoubleCborEncoding(script)
286
+ };
287
+ case "plutusV2":
288
+ return {
289
+ type: "PlutusV2",
290
+ script: applyDoubleCborEncoding(script)
291
+ };
292
+ }
285
293
  })() : void 0
286
294
  };
287
295
  })
@@ -291,19 +299,9 @@ var Blockfrost = class {
291
299
  return utxos;
292
300
  }
293
301
  async evaluateTx(tx, additionalUTxOs) {
294
- const additionalUTxOSet = (additionalUTxOs || []).map((utxo) => [
295
- { txId: utxo.txHash, index: utxo.outputIndex },
296
- {
297
- address: utxo.address,
298
- value: { coins: utxo.assets.lovelace, assets: utxo.assets.restAssets },
299
- datum_hash: utxo.datumHash,
300
- datum: utxo.datum,
301
- script: utxo.scriptRef
302
- }
303
- ]);
304
302
  const payload = {
305
303
  cbor: tx,
306
- additionalUTxOSet
304
+ additionalUtxoSet: toAditionalUTXOs(additionalUTxOs)
307
305
  };
308
306
  const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
309
307
  method: "POST",
@@ -312,10 +310,7 @@ var Blockfrost = class {
312
310
  project_id: this.projectId,
313
311
  lucid
314
312
  },
315
- body: JSON.stringify(
316
- payload,
317
- (_, value) => typeof value === "bigint" ? value.toString() : value
318
- )
313
+ body: JSON.stringify(payload)
319
314
  }).then((res2) => res2.json());
320
315
  if (!res || res.error) {
321
316
  const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}`;
@@ -379,17 +374,41 @@ function datumJsonToCbor(json) {
379
374
  }
380
375
  var handleRateLimit = async (count) => {
381
376
  if (count % 100 === 0) {
382
- await sleep(2e3);
377
+ await sleep(5e3);
383
378
  } else if (count % 10 === 0) {
384
- await sleep(200);
379
+ await sleep(500);
385
380
  }
386
381
  };
387
382
  var lucid = package_default.version;
383
+ var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
384
+ {
385
+ txId: utxo.txHash,
386
+ index: utxo.outputIndex
387
+ },
388
+ {
389
+ address: utxo.address,
390
+ value: {
391
+ coins: Number(utxo.assets["lovelace"]),
392
+ assets: fromAssets(utxo.assets)
393
+ },
394
+ datumHash: utxo.datumHash,
395
+ datum: utxo.datum,
396
+ script: utxo.scriptRef ? utxo.scriptRef.type === "PlutusV1" ? { "plutus:v1": utxo.scriptRef.script } : { "plutus:v2": utxo.scriptRef.script } : void 0
397
+ }
398
+ ]);
399
+ var fromAssets = (assets) => pipe(
400
+ Record.remove(assets, "lovelace"),
401
+ Record.mapEntries((amount, unit) => [
402
+ unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
403
+ Number(amount)
404
+ ]),
405
+ (r) => Record.isEmptyRecord(r) ? void 0 : r
406
+ );
388
407
 
389
408
  // src/kupmios/kupmios.ts
390
- import { fromUnit } from "@lucid-evolution/utils";
409
+ import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit } from "@lucid-evolution/utils";
391
410
  import * as S2 from "@effect/schema/Schema";
392
- import { Effect, pipe, Array as _Array, Schedule, Data } from "effect";
411
+ import { Effect, pipe as pipe2, Array as _Array, Schedule, Data } from "effect";
393
412
 
394
413
  // src/kupmios/schema.ts
395
414
  import * as S from "@effect/schema/Schema";
@@ -459,7 +478,12 @@ var KupoUTxO = S.Struct({
459
478
  slot_no: S.Number,
460
479
  header_hash: S.String
461
480
  }),
462
- spent_at: S.NullOr(S.Number)
481
+ spent_at: S.NullOr(
482
+ S.Struct({
483
+ slot_no: S.Number,
484
+ header_hash: S.String
485
+ })
486
+ )
463
487
  });
464
488
  var KupoScriptSchema = S.NullOr(
465
489
  S.Struct({
@@ -621,7 +645,7 @@ var Kupmios = class {
621
645
  return result.datum;
622
646
  }
623
647
  async awaitTx(txHash, checkInterval = 2e4) {
624
- const pattern = `${this.kupoUrl}/matches/*@${txHash}?unspent`;
648
+ const pattern = `${this.kupoUrl}/matches/*@${txHash}?spent`;
625
649
  const schema = S2.Array(KupoUTxO).annotations({
626
650
  identifier: "Array<KupmiosSchema.KupoUTxO>"
627
651
  });
@@ -732,28 +756,34 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* (
732
756
  Effect.map((result) => result.datum),
733
757
  Effect.timeout(1e4)
734
758
  );
735
- } else return null;
759
+ } else return void 0;
736
760
  });
737
761
  var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
738
762
  if (script_hash) {
739
763
  const pattern = `${kupoUrl}/scripts/${script_hash}`;
740
764
  const schema = KupoScriptSchema;
741
- return yield* pipe(
765
+ return yield* pipe2(
742
766
  fetchKupoParse(pattern, schema),
743
767
  Effect.flatMap(Effect.fromNullable),
744
768
  Effect.timeout(1e4),
745
769
  Effect.map(({ language, script }) => {
746
770
  switch (language) {
747
771
  case "native":
748
- return { type: "Native", script };
772
+ return void 0;
749
773
  case "plutus:v1":
750
- return { type: "PlutusV1", script };
774
+ return {
775
+ type: "PlutusV1",
776
+ script: applyDoubleCborEncoding2(script)
777
+ };
751
778
  case "plutus:v2":
752
- return { type: "PlutusV2", script };
779
+ return {
780
+ type: "PlutusV2",
781
+ script: applyDoubleCborEncoding2(script)
782
+ };
753
783
  }
754
784
  })
755
785
  );
756
- } else return null;
786
+ } else return void 0;
757
787
  });
758
788
  var toAssets = (value) => {
759
789
  const assets = { lovelace: BigInt(value.coins) };
@@ -798,7 +828,7 @@ var toProtocolParameters = (result) => {
798
828
  }
799
829
  };
800
830
  };
801
- var fetchOgmiosParse = (url, data, schema) => pipe(
831
+ var fetchOgmiosParse = (url, data, schema) => pipe2(
802
832
  HttpClientRequest.post(url),
803
833
  HttpClientRequest.jsonBody(data),
804
834
  Effect.flatMap(HttpClient.fetch),
@@ -809,7 +839,7 @@ var fetchOgmiosParse = (url, data, schema) => pipe(
809
839
  // ),
810
840
  // Effect.scoped
811
841
  );
812
- var fetchKupoParse = (url, schema) => pipe(
842
+ var fetchKupoParse = (url, schema) => pipe2(
813
843
  HttpClientRequest.get(url),
814
844
  HttpClient.fetchOk,
815
845
  HttpClientResponse.json,
@@ -822,7 +852,7 @@ var fetchKupoParse = (url, schema) => pipe(
822
852
  var kupmiosUtxosToUtxos = (kupoURL, utxos) => Effect.forEach(
823
853
  utxos,
824
854
  (utxo) => {
825
- return pipe(
855
+ return pipe2(
826
856
  Effect.all([
827
857
  getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
828
858
  getScriptEffect(kupoURL, utxo.script_hash)
@@ -833,7 +863,7 @@ var kupmiosUtxosToUtxos = (kupoURL, utxos) => Effect.forEach(
833
863
  outputIndex: utxo.output_index,
834
864
  address: utxo.address,
835
865
  assets: toAssets(utxo.value),
836
- datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : null,
866
+ datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
837
867
  datum,
838
868
  scriptRef: script
839
869
  })
@@ -1568,7 +1598,7 @@ function redeemerTagToString(tag) {
1568
1598
  }
1569
1599
 
1570
1600
  // src/maestro.ts
1571
- import { applyDoubleCborEncoding as applyDoubleCborEncoding2, utxoToCore } from "@lucid-evolution/utils";
1601
+ import { applyDoubleCborEncoding as applyDoubleCborEncoding3, utxoToCore } from "@lucid-evolution/utils";
1572
1602
  import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
1573
1603
  var Maestro = class {
1574
1604
  url;
@@ -1803,7 +1833,7 @@ var Maestro = class {
1803
1833
  datum: result.datum?.bytes,
1804
1834
  scriptRef: result.reference_script ? result.reference_script.type == "native" ? void 0 : {
1805
1835
  type: result.reference_script.type == "plutusv1" ? "PlutusV1" : "PlutusV2",
1806
- script: applyDoubleCborEncoding2(result.reference_script.bytes)
1836
+ script: applyDoubleCborEncoding3(result.reference_script.bytes)
1807
1837
  } : void 0
1808
1838
  };
1809
1839
  }
@@ -1860,7 +1890,7 @@ var lucid2 = package_default.version;
1860
1890
  // src/koios/koios.ts
1861
1891
  import * as S4 from "@effect/schema/Schema";
1862
1892
  import { fromHex as fromHex4 } from "@lucid-evolution/core-utils";
1863
- import { applyDoubleCborEncoding as applyDoubleCborEncoding3, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
1893
+ import { applyDoubleCborEncoding as applyDoubleCborEncoding4, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
1864
1894
 
1865
1895
  // src/koios/schema.ts
1866
1896
  import * as S3 from "@effect/schema/Schema";
@@ -2054,7 +2084,7 @@ var KoiosTxInfoSchema = S3.Struct({
2054
2084
  });
2055
2085
 
2056
2086
  // src/koios/koios.ts
2057
- import { Effect as Effect3, pipe as pipe3, Schedule as Schedule2 } from "effect";
2087
+ import { Effect as Effect3, pipe as pipe4, Schedule as Schedule2 } from "effect";
2058
2088
  import { ArrayFormatter } from "@effect/schema";
2059
2089
 
2060
2090
  // src/fetch.ts
@@ -2065,14 +2095,14 @@ __export(fetch_exports, {
2065
2095
  ResponseError: () => ResponseError,
2066
2096
  fetchEffect: () => fetchEffect
2067
2097
  });
2068
- import { Data as Data2, Effect as Effect2, pipe as pipe2 } from "effect";
2098
+ import { Data as Data2, Effect as Effect2, pipe as pipe3 } from "effect";
2069
2099
  var FetchError = class extends Data2.TaggedError("FetchError") {
2070
2100
  };
2071
2101
  var ResponseError = class extends Data2.TaggedError("ResponseError") {
2072
2102
  };
2073
2103
  var JsonError = class extends Data2.TaggedError("JsonError") {
2074
2104
  };
2075
- var fetchEffect = (input, requestInit) => pipe2(
2105
+ var fetchEffect = (input, requestInit) => pipe3(
2076
2106
  Effect2.tryPromise({
2077
2107
  try: () => fetch(input, requestInit),
2078
2108
  catch: (error) => new FetchError({
@@ -2284,7 +2314,7 @@ var Koios = class {
2284
2314
  method: "POST",
2285
2315
  body: JSON.stringify(body)
2286
2316
  };
2287
- const program = pipe3(
2317
+ const program = pipe4(
2288
2318
  fetchEffect(`${this.baseUrl}/tx_info`, request),
2289
2319
  Effect3.flatMap(
2290
2320
  (json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
@@ -2394,10 +2424,10 @@ var toUTxO = (koiosUTxO, address) => ({
2394
2424
  datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
2395
2425
  scriptRef: koiosUTxO.reference_script ? koiosUTxO.reference_script.type == "plutusV1" ? {
2396
2426
  type: "PlutusV1",
2397
- script: applyDoubleCborEncoding3(koiosUTxO.reference_script.bytes)
2427
+ script: applyDoubleCborEncoding4(koiosUTxO.reference_script.bytes)
2398
2428
  } : {
2399
2429
  type: "PlutusV2",
2400
- script: applyDoubleCborEncoding3(koiosUTxO.reference_script.bytes)
2430
+ script: applyDoubleCborEncoding4(koiosUTxO.reference_script.bytes)
2401
2431
  } : void 0
2402
2432
  });
2403
2433
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/provider",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  "effect": "^3.5.6",
33
33
  "@lucid-evolution/core-types": "0.1.13",
34
34
  "@lucid-evolution/core-utils": "0.1.13",
35
- "@lucid-evolution/utils": "0.1.33",
36
- "@lucid-evolution/wallet": "0.1.37"
35
+ "@lucid-evolution/utils": "0.1.35",
36
+ "@lucid-evolution/wallet": "0.1.39"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^20.12.8",