@lucid-evolution/provider 0.1.45 → 0.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -32,12 +32,11 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  Blockfrost: () => Blockfrost,
34
34
  Emulator: () => Emulator,
35
- FetchProvider: () => fetch_exports,
36
35
  Koios: () => Koios,
36
+ KoiosError: () => KoiosError,
37
37
  Kupmios: () => Kupmios,
38
38
  KupmiosError: () => KupmiosError,
39
39
  Maestro: () => Maestro,
40
- datumJsonToCbor: () => datumJsonToCbor,
41
40
  generateEmulatorAccount: () => generateEmulatorAccount
42
41
  });
43
42
  module.exports = __toCommonJS(src_exports);
@@ -45,14 +44,14 @@ module.exports = __toCommonJS(src_exports);
45
44
  // src/core.ts
46
45
  var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
47
46
 
48
- // src/blockfrost/blockfrost.ts
47
+ // src/blockfrost.ts
49
48
  var import_core_utils = require("@lucid-evolution/core-utils");
50
49
  var import_utils = require("@lucid-evolution/utils");
51
50
 
52
51
  // package.json
53
52
  var package_default = {
54
53
  name: "@lucid-evolution/provider",
55
- version: "0.1.45",
54
+ version: "0.1.46",
56
55
  description: "",
57
56
  main: "./dist/index.js",
58
57
  types: "./dist/index.d.ts",
@@ -100,8 +99,48 @@ var package_default = {
100
99
  }
101
100
  };
102
101
 
103
- // src/blockfrost/blockfrost.ts
102
+ // src/internal/blockfrost.ts
104
103
  var import_effect = require("effect");
104
+ var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
105
+ {
106
+ txId: utxo.txHash,
107
+ index: utxo.outputIndex
108
+ },
109
+ {
110
+ address: utxo.address,
111
+ value: {
112
+ coins: Number(utxo.assets["lovelace"]),
113
+ assets: fromAssets(utxo.assets)
114
+ },
115
+ datumHash: utxo.datumHash,
116
+ datum: utxo.datum,
117
+ script: toTxOutScript(utxo.scriptRef)
118
+ }
119
+ ]);
120
+ var toTxOutScript = (scriptRef) => {
121
+ if (scriptRef) {
122
+ switch (scriptRef.type) {
123
+ case "PlutusV1":
124
+ return { "plutus:v1": scriptRef.script };
125
+ case "PlutusV2":
126
+ return { "plutus:v2": scriptRef.script };
127
+ case "PlutusV3":
128
+ return { "plutus:v3": scriptRef.script };
129
+ default:
130
+ return void 0;
131
+ }
132
+ }
133
+ };
134
+ var fromAssets = (assets) => (0, import_effect.pipe)(
135
+ import_effect.Record.remove(assets, "lovelace"),
136
+ import_effect.Record.mapEntries((amount, unit) => [
137
+ unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
138
+ Number(amount)
139
+ ]),
140
+ (r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
141
+ );
142
+
143
+ // src/blockfrost.ts
105
144
  var Blockfrost = class {
106
145
  url;
107
146
  projectId;
@@ -379,42 +418,6 @@ var Blockfrost = class {
379
418
  return evalRedeemers;
380
419
  }
381
420
  };
382
- function datumJsonToCbor(json) {
383
- const convert = (json2) => {
384
- if (!isNaN(json2.int)) {
385
- return CML.PlutusData.new_integer(
386
- CML.BigInteger.from_str(json2.int.toString())
387
- );
388
- } else if (json2.bytes || !isNaN(Number(json2.bytes))) {
389
- return CML.PlutusData.new_bytes((0, import_core_utils.fromHex)(json2.bytes));
390
- } else if (json2.map) {
391
- const m = CML.PlutusMap.new();
392
- json2.map.forEach(({ k, v }) => {
393
- m.set(convert(k), convert(v));
394
- });
395
- return CML.PlutusData.new_map(m);
396
- } else if (json2.list) {
397
- const l = CML.PlutusDataList.new();
398
- json2.list.forEach((v) => {
399
- l.add(convert(v));
400
- });
401
- return CML.PlutusData.new_list(l);
402
- } else if (!isNaN(json2.constructor)) {
403
- const l = CML.PlutusDataList.new();
404
- json2.fields.forEach((v) => {
405
- l.add(convert(v));
406
- });
407
- return CML.PlutusData.new_constr_plutus_data(
408
- CML.ConstrPlutusData.new(
409
- CML.BigInteger.from_str(json2.constructor.toString()).as_u64(),
410
- l
411
- )
412
- );
413
- }
414
- throw new Error("Unsupported type");
415
- };
416
- return convert(json).to_cbor_hex();
417
- }
418
421
  var handleRateLimit = async (count) => {
419
422
  if (count % 100 === 0) {
420
423
  await (0, import_core_utils.sleep)(5e3);
@@ -423,52 +426,17 @@ var handleRateLimit = async (count) => {
423
426
  }
424
427
  };
425
428
  var lucid = package_default.version;
426
- var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
427
- {
428
- txId: utxo.txHash,
429
- index: utxo.outputIndex
430
- },
431
- {
432
- address: utxo.address,
433
- value: {
434
- coins: Number(utxo.assets["lovelace"]),
435
- assets: fromAssets(utxo.assets)
436
- },
437
- datumHash: utxo.datumHash,
438
- datum: utxo.datum,
439
- script: toTxOutScript(utxo.scriptRef)
440
- }
441
- ]);
442
- var toTxOutScript = (scriptRef) => {
443
- if (scriptRef) {
444
- switch (scriptRef.type) {
445
- case "PlutusV1":
446
- return { "plutus:v1": scriptRef.script };
447
- case "PlutusV2":
448
- return { "plutus:v2": scriptRef.script };
449
- case "PlutusV3":
450
- return { "plutus:v3": scriptRef.script };
451
- default:
452
- return void 0;
453
- }
454
- }
455
- };
456
- var fromAssets = (assets) => (0, import_effect.pipe)(
457
- import_effect.Record.remove(assets, "lovelace"),
458
- import_effect.Record.mapEntries((amount, unit) => [
459
- unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
460
- Number(amount)
461
- ]),
462
- (r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
463
- );
464
429
 
465
- // src/kupmios/kupmios.ts
466
- var import_utils2 = require("@lucid-evolution/utils");
467
- var S2 = __toESM(require("@effect/schema/Schema"), 1);
430
+ // src/kupmios.ts
431
+ var import_utils3 = require("@lucid-evolution/utils");
432
+ var S3 = __toESM(require("@effect/schema/Schema"), 1);
468
433
  var import_effect2 = require("effect");
434
+ var import_platform = require("@effect/platform");
435
+ var import_schema = require("@effect/schema");
469
436
 
470
- // src/kupmios/schema.ts
437
+ // src/internal/ogmios.ts
471
438
  var S = __toESM(require("@effect/schema/Schema"), 1);
439
+ var import_utils2 = require("@lucid-evolution/utils");
472
440
  var JSONRPCSchema = (schema) => S.extend(
473
441
  S.Struct({
474
442
  jsonrpc: S.String,
@@ -564,59 +532,118 @@ var ProtocolParametersSchema = S.Struct({
564
532
  maxCollateralInputs: S.Number,
565
533
  version: S.Struct({ major: S.Number, minor: S.Number })
566
534
  });
567
- var KupoValueSchema = S.Struct({
568
- coins: S.Number,
569
- assets: S.Record(S.String, S.Number)
535
+ var Delegation = S.NullOr(
536
+ S.Record(
537
+ S.String,
538
+ S.Struct({
539
+ delegate: S.Struct({ id: S.String }),
540
+ rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
541
+ deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
542
+ })
543
+ )
544
+ );
545
+ var RedeemerSchema = S.Struct({
546
+ validator: S.Struct({
547
+ purpose: S.String,
548
+ index: S.Int
549
+ }),
550
+ budget: S.Struct({
551
+ memory: S.Int,
552
+ cpu: S.Int
553
+ })
570
554
  });
571
- var KupoUTxO = S.Struct({
572
- transaction_index: S.Number,
573
- transaction_id: S.String,
574
- output_index: S.Number,
575
- address: S.String,
576
- value: KupoValueSchema,
577
- datum_hash: S.NullOr(S.String),
578
- datum_type: S.optional(S.Literal("hash", "inline")),
579
- script_hash: S.NullOr(S.String),
580
- created_at: S.Struct({
581
- slot_no: S.Number,
582
- header_hash: S.String
555
+ var toOgmiosUTxOs = (utxos) => {
556
+ const toOgmiosScript = (scriptRef) => {
557
+ if (scriptRef) {
558
+ switch (scriptRef.type) {
559
+ case "PlutusV1":
560
+ return { language: "plutus:v1", cbor: scriptRef.script };
561
+ case "PlutusV2":
562
+ return { language: "plutus:v2", cbor: scriptRef.script };
563
+ case "PlutusV3":
564
+ return { language: "plutus:v3", cbor: scriptRef.script };
565
+ default:
566
+ return null;
567
+ }
568
+ }
569
+ };
570
+ const toOgmiosAssets = (assets) => {
571
+ const newAssets = {};
572
+ Object.entries(assets).map(([unit, amount]) => {
573
+ if (unit == "lovelace") return;
574
+ const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
575
+ newAssets[policyId][assetName ? assetName : ""] = Number(amount);
576
+ });
577
+ return newAssets;
578
+ };
579
+ return (utxos || []).map(
580
+ (utxo) => ({
581
+ transaction: {
582
+ id: utxo.txHash
583
+ },
584
+ index: utxo.outputIndex,
585
+ address: utxo.address,
586
+ value: {
587
+ ada: { lovelace: Number(utxo.assets["lovelace"]) },
588
+ ...toOgmiosAssets(utxo.assets)
589
+ },
590
+ datumHash: utxo.datumHash,
591
+ datum: utxo.datum,
592
+ script: toOgmiosScript(utxo.scriptRef)
593
+ })
594
+ );
595
+ };
596
+
597
+ // src/internal/kupo.ts
598
+ var S2 = __toESM(require("@effect/schema/Schema"), 1);
599
+ var ValueSchema = S2.Struct({
600
+ coins: S2.Number,
601
+ assets: S2.Record(S2.String, S2.Number)
602
+ });
603
+ var UTxOSchema = S2.Struct({
604
+ transaction_index: S2.Number,
605
+ transaction_id: S2.String,
606
+ output_index: S2.Number,
607
+ address: S2.String,
608
+ value: ValueSchema,
609
+ datum_hash: S2.NullOr(S2.String),
610
+ datum_type: S2.optional(S2.Literal("hash", "inline")),
611
+ script_hash: S2.NullOr(S2.String),
612
+ created_at: S2.Struct({
613
+ slot_no: S2.Number,
614
+ header_hash: S2.String
583
615
  }),
584
- spent_at: S.NullOr(
585
- S.Struct({
586
- slot_no: S.Number,
587
- header_hash: S.String
616
+ spent_at: S2.NullOr(
617
+ S2.Struct({
618
+ slot_no: S2.Number,
619
+ header_hash: S2.String
588
620
  })
589
621
  )
590
622
  });
591
- var KupoScriptSchema = S.NullOr(
592
- S.Struct({
593
- language: S.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
594
- script: S.String
623
+ var ScriptSchema = S2.NullOr(
624
+ S2.Struct({
625
+ language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
626
+ script: S2.String
595
627
  })
596
628
  );
597
- var KupoDatumSchema = S.NullOr(S.Struct({ datum: S.String }));
598
- var KupoDelegation = S.NullOr(
599
- S.Record(
600
- S.String,
601
- S.Struct({
602
- delegate: S.Struct({ id: S.String }),
603
- rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
604
- deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
629
+ var DatumSchema = S2.NullOr(S2.Struct({ datum: S2.String }));
630
+ var DelegationSchema = S2.NullOr(
631
+ S2.Record(
632
+ S2.String,
633
+ S2.Struct({
634
+ delegate: S2.Struct({ id: S2.String }),
635
+ rewards: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) }),
636
+ deposit: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) })
605
637
  })
606
638
  )
607
639
  );
608
640
 
609
- // src/kupmios/kupmios.ts
610
- var import_platform = require("@effect/platform");
611
- var import_schema = require("@effect/schema");
641
+ // src/kupmios.ts
612
642
  var KupmiosError = class extends import_effect2.Data.TaggedError("KupmiosError") {
613
643
  get message() {
614
- return `${this.cause}`;
644
+ return `${JSON.stringify(this.cause)}`;
615
645
  }
616
646
  };
617
- var kupmiosError = (cause) => new KupmiosError({
618
- cause: JSON.stringify(cause)
619
- });
620
647
  var Kupmios = class {
621
648
  kupoUrl;
622
649
  ogmiosUrl;
@@ -635,15 +662,13 @@ var Kupmios = class {
635
662
  params: {},
636
663
  id: null
637
664
  };
638
- const schema = JSONRPCSchema(
639
- ProtocolParametersSchema
640
- );
665
+ const schema = JSONRPCSchema(ProtocolParametersSchema);
641
666
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
642
667
  import_effect2.Effect.flatMap(
643
- (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
668
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
644
669
  ),
645
670
  import_effect2.Effect.timeout(1e4),
646
- import_effect2.Effect.catchAll(kupmiosError)
671
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
647
672
  );
648
673
  const result = await import_effect2.Effect.runPromise(program);
649
674
  return toProtocolParameters(result);
@@ -652,11 +677,11 @@ var Kupmios = class {
652
677
  const isAddress = typeof addressOrCredential === "string";
653
678
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
654
679
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
655
- const schema = S2.Array(KupoUTxO);
680
+ const schema = S3.Array(UTxOSchema);
656
681
  const program = fetchKupoParse(pattern, schema).pipe(
657
682
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
658
683
  import_effect2.Effect.timeout(1e4),
659
- import_effect2.Effect.catchAll(kupmiosError)
684
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
660
685
  );
661
686
  const utxos = await import_effect2.Effect.runPromise(program);
662
687
  return utxos;
@@ -664,25 +689,25 @@ var Kupmios = class {
664
689
  async getUtxosWithUnit(addressOrCredential, unit) {
665
690
  const isAddress = typeof addressOrCredential === "string";
666
691
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
667
- const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
692
+ const { policyId, assetName } = (0, import_utils3.fromUnit)(unit);
668
693
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
669
- const schema = S2.Array(KupoUTxO);
694
+ const schema = S3.Array(UTxOSchema);
670
695
  const program = fetchKupoParse(pattern, schema).pipe(
671
696
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
672
697
  import_effect2.Effect.timeout(1e4),
673
- import_effect2.Effect.catchAll(kupmiosError)
698
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
674
699
  );
675
700
  const utxos = await import_effect2.Effect.runPromise(program);
676
701
  return utxos;
677
702
  }
678
703
  async getUtxoByUnit(unit) {
679
- const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
704
+ const { policyId, assetName } = (0, import_utils3.fromUnit)(unit);
680
705
  const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
681
- const schema = S2.Array(KupoUTxO);
706
+ const schema = S3.Array(UTxOSchema);
682
707
  const program = fetchKupoParse(pattern, schema).pipe(
683
708
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
684
709
  import_effect2.Effect.timeout(1e4),
685
- import_effect2.Effect.catchAll(kupmiosError)
710
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
686
711
  );
687
712
  const utxos = await import_effect2.Effect.runPromise(program);
688
713
  if (utxos.length > 1) {
@@ -695,13 +720,13 @@ var Kupmios = class {
695
720
  ...new Set(outRefs.map((outRef) => outRef.txHash))
696
721
  ];
697
722
  const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
698
- const schema = S2.Array(KupoUTxO);
723
+ const schema = S3.Array(UTxOSchema);
699
724
  const program = import_effect2.Effect.forEach(
700
725
  queryHashes,
701
726
  (txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
702
727
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
703
728
  import_effect2.Effect.timeout(1e4),
704
- import_effect2.Effect.catchAll(kupmiosError)
729
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
705
730
  )
706
731
  );
707
732
  const utxos = await import_effect2.Effect.runPromise(program);
@@ -718,13 +743,13 @@ var Kupmios = class {
718
743
  params: { keys: [rewardAddress] },
719
744
  id: null
720
745
  };
721
- const schema = JSONRPCSchema(KupoDelegation);
746
+ const schema = JSONRPCSchema(Delegation);
722
747
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
723
748
  import_effect2.Effect.flatMap(
724
- (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
749
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
725
750
  ),
726
751
  import_effect2.Effect.timeout(1e4),
727
- import_effect2.Effect.catchAll(kupmiosError)
752
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
728
753
  );
729
754
  const result = await import_effect2.Effect.runPromise(program);
730
755
  const delegation = result ? Object.values(result)[0] : null;
@@ -735,18 +760,18 @@ var Kupmios = class {
735
760
  }
736
761
  async getDatum(datumHash) {
737
762
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
738
- const schema = KupoDatumSchema;
763
+ const schema = DatumSchema;
739
764
  const program = fetchKupoParse(pattern, schema).pipe(
740
765
  import_effect2.Effect.timeout(1e4),
741
766
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
742
- import_effect2.Effect.catchAll(kupmiosError)
767
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
743
768
  );
744
769
  const result = await import_effect2.Effect.runPromise(program);
745
770
  return result.datum;
746
771
  }
747
772
  async awaitTx(txHash, checkInterval = 2e4) {
748
773
  const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
749
- const schema = S2.Array(KupoUTxO).annotations({
774
+ const schema = S3.Array(UTxOSchema).annotations({
750
775
  identifier: "Array<KupmiosSchema.KupoUTxO>"
751
776
  });
752
777
  const program = fetchKupoParse(pattern, schema).pipe(
@@ -755,7 +780,7 @@ var Kupmios = class {
755
780
  until: (result) => result.length > 0
756
781
  }),
757
782
  import_effect2.Effect.timeout(16e4),
758
- import_effect2.Effect.catchAll(kupmiosError),
783
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause })),
759
784
  import_effect2.Effect.as(true)
760
785
  );
761
786
  return await import_effect2.Effect.runPromise(program);
@@ -770,70 +795,39 @@ var Kupmios = class {
770
795
  id: null
771
796
  };
772
797
  const schema = JSONRPCSchema(
773
- S2.Struct({
774
- transaction: S2.Struct({
775
- id: S2.String
798
+ S3.Struct({
799
+ transaction: S3.Struct({
800
+ id: S3.String
776
801
  })
777
802
  })
778
803
  );
779
804
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
780
805
  import_effect2.Effect.flatMap(
781
- (response) => "error" in response ? import_effect2.Effect.fail(response.error) : import_effect2.Effect.succeed(response)
806
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response)
782
807
  ),
783
808
  import_effect2.Effect.timeout(1e4),
784
- import_effect2.Effect.catchAll(kupmiosError)
809
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
785
810
  );
786
811
  const { result } = await import_effect2.Effect.runPromise(program);
787
812
  return result.transaction.id;
788
813
  }
789
814
  async evaluateTx(tx, additionalUTxOs) {
790
- const utxos = (additionalUTxOs || []).map((utxo) => {
791
- const script = utxo.scriptRef ? {
792
- language: utxo.scriptRef.type,
793
- cbor: utxo.scriptRef.script
794
- } : void 0;
795
- return [
796
- {
797
- transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
798
- },
799
- {
800
- address: utxo.address,
801
- value: {
802
- coins: utxo.assets.lovelace,
803
- assets: utxo.assets.restAssets
804
- },
805
- datumHash: utxo.datumHash,
806
- datum: utxo.datum,
807
- script
808
- }
809
- ];
810
- });
811
815
  const data = {
812
816
  jsonrpc: "2.0",
813
817
  method: "evaluateTransaction",
814
- params: { transaction: { cbor: tx }, additionalUTxO: utxos },
818
+ params: {
819
+ transaction: { cbor: tx },
820
+ additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
821
+ },
815
822
  id: null
816
823
  };
817
- const schema = JSONRPCSchema(
818
- S2.Array(
819
- S2.Struct({
820
- validator: S2.Struct({
821
- purpose: S2.String,
822
- index: S2.Int
823
- }),
824
- budget: S2.Struct({
825
- memory: S2.Int,
826
- cpu: S2.Int
827
- })
828
- })
829
- )
830
- );
824
+ const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
831
825
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
832
826
  import_effect2.Effect.flatMap(
833
- (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
827
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
834
828
  ),
835
829
  import_effect2.Effect.timeout(1e4),
836
- import_effect2.Effect.catchAll(kupmiosError)
830
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
837
831
  );
838
832
  const result = await import_effect2.Effect.runPromise(program);
839
833
  const evalRedeemers = result.map((item) => ({
@@ -850,7 +844,7 @@ var Kupmios = class {
850
844
  var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.gen(function* () {
851
845
  if (datum_type === "inline" && datum_hash) {
852
846
  const pattern = `${kupoUrl}/datums/${datum_hash}`;
853
- const schema = KupoDatumSchema;
847
+ const schema = DatumSchema;
854
848
  return yield* fetchKupoParse(pattern, schema).pipe(
855
849
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
856
850
  import_effect2.Effect.map((result) => result.datum),
@@ -861,7 +855,7 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.
861
855
  var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(function* () {
862
856
  if (script_hash) {
863
857
  const pattern = `${kupoUrl}/scripts/${script_hash}`;
864
- const schema = KupoScriptSchema;
858
+ const schema = ScriptSchema;
865
859
  return yield* (0, import_effect2.pipe)(
866
860
  fetchKupoParse(pattern, schema),
867
861
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
@@ -873,12 +867,17 @@ var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(functi
873
867
  case "plutus:v1":
874
868
  return {
875
869
  type: "PlutusV1",
876
- script: (0, import_utils2.applyDoubleCborEncoding)(script)
870
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
877
871
  };
878
872
  case "plutus:v2":
879
873
  return {
880
874
  type: "PlutusV2",
881
- script: (0, import_utils2.applyDoubleCborEncoding)(script)
875
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
876
+ };
877
+ case "plutus:v3":
878
+ return {
879
+ type: "PlutusV3",
880
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
882
881
  };
883
882
  }
884
883
  })
@@ -939,9 +938,7 @@ var fetchOgmiosParse = (url, data, schema) => (0, import_effect2.pipe)(
939
938
  import_platform.HttpClientRequest.jsonBody(data),
940
939
  import_effect2.Effect.flatMap(import_platform.HttpClient.fetch),
941
940
  import_platform.HttpClientResponse.json,
942
- import_effect2.Effect.flatMap(
943
- S2.decodeUnknown(schema, { onExcessProperty: "error", errors: "first" })
944
- ),
941
+ import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
945
942
  import_effect2.Effect.catchTag(
946
943
  "ParseError",
947
944
  (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
@@ -952,7 +949,7 @@ var fetchKupoParse = (url, schema) => (0, import_effect2.pipe)(
952
949
  import_platform.HttpClientRequest.get(url),
953
950
  import_platform.HttpClient.fetchOk,
954
951
  import_platform.HttpClientResponse.json,
955
- import_effect2.Effect.flatMap(S2.decodeUnknown(schema, { onExcessProperty: "error" })),
952
+ import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
956
953
  import_effect2.Effect.catchTag(
957
954
  "ParseError",
958
955
  (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
@@ -984,13 +981,13 @@ var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
984
981
  );
985
982
 
986
983
  // src/emulator.ts
987
- var import_utils3 = require("@lucid-evolution/utils");
988
984
  var import_utils4 = require("@lucid-evolution/utils");
985
+ var import_utils5 = require("@lucid-evolution/utils");
989
986
  var import_core_utils2 = require("@lucid-evolution/core-utils");
990
987
  var import_wallet = require("@lucid-evolution/wallet");
991
988
  var import_cardano_multiplatform_lib_nodejs = require("@anastasia-labs/cardano-multiplatform-lib-nodejs");
992
989
  function generateEmulatorAccount(assets) {
993
- const seedPhrase = (0, import_utils3.generateSeedPhrase)();
990
+ const seedPhrase = (0, import_utils4.generateSeedPhrase)();
994
991
  return {
995
992
  seedPhrase,
996
993
  address: (0, import_wallet.walletFromSeed)(seedPhrase, {
@@ -1014,7 +1011,7 @@ var Emulator = class {
1014
1011
  time;
1015
1012
  protocolParameters;
1016
1013
  datumTable = {};
1017
- constructor(accounts, protocolParameters = import_utils3.PROTOCOL_PARAMETERS_DEFAULT) {
1014
+ constructor(accounts, protocolParameters = import_utils4.PROTOCOL_PARAMETERS_DEFAULT) {
1018
1015
  const GENESIS_HASH = "00".repeat(32);
1019
1016
  this.blockHeight = 0;
1020
1017
  this.slot = 0;
@@ -1080,7 +1077,7 @@ var Emulator = class {
1080
1077
  if (typeof addressOrCredential === "string") {
1081
1078
  return addressOrCredential === utxo.address ? utxo : [];
1082
1079
  } else {
1083
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1080
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1084
1081
  return paymentCredential?.hash === addressOrCredential.hash ? utxo : [];
1085
1082
  }
1086
1083
  });
@@ -1097,7 +1094,7 @@ var Emulator = class {
1097
1094
  if (typeof addressOrCredential === "string") {
1098
1095
  return addressOrCredential === utxo.address && utxo.assets[unit] > 0n ? utxo : [];
1099
1096
  } else {
1100
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1097
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1101
1098
  return paymentCredential?.hash === addressOrCredential.hash && utxo.assets[unit] > 0n ? utxo : [];
1102
1099
  }
1103
1100
  });
@@ -1411,7 +1408,7 @@ It does not exist or was already spent.`
1411
1408
  It does not exist or was already spent.`
1412
1409
  );
1413
1410
  }
1414
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(entry.utxo.address);
1411
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(entry.utxo.address);
1415
1412
  if (paymentCredential?.type === "Script") {
1416
1413
  throw new Error("Collateral inputs can only contain vkeys.");
1417
1414
  }
@@ -1432,7 +1429,7 @@ It does not exist or was already spent.`
1432
1429
  body.withdrawals().get(rawAddress).toString()
1433
1430
  );
1434
1431
  const rewardAddress = rawAddress.to_address().to_bech32(void 0);
1435
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1432
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1436
1433
  checkAndConsumeHash(stakeCredential, "Reward", index);
1437
1434
  if (this.chain[rewardAddress]?.delegation.rewards !== withdrawal) {
1438
1435
  throw new Error(
@@ -1465,7 +1462,7 @@ It does not exist or was already spent.`
1465
1462
  CML.NetworkInfo.testnet().network_id(),
1466
1463
  deregistration.stake_credential()
1467
1464
  ).to_address().to_bech32(void 0);
1468
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1465
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1469
1466
  checkAndConsumeHash(stakeCredential, "Cert", index);
1470
1467
  if (!this.chain[rewardAddress]?.registeredStake) {
1471
1468
  throw new Error(
@@ -1482,7 +1479,7 @@ It does not exist or was already spent.`
1482
1479
  delegation.stake_credential()
1483
1480
  ).to_address().to_bech32(void 0);
1484
1481
  const poolId = delegation.pool().to_bech32("pool");
1485
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1482
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1486
1483
  checkAndConsumeHash(stakeCredential, "Cert", index);
1487
1484
  if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1488
1485
  (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
@@ -1497,7 +1494,7 @@ It does not exist or was already spent.`
1497
1494
  }
1498
1495
  }
1499
1496
  resolvedInputs.forEach(({ entry: { utxo } }, index) => {
1500
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1497
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1501
1498
  checkAndConsumeHash(paymentCredential, "Spend", index);
1502
1499
  });
1503
1500
  const outputs = (() => {
@@ -1511,7 +1508,7 @@ It does not exist or was already spent.`
1511
1508
  ),
1512
1509
  output
1513
1510
  );
1514
- const utxo = (0, import_utils4.coreToUtxo)(unspentOutput);
1511
+ const utxo = (0, import_utils5.coreToUtxo)(unspentOutput);
1515
1512
  if (utxo.datumHash) consumedHashes.add(utxo.datumHash);
1516
1513
  collected.push({
1517
1514
  utxo,
@@ -1720,7 +1717,7 @@ function redeemerTagToString(tag) {
1720
1717
  }
1721
1718
 
1722
1719
  // src/maestro.ts
1723
- var import_utils5 = require("@lucid-evolution/utils");
1720
+ var import_utils6 = require("@lucid-evolution/utils");
1724
1721
  var import_core_utils3 = require("@lucid-evolution/core-utils");
1725
1722
  var Maestro = class {
1726
1723
  url;
@@ -1980,13 +1977,13 @@ var Maestro = class {
1980
1977
  }
1981
1978
  async evaluateTx(tx, additionalUTxOs) {
1982
1979
  const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
1983
- index: utxo.outputIndex,
1984
1980
  tx_hash: utxo.txHash,
1985
- tx_cbor: (0, import_utils5.utxoToCore)(utxo).to_cbor_hex
1981
+ index: utxo.outputIndex,
1982
+ txout_cbor: (0, import_utils6.utxoToCore)(utxo).output().to_cbor_hex()
1986
1983
  }));
1987
1984
  const payload = {
1988
1985
  cbor: tx,
1989
- additionalMaestroUTxOs
1986
+ additional_utxos: additionalMaestroUTxOs
1990
1987
  };
1991
1988
  const res = await fetch(`${this.url}/transactions/evaluate`, {
1992
1989
  method: "POST",
@@ -2012,17 +2009,17 @@ var toScriptRef = (reference_script) => {
2012
2009
  case "plutusv1":
2013
2010
  return {
2014
2011
  type: "PlutusV1",
2015
- script: (0, import_utils5.applyDoubleCborEncoding)(reference_script.bytes)
2012
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2016
2013
  };
2017
2014
  case "plutusv2":
2018
2015
  return {
2019
2016
  type: "PlutusV2",
2020
- script: (0, import_utils5.applyDoubleCborEncoding)(reference_script.bytes)
2017
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2021
2018
  };
2022
2019
  case "plutusv3":
2023
2020
  return {
2024
2021
  type: "PlutusV3",
2025
- script: (0, import_utils5.applyDoubleCborEncoding)(reference_script.bytes)
2022
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2026
2023
  };
2027
2024
  default:
2028
2025
  return void 0;
@@ -2031,211 +2028,214 @@ var toScriptRef = (reference_script) => {
2031
2028
  };
2032
2029
  var lucid2 = package_default.version;
2033
2030
 
2034
- // src/koios/koios.ts
2035
- var S4 = __toESM(require("@effect/schema/Schema"), 1);
2031
+ // src/koios.ts
2032
+ var S5 = __toESM(require("@effect/schema/Schema"), 1);
2036
2033
  var import_core_utils4 = require("@lucid-evolution/core-utils");
2037
- var import_utils6 = require("@lucid-evolution/utils");
2034
+ var import_utils8 = require("@lucid-evolution/utils");
2038
2035
 
2039
- // src/koios/schema.ts
2040
- var S3 = __toESM(require("@effect/schema/Schema"), 1);
2041
- var ProtocolParametersSchema2 = S3.Struct({
2042
- pvt_motion_no_confidence: S3.Number,
2043
- pvt_committee_normal: S3.Number,
2044
- pvt_committee_no_confidence: S3.Number,
2045
- pvt_hard_fork_initiation: S3.Number,
2046
- pvtpp_security_group: S3.Number,
2047
- dvt_motion_no_confidence: S3.Number,
2048
- dvt_committee_normal: S3.Number,
2049
- dvt_committee_no_confidence: S3.Number,
2050
- dvt_update_to_constitution: S3.Number,
2051
- dvt_hard_fork_initiation: S3.Number,
2052
- dvt_p_p_network_group: S3.Number,
2053
- dvt_p_p_economic_group: S3.Number,
2054
- dvt_p_p_technical_group: S3.Number,
2055
- dvt_p_p_gov_group: S3.Number,
2056
- dvt_treasury_withdrawal: S3.Number,
2057
- committee_min_size: S3.Number,
2058
- committee_max_term_length: S3.Number,
2059
- gov_action_lifetime: S3.Number,
2060
- gov_action_deposit: S3.NumberFromString,
2061
- drep_deposit: S3.NumberFromString,
2062
- drep_activity: S3.Number,
2063
- min_fee_ref_script_cost_per_byte: S3.Number,
2064
- epoch_no: S3.Number,
2065
- min_fee_a: S3.Number,
2066
- min_fee_b: S3.Number,
2067
- max_block_size: S3.Number,
2068
- max_tx_size: S3.Number,
2069
- max_bh_size: S3.Number,
2070
- key_deposit: S3.BigInt,
2071
- pool_deposit: S3.BigInt,
2072
- max_epoch: S3.Number,
2073
- optimal_pool_count: S3.Number,
2074
- influence: S3.Number,
2075
- monetary_expand_rate: S3.Number,
2076
- treasury_growth_rate: S3.Number,
2077
- decentralisation: S3.Number,
2078
- extra_entropy: S3.NullOr(S3.String),
2079
- protocol_major: S3.Number,
2080
- protocol_minor: S3.Number,
2081
- min_utxo_value: S3.String,
2082
- min_pool_cost: S3.String,
2083
- nonce: S3.String,
2084
- block_hash: S3.NullOr(S3.String),
2085
- cost_models: S3.Struct({
2086
- PlutusV1: S3.Array(S3.Number),
2087
- PlutusV2: S3.Array(S3.Number),
2088
- PlutusV3: S3.Array(S3.Number)
2036
+ // src/internal/koios.ts
2037
+ var import_platform2 = require("@effect/platform");
2038
+ var S4 = __toESM(require("@effect/schema/Schema"), 1);
2039
+ var import_effect3 = require("effect");
2040
+ var import_utils7 = require("@lucid-evolution/utils");
2041
+ var ProtocolParametersSchema2 = S4.Struct({
2042
+ pvt_motion_no_confidence: S4.Number,
2043
+ pvt_committee_normal: S4.Number,
2044
+ pvt_committee_no_confidence: S4.Number,
2045
+ pvt_hard_fork_initiation: S4.Number,
2046
+ pvtpp_security_group: S4.Number,
2047
+ dvt_motion_no_confidence: S4.Number,
2048
+ dvt_committee_normal: S4.Number,
2049
+ dvt_committee_no_confidence: S4.Number,
2050
+ dvt_update_to_constitution: S4.Number,
2051
+ dvt_hard_fork_initiation: S4.Number,
2052
+ dvt_p_p_network_group: S4.Number,
2053
+ dvt_p_p_economic_group: S4.Number,
2054
+ dvt_p_p_technical_group: S4.Number,
2055
+ dvt_p_p_gov_group: S4.Number,
2056
+ dvt_treasury_withdrawal: S4.Number,
2057
+ committee_min_size: S4.Number,
2058
+ committee_max_term_length: S4.Number,
2059
+ gov_action_lifetime: S4.Number,
2060
+ gov_action_deposit: S4.NumberFromString,
2061
+ drep_deposit: S4.NumberFromString,
2062
+ drep_activity: S4.Number,
2063
+ min_fee_ref_script_cost_per_byte: S4.Number,
2064
+ epoch_no: S4.Number,
2065
+ min_fee_a: S4.Number,
2066
+ min_fee_b: S4.Number,
2067
+ max_block_size: S4.Number,
2068
+ max_tx_size: S4.Number,
2069
+ max_bh_size: S4.Number,
2070
+ key_deposit: S4.BigInt,
2071
+ pool_deposit: S4.BigInt,
2072
+ max_epoch: S4.Number,
2073
+ optimal_pool_count: S4.Number,
2074
+ influence: S4.Number,
2075
+ monetary_expand_rate: S4.Number,
2076
+ treasury_growth_rate: S4.Number,
2077
+ decentralisation: S4.Number,
2078
+ extra_entropy: S4.NullOr(S4.String),
2079
+ protocol_major: S4.Number,
2080
+ protocol_minor: S4.Number,
2081
+ min_utxo_value: S4.String,
2082
+ min_pool_cost: S4.String,
2083
+ nonce: S4.String,
2084
+ block_hash: S4.NullOr(S4.String),
2085
+ cost_models: S4.Struct({
2086
+ PlutusV1: S4.Array(S4.Number),
2087
+ PlutusV2: S4.Array(S4.Number),
2088
+ PlutusV3: S4.Array(S4.Number)
2089
2089
  }),
2090
- price_mem: S3.Number,
2091
- price_step: S3.Number,
2092
- max_tx_ex_mem: S3.BigIntFromNumber,
2093
- max_tx_ex_steps: S3.BigIntFromNumber,
2094
- max_block_ex_mem: S3.Number,
2095
- max_block_ex_steps: S3.Number,
2096
- max_val_size: S3.Number,
2097
- collateral_percent: S3.Number,
2098
- max_collateral_inputs: S3.Number,
2099
- coins_per_utxo_size: S3.BigInt
2090
+ price_mem: S4.Number,
2091
+ price_step: S4.Number,
2092
+ max_tx_ex_mem: S4.BigIntFromNumber,
2093
+ max_tx_ex_steps: S4.BigIntFromNumber,
2094
+ max_block_ex_mem: S4.Number,
2095
+ max_block_ex_steps: S4.Number,
2096
+ max_val_size: S4.Number,
2097
+ collateral_percent: S4.Number,
2098
+ max_collateral_inputs: S4.Number,
2099
+ coins_per_utxo_size: S4.BigInt
2100
2100
  });
2101
- var KoiosAssetSchema = S3.Struct({
2102
- policy_id: S3.String,
2103
- asset_name: S3.NullOr(S3.String),
2104
- fingerprint: S3.String,
2105
- decimals: S3.Number,
2106
- quantity: S3.String
2101
+ var AssetSchema = S4.Struct({
2102
+ policy_id: S4.String,
2103
+ asset_name: S4.NullOr(S4.String),
2104
+ fingerprint: S4.String,
2105
+ decimals: S4.Number,
2106
+ quantity: S4.String
2107
2107
  });
2108
- var ReferenceScriptSchema = S3.Struct({
2109
- hash: S3.NullOr(S3.String),
2110
- size: S3.NullOr(S3.Number),
2111
- type: S3.NullOr(S3.String),
2112
- bytes: S3.NullOr(S3.String),
2113
- value: S3.NullOr(S3.Object)
2108
+ var ReferenceScriptSchema = S4.Struct({
2109
+ hash: S4.NullOr(S4.String),
2110
+ size: S4.NullOr(S4.Number),
2111
+ type: S4.NullOr(S4.String),
2112
+ bytes: S4.NullOr(S4.String),
2113
+ value: S4.NullOr(S4.Object)
2114
2114
  });
2115
- var KoiosUTxOSchema = S3.Struct({
2116
- tx_hash: S3.String,
2117
- tx_index: S3.Number,
2118
- block_time: S3.Number,
2119
- block_height: S3.NullOr(S3.Number),
2120
- value: S3.String,
2121
- datum_hash: S3.NullOr(S3.String),
2122
- inline_datum: S3.NullOr(
2123
- S3.Struct({
2124
- bytes: S3.String,
2125
- value: S3.Object
2115
+ var UTxOSchema2 = S4.Struct({
2116
+ tx_hash: S4.String,
2117
+ tx_index: S4.Number,
2118
+ block_time: S4.Number,
2119
+ block_height: S4.NullOr(S4.Number),
2120
+ value: S4.String,
2121
+ datum_hash: S4.NullOr(S4.String),
2122
+ inline_datum: S4.NullOr(
2123
+ S4.Struct({
2124
+ bytes: S4.String,
2125
+ value: S4.Object
2126
2126
  })
2127
2127
  ),
2128
- reference_script: S3.NullOr(ReferenceScriptSchema),
2129
- asset_list: S3.NullOr(S3.Array(KoiosAssetSchema))
2128
+ reference_script: S4.NullOr(ReferenceScriptSchema),
2129
+ asset_list: S4.NullOr(S4.Array(AssetSchema))
2130
2130
  });
2131
- var KoiosAddressInfoSchema = S3.Array(
2132
- S3.NullishOr(
2133
- S3.Struct({
2134
- address: S3.String,
2135
- balance: S3.String,
2136
- stake_address: S3.NullOr(S3.String),
2137
- script_address: S3.Boolean,
2138
- utxo_set: S3.Array(KoiosUTxOSchema)
2131
+ var AddressInfoSchema = S4.Array(
2132
+ S4.NullishOr(
2133
+ S4.Struct({
2134
+ address: S4.String,
2135
+ balance: S4.String,
2136
+ stake_address: S4.NullOr(S4.String),
2137
+ script_address: S4.Boolean,
2138
+ utxo_set: S4.Array(UTxOSchema2)
2139
2139
  })
2140
2140
  )
2141
2141
  );
2142
- var KoiosInputOutputSchema = S3.Struct({
2143
- payment_addr: S3.Struct({
2144
- bech32: S3.String,
2145
- cred: S3.String
2142
+ var InputOutputSchema = S4.Struct({
2143
+ payment_addr: S4.Struct({
2144
+ bech32: S4.String,
2145
+ cred: S4.String
2146
2146
  }),
2147
- stake_addr: S3.NullOr(S3.String),
2148
- tx_hash: S3.String,
2149
- tx_index: S3.Number,
2150
- value: S3.String,
2151
- datum_hash: S3.NullOr(S3.String),
2152
- inline_datum: S3.NullOr(
2153
- S3.Struct({
2154
- bytes: S3.String,
2155
- value: S3.Object
2147
+ stake_addr: S4.NullOr(S4.String),
2148
+ tx_hash: S4.String,
2149
+ tx_index: S4.Number,
2150
+ value: S4.String,
2151
+ datum_hash: S4.NullOr(S4.String),
2152
+ inline_datum: S4.NullOr(
2153
+ S4.Struct({
2154
+ bytes: S4.String,
2155
+ value: S4.Object
2156
2156
  })
2157
2157
  ),
2158
- reference_script: S3.NullOr(ReferenceScriptSchema),
2159
- asset_list: S3.Array(KoiosAssetSchema)
2158
+ reference_script: S4.NullOr(ReferenceScriptSchema),
2159
+ asset_list: S4.Array(AssetSchema)
2160
2160
  });
2161
- var KoiosTxInfoSchema = S3.Struct({
2162
- tx_hash: S3.String,
2163
- block_hash: S3.String,
2164
- block_height: S3.Number,
2165
- epoch_no: S3.Number,
2166
- epoch_slot: S3.Number,
2167
- absolute_slot: S3.Number,
2168
- tx_timestamp: S3.Number,
2169
- tx_block_index: S3.Number,
2170
- tx_size: S3.Number,
2171
- total_output: S3.String,
2172
- fee: S3.String,
2173
- treasury_donation: S3.String,
2174
- deposit: S3.String,
2175
- invalid_before: S3.NullOr(S3.String),
2176
- invalid_after: S3.NullOr(S3.String),
2177
- collateral_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
2178
- collateral_output: S3.NullOr(KoiosInputOutputSchema),
2179
- reference_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
2180
- inputs: S3.Array(KoiosInputOutputSchema),
2181
- outputs: S3.Array(KoiosInputOutputSchema),
2182
- withdrawals: S3.NullOr(
2183
- S3.Array(
2184
- S3.Struct({
2185
- amount: S3.String,
2186
- stake_addr: S3.String
2161
+ var TxInfoSchema = S4.Struct({
2162
+ tx_hash: S4.String,
2163
+ block_hash: S4.String,
2164
+ block_height: S4.Number,
2165
+ epoch_no: S4.Number,
2166
+ epoch_slot: S4.Number,
2167
+ absolute_slot: S4.Number,
2168
+ tx_timestamp: S4.Number,
2169
+ tx_block_index: S4.Number,
2170
+ tx_size: S4.Number,
2171
+ total_output: S4.String,
2172
+ fee: S4.String,
2173
+ treasury_donation: S4.String,
2174
+ deposit: S4.String,
2175
+ invalid_before: S4.NullOr(S4.String),
2176
+ invalid_after: S4.NullOr(S4.String),
2177
+ collateral_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
2178
+ collateral_output: S4.NullOr(InputOutputSchema),
2179
+ reference_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
2180
+ inputs: S4.Array(InputOutputSchema),
2181
+ outputs: S4.Array(InputOutputSchema),
2182
+ withdrawals: S4.NullOr(
2183
+ S4.Array(
2184
+ S4.Struct({
2185
+ amount: S4.String,
2186
+ stake_addr: S4.String
2187
2187
  })
2188
2188
  )
2189
2189
  ),
2190
- assets_minted: S3.NullOr(S3.Array(KoiosAssetSchema)),
2191
- metadata: S3.NullOr(S3.Object),
2192
- certificates: S3.NullOr(
2193
- S3.Array(
2194
- S3.Struct({
2195
- index: S3.Number,
2196
- type: S3.String,
2197
- info: S3.NullOr(S3.Object)
2190
+ assets_minted: S4.NullOr(S4.Array(AssetSchema)),
2191
+ metadata: S4.NullOr(S4.Object),
2192
+ certificates: S4.NullOr(
2193
+ S4.Array(
2194
+ S4.Struct({
2195
+ index: S4.Number,
2196
+ type: S4.String,
2197
+ info: S4.NullOr(S4.Object)
2198
2198
  })
2199
2199
  )
2200
2200
  ),
2201
- native_scripts: S3.NullOr(
2202
- S3.Array(
2203
- S3.Struct({
2204
- script_hash: S3.String,
2205
- script_json: S3.Object
2201
+ native_scripts: S4.NullOr(
2202
+ S4.Array(
2203
+ S4.Struct({
2204
+ script_hash: S4.String,
2205
+ script_json: S4.Object
2206
2206
  })
2207
2207
  )
2208
2208
  ),
2209
- plutus_contracts: S3.NullOr(
2210
- S3.Array(
2211
- S3.Struct({
2212
- address: S3.String,
2213
- spends_input: S3.NullOr(
2214
- S3.Struct({
2215
- tx_hash: S3.String,
2216
- tx_index: S3.Number
2209
+ plutus_contracts: S4.NullOr(
2210
+ S4.Array(
2211
+ S4.Struct({
2212
+ address: S4.String,
2213
+ spends_input: S4.NullOr(
2214
+ S4.Struct({
2215
+ tx_hash: S4.String,
2216
+ tx_index: S4.Number
2217
2217
  })
2218
2218
  ),
2219
- script_hash: S3.String,
2220
- bytecode: S3.String,
2221
- size: S3.Number,
2222
- valid_contract: S3.Boolean,
2223
- input: S3.Struct({
2224
- redeemer: S3.Struct({
2225
- purpose: S3.Literal("spend", "mint", "cert", "reward"),
2226
- fee: S3.String,
2227
- unit: S3.Struct({
2228
- steps: S3.String,
2229
- mem: S3.String
2219
+ script_hash: S4.String,
2220
+ bytecode: S4.String,
2221
+ size: S4.Number,
2222
+ valid_contract: S4.Boolean,
2223
+ input: S4.Struct({
2224
+ redeemer: S4.Struct({
2225
+ purpose: S4.Literal("spend", "mint", "cert", "reward"),
2226
+ fee: S4.String,
2227
+ unit: S4.Struct({
2228
+ steps: S4.String,
2229
+ mem: S4.String
2230
2230
  }),
2231
- datum: S3.Struct({
2232
- hash: S3.NullOr(S3.String),
2233
- value: S3.NullOr(S3.Object)
2231
+ datum: S4.Struct({
2232
+ hash: S4.NullOr(S4.String),
2233
+ value: S4.NullOr(S4.Object)
2234
2234
  })
2235
2235
  }),
2236
- datum: S3.Struct({
2237
- hash: S3.NullOr(S3.String),
2238
- value: S3.NullOr(S3.Object)
2236
+ datum: S4.Struct({
2237
+ hash: S4.NullOr(S4.String),
2238
+ value: S4.NullOr(S4.Object)
2239
2239
  })
2240
2240
  })
2241
2241
  })
@@ -2243,101 +2243,147 @@ var KoiosTxInfoSchema = S3.Struct({
2243
2243
  ),
2244
2244
  //TODO: add S.Struct
2245
2245
  // https://preprod.koios.rest/#post-/tx_info
2246
- voting_procedures: S3.Array(S3.Object),
2246
+ voting_procedures: S4.Array(S4.Object),
2247
2247
  //TODO: add S.Struct
2248
2248
  // https://preprod.koios.rest/#post-/tx_info
2249
- proposal_procedures: S3.Object
2249
+ proposal_procedures: S4.Object
2250
2250
  });
2251
-
2252
- // src/koios/koios.ts
2253
- var import_effect4 = require("effect");
2254
- var import_schema3 = require("@effect/schema");
2255
-
2256
- // src/fetch.ts
2257
- var fetch_exports = {};
2258
- __export(fetch_exports, {
2259
- FetchError: () => FetchError,
2260
- JsonError: () => JsonError,
2261
- ResponseError: () => ResponseError,
2262
- fetchEffect: () => fetchEffect
2251
+ var TxHashSchema = S4.String;
2252
+ var AssetAddressSchema = S4.Struct({
2253
+ payment_address: S4.String,
2254
+ stake_address: S4.NullOr(S4.String),
2255
+ quantity: S4.String
2263
2256
  });
2264
- var import_effect3 = require("effect");
2265
- var FetchError = class extends import_effect3.Data.TaggedError("FetchError") {
2266
- };
2267
- var ResponseError = class extends import_effect3.Data.TaggedError("ResponseError") {
2257
+ var AccountInfoSchema = S4.Struct({
2258
+ delegated_pool: S4.NullOr(S4.String),
2259
+ rewards_available: S4.NumberFromString
2260
+ });
2261
+ var DatumInfo = S4.Struct({
2262
+ bytes: S4.String
2263
+ });
2264
+ var postWithSchemaValidation = (url, data, schema) => (0, import_effect3.pipe)(
2265
+ import_platform2.HttpClientRequest.post(url),
2266
+ import_platform2.HttpClientRequest.jsonBody(data),
2267
+ import_effect3.Effect.flatMap(import_platform2.HttpClient.fetchOk),
2268
+ import_platform2.HttpClientResponse.json,
2269
+ import_effect3.Effect.flatMap(S4.decodeUnknown(schema))
2270
+ // Effect.scoped
2271
+ );
2272
+ var getWithSchemaValidation = (url, schema) => (0, import_effect3.pipe)(
2273
+ import_platform2.HttpClientRequest.get(url),
2274
+ import_platform2.HttpClient.fetchOk,
2275
+ import_platform2.HttpClientResponse.json,
2276
+ import_effect3.Effect.flatMap(S4.decodeUnknown(schema))
2277
+ );
2278
+ var toUTxO = (koiosUTxO, address) => ({
2279
+ txHash: koiosUTxO.tx_hash,
2280
+ outputIndex: koiosUTxO.tx_index,
2281
+ assets: (() => {
2282
+ const a = {};
2283
+ if (koiosUTxO.asset_list) {
2284
+ koiosUTxO.asset_list.forEach((am) => {
2285
+ a[am.policy_id + am.asset_name] = BigInt(am.quantity);
2286
+ });
2287
+ }
2288
+ a["lovelace"] = BigInt(koiosUTxO.value);
2289
+ return a;
2290
+ })(),
2291
+ address,
2292
+ datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
2293
+ datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
2294
+ scriptRef: toScriptRef2(koiosUTxO.reference_script)
2295
+ });
2296
+ var toScriptRef2 = (reference_script) => {
2297
+ if (reference_script && reference_script.bytes && reference_script.type) {
2298
+ switch (reference_script.type) {
2299
+ case "plutusV1":
2300
+ return {
2301
+ type: "PlutusV1",
2302
+ script: (0, import_utils7.applyDoubleCborEncoding)(reference_script.bytes)
2303
+ };
2304
+ case "plutusV2":
2305
+ return {
2306
+ type: "PlutusV2",
2307
+ script: (0, import_utils7.applyDoubleCborEncoding)(reference_script.bytes)
2308
+ };
2309
+ case "plutusV3":
2310
+ return {
2311
+ type: "PlutusV3",
2312
+ script: (0, import_utils7.applyDoubleCborEncoding)(reference_script.bytes)
2313
+ };
2314
+ default:
2315
+ return void 0;
2316
+ }
2317
+ }
2268
2318
  };
2269
- var JsonError = class extends import_effect3.Data.TaggedError("JsonError") {
2319
+ var getUtxosEffect = (baseUrl, addressOrCredential) => {
2320
+ const url = `${baseUrl}/address_info`;
2321
+ const body = {
2322
+ _addresses: [addressOrCredential]
2323
+ };
2324
+ const schema = AddressInfoSchema;
2325
+ const result = (0, import_effect3.pipe)(
2326
+ import_effect3.Effect.if(typeof addressOrCredential === "string", {
2327
+ onFalse: () => import_effect3.Effect.fail("Credential Type is not supported in Koios yet."),
2328
+ onTrue: () => postWithSchemaValidation(url, body, schema)
2329
+ }),
2330
+ import_effect3.Effect.map(
2331
+ ([result2]) => result2 ? result2.utxo_set.map((koiosUtxo) => toUTxO(koiosUtxo, result2.address)) : []
2332
+ )
2333
+ );
2334
+ return result;
2270
2335
  };
2271
- var fetchEffect = (input, requestInit) => (0, import_effect3.pipe)(
2272
- import_effect3.Effect.tryPromise({
2273
- try: () => fetch(input, requestInit),
2274
- catch: (error) => new FetchError({
2275
- message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
2276
- })
2277
- }),
2278
- import_effect3.Effect.flatMap(
2279
- (response) => !response.ok ? new ResponseError({
2280
- message: `${response.status} ${response.statusText}`
2281
- }) : import_effect3.Effect.succeed(response)
2282
- ),
2283
- import_effect3.Effect.flatMap(
2284
- (response) => import_effect3.Effect.tryPromise({
2285
- try: () => response.json(),
2286
- catch: (error) => new JsonError({ message: String(error) })
2287
- })
2288
- )
2289
- );
2290
2336
 
2291
- // src/koios/koios.ts
2337
+ // src/koios.ts
2338
+ var import_effect4 = require("effect");
2339
+ var KoiosError = class extends import_effect4.Data.TaggedError("KoiosError") {
2340
+ get message() {
2341
+ return `${this.cause}`;
2342
+ }
2343
+ };
2292
2344
  var Koios = class {
2293
2345
  baseUrl;
2294
2346
  constructor(baseUrl) {
2295
2347
  this.baseUrl = baseUrl;
2296
2348
  }
2297
2349
  async getProtocolParameters() {
2298
- const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
2299
- (res) => res.json()
2300
- );
2301
- const param = await (0, import_effect4.pipe)(
2302
- S4.decodeUnknown(ProtocolParametersSchema2, {
2303
- onExcessProperty: "error",
2304
- errors: "first"
2305
- })(result[0]),
2306
- import_effect4.Effect.catchTag(
2307
- "ParseError",
2308
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2309
- ),
2350
+ const url = `${this.baseUrl}/epoch_params?limit=1`;
2351
+ const schema = S5.Array(ProtocolParametersSchema2);
2352
+ const [result] = await (0, import_effect4.pipe)(
2353
+ getWithSchemaValidation(url, schema),
2354
+ import_effect4.Effect.timeout(1e4),
2355
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2310
2356
  import_effect4.Effect.runPromise
2311
2357
  );
2312
2358
  return {
2313
- minFeeA: param.min_fee_a,
2314
- minFeeB: param.min_fee_b,
2315
- maxTxSize: param.max_tx_size,
2316
- maxValSize: param.max_val_size,
2317
- keyDeposit: param.key_deposit,
2318
- poolDeposit: param.pool_deposit,
2319
- priceMem: param.price_mem,
2320
- priceStep: param.price_step,
2321
- maxTxExMem: param.max_tx_ex_mem,
2322
- maxTxExSteps: param.max_tx_ex_steps,
2323
- coinsPerUtxoByte: param.coins_per_utxo_size,
2324
- collateralPercentage: param.collateral_percent,
2325
- maxCollateralInputs: param.max_collateral_inputs,
2359
+ minFeeA: result.min_fee_a,
2360
+ minFeeB: result.min_fee_b,
2361
+ maxTxSize: result.max_tx_size,
2362
+ maxValSize: result.max_val_size,
2363
+ keyDeposit: result.key_deposit,
2364
+ poolDeposit: result.pool_deposit,
2365
+ priceMem: result.price_mem,
2366
+ priceStep: result.price_step,
2367
+ maxTxExMem: result.max_tx_ex_mem,
2368
+ maxTxExSteps: result.max_tx_ex_steps,
2369
+ coinsPerUtxoByte: result.coins_per_utxo_size,
2370
+ collateralPercentage: result.collateral_percent,
2371
+ maxCollateralInputs: result.max_collateral_inputs,
2326
2372
  costModels: {
2327
2373
  PlutusV1: Object.fromEntries(
2328
- param.cost_models.PlutusV1.map((value, index) => [
2374
+ result.cost_models.PlutusV1.map((value, index) => [
2329
2375
  index.toString(),
2330
2376
  value
2331
2377
  ])
2332
2378
  ),
2333
2379
  PlutusV2: Object.fromEntries(
2334
- param.cost_models.PlutusV2.map((value, index) => [
2380
+ result.cost_models.PlutusV2.map((value, index) => [
2335
2381
  index.toString(),
2336
2382
  value
2337
2383
  ])
2338
2384
  ),
2339
2385
  PlutusV3: Object.fromEntries(
2340
- param.cost_models.PlutusV3.map((value, index) => [
2386
+ result.cost_models.PlutusV3.map((value, index) => [
2341
2387
  index.toString(),
2342
2388
  value
2343
2389
  ])
@@ -2346,109 +2392,80 @@ var Koios = class {
2346
2392
  };
2347
2393
  }
2348
2394
  async getUtxos(addressOrCredential) {
2349
- if (typeof addressOrCredential === "string") {
2350
- const body = {
2351
- _addresses: [addressOrCredential]
2352
- };
2353
- const result = await fetch(`${this.baseUrl}/address_info`, {
2354
- headers: {
2355
- Accept: "application/json",
2356
- "Content-Type": "application/json"
2357
- },
2358
- method: "POST",
2359
- body: JSON.stringify(body)
2360
- }).then((res) => res.json());
2361
- const [parsedResult] = await (0, import_effect4.pipe)(
2362
- S4.decodeUnknown(KoiosAddressInfoSchema, {
2363
- onExcessProperty: "error",
2364
- errors: "first"
2365
- })(result),
2366
- import_effect4.Effect.catchTag(
2367
- "ParseError",
2368
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2369
- ),
2370
- import_effect4.Effect.runPromise
2371
- );
2372
- return parsedResult ? parsedResult.utxo_set.map(
2373
- (koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
2374
- ) : [];
2375
- } else {
2376
- throw Error("getUtxos by Credential Type is not supported in Koios yet.");
2377
- }
2395
+ const result = await (0, import_effect4.pipe)(
2396
+ getUtxosEffect(this.baseUrl, addressOrCredential),
2397
+ import_effect4.Effect.timeout(1e4),
2398
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2399
+ import_effect4.Effect.runPromise
2400
+ );
2401
+ return result;
2378
2402
  }
2379
2403
  async getUtxosWithUnit(addressOrCredential, unit) {
2380
- if (typeof addressOrCredential === "string") {
2381
- const utxos = await this.getUtxos(addressOrCredential);
2382
- if (utxos && utxos.length > 0) {
2383
- return utxos.filter((utxo) => {
2404
+ const result = await (0, import_effect4.pipe)(
2405
+ getUtxosEffect(this.baseUrl, addressOrCredential),
2406
+ import_effect4.Effect.map(
2407
+ (utxos) => utxos.filter((utxo) => {
2384
2408
  const keys = Object.keys(utxo.assets);
2385
2409
  return keys.length > 0 && keys.includes(unit);
2386
- });
2387
- } else {
2388
- return [];
2389
- }
2390
- } else {
2391
- throw Error(
2392
- "getUtxosWithUnit by Credential Type is not supported in Koios yet."
2393
- );
2394
- }
2410
+ })
2411
+ ),
2412
+ import_effect4.Effect.timeout(1e4),
2413
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2414
+ import_effect4.Effect.runPromise
2415
+ );
2416
+ return result;
2395
2417
  }
2396
2418
  async getUtxoByUnit(unit) {
2397
- let { policyId, assetName } = (0, import_utils6.fromUnit)(unit);
2398
- assetName = String(assetName);
2399
- const assetAddresses = await fetch(
2400
- `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`
2401
- ).then((res) => res.json());
2402
- if (Array.isArray(assetAddresses) && assetAddresses.length > 0) {
2403
- if (assetAddresses.length > 1) {
2404
- throw new Error("Unit needs to be an NFT or only held by one address.");
2405
- }
2406
- const utxos = await this.getUtxos(
2407
- assetAddresses[0].payment_address
2408
- );
2409
- const result = utxos.find((utxo) => {
2410
- const keys = Object.keys(utxo.assets);
2411
- return keys.length > 0 && keys.includes(unit);
2412
- });
2413
- if (result) {
2414
- return result;
2415
- }
2416
- }
2417
- throw new Error("Unit not found.");
2419
+ let { policyId, assetName } = (0, import_utils8.fromUnit)(unit);
2420
+ const url = `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`;
2421
+ const result = await (0, import_effect4.pipe)(
2422
+ getWithSchemaValidation(url, S5.Array(AssetAddressSchema)),
2423
+ import_effect4.Effect.flatMap(
2424
+ (adresses) => adresses.length === 0 ? import_effect4.Effect.fail("Unit not found") : import_effect4.Effect.succeed(adresses)
2425
+ ),
2426
+ import_effect4.Effect.flatMap(
2427
+ (adresses) => adresses.length > 1 ? import_effect4.Effect.fail("Unit needs to be an NFT or only held by one address.") : import_effect4.Effect.succeed(adresses[0])
2428
+ ),
2429
+ import_effect4.Effect.flatMap(
2430
+ (address) => getUtxosEffect(this.baseUrl, address.payment_address)
2431
+ ),
2432
+ import_effect4.Effect.map(
2433
+ (utxos) => utxos.filter((utxo) => {
2434
+ const keys = Object.keys(utxo.assets);
2435
+ return keys.length > 0 && keys.includes(unit);
2436
+ })
2437
+ ),
2438
+ import_effect4.Effect.flatMap(
2439
+ (utxos) => utxos.length > 1 ? import_effect4.Effect.fail("Unit needs to be an NFT or only held by one address.") : import_effect4.Effect.succeed(utxos[0])
2440
+ ),
2441
+ import_effect4.Effect.timeout(1e4),
2442
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2443
+ import_effect4.Effect.runPromise
2444
+ );
2445
+ return result;
2418
2446
  }
2419
2447
  async getUtxosByOutRef(outRefs) {
2448
+ const url = `${this.baseUrl}/tx_info`;
2420
2449
  const body = {
2421
2450
  _tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))],
2422
2451
  _assets: true,
2423
2452
  _scripts: true
2424
2453
  };
2425
- const result = await fetch(`${this.baseUrl}/tx_info`, {
2426
- headers: {
2427
- Accept: "application/json",
2428
- "Content-Type": "application/json"
2429
- },
2430
- method: "POST",
2431
- body: JSON.stringify(body)
2432
- }).then((res) => res.json());
2433
- const [parsedResult] = await (0, import_effect4.pipe)(
2434
- S4.decodeUnknown(S4.Array(KoiosTxInfoSchema), {
2435
- onExcessProperty: "error",
2436
- errors: "first"
2437
- })(result),
2438
- import_effect4.Effect.catchTag(
2439
- "ParseError",
2440
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2441
- ),
2454
+ const schema = S5.Array(TxInfoSchema);
2455
+ const [result] = await (0, import_effect4.pipe)(
2456
+ postWithSchemaValidation(url, body, schema),
2457
+ import_effect4.Effect.timeout(1e4),
2458
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2442
2459
  import_effect4.Effect.runPromise
2443
2460
  );
2444
- if (parsedResult) {
2445
- const utxos = parsedResult.outputs.map(
2461
+ if (result) {
2462
+ const utxos = result.outputs.map(
2446
2463
  (koiosInputOutput) => toUTxO(
2447
2464
  {
2448
2465
  tx_hash: koiosInputOutput.tx_hash,
2449
2466
  tx_index: koiosInputOutput.tx_index,
2450
2467
  block_time: 0,
2451
- block_height: parsedResult.block_height,
2468
+ block_height: result.block_height,
2452
2469
  value: koiosInputOutput.value,
2453
2470
  datum_hash: koiosInputOutput.datum_hash,
2454
2471
  inline_datum: koiosInputOutput.inline_datum,
@@ -2471,135 +2488,94 @@ var Koios = class {
2471
2488
  const body = {
2472
2489
  _stake_addresses: [rewardAddress]
2473
2490
  };
2474
- const result = await fetch(`${this.baseUrl}/account_info`, {
2475
- headers: {
2476
- Accept: "application/json",
2477
- "Content-Type": "application/json"
2478
- },
2479
- method: "POST",
2480
- body: JSON.stringify(body)
2481
- }).then((res) => res.json());
2482
- if (Array.isArray(result) && result.length > 0) {
2483
- return {
2484
- poolId: result[0].delegated_pool || null,
2485
- rewards: BigInt(result[0].rewards_available)
2486
- };
2487
- } else {
2488
- throw new Error("No Delegation Found by Reward Address");
2489
- }
2491
+ const url = `${this.baseUrl}/account_info`;
2492
+ const result = await (0, import_effect4.pipe)(
2493
+ postWithSchemaValidation(
2494
+ url,
2495
+ body,
2496
+ S5.Array(AccountInfoSchema)
2497
+ ),
2498
+ import_effect4.Effect.flatMap(
2499
+ (result2) => result2.length === 0 ? import_effect4.Effect.fail("No Delegation Found by Reward Address") : import_effect4.Effect.succeed(result2[0])
2500
+ ),
2501
+ import_effect4.Effect.timeout(1e4),
2502
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2503
+ import_effect4.Effect.runPromise
2504
+ );
2505
+ return {
2506
+ poolId: result.delegated_pool || null,
2507
+ rewards: BigInt(result.rewards_available)
2508
+ };
2490
2509
  }
2491
2510
  async getDatum(datumHash) {
2511
+ const url = `${this.baseUrl}/datum_info`;
2492
2512
  const body = {
2493
2513
  _datum_hashes: [datumHash]
2494
2514
  };
2495
- const datum = await fetch(`${this.baseUrl}/datum_info`, {
2496
- headers: {
2497
- Accept: "application/json",
2498
- "Content-Type": "application/json"
2499
- },
2500
- method: "POST",
2501
- body: JSON.stringify(body)
2502
- }).then((res) => res.json());
2503
- if (Array.isArray(datum) && datum.length > 0) {
2504
- return datum[0].bytes;
2505
- } else {
2506
- throw new Error("No Datum Found by Datum Hash");
2507
- }
2515
+ const result = await (0, import_effect4.pipe)(
2516
+ postWithSchemaValidation(url, body, S5.Array(DatumInfo)),
2517
+ import_effect4.Effect.flatMap(
2518
+ (result2) => result2.length === 0 ? import_effect4.Effect.fail("No Datum Found by Datum Hash") : import_effect4.Effect.succeed(result2[0])
2519
+ ),
2520
+ import_effect4.Effect.timeout(1e4),
2521
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2522
+ import_effect4.Effect.runPromise
2523
+ );
2524
+ return result.bytes;
2508
2525
  }
2509
2526
  async awaitTx(txHash, checkInterval = 2e4) {
2527
+ const url = `${this.baseUrl}/tx_info`;
2510
2528
  const body = {
2511
2529
  _tx_hashes: [txHash]
2512
2530
  };
2513
- const request = {
2514
- headers: {
2515
- Accept: "application/json",
2516
- "Content-Type": "application/json"
2517
- },
2518
- method: "POST",
2519
- body: JSON.stringify(body)
2520
- };
2521
- const program = (0, import_effect4.pipe)(
2522
- fetchEffect(`${this.baseUrl}/tx_info`, request),
2523
- import_effect4.Effect.flatMap(
2524
- (json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
2525
- ),
2526
- import_effect4.Effect.catchTag(
2527
- "ParseError",
2528
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2529
- ),
2531
+ const schema = S5.Array(TxInfoSchema);
2532
+ const result = await (0, import_effect4.pipe)(
2533
+ postWithSchemaValidation(url, body, schema),
2530
2534
  import_effect4.Effect.repeat({
2531
2535
  schedule: import_effect4.Schedule.exponential(checkInterval),
2532
- until: (result) => result.length > 0
2536
+ until: (result2) => result2.length > 0
2533
2537
  }),
2534
2538
  import_effect4.Effect.timeout(16e4),
2535
2539
  import_effect4.Effect.orDie,
2536
- import_effect4.Effect.as(true)
2540
+ import_effect4.Effect.as(true),
2541
+ import_effect4.Effect.runPromise
2537
2542
  );
2538
- return import_effect4.Effect.runPromise(program);
2543
+ return result;
2539
2544
  }
2540
2545
  async submitTx(tx) {
2541
- const result = await fetch(`${this.baseUrl}/submittx`, {
2542
- headers: {
2543
- Accept: "application/json",
2544
- "Content-Type": "application/cbor"
2545
- },
2546
- method: "POST",
2547
- body: (0, import_core_utils4.fromHex)(tx)
2548
- }).then((res) => res.json());
2549
- const TxHashSchema = S4.String;
2550
- const isTxHash = S4.is(TxHashSchema);
2551
- if (!isTxHash(result)) {
2552
- throw new Error(JSON.stringify(result));
2553
- }
2546
+ const url = `${this.baseUrl}/submittx`;
2547
+ const body = (0, import_core_utils4.fromHex)(tx);
2548
+ const schema = TxHashSchema;
2549
+ const result = await (0, import_effect4.pipe)(
2550
+ postWithSchemaValidation(url, body, schema),
2551
+ import_effect4.Effect.timeout(1e4),
2552
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2553
+ import_effect4.Effect.runPromise
2554
+ );
2554
2555
  return result;
2555
2556
  }
2556
2557
  async evaluateTx(tx, additionalUTxOs) {
2557
- const utxos = (additionalUTxOs || []).map((utxo) => {
2558
- const script = utxo.scriptRef ? {
2559
- language: utxo.scriptRef.type,
2560
- cbor: utxo.scriptRef.script
2561
- } : void 0;
2562
- return [
2563
- {
2564
- transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
2565
- },
2566
- {
2567
- address: utxo.address,
2568
- value: {
2569
- coins: utxo.assets.lovelace,
2570
- assets: utxo.assets.restAssets
2571
- },
2572
- datumHash: utxo.datumHash,
2573
- datum: utxo.datum,
2574
- script
2575
- }
2576
- ];
2577
- });
2578
- const data = {
2558
+ const url = `${this.baseUrl}/ogmios`;
2559
+ const body = {
2579
2560
  jsonrpc: "2.0",
2580
2561
  method: "evaluateTransaction",
2581
- params: { transaction: { cbor: tx }, additionalUTxO: utxos },
2562
+ params: {
2563
+ transaction: { cbor: tx },
2564
+ additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
2565
+ },
2582
2566
  id: null
2583
2567
  };
2584
- const response = await fetch(`${this.baseUrl}/ogmios`, {
2585
- headers: {
2586
- Accept: "application/json",
2587
- "Content-Type": "application/json"
2588
- },
2589
- method: "POST",
2590
- body: JSON.stringify(
2591
- data,
2592
- (_, value) => typeof value === "bigint" ? value.toString() : value
2593
- )
2594
- });
2595
- if (!response.ok) {
2596
- const errorBody = await response.text();
2597
- throw new Error(
2598
- `Request failed with status ${response.status}: ${errorBody}`
2599
- );
2600
- }
2601
- const result = await response.json();
2602
- const evalRedeemers = result.result.map((item) => ({
2568
+ const schema = JSONRPCSchema(S5.Array(RedeemerSchema));
2569
+ const result = await (0, import_effect4.pipe)(
2570
+ postWithSchemaValidation(url, body, schema),
2571
+ import_effect4.Effect.flatMap(
2572
+ (response) => "error" in response ? import_effect4.Effect.fail(response) : import_effect4.Effect.succeed(response.result)
2573
+ ),
2574
+ import_effect4.Effect.timeout(1e4),
2575
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2576
+ import_effect4.Effect.runPromise
2577
+ );
2578
+ const evalRedeemers = result.map((item) => ({
2603
2579
  ex_units: {
2604
2580
  mem: item.budget.memory,
2605
2581
  steps: item.budget.cpu
@@ -2610,56 +2586,14 @@ var Koios = class {
2610
2586
  return evalRedeemers;
2611
2587
  }
2612
2588
  };
2613
- var toUTxO = (koiosUTxO, address) => ({
2614
- txHash: koiosUTxO.tx_hash,
2615
- outputIndex: koiosUTxO.tx_index,
2616
- assets: (() => {
2617
- const a = {};
2618
- if (koiosUTxO.asset_list) {
2619
- koiosUTxO.asset_list.forEach((am) => {
2620
- a[am.policy_id + am.asset_name] = BigInt(am.quantity);
2621
- });
2622
- }
2623
- a["lovelace"] = BigInt(koiosUTxO.value);
2624
- return a;
2625
- })(),
2626
- address,
2627
- datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
2628
- datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
2629
- scriptRef: toScriptRef2(koiosUTxO.reference_script)
2630
- });
2631
- var toScriptRef2 = (reference_script) => {
2632
- if (reference_script && reference_script.bytes && reference_script.type) {
2633
- switch (reference_script.type) {
2634
- case "plutusV1":
2635
- return {
2636
- type: "PlutusV1",
2637
- script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2638
- };
2639
- case "plutusV2":
2640
- return {
2641
- type: "PlutusV2",
2642
- script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2643
- };
2644
- case "plutusV3":
2645
- return {
2646
- type: "PlutusV3",
2647
- script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2648
- };
2649
- default:
2650
- return void 0;
2651
- }
2652
- }
2653
- };
2654
2589
  // Annotate the CommonJS export names for ESM import in node:
2655
2590
  0 && (module.exports = {
2656
2591
  Blockfrost,
2657
2592
  Emulator,
2658
- FetchProvider,
2659
2593
  Koios,
2594
+ KoiosError,
2660
2595
  Kupmios,
2661
2596
  KupmiosError,
2662
2597
  Maestro,
2663
- datumJsonToCbor,
2664
2598
  generateEmulatorAccount
2665
2599
  });