@xyo-network/xl1-protocol-sdk 2.0.11 → 2.0.12
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/neutral/CreatableProvider/AbstractCreatableProvider.d.ts +7 -0
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/config/Actor.d.ts +42 -0
- package/dist/neutral/config/Actor.d.ts.map +1 -1
- package/dist/neutral/config/Actors.d.ts +7 -0
- package/dist/neutral/config/Actors.d.ts.map +1 -1
- package/dist/neutral/config/Base.d.ts +7 -0
- package/dist/neutral/config/Base.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +28 -0
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/HostActor.d.ts +42 -0
- package/dist/neutral/config/HostActor.d.ts.map +1 -1
- package/dist/neutral/config/index.d.ts +1 -1
- package/dist/neutral/config/index.d.ts.map +1 -1
- package/dist/neutral/config/storage/Storage.d.ts +7 -0
- package/dist/neutral/config/storage/Storage.d.ts.map +1 -1
- package/dist/neutral/config/storage/driver/R2.d.ts +25 -0
- package/dist/neutral/config/storage/driver/R2.d.ts.map +1 -0
- package/dist/neutral/config/storage/driver/index.d.ts +1 -0
- package/dist/neutral/config/storage/driver/index.d.ts.map +1 -1
- package/dist/neutral/context/Actor.d.ts +42 -0
- package/dist/neutral/context/Actor.d.ts.map +1 -1
- package/dist/neutral/context/HostActor.d.ts +42 -0
- package/dist/neutral/context/HostActor.d.ts.map +1 -1
- package/dist/neutral/getFileConfig.d.ts +14 -0
- package/dist/neutral/getFileConfig.d.ts.map +1 -1
- package/dist/neutral/getFileConfig.mjs +76 -44
- package/dist/neutral/getFileConfig.mjs.map +4 -4
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +560 -156
- package/dist/neutral/index.mjs.map +4 -4
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts +42 -0
- package/dist/neutral/model/CreatableProviderContext.zod.d.ts.map +1 -1
- package/dist/neutral/test/index.d.ts +1 -0
- package/dist/neutral/test/index.d.ts.map +1 -1
- package/dist/neutral/test/index.mjs +1056 -1019
- package/dist/neutral/test/index.mjs.map +4 -4
- package/package.json +6 -6
package/dist/neutral/index.mjs
CHANGED
|
@@ -1162,10 +1162,10 @@ import {
|
|
|
1162
1162
|
zodIsFactory as zodIsFactory2,
|
|
1163
1163
|
zodToFactory as zodToFactory2
|
|
1164
1164
|
} from "@xylabs/sdk-js";
|
|
1165
|
-
import { globalRegistry as
|
|
1165
|
+
import { globalRegistry as globalRegistry13, z as z18 } from "zod/mini";
|
|
1166
1166
|
|
|
1167
1167
|
// src/config/Base.ts
|
|
1168
|
-
import { z as
|
|
1168
|
+
import { z as z17 } from "zod/mini";
|
|
1169
1169
|
|
|
1170
1170
|
// src/config/Chain.ts
|
|
1171
1171
|
import { HexZod } from "@xylabs/sdk-js";
|
|
@@ -1370,11 +1370,47 @@ var MongoConfigZod = z12.object({
|
|
|
1370
1370
|
})
|
|
1371
1371
|
});
|
|
1372
1372
|
|
|
1373
|
-
// src/config/storage/
|
|
1373
|
+
// src/config/storage/driver/R2.ts
|
|
1374
|
+
import { isDefined as isDefined5, isUndefined as isUndefined6 } from "@xylabs/sdk-js";
|
|
1374
1375
|
import { globalRegistry as globalRegistry9, z as z13 } from "zod";
|
|
1375
|
-
var
|
|
1376
|
+
var hasR2Config = (config) => {
|
|
1377
|
+
if (isUndefined6(config)) return false;
|
|
1378
|
+
return isDefined5(config.accountId) && isDefined5(config.accessKeyId) && isDefined5(config.secretAccessKey) && isDefined5(config.bucket);
|
|
1379
|
+
};
|
|
1380
|
+
var R2ConfigZod = z13.object({
|
|
1381
|
+
accessKeyId: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1382
|
+
description: "Cloudflare R2 access key id (from an R2 API token)",
|
|
1383
|
+
title: "storage.r2.accessKeyId",
|
|
1384
|
+
type: "string"
|
|
1385
|
+
}),
|
|
1386
|
+
accountId: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1387
|
+
description: "Cloudflare account id; determines the R2 endpoint https://<accountId>.r2.cloudflarestorage.com",
|
|
1388
|
+
title: "storage.r2.accountId",
|
|
1389
|
+
type: "string"
|
|
1390
|
+
}),
|
|
1391
|
+
bucket: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1392
|
+
description: "Cloudflare R2 bucket name",
|
|
1393
|
+
title: "storage.r2.bucket",
|
|
1394
|
+
type: "string"
|
|
1395
|
+
}),
|
|
1396
|
+
prefix: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1397
|
+
description: "Optional key prefix namespacing this store within the bucket",
|
|
1398
|
+
title: "storage.r2.prefix",
|
|
1399
|
+
type: "string"
|
|
1400
|
+
}),
|
|
1401
|
+
secretAccessKey: z13.string().nonempty().optional().register(globalRegistry9, {
|
|
1402
|
+
description: "Cloudflare R2 secret access key (from an R2 API token)",
|
|
1403
|
+
title: "storage.r2.secretAccessKey",
|
|
1404
|
+
type: "string"
|
|
1405
|
+
})
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
// src/config/storage/Storage.ts
|
|
1409
|
+
import { globalRegistry as globalRegistry10, z as z14 } from "zod";
|
|
1410
|
+
var StorageConfigZod = z14.object({
|
|
1376
1411
|
mongo: MongoConfigZod.optional().describe("Configuration for the MongoD storage driver"),
|
|
1377
|
-
|
|
1412
|
+
r2: R2ConfigZod.optional().describe("Configuration for the Cloudflare R2 storage driver"),
|
|
1413
|
+
root: z14.string().optional().register(globalRegistry10, {
|
|
1378
1414
|
description: "Root directory for local storage",
|
|
1379
1415
|
title: "storage.root",
|
|
1380
1416
|
type: "string"
|
|
@@ -1382,7 +1418,7 @@ var StorageConfigZod = z13.object({
|
|
|
1382
1418
|
}).describe("Storage configuration options");
|
|
1383
1419
|
|
|
1384
1420
|
// src/config/Telemetry.ts
|
|
1385
|
-
import { globalRegistry as
|
|
1421
|
+
import { globalRegistry as globalRegistry11, z as z15 } from "zod";
|
|
1386
1422
|
var DefaultMetricsScrapePorts = {
|
|
1387
1423
|
api: 9465,
|
|
1388
1424
|
bridge: 9468,
|
|
@@ -1390,29 +1426,29 @@ var DefaultMetricsScrapePorts = {
|
|
|
1390
1426
|
producer: 9464,
|
|
1391
1427
|
rewardRedemptionApi: 9467
|
|
1392
1428
|
};
|
|
1393
|
-
var MetricsScrapeConfigZod =
|
|
1394
|
-
path:
|
|
1429
|
+
var MetricsScrapeConfigZod = z15.object({
|
|
1430
|
+
path: z15.string().default("/metrics").register(globalRegistry11, {
|
|
1395
1431
|
default: "/metrics",
|
|
1396
1432
|
description: "Path for the metrics scrape endpoint",
|
|
1397
1433
|
title: "telemetry.metrics.scrape.path",
|
|
1398
1434
|
type: "string"
|
|
1399
1435
|
}),
|
|
1400
|
-
port:
|
|
1436
|
+
port: z15.coerce.number().int().positive().optional().register(globalRegistry11, {
|
|
1401
1437
|
description: "Port for the metrics scrape endpoint",
|
|
1402
1438
|
title: "telemetry.metrics.scrape.port",
|
|
1403
1439
|
type: "number"
|
|
1404
1440
|
})
|
|
1405
1441
|
}).describe("Metrics scrape configuration");
|
|
1406
|
-
var MetricsConfigZod =
|
|
1407
|
-
var OpenTelemetryConfigZod =
|
|
1442
|
+
var MetricsConfigZod = z15.object({ scrape: MetricsScrapeConfigZod }).describe("Metrics configuration options");
|
|
1443
|
+
var OpenTelemetryConfigZod = z15.object({
|
|
1408
1444
|
// OpenTelemetry options
|
|
1409
|
-
otlpEndpoint:
|
|
1445
|
+
otlpEndpoint: z15.url().optional().register(globalRegistry11, {
|
|
1410
1446
|
description: "OTLP endpoint for exporting telemetry data",
|
|
1411
1447
|
title: "telemetry.otel.otlpEndpoint",
|
|
1412
1448
|
type: "string"
|
|
1413
1449
|
})
|
|
1414
1450
|
});
|
|
1415
|
-
var TelemetryConfigZod =
|
|
1451
|
+
var TelemetryConfigZod = z15.object({
|
|
1416
1452
|
// Metrics configuration
|
|
1417
1453
|
metrics: MetricsConfigZod.optional().describe("Metrics configuration"),
|
|
1418
1454
|
// OpenTelemetry configuration
|
|
@@ -1421,7 +1457,7 @@ var TelemetryConfigZod = z14.object({
|
|
|
1421
1457
|
|
|
1422
1458
|
// src/config/Validation.ts
|
|
1423
1459
|
import { XyoAddressZod as XyoAddressZod2 } from "@xyo-network/address";
|
|
1424
|
-
import { globalRegistry as
|
|
1460
|
+
import { globalRegistry as globalRegistry12, z as z16 } from "zod";
|
|
1425
1461
|
|
|
1426
1462
|
// src/primitives/block/range/blockRangeSteps.ts
|
|
1427
1463
|
import { asXL1BlockNumber as asXL1BlockNumber2, StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol-lib";
|
|
@@ -1442,11 +1478,11 @@ function blockRangeSteps(range, steps) {
|
|
|
1442
1478
|
}
|
|
1443
1479
|
|
|
1444
1480
|
// src/primitives/block/rate/blockRate.ts
|
|
1445
|
-
import { isDefined as
|
|
1481
|
+
import { isDefined as isDefined7, isFalsy } from "@xylabs/sdk-js";
|
|
1446
1482
|
import { asXL1BlockRange } from "@xyo-network/xl1-protocol-lib";
|
|
1447
1483
|
|
|
1448
1484
|
// src/primitives/block/rate/timeHelpers.ts
|
|
1449
|
-
import { assertEx as assertEx8, isDefined as
|
|
1485
|
+
import { assertEx as assertEx8, isDefined as isDefined6 } from "@xylabs/sdk-js";
|
|
1450
1486
|
var rateMultipliers = {
|
|
1451
1487
|
millis: 1,
|
|
1452
1488
|
seconds: 1e3,
|
|
@@ -1464,7 +1500,7 @@ var timeDurations = (timeInMs) => ({
|
|
|
1464
1500
|
weeks: timeInMs / (1e3 * 60 * 60 * 24 * 7)
|
|
1465
1501
|
});
|
|
1466
1502
|
var getTimeConfigInMilliseconds = (timeConfig) => {
|
|
1467
|
-
const assertedTimeConfig = assertEx8(
|
|
1503
|
+
const assertedTimeConfig = assertEx8(isDefined6(timeConfig) ? timeConfig : void 0, () => "Time configuration must be provided");
|
|
1468
1504
|
let totalMilliseconds = 0;
|
|
1469
1505
|
if ("years" in assertedTimeConfig) {
|
|
1470
1506
|
totalMilliseconds += assertedTimeConfig.years * 31536e6;
|
|
@@ -1503,13 +1539,13 @@ var blockRate = (startBlock, endBlock, timeUnit) => {
|
|
|
1503
1539
|
throw new Error("Time difference must be greater than 0");
|
|
1504
1540
|
}
|
|
1505
1541
|
const rate = heightDifference / timeDifference;
|
|
1506
|
-
const timeUnitValue =
|
|
1507
|
-
const returnedTimeDifference =
|
|
1542
|
+
const timeUnitValue = isDefined7(timeUnit) ? timeUnit : "millis";
|
|
1543
|
+
const returnedTimeDifference = isDefined7(timeUnit) ? timeDurations(timeDifference)[timeUnit] : timeDifference;
|
|
1508
1544
|
const timePerBlock = returnedTimeDifference / heightDifference;
|
|
1509
1545
|
return {
|
|
1510
1546
|
range: asXL1BlockRange([startingBlock.block, endingBlock.block], true),
|
|
1511
1547
|
span: heightDifference,
|
|
1512
|
-
rate:
|
|
1548
|
+
rate: isDefined7(timeUnit) ? rate * rateMultipliers[timeUnit] : rate,
|
|
1513
1549
|
timeUnit: timeUnitValue,
|
|
1514
1550
|
timeDifference: returnedTimeDifference,
|
|
1515
1551
|
timePerBlock
|
|
@@ -1557,7 +1593,7 @@ var calculateStepSizeRate = async (viewer, start, stepIndex, count = 1, timeUnit
|
|
|
1557
1593
|
// src/primitives/block/rate/timeRate.ts
|
|
1558
1594
|
import {
|
|
1559
1595
|
assertEx as assertEx10,
|
|
1560
|
-
isDefined as
|
|
1596
|
+
isDefined as isDefined8,
|
|
1561
1597
|
isDefinedNotNull
|
|
1562
1598
|
} from "@xylabs/sdk-js";
|
|
1563
1599
|
import { asXL1BlockNumber as asXL1BlockNumber3, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol-lib";
|
|
@@ -1594,7 +1630,7 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
|
|
|
1594
1630
|
}
|
|
1595
1631
|
const endBlock = await viewer.blockByNumber(estimatedEndBlockNumber);
|
|
1596
1632
|
const resolvedEndBlock = assertEx10(
|
|
1597
|
-
|
|
1633
|
+
isDefined8(endBlock?.[0]) ? endBlock[0] : void 0,
|
|
1598
1634
|
() => `Could not retrieve block ${estimatedEndBlockNumber} for time rate calculation`
|
|
1599
1635
|
);
|
|
1600
1636
|
const endBlockEpoch = resolvedEndBlock.$epoch;
|
|
@@ -1631,7 +1667,7 @@ var findEndBlockRecursive = async (viewer, startBlock, targetTimeMs, estimatedBl
|
|
|
1631
1667
|
// src/primitives/chain/getWindowedChain.ts
|
|
1632
1668
|
import {
|
|
1633
1669
|
assertEx as assertEx11,
|
|
1634
|
-
isDefined as
|
|
1670
|
+
isDefined as isDefined9,
|
|
1635
1671
|
isNull,
|
|
1636
1672
|
spanRootAsync
|
|
1637
1673
|
} from "@xylabs/sdk-js";
|
|
@@ -1645,7 +1681,7 @@ async function getWindowedChain(context, blockViewer, maxWindowSize, previousCha
|
|
|
1645
1681
|
while (currentBlock !== null && newChain.length < maxWindowSize) {
|
|
1646
1682
|
const currentBlockNumber = currentBlock[0].block;
|
|
1647
1683
|
const nextBlock = newChain[0];
|
|
1648
|
-
if (
|
|
1684
|
+
if (isDefined9(nextBlock)) {
|
|
1649
1685
|
const nextBlockNumber = nextBlock[0].block;
|
|
1650
1686
|
assertEx11(
|
|
1651
1687
|
currentBlockNumber === nextBlockNumber - 1,
|
|
@@ -1740,7 +1776,7 @@ async function chainStepRewardAddress(context, blockViewer, { block, step }) {
|
|
|
1740
1776
|
}
|
|
1741
1777
|
|
|
1742
1778
|
// src/primitives/chain/step/stepRewardTotal.ts
|
|
1743
|
-
import { assertEx as assertEx15, isDefined as
|
|
1779
|
+
import { assertEx as assertEx15, isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
1744
1780
|
import {
|
|
1745
1781
|
asAttoXL1,
|
|
1746
1782
|
asXL1BlockRange as asXL1BlockRange5,
|
|
@@ -1829,7 +1865,7 @@ function stepInRange(step, range) {
|
|
|
1829
1865
|
return stepRange[0] >= range[0] && stepRange[1] <= range[1];
|
|
1830
1866
|
}
|
|
1831
1867
|
async function stepRewardTotal(context, blockViewer, { block, step }, multipliers) {
|
|
1832
|
-
const cacheKey = `${block}|${step}|${
|
|
1868
|
+
const cacheKey = `${block}|${step}|${isDefined10(multipliers)}`;
|
|
1833
1869
|
return await withContextCacheResponse(context, "stepRewardTotal", cacheKey, async () => {
|
|
1834
1870
|
const [blockBw, payloads] = await stepRewardBlock(context, blockViewer, { block, step });
|
|
1835
1871
|
assertEx15(blockBw.block === block, () => `Block Mismatch: expected ${block}, got ${blockBw.block}`);
|
|
@@ -1918,7 +1954,7 @@ async function externalBlockRangeFromStep(context, blockViewer, stepIdentity) {
|
|
|
1918
1954
|
}
|
|
1919
1955
|
|
|
1920
1956
|
// src/primitives/mapToMapType.ts
|
|
1921
|
-
import { isDefined as
|
|
1957
|
+
import { isDefined as isDefined11 } from "@xylabs/sdk-js";
|
|
1922
1958
|
function mapToMapType(map) {
|
|
1923
1959
|
return {
|
|
1924
1960
|
get: (key) => map.get(key),
|
|
@@ -1937,7 +1973,7 @@ function mapToMapType(map) {
|
|
|
1937
1973
|
const result = [];
|
|
1938
1974
|
for (const key of keys) {
|
|
1939
1975
|
const value = map.get(key);
|
|
1940
|
-
if (
|
|
1976
|
+
if (isDefined11(value)) {
|
|
1941
1977
|
result.push(value);
|
|
1942
1978
|
}
|
|
1943
1979
|
}
|
|
@@ -1952,7 +1988,7 @@ function mapToMapType(map) {
|
|
|
1952
1988
|
}
|
|
1953
1989
|
|
|
1954
1990
|
// src/primitives/readPayloadMapFromStore.ts
|
|
1955
|
-
import { isDefined as
|
|
1991
|
+
import { isDefined as isDefined12 } from "@xylabs/sdk-js";
|
|
1956
1992
|
function readPayloadMapFromStore(store) {
|
|
1957
1993
|
if (isReadArchivist(store)) {
|
|
1958
1994
|
return {
|
|
@@ -1963,7 +1999,7 @@ function readPayloadMapFromStore(store) {
|
|
|
1963
1999
|
return await store.get(hashes);
|
|
1964
2000
|
},
|
|
1965
2001
|
has: async (hash) => {
|
|
1966
|
-
return
|
|
2002
|
+
return isDefined12((await store.get([hash]))[0]);
|
|
1967
2003
|
}
|
|
1968
2004
|
};
|
|
1969
2005
|
}
|
|
@@ -1979,7 +2015,7 @@ function payloadMapFromStore(store) {
|
|
|
1979
2015
|
return await store.get(hashes);
|
|
1980
2016
|
},
|
|
1981
2017
|
has: async (hash) => {
|
|
1982
|
-
return
|
|
2018
|
+
return isDefined12((await store.get([hash]))[0]);
|
|
1983
2019
|
},
|
|
1984
2020
|
clear: async () => {
|
|
1985
2021
|
return await store.clear();
|
|
@@ -2025,7 +2061,7 @@ function rewardFromBlockNumber(blockNumber) {
|
|
|
2025
2061
|
import { XYO_NETWORK_STAKING_ADDRESS } from "@xyo-network/xl1-protocol-lib";
|
|
2026
2062
|
|
|
2027
2063
|
// src/primitives/stake/activeStakeAtTimeByAddress.ts
|
|
2028
|
-
import { isDefined as
|
|
2064
|
+
import { isDefined as isDefined13 } from "@xylabs/sdk-js";
|
|
2029
2065
|
|
|
2030
2066
|
// src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts
|
|
2031
2067
|
async function mergedAddRemoveStakeEventsByStaker(chainEvents, range, staked, staker) {
|
|
@@ -2044,7 +2080,7 @@ async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
|
2044
2080
|
for (const event of stakeEvents) {
|
|
2045
2081
|
if (event.time > time) break;
|
|
2046
2082
|
if (event.args.staked !== staked) continue;
|
|
2047
|
-
if (
|
|
2083
|
+
if (isDefined13(staker) && event.args.staker !== staker) continue;
|
|
2048
2084
|
if (event.name === "StakeAdded") {
|
|
2049
2085
|
result += event.args.amount;
|
|
2050
2086
|
} else if (event.name === "StakeRemoved") {
|
|
@@ -2055,7 +2091,7 @@ async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
|
2055
2091
|
}
|
|
2056
2092
|
|
|
2057
2093
|
// src/primitives/stake/activeStakeAtTimeByPosition.ts
|
|
2058
|
-
import { isUndefined as
|
|
2094
|
+
import { isUndefined as isUndefined7 } from "@xylabs/sdk-js";
|
|
2059
2095
|
|
|
2060
2096
|
// src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts
|
|
2061
2097
|
async function mergedAddRemoveStakeEventsByPosition(chainEvents, range, position) {
|
|
@@ -2073,7 +2109,7 @@ async function activeStakeAtTimeByPosition(chainStakeEvents, externalTime, posit
|
|
|
2073
2109
|
let result = 0n;
|
|
2074
2110
|
for (const event of stakeEvents) {
|
|
2075
2111
|
if (event.time > externalTime) break;
|
|
2076
|
-
if (
|
|
2112
|
+
if (isUndefined7(position) || position === Number(event.args.id)) {
|
|
2077
2113
|
if (event.name === "StakeAdded") {
|
|
2078
2114
|
result += event.args.amount;
|
|
2079
2115
|
} else if (event.name === "StakeRemoved") {
|
|
@@ -2117,13 +2153,13 @@ async function allStakersForStep(context, blockViewer, stakeEventsViewer, stepCo
|
|
|
2117
2153
|
}
|
|
2118
2154
|
|
|
2119
2155
|
// src/primitives/stake/weightedStakeForRangeByPosition.ts
|
|
2120
|
-
import { isDefined as
|
|
2156
|
+
import { isDefined as isDefined14 } from "@xylabs/sdk-js";
|
|
2121
2157
|
import { asBlockNumber as asBlockNumber2 } from "@xyo-network/xl1-protocol-lib";
|
|
2122
2158
|
async function weightedStakeForRangeByPosition(context, blockViewer, stakeEventsViewer, externalRange, staked, positionId) {
|
|
2123
|
-
const cacheKey =
|
|
2159
|
+
const cacheKey = isDefined14(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`;
|
|
2124
2160
|
return await withContextCacheResponse(context, "weightedStakeForRangeByPosition", cacheKey, async () => {
|
|
2125
2161
|
let weightedStakeSum = 0n;
|
|
2126
|
-
if (
|
|
2162
|
+
if (isDefined14(positionId)) {
|
|
2127
2163
|
const mergedEvents = (await mergedAddRemoveStakeEventsByPosition(
|
|
2128
2164
|
stakeEventsViewer,
|
|
2129
2165
|
[0, externalRange[1]],
|
|
@@ -2131,7 +2167,7 @@ async function weightedStakeForRangeByPosition(context, blockViewer, stakeEvents
|
|
|
2131
2167
|
)).toSorted((a, b) => a.time - b.time);
|
|
2132
2168
|
let currentTime = externalRange[0];
|
|
2133
2169
|
let currentStake = 0n;
|
|
2134
|
-
if (
|
|
2170
|
+
if (isDefined14(staked) && mergedEvents.at(0)?.args.staked !== staked) {
|
|
2135
2171
|
return 0n;
|
|
2136
2172
|
}
|
|
2137
2173
|
for (const event of mergedEvents) {
|
|
@@ -2320,24 +2356,24 @@ function findUncles(context, finalizedWindowedChain, blocks) {
|
|
|
2320
2356
|
}
|
|
2321
2357
|
|
|
2322
2358
|
// src/config/Validation.ts
|
|
2323
|
-
var ValidationConfigZod =
|
|
2324
|
-
allowedRewardRedeemers:
|
|
2359
|
+
var ValidationConfigZod = z16.object({
|
|
2360
|
+
allowedRewardRedeemers: z16.array(XyoAddressZod2).optional().register(globalRegistry12, {
|
|
2325
2361
|
description: "List of allowed reward redeemer addresses, if undefined anyone can participate",
|
|
2326
2362
|
title: "allowedRewardRedeemers",
|
|
2327
2363
|
type: "array"
|
|
2328
2364
|
}),
|
|
2329
|
-
allowedRewardEscrowAccountSigners:
|
|
2365
|
+
allowedRewardEscrowAccountSigners: z16.array(XyoAddressZod2).optional().register(globalRegistry12, {
|
|
2330
2366
|
description: "List of allowed reward escrow account signer addresses, if undefined anyone can participate",
|
|
2331
2367
|
title: "allowedRewardEscrowAccountSigners",
|
|
2332
2368
|
type: "array"
|
|
2333
2369
|
}),
|
|
2334
|
-
minCandidates:
|
|
2370
|
+
minCandidates: z16.coerce.number().default(DEFAULT_MIN_CANDIDATES).register(globalRegistry12, {
|
|
2335
2371
|
default: DEFAULT_MIN_CANDIDATES,
|
|
2336
2372
|
description: "Minimum number of uncle candidates before selecting the best uncle",
|
|
2337
2373
|
title: "validation.minCandidates",
|
|
2338
2374
|
type: "number"
|
|
2339
2375
|
}),
|
|
2340
|
-
backoffMs:
|
|
2376
|
+
backoffMs: z16.coerce.number().default(DEFAULT_BACKOFF_MS).register(globalRegistry12, {
|
|
2341
2377
|
default: DEFAULT_BACKOFF_MS,
|
|
2342
2378
|
description: "Back-off timeout in ms. If head age exceeds this, minCandidates is ignored",
|
|
2343
2379
|
title: "validation.backoffMs",
|
|
@@ -2346,26 +2382,26 @@ var ValidationConfigZod = z15.object({
|
|
|
2346
2382
|
});
|
|
2347
2383
|
|
|
2348
2384
|
// src/config/Base.ts
|
|
2349
|
-
var BaseConfigZod =
|
|
2350
|
-
chain:
|
|
2351
|
-
dataLake:
|
|
2352
|
-
evm:
|
|
2353
|
-
log:
|
|
2354
|
-
providers:
|
|
2355
|
-
remote:
|
|
2356
|
-
storage:
|
|
2357
|
-
telemetry:
|
|
2358
|
-
validation:
|
|
2385
|
+
var BaseConfigZod = z17.object({
|
|
2386
|
+
chain: z17._default(ChainConfigZod, ChainConfigZod.parse({})).check(z17.describe("Configuration for the chain")),
|
|
2387
|
+
dataLake: z17.optional(DataLakeConfigZod).check(z17.describe("Configuration for data lakes")),
|
|
2388
|
+
evm: z17._default(EvmConfigZod, EvmConfigZod.parse({})).check(z17.describe("Configuration for EVM-backed services")),
|
|
2389
|
+
log: z17._default(LogConfigZod, LogConfigZod.parse({})).check(z17.describe("Configuration for logging")),
|
|
2390
|
+
providers: z17._default(ProvidersConfigZod, ProvidersConfigZod.parse([])).check(z17.describe("Configuration for providers")),
|
|
2391
|
+
remote: z17._default(RemoteConfigZod, RemoteConfigZod.parse({})).check(z17.describe("Configuration for remote services")),
|
|
2392
|
+
storage: z17._default(StorageConfigZod, StorageConfigZod.parse({})).check(z17.describe("Configuration for the storage")),
|
|
2393
|
+
telemetry: z17._default(TelemetryConfigZod, TelemetryConfigZod.parse({})).check(z17.describe("Configuration for telemetry")),
|
|
2394
|
+
validation: z17._default(ValidationConfigZod, ValidationConfigZod.parse({})).check(z17.describe("Configuration for validation"))
|
|
2359
2395
|
});
|
|
2360
2396
|
|
|
2361
2397
|
// src/config/Actor.ts
|
|
2362
|
-
var AccountPathZod =
|
|
2398
|
+
var AccountPathZod = z18.string().check(z18.regex(
|
|
2363
2399
|
/^(m(\/\d+'?)+|\d+'?(\/\d+'?)*)$/,
|
|
2364
2400
|
`Invalid BIP-32 derivation path. Use either an absolute path like "m/44'/60'/0'/0/0" or a relative path like "0", "0/1", or "44'/60'/0'/0/0".`
|
|
2365
2401
|
));
|
|
2366
|
-
var ActorConfigZod =
|
|
2367
|
-
name:
|
|
2368
|
-
accountPath:
|
|
2402
|
+
var ActorConfigZod = z18.extend(BaseConfigZod, {
|
|
2403
|
+
name: z18.string(),
|
|
2404
|
+
accountPath: z18.optional(AccountPathZod).register(globalRegistry13, {
|
|
2369
2405
|
description: 'BIP-32 derivation path for the actor wallet. Absolute when it starts with "m/"; otherwise relative to the root wallet base path. Each actor must derive to a distinct path.',
|
|
2370
2406
|
title: "accountPath",
|
|
2371
2407
|
type: "string"
|
|
@@ -2376,22 +2412,22 @@ var asActorConfig = zodAsFactory3(ActorConfigZod, "asActorConfig");
|
|
|
2376
2412
|
var toActorConfig = zodToFactory2(ActorConfigZod, "toActorConfig");
|
|
2377
2413
|
|
|
2378
2414
|
// src/config/Actors.ts
|
|
2379
|
-
import { z as
|
|
2380
|
-
var ActorsConfigZod =
|
|
2381
|
-
|
|
2415
|
+
import { z as z19 } from "zod/mini";
|
|
2416
|
+
var ActorsConfigZod = z19._default(
|
|
2417
|
+
z19.array(z19.looseObject(ActorConfigZod.shape)).check(z19.describe("Actor-specific configurations that override the base configuration when the actor is running")),
|
|
2382
2418
|
[]
|
|
2383
2419
|
);
|
|
2384
2420
|
|
|
2385
2421
|
// src/config/Config.ts
|
|
2386
|
-
import { globalRegistry as
|
|
2387
|
-
var ConfigZod =
|
|
2422
|
+
import { globalRegistry as globalRegistry14, z as z20 } from "zod/mini";
|
|
2423
|
+
var ConfigZod = z20.extend(BaseConfigZod, {
|
|
2388
2424
|
actors: ActorsConfigZod,
|
|
2389
|
-
healthCheckPort:
|
|
2425
|
+
healthCheckPort: z20.optional(z20.coerce.number()).register(globalRegistry14, {
|
|
2390
2426
|
description: "Port for the system-wide health, readiness, and liveness endpoints (/healthz, /livez, /readyz). Set to 0 to disable.",
|
|
2391
2427
|
title: "healthCheckPort",
|
|
2392
2428
|
type: "number"
|
|
2393
2429
|
})
|
|
2394
|
-
}).check(
|
|
2430
|
+
}).check(z20.describe("The complete configuration for the protocol, including global settings and actor-specific overrides"));
|
|
2395
2431
|
function resolveConfig(config) {
|
|
2396
2432
|
const parsedConfig = ConfigZod.parse(config);
|
|
2397
2433
|
const {
|
|
@@ -2400,7 +2436,7 @@ function resolveConfig(config) {
|
|
|
2400
2436
|
...rootConfig
|
|
2401
2437
|
} = parsedConfig;
|
|
2402
2438
|
parsedConfig.actors = actors.map((actorConfig) => {
|
|
2403
|
-
return
|
|
2439
|
+
return z20.looseObject(ActorConfigZod.shape).parse({ ...rootConfig, ...actorConfig });
|
|
2404
2440
|
});
|
|
2405
2441
|
return parsedConfig;
|
|
2406
2442
|
}
|
|
@@ -2411,15 +2447,15 @@ import {
|
|
|
2411
2447
|
zodIsFactory as zodIsFactory3,
|
|
2412
2448
|
zodToFactory as zodToFactory3
|
|
2413
2449
|
} from "@xylabs/sdk-js";
|
|
2414
|
-
import { globalRegistry as
|
|
2415
|
-
var HostActorConfigZod =
|
|
2416
|
-
host:
|
|
2450
|
+
import { globalRegistry as globalRegistry15, z as z21 } from "zod/mini";
|
|
2451
|
+
var HostActorConfigZod = z21.extend(ActorConfigZod, {
|
|
2452
|
+
host: z21._default(z21.string(), "localhost").register(globalRegistry15, {
|
|
2417
2453
|
default: "localhost",
|
|
2418
2454
|
description: "Host for the Actor",
|
|
2419
2455
|
title: "host",
|
|
2420
2456
|
type: "string"
|
|
2421
2457
|
}),
|
|
2422
|
-
port:
|
|
2458
|
+
port: z21._default(z21.coerce.number(), 8080).register(globalRegistry15, {
|
|
2423
2459
|
default: 8080,
|
|
2424
2460
|
description: "Port for the Actor",
|
|
2425
2461
|
title: "port",
|
|
@@ -2431,30 +2467,30 @@ var asHostActorConfig = zodAsFactory4(HostActorConfigZod, "asHostActorConfig");
|
|
|
2431
2467
|
var toHostActorConfig = zodToFactory3(HostActorConfigZod, "toHostActorConfig");
|
|
2432
2468
|
|
|
2433
2469
|
// src/config/UsageMeta.ts
|
|
2434
|
-
import { z as
|
|
2435
|
-
var DescriptionSchema =
|
|
2436
|
-
var TitleSchema =
|
|
2437
|
-
var JSONSchemaMetaSchema =
|
|
2438
|
-
id:
|
|
2470
|
+
import { z as z22 } from "zod";
|
|
2471
|
+
var DescriptionSchema = z22.string();
|
|
2472
|
+
var TitleSchema = z22.string();
|
|
2473
|
+
var JSONSchemaMetaSchema = z22.object({
|
|
2474
|
+
id: z22.string().optional(),
|
|
2439
2475
|
title: TitleSchema.optional(),
|
|
2440
2476
|
description: DescriptionSchema.optional(),
|
|
2441
|
-
deprecated:
|
|
2442
|
-
}).catchall(
|
|
2477
|
+
deprecated: z22.boolean().optional()
|
|
2478
|
+
}).catchall(z22.unknown());
|
|
2443
2479
|
var GlobalMetaSchema = JSONSchemaMetaSchema.extend({});
|
|
2444
|
-
var ChoicesSchema =
|
|
2480
|
+
var ChoicesSchema = z22.array(z22.union([z22.string(), z22.number(), z22.literal(true), z22.undefined()])).readonly();
|
|
2445
2481
|
var UsageMetaSchema = GlobalMetaSchema.extend({
|
|
2446
2482
|
choices: ChoicesSchema.optional(),
|
|
2447
|
-
default:
|
|
2483
|
+
default: z22.unknown().optional(),
|
|
2448
2484
|
description: DescriptionSchema,
|
|
2449
|
-
group:
|
|
2450
|
-
hidden:
|
|
2485
|
+
group: z22.string().optional(),
|
|
2486
|
+
hidden: z22.boolean().optional(),
|
|
2451
2487
|
title: TitleSchema,
|
|
2452
|
-
type:
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2488
|
+
type: z22.union([
|
|
2489
|
+
z22.literal("array"),
|
|
2490
|
+
z22.literal("count"),
|
|
2491
|
+
z22.literal("boolean"),
|
|
2492
|
+
z22.literal("number"),
|
|
2493
|
+
z22.literal("string")
|
|
2458
2494
|
])
|
|
2459
2495
|
});
|
|
2460
2496
|
function isUsageMeta(v) {
|
|
@@ -2467,7 +2503,7 @@ import {
|
|
|
2467
2503
|
zodIsFactory as zodIsFactory5,
|
|
2468
2504
|
zodToFactory as zodToFactory5
|
|
2469
2505
|
} from "@xylabs/sdk-js";
|
|
2470
|
-
import { z as
|
|
2506
|
+
import { z as z24 } from "zod/mini";
|
|
2471
2507
|
|
|
2472
2508
|
// src/model/CreatableProviderContext.zod.ts
|
|
2473
2509
|
import {
|
|
@@ -2476,17 +2512,17 @@ import {
|
|
|
2476
2512
|
zodToFactory as zodToFactory4
|
|
2477
2513
|
} from "@xylabs/sdk-js";
|
|
2478
2514
|
import { CachingContextZod } from "@xyo-network/xl1-protocol-lib";
|
|
2479
|
-
import { z as
|
|
2480
|
-
var RuntimeStatusMonitorZod =
|
|
2481
|
-
var ProviderFactoryLocatorZod =
|
|
2482
|
-
var BaseConfigContextZod =
|
|
2483
|
-
config:
|
|
2484
|
-
locator:
|
|
2515
|
+
import { z as z23 } from "zod/mini";
|
|
2516
|
+
var RuntimeStatusMonitorZod = z23.custom((val) => val && typeof val === "object");
|
|
2517
|
+
var ProviderFactoryLocatorZod = z23.lazy(() => z23.custom((val) => val && typeof val === "object" && "context" in val && "registry" in val));
|
|
2518
|
+
var BaseConfigContextZod = z23.extend(CachingContextZod, {
|
|
2519
|
+
config: z23.looseObject(BaseConfigZod.shape),
|
|
2520
|
+
locator: z23.optional(ProviderFactoryLocatorZod)
|
|
2485
2521
|
});
|
|
2486
|
-
var CreatableProviderContextZod =
|
|
2487
|
-
_id:
|
|
2522
|
+
var CreatableProviderContextZod = z23.lazy(() => z23.extend(BaseConfigContextZod, {
|
|
2523
|
+
_id: z23.optional(z23.string()),
|
|
2488
2524
|
locator: ProviderFactoryLocatorZod,
|
|
2489
|
-
statusReporter:
|
|
2525
|
+
statusReporter: z23.optional(RuntimeStatusMonitorZod)
|
|
2490
2526
|
}));
|
|
2491
2527
|
var isBaseConfigContext = zodIsFactory4(BaseConfigContextZod);
|
|
2492
2528
|
var asBaseConfigContext = zodAsFactory5(BaseConfigContextZod, "asBaseConfigContext");
|
|
@@ -2607,7 +2643,7 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
2607
2643
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
2608
2644
|
import {
|
|
2609
2645
|
delay,
|
|
2610
|
-
isDefined as
|
|
2646
|
+
isDefined as isDefined15,
|
|
2611
2647
|
isNumber
|
|
2612
2648
|
} from "@xylabs/sdk-js";
|
|
2613
2649
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
@@ -2629,7 +2665,7 @@ var confirmSubmittedTransaction = async (viewer, txHash, options) => {
|
|
|
2629
2665
|
let attempts = 0;
|
|
2630
2666
|
while (true) {
|
|
2631
2667
|
const tx = await viewer.transaction.byHash(txHash) ?? void 0;
|
|
2632
|
-
if (
|
|
2668
|
+
if (isDefined15(tx)) {
|
|
2633
2669
|
options?.logger?.debug("Transaction confirmed", txHash);
|
|
2634
2670
|
return tx;
|
|
2635
2671
|
} else {
|
|
@@ -2944,7 +2980,7 @@ var bundle2 = (root, transaction) => {
|
|
|
2944
2980
|
};
|
|
2945
2981
|
|
|
2946
2982
|
// src/context/Actor.ts
|
|
2947
|
-
var ActorConfigContext =
|
|
2983
|
+
var ActorConfigContext = z24.extend(BaseConfigContextZod, { config: ActorConfigZod });
|
|
2948
2984
|
var isActorConfigContext = zodIsFactory5(ActorConfigContext);
|
|
2949
2985
|
var asActorConfigContext = zodAsFactory6(ActorConfigContext, "asActorConfigContext");
|
|
2950
2986
|
var toActorConfigContext = zodToFactory5(ActorConfigContext, "toActorConfigContext");
|
|
@@ -3334,20 +3370,20 @@ import {
|
|
|
3334
3370
|
zodIsFactory as zodIsFactory6,
|
|
3335
3371
|
zodToFactory as zodToFactory6
|
|
3336
3372
|
} from "@xylabs/sdk-js";
|
|
3337
|
-
import { z as
|
|
3338
|
-
var HostActorConfigContext =
|
|
3373
|
+
import { z as z25 } from "zod/mini";
|
|
3374
|
+
var HostActorConfigContext = z25.extend(BaseConfigContextZod, { config: HostActorConfigZod });
|
|
3339
3375
|
var isHostActorConfigContext = zodIsFactory6(HostActorConfigContext);
|
|
3340
3376
|
var asHostActorConfigContext = zodAsFactory7(HostActorConfigContext, "asHostActorConfigContext");
|
|
3341
3377
|
var toHostActorConfigContext = zodToFactory6(HostActorConfigContext, "toHostActorConfigContext");
|
|
3342
3378
|
|
|
3343
3379
|
// src/createDeclarationPayload.ts
|
|
3344
|
-
import { isDefined as
|
|
3380
|
+
import { isDefined as isDefined16 } from "@xylabs/sdk-js";
|
|
3345
3381
|
import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/sdk-js";
|
|
3346
3382
|
import {
|
|
3347
3383
|
ChainStakeIntentSchema
|
|
3348
3384
|
} from "@xyo-network/xl1-protocol-lib";
|
|
3349
3385
|
var createDeclarationIntent = (address, intent, nbf, exp) => {
|
|
3350
|
-
const expiration =
|
|
3386
|
+
const expiration = isDefined16(exp) ? exp : nbf + 1e4;
|
|
3351
3387
|
const redeclarationIntent = new PayloadBuilder13({ schema: ChainStakeIntentSchema }).fields({
|
|
3352
3388
|
from: address,
|
|
3353
3389
|
intent,
|
|
@@ -3376,26 +3412,26 @@ import {
|
|
|
3376
3412
|
asSchema as asSchema2,
|
|
3377
3413
|
isPayloadOfZodType
|
|
3378
3414
|
} from "@xyo-network/sdk-js";
|
|
3379
|
-
import { z as
|
|
3415
|
+
import { z as z27 } from "zod";
|
|
3380
3416
|
|
|
3381
3417
|
// src/eip-712/Types.ts
|
|
3382
|
-
import { z as
|
|
3383
|
-
var TypedDataDomainZod =
|
|
3384
|
-
name:
|
|
3385
|
-
version:
|
|
3386
|
-
chainId:
|
|
3387
|
-
verifyingContract:
|
|
3388
|
-
salt:
|
|
3418
|
+
import { z as z26 } from "zod";
|
|
3419
|
+
var TypedDataDomainZod = z26.object({
|
|
3420
|
+
name: z26.string().nullable().optional(),
|
|
3421
|
+
version: z26.string().nullable().optional(),
|
|
3422
|
+
chainId: z26.union([z26.string(), z26.number(), z26.bigint()]).nullable().optional(),
|
|
3423
|
+
verifyingContract: z26.string().nullable().optional(),
|
|
3424
|
+
salt: z26.union([z26.string(), z26.instanceof(Uint8Array)]).nullable().optional()
|
|
3389
3425
|
});
|
|
3390
|
-
var TypedDataFieldZod =
|
|
3391
|
-
name:
|
|
3392
|
-
type:
|
|
3426
|
+
var TypedDataFieldZod = z26.object({
|
|
3427
|
+
name: z26.string(),
|
|
3428
|
+
type: z26.string()
|
|
3393
3429
|
});
|
|
3394
|
-
var TypedDataTypesZod =
|
|
3395
|
-
var TypedDataValueZod =
|
|
3430
|
+
var TypedDataTypesZod = z26.record(z26.string(), z26.array(TypedDataFieldZod));
|
|
3431
|
+
var TypedDataValueZod = z26.record(z26.string(), z26.any());
|
|
3396
3432
|
|
|
3397
3433
|
// src/eip-712/Payloads/EIP712Data.ts
|
|
3398
|
-
var EIP712DataPayloadFieldsZod =
|
|
3434
|
+
var EIP712DataPayloadFieldsZod = z27.object({
|
|
3399
3435
|
domain: TypedDataDomainZod,
|
|
3400
3436
|
types: TypedDataTypesZod,
|
|
3401
3437
|
values: TypedDataValueZod
|
|
@@ -3413,11 +3449,11 @@ import {
|
|
|
3413
3449
|
asSchema as asSchema3,
|
|
3414
3450
|
isPayloadOfZodType as isPayloadOfZodType2
|
|
3415
3451
|
} from "@xyo-network/sdk-js";
|
|
3416
|
-
import { z as
|
|
3417
|
-
var EIP712SignaturePayloadFieldsZod =
|
|
3418
|
-
address:
|
|
3452
|
+
import { z as z28 } from "zod";
|
|
3453
|
+
var EIP712SignaturePayloadFieldsZod = z28.object({
|
|
3454
|
+
address: z28.string(),
|
|
3419
3455
|
hash: HashZod,
|
|
3420
|
-
signature:
|
|
3456
|
+
signature: z28.string()
|
|
3421
3457
|
});
|
|
3422
3458
|
var EIP712SignaturePayloadSchema = asSchema3("network.xyo.chains.ethereum.eip712.signature", true);
|
|
3423
3459
|
var isEIP712SignaturePayload = isPayloadOfZodType2(
|
|
@@ -3446,7 +3482,7 @@ var signEIP712Message = async (signer, data) => {
|
|
|
3446
3482
|
};
|
|
3447
3483
|
|
|
3448
3484
|
// src/eip-712/verify.ts
|
|
3449
|
-
import { asHash as asHash3, isUndefined as
|
|
3485
|
+
import { asHash as asHash3, isUndefined as isUndefined8 } from "@xylabs/sdk-js";
|
|
3450
3486
|
import { PayloadBuilder as PayloadBuilder16 } from "@xyo-network/sdk-js";
|
|
3451
3487
|
import { verifyTypedData } from "ethers";
|
|
3452
3488
|
var verifyEIP712Message = async (data, sig) => {
|
|
@@ -3457,7 +3493,7 @@ var verifyEIP712Message = async (data, sig) => {
|
|
|
3457
3493
|
} = sig;
|
|
3458
3494
|
const { schema, ...fields } = data;
|
|
3459
3495
|
const signedHash = asHash3(hash);
|
|
3460
|
-
if (
|
|
3496
|
+
if (isUndefined8(signedHash) || signedHash !== await PayloadBuilder16.hash(data)) return false;
|
|
3461
3497
|
const recoveredAddress = verifyTypedData(fields.domain, fields.types, fields.values, signature);
|
|
3462
3498
|
return recoveredAddress.toLowerCase() === address.toLowerCase();
|
|
3463
3499
|
};
|
|
@@ -3528,7 +3564,7 @@ import {
|
|
|
3528
3564
|
asHash as asHash4,
|
|
3529
3565
|
assertEx as assertEx33,
|
|
3530
3566
|
exists as exists3,
|
|
3531
|
-
isDefined as
|
|
3567
|
+
isDefined as isDefined17,
|
|
3532
3568
|
ZERO_ADDRESS
|
|
3533
3569
|
} from "@xylabs/sdk-js";
|
|
3534
3570
|
import {
|
|
@@ -4043,7 +4079,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4043
4079
|
block[1].find((p) => p._hash === hash),
|
|
4044
4080
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4045
4081
|
);
|
|
4046
|
-
}).filter(exists3).filter((t) => t.from === address ||
|
|
4082
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
|
|
4047
4083
|
if (transfers.length === 0) {
|
|
4048
4084
|
continue;
|
|
4049
4085
|
}
|
|
@@ -4162,7 +4198,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4162
4198
|
return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
|
|
4163
4199
|
const range = asRange(headOrRange);
|
|
4164
4200
|
const headHash = asHash4(headOrRange);
|
|
4165
|
-
const [head] = assertEx33(
|
|
4201
|
+
const [head] = assertEx33(isDefined17(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
4166
4202
|
const startingRange = asXL1BlockRange10(range ?? [0, head.block], true);
|
|
4167
4203
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
4168
4204
|
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists3);
|
|
@@ -4175,7 +4211,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
|
|
|
4175
4211
|
block[1].find((p) => p._hash === hash),
|
|
4176
4212
|
() => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`
|
|
4177
4213
|
);
|
|
4178
|
-
}).filter(exists3).filter((t) => t.from === address ||
|
|
4214
|
+
}).filter(exists3).filter((t) => t.from === address || isDefined17(t.transfers[address]));
|
|
4179
4215
|
if (transfers.length === 0) {
|
|
4180
4216
|
continue;
|
|
4181
4217
|
}
|
|
@@ -4203,7 +4239,7 @@ SimpleAccountBalanceViewer = __decorateClass([
|
|
|
4203
4239
|
import {
|
|
4204
4240
|
assertEx as assertEx34,
|
|
4205
4241
|
exists as exists4,
|
|
4206
|
-
isUndefined as
|
|
4242
|
+
isUndefined as isUndefined9
|
|
4207
4243
|
} from "@xylabs/sdk-js";
|
|
4208
4244
|
import { LruCacheMap as LruCacheMap2 } from "@xyo-network/xl1-driver-memory";
|
|
4209
4245
|
import {
|
|
@@ -4242,12 +4278,12 @@ var HydratedCache = class {
|
|
|
4242
4278
|
};
|
|
4243
4279
|
|
|
4244
4280
|
// src/utils/isZodError.ts
|
|
4245
|
-
import { z as
|
|
4281
|
+
import { z as z29 } from "zod";
|
|
4246
4282
|
var isZodError = (error) => {
|
|
4247
|
-
return error instanceof
|
|
4283
|
+
return error instanceof z29.ZodError;
|
|
4248
4284
|
};
|
|
4249
4285
|
var prettifyZodError = (error) => {
|
|
4250
|
-
return
|
|
4286
|
+
return z29.prettifyError(error);
|
|
4251
4287
|
};
|
|
4252
4288
|
|
|
4253
4289
|
// src/simple/block/SimpleBlockViewer.ts
|
|
@@ -4315,7 +4351,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4315
4351
|
async blockByNumber(blockNumber) {
|
|
4316
4352
|
return await this.spanAsync("blockByNumber", async () => {
|
|
4317
4353
|
const chainContext = await this.getChainContextRead();
|
|
4318
|
-
if (
|
|
4354
|
+
if (isUndefined9(chainContext.head)) {
|
|
4319
4355
|
return null;
|
|
4320
4356
|
}
|
|
4321
4357
|
return await this.blockByNumberWithContext(chainContext, blockNumber);
|
|
@@ -4341,7 +4377,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4341
4377
|
assertEx34(limit > 0, () => "limit must be greater than 0");
|
|
4342
4378
|
assertEx34(limit <= 100, () => "limit must be less than 100");
|
|
4343
4379
|
const chainContext = await this.getChainContextRead();
|
|
4344
|
-
if (
|
|
4380
|
+
if (isUndefined9(chainContext.head)) {
|
|
4345
4381
|
return [];
|
|
4346
4382
|
}
|
|
4347
4383
|
const blocks = [];
|
|
@@ -4364,7 +4400,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
4364
4400
|
() => `blocksByStep does not support step levels above ${blocksMaxStep} (requested ${stepLevel})`
|
|
4365
4401
|
);
|
|
4366
4402
|
const chainContext = await this.getChainContextRead();
|
|
4367
|
-
if (
|
|
4403
|
+
if (isUndefined9(chainContext.head)) {
|
|
4368
4404
|
return [];
|
|
4369
4405
|
}
|
|
4370
4406
|
const start = stepIndex * size;
|
|
@@ -4717,7 +4753,7 @@ var SimpleXyoClient = class {
|
|
|
4717
4753
|
import { assertEx as assertEx37, exists as exists6 } from "@xylabs/sdk-js";
|
|
4718
4754
|
import { isAnyPayload as isAnyPayload8, PayloadZodLoose } from "@xyo-network/sdk-js";
|
|
4719
4755
|
import { DataLakeRunnerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
4720
|
-
import { z as
|
|
4756
|
+
import { z as z30 } from "zod/mini";
|
|
4721
4757
|
|
|
4722
4758
|
// src/simple/datalake/AbstractRestDataLake.ts
|
|
4723
4759
|
import { FetchClientError, FetchJsonClient } from "@xylabs/sdk-js";
|
|
@@ -4790,7 +4826,7 @@ var RestDataLakeRunner = class extends AbstractRestDataLake {
|
|
|
4790
4826
|
}).filter(exists6);
|
|
4791
4827
|
if (allowedItems.length > 0) {
|
|
4792
4828
|
const result = await this.client.post(`${this.params.endpoint}/insert`, allowedItems);
|
|
4793
|
-
return
|
|
4829
|
+
return z30.array(PayloadZodLoose).parse(result.data);
|
|
4794
4830
|
} else {
|
|
4795
4831
|
return [];
|
|
4796
4832
|
}
|
|
@@ -5033,7 +5069,7 @@ var SimpleXyoGateway = class _SimpleXyoGateway extends AbstractCreatableProvider
|
|
|
5033
5069
|
import {
|
|
5034
5070
|
assertEx as assertEx39,
|
|
5035
5071
|
BigIntToJsonZod,
|
|
5036
|
-
isDefined as
|
|
5072
|
+
isDefined as isDefined18
|
|
5037
5073
|
} from "@xylabs/sdk-js";
|
|
5038
5074
|
import { PayloadBuilder as PayloadBuilder20 } from "@xyo-network/sdk-js";
|
|
5039
5075
|
import {
|
|
@@ -5071,9 +5107,9 @@ var SimpleXyoGatewayRunner = class _SimpleXyoGatewayRunner extends AbstractCreat
|
|
|
5071
5107
|
chain,
|
|
5072
5108
|
fees
|
|
5073
5109
|
} = options ?? {};
|
|
5074
|
-
const resolvedChainId =
|
|
5075
|
-
const resolvedNbf = asXL1BlockNumber10(
|
|
5076
|
-
const resolvedExp = asXL1BlockNumber10(
|
|
5110
|
+
const resolvedChainId = isDefined18(chain) ? chain : await viewer.chainId();
|
|
5111
|
+
const resolvedNbf = asXL1BlockNumber10(isDefined18(nbf) ? nbf : await viewer.currentBlockNumber(), true);
|
|
5112
|
+
const resolvedExp = asXL1BlockNumber10(isDefined18(exp) ? exp : resolvedNbf + 10, true);
|
|
5077
5113
|
const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await this.signer.address(), fees);
|
|
5078
5114
|
return await this.addTransactionToChain(tx, await PayloadBuilder20.addHashMeta(offChain));
|
|
5079
5115
|
}
|
|
@@ -5561,7 +5597,7 @@ SimpleMempoolRunner = __decorateClass([
|
|
|
5561
5597
|
// src/simple/mempool/SimpleMempoolViewer.ts
|
|
5562
5598
|
import {
|
|
5563
5599
|
exists as exists9,
|
|
5564
|
-
isDefined as
|
|
5600
|
+
isDefined as isDefined19,
|
|
5565
5601
|
isHash as isHash2
|
|
5566
5602
|
} from "@xylabs/sdk-js";
|
|
5567
5603
|
import { isHashMeta as isHashMeta2, isPayloadBundle as isPayloadBundle2 } from "@xyo-network/sdk-js";
|
|
@@ -5622,7 +5658,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5622
5658
|
let cursor = void 0;
|
|
5623
5659
|
if (isHash2(providedCursor)) {
|
|
5624
5660
|
const [p] = await this.pendingBlocksArchivist.get([providedCursor]);
|
|
5625
|
-
if (
|
|
5661
|
+
if (isDefined19(p)) {
|
|
5626
5662
|
cursor = p._sequence;
|
|
5627
5663
|
}
|
|
5628
5664
|
}
|
|
@@ -5641,7 +5677,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5641
5677
|
let cursor = void 0;
|
|
5642
5678
|
if (isHash2(providedCursor)) {
|
|
5643
5679
|
const [p] = await this.pendingTransactionsArchivist.get([providedCursor]);
|
|
5644
|
-
if (
|
|
5680
|
+
if (isDefined19(p)) {
|
|
5645
5681
|
cursor = p._sequence;
|
|
5646
5682
|
}
|
|
5647
5683
|
}
|
|
@@ -5656,7 +5692,7 @@ var SimpleMempoolViewer = class extends AbstractCreatableProvider {
|
|
|
5656
5692
|
const hydratedWithBundle = (await Promise.all(
|
|
5657
5693
|
filteredBundles.map(async (bundle3) => {
|
|
5658
5694
|
const tx = await bundledPayloadToHydratedTransaction(bundle3);
|
|
5659
|
-
return
|
|
5695
|
+
return isDefined19(tx) ? { bundle: bundle3, tx } : void 0;
|
|
5660
5696
|
})
|
|
5661
5697
|
)).filter(exists9);
|
|
5662
5698
|
const currentBlock = await this.windowedBlockViewer.currentBlock();
|
|
@@ -5776,7 +5812,7 @@ function deduplicateWithBundleBySigner(items) {
|
|
|
5776
5812
|
}
|
|
5777
5813
|
|
|
5778
5814
|
// src/simple/network/SimpleXyoNetwork.ts
|
|
5779
|
-
import { fetchJsonGet, isUndefined as
|
|
5815
|
+
import { fetchJsonGet, isUndefined as isUndefined10 } from "@xylabs/sdk-js";
|
|
5780
5816
|
import { isNetworkStatus } from "@xyo-network/xl1-protocol-lib";
|
|
5781
5817
|
|
|
5782
5818
|
// src/simple/network/lib/FailedNetworkStatusPayloads.ts
|
|
@@ -5824,7 +5860,7 @@ var SimpleXyoNetwork = class {
|
|
|
5824
5860
|
}
|
|
5825
5861
|
async status() {
|
|
5826
5862
|
const statusNetwork = StatusNetworks[this._networkId];
|
|
5827
|
-
if (
|
|
5863
|
+
if (isUndefined10(statusNetwork)) {
|
|
5828
5864
|
throw new Error(`Unknown status network ID: ${this._networkId}`);
|
|
5829
5865
|
}
|
|
5830
5866
|
return await this.makeRequest(statusNetwork.statusUrl);
|
|
@@ -6007,7 +6043,7 @@ var SimpleXyoSigner = class _SimpleXyoSigner extends AbstractCreatableProvider {
|
|
|
6007
6043
|
};
|
|
6008
6044
|
|
|
6009
6045
|
// src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts
|
|
6010
|
-
import { isDefined as
|
|
6046
|
+
import { isDefined as isDefined20 } from "@xylabs/sdk-js";
|
|
6011
6047
|
import { StakeEventsViewerMoniker } from "@xyo-network/xl1-protocol-lib";
|
|
6012
6048
|
var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
|
|
6013
6049
|
moniker = SimpleStakeEventsViewer.defaultMoniker;
|
|
@@ -6020,7 +6056,7 @@ var SimpleStakeEventsViewer = class extends AbstractCreatableProvider {
|
|
|
6020
6056
|
stakeEvents(range, { name } = {}) {
|
|
6021
6057
|
const positions = this.positionsFromRange(range);
|
|
6022
6058
|
const events = this.eventsFromPositions(positions);
|
|
6023
|
-
if (
|
|
6059
|
+
if (isDefined20(name)) {
|
|
6024
6060
|
return events.filter((event) => event.name === name);
|
|
6025
6061
|
}
|
|
6026
6062
|
return events;
|
|
@@ -6368,7 +6404,7 @@ RestSyncViewer = __decorateClass([
|
|
|
6368
6404
|
import {
|
|
6369
6405
|
asHash as asHash5,
|
|
6370
6406
|
assertEx as assertEx45,
|
|
6371
|
-
isDefined as
|
|
6407
|
+
isDefined as isDefined21
|
|
6372
6408
|
} from "@xylabs/sdk-js";
|
|
6373
6409
|
import {
|
|
6374
6410
|
asTimePayload as asTimePayload2,
|
|
@@ -6392,7 +6428,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6392
6428
|
const [block, payloads] = assertEx45(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
|
|
6393
6429
|
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
|
|
6394
6430
|
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
6395
|
-
const timePayload = asTimePayload2(
|
|
6431
|
+
const timePayload = asTimePayload2(isDefined21(hash) ? payloads.find((p) => p._hash === hash) : void 0);
|
|
6396
6432
|
if (timePayload === void 0) return 0;
|
|
6397
6433
|
switch (toDomain) {
|
|
6398
6434
|
case "xl1": {
|
|
@@ -6465,7 +6501,7 @@ var SimpleTimeSyncViewer = class extends AbstractCreatableProvider {
|
|
|
6465
6501
|
xl1Hash: assertEx45(xl1Hash, () => "No xl1 hash available from time sync service"),
|
|
6466
6502
|
epoch: Date.now()
|
|
6467
6503
|
};
|
|
6468
|
-
if (
|
|
6504
|
+
if (isDefined21(this.ethProvider)) {
|
|
6469
6505
|
const [ethereum, ethHashOrNull] = await this.currentTimeAndHash("ethereum");
|
|
6470
6506
|
const ethereumHash = asHash5(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
6471
6507
|
timePayload.ethereum = ethereum;
|
|
@@ -6935,14 +6971,375 @@ var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
|
6935
6971
|
}
|
|
6936
6972
|
};
|
|
6937
6973
|
|
|
6974
|
+
// src/test/buildRandomChain.ts
|
|
6975
|
+
import { asAddress as asAddress2, assertEx as assertEx51 } from "@xylabs/sdk-js";
|
|
6976
|
+
import {
|
|
6977
|
+
Account as Account4,
|
|
6978
|
+
asSchema as asSchema11,
|
|
6979
|
+
IdSchema as IdSchema2,
|
|
6980
|
+
MemoryArchivist,
|
|
6981
|
+
PayloadBuilder as PayloadBuilder29
|
|
6982
|
+
} from "@xyo-network/sdk-js";
|
|
6983
|
+
import {
|
|
6984
|
+
asXL1BlockNumber as asXL1BlockNumber17
|
|
6985
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
6986
|
+
|
|
6987
|
+
// src/test/buildNextBlock.ts
|
|
6988
|
+
import {
|
|
6989
|
+
AttoXL1 as AttoXL15,
|
|
6990
|
+
XYO_STEP_REWARD_ADDRESS as XYO_STEP_REWARD_ADDRESS4
|
|
6991
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
6992
|
+
|
|
6993
|
+
// src/test/buildBlock.ts
|
|
6994
|
+
import { assertEx as assertEx49, isDefined as isDefined22 } from "@xylabs/sdk-js";
|
|
6995
|
+
import {
|
|
6996
|
+
asAnyPayload as asAnyPayload5,
|
|
6997
|
+
BoundWitnessBuilder as BoundWitnessBuilder3,
|
|
6998
|
+
PayloadBuilder as PayloadBuilder25
|
|
6999
|
+
} from "@xyo-network/sdk-js";
|
|
7000
|
+
import {
|
|
7001
|
+
asXL1BlockNumber as asXL1BlockNumber13,
|
|
7002
|
+
AttoXL1 as AttoXL14,
|
|
7003
|
+
isBlockBoundWitness,
|
|
7004
|
+
rewardAddressFromStepIdentity,
|
|
7005
|
+
StepRewardFractions,
|
|
7006
|
+
StepSizes as StepSizes15,
|
|
7007
|
+
XL1_PROTOCOL_VERSION,
|
|
7008
|
+
XYO_STEP_REWARD_ADDRESS as XYO_STEP_REWARD_ADDRESS3,
|
|
7009
|
+
XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS2
|
|
7010
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
7011
|
+
|
|
7012
|
+
// src/test/BuildBlockOptions.ts
|
|
7013
|
+
import {
|
|
7014
|
+
isAddress,
|
|
7015
|
+
isArray as isArray2,
|
|
7016
|
+
isHash as isHash3,
|
|
7017
|
+
isNumber as isNumber2,
|
|
7018
|
+
isObject as isObject3
|
|
7019
|
+
} from "@xylabs/sdk-js";
|
|
7020
|
+
var isBaseBuildBlockOptions = (value) => {
|
|
7021
|
+
if (!isObject3(value)) {
|
|
7022
|
+
return false;
|
|
7023
|
+
}
|
|
7024
|
+
const typedValue = value;
|
|
7025
|
+
if (!isArray2(typedValue.blockPayloads) || !isAddress(typedValue.chainId) || !isArray2(typedValue.signers) || !isArray2(typedValue.txs)) {
|
|
7026
|
+
return false;
|
|
7027
|
+
}
|
|
7028
|
+
return true;
|
|
7029
|
+
};
|
|
7030
|
+
var isBuildGenesisBlockOptions = (value) => {
|
|
7031
|
+
if (!isBaseBuildBlockOptions(value)) {
|
|
7032
|
+
return false;
|
|
7033
|
+
}
|
|
7034
|
+
const typedValue = value;
|
|
7035
|
+
if (typedValue.previousBlockHash !== null) {
|
|
7036
|
+
return false;
|
|
7037
|
+
}
|
|
7038
|
+
if (typedValue.previousBlockNumber !== void 0) {
|
|
7039
|
+
return false;
|
|
7040
|
+
}
|
|
7041
|
+
return true;
|
|
7042
|
+
};
|
|
7043
|
+
var isBuildNextBlockOptions = (value) => {
|
|
7044
|
+
if (!isBaseBuildBlockOptions(value)) {
|
|
7045
|
+
return false;
|
|
7046
|
+
}
|
|
7047
|
+
const typedValue = value;
|
|
7048
|
+
if (!isHash3(typedValue.previousBlockHash)) {
|
|
7049
|
+
return false;
|
|
7050
|
+
}
|
|
7051
|
+
if (!isNumber2(typedValue.previousBlockNumber)) {
|
|
7052
|
+
return false;
|
|
7053
|
+
}
|
|
7054
|
+
if (!isArray2(typedValue.previousStepHashes)) {
|
|
7055
|
+
return false;
|
|
7056
|
+
}
|
|
7057
|
+
return true;
|
|
7058
|
+
};
|
|
7059
|
+
|
|
7060
|
+
// src/test/buildBlock.ts
|
|
7061
|
+
function calculateCompletedStepReward(step, balance) {
|
|
7062
|
+
return AttoXL14(StepRewardFractions[step][0] * balance / StepRewardFractions[step][1]);
|
|
7063
|
+
}
|
|
7064
|
+
async function buildBlock(options) {
|
|
7065
|
+
const previousBlockNumber = isBuildGenesisBlockOptions(options) ? -1 : options.previousBlockNumber;
|
|
7066
|
+
const blockNumber = asXL1BlockNumber13(previousBlockNumber + 1, true);
|
|
7067
|
+
const inStepHashes = isBuildNextBlockOptions(options) ? options.previousStepHashes : [];
|
|
7068
|
+
const previousBlockHash = isBuildNextBlockOptions(options) ? options.previousBlockHash : void 0;
|
|
7069
|
+
const stepRewardPoolBalance = isBuildNextBlockOptions(options) ? options.stepRewardPoolBalance : AttoXL14(0n);
|
|
7070
|
+
const {
|
|
7071
|
+
chainId,
|
|
7072
|
+
txs,
|
|
7073
|
+
chainStepRewardAddress: chainStepRewardAddress2 = XYO_STEP_REWARD_ADDRESS3,
|
|
7074
|
+
blockPayloads,
|
|
7075
|
+
protocol = XL1_PROTOCOL_VERSION,
|
|
7076
|
+
signers
|
|
7077
|
+
} = options;
|
|
7078
|
+
const step_hashes = [];
|
|
7079
|
+
for (const [tx] of txs) {
|
|
7080
|
+
if (tx.nbf > blockNumber) {
|
|
7081
|
+
throw new Error(`Transaction ${await PayloadBuilder25.hash(tx)} not valid for block ${blockNumber} - NBF is ${tx.nbf}`);
|
|
7082
|
+
}
|
|
7083
|
+
if (tx.exp < blockNumber) {
|
|
7084
|
+
throw new Error(`Transaction ${await PayloadBuilder25.hash(tx)} not valid for block ${blockNumber} - EXP is ${tx.exp}`);
|
|
7085
|
+
}
|
|
7086
|
+
}
|
|
7087
|
+
const completedStepRewardTransfers = [];
|
|
7088
|
+
for (const [i, step] of StepSizes15.entries()) {
|
|
7089
|
+
if (blockNumber < step) {
|
|
7090
|
+
break;
|
|
7091
|
+
}
|
|
7092
|
+
if (blockNumber % step === 0) {
|
|
7093
|
+
if (StepRewardFractions[i][0] > 0 && chainStepRewardAddress2 !== XYO_ZERO_ADDRESS2) {
|
|
7094
|
+
const completedStepRewardHolderAddress = rewardAddressFromStepIdentity({ block: blockNumber, step });
|
|
7095
|
+
const completedStepReward = calculateCompletedStepReward(i, stepRewardPoolBalance);
|
|
7096
|
+
completedStepRewardTransfers.push(createTransferPayload(chainStepRewardAddress2, { [completedStepRewardHolderAddress]: completedStepReward }));
|
|
7097
|
+
}
|
|
7098
|
+
step_hashes.push(assertEx49(previousBlockHash, () => `Previous block hash is required for step ${step} at block ${blockNumber}`));
|
|
7099
|
+
} else {
|
|
7100
|
+
if (isDefined22(inStepHashes.at(i))) {
|
|
7101
|
+
step_hashes.push(inStepHashes[i]);
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
}
|
|
7105
|
+
const previous = previousBlockHash ?? null;
|
|
7106
|
+
const block = blockNumber;
|
|
7107
|
+
const txElevatedPayloads = await validateTransactionsOpcodes(txs);
|
|
7108
|
+
const payloads = [
|
|
7109
|
+
...txs.map(([tx]) => tx),
|
|
7110
|
+
...blockPayloads,
|
|
7111
|
+
...txElevatedPayloads,
|
|
7112
|
+
...completedStepRewardTransfers
|
|
7113
|
+
];
|
|
7114
|
+
const [bw, txPayloads] = await new BoundWitnessBuilder3().fields({
|
|
7115
|
+
block,
|
|
7116
|
+
chain: chainId,
|
|
7117
|
+
previous,
|
|
7118
|
+
step_hashes,
|
|
7119
|
+
protocol
|
|
7120
|
+
}).meta({ $epoch: Date.now(), $signatures: [] }).signers(signers).payloads(await PayloadBuilder25.addStorageMeta(payloads)).build();
|
|
7121
|
+
assertEx49(isBlockBoundWitness(bw), () => "Build of BlockBoundWitness failed");
|
|
7122
|
+
return [await PayloadBuilder25.addStorageMeta(bw), txPayloads.map((p) => asAnyPayload5(p, true))];
|
|
7123
|
+
}
|
|
7124
|
+
|
|
7125
|
+
// src/test/buildNextBlock.ts
|
|
7126
|
+
async function buildNextBlock(previousBlock, txs, blockPayloads, signers, chainStepRewardAddress2 = XYO_STEP_REWARD_ADDRESS4, stepRewardPoolBalance = AttoXL15(0n), protocol, chainId) {
|
|
7127
|
+
return await buildBlock({
|
|
7128
|
+
chainId: chainId ?? previousBlock.chain,
|
|
7129
|
+
previousBlockNumber: previousBlock.block,
|
|
7130
|
+
previousStepHashes: previousBlock.step_hashes ?? [],
|
|
7131
|
+
previousBlockHash: previousBlock._hash,
|
|
7132
|
+
txs,
|
|
7133
|
+
blockPayloads,
|
|
7134
|
+
signers,
|
|
7135
|
+
protocol,
|
|
7136
|
+
chainStepRewardAddress: chainStepRewardAddress2,
|
|
7137
|
+
stepRewardPoolBalance
|
|
7138
|
+
});
|
|
7139
|
+
}
|
|
7140
|
+
|
|
7141
|
+
// src/test/buildRandomGenesisBlock.ts
|
|
7142
|
+
import { asAddress, assertEx as assertEx50 } from "@xylabs/sdk-js";
|
|
7143
|
+
import {
|
|
7144
|
+
Account as Account3,
|
|
7145
|
+
asAnyPayload as asAnyPayload6,
|
|
7146
|
+
asSchema as asSchema10,
|
|
7147
|
+
IdSchema,
|
|
7148
|
+
PayloadBuilder as PayloadBuilder26
|
|
7149
|
+
} from "@xyo-network/sdk-js";
|
|
7150
|
+
import {
|
|
7151
|
+
asXL1BlockNumber as asXL1BlockNumber15
|
|
7152
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
7153
|
+
|
|
7154
|
+
// src/test/buildGenesisBlock.ts
|
|
7155
|
+
import { XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS3 } from "@xyo-network/xl1-protocol-lib";
|
|
7156
|
+
async function buildGenesisBlock(chainId, txs, blockPayloads, signers, chainStepRewardAddress2 = XYO_ZERO_ADDRESS3, protocol) {
|
|
7157
|
+
return await buildBlock({
|
|
7158
|
+
previousBlockHash: null,
|
|
7159
|
+
chainId,
|
|
7160
|
+
txs,
|
|
7161
|
+
blockPayloads,
|
|
7162
|
+
signers,
|
|
7163
|
+
chainStepRewardAddress: chainStepRewardAddress2,
|
|
7164
|
+
protocol
|
|
7165
|
+
});
|
|
7166
|
+
}
|
|
7167
|
+
|
|
7168
|
+
// src/test/buildRandomTransaction.ts
|
|
7169
|
+
import { Account as Account2 } from "@xyo-network/sdk-js";
|
|
7170
|
+
import { asXL1BlockNumber as asXL1BlockNumber14, isAllowedBlockPayload as isAllowedBlockPayload3 } from "@xyo-network/xl1-protocol-lib";
|
|
7171
|
+
var buildRandomTransaction = async (chain, payloads, account, nbf = asXL1BlockNumber14(0, true), exp = asXL1BlockNumber14(nbf + 1e3, true), privatePayloadSchemas = [], receiverAddress) => {
|
|
7172
|
+
const elevatedPayloads = (payloads ?? []).filter(isAllowedBlockPayload3);
|
|
7173
|
+
const additionalPayloads = (payloads ?? []).filter((payload) => !isAllowedBlockPayload3(payload));
|
|
7174
|
+
const sender = account ?? await Account2.random();
|
|
7175
|
+
if (elevatedPayloads.length === 0) {
|
|
7176
|
+
const receiver = receiverAddress ?? (await Account2.random()).address;
|
|
7177
|
+
const transferPayload = createTransferPayload(sender.address, { [receiver]: 1n });
|
|
7178
|
+
elevatedPayloads.push(transferPayload);
|
|
7179
|
+
}
|
|
7180
|
+
const hydratedTransaction = await buildTransaction(chain, elevatedPayloads, additionalPayloads, sender, nbf, exp);
|
|
7181
|
+
return [hydratedTransaction[0], hydratedTransaction[1].filter((payload) => !privatePayloadSchemas.includes(payload.schema))];
|
|
7182
|
+
};
|
|
7183
|
+
|
|
7184
|
+
// src/test/buildRandomGenesisBlock.ts
|
|
7185
|
+
var TestChainId = assertEx50(asAddress("c5fe2e6F6841Cbab12d8C0618Be2DF8C6156cC44"));
|
|
7186
|
+
|
|
7187
|
+
// src/test/createGenesisBlock.ts
|
|
7188
|
+
import { PayloadBuilder as PayloadBuilder28 } from "@xyo-network/sdk-js";
|
|
7189
|
+
import {
|
|
7190
|
+
BlockBoundWitnessSchemaPayload,
|
|
7191
|
+
BlockBoundWitnessWithStorageMetaSchemaPayload,
|
|
7192
|
+
ChainStakeIntentPayloadJsonSchemaPayload,
|
|
7193
|
+
HashPayloadJsonSchemaPayload,
|
|
7194
|
+
TransactionBoundWitnessSchemaPayload,
|
|
7195
|
+
TransactionBoundWitnessWithStorageMetaSchemaPayload,
|
|
7196
|
+
TransferPayloadJsonSchemaPayload
|
|
7197
|
+
} from "@xyo-network/xl1-schema";
|
|
7198
|
+
|
|
7199
|
+
// src/test/createProducerChainStakeIntentTransaction.ts
|
|
7200
|
+
import { PayloadBuilder as PayloadBuilder27 } from "@xyo-network/sdk-js";
|
|
7201
|
+
import {
|
|
7202
|
+
asXL1BlockNumber as asXL1BlockNumber16,
|
|
7203
|
+
ChainStakeIntentSchema as ChainStakeIntentSchema2,
|
|
7204
|
+
defaultTransactionFees as defaultTransactionFees4
|
|
7205
|
+
} from "@xyo-network/xl1-protocol-lib";
|
|
7206
|
+
async function createProducerChainStakeIntent(from, exp, nbf = 0) {
|
|
7207
|
+
return await PayloadBuilder27.addHashMeta(new PayloadBuilder27({ schema: ChainStakeIntentSchema2 }).fields({
|
|
7208
|
+
from,
|
|
7209
|
+
exp,
|
|
7210
|
+
nbf,
|
|
7211
|
+
intent: "producer"
|
|
7212
|
+
}).build());
|
|
7213
|
+
}
|
|
7214
|
+
|
|
7215
|
+
// src/test/createGenesisBlock.ts
|
|
7216
|
+
var createGenesisBlock = async (initialBlockProducer, nextContractAddress, genesisBlockRewardAmount, genesisBlockRewardAddress) => {
|
|
7217
|
+
const blockPayloads = await PayloadBuilder28.addHashMeta([
|
|
7218
|
+
TransferPayloadJsonSchemaPayload,
|
|
7219
|
+
BlockBoundWitnessSchemaPayload,
|
|
7220
|
+
BlockBoundWitnessWithStorageMetaSchemaPayload,
|
|
7221
|
+
TransactionBoundWitnessSchemaPayload,
|
|
7222
|
+
TransactionBoundWitnessWithStorageMetaSchemaPayload,
|
|
7223
|
+
ChainStakeIntentPayloadJsonSchemaPayload,
|
|
7224
|
+
HashPayloadJsonSchemaPayload
|
|
7225
|
+
]);
|
|
7226
|
+
const intentPayload = await createProducerChainStakeIntent(initialBlockProducer.address, 1, 0);
|
|
7227
|
+
blockPayloads.push(intentPayload);
|
|
7228
|
+
if (genesisBlockRewardAmount > 0n) {
|
|
7229
|
+
blockPayloads.push(await PayloadBuilder28.addHashMeta(createTransferPayload(
|
|
7230
|
+
nextContractAddress,
|
|
7231
|
+
{ [genesisBlockRewardAddress]: genesisBlockRewardAmount }
|
|
7232
|
+
)));
|
|
7233
|
+
}
|
|
7234
|
+
return await buildGenesisBlock(nextContractAddress, [], blockPayloads, [initialBlockProducer]);
|
|
7235
|
+
};
|
|
7236
|
+
|
|
7237
|
+
// src/test/buildRandomChain.ts
|
|
7238
|
+
var TestGenesisBlockRewardAddress = assertEx51(asAddress2("fa7f0bb865a4bfff3d5e2c726d3e063297014da9"));
|
|
7239
|
+
var buildRandomChain = async (blockProducer, count = 10, previousBlock, chainId, transactionAccount, receiverAddresses) => {
|
|
7240
|
+
const chainIdToUse = chainId ?? TestChainId;
|
|
7241
|
+
const blocks = [];
|
|
7242
|
+
let remaining = count;
|
|
7243
|
+
let lastBlock = previousBlock;
|
|
7244
|
+
const transactionAccountToUse = transactionAccount ?? await Account4.random();
|
|
7245
|
+
if (!lastBlock) {
|
|
7246
|
+
const block = await createGenesisBlock(
|
|
7247
|
+
blockProducer,
|
|
7248
|
+
chainIdToUse,
|
|
7249
|
+
1000000000n * 10n ** 18n,
|
|
7250
|
+
transactionAccountToUse.address
|
|
7251
|
+
);
|
|
7252
|
+
blocks.push(block);
|
|
7253
|
+
remaining = remaining - 1;
|
|
7254
|
+
lastBlock = block;
|
|
7255
|
+
}
|
|
7256
|
+
const resolvedReceiverAddresses = receiverAddresses ?? [(await Account4.random()).address];
|
|
7257
|
+
let saltCounter = 0;
|
|
7258
|
+
while (remaining > 0) {
|
|
7259
|
+
saltCounter += 1;
|
|
7260
|
+
const payloads = [new PayloadBuilder29({ schema: IdSchema2 }).fields({ salt: `${Date.now()}-${saltCounter}` }).build()];
|
|
7261
|
+
saltCounter += 1;
|
|
7262
|
+
const additionalPrivatePayloads = remaining % 2 === 0 ? [new PayloadBuilder29({ schema: asSchema11("network.xyo.private", true) }).fields({ salt: `${Date.now()}-${saltCounter}` }).build()] : [];
|
|
7263
|
+
const txs = [];
|
|
7264
|
+
for (const receiverAddress of resolvedReceiverAddresses) {
|
|
7265
|
+
txs.push(await buildRandomTransaction(
|
|
7266
|
+
chainIdToUse,
|
|
7267
|
+
[...payloads, ...additionalPrivatePayloads],
|
|
7268
|
+
transactionAccountToUse,
|
|
7269
|
+
asXL1BlockNumber17(Math.max(count - remaining - 1e3, 0), true),
|
|
7270
|
+
asXL1BlockNumber17(count - remaining + 1e3, true),
|
|
7271
|
+
[asSchema11("network.xyo.private", true)],
|
|
7272
|
+
receiverAddress
|
|
7273
|
+
));
|
|
7274
|
+
}
|
|
7275
|
+
const previousBlock2 = assertEx51(lastBlock?.[0], () => new Error("No last block"));
|
|
7276
|
+
const block = await buildNextBlock(previousBlock2, txs, [], [blockProducer], transactionAccountToUse.address);
|
|
7277
|
+
blocks.push(block);
|
|
7278
|
+
remaining = remaining - 1;
|
|
7279
|
+
lastBlock = block;
|
|
7280
|
+
}
|
|
7281
|
+
return blocks;
|
|
7282
|
+
};
|
|
7283
|
+
async function buildRandomChainArchivist(count = 20) {
|
|
7284
|
+
const producerAccount = await Account4.random();
|
|
7285
|
+
const blocks = await buildRandomChain(producerAccount, count);
|
|
7286
|
+
const archivist = await MemoryArchivist.create();
|
|
7287
|
+
const payloads = flattenHydratedBlocks(blocks);
|
|
7288
|
+
await archivist.insert(payloads);
|
|
7289
|
+
return archivist;
|
|
7290
|
+
}
|
|
7291
|
+
|
|
7292
|
+
// src/test/getSimpleBlockViewerLocator.ts
|
|
7293
|
+
import { XYO_ZERO_ADDRESS as XYO_ZERO_ADDRESS4 } from "@xyo-network/xl1-protocol-lib";
|
|
7294
|
+
|
|
7295
|
+
// src/_internal/context/getTestProviderContext.ts
|
|
7296
|
+
function getTestProviderContext(config) {
|
|
7297
|
+
const singletons = {};
|
|
7298
|
+
const caches = {};
|
|
7299
|
+
const locator = new ProviderFactoryLocator({
|
|
7300
|
+
config,
|
|
7301
|
+
singletons,
|
|
7302
|
+
caches,
|
|
7303
|
+
logger: console
|
|
7304
|
+
});
|
|
7305
|
+
return locator.context;
|
|
7306
|
+
}
|
|
7307
|
+
|
|
7308
|
+
// src/test/getSimpleBlockViewerLocator.ts
|
|
7309
|
+
async function getTestSimpleBlockViewerLocator({
|
|
7310
|
+
minWithdrawalBlocks = 10,
|
|
7311
|
+
config = ConfigZod.parse({}),
|
|
7312
|
+
finalizedArchivist: finalizedArchivistIn,
|
|
7313
|
+
rewardsContract = XYO_ZERO_ADDRESS4,
|
|
7314
|
+
stakingTokenAddress = XYO_ZERO_ADDRESS4
|
|
7315
|
+
}) {
|
|
7316
|
+
const finalizedArchivist = finalizedArchivistIn ?? await buildRandomChainArchivist();
|
|
7317
|
+
const context = getTestProviderContext(config);
|
|
7318
|
+
context.locator.registerMany([
|
|
7319
|
+
SimpleChainContractViewer.factory(SimpleChainContractViewer.dependencies, {
|
|
7320
|
+
minWithdrawalBlocks,
|
|
7321
|
+
rewardsContract,
|
|
7322
|
+
stakingTokenAddress
|
|
7323
|
+
}),
|
|
7324
|
+
SimpleFinalizationViewer.factory(SimpleFinalizationViewer.dependencies, { finalizedArchivist }),
|
|
7325
|
+
SimpleBlockViewer.factory(SimpleBlockViewer.dependencies, { finalizedArchivist })
|
|
7326
|
+
]);
|
|
7327
|
+
return context.locator;
|
|
7328
|
+
}
|
|
7329
|
+
|
|
7330
|
+
// src/test/getTestProviderContext.ts
|
|
7331
|
+
function getTestProviderContext2(config) {
|
|
7332
|
+
return getTestProviderContext(config);
|
|
7333
|
+
}
|
|
7334
|
+
|
|
6938
7335
|
// src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
|
|
6939
|
-
import { assertEx as
|
|
7336
|
+
import { assertEx as assertEx52 } from "@xylabs/sdk-js";
|
|
6940
7337
|
import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol-lib";
|
|
6941
7338
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
6942
7339
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
6943
7340
|
const hydratedBlock = await hydrateBlock(context, blockHash);
|
|
6944
7341
|
const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), { required: true });
|
|
6945
|
-
return
|
|
7342
|
+
return assertEx52(timePayload.ethereum, () => "No ethereum timestamp found on block");
|
|
6946
7343
|
}
|
|
6947
7344
|
|
|
6948
7345
|
// src/validation/lib/isLocalhost.ts
|
|
@@ -6960,8 +7357,8 @@ var getUrl = (host, port) => {
|
|
|
6960
7357
|
var TODO = true;
|
|
6961
7358
|
|
|
6962
7359
|
// src/validation/schema/Mnemonic.ts
|
|
6963
|
-
import { z as
|
|
6964
|
-
var MnemonicStringZod =
|
|
7360
|
+
import { z as z31 } from "zod";
|
|
7361
|
+
var MnemonicStringZod = z31.string().transform((s) => s.trim().replaceAll(/\s+/g, " ")).refine(
|
|
6965
7362
|
(s) => [12, 15, 18, 21, 24].includes(s.split(" ").length),
|
|
6966
7363
|
{ message: "Mnemonic must contain 12, 15, 18, 21, or 24 words." }
|
|
6967
7364
|
).describe("BIP-39 mnemonic string");
|
|
@@ -7076,6 +7473,7 @@ export {
|
|
|
7076
7473
|
SimpleXyoSigner,
|
|
7077
7474
|
StepSummarySchema,
|
|
7078
7475
|
TODO,
|
|
7476
|
+
TestGenesisBlockRewardAddress,
|
|
7079
7477
|
TransactionBuilder,
|
|
7080
7478
|
TransfersStepSummarySchema,
|
|
7081
7479
|
TypedDataDomainZod,
|
|
@@ -7133,6 +7531,9 @@ export {
|
|
|
7133
7531
|
blocksMaxStep,
|
|
7134
7532
|
blocksStepSummaryFromRange,
|
|
7135
7533
|
blocksStepSummaryKey,
|
|
7534
|
+
buildRandomChain,
|
|
7535
|
+
buildRandomChainArchivist,
|
|
7536
|
+
buildRandomTransaction,
|
|
7136
7537
|
buildTransaction,
|
|
7137
7538
|
buildUnsignedTransaction,
|
|
7138
7539
|
bundledPayloadToHydratedBlock,
|
|
@@ -7171,11 +7572,14 @@ export {
|
|
|
7171
7572
|
getEmptyContext,
|
|
7172
7573
|
getEmptyProviderContext,
|
|
7173
7574
|
getProducerKey,
|
|
7575
|
+
getTestProviderContext2 as getTestProviderContext,
|
|
7576
|
+
getTestSimpleBlockViewerLocator,
|
|
7174
7577
|
getTimeConfigInMilliseconds,
|
|
7175
7578
|
getUrl,
|
|
7176
7579
|
getWindowedChain,
|
|
7177
7580
|
hasLabels,
|
|
7178
7581
|
hasMongoConfig,
|
|
7582
|
+
hasR2Config,
|
|
7179
7583
|
hashFromBlockNumber,
|
|
7180
7584
|
hydrateBlock,
|
|
7181
7585
|
hydrateElevatedTransaction,
|