@lucid-evolution/provider 0.1.90 → 0.1.91

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.90",
55
+ version: "0.1.91",
56
56
  description: "",
57
57
  main: "./dist/index.js",
58
58
  types: "./dist/index.d.ts",
@@ -464,6 +464,29 @@ var JSONRPCSchema = (schema) => import_effect2.Schema.Struct({
464
464
  id: import_effect2.Schema.NullOr(import_effect2.Schema.Number),
465
465
  result: schema
466
466
  }).annotations({ identifier: "JSONRPCSchema" });
467
+ var JSONRPCErrorSchema = import_effect2.Schema.Struct({
468
+ code: import_effect2.Schema.Number,
469
+ message: import_effect2.Schema.String,
470
+ data: import_effect2.Schema.optional(import_effect2.Schema.Unknown)
471
+ });
472
+ var JSONRPCErrorResponseSchema = import_effect2.Schema.Struct({
473
+ jsonrpc: import_effect2.Schema.String,
474
+ method: import_effect2.Schema.optional(import_effect2.Schema.String),
475
+ id: import_effect2.Schema.NullOr(import_effect2.Schema.Number),
476
+ error: JSONRPCErrorSchema
477
+ });
478
+ var JSONRPCResponseSchema = (schema) => import_effect2.Schema.Union(JSONRPCSchema(schema), JSONRPCErrorResponseSchema).annotations({
479
+ identifier: "JSONRPCResponseSchema"
480
+ });
481
+ var getJSONRPCResult = (response) => {
482
+ if ("error" in response) {
483
+ const data = response.error.data === void 0 ? "" : `: ${JSON.stringify(response.error.data)}`;
484
+ throw new Error(
485
+ `Ogmios JSON-RPC error ${response.error.code}: ${response.error.message}${data}`
486
+ );
487
+ }
488
+ return response.result;
489
+ };
467
490
  var LovelaceAsset = import_effect2.Schema.Struct({
468
491
  lovelace: import_effect2.Schema.Number
469
492
  });
@@ -551,16 +574,38 @@ var ProtocolParametersSchema = import_effect2.Schema.Struct({
551
574
  maxCollateralInputs: import_effect2.Schema.Number,
552
575
  version: import_effect2.Schema.Struct({ major: import_effect2.Schema.Number, minor: import_effect2.Schema.Number })
553
576
  }).annotations({ identifier: "ProtocolParametersSchema" });
554
- var Delegation = import_effect2.Schema.NullOr(
577
+ var RewardAccountAdaSchema = import_effect2.Schema.Struct({
578
+ ada: LovelaceAsset
579
+ });
580
+ var LegacyDelegationSummarySchema = import_effect2.Schema.Struct({
581
+ delegate: import_effect2.Schema.optional(import_effect2.Schema.NullOr(import_effect2.Schema.Struct({ id: import_effect2.Schema.String }))),
582
+ rewards: RewardAccountAdaSchema,
583
+ deposit: RewardAccountAdaSchema
584
+ });
585
+ var RewardAccountSummarySchema = import_effect2.Schema.Struct({
586
+ from: import_effect2.Schema.optional(import_effect2.Schema.Literal("key", "script")),
587
+ credential: import_effect2.Schema.optional(import_effect2.Schema.String),
588
+ stakePool: import_effect2.Schema.optional(import_effect2.Schema.NullOr(import_effect2.Schema.Struct({ id: import_effect2.Schema.String }))),
589
+ rewards: RewardAccountAdaSchema,
590
+ deposit: RewardAccountAdaSchema
591
+ });
592
+ var Delegation = import_effect2.Schema.Union(
593
+ import_effect2.Schema.Null,
555
594
  import_effect2.Schema.Record({
556
595
  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 }) })
561
- })
562
- })
596
+ value: LegacyDelegationSummarySchema
597
+ }),
598
+ import_effect2.Schema.Array(RewardAccountSummarySchema)
563
599
  );
600
+ var toOgmiosQuantity = (amount) => {
601
+ const quantity = Number(amount);
602
+ if (amount < 0n || !Number.isSafeInteger(quantity)) {
603
+ throw new Error(
604
+ `Cannot encode Ogmios quantity ${amount.toString()}. Ogmios expects JSON numbers, so quantities must be non-negative safe integers.`
605
+ );
606
+ }
607
+ return quantity;
608
+ };
564
609
  var RedeemerSchema = import_effect2.Schema.Struct({
565
610
  validator: import_effect2.Schema.Struct({
566
611
  purpose: import_effect2.Schema.Literal(
@@ -610,7 +655,7 @@ var toOgmiosUTxOs = (utxos) => {
610
655
  if (!newAssets[policyId]) {
611
656
  newAssets[policyId] = {};
612
657
  }
613
- return newAssets[policyId][assetName ? assetName : ""] = Number(amount);
658
+ return newAssets[policyId][assetName ? assetName : ""] = toOgmiosQuantity(amount);
614
659
  });
615
660
  return newAssets;
616
661
  };
@@ -622,7 +667,7 @@ var toOgmiosUTxOs = (utxos) => {
622
667
  index: utxo.outputIndex,
623
668
  address: utxo.address,
624
669
  value: {
625
- ada: { lovelace: Number(utxo.assets["lovelace"]) },
670
+ ada: { lovelace: toOgmiosQuantity(utxo.assets["lovelace"]) },
626
671
  ...toOgmiosAssets(utxo.assets)
627
672
  },
628
673
  datumHash: utxo.datumHash,
@@ -634,9 +679,13 @@ var toOgmiosUTxOs = (utxos) => {
634
679
 
635
680
  // src/internal/kupo.ts
636
681
  var import_effect3 = require("effect");
682
+ var QuantitySchema = import_effect3.Schema.Union(
683
+ import_effect3.Schema.Number.pipe(import_effect3.Schema.filter(Number.isSafeInteger)),
684
+ import_effect3.Schema.String.pipe(import_effect3.Schema.pattern(/^\d+$/))
685
+ );
637
686
  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 })
687
+ coins: QuantitySchema,
688
+ assets: import_effect3.Schema.Record({ key: import_effect3.Schema.String, value: QuantitySchema })
640
689
  });
641
690
  var UTxOSchema = import_effect3.Schema.Struct({
642
691
  transaction_index: import_effect3.Schema.Number,
@@ -767,8 +816,10 @@ var Kupmios = class {
767
816
  params: {},
768
817
  id: null
769
818
  };
770
- const schema = JSONRPCSchema(ProtocolParametersSchema);
771
- const { result } = await (0, import_effect6.pipe)(
819
+ const schema = JSONRPCResponseSchema(
820
+ ProtocolParametersSchema
821
+ );
822
+ const response = await (0, import_effect6.pipe)(
772
823
  makePostAsJson(
773
824
  this.ogmiosUrl,
774
825
  data,
@@ -780,6 +831,7 @@ var Kupmios = class {
780
831
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
781
832
  import_effect6.Effect.runPromise
782
833
  );
834
+ const result = getJSONRPCResult(response);
783
835
  return toProtocolParameters(result);
784
836
  }
785
837
  async getUtxos(addressOrCredential) {
@@ -789,7 +841,9 @@ var Kupmios = class {
789
841
  const schema = import_effect5.Schema.Array(UTxOSchema);
790
842
  const utxos = await (0, import_effect6.pipe)(
791
843
  makeGet(pattern, schema, this.headers?.kupoHeader),
792
- import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
844
+ import_effect6.Effect.flatMap(
845
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
846
+ ),
793
847
  import_effect6.Effect.timeout(1e4),
794
848
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
795
849
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
@@ -805,7 +859,9 @@ var Kupmios = class {
805
859
  const schema = import_effect5.Schema.Array(UTxOSchema);
806
860
  const utxos = await (0, import_effect6.pipe)(
807
861
  makeGet(pattern, schema, this.headers?.kupoHeader),
808
- import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
862
+ import_effect6.Effect.flatMap(
863
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
864
+ ),
809
865
  import_effect6.Effect.timeout(1e4),
810
866
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
811
867
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
@@ -819,12 +875,17 @@ var Kupmios = class {
819
875
  const schema = import_effect5.Schema.Array(UTxOSchema);
820
876
  const utxos = await (0, import_effect6.pipe)(
821
877
  makeGet(pattern, schema, this.headers?.kupoHeader),
822
- import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
878
+ import_effect6.Effect.flatMap(
879
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
880
+ ),
823
881
  import_effect6.Effect.timeout(1e4),
824
882
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
825
883
  import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
826
884
  import_effect6.Effect.runPromise
827
885
  );
886
+ if (utxos.length === 0) {
887
+ throw new Error("Unit not found.");
888
+ }
828
889
  if (utxos.length > 1) {
829
890
  throw new Error("Unit needs to be an NFT or only held by one address.");
830
891
  }
@@ -840,7 +901,9 @@ var Kupmios = class {
840
901
  queryHashes,
841
902
  (txHash) => (0, import_effect6.pipe)(
842
903
  makeGet(mkPattern(txHash), schema, this.headers?.kupoHeader),
843
- import_effect6.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
904
+ import_effect6.Effect.flatMap(
905
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
906
+ ),
844
907
  import_effect6.Effect.timeout(1e4),
845
908
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause }))
846
909
  )
@@ -861,8 +924,8 @@ var Kupmios = class {
861
924
  params: { keys: [rewardAddress] },
862
925
  id: null
863
926
  };
864
- const schema = JSONRPCSchema(Delegation);
865
- const { result } = await (0, import_effect6.pipe)(
927
+ const schema = JSONRPCResponseSchema(Delegation);
928
+ const response = await (0, import_effect6.pipe)(
866
929
  makePostAsJson(
867
930
  this.ogmiosUrl,
868
931
  data,
@@ -874,11 +937,8 @@ var Kupmios = class {
874
937
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
875
938
  import_effect6.Effect.runPromise
876
939
  );
877
- const delegation = result ? Object.values(result)[0] : null;
878
- return {
879
- poolId: delegation?.delegate?.id || null,
880
- rewards: BigInt(delegation?.rewards?.ada?.lovelace || 0)
881
- };
940
+ const result = getJSONRPCResult(response);
941
+ return toDelegation(result);
882
942
  }
883
943
  async getDatum(datumHash) {
884
944
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
@@ -921,14 +981,14 @@ var Kupmios = class {
921
981
  },
922
982
  id: null
923
983
  };
924
- const schema = JSONRPCSchema(
984
+ const schema = JSONRPCResponseSchema(
925
985
  import_effect5.Schema.Struct({
926
986
  transaction: import_effect5.Schema.Struct({
927
987
  id: import_effect5.Schema.String
928
988
  })
929
989
  })
930
990
  );
931
- const { result } = await (0, import_effect6.pipe)(
991
+ const response = await (0, import_effect6.pipe)(
932
992
  makePostAsJson(
933
993
  this.ogmiosUrl,
934
994
  data,
@@ -940,6 +1000,7 @@ var Kupmios = class {
940
1000
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
941
1001
  import_effect6.Effect.runPromise
942
1002
  );
1003
+ const result = getJSONRPCResult(response);
943
1004
  return result.transaction.id;
944
1005
  }
945
1006
  async evaluateTx(tx, additionalUTxOs) {
@@ -952,8 +1013,8 @@ var Kupmios = class {
952
1013
  },
953
1014
  id: null
954
1015
  };
955
- const schema = JSONRPCSchema(import_effect5.Schema.Array(RedeemerSchema));
956
- const { result } = await (0, import_effect6.pipe)(
1016
+ const schema = JSONRPCResponseSchema(import_effect5.Schema.Array(RedeemerSchema));
1017
+ const response = await (0, import_effect6.pipe)(
957
1018
  makePostAsJson(
958
1019
  this.ogmiosUrl,
959
1020
  data,
@@ -965,6 +1026,7 @@ var Kupmios = class {
965
1026
  import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
966
1027
  import_effect6.Effect.runPromise
967
1028
  );
1029
+ const result = getJSONRPCResult(response);
968
1030
  const evalRedeemers = result.map((item) => ({
969
1031
  ex_units: {
970
1032
  mem: item.budget.memory,
@@ -1081,6 +1143,19 @@ var toProtocolParameters = (result) => {
1081
1143
  }
1082
1144
  };
1083
1145
  };
1146
+ var toDelegation = (result) => {
1147
+ if (!result) {
1148
+ return { poolId: null, rewards: 0n };
1149
+ }
1150
+ const delegation = Array.isArray(result) ? result[0] : Object.values(result)[0];
1151
+ if (!delegation) {
1152
+ return { poolId: null, rewards: 0n };
1153
+ }
1154
+ return {
1155
+ poolId: "stakePool" in delegation ? delegation.stakePool?.id || null : delegation.delegate?.id || null,
1156
+ rewards: BigInt(delegation.rewards.ada.lovelace)
1157
+ };
1158
+ };
1084
1159
  var kupmiosUtxosToUtxos = (kupoURL, utxos, kupoHeader) => import_effect6.Effect.forEach(
1085
1160
  utxos,
1086
1161
  (utxo) => {
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, Assets, OutputData, UnixTime, Lovelace } from '@lucid-evolution/core-types';
1
+ import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, UnixTime, Assets, OutputData, Lovelace } from '@lucid-evolution/core-types';
2
2
  import * as effect_Cause from 'effect/Cause';
3
3
  import * as effect_Types from 'effect/Types';
4
4
 
@@ -19,7 +19,7 @@ declare class Blockfrost implements Provider {
19
19
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
20
20
  }
21
21
 
22
- declare const KupmiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
22
+ declare const KupmiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
23
23
  readonly _tag: "KupmiosError";
24
24
  } & Readonly<A>;
25
25
  declare class KupmiosError extends KupmiosError_base<{
@@ -160,7 +160,7 @@ declare class Maestro implements Provider {
160
160
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
161
161
  }
162
162
 
163
- declare const KoiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
163
+ declare const KoiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
164
164
  readonly _tag: "KoiosError";
165
165
  } & Readonly<A>;
166
166
  declare class KoiosError extends KoiosError_base<{
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, Assets, OutputData, UnixTime, Lovelace } from '@lucid-evolution/core-types';
1
+ import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, UnixTime, Assets, OutputData, Lovelace } from '@lucid-evolution/core-types';
2
2
  import * as effect_Cause from 'effect/Cause';
3
3
  import * as effect_Types from 'effect/Types';
4
4
 
@@ -19,7 +19,7 @@ declare class Blockfrost implements Provider {
19
19
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
20
20
  }
21
21
 
22
- declare const KupmiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
22
+ declare const KupmiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
23
23
  readonly _tag: "KupmiosError";
24
24
  } & Readonly<A>;
25
25
  declare class KupmiosError extends KupmiosError_base<{
@@ -160,7 +160,7 @@ declare class Maestro implements Provider {
160
160
  evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
161
161
  }
162
162
 
163
- declare const KoiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
163
+ declare const KoiosError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
164
164
  readonly _tag: "KoiosError";
165
165
  } & Readonly<A>;
166
166
  declare class KoiosError extends KoiosError_base<{
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "@lucid-evolution/provider",
14
- version: "0.1.90",
14
+ version: "0.1.91",
15
15
  description: "",
16
16
  main: "./dist/index.js",
17
17
  types: "./dist/index.d.ts",
@@ -423,6 +423,29 @@ var JSONRPCSchema = (schema) => S.Struct({
423
423
  id: S.NullOr(S.Number),
424
424
  result: schema
425
425
  }).annotations({ identifier: "JSONRPCSchema" });
426
+ var JSONRPCErrorSchema = S.Struct({
427
+ code: S.Number,
428
+ message: S.String,
429
+ data: S.optional(S.Unknown)
430
+ });
431
+ var JSONRPCErrorResponseSchema = S.Struct({
432
+ jsonrpc: S.String,
433
+ method: S.optional(S.String),
434
+ id: S.NullOr(S.Number),
435
+ error: JSONRPCErrorSchema
436
+ });
437
+ var JSONRPCResponseSchema = (schema) => S.Union(JSONRPCSchema(schema), JSONRPCErrorResponseSchema).annotations({
438
+ identifier: "JSONRPCResponseSchema"
439
+ });
440
+ var getJSONRPCResult = (response) => {
441
+ if ("error" in response) {
442
+ const data = response.error.data === void 0 ? "" : `: ${JSON.stringify(response.error.data)}`;
443
+ throw new Error(
444
+ `Ogmios JSON-RPC error ${response.error.code}: ${response.error.message}${data}`
445
+ );
446
+ }
447
+ return response.result;
448
+ };
426
449
  var LovelaceAsset = S.Struct({
427
450
  lovelace: S.Number
428
451
  });
@@ -510,16 +533,38 @@ var ProtocolParametersSchema = S.Struct({
510
533
  maxCollateralInputs: S.Number,
511
534
  version: S.Struct({ major: S.Number, minor: S.Number })
512
535
  }).annotations({ identifier: "ProtocolParametersSchema" });
513
- var Delegation = S.NullOr(
536
+ var RewardAccountAdaSchema = S.Struct({
537
+ ada: LovelaceAsset
538
+ });
539
+ var LegacyDelegationSummarySchema = S.Struct({
540
+ delegate: S.optional(S.NullOr(S.Struct({ id: S.String }))),
541
+ rewards: RewardAccountAdaSchema,
542
+ deposit: RewardAccountAdaSchema
543
+ });
544
+ var RewardAccountSummarySchema = S.Struct({
545
+ from: S.optional(S.Literal("key", "script")),
546
+ credential: S.optional(S.String),
547
+ stakePool: S.optional(S.NullOr(S.Struct({ id: S.String }))),
548
+ rewards: RewardAccountAdaSchema,
549
+ deposit: RewardAccountAdaSchema
550
+ });
551
+ var Delegation = S.Union(
552
+ S.Null,
514
553
  S.Record({
515
554
  key: S.String,
516
- value: S.Struct({
517
- delegate: S.Struct({ id: S.String }),
518
- rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
519
- deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
520
- })
521
- })
555
+ value: LegacyDelegationSummarySchema
556
+ }),
557
+ S.Array(RewardAccountSummarySchema)
522
558
  );
559
+ var toOgmiosQuantity = (amount) => {
560
+ const quantity = Number(amount);
561
+ if (amount < 0n || !Number.isSafeInteger(quantity)) {
562
+ throw new Error(
563
+ `Cannot encode Ogmios quantity ${amount.toString()}. Ogmios expects JSON numbers, so quantities must be non-negative safe integers.`
564
+ );
565
+ }
566
+ return quantity;
567
+ };
523
568
  var RedeemerSchema = S.Struct({
524
569
  validator: S.Struct({
525
570
  purpose: S.Literal(
@@ -569,7 +614,7 @@ var toOgmiosUTxOs = (utxos) => {
569
614
  if (!newAssets[policyId]) {
570
615
  newAssets[policyId] = {};
571
616
  }
572
- return newAssets[policyId][assetName ? assetName : ""] = Number(amount);
617
+ return newAssets[policyId][assetName ? assetName : ""] = toOgmiosQuantity(amount);
573
618
  });
574
619
  return newAssets;
575
620
  };
@@ -581,7 +626,7 @@ var toOgmiosUTxOs = (utxos) => {
581
626
  index: utxo.outputIndex,
582
627
  address: utxo.address,
583
628
  value: {
584
- ada: { lovelace: Number(utxo.assets["lovelace"]) },
629
+ ada: { lovelace: toOgmiosQuantity(utxo.assets["lovelace"]) },
585
630
  ...toOgmiosAssets(utxo.assets)
586
631
  },
587
632
  datumHash: utxo.datumHash,
@@ -593,9 +638,13 @@ var toOgmiosUTxOs = (utxos) => {
593
638
 
594
639
  // src/internal/kupo.ts
595
640
  import { Schema as S2 } from "effect";
641
+ var QuantitySchema = S2.Union(
642
+ S2.Number.pipe(S2.filter(Number.isSafeInteger)),
643
+ S2.String.pipe(S2.pattern(/^\d+$/))
644
+ );
596
645
  var ValueSchema = S2.Struct({
597
- coins: S2.Number,
598
- assets: S2.Record({ key: S2.String, value: S2.Number })
646
+ coins: QuantitySchema,
647
+ assets: S2.Record({ key: S2.String, value: QuantitySchema })
599
648
  });
600
649
  var UTxOSchema = S2.Struct({
601
650
  transaction_index: S2.Number,
@@ -731,8 +780,10 @@ var Kupmios = class {
731
780
  params: {},
732
781
  id: null
733
782
  };
734
- const schema = JSONRPCSchema(ProtocolParametersSchema);
735
- const { result } = await pipe3(
783
+ const schema = JSONRPCResponseSchema(
784
+ ProtocolParametersSchema
785
+ );
786
+ const response = await pipe3(
736
787
  makePostAsJson(
737
788
  this.ogmiosUrl,
738
789
  data,
@@ -744,6 +795,7 @@ var Kupmios = class {
744
795
  Effect2.provide(FetchHttpClient.layer),
745
796
  Effect2.runPromise
746
797
  );
798
+ const result = getJSONRPCResult(response);
747
799
  return toProtocolParameters(result);
748
800
  }
749
801
  async getUtxos(addressOrCredential) {
@@ -753,7 +805,9 @@ var Kupmios = class {
753
805
  const schema = S3.Array(UTxOSchema);
754
806
  const utxos = await pipe3(
755
807
  makeGet(pattern, schema, this.headers?.kupoHeader),
756
- Effect2.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
808
+ Effect2.flatMap(
809
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
810
+ ),
757
811
  Effect2.timeout(1e4),
758
812
  Effect2.catchAll((cause) => new KupmiosError({ cause })),
759
813
  Effect2.provide(FetchHttpClient.layer),
@@ -769,7 +823,9 @@ var Kupmios = class {
769
823
  const schema = S3.Array(UTxOSchema);
770
824
  const utxos = await pipe3(
771
825
  makeGet(pattern, schema, this.headers?.kupoHeader),
772
- Effect2.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
826
+ Effect2.flatMap(
827
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
828
+ ),
773
829
  Effect2.timeout(1e4),
774
830
  Effect2.catchAll((cause) => new KupmiosError({ cause })),
775
831
  Effect2.provide(FetchHttpClient.layer),
@@ -783,12 +839,17 @@ var Kupmios = class {
783
839
  const schema = S3.Array(UTxOSchema);
784
840
  const utxos = await pipe3(
785
841
  makeGet(pattern, schema, this.headers?.kupoHeader),
786
- Effect2.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
842
+ Effect2.flatMap(
843
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
844
+ ),
787
845
  Effect2.timeout(1e4),
788
846
  Effect2.catchAll((cause) => new KupmiosError({ cause })),
789
847
  Effect2.provide(FetchHttpClient.layer),
790
848
  Effect2.runPromise
791
849
  );
850
+ if (utxos.length === 0) {
851
+ throw new Error("Unit not found.");
852
+ }
792
853
  if (utxos.length > 1) {
793
854
  throw new Error("Unit needs to be an NFT or only held by one address.");
794
855
  }
@@ -804,7 +865,9 @@ var Kupmios = class {
804
865
  queryHashes,
805
866
  (txHash) => pipe3(
806
867
  makeGet(mkPattern(txHash), schema, this.headers?.kupoHeader),
807
- Effect2.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
868
+ Effect2.flatMap(
869
+ (u) => kupmiosUtxosToUtxos(this.kupoUrl, u, this.headers?.kupoHeader)
870
+ ),
808
871
  Effect2.timeout(1e4),
809
872
  Effect2.catchAll((cause) => new KupmiosError({ cause }))
810
873
  )
@@ -825,8 +888,8 @@ var Kupmios = class {
825
888
  params: { keys: [rewardAddress] },
826
889
  id: null
827
890
  };
828
- const schema = JSONRPCSchema(Delegation);
829
- const { result } = await pipe3(
891
+ const schema = JSONRPCResponseSchema(Delegation);
892
+ const response = await pipe3(
830
893
  makePostAsJson(
831
894
  this.ogmiosUrl,
832
895
  data,
@@ -838,11 +901,8 @@ var Kupmios = class {
838
901
  Effect2.catchAll((cause) => new KupmiosError({ cause })),
839
902
  Effect2.runPromise
840
903
  );
841
- const delegation = result ? Object.values(result)[0] : null;
842
- return {
843
- poolId: delegation?.delegate?.id || null,
844
- rewards: BigInt(delegation?.rewards?.ada?.lovelace || 0)
845
- };
904
+ const result = getJSONRPCResult(response);
905
+ return toDelegation(result);
846
906
  }
847
907
  async getDatum(datumHash) {
848
908
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
@@ -885,14 +945,14 @@ var Kupmios = class {
885
945
  },
886
946
  id: null
887
947
  };
888
- const schema = JSONRPCSchema(
948
+ const schema = JSONRPCResponseSchema(
889
949
  S3.Struct({
890
950
  transaction: S3.Struct({
891
951
  id: S3.String
892
952
  })
893
953
  })
894
954
  );
895
- const { result } = await pipe3(
955
+ const response = await pipe3(
896
956
  makePostAsJson(
897
957
  this.ogmiosUrl,
898
958
  data,
@@ -904,6 +964,7 @@ var Kupmios = class {
904
964
  Effect2.catchAll((cause) => new KupmiosError({ cause })),
905
965
  Effect2.runPromise
906
966
  );
967
+ const result = getJSONRPCResult(response);
907
968
  return result.transaction.id;
908
969
  }
909
970
  async evaluateTx(tx, additionalUTxOs) {
@@ -916,8 +977,8 @@ var Kupmios = class {
916
977
  },
917
978
  id: null
918
979
  };
919
- const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
920
- const { result } = await pipe3(
980
+ const schema = JSONRPCResponseSchema(S3.Array(RedeemerSchema));
981
+ const response = await pipe3(
921
982
  makePostAsJson(
922
983
  this.ogmiosUrl,
923
984
  data,
@@ -929,6 +990,7 @@ var Kupmios = class {
929
990
  Effect2.catchAll((cause) => new KupmiosError({ cause })),
930
991
  Effect2.runPromise
931
992
  );
993
+ const result = getJSONRPCResult(response);
932
994
  const evalRedeemers = result.map((item) => ({
933
995
  ex_units: {
934
996
  mem: item.budget.memory,
@@ -1045,6 +1107,19 @@ var toProtocolParameters = (result) => {
1045
1107
  }
1046
1108
  };
1047
1109
  };
1110
+ var toDelegation = (result) => {
1111
+ if (!result) {
1112
+ return { poolId: null, rewards: 0n };
1113
+ }
1114
+ const delegation = Array.isArray(result) ? result[0] : Object.values(result)[0];
1115
+ if (!delegation) {
1116
+ return { poolId: null, rewards: 0n };
1117
+ }
1118
+ return {
1119
+ poolId: "stakePool" in delegation ? delegation.stakePool?.id || null : delegation.delegate?.id || null,
1120
+ rewards: BigInt(delegation.rewards.ada.lovelace)
1121
+ };
1122
+ };
1048
1123
  var kupmiosUtxosToUtxos = (kupoURL, utxos, kupoHeader) => Effect2.forEach(
1049
1124
  utxos,
1050
1125
  (utxo) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/provider",
3
- "version": "0.1.90",
3
+ "version": "0.1.91",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "@effect/schema": "^0.68.26",
32
32
  "effect": "^3.11.7",
33
33
  "@lucid-evolution/core-types": "0.1.22",
34
- "@lucid-evolution/core-utils": "0.1.16",
35
34
  "@lucid-evolution/utils": "0.1.66",
35
+ "@lucid-evolution/core-utils": "0.1.16",
36
36
  "@lucid-evolution/wallet": "0.1.72"
37
37
  },
38
38
  "devDependencies": {