@lucid-evolution/provider 0.1.81 → 0.1.83

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
@@ -52,7 +52,7 @@ var import_utils2 = require("@lucid-evolution/utils");
52
52
  // package.json
53
53
  var package_default = {
54
54
  name: "@lucid-evolution/provider",
55
- version: "0.1.81",
55
+ version: "0.1.83",
56
56
  description: "",
57
57
  main: "./dist/index.js",
58
58
  types: "./dist/index.d.ts",
@@ -84,13 +84,13 @@ var package_default = {
84
84
  dependencies: {
85
85
  "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-3",
86
86
  "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-3",
87
- "@effect/platform": "^0.59.2",
87
+ "@effect/platform": "^0.71.3",
88
88
  "@effect/schema": "^0.68.26",
89
89
  "@lucid-evolution/core-types": "workspace:*",
90
90
  "@lucid-evolution/core-utils": "workspace:*",
91
91
  "@lucid-evolution/utils": "workspace:*",
92
92
  "@lucid-evolution/wallet": "workspace:*",
93
- effect: "^3.10.4"
93
+ effect: "^3.11.7"
94
94
  },
95
95
  devDependencies: {
96
96
  "@types/node": "^20.12.8",
@@ -452,59 +452,55 @@ var lucid = package_default.version;
452
452
 
453
453
  // src/kupmios.ts
454
454
  var import_utils4 = require("@lucid-evolution/utils");
455
- var S3 = __toESM(require("@effect/schema/Schema"), 1);
456
- var import_effect2 = require("effect");
457
- var import_platform = require("@effect/platform");
458
- var import_schema = require("@effect/schema");
455
+ var import_effect5 = require("effect");
456
+ var import_effect6 = require("effect");
459
457
 
460
458
  // src/internal/ogmios.ts
461
- var S = __toESM(require("@effect/schema/Schema"), 1);
459
+ var import_effect2 = require("effect");
462
460
  var import_utils3 = require("@lucid-evolution/utils");
463
- var JSONRPCSchema = (schema) => S.extend(
464
- S.Struct({
465
- jsonrpc: S.String,
466
- method: S.optional(S.String),
467
- id: S.NullOr(S.Number)
468
- }),
469
- S.Union(S.Struct({ result: schema }), S.Struct({ error: S.Object }))
470
- );
471
- var LovelaceAsset = S.Struct({
472
- lovelace: S.Number
461
+ var JSONRPCSchema = (schema) => import_effect2.Schema.Struct({
462
+ jsonrpc: import_effect2.Schema.String,
463
+ method: import_effect2.Schema.optional(import_effect2.Schema.String),
464
+ id: import_effect2.Schema.NullOr(import_effect2.Schema.Number),
465
+ result: schema
466
+ }).annotations({ identifier: "JSONRPCSchema" });
467
+ var LovelaceAsset = import_effect2.Schema.Struct({
468
+ lovelace: import_effect2.Schema.Number
473
469
  });
474
- var TupleNumberFromString = S.compose(
475
- S.split("/"),
476
- S.Array(S.NumberFromString)
470
+ var TupleNumberFromString = import_effect2.Schema.compose(
471
+ import_effect2.Schema.split("/"),
472
+ import_effect2.Schema.Array(import_effect2.Schema.NumberFromString)
477
473
  );
478
- var ProtocolParametersSchema = S.Struct({
479
- minFeeCoefficient: S.Number,
480
- minFeeReferenceScripts: S.Struct({
481
- base: S.Number,
482
- range: S.Number,
483
- multiplier: S.Number
474
+ var ProtocolParametersSchema = import_effect2.Schema.Struct({
475
+ minFeeCoefficient: import_effect2.Schema.Number,
476
+ minFeeReferenceScripts: import_effect2.Schema.Struct({
477
+ base: import_effect2.Schema.Number,
478
+ range: import_effect2.Schema.Number,
479
+ multiplier: import_effect2.Schema.Number
484
480
  }),
485
- maxReferenceScriptsSize: S.Struct({
486
- bytes: S.Number
481
+ maxReferenceScriptsSize: import_effect2.Schema.Struct({
482
+ bytes: import_effect2.Schema.Number
487
483
  }),
488
- stakePoolVotingThresholds: S.Struct({
484
+ stakePoolVotingThresholds: import_effect2.Schema.Struct({
489
485
  noConfidence: TupleNumberFromString,
490
- constitutionalCommittee: S.Struct({
486
+ constitutionalCommittee: import_effect2.Schema.Struct({
491
487
  default: TupleNumberFromString,
492
488
  stateOfNoConfidence: TupleNumberFromString
493
489
  }),
494
490
  hardForkInitiation: TupleNumberFromString,
495
- protocolParametersUpdate: S.Struct({
491
+ protocolParametersUpdate: import_effect2.Schema.Struct({
496
492
  security: TupleNumberFromString
497
493
  })
498
494
  }),
499
- delegateRepresentativeVotingThresholds: S.Struct({
495
+ delegateRepresentativeVotingThresholds: import_effect2.Schema.Struct({
500
496
  noConfidence: TupleNumberFromString,
501
- constitutionalCommittee: S.Struct({
497
+ constitutionalCommittee: import_effect2.Schema.Struct({
502
498
  default: TupleNumberFromString,
503
499
  stateOfNoConfidence: TupleNumberFromString
504
500
  }),
505
501
  constitution: TupleNumberFromString,
506
502
  hardForkInitiation: TupleNumberFromString,
507
- protocolParametersUpdate: S.Struct({
503
+ protocolParametersUpdate: import_effect2.Schema.Struct({
508
504
  network: TupleNumberFromString,
509
505
  economic: TupleNumberFromString,
510
506
  technical: TupleNumberFromString,
@@ -512,62 +508,62 @@ var ProtocolParametersSchema = S.Struct({
512
508
  }),
513
509
  treasuryWithdrawals: TupleNumberFromString
514
510
  }),
515
- constitutionalCommitteeMinSize: S.optional(S.Number),
516
- constitutionalCommitteeMaxTermLength: S.Number,
517
- governanceActionLifetime: S.Number,
518
- governanceActionDeposit: S.Struct({
511
+ constitutionalCommitteeMinSize: import_effect2.Schema.optional(import_effect2.Schema.Number),
512
+ constitutionalCommitteeMaxTermLength: import_effect2.Schema.Number,
513
+ governanceActionLifetime: import_effect2.Schema.Number,
514
+ governanceActionDeposit: import_effect2.Schema.Struct({
519
515
  ada: LovelaceAsset
520
516
  }),
521
- delegateRepresentativeDeposit: S.Struct({
517
+ delegateRepresentativeDeposit: import_effect2.Schema.Struct({
522
518
  ada: LovelaceAsset
523
519
  }),
524
- delegateRepresentativeMaxIdleTime: S.Number,
525
- minFeeConstant: S.Struct({ ada: LovelaceAsset }),
526
- maxBlockBodySize: S.Struct({ bytes: S.Number }),
527
- maxBlockHeaderSize: S.Struct({ bytes: S.Number }),
528
- maxTransactionSize: S.Struct({ bytes: S.Number }),
529
- stakeCredentialDeposit: S.Struct({ ada: LovelaceAsset }),
530
- stakePoolDeposit: S.Struct({ ada: LovelaceAsset }),
531
- stakePoolRetirementEpochBound: S.Number,
532
- desiredNumberOfStakePools: S.Number,
520
+ delegateRepresentativeMaxIdleTime: import_effect2.Schema.Number,
521
+ minFeeConstant: import_effect2.Schema.Struct({ ada: LovelaceAsset }),
522
+ maxBlockBodySize: import_effect2.Schema.Struct({ bytes: import_effect2.Schema.Number }),
523
+ maxBlockHeaderSize: import_effect2.Schema.Struct({ bytes: import_effect2.Schema.Number }),
524
+ maxTransactionSize: import_effect2.Schema.Struct({ bytes: import_effect2.Schema.Number }),
525
+ stakeCredentialDeposit: import_effect2.Schema.Struct({ ada: LovelaceAsset }),
526
+ stakePoolDeposit: import_effect2.Schema.Struct({ ada: LovelaceAsset }),
527
+ stakePoolRetirementEpochBound: import_effect2.Schema.Number,
528
+ desiredNumberOfStakePools: import_effect2.Schema.Number,
533
529
  stakePoolPledgeInfluence: TupleNumberFromString,
534
530
  monetaryExpansion: TupleNumberFromString,
535
531
  treasuryExpansion: TupleNumberFromString,
536
- minStakePoolCost: S.Struct({ ada: LovelaceAsset }),
537
- minUtxoDepositConstant: S.Struct({ ada: LovelaceAsset }),
538
- minUtxoDepositCoefficient: S.Number,
539
- plutusCostModels: S.Struct({
540
- "plutus:v1": S.Array(S.Number),
541
- "plutus:v2": S.Array(S.Number),
542
- "plutus:v3": S.Array(S.Number)
532
+ minStakePoolCost: import_effect2.Schema.Struct({ ada: LovelaceAsset }),
533
+ minUtxoDepositConstant: import_effect2.Schema.Struct({ ada: LovelaceAsset }),
534
+ minUtxoDepositCoefficient: import_effect2.Schema.Number,
535
+ plutusCostModels: import_effect2.Schema.Struct({
536
+ "plutus:v1": import_effect2.Schema.Array(import_effect2.Schema.Number),
537
+ "plutus:v2": import_effect2.Schema.Array(import_effect2.Schema.Number),
538
+ "plutus:v3": import_effect2.Schema.Array(import_effect2.Schema.Number)
543
539
  }),
544
- scriptExecutionPrices: S.Struct({
540
+ scriptExecutionPrices: import_effect2.Schema.Struct({
545
541
  memory: TupleNumberFromString,
546
542
  cpu: TupleNumberFromString
547
543
  }),
548
- maxExecutionUnitsPerTransaction: S.Struct({
549
- memory: S.Number,
550
- cpu: S.Number
544
+ maxExecutionUnitsPerTransaction: import_effect2.Schema.Struct({
545
+ memory: import_effect2.Schema.Number,
546
+ cpu: import_effect2.Schema.Number
551
547
  }),
552
- maxExecutionUnitsPerBlock: S.Struct({ memory: S.Number, cpu: S.Number }),
553
- maxValueSize: S.Struct({ bytes: S.Number }),
554
- collateralPercentage: S.Number,
555
- maxCollateralInputs: S.Number,
556
- version: S.Struct({ major: S.Number, minor: S.Number })
557
- });
558
- var Delegation = S.NullOr(
559
- S.Record(
560
- S.String,
561
- S.Struct({
562
- delegate: S.Struct({ id: S.String }),
563
- rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
564
- deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
548
+ maxExecutionUnitsPerBlock: import_effect2.Schema.Struct({ memory: import_effect2.Schema.Number, cpu: import_effect2.Schema.Number }),
549
+ maxValueSize: import_effect2.Schema.Struct({ bytes: import_effect2.Schema.Number }),
550
+ collateralPercentage: import_effect2.Schema.Number,
551
+ maxCollateralInputs: import_effect2.Schema.Number,
552
+ version: import_effect2.Schema.Struct({ major: import_effect2.Schema.Number, minor: import_effect2.Schema.Number })
553
+ }).annotations({ identifier: "ProtocolParametersSchema" });
554
+ var Delegation = import_effect2.Schema.NullOr(
555
+ import_effect2.Schema.Record({
556
+ key: import_effect2.Schema.String,
557
+ value: import_effect2.Schema.Struct({
558
+ delegate: import_effect2.Schema.Struct({ id: import_effect2.Schema.String }),
559
+ rewards: import_effect2.Schema.Struct({ ada: import_effect2.Schema.Struct({ lovelace: import_effect2.Schema.Number }) }),
560
+ deposit: import_effect2.Schema.Struct({ ada: import_effect2.Schema.Struct({ lovelace: import_effect2.Schema.Number }) })
565
561
  })
566
- )
562
+ })
567
563
  );
568
- var RedeemerSchema = S.Struct({
569
- validator: S.Struct({
570
- purpose: S.Literal(
564
+ var RedeemerSchema = import_effect2.Schema.Struct({
565
+ validator: import_effect2.Schema.Struct({
566
+ purpose: import_effect2.Schema.Literal(
571
567
  "spend",
572
568
  "mint",
573
569
  "publish",
@@ -575,13 +571,13 @@ var RedeemerSchema = S.Struct({
575
571
  "vote",
576
572
  "propose"
577
573
  ),
578
- index: S.Int
574
+ index: import_effect2.Schema.Int
579
575
  }),
580
- budget: S.Struct({
581
- memory: S.Int,
582
- cpu: S.Int
576
+ budget: import_effect2.Schema.Struct({
577
+ memory: import_effect2.Schema.Int,
578
+ cpu: import_effect2.Schema.Int
583
579
  })
584
- });
580
+ }).annotations({ identifier: "RedeemerSchema" });
585
581
  var toOgmiosUTxOs = (utxos) => {
586
582
  const toOgmiosScript = (scriptRef) => {
587
583
  if (scriptRef) {
@@ -637,65 +633,132 @@ var toOgmiosUTxOs = (utxos) => {
637
633
  };
638
634
 
639
635
  // src/internal/kupo.ts
640
- var S2 = __toESM(require("@effect/schema/Schema"), 1);
641
- var ValueSchema = S2.Struct({
642
- coins: S2.Number,
643
- assets: S2.Record(S2.String, S2.Number)
636
+ var import_effect3 = require("effect");
637
+ var ValueSchema = import_effect3.Schema.Struct({
638
+ coins: import_effect3.Schema.Number,
639
+ assets: import_effect3.Schema.Record({ key: import_effect3.Schema.String, value: import_effect3.Schema.Number })
644
640
  });
645
- var UTxOSchema = S2.Struct({
646
- transaction_index: S2.Number,
647
- transaction_id: S2.String,
648
- output_index: S2.Number,
649
- address: S2.String,
641
+ var UTxOSchema = import_effect3.Schema.Struct({
642
+ transaction_index: import_effect3.Schema.Number,
643
+ transaction_id: import_effect3.Schema.String,
644
+ output_index: import_effect3.Schema.Number,
645
+ address: import_effect3.Schema.String,
650
646
  value: ValueSchema,
651
- datum_hash: S2.NullOr(S2.String),
652
- datum_type: S2.optional(S2.Literal("hash", "inline")),
653
- script_hash: S2.NullOr(S2.String),
654
- created_at: S2.Struct({
655
- slot_no: S2.Number,
656
- header_hash: S2.String
647
+ datum_hash: import_effect3.Schema.NullOr(import_effect3.Schema.String),
648
+ datum_type: import_effect3.Schema.optional(import_effect3.Schema.Literal("hash", "inline")),
649
+ script_hash: import_effect3.Schema.NullOr(import_effect3.Schema.String),
650
+ created_at: import_effect3.Schema.Struct({
651
+ slot_no: import_effect3.Schema.Number,
652
+ header_hash: import_effect3.Schema.String
657
653
  }),
658
- spent_at: S2.NullOr(
659
- S2.Struct({
660
- slot_no: S2.Number,
661
- header_hash: S2.String
654
+ spent_at: import_effect3.Schema.NullOr(
655
+ import_effect3.Schema.Struct({
656
+ slot_no: import_effect3.Schema.Number,
657
+ header_hash: import_effect3.Schema.String
662
658
  })
663
659
  )
664
660
  });
665
- var ScriptSchema = S2.NullOr(
666
- S2.Struct({
667
- language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
668
- script: S2.String
661
+ var ScriptSchema = import_effect3.Schema.NullOr(
662
+ import_effect3.Schema.Struct({
663
+ language: import_effect3.Schema.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
664
+ script: import_effect3.Schema.String
669
665
  })
670
666
  );
671
- var DatumSchema = S2.NullOr(S2.Struct({ datum: S2.String }));
672
- var DelegationSchema = S2.NullOr(
673
- S2.Record(
674
- S2.String,
675
- S2.Struct({
676
- delegate: S2.Struct({ id: S2.String }),
677
- rewards: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) }),
678
- deposit: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) })
667
+ var DatumSchema = import_effect3.Schema.NullOr(import_effect3.Schema.Struct({ datum: import_effect3.Schema.String }));
668
+ var DelegationSchema = import_effect3.Schema.NullOr(
669
+ import_effect3.Schema.Record({
670
+ key: import_effect3.Schema.String,
671
+ value: import_effect3.Schema.Struct({
672
+ delegate: import_effect3.Schema.Struct({ id: import_effect3.Schema.String }),
673
+ rewards: import_effect3.Schema.Struct({ ada: import_effect3.Schema.Struct({ lovelace: import_effect3.Schema.Number }) }),
674
+ deposit: import_effect3.Schema.Struct({ ada: import_effect3.Schema.Struct({ lovelace: import_effect3.Schema.Number }) })
679
675
  })
676
+ })
677
+ );
678
+
679
+ // src/internal/HttpUtils.ts
680
+ var import_platform = require("@effect/platform");
681
+ var import_effect4 = require("effect");
682
+ var filterStatusOk = (self) => self.status >= 200 && self.status < 300 ? import_effect4.Effect.succeed(self) : self.text.pipe(
683
+ import_effect4.Effect.flatMap(
684
+ (text) => import_effect4.Effect.fail(
685
+ new import_platform.HttpClientError.ResponseError({
686
+ response: self,
687
+ request: self.request,
688
+ reason: "StatusCode",
689
+ description: `non 2xx status code : ${text}`
690
+ })
691
+ )
680
692
  )
681
693
  );
694
+ var makeGet = (url, schema, headers) => (0, import_effect4.pipe)(
695
+ // Initiate a GET request to the specified URL
696
+ import_platform.HttpClientRequest.get(url),
697
+ // Conditional bearer token authentication
698
+ headers ? import_platform.HttpClientRequest.setHeaders(headers) : import_effect4.identity,
699
+ // Execute the HTTP request and retrieve the response
700
+ import_platform.HttpClient.execute,
701
+ // Ensure only 2xx responses are treated as successes.
702
+ import_effect4.Effect.flatMap(filterStatusOk),
703
+ // Parse the response body using the provided JSON schema
704
+ // This validates and transforms the response to the expected type
705
+ import_effect4.Effect.flatMap(import_platform.HttpClientResponse.schemaBodyJson(schema)),
706
+ // Ensure request is aborted if the program is interrupted
707
+ // Prevents resource leaks and ensures clean request termination
708
+ import_effect4.Effect.scoped
709
+ );
710
+ var makePostAsJson = (url, data, schema, headers) => (0, import_effect4.pipe)(
711
+ // Initiate a POST request to the specified URL
712
+ import_platform.HttpClientRequest.post(url),
713
+ // Conditional headers
714
+ headers ? import_platform.HttpClientRequest.setHeaders(headers) : import_effect4.identity,
715
+ // Set the request body as Json
716
+ import_platform.HttpClientRequest.bodyJson(data),
717
+ // Execute the HTTP request and retrieve the response
718
+ import_effect4.Effect.flatMap(import_platform.HttpClient.execute),
719
+ // Ensure only 2xx responses are treated as successes.
720
+ import_effect4.Effect.flatMap(filterStatusOk),
721
+ // Parse the response body using the provided JSON schema
722
+ // This validates and transforms the response to the expected type
723
+ import_effect4.Effect.flatMap(import_platform.HttpClientResponse.schemaBodyJson(schema)),
724
+ // Ensure request is aborted if the program is interrupted
725
+ // Prevents resource leaks and ensures clean request termination
726
+ import_effect4.Effect.scoped
727
+ );
728
+ var makePostAsUint8Array = (url, data, schema, headers) => (0, import_effect4.pipe)(
729
+ // Initiate a POST request to the specified URL
730
+ import_platform.HttpClientRequest.post(url),
731
+ // Conditional bearer token authentication
732
+ headers ? import_platform.HttpClientRequest.setHeaders(headers) : import_effect4.identity,
733
+ // Set the request body as a Uint8Array with CBOR content type
734
+ import_platform.HttpClientRequest.bodyUint8Array(data, "application/cbor"),
735
+ // Execute the HTTP request and retrieve the response
736
+ import_platform.HttpClient.execute,
737
+ // Ensure only 2xx responses are treated as successes.
738
+ import_effect4.Effect.flatMap(filterStatusOk),
739
+ // Parse the response body using the provided JSON schema
740
+ // This validates and transforms the response to the expected type
741
+ import_effect4.Effect.flatMap(import_platform.HttpClientResponse.schemaBodyJson(schema)),
742
+ // Ensure request is aborted if the program is interrupted
743
+ // Prevents resource leaks and ensures clean request termination
744
+ import_effect4.Effect.scoped
745
+ );
682
746
 
683
747
  // src/kupmios.ts
684
- var KupmiosError = class extends import_effect2.Data.TaggedError("KupmiosError") {
748
+ var import_platform2 = require("@effect/platform");
749
+ var KupmiosError = class extends import_effect6.Data.TaggedError("KupmiosError") {
685
750
  get message() {
686
- return `${JSON.stringify(this.cause)}`;
751
+ return `${this.cause}`;
687
752
  }
688
753
  };
689
754
  var Kupmios = class {
690
755
  kupoUrl;
691
756
  ogmiosUrl;
692
- /**
693
- * @param kupoUrl: http(s)://localhost:1442
694
- * @param ogmiosUrl: http(s)://localhost:1337
695
- */
696
- constructor(kupoUrl, ogmiosUrl) {
757
+ headers;
758
+ constructor(kupoUrl, ogmiosUrl, headers) {
697
759
  this.kupoUrl = kupoUrl;
698
760
  this.ogmiosUrl = ogmiosUrl;
761
+ this.headers = headers;
699
762
  }
700
763
  async getProtocolParameters() {
701
764
  const data = {
@@ -705,27 +768,33 @@ var Kupmios = class {
705
768
  id: null
706
769
  };
707
770
  const schema = JSONRPCSchema(ProtocolParametersSchema);
708
- const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
709
- import_effect2.Effect.flatMap(
710
- (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
771
+ const { result } = await (0, import_effect6.pipe)(
772
+ makePostAsJson(
773
+ this.ogmiosUrl,
774
+ data,
775
+ schema,
776
+ this.headers?.ogmiosHeader
711
777
  ),
712
- import_effect2.Effect.timeout(1e4),
713
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
778
+ import_effect6.Effect.timeout(1e4),
779
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
780
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
781
+ import_effect6.Effect.runPromise
714
782
  );
715
- const result = await import_effect2.Effect.runPromise(program);
716
783
  return toProtocolParameters(result);
717
784
  }
718
785
  async getUtxos(addressOrCredential) {
719
786
  const isAddress = typeof addressOrCredential === "string";
720
787
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
721
788
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
722
- const schema = S3.Array(UTxOSchema);
723
- const program = fetchKupoParse(pattern, schema).pipe(
724
- import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
725
- import_effect2.Effect.timeout(1e4),
726
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
789
+ const schema = import_effect5.Schema.Array(UTxOSchema);
790
+ const utxos = await (0, import_effect6.pipe)(
791
+ makeGet(pattern, schema, this.headers?.kupoHeader),
792
+ import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
793
+ import_effect6.Effect.timeout(1e4),
794
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
795
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
796
+ import_effect6.Effect.runPromise
727
797
  );
728
- const utxos = await import_effect2.Effect.runPromise(program);
729
798
  return utxos;
730
799
  }
731
800
  async getUtxosWithUnit(addressOrCredential, unit) {
@@ -733,25 +802,29 @@ var Kupmios = class {
733
802
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
734
803
  const { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
735
804
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
736
- const schema = S3.Array(UTxOSchema);
737
- const program = fetchKupoParse(pattern, schema).pipe(
738
- import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
739
- import_effect2.Effect.timeout(1e4),
740
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
805
+ const schema = import_effect5.Schema.Array(UTxOSchema);
806
+ const utxos = await (0, import_effect6.pipe)(
807
+ makeGet(pattern, schema, this.headers?.kupoHeader),
808
+ import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
809
+ import_effect6.Effect.timeout(1e4),
810
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
811
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
812
+ import_effect6.Effect.runPromise
741
813
  );
742
- const utxos = await import_effect2.Effect.runPromise(program);
743
814
  return utxos;
744
815
  }
745
816
  async getUtxoByUnit(unit) {
746
817
  const { policyId, assetName } = (0, import_utils4.fromUnit)(unit);
747
818
  const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
748
- const schema = S3.Array(UTxOSchema);
749
- const program = fetchKupoParse(pattern, schema).pipe(
750
- import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
751
- import_effect2.Effect.timeout(1e4),
752
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
819
+ const schema = import_effect5.Schema.Array(UTxOSchema);
820
+ const utxos = await (0, import_effect6.pipe)(
821
+ makeGet(pattern, schema, this.headers?.kupoHeader),
822
+ import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
823
+ import_effect6.Effect.timeout(1e4),
824
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
825
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
826
+ import_effect6.Effect.runPromise
753
827
  );
754
- const utxos = await import_effect2.Effect.runPromise(program);
755
828
  if (utxos.length > 1) {
756
829
  throw new Error("Unit needs to be an NFT or only held by one address.");
757
830
  }
@@ -762,17 +835,20 @@ var Kupmios = class {
762
835
  ...new Set(outRefs.map((outRef) => outRef.txHash))
763
836
  ];
764
837
  const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
765
- const schema = S3.Array(UTxOSchema);
766
- const program = import_effect2.Effect.forEach(
838
+ const schema = import_effect5.Schema.Array(UTxOSchema);
839
+ const program = import_effect6.Effect.forEach(
767
840
  queryHashes,
768
- (txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
769
- import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
770
- import_effect2.Effect.timeout(1e4),
771
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
841
+ (txHash) => (0, import_effect6.pipe)(
842
+ makeGet(mkPattern(txHash), schema, this.headers?.kupoHeader),
843
+ import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
844
+ import_effect6.Effect.timeout(1e4),
845
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause }))
772
846
  )
773
847
  );
774
- const utxos = await import_effect2.Effect.runPromise(program);
775
- return import_effect2.Array.flatten(utxos).filter(
848
+ const utxos = await import_effect6.Effect.runPromise(
849
+ (0, import_effect6.pipe)(program, import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer))
850
+ );
851
+ return import_effect6.Array.flatten(utxos).filter(
776
852
  (utxo) => outRefs.some(
777
853
  (outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
778
854
  )
@@ -786,14 +862,18 @@ var Kupmios = class {
786
862
  id: null
787
863
  };
788
864
  const schema = JSONRPCSchema(Delegation);
789
- const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
790
- import_effect2.Effect.flatMap(
791
- (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
865
+ const { result } = await (0, import_effect6.pipe)(
866
+ makePostAsJson(
867
+ this.ogmiosUrl,
868
+ data,
869
+ schema,
870
+ this.headers?.ogmiosHeader
792
871
  ),
793
- import_effect2.Effect.timeout(1e4),
794
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
872
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
873
+ import_effect6.Effect.timeout(1e4),
874
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
875
+ import_effect6.Effect.runPromise
795
876
  );
796
- const result = await import_effect2.Effect.runPromise(program);
797
877
  const delegation = result ? Object.values(result)[0] : null;
798
878
  return {
799
879
  poolId: delegation?.delegate?.id || null,
@@ -803,29 +883,34 @@ var Kupmios = class {
803
883
  async getDatum(datumHash) {
804
884
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
805
885
  const schema = DatumSchema;
806
- const program = fetchKupoParse(pattern, schema).pipe(
807
- import_effect2.Effect.timeout(1e4),
808
- import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
809
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
886
+ const result = await (0, import_effect6.pipe)(
887
+ makeGet(pattern, schema, this.headers?.kupoHeader),
888
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
889
+ import_effect6.Effect.timeout(1e4),
890
+ import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
891
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
892
+ import_effect6.Effect.runPromise
810
893
  );
811
- const result = await import_effect2.Effect.runPromise(program);
812
894
  return result.datum;
813
895
  }
814
896
  async awaitTx(txHash, checkInterval = 2e4) {
815
897
  const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
816
- const schema = S3.Array(UTxOSchema).annotations({
898
+ const schema = import_effect5.Schema.Array(UTxOSchema).annotations({
817
899
  identifier: "Array<KupmiosSchema.KupoUTxO>"
818
900
  });
819
- const program = fetchKupoParse(pattern, schema).pipe(
820
- import_effect2.Effect.repeat({
821
- schedule: import_effect2.Schedule.exponential(checkInterval),
822
- until: (result) => result.length > 0
901
+ const result = await (0, import_effect6.pipe)(
902
+ makeGet(pattern, schema, this.headers?.kupoHeader),
903
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
904
+ import_effect6.Effect.repeat({
905
+ schedule: import_effect6.Schedule.exponential(checkInterval),
906
+ until: (result2) => result2.length > 0
823
907
  }),
824
- import_effect2.Effect.timeout(16e4),
825
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause })),
826
- import_effect2.Effect.as(true)
908
+ import_effect6.Effect.timeout(16e4),
909
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
910
+ import_effect6.Effect.as(true),
911
+ import_effect6.Effect.runPromise
827
912
  );
828
- return await import_effect2.Effect.runPromise(program);
913
+ return result;
829
914
  }
830
915
  async submitTx(cbor) {
831
916
  const data = {
@@ -837,20 +922,24 @@ var Kupmios = class {
837
922
  id: null
838
923
  };
839
924
  const schema = JSONRPCSchema(
840
- S3.Struct({
841
- transaction: S3.Struct({
842
- id: S3.String
925
+ import_effect5.Schema.Struct({
926
+ transaction: import_effect5.Schema.Struct({
927
+ id: import_effect5.Schema.String
843
928
  })
844
929
  })
845
930
  );
846
- const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
847
- import_effect2.Effect.flatMap(
848
- (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response)
931
+ const { result } = await (0, import_effect6.pipe)(
932
+ makePostAsJson(
933
+ this.ogmiosUrl,
934
+ data,
935
+ schema,
936
+ this.headers?.ogmiosHeader
849
937
  ),
850
- import_effect2.Effect.timeout(1e4),
851
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
938
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
939
+ import_effect6.Effect.timeout(1e4),
940
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
941
+ import_effect6.Effect.runPromise
852
942
  );
853
- const { result } = await import_effect2.Effect.runPromise(program);
854
943
  return result.transaction.id;
855
944
  }
856
945
  async evaluateTx(tx, additionalUTxOs) {
@@ -863,15 +952,19 @@ var Kupmios = class {
863
952
  },
864
953
  id: null
865
954
  };
866
- const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
867
- const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
868
- import_effect2.Effect.flatMap(
869
- (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
955
+ const schema = JSONRPCSchema(import_effect5.Schema.Array(RedeemerSchema));
956
+ const { result } = await (0, import_effect6.pipe)(
957
+ makePostAsJson(
958
+ this.ogmiosUrl,
959
+ data,
960
+ schema,
961
+ this.headers?.ogmiosHeader
870
962
  ),
871
- import_effect2.Effect.timeout(1e4),
872
- import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
963
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
964
+ import_effect6.Effect.timeout(1e4),
965
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
966
+ import_effect6.Effect.runPromise
873
967
  );
874
- const result = await import_effect2.Effect.runPromise(program);
875
968
  const evalRedeemers = result.map((item) => ({
876
969
  ex_units: {
877
970
  mem: item.budget.memory,
@@ -883,32 +976,33 @@ var Kupmios = class {
883
976
  return evalRedeemers;
884
977
  }
885
978
  };
886
- var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.gen(function* () {
979
+ var getDatumEffect = (kupoUrl, datum_type, datum_hash, kupoHeader) => import_effect6.Effect.gen(function* () {
887
980
  if (datum_type === "inline" && datum_hash) {
888
981
  const pattern = `${kupoUrl}/datums/${datum_hash}`;
889
982
  const schema = DatumSchema;
890
- return yield* fetchKupoParse(pattern, schema).pipe(
891
- import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
892
- import_effect2.Effect.map((result) => result.datum),
893
- import_effect2.Effect.retry(
894
- import_effect2.Schedule.compose(import_effect2.Schedule.exponential(50), import_effect2.Schedule.recurs(5))
983
+ return yield* (0, import_effect6.pipe)(
984
+ makeGet(pattern, schema, kupoHeader),
985
+ import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
986
+ import_effect6.Effect.map((result) => result.datum),
987
+ import_effect6.Effect.retry(
988
+ import_effect6.Schedule.compose(import_effect6.Schedule.exponential(50), import_effect6.Schedule.recurs(5))
895
989
  ),
896
- import_effect2.Effect.timeout(5e3)
990
+ import_effect6.Effect.timeout(5e3)
897
991
  );
898
992
  } else return void 0;
899
993
  });
900
- var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(function* () {
994
+ var getScriptEffect = (kupoUrl, script_hash, kupoHeader) => import_effect6.Effect.gen(function* () {
901
995
  if (script_hash) {
902
996
  const pattern = `${kupoUrl}/scripts/${script_hash}`;
903
997
  const schema = ScriptSchema;
904
- return yield* (0, import_effect2.pipe)(
905
- fetchKupoParse(pattern, schema),
906
- import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
907
- import_effect2.Effect.retry(
908
- import_effect2.Schedule.compose(import_effect2.Schedule.exponential(50), import_effect2.Schedule.recurs(5))
998
+ return yield* (0, import_effect6.pipe)(
999
+ makeGet(pattern, schema, kupoHeader),
1000
+ import_effect6.Effect.flatMap(import_effect6.Effect.fromNullable),
1001
+ import_effect6.Effect.retry(
1002
+ import_effect6.Schedule.compose(import_effect6.Schedule.exponential(50), import_effect6.Schedule.recurs(5))
909
1003
  ),
910
- import_effect2.Effect.timeout(5e3),
911
- import_effect2.Effect.map(({ language, script }) => {
1004
+ import_effect6.Effect.timeout(5e3),
1005
+ import_effect6.Effect.map(({ language, script }) => {
912
1006
  switch (language) {
913
1007
  case "native":
914
1008
  return {
@@ -987,38 +1081,15 @@ var toProtocolParameters = (result) => {
987
1081
  }
988
1082
  };
989
1083
  };
990
- var fetchOgmiosParse = (url, data, schema) => (0, import_effect2.pipe)(
991
- import_platform.HttpClientRequest.post(url),
992
- import_platform.HttpClientRequest.jsonBody(data),
993
- import_effect2.Effect.flatMap(import_platform.HttpClient.fetch),
994
- import_platform.HttpClientResponse.json,
995
- import_effect2.Effect.flatMap(S3.decodeUnknown(schema)),
996
- import_effect2.Effect.catchTag(
997
- "ParseError",
998
- (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
999
- )
1000
- // Effect.scoped
1001
- );
1002
- var fetchKupoParse = (url, schema) => (0, import_effect2.pipe)(
1003
- import_platform.HttpClientRequest.get(url),
1004
- import_platform.HttpClient.fetchOk,
1005
- import_platform.HttpClientResponse.json,
1006
- import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
1007
- import_effect2.Effect.catchTag(
1008
- "ParseError",
1009
- (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
1010
- )
1011
- // Effect.scoped
1012
- );
1013
- var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
1084
+ var kupmiosUtxosToUtxos = (kupoURL, utxos, kupoHeader) => import_effect6.Effect.forEach(
1014
1085
  utxos,
1015
1086
  (utxo) => {
1016
- return (0, import_effect2.pipe)(
1017
- import_effect2.Effect.all([
1018
- getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
1019
- getScriptEffect(kupoURL, utxo.script_hash)
1087
+ return (0, import_effect6.pipe)(
1088
+ import_effect6.Effect.all([
1089
+ getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash, kupoHeader),
1090
+ getScriptEffect(kupoURL, utxo.script_hash, kupoHeader)
1020
1091
  ]),
1021
- import_effect2.Effect.map(
1092
+ import_effect6.Effect.map(
1022
1093
  ([datum, script]) => ({
1023
1094
  txHash: utxo.transaction_id,
1024
1095
  outputIndex: utxo.output_index,
@@ -2108,213 +2179,211 @@ var toScriptRef = (reference_script) => {
2108
2179
  var lucid2 = package_default.version;
2109
2180
 
2110
2181
  // src/koios.ts
2111
- var S5 = __toESM(require("@effect/schema/Schema"), 1);
2112
2182
  var import_core_utils4 = require("@lucid-evolution/core-utils");
2113
2183
  var import_utils9 = require("@lucid-evolution/utils");
2114
2184
 
2115
2185
  // src/internal/koios.ts
2116
- var import_platform2 = require("@effect/platform");
2117
- var S4 = __toESM(require("@effect/schema/Schema"), 1);
2118
- var import_effect3 = require("effect");
2186
+ var import_platform3 = require("@effect/platform");
2187
+ var import_effect7 = require("effect");
2119
2188
  var import_utils8 = require("@lucid-evolution/utils");
2120
- var ProtocolParametersSchema2 = S4.Struct({
2121
- pvt_motion_no_confidence: S4.Number,
2122
- pvt_committee_normal: S4.Number,
2123
- pvt_committee_no_confidence: S4.Number,
2124
- pvt_hard_fork_initiation: S4.Number,
2125
- pvtpp_security_group: S4.Number,
2126
- dvt_motion_no_confidence: S4.Number,
2127
- dvt_committee_normal: S4.Number,
2128
- dvt_committee_no_confidence: S4.Number,
2129
- dvt_update_to_constitution: S4.Number,
2130
- dvt_hard_fork_initiation: S4.Number,
2131
- dvt_p_p_network_group: S4.Number,
2132
- dvt_p_p_economic_group: S4.Number,
2133
- dvt_p_p_technical_group: S4.Number,
2134
- dvt_p_p_gov_group: S4.Number,
2135
- dvt_treasury_withdrawal: S4.Number,
2136
- committee_min_size: S4.Number,
2137
- committee_max_term_length: S4.Number,
2138
- gov_action_lifetime: S4.Number,
2139
- gov_action_deposit: S4.NumberFromString,
2140
- drep_deposit: S4.NumberFromString,
2141
- drep_activity: S4.Number,
2142
- min_fee_ref_script_cost_per_byte: S4.Number,
2143
- epoch_no: S4.Number,
2144
- min_fee_a: S4.Number,
2145
- min_fee_b: S4.Number,
2146
- max_block_size: S4.Number,
2147
- max_tx_size: S4.Number,
2148
- max_bh_size: S4.Number,
2149
- key_deposit: S4.BigInt,
2150
- pool_deposit: S4.BigInt,
2151
- max_epoch: S4.Number,
2152
- optimal_pool_count: S4.Number,
2153
- influence: S4.Number,
2154
- monetary_expand_rate: S4.Number,
2155
- treasury_growth_rate: S4.Number,
2156
- decentralisation: S4.Number,
2157
- extra_entropy: S4.NullOr(S4.String),
2158
- protocol_major: S4.Number,
2159
- protocol_minor: S4.Number,
2160
- min_utxo_value: S4.String,
2161
- min_pool_cost: S4.String,
2162
- nonce: S4.String,
2163
- block_hash: S4.NullOr(S4.String),
2164
- cost_models: S4.Struct({
2165
- PlutusV1: S4.Array(S4.Number),
2166
- PlutusV2: S4.Array(S4.Number),
2167
- PlutusV3: S4.Array(S4.Number)
2189
+ var ProtocolParametersSchema2 = import_effect7.Schema.Struct({
2190
+ pvt_motion_no_confidence: import_effect7.Schema.Number,
2191
+ pvt_committee_normal: import_effect7.Schema.Number,
2192
+ pvt_committee_no_confidence: import_effect7.Schema.Number,
2193
+ pvt_hard_fork_initiation: import_effect7.Schema.Number,
2194
+ pvtpp_security_group: import_effect7.Schema.Number,
2195
+ dvt_motion_no_confidence: import_effect7.Schema.Number,
2196
+ dvt_committee_normal: import_effect7.Schema.Number,
2197
+ dvt_committee_no_confidence: import_effect7.Schema.Number,
2198
+ dvt_update_to_constitution: import_effect7.Schema.Number,
2199
+ dvt_hard_fork_initiation: import_effect7.Schema.Number,
2200
+ dvt_p_p_network_group: import_effect7.Schema.Number,
2201
+ dvt_p_p_economic_group: import_effect7.Schema.Number,
2202
+ dvt_p_p_technical_group: import_effect7.Schema.Number,
2203
+ dvt_p_p_gov_group: import_effect7.Schema.Number,
2204
+ dvt_treasury_withdrawal: import_effect7.Schema.Number,
2205
+ committee_min_size: import_effect7.Schema.Number,
2206
+ committee_max_term_length: import_effect7.Schema.Number,
2207
+ gov_action_lifetime: import_effect7.Schema.Number,
2208
+ gov_action_deposit: import_effect7.Schema.NumberFromString,
2209
+ drep_deposit: import_effect7.Schema.NumberFromString,
2210
+ drep_activity: import_effect7.Schema.Number,
2211
+ min_fee_ref_script_cost_per_byte: import_effect7.Schema.Number,
2212
+ epoch_no: import_effect7.Schema.Number,
2213
+ min_fee_a: import_effect7.Schema.Number,
2214
+ min_fee_b: import_effect7.Schema.Number,
2215
+ max_block_size: import_effect7.Schema.Number,
2216
+ max_tx_size: import_effect7.Schema.Number,
2217
+ max_bh_size: import_effect7.Schema.Number,
2218
+ key_deposit: import_effect7.Schema.BigInt,
2219
+ pool_deposit: import_effect7.Schema.BigInt,
2220
+ max_epoch: import_effect7.Schema.Number,
2221
+ optimal_pool_count: import_effect7.Schema.Number,
2222
+ influence: import_effect7.Schema.Number,
2223
+ monetary_expand_rate: import_effect7.Schema.Number,
2224
+ treasury_growth_rate: import_effect7.Schema.Number,
2225
+ decentralisation: import_effect7.Schema.Number,
2226
+ extra_entropy: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2227
+ protocol_major: import_effect7.Schema.Number,
2228
+ protocol_minor: import_effect7.Schema.Number,
2229
+ min_utxo_value: import_effect7.Schema.String,
2230
+ min_pool_cost: import_effect7.Schema.String,
2231
+ nonce: import_effect7.Schema.String,
2232
+ block_hash: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2233
+ cost_models: import_effect7.Schema.Struct({
2234
+ PlutusV1: import_effect7.Schema.Array(import_effect7.Schema.Number),
2235
+ PlutusV2: import_effect7.Schema.Array(import_effect7.Schema.Number),
2236
+ PlutusV3: import_effect7.Schema.Array(import_effect7.Schema.Number)
2168
2237
  }),
2169
- price_mem: S4.Number,
2170
- price_step: S4.Number,
2171
- max_tx_ex_mem: S4.BigIntFromNumber,
2172
- max_tx_ex_steps: S4.BigIntFromNumber,
2173
- max_block_ex_mem: S4.Number,
2174
- max_block_ex_steps: S4.Number,
2175
- max_val_size: S4.Number,
2176
- collateral_percent: S4.Number,
2177
- max_collateral_inputs: S4.Number,
2178
- coins_per_utxo_size: S4.BigInt
2238
+ price_mem: import_effect7.Schema.Number,
2239
+ price_step: import_effect7.Schema.Number,
2240
+ max_tx_ex_mem: import_effect7.Schema.BigIntFromNumber,
2241
+ max_tx_ex_steps: import_effect7.Schema.BigIntFromNumber,
2242
+ max_block_ex_mem: import_effect7.Schema.Number,
2243
+ max_block_ex_steps: import_effect7.Schema.Number,
2244
+ max_val_size: import_effect7.Schema.Number,
2245
+ collateral_percent: import_effect7.Schema.Number,
2246
+ max_collateral_inputs: import_effect7.Schema.Number,
2247
+ coins_per_utxo_size: import_effect7.Schema.BigInt
2179
2248
  });
2180
- var AssetSchema = S4.Struct({
2181
- policy_id: S4.String,
2182
- asset_name: S4.NullOr(S4.String),
2183
- fingerprint: S4.String,
2184
- decimals: S4.Number,
2185
- quantity: S4.String
2249
+ var AssetSchema = import_effect7.Schema.Struct({
2250
+ policy_id: import_effect7.Schema.String,
2251
+ asset_name: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2252
+ fingerprint: import_effect7.Schema.String,
2253
+ decimals: import_effect7.Schema.Number,
2254
+ quantity: import_effect7.Schema.String
2186
2255
  });
2187
- var ReferenceScriptSchema = S4.Struct({
2188
- hash: S4.NullOr(S4.String),
2189
- size: S4.NullOr(S4.Number),
2190
- type: S4.NullOr(S4.String),
2191
- bytes: S4.NullOr(S4.String),
2192
- value: S4.NullOr(S4.Object)
2256
+ var ReferenceScriptSchema = import_effect7.Schema.Struct({
2257
+ hash: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2258
+ size: import_effect7.Schema.NullOr(import_effect7.Schema.Number),
2259
+ type: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2260
+ bytes: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2261
+ value: import_effect7.Schema.NullOr(import_effect7.Schema.Object)
2193
2262
  });
2194
- var UTxOSchema2 = S4.Struct({
2195
- tx_hash: S4.String,
2196
- tx_index: S4.Number,
2197
- block_time: S4.Number,
2198
- block_height: S4.NullOr(S4.Number),
2199
- value: S4.String,
2200
- datum_hash: S4.NullOr(S4.String),
2201
- inline_datum: S4.NullOr(
2202
- S4.Struct({
2203
- bytes: S4.String,
2204
- value: S4.Object
2263
+ var UTxOSchema2 = import_effect7.Schema.Struct({
2264
+ tx_hash: import_effect7.Schema.String,
2265
+ tx_index: import_effect7.Schema.Number,
2266
+ block_time: import_effect7.Schema.Number,
2267
+ block_height: import_effect7.Schema.NullOr(import_effect7.Schema.Number),
2268
+ value: import_effect7.Schema.String,
2269
+ datum_hash: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2270
+ inline_datum: import_effect7.Schema.NullOr(
2271
+ import_effect7.Schema.Struct({
2272
+ bytes: import_effect7.Schema.String,
2273
+ value: import_effect7.Schema.Object
2205
2274
  })
2206
2275
  ),
2207
- reference_script: S4.NullOr(ReferenceScriptSchema),
2208
- asset_list: S4.NullOr(S4.Array(AssetSchema))
2276
+ reference_script: import_effect7.Schema.NullOr(ReferenceScriptSchema),
2277
+ asset_list: import_effect7.Schema.NullOr(import_effect7.Schema.Array(AssetSchema))
2209
2278
  });
2210
- var AddressInfoSchema = S4.Array(
2211
- S4.NullishOr(
2212
- S4.Struct({
2213
- address: S4.String,
2214
- balance: S4.String,
2215
- stake_address: S4.NullOr(S4.String),
2216
- script_address: S4.Boolean,
2217
- utxo_set: S4.Array(UTxOSchema2)
2279
+ var AddressInfoSchema = import_effect7.Schema.Array(
2280
+ import_effect7.Schema.NullishOr(
2281
+ import_effect7.Schema.Struct({
2282
+ address: import_effect7.Schema.String,
2283
+ balance: import_effect7.Schema.String,
2284
+ stake_address: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2285
+ script_address: import_effect7.Schema.Boolean,
2286
+ utxo_set: import_effect7.Schema.Array(UTxOSchema2)
2218
2287
  })
2219
2288
  )
2220
2289
  );
2221
- var InputOutputSchema = S4.Struct({
2222
- payment_addr: S4.Struct({
2223
- bech32: S4.String,
2224
- cred: S4.String
2290
+ var InputOutputSchema = import_effect7.Schema.Struct({
2291
+ payment_addr: import_effect7.Schema.Struct({
2292
+ bech32: import_effect7.Schema.String,
2293
+ cred: import_effect7.Schema.String
2225
2294
  }),
2226
- stake_addr: S4.NullOr(S4.String),
2227
- tx_hash: S4.String,
2228
- tx_index: S4.Number,
2229
- value: S4.String,
2230
- datum_hash: S4.NullOr(S4.String),
2231
- inline_datum: S4.NullOr(
2232
- S4.Struct({
2233
- bytes: S4.String,
2234
- value: S4.Object
2295
+ stake_addr: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2296
+ tx_hash: import_effect7.Schema.String,
2297
+ tx_index: import_effect7.Schema.Number,
2298
+ value: import_effect7.Schema.String,
2299
+ datum_hash: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2300
+ inline_datum: import_effect7.Schema.NullOr(
2301
+ import_effect7.Schema.Struct({
2302
+ bytes: import_effect7.Schema.String,
2303
+ value: import_effect7.Schema.Object
2235
2304
  })
2236
2305
  ),
2237
- reference_script: S4.NullOr(ReferenceScriptSchema),
2238
- asset_list: S4.Array(AssetSchema)
2306
+ reference_script: import_effect7.Schema.NullOr(ReferenceScriptSchema),
2307
+ asset_list: import_effect7.Schema.Array(AssetSchema)
2239
2308
  });
2240
- var TxInfoSchema = S4.Struct({
2241
- tx_hash: S4.String,
2242
- block_hash: S4.String,
2243
- block_height: S4.Number,
2244
- epoch_no: S4.Number,
2245
- epoch_slot: S4.Number,
2246
- absolute_slot: S4.Number,
2247
- tx_timestamp: S4.Number,
2248
- tx_block_index: S4.Number,
2249
- tx_size: S4.Number,
2250
- total_output: S4.String,
2251
- fee: S4.String,
2252
- treasury_donation: S4.String,
2253
- deposit: S4.String,
2254
- invalid_before: S4.NullOr(S4.String),
2255
- invalid_after: S4.NullOr(S4.String),
2256
- collateral_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
2257
- collateral_output: S4.NullOr(InputOutputSchema),
2258
- reference_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
2259
- inputs: S4.Array(InputOutputSchema),
2260
- outputs: S4.Array(InputOutputSchema),
2261
- withdrawals: S4.NullOr(
2262
- S4.Array(
2263
- S4.Struct({
2264
- amount: S4.String,
2265
- stake_addr: S4.String
2309
+ var TxInfoSchema = import_effect7.Schema.Struct({
2310
+ tx_hash: import_effect7.Schema.String,
2311
+ block_hash: import_effect7.Schema.String,
2312
+ block_height: import_effect7.Schema.Number,
2313
+ epoch_no: import_effect7.Schema.Number,
2314
+ epoch_slot: import_effect7.Schema.Number,
2315
+ absolute_slot: import_effect7.Schema.Number,
2316
+ tx_timestamp: import_effect7.Schema.Number,
2317
+ tx_block_index: import_effect7.Schema.Number,
2318
+ tx_size: import_effect7.Schema.Number,
2319
+ total_output: import_effect7.Schema.String,
2320
+ fee: import_effect7.Schema.String,
2321
+ treasury_donation: import_effect7.Schema.String,
2322
+ deposit: import_effect7.Schema.String,
2323
+ invalid_before: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2324
+ invalid_after: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2325
+ collateral_inputs: import_effect7.Schema.NullOr(import_effect7.Schema.Array(InputOutputSchema)),
2326
+ collateral_output: import_effect7.Schema.NullOr(InputOutputSchema),
2327
+ reference_inputs: import_effect7.Schema.NullOr(import_effect7.Schema.Array(InputOutputSchema)),
2328
+ inputs: import_effect7.Schema.Array(InputOutputSchema),
2329
+ outputs: import_effect7.Schema.Array(InputOutputSchema),
2330
+ withdrawals: import_effect7.Schema.NullOr(
2331
+ import_effect7.Schema.Array(
2332
+ import_effect7.Schema.Struct({
2333
+ amount: import_effect7.Schema.String,
2334
+ stake_addr: import_effect7.Schema.String
2266
2335
  })
2267
2336
  )
2268
2337
  ),
2269
- assets_minted: S4.NullOr(S4.Array(AssetSchema)),
2270
- metadata: S4.NullOr(S4.Object),
2271
- certificates: S4.NullOr(
2272
- S4.Array(
2273
- S4.Struct({
2274
- index: S4.Number,
2275
- type: S4.String,
2276
- info: S4.NullOr(S4.Object)
2338
+ assets_minted: import_effect7.Schema.NullOr(import_effect7.Schema.Array(AssetSchema)),
2339
+ metadata: import_effect7.Schema.NullOr(import_effect7.Schema.Object),
2340
+ certificates: import_effect7.Schema.NullOr(
2341
+ import_effect7.Schema.Array(
2342
+ import_effect7.Schema.Struct({
2343
+ index: import_effect7.Schema.Number,
2344
+ type: import_effect7.Schema.String,
2345
+ info: import_effect7.Schema.NullOr(import_effect7.Schema.Object)
2277
2346
  })
2278
2347
  )
2279
2348
  ),
2280
- native_scripts: S4.NullOr(
2281
- S4.Array(
2282
- S4.Struct({
2283
- script_hash: S4.String,
2284
- script_json: S4.Object
2349
+ native_scripts: import_effect7.Schema.NullOr(
2350
+ import_effect7.Schema.Array(
2351
+ import_effect7.Schema.Struct({
2352
+ script_hash: import_effect7.Schema.String,
2353
+ script_json: import_effect7.Schema.Object
2285
2354
  })
2286
2355
  )
2287
2356
  ),
2288
- plutus_contracts: S4.NullOr(
2289
- S4.Array(
2290
- S4.Struct({
2291
- address: S4.String,
2292
- spends_input: S4.NullOr(
2293
- S4.Struct({
2294
- tx_hash: S4.String,
2295
- tx_index: S4.Number
2357
+ plutus_contracts: import_effect7.Schema.NullOr(
2358
+ import_effect7.Schema.Array(
2359
+ import_effect7.Schema.Struct({
2360
+ address: import_effect7.Schema.String,
2361
+ spends_input: import_effect7.Schema.NullOr(
2362
+ import_effect7.Schema.Struct({
2363
+ tx_hash: import_effect7.Schema.String,
2364
+ tx_index: import_effect7.Schema.Number
2296
2365
  })
2297
2366
  ),
2298
- script_hash: S4.String,
2299
- bytecode: S4.String,
2300
- size: S4.Number,
2301
- valid_contract: S4.Boolean,
2302
- input: S4.Struct({
2303
- redeemer: S4.Struct({
2304
- purpose: S4.Literal("spend", "mint", "cert", "reward"),
2305
- fee: S4.String,
2306
- unit: S4.Struct({
2307
- steps: S4.String,
2308
- mem: S4.String
2367
+ script_hash: import_effect7.Schema.String,
2368
+ bytecode: import_effect7.Schema.String,
2369
+ size: import_effect7.Schema.Number,
2370
+ valid_contract: import_effect7.Schema.Boolean,
2371
+ input: import_effect7.Schema.Struct({
2372
+ redeemer: import_effect7.Schema.Struct({
2373
+ purpose: import_effect7.Schema.Literal("spend", "mint", "cert", "reward"),
2374
+ fee: import_effect7.Schema.String,
2375
+ unit: import_effect7.Schema.Struct({
2376
+ steps: import_effect7.Schema.String,
2377
+ mem: import_effect7.Schema.String
2309
2378
  }),
2310
- datum: S4.Struct({
2311
- hash: S4.NullOr(S4.String),
2312
- value: S4.NullOr(S4.Object)
2379
+ datum: import_effect7.Schema.Struct({
2380
+ hash: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2381
+ value: import_effect7.Schema.NullOr(import_effect7.Schema.Object)
2313
2382
  })
2314
2383
  }),
2315
- datum: S4.Struct({
2316
- hash: S4.NullOr(S4.String),
2317
- value: S4.NullOr(S4.Object)
2384
+ datum: import_effect7.Schema.Struct({
2385
+ hash: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2386
+ value: import_effect7.Schema.NullOr(import_effect7.Schema.Object)
2318
2387
  })
2319
2388
  })
2320
2389
  })
@@ -2322,45 +2391,24 @@ var TxInfoSchema = S4.Struct({
2322
2391
  ),
2323
2392
  //TODO: add S.Struct
2324
2393
  // https://preprod.koios.rest/#post-/tx_info
2325
- voting_procedures: S4.Array(S4.Object),
2394
+ voting_procedures: import_effect7.Schema.Array(import_effect7.Schema.Object),
2326
2395
  //TODO: add S.Struct
2327
2396
  // https://preprod.koios.rest/#post-/tx_info
2328
- proposal_procedures: S4.Object
2397
+ proposal_procedures: import_effect7.Schema.Object
2329
2398
  });
2330
- var TxHashSchema = S4.String;
2331
- var AssetAddressSchema = S4.Struct({
2332
- payment_address: S4.String,
2333
- stake_address: S4.NullOr(S4.String),
2334
- quantity: S4.String
2399
+ var TxHashSchema = import_effect7.Schema.String;
2400
+ var AssetAddressSchema = import_effect7.Schema.Struct({
2401
+ payment_address: import_effect7.Schema.String,
2402
+ stake_address: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2403
+ quantity: import_effect7.Schema.String
2335
2404
  });
2336
- var AccountInfoSchema = S4.Struct({
2337
- delegated_pool: S4.NullOr(S4.String),
2338
- rewards_available: S4.NumberFromString
2405
+ var AccountInfoSchema = import_effect7.Schema.Struct({
2406
+ delegated_pool: import_effect7.Schema.NullOr(import_effect7.Schema.String),
2407
+ rewards_available: import_effect7.Schema.NumberFromString
2339
2408
  });
2340
- var DatumInfo = S4.Struct({
2341
- bytes: S4.String
2409
+ var DatumInfo = import_effect7.Schema.Struct({
2410
+ bytes: import_effect7.Schema.String
2342
2411
  });
2343
- var postWithSchemaValidation = (url, data, schema, headers = {}) => (0, import_effect3.pipe)(
2344
- import_effect3.Effect.succeed(import_platform2.HttpClientRequest.post(url)),
2345
- import_effect3.Effect.map(import_platform2.HttpClientRequest.setHeaders(headers)),
2346
- import_effect3.Effect.flatMap(
2347
- (req) => headers["Content-Type"] === "application/cbor" ? import_effect3.Effect.succeed(
2348
- import_platform2.HttpClientRequest.uint8ArrayBody(
2349
- data,
2350
- headers["Content-Type"]
2351
- )(req)
2352
- ) : import_platform2.HttpClientRequest.jsonBody(data)(req)
2353
- ),
2354
- import_effect3.Effect.flatMap(import_platform2.HttpClient.fetch),
2355
- import_platform2.HttpClientResponse.json,
2356
- import_effect3.Effect.flatMap(S4.decodeUnknown(schema))
2357
- );
2358
- var getWithSchemaValidation = (url, schema) => (0, import_effect3.pipe)(
2359
- import_platform2.HttpClientRequest.get(url),
2360
- import_platform2.HttpClient.fetchOk,
2361
- import_platform2.HttpClientResponse.json,
2362
- import_effect3.Effect.flatMap(S4.decodeUnknown(schema))
2363
- );
2364
2412
  var toUTxO = (koiosUTxO, address) => ({
2365
2413
  txHash: koiosUTxO.tx_hash,
2366
2414
  outputIndex: koiosUTxO.tx_index,
@@ -2402,44 +2450,51 @@ var toScriptRef2 = (reference_script) => {
2402
2450
  }
2403
2451
  }
2404
2452
  };
2405
- var getUtxosEffect = (baseUrl, addressOrCredential) => {
2453
+ var getUtxosEffect = (baseUrl, addressOrCredential, headers) => {
2406
2454
  const url = `${baseUrl}/address_info`;
2407
2455
  const body = {
2408
2456
  _addresses: [addressOrCredential]
2409
2457
  };
2410
2458
  const schema = AddressInfoSchema;
2411
- const result = (0, import_effect3.pipe)(
2412
- import_effect3.Effect.if(typeof addressOrCredential === "string", {
2413
- onFalse: () => import_effect3.Effect.fail("Credential Type is not supported in Koios yet."),
2414
- onTrue: () => postWithSchemaValidation(url, body, schema)
2459
+ const result = (0, import_effect7.pipe)(
2460
+ import_effect7.Effect.if(typeof addressOrCredential === "string", {
2461
+ onFalse: () => import_effect7.Effect.fail("Credential Type is not supported in Koios yet."),
2462
+ onTrue: () => makePostAsJson(url, body, schema, headers)
2415
2463
  }),
2416
- import_effect3.Effect.map(
2464
+ import_effect7.Effect.map(
2417
2465
  ([result2]) => result2 ? result2.utxo_set.map((koiosUtxo) => toUTxO(koiosUtxo, result2.address)) : []
2418
- )
2466
+ ),
2467
+ import_effect7.Effect.provide(import_platform3.FetchHttpClient.layer)
2419
2468
  );
2420
2469
  return result;
2421
2470
  };
2422
2471
 
2423
2472
  // src/koios.ts
2424
- var import_effect4 = require("effect");
2425
- var KoiosError = class extends import_effect4.Data.TaggedError("KoiosError") {
2473
+ var import_effect8 = require("effect");
2474
+ var import_platform4 = require("@effect/platform");
2475
+ var KoiosError = class extends import_effect8.Data.TaggedError("KoiosError") {
2426
2476
  get message() {
2427
2477
  return `${this.cause}`;
2428
2478
  }
2429
2479
  };
2430
2480
  var Koios = class {
2431
2481
  baseUrl;
2432
- constructor(baseUrl) {
2482
+ token;
2483
+ constructor(baseUrl, token) {
2433
2484
  this.baseUrl = baseUrl;
2485
+ this.token = token;
2434
2486
  }
2435
2487
  async getProtocolParameters() {
2436
2488
  const url = `${this.baseUrl}/epoch_params?limit=1`;
2437
- const schema = S5.Array(ProtocolParametersSchema2);
2438
- const [result] = await (0, import_effect4.pipe)(
2439
- getWithSchemaValidation(url, schema),
2440
- import_effect4.Effect.timeout(1e4),
2441
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2442
- import_effect4.Effect.runPromise
2489
+ const schema = import_effect8.Schema.Array(ProtocolParametersSchema2);
2490
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2491
+ const [result] = await (0, import_effect8.pipe)(
2492
+ makeGet(url, schema, bearerToken),
2493
+ // Allows for dependency injection and easier testing
2494
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2495
+ import_effect8.Effect.timeout(1e4),
2496
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2497
+ import_effect8.Effect.runPromise
2443
2498
  );
2444
2499
  return {
2445
2500
  minFeeA: result.min_fee_a,
@@ -2481,55 +2536,64 @@ var Koios = class {
2481
2536
  };
2482
2537
  }
2483
2538
  async getUtxos(addressOrCredential) {
2484
- const result = await (0, import_effect4.pipe)(
2485
- getUtxosEffect(this.baseUrl, addressOrCredential),
2486
- import_effect4.Effect.timeout(1e4),
2487
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2488
- import_effect4.Effect.runPromise
2539
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2540
+ const result = await (0, import_effect8.pipe)(
2541
+ getUtxosEffect(this.baseUrl, addressOrCredential, bearerToken),
2542
+ import_effect8.Effect.timeout(1e4),
2543
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2544
+ import_effect8.Effect.runPromise
2489
2545
  );
2490
2546
  return result;
2491
2547
  }
2492
2548
  async getUtxosWithUnit(addressOrCredential, unit) {
2493
- const result = await (0, import_effect4.pipe)(
2494
- getUtxosEffect(this.baseUrl, addressOrCredential),
2495
- import_effect4.Effect.map(
2549
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2550
+ const result = await (0, import_effect8.pipe)(
2551
+ getUtxosEffect(this.baseUrl, addressOrCredential, bearerToken),
2552
+ import_effect8.Effect.map(
2496
2553
  (utxos) => utxos.filter((utxo) => {
2497
2554
  const keys = Object.keys(utxo.assets);
2498
2555
  return keys.length > 0 && keys.includes(unit);
2499
2556
  })
2500
2557
  ),
2501
- import_effect4.Effect.timeout(1e4),
2502
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2503
- import_effect4.Effect.runPromise
2558
+ import_effect8.Effect.timeout(1e4),
2559
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2560
+ import_effect8.Effect.runPromise
2504
2561
  );
2505
2562
  return result;
2506
2563
  }
2507
2564
  async getUtxoByUnit(unit) {
2508
2565
  let { policyId, assetName } = (0, import_utils9.fromUnit)(unit);
2509
2566
  const url = `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`;
2510
- const result = await (0, import_effect4.pipe)(
2511
- getWithSchemaValidation(url, S5.Array(AssetAddressSchema)),
2512
- import_effect4.Effect.flatMap(
2513
- (adresses) => adresses.length === 0 ? import_effect4.Effect.fail("Unit not found") : import_effect4.Effect.succeed(adresses)
2567
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2568
+ const result = await (0, import_effect8.pipe)(
2569
+ makeGet(url, import_effect8.Schema.Array(AssetAddressSchema), bearerToken),
2570
+ // Allows for dependency injection and easier testing
2571
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2572
+ import_effect8.Effect.flatMap(
2573
+ (adresses) => adresses.length === 0 ? import_effect8.Effect.fail("Unit not found") : import_effect8.Effect.succeed(adresses)
2514
2574
  ),
2515
- import_effect4.Effect.flatMap(
2516
- (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])
2575
+ import_effect8.Effect.flatMap(
2576
+ (adresses) => adresses.length > 1 ? import_effect8.Effect.fail("Unit needs to be an NFT or only held by one address.") : import_effect8.Effect.succeed(adresses[0])
2517
2577
  ),
2518
- import_effect4.Effect.flatMap(
2519
- (address) => getUtxosEffect(this.baseUrl, address.payment_address)
2578
+ import_effect8.Effect.flatMap(
2579
+ (address) => getUtxosEffect(
2580
+ this.baseUrl,
2581
+ address.payment_address,
2582
+ bearerToken
2583
+ )
2520
2584
  ),
2521
- import_effect4.Effect.map(
2585
+ import_effect8.Effect.map(
2522
2586
  (utxos) => utxos.filter((utxo) => {
2523
2587
  const keys = Object.keys(utxo.assets);
2524
2588
  return keys.length > 0 && keys.includes(unit);
2525
2589
  })
2526
2590
  ),
2527
- import_effect4.Effect.flatMap(
2528
- (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])
2591
+ import_effect8.Effect.flatMap(
2592
+ (utxos) => utxos.length > 1 ? import_effect8.Effect.fail("Unit needs to be an NFT or only held by one address.") : import_effect8.Effect.succeed(utxos[0])
2529
2593
  ),
2530
- import_effect4.Effect.timeout(1e4),
2531
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2532
- import_effect4.Effect.runPromise
2594
+ import_effect8.Effect.timeout(1e4),
2595
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2596
+ import_effect8.Effect.runPromise
2533
2597
  );
2534
2598
  return result;
2535
2599
  }
@@ -2540,12 +2604,15 @@ var Koios = class {
2540
2604
  _assets: true,
2541
2605
  _scripts: true
2542
2606
  };
2543
- const schema = S5.Array(TxInfoSchema);
2544
- const [result] = await (0, import_effect4.pipe)(
2545
- postWithSchemaValidation(url, body, schema),
2546
- import_effect4.Effect.timeout(1e4),
2547
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2548
- import_effect4.Effect.runPromise
2607
+ const schema = import_effect8.Schema.Array(TxInfoSchema);
2608
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2609
+ const [result] = await (0, import_effect8.pipe)(
2610
+ makePostAsJson(url, body, schema, bearerToken),
2611
+ // Allows for dependency injection and easier testing
2612
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2613
+ import_effect8.Effect.timeout(1e4),
2614
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2615
+ import_effect8.Effect.runPromise
2549
2616
  );
2550
2617
  if (result) {
2551
2618
  const utxos = result.outputs.map(
@@ -2578,18 +2645,22 @@ var Koios = class {
2578
2645
  _stake_addresses: [rewardAddress]
2579
2646
  };
2580
2647
  const url = `${this.baseUrl}/account_info`;
2581
- const result = await (0, import_effect4.pipe)(
2582
- postWithSchemaValidation(
2648
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2649
+ const result = await (0, import_effect8.pipe)(
2650
+ makePostAsJson(
2583
2651
  url,
2584
2652
  body,
2585
- S5.Array(AccountInfoSchema)
2653
+ import_effect8.Schema.Array(AccountInfoSchema),
2654
+ bearerToken
2586
2655
  ),
2587
- import_effect4.Effect.flatMap(
2588
- (result2) => result2.length === 0 ? import_effect4.Effect.fail("No Delegation Found by Reward Address") : import_effect4.Effect.succeed(result2[0])
2656
+ // Allows for dependency injection and easier testing
2657
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2658
+ import_effect8.Effect.flatMap(
2659
+ (result2) => result2.length === 0 ? import_effect8.Effect.fail("No Delegation Found by Reward Address") : import_effect8.Effect.succeed(result2[0])
2589
2660
  ),
2590
- import_effect4.Effect.timeout(1e4),
2591
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2592
- import_effect4.Effect.runPromise
2661
+ import_effect8.Effect.timeout(1e4),
2662
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2663
+ import_effect8.Effect.runPromise
2593
2664
  );
2594
2665
  return {
2595
2666
  poolId: result.delegated_pool || null,
@@ -2601,14 +2672,22 @@ var Koios = class {
2601
2672
  const body = {
2602
2673
  _datum_hashes: [datumHash]
2603
2674
  };
2604
- const result = await (0, import_effect4.pipe)(
2605
- postWithSchemaValidation(url, body, S5.Array(DatumInfo)),
2606
- import_effect4.Effect.flatMap(
2607
- (result2) => result2.length === 0 ? import_effect4.Effect.fail("No Datum Found by Datum Hash") : import_effect4.Effect.succeed(result2[0])
2675
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2676
+ const result = await (0, import_effect8.pipe)(
2677
+ makePostAsJson(
2678
+ url,
2679
+ body,
2680
+ import_effect8.Schema.Array(DatumInfo),
2681
+ bearerToken
2608
2682
  ),
2609
- import_effect4.Effect.timeout(1e4),
2610
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2611
- import_effect4.Effect.runPromise
2683
+ // Allows for dependency injection and easier testing
2684
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2685
+ import_effect8.Effect.flatMap(
2686
+ (result2) => result2.length === 0 ? import_effect8.Effect.fail("No Datum Found by Datum Hash") : import_effect8.Effect.succeed(result2[0])
2687
+ ),
2688
+ import_effect8.Effect.timeout(1e4),
2689
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2690
+ import_effect8.Effect.runPromise
2612
2691
  );
2613
2692
  return result.bytes;
2614
2693
  }
@@ -2617,17 +2696,20 @@ var Koios = class {
2617
2696
  const body = {
2618
2697
  _tx_hashes: [txHash]
2619
2698
  };
2620
- const schema = S5.Array(TxInfoSchema);
2621
- const result = await (0, import_effect4.pipe)(
2622
- postWithSchemaValidation(url, body, schema),
2623
- import_effect4.Effect.repeat({
2624
- schedule: import_effect4.Schedule.exponential(checkInterval),
2699
+ const schema = import_effect8.Schema.Array(TxInfoSchema);
2700
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2701
+ const result = await (0, import_effect8.pipe)(
2702
+ makePostAsJson(url, body, schema, bearerToken),
2703
+ import_effect8.Effect.repeat({
2704
+ schedule: import_effect8.Schedule.exponential(checkInterval),
2625
2705
  until: (result2) => result2.length > 0
2626
2706
  }),
2627
- import_effect4.Effect.timeout(16e4),
2628
- import_effect4.Effect.orDie,
2629
- import_effect4.Effect.as(true),
2630
- import_effect4.Effect.runPromise
2707
+ // Allows for dependency injection and easier testing
2708
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2709
+ import_effect8.Effect.timeout(16e4),
2710
+ import_effect8.Effect.orDie,
2711
+ import_effect8.Effect.as(true),
2712
+ import_effect8.Effect.runPromise
2631
2713
  );
2632
2714
  return result;
2633
2715
  }
@@ -2635,13 +2717,14 @@ var Koios = class {
2635
2717
  const url = `${this.baseUrl}/submittx`;
2636
2718
  const body = (0, import_core_utils4.fromHex)(tx);
2637
2719
  const schema = TxHashSchema;
2638
- const result = await (0, import_effect4.pipe)(
2639
- postWithSchemaValidation(url, body, schema, {
2640
- "Content-Type": "application/cbor"
2641
- }),
2642
- import_effect4.Effect.timeout(1e4),
2643
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2644
- import_effect4.Effect.runPromise
2720
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2721
+ const result = await (0, import_effect8.pipe)(
2722
+ makePostAsUint8Array(url, body, schema, bearerToken),
2723
+ // Allows for dependency injection and easier testing
2724
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2725
+ import_effect8.Effect.timeout(1e4),
2726
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2727
+ import_effect8.Effect.runPromise
2645
2728
  );
2646
2729
  return result;
2647
2730
  }
@@ -2656,15 +2739,15 @@ var Koios = class {
2656
2739
  },
2657
2740
  id: null
2658
2741
  };
2659
- const schema = JSONRPCSchema(S5.Array(RedeemerSchema));
2660
- const result = await (0, import_effect4.pipe)(
2661
- postWithSchemaValidation(url, body, schema),
2662
- import_effect4.Effect.flatMap(
2663
- (response) => "error" in response ? import_effect4.Effect.fail(response) : import_effect4.Effect.succeed(response.result)
2664
- ),
2665
- import_effect4.Effect.timeout(1e4),
2666
- import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2667
- import_effect4.Effect.runPromise
2742
+ const schema = JSONRPCSchema(import_effect8.Schema.Array(RedeemerSchema));
2743
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2744
+ const { result } = await (0, import_effect8.pipe)(
2745
+ makePostAsJson(url, body, schema, bearerToken),
2746
+ // Allows for dependency injection and easier testing
2747
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2748
+ import_effect8.Effect.timeout(1e4),
2749
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2750
+ import_effect8.Effect.runPromise
2668
2751
  );
2669
2752
  const evalRedeemers = result.map((item) => ({
2670
2753
  ex_units: {