@lucid-evolution/provider 0.1.94 → 0.1.96

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.94",
55
+ version: "0.1.96",
56
56
  description: "",
57
57
  main: "./dist/index.js",
58
58
  types: "./dist/index.d.ts",
@@ -82,8 +82,8 @@ var package_default = {
82
82
  "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
83
83
  },
84
84
  dependencies: {
85
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-3",
86
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-3",
85
+ "@anastasia-labs/cardano-multiplatform-lib-browser": "6.2.0-1",
86
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.2.0-1",
87
87
  "@effect/platform": "^0.71.3",
88
88
  "@effect/schema": "^0.68.26",
89
89
  "@lucid-evolution/core-types": "workspace:*",
@@ -111,8 +111,8 @@ var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
111
111
  {
112
112
  address: utxo.address,
113
113
  value: {
114
- coins: Number(utxo.assets["lovelace"]),
115
- assets: fromAssets(utxo.assets)
114
+ ada: { lovelace: Number(utxo.assets["lovelace"]) },
115
+ ...fromAssets(utxo.assets)
116
116
  },
117
117
  datumHash: utxo.datumHash,
118
118
  datum: utxo.datum,
@@ -133,14 +133,16 @@ var toTxOutScript = (scriptRef) => {
133
133
  }
134
134
  }
135
135
  };
136
- var fromAssets = (assets) => (0, import_effect.pipe)(
137
- import_effect.Record.remove(assets, "lovelace"),
138
- import_effect.Record.mapEntries((amount, unit) => [
139
- unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
140
- Number(amount)
141
- ]),
142
- (r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
143
- );
136
+ var fromAssets = (assets) => (0, import_effect.pipe)(import_effect.Record.remove(assets, "lovelace"), (nativeAssets) => {
137
+ const result = {};
138
+ for (const [unit, amount] of Object.entries(nativeAssets)) {
139
+ const policyId = unit.slice(0, 56);
140
+ const assetName = unit.slice(56);
141
+ result[policyId] ??= {};
142
+ result[policyId][assetName] = Number(amount);
143
+ }
144
+ return result;
145
+ });
144
146
  var fromLegacyRedeemerTag = (redeemerTag) => {
145
147
  switch (redeemerTag) {
146
148
  case "certificate":
@@ -153,6 +155,15 @@ var fromLegacyRedeemerTag = (redeemerTag) => {
153
155
  };
154
156
 
155
157
  // src/blockfrost.ts
158
+ var toBlockfrostQueryPredicate = (addressOrCredential) => {
159
+ if (typeof addressOrCredential === "string") return addressOrCredential;
160
+ if (addressOrCredential.type === "Key") {
161
+ return CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
162
+ "addr_vkh"
163
+ );
164
+ }
165
+ return CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32("script");
166
+ };
156
167
  var Blockfrost = class {
157
168
  url;
158
169
  projectId;
@@ -165,6 +176,8 @@ var Blockfrost = class {
165
176
  headers: { project_id: this.projectId, lucid }
166
177
  }).then((res) => res.json());
167
178
  return {
179
+ protocolMajorVersion: parseInt(result.protocol_major_ver),
180
+ protocolMinorVersion: parseInt(result.protocol_minor_ver),
168
181
  minFeeA: parseInt(result.min_fee_a),
169
182
  minFeeB: parseInt(result.min_fee_b),
170
183
  maxTxSize: parseInt(result.max_tx_size),
@@ -186,16 +199,17 @@ var Blockfrost = class {
186
199
  costModels: result.cost_models_raw
187
200
  };
188
201
  }
202
+ async getTreasury() {
203
+ const result = await fetch(`${this.url}/network`, {
204
+ headers: { project_id: this.projectId, lucid }
205
+ }).then((res) => res.json());
206
+ if (!result || result.error || result.supply?.treasury === void 0) {
207
+ throw new Error("Could not fetch treasury amount from Blockfrost.");
208
+ }
209
+ return BigInt(result.supply.treasury);
210
+ }
189
211
  async getUtxos(addressOrCredential) {
190
- const queryPredicate = (() => {
191
- if (typeof addressOrCredential === "string") return addressOrCredential;
192
- const credentialBech32 = addressOrCredential.type === "Key" ? CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
193
- "addr_vkh"
194
- ) : CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32(
195
- "addr_vkh"
196
- );
197
- return credentialBech32;
198
- })();
212
+ const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
199
213
  let result = [];
200
214
  let page = 1;
201
215
  while (true) {
@@ -217,15 +231,7 @@ var Blockfrost = class {
217
231
  return this.blockfrostUtxosToUtxos(result);
218
232
  }
219
233
  async getUtxosWithUnit(addressOrCredential, unit) {
220
- const queryPredicate = (() => {
221
- if (typeof addressOrCredential === "string") return addressOrCredential;
222
- const credentialBech32 = addressOrCredential.type === "Key" ? CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
223
- "addr_vkh"
224
- ) : CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32(
225
- "addr_vkh"
226
- );
227
- return credentialBech32;
228
- })();
234
+ const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
229
235
  let result = [];
230
236
  let page = 1;
231
237
  while (true) {
@@ -402,29 +408,33 @@ var Blockfrost = class {
402
408
  return utxos;
403
409
  }
404
410
  async evaluateTx(tx, additionalUTxOs) {
405
- const payload = {
406
- cbor: tx,
407
- additionalUtxoSet: toAditionalUTXOs(additionalUTxOs)
411
+ const evaluate = async (utxos) => {
412
+ const payload = {
413
+ cbor: tx,
414
+ ...utxos?.length ? { additionalUtxoSet: toAditionalUTXOs(utxos) } : {}
415
+ };
416
+ const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
417
+ method: "POST",
418
+ headers: {
419
+ "Content-Type": "application/json",
420
+ project_id: this.projectId,
421
+ lucid
422
+ },
423
+ body: JSON.stringify(payload)
424
+ }).then((res2) => res2.json());
425
+ if (!res || res.fault) {
426
+ const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}. Transaction: ${tx}`;
427
+ throw new Error(message);
428
+ }
429
+ const blockfrostRedeemer2 = res;
430
+ if (!("EvaluationResult" in blockfrostRedeemer2.result)) {
431
+ throw new Error(
432
+ `EvaluateTransaction fails: ${JSON.stringify(blockfrostRedeemer2.result)}`
433
+ );
434
+ }
435
+ return blockfrostRedeemer2;
408
436
  };
409
- const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
410
- method: "POST",
411
- headers: {
412
- "Content-Type": "application/json",
413
- project_id: this.projectId,
414
- lucid
415
- },
416
- body: JSON.stringify(payload)
417
- }).then((res2) => res2.json());
418
- if (!res || res.fault) {
419
- const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}. Transaction: ${tx}`;
420
- throw new Error(message);
421
- }
422
- const blockfrostRedeemer = res;
423
- if (!("EvaluationResult" in blockfrostRedeemer.result)) {
424
- throw new Error(
425
- `EvaluateTransaction fails: ${JSON.stringify(blockfrostRedeemer.result)}`
426
- );
427
- }
437
+ const blockfrostRedeemer = additionalUTxOs?.length ? await evaluate().catch(() => evaluate(additionalUTxOs)) : await evaluate();
428
438
  const evalRedeemers = [];
429
439
  Object.entries(blockfrostRedeemer.result.EvaluationResult).forEach(
430
440
  ([redeemerPointer, data]) => {
@@ -490,6 +500,29 @@ var getJSONRPCResult = (response) => {
490
500
  var LovelaceAsset = import_effect2.Schema.Struct({
491
501
  lovelace: import_effect2.Schema.Number
492
502
  });
503
+ var LovelaceAmount = import_effect2.Schema.Union(import_effect2.Schema.Number, import_effect2.Schema.String, import_effect2.Schema.BigInt);
504
+ var TreasuryAndReservesSchema = import_effect2.Schema.Struct({
505
+ treasury: import_effect2.Schema.Struct({
506
+ ada: import_effect2.Schema.Struct({
507
+ lovelace: LovelaceAmount
508
+ })
509
+ }),
510
+ reserves: import_effect2.Schema.Struct({
511
+ ada: import_effect2.Schema.Struct({
512
+ lovelace: LovelaceAmount
513
+ })
514
+ })
515
+ });
516
+ var lovelaceAmountToBigInt = (lovelace) => {
517
+ if (typeof lovelace === "bigint") return lovelace;
518
+ if (typeof lovelace === "string") return BigInt(lovelace);
519
+ if (!Number.isSafeInteger(lovelace)) {
520
+ throw new Error(
521
+ `Cannot decode Ogmios lovelace amount ${lovelace}; number is outside the safe integer range.`
522
+ );
523
+ }
524
+ return BigInt(lovelace);
525
+ };
493
526
  var TupleNumberFromString = import_effect2.Schema.compose(
494
527
  import_effect2.Schema.split("/"),
495
528
  import_effect2.Schema.Array(import_effect2.Schema.NumberFromString)
@@ -834,6 +867,31 @@ var Kupmios = class {
834
867
  const result = getJSONRPCResult(response);
835
868
  return toProtocolParameters(result);
836
869
  }
870
+ async getTreasury() {
871
+ const data = {
872
+ jsonrpc: "2.0",
873
+ method: "queryLedgerState/treasuryAndReserves",
874
+ params: {},
875
+ id: null
876
+ };
877
+ const schema = JSONRPCResponseSchema(
878
+ TreasuryAndReservesSchema
879
+ );
880
+ const response = await (0, import_effect6.pipe)(
881
+ makePostAsJson(
882
+ this.ogmiosUrl,
883
+ data,
884
+ schema,
885
+ this.headers?.ogmiosHeader
886
+ ),
887
+ import_effect6.Effect.timeout(1e4),
888
+ import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
889
+ import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
890
+ import_effect6.Effect.runPromise
891
+ );
892
+ const result = getJSONRPCResult(response);
893
+ return lovelaceAmountToBigInt(result.treasury.ada.lovelace);
894
+ }
837
895
  async getUtxos(addressOrCredential) {
838
896
  const isAddress = typeof addressOrCredential === "string";
839
897
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
@@ -1211,7 +1269,8 @@ var Emulator = class {
1211
1269
  time;
1212
1270
  protocolParameters;
1213
1271
  datumTable = {};
1214
- constructor(accounts, protocolParameters = import_utils5.PROTOCOL_PARAMETERS_DEFAULT) {
1272
+ treasury;
1273
+ constructor(accounts, protocolParameters = import_utils5.PROTOCOL_PARAMETERS_DEFAULT, treasury = 0n) {
1215
1274
  const GENESIS_HASH = "00".repeat(32);
1216
1275
  this.blockHeight = 0;
1217
1276
  this.slot = 0;
@@ -1241,6 +1300,7 @@ var Emulator = class {
1241
1300
  };
1242
1301
  });
1243
1302
  this.protocolParameters = protocolParameters;
1303
+ this.treasury = treasury;
1244
1304
  }
1245
1305
  now() {
1246
1306
  return this.time;
@@ -1286,6 +1346,9 @@ var Emulator = class {
1286
1346
  getProtocolParameters() {
1287
1347
  return Promise.resolve(this.protocolParameters);
1288
1348
  }
1349
+ getTreasury() {
1350
+ return Promise.resolve(this.treasury);
1351
+ }
1289
1352
  getDatum(datumHash) {
1290
1353
  return Promise.resolve(this.datumTable[datumHash]);
1291
1354
  }
@@ -1368,6 +1431,23 @@ var Emulator = class {
1368
1431
  `Upper bound (${upperBound}) not in slot range (${this.slot}).`
1369
1432
  );
1370
1433
  }
1434
+ const currentTreasuryValue = body.current_treasury_value();
1435
+ const treasuryDonation = body.donation();
1436
+ if (currentTreasuryValue === void 0 && treasuryDonation !== void 0 || currentTreasuryValue !== void 0 && treasuryDonation === void 0) {
1437
+ throw new Error(
1438
+ "Treasury donation transactions must include both current treasury value and donation."
1439
+ );
1440
+ }
1441
+ if (treasuryDonation !== void 0) {
1442
+ if (treasuryDonation <= 0n) {
1443
+ throw new Error("Treasury donation must be greater than 0 lovelace.");
1444
+ }
1445
+ if (currentTreasuryValue !== this.treasury) {
1446
+ throw new Error(
1447
+ `Current treasury value (${currentTreasuryValue}) does not match emulator treasury (${this.treasury}).`
1448
+ );
1449
+ }
1450
+ }
1371
1451
  const datumTable = (() => {
1372
1452
  const table = {};
1373
1453
  for (let i = 0; i < (datums?.len() || 0); i++) {
@@ -1660,6 +1740,12 @@ It does not exist or was already spent.`
1660
1740
  withdrawalRequests.push({ rewardAddress, withdrawal });
1661
1741
  }
1662
1742
  const certRequests = [];
1743
+ const credentialToCore = (credential) => credential.kind() === 0 ? { type: "Key", hash: credential.as_pub_key().to_hex() } : { type: "Script", hash: credential.as_script().to_hex() };
1744
+ const checkCertCredential = (credential, index) => {
1745
+ if (!credential) return;
1746
+ checkAndConsumeHash(credentialToCore(credential), "Cert", index);
1747
+ };
1748
+ const rewardAddressFromCredential = (credential) => CML.RewardAddress.new(CML.NetworkInfo.testnet().network_id(), credential).to_address().to_bech32(void 0);
1663
1749
  for (let index = 0; index < (body.certs()?.len() || 0); index++) {
1664
1750
  const cert = body.certs().get(index);
1665
1751
  switch (cert.kind()) {
@@ -1728,6 +1814,166 @@ It does not exist or was already spent.`
1728
1814
  certRequests.push({ type: "Delegation", rewardAddress, poolId });
1729
1815
  break;
1730
1816
  }
1817
+ case CML.CertificateKind.PoolRegistration: {
1818
+ const poolParams = cert.as_pool_registration()?.pool_params();
1819
+ if (!poolParams) break;
1820
+ checkAndConsumeHash(
1821
+ { type: "Key", hash: poolParams.operator().to_hex() },
1822
+ "Cert",
1823
+ index
1824
+ );
1825
+ const owners = poolParams.pool_owners();
1826
+ for (let ownerIndex = 0; ownerIndex < owners.len(); ownerIndex++) {
1827
+ checkAndConsumeHash(
1828
+ { type: "Key", hash: owners.get(ownerIndex).to_hex() },
1829
+ "Cert",
1830
+ index
1831
+ );
1832
+ }
1833
+ break;
1834
+ }
1835
+ case CML.CertificateKind.PoolRetirement: {
1836
+ const pool = cert.as_pool_retirement()?.pool();
1837
+ if (pool) {
1838
+ checkAndConsumeHash(
1839
+ { type: "Key", hash: pool.to_hex() },
1840
+ "Cert",
1841
+ index
1842
+ );
1843
+ }
1844
+ break;
1845
+ }
1846
+ case CML.CertificateKind.UnregCert: {
1847
+ const deregistration = cert.as_unreg_cert()?.stake_credential();
1848
+ checkCertCredential(deregistration, index);
1849
+ if (deregistration) {
1850
+ const rewardAddress = rewardAddressFromCredential(deregistration);
1851
+ if (!this.chain[rewardAddress]?.registeredStake) {
1852
+ throw new Error(
1853
+ `Stake key is already deregistered. Reward address: ${rewardAddress}`
1854
+ );
1855
+ }
1856
+ certRequests.push({ type: "Deregistration", rewardAddress });
1857
+ }
1858
+ break;
1859
+ }
1860
+ case CML.CertificateKind.VoteDelegCert: {
1861
+ const credential = cert.as_vote_deleg_cert()?.stake_credential();
1862
+ checkCertCredential(credential, index);
1863
+ if (credential) {
1864
+ const rewardAddress = rewardAddressFromCredential(credential);
1865
+ if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1866
+ (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
1867
+ )) {
1868
+ throw new Error(
1869
+ `Stake key is not registered. Reward address: ${rewardAddress}`
1870
+ );
1871
+ }
1872
+ }
1873
+ break;
1874
+ }
1875
+ case CML.CertificateKind.StakeVoteDelegCert: {
1876
+ const delegation = cert.as_stake_vote_deleg_cert();
1877
+ const credential = delegation?.stake_credential();
1878
+ checkCertCredential(credential, index);
1879
+ if (delegation && credential) {
1880
+ const rewardAddress = rewardAddressFromCredential(credential);
1881
+ const poolId = delegation.pool().to_bech32("pool");
1882
+ if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1883
+ (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
1884
+ )) {
1885
+ throw new Error(
1886
+ `Stake key is not registered. Reward address: ${rewardAddress}`
1887
+ );
1888
+ }
1889
+ certRequests.push({ type: "Delegation", rewardAddress, poolId });
1890
+ }
1891
+ break;
1892
+ }
1893
+ case CML.CertificateKind.StakeRegDelegCert: {
1894
+ const registration = cert.as_stake_reg_deleg_cert();
1895
+ const credential = registration?.stake_credential();
1896
+ checkCertCredential(credential, index);
1897
+ if (registration && credential) {
1898
+ const rewardAddress = rewardAddressFromCredential(credential);
1899
+ const poolId = registration.pool().to_bech32("pool");
1900
+ if (this.chain[rewardAddress]?.registeredStake) {
1901
+ throw new Error(
1902
+ `Stake key is already registered. Reward address: ${rewardAddress}`
1903
+ );
1904
+ }
1905
+ certRequests.push({ type: "Registration", rewardAddress });
1906
+ certRequests.push({ type: "Delegation", rewardAddress, poolId });
1907
+ }
1908
+ break;
1909
+ }
1910
+ case CML.CertificateKind.VoteRegDelegCert: {
1911
+ const registration = cert.as_vote_reg_deleg_cert();
1912
+ const credential = registration?.stake_credential();
1913
+ checkCertCredential(credential, index);
1914
+ if (credential) {
1915
+ const rewardAddress = rewardAddressFromCredential(credential);
1916
+ if (this.chain[rewardAddress]?.registeredStake) {
1917
+ throw new Error(
1918
+ `Stake key is already registered. Reward address: ${rewardAddress}`
1919
+ );
1920
+ }
1921
+ certRequests.push({ type: "Registration", rewardAddress });
1922
+ }
1923
+ break;
1924
+ }
1925
+ case CML.CertificateKind.StakeVoteRegDelegCert: {
1926
+ const registration = cert.as_stake_vote_reg_deleg_cert();
1927
+ const credential = registration?.stake_credential();
1928
+ checkCertCredential(credential, index);
1929
+ if (registration && credential) {
1930
+ const rewardAddress = rewardAddressFromCredential(credential);
1931
+ const poolId = registration.pool().to_bech32("pool");
1932
+ if (this.chain[rewardAddress]?.registeredStake) {
1933
+ throw new Error(
1934
+ `Stake key is already registered. Reward address: ${rewardAddress}`
1935
+ );
1936
+ }
1937
+ certRequests.push({ type: "Registration", rewardAddress });
1938
+ certRequests.push({ type: "Delegation", rewardAddress, poolId });
1939
+ }
1940
+ break;
1941
+ }
1942
+ case CML.CertificateKind.AuthCommitteeHotCert: {
1943
+ checkCertCredential(
1944
+ cert.as_auth_committee_hot_cert()?.committee_cold_credential(),
1945
+ index
1946
+ );
1947
+ break;
1948
+ }
1949
+ case CML.CertificateKind.ResignCommitteeColdCert: {
1950
+ checkCertCredential(
1951
+ cert.as_resign_committee_cold_cert()?.committee_cold_credential(),
1952
+ index
1953
+ );
1954
+ break;
1955
+ }
1956
+ case CML.CertificateKind.RegDrepCert: {
1957
+ checkCertCredential(
1958
+ cert.as_reg_drep_cert()?.drep_credential(),
1959
+ index
1960
+ );
1961
+ break;
1962
+ }
1963
+ case CML.CertificateKind.UnregDrepCert: {
1964
+ checkCertCredential(
1965
+ cert.as_unreg_drep_cert()?.drep_credential(),
1966
+ index
1967
+ );
1968
+ break;
1969
+ }
1970
+ case CML.CertificateKind.UpdateDrepCert: {
1971
+ checkCertCredential(
1972
+ cert.as_update_drep_cert()?.drep_credential(),
1973
+ index
1974
+ );
1975
+ break;
1976
+ }
1731
1977
  }
1732
1978
  }
1733
1979
  resolvedInputs.forEach(({ entry: { utxo } }, index) => {
@@ -1791,6 +2037,9 @@ It does not exist or was already spent.`
1791
2037
  withdrawalRequests.forEach(({ rewardAddress, withdrawal }) => {
1792
2038
  this.chain[rewardAddress].delegation.rewards -= withdrawal;
1793
2039
  });
2040
+ if (treasuryDonation !== void 0) {
2041
+ this.treasury += treasuryDonation;
2042
+ }
1794
2043
  certRequests.forEach(({ type, rewardAddress, poolId }) => {
1795
2044
  switch (type) {
1796
2045
  case "Registration": {
@@ -1984,6 +2233,11 @@ var Maestro = class {
1984
2233
  }
1985
2234
  };
1986
2235
  }
2236
+ async getTreasury() {
2237
+ throw new Error(
2238
+ "Maestro does not expose a current treasury query. Pass currentTreasuryValue explicitly to donateToTreasury."
2239
+ );
2240
+ }
1987
2241
  async getUtxosInternal(addressOrCredential, unit) {
1988
2242
  const queryPredicate = (() => {
1989
2243
  if (typeof addressOrCredential === "string") {
@@ -2310,6 +2564,9 @@ var ProtocolParametersSchema2 = import_effect7.Schema.Struct({
2310
2564
  max_collateral_inputs: import_effect7.Schema.Number,
2311
2565
  coins_per_utxo_size: import_effect7.Schema.BigInt
2312
2566
  });
2567
+ var TotalsSchema = import_effect7.Schema.Struct({
2568
+ treasury: import_effect7.Schema.String
2569
+ });
2313
2570
  var AssetSchema = import_effect7.Schema.Struct({
2314
2571
  policy_id: import_effect7.Schema.String,
2315
2572
  asset_name: import_effect7.Schema.NullOr(import_effect7.Schema.String),
@@ -2584,6 +2841,22 @@ var Koios = class {
2584
2841
  }
2585
2842
  };
2586
2843
  }
2844
+ async getTreasury() {
2845
+ const url = `${this.baseUrl}/totals?order=epoch_no.desc&limit=1`;
2846
+ const schema = import_effect8.Schema.Array(TotalsSchema);
2847
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2848
+ const [result] = await (0, import_effect8.pipe)(
2849
+ makeGet(url, schema, bearerToken),
2850
+ import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
2851
+ import_effect8.Effect.flatMap(
2852
+ (result2) => result2.length === 0 ? import_effect8.Effect.fail("No totals found") : import_effect8.Effect.succeed(result2)
2853
+ ),
2854
+ import_effect8.Effect.timeout(1e4),
2855
+ import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2856
+ import_effect8.Effect.runPromise
2857
+ );
2858
+ return BigInt(result.treasury);
2859
+ }
2587
2860
  async getUtxos(addressOrCredential) {
2588
2861
  const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2589
2862
  const result = await (0, import_effect8.pipe)(
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, UnixTime, Assets, OutputData, Lovelace } from '@lucid-evolution/core-types';
1
+ import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, UnixTime, Lovelace, Assets, OutputData } 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
 
@@ -7,6 +7,7 @@ declare class Blockfrost implements Provider {
7
7
  projectId: string;
8
8
  constructor(url: string, projectId?: string);
9
9
  getProtocolParameters(): Promise<ProtocolParameters>;
10
+ getTreasury(): Promise<bigint>;
10
11
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
11
12
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
12
13
  getUtxoByUnit(unit: Unit): Promise<UTxO>;
@@ -66,6 +67,7 @@ declare class Kupmios implements Provider {
66
67
  kupoHeader?: Record<string, string>;
67
68
  });
68
69
  getProtocolParameters(): Promise<ProtocolParameters>;
70
+ getTreasury(): Promise<bigint>;
69
71
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
70
72
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
71
73
  getUtxoByUnit(unit: Unit): Promise<UTxO>;
@@ -110,12 +112,14 @@ declare class Emulator implements Provider {
110
112
  time: UnixTime;
111
113
  protocolParameters: ProtocolParameters;
112
114
  datumTable: Record<DatumHash, Datum>;
113
- constructor(accounts: EmulatorAccount[], protocolParameters?: ProtocolParameters);
115
+ treasury: Lovelace;
116
+ constructor(accounts: EmulatorAccount[], protocolParameters?: ProtocolParameters, treasury?: Lovelace);
114
117
  now(): UnixTime;
115
118
  awaitSlot(length?: number): void;
116
119
  awaitBlock(height?: number): void;
117
120
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
118
121
  getProtocolParameters(): Promise<ProtocolParameters>;
122
+ getTreasury(): Promise<bigint>;
119
123
  getDatum(datumHash: DatumHash): Promise<Datum>;
120
124
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
121
125
  getUtxosByOutRef(outRefs: OutRef[]): Promise<UTxO[]>;
@@ -144,6 +148,7 @@ declare class Maestro implements Provider {
144
148
  turboSubmit: boolean;
145
149
  constructor({ network, apiKey, turboSubmit }: MaestroConfig);
146
150
  getProtocolParameters(): Promise<ProtocolParameters>;
151
+ getTreasury(): Promise<bigint>;
147
152
  private getUtxosInternal;
148
153
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
149
154
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
@@ -201,6 +206,7 @@ declare class Koios implements Provider {
201
206
  private readonly token?;
202
207
  constructor(baseUrl: string, token?: string);
203
208
  getProtocolParameters(): Promise<ProtocolParameters>;
209
+ getTreasury(): Promise<bigint>;
204
210
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
205
211
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
206
212
  getUtxoByUnit(unit: Unit): Promise<UTxO>;
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, UnixTime, Assets, OutputData, Lovelace } from '@lucid-evolution/core-types';
1
+ import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, UnixTime, Lovelace, Assets, OutputData } 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
 
@@ -7,6 +7,7 @@ declare class Blockfrost implements Provider {
7
7
  projectId: string;
8
8
  constructor(url: string, projectId?: string);
9
9
  getProtocolParameters(): Promise<ProtocolParameters>;
10
+ getTreasury(): Promise<bigint>;
10
11
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
11
12
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
12
13
  getUtxoByUnit(unit: Unit): Promise<UTxO>;
@@ -66,6 +67,7 @@ declare class Kupmios implements Provider {
66
67
  kupoHeader?: Record<string, string>;
67
68
  });
68
69
  getProtocolParameters(): Promise<ProtocolParameters>;
70
+ getTreasury(): Promise<bigint>;
69
71
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
70
72
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
71
73
  getUtxoByUnit(unit: Unit): Promise<UTxO>;
@@ -110,12 +112,14 @@ declare class Emulator implements Provider {
110
112
  time: UnixTime;
111
113
  protocolParameters: ProtocolParameters;
112
114
  datumTable: Record<DatumHash, Datum>;
113
- constructor(accounts: EmulatorAccount[], protocolParameters?: ProtocolParameters);
115
+ treasury: Lovelace;
116
+ constructor(accounts: EmulatorAccount[], protocolParameters?: ProtocolParameters, treasury?: Lovelace);
114
117
  now(): UnixTime;
115
118
  awaitSlot(length?: number): void;
116
119
  awaitBlock(height?: number): void;
117
120
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
118
121
  getProtocolParameters(): Promise<ProtocolParameters>;
122
+ getTreasury(): Promise<bigint>;
119
123
  getDatum(datumHash: DatumHash): Promise<Datum>;
120
124
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
121
125
  getUtxosByOutRef(outRefs: OutRef[]): Promise<UTxO[]>;
@@ -144,6 +148,7 @@ declare class Maestro implements Provider {
144
148
  turboSubmit: boolean;
145
149
  constructor({ network, apiKey, turboSubmit }: MaestroConfig);
146
150
  getProtocolParameters(): Promise<ProtocolParameters>;
151
+ getTreasury(): Promise<bigint>;
147
152
  private getUtxosInternal;
148
153
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
149
154
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
@@ -201,6 +206,7 @@ declare class Koios implements Provider {
201
206
  private readonly token?;
202
207
  constructor(baseUrl: string, token?: string);
203
208
  getProtocolParameters(): Promise<ProtocolParameters>;
209
+ getTreasury(): Promise<bigint>;
204
210
  getUtxos(addressOrCredential: Address | Credential): Promise<UTxO[]>;
205
211
  getUtxosWithUnit(addressOrCredential: Address | Credential, unit: Unit): Promise<UTxO[]>;
206
212
  getUtxoByUnit(unit: Unit): Promise<UTxO>;
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.94",
14
+ version: "0.1.96",
15
15
  description: "",
16
16
  main: "./dist/index.js",
17
17
  types: "./dist/index.d.ts",
@@ -41,8 +41,8 @@ var package_default = {
41
41
  "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
42
42
  },
43
43
  dependencies: {
44
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-3",
45
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-3",
44
+ "@anastasia-labs/cardano-multiplatform-lib-browser": "6.2.0-1",
45
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.2.0-1",
46
46
  "@effect/platform": "^0.71.3",
47
47
  "@effect/schema": "^0.68.26",
48
48
  "@lucid-evolution/core-types": "workspace:*",
@@ -70,8 +70,8 @@ var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
70
70
  {
71
71
  address: utxo.address,
72
72
  value: {
73
- coins: Number(utxo.assets["lovelace"]),
74
- assets: fromAssets(utxo.assets)
73
+ ada: { lovelace: Number(utxo.assets["lovelace"]) },
74
+ ...fromAssets(utxo.assets)
75
75
  },
76
76
  datumHash: utxo.datumHash,
77
77
  datum: utxo.datum,
@@ -92,14 +92,16 @@ var toTxOutScript = (scriptRef) => {
92
92
  }
93
93
  }
94
94
  };
95
- var fromAssets = (assets) => pipe(
96
- Record.remove(assets, "lovelace"),
97
- Record.mapEntries((amount, unit) => [
98
- unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
99
- Number(amount)
100
- ]),
101
- (r) => Record.isEmptyRecord(r) ? void 0 : r
102
- );
95
+ var fromAssets = (assets) => pipe(Record.remove(assets, "lovelace"), (nativeAssets) => {
96
+ const result = {};
97
+ for (const [unit, amount] of Object.entries(nativeAssets)) {
98
+ const policyId = unit.slice(0, 56);
99
+ const assetName = unit.slice(56);
100
+ result[policyId] ??= {};
101
+ result[policyId][assetName] = Number(amount);
102
+ }
103
+ return result;
104
+ });
103
105
  var fromLegacyRedeemerTag = (redeemerTag) => {
104
106
  switch (redeemerTag) {
105
107
  case "certificate":
@@ -112,6 +114,15 @@ var fromLegacyRedeemerTag = (redeemerTag) => {
112
114
  };
113
115
 
114
116
  // src/blockfrost.ts
117
+ var toBlockfrostQueryPredicate = (addressOrCredential) => {
118
+ if (typeof addressOrCredential === "string") return addressOrCredential;
119
+ if (addressOrCredential.type === "Key") {
120
+ return CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
121
+ "addr_vkh"
122
+ );
123
+ }
124
+ return CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32("script");
125
+ };
115
126
  var Blockfrost = class {
116
127
  url;
117
128
  projectId;
@@ -124,6 +135,8 @@ var Blockfrost = class {
124
135
  headers: { project_id: this.projectId, lucid }
125
136
  }).then((res) => res.json());
126
137
  return {
138
+ protocolMajorVersion: parseInt(result.protocol_major_ver),
139
+ protocolMinorVersion: parseInt(result.protocol_minor_ver),
127
140
  minFeeA: parseInt(result.min_fee_a),
128
141
  minFeeB: parseInt(result.min_fee_b),
129
142
  maxTxSize: parseInt(result.max_tx_size),
@@ -145,16 +158,17 @@ var Blockfrost = class {
145
158
  costModels: result.cost_models_raw
146
159
  };
147
160
  }
161
+ async getTreasury() {
162
+ const result = await fetch(`${this.url}/network`, {
163
+ headers: { project_id: this.projectId, lucid }
164
+ }).then((res) => res.json());
165
+ if (!result || result.error || result.supply?.treasury === void 0) {
166
+ throw new Error("Could not fetch treasury amount from Blockfrost.");
167
+ }
168
+ return BigInt(result.supply.treasury);
169
+ }
148
170
  async getUtxos(addressOrCredential) {
149
- const queryPredicate = (() => {
150
- if (typeof addressOrCredential === "string") return addressOrCredential;
151
- const credentialBech32 = addressOrCredential.type === "Key" ? CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
152
- "addr_vkh"
153
- ) : CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32(
154
- "addr_vkh"
155
- );
156
- return credentialBech32;
157
- })();
171
+ const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
158
172
  let result = [];
159
173
  let page = 1;
160
174
  while (true) {
@@ -176,15 +190,7 @@ var Blockfrost = class {
176
190
  return this.blockfrostUtxosToUtxos(result);
177
191
  }
178
192
  async getUtxosWithUnit(addressOrCredential, unit) {
179
- const queryPredicate = (() => {
180
- if (typeof addressOrCredential === "string") return addressOrCredential;
181
- const credentialBech32 = addressOrCredential.type === "Key" ? CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
182
- "addr_vkh"
183
- ) : CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32(
184
- "addr_vkh"
185
- );
186
- return credentialBech32;
187
- })();
193
+ const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
188
194
  let result = [];
189
195
  let page = 1;
190
196
  while (true) {
@@ -361,29 +367,33 @@ var Blockfrost = class {
361
367
  return utxos;
362
368
  }
363
369
  async evaluateTx(tx, additionalUTxOs) {
364
- const payload = {
365
- cbor: tx,
366
- additionalUtxoSet: toAditionalUTXOs(additionalUTxOs)
370
+ const evaluate = async (utxos) => {
371
+ const payload = {
372
+ cbor: tx,
373
+ ...utxos?.length ? { additionalUtxoSet: toAditionalUTXOs(utxos) } : {}
374
+ };
375
+ const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
376
+ method: "POST",
377
+ headers: {
378
+ "Content-Type": "application/json",
379
+ project_id: this.projectId,
380
+ lucid
381
+ },
382
+ body: JSON.stringify(payload)
383
+ }).then((res2) => res2.json());
384
+ if (!res || res.fault) {
385
+ const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}. Transaction: ${tx}`;
386
+ throw new Error(message);
387
+ }
388
+ const blockfrostRedeemer2 = res;
389
+ if (!("EvaluationResult" in blockfrostRedeemer2.result)) {
390
+ throw new Error(
391
+ `EvaluateTransaction fails: ${JSON.stringify(blockfrostRedeemer2.result)}`
392
+ );
393
+ }
394
+ return blockfrostRedeemer2;
367
395
  };
368
- const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
369
- method: "POST",
370
- headers: {
371
- "Content-Type": "application/json",
372
- project_id: this.projectId,
373
- lucid
374
- },
375
- body: JSON.stringify(payload)
376
- }).then((res2) => res2.json());
377
- if (!res || res.fault) {
378
- const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}. Transaction: ${tx}`;
379
- throw new Error(message);
380
- }
381
- const blockfrostRedeemer = res;
382
- if (!("EvaluationResult" in blockfrostRedeemer.result)) {
383
- throw new Error(
384
- `EvaluateTransaction fails: ${JSON.stringify(blockfrostRedeemer.result)}`
385
- );
386
- }
396
+ const blockfrostRedeemer = additionalUTxOs?.length ? await evaluate().catch(() => evaluate(additionalUTxOs)) : await evaluate();
387
397
  const evalRedeemers = [];
388
398
  Object.entries(blockfrostRedeemer.result.EvaluationResult).forEach(
389
399
  ([redeemerPointer, data]) => {
@@ -449,6 +459,29 @@ var getJSONRPCResult = (response) => {
449
459
  var LovelaceAsset = S.Struct({
450
460
  lovelace: S.Number
451
461
  });
462
+ var LovelaceAmount = S.Union(S.Number, S.String, S.BigInt);
463
+ var TreasuryAndReservesSchema = S.Struct({
464
+ treasury: S.Struct({
465
+ ada: S.Struct({
466
+ lovelace: LovelaceAmount
467
+ })
468
+ }),
469
+ reserves: S.Struct({
470
+ ada: S.Struct({
471
+ lovelace: LovelaceAmount
472
+ })
473
+ })
474
+ });
475
+ var lovelaceAmountToBigInt = (lovelace) => {
476
+ if (typeof lovelace === "bigint") return lovelace;
477
+ if (typeof lovelace === "string") return BigInt(lovelace);
478
+ if (!Number.isSafeInteger(lovelace)) {
479
+ throw new Error(
480
+ `Cannot decode Ogmios lovelace amount ${lovelace}; number is outside the safe integer range.`
481
+ );
482
+ }
483
+ return BigInt(lovelace);
484
+ };
452
485
  var TupleNumberFromString = S.compose(
453
486
  S.split("/"),
454
487
  S.Array(S.NumberFromString)
@@ -798,6 +831,31 @@ var Kupmios = class {
798
831
  const result = getJSONRPCResult(response);
799
832
  return toProtocolParameters(result);
800
833
  }
834
+ async getTreasury() {
835
+ const data = {
836
+ jsonrpc: "2.0",
837
+ method: "queryLedgerState/treasuryAndReserves",
838
+ params: {},
839
+ id: null
840
+ };
841
+ const schema = JSONRPCResponseSchema(
842
+ TreasuryAndReservesSchema
843
+ );
844
+ const response = await pipe3(
845
+ makePostAsJson(
846
+ this.ogmiosUrl,
847
+ data,
848
+ schema,
849
+ this.headers?.ogmiosHeader
850
+ ),
851
+ Effect2.timeout(1e4),
852
+ Effect2.catchAll((cause) => new KupmiosError({ cause })),
853
+ Effect2.provide(FetchHttpClient.layer),
854
+ Effect2.runPromise
855
+ );
856
+ const result = getJSONRPCResult(response);
857
+ return lovelaceAmountToBigInt(result.treasury.ada.lovelace);
858
+ }
801
859
  async getUtxos(addressOrCredential) {
802
860
  const isAddress = typeof addressOrCredential === "string";
803
861
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
@@ -1179,7 +1237,8 @@ var Emulator = class {
1179
1237
  time;
1180
1238
  protocolParameters;
1181
1239
  datumTable = {};
1182
- constructor(accounts, protocolParameters = PROTOCOL_PARAMETERS_DEFAULT) {
1240
+ treasury;
1241
+ constructor(accounts, protocolParameters = PROTOCOL_PARAMETERS_DEFAULT, treasury = 0n) {
1183
1242
  const GENESIS_HASH = "00".repeat(32);
1184
1243
  this.blockHeight = 0;
1185
1244
  this.slot = 0;
@@ -1209,6 +1268,7 @@ var Emulator = class {
1209
1268
  };
1210
1269
  });
1211
1270
  this.protocolParameters = protocolParameters;
1271
+ this.treasury = treasury;
1212
1272
  }
1213
1273
  now() {
1214
1274
  return this.time;
@@ -1254,6 +1314,9 @@ var Emulator = class {
1254
1314
  getProtocolParameters() {
1255
1315
  return Promise.resolve(this.protocolParameters);
1256
1316
  }
1317
+ getTreasury() {
1318
+ return Promise.resolve(this.treasury);
1319
+ }
1257
1320
  getDatum(datumHash) {
1258
1321
  return Promise.resolve(this.datumTable[datumHash]);
1259
1322
  }
@@ -1336,6 +1399,23 @@ var Emulator = class {
1336
1399
  `Upper bound (${upperBound}) not in slot range (${this.slot}).`
1337
1400
  );
1338
1401
  }
1402
+ const currentTreasuryValue = body.current_treasury_value();
1403
+ const treasuryDonation = body.donation();
1404
+ if (currentTreasuryValue === void 0 && treasuryDonation !== void 0 || currentTreasuryValue !== void 0 && treasuryDonation === void 0) {
1405
+ throw new Error(
1406
+ "Treasury donation transactions must include both current treasury value and donation."
1407
+ );
1408
+ }
1409
+ if (treasuryDonation !== void 0) {
1410
+ if (treasuryDonation <= 0n) {
1411
+ throw new Error("Treasury donation must be greater than 0 lovelace.");
1412
+ }
1413
+ if (currentTreasuryValue !== this.treasury) {
1414
+ throw new Error(
1415
+ `Current treasury value (${currentTreasuryValue}) does not match emulator treasury (${this.treasury}).`
1416
+ );
1417
+ }
1418
+ }
1339
1419
  const datumTable = (() => {
1340
1420
  const table = {};
1341
1421
  for (let i = 0; i < (datums?.len() || 0); i++) {
@@ -1628,6 +1708,12 @@ It does not exist or was already spent.`
1628
1708
  withdrawalRequests.push({ rewardAddress, withdrawal });
1629
1709
  }
1630
1710
  const certRequests = [];
1711
+ const credentialToCore = (credential) => credential.kind() === 0 ? { type: "Key", hash: credential.as_pub_key().to_hex() } : { type: "Script", hash: credential.as_script().to_hex() };
1712
+ const checkCertCredential = (credential, index) => {
1713
+ if (!credential) return;
1714
+ checkAndConsumeHash(credentialToCore(credential), "Cert", index);
1715
+ };
1716
+ const rewardAddressFromCredential = (credential) => CML.RewardAddress.new(CML.NetworkInfo.testnet().network_id(), credential).to_address().to_bech32(void 0);
1631
1717
  for (let index = 0; index < (body.certs()?.len() || 0); index++) {
1632
1718
  const cert = body.certs().get(index);
1633
1719
  switch (cert.kind()) {
@@ -1696,6 +1782,166 @@ It does not exist or was already spent.`
1696
1782
  certRequests.push({ type: "Delegation", rewardAddress, poolId });
1697
1783
  break;
1698
1784
  }
1785
+ case CML.CertificateKind.PoolRegistration: {
1786
+ const poolParams = cert.as_pool_registration()?.pool_params();
1787
+ if (!poolParams) break;
1788
+ checkAndConsumeHash(
1789
+ { type: "Key", hash: poolParams.operator().to_hex() },
1790
+ "Cert",
1791
+ index
1792
+ );
1793
+ const owners = poolParams.pool_owners();
1794
+ for (let ownerIndex = 0; ownerIndex < owners.len(); ownerIndex++) {
1795
+ checkAndConsumeHash(
1796
+ { type: "Key", hash: owners.get(ownerIndex).to_hex() },
1797
+ "Cert",
1798
+ index
1799
+ );
1800
+ }
1801
+ break;
1802
+ }
1803
+ case CML.CertificateKind.PoolRetirement: {
1804
+ const pool = cert.as_pool_retirement()?.pool();
1805
+ if (pool) {
1806
+ checkAndConsumeHash(
1807
+ { type: "Key", hash: pool.to_hex() },
1808
+ "Cert",
1809
+ index
1810
+ );
1811
+ }
1812
+ break;
1813
+ }
1814
+ case CML.CertificateKind.UnregCert: {
1815
+ const deregistration = cert.as_unreg_cert()?.stake_credential();
1816
+ checkCertCredential(deregistration, index);
1817
+ if (deregistration) {
1818
+ const rewardAddress = rewardAddressFromCredential(deregistration);
1819
+ if (!this.chain[rewardAddress]?.registeredStake) {
1820
+ throw new Error(
1821
+ `Stake key is already deregistered. Reward address: ${rewardAddress}`
1822
+ );
1823
+ }
1824
+ certRequests.push({ type: "Deregistration", rewardAddress });
1825
+ }
1826
+ break;
1827
+ }
1828
+ case CML.CertificateKind.VoteDelegCert: {
1829
+ const credential = cert.as_vote_deleg_cert()?.stake_credential();
1830
+ checkCertCredential(credential, index);
1831
+ if (credential) {
1832
+ const rewardAddress = rewardAddressFromCredential(credential);
1833
+ if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1834
+ (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
1835
+ )) {
1836
+ throw new Error(
1837
+ `Stake key is not registered. Reward address: ${rewardAddress}`
1838
+ );
1839
+ }
1840
+ }
1841
+ break;
1842
+ }
1843
+ case CML.CertificateKind.StakeVoteDelegCert: {
1844
+ const delegation = cert.as_stake_vote_deleg_cert();
1845
+ const credential = delegation?.stake_credential();
1846
+ checkCertCredential(credential, index);
1847
+ if (delegation && credential) {
1848
+ const rewardAddress = rewardAddressFromCredential(credential);
1849
+ const poolId = delegation.pool().to_bech32("pool");
1850
+ if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1851
+ (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
1852
+ )) {
1853
+ throw new Error(
1854
+ `Stake key is not registered. Reward address: ${rewardAddress}`
1855
+ );
1856
+ }
1857
+ certRequests.push({ type: "Delegation", rewardAddress, poolId });
1858
+ }
1859
+ break;
1860
+ }
1861
+ case CML.CertificateKind.StakeRegDelegCert: {
1862
+ const registration = cert.as_stake_reg_deleg_cert();
1863
+ const credential = registration?.stake_credential();
1864
+ checkCertCredential(credential, index);
1865
+ if (registration && credential) {
1866
+ const rewardAddress = rewardAddressFromCredential(credential);
1867
+ const poolId = registration.pool().to_bech32("pool");
1868
+ if (this.chain[rewardAddress]?.registeredStake) {
1869
+ throw new Error(
1870
+ `Stake key is already registered. Reward address: ${rewardAddress}`
1871
+ );
1872
+ }
1873
+ certRequests.push({ type: "Registration", rewardAddress });
1874
+ certRequests.push({ type: "Delegation", rewardAddress, poolId });
1875
+ }
1876
+ break;
1877
+ }
1878
+ case CML.CertificateKind.VoteRegDelegCert: {
1879
+ const registration = cert.as_vote_reg_deleg_cert();
1880
+ const credential = registration?.stake_credential();
1881
+ checkCertCredential(credential, index);
1882
+ if (credential) {
1883
+ const rewardAddress = rewardAddressFromCredential(credential);
1884
+ if (this.chain[rewardAddress]?.registeredStake) {
1885
+ throw new Error(
1886
+ `Stake key is already registered. Reward address: ${rewardAddress}`
1887
+ );
1888
+ }
1889
+ certRequests.push({ type: "Registration", rewardAddress });
1890
+ }
1891
+ break;
1892
+ }
1893
+ case CML.CertificateKind.StakeVoteRegDelegCert: {
1894
+ const registration = cert.as_stake_vote_reg_deleg_cert();
1895
+ const credential = registration?.stake_credential();
1896
+ checkCertCredential(credential, index);
1897
+ if (registration && credential) {
1898
+ const rewardAddress = rewardAddressFromCredential(credential);
1899
+ const poolId = registration.pool().to_bech32("pool");
1900
+ if (this.chain[rewardAddress]?.registeredStake) {
1901
+ throw new Error(
1902
+ `Stake key is already registered. Reward address: ${rewardAddress}`
1903
+ );
1904
+ }
1905
+ certRequests.push({ type: "Registration", rewardAddress });
1906
+ certRequests.push({ type: "Delegation", rewardAddress, poolId });
1907
+ }
1908
+ break;
1909
+ }
1910
+ case CML.CertificateKind.AuthCommitteeHotCert: {
1911
+ checkCertCredential(
1912
+ cert.as_auth_committee_hot_cert()?.committee_cold_credential(),
1913
+ index
1914
+ );
1915
+ break;
1916
+ }
1917
+ case CML.CertificateKind.ResignCommitteeColdCert: {
1918
+ checkCertCredential(
1919
+ cert.as_resign_committee_cold_cert()?.committee_cold_credential(),
1920
+ index
1921
+ );
1922
+ break;
1923
+ }
1924
+ case CML.CertificateKind.RegDrepCert: {
1925
+ checkCertCredential(
1926
+ cert.as_reg_drep_cert()?.drep_credential(),
1927
+ index
1928
+ );
1929
+ break;
1930
+ }
1931
+ case CML.CertificateKind.UnregDrepCert: {
1932
+ checkCertCredential(
1933
+ cert.as_unreg_drep_cert()?.drep_credential(),
1934
+ index
1935
+ );
1936
+ break;
1937
+ }
1938
+ case CML.CertificateKind.UpdateDrepCert: {
1939
+ checkCertCredential(
1940
+ cert.as_update_drep_cert()?.drep_credential(),
1941
+ index
1942
+ );
1943
+ break;
1944
+ }
1699
1945
  }
1700
1946
  }
1701
1947
  resolvedInputs.forEach(({ entry: { utxo } }, index) => {
@@ -1759,6 +2005,9 @@ It does not exist or was already spent.`
1759
2005
  withdrawalRequests.forEach(({ rewardAddress, withdrawal }) => {
1760
2006
  this.chain[rewardAddress].delegation.rewards -= withdrawal;
1761
2007
  });
2008
+ if (treasuryDonation !== void 0) {
2009
+ this.treasury += treasuryDonation;
2010
+ }
1762
2011
  certRequests.forEach(({ type, rewardAddress, poolId }) => {
1763
2012
  switch (type) {
1764
2013
  case "Registration": {
@@ -1956,6 +2205,11 @@ var Maestro = class {
1956
2205
  }
1957
2206
  };
1958
2207
  }
2208
+ async getTreasury() {
2209
+ throw new Error(
2210
+ "Maestro does not expose a current treasury query. Pass currentTreasuryValue explicitly to donateToTreasury."
2211
+ );
2212
+ }
1959
2213
  async getUtxosInternal(addressOrCredential, unit) {
1960
2214
  const queryPredicate = (() => {
1961
2215
  if (typeof addressOrCredential === "string") {
@@ -2282,6 +2536,9 @@ var ProtocolParametersSchema2 = S4.Struct({
2282
2536
  max_collateral_inputs: S4.Number,
2283
2537
  coins_per_utxo_size: S4.BigInt
2284
2538
  });
2539
+ var TotalsSchema = S4.Struct({
2540
+ treasury: S4.String
2541
+ });
2285
2542
  var AssetSchema = S4.Struct({
2286
2543
  policy_id: S4.String,
2287
2544
  asset_name: S4.NullOr(S4.String),
@@ -2556,6 +2813,22 @@ var Koios = class {
2556
2813
  }
2557
2814
  };
2558
2815
  }
2816
+ async getTreasury() {
2817
+ const url = `${this.baseUrl}/totals?order=epoch_no.desc&limit=1`;
2818
+ const schema = S5.Array(TotalsSchema);
2819
+ const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2820
+ const [result] = await pipe5(
2821
+ makeGet(url, schema, bearerToken),
2822
+ Effect4.provide(FetchHttpClient3.layer),
2823
+ Effect4.flatMap(
2824
+ (result2) => result2.length === 0 ? Effect4.fail("No totals found") : Effect4.succeed(result2)
2825
+ ),
2826
+ Effect4.timeout(1e4),
2827
+ Effect4.catchAllCause((cause) => new KoiosError({ cause })),
2828
+ Effect4.runPromise
2829
+ );
2830
+ return BigInt(result.treasury);
2831
+ }
2559
2832
  async getUtxos(addressOrCredential) {
2560
2833
  const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
2561
2834
  const result = await pipe5(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/provider",
3
- "version": "0.1.94",
3
+ "version": "0.1.96",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,15 +25,15 @@
25
25
  "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
26
26
  },
27
27
  "dependencies": {
28
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-3",
29
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-3",
28
+ "@anastasia-labs/cardano-multiplatform-lib-browser": "6.2.0-1",
29
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.2.0-1",
30
30
  "@effect/platform": "^0.71.3",
31
31
  "@effect/schema": "^0.68.26",
32
32
  "effect": "^3.11.7",
33
- "@lucid-evolution/core-types": "0.1.24",
33
+ "@lucid-evolution/core-types": "0.2.1",
34
34
  "@lucid-evolution/core-utils": "0.1.16",
35
- "@lucid-evolution/utils": "0.1.68",
36
- "@lucid-evolution/wallet": "0.1.74"
35
+ "@lucid-evolution/utils": "0.1.70",
36
+ "@lucid-evolution/wallet": "0.1.76"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^20.12.8",