@lucid-evolution/provider 0.1.94 → 0.1.95
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 +287 -22
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +287 -22
- package/package.json +6 -6
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.
|
|
55
|
+
version: "0.1.95",
|
|
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
|
|
86
|
-
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0
|
|
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:*",
|
|
@@ -153,6 +153,15 @@ var fromLegacyRedeemerTag = (redeemerTag) => {
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
// src/blockfrost.ts
|
|
156
|
+
var toBlockfrostQueryPredicate = (addressOrCredential) => {
|
|
157
|
+
if (typeof addressOrCredential === "string") return addressOrCredential;
|
|
158
|
+
if (addressOrCredential.type === "Key") {
|
|
159
|
+
return CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
|
|
160
|
+
"addr_vkh"
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32("script");
|
|
164
|
+
};
|
|
156
165
|
var Blockfrost = class {
|
|
157
166
|
url;
|
|
158
167
|
projectId;
|
|
@@ -186,16 +195,17 @@ var Blockfrost = class {
|
|
|
186
195
|
costModels: result.cost_models_raw
|
|
187
196
|
};
|
|
188
197
|
}
|
|
198
|
+
async getTreasury() {
|
|
199
|
+
const result = await fetch(`${this.url}/network`, {
|
|
200
|
+
headers: { project_id: this.projectId, lucid }
|
|
201
|
+
}).then((res) => res.json());
|
|
202
|
+
if (!result || result.error || result.supply?.treasury === void 0) {
|
|
203
|
+
throw new Error("Could not fetch treasury amount from Blockfrost.");
|
|
204
|
+
}
|
|
205
|
+
return BigInt(result.supply.treasury);
|
|
206
|
+
}
|
|
189
207
|
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
|
-
})();
|
|
208
|
+
const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
|
|
199
209
|
let result = [];
|
|
200
210
|
let page = 1;
|
|
201
211
|
while (true) {
|
|
@@ -217,15 +227,7 @@ var Blockfrost = class {
|
|
|
217
227
|
return this.blockfrostUtxosToUtxos(result);
|
|
218
228
|
}
|
|
219
229
|
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
|
-
})();
|
|
230
|
+
const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
|
|
229
231
|
let result = [];
|
|
230
232
|
let page = 1;
|
|
231
233
|
while (true) {
|
|
@@ -490,6 +492,29 @@ var getJSONRPCResult = (response) => {
|
|
|
490
492
|
var LovelaceAsset = import_effect2.Schema.Struct({
|
|
491
493
|
lovelace: import_effect2.Schema.Number
|
|
492
494
|
});
|
|
495
|
+
var LovelaceAmount = import_effect2.Schema.Union(import_effect2.Schema.Number, import_effect2.Schema.String, import_effect2.Schema.BigInt);
|
|
496
|
+
var TreasuryAndReservesSchema = import_effect2.Schema.Struct({
|
|
497
|
+
treasury: import_effect2.Schema.Struct({
|
|
498
|
+
ada: import_effect2.Schema.Struct({
|
|
499
|
+
lovelace: LovelaceAmount
|
|
500
|
+
})
|
|
501
|
+
}),
|
|
502
|
+
reserves: import_effect2.Schema.Struct({
|
|
503
|
+
ada: import_effect2.Schema.Struct({
|
|
504
|
+
lovelace: LovelaceAmount
|
|
505
|
+
})
|
|
506
|
+
})
|
|
507
|
+
});
|
|
508
|
+
var lovelaceAmountToBigInt = (lovelace) => {
|
|
509
|
+
if (typeof lovelace === "bigint") return lovelace;
|
|
510
|
+
if (typeof lovelace === "string") return BigInt(lovelace);
|
|
511
|
+
if (!Number.isSafeInteger(lovelace)) {
|
|
512
|
+
throw new Error(
|
|
513
|
+
`Cannot decode Ogmios lovelace amount ${lovelace}; number is outside the safe integer range.`
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
return BigInt(lovelace);
|
|
517
|
+
};
|
|
493
518
|
var TupleNumberFromString = import_effect2.Schema.compose(
|
|
494
519
|
import_effect2.Schema.split("/"),
|
|
495
520
|
import_effect2.Schema.Array(import_effect2.Schema.NumberFromString)
|
|
@@ -834,6 +859,31 @@ var Kupmios = class {
|
|
|
834
859
|
const result = getJSONRPCResult(response);
|
|
835
860
|
return toProtocolParameters(result);
|
|
836
861
|
}
|
|
862
|
+
async getTreasury() {
|
|
863
|
+
const data = {
|
|
864
|
+
jsonrpc: "2.0",
|
|
865
|
+
method: "queryLedgerState/treasuryAndReserves",
|
|
866
|
+
params: {},
|
|
867
|
+
id: null
|
|
868
|
+
};
|
|
869
|
+
const schema = JSONRPCResponseSchema(
|
|
870
|
+
TreasuryAndReservesSchema
|
|
871
|
+
);
|
|
872
|
+
const response = await (0, import_effect6.pipe)(
|
|
873
|
+
makePostAsJson(
|
|
874
|
+
this.ogmiosUrl,
|
|
875
|
+
data,
|
|
876
|
+
schema,
|
|
877
|
+
this.headers?.ogmiosHeader
|
|
878
|
+
),
|
|
879
|
+
import_effect6.Effect.timeout(1e4),
|
|
880
|
+
import_effect6.Effect.catchAll((cause) => new KupmiosError({ cause })),
|
|
881
|
+
import_effect6.Effect.provide(import_platform2.FetchHttpClient.layer),
|
|
882
|
+
import_effect6.Effect.runPromise
|
|
883
|
+
);
|
|
884
|
+
const result = getJSONRPCResult(response);
|
|
885
|
+
return lovelaceAmountToBigInt(result.treasury.ada.lovelace);
|
|
886
|
+
}
|
|
837
887
|
async getUtxos(addressOrCredential) {
|
|
838
888
|
const isAddress = typeof addressOrCredential === "string";
|
|
839
889
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
@@ -1211,7 +1261,8 @@ var Emulator = class {
|
|
|
1211
1261
|
time;
|
|
1212
1262
|
protocolParameters;
|
|
1213
1263
|
datumTable = {};
|
|
1214
|
-
|
|
1264
|
+
treasury;
|
|
1265
|
+
constructor(accounts, protocolParameters = import_utils5.PROTOCOL_PARAMETERS_DEFAULT, treasury = 0n) {
|
|
1215
1266
|
const GENESIS_HASH = "00".repeat(32);
|
|
1216
1267
|
this.blockHeight = 0;
|
|
1217
1268
|
this.slot = 0;
|
|
@@ -1241,6 +1292,7 @@ var Emulator = class {
|
|
|
1241
1292
|
};
|
|
1242
1293
|
});
|
|
1243
1294
|
this.protocolParameters = protocolParameters;
|
|
1295
|
+
this.treasury = treasury;
|
|
1244
1296
|
}
|
|
1245
1297
|
now() {
|
|
1246
1298
|
return this.time;
|
|
@@ -1286,6 +1338,9 @@ var Emulator = class {
|
|
|
1286
1338
|
getProtocolParameters() {
|
|
1287
1339
|
return Promise.resolve(this.protocolParameters);
|
|
1288
1340
|
}
|
|
1341
|
+
getTreasury() {
|
|
1342
|
+
return Promise.resolve(this.treasury);
|
|
1343
|
+
}
|
|
1289
1344
|
getDatum(datumHash) {
|
|
1290
1345
|
return Promise.resolve(this.datumTable[datumHash]);
|
|
1291
1346
|
}
|
|
@@ -1368,6 +1423,23 @@ var Emulator = class {
|
|
|
1368
1423
|
`Upper bound (${upperBound}) not in slot range (${this.slot}).`
|
|
1369
1424
|
);
|
|
1370
1425
|
}
|
|
1426
|
+
const currentTreasuryValue = body.current_treasury_value();
|
|
1427
|
+
const treasuryDonation = body.donation();
|
|
1428
|
+
if (currentTreasuryValue === void 0 && treasuryDonation !== void 0 || currentTreasuryValue !== void 0 && treasuryDonation === void 0) {
|
|
1429
|
+
throw new Error(
|
|
1430
|
+
"Treasury donation transactions must include both current treasury value and donation."
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
if (treasuryDonation !== void 0) {
|
|
1434
|
+
if (treasuryDonation <= 0n) {
|
|
1435
|
+
throw new Error("Treasury donation must be greater than 0 lovelace.");
|
|
1436
|
+
}
|
|
1437
|
+
if (currentTreasuryValue !== this.treasury) {
|
|
1438
|
+
throw new Error(
|
|
1439
|
+
`Current treasury value (${currentTreasuryValue}) does not match emulator treasury (${this.treasury}).`
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1371
1443
|
const datumTable = (() => {
|
|
1372
1444
|
const table = {};
|
|
1373
1445
|
for (let i = 0; i < (datums?.len() || 0); i++) {
|
|
@@ -1660,6 +1732,12 @@ It does not exist or was already spent.`
|
|
|
1660
1732
|
withdrawalRequests.push({ rewardAddress, withdrawal });
|
|
1661
1733
|
}
|
|
1662
1734
|
const certRequests = [];
|
|
1735
|
+
const credentialToCore = (credential) => credential.kind() === 0 ? { type: "Key", hash: credential.as_pub_key().to_hex() } : { type: "Script", hash: credential.as_script().to_hex() };
|
|
1736
|
+
const checkCertCredential = (credential, index) => {
|
|
1737
|
+
if (!credential) return;
|
|
1738
|
+
checkAndConsumeHash(credentialToCore(credential), "Cert", index);
|
|
1739
|
+
};
|
|
1740
|
+
const rewardAddressFromCredential = (credential) => CML.RewardAddress.new(CML.NetworkInfo.testnet().network_id(), credential).to_address().to_bech32(void 0);
|
|
1663
1741
|
for (let index = 0; index < (body.certs()?.len() || 0); index++) {
|
|
1664
1742
|
const cert = body.certs().get(index);
|
|
1665
1743
|
switch (cert.kind()) {
|
|
@@ -1728,6 +1806,166 @@ It does not exist or was already spent.`
|
|
|
1728
1806
|
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1729
1807
|
break;
|
|
1730
1808
|
}
|
|
1809
|
+
case CML.CertificateKind.PoolRegistration: {
|
|
1810
|
+
const poolParams = cert.as_pool_registration()?.pool_params();
|
|
1811
|
+
if (!poolParams) break;
|
|
1812
|
+
checkAndConsumeHash(
|
|
1813
|
+
{ type: "Key", hash: poolParams.operator().to_hex() },
|
|
1814
|
+
"Cert",
|
|
1815
|
+
index
|
|
1816
|
+
);
|
|
1817
|
+
const owners = poolParams.pool_owners();
|
|
1818
|
+
for (let ownerIndex = 0; ownerIndex < owners.len(); ownerIndex++) {
|
|
1819
|
+
checkAndConsumeHash(
|
|
1820
|
+
{ type: "Key", hash: owners.get(ownerIndex).to_hex() },
|
|
1821
|
+
"Cert",
|
|
1822
|
+
index
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
break;
|
|
1826
|
+
}
|
|
1827
|
+
case CML.CertificateKind.PoolRetirement: {
|
|
1828
|
+
const pool = cert.as_pool_retirement()?.pool();
|
|
1829
|
+
if (pool) {
|
|
1830
|
+
checkAndConsumeHash(
|
|
1831
|
+
{ type: "Key", hash: pool.to_hex() },
|
|
1832
|
+
"Cert",
|
|
1833
|
+
index
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
break;
|
|
1837
|
+
}
|
|
1838
|
+
case CML.CertificateKind.UnregCert: {
|
|
1839
|
+
const deregistration = cert.as_unreg_cert()?.stake_credential();
|
|
1840
|
+
checkCertCredential(deregistration, index);
|
|
1841
|
+
if (deregistration) {
|
|
1842
|
+
const rewardAddress = rewardAddressFromCredential(deregistration);
|
|
1843
|
+
if (!this.chain[rewardAddress]?.registeredStake) {
|
|
1844
|
+
throw new Error(
|
|
1845
|
+
`Stake key is already deregistered. Reward address: ${rewardAddress}`
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
certRequests.push({ type: "Deregistration", rewardAddress });
|
|
1849
|
+
}
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
case CML.CertificateKind.VoteDelegCert: {
|
|
1853
|
+
const credential = cert.as_vote_deleg_cert()?.stake_credential();
|
|
1854
|
+
checkCertCredential(credential, index);
|
|
1855
|
+
if (credential) {
|
|
1856
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1857
|
+
if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
|
|
1858
|
+
(request) => request.type === "Registration" && request.rewardAddress === rewardAddress
|
|
1859
|
+
)) {
|
|
1860
|
+
throw new Error(
|
|
1861
|
+
`Stake key is not registered. Reward address: ${rewardAddress}`
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
break;
|
|
1866
|
+
}
|
|
1867
|
+
case CML.CertificateKind.StakeVoteDelegCert: {
|
|
1868
|
+
const delegation = cert.as_stake_vote_deleg_cert();
|
|
1869
|
+
const credential = delegation?.stake_credential();
|
|
1870
|
+
checkCertCredential(credential, index);
|
|
1871
|
+
if (delegation && credential) {
|
|
1872
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1873
|
+
const poolId = delegation.pool().to_bech32("pool");
|
|
1874
|
+
if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
|
|
1875
|
+
(request) => request.type === "Registration" && request.rewardAddress === rewardAddress
|
|
1876
|
+
)) {
|
|
1877
|
+
throw new Error(
|
|
1878
|
+
`Stake key is not registered. Reward address: ${rewardAddress}`
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1882
|
+
}
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
case CML.CertificateKind.StakeRegDelegCert: {
|
|
1886
|
+
const registration = cert.as_stake_reg_deleg_cert();
|
|
1887
|
+
const credential = registration?.stake_credential();
|
|
1888
|
+
checkCertCredential(credential, index);
|
|
1889
|
+
if (registration && credential) {
|
|
1890
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1891
|
+
const poolId = registration.pool().to_bech32("pool");
|
|
1892
|
+
if (this.chain[rewardAddress]?.registeredStake) {
|
|
1893
|
+
throw new Error(
|
|
1894
|
+
`Stake key is already registered. Reward address: ${rewardAddress}`
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
certRequests.push({ type: "Registration", rewardAddress });
|
|
1898
|
+
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1899
|
+
}
|
|
1900
|
+
break;
|
|
1901
|
+
}
|
|
1902
|
+
case CML.CertificateKind.VoteRegDelegCert: {
|
|
1903
|
+
const registration = cert.as_vote_reg_deleg_cert();
|
|
1904
|
+
const credential = registration?.stake_credential();
|
|
1905
|
+
checkCertCredential(credential, index);
|
|
1906
|
+
if (credential) {
|
|
1907
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1908
|
+
if (this.chain[rewardAddress]?.registeredStake) {
|
|
1909
|
+
throw new Error(
|
|
1910
|
+
`Stake key is already registered. Reward address: ${rewardAddress}`
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
certRequests.push({ type: "Registration", rewardAddress });
|
|
1914
|
+
}
|
|
1915
|
+
break;
|
|
1916
|
+
}
|
|
1917
|
+
case CML.CertificateKind.StakeVoteRegDelegCert: {
|
|
1918
|
+
const registration = cert.as_stake_vote_reg_deleg_cert();
|
|
1919
|
+
const credential = registration?.stake_credential();
|
|
1920
|
+
checkCertCredential(credential, index);
|
|
1921
|
+
if (registration && credential) {
|
|
1922
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1923
|
+
const poolId = registration.pool().to_bech32("pool");
|
|
1924
|
+
if (this.chain[rewardAddress]?.registeredStake) {
|
|
1925
|
+
throw new Error(
|
|
1926
|
+
`Stake key is already registered. Reward address: ${rewardAddress}`
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1929
|
+
certRequests.push({ type: "Registration", rewardAddress });
|
|
1930
|
+
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1931
|
+
}
|
|
1932
|
+
break;
|
|
1933
|
+
}
|
|
1934
|
+
case CML.CertificateKind.AuthCommitteeHotCert: {
|
|
1935
|
+
checkCertCredential(
|
|
1936
|
+
cert.as_auth_committee_hot_cert()?.committee_cold_credential(),
|
|
1937
|
+
index
|
|
1938
|
+
);
|
|
1939
|
+
break;
|
|
1940
|
+
}
|
|
1941
|
+
case CML.CertificateKind.ResignCommitteeColdCert: {
|
|
1942
|
+
checkCertCredential(
|
|
1943
|
+
cert.as_resign_committee_cold_cert()?.committee_cold_credential(),
|
|
1944
|
+
index
|
|
1945
|
+
);
|
|
1946
|
+
break;
|
|
1947
|
+
}
|
|
1948
|
+
case CML.CertificateKind.RegDrepCert: {
|
|
1949
|
+
checkCertCredential(
|
|
1950
|
+
cert.as_reg_drep_cert()?.drep_credential(),
|
|
1951
|
+
index
|
|
1952
|
+
);
|
|
1953
|
+
break;
|
|
1954
|
+
}
|
|
1955
|
+
case CML.CertificateKind.UnregDrepCert: {
|
|
1956
|
+
checkCertCredential(
|
|
1957
|
+
cert.as_unreg_drep_cert()?.drep_credential(),
|
|
1958
|
+
index
|
|
1959
|
+
);
|
|
1960
|
+
break;
|
|
1961
|
+
}
|
|
1962
|
+
case CML.CertificateKind.UpdateDrepCert: {
|
|
1963
|
+
checkCertCredential(
|
|
1964
|
+
cert.as_update_drep_cert()?.drep_credential(),
|
|
1965
|
+
index
|
|
1966
|
+
);
|
|
1967
|
+
break;
|
|
1968
|
+
}
|
|
1731
1969
|
}
|
|
1732
1970
|
}
|
|
1733
1971
|
resolvedInputs.forEach(({ entry: { utxo } }, index) => {
|
|
@@ -1791,6 +2029,9 @@ It does not exist or was already spent.`
|
|
|
1791
2029
|
withdrawalRequests.forEach(({ rewardAddress, withdrawal }) => {
|
|
1792
2030
|
this.chain[rewardAddress].delegation.rewards -= withdrawal;
|
|
1793
2031
|
});
|
|
2032
|
+
if (treasuryDonation !== void 0) {
|
|
2033
|
+
this.treasury += treasuryDonation;
|
|
2034
|
+
}
|
|
1794
2035
|
certRequests.forEach(({ type, rewardAddress, poolId }) => {
|
|
1795
2036
|
switch (type) {
|
|
1796
2037
|
case "Registration": {
|
|
@@ -1984,6 +2225,11 @@ var Maestro = class {
|
|
|
1984
2225
|
}
|
|
1985
2226
|
};
|
|
1986
2227
|
}
|
|
2228
|
+
async getTreasury() {
|
|
2229
|
+
throw new Error(
|
|
2230
|
+
"Maestro does not expose a current treasury query. Pass currentTreasuryValue explicitly to donateToTreasury."
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
1987
2233
|
async getUtxosInternal(addressOrCredential, unit) {
|
|
1988
2234
|
const queryPredicate = (() => {
|
|
1989
2235
|
if (typeof addressOrCredential === "string") {
|
|
@@ -2310,6 +2556,9 @@ var ProtocolParametersSchema2 = import_effect7.Schema.Struct({
|
|
|
2310
2556
|
max_collateral_inputs: import_effect7.Schema.Number,
|
|
2311
2557
|
coins_per_utxo_size: import_effect7.Schema.BigInt
|
|
2312
2558
|
});
|
|
2559
|
+
var TotalsSchema = import_effect7.Schema.Struct({
|
|
2560
|
+
treasury: import_effect7.Schema.String
|
|
2561
|
+
});
|
|
2313
2562
|
var AssetSchema = import_effect7.Schema.Struct({
|
|
2314
2563
|
policy_id: import_effect7.Schema.String,
|
|
2315
2564
|
asset_name: import_effect7.Schema.NullOr(import_effect7.Schema.String),
|
|
@@ -2584,6 +2833,22 @@ var Koios = class {
|
|
|
2584
2833
|
}
|
|
2585
2834
|
};
|
|
2586
2835
|
}
|
|
2836
|
+
async getTreasury() {
|
|
2837
|
+
const url = `${this.baseUrl}/totals?order=epoch_no.desc&limit=1`;
|
|
2838
|
+
const schema = import_effect8.Schema.Array(TotalsSchema);
|
|
2839
|
+
const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
|
|
2840
|
+
const [result] = await (0, import_effect8.pipe)(
|
|
2841
|
+
makeGet(url, schema, bearerToken),
|
|
2842
|
+
import_effect8.Effect.provide(import_platform4.FetchHttpClient.layer),
|
|
2843
|
+
import_effect8.Effect.flatMap(
|
|
2844
|
+
(result2) => result2.length === 0 ? import_effect8.Effect.fail("No totals found") : import_effect8.Effect.succeed(result2)
|
|
2845
|
+
),
|
|
2846
|
+
import_effect8.Effect.timeout(1e4),
|
|
2847
|
+
import_effect8.Effect.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2848
|
+
import_effect8.Effect.runPromise
|
|
2849
|
+
);
|
|
2850
|
+
return BigInt(result.treasury);
|
|
2851
|
+
}
|
|
2587
2852
|
async getUtxos(addressOrCredential) {
|
|
2588
2853
|
const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
|
|
2589
2854
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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.
|
|
14
|
+
version: "0.1.95",
|
|
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
|
|
45
|
-
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0
|
|
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:*",
|
|
@@ -112,6 +112,15 @@ var fromLegacyRedeemerTag = (redeemerTag) => {
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// src/blockfrost.ts
|
|
115
|
+
var toBlockfrostQueryPredicate = (addressOrCredential) => {
|
|
116
|
+
if (typeof addressOrCredential === "string") return addressOrCredential;
|
|
117
|
+
if (addressOrCredential.type === "Key") {
|
|
118
|
+
return CML.Ed25519KeyHash.from_hex(addressOrCredential.hash).to_bech32(
|
|
119
|
+
"addr_vkh"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return CML.ScriptHash.from_hex(addressOrCredential.hash).to_bech32("script");
|
|
123
|
+
};
|
|
115
124
|
var Blockfrost = class {
|
|
116
125
|
url;
|
|
117
126
|
projectId;
|
|
@@ -145,16 +154,17 @@ var Blockfrost = class {
|
|
|
145
154
|
costModels: result.cost_models_raw
|
|
146
155
|
};
|
|
147
156
|
}
|
|
157
|
+
async getTreasury() {
|
|
158
|
+
const result = await fetch(`${this.url}/network`, {
|
|
159
|
+
headers: { project_id: this.projectId, lucid }
|
|
160
|
+
}).then((res) => res.json());
|
|
161
|
+
if (!result || result.error || result.supply?.treasury === void 0) {
|
|
162
|
+
throw new Error("Could not fetch treasury amount from Blockfrost.");
|
|
163
|
+
}
|
|
164
|
+
return BigInt(result.supply.treasury);
|
|
165
|
+
}
|
|
148
166
|
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
|
-
})();
|
|
167
|
+
const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
|
|
158
168
|
let result = [];
|
|
159
169
|
let page = 1;
|
|
160
170
|
while (true) {
|
|
@@ -176,15 +186,7 @@ var Blockfrost = class {
|
|
|
176
186
|
return this.blockfrostUtxosToUtxos(result);
|
|
177
187
|
}
|
|
178
188
|
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
|
-
})();
|
|
189
|
+
const queryPredicate = toBlockfrostQueryPredicate(addressOrCredential);
|
|
188
190
|
let result = [];
|
|
189
191
|
let page = 1;
|
|
190
192
|
while (true) {
|
|
@@ -449,6 +451,29 @@ var getJSONRPCResult = (response) => {
|
|
|
449
451
|
var LovelaceAsset = S.Struct({
|
|
450
452
|
lovelace: S.Number
|
|
451
453
|
});
|
|
454
|
+
var LovelaceAmount = S.Union(S.Number, S.String, S.BigInt);
|
|
455
|
+
var TreasuryAndReservesSchema = S.Struct({
|
|
456
|
+
treasury: S.Struct({
|
|
457
|
+
ada: S.Struct({
|
|
458
|
+
lovelace: LovelaceAmount
|
|
459
|
+
})
|
|
460
|
+
}),
|
|
461
|
+
reserves: S.Struct({
|
|
462
|
+
ada: S.Struct({
|
|
463
|
+
lovelace: LovelaceAmount
|
|
464
|
+
})
|
|
465
|
+
})
|
|
466
|
+
});
|
|
467
|
+
var lovelaceAmountToBigInt = (lovelace) => {
|
|
468
|
+
if (typeof lovelace === "bigint") return lovelace;
|
|
469
|
+
if (typeof lovelace === "string") return BigInt(lovelace);
|
|
470
|
+
if (!Number.isSafeInteger(lovelace)) {
|
|
471
|
+
throw new Error(
|
|
472
|
+
`Cannot decode Ogmios lovelace amount ${lovelace}; number is outside the safe integer range.`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
return BigInt(lovelace);
|
|
476
|
+
};
|
|
452
477
|
var TupleNumberFromString = S.compose(
|
|
453
478
|
S.split("/"),
|
|
454
479
|
S.Array(S.NumberFromString)
|
|
@@ -798,6 +823,31 @@ var Kupmios = class {
|
|
|
798
823
|
const result = getJSONRPCResult(response);
|
|
799
824
|
return toProtocolParameters(result);
|
|
800
825
|
}
|
|
826
|
+
async getTreasury() {
|
|
827
|
+
const data = {
|
|
828
|
+
jsonrpc: "2.0",
|
|
829
|
+
method: "queryLedgerState/treasuryAndReserves",
|
|
830
|
+
params: {},
|
|
831
|
+
id: null
|
|
832
|
+
};
|
|
833
|
+
const schema = JSONRPCResponseSchema(
|
|
834
|
+
TreasuryAndReservesSchema
|
|
835
|
+
);
|
|
836
|
+
const response = await pipe3(
|
|
837
|
+
makePostAsJson(
|
|
838
|
+
this.ogmiosUrl,
|
|
839
|
+
data,
|
|
840
|
+
schema,
|
|
841
|
+
this.headers?.ogmiosHeader
|
|
842
|
+
),
|
|
843
|
+
Effect2.timeout(1e4),
|
|
844
|
+
Effect2.catchAll((cause) => new KupmiosError({ cause })),
|
|
845
|
+
Effect2.provide(FetchHttpClient.layer),
|
|
846
|
+
Effect2.runPromise
|
|
847
|
+
);
|
|
848
|
+
const result = getJSONRPCResult(response);
|
|
849
|
+
return lovelaceAmountToBigInt(result.treasury.ada.lovelace);
|
|
850
|
+
}
|
|
801
851
|
async getUtxos(addressOrCredential) {
|
|
802
852
|
const isAddress = typeof addressOrCredential === "string";
|
|
803
853
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
@@ -1179,7 +1229,8 @@ var Emulator = class {
|
|
|
1179
1229
|
time;
|
|
1180
1230
|
protocolParameters;
|
|
1181
1231
|
datumTable = {};
|
|
1182
|
-
|
|
1232
|
+
treasury;
|
|
1233
|
+
constructor(accounts, protocolParameters = PROTOCOL_PARAMETERS_DEFAULT, treasury = 0n) {
|
|
1183
1234
|
const GENESIS_HASH = "00".repeat(32);
|
|
1184
1235
|
this.blockHeight = 0;
|
|
1185
1236
|
this.slot = 0;
|
|
@@ -1209,6 +1260,7 @@ var Emulator = class {
|
|
|
1209
1260
|
};
|
|
1210
1261
|
});
|
|
1211
1262
|
this.protocolParameters = protocolParameters;
|
|
1263
|
+
this.treasury = treasury;
|
|
1212
1264
|
}
|
|
1213
1265
|
now() {
|
|
1214
1266
|
return this.time;
|
|
@@ -1254,6 +1306,9 @@ var Emulator = class {
|
|
|
1254
1306
|
getProtocolParameters() {
|
|
1255
1307
|
return Promise.resolve(this.protocolParameters);
|
|
1256
1308
|
}
|
|
1309
|
+
getTreasury() {
|
|
1310
|
+
return Promise.resolve(this.treasury);
|
|
1311
|
+
}
|
|
1257
1312
|
getDatum(datumHash) {
|
|
1258
1313
|
return Promise.resolve(this.datumTable[datumHash]);
|
|
1259
1314
|
}
|
|
@@ -1336,6 +1391,23 @@ var Emulator = class {
|
|
|
1336
1391
|
`Upper bound (${upperBound}) not in slot range (${this.slot}).`
|
|
1337
1392
|
);
|
|
1338
1393
|
}
|
|
1394
|
+
const currentTreasuryValue = body.current_treasury_value();
|
|
1395
|
+
const treasuryDonation = body.donation();
|
|
1396
|
+
if (currentTreasuryValue === void 0 && treasuryDonation !== void 0 || currentTreasuryValue !== void 0 && treasuryDonation === void 0) {
|
|
1397
|
+
throw new Error(
|
|
1398
|
+
"Treasury donation transactions must include both current treasury value and donation."
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
if (treasuryDonation !== void 0) {
|
|
1402
|
+
if (treasuryDonation <= 0n) {
|
|
1403
|
+
throw new Error("Treasury donation must be greater than 0 lovelace.");
|
|
1404
|
+
}
|
|
1405
|
+
if (currentTreasuryValue !== this.treasury) {
|
|
1406
|
+
throw new Error(
|
|
1407
|
+
`Current treasury value (${currentTreasuryValue}) does not match emulator treasury (${this.treasury}).`
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1339
1411
|
const datumTable = (() => {
|
|
1340
1412
|
const table = {};
|
|
1341
1413
|
for (let i = 0; i < (datums?.len() || 0); i++) {
|
|
@@ -1628,6 +1700,12 @@ It does not exist or was already spent.`
|
|
|
1628
1700
|
withdrawalRequests.push({ rewardAddress, withdrawal });
|
|
1629
1701
|
}
|
|
1630
1702
|
const certRequests = [];
|
|
1703
|
+
const credentialToCore = (credential) => credential.kind() === 0 ? { type: "Key", hash: credential.as_pub_key().to_hex() } : { type: "Script", hash: credential.as_script().to_hex() };
|
|
1704
|
+
const checkCertCredential = (credential, index) => {
|
|
1705
|
+
if (!credential) return;
|
|
1706
|
+
checkAndConsumeHash(credentialToCore(credential), "Cert", index);
|
|
1707
|
+
};
|
|
1708
|
+
const rewardAddressFromCredential = (credential) => CML.RewardAddress.new(CML.NetworkInfo.testnet().network_id(), credential).to_address().to_bech32(void 0);
|
|
1631
1709
|
for (let index = 0; index < (body.certs()?.len() || 0); index++) {
|
|
1632
1710
|
const cert = body.certs().get(index);
|
|
1633
1711
|
switch (cert.kind()) {
|
|
@@ -1696,6 +1774,166 @@ It does not exist or was already spent.`
|
|
|
1696
1774
|
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1697
1775
|
break;
|
|
1698
1776
|
}
|
|
1777
|
+
case CML.CertificateKind.PoolRegistration: {
|
|
1778
|
+
const poolParams = cert.as_pool_registration()?.pool_params();
|
|
1779
|
+
if (!poolParams) break;
|
|
1780
|
+
checkAndConsumeHash(
|
|
1781
|
+
{ type: "Key", hash: poolParams.operator().to_hex() },
|
|
1782
|
+
"Cert",
|
|
1783
|
+
index
|
|
1784
|
+
);
|
|
1785
|
+
const owners = poolParams.pool_owners();
|
|
1786
|
+
for (let ownerIndex = 0; ownerIndex < owners.len(); ownerIndex++) {
|
|
1787
|
+
checkAndConsumeHash(
|
|
1788
|
+
{ type: "Key", hash: owners.get(ownerIndex).to_hex() },
|
|
1789
|
+
"Cert",
|
|
1790
|
+
index
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
case CML.CertificateKind.PoolRetirement: {
|
|
1796
|
+
const pool = cert.as_pool_retirement()?.pool();
|
|
1797
|
+
if (pool) {
|
|
1798
|
+
checkAndConsumeHash(
|
|
1799
|
+
{ type: "Key", hash: pool.to_hex() },
|
|
1800
|
+
"Cert",
|
|
1801
|
+
index
|
|
1802
|
+
);
|
|
1803
|
+
}
|
|
1804
|
+
break;
|
|
1805
|
+
}
|
|
1806
|
+
case CML.CertificateKind.UnregCert: {
|
|
1807
|
+
const deregistration = cert.as_unreg_cert()?.stake_credential();
|
|
1808
|
+
checkCertCredential(deregistration, index);
|
|
1809
|
+
if (deregistration) {
|
|
1810
|
+
const rewardAddress = rewardAddressFromCredential(deregistration);
|
|
1811
|
+
if (!this.chain[rewardAddress]?.registeredStake) {
|
|
1812
|
+
throw new Error(
|
|
1813
|
+
`Stake key is already deregistered. Reward address: ${rewardAddress}`
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
certRequests.push({ type: "Deregistration", rewardAddress });
|
|
1817
|
+
}
|
|
1818
|
+
break;
|
|
1819
|
+
}
|
|
1820
|
+
case CML.CertificateKind.VoteDelegCert: {
|
|
1821
|
+
const credential = cert.as_vote_deleg_cert()?.stake_credential();
|
|
1822
|
+
checkCertCredential(credential, index);
|
|
1823
|
+
if (credential) {
|
|
1824
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1825
|
+
if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
|
|
1826
|
+
(request) => request.type === "Registration" && request.rewardAddress === rewardAddress
|
|
1827
|
+
)) {
|
|
1828
|
+
throw new Error(
|
|
1829
|
+
`Stake key is not registered. Reward address: ${rewardAddress}`
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
case CML.CertificateKind.StakeVoteDelegCert: {
|
|
1836
|
+
const delegation = cert.as_stake_vote_deleg_cert();
|
|
1837
|
+
const credential = delegation?.stake_credential();
|
|
1838
|
+
checkCertCredential(credential, index);
|
|
1839
|
+
if (delegation && credential) {
|
|
1840
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1841
|
+
const poolId = delegation.pool().to_bech32("pool");
|
|
1842
|
+
if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
|
|
1843
|
+
(request) => request.type === "Registration" && request.rewardAddress === rewardAddress
|
|
1844
|
+
)) {
|
|
1845
|
+
throw new Error(
|
|
1846
|
+
`Stake key is not registered. Reward address: ${rewardAddress}`
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1850
|
+
}
|
|
1851
|
+
break;
|
|
1852
|
+
}
|
|
1853
|
+
case CML.CertificateKind.StakeRegDelegCert: {
|
|
1854
|
+
const registration = cert.as_stake_reg_deleg_cert();
|
|
1855
|
+
const credential = registration?.stake_credential();
|
|
1856
|
+
checkCertCredential(credential, index);
|
|
1857
|
+
if (registration && credential) {
|
|
1858
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1859
|
+
const poolId = registration.pool().to_bech32("pool");
|
|
1860
|
+
if (this.chain[rewardAddress]?.registeredStake) {
|
|
1861
|
+
throw new Error(
|
|
1862
|
+
`Stake key is already registered. Reward address: ${rewardAddress}`
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1865
|
+
certRequests.push({ type: "Registration", rewardAddress });
|
|
1866
|
+
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1867
|
+
}
|
|
1868
|
+
break;
|
|
1869
|
+
}
|
|
1870
|
+
case CML.CertificateKind.VoteRegDelegCert: {
|
|
1871
|
+
const registration = cert.as_vote_reg_deleg_cert();
|
|
1872
|
+
const credential = registration?.stake_credential();
|
|
1873
|
+
checkCertCredential(credential, index);
|
|
1874
|
+
if (credential) {
|
|
1875
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1876
|
+
if (this.chain[rewardAddress]?.registeredStake) {
|
|
1877
|
+
throw new Error(
|
|
1878
|
+
`Stake key is already registered. Reward address: ${rewardAddress}`
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
certRequests.push({ type: "Registration", rewardAddress });
|
|
1882
|
+
}
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
case CML.CertificateKind.StakeVoteRegDelegCert: {
|
|
1886
|
+
const registration = cert.as_stake_vote_reg_deleg_cert();
|
|
1887
|
+
const credential = registration?.stake_credential();
|
|
1888
|
+
checkCertCredential(credential, index);
|
|
1889
|
+
if (registration && credential) {
|
|
1890
|
+
const rewardAddress = rewardAddressFromCredential(credential);
|
|
1891
|
+
const poolId = registration.pool().to_bech32("pool");
|
|
1892
|
+
if (this.chain[rewardAddress]?.registeredStake) {
|
|
1893
|
+
throw new Error(
|
|
1894
|
+
`Stake key is already registered. Reward address: ${rewardAddress}`
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
certRequests.push({ type: "Registration", rewardAddress });
|
|
1898
|
+
certRequests.push({ type: "Delegation", rewardAddress, poolId });
|
|
1899
|
+
}
|
|
1900
|
+
break;
|
|
1901
|
+
}
|
|
1902
|
+
case CML.CertificateKind.AuthCommitteeHotCert: {
|
|
1903
|
+
checkCertCredential(
|
|
1904
|
+
cert.as_auth_committee_hot_cert()?.committee_cold_credential(),
|
|
1905
|
+
index
|
|
1906
|
+
);
|
|
1907
|
+
break;
|
|
1908
|
+
}
|
|
1909
|
+
case CML.CertificateKind.ResignCommitteeColdCert: {
|
|
1910
|
+
checkCertCredential(
|
|
1911
|
+
cert.as_resign_committee_cold_cert()?.committee_cold_credential(),
|
|
1912
|
+
index
|
|
1913
|
+
);
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
case CML.CertificateKind.RegDrepCert: {
|
|
1917
|
+
checkCertCredential(
|
|
1918
|
+
cert.as_reg_drep_cert()?.drep_credential(),
|
|
1919
|
+
index
|
|
1920
|
+
);
|
|
1921
|
+
break;
|
|
1922
|
+
}
|
|
1923
|
+
case CML.CertificateKind.UnregDrepCert: {
|
|
1924
|
+
checkCertCredential(
|
|
1925
|
+
cert.as_unreg_drep_cert()?.drep_credential(),
|
|
1926
|
+
index
|
|
1927
|
+
);
|
|
1928
|
+
break;
|
|
1929
|
+
}
|
|
1930
|
+
case CML.CertificateKind.UpdateDrepCert: {
|
|
1931
|
+
checkCertCredential(
|
|
1932
|
+
cert.as_update_drep_cert()?.drep_credential(),
|
|
1933
|
+
index
|
|
1934
|
+
);
|
|
1935
|
+
break;
|
|
1936
|
+
}
|
|
1699
1937
|
}
|
|
1700
1938
|
}
|
|
1701
1939
|
resolvedInputs.forEach(({ entry: { utxo } }, index) => {
|
|
@@ -1759,6 +1997,9 @@ It does not exist or was already spent.`
|
|
|
1759
1997
|
withdrawalRequests.forEach(({ rewardAddress, withdrawal }) => {
|
|
1760
1998
|
this.chain[rewardAddress].delegation.rewards -= withdrawal;
|
|
1761
1999
|
});
|
|
2000
|
+
if (treasuryDonation !== void 0) {
|
|
2001
|
+
this.treasury += treasuryDonation;
|
|
2002
|
+
}
|
|
1762
2003
|
certRequests.forEach(({ type, rewardAddress, poolId }) => {
|
|
1763
2004
|
switch (type) {
|
|
1764
2005
|
case "Registration": {
|
|
@@ -1956,6 +2197,11 @@ var Maestro = class {
|
|
|
1956
2197
|
}
|
|
1957
2198
|
};
|
|
1958
2199
|
}
|
|
2200
|
+
async getTreasury() {
|
|
2201
|
+
throw new Error(
|
|
2202
|
+
"Maestro does not expose a current treasury query. Pass currentTreasuryValue explicitly to donateToTreasury."
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
1959
2205
|
async getUtxosInternal(addressOrCredential, unit) {
|
|
1960
2206
|
const queryPredicate = (() => {
|
|
1961
2207
|
if (typeof addressOrCredential === "string") {
|
|
@@ -2282,6 +2528,9 @@ var ProtocolParametersSchema2 = S4.Struct({
|
|
|
2282
2528
|
max_collateral_inputs: S4.Number,
|
|
2283
2529
|
coins_per_utxo_size: S4.BigInt
|
|
2284
2530
|
});
|
|
2531
|
+
var TotalsSchema = S4.Struct({
|
|
2532
|
+
treasury: S4.String
|
|
2533
|
+
});
|
|
2285
2534
|
var AssetSchema = S4.Struct({
|
|
2286
2535
|
policy_id: S4.String,
|
|
2287
2536
|
asset_name: S4.NullOr(S4.String),
|
|
@@ -2556,6 +2805,22 @@ var Koios = class {
|
|
|
2556
2805
|
}
|
|
2557
2806
|
};
|
|
2558
2807
|
}
|
|
2808
|
+
async getTreasury() {
|
|
2809
|
+
const url = `${this.baseUrl}/totals?order=epoch_no.desc&limit=1`;
|
|
2810
|
+
const schema = S5.Array(TotalsSchema);
|
|
2811
|
+
const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
|
|
2812
|
+
const [result] = await pipe5(
|
|
2813
|
+
makeGet(url, schema, bearerToken),
|
|
2814
|
+
Effect4.provide(FetchHttpClient3.layer),
|
|
2815
|
+
Effect4.flatMap(
|
|
2816
|
+
(result2) => result2.length === 0 ? Effect4.fail("No totals found") : Effect4.succeed(result2)
|
|
2817
|
+
),
|
|
2818
|
+
Effect4.timeout(1e4),
|
|
2819
|
+
Effect4.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2820
|
+
Effect4.runPromise
|
|
2821
|
+
);
|
|
2822
|
+
return BigInt(result.treasury);
|
|
2823
|
+
}
|
|
2559
2824
|
async getUtxos(addressOrCredential) {
|
|
2560
2825
|
const bearerToken = this.token ? { Authorization: `Bearer ${this.token}` } : void 0;
|
|
2561
2826
|
const result = await pipe5(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.95",
|
|
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
|
|
29
|
-
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0
|
|
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.
|
|
33
|
+
"@lucid-evolution/core-types": "0.2.0",
|
|
34
34
|
"@lucid-evolution/core-utils": "0.1.16",
|
|
35
|
-
"@lucid-evolution/utils": "0.1.
|
|
36
|
-
"@lucid-evolution/wallet": "0.1.
|
|
35
|
+
"@lucid-evolution/utils": "0.1.69",
|
|
36
|
+
"@lucid-evolution/wallet": "0.1.75"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^20.12.8",
|