@lucid-evolution/provider 0.1.44 → 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.44",
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;
@@ -327,6 +366,11 @@ var Blockfrost = class {
327
366
  type: "PlutusV2",
328
367
  script: (0, import_utils.applyDoubleCborEncoding)(script)
329
368
  };
369
+ case "plutusV3":
370
+ return {
371
+ type: "PlutusV3",
372
+ script: (0, import_utils.applyDoubleCborEncoding)(script)
373
+ };
330
374
  }
331
375
  })() : void 0
332
376
  };
@@ -374,42 +418,6 @@ var Blockfrost = class {
374
418
  return evalRedeemers;
375
419
  }
376
420
  };
377
- function datumJsonToCbor(json) {
378
- const convert = (json2) => {
379
- if (!isNaN(json2.int)) {
380
- return CML.PlutusData.new_integer(
381
- CML.BigInteger.from_str(json2.int.toString())
382
- );
383
- } else if (json2.bytes || !isNaN(Number(json2.bytes))) {
384
- return CML.PlutusData.new_bytes((0, import_core_utils.fromHex)(json2.bytes));
385
- } else if (json2.map) {
386
- const m = CML.PlutusMap.new();
387
- json2.map.forEach(({ k, v }) => {
388
- m.set(convert(k), convert(v));
389
- });
390
- return CML.PlutusData.new_map(m);
391
- } else if (json2.list) {
392
- const l = CML.PlutusDataList.new();
393
- json2.list.forEach((v) => {
394
- l.add(convert(v));
395
- });
396
- return CML.PlutusData.new_list(l);
397
- } else if (!isNaN(json2.constructor)) {
398
- const l = CML.PlutusDataList.new();
399
- json2.fields.forEach((v) => {
400
- l.add(convert(v));
401
- });
402
- return CML.PlutusData.new_constr_plutus_data(
403
- CML.ConstrPlutusData.new(
404
- CML.BigInteger.from_str(json2.constructor.toString()).as_u64(),
405
- l
406
- )
407
- );
408
- }
409
- throw new Error("Unsupported type");
410
- };
411
- return convert(json).to_cbor_hex();
412
- }
413
421
  var handleRateLimit = async (count) => {
414
422
  if (count % 100 === 0) {
415
423
  await (0, import_core_utils.sleep)(5e3);
@@ -418,38 +426,17 @@ var handleRateLimit = async (count) => {
418
426
  }
419
427
  };
420
428
  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
- );
445
429
 
446
- // src/kupmios/kupmios.ts
447
- var import_utils2 = require("@lucid-evolution/utils");
448
- 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);
449
433
  var import_effect2 = require("effect");
434
+ var import_platform = require("@effect/platform");
435
+ var import_schema = require("@effect/schema");
450
436
 
451
- // src/kupmios/schema.ts
437
+ // src/internal/ogmios.ts
452
438
  var S = __toESM(require("@effect/schema/Schema"), 1);
439
+ var import_utils2 = require("@lucid-evolution/utils");
453
440
  var JSONRPCSchema = (schema) => S.extend(
454
441
  S.Struct({
455
442
  jsonrpc: S.String,
@@ -467,6 +454,51 @@ var TupleNumberFromString = S.compose(
467
454
  );
468
455
  var ProtocolParametersSchema = S.Struct({
469
456
  minFeeCoefficient: S.Number,
457
+ minFeeReferenceScripts: S.Struct({
458
+ base: S.Number,
459
+ range: S.Number,
460
+ multiplier: S.Number
461
+ }),
462
+ maxReferenceScriptsSize: S.Struct({
463
+ bytes: S.Number
464
+ }),
465
+ stakePoolVotingThresholds: S.Struct({
466
+ noConfidence: TupleNumberFromString,
467
+ constitutionalCommittee: S.Struct({
468
+ default: TupleNumberFromString,
469
+ stateOfNoConfidence: TupleNumberFromString
470
+ }),
471
+ hardForkInitiation: TupleNumberFromString,
472
+ protocolParametersUpdate: S.Struct({
473
+ security: TupleNumberFromString
474
+ })
475
+ }),
476
+ delegateRepresentativeVotingThresholds: S.Struct({
477
+ noConfidence: TupleNumberFromString,
478
+ constitutionalCommittee: S.Struct({
479
+ default: TupleNumberFromString,
480
+ stateOfNoConfidence: TupleNumberFromString
481
+ }),
482
+ constitution: TupleNumberFromString,
483
+ hardForkInitiation: TupleNumberFromString,
484
+ protocolParametersUpdate: S.Struct({
485
+ network: TupleNumberFromString,
486
+ economic: TupleNumberFromString,
487
+ technical: TupleNumberFromString,
488
+ governance: TupleNumberFromString
489
+ }),
490
+ treasuryWithdrawals: TupleNumberFromString
491
+ }),
492
+ constitutionalCommitteeMinSize: S.Number,
493
+ constitutionalCommitteeMaxTermLength: S.Number,
494
+ governanceActionLifetime: S.Number,
495
+ governanceActionDeposit: S.Struct({
496
+ ada: LovelaceAsset
497
+ }),
498
+ delegateRepresentativeDeposit: S.Struct({
499
+ ada: LovelaceAsset
500
+ }),
501
+ delegateRepresentativeMaxIdleTime: S.Number,
470
502
  minFeeConstant: S.Struct({ ada: LovelaceAsset }),
471
503
  maxBlockBodySize: S.Struct({ bytes: S.Number }),
472
504
  maxBlockHeaderSize: S.Struct({ bytes: S.Number }),
@@ -483,7 +515,8 @@ var ProtocolParametersSchema = S.Struct({
483
515
  minUtxoDepositCoefficient: S.Number,
484
516
  plutusCostModels: S.Struct({
485
517
  "plutus:v1": S.Array(S.Number),
486
- "plutus:v2": S.Array(S.Number)
518
+ "plutus:v2": S.Array(S.Number),
519
+ "plutus:v3": S.Array(S.Number)
487
520
  }),
488
521
  scriptExecutionPrices: S.Struct({
489
522
  memory: TupleNumberFromString,
@@ -499,58 +532,118 @@ var ProtocolParametersSchema = S.Struct({
499
532
  maxCollateralInputs: S.Number,
500
533
  version: S.Struct({ major: S.Number, minor: S.Number })
501
534
  });
502
- var KupoValueSchema = S.Struct({
503
- coins: S.Number,
504
- 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
+ })
554
+ });
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)
505
602
  });
506
- var KupoUTxO = S.Struct({
507
- transaction_index: S.Number,
508
- transaction_id: S.String,
509
- output_index: S.Number,
510
- address: S.String,
511
- value: KupoValueSchema,
512
- datum_hash: S.NullOr(S.String),
513
- datum_type: S.optional(S.Literal("hash", "inline")),
514
- script_hash: S.NullOr(S.String),
515
- created_at: S.Struct({
516
- slot_no: S.Number,
517
- header_hash: S.String
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
518
615
  }),
519
- spent_at: S.NullOr(
520
- S.Struct({
521
- slot_no: S.Number,
522
- header_hash: S.String
616
+ spent_at: S2.NullOr(
617
+ S2.Struct({
618
+ slot_no: S2.Number,
619
+ header_hash: S2.String
523
620
  })
524
621
  )
525
622
  });
526
- var KupoScriptSchema = S.NullOr(
527
- S.Struct({
528
- language: S.Literal("native", "plutus:v1", "plutus:v2"),
529
- 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
530
627
  })
531
628
  );
532
- var KupoDatumSchema = S.NullOr(S.Struct({ datum: S.String }));
533
- var KupoDelegation = S.NullOr(
534
- S.Record(
535
- S.String,
536
- S.Struct({
537
- delegate: S.Struct({ id: S.String }),
538
- rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
539
- 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 }) })
540
637
  })
541
638
  )
542
639
  );
543
640
 
544
- // src/kupmios/kupmios.ts
545
- var import_platform = require("@effect/platform");
641
+ // src/kupmios.ts
546
642
  var KupmiosError = class extends import_effect2.Data.TaggedError("KupmiosError") {
547
643
  get message() {
548
- return `${this.cause}`;
644
+ return `${JSON.stringify(this.cause)}`;
549
645
  }
550
646
  };
551
- var kupmiosError = (cause) => new KupmiosError({
552
- cause: JSON.stringify(cause)
553
- });
554
647
  var Kupmios = class {
555
648
  kupoUrl;
556
649
  ogmiosUrl;
@@ -569,15 +662,13 @@ var Kupmios = class {
569
662
  params: {},
570
663
  id: null
571
664
  };
572
- const schema = JSONRPCSchema(
573
- ProtocolParametersSchema
574
- );
665
+ const schema = JSONRPCSchema(ProtocolParametersSchema);
575
666
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
576
667
  import_effect2.Effect.flatMap(
577
- (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)
578
669
  ),
579
670
  import_effect2.Effect.timeout(1e4),
580
- import_effect2.Effect.catchAll(kupmiosError)
671
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
581
672
  );
582
673
  const result = await import_effect2.Effect.runPromise(program);
583
674
  return toProtocolParameters(result);
@@ -586,11 +677,11 @@ var Kupmios = class {
586
677
  const isAddress = typeof addressOrCredential === "string";
587
678
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
588
679
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
589
- const schema = S2.Array(KupoUTxO);
680
+ const schema = S3.Array(UTxOSchema);
590
681
  const program = fetchKupoParse(pattern, schema).pipe(
591
682
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
592
683
  import_effect2.Effect.timeout(1e4),
593
- import_effect2.Effect.catchAll(kupmiosError)
684
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
594
685
  );
595
686
  const utxos = await import_effect2.Effect.runPromise(program);
596
687
  return utxos;
@@ -598,25 +689,25 @@ var Kupmios = class {
598
689
  async getUtxosWithUnit(addressOrCredential, unit) {
599
690
  const isAddress = typeof addressOrCredential === "string";
600
691
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
601
- const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
692
+ const { policyId, assetName } = (0, import_utils3.fromUnit)(unit);
602
693
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
603
- const schema = S2.Array(KupoUTxO);
694
+ const schema = S3.Array(UTxOSchema);
604
695
  const program = fetchKupoParse(pattern, schema).pipe(
605
696
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
606
697
  import_effect2.Effect.timeout(1e4),
607
- import_effect2.Effect.catchAll(kupmiosError)
698
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
608
699
  );
609
700
  const utxos = await import_effect2.Effect.runPromise(program);
610
701
  return utxos;
611
702
  }
612
703
  async getUtxoByUnit(unit) {
613
- const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
704
+ const { policyId, assetName } = (0, import_utils3.fromUnit)(unit);
614
705
  const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
615
- const schema = S2.Array(KupoUTxO);
706
+ const schema = S3.Array(UTxOSchema);
616
707
  const program = fetchKupoParse(pattern, schema).pipe(
617
708
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
618
709
  import_effect2.Effect.timeout(1e4),
619
- import_effect2.Effect.catchAll(kupmiosError)
710
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
620
711
  );
621
712
  const utxos = await import_effect2.Effect.runPromise(program);
622
713
  if (utxos.length > 1) {
@@ -629,13 +720,13 @@ var Kupmios = class {
629
720
  ...new Set(outRefs.map((outRef) => outRef.txHash))
630
721
  ];
631
722
  const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
632
- const schema = S2.Array(KupoUTxO);
723
+ const schema = S3.Array(UTxOSchema);
633
724
  const program = import_effect2.Effect.forEach(
634
725
  queryHashes,
635
726
  (txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
636
727
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
637
728
  import_effect2.Effect.timeout(1e4),
638
- import_effect2.Effect.catchAll(kupmiosError)
729
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
639
730
  )
640
731
  );
641
732
  const utxos = await import_effect2.Effect.runPromise(program);
@@ -652,13 +743,13 @@ var Kupmios = class {
652
743
  params: { keys: [rewardAddress] },
653
744
  id: null
654
745
  };
655
- const schema = JSONRPCSchema(KupoDelegation);
746
+ const schema = JSONRPCSchema(Delegation);
656
747
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
657
748
  import_effect2.Effect.flatMap(
658
- (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)
659
750
  ),
660
751
  import_effect2.Effect.timeout(1e4),
661
- import_effect2.Effect.catchAll(kupmiosError)
752
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
662
753
  );
663
754
  const result = await import_effect2.Effect.runPromise(program);
664
755
  const delegation = result ? Object.values(result)[0] : null;
@@ -669,18 +760,18 @@ var Kupmios = class {
669
760
  }
670
761
  async getDatum(datumHash) {
671
762
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
672
- const schema = KupoDatumSchema;
763
+ const schema = DatumSchema;
673
764
  const program = fetchKupoParse(pattern, schema).pipe(
674
765
  import_effect2.Effect.timeout(1e4),
675
766
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
676
- import_effect2.Effect.catchAll(kupmiosError)
767
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
677
768
  );
678
769
  const result = await import_effect2.Effect.runPromise(program);
679
770
  return result.datum;
680
771
  }
681
772
  async awaitTx(txHash, checkInterval = 2e4) {
682
- const pattern = `${this.kupoUrl}/matches/*@${txHash}?spent`;
683
- const schema = S2.Array(KupoUTxO).annotations({
773
+ const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
774
+ const schema = S3.Array(UTxOSchema).annotations({
684
775
  identifier: "Array<KupmiosSchema.KupoUTxO>"
685
776
  });
686
777
  const program = fetchKupoParse(pattern, schema).pipe(
@@ -689,7 +780,7 @@ var Kupmios = class {
689
780
  until: (result) => result.length > 0
690
781
  }),
691
782
  import_effect2.Effect.timeout(16e4),
692
- import_effect2.Effect.catchAll(kupmiosError),
783
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause })),
693
784
  import_effect2.Effect.as(true)
694
785
  );
695
786
  return await import_effect2.Effect.runPromise(program);
@@ -704,70 +795,39 @@ var Kupmios = class {
704
795
  id: null
705
796
  };
706
797
  const schema = JSONRPCSchema(
707
- S2.Struct({
708
- transaction: S2.Struct({
709
- id: S2.String
798
+ S3.Struct({
799
+ transaction: S3.Struct({
800
+ id: S3.String
710
801
  })
711
802
  })
712
803
  );
713
804
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
714
805
  import_effect2.Effect.flatMap(
715
- (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)
716
807
  ),
717
808
  import_effect2.Effect.timeout(1e4),
718
- import_effect2.Effect.catchAll(kupmiosError)
809
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
719
810
  );
720
811
  const { result } = await import_effect2.Effect.runPromise(program);
721
812
  return result.transaction.id;
722
813
  }
723
814
  async evaluateTx(tx, additionalUTxOs) {
724
- const utxos = (additionalUTxOs || []).map((utxo) => {
725
- const script = utxo.scriptRef ? {
726
- language: utxo.scriptRef.type,
727
- cbor: utxo.scriptRef.script
728
- } : void 0;
729
- return [
730
- {
731
- transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
732
- },
733
- {
734
- address: utxo.address,
735
- value: {
736
- coins: utxo.assets.lovelace,
737
- assets: utxo.assets.restAssets
738
- },
739
- datumHash: utxo.datumHash,
740
- datum: utxo.datum,
741
- script
742
- }
743
- ];
744
- });
745
815
  const data = {
746
816
  jsonrpc: "2.0",
747
817
  method: "evaluateTransaction",
748
- params: { transaction: { cbor: tx }, additionalUTxO: utxos },
818
+ params: {
819
+ transaction: { cbor: tx },
820
+ additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
821
+ },
749
822
  id: null
750
823
  };
751
- const schema = JSONRPCSchema(
752
- S2.Array(
753
- S2.Struct({
754
- validator: S2.Struct({
755
- purpose: S2.String,
756
- index: S2.Int
757
- }),
758
- budget: S2.Struct({
759
- memory: S2.Int,
760
- cpu: S2.Int
761
- })
762
- })
763
- )
764
- );
824
+ const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
765
825
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
766
826
  import_effect2.Effect.flatMap(
767
- (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)
768
828
  ),
769
829
  import_effect2.Effect.timeout(1e4),
770
- import_effect2.Effect.catchAll(kupmiosError)
830
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
771
831
  );
772
832
  const result = await import_effect2.Effect.runPromise(program);
773
833
  const evalRedeemers = result.map((item) => ({
@@ -784,7 +844,7 @@ var Kupmios = class {
784
844
  var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.gen(function* () {
785
845
  if (datum_type === "inline" && datum_hash) {
786
846
  const pattern = `${kupoUrl}/datums/${datum_hash}`;
787
- const schema = KupoDatumSchema;
847
+ const schema = DatumSchema;
788
848
  return yield* fetchKupoParse(pattern, schema).pipe(
789
849
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
790
850
  import_effect2.Effect.map((result) => result.datum),
@@ -795,7 +855,7 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.
795
855
  var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(function* () {
796
856
  if (script_hash) {
797
857
  const pattern = `${kupoUrl}/scripts/${script_hash}`;
798
- const schema = KupoScriptSchema;
858
+ const schema = ScriptSchema;
799
859
  return yield* (0, import_effect2.pipe)(
800
860
  fetchKupoParse(pattern, schema),
801
861
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
@@ -807,12 +867,17 @@ var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(functi
807
867
  case "plutus:v1":
808
868
  return {
809
869
  type: "PlutusV1",
810
- script: (0, import_utils2.applyDoubleCborEncoding)(script)
870
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
811
871
  };
812
872
  case "plutus:v2":
813
873
  return {
814
874
  type: "PlutusV2",
815
- 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)
816
881
  };
817
882
  }
818
883
  })
@@ -858,6 +923,12 @@ var toProtocolParameters = (result) => {
858
923
  index.toString(),
859
924
  value
860
925
  ])
926
+ ),
927
+ PlutusV3: Object.fromEntries(
928
+ result.plutusCostModels["plutus:v3"].map((value, index) => [
929
+ index.toString(),
930
+ value
931
+ ])
861
932
  )
862
933
  }
863
934
  };
@@ -867,20 +938,22 @@ var fetchOgmiosParse = (url, data, schema) => (0, import_effect2.pipe)(
867
938
  import_platform.HttpClientRequest.jsonBody(data),
868
939
  import_effect2.Effect.flatMap(import_platform.HttpClient.fetch),
869
940
  import_platform.HttpClientResponse.json,
870
- import_effect2.Effect.flatMap(S2.decodeUnknown(schema))
871
- // Effect.catchTag("ParseError", (e) =>
872
- // Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
873
- // ),
941
+ import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
942
+ import_effect2.Effect.catchTag(
943
+ "ParseError",
944
+ (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
945
+ )
874
946
  // Effect.scoped
875
947
  );
876
948
  var fetchKupoParse = (url, schema) => (0, import_effect2.pipe)(
877
949
  import_platform.HttpClientRequest.get(url),
878
950
  import_platform.HttpClient.fetchOk,
879
951
  import_platform.HttpClientResponse.json,
880
- import_effect2.Effect.flatMap(S2.decodeUnknown(schema))
881
- // Effect.catchTag("ParseError", (e) =>
882
- // Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
883
- // ),
952
+ import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
953
+ import_effect2.Effect.catchTag(
954
+ "ParseError",
955
+ (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
956
+ )
884
957
  // Effect.scoped
885
958
  );
886
959
  var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
@@ -908,13 +981,13 @@ var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
908
981
  );
909
982
 
910
983
  // src/emulator.ts
911
- var import_utils3 = require("@lucid-evolution/utils");
912
984
  var import_utils4 = require("@lucid-evolution/utils");
985
+ var import_utils5 = require("@lucid-evolution/utils");
913
986
  var import_core_utils2 = require("@lucid-evolution/core-utils");
914
987
  var import_wallet = require("@lucid-evolution/wallet");
915
988
  var import_cardano_multiplatform_lib_nodejs = require("@anastasia-labs/cardano-multiplatform-lib-nodejs");
916
989
  function generateEmulatorAccount(assets) {
917
- const seedPhrase = (0, import_utils3.generateSeedPhrase)();
990
+ const seedPhrase = (0, import_utils4.generateSeedPhrase)();
918
991
  return {
919
992
  seedPhrase,
920
993
  address: (0, import_wallet.walletFromSeed)(seedPhrase, {
@@ -938,7 +1011,7 @@ var Emulator = class {
938
1011
  time;
939
1012
  protocolParameters;
940
1013
  datumTable = {};
941
- constructor(accounts, protocolParameters = import_utils3.PROTOCOL_PARAMETERS_DEFAULT) {
1014
+ constructor(accounts, protocolParameters = import_utils4.PROTOCOL_PARAMETERS_DEFAULT) {
942
1015
  const GENESIS_HASH = "00".repeat(32);
943
1016
  this.blockHeight = 0;
944
1017
  this.slot = 0;
@@ -1004,7 +1077,7 @@ var Emulator = class {
1004
1077
  if (typeof addressOrCredential === "string") {
1005
1078
  return addressOrCredential === utxo.address ? utxo : [];
1006
1079
  } else {
1007
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1080
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1008
1081
  return paymentCredential?.hash === addressOrCredential.hash ? utxo : [];
1009
1082
  }
1010
1083
  });
@@ -1021,7 +1094,7 @@ var Emulator = class {
1021
1094
  if (typeof addressOrCredential === "string") {
1022
1095
  return addressOrCredential === utxo.address && utxo.assets[unit] > 0n ? utxo : [];
1023
1096
  } else {
1024
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1097
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1025
1098
  return paymentCredential?.hash === addressOrCredential.hash && utxo.assets[unit] > 0n ? utxo : [];
1026
1099
  }
1027
1100
  });
@@ -1254,12 +1327,27 @@ It does not exist or was already spent.`
1254
1327
  3: "Reward"
1255
1328
  };
1256
1329
  const collected = [];
1257
- for (let i = 0; i < (witnesses.redeemers()?.to_js_value().len() || 0); i++) {
1258
- const redeemer = witnesses.redeemers().to_js_value().get(i);
1259
- collected.push({
1260
- tag: tagMap[redeemer.tag().kind()],
1261
- index: parseInt(redeemer.index().to_str())
1262
- });
1330
+ const redeemers2 = witnesses.redeemers();
1331
+ const arrLegacyRedeemer = redeemers2?.as_arr_legacy_redeemer();
1332
+ if (arrLegacyRedeemer) {
1333
+ for (let i = 0; i < (arrLegacyRedeemer.len() || 0); i++) {
1334
+ const redeemer = arrLegacyRedeemer.get(i);
1335
+ collected.push({
1336
+ tag: tagMap[redeemer.tag()],
1337
+ index: Number(redeemer.index())
1338
+ });
1339
+ }
1340
+ }
1341
+ const mapRedeemerKeyToRedeemerVal = redeemers2?.as_map_redeemer_key_to_redeemer_val();
1342
+ if (mapRedeemerKeyToRedeemerVal) {
1343
+ const keys = mapRedeemerKeyToRedeemerVal.keys();
1344
+ for (let i = 0; i < (keys.len() || 0); i++) {
1345
+ const key = keys.get(i);
1346
+ collected.push({
1347
+ tag: tagMap[key.tag()],
1348
+ index: Number(key.index())
1349
+ });
1350
+ }
1263
1351
  }
1264
1352
  return collected;
1265
1353
  })();
@@ -1320,7 +1408,7 @@ It does not exist or was already spent.`
1320
1408
  It does not exist or was already spent.`
1321
1409
  );
1322
1410
  }
1323
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(entry.utxo.address);
1411
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(entry.utxo.address);
1324
1412
  if (paymentCredential?.type === "Script") {
1325
1413
  throw new Error("Collateral inputs can only contain vkeys.");
1326
1414
  }
@@ -1341,7 +1429,7 @@ It does not exist or was already spent.`
1341
1429
  body.withdrawals().get(rawAddress).toString()
1342
1430
  );
1343
1431
  const rewardAddress = rawAddress.to_address().to_bech32(void 0);
1344
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1432
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1345
1433
  checkAndConsumeHash(stakeCredential, "Reward", index);
1346
1434
  if (this.chain[rewardAddress]?.delegation.rewards !== withdrawal) {
1347
1435
  throw new Error(
@@ -1374,7 +1462,7 @@ It does not exist or was already spent.`
1374
1462
  CML.NetworkInfo.testnet().network_id(),
1375
1463
  deregistration.stake_credential()
1376
1464
  ).to_address().to_bech32(void 0);
1377
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1465
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1378
1466
  checkAndConsumeHash(stakeCredential, "Cert", index);
1379
1467
  if (!this.chain[rewardAddress]?.registeredStake) {
1380
1468
  throw new Error(
@@ -1391,7 +1479,7 @@ It does not exist or was already spent.`
1391
1479
  delegation.stake_credential()
1392
1480
  ).to_address().to_bech32(void 0);
1393
1481
  const poolId = delegation.pool().to_bech32("pool");
1394
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1482
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1395
1483
  checkAndConsumeHash(stakeCredential, "Cert", index);
1396
1484
  if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1397
1485
  (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
@@ -1406,7 +1494,7 @@ It does not exist or was already spent.`
1406
1494
  }
1407
1495
  }
1408
1496
  resolvedInputs.forEach(({ entry: { utxo } }, index) => {
1409
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1497
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1410
1498
  checkAndConsumeHash(paymentCredential, "Spend", index);
1411
1499
  });
1412
1500
  const outputs = (() => {
@@ -1420,7 +1508,7 @@ It does not exist or was already spent.`
1420
1508
  ),
1421
1509
  output
1422
1510
  );
1423
- const utxo = (0, import_utils4.coreToUtxo)(unspentOutput);
1511
+ const utxo = (0, import_utils5.coreToUtxo)(unspentOutput);
1424
1512
  if (utxo.datumHash) consumedHashes.add(utxo.datumHash);
1425
1513
  collected.push({
1426
1514
  utxo,
@@ -1629,7 +1717,7 @@ function redeemerTagToString(tag) {
1629
1717
  }
1630
1718
 
1631
1719
  // src/maestro.ts
1632
- var import_utils5 = require("@lucid-evolution/utils");
1720
+ var import_utils6 = require("@lucid-evolution/utils");
1633
1721
  var import_core_utils3 = require("@lucid-evolution/core-utils");
1634
1722
  var Maestro = class {
1635
1723
  url;
@@ -1641,7 +1729,7 @@ var Maestro = class {
1641
1729
  this.turboSubmit = turboSubmit;
1642
1730
  }
1643
1731
  async getProtocolParameters() {
1644
- const timestampedResult = await fetch(`${this.url}/protocol-params`, {
1732
+ const timestampedResult = await fetch(`${this.url}/protocol-parameters`, {
1645
1733
  headers: this.commonHeaders()
1646
1734
  }).then((res) => res.json());
1647
1735
  const result = timestampedResult.data;
@@ -1649,37 +1737,39 @@ var Maestro = class {
1649
1737
  const forwardSlashIndex = str.indexOf("/");
1650
1738
  return parseInt(str.slice(0, forwardSlashIndex)) / parseInt(str.slice(forwardSlashIndex + 1));
1651
1739
  };
1652
- const renameKeysAndSort = (obj, newKeys) => {
1653
- const entries = Object.keys(obj).sort().map((key) => {
1654
- const newKey = newKeys[key] || key;
1655
- return {
1656
- [newKey]: Object.fromEntries(
1657
- Object.entries(obj[key]).sort(
1658
- ([k, _v], [k2, _v2]) => k.localeCompare(k2)
1659
- )
1660
- )
1661
- };
1662
- });
1663
- return Object.assign({}, ...entries);
1664
- };
1665
1740
  return {
1666
1741
  minFeeA: parseInt(result.min_fee_coefficient),
1667
- minFeeB: parseInt(result.min_fee_constant),
1668
- maxTxSize: parseInt(result.max_tx_size),
1669
- maxValSize: parseInt(result.max_value_size),
1670
- keyDeposit: BigInt(result.stake_key_deposit),
1671
- poolDeposit: BigInt(result.pool_deposit),
1672
- priceMem: decimalFromRationalString(result.prices.memory),
1673
- priceStep: decimalFromRationalString(result.prices.steps),
1742
+ minFeeB: parseInt(result.min_fee_constant.ada.lovelace),
1743
+ maxTxSize: parseInt(result.max_transaction_size.bytes),
1744
+ maxValSize: parseInt(result.max_value_size.bytes),
1745
+ keyDeposit: BigInt(result.stake_credential_deposit.ada.lovelace),
1746
+ poolDeposit: BigInt(result.stake_pool_deposit.ada.lovelace),
1747
+ priceMem: decimalFromRationalString(
1748
+ result.script_execution_prices.memory
1749
+ ),
1750
+ priceStep: decimalFromRationalString(result.script_execution_prices.cpu),
1674
1751
  maxTxExMem: BigInt(result.max_execution_units_per_transaction.memory),
1675
- maxTxExSteps: BigInt(result.max_execution_units_per_transaction.steps),
1676
- coinsPerUtxoByte: BigInt(result.coins_per_utxo_byte),
1752
+ maxTxExSteps: BigInt(result.max_execution_units_per_transaction.cpu),
1753
+ coinsPerUtxoByte: BigInt(result.min_utxo_deposit_coefficient),
1677
1754
  collateralPercentage: parseInt(result.collateral_percentage),
1678
1755
  maxCollateralInputs: parseInt(result.max_collateral_inputs),
1679
- costModels: renameKeysAndSort(result.cost_models, {
1680
- "plutus:v1": "PlutusV1",
1681
- "plutus:v2": "PlutusV2"
1682
- })
1756
+ costModels: {
1757
+ PlutusV1: Object.fromEntries(
1758
+ result.plutus_cost_models.plutus_v1.map(
1759
+ (value, index) => [index.toString(), value]
1760
+ )
1761
+ ),
1762
+ PlutusV2: Object.fromEntries(
1763
+ result.plutus_cost_models.plutus_v2.map(
1764
+ (value, index) => [index.toString(), value]
1765
+ )
1766
+ ),
1767
+ PlutusV3: Object.fromEntries(
1768
+ result.plutus_cost_models.plutus_v2.map(
1769
+ (value, index) => [index.toString(), value]
1770
+ )
1771
+ )
1772
+ }
1683
1773
  };
1684
1774
  }
1685
1775
  async getUtxosInternal(addressOrCredential, unit) {
@@ -1862,10 +1952,7 @@ var Maestro = class {
1862
1952
  address: result.address,
1863
1953
  datumHash: result.datum ? result.datum.type == "inline" ? void 0 : result.datum.hash : void 0,
1864
1954
  datum: result.datum?.bytes,
1865
- scriptRef: result.reference_script ? result.reference_script.type == "native" ? void 0 : {
1866
- type: result.reference_script.type == "plutusv1" ? "PlutusV1" : "PlutusV2",
1867
- script: (0, import_utils5.applyDoubleCborEncoding)(result.reference_script.bytes)
1868
- } : void 0
1955
+ scriptRef: toScriptRef(result.reference_script)
1869
1956
  };
1870
1957
  }
1871
1958
  async getAllPagesData(getResponse, qry, paramsGiven, errorMsg) {
@@ -1890,13 +1977,13 @@ var Maestro = class {
1890
1977
  }
1891
1978
  async evaluateTx(tx, additionalUTxOs) {
1892
1979
  const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
1893
- index: utxo.outputIndex,
1894
1980
  tx_hash: utxo.txHash,
1895
- 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()
1896
1983
  }));
1897
1984
  const payload = {
1898
1985
  cbor: tx,
1899
- additionalMaestroUTxOs
1986
+ additional_utxos: additionalMaestroUTxOs
1900
1987
  };
1901
1988
  const res = await fetch(`${this.url}/transactions/evaluate`, {
1902
1989
  method: "POST",
@@ -1916,277 +2003,387 @@ var Maestro = class {
1916
2003
  return result;
1917
2004
  }
1918
2005
  };
2006
+ var toScriptRef = (reference_script) => {
2007
+ if (reference_script && reference_script.bytes) {
2008
+ switch (reference_script.type) {
2009
+ case "plutusv1":
2010
+ return {
2011
+ type: "PlutusV1",
2012
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2013
+ };
2014
+ case "plutusv2":
2015
+ return {
2016
+ type: "PlutusV2",
2017
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2018
+ };
2019
+ case "plutusv3":
2020
+ return {
2021
+ type: "PlutusV3",
2022
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2023
+ };
2024
+ default:
2025
+ return void 0;
2026
+ }
2027
+ }
2028
+ };
1919
2029
  var lucid2 = package_default.version;
1920
2030
 
1921
- // src/koios/koios.ts
1922
- var S4 = __toESM(require("@effect/schema/Schema"), 1);
2031
+ // src/koios.ts
2032
+ var S5 = __toESM(require("@effect/schema/Schema"), 1);
1923
2033
  var import_core_utils4 = require("@lucid-evolution/core-utils");
1924
- var import_utils6 = require("@lucid-evolution/utils");
2034
+ var import_utils8 = require("@lucid-evolution/utils");
1925
2035
 
1926
- // src/koios/schema.ts
1927
- var S3 = __toESM(require("@effect/schema/Schema"), 1);
1928
- var ProtocolParametersSchema2 = S3.Struct({
1929
- epoch_no: S3.Number,
1930
- min_fee_a: S3.Number,
1931
- min_fee_b: S3.Number,
1932
- max_block_size: S3.Number,
1933
- max_tx_size: S3.Number,
1934
- max_bh_size: S3.Number,
1935
- key_deposit: S3.BigInt,
1936
- pool_deposit: S3.BigInt,
1937
- max_epoch: S3.Number,
1938
- optimal_pool_count: S3.Number,
1939
- influence: S3.Number,
1940
- monetary_expand_rate: S3.Number,
1941
- treasury_growth_rate: S3.Number,
1942
- decentralisation: S3.Number,
1943
- extra_entropy: S3.NullOr(S3.String),
1944
- protocol_major: S3.Number,
1945
- protocol_minor: S3.Number,
1946
- min_utxo_value: S3.String,
1947
- min_pool_cost: S3.String,
1948
- nonce: S3.String,
1949
- block_hash: S3.NullOr(S3.String),
1950
- cost_models: S3.Struct({
1951
- PlutusV1: S3.Array(S3.Number),
1952
- PlutusV2: 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)
1953
2089
  }),
1954
- price_mem: S3.Number,
1955
- price_step: S3.Number,
1956
- max_tx_ex_mem: S3.BigIntFromNumber,
1957
- max_tx_ex_steps: S3.BigIntFromNumber,
1958
- max_block_ex_mem: S3.Number,
1959
- max_block_ex_steps: S3.Number,
1960
- max_val_size: S3.Number,
1961
- collateral_percent: S3.Number,
1962
- max_collateral_inputs: S3.Number,
1963
- 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
1964
2100
  });
1965
- var KoiosAssetSchema = S3.Struct({
1966
- policy_id: S3.String,
1967
- asset_name: S3.NullOr(S3.String),
1968
- fingerprint: S3.String,
1969
- decimals: S3.Number,
1970
- 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
1971
2107
  });
1972
- var KoiosUTxOSchema = S3.Struct({
1973
- tx_hash: S3.String,
1974
- tx_index: S3.Number,
1975
- block_height: S3.NullOr(S3.Number),
1976
- value: S3.String,
1977
- datum_hash: S3.NullOr(S3.String),
1978
- inline_datum: S3.NullOr(
1979
- S3.Struct({
1980
- bytes: S3.String,
1981
- value: S3.Object
1982
- })
1983
- ),
1984
- reference_script: S3.NullOr(
1985
- S3.Struct({
1986
- hash: S3.String,
1987
- size: S3.Number,
1988
- type: S3.String,
1989
- bytes: S3.String,
1990
- 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
+ });
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
1991
2126
  })
1992
2127
  ),
1993
- asset_list: S3.NullOr(S3.Array(KoiosAssetSchema))
2128
+ reference_script: S4.NullOr(ReferenceScriptSchema),
2129
+ asset_list: S4.NullOr(S4.Array(AssetSchema))
1994
2130
  });
1995
- var KoiosAddressInfoSchema = S3.Array(
1996
- S3.NullishOr(
1997
- S3.Struct({
1998
- address: S3.String,
1999
- balance: S3.String,
2000
- stake_address: S3.NullOr(S3.String),
2001
- script_address: S3.Boolean,
2002
- 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)
2003
2139
  })
2004
2140
  )
2005
2141
  );
2006
- var KoiosInputOutputSchema = S3.Struct({
2007
- payment_addr: S3.Struct({
2008
- bech32: S3.String,
2009
- cred: S3.String
2142
+ var InputOutputSchema = S4.Struct({
2143
+ payment_addr: S4.Struct({
2144
+ bech32: S4.String,
2145
+ cred: S4.String
2010
2146
  }),
2011
- stake_addr: S3.NullOr(S3.String),
2012
- tx_hash: S3.String,
2013
- tx_index: S3.Number,
2014
- value: S3.String,
2015
- datum_hash: S3.NullOr(S3.String),
2016
- inline_datum: S3.NullOr(
2017
- S3.Struct({
2018
- bytes: S3.String,
2019
- 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
2020
2156
  })
2021
2157
  ),
2022
- reference_script: S3.NullOr(
2023
- S3.Struct({
2024
- hash: S3.String,
2025
- size: S3.Number,
2026
- type: S3.String,
2027
- bytes: S3.String,
2028
- value: S3.NullOr(S3.Object)
2029
- })
2030
- ),
2031
- asset_list: S3.Union(S3.Array(KoiosAssetSchema), S3.String)
2158
+ reference_script: S4.NullOr(ReferenceScriptSchema),
2159
+ asset_list: S4.Array(AssetSchema)
2032
2160
  });
2033
- var KoiosTxInfoSchema = S3.Struct({
2034
- tx_hash: S3.String,
2035
- block_hash: S3.String,
2036
- block_height: S3.Number,
2037
- epoch_no: S3.Number,
2038
- epoch_slot: S3.Number,
2039
- absolute_slot: S3.Number,
2040
- tx_timestamp: S3.Number,
2041
- tx_block_index: S3.Number,
2042
- tx_size: S3.Number,
2043
- total_output: S3.String,
2044
- fee: S3.String,
2045
- deposit: S3.String,
2046
- invalid_before: S3.NullOr(S3.String),
2047
- invalid_after: S3.NullOr(S3.String),
2048
- collateral_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
2049
- collateral_output: S3.NullOr(KoiosInputOutputSchema),
2050
- reference_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
2051
- inputs: S3.Array(KoiosInputOutputSchema),
2052
- outputs: S3.Array(KoiosInputOutputSchema),
2053
- withdrawals: S3.NullOr(
2054
- S3.Array(
2055
- S3.Struct({
2056
- amount: S3.String,
2057
- 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
2058
2187
  })
2059
2188
  )
2060
2189
  ),
2061
- assets_minted: S3.NullOr(S3.Array(KoiosAssetSchema)),
2062
- metadata: S3.NullOr(S3.Object),
2063
- certificates: S3.NullOr(
2064
- S3.Array(
2065
- S3.Struct({
2066
- index: S3.Number,
2067
- type: S3.String,
2068
- 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)
2069
2198
  })
2070
2199
  )
2071
2200
  ),
2072
- native_scripts: S3.NullOr(
2073
- S3.Array(
2074
- S3.Struct({
2075
- script_hash: S3.String,
2076
- 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
2077
2206
  })
2078
2207
  )
2079
2208
  ),
2080
- plutus_contracts: S3.NullOr(
2081
- S3.Array(
2082
- S3.Struct({
2083
- address: S3.String,
2084
- spends_input: S3.NullOr(
2085
- S3.Struct({
2086
- tx_hash: S3.String,
2087
- 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
2088
2217
  })
2089
2218
  ),
2090
- script_hash: S3.String,
2091
- bytecode: S3.String,
2092
- size: S3.Number,
2093
- valid_contract: S3.Boolean,
2094
- input: S3.Struct({
2095
- redeemer: S3.Struct({
2096
- purpose: S3.Literal("spend", "mint", "cert", "reward"),
2097
- fee: S3.String,
2098
- unit: S3.Struct({
2099
- steps: S3.String,
2100
- 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
2101
2230
  }),
2102
- datum: S3.Struct({
2103
- hash: S3.NullOr(S3.String),
2104
- value: S3.NullOr(S3.Object)
2231
+ datum: S4.Struct({
2232
+ hash: S4.NullOr(S4.String),
2233
+ value: S4.NullOr(S4.Object)
2105
2234
  })
2106
2235
  }),
2107
- datum: S3.Struct({
2108
- hash: S3.NullOr(S3.String),
2109
- value: S3.NullOr(S3.Object)
2236
+ datum: S4.Struct({
2237
+ hash: S4.NullOr(S4.String),
2238
+ value: S4.NullOr(S4.Object)
2110
2239
  })
2111
2240
  })
2112
2241
  })
2113
2242
  )
2114
- )
2243
+ ),
2244
+ //TODO: add S.Struct
2245
+ // https://preprod.koios.rest/#post-/tx_info
2246
+ voting_procedures: S4.Array(S4.Object),
2247
+ //TODO: add S.Struct
2248
+ // https://preprod.koios.rest/#post-/tx_info
2249
+ proposal_procedures: S4.Object
2115
2250
  });
2116
-
2117
- // src/koios/koios.ts
2118
- var import_effect4 = require("effect");
2119
- var import_schema2 = require("@effect/schema");
2120
-
2121
- // src/fetch.ts
2122
- var fetch_exports = {};
2123
- __export(fetch_exports, {
2124
- FetchError: () => FetchError,
2125
- JsonError: () => JsonError,
2126
- ResponseError: () => ResponseError,
2127
- 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
2128
2256
  });
2129
- var import_effect3 = require("effect");
2130
- var FetchError = class extends import_effect3.Data.TaggedError("FetchError") {
2131
- };
2132
- 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
+ }
2133
2318
  };
2134
- 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;
2135
2335
  };
2136
- var fetchEffect = (input, requestInit) => (0, import_effect3.pipe)(
2137
- import_effect3.Effect.tryPromise({
2138
- try: () => fetch(input, requestInit),
2139
- catch: (error) => new FetchError({
2140
- message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
2141
- })
2142
- }),
2143
- import_effect3.Effect.flatMap(
2144
- (response) => !response.ok ? new ResponseError({
2145
- message: `${response.status} ${response.statusText}`
2146
- }) : import_effect3.Effect.succeed(response)
2147
- ),
2148
- import_effect3.Effect.flatMap(
2149
- (response) => import_effect3.Effect.tryPromise({
2150
- try: () => response.json(),
2151
- catch: (error) => new JsonError({ message: String(error) })
2152
- })
2153
- )
2154
- );
2155
2336
 
2156
- // 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
+ };
2157
2344
  var Koios = class {
2158
2345
  baseUrl;
2159
2346
  constructor(baseUrl) {
2160
2347
  this.baseUrl = baseUrl;
2161
2348
  }
2162
2349
  async getProtocolParameters() {
2163
- const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
2164
- (res) => res.json()
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 })),
2356
+ import_effect4.Effect.runPromise
2165
2357
  );
2166
- const param = S4.decodeUnknownSync(ProtocolParametersSchema2)(result[0]);
2167
2358
  return {
2168
- minFeeA: param.min_fee_a,
2169
- minFeeB: param.min_fee_b,
2170
- maxTxSize: param.max_tx_size,
2171
- maxValSize: param.max_val_size,
2172
- keyDeposit: param.key_deposit,
2173
- poolDeposit: param.pool_deposit,
2174
- priceMem: param.price_mem,
2175
- priceStep: param.price_step,
2176
- maxTxExMem: param.max_tx_ex_mem,
2177
- maxTxExSteps: param.max_tx_ex_steps,
2178
- coinsPerUtxoByte: param.coins_per_utxo_size,
2179
- collateralPercentage: param.collateral_percent,
2180
- 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,
2181
2372
  costModels: {
2182
2373
  PlutusV1: Object.fromEntries(
2183
- param.cost_models.PlutusV1.map((value, index) => [
2374
+ result.cost_models.PlutusV1.map((value, index) => [
2184
2375
  index.toString(),
2185
2376
  value
2186
2377
  ])
2187
2378
  ),
2188
2379
  PlutusV2: Object.fromEntries(
2189
- param.cost_models.PlutusV2.map((value, index) => [
2380
+ result.cost_models.PlutusV2.map((value, index) => [
2381
+ index.toString(),
2382
+ value
2383
+ ])
2384
+ ),
2385
+ PlutusV3: Object.fromEntries(
2386
+ result.cost_models.PlutusV3.map((value, index) => [
2190
2387
  index.toString(),
2191
2388
  value
2192
2389
  ])
@@ -2195,101 +2392,94 @@ var Koios = class {
2195
2392
  };
2196
2393
  }
2197
2394
  async getUtxos(addressOrCredential) {
2198
- if (typeof addressOrCredential === "string") {
2199
- const body = {
2200
- _addresses: [addressOrCredential]
2201
- };
2202
- const result = await fetch(`${this.baseUrl}/address_info`, {
2203
- headers: {
2204
- Accept: "application/json",
2205
- "Content-Type": "application/json"
2206
- },
2207
- method: "POST",
2208
- body: JSON.stringify(body)
2209
- }).then((res) => res.json());
2210
- const parsedResult = S4.decodeUnknownSync(KoiosAddressInfoSchema)(
2211
- result
2212
- )[0];
2213
- return parsedResult ? parsedResult.utxo_set.map(
2214
- (koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
2215
- ) : [];
2216
- } else {
2217
- throw Error("getUtxos by Credential Type is not supported in Koios yet.");
2218
- }
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;
2219
2402
  }
2220
2403
  async getUtxosWithUnit(addressOrCredential, unit) {
2221
- if (typeof addressOrCredential === "string") {
2222
- const utxos = await this.getUtxos(addressOrCredential);
2223
- if (utxos && utxos.length > 0) {
2224
- 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) => {
2225
2408
  const keys = Object.keys(utxo.assets);
2226
2409
  return keys.length > 0 && keys.includes(unit);
2227
- });
2228
- } else {
2229
- return [];
2230
- }
2231
- } else {
2232
- throw Error(
2233
- "getUtxosWithUnit by Credential Type is not supported in Koios yet."
2234
- );
2235
- }
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;
2236
2417
  }
2237
2418
  async getUtxoByUnit(unit) {
2238
- let { policyId, assetName } = (0, import_utils6.fromUnit)(unit);
2239
- assetName = String(assetName);
2240
- const assetAddresses = await fetch(
2241
- `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`
2242
- ).then((res) => res.json());
2243
- if (Array.isArray(assetAddresses) && assetAddresses.length > 0) {
2244
- if (assetAddresses.length > 1) {
2245
- throw new Error("Unit needs to be an NFT or only held by one address.");
2246
- }
2247
- const utxos = await this.getUtxos(
2248
- assetAddresses[0].payment_address
2249
- );
2250
- const result = utxos.find((utxo) => {
2251
- const keys = Object.keys(utxo.assets);
2252
- return keys.length > 0 && keys.includes(unit);
2253
- });
2254
- if (result) {
2255
- return result;
2256
- }
2257
- }
2258
- 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;
2259
2446
  }
2260
2447
  async getUtxosByOutRef(outRefs) {
2261
- const utxos = [];
2448
+ const url = `${this.baseUrl}/tx_info`;
2262
2449
  const body = {
2263
- _tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))]
2450
+ _tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))],
2451
+ _assets: true,
2452
+ _scripts: true
2264
2453
  };
2265
- const result = await fetch(`${this.baseUrl}/tx_info`, {
2266
- headers: {
2267
- Accept: "application/json",
2268
- "Content-Type": "application/json"
2269
- },
2270
- method: "POST",
2271
- body: JSON.stringify(body)
2272
- }).then((res) => res.json());
2273
- const parsedResult = S4.decodeUnknownSync(S4.Array(KoiosTxInfoSchema))(
2274
- result
2275
- )[0];
2276
- if (parsedResult) {
2277
- return parsedResult.outputs.map(
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 })),
2459
+ import_effect4.Effect.runPromise
2460
+ );
2461
+ if (result) {
2462
+ const utxos = result.outputs.map(
2278
2463
  (koiosInputOutput) => toUTxO(
2279
2464
  {
2280
2465
  tx_hash: koiosInputOutput.tx_hash,
2281
2466
  tx_index: koiosInputOutput.tx_index,
2282
- block_height: null,
2467
+ block_time: 0,
2468
+ block_height: result.block_height,
2283
2469
  value: koiosInputOutput.value,
2284
2470
  datum_hash: koiosInputOutput.datum_hash,
2285
2471
  inline_datum: koiosInputOutput.inline_datum,
2286
2472
  reference_script: koiosInputOutput.reference_script,
2287
- //NOTE: Koios api returns collateral_output like asset_list: "[]", instead of asset_list: []
2288
- asset_list: typeof koiosInputOutput.asset_list === "string" ? [] : koiosInputOutput.asset_list
2473
+ asset_list: koiosInputOutput.asset_list
2289
2474
  },
2290
2475
  koiosInputOutput.payment_addr.bech32
2291
2476
  )
2292
2477
  );
2478
+ return utxos.filter(
2479
+ (utxo) => outRefs.some(
2480
+ (outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
2481
+ )
2482
+ );
2293
2483
  } else {
2294
2484
  return [];
2295
2485
  }
@@ -2298,135 +2488,94 @@ var Koios = class {
2298
2488
  const body = {
2299
2489
  _stake_addresses: [rewardAddress]
2300
2490
  };
2301
- const result = await fetch(`${this.baseUrl}/account_info`, {
2302
- headers: {
2303
- Accept: "application/json",
2304
- "Content-Type": "application/json"
2305
- },
2306
- method: "POST",
2307
- body: JSON.stringify(body)
2308
- }).then((res) => res.json());
2309
- if (Array.isArray(result) && result.length > 0) {
2310
- return {
2311
- poolId: result[0].delegated_pool || null,
2312
- rewards: BigInt(result[0].rewards_available)
2313
- };
2314
- } else {
2315
- throw new Error("No Delegation Found by Reward Address");
2316
- }
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
+ };
2317
2509
  }
2318
2510
  async getDatum(datumHash) {
2511
+ const url = `${this.baseUrl}/datum_info`;
2319
2512
  const body = {
2320
2513
  _datum_hashes: [datumHash]
2321
2514
  };
2322
- const datum = await fetch(`${this.baseUrl}/datum_info`, {
2323
- headers: {
2324
- Accept: "application/json",
2325
- "Content-Type": "application/json"
2326
- },
2327
- method: "POST",
2328
- body: JSON.stringify(body)
2329
- }).then((res) => res.json());
2330
- if (Array.isArray(datum) && datum.length > 0) {
2331
- return datum[0].bytes;
2332
- } else {
2333
- throw new Error("No Datum Found by Datum Hash");
2334
- }
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;
2335
2525
  }
2336
2526
  async awaitTx(txHash, checkInterval = 2e4) {
2527
+ const url = `${this.baseUrl}/tx_info`;
2337
2528
  const body = {
2338
2529
  _tx_hashes: [txHash]
2339
2530
  };
2340
- const request = {
2341
- headers: {
2342
- Accept: "application/json",
2343
- "Content-Type": "application/json"
2344
- },
2345
- method: "POST",
2346
- body: JSON.stringify(body)
2347
- };
2348
- const program = (0, import_effect4.pipe)(
2349
- fetchEffect(`${this.baseUrl}/tx_info`, request),
2350
- import_effect4.Effect.flatMap(
2351
- (json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
2352
- ),
2353
- import_effect4.Effect.catchTag(
2354
- "ParseError",
2355
- (e) => import_effect4.Effect.fail(import_schema2.ArrayFormatter.formatErrorSync(e))
2356
- ),
2531
+ const schema = S5.Array(TxInfoSchema);
2532
+ const result = await (0, import_effect4.pipe)(
2533
+ postWithSchemaValidation(url, body, schema),
2357
2534
  import_effect4.Effect.repeat({
2358
2535
  schedule: import_effect4.Schedule.exponential(checkInterval),
2359
- until: (result) => result.length > 0
2536
+ until: (result2) => result2.length > 0
2360
2537
  }),
2361
2538
  import_effect4.Effect.timeout(16e4),
2362
2539
  import_effect4.Effect.orDie,
2363
- import_effect4.Effect.as(true)
2540
+ import_effect4.Effect.as(true),
2541
+ import_effect4.Effect.runPromise
2364
2542
  );
2365
- return import_effect4.Effect.runPromise(program);
2543
+ return result;
2366
2544
  }
2367
2545
  async submitTx(tx) {
2368
- const result = await fetch(`${this.baseUrl}/submittx`, {
2369
- headers: {
2370
- Accept: "application/json",
2371
- "Content-Type": "application/cbor"
2372
- },
2373
- method: "POST",
2374
- body: (0, import_core_utils4.fromHex)(tx)
2375
- }).then((res) => res.json());
2376
- const TxHashSchema = S4.String;
2377
- const isTxHash = S4.is(TxHashSchema);
2378
- if (!isTxHash(result)) {
2379
- throw new Error(JSON.stringify(result));
2380
- }
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
+ );
2381
2555
  return result;
2382
2556
  }
2383
2557
  async evaluateTx(tx, additionalUTxOs) {
2384
- const utxos = (additionalUTxOs || []).map((utxo) => {
2385
- const script = utxo.scriptRef ? {
2386
- language: utxo.scriptRef.type,
2387
- cbor: utxo.scriptRef.script
2388
- } : void 0;
2389
- return [
2390
- {
2391
- transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
2392
- },
2393
- {
2394
- address: utxo.address,
2395
- value: {
2396
- coins: utxo.assets.lovelace,
2397
- assets: utxo.assets.restAssets
2398
- },
2399
- datumHash: utxo.datumHash,
2400
- datum: utxo.datum,
2401
- script
2402
- }
2403
- ];
2404
- });
2405
- const data = {
2558
+ const url = `${this.baseUrl}/ogmios`;
2559
+ const body = {
2406
2560
  jsonrpc: "2.0",
2407
2561
  method: "evaluateTransaction",
2408
- params: { transaction: { cbor: tx }, additionalUTxO: utxos },
2562
+ params: {
2563
+ transaction: { cbor: tx },
2564
+ additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
2565
+ },
2409
2566
  id: null
2410
2567
  };
2411
- const response = await fetch(`${this.baseUrl}/ogmios`, {
2412
- headers: {
2413
- Accept: "application/json",
2414
- "Content-Type": "application/json"
2415
- },
2416
- method: "POST",
2417
- body: JSON.stringify(
2418
- data,
2419
- (_, value) => typeof value === "bigint" ? value.toString() : value
2420
- )
2421
- });
2422
- if (!response.ok) {
2423
- const errorBody = await response.text();
2424
- throw new Error(
2425
- `Request failed with status ${response.status}: ${errorBody}`
2426
- );
2427
- }
2428
- const result = await response.json();
2429
- 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) => ({
2430
2579
  ex_units: {
2431
2580
  mem: item.budget.memory,
2432
2581
  steps: item.budget.cpu
@@ -2437,39 +2586,14 @@ var Koios = class {
2437
2586
  return evalRedeemers;
2438
2587
  }
2439
2588
  };
2440
- var toUTxO = (koiosUTxO, address) => ({
2441
- txHash: koiosUTxO.tx_hash,
2442
- outputIndex: koiosUTxO.tx_index,
2443
- assets: (() => {
2444
- const a = {};
2445
- if (koiosUTxO.asset_list) {
2446
- koiosUTxO.asset_list.forEach((am) => {
2447
- a[am.policy_id + am.asset_name] = BigInt(am.quantity);
2448
- });
2449
- }
2450
- a["lovelace"] = BigInt(koiosUTxO.value);
2451
- return a;
2452
- })(),
2453
- address,
2454
- datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash,
2455
- datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
2456
- scriptRef: koiosUTxO.reference_script ? koiosUTxO.reference_script.type == "plutusV1" ? {
2457
- type: "PlutusV1",
2458
- script: (0, import_utils6.applyDoubleCborEncoding)(koiosUTxO.reference_script.bytes)
2459
- } : {
2460
- type: "PlutusV2",
2461
- script: (0, import_utils6.applyDoubleCborEncoding)(koiosUTxO.reference_script.bytes)
2462
- } : void 0
2463
- });
2464
2589
  // Annotate the CommonJS export names for ESM import in node:
2465
2590
  0 && (module.exports = {
2466
2591
  Blockfrost,
2467
2592
  Emulator,
2468
- FetchProvider,
2469
2593
  Koios,
2594
+ KoiosError,
2470
2595
  Kupmios,
2471
2596
  KupmiosError,
2472
2597
  Maestro,
2473
- datumJsonToCbor,
2474
2598
  generateEmulatorAccount
2475
2599
  });