@xyo-network/xl1-protocol-sdk 1.17.6 → 1.18.0-rc.1
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 +103 -1
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +25 -8
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts +11 -3
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts +19 -13
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts +14 -10
- package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts.map +1 -1
- package/dist/neutral/config/Bridge.d.ts +3 -0
- package/dist/neutral/config/Bridge.d.ts.map +1 -1
- package/dist/neutral/config/Chain.d.ts +1 -1
- package/dist/neutral/config/Config.d.ts +6 -3
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Log.d.ts +1 -1
- package/dist/neutral/createDeclarationPayload.d.ts +4 -0
- package/dist/neutral/createDeclarationPayload.d.ts.map +1 -0
- package/dist/neutral/createTransferPayload.d.ts +4 -0
- package/dist/neutral/createTransferPayload.d.ts.map +1 -0
- package/dist/neutral/driver/cache/LruCacheMap.d.ts +2 -2
- package/dist/neutral/driver/cache/LruCacheMap.d.ts.map +1 -1
- package/dist/neutral/driver/memory/MemoryMap.d.ts +2 -2
- package/dist/neutral/driver/memory/MemoryMap.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +3 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +1584 -655
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/map/MapType.d.ts +3 -2
- package/dist/neutral/map/MapType.d.ts.map +1 -1
- package/dist/neutral/model/ChainContext/ChainContext.d.ts +4 -4
- package/dist/neutral/model/ChainContext/ChainContext.d.ts.map +1 -1
- package/dist/neutral/model/PayloadBundle/bundledPayloadToHydratedTransaction.d.ts +2 -2
- package/dist/neutral/model/PayloadBundle/bundledPayloadToHydratedTransaction.d.ts.map +1 -1
- package/dist/neutral/primitives/block/index.d.ts +2 -0
- package/dist/neutral/primitives/block/index.d.ts.map +1 -0
- package/dist/neutral/primitives/block/range/blockRangeSteps.d.ts +3 -0
- package/dist/neutral/primitives/block/range/blockRangeSteps.d.ts.map +1 -0
- package/dist/neutral/primitives/block/range/index.d.ts +2 -0
- package/dist/neutral/primitives/block/range/index.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/index.d.ts +3 -0
- package/dist/neutral/primitives/chain/index.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/step/chainStepRewardAddress.d.ts +5 -0
- package/dist/neutral/primitives/chain/step/chainStepRewardAddress.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/step/index.d.ts +5 -0
- package/dist/neutral/primitives/chain/step/index.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/step/stepRewardBlock.d.ts +4 -0
- package/dist/neutral/primitives/chain/step/stepRewardBlock.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/step/stepRewardTotal.d.ts +4 -0
- package/dist/neutral/primitives/chain/step/stepRewardTotal.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/step/stepsRewardTotal.d.ts +6 -0
- package/dist/neutral/primitives/chain/step/stepsRewardTotal.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.d.ts +5 -0
- package/dist/neutral/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/time/externalBlockRangeFromStep.d.ts +5 -0
- package/dist/neutral/primitives/chain/time/externalBlockRangeFromStep.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/time/externalBlockRangeFromXL1BlockRange.d.ts +5 -0
- package/dist/neutral/primitives/chain/time/externalBlockRangeFromXL1BlockRange.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/time/index.d.ts +4 -0
- package/dist/neutral/primitives/chain/time/index.d.ts.map +1 -0
- package/dist/neutral/primitives/index.d.ts +6 -0
- package/dist/neutral/primitives/index.d.ts.map +1 -1
- package/dist/neutral/primitives/mapToMapType.d.ts +3 -0
- package/dist/neutral/primitives/mapToMapType.d.ts.map +1 -0
- package/dist/neutral/primitives/payload/index.d.ts +2 -0
- package/dist/neutral/primitives/payload/index.d.ts.map +1 -0
- package/dist/neutral/primitives/payload/mergeTransfers.d.ts +4 -0
- package/dist/neutral/primitives/payload/mergeTransfers.d.ts.map +1 -0
- package/dist/neutral/primitives/readPayloadMapFromStore.d.ts +5 -4
- package/dist/neutral/primitives/readPayloadMapFromStore.d.ts.map +1 -1
- package/dist/neutral/primitives/rewards/index.d.ts +2 -0
- package/dist/neutral/primitives/rewards/index.d.ts.map +1 -0
- package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts +5 -0
- package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/activeStakeAtTimeByAddress.d.ts +4 -0
- package/dist/neutral/primitives/stake/activeStakeAtTimeByAddress.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/activeStakeAtTimeByPosition.d.ts +3 -0
- package/dist/neutral/primitives/stake/activeStakeAtTimeByPosition.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/allStakersForRange.d.ts +4 -0
- package/dist/neutral/primitives/stake/allStakersForRange.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/allStakersForStep.d.ts +6 -0
- package/dist/neutral/primitives/stake/allStakersForStep.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/index.d.ts +7 -0
- package/dist/neutral/primitives/stake/index.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/mergedAddRemoveStakeEventsByPosition.d.ts +3 -0
- package/dist/neutral/primitives/stake/mergedAddRemoveStakeEventsByPosition.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/mergedAddRemoveStakeEventsByStaker.d.ts +4 -0
- package/dist/neutral/primitives/stake/mergedAddRemoveStakeEventsByStaker.d.ts.map +1 -0
- package/dist/neutral/primitives/stake/weightedStakeForRangeByPosition.d.ts +6 -0
- package/dist/neutral/primitives/stake/weightedStakeForRangeByPosition.d.ts.map +1 -0
- package/dist/neutral/provider/DataLake.d.ts +10 -9
- package/dist/neutral/provider/DataLake.d.ts.map +1 -1
- package/dist/neutral/provider/XyoConnection.d.ts +4 -1
- package/dist/neutral/provider/XyoConnection.d.ts.map +1 -1
- package/dist/neutral/provider/XyoGatewayRunner.d.ts +3 -3
- package/dist/neutral/provider/XyoGatewayRunner.d.ts.map +1 -1
- package/dist/neutral/provider/XyoRunner.d.ts +5 -2
- package/dist/neutral/provider/XyoRunner.d.ts.map +1 -1
- package/dist/neutral/provider/viewer/XyoViewer.d.ts +9 -8
- package/dist/neutral/provider/viewer/XyoViewer.d.ts.map +1 -1
- package/dist/neutral/runners/Block.d.ts +7 -2
- package/dist/neutral/runners/Block.d.ts.map +1 -1
- package/dist/neutral/runners/Mempool.d.ts +4 -1
- package/dist/neutral/runners/Mempool.d.ts.map +1 -1
- package/dist/neutral/services/Chain/ChainService.d.ts +2 -2
- package/dist/neutral/services/Chain/ChainService.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +5 -12
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +9 -6
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chainStake/{SimpleChainStakeViewer.d.ts → SimpleStakeViewer.d.ts} +3 -5
- package/dist/neutral/simple/chainStake/SimpleStakeViewer.d.ts.map +1 -0
- package/dist/neutral/simple/chainStake/index.d.ts +1 -1
- package/dist/neutral/simple/chainStake/index.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts +5 -2
- package/dist/neutral/simple/datalake/AbstractSimpleDataLake.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +4 -3
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts +0 -3
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/index.d.ts +1 -0
- package/dist/neutral/simple/index.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts +8 -4
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts.map +1 -1
- package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts +24 -6
- package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts.map +1 -1
- package/dist/neutral/simple/{chainStakeEvents/SimpleChainStakeEventsViewer.d.ts → stakeEvents/SimpleStakeEventsViewer.d.ts} +3 -3
- package/dist/neutral/simple/stakeEvents/SimpleStakeEventsViewer.d.ts.map +1 -0
- package/dist/neutral/simple/stakeEvents/index.d.ts +2 -0
- package/dist/neutral/simple/stakeEvents/index.d.ts.map +1 -0
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts +4 -3
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts.map +1 -1
- package/dist/neutral/status/RuntimeStatusMonitor.d.ts +31 -0
- package/dist/neutral/status/RuntimeStatusMonitor.d.ts.map +1 -0
- package/dist/neutral/status/ServiceStatus.d.ts +8 -0
- package/dist/neutral/status/ServiceStatus.d.ts.map +1 -0
- package/dist/neutral/status/index.d.ts +3 -0
- package/dist/neutral/status/index.d.ts.map +1 -0
- package/dist/neutral/summary/model/summary.d.ts +4 -4
- package/dist/neutral/summary/model/summary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/balances/balancesStepSummaryFromRange.d.ts +1 -1
- package/dist/neutral/summary/primitives/balances/balancesStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/transaction/TransactionBuilder.d.ts +82 -0
- package/dist/neutral/transaction/TransactionBuilder.d.ts.map +1 -0
- package/dist/neutral/transaction/buildRandomTransaction.d.ts +6 -0
- package/dist/neutral/transaction/buildRandomTransaction.d.ts.map +1 -0
- package/dist/neutral/transaction/index.d.ts +2 -0
- package/dist/neutral/transaction/index.d.ts.map +1 -1
- package/dist/neutral/viewers/Block.d.ts +4 -1
- package/dist/neutral/viewers/Block.d.ts.map +1 -1
- package/dist/neutral/viewers/ChainStakeViewer.d.ts +1 -2
- package/dist/neutral/viewers/ChainStakeViewer.d.ts.map +1 -1
- package/dist/neutral/viewers/Fork.d.ts +0 -1
- package/dist/neutral/viewers/Fork.d.ts.map +1 -1
- package/dist/neutral/viewers/Stake.d.ts +0 -1
- package/dist/neutral/viewers/Stake.d.ts.map +1 -1
- package/dist/neutral/viewers/index.d.ts +0 -1
- package/dist/neutral/viewers/index.d.ts.map +1 -1
- package/package.json +10 -8
- package/src/CreatableProvider/AbstractCreatableProvider.ts +44 -3
- package/src/CreatableProvider/CreatableProvider.ts +36 -9
- package/src/CreatableProvider/CreatableProviderRegistry.ts +9 -5
- package/src/CreatableProvider/ProviderFactory.ts +72 -10
- package/src/CreatableProvider/ProviderFactoryLocator.ts +78 -19
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +33 -10
- package/src/config/Bridge.ts +22 -4
- package/src/config/Chain.ts +2 -2
- package/src/createDeclarationPayload.ts +14 -0
- package/src/createTransferPayload.ts +15 -0
- package/src/driver/cache/LruCacheMap.ts +2 -2
- package/src/driver/memory/MemoryMap.ts +2 -2
- package/src/index.ts +3 -0
- package/src/map/MapType.ts +4 -2
- package/src/model/ChainContext/ChainContext.ts +4 -4
- package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +2 -2
- package/src/primitives/block/index.ts +1 -0
- package/src/primitives/block/range/blockRangeSteps.ts +22 -0
- package/src/primitives/block/range/index.ts +1 -0
- package/src/primitives/chain/index.ts +2 -0
- package/src/primitives/chain/step/chainStepRewardAddress.ts +28 -0
- package/src/primitives/chain/step/index.ts +4 -0
- package/src/primitives/chain/step/stepRewardBlock.ts +11 -0
- package/src/primitives/chain/step/stepRewardTotal.ts +45 -0
- package/src/primitives/chain/step/stepsRewardTotal.ts +34 -0
- package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +31 -0
- package/src/primitives/chain/time/externalBlockRangeFromStep.ts +19 -0
- package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +16 -0
- package/src/primitives/chain/time/index.ts +3 -0
- package/src/primitives/index.ts +6 -0
- package/src/primitives/mapToMapType.ts +35 -0
- package/src/primitives/payload/index.ts +1 -0
- package/src/primitives/payload/mergeTransfers.ts +15 -0
- package/src/primitives/readPayloadMapFromStore.ts +38 -8
- package/src/primitives/rewards/index.ts +1 -0
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +21 -0
- package/src/primitives/stake/activeStakeAtTimeByAddress.ts +26 -0
- package/src/primitives/stake/activeStakeAtTimeByPosition.ts +24 -0
- package/src/primitives/stake/allStakersForRange.ts +31 -0
- package/src/primitives/stake/allStakersForStep.ts +22 -0
- package/src/primitives/stake/index.ts +6 -0
- package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +14 -0
- package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +17 -0
- package/src/primitives/stake/weightedStakeForRangeByPosition.ts +54 -0
- package/src/provider/DataLake.ts +12 -11
- package/src/provider/XyoConnection.ts +5 -1
- package/src/provider/XyoGatewayRunner.ts +3 -3
- package/src/provider/XyoRunner.ts +6 -2
- package/src/provider/viewer/XyoViewer.ts +9 -8
- package/src/runners/Block.ts +10 -2
- package/src/runners/Mempool.ts +6 -1
- package/src/services/Chain/ChainService.ts +2 -4
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +21 -14
- package/src/simple/block/SimpleBlockViewer.ts +47 -14
- package/src/simple/chainStake/{SimpleChainStakeViewer.ts → SimpleStakeViewer.ts} +11 -16
- package/src/simple/chainStake/index.ts +1 -1
- package/src/simple/datalake/AbstractSimpleDataLake.ts +17 -17
- package/src/simple/datalake/SimpleDataLakeRunner.ts +4 -3
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -18
- package/src/simple/index.ts +1 -0
- package/src/simple/mempool/SimpleMempoolRunner.ts +13 -8
- package/src/simple/mempool/SimpleMempoolViewer.ts +6 -1
- package/src/simple/runner/SimpleXyoRunner.ts +41 -16
- package/src/simple/{chainStakeEvents/SimpleChainStakeEventsViewer.ts → stakeEvents/SimpleStakeEventsViewer.ts} +5 -5
- package/src/simple/stakeEvents/index.ts +1 -0
- package/src/simple/timesync/SimpleTimeSyncViewer.ts +26 -5
- package/src/status/RuntimeStatusMonitor.ts +117 -0
- package/src/status/ServiceStatus.ts +20 -0
- package/src/status/index.ts +2 -0
- package/src/summary/model/summary.ts +6 -4
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +2 -3
- package/src/transaction/TransactionBuilder.ts +162 -0
- package/src/transaction/buildRandomTransaction.ts +36 -0
- package/src/transaction/hydrateTransaction.ts +1 -1
- package/src/transaction/index.ts +2 -0
- package/src/viewers/Block.ts +6 -1
- package/src/viewers/ChainStakeViewer.ts +1 -2
- package/src/viewers/Fork.ts +0 -1
- package/src/viewers/Stake.ts +0 -1
- package/src/viewers/index.ts +0 -1
- package/dist/neutral/simple/chain/SimpleChainViewer.d.ts +0 -15
- package/dist/neutral/simple/chain/SimpleChainViewer.d.ts.map +0 -1
- package/dist/neutral/simple/chain/index.d.ts +0 -2
- package/dist/neutral/simple/chain/index.d.ts.map +0 -1
- package/dist/neutral/simple/chainStake/SimpleChainStakeViewer.d.ts.map +0 -1
- package/dist/neutral/simple/chainStakeEvents/SimpleChainStakeEventsViewer.d.ts.map +0 -1
- package/dist/neutral/simple/chainStakeEvents/index.d.ts +0 -2
- package/dist/neutral/simple/chainStakeEvents/index.d.ts.map +0 -1
- package/dist/neutral/viewers/Chain.d.ts +0 -11
- package/dist/neutral/viewers/Chain.d.ts.map +0 -1
- package/src/simple/chain/SimpleChainViewer.ts +0 -28
- package/src/simple/chain/index.ts +0 -1
- package/src/simple/chainStakeEvents/index.ts +0 -1
- package/src/viewers/Chain.ts +0 -13
package/dist/neutral/index.mjs
CHANGED
|
@@ -118,12 +118,12 @@ var tryHydrateBlock = /* @__PURE__ */ __name(async (archivist, hash, maxDepth =
|
|
|
118
118
|
}, "tryHydrateBlock");
|
|
119
119
|
|
|
120
120
|
// src/block/primitives/blockFromBlockNumber.ts
|
|
121
|
-
import { asHash as asHash3, isDefined as
|
|
121
|
+
import { asHash as asHash3, isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
122
122
|
import { toSafeJsonString } from "@xylabs/sdk-js";
|
|
123
|
-
import { asSignedBlockBoundWitnessWithStorageMeta, SignedBlockBoundWitnessWithHashMetaZod, StepSizes as
|
|
123
|
+
import { asSignedBlockBoundWitnessWithStorageMeta, SignedBlockBoundWitnessWithHashMetaZod, StepSizes as StepSizes6 } from "@xyo-network/xl1-protocol";
|
|
124
124
|
|
|
125
125
|
// src/model/ChainContext/ChainContext.ts
|
|
126
|
-
import { isDefined as
|
|
126
|
+
import { isDefined as isDefined8, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
|
|
127
127
|
|
|
128
128
|
// src/driver/cache/LruCacheMap.ts
|
|
129
129
|
import { LRUCache } from "lru-cache";
|
|
@@ -211,46 +211,113 @@ var MemoryMap = class {
|
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
// src/primitives/
|
|
215
|
-
import {
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
};
|
|
214
|
+
// src/primitives/block/range/blockRangeSteps.ts
|
|
215
|
+
import { asXL1BlockNumber, StepSizes } from "@xyo-network/xl1-protocol";
|
|
216
|
+
function blockRangeSteps(range, steps) {
|
|
217
|
+
const result = [];
|
|
218
|
+
for (const step of steps) {
|
|
219
|
+
const stepSize2 = StepSizes[step];
|
|
220
|
+
const startOfFirstStepCandidate = range[0] - range[0] % stepSize2 + stepSize2;
|
|
221
|
+
const startOfFirstStep = asXL1BlockNumber(startOfFirstStepCandidate, {
|
|
222
|
+
name: "blockRangeSteps"
|
|
223
|
+
});
|
|
224
|
+
for (let block = startOfFirstStep; block <= range[1]; block = asXL1BlockNumber(block + stepSize2, {
|
|
225
|
+
name: "blockRangeSteps"
|
|
226
|
+
})) {
|
|
227
|
+
result.push({
|
|
228
|
+
step,
|
|
229
|
+
block
|
|
230
|
+
});
|
|
231
|
+
}
|
|
233
232
|
}
|
|
234
|
-
return
|
|
233
|
+
return result;
|
|
235
234
|
}
|
|
236
|
-
__name(
|
|
235
|
+
__name(blockRangeSteps, "blockRangeSteps");
|
|
236
|
+
|
|
237
|
+
// src/primitives/chain/step/chainStepRewardAddress.ts
|
|
238
|
+
import { assertEx as assertEx7, exists, toAddress as toAddress4 } from "@xylabs/sdk-js";
|
|
239
|
+
import { asTransfer, isTransfer, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
240
|
+
|
|
241
|
+
// src/primitives/payload/mergeTransfers.ts
|
|
242
|
+
import { hexToBigInt, toAddress } from "@xylabs/sdk-js";
|
|
243
|
+
function mergeTransfers(transfers) {
|
|
244
|
+
const result = {};
|
|
245
|
+
for (const transfer of transfers) {
|
|
246
|
+
result[transfer.from] = result[transfer.from] ?? {};
|
|
247
|
+
for (const [to, value] of Object.entries(transfer.transfers)) {
|
|
248
|
+
const typedTo = toAddress(to);
|
|
249
|
+
result[transfer.from][typedTo] = (result[transfer.from][typedTo] ?? 0n) + hexToBigInt(value);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
__name(mergeTransfers, "mergeTransfers");
|
|
237
255
|
|
|
238
|
-
// src/primitives/
|
|
239
|
-
import {
|
|
240
|
-
import {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
256
|
+
// src/primitives/step/completedStepRewardAddress.ts
|
|
257
|
+
import { toAddress as toAddress2 } from "@xylabs/sdk-js";
|
|
258
|
+
import { StepSizes as StepSizes2 } from "@xyo-network/xl1-protocol";
|
|
259
|
+
import { keccak256 } from "ethers";
|
|
260
|
+
function completedStepRewardAddress({ block, step }) {
|
|
261
|
+
const resolvedStepSize = step < StepSizes2.length ? StepSizes2[step] : step;
|
|
262
|
+
const addressKey = new TextEncoder().encode(`${block}|${resolvedStepSize}`);
|
|
263
|
+
return toAddress2(keccak256(addressKey).slice(-40), {
|
|
264
|
+
prefix: false
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
__name(completedStepRewardAddress, "completedStepRewardAddress");
|
|
268
|
+
|
|
269
|
+
// src/primitives/step/derivedReceiveAddress.ts
|
|
270
|
+
import { toAddress as toAddress3 } from "@xylabs/sdk-js";
|
|
271
|
+
import { isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
272
|
+
import { keccak256 as keccak2562 } from "ethers";
|
|
273
|
+
function derivedReceiveAddress(address, scope) {
|
|
274
|
+
const addressKey = new TextEncoder().encode(isDefined2(scope) ? `${scope}|${address}` : address);
|
|
275
|
+
return toAddress3(keccak2562(addressKey).slice(-40), {
|
|
276
|
+
prefix: false
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
__name(derivedReceiveAddress, "derivedReceiveAddress");
|
|
280
|
+
|
|
281
|
+
// src/primitives/step/stepBlockRange.ts
|
|
282
|
+
import { asXL1BlockRange, StepSizes as StepSizes3 } from "@xyo-network/xl1-protocol";
|
|
283
|
+
function stepBlockRange({ block, step }) {
|
|
284
|
+
const stepSize2 = StepSizes3[step];
|
|
285
|
+
const start = block - stepSize2;
|
|
286
|
+
return asXL1BlockRange([
|
|
287
|
+
start,
|
|
288
|
+
start + stepSize2 - 1
|
|
289
|
+
], {
|
|
290
|
+
name: "stepBlockRange"
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
__name(stepBlockRange, "stepBlockRange");
|
|
294
|
+
|
|
295
|
+
// src/primitives/step/stepTransferIndex.ts
|
|
296
|
+
import { assertEx as assertEx4 } from "@xylabs/sdk-js";
|
|
297
|
+
import { StepSizes as StepSizes4 } from "@xyo-network/xl1-protocol";
|
|
298
|
+
function stepTransferIndex(block, step) {
|
|
299
|
+
let rewardTransferCount = 0;
|
|
300
|
+
let rewardTransferIndex = -1;
|
|
301
|
+
for (let i = 3; i < StepSizes4.length; i++) {
|
|
302
|
+
const stepSize2 = StepSizes4[i];
|
|
303
|
+
if (block % stepSize2 === 0) {
|
|
304
|
+
if (stepSize2 === StepSizes4[step]) {
|
|
305
|
+
rewardTransferIndex = rewardTransferCount;
|
|
306
|
+
}
|
|
307
|
+
rewardTransferCount++;
|
|
245
308
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
309
|
+
}
|
|
310
|
+
assertEx4(rewardTransferIndex >= 0, () => `Could not find step size for step ${step} at block ${block}`);
|
|
311
|
+
return [
|
|
312
|
+
rewardTransferIndex,
|
|
313
|
+
rewardTransferCount
|
|
314
|
+
];
|
|
315
|
+
}
|
|
316
|
+
__name(stepTransferIndex, "stepTransferIndex");
|
|
317
|
+
|
|
318
|
+
// src/primitives/chain/step/stepRewardBlock.ts
|
|
319
|
+
import { assertEx as assertEx6 } from "@xylabs/sdk-js";
|
|
320
|
+
import { StepSizes as StepSizes5 } from "@xyo-network/xl1-protocol";
|
|
254
321
|
|
|
255
322
|
// src/primitives/state/findMostRecentBlock.ts
|
|
256
323
|
import { isSignedBlockBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
@@ -282,80 +349,534 @@ var findMostRecentBlock = /* @__PURE__ */ __name(async (chainArchivist, nextOpti
|
|
|
282
349
|
}, "findMostRecentBlock");
|
|
283
350
|
|
|
284
351
|
// src/primitives/state/hydratedBlockByNumber.ts
|
|
285
|
-
import { assertEx as
|
|
352
|
+
import { assertEx as assertEx5 } from "@xylabs/sdk-js";
|
|
286
353
|
async function hydratedBlockByNumber(context, blockNumber) {
|
|
287
354
|
if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`);
|
|
288
355
|
if (blockNumber > Number.MAX_SAFE_INTEGER) throw new Error(`Block number ${blockNumber} is greater than the maximum safe integer`);
|
|
289
356
|
if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`);
|
|
290
357
|
const cacheKey = `${blockNumber}`;
|
|
291
358
|
return await withContextCacheResponse(context, "hydratedBlockByNumber", cacheKey, async () => {
|
|
292
|
-
const block =
|
|
359
|
+
const block = assertEx5(await blockFromBlockNumber(context, blockNumber), () => `Could not find block for block number ${blockNumber}`);
|
|
293
360
|
return await hydrateBlock(context.store, block._hash);
|
|
294
361
|
});
|
|
295
362
|
}
|
|
296
363
|
__name(hydratedBlockByNumber, "hydratedBlockByNumber");
|
|
297
364
|
|
|
298
|
-
// src/primitives/step/
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
365
|
+
// src/primitives/chain/step/stepRewardBlock.ts
|
|
366
|
+
async function stepRewardBlock(context, { block, step }) {
|
|
367
|
+
assertEx6(block % StepSizes5[step] === 0, () => `Block must be the first block of the step [${StepSizes5[step]}], got ${block}`);
|
|
368
|
+
return assertEx6(await hydratedBlockByNumber(context, block), () => `Could not find block for block number ${block}`);
|
|
369
|
+
}
|
|
370
|
+
__name(stepRewardBlock, "stepRewardBlock");
|
|
371
|
+
|
|
372
|
+
// src/primitives/chain/step/chainStepRewardAddress.ts
|
|
373
|
+
async function chainStepRewardAddress(context, { block, step }) {
|
|
374
|
+
const hydratedBlock = await stepRewardBlock(context, {
|
|
375
|
+
block,
|
|
376
|
+
step
|
|
307
377
|
});
|
|
378
|
+
const [transferIndex, transferCount] = stepTransferIndex(block, step);
|
|
379
|
+
const [blockBw, payloads] = hydratedBlock;
|
|
380
|
+
const transfersFromPool = payloads.filter(isTransfer).map((p) => asTransfer(p)).filter(exists).filter((t) => t.from === XYO_STEP_REWARD_ADDRESS);
|
|
381
|
+
const fromEntries = Object.entries(mergeTransfers(transfersFromPool)[XYO_STEP_REWARD_ADDRESS]);
|
|
382
|
+
const sortedTransferAmounts = fromEntries.toSorted(([, a], [, b]) => a > b ? -1 : a < b ? 1 : 0);
|
|
383
|
+
assertEx7(sortedTransferAmounts.length === transferCount, () => `Step Transfers mismatch ${block} (${blockBw._hash}) [${sortedTransferAmounts.length} - ${transferCount}]`);
|
|
384
|
+
return toAddress4(sortedTransferAmounts[transferIndex][0]);
|
|
308
385
|
}
|
|
309
|
-
__name(
|
|
386
|
+
__name(chainStepRewardAddress, "chainStepRewardAddress");
|
|
310
387
|
|
|
311
|
-
// src/primitives/step/
|
|
312
|
-
import {
|
|
313
|
-
import {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
388
|
+
// src/primitives/chain/step/stepRewardTotal.ts
|
|
389
|
+
import { assertEx as assertEx8, isDefined as isDefined3 } from "@xylabs/sdk-js";
|
|
390
|
+
import { asAttoXL1, asXL1BlockRange as asXL1BlockRange2, isTransfer as isTransfer5, XYO_STEP_REWARD_ADDRESS as XYO_STEP_REWARD_ADDRESS2 } from "@xyo-network/xl1-protocol";
|
|
391
|
+
|
|
392
|
+
// src/payloads/AddressPairPayload.ts
|
|
393
|
+
import { AsObjectFactory } from "@xylabs/sdk-js";
|
|
394
|
+
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
395
|
+
var AddressPairSchema = "network.xyo.address.pair";
|
|
396
|
+
var isAddressPairPayload = isPayloadOfSchemaType(AddressPairSchema);
|
|
397
|
+
var asAddressPairPayload = AsObjectFactory.create(isAddressPairPayload);
|
|
398
|
+
var asOptionalAddressPairPayload = AsObjectFactory.createOptional(isAddressPairPayload);
|
|
399
|
+
|
|
400
|
+
// src/payloads/netBalancesForPayloads.ts
|
|
401
|
+
import { hexToBigInt as hexToBigInt2, toAddress as toAddress5 } from "@xylabs/sdk-js";
|
|
402
|
+
import { span } from "@xylabs/sdk-js";
|
|
403
|
+
import { isTransfer as isTransfer2 } from "@xyo-network/xl1-protocol";
|
|
404
|
+
var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
405
|
+
return span("netBalancesForPayloads", () => {
|
|
406
|
+
const balances = {};
|
|
407
|
+
for (const payload of payloads) {
|
|
408
|
+
if (isTransfer2(payload)) {
|
|
409
|
+
const { from } = payload;
|
|
410
|
+
for (let [address, amount] of Object.entries(payload.transfers)) {
|
|
411
|
+
balances[toAddress5(address)] = (balances[toAddress5(address)] ?? 0n) + hexToBigInt2(amount);
|
|
412
|
+
balances[toAddress5(from)] = (balances[toAddress5(from)] ?? 0n) - hexToBigInt2(amount);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return balances;
|
|
417
|
+
});
|
|
418
|
+
}, "netBalancesForPayloads");
|
|
419
|
+
|
|
420
|
+
// src/payloads/netSchemasForPayloads.ts
|
|
421
|
+
import { hexToBigInt as hexToBigInt3, toAddress as toAddress6 } from "@xylabs/sdk-js";
|
|
422
|
+
import { span as span2 } from "@xylabs/sdk-js";
|
|
423
|
+
import { isTransfer as isTransfer3 } from "@xyo-network/xl1-protocol";
|
|
424
|
+
var netSchemasForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
425
|
+
return span2("netSchemasForPayloads", () => {
|
|
426
|
+
const balances = {};
|
|
427
|
+
for (const payload of payloads) {
|
|
428
|
+
if (isTransfer3(payload)) {
|
|
429
|
+
const { from } = payload;
|
|
430
|
+
for (let [address, amount] of Object.entries(payload.transfers)) {
|
|
431
|
+
balances[toAddress6(address)] = (balances[toAddress6(address)] ?? 0n) + hexToBigInt3(amount);
|
|
432
|
+
balances[toAddress6(from)] = (balances[toAddress6(from)] ?? 0n) - hexToBigInt3(amount);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return balances;
|
|
437
|
+
});
|
|
438
|
+
}, "netSchemasForPayloads");
|
|
439
|
+
|
|
440
|
+
// src/payloads/netTransfersForPayloads.ts
|
|
441
|
+
import { hexToBigInt as hexToBigInt4 } from "@xylabs/sdk-js";
|
|
442
|
+
import { span as span3 } from "@xylabs/sdk-js";
|
|
443
|
+
import { isTransfer as isTransfer4 } from "@xyo-network/xl1-protocol";
|
|
444
|
+
function netTransfersForPayloads(payloads) {
|
|
445
|
+
return span3("netTransfersForPayloads", () => {
|
|
446
|
+
const transfers = {};
|
|
447
|
+
for (const payload of payloads) {
|
|
448
|
+
if (isTransfer4(payload)) {
|
|
449
|
+
const { from } = payload;
|
|
450
|
+
transfers[from] = transfers[from] ?? {};
|
|
451
|
+
for (let [to, amount] of Object.entries(payload.transfers)) {
|
|
452
|
+
transfers[to] = transfers[to] ?? {};
|
|
453
|
+
transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt4(amount);
|
|
454
|
+
transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt4(amount);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return transfers;
|
|
319
459
|
});
|
|
320
460
|
}
|
|
321
|
-
__name(
|
|
461
|
+
__name(netTransfersForPayloads, "netTransfersForPayloads");
|
|
322
462
|
|
|
323
|
-
// src/primitives/step/
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
463
|
+
// src/primitives/chain/step/stepRewardTotal.ts
|
|
464
|
+
function stepInRange(step, range) {
|
|
465
|
+
const stepRange = stepBlockRange(step);
|
|
466
|
+
return stepRange[0] >= range[0] && stepRange[1] <= range[1];
|
|
467
|
+
}
|
|
468
|
+
__name(stepInRange, "stepInRange");
|
|
469
|
+
async function stepRewardTotal(context, { block, step }, multipliers) {
|
|
470
|
+
const cacheKey = `${block}|${step}|${isDefined3(multipliers)}`;
|
|
471
|
+
return await withContextCacheResponse(context, "stepRewardTotal", cacheKey, async () => {
|
|
472
|
+
const [blockBw, payloads] = await stepRewardBlock(context, {
|
|
473
|
+
block,
|
|
474
|
+
step
|
|
475
|
+
});
|
|
476
|
+
assertEx8(blockBw.block === block, () => `Block Mismatch: expected ${block}, got ${blockBw.block}`);
|
|
477
|
+
const [transferIndex] = stepTransferIndex(block, step);
|
|
478
|
+
const stepTransfer = assertEx8(payloads.find((p) => isTransfer5(p) && p.from === XYO_STEP_REWARD_ADDRESS2), () => `No step transfer found for step ${step} at block ${block} (${blockBw._hash})`);
|
|
479
|
+
const rewards = assertEx8(netTransfersForPayloads([
|
|
480
|
+
stepTransfer
|
|
481
|
+
])[XYO_STEP_REWARD_ADDRESS2], () => `No rewards found for step reward address ${XYO_STEP_REWARD_ADDRESS2} at block ${block} (${blockBw._hash})`);
|
|
482
|
+
const sortedTransfers = Object.entries(rewards).toSorted(([, a], [, b]) => a > b ? -1 : a < b ? 1 : 0);
|
|
483
|
+
let result = asAttoXL1(sortedTransfers[transferIndex][1] * -1n);
|
|
484
|
+
for (const [rangeKey, [numerator, denominator]] of Object.entries(multipliers)) {
|
|
485
|
+
const rangeParts = rangeKey.split("|").map(Number);
|
|
486
|
+
const range = asXL1BlockRange2([
|
|
487
|
+
rangeParts[0],
|
|
488
|
+
rangeParts[1]
|
|
489
|
+
], {
|
|
490
|
+
name: "stepRewardTotal"
|
|
491
|
+
});
|
|
492
|
+
if (stepInRange({
|
|
493
|
+
block,
|
|
494
|
+
step
|
|
495
|
+
}, range)) {
|
|
496
|
+
result = asAttoXL1(result + result * numerator / denominator);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return result;
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
__name(stepRewardTotal, "stepRewardTotal");
|
|
503
|
+
|
|
504
|
+
// src/primitives/chain/step/stepsRewardTotal.ts
|
|
505
|
+
import { asAttoXL1 as asAttoXL12, asXL1BlockRange as asXL1BlockRange3 } from "@xyo-network/xl1-protocol";
|
|
506
|
+
|
|
507
|
+
// src/constants.ts
|
|
508
|
+
var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_EPOCH = 1760572800;
|
|
509
|
+
var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK = 107496;
|
|
510
|
+
|
|
511
|
+
// src/primitives/chain/step/stepsRewardTotal.ts
|
|
512
|
+
async function stepsRewardTotalGenesisPeriod(context, multipliers, stepSizes) {
|
|
513
|
+
const range = asXL1BlockRange3([
|
|
514
|
+
0,
|
|
515
|
+
XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK
|
|
331
516
|
], {
|
|
332
|
-
name: "
|
|
517
|
+
name: "stepsRewardTotalGenesisPeriod"
|
|
333
518
|
});
|
|
519
|
+
return await stepsRewardTotalRange(context, range, stepSizes, multipliers);
|
|
334
520
|
}
|
|
335
|
-
__name(
|
|
521
|
+
__name(stepsRewardTotalGenesisPeriod, "stepsRewardTotalGenesisPeriod");
|
|
522
|
+
async function stepsRewardTotalRange(context, range, stepSizes = [
|
|
523
|
+
3,
|
|
524
|
+
4,
|
|
525
|
+
5,
|
|
526
|
+
6
|
|
527
|
+
], multipliers) {
|
|
528
|
+
const steps = blockRangeSteps(range, stepSizes);
|
|
529
|
+
return await stepsRewardTotal(context, steps, multipliers);
|
|
530
|
+
}
|
|
531
|
+
__name(stepsRewardTotalRange, "stepsRewardTotalRange");
|
|
532
|
+
async function stepsRewardTotal(context, steps, multipliers) {
|
|
533
|
+
let totalRewards = 0n;
|
|
534
|
+
for (const step of steps) {
|
|
535
|
+
const stepTotal = await stepRewardTotal(context, step, multipliers);
|
|
536
|
+
totalRewards += stepTotal;
|
|
537
|
+
}
|
|
538
|
+
return asAttoXL12(totalRewards);
|
|
539
|
+
}
|
|
540
|
+
__name(stepsRewardTotal, "stepsRewardTotal");
|
|
541
|
+
|
|
542
|
+
// src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts
|
|
543
|
+
import { assertEx as assertEx9, isArray } from "@xylabs/sdk-js";
|
|
544
|
+
import { asBlockNumber, asTimePayload, isTimePayload } from "@xyo-network/xl1-protocol";
|
|
545
|
+
var functionName = "externalBlockNumberFromXL1BlockNumber";
|
|
546
|
+
async function externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockNumber, externalTimeName, externalGenesisTime, timeBudgetMs = 2e3) {
|
|
547
|
+
const cacheKey = `${xl1BlockNumber}-${externalTimeName}-${externalGenesisTime ?? "default"}`;
|
|
548
|
+
return await withContextCacheResponse(context, functionName, cacheKey, async () => {
|
|
549
|
+
const [, payloads = []] = await blockViewer.blockByNumber(xl1BlockNumber) ?? [];
|
|
550
|
+
assertEx9(isArray(payloads));
|
|
551
|
+
const timePayload = asTimePayload(payloads.find(isTimePayload));
|
|
552
|
+
return asBlockNumber(timePayload?.[externalTimeName] ?? externalGenesisTime ?? 23372716, {
|
|
553
|
+
name: functionName
|
|
554
|
+
});
|
|
555
|
+
}, {
|
|
556
|
+
timeBudgetMs
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
__name(externalBlockNumberFromXL1BlockNumber, "externalBlockNumberFromXL1BlockNumber");
|
|
336
560
|
|
|
337
|
-
// src/primitives/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
561
|
+
// src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts
|
|
562
|
+
async function externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange, externalTimeName = "ethereum") {
|
|
563
|
+
const start = await externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockRange[0], externalTimeName);
|
|
564
|
+
const end = await externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockRange[1], externalTimeName);
|
|
565
|
+
return [
|
|
566
|
+
start,
|
|
567
|
+
end
|
|
568
|
+
];
|
|
569
|
+
}
|
|
570
|
+
__name(externalBlockRangeFromXL1BlockRange, "externalBlockRangeFromXL1BlockRange");
|
|
571
|
+
|
|
572
|
+
// src/primitives/chain/time/externalBlockRangeFromStep.ts
|
|
573
|
+
async function externalBlockRangeFromStep(context, blockViewer, stepIdentity) {
|
|
574
|
+
const cacheKey = toStepIdentityString(stepIdentity);
|
|
575
|
+
return await withContextCacheResponse(context, "externalBlockRangeFromStep", cacheKey, async () => {
|
|
576
|
+
const xl1BlockRange = stepBlockRange(stepIdentity);
|
|
577
|
+
return await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange);
|
|
578
|
+
}, {
|
|
579
|
+
timeBudgetMs: 1e3
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
__name(externalBlockRangeFromStep, "externalBlockRangeFromStep");
|
|
583
|
+
|
|
584
|
+
// src/primitives/mapToMapType.ts
|
|
585
|
+
import { isDefined as isDefined4 } from "@xylabs/sdk-js";
|
|
586
|
+
function mapToMapType(map) {
|
|
587
|
+
return {
|
|
588
|
+
get: /* @__PURE__ */ __name((key) => map.get(key), "get"),
|
|
589
|
+
has: /* @__PURE__ */ __name((key) => map.has(key), "has"),
|
|
590
|
+
set: /* @__PURE__ */ __name((key, value) => {
|
|
591
|
+
map.set(key, value);
|
|
592
|
+
}, "set"),
|
|
593
|
+
setMany: /* @__PURE__ */ __name((entries) => {
|
|
594
|
+
for (const [key, value] of entries) {
|
|
595
|
+
map.set(key, value);
|
|
596
|
+
}
|
|
597
|
+
}, "setMany"),
|
|
598
|
+
delete: /* @__PURE__ */ __name((key) => map.delete(key), "delete"),
|
|
599
|
+
clear: /* @__PURE__ */ __name(() => map.clear(), "clear"),
|
|
600
|
+
getMany: /* @__PURE__ */ __name((keys) => {
|
|
601
|
+
const result = [];
|
|
602
|
+
for (const key of keys) {
|
|
603
|
+
const value = map.get(key);
|
|
604
|
+
if (isDefined4(value)) {
|
|
605
|
+
result.push(value);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return result;
|
|
609
|
+
}, "getMany"),
|
|
610
|
+
[Symbol.iterator]: function* () {
|
|
611
|
+
for (const entry of map) {
|
|
612
|
+
yield entry;
|
|
348
613
|
}
|
|
349
|
-
rewardTransferCount++;
|
|
350
614
|
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
__name(mapToMapType, "mapToMapType");
|
|
618
|
+
|
|
619
|
+
// src/primitives/readPayloadMapFromStore.ts
|
|
620
|
+
import { isDefined as isDefined5 } from "@xylabs/sdk-js";
|
|
621
|
+
function readPayloadMapFromStore(store) {
|
|
622
|
+
if (isReadArchivist(store)) {
|
|
623
|
+
return {
|
|
624
|
+
get: /* @__PURE__ */ __name(async (hash) => {
|
|
625
|
+
return (await store.get([
|
|
626
|
+
hash
|
|
627
|
+
]))[0];
|
|
628
|
+
}, "get"),
|
|
629
|
+
getMany: /* @__PURE__ */ __name(async (hashes) => {
|
|
630
|
+
return await store.get(hashes);
|
|
631
|
+
}, "getMany"),
|
|
632
|
+
has: /* @__PURE__ */ __name(async (hash) => {
|
|
633
|
+
return isDefined5((await store.get([
|
|
634
|
+
hash
|
|
635
|
+
]))[0]);
|
|
636
|
+
}, "has")
|
|
637
|
+
};
|
|
351
638
|
}
|
|
352
|
-
|
|
353
|
-
return [
|
|
354
|
-
rewardTransferIndex,
|
|
355
|
-
rewardTransferCount
|
|
356
|
-
];
|
|
639
|
+
return store;
|
|
357
640
|
}
|
|
358
|
-
__name(
|
|
641
|
+
__name(readPayloadMapFromStore, "readPayloadMapFromStore");
|
|
642
|
+
function payloadMapFromStore(store) {
|
|
643
|
+
if (isReadWriteArchivist(store)) {
|
|
644
|
+
return {
|
|
645
|
+
get: /* @__PURE__ */ __name(async (hash) => {
|
|
646
|
+
return (await store.get([
|
|
647
|
+
hash
|
|
648
|
+
]))[0];
|
|
649
|
+
}, "get"),
|
|
650
|
+
getMany: /* @__PURE__ */ __name(async (hashes) => {
|
|
651
|
+
return await store.get(hashes);
|
|
652
|
+
}, "getMany"),
|
|
653
|
+
has: /* @__PURE__ */ __name(async (hash) => {
|
|
654
|
+
return isDefined5((await store.get([
|
|
655
|
+
hash
|
|
656
|
+
]))[0]);
|
|
657
|
+
}, "has"),
|
|
658
|
+
clear: /* @__PURE__ */ __name(async () => {
|
|
659
|
+
return await store.clear();
|
|
660
|
+
}, "clear"),
|
|
661
|
+
delete: /* @__PURE__ */ __name(async (id) => {
|
|
662
|
+
await store.delete([
|
|
663
|
+
id
|
|
664
|
+
]);
|
|
665
|
+
return true;
|
|
666
|
+
}, "delete"),
|
|
667
|
+
set: /* @__PURE__ */ __name(async (_id, data) => {
|
|
668
|
+
await store.insert([
|
|
669
|
+
data
|
|
670
|
+
]);
|
|
671
|
+
}, "set"),
|
|
672
|
+
setMany: /* @__PURE__ */ __name(async (entries) => {
|
|
673
|
+
await store.insert(entries.map((e) => e[1]));
|
|
674
|
+
}, "setMany")
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return store;
|
|
678
|
+
}
|
|
679
|
+
__name(payloadMapFromStore, "payloadMapFromStore");
|
|
680
|
+
|
|
681
|
+
// src/primitives/rewardFromBlockNumber.ts
|
|
682
|
+
import { toFixedPoint } from "@xylabs/sdk-js";
|
|
683
|
+
import { asAttoXL1 as asAttoXL13 } from "@xyo-network/xl1-protocol";
|
|
684
|
+
var rewardFromBlockNumber = /* @__PURE__ */ __name((places = 18) => {
|
|
685
|
+
return (blockNumber, startingReward = asAttoXL13(toFixedPoint(500n, places)), blocksPerStep = 1e6, stepFactorNumerator = 95n, stepFactorDenominator = 100n, minBlockReward = asAttoXL13(toFixedPoint(10n, places)), creatorReward = asAttoXL13(toFixedPoint(20000000000n, places))) => {
|
|
686
|
+
if (blockNumber === 0) {
|
|
687
|
+
return creatorReward;
|
|
688
|
+
}
|
|
689
|
+
const step = Math.floor((blockNumber + blocksPerStep) / blocksPerStep);
|
|
690
|
+
const stepExp = BigInt(step - 1);
|
|
691
|
+
const poweredNumerator = stepExp > 0 ? stepFactorNumerator ** stepExp : 1n;
|
|
692
|
+
const poweredDenominator = stepExp > 0 ? stepFactorDenominator ** stepExp : 1n;
|
|
693
|
+
let reward = startingReward * poweredNumerator / poweredDenominator;
|
|
694
|
+
return asAttoXL13(reward < minBlockReward ? minBlockReward : reward);
|
|
695
|
+
};
|
|
696
|
+
}, "rewardFromBlockNumber");
|
|
697
|
+
|
|
698
|
+
// src/primitives/stake/activeStakeAtTimeByAddress.ts
|
|
699
|
+
import { isDefined as isDefined6 } from "@xylabs/sdk-js";
|
|
700
|
+
|
|
701
|
+
// src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts
|
|
702
|
+
async function mergedAddRemoveStakeEventsByStaker(chainEvents, range, staked, staker) {
|
|
703
|
+
const [addedEvents, removedEvents] = await Promise.all([
|
|
704
|
+
chainEvents.stakeEvents(range, {
|
|
705
|
+
name: "StakeAdded",
|
|
706
|
+
args: {
|
|
707
|
+
staked,
|
|
708
|
+
staker
|
|
709
|
+
}
|
|
710
|
+
}),
|
|
711
|
+
chainEvents.stakeEvents(range, {
|
|
712
|
+
name: "StakeRemoved",
|
|
713
|
+
args: {
|
|
714
|
+
staked,
|
|
715
|
+
staker
|
|
716
|
+
}
|
|
717
|
+
})
|
|
718
|
+
]);
|
|
719
|
+
const result = [
|
|
720
|
+
...addedEvents,
|
|
721
|
+
...removedEvents
|
|
722
|
+
].toSorted((a, b) => a.time - b.time);
|
|
723
|
+
return result;
|
|
724
|
+
}
|
|
725
|
+
__name(mergedAddRemoveStakeEventsByStaker, "mergedAddRemoveStakeEventsByStaker");
|
|
726
|
+
|
|
727
|
+
// src/primitives/stake/activeStakeAtTimeByAddress.ts
|
|
728
|
+
async function activeStakeAtTimeByAddress(chain, staked, time, staker) {
|
|
729
|
+
const stakeEvents = (await mergedAddRemoveStakeEventsByStaker(chain, [
|
|
730
|
+
0,
|
|
731
|
+
time
|
|
732
|
+
], staked, staker)).toSorted((a, b) => a.time - b.time);
|
|
733
|
+
let result = 0n;
|
|
734
|
+
for (const event of stakeEvents) {
|
|
735
|
+
if (event.time > time) break;
|
|
736
|
+
if (event.args.staked !== staked) continue;
|
|
737
|
+
if (isDefined6(staker) && event.args.staker !== staker) continue;
|
|
738
|
+
if (event.name === "StakeAdded") {
|
|
739
|
+
result += event.args.amount;
|
|
740
|
+
} else if (event.name === "StakeRemoved") {
|
|
741
|
+
result -= event.args.amount;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return result;
|
|
745
|
+
}
|
|
746
|
+
__name(activeStakeAtTimeByAddress, "activeStakeAtTimeByAddress");
|
|
747
|
+
|
|
748
|
+
// src/primitives/stake/activeStakeAtTimeByPosition.ts
|
|
749
|
+
import { isUndefined } from "@xylabs/sdk-js";
|
|
750
|
+
|
|
751
|
+
// src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts
|
|
752
|
+
async function mergedAddRemoveStakeEventsByPosition(chainEvents, range, position) {
|
|
753
|
+
const [addedEvents, removedEvents] = await Promise.all([
|
|
754
|
+
chainEvents.stakeEvents(range, {
|
|
755
|
+
name: "StakeAdded",
|
|
756
|
+
args: {
|
|
757
|
+
id: position
|
|
758
|
+
}
|
|
759
|
+
}),
|
|
760
|
+
chainEvents.stakeEvents(range, {
|
|
761
|
+
name: "StakeRemoved",
|
|
762
|
+
args: {
|
|
763
|
+
id: position
|
|
764
|
+
}
|
|
765
|
+
})
|
|
766
|
+
]);
|
|
767
|
+
const result = [
|
|
768
|
+
...addedEvents,
|
|
769
|
+
...removedEvents
|
|
770
|
+
].toSorted((a, b) => a.time - b.time);
|
|
771
|
+
return result;
|
|
772
|
+
}
|
|
773
|
+
__name(mergedAddRemoveStakeEventsByPosition, "mergedAddRemoveStakeEventsByPosition");
|
|
774
|
+
|
|
775
|
+
// src/primitives/stake/activeStakeAtTimeByPosition.ts
|
|
776
|
+
async function activeStakeAtTimeByPosition(chainStakeEvents, externalTime, position) {
|
|
777
|
+
const stakeEvents = (await mergedAddRemoveStakeEventsByPosition(chainStakeEvents, [
|
|
778
|
+
0,
|
|
779
|
+
externalTime
|
|
780
|
+
], position)).toSorted((a, b) => a.time - b.time);
|
|
781
|
+
let result = 0n;
|
|
782
|
+
for (const event of stakeEvents) {
|
|
783
|
+
if (event.time > externalTime) break;
|
|
784
|
+
if (isUndefined(position) || position === Number(event.args.id)) {
|
|
785
|
+
if (event.name === "StakeAdded") {
|
|
786
|
+
result += event.args.amount;
|
|
787
|
+
} else if (event.name === "StakeRemoved") {
|
|
788
|
+
result -= event.args.amount;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return result;
|
|
793
|
+
}
|
|
794
|
+
__name(activeStakeAtTimeByPosition, "activeStakeAtTimeByPosition");
|
|
795
|
+
|
|
796
|
+
// src/primitives/stake/allStakersForRange.ts
|
|
797
|
+
import { toAddress as toAddress7 } from "@xylabs/sdk-js";
|
|
798
|
+
async function allStakersForRange(chain, externalRange, staked) {
|
|
799
|
+
const mergedEvents = await mergedAddRemoveStakeEventsByStaker(chain, [
|
|
800
|
+
0,
|
|
801
|
+
externalRange[1]
|
|
802
|
+
], staked);
|
|
803
|
+
const resultWithZeros = {};
|
|
804
|
+
for (const event of mergedEvents) {
|
|
805
|
+
const staker = toAddress7(event.args.staker);
|
|
806
|
+
resultWithZeros[staker] = resultWithZeros[staker] ?? 0n;
|
|
807
|
+
if (event.name === "StakeAdded") {
|
|
808
|
+
resultWithZeros[staker] += event.args.amount;
|
|
809
|
+
} else if (event.name === "StakeRemoved") {
|
|
810
|
+
resultWithZeros[staker] -= event.args.amount;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
const nonZero = Object.entries(resultWithZeros).filter(([, amount]) => amount > 0n).map(([address]) => address);
|
|
814
|
+
const result = {};
|
|
815
|
+
for (const address of nonZero) {
|
|
816
|
+
result[toAddress7(address)] = resultWithZeros[toAddress7(address)];
|
|
817
|
+
}
|
|
818
|
+
return result;
|
|
819
|
+
}
|
|
820
|
+
__name(allStakersForRange, "allStakersForRange");
|
|
821
|
+
|
|
822
|
+
// src/primitives/stake/allStakersForStep.ts
|
|
823
|
+
async function allStakersForStep(context, blockViewer, stepContext, staked) {
|
|
824
|
+
const xl1BlockRange = stepBlockRange(stepContext);
|
|
825
|
+
return await allStakersForRange(context.stake.stakeEvents, await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange), staked);
|
|
826
|
+
}
|
|
827
|
+
__name(allStakersForStep, "allStakersForStep");
|
|
828
|
+
|
|
829
|
+
// src/primitives/stake/weightedStakeForRangeByPosition.ts
|
|
830
|
+
import { isDefined as isDefined7 } from "@xylabs/sdk-js";
|
|
831
|
+
import { asBlockNumber as asBlockNumber2 } from "@xyo-network/xl1-protocol";
|
|
832
|
+
async function weightedStakeForRangeByPosition(context, blockViewer, externalRange, positionId) {
|
|
833
|
+
const cacheKey = isDefined7(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`;
|
|
834
|
+
return await withContextCacheResponse(context, "weightedStakeForRangeByPosition", cacheKey, async () => {
|
|
835
|
+
let weightedStakeSum = 0n;
|
|
836
|
+
if (isDefined7(positionId)) {
|
|
837
|
+
const mergedEvents = (await mergedAddRemoveStakeEventsByPosition(context.stake.stakeEvents, [
|
|
838
|
+
0,
|
|
839
|
+
externalRange[1]
|
|
840
|
+
], positionId)).toSorted((a, b) => a.time - b.time);
|
|
841
|
+
let currentTime = externalRange[0];
|
|
842
|
+
let currentStake = 0n;
|
|
843
|
+
for (const event of mergedEvents) {
|
|
844
|
+
if (event.time > currentTime) {
|
|
845
|
+
weightedStakeSum += currentStake * BigInt(event.time - currentTime);
|
|
846
|
+
}
|
|
847
|
+
if (event.name === "StakeAdded") {
|
|
848
|
+
currentStake += event.args.amount;
|
|
849
|
+
} else if (event.name === "StakeRemoved") {
|
|
850
|
+
currentStake -= event.args.amount;
|
|
851
|
+
}
|
|
852
|
+
currentStake = currentStake < 0n ? 0n : currentStake;
|
|
853
|
+
currentTime = asBlockNumber2(event.time, {
|
|
854
|
+
name: "weightedStakeForRangeByPosition"
|
|
855
|
+
});
|
|
856
|
+
if (currentTime > externalRange[1]) {
|
|
857
|
+
break;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (externalRange[1] > currentTime) {
|
|
861
|
+
weightedStakeSum += currentStake * BigInt(externalRange[1] - currentTime);
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
const positionCount = await context.stake.stakeEvents.positionCount(externalRange);
|
|
865
|
+
for (let pos = 0; pos < positionCount; pos++) {
|
|
866
|
+
weightedStakeSum += await weightedStakeForRangeByPosition(context, blockViewer, externalRange, pos);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return weightedStakeSum;
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
__name(weightedStakeForRangeByPosition, "weightedStakeForRangeByPosition");
|
|
873
|
+
|
|
874
|
+
// src/primitives/rewards/networkStakeStepRewardPositionWeight.ts
|
|
875
|
+
async function networkStakeStepRewardPositionWeight(context, blockViewer, stepContext, position) {
|
|
876
|
+
const result = await weightedStakeForRangeByPosition(context, blockViewer, await externalBlockRangeFromStep(context, blockViewer, stepContext), position);
|
|
877
|
+
return result;
|
|
878
|
+
}
|
|
879
|
+
__name(networkStakeStepRewardPositionWeight, "networkStakeStepRewardPositionWeight");
|
|
359
880
|
|
|
360
881
|
// src/primitives/timeBudget.ts
|
|
361
882
|
async function timeBudget(name, logger, func, budget, status = false) {
|
|
@@ -405,7 +926,7 @@ function contextCache(context, name, create) {
|
|
|
405
926
|
if (!context.caches) {
|
|
406
927
|
context.caches = {};
|
|
407
928
|
}
|
|
408
|
-
if (
|
|
929
|
+
if (isUndefined2(context.caches[name])) {
|
|
409
930
|
context.caches[name] = create?.() ?? new MemoryMap();
|
|
410
931
|
}
|
|
411
932
|
return context.caches[name];
|
|
@@ -416,7 +937,7 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4, t
|
|
|
416
937
|
max
|
|
417
938
|
}));
|
|
418
939
|
const cacheResult = await cache.get(key);
|
|
419
|
-
if (
|
|
940
|
+
if (isDefined8(cacheResult)) {
|
|
420
941
|
return cacheResult;
|
|
421
942
|
}
|
|
422
943
|
const result = timeBudgetMs > 0 ? await timeBudget(name, context.logger, func, timeBudgetMs) : await func();
|
|
@@ -471,13 +992,36 @@ var bundle = /* @__PURE__ */ __name((root, transaction) => {
|
|
|
471
992
|
}, "bundle");
|
|
472
993
|
|
|
473
994
|
// src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts
|
|
474
|
-
import { PayloadBuilder as
|
|
995
|
+
import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/payload-builder";
|
|
475
996
|
import { PayloadBundleSchema as PayloadBundleSchema2 } from "@xyo-network/payload-model";
|
|
476
997
|
|
|
998
|
+
// src/transaction/buildRandomTransaction.ts
|
|
999
|
+
import { Account } from "@xyo-network/account";
|
|
1000
|
+
import { asXL1BlockNumber as asXL1BlockNumber2, isAllowedBlockPayload as isAllowedBlockPayload2 } from "@xyo-network/xl1-protocol";
|
|
1001
|
+
|
|
1002
|
+
// src/createTransferPayload.ts
|
|
1003
|
+
import { toHex } from "@xylabs/sdk-js";
|
|
1004
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
|
|
1005
|
+
import { TransferSchema } from "@xyo-network/xl1-protocol";
|
|
1006
|
+
function createTransferPayload(from, transfers, context) {
|
|
1007
|
+
return new PayloadBuilder4({
|
|
1008
|
+
schema: TransferSchema
|
|
1009
|
+
}).fields({
|
|
1010
|
+
epoch: Date.now(),
|
|
1011
|
+
from,
|
|
1012
|
+
transfers: Object.fromEntries(Object.entries(transfers).map(([k, v]) => [
|
|
1013
|
+
k,
|
|
1014
|
+
toHex(v)
|
|
1015
|
+
])),
|
|
1016
|
+
context
|
|
1017
|
+
}).build();
|
|
1018
|
+
}
|
|
1019
|
+
__name(createTransferPayload, "createTransferPayload");
|
|
1020
|
+
|
|
477
1021
|
// src/transaction/buildTransaction.ts
|
|
478
|
-
import { assertEx as
|
|
1022
|
+
import { assertEx as assertEx10, toHex as toHex2 } from "@xylabs/sdk-js";
|
|
479
1023
|
import { BoundWitnessBuilder } from "@xyo-network/boundwitness-builder";
|
|
480
|
-
import { PayloadBuilder as
|
|
1024
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
|
|
481
1025
|
import { defaultTransactionFees } from "@xyo-network/xl1-protocol";
|
|
482
1026
|
async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer, nbf, exp, from, fees = defaultTransactionFees) {
|
|
483
1027
|
if (from === void 0 && Array.isArray(signer)) {
|
|
@@ -486,22 +1030,22 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
486
1030
|
const txBoundWitnessFields = {
|
|
487
1031
|
chain,
|
|
488
1032
|
fees: {
|
|
489
|
-
base:
|
|
490
|
-
gasLimit:
|
|
491
|
-
gasPrice:
|
|
492
|
-
priority:
|
|
1033
|
+
base: toHex2(fees.base),
|
|
1034
|
+
gasLimit: toHex2(fees.gasLimit),
|
|
1035
|
+
gasPrice: toHex2(fees.gasPrice),
|
|
1036
|
+
priority: toHex2(fees.priority)
|
|
493
1037
|
},
|
|
494
1038
|
nbf,
|
|
495
1039
|
exp
|
|
496
1040
|
};
|
|
497
|
-
const elevatedHashes = await
|
|
1041
|
+
const elevatedHashes = await PayloadBuilder5.hashes(onChainPayloads);
|
|
498
1042
|
const script = [];
|
|
499
1043
|
for (const elevatedHash of elevatedHashes) {
|
|
500
1044
|
script.push(`elevate|${elevatedHash}`);
|
|
501
1045
|
}
|
|
502
1046
|
const fields = {
|
|
503
1047
|
...txBoundWitnessFields,
|
|
504
|
-
from: from ?? (Array.isArray(signer) ?
|
|
1048
|
+
from: from ?? (Array.isArray(signer) ? assertEx10(signer.at(0)?.address) : signer.address)
|
|
505
1049
|
};
|
|
506
1050
|
if (script.length > 0) {
|
|
507
1051
|
fields.script = script;
|
|
@@ -515,30 +1059,49 @@ async function buildTransaction(chain, onChainPayloads, offChainPayloads, signer
|
|
|
515
1059
|
signer
|
|
516
1060
|
]).build();
|
|
517
1061
|
return [
|
|
518
|
-
await
|
|
519
|
-
await
|
|
1062
|
+
await PayloadBuilder5.addHashMeta(tx),
|
|
1063
|
+
await PayloadBuilder5.addHashMeta(txPayloads)
|
|
520
1064
|
];
|
|
521
1065
|
}
|
|
522
1066
|
__name(buildTransaction, "buildTransaction");
|
|
523
1067
|
|
|
1068
|
+
// src/transaction/buildRandomTransaction.ts
|
|
1069
|
+
var buildRandomTransaction = /* @__PURE__ */ __name(async (chain, payloads, account, nbf = asXL1BlockNumber2(0, true), exp = asXL1BlockNumber2(nbf + 1e3, true), privatePayloadSchemas = [], receiverAddress) => {
|
|
1070
|
+
const elevatedPayloads2 = (payloads ?? []).filter(isAllowedBlockPayload2);
|
|
1071
|
+
const additionalPayloads = (payloads ?? []).filter((payload) => !isAllowedBlockPayload2(payload));
|
|
1072
|
+
const sender = account ?? await Account.random();
|
|
1073
|
+
if (elevatedPayloads2?.length === 0) {
|
|
1074
|
+
const receiver = receiverAddress ?? (await Account.random()).address;
|
|
1075
|
+
const transferPayload = createTransferPayload(sender.address, {
|
|
1076
|
+
[receiver]: 1n
|
|
1077
|
+
});
|
|
1078
|
+
elevatedPayloads2.push(transferPayload);
|
|
1079
|
+
}
|
|
1080
|
+
const hydratedTransaction = await buildTransaction(chain, elevatedPayloads2, additionalPayloads, sender, nbf, exp);
|
|
1081
|
+
return [
|
|
1082
|
+
hydratedTransaction[0],
|
|
1083
|
+
hydratedTransaction[1].filter((p) => !privatePayloadSchemas.includes(p.schema))
|
|
1084
|
+
];
|
|
1085
|
+
}, "buildRandomTransaction");
|
|
1086
|
+
|
|
524
1087
|
// src/transaction/buildUnsignedTransaction.ts
|
|
525
|
-
import { toHex as
|
|
1088
|
+
import { toHex as toHex3 } from "@xylabs/sdk-js";
|
|
526
1089
|
import { BoundWitnessBuilder as BoundWitnessBuilder2 } from "@xyo-network/boundwitness-builder";
|
|
527
|
-
import { PayloadBuilder as
|
|
1090
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
|
|
528
1091
|
import { defaultTransactionFees as defaultTransactionFees2 } from "@xyo-network/xl1-protocol";
|
|
529
1092
|
async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads, nbf, exp, from, fees = defaultTransactionFees2) {
|
|
530
1093
|
const txBoundWitnessFields = {
|
|
531
1094
|
chain,
|
|
532
1095
|
fees: {
|
|
533
|
-
base:
|
|
534
|
-
gasLimit:
|
|
535
|
-
gasPrice:
|
|
536
|
-
priority:
|
|
1096
|
+
base: toHex3(fees.base),
|
|
1097
|
+
gasLimit: toHex3(fees.gasLimit),
|
|
1098
|
+
gasPrice: toHex3(fees.gasPrice),
|
|
1099
|
+
priority: toHex3(fees.priority)
|
|
537
1100
|
},
|
|
538
1101
|
nbf,
|
|
539
1102
|
exp
|
|
540
1103
|
};
|
|
541
|
-
const elevatedHashes = await
|
|
1104
|
+
const elevatedHashes = await PayloadBuilder6.hashes(onChainPayloads);
|
|
542
1105
|
const script = [];
|
|
543
1106
|
for (const elevatedHash of elevatedHashes) {
|
|
544
1107
|
script.push(`elevate|${elevatedHash}`);
|
|
@@ -564,7 +1127,7 @@ async function buildUnsignedTransaction(chain, onChainPayloads, offChainPayloads
|
|
|
564
1127
|
__name(buildUnsignedTransaction, "buildUnsignedTransaction");
|
|
565
1128
|
|
|
566
1129
|
// src/transaction/confirmSubmittedTransaction.ts
|
|
567
|
-
import { delay, isDefined as
|
|
1130
|
+
import { delay, isDefined as isDefined9 } from "@xylabs/sdk-js";
|
|
568
1131
|
var DEFAULT_CONFIRMATION_ATTEMPTS = 20;
|
|
569
1132
|
var DEFAULT_DELAY_BETWEEN_ATTEMPTS = 1e3;
|
|
570
1133
|
var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, txHash, options) => {
|
|
@@ -573,7 +1136,7 @@ var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, txHash,
|
|
|
573
1136
|
let attempts = 0;
|
|
574
1137
|
while (true) {
|
|
575
1138
|
const tx = await viewer.transactionByHash(txHash) ?? void 0;
|
|
576
|
-
if (
|
|
1139
|
+
if (isDefined9(tx)) {
|
|
577
1140
|
options?.logger?.log("\u2705 Transaction confirmed:", txHash, "\n");
|
|
578
1141
|
return tx;
|
|
579
1142
|
} else {
|
|
@@ -590,9 +1153,9 @@ var confirmSubmittedTransaction = /* @__PURE__ */ __name(async (viewer, txHash,
|
|
|
590
1153
|
}, "confirmSubmittedTransaction");
|
|
591
1154
|
|
|
592
1155
|
// src/transaction/hydrateTransaction.ts
|
|
593
|
-
import { assertEx as
|
|
1156
|
+
import { assertEx as assertEx11 } from "@xylabs/sdk-js";
|
|
594
1157
|
import { hydrateTypedBoundWitness, tryHydrateTypedBoundWitness } from "@xyo-network/archivist-model";
|
|
595
|
-
import { asSignedHydratedTransaction, isAllowedBlockPayload as
|
|
1158
|
+
import { asSignedHydratedTransaction, isAllowedBlockPayload as isAllowedBlockPayload3, isSignedTransactionBoundWitnessWithStorageMeta } from "@xyo-network/xl1-protocol";
|
|
596
1159
|
var tryHydrateTransaction = /* @__PURE__ */ __name(async ({ chainMap }, hash) => {
|
|
597
1160
|
return await tryHydrateTypedBoundWitness({
|
|
598
1161
|
get(hashes) {
|
|
@@ -644,7 +1207,7 @@ var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async ({ chainMap },
|
|
|
644
1207
|
const [code, hash2] = opCode.split("|");
|
|
645
1208
|
if (code === "elevated") {
|
|
646
1209
|
const elevatedPayload = payloads.find((payload) => payload._hash === hash2);
|
|
647
|
-
if (
|
|
1210
|
+
if (isAllowedBlockPayload3(elevatedPayload)) {
|
|
648
1211
|
elevatedPayloads2.push(elevatedPayload);
|
|
649
1212
|
}
|
|
650
1213
|
}
|
|
@@ -658,15 +1221,15 @@ var tryHydrateElevatedTransaction = /* @__PURE__ */ __name(async ({ chainMap },
|
|
|
658
1221
|
return void 0;
|
|
659
1222
|
}, "tryHydrateElevatedTransaction");
|
|
660
1223
|
var hydrateElevatedTransaction = /* @__PURE__ */ __name(async (context, hash) => {
|
|
661
|
-
return
|
|
1224
|
+
return assertEx11(await tryHydrateElevatedTransaction(context, hash), () => "Hydration failed");
|
|
662
1225
|
}, "hydrateElevatedTransaction");
|
|
663
1226
|
|
|
664
1227
|
// src/transaction/primitives/transactionBlockByteCount.ts
|
|
665
|
-
import { PayloadBuilder as
|
|
1228
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
|
|
666
1229
|
function transactionBlockByteCount([transaction, payloads]) {
|
|
667
|
-
const cleanTransaction =
|
|
1230
|
+
const cleanTransaction = PayloadBuilder7.omitStorageMeta(transaction);
|
|
668
1231
|
const transactionBytes = JSON.stringify(cleanTransaction).length;
|
|
669
|
-
const cleanPayloads =
|
|
1232
|
+
const cleanPayloads = PayloadBuilder7.omitStorageMeta(payloads);
|
|
670
1233
|
return cleanPayloads.reduce((acc, payload) => acc + JSON.stringify(payload).length, 0) + transactionBytes;
|
|
671
1234
|
}
|
|
672
1235
|
__name(transactionBlockByteCount, "transactionBlockByteCount");
|
|
@@ -724,7 +1287,7 @@ __name(transactionRequiredGas, "transactionRequiredGas");
|
|
|
724
1287
|
|
|
725
1288
|
// src/transaction/script.ts
|
|
726
1289
|
import { asHash as asHash2 } from "@xylabs/sdk-js";
|
|
727
|
-
import { assertEx as
|
|
1290
|
+
import { assertEx as assertEx12, filterAs } from "@xylabs/sdk-js";
|
|
728
1291
|
import { isAllowedBlockPayloadWithHashMeta } from "@xyo-network/xl1-protocol";
|
|
729
1292
|
var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
730
1293
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
@@ -733,7 +1296,7 @@ var tryExtractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
|
733
1296
|
var extractElevatedHashesFromScript = /* @__PURE__ */ __name((strings) => {
|
|
734
1297
|
const hashes = strings.filter((str) => str.startsWith("elevate|")).map((str) => str.split("|")[1]);
|
|
735
1298
|
const filtered = filterAs(hashes, (h) => asHash2(h));
|
|
736
|
-
|
|
1299
|
+
assertEx12(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
737
1300
|
return filtered;
|
|
738
1301
|
}, "extractElevatedHashesFromScript");
|
|
739
1302
|
var tryExtractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
@@ -747,15 +1310,15 @@ var extractElevatedHashes = /* @__PURE__ */ __name((tx) => {
|
|
|
747
1310
|
const { script } = bw;
|
|
748
1311
|
const hashes = script ? tryExtractElevatedHashesFromScript(script) : [];
|
|
749
1312
|
const filtered = payloads.filter((p) => hashes.includes(p._hash)).filter(isAllowedBlockPayloadWithHashMeta);
|
|
750
|
-
|
|
1313
|
+
assertEx12(filtered.length === hashes.length, () => "Invalid elevated hashes");
|
|
751
1314
|
return filtered;
|
|
752
1315
|
}, "extractElevatedHashes");
|
|
753
1316
|
|
|
754
1317
|
// src/transaction/signTransaction.ts
|
|
755
|
-
import { assertEx as
|
|
756
|
-
import { PayloadBuilder as
|
|
1318
|
+
import { assertEx as assertEx13, hexFromArrayBuffer, toArrayBuffer } from "@xylabs/sdk-js";
|
|
1319
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/payload-builder";
|
|
757
1320
|
async function signTransaction(tx, account) {
|
|
758
|
-
|
|
1321
|
+
assertEx13(tx.from === account.address, () => "Signer address does not match transaction from address");
|
|
759
1322
|
const unsignedTx = structuredClone(tx);
|
|
760
1323
|
unsignedTx.addresses = [
|
|
761
1324
|
account.address
|
|
@@ -763,7 +1326,7 @@ async function signTransaction(tx, account) {
|
|
|
763
1326
|
unsignedTx.previous_hashes = [
|
|
764
1327
|
account.previousHash ?? null
|
|
765
1328
|
];
|
|
766
|
-
const hash = await
|
|
1329
|
+
const hash = await PayloadBuilder8.dataHash(unsignedTx);
|
|
767
1330
|
const hashBytes = toArrayBuffer(hash);
|
|
768
1331
|
const [signature] = await account.sign(hashBytes);
|
|
769
1332
|
const result = {
|
|
@@ -776,14 +1339,126 @@ async function signTransaction(tx, account) {
|
|
|
776
1339
|
}
|
|
777
1340
|
__name(signTransaction, "signTransaction");
|
|
778
1341
|
|
|
1342
|
+
// src/transaction/TransactionBuilder.ts
|
|
1343
|
+
import { assertEx as assertEx14, Base } from "@xylabs/sdk-js";
|
|
1344
|
+
import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/payload-builder";
|
|
1345
|
+
import { asXL1BlockNumber as asXL1BlockNumber3, defaultTransactionFees as defaultTransactionFees3, isAllowedBlockPayload as isAllowedBlockPayload4, minTransactionFees, XYO_ZERO_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
1346
|
+
var TransactionBuilder = class extends Base {
|
|
1347
|
+
static {
|
|
1348
|
+
__name(this, "TransactionBuilder");
|
|
1349
|
+
}
|
|
1350
|
+
_blockRange;
|
|
1351
|
+
_chain;
|
|
1352
|
+
_elevatedPayloads = [];
|
|
1353
|
+
_fees;
|
|
1354
|
+
_payloads = [];
|
|
1355
|
+
_signers = [];
|
|
1356
|
+
constructor(options = {}) {
|
|
1357
|
+
super(options);
|
|
1358
|
+
}
|
|
1359
|
+
async build() {
|
|
1360
|
+
const chain = assertEx14(this._chain, () => "Chain must be set before building the transaction");
|
|
1361
|
+
const fees = assertEx14(this._fees, () => "Fees must be set before building the transaction");
|
|
1362
|
+
const blockRange = assertEx14(this._blockRange, () => "Block range must be set before building the transaction");
|
|
1363
|
+
return await buildTransaction(chain, this._elevatedPayloads, this._payloads, this._signers, asXL1BlockNumber3(blockRange[0], true), asXL1BlockNumber3(blockRange[1], true), this._signers[0]?.address, fees);
|
|
1364
|
+
}
|
|
1365
|
+
chain(chain) {
|
|
1366
|
+
this._chain = chain;
|
|
1367
|
+
return this;
|
|
1368
|
+
}
|
|
1369
|
+
async dryRun() {
|
|
1370
|
+
return await buildTransaction(XYO_ZERO_ADDRESS, this._elevatedPayloads, this._payloads, this._signers, asXL1BlockNumber3(0, true), asXL1BlockNumber3(1e3, true), this._signers[0]?.address, defaultTransactionFees3);
|
|
1371
|
+
}
|
|
1372
|
+
elevatedPayload(payload) {
|
|
1373
|
+
const allowedPayload = isAllowedBlockPayload4(payload) ? payload : void 0;
|
|
1374
|
+
const allowPayloadExists = assertEx14(allowedPayload, () => "Payload must be an AllowedBlockPayload");
|
|
1375
|
+
this._elevatedPayloads.push(allowPayloadExists);
|
|
1376
|
+
return this;
|
|
1377
|
+
}
|
|
1378
|
+
elevatedPayloads(payloads) {
|
|
1379
|
+
if (payloads) for (const payload of payloads) {
|
|
1380
|
+
this.elevatedPayload(payload);
|
|
1381
|
+
}
|
|
1382
|
+
return this;
|
|
1383
|
+
}
|
|
1384
|
+
async estimatedMinimumFees() {
|
|
1385
|
+
const tx = await this.dryRun();
|
|
1386
|
+
const requiredGas = transactionRequiredGas(tx);
|
|
1387
|
+
return {
|
|
1388
|
+
base: minTransactionFees.base,
|
|
1389
|
+
// eslint-disable-next-line unicorn/prefer-math-min-max
|
|
1390
|
+
gasLimit: requiredGas > minTransactionFees.gasLimit ? requiredGas : minTransactionFees.gasLimit,
|
|
1391
|
+
gasPrice: minTransactionFees.gasPrice,
|
|
1392
|
+
priority: minTransactionFees.priority
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
fees(fees) {
|
|
1396
|
+
this._fees = fees;
|
|
1397
|
+
return this;
|
|
1398
|
+
}
|
|
1399
|
+
payload(payload) {
|
|
1400
|
+
this._payloads.push(payload);
|
|
1401
|
+
return this;
|
|
1402
|
+
}
|
|
1403
|
+
payloads(payloads) {
|
|
1404
|
+
if (payloads) for (const payload of payloads) {
|
|
1405
|
+
if (payload !== null) {
|
|
1406
|
+
this.payload(payload);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return this;
|
|
1410
|
+
}
|
|
1411
|
+
range(blockRange) {
|
|
1412
|
+
if (blockRange.length !== 2) {
|
|
1413
|
+
throw new Error("Block range must be an array of two numbers");
|
|
1414
|
+
}
|
|
1415
|
+
this._blockRange = blockRange;
|
|
1416
|
+
return this;
|
|
1417
|
+
}
|
|
1418
|
+
async removeElevatedPayload(payload) {
|
|
1419
|
+
const hash = await PayloadBuilder9.hash(payload);
|
|
1420
|
+
const existingHashes = await PayloadBuilder9.hashes(this._elevatedPayloads);
|
|
1421
|
+
const existingPayloadIndex = existingHashes.indexOf(hash);
|
|
1422
|
+
if (existingPayloadIndex === -1) {
|
|
1423
|
+
throw new Error("Payload not found in the transaction");
|
|
1424
|
+
}
|
|
1425
|
+
this._elevatedPayloads = this._elevatedPayloads.filter((_, index) => index !== existingPayloadIndex);
|
|
1426
|
+
return this;
|
|
1427
|
+
}
|
|
1428
|
+
async removePayload(payload) {
|
|
1429
|
+
const hash = await PayloadBuilder9.hash(payload);
|
|
1430
|
+
const existingHashes = await PayloadBuilder9.hashes(this._payloads);
|
|
1431
|
+
const existingPayloadIndex = existingHashes.indexOf(hash);
|
|
1432
|
+
if (existingPayloadIndex === -1) {
|
|
1433
|
+
throw new Error("Payload not found in the transaction");
|
|
1434
|
+
}
|
|
1435
|
+
this._payloads = this._payloads.filter((_, index) => index !== existingPayloadIndex);
|
|
1436
|
+
return this;
|
|
1437
|
+
}
|
|
1438
|
+
signer(signer) {
|
|
1439
|
+
if (signer) {
|
|
1440
|
+
this._signers.push(signer);
|
|
1441
|
+
}
|
|
1442
|
+
return this;
|
|
1443
|
+
}
|
|
1444
|
+
signers(signers) {
|
|
1445
|
+
if (signers) for (const signer of signers) {
|
|
1446
|
+
if (signer !== null) {
|
|
1447
|
+
this.signer(signer);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return this;
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
|
|
779
1454
|
// src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts
|
|
780
1455
|
var hydratedTransactionToPayloadBundle = /* @__PURE__ */ __name((transaction) => {
|
|
781
1456
|
const root = transaction[0]._hash;
|
|
782
1457
|
return bundle2(root, transaction);
|
|
783
1458
|
}, "hydratedTransactionToPayloadBundle");
|
|
784
1459
|
var bundle2 = /* @__PURE__ */ __name((root, transaction) => {
|
|
785
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap((p) =>
|
|
786
|
-
return new
|
|
1460
|
+
const payloads = flattenHydratedTransaction(transaction).flatMap((p) => PayloadBuilder10.omitStorageMeta(p));
|
|
1461
|
+
return new PayloadBuilder10({
|
|
787
1462
|
schema: PayloadBundleSchema2
|
|
788
1463
|
}).fields({
|
|
789
1464
|
payloads,
|
|
@@ -792,10 +1467,10 @@ var bundle2 = /* @__PURE__ */ __name((root, transaction) => {
|
|
|
792
1467
|
}, "bundle");
|
|
793
1468
|
|
|
794
1469
|
// src/model/Provider.ts
|
|
795
|
-
import { assertEx as
|
|
1470
|
+
import { assertEx as assertEx15, isString } from "@xylabs/sdk-js";
|
|
796
1471
|
var asProviderMoniker = /* @__PURE__ */ __name((value) => {
|
|
797
1472
|
const moniker = isString(value) ? value : void 0;
|
|
798
|
-
return
|
|
1473
|
+
return assertEx15(moniker);
|
|
799
1474
|
}, "asProviderMoniker");
|
|
800
1475
|
var DefaultProviderMoniker = "Provider";
|
|
801
1476
|
|
|
@@ -817,7 +1492,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
817
1492
|
return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
|
|
818
1493
|
const [headHash] = await context.head();
|
|
819
1494
|
const result = await context.store.chainMap.get(headHash);
|
|
820
|
-
if (!
|
|
1495
|
+
if (!isDefined10(result)) {
|
|
821
1496
|
throw new Error(`Head block not found for hash: ${headHash}`);
|
|
822
1497
|
}
|
|
823
1498
|
let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(result, () => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`);
|
|
@@ -827,7 +1502,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
827
1502
|
while (currentBlock.block > blockNumber) {
|
|
828
1503
|
let jumpHash = currentBlock.previous;
|
|
829
1504
|
let jumpBlockNumber = currentBlock.block - 1;
|
|
830
|
-
for (const [step, stepSize2] of
|
|
1505
|
+
for (const [step, stepSize2] of StepSizes6.entries()) {
|
|
831
1506
|
const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize2 - 1;
|
|
832
1507
|
if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
|
|
833
1508
|
jumpBlockNumber = possibleJumpBlockNumber;
|
|
@@ -835,7 +1510,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
835
1510
|
}
|
|
836
1511
|
}
|
|
837
1512
|
const newBlock = await context.store.chainMap.get(asHash3(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`));
|
|
838
|
-
if (!
|
|
1513
|
+
if (!isDefined10(newBlock)) {
|
|
839
1514
|
throw new Error(`Block not found for jump hash: ${jumpHash}`);
|
|
840
1515
|
}
|
|
841
1516
|
currentBlock = asSignedBlockBoundWitnessWithStorageMeta(newBlock, () => {
|
|
@@ -855,7 +1530,7 @@ async function blockFromBlockNumber(context, blockNumber) {
|
|
|
855
1530
|
__name(blockFromBlockNumber, "blockFromBlockNumber");
|
|
856
1531
|
|
|
857
1532
|
// src/block/primitives/frames/calculateFramesFromRange.ts
|
|
858
|
-
import { asXL1BlockNumber, stepSize } from "@xyo-network/xl1-protocol";
|
|
1533
|
+
import { asXL1BlockNumber as asXL1BlockNumber4, stepSize } from "@xyo-network/xl1-protocol";
|
|
859
1534
|
function calculateFramesFromRange(range, step) {
|
|
860
1535
|
const size = stepSize(step);
|
|
861
1536
|
let start = Math.trunc(range[0] / size) * size;
|
|
@@ -865,22 +1540,22 @@ function calculateFramesFromRange(range, step) {
|
|
|
865
1540
|
start += size;
|
|
866
1541
|
remaining.push([
|
|
867
1542
|
range[0],
|
|
868
|
-
|
|
1543
|
+
asXL1BlockNumber4(Math.min(start - 1, range[1]), true)
|
|
869
1544
|
]);
|
|
870
1545
|
}
|
|
871
1546
|
for (let i = start; i <= range[1]; i += size) {
|
|
872
1547
|
if (i + size - 1 <= range[1]) {
|
|
873
1548
|
fitted.push([
|
|
874
|
-
|
|
1549
|
+
asXL1BlockNumber4(i, {
|
|
875
1550
|
name: "calculateFramesFromRange A"
|
|
876
1551
|
}),
|
|
877
|
-
|
|
1552
|
+
asXL1BlockNumber4(Math.min(i + size - 1, range[1]), {
|
|
878
1553
|
name: "calculateFramesFromRange B"
|
|
879
1554
|
})
|
|
880
1555
|
]);
|
|
881
1556
|
} else {
|
|
882
1557
|
remaining.push([
|
|
883
|
-
|
|
1558
|
+
asXL1BlockNumber4(i, {
|
|
884
1559
|
name: "calculateFramesFromRange C"
|
|
885
1560
|
}),
|
|
886
1561
|
range[1]
|
|
@@ -895,8 +1570,8 @@ function calculateFramesFromRange(range, step) {
|
|
|
895
1570
|
__name(calculateFramesFromRange, "calculateFramesFromRange");
|
|
896
1571
|
|
|
897
1572
|
// src/block/primitives/frames/deepCalculateFramesFromRange.ts
|
|
898
|
-
import { StepSizes as
|
|
899
|
-
function deepCalculateFramesFromRange(range, startingStep =
|
|
1573
|
+
import { StepSizes as StepSizes7 } from "@xyo-network/xl1-protocol";
|
|
1574
|
+
function deepCalculateFramesFromRange(range, startingStep = StepSizes7.length - 1) {
|
|
900
1575
|
const fitted = [];
|
|
901
1576
|
let remaining = [
|
|
902
1577
|
range
|
|
@@ -949,7 +1624,7 @@ function toStepIdentityString({ block, step }) {
|
|
|
949
1624
|
__name(toStepIdentityString, "toStepIdentityString");
|
|
950
1625
|
|
|
951
1626
|
// src/config/Bridge.ts
|
|
952
|
-
import { AddressZod, HexZod, toAddress as
|
|
1627
|
+
import { AddressZod, HexZod, toAddress as toAddress8, toHex as toHex4 } from "@xylabs/hex";
|
|
953
1628
|
import { AttoXL1ConvertFactor, XL1 } from "@xyo-network/xl1-protocol";
|
|
954
1629
|
import { globalRegistry } from "zod";
|
|
955
1630
|
import * as z3 from "zod";
|
|
@@ -1016,12 +1691,13 @@ var MnemonicStringZod = z2.string().transform((s) => s.trim().replaceAll(/\s+/g,
|
|
|
1016
1691
|
}).describe("BIP-39 mnemonic string");
|
|
1017
1692
|
|
|
1018
1693
|
// src/config/Bridge.ts
|
|
1019
|
-
var DEFAULT_FIXED_FEE =
|
|
1020
|
-
var
|
|
1021
|
-
var
|
|
1022
|
-
var
|
|
1023
|
-
var DEFAULT_HARDHAT_TOKEN_CONTRACT =
|
|
1024
|
-
var
|
|
1694
|
+
var DEFAULT_FIXED_FEE = toHex4(XL1(1n) * AttoXL1ConvertFactor.xl1);
|
|
1695
|
+
var DEFAULT_HARDHAT_BRIDGE_CONTRACT = toAddress8("2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6");
|
|
1696
|
+
var DEFAULT_HARDHAT_CHAIN_ID = toHex4("7A69");
|
|
1697
|
+
var DEFAULT_HARDHAT_REMOTE_CHAIN_WALLET_PRIVATE_KEY = toHex4("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80");
|
|
1698
|
+
var DEFAULT_HARDHAT_TOKEN_CONTRACT = toAddress8("5FbDB2315678afecb367f032d93F642f64180aa3");
|
|
1699
|
+
var DEFAULT_MAX_BRIDGE_AMOUNT = toHex4(XL1(100000n) * AttoXL1ConvertFactor.xl1);
|
|
1700
|
+
var DEFAULT_MIN_BRIDGE_AMOUNT = toHex4(XL1(10n) * AttoXL1ConvertFactor.xl1);
|
|
1025
1701
|
var BasisPointsZod = z3.coerce.number().int().nonnegative().max(1e4);
|
|
1026
1702
|
var BridgeConfigZod = z3.object({
|
|
1027
1703
|
chainRpcApiUrl: z3.string().default("http://localhost:8080/rpc").register(globalRegistry, {
|
|
@@ -1075,12 +1751,24 @@ var BridgeConfigZod = z3.object({
|
|
|
1075
1751
|
title: "bridge.mnemonic",
|
|
1076
1752
|
type: "string"
|
|
1077
1753
|
}),
|
|
1078
|
-
port: z3.coerce.number().default(8081).register(globalRegistry, {
|
|
1754
|
+
port: z3.coerce.number().int().positive().default(8081).register(globalRegistry, {
|
|
1079
1755
|
default: 8081,
|
|
1080
1756
|
description: "Port for the Bridge",
|
|
1081
1757
|
title: "bridge.port",
|
|
1082
1758
|
type: "number"
|
|
1083
1759
|
}),
|
|
1760
|
+
redisHost: z3.string().default("localhost").register(globalRegistry, {
|
|
1761
|
+
default: "localhost",
|
|
1762
|
+
description: "Host for the Bridge Redis instance",
|
|
1763
|
+
title: "bridge.redisHost",
|
|
1764
|
+
type: "string"
|
|
1765
|
+
}),
|
|
1766
|
+
redisPort: z3.coerce.number().int().positive().default(6379).register(globalRegistry, {
|
|
1767
|
+
default: 6379,
|
|
1768
|
+
description: "Port for the Bridge Redis instance",
|
|
1769
|
+
title: "bridge.redisPort",
|
|
1770
|
+
type: "number"
|
|
1771
|
+
}),
|
|
1084
1772
|
remoteBridgeContractAddress: AddressZod.default(DEFAULT_HARDHAT_BRIDGE_CONTRACT).register(globalRegistry, {
|
|
1085
1773
|
default: DEFAULT_HARDHAT_BRIDGE_CONTRACT,
|
|
1086
1774
|
description: "Hex representation of remote token address used for bridging",
|
|
@@ -1099,6 +1787,11 @@ var BridgeConfigZod = z3.object({
|
|
|
1099
1787
|
title: "bridge.remoteTokenAddress",
|
|
1100
1788
|
type: "string"
|
|
1101
1789
|
}),
|
|
1790
|
+
remoteChainWalletPrivateKey: HexZod.default(DEFAULT_HARDHAT_REMOTE_CHAIN_WALLET_PRIVATE_KEY).register(globalRegistry, {
|
|
1791
|
+
description: "Private key for the wallet to use for the remote chain wallet",
|
|
1792
|
+
title: "bridge.remoteChainWalletPrivateKey",
|
|
1793
|
+
type: "string"
|
|
1794
|
+
}),
|
|
1102
1795
|
xl1ChainId: HexZod.optional().register(globalRegistry, {
|
|
1103
1796
|
description: "XL1 chain id used for bridging",
|
|
1104
1797
|
title: "bridge.xl1ChainId",
|
|
@@ -1158,11 +1851,11 @@ var ApiConfigZod = z4.object({
|
|
|
1158
1851
|
});
|
|
1159
1852
|
|
|
1160
1853
|
// src/config/Chain.ts
|
|
1161
|
-
import { AddressZod as AddressZod2 } from "@xylabs/sdk-js";
|
|
1854
|
+
import { AddressZod as AddressZod2, HexZod as HexZod2 } from "@xylabs/sdk-js";
|
|
1162
1855
|
import { globalRegistry as globalRegistry3 } from "zod";
|
|
1163
1856
|
import * as z5 from "zod";
|
|
1164
1857
|
var ChainConfigZod = z5.object({
|
|
1165
|
-
id:
|
|
1858
|
+
id: HexZod2.optional().register(globalRegistry3, {
|
|
1166
1859
|
description: "The unique identifier for the chain. Should be the staking contract address for contract-backed chains.",
|
|
1167
1860
|
title: "chain.id",
|
|
1168
1861
|
type: "string"
|
|
@@ -1379,12 +2072,12 @@ var ServicesConfigZod = z11.object({
|
|
|
1379
2072
|
});
|
|
1380
2073
|
|
|
1381
2074
|
// src/config/storage/driver/Mongo.ts
|
|
1382
|
-
import { isDefined as
|
|
2075
|
+
import { isDefined as isDefined11, isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
1383
2076
|
import { globalRegistry as globalRegistry10 } from "zod";
|
|
1384
2077
|
import * as z12 from "zod";
|
|
1385
2078
|
var hasMongoConfig = /* @__PURE__ */ __name((config) => {
|
|
1386
|
-
if (
|
|
1387
|
-
return
|
|
2079
|
+
if (isUndefined3(config)) return false;
|
|
2080
|
+
return isDefined11(config.connectionString) && isDefined11(config.database) && isDefined11(config.domain) && isDefined11(config.password) && isDefined11(config.username);
|
|
1388
2081
|
}, "hasMongoConfig");
|
|
1389
2082
|
var MongoConfigZod = z12.object({
|
|
1390
2083
|
// TODO: Create from other arguments
|
|
@@ -1546,15 +2239,11 @@ function isUsageMeta(v) {
|
|
|
1546
2239
|
}
|
|
1547
2240
|
__name(isUsageMeta, "isUsageMeta");
|
|
1548
2241
|
|
|
1549
|
-
// src/constants.ts
|
|
1550
|
-
var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_EPOCH = 1760572800;
|
|
1551
|
-
var XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK = 107496;
|
|
1552
|
-
|
|
1553
2242
|
// src/CreatableProvider/AbstractCreatableProvider.ts
|
|
1554
|
-
import { AbstractCreatable } from "@xylabs/sdk-js";
|
|
2243
|
+
import { AbstractCreatable, assertEx as assertEx17 } from "@xylabs/sdk-js";
|
|
1555
2244
|
|
|
1556
2245
|
// src/CreatableProvider/ProviderFactory.ts
|
|
1557
|
-
import { assertEx as
|
|
2246
|
+
import { assertEx as assertEx16 } from "@xylabs/sdk-js";
|
|
1558
2247
|
var ProviderFactory = class _ProviderFactory {
|
|
1559
2248
|
static {
|
|
1560
2249
|
__name(this, "ProviderFactory");
|
|
@@ -1564,30 +2253,79 @@ var ProviderFactory = class _ProviderFactory {
|
|
|
1564
2253
|
defaultParams;
|
|
1565
2254
|
labels;
|
|
1566
2255
|
monikers;
|
|
1567
|
-
|
|
2256
|
+
scope;
|
|
2257
|
+
constructor(creatableProvider2, params, labels = {}, scope = "context") {
|
|
1568
2258
|
this.creatableProvider = creatableProvider2;
|
|
1569
2259
|
this.defaultParams = params;
|
|
1570
2260
|
this.defaultMoniker = creatableProvider2.defaultMoniker;
|
|
1571
2261
|
this.monikers = creatableProvider2.monikers;
|
|
1572
|
-
|
|
2262
|
+
this.scope = scope;
|
|
2263
|
+
assertEx16(this.monikers.includes(this.defaultMoniker), () => "defaultMoniker must be in monikers");
|
|
1573
2264
|
this.labels = Object.assign({}, creatableProvider2.labels ?? {}, labels ?? {});
|
|
1574
2265
|
}
|
|
2266
|
+
get resolvedMoniker() {
|
|
2267
|
+
const labels = this.labels ?? {};
|
|
2268
|
+
const labelString = Object.entries(labels).map(([key, value]) => `${key}=${value}`).join(",");
|
|
2269
|
+
return labelString.length === 0 ? `${this.defaultMoniker}` : `${this.defaultMoniker}|${labelString}`;
|
|
2270
|
+
}
|
|
1575
2271
|
static withParams(creatableProvider2, params, labels = {}) {
|
|
1576
2272
|
return new _ProviderFactory(creatableProvider2, params, labels);
|
|
1577
2273
|
}
|
|
1578
|
-
|
|
2274
|
+
/** @deprecated use getInstance instead */
|
|
2275
|
+
async create(params, start = true) {
|
|
2276
|
+
return await this.getInstance(params, start);
|
|
2277
|
+
}
|
|
2278
|
+
factory(params, labels = {}) {
|
|
2279
|
+
return new _ProviderFactory(this.creatableProvider, params, labels);
|
|
2280
|
+
}
|
|
2281
|
+
async getInstance(params, start = true) {
|
|
2282
|
+
let scopeObject = {};
|
|
2283
|
+
switch (this.scope) {
|
|
2284
|
+
case "global": {
|
|
2285
|
+
if (globalThis.xyoServiceSingletons === void 0) {
|
|
2286
|
+
globalThis.xyoServiceSingletons = {};
|
|
2287
|
+
}
|
|
2288
|
+
scopeObject = globalThis.xyoServiceSingletons;
|
|
2289
|
+
break;
|
|
2290
|
+
}
|
|
2291
|
+
case "context": {
|
|
2292
|
+
const context = assertEx16(params?.context, () => "Context is required for context-scoped providers");
|
|
2293
|
+
if (context.singletons === void 0) {
|
|
2294
|
+
context.singletons = {};
|
|
2295
|
+
}
|
|
2296
|
+
scopeObject = context.singletons;
|
|
2297
|
+
break;
|
|
2298
|
+
}
|
|
2299
|
+
default: {
|
|
2300
|
+
scopeObject = {};
|
|
2301
|
+
break;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
1579
2304
|
const mergedParams = {
|
|
1580
2305
|
...this.defaultParams,
|
|
1581
2306
|
...params,
|
|
1582
|
-
|
|
1583
|
-
...this.defaultParams?.
|
|
1584
|
-
...params?.
|
|
2307
|
+
context: {
|
|
2308
|
+
...this.defaultParams?.context,
|
|
2309
|
+
...params?.context,
|
|
2310
|
+
config: {
|
|
2311
|
+
...this.defaultParams?.context?.config,
|
|
2312
|
+
...params?.context?.config
|
|
2313
|
+
}
|
|
1585
2314
|
}
|
|
1586
2315
|
};
|
|
1587
|
-
|
|
2316
|
+
const result = await this.creatableProvider.create(mergedParams);
|
|
2317
|
+
if (start) {
|
|
2318
|
+
assertEx16(await result.start(), () => "Failed to start provider instance");
|
|
2319
|
+
}
|
|
2320
|
+
scopeObject[this.resolvedMoniker] = result;
|
|
2321
|
+
return result;
|
|
1588
2322
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
2323
|
+
async tryGetInstance(params, start = true) {
|
|
2324
|
+
try {
|
|
2325
|
+
return await this.getInstance(params, start);
|
|
2326
|
+
} catch {
|
|
2327
|
+
return;
|
|
2328
|
+
}
|
|
1591
2329
|
}
|
|
1592
2330
|
};
|
|
1593
2331
|
|
|
@@ -1596,8 +2334,33 @@ var AbstractCreatableProvider = class extends AbstractCreatable {
|
|
|
1596
2334
|
static {
|
|
1597
2335
|
__name(this, "AbstractCreatableProvider");
|
|
1598
2336
|
}
|
|
2337
|
+
_contextCache;
|
|
2338
|
+
get config() {
|
|
2339
|
+
return assertEx17(this.context.config, () => "config is required");
|
|
2340
|
+
}
|
|
2341
|
+
get context() {
|
|
2342
|
+
return assertEx17(this.params.context, () => "context is required");
|
|
2343
|
+
}
|
|
2344
|
+
get locator() {
|
|
2345
|
+
return assertEx17(this.context.locator, () => "locator is required");
|
|
2346
|
+
}
|
|
1599
2347
|
static factory(params) {
|
|
1600
|
-
|
|
2348
|
+
const factory = ProviderFactory.withParams(this, params);
|
|
2349
|
+
return factory;
|
|
2350
|
+
}
|
|
2351
|
+
static async getInstance(inParams) {
|
|
2352
|
+
const instance = await this.create(inParams);
|
|
2353
|
+
return instance;
|
|
2354
|
+
}
|
|
2355
|
+
static async tryGetInstance(inParams) {
|
|
2356
|
+
try {
|
|
2357
|
+
return await this.create(inParams);
|
|
2358
|
+
} catch {
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
async locateAndCreate(moniker) {
|
|
2363
|
+
return await this.locator?.getInstance(moniker);
|
|
1601
2364
|
}
|
|
1602
2365
|
};
|
|
1603
2366
|
|
|
@@ -1619,8 +2382,6 @@ __name(labeledCreatableProvider, "labeledCreatableProvider");
|
|
|
1619
2382
|
import { isTruthy } from "@xylabs/sdk-js";
|
|
1620
2383
|
var buildProviderFactory = /* @__PURE__ */ __name((provider, labels) => {
|
|
1621
2384
|
const factory = {
|
|
1622
|
-
// Destructure instance properties
|
|
1623
|
-
...provider,
|
|
1624
2385
|
monikers: provider.monikers,
|
|
1625
2386
|
// Copy static methods
|
|
1626
2387
|
create: provider.create.bind(provider),
|
|
@@ -1628,7 +2389,14 @@ var buildProviderFactory = /* @__PURE__ */ __name((provider, labels) => {
|
|
|
1628
2389
|
labels: {
|
|
1629
2390
|
...provider.labels,
|
|
1630
2391
|
...labels
|
|
1631
|
-
}
|
|
2392
|
+
},
|
|
2393
|
+
creatableProvider: provider.creatableProvider,
|
|
2394
|
+
resolvedMoniker: provider.resolvedMoniker,
|
|
2395
|
+
scope: provider.scope,
|
|
2396
|
+
getInstance: provider.getInstance.bind(provider),
|
|
2397
|
+
tryGetInstance: provider.tryGetInstance?.bind(provider),
|
|
2398
|
+
defaultMoniker: provider.defaultMoniker,
|
|
2399
|
+
factory: provider.factory.bind(provider)
|
|
1632
2400
|
};
|
|
1633
2401
|
return factory;
|
|
1634
2402
|
}, "buildProviderFactory");
|
|
@@ -1692,15 +2460,23 @@ __name(labeledCreatableProviderFactory, "labeledCreatableProviderFactory");
|
|
|
1692
2460
|
|
|
1693
2461
|
// src/CreatableProvider/ProviderFactoryLocator.ts
|
|
1694
2462
|
import { hasAllLabels } from "@xylabs/sdk-js";
|
|
1695
|
-
import { assertEx as
|
|
2463
|
+
import { assertEx as assertEx18 } from "@xylabs/sdk-js";
|
|
1696
2464
|
var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
1697
2465
|
static {
|
|
1698
2466
|
__name(this, "ProviderFactoryLocator");
|
|
1699
2467
|
}
|
|
2468
|
+
_context;
|
|
1700
2469
|
_registry;
|
|
1701
2470
|
_frozen = false;
|
|
1702
|
-
constructor(registry = {}) {
|
|
2471
|
+
constructor(context, registry = {}) {
|
|
1703
2472
|
this._registry = registry;
|
|
2473
|
+
this._context = {
|
|
2474
|
+
...context,
|
|
2475
|
+
locator: this
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
get context() {
|
|
2479
|
+
return this._context;
|
|
1704
2480
|
}
|
|
1705
2481
|
/**
|
|
1706
2482
|
* The current registry for the module factory
|
|
@@ -1708,23 +2484,38 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
1708
2484
|
get registry() {
|
|
1709
2485
|
return this._registry;
|
|
1710
2486
|
}
|
|
1711
|
-
static empty() {
|
|
1712
|
-
return new _ProviderFactoryLocator({});
|
|
2487
|
+
static empty(context) {
|
|
2488
|
+
return new _ProviderFactoryLocator(context, {});
|
|
1713
2489
|
}
|
|
1714
|
-
static standard() {
|
|
1715
|
-
return new _ProviderFactoryLocator({});
|
|
2490
|
+
static standard(context) {
|
|
2491
|
+
return new _ProviderFactoryLocator(context, {});
|
|
2492
|
+
}
|
|
2493
|
+
/** @deprecated use getInstance instead */
|
|
2494
|
+
async create(moniker, params, labels) {
|
|
2495
|
+
return await this.getInstance(moniker, params, labels);
|
|
1716
2496
|
}
|
|
1717
2497
|
freeze() {
|
|
1718
2498
|
this._frozen = true;
|
|
1719
2499
|
}
|
|
2500
|
+
async getInstance(moniker, params, labels) {
|
|
2501
|
+
const resolvedParams = {
|
|
2502
|
+
...params,
|
|
2503
|
+
context: {
|
|
2504
|
+
...this.context,
|
|
2505
|
+
...params?.context
|
|
2506
|
+
}
|
|
2507
|
+
};
|
|
2508
|
+
const factory = this.locate(moniker, labels);
|
|
2509
|
+
return await factory.getInstance(resolvedParams);
|
|
2510
|
+
}
|
|
1720
2511
|
/**
|
|
1721
|
-
* Locates a provider factory that matches the supplied
|
|
1722
|
-
* @param
|
|
2512
|
+
* Locates a provider factory that matches the supplied moniker and labels
|
|
2513
|
+
* @param moniker The config moniker for the provider
|
|
1723
2514
|
* @param labels The labels for the provider factory
|
|
1724
|
-
* @returns A provider factory that matches the supplied
|
|
2515
|
+
* @returns A provider factory that matches the supplied moniker and labels or throws if one is not found
|
|
1725
2516
|
*/
|
|
1726
2517
|
locate(moniker, labels) {
|
|
1727
|
-
return
|
|
2518
|
+
return assertEx18(this.tryLocate(moniker, labels), () => `No module factory for the supplied config moniker [${moniker}]${labels ? ` & labels [${JSON.stringify(labels)}]` : ""} registered`);
|
|
1728
2519
|
}
|
|
1729
2520
|
merge(locator) {
|
|
1730
2521
|
const registry = {
|
|
@@ -1737,7 +2528,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
1737
2528
|
registry[moniker] = locator.registry[moniker];
|
|
1738
2529
|
}
|
|
1739
2530
|
}
|
|
1740
|
-
return new _ProviderFactoryLocator(registry);
|
|
2531
|
+
return new _ProviderFactoryLocator(this.context, registry);
|
|
1741
2532
|
}
|
|
1742
2533
|
/**
|
|
1743
2534
|
* Registers a single module factory (with optional tags) with the locator
|
|
@@ -1745,7 +2536,7 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
1745
2536
|
* @param labels The labels for the module factory
|
|
1746
2537
|
*/
|
|
1747
2538
|
register(factory, labels, primary = false) {
|
|
1748
|
-
|
|
2539
|
+
assertEx18(!this._frozen, () => "Cannot register a module factory after the locator has been frozen");
|
|
1749
2540
|
registerCreatableProviderFactory(this._registry, factory, labels, primary);
|
|
1750
2541
|
return this;
|
|
1751
2542
|
}
|
|
@@ -1759,19 +2550,53 @@ var ProviderFactoryLocator = class _ProviderFactoryLocator {
|
|
|
1759
2550
|
}
|
|
1760
2551
|
return this;
|
|
1761
2552
|
}
|
|
2553
|
+
async tryGetInstance(moniker, params, labels) {
|
|
2554
|
+
try {
|
|
2555
|
+
return await this.getInstance(moniker, params, labels);
|
|
2556
|
+
} catch {
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
1762
2560
|
/**
|
|
1763
|
-
* Tries to locate a module factory that matches the supplied
|
|
1764
|
-
* @param
|
|
2561
|
+
* Tries to locate a module factory that matches the supplied moniker and labels
|
|
2562
|
+
* @param moniker The config moniker for the module
|
|
1765
2563
|
* @param labels The labels for the module factory
|
|
1766
|
-
* @returns A module factory that matches the supplied
|
|
2564
|
+
* @returns A module factory that matches the supplied moniker and labels or undefined
|
|
1767
2565
|
*/
|
|
1768
2566
|
tryLocate(moniker, labels) {
|
|
1769
|
-
|
|
2567
|
+
const result = labels ? this._registry[moniker]?.filter(hasLabels).find((factory) => hasAllLabels(factory?.labels, labels)) ?? this._registry[moniker]?.[0] : this._registry[moniker]?.[0];
|
|
2568
|
+
if (result) {
|
|
2569
|
+
result.defaultParams = {
|
|
2570
|
+
...result?.defaultParams,
|
|
2571
|
+
context: {
|
|
2572
|
+
...this.context,
|
|
2573
|
+
...result?.defaultParams?.context
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
}
|
|
2577
|
+
return result;
|
|
1770
2578
|
}
|
|
1771
2579
|
};
|
|
1772
2580
|
|
|
2581
|
+
// src/createDeclarationPayload.ts
|
|
2582
|
+
import { isDefined as isDefined12 } from "@xylabs/sdk-js";
|
|
2583
|
+
import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/payload-builder";
|
|
2584
|
+
import { ChainStakeIntentSchema } from "@xyo-network/xl1-protocol";
|
|
2585
|
+
var createDeclarationIntent = /* @__PURE__ */ __name((address, intent, nbf, exp) => {
|
|
2586
|
+
const expiration = isDefined12(exp) ? exp : nbf + 1e4;
|
|
2587
|
+
const redeclarationIntent = new PayloadBuilder11({
|
|
2588
|
+
schema: ChainStakeIntentSchema
|
|
2589
|
+
}).fields({
|
|
2590
|
+
from: address,
|
|
2591
|
+
intent,
|
|
2592
|
+
nbf,
|
|
2593
|
+
exp: expiration
|
|
2594
|
+
}).build();
|
|
2595
|
+
return redeclarationIntent;
|
|
2596
|
+
}, "createDeclarationIntent");
|
|
2597
|
+
|
|
1773
2598
|
// src/eip-712/Payloads/EIP712Data.ts
|
|
1774
|
-
import { AsObjectFactory } from "@xylabs/sdk-js";
|
|
2599
|
+
import { AsObjectFactory as AsObjectFactory2 } from "@xylabs/sdk-js";
|
|
1775
2600
|
import { isPayloadOfZodType } from "@xyo-network/payload-model";
|
|
1776
2601
|
import z19 from "zod";
|
|
1777
2602
|
|
|
@@ -1806,10 +2631,10 @@ var EIP712DataPayloadFieldsZod = z19.object({
|
|
|
1806
2631
|
});
|
|
1807
2632
|
var EIP712DataPayloadSchema = "network.xyo.chains.ethereum.eip712.data";
|
|
1808
2633
|
var isEIP712DataPayload = isPayloadOfZodType(EIP712DataPayloadFieldsZod, EIP712DataPayloadSchema);
|
|
1809
|
-
var asEIP712DataPayload =
|
|
2634
|
+
var asEIP712DataPayload = AsObjectFactory2.create(isEIP712DataPayload);
|
|
1810
2635
|
|
|
1811
2636
|
// src/eip-712/Payloads/EIP712Signature.ts
|
|
1812
|
-
import { AsObjectFactory as
|
|
2637
|
+
import { AsObjectFactory as AsObjectFactory3, HashZod as HashZod2 } from "@xylabs/sdk-js";
|
|
1813
2638
|
import { isPayloadOfZodType as isPayloadOfZodType2 } from "@xyo-network/payload-model";
|
|
1814
2639
|
import z20 from "zod";
|
|
1815
2640
|
var EIP712SignaturePayloadFieldsZod = z20.object({
|
|
@@ -1819,14 +2644,14 @@ var EIP712SignaturePayloadFieldsZod = z20.object({
|
|
|
1819
2644
|
});
|
|
1820
2645
|
var EIP712SignaturePayloadSchema = "network.xyo.chains.ethereum.eip712.signature";
|
|
1821
2646
|
var isEIP712SignaturePayload = isPayloadOfZodType2(EIP712SignaturePayloadFieldsZod, EIP712SignaturePayloadSchema);
|
|
1822
|
-
var asEIP712SignaturePayload =
|
|
2647
|
+
var asEIP712SignaturePayload = AsObjectFactory3.create(isEIP712SignaturePayload);
|
|
1823
2648
|
|
|
1824
2649
|
// src/eip-712/sign.ts
|
|
1825
|
-
import { PayloadBuilder as
|
|
2650
|
+
import { PayloadBuilder as PayloadBuilder12 } from "@xyo-network/payload-builder";
|
|
1826
2651
|
var signEIP712Message = /* @__PURE__ */ __name(async (signer, data) => {
|
|
1827
2652
|
const { domain, types, values } = data;
|
|
1828
2653
|
const signature = await signer.signTypedData(domain, types, values);
|
|
1829
|
-
const hash = await
|
|
2654
|
+
const hash = await PayloadBuilder12.hash(data);
|
|
1830
2655
|
const address = await signer.getAddress();
|
|
1831
2656
|
return {
|
|
1832
2657
|
address,
|
|
@@ -1837,22 +2662,22 @@ var signEIP712Message = /* @__PURE__ */ __name(async (signer, data) => {
|
|
|
1837
2662
|
}, "signEIP712Message");
|
|
1838
2663
|
|
|
1839
2664
|
// src/eip-712/verify.ts
|
|
1840
|
-
import { asHash as asHash4, isUndefined as
|
|
1841
|
-
import { PayloadBuilder as
|
|
2665
|
+
import { asHash as asHash4, isUndefined as isUndefined4 } from "@xylabs/sdk-js";
|
|
2666
|
+
import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/payload-builder";
|
|
1842
2667
|
import { verifyTypedData } from "ethers/hash";
|
|
1843
2668
|
var verifyEIP712Message = /* @__PURE__ */ __name(async (data, sig) => {
|
|
1844
2669
|
const { address, signature, hash } = sig;
|
|
1845
2670
|
const { schema, ...fields } = data;
|
|
1846
2671
|
const signedHash = asHash4(hash);
|
|
1847
|
-
if (
|
|
2672
|
+
if (isUndefined4(signedHash) || signedHash !== await PayloadBuilder13.hash(data)) return false;
|
|
1848
2673
|
const recoveredAddress = verifyTypedData(fields.domain, fields.types, fields.values, signature);
|
|
1849
2674
|
return recoveredAddress.toLowerCase() === address.toLowerCase();
|
|
1850
2675
|
}, "verifyEIP712Message");
|
|
1851
2676
|
|
|
1852
2677
|
// src/multipliers.ts
|
|
1853
|
-
import { asAttoXL1 as
|
|
1854
|
-
var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS =
|
|
1855
|
-
var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS =
|
|
2678
|
+
import { asAttoXL1 as asAttoXL14 } from "@xyo-network/xl1-protocol";
|
|
2679
|
+
var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS = asAttoXL14(1343884111859145740576652n);
|
|
2680
|
+
var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS = asAttoXL14(100000000000000000000000000n);
|
|
1856
2681
|
var XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS = XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS + XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS;
|
|
1857
2682
|
var RewardMultipliers = {
|
|
1858
2683
|
[`0|${XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK}`]: [
|
|
@@ -1861,77 +2686,6 @@ var RewardMultipliers = {
|
|
|
1861
2686
|
]
|
|
1862
2687
|
};
|
|
1863
2688
|
|
|
1864
|
-
// src/payloads/AddressPairPayload.ts
|
|
1865
|
-
import { AsObjectFactory as AsObjectFactory3 } from "@xylabs/sdk-js";
|
|
1866
|
-
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
1867
|
-
var AddressPairSchema = "network.xyo.address.pair";
|
|
1868
|
-
var isAddressPairPayload = isPayloadOfSchemaType(AddressPairSchema);
|
|
1869
|
-
var asAddressPairPayload = AsObjectFactory3.create(isAddressPairPayload);
|
|
1870
|
-
var asOptionalAddressPairPayload = AsObjectFactory3.createOptional(isAddressPairPayload);
|
|
1871
|
-
|
|
1872
|
-
// src/payloads/netBalancesForPayloads.ts
|
|
1873
|
-
import { hexToBigInt, toAddress as toAddress4 } from "@xylabs/sdk-js";
|
|
1874
|
-
import { span } from "@xylabs/sdk-js";
|
|
1875
|
-
import { isTransfer } from "@xyo-network/xl1-protocol";
|
|
1876
|
-
var netBalancesForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
1877
|
-
return span("netBalancesForPayloads", () => {
|
|
1878
|
-
const balances = {};
|
|
1879
|
-
for (const payload of payloads) {
|
|
1880
|
-
if (isTransfer(payload)) {
|
|
1881
|
-
const { from } = payload;
|
|
1882
|
-
for (let [address, amount] of Object.entries(payload.transfers)) {
|
|
1883
|
-
balances[toAddress4(address)] = (balances[toAddress4(address)] ?? 0n) + hexToBigInt(amount);
|
|
1884
|
-
balances[toAddress4(from)] = (balances[toAddress4(from)] ?? 0n) - hexToBigInt(amount);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
return balances;
|
|
1889
|
-
});
|
|
1890
|
-
}, "netBalancesForPayloads");
|
|
1891
|
-
|
|
1892
|
-
// src/payloads/netSchemasForPayloads.ts
|
|
1893
|
-
import { hexToBigInt as hexToBigInt2, toAddress as toAddress5 } from "@xylabs/sdk-js";
|
|
1894
|
-
import { span as span2 } from "@xylabs/sdk-js";
|
|
1895
|
-
import { isTransfer as isTransfer2 } from "@xyo-network/xl1-protocol";
|
|
1896
|
-
var netSchemasForPayloads = /* @__PURE__ */ __name((payloads) => {
|
|
1897
|
-
return span2("netSchemasForPayloads", () => {
|
|
1898
|
-
const balances = {};
|
|
1899
|
-
for (const payload of payloads) {
|
|
1900
|
-
if (isTransfer2(payload)) {
|
|
1901
|
-
const { from } = payload;
|
|
1902
|
-
for (let [address, amount] of Object.entries(payload.transfers)) {
|
|
1903
|
-
balances[toAddress5(address)] = (balances[toAddress5(address)] ?? 0n) + hexToBigInt2(amount);
|
|
1904
|
-
balances[toAddress5(from)] = (balances[toAddress5(from)] ?? 0n) - hexToBigInt2(amount);
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
return balances;
|
|
1909
|
-
});
|
|
1910
|
-
}, "netSchemasForPayloads");
|
|
1911
|
-
|
|
1912
|
-
// src/payloads/netTransfersForPayloads.ts
|
|
1913
|
-
import { hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
|
|
1914
|
-
import { span as span3 } from "@xylabs/sdk-js";
|
|
1915
|
-
import { isTransfer as isTransfer3 } from "@xyo-network/xl1-protocol";
|
|
1916
|
-
function netTransfersForPayloads(payloads) {
|
|
1917
|
-
return span3("netTransfersForPayloads", () => {
|
|
1918
|
-
const transfers = {};
|
|
1919
|
-
for (const payload of payloads) {
|
|
1920
|
-
if (isTransfer3(payload)) {
|
|
1921
|
-
const { from } = payload;
|
|
1922
|
-
transfers[from] = transfers[from] ?? {};
|
|
1923
|
-
for (let [to, amount] of Object.entries(payload.transfers)) {
|
|
1924
|
-
transfers[to] = transfers[to] ?? {};
|
|
1925
|
-
transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt3(amount);
|
|
1926
|
-
transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt3(amount);
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
return transfers;
|
|
1931
|
-
});
|
|
1932
|
-
}
|
|
1933
|
-
__name(netTransfersForPayloads, "netTransfersForPayloads");
|
|
1934
|
-
|
|
1935
2689
|
// src/provider/DataLake.ts
|
|
1936
2690
|
var DataLakeViewerMoniker = "DataLakeViewer";
|
|
1937
2691
|
var DataLakeRunnerMoniker = "DataLakeRunner";
|
|
@@ -1957,6 +2711,18 @@ var NetworkStakeStepRewardsViewerMoniker = "NetworkStakeStepRewardsViewer";
|
|
|
1957
2711
|
// src/provider/viewer/XyoViewer.ts
|
|
1958
2712
|
var XyoViewerMoniker = "XyoViewer";
|
|
1959
2713
|
|
|
2714
|
+
// src/provider/XyoConnection.ts
|
|
2715
|
+
var XyoConnectionMoniker = "XyoConnection";
|
|
2716
|
+
|
|
2717
|
+
// src/provider/XyoRunner.ts
|
|
2718
|
+
var XyoRunnerMoniker = "XyoRunner";
|
|
2719
|
+
|
|
2720
|
+
// src/runners/Block.ts
|
|
2721
|
+
var BlockRunnerMoniker = "BlockRunner";
|
|
2722
|
+
|
|
2723
|
+
// src/runners/Mempool.ts
|
|
2724
|
+
var MempoolRunnerMoniker = "MempoolRunner";
|
|
2725
|
+
|
|
1960
2726
|
// src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts
|
|
1961
2727
|
import { AsObjectFactory as AsObjectFactory4 } from "@xylabs/sdk-js";
|
|
1962
2728
|
import { isPayloadOfSchemaType as isPayloadOfSchemaType2, isStorageMeta } from "@xyo-network/payload-model";
|
|
@@ -1969,7 +2735,7 @@ var isChainIndexingServiceStateWithStorageMeta = /* @__PURE__ */ __name((value)
|
|
|
1969
2735
|
var asChainIndexingServiceStateWithStorageMeta = AsObjectFactory4.create(isChainIndexingServiceStateWithStorageMeta);
|
|
1970
2736
|
|
|
1971
2737
|
// src/SignedBigInt.ts
|
|
1972
|
-
import { hexToBigInt as
|
|
2738
|
+
import { hexToBigInt as hexToBigInt5, toHex as toHex5 } from "@xylabs/sdk-js";
|
|
1973
2739
|
import { isObject } from "@xylabs/sdk-js";
|
|
1974
2740
|
var isNegativeBigInt = /* @__PURE__ */ __name((value) => {
|
|
1975
2741
|
return isObject(value) && "negative" in value && typeof value.negative === "string";
|
|
@@ -1979,24 +2745,24 @@ var isPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
|
1979
2745
|
}, "isPositiveBigInt");
|
|
1980
2746
|
var parseSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
1981
2747
|
if (isNegativeBigInt(value)) {
|
|
1982
|
-
return -
|
|
2748
|
+
return -hexToBigInt5(value.negative);
|
|
1983
2749
|
} else if (isPositiveBigInt(value)) {
|
|
1984
|
-
return
|
|
2750
|
+
return hexToBigInt5(value.positive);
|
|
1985
2751
|
} else {
|
|
1986
2752
|
throw new Error("Invalid balance type");
|
|
1987
2753
|
}
|
|
1988
2754
|
}, "parseSignedBigInt");
|
|
1989
2755
|
var toSignedBigInt = /* @__PURE__ */ __name((value) => {
|
|
1990
2756
|
return value < 0n ? {
|
|
1991
|
-
negative:
|
|
2757
|
+
negative: toHex5(-value)
|
|
1992
2758
|
} : {
|
|
1993
|
-
positive:
|
|
2759
|
+
positive: toHex5(value)
|
|
1994
2760
|
};
|
|
1995
2761
|
}, "toSignedBigInt");
|
|
1996
2762
|
var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
1997
2763
|
if (isNegativeBigInt(value)) {
|
|
1998
2764
|
return {
|
|
1999
|
-
positive:
|
|
2765
|
+
positive: toHex5(0n)
|
|
2000
2766
|
};
|
|
2001
2767
|
}
|
|
2002
2768
|
if (isPositiveBigInt(value)) {
|
|
@@ -2006,15 +2772,15 @@ var toPositiveBigInt = /* @__PURE__ */ __name((value) => {
|
|
|
2006
2772
|
}
|
|
2007
2773
|
if (typeof value === "bigint") {
|
|
2008
2774
|
return {
|
|
2009
|
-
positive:
|
|
2775
|
+
positive: toHex5(value)
|
|
2010
2776
|
};
|
|
2011
2777
|
}
|
|
2012
2778
|
throw new Error("Invalid value for positive big int");
|
|
2013
2779
|
}, "toPositiveBigInt");
|
|
2014
2780
|
|
|
2015
2781
|
// src/simple/accountBalance/SimpleAccountBalanceViewer.ts
|
|
2016
|
-
import { asHash as asHash5, assertEx as
|
|
2017
|
-
import { asRange, asXL1BlockNumber as
|
|
2782
|
+
import { asHash as asHash5, assertEx as assertEx22, exists as exists2, isDefined as isDefined16, spanRootAsync as spanRootAsync4 } from "@xylabs/sdk-js";
|
|
2783
|
+
import { asRange, asXL1BlockNumber as asXL1BlockNumber8, asXL1BlockRange as asXL1BlockRange7, AttoXL1 as AttoXL12, StepSizes as StepSizes11, TransferSchema as TransferSchema2 } from "@xyo-network/xl1-protocol";
|
|
2018
2784
|
|
|
2019
2785
|
// src/summary/model/BalancesStepSummary.ts
|
|
2020
2786
|
import { AsObjectFactory as AsObjectFactory5 } from "@xylabs/sdk-js";
|
|
@@ -2053,10 +2819,10 @@ var isTransfersStepSummaryWithStorageMeta = /* @__PURE__ */ __name((value) => {
|
|
|
2053
2819
|
var asTransfersStepSummaryWithStorageMeta = AsObjectFactory7.create(isTransfersStepSummaryWithStorageMeta);
|
|
2054
2820
|
|
|
2055
2821
|
// src/summary/primitives/balances/balancesStepSummaryFromRange.ts
|
|
2056
|
-
import { assertEx as
|
|
2057
|
-
import { PayloadBuilder as
|
|
2822
|
+
import { assertEx as assertEx19 } from "@xylabs/sdk-js";
|
|
2823
|
+
import { PayloadBuilder as PayloadBuilder14 } from "@xyo-network/payload-builder";
|
|
2058
2824
|
import { isAnyPayload } from "@xyo-network/payload-model";
|
|
2059
|
-
import { StepSizes as
|
|
2825
|
+
import { StepSizes as StepSizes8 } from "@xyo-network/xl1-protocol";
|
|
2060
2826
|
async function balancesStepSummaryFromRange(context, range) {
|
|
2061
2827
|
const frameHeadHash = await hashFromBlockNumber(context, range[1]);
|
|
2062
2828
|
const frameSize = range[1] - range[0] + 1;
|
|
@@ -2076,8 +2842,8 @@ async function balancesStepSummaryFromRange(context, range) {
|
|
|
2076
2842
|
balances
|
|
2077
2843
|
};
|
|
2078
2844
|
} else {
|
|
2079
|
-
const step =
|
|
2080
|
-
|
|
2845
|
+
const step = StepSizes8.indexOf(frameSize);
|
|
2846
|
+
assertEx19(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes8.join(", ")}`);
|
|
2081
2847
|
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
2082
2848
|
if (isAnyPayload(summaryResult)) {
|
|
2083
2849
|
result = summaryResult;
|
|
@@ -2109,21 +2875,21 @@ async function balancesStepSummaryFromRange(context, range) {
|
|
|
2109
2875
|
}
|
|
2110
2876
|
}
|
|
2111
2877
|
}
|
|
2112
|
-
const finalResult = await
|
|
2878
|
+
const finalResult = await PayloadBuilder14.addStorageMeta(result);
|
|
2113
2879
|
return finalResult;
|
|
2114
2880
|
}
|
|
2115
2881
|
__name(balancesStepSummaryFromRange, "balancesStepSummaryFromRange");
|
|
2116
2882
|
|
|
2117
2883
|
// src/summary/primitives/balances/balancesSummary.ts
|
|
2118
|
-
import { asAddress as asAddress3, isDefined as
|
|
2119
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockNumber as
|
|
2884
|
+
import { asAddress as asAddress3, isDefined as isDefined13, spanRootAsync } from "@xylabs/sdk-js";
|
|
2885
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta2, asXL1BlockNumber as asXL1BlockNumber5, asXL1BlockRange as asXL1BlockRange4 } from "@xyo-network/xl1-protocol";
|
|
2120
2886
|
async function balancesSummary(context) {
|
|
2121
2887
|
return await spanRootAsync("balancesSummary", async () => {
|
|
2122
2888
|
const [headHash] = await context.head();
|
|
2123
2889
|
const headResult = await context.store.chainMap.get(headHash);
|
|
2124
2890
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta2(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
2125
|
-
const rangeStart =
|
|
2126
|
-
const ranges = deepCalculateFramesFromRange(
|
|
2891
|
+
const rangeStart = asXL1BlockNumber5(isDefined13(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0, true);
|
|
2892
|
+
const ranges = deepCalculateFramesFromRange(asXL1BlockRange4([
|
|
2127
2893
|
rangeStart,
|
|
2128
2894
|
headBoundWitness.block
|
|
2129
2895
|
], {
|
|
@@ -2150,11 +2916,11 @@ async function balancesSummary(context) {
|
|
|
2150
2916
|
__name(balancesSummary, "balancesSummary");
|
|
2151
2917
|
|
|
2152
2918
|
// src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
|
|
2153
|
-
import { assertEx as
|
|
2919
|
+
import { assertEx as assertEx20 } from "@xylabs/sdk-js";
|
|
2154
2920
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
2155
|
-
import { PayloadBuilder as
|
|
2921
|
+
import { PayloadBuilder as PayloadBuilder15 } from "@xyo-network/payload-builder";
|
|
2156
2922
|
import { isAnyPayload as isAnyPayload2, isHashMeta } from "@xyo-network/payload-model";
|
|
2157
|
-
import { StepSizes as
|
|
2923
|
+
import { StepSizes as StepSizes9 } from "@xyo-network/xl1-protocol";
|
|
2158
2924
|
async function schemasStepSummaryFromRange(context, range) {
|
|
2159
2925
|
const frameHeadHash = await hashFromBlockNumber(context, range[1]);
|
|
2160
2926
|
const frameSize = range[1] - range[0] + 1;
|
|
@@ -2181,8 +2947,8 @@ async function schemasStepSummaryFromRange(context, range) {
|
|
|
2181
2947
|
schemas
|
|
2182
2948
|
};
|
|
2183
2949
|
} else {
|
|
2184
|
-
const step =
|
|
2185
|
-
|
|
2950
|
+
const step = StepSizes9.indexOf(frameSize);
|
|
2951
|
+
assertEx20(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
|
|
2186
2952
|
const summaryResult = await context.summaryMap.get(`${frameHeadHash}|${frameSize}`);
|
|
2187
2953
|
if (isAnyPayload2(summaryResult)) {
|
|
2188
2954
|
result = summaryResult;
|
|
@@ -2210,20 +2976,20 @@ async function schemasStepSummaryFromRange(context, range) {
|
|
|
2210
2976
|
}
|
|
2211
2977
|
}
|
|
2212
2978
|
}
|
|
2213
|
-
return await
|
|
2979
|
+
return await PayloadBuilder15.addHashMeta(result);
|
|
2214
2980
|
}
|
|
2215
2981
|
__name(schemasStepSummaryFromRange, "schemasStepSummaryFromRange");
|
|
2216
2982
|
|
|
2217
2983
|
// src/summary/primitives/schemas/schemasSummary.ts
|
|
2218
|
-
import { isDefined as
|
|
2219
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockNumber as
|
|
2984
|
+
import { isDefined as isDefined14, spanRootAsync as spanRootAsync2 } from "@xylabs/sdk-js";
|
|
2985
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta3, asXL1BlockNumber as asXL1BlockNumber6, asXL1BlockRange as asXL1BlockRange5 } from "@xyo-network/xl1-protocol";
|
|
2220
2986
|
async function schemasSummary(context) {
|
|
2221
2987
|
return await spanRootAsync2("schemasSummary", async () => {
|
|
2222
2988
|
const [headHash] = await context.head();
|
|
2223
2989
|
const headResult = await context.store.chainMap.get(headHash);
|
|
2224
2990
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta3(headResult, () => `Head block not found for hash: ${headHash}`);
|
|
2225
|
-
const rangeStart =
|
|
2226
|
-
const ranges = deepCalculateFramesFromRange(
|
|
2991
|
+
const rangeStart = asXL1BlockNumber6(isDefined14(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0, true);
|
|
2992
|
+
const ranges = deepCalculateFramesFromRange(asXL1BlockRange5([
|
|
2227
2993
|
rangeStart,
|
|
2228
2994
|
headBoundWitness.block
|
|
2229
2995
|
], {
|
|
@@ -2249,21 +3015,21 @@ async function schemasSummary(context) {
|
|
|
2249
3015
|
__name(schemasSummary, "schemasSummary");
|
|
2250
3016
|
|
|
2251
3017
|
// src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
|
|
2252
|
-
import { assertEx as
|
|
2253
|
-
import { PayloadBuilder as
|
|
3018
|
+
import { assertEx as assertEx21 } from "@xylabs/sdk-js";
|
|
3019
|
+
import { PayloadBuilder as PayloadBuilder16 } from "@xyo-network/payload-builder";
|
|
2254
3020
|
import { isAnyPayload as isAnyPayload3 } from "@xyo-network/payload-model";
|
|
2255
|
-
import { StepSizes as
|
|
3021
|
+
import { StepSizes as StepSizes10 } from "@xyo-network/xl1-protocol";
|
|
2256
3022
|
|
|
2257
3023
|
// src/summary/primitives/transfers/transfersSummary.ts
|
|
2258
|
-
import { asAddress as asAddress4, isDefined as
|
|
2259
|
-
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockNumber as
|
|
3024
|
+
import { asAddress as asAddress4, isDefined as isDefined15, spanRootAsync as spanRootAsync3 } from "@xylabs/sdk-js";
|
|
3025
|
+
import { asBlockBoundWitnessWithStorageMeta as asBlockBoundWitnessWithStorageMeta4, asXL1BlockNumber as asXL1BlockNumber7, asXL1BlockRange as asXL1BlockRange6 } from "@xyo-network/xl1-protocol";
|
|
2260
3026
|
async function transfersSummary(transferContext) {
|
|
2261
3027
|
return await spanRootAsync3("transferSummary", async () => {
|
|
2262
3028
|
const [headHash] = await transferContext.head();
|
|
2263
3029
|
const headResult = await transferContext.store.chainMap.get(headHash);
|
|
2264
3030
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta4(headResult, () => `Head block not found for hash: ${transferContext.head}`);
|
|
2265
|
-
const rangeStart =
|
|
2266
|
-
const ranges = deepCalculateFramesFromRange(
|
|
3031
|
+
const rangeStart = asXL1BlockNumber7(isDefined15(transferContext.windowSize) ? Math.max(headBoundWitness.block - transferContext.windowSize + 1, 0) : 0, true);
|
|
3032
|
+
const ranges = deepCalculateFramesFromRange(asXL1BlockRange6([
|
|
2267
3033
|
rangeStart,
|
|
2268
3034
|
headBoundWitness.block
|
|
2269
3035
|
], {
|
|
@@ -2320,8 +3086,8 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
2320
3086
|
transfers
|
|
2321
3087
|
};
|
|
2322
3088
|
} else {
|
|
2323
|
-
const step =
|
|
2324
|
-
|
|
3089
|
+
const step = StepSizes10.indexOf(frameSize);
|
|
3090
|
+
assertEx21(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes10.join(", ")}`);
|
|
2325
3091
|
const key = transfersSummaryKey(frameHeadHash, frameSize);
|
|
2326
3092
|
const summaryResult = await context.summaryMap.get(key);
|
|
2327
3093
|
if (isAnyPayload3(summaryResult)) {
|
|
@@ -2360,7 +3126,7 @@ async function transfersStepSummaryFromRange(context, range) {
|
|
|
2360
3126
|
}
|
|
2361
3127
|
}
|
|
2362
3128
|
}
|
|
2363
|
-
const finalResult = await
|
|
3129
|
+
const finalResult = await PayloadBuilder16.addStorageMeta(result);
|
|
2364
3130
|
return finalResult;
|
|
2365
3131
|
}
|
|
2366
3132
|
__name(transfersStepSummaryFromRange, "transfersStepSummaryFromRange");
|
|
@@ -2383,9 +3149,6 @@ var BlockViewerMoniker = "BlockViewer";
|
|
|
2383
3149
|
// src/viewers/BlockReward.ts
|
|
2384
3150
|
var BlockRewardViewerMoniker = "BlockRewardViewer";
|
|
2385
3151
|
|
|
2386
|
-
// src/viewers/Chain.ts
|
|
2387
|
-
var ChainViewerMoniker = "ChainViewer";
|
|
2388
|
-
|
|
2389
3152
|
// src/viewers/ChainContract.ts
|
|
2390
3153
|
var ChainContractViewerMoniker = "ChainContractViewer";
|
|
2391
3154
|
|
|
@@ -2455,22 +3218,22 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2455
3218
|
AccountBalanceViewerMoniker
|
|
2456
3219
|
];
|
|
2457
3220
|
moniker = _SimpleAccountBalanceViewer.defaultMoniker;
|
|
2458
|
-
|
|
2459
|
-
|
|
3221
|
+
_blockViewer;
|
|
3222
|
+
get balanceSummaryContext() {
|
|
3223
|
+
return this.params.balanceSummaryContext;
|
|
2460
3224
|
}
|
|
2461
|
-
get
|
|
2462
|
-
return this.
|
|
3225
|
+
get blockViewer() {
|
|
3226
|
+
return this._blockViewer;
|
|
2463
3227
|
}
|
|
2464
3228
|
get transfersSummaryContext() {
|
|
2465
3229
|
return this.params.transfersSummaryContext;
|
|
2466
3230
|
}
|
|
2467
|
-
static async paramsHandler(params) {
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
};
|
|
3231
|
+
static async paramsHandler(params = {}) {
|
|
3232
|
+
assertEx22(params.transfersSummaryContext, () => "transfersSummaryContext is required");
|
|
3233
|
+
assertEx22(params.balanceSummaryContext, () => "balanceSummaryContext is required");
|
|
3234
|
+
return await super.paramsHandler({
|
|
3235
|
+
...params
|
|
3236
|
+
});
|
|
2474
3237
|
}
|
|
2475
3238
|
async accountBalance(address, headOrRange) {
|
|
2476
3239
|
const balances = await this.accountBalances([
|
|
@@ -2483,19 +3246,19 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2483
3246
|
}
|
|
2484
3247
|
async accountBalanceHistory(address, headOrRange) {
|
|
2485
3248
|
const range = asRange(headOrRange);
|
|
2486
|
-
const startingRange =
|
|
3249
|
+
const startingRange = asXL1BlockRange7(range ?? [
|
|
2487
3250
|
0,
|
|
2488
3251
|
await this.blockViewer.currentBlockNumber()
|
|
2489
3252
|
], true);
|
|
2490
3253
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
2491
|
-
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(
|
|
3254
|
+
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists2);
|
|
2492
3255
|
const result = [];
|
|
2493
3256
|
for (const block of blocks) {
|
|
2494
|
-
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema ===
|
|
3257
|
+
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists2);
|
|
2495
3258
|
const transfers = transferIndexes.map((index) => {
|
|
2496
3259
|
const hash = block[0].payload_hashes[index];
|
|
2497
|
-
return
|
|
2498
|
-
}).filter(
|
|
3260
|
+
return assertEx22(block[1].find((p) => p._hash === hash), () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`);
|
|
3261
|
+
}).filter(exists2).filter((t) => t.from === address || isDefined16(t.transfers[address]));
|
|
2499
3262
|
if (transfers.length === 0) {
|
|
2500
3263
|
continue;
|
|
2501
3264
|
}
|
|
@@ -2517,11 +3280,15 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2517
3280
|
const [result] = await this.qualifiedAccountBalances(address, _headOrRange);
|
|
2518
3281
|
return result;
|
|
2519
3282
|
}
|
|
3283
|
+
async createHandler() {
|
|
3284
|
+
await super.createHandler();
|
|
3285
|
+
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker);
|
|
3286
|
+
}
|
|
2520
3287
|
async qualifiedAccountBalanceHistories(addresses, headOrRange) {
|
|
2521
3288
|
const head = asHash5(headOrRange) ?? await this.blockViewer.currentBlockHash();
|
|
2522
|
-
const range =
|
|
3289
|
+
const range = asXL1BlockRange7(headOrRange) ?? asXL1BlockRange7([
|
|
2523
3290
|
0,
|
|
2524
|
-
|
|
3291
|
+
assertEx22(await this.blockViewer.blockByHash(head), () => `Error: Could not find block with hash ${head}`)[0].block
|
|
2525
3292
|
]);
|
|
2526
3293
|
const qualifiedEntries = await Promise.all(addresses.map(async (address) => [
|
|
2527
3294
|
address,
|
|
@@ -2536,8 +3303,8 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2536
3303
|
const qualifiedRange = qualifiedEntries[0][1][1];
|
|
2537
3304
|
const qualifiedHeadHash = qualifiedEntries[0][1][2];
|
|
2538
3305
|
for (const [_, [__, range2, headHash]] of qualifiedEntries) {
|
|
2539
|
-
|
|
2540
|
-
|
|
3306
|
+
assertEx22(range2[0] === qualifiedRange[0] && range2[1] === qualifiedRange[1], () => "Inconsistent ranges in qualifiedAccountBalanceHistories");
|
|
3307
|
+
assertEx22(headHash === qualifiedHeadHash, () => "Inconsistent head hashes in qualifiedAccountBalanceHistories");
|
|
2541
3308
|
}
|
|
2542
3309
|
return [
|
|
2543
3310
|
Object.fromEntries(entries),
|
|
@@ -2547,7 +3314,7 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2547
3314
|
}
|
|
2548
3315
|
async qualifiedAccountBalances(address, _headOrRange) {
|
|
2549
3316
|
return await spanRootAsync4("qualifiedAccountsBalances", async () => {
|
|
2550
|
-
const qualifiedSummary = await balancesSummary(this.
|
|
3317
|
+
const qualifiedSummary = await balancesSummary(this.balanceSummaryContext);
|
|
2551
3318
|
const result = {};
|
|
2552
3319
|
for (const addr of address) {
|
|
2553
3320
|
const summaryBalance = qualifiedSummary[0][addr] ?? 0n;
|
|
@@ -2561,12 +3328,12 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2561
3328
|
});
|
|
2562
3329
|
}
|
|
2563
3330
|
async distillTransferHistory(address, range, max = 50) {
|
|
2564
|
-
if (range[1] - range[0] <=
|
|
3331
|
+
if (range[1] - range[0] <= StepSizes11[0] || max <= 1) {
|
|
2565
3332
|
return Array.from({
|
|
2566
3333
|
length: range[1] - range[0] + 1
|
|
2567
|
-
}, (_, i) => range[1] - i).slice(0, max).map((n) =>
|
|
3334
|
+
}, (_, i) => range[1] - i).slice(0, max).map((n) => asXL1BlockNumber8(n, true));
|
|
2568
3335
|
}
|
|
2569
|
-
const frames = deepCalculateFramesFromRange(
|
|
3336
|
+
const frames = deepCalculateFramesFromRange(asXL1BlockRange7(range, true));
|
|
2570
3337
|
const transferSummaryPairs = await Promise.all(frames.map(async (frame) => {
|
|
2571
3338
|
return [
|
|
2572
3339
|
frame,
|
|
@@ -2579,8 +3346,8 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2579
3346
|
});
|
|
2580
3347
|
const resultBlockNumbers = /* @__PURE__ */ new Set();
|
|
2581
3348
|
for (const [frame] of sortedTransferSummaryPairs) {
|
|
2582
|
-
if (frame[1] - frame[0] + 1 >
|
|
2583
|
-
const values = await this.distillTransferHistory(address,
|
|
3349
|
+
if (frame[1] - frame[0] + 1 > StepSizes11[0]) {
|
|
3350
|
+
const values = await this.distillTransferHistory(address, asXL1BlockRange7([
|
|
2584
3351
|
frame[0],
|
|
2585
3352
|
frame[1] - 1
|
|
2586
3353
|
], true), max - resultBlockNumbers.size);
|
|
@@ -2604,20 +3371,20 @@ var SimpleAccountBalanceViewer = class _SimpleAccountBalanceViewer extends Abstr
|
|
|
2604
3371
|
async qualifiedAccountBalanceHistory(address, headOrRange) {
|
|
2605
3372
|
const range = asRange(headOrRange);
|
|
2606
3373
|
const headHash = asHash5(headOrRange);
|
|
2607
|
-
const [head] =
|
|
2608
|
-
const startingRange =
|
|
3374
|
+
const [head] = assertEx22(isDefined16(headHash) ? await this.blockViewer.blockByHash(headHash) : await this.blockViewer.currentBlock(), () => "Could not resolve head block");
|
|
3375
|
+
const startingRange = asXL1BlockRange7(range ?? [
|
|
2609
3376
|
0,
|
|
2610
3377
|
head.block
|
|
2611
3378
|
], true);
|
|
2612
3379
|
const blockNumbers = await this.distillTransferHistory(address, startingRange);
|
|
2613
|
-
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(
|
|
3380
|
+
const blocks = (await Promise.all(blockNumbers.map(async (bn) => await this.blockViewer.blockByNumber(bn)))).filter(exists2);
|
|
2614
3381
|
const result = [];
|
|
2615
3382
|
for (const block of blocks) {
|
|
2616
|
-
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema ===
|
|
3383
|
+
const transferIndexes = block[0].payload_schemas.map((schema, index) => schema === TransferSchema2 ? index : void 0).filter(exists2);
|
|
2617
3384
|
const transfers = transferIndexes.map((index) => {
|
|
2618
3385
|
const hash = block[0].payload_hashes[index];
|
|
2619
|
-
return
|
|
2620
|
-
}).filter(
|
|
3386
|
+
return assertEx22(block[1].find((p) => p._hash === hash), () => `Error: Could not find Transfer with hash ${hash} in block ${block[0]._hash}`);
|
|
3387
|
+
}).filter(exists2).filter((t) => t.from === address || isDefined16(t.transfers[address]));
|
|
2621
3388
|
if (transfers.length === 0) {
|
|
2622
3389
|
continue;
|
|
2623
3390
|
}
|
|
@@ -2645,8 +3412,8 @@ SimpleAccountBalanceViewer = _ts_decorate([
|
|
|
2645
3412
|
], SimpleAccountBalanceViewer);
|
|
2646
3413
|
|
|
2647
3414
|
// src/simple/block/SimpleBlockViewer.ts
|
|
2648
|
-
import { assertEx as
|
|
2649
|
-
import { asSignedHydratedBlockWithHashMeta, asXL1BlockNumber as
|
|
3415
|
+
import { assertEx as assertEx23, exists as exists3, isDefined as isDefined17, isUndefined as isUndefined5, spanRootAsync as spanRootAsync5 } from "@xylabs/sdk-js";
|
|
3416
|
+
import { asSignedHydratedBlockWithHashMeta, asXL1BlockNumber as asXL1BlockNumber9 } from "@xyo-network/xl1-protocol";
|
|
2650
3417
|
|
|
2651
3418
|
// src/utils/HydratedCache.ts
|
|
2652
3419
|
import { LRUCache as LRUCache2 } from "lru-cache";
|
|
@@ -2704,21 +3471,17 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
2704
3471
|
BlockViewerMoniker
|
|
2705
3472
|
];
|
|
2706
3473
|
moniker = _SimpleBlockViewer.defaultMoniker;
|
|
3474
|
+
_store;
|
|
2707
3475
|
_payloadCache;
|
|
2708
3476
|
_signedHydratedBlockCache;
|
|
2709
|
-
get context() {
|
|
2710
|
-
return this.params.context;
|
|
2711
|
-
}
|
|
2712
3477
|
get finalizedArchivist() {
|
|
2713
3478
|
return this.params.finalizedArchivist;
|
|
2714
3479
|
}
|
|
2715
3480
|
get hydratedBlockCache() {
|
|
2716
3481
|
if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache;
|
|
2717
|
-
const chainMap = this.
|
|
2718
|
-
this._signedHydratedBlockCache = new HydratedCache(chainMap, async (
|
|
2719
|
-
const result = await hydrateBlock(
|
|
2720
|
-
chainMap: chainMap2
|
|
2721
|
-
}, hash, maxDepth, minDepth);
|
|
3482
|
+
const chainMap = this.store.chainMap;
|
|
3483
|
+
this._signedHydratedBlockCache = new HydratedCache(chainMap, async (store, hash, maxDepth, minDepth) => {
|
|
3484
|
+
const result = await hydrateBlock(store, hash, maxDepth, minDepth);
|
|
2722
3485
|
return asSignedHydratedBlockWithHashMeta(result, true);
|
|
2723
3486
|
}, 200);
|
|
2724
3487
|
return this._signedHydratedBlockCache;
|
|
@@ -2730,9 +3493,11 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
2730
3493
|
});
|
|
2731
3494
|
return this._payloadCache;
|
|
2732
3495
|
}
|
|
3496
|
+
get store() {
|
|
3497
|
+
return this._store;
|
|
3498
|
+
}
|
|
2733
3499
|
static async paramsHandler(params) {
|
|
2734
|
-
|
|
2735
|
-
assertEx17(params.finalizedArchivist, () => "finalizedArchivist is required");
|
|
3500
|
+
assertEx23(params.finalizedArchivist, () => "finalizedArchivist is required");
|
|
2736
3501
|
return {
|
|
2737
3502
|
...await super.paramsHandler(params)
|
|
2738
3503
|
};
|
|
@@ -2745,13 +3510,27 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
2745
3510
|
}
|
|
2746
3511
|
async blockByNumber(blockNumber) {
|
|
2747
3512
|
return await spanRootAsync5("blockByNumber", async () => {
|
|
2748
|
-
|
|
3513
|
+
const head = await this.getCurrentHead();
|
|
3514
|
+
if (isUndefined5(head)) {
|
|
3515
|
+
return null;
|
|
3516
|
+
}
|
|
3517
|
+
return asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber({
|
|
3518
|
+
chainId: head.chain,
|
|
3519
|
+
head: /* @__PURE__ */ __name(() => {
|
|
3520
|
+
return [
|
|
3521
|
+
head._hash,
|
|
3522
|
+
head.block
|
|
3523
|
+
];
|
|
3524
|
+
}, "head"),
|
|
3525
|
+
store: this.store,
|
|
3526
|
+
singletons: this.context.singletons
|
|
3527
|
+
}, blockNumber)) ?? null;
|
|
2749
3528
|
}, this.tracer);
|
|
2750
3529
|
}
|
|
2751
3530
|
async blocksByHash(hash, limit = 50) {
|
|
2752
3531
|
return await spanRootAsync5("blocksByHash", async () => {
|
|
2753
|
-
|
|
2754
|
-
|
|
3532
|
+
assertEx23(limit > 0, () => "limit must be greater than 0");
|
|
3533
|
+
assertEx23(limit <= 100, () => "limit must be less than 100");
|
|
2755
3534
|
const blocks = [];
|
|
2756
3535
|
let current = await this.blockByHash(hash);
|
|
2757
3536
|
while (current && blocks.length < limit) {
|
|
@@ -2765,223 +3544,138 @@ var SimpleBlockViewer = class _SimpleBlockViewer extends AbstractCreatableProvid
|
|
|
2765
3544
|
}
|
|
2766
3545
|
async blocksByNumber(blockNumber, limit = 50) {
|
|
2767
3546
|
return await spanRootAsync5("blocksByHash", async () => {
|
|
2768
|
-
|
|
2769
|
-
|
|
3547
|
+
assertEx23(limit > 0, () => "limit must be greater than 0");
|
|
3548
|
+
assertEx23(limit <= 100, () => "limit must be less than 100");
|
|
2770
3549
|
const blocks = [];
|
|
2771
3550
|
let current = await this.blockByNumber(blockNumber);
|
|
2772
3551
|
while (current && blocks.length < limit) {
|
|
2773
3552
|
blocks.push(current);
|
|
2774
3553
|
if (current[0].block === 0) break;
|
|
2775
|
-
const previousNumber =
|
|
3554
|
+
const previousNumber = asXL1BlockNumber9(current[0].block - 1, true);
|
|
2776
3555
|
current = await this.blockByNumber(previousNumber);
|
|
2777
3556
|
}
|
|
2778
3557
|
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
|
|
2779
3558
|
}, this.tracer);
|
|
2780
3559
|
}
|
|
3560
|
+
async chainId(blockNumber = "latest") {
|
|
3561
|
+
return await spanRootAsync5("chainId", async () => {
|
|
3562
|
+
const block = assertEx23(blockNumber === "latest" ? await this.currentBlock() : await this.blockByNumber(blockNumber), () => `Could not find block for block number ${blockNumber}`);
|
|
3563
|
+
return block[0].chain;
|
|
3564
|
+
});
|
|
3565
|
+
}
|
|
3566
|
+
async createHandler() {
|
|
3567
|
+
await super.createHandler();
|
|
3568
|
+
this._store = {
|
|
3569
|
+
chainMap: readPayloadMapFromStore(this.params.finalizedArchivist)
|
|
3570
|
+
};
|
|
3571
|
+
}
|
|
2781
3572
|
async currentBlock() {
|
|
2782
3573
|
return await spanRootAsync5("currentBlock", async () => {
|
|
2783
|
-
const currentHead =
|
|
3574
|
+
const currentHead = assertEx23(await this.getCurrentHead(), () => "Could not find most recent block [currentBlock]");
|
|
2784
3575
|
const cache = this.hydratedBlockCache;
|
|
2785
3576
|
const block = await cache.get(currentHead._hash);
|
|
2786
3577
|
if (!block) {
|
|
2787
3578
|
console.log(`Could not find current block with hash ${currentHead._hash}`);
|
|
2788
3579
|
}
|
|
2789
|
-
return
|
|
3580
|
+
return assertEx23(block, () => "Could not find current block");
|
|
2790
3581
|
}, this.tracer);
|
|
2791
3582
|
}
|
|
2792
3583
|
async currentBlockHash() {
|
|
2793
3584
|
return await spanRootAsync5("currentBlockHash", async () => {
|
|
2794
|
-
const currentHead =
|
|
3585
|
+
const currentHead = assertEx23(await this.getCurrentHead(), () => "Could not find most recent block [currentBlockHash]");
|
|
2795
3586
|
return currentHead._hash;
|
|
2796
3587
|
}, this.tracer);
|
|
2797
3588
|
}
|
|
2798
3589
|
async currentBlockNumber() {
|
|
2799
|
-
return await spanRootAsync5("currentBlockNumber", async () => {
|
|
2800
|
-
const currentHead =
|
|
2801
|
-
return
|
|
2802
|
-
name: "currentBlockNumber"
|
|
2803
|
-
});
|
|
2804
|
-
}, this.tracer);
|
|
2805
|
-
}
|
|
2806
|
-
async payloadByHash(hash) {
|
|
2807
|
-
const cachedPayload = await this.payloadCache.get(hash);
|
|
2808
|
-
if (cachedPayload) {
|
|
2809
|
-
return cachedPayload;
|
|
2810
|
-
} else {
|
|
2811
|
-
const [result] = await this.finalizedArchivist.get([
|
|
2812
|
-
hash
|
|
2813
|
-
]);
|
|
2814
|
-
if (
|
|
2815
|
-
await this.payloadCache.set(hash, result);
|
|
2816
|
-
}
|
|
2817
|
-
return result ?? null;
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
async payloadsByHash(hashes) {
|
|
2821
|
-
let remainingHashes = [
|
|
2822
|
-
...hashes
|
|
2823
|
-
];
|
|
2824
|
-
const cachedPayloads = await this.payloadCache.getMany(remainingHashes);
|
|
2825
|
-
const cachedHashes = new Set(cachedPayloads.map((p) => p._hash));
|
|
2826
|
-
remainingHashes = remainingHashes.filter((h) => !cachedHashes.has(h));
|
|
2827
|
-
const remainingPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
|
|
2828
|
-
return [
|
|
2829
|
-
...cachedPayloads,
|
|
2830
|
-
...remainingPayloads.filter(exists2)
|
|
2831
|
-
];
|
|
2832
|
-
}
|
|
2833
|
-
async getCurrentHead() {
|
|
2834
|
-
const chainArchivist = this.finalizedArchivist;
|
|
2835
|
-
return await findMostRecentBlock(chainArchivist);
|
|
2836
|
-
}
|
|
2837
|
-
};
|
|
2838
|
-
SimpleBlockViewer = _ts_decorate2([
|
|
2839
|
-
creatableProvider()
|
|
2840
|
-
], SimpleBlockViewer);
|
|
2841
|
-
|
|
2842
|
-
// src/simple/blockReward/SimpleBlockRewardViewer.ts
|
|
2843
|
-
function _ts_decorate3(decorators, target, key, desc) {
|
|
2844
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2845
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2846
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2847
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2848
|
-
}
|
|
2849
|
-
__name(_ts_decorate3, "_ts_decorate");
|
|
2850
|
-
var SimpleBlockRewardViewer = class _SimpleBlockRewardViewer extends AbstractCreatableProvider {
|
|
2851
|
-
static {
|
|
2852
|
-
__name(this, "SimpleBlockRewardViewer");
|
|
2853
|
-
}
|
|
2854
|
-
static defaultMoniker = BlockRewardViewerMoniker;
|
|
2855
|
-
static monikers = [
|
|
2856
|
-
BlockRewardViewerMoniker
|
|
2857
|
-
];
|
|
2858
|
-
moniker = _SimpleBlockRewardViewer.defaultMoniker;
|
|
2859
|
-
rewardFromBlockNumber = rewardFromBlockNumber(18);
|
|
2860
|
-
allowedRewardForBlock(block) {
|
|
2861
|
-
return this.rewardFromBlockNumber(block, this.params.initialReward, this.params.stepSize, this.params.stepFactorNumerator, this.params.stepFactorDenominator, this.params.minRewardPerBlock, this.params.creatorReward);
|
|
2862
|
-
}
|
|
2863
|
-
};
|
|
2864
|
-
SimpleBlockRewardViewer = _ts_decorate3([
|
|
2865
|
-
creatableProvider()
|
|
2866
|
-
], SimpleBlockRewardViewer);
|
|
2867
|
-
|
|
2868
|
-
// src/simple/chainStake/SimpleChainStakeViewer.ts
|
|
2869
|
-
import { asAddress as asAddress5, toAddress as toAddress6 } from "@xylabs/sdk-js";
|
|
2870
|
-
import { assertEx as assertEx18 } from "@xylabs/sdk-js";
|
|
2871
|
-
import { Account } from "@xyo-network/account";
|
|
2872
|
-
|
|
2873
|
-
// src/simple/chainStakeEvents/SimpleChainStakeEventsViewer.ts
|
|
2874
|
-
import { isDefined as isDefined13 } from "@xylabs/sdk-js";
|
|
2875
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
2876
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2877
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2878
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2879
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2880
|
-
}
|
|
2881
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
2882
|
-
var SimpleChainStakeEventsViewer = class _SimpleChainStakeEventsViewer extends AbstractCreatableProvider {
|
|
2883
|
-
static {
|
|
2884
|
-
__name(this, "SimpleChainStakeEventsViewer");
|
|
2885
|
-
}
|
|
2886
|
-
static defaultMoniker = StakeEventsViewerMoniker;
|
|
2887
|
-
static monikers = [
|
|
2888
|
-
StakeEventsViewerMoniker
|
|
2889
|
-
];
|
|
2890
|
-
moniker = _SimpleChainStakeEventsViewer.defaultMoniker;
|
|
2891
|
-
get positions() {
|
|
2892
|
-
return this.params.positions;
|
|
2893
|
-
}
|
|
2894
|
-
positionCount(range) {
|
|
2895
|
-
return this.positionsFromRange(range).length;
|
|
2896
|
-
}
|
|
2897
|
-
stakeEvents(range, { name } = {}) {
|
|
2898
|
-
const positions = this.positionsFromRange(range);
|
|
2899
|
-
const events = this.eventsFromPositions(positions);
|
|
2900
|
-
if (isDefined13(name)) {
|
|
2901
|
-
return events.filter((event) => event.name === name);
|
|
2902
|
-
}
|
|
2903
|
-
return events;
|
|
2904
|
-
}
|
|
2905
|
-
async startHandler() {
|
|
2906
|
-
await super.startHandler();
|
|
2907
|
-
}
|
|
2908
|
-
eventsFromPositions(positions) {
|
|
2909
|
-
const events = positions.map((position) => {
|
|
2910
|
-
const events2 = [
|
|
2911
|
-
{
|
|
2912
|
-
name: "StakeAdded",
|
|
2913
|
-
time: position.addBlock,
|
|
2914
|
-
args: {
|
|
2915
|
-
staker: position.staker,
|
|
2916
|
-
staked: position.staked,
|
|
2917
|
-
amount: position.amount,
|
|
2918
|
-
id: position.id
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
];
|
|
2922
|
-
if (position.removeBlock !== 0) {
|
|
2923
|
-
events2.push({
|
|
2924
|
-
name: "StakeRemoved",
|
|
2925
|
-
time: position.removeBlock,
|
|
2926
|
-
args: {
|
|
2927
|
-
staker: position.staker,
|
|
2928
|
-
staked: position.staked,
|
|
2929
|
-
amount: position.amount,
|
|
2930
|
-
id: position.id
|
|
2931
|
-
}
|
|
2932
|
-
});
|
|
2933
|
-
}
|
|
2934
|
-
if (position.withdrawBlock !== 0) {
|
|
2935
|
-
events2.push({
|
|
2936
|
-
name: "StakeWithdrawn",
|
|
2937
|
-
time: position.withdrawBlock,
|
|
2938
|
-
args: {
|
|
2939
|
-
staker: position.staker,
|
|
2940
|
-
staked: position.staked,
|
|
2941
|
-
amount: position.amount,
|
|
2942
|
-
id: position.id
|
|
2943
|
-
}
|
|
2944
|
-
});
|
|
3590
|
+
return await spanRootAsync5("currentBlockNumber", async () => {
|
|
3591
|
+
const currentHead = assertEx23(await this.getCurrentHead(), () => "Could not find most recent block [currentBlockNumber]");
|
|
3592
|
+
return asXL1BlockNumber9(currentHead.block, {
|
|
3593
|
+
name: "currentBlockNumber"
|
|
3594
|
+
});
|
|
3595
|
+
}, this.tracer);
|
|
3596
|
+
}
|
|
3597
|
+
async payloadByHash(hash) {
|
|
3598
|
+
const cachedPayload = await this.payloadCache.get(hash);
|
|
3599
|
+
if (cachedPayload) {
|
|
3600
|
+
return cachedPayload;
|
|
3601
|
+
} else {
|
|
3602
|
+
const [result] = await this.finalizedArchivist.get([
|
|
3603
|
+
hash
|
|
3604
|
+
]);
|
|
3605
|
+
if (isDefined17(result)) {
|
|
3606
|
+
await this.payloadCache.set(hash, result);
|
|
2945
3607
|
}
|
|
2946
|
-
return
|
|
2947
|
-
}
|
|
2948
|
-
return events.flat();
|
|
3608
|
+
return result ?? null;
|
|
3609
|
+
}
|
|
2949
3610
|
}
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
3611
|
+
async payloadsByHash(hashes) {
|
|
3612
|
+
let remainingHashes = [
|
|
3613
|
+
...hashes
|
|
3614
|
+
];
|
|
3615
|
+
const cachedPayloads = await this.payloadCache.getMany(remainingHashes);
|
|
3616
|
+
const cachedHashes = new Set(cachedPayloads.map((p) => p._hash));
|
|
3617
|
+
remainingHashes = remainingHashes.filter((h) => !cachedHashes.has(h));
|
|
3618
|
+
const remainingPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
|
|
3619
|
+
return [
|
|
3620
|
+
...cachedPayloads,
|
|
3621
|
+
...remainingPayloads.filter(exists3)
|
|
3622
|
+
];
|
|
3623
|
+
}
|
|
3624
|
+
async getCurrentHead() {
|
|
3625
|
+
const chainArchivist = this.finalizedArchivist;
|
|
3626
|
+
return await findMostRecentBlock(chainArchivist);
|
|
2957
3627
|
}
|
|
2958
3628
|
};
|
|
2959
|
-
|
|
3629
|
+
SimpleBlockViewer = _ts_decorate2([
|
|
2960
3630
|
creatableProvider()
|
|
2961
|
-
],
|
|
3631
|
+
], SimpleBlockViewer);
|
|
2962
3632
|
|
|
2963
|
-
// src/simple/
|
|
2964
|
-
function
|
|
3633
|
+
// src/simple/blockReward/SimpleBlockRewardViewer.ts
|
|
3634
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
2965
3635
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2966
3636
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2967
3637
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2968
3638
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2969
3639
|
}
|
|
2970
|
-
__name(
|
|
2971
|
-
var
|
|
3640
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
3641
|
+
var SimpleBlockRewardViewer = class _SimpleBlockRewardViewer extends AbstractCreatableProvider {
|
|
3642
|
+
static {
|
|
3643
|
+
__name(this, "SimpleBlockRewardViewer");
|
|
3644
|
+
}
|
|
3645
|
+
static defaultMoniker = BlockRewardViewerMoniker;
|
|
3646
|
+
static monikers = [
|
|
3647
|
+
BlockRewardViewerMoniker
|
|
3648
|
+
];
|
|
3649
|
+
moniker = _SimpleBlockRewardViewer.defaultMoniker;
|
|
3650
|
+
rewardFromBlockNumber = rewardFromBlockNumber(18);
|
|
3651
|
+
allowedRewardForBlock(block) {
|
|
3652
|
+
return this.rewardFromBlockNumber(block, this.params.initialReward, this.params.stepSize, this.params.stepFactorNumerator, this.params.stepFactorDenominator, this.params.minRewardPerBlock, this.params.creatorReward);
|
|
3653
|
+
}
|
|
3654
|
+
};
|
|
3655
|
+
SimpleBlockRewardViewer = _ts_decorate3([
|
|
3656
|
+
creatableProvider()
|
|
3657
|
+
], SimpleBlockRewardViewer);
|
|
3658
|
+
|
|
3659
|
+
// src/simple/chainStake/SimpleStakeViewer.ts
|
|
3660
|
+
import { asAddress as asAddress5, toAddress as toAddress9 } from "@xylabs/sdk-js";
|
|
3661
|
+
import { assertEx as assertEx24 } from "@xylabs/sdk-js";
|
|
3662
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
3663
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3664
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3665
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3666
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3667
|
+
}
|
|
3668
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
3669
|
+
var SimpleStakeViewer = class _SimpleStakeViewer extends AbstractCreatableProvider {
|
|
2972
3670
|
static {
|
|
2973
|
-
__name(this, "
|
|
3671
|
+
__name(this, "SimpleStakeViewer");
|
|
2974
3672
|
}
|
|
2975
3673
|
static defaultMoniker = StakeViewerMoniker;
|
|
2976
3674
|
static monikers = [
|
|
2977
3675
|
StakeViewerMoniker
|
|
2978
3676
|
];
|
|
2979
|
-
moniker =
|
|
2980
|
-
_chainId;
|
|
3677
|
+
moniker = _SimpleStakeViewer.defaultMoniker;
|
|
2981
3678
|
_chainStakeEventsViewer;
|
|
2982
|
-
get chainId() {
|
|
2983
|
-
return assertEx18(this._chainId, () => "Chain ID not set");
|
|
2984
|
-
}
|
|
2985
3679
|
get chainMap() {
|
|
2986
3680
|
return this.params.chainMap;
|
|
2987
3681
|
}
|
|
@@ -2989,13 +3683,13 @@ var SimpleChainStakeViewer = class _SimpleChainStakeViewer extends AbstractCreat
|
|
|
2989
3683
|
return this.params.minWithdrawalBlocks ?? 10;
|
|
2990
3684
|
}
|
|
2991
3685
|
get rewardsContract() {
|
|
2992
|
-
return
|
|
3686
|
+
return toAddress9(toAddress9(1n));
|
|
2993
3687
|
}
|
|
2994
3688
|
get stakeEvents() {
|
|
2995
|
-
return
|
|
3689
|
+
return assertEx24(this._chainStakeEventsViewer, () => "Stake events viewer not set");
|
|
2996
3690
|
}
|
|
2997
3691
|
get stakingTokenAddress() {
|
|
2998
|
-
return
|
|
3692
|
+
return toAddress9("0x000000000000000000000000000011");
|
|
2999
3693
|
}
|
|
3000
3694
|
get positions() {
|
|
3001
3695
|
return this.params.positions;
|
|
@@ -3027,6 +3721,10 @@ var SimpleChainStakeViewer = class _SimpleChainStakeViewer extends AbstractCreat
|
|
|
3027
3721
|
}
|
|
3028
3722
|
return active;
|
|
3029
3723
|
}
|
|
3724
|
+
async createHandler() {
|
|
3725
|
+
await super.createHandler();
|
|
3726
|
+
this._chainStakeEventsViewer = assertEx24(await this.locateAndCreate(StakeEventsViewerMoniker), () => "Failed to create StakeEventsViewer");
|
|
3727
|
+
}
|
|
3030
3728
|
pending() {
|
|
3031
3729
|
let pending = 0n;
|
|
3032
3730
|
for (const position of this.positions) {
|
|
@@ -3046,7 +3744,7 @@ var SimpleChainStakeViewer = class _SimpleChainStakeViewer extends AbstractCreat
|
|
|
3046
3744
|
return pending;
|
|
3047
3745
|
}
|
|
3048
3746
|
stakeById(id) {
|
|
3049
|
-
return
|
|
3747
|
+
return assertEx24(this.positions[id], () => new Error(`Stake with id ${id} not found`));
|
|
3050
3748
|
}
|
|
3051
3749
|
stakeByStaker(staker, slot) {
|
|
3052
3750
|
return this.positions.filter((s) => asAddress5(s.staker) === asAddress5(staker))[slot];
|
|
@@ -3083,17 +3781,10 @@ var SimpleChainStakeViewer = class _SimpleChainStakeViewer extends AbstractCreat
|
|
|
3083
3781
|
}
|
|
3084
3782
|
return withdrawn;
|
|
3085
3783
|
}
|
|
3086
|
-
async startHandler() {
|
|
3087
|
-
await super.startHandler();
|
|
3088
|
-
this._chainId = this.params.chainId ?? (await Account.random()).address;
|
|
3089
|
-
this._chainStakeEventsViewer = await SimpleChainStakeEventsViewer.create({
|
|
3090
|
-
positions: this.positions
|
|
3091
|
-
});
|
|
3092
|
-
}
|
|
3093
3784
|
};
|
|
3094
|
-
|
|
3785
|
+
SimpleStakeViewer = _ts_decorate4([
|
|
3095
3786
|
creatableProvider()
|
|
3096
|
-
],
|
|
3787
|
+
], SimpleStakeViewer);
|
|
3097
3788
|
|
|
3098
3789
|
// src/simple/client/SimpleXyoClient.ts
|
|
3099
3790
|
var SimpleXyoClient = class {
|
|
@@ -3123,21 +3814,21 @@ var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
|
3123
3814
|
get map() {
|
|
3124
3815
|
return this.params.map;
|
|
3125
3816
|
}
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3817
|
+
async get(hash) {
|
|
3818
|
+
const result = await this.map.get(hash);
|
|
3819
|
+
return this.isAllowed(result) ? result : void 0;
|
|
3820
|
+
}
|
|
3821
|
+
async getMany(hashes) {
|
|
3822
|
+
const result = await this.map.getMany(hashes);
|
|
3823
|
+
return result.filter((data) => this.isAllowed(data));
|
|
3824
|
+
}
|
|
3825
|
+
async has(hash) {
|
|
3826
|
+
const value = await this.get(hash);
|
|
3827
|
+
if (isAnyPayload4(value)) {
|
|
3828
|
+
return this.isAllowed(value);
|
|
3829
|
+
}
|
|
3830
|
+
return value !== void 0;
|
|
3831
|
+
}
|
|
3141
3832
|
isAllowed(value) {
|
|
3142
3833
|
if (isAnyPayload4(value)) {
|
|
3143
3834
|
return this.isAllowedSchema(value.schema);
|
|
@@ -3156,13 +3847,13 @@ var AbstractSimpleDataLake = class extends AbstractCreatableProvider {
|
|
|
3156
3847
|
};
|
|
3157
3848
|
|
|
3158
3849
|
// src/simple/datalake/SimpleDataLakeRunner.ts
|
|
3159
|
-
function
|
|
3850
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
3160
3851
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3161
3852
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3162
3853
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3163
3854
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3164
3855
|
}
|
|
3165
|
-
__name(
|
|
3856
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
3166
3857
|
var SimpleDataLakeRunner = class _SimpleDataLakeRunner extends AbstractSimpleDataLake {
|
|
3167
3858
|
static {
|
|
3168
3859
|
__name(this, "SimpleDataLakeRunner");
|
|
@@ -3188,19 +3879,18 @@ var SimpleDataLakeRunner = class _SimpleDataLakeRunner extends AbstractSimpleDat
|
|
|
3188
3879
|
return await this.map.setMany(allowed);
|
|
3189
3880
|
}
|
|
3190
3881
|
};
|
|
3191
|
-
SimpleDataLakeRunner =
|
|
3882
|
+
SimpleDataLakeRunner = _ts_decorate5([
|
|
3192
3883
|
creatableProvider()
|
|
3193
3884
|
], SimpleDataLakeRunner);
|
|
3194
3885
|
|
|
3195
3886
|
// src/simple/datalake/SimpleDataLakeViewer.ts
|
|
3196
|
-
|
|
3197
|
-
function _ts_decorate7(decorators, target, key, desc) {
|
|
3887
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
3198
3888
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3199
3889
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3200
3890
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3201
3891
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3202
3892
|
}
|
|
3203
|
-
__name(
|
|
3893
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
3204
3894
|
var SimpleDataLakeViewer = class _SimpleDataLakeViewer extends AbstractSimpleDataLake {
|
|
3205
3895
|
static {
|
|
3206
3896
|
__name(this, "SimpleDataLakeViewer");
|
|
@@ -3210,23 +3900,8 @@ var SimpleDataLakeViewer = class _SimpleDataLakeViewer extends AbstractSimpleDat
|
|
|
3210
3900
|
DataLakeViewerMoniker
|
|
3211
3901
|
];
|
|
3212
3902
|
moniker = _SimpleDataLakeViewer.defaultMoniker;
|
|
3213
|
-
async get(hash) {
|
|
3214
|
-
const result = await this.map.get(hash);
|
|
3215
|
-
return this.isAllowed(result) ? result : void 0;
|
|
3216
|
-
}
|
|
3217
|
-
async getMany(hashes) {
|
|
3218
|
-
const result = await this.map.getMany(hashes);
|
|
3219
|
-
return result.filter((data) => this.isAllowed(data));
|
|
3220
|
-
}
|
|
3221
|
-
async has(hash) {
|
|
3222
|
-
const value = await this.get(hash);
|
|
3223
|
-
if (isAnyPayload5(value)) {
|
|
3224
|
-
return this.isAllowed(value);
|
|
3225
|
-
}
|
|
3226
|
-
return value !== void 0;
|
|
3227
|
-
}
|
|
3228
3903
|
};
|
|
3229
|
-
SimpleDataLakeViewer =
|
|
3904
|
+
SimpleDataLakeViewer = _ts_decorate6([
|
|
3230
3905
|
creatableProvider()
|
|
3231
3906
|
], SimpleDataLakeViewer);
|
|
3232
3907
|
|
|
@@ -3256,9 +3931,9 @@ var SimpleXyoGateway = class {
|
|
|
3256
3931
|
};
|
|
3257
3932
|
|
|
3258
3933
|
// src/simple/gateway/SimpleXyoGatewayRunner.ts
|
|
3259
|
-
import { assertEx as
|
|
3260
|
-
import { PayloadBuilder as
|
|
3261
|
-
import { asXL1BlockNumber as
|
|
3934
|
+
import { assertEx as assertEx25, BigIntToJsonZod, isDefined as isDefined18 } from "@xylabs/sdk-js";
|
|
3935
|
+
import { PayloadBuilder as PayloadBuilder17 } from "@xyo-network/payload-builder";
|
|
3936
|
+
import { asXL1BlockNumber as asXL1BlockNumber10, TransferSchema as TransferSchema3 } from "@xyo-network/xl1-protocol";
|
|
3262
3937
|
var SimpleXyoGatewayRunner = class {
|
|
3263
3938
|
static {
|
|
3264
3939
|
__name(this, "SimpleXyoGatewayRunner");
|
|
@@ -3287,18 +3962,18 @@ var SimpleXyoGatewayRunner = class {
|
|
|
3287
3962
|
return this._dataLakes.length - 1;
|
|
3288
3963
|
}
|
|
3289
3964
|
async addPayloadsToChain(onChain, offChain, options) {
|
|
3290
|
-
const viewer =
|
|
3965
|
+
const viewer = assertEx25(this.connectionInstance.viewer, () => "No viewer available on connection");
|
|
3291
3966
|
const { nbf, exp, chain, fees } = options ?? {};
|
|
3292
|
-
const resolvedChainId =
|
|
3293
|
-
const resolvedNbf =
|
|
3294
|
-
const resolvedExp =
|
|
3967
|
+
const resolvedChainId = isDefined18(chain) ? chain : await viewer.chainId();
|
|
3968
|
+
const resolvedNbf = asXL1BlockNumber10(isDefined18(nbf) ? nbf : await viewer.currentBlockNumber(), true);
|
|
3969
|
+
const resolvedExp = asXL1BlockNumber10(isDefined18(exp) ? exp : resolvedNbf + 10, true);
|
|
3295
3970
|
const tx = await buildUnsignedTransaction(resolvedChainId, onChain, offChain, resolvedNbf, resolvedExp, await (await this.signer()).address(), fees);
|
|
3296
3971
|
return await this.addTransactionToChain(tx);
|
|
3297
3972
|
}
|
|
3298
3973
|
async addTransactionToChain(tx) {
|
|
3299
3974
|
const connection = this.connectionInstance;
|
|
3300
3975
|
const signer = this.signerInstance;
|
|
3301
|
-
const runner =
|
|
3976
|
+
const runner = assertEx25(connection.runner, () => "No runner available on connection");
|
|
3302
3977
|
const signedTx = await signer.signTransaction(tx);
|
|
3303
3978
|
await this.addPayloadsToDataLakes(signedTx[1]);
|
|
3304
3979
|
return [
|
|
@@ -3310,7 +3985,7 @@ var SimpleXyoGatewayRunner = class {
|
|
|
3310
3985
|
];
|
|
3311
3986
|
}
|
|
3312
3987
|
async confirmSubmittedTransaction(txHash, options) {
|
|
3313
|
-
return await confirmSubmittedTransaction(
|
|
3988
|
+
return await confirmSubmittedTransaction(assertEx25(this.connectionInstance.viewer, () => "Connection viewer is undefined"), txHash, options);
|
|
3314
3989
|
}
|
|
3315
3990
|
/** @deprecated use connectionInstance instead */
|
|
3316
3991
|
connection() {
|
|
@@ -3330,8 +4005,8 @@ var SimpleXyoGatewayRunner = class {
|
|
|
3330
4005
|
address,
|
|
3331
4006
|
BigIntToJsonZod.parse(amount)
|
|
3332
4007
|
]));
|
|
3333
|
-
const transfer = new
|
|
3334
|
-
schema:
|
|
4008
|
+
const transfer = new PayloadBuilder17({
|
|
4009
|
+
schema: TransferSchema3
|
|
3335
4010
|
}).fields({
|
|
3336
4011
|
from,
|
|
3337
4012
|
transfers: hexTransfers,
|
|
@@ -3356,19 +4031,23 @@ var SimpleXyoGatewayRunner = class {
|
|
|
3356
4031
|
};
|
|
3357
4032
|
|
|
3358
4033
|
// src/simple/mempool/SimpleMempoolRunner.ts
|
|
3359
|
-
import {
|
|
3360
|
-
|
|
3361
|
-
function _ts_decorate8(decorators, target, key, desc) {
|
|
4034
|
+
import { PayloadBuilder as PayloadBuilder18 } from "@xyo-network/payload-builder";
|
|
4035
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
3362
4036
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3363
4037
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3364
4038
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3365
4039
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3366
4040
|
}
|
|
3367
|
-
__name(
|
|
3368
|
-
var SimpleMempoolRunner = class extends
|
|
4041
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
4042
|
+
var SimpleMempoolRunner = class _SimpleMempoolRunner extends AbstractCreatableProvider {
|
|
3369
4043
|
static {
|
|
3370
4044
|
__name(this, "SimpleMempoolRunner");
|
|
3371
4045
|
}
|
|
4046
|
+
static defaultMoniker = MempoolRunnerMoniker;
|
|
4047
|
+
static monikers = [
|
|
4048
|
+
MempoolRunnerMoniker
|
|
4049
|
+
];
|
|
4050
|
+
moniker = _SimpleMempoolRunner.defaultMoniker;
|
|
3372
4051
|
get pendingBlocksArchivist() {
|
|
3373
4052
|
return this.params.pendingBlocksArchivist;
|
|
3374
4053
|
}
|
|
@@ -3378,8 +4057,8 @@ var SimpleMempoolRunner = class extends AbstractCreatable2 {
|
|
|
3378
4057
|
async submitBlocks(blocks) {
|
|
3379
4058
|
const bundles = await Promise.all(blocks.map(async ([bw, payloads]) => {
|
|
3380
4059
|
return hydratedBlockToPayloadBundle([
|
|
3381
|
-
await
|
|
3382
|
-
await
|
|
4060
|
+
await PayloadBuilder18.addHashMeta(bw),
|
|
4061
|
+
await PayloadBuilder18.addHashMeta(payloads)
|
|
3383
4062
|
]);
|
|
3384
4063
|
}));
|
|
3385
4064
|
const inserted = await this.pendingBlocksArchivist.insert(bundles);
|
|
@@ -3388,28 +4067,28 @@ var SimpleMempoolRunner = class extends AbstractCreatable2 {
|
|
|
3388
4067
|
async submitTransactions(transactions) {
|
|
3389
4068
|
const bundles = await Promise.all(transactions.map(async ([tx, payloads]) => {
|
|
3390
4069
|
return hydratedTransactionToPayloadBundle([
|
|
3391
|
-
await
|
|
3392
|
-
await
|
|
4070
|
+
await PayloadBuilder18.addHashMeta(tx),
|
|
4071
|
+
await PayloadBuilder18.addHashMeta(payloads)
|
|
3393
4072
|
]);
|
|
3394
4073
|
}));
|
|
3395
|
-
const inserted = await this.
|
|
4074
|
+
const inserted = await this.pendingTransactionsArchivist.insert(bundles);
|
|
3396
4075
|
return inserted.map((p) => p._hash);
|
|
3397
4076
|
}
|
|
3398
4077
|
};
|
|
3399
|
-
SimpleMempoolRunner =
|
|
3400
|
-
|
|
4078
|
+
SimpleMempoolRunner = _ts_decorate7([
|
|
4079
|
+
creatableProvider()
|
|
3401
4080
|
], SimpleMempoolRunner);
|
|
3402
4081
|
|
|
3403
4082
|
// src/simple/mempool/SimpleMempoolViewer.ts
|
|
3404
|
-
import { creatable
|
|
4083
|
+
import { creatable, exists as exists4, isDefined as isDefined19, isHash } from "@xylabs/sdk-js";
|
|
3405
4084
|
import { isHashMeta as isHashMeta2, isPayloadBundle } from "@xyo-network/payload-model";
|
|
3406
|
-
function
|
|
4085
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
3407
4086
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3408
4087
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3409
4088
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3410
4089
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3411
4090
|
}
|
|
3412
|
-
__name(
|
|
4091
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
3413
4092
|
var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatableProvider {
|
|
3414
4093
|
static {
|
|
3415
4094
|
__name(this, "SimpleMempoolViewer");
|
|
@@ -3431,7 +4110,7 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
3431
4110
|
const [p] = await this.pendingBlocksArchivist.get([
|
|
3432
4111
|
providedCursor
|
|
3433
4112
|
]);
|
|
3434
|
-
if (
|
|
4113
|
+
if (isDefined19(p)) {
|
|
3435
4114
|
cursor = p._sequence;
|
|
3436
4115
|
}
|
|
3437
4116
|
}
|
|
@@ -3441,7 +4120,7 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
3441
4120
|
cursor
|
|
3442
4121
|
});
|
|
3443
4122
|
const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta2);
|
|
3444
|
-
return (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedBlock(bundle3)))).filter(
|
|
4123
|
+
return (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedBlock(bundle3)))).filter(exists4);
|
|
3445
4124
|
}
|
|
3446
4125
|
async pendingTransactions({ cursor: providedCursor } = {}) {
|
|
3447
4126
|
let cursor = void 0;
|
|
@@ -3449,25 +4128,30 @@ var SimpleMempoolViewer = class _SimpleMempoolViewer extends AbstractCreatablePr
|
|
|
3449
4128
|
const [p] = await this.pendingTransactionsArchivist.get([
|
|
3450
4129
|
providedCursor
|
|
3451
4130
|
]);
|
|
3452
|
-
if (
|
|
4131
|
+
if (isDefined19(p)) {
|
|
3453
4132
|
cursor = p._sequence;
|
|
3454
4133
|
}
|
|
3455
4134
|
}
|
|
4135
|
+
this.logger?.info(`Fetching pending transactions from cursor: ${cursor}`);
|
|
3456
4136
|
const bundles = await this.pendingTransactionsArchivist.next({
|
|
3457
4137
|
order: "asc",
|
|
3458
4138
|
limit: 100,
|
|
3459
4139
|
cursor
|
|
3460
4140
|
});
|
|
4141
|
+
this.logger?.info(`Fetched pending transactions: ${bundles.length} bundles`);
|
|
3461
4142
|
const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta2);
|
|
3462
|
-
|
|
4143
|
+
this.logger?.info(`Filtered pending transactions: ${JSON.stringify(bundles, null, 2)} filteredBundles`);
|
|
4144
|
+
const result = (await Promise.all(filteredBundles.map(async (bundle3) => await bundledPayloadToHydratedTransaction(bundle3)))).filter(exists4);
|
|
4145
|
+
this.logger?.info(`Converted pending transactions: ${JSON.stringify(result, null, 2)} results`);
|
|
4146
|
+
return result;
|
|
3463
4147
|
}
|
|
3464
4148
|
};
|
|
3465
|
-
SimpleMempoolViewer =
|
|
3466
|
-
|
|
4149
|
+
SimpleMempoolViewer = _ts_decorate8([
|
|
4150
|
+
creatable()
|
|
3467
4151
|
], SimpleMempoolViewer);
|
|
3468
4152
|
|
|
3469
4153
|
// src/simple/network/SimpleXyoNetwork.ts
|
|
3470
|
-
import { isUndefined as
|
|
4154
|
+
import { isUndefined as isUndefined6 } from "@xylabs/sdk-js";
|
|
3471
4155
|
import { isNetworkStatus } from "@xyo-network/xl1-protocol";
|
|
3472
4156
|
import axios from "axios";
|
|
3473
4157
|
|
|
@@ -3514,7 +4198,7 @@ var SimpleXyoNetwork = class {
|
|
|
3514
4198
|
}
|
|
3515
4199
|
async status() {
|
|
3516
4200
|
const statusNetwork = StatusNetworks[this._networkId];
|
|
3517
|
-
if (
|
|
4201
|
+
if (isUndefined6(statusNetwork)) {
|
|
3518
4202
|
throw new Error(`Unknown status network ID: ${this._networkId}`);
|
|
3519
4203
|
}
|
|
3520
4204
|
return await this.makeRequest(statusNetwork.statusUrl);
|
|
@@ -3539,7 +4223,7 @@ var SimpleXyoNetwork = class {
|
|
|
3539
4223
|
};
|
|
3540
4224
|
|
|
3541
4225
|
// src/simple/permissions/SimpleXyoPermissions.ts
|
|
3542
|
-
import { assertEx as
|
|
4226
|
+
import { assertEx as assertEx26 } from "@xylabs/sdk-js";
|
|
3543
4227
|
var SimpleXyoPermissions = class {
|
|
3544
4228
|
static {
|
|
3545
4229
|
__name(this, "SimpleXyoPermissions");
|
|
@@ -3551,7 +4235,7 @@ var SimpleXyoPermissions = class {
|
|
|
3551
4235
|
this.invoker = store.invoker;
|
|
3552
4236
|
}
|
|
3553
4237
|
get store() {
|
|
3554
|
-
return
|
|
4238
|
+
return assertEx26(this._store, () => "Store must be defined to get permissions");
|
|
3555
4239
|
}
|
|
3556
4240
|
async getPermissions() {
|
|
3557
4241
|
return await this.store.getPermissions();
|
|
@@ -3609,7 +4293,7 @@ var SimpleXyoPermissions = class {
|
|
|
3609
4293
|
};
|
|
3610
4294
|
|
|
3611
4295
|
// src/simple/permissions/store/MemoryPermissions.ts
|
|
3612
|
-
import { assertEx as
|
|
4296
|
+
import { assertEx as assertEx27 } from "@xylabs/sdk-js";
|
|
3613
4297
|
var MemoryPermissionsStore = class {
|
|
3614
4298
|
static {
|
|
3615
4299
|
__name(this, "MemoryPermissionsStore");
|
|
@@ -3620,7 +4304,7 @@ var MemoryPermissionsStore = class {
|
|
|
3620
4304
|
this._invoker = invoker;
|
|
3621
4305
|
}
|
|
3622
4306
|
get invoker() {
|
|
3623
|
-
return
|
|
4307
|
+
return assertEx27(this._invoker, () => "Invoker must be defined to get permissions");
|
|
3624
4308
|
}
|
|
3625
4309
|
async getPermissions() {
|
|
3626
4310
|
await Promise.resolve();
|
|
@@ -3633,33 +4317,48 @@ var MemoryPermissionsStore = class {
|
|
|
3633
4317
|
};
|
|
3634
4318
|
|
|
3635
4319
|
// src/simple/runner/SimpleXyoRunner.ts
|
|
3636
|
-
import {
|
|
3637
|
-
import { PayloadBuilder as
|
|
3638
|
-
var SimpleXyoRunner = class {
|
|
4320
|
+
import { assertEx as assertEx28 } from "@xylabs/sdk-js";
|
|
4321
|
+
import { PayloadBuilder as PayloadBuilder19 } from "@xyo-network/payload-builder";
|
|
4322
|
+
var SimpleXyoRunner = class _SimpleXyoRunner extends AbstractCreatableProvider {
|
|
3639
4323
|
static {
|
|
3640
4324
|
__name(this, "SimpleXyoRunner");
|
|
3641
4325
|
}
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
4326
|
+
static defaultMoniker = XyoRunnerMoniker;
|
|
4327
|
+
static monikers = [
|
|
4328
|
+
XyoRunnerMoniker
|
|
4329
|
+
];
|
|
4330
|
+
moniker = _SimpleXyoRunner.defaultMoniker;
|
|
4331
|
+
_mempoolRunner;
|
|
4332
|
+
get mempool() {
|
|
4333
|
+
return this._mempoolRunner;
|
|
4334
|
+
}
|
|
4335
|
+
static async paramsHandler(params) {
|
|
4336
|
+
return {
|
|
4337
|
+
...await super.paramsHandler(params),
|
|
4338
|
+
pendingTransactionsArchivist: assertEx28(params?.pendingTransactionsArchivist, () => "A pendingTransactionsArchivist is required to create a SimpleXyoRunner")
|
|
4339
|
+
};
|
|
3645
4340
|
}
|
|
3646
4341
|
async broadcastTransaction(transaction) {
|
|
3647
|
-
const archivist =
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
}
|
|
3657
|
-
return
|
|
4342
|
+
const archivist = this.params.pendingTransactionsArchivist;
|
|
4343
|
+
const bundle3 = hydratedTransactionToPayloadBundle(transaction);
|
|
4344
|
+
await archivist.insert([
|
|
4345
|
+
bundle3
|
|
4346
|
+
]);
|
|
4347
|
+
await this.mempool.submitTransactions([
|
|
4348
|
+
transaction
|
|
4349
|
+
]);
|
|
4350
|
+
const hash = await PayloadBuilder19.hash(transaction[0]);
|
|
4351
|
+
this.logger?.info(`Broadcasted transaction with hash ${hash}`);
|
|
4352
|
+
return hash;
|
|
4353
|
+
}
|
|
4354
|
+
async createHandler() {
|
|
4355
|
+
await super.createHandler();
|
|
4356
|
+
this._mempoolRunner = await this.locator.getInstance(MempoolRunnerMoniker);
|
|
3658
4357
|
}
|
|
3659
4358
|
};
|
|
3660
4359
|
|
|
3661
4360
|
// src/simple/signer/SimpleXyoSigner.ts
|
|
3662
|
-
import { PayloadBuilder as
|
|
4361
|
+
import { PayloadBuilder as PayloadBuilder20 } from "@xyo-network/payload-builder";
|
|
3663
4362
|
import { SignedHydratedTransactionWithHashMetaZod } from "@xyo-network/xl1-protocol";
|
|
3664
4363
|
var SimpleXyoSigner = class {
|
|
3665
4364
|
static {
|
|
@@ -3680,15 +4379,105 @@ var SimpleXyoSigner = class {
|
|
|
3680
4379
|
async signTransaction(tx) {
|
|
3681
4380
|
const txBW = await signTransaction(tx[0], this._account);
|
|
3682
4381
|
return SignedHydratedTransactionWithHashMetaZod.parse([
|
|
3683
|
-
await
|
|
3684
|
-
await
|
|
4382
|
+
await PayloadBuilder20.addStorageMeta(txBW),
|
|
4383
|
+
await PayloadBuilder20.addStorageMeta(tx[1])
|
|
3685
4384
|
]);
|
|
3686
4385
|
}
|
|
3687
4386
|
};
|
|
3688
4387
|
|
|
4388
|
+
// src/simple/stakeEvents/SimpleStakeEventsViewer.ts
|
|
4389
|
+
import { isDefined as isDefined20 } from "@xylabs/sdk-js";
|
|
4390
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
4391
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4392
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4393
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4394
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4395
|
+
}
|
|
4396
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
4397
|
+
var SimpleStakeEventsViewer = class _SimpleStakeEventsViewer extends AbstractCreatableProvider {
|
|
4398
|
+
static {
|
|
4399
|
+
__name(this, "SimpleStakeEventsViewer");
|
|
4400
|
+
}
|
|
4401
|
+
static defaultMoniker = StakeEventsViewerMoniker;
|
|
4402
|
+
static monikers = [
|
|
4403
|
+
StakeEventsViewerMoniker
|
|
4404
|
+
];
|
|
4405
|
+
moniker = _SimpleStakeEventsViewer.defaultMoniker;
|
|
4406
|
+
get positions() {
|
|
4407
|
+
return this.params.positions;
|
|
4408
|
+
}
|
|
4409
|
+
positionCount(range) {
|
|
4410
|
+
return this.positionsFromRange(range).length;
|
|
4411
|
+
}
|
|
4412
|
+
stakeEvents(range, { name } = {}) {
|
|
4413
|
+
const positions = this.positionsFromRange(range);
|
|
4414
|
+
const events = this.eventsFromPositions(positions);
|
|
4415
|
+
if (isDefined20(name)) {
|
|
4416
|
+
return events.filter((event) => event.name === name);
|
|
4417
|
+
}
|
|
4418
|
+
return events;
|
|
4419
|
+
}
|
|
4420
|
+
async startHandler() {
|
|
4421
|
+
await super.startHandler();
|
|
4422
|
+
}
|
|
4423
|
+
eventsFromPositions(positions) {
|
|
4424
|
+
const events = positions.map((position) => {
|
|
4425
|
+
const events2 = [
|
|
4426
|
+
{
|
|
4427
|
+
name: "StakeAdded",
|
|
4428
|
+
time: position.addBlock,
|
|
4429
|
+
args: {
|
|
4430
|
+
staker: position.staker,
|
|
4431
|
+
staked: position.staked,
|
|
4432
|
+
amount: position.amount,
|
|
4433
|
+
id: position.id
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
];
|
|
4437
|
+
if (position.removeBlock !== 0) {
|
|
4438
|
+
events2.push({
|
|
4439
|
+
name: "StakeRemoved",
|
|
4440
|
+
time: position.removeBlock,
|
|
4441
|
+
args: {
|
|
4442
|
+
staker: position.staker,
|
|
4443
|
+
staked: position.staked,
|
|
4444
|
+
amount: position.amount,
|
|
4445
|
+
id: position.id
|
|
4446
|
+
}
|
|
4447
|
+
});
|
|
4448
|
+
}
|
|
4449
|
+
if (position.withdrawBlock !== 0) {
|
|
4450
|
+
events2.push({
|
|
4451
|
+
name: "StakeWithdrawn",
|
|
4452
|
+
time: position.withdrawBlock,
|
|
4453
|
+
args: {
|
|
4454
|
+
staker: position.staker,
|
|
4455
|
+
staked: position.staked,
|
|
4456
|
+
amount: position.amount,
|
|
4457
|
+
id: position.id
|
|
4458
|
+
}
|
|
4459
|
+
});
|
|
4460
|
+
}
|
|
4461
|
+
return events2;
|
|
4462
|
+
});
|
|
4463
|
+
return events.flat();
|
|
4464
|
+
}
|
|
4465
|
+
positionsFromRange(range) {
|
|
4466
|
+
const startBlock = range[0];
|
|
4467
|
+
const endBlock = range[1] === "latest" ? Number.MAX_SAFE_INTEGER : range[1];
|
|
4468
|
+
const filteredPositions = this.positions?.filter((position) => {
|
|
4469
|
+
return position.addBlock <= endBlock && (position.removeBlock === 0 || position.removeBlock >= startBlock);
|
|
4470
|
+
}) ?? [];
|
|
4471
|
+
return filteredPositions;
|
|
4472
|
+
}
|
|
4473
|
+
};
|
|
4474
|
+
SimpleStakeEventsViewer = _ts_decorate9([
|
|
4475
|
+
creatableProvider()
|
|
4476
|
+
], SimpleStakeEventsViewer);
|
|
4477
|
+
|
|
3689
4478
|
// src/simple/timesync/SimpleTimeSyncViewer.ts
|
|
3690
|
-
import { asHash as asHash6, assertEx as
|
|
3691
|
-
import { asTimePayload, asXL1BlockNumber as
|
|
4479
|
+
import { asHash as asHash6, assertEx as assertEx29, isDefined as isDefined21 } from "@xylabs/sdk-js";
|
|
4480
|
+
import { asTimePayload as asTimePayload2, asXL1BlockNumber as asXL1BlockNumber11, TimeSchema } from "@xyo-network/xl1-protocol";
|
|
3692
4481
|
var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatableProvider {
|
|
3693
4482
|
static {
|
|
3694
4483
|
__name(this, "SimpleTimeSyncViewer");
|
|
@@ -3698,8 +4487,9 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
3698
4487
|
TimeSyncViewerMoniker
|
|
3699
4488
|
];
|
|
3700
4489
|
moniker = _SimpleTimeSyncViewer.defaultMoniker;
|
|
4490
|
+
_blockViewer;
|
|
3701
4491
|
get blockViewer() {
|
|
3702
|
-
return this.
|
|
4492
|
+
return this._blockViewer;
|
|
3703
4493
|
}
|
|
3704
4494
|
get ethProvider() {
|
|
3705
4495
|
return this.params.ethProvider;
|
|
@@ -3707,10 +4497,10 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
3707
4497
|
async convertTime(fromDomain, toDomain, from) {
|
|
3708
4498
|
switch (fromDomain) {
|
|
3709
4499
|
case "xl1": {
|
|
3710
|
-
const [block, payloads] =
|
|
4500
|
+
const [block, payloads] = assertEx29(await this.blockViewer.blockByNumber(asXL1BlockNumber11(from, true)), () => "Block not found");
|
|
3711
4501
|
const timeSchemaIndex = block.payload_schemas.indexOf(TimeSchema);
|
|
3712
4502
|
const hash = timeSchemaIndex === -1 ? void 0 : block.payload_hashes[timeSchemaIndex];
|
|
3713
|
-
const timePayload =
|
|
4503
|
+
const timePayload = asTimePayload2(isDefined21(hash) ? payloads.find((p) => p._hash === hash) : void 0);
|
|
3714
4504
|
if (timePayload === void 0) return 0;
|
|
3715
4505
|
switch (toDomain) {
|
|
3716
4506
|
case "xl1": {
|
|
@@ -3732,6 +4522,10 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
3732
4522
|
}
|
|
3733
4523
|
}
|
|
3734
4524
|
}
|
|
4525
|
+
async createHandler() {
|
|
4526
|
+
await super.createHandler();
|
|
4527
|
+
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker);
|
|
4528
|
+
}
|
|
3735
4529
|
async currentTime(domain) {
|
|
3736
4530
|
switch (domain) {
|
|
3737
4531
|
case "xl1": {
|
|
@@ -3773,10 +4567,10 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
3773
4567
|
];
|
|
3774
4568
|
}
|
|
3775
4569
|
case "ethereum": {
|
|
3776
|
-
const provider =
|
|
4570
|
+
const provider = assertEx29(this.ethProvider, () => "Ethereum provider not configured");
|
|
3777
4571
|
const blockNumber = await provider.getBlockNumber() ?? 0;
|
|
3778
4572
|
const block = await provider.getBlock(blockNumber);
|
|
3779
|
-
const blockHash = asHash6(
|
|
4573
|
+
const blockHash = asHash6(assertEx29(block?.hash, () => "Block hash not found"), true);
|
|
3780
4574
|
return [
|
|
3781
4575
|
blockNumber,
|
|
3782
4576
|
blockHash
|
|
@@ -3787,21 +4581,126 @@ var SimpleTimeSyncViewer = class _SimpleTimeSyncViewer extends AbstractCreatable
|
|
|
3787
4581
|
}
|
|
3788
4582
|
}
|
|
3789
4583
|
}
|
|
3790
|
-
currentTimePayload() {
|
|
3791
|
-
|
|
4584
|
+
async currentTimePayload() {
|
|
4585
|
+
const [xl1, xl1Hash] = await this.currentTimeAndHash("xl1");
|
|
4586
|
+
const timePayload = {
|
|
4587
|
+
schema: TimeSchema,
|
|
4588
|
+
// this is for the previous block
|
|
4589
|
+
xl1,
|
|
4590
|
+
// this is for the previous block
|
|
4591
|
+
xl1Hash: assertEx29(xl1Hash, () => "No xl1 hash available from time sync service"),
|
|
4592
|
+
epoch: Date.now()
|
|
4593
|
+
};
|
|
4594
|
+
if (isDefined21(this.ethProvider)) {
|
|
4595
|
+
const [ethereum, ethHashOrNull] = await this.currentTimeAndHash("ethereum");
|
|
4596
|
+
const ethereumHash = asHash6(ethHashOrNull, () => "No ethereum hash available from time sync service");
|
|
4597
|
+
timePayload.ethereum = ethereum;
|
|
4598
|
+
timePayload.ethereumHash = ethereumHash;
|
|
4599
|
+
}
|
|
4600
|
+
return timePayload;
|
|
4601
|
+
}
|
|
4602
|
+
};
|
|
4603
|
+
|
|
4604
|
+
// src/status/ServiceStatus.ts
|
|
4605
|
+
var LoggerStatusReporter = class {
|
|
4606
|
+
static {
|
|
4607
|
+
__name(this, "LoggerStatusReporter");
|
|
4608
|
+
}
|
|
4609
|
+
logger;
|
|
4610
|
+
statusMap = {};
|
|
4611
|
+
constructor(logger) {
|
|
4612
|
+
this.logger = logger;
|
|
4613
|
+
}
|
|
4614
|
+
report(name, status, progress) {
|
|
4615
|
+
this.statusMap[name] = status;
|
|
4616
|
+
const starting = Object.entries(this.statusMap).map(([, value]) => value === "starting" ? 1 : 0).reduce((a, b) => a + b, 0);
|
|
4617
|
+
const started = Object.entries(this.statusMap).map(([, value]) => value === "started" ? 1 : 0).reduce((a, b) => a + b, 0);
|
|
4618
|
+
this.logger.info(`${started}/${starting + started} ${name} status: ${status}`, {
|
|
4619
|
+
progress
|
|
4620
|
+
});
|
|
4621
|
+
}
|
|
4622
|
+
};
|
|
4623
|
+
|
|
4624
|
+
// src/status/RuntimeStatusMonitor.ts
|
|
4625
|
+
var statusPriority = {
|
|
4626
|
+
error: 0,
|
|
4627
|
+
stopped: 1,
|
|
4628
|
+
stopping: 2,
|
|
4629
|
+
creating: 3,
|
|
4630
|
+
created: 4,
|
|
4631
|
+
starting: 5,
|
|
4632
|
+
started: 6
|
|
4633
|
+
};
|
|
4634
|
+
var SENTINEL_STATUS = "starting";
|
|
4635
|
+
var reduceToMinimumStatus = /* @__PURE__ */ __name((statuses) => {
|
|
4636
|
+
let minStatus = SENTINEL_STATUS;
|
|
4637
|
+
let minPriority = Infinity;
|
|
4638
|
+
for (const status of statuses) {
|
|
4639
|
+
const priority = statusPriority[status];
|
|
4640
|
+
if (priority < minPriority) {
|
|
4641
|
+
minPriority = priority;
|
|
4642
|
+
minStatus = status;
|
|
4643
|
+
}
|
|
4644
|
+
}
|
|
4645
|
+
return minStatus;
|
|
4646
|
+
}, "reduceToMinimumStatus");
|
|
4647
|
+
var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
4648
|
+
static {
|
|
4649
|
+
__name(this, "RuntimeStatusMonitor");
|
|
4650
|
+
}
|
|
4651
|
+
globalTransitions = [];
|
|
4652
|
+
transitions = [];
|
|
4653
|
+
getGlobalStatus() {
|
|
4654
|
+
if (Object.keys(this.statusMap).length === 0) return SENTINEL_STATUS;
|
|
4655
|
+
return reduceToMinimumStatus(Object.values(this.statusMap));
|
|
4656
|
+
}
|
|
4657
|
+
getStatus(name) {
|
|
4658
|
+
return this.statusMap[name];
|
|
4659
|
+
}
|
|
4660
|
+
onGlobalTransition(match, handler) {
|
|
4661
|
+
this.globalTransitions.push({
|
|
4662
|
+
...match,
|
|
4663
|
+
handler
|
|
4664
|
+
});
|
|
4665
|
+
}
|
|
4666
|
+
/**
|
|
4667
|
+
* Register a callback to be called on a specific transition.
|
|
4668
|
+
*/
|
|
4669
|
+
onTransition(match, handler) {
|
|
4670
|
+
this.transitions.push({
|
|
4671
|
+
...match,
|
|
4672
|
+
handler
|
|
4673
|
+
});
|
|
4674
|
+
}
|
|
4675
|
+
report(name, status, progress) {
|
|
4676
|
+
const previous = this.statusMap[name];
|
|
4677
|
+
const previousGlobal = this.getGlobalStatus();
|
|
4678
|
+
super.report(name, status, progress);
|
|
4679
|
+
if (previous === status) return;
|
|
4680
|
+
this.runTransitions(this.transitions, previous, status, name);
|
|
4681
|
+
const globalStatus = this.getGlobalStatus();
|
|
4682
|
+
if (previousGlobal === globalStatus) return;
|
|
4683
|
+
this.runTransitions(this.globalTransitions, previousGlobal, globalStatus);
|
|
4684
|
+
}
|
|
4685
|
+
runTransitions(transitions, prev, next, name) {
|
|
4686
|
+
for (const { from, to, name: matchName, handler } of transitions) {
|
|
4687
|
+
if ((matchName === void 0 || matchName === name) && (from === void 0 || from === prev) && (to === void 0 || to === next)) {
|
|
4688
|
+
handler(prev, next);
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
3792
4691
|
}
|
|
3793
4692
|
};
|
|
3794
4693
|
|
|
3795
4694
|
// src/time/primitives/xl1BlockNumberToEthBlockNumber.ts
|
|
3796
|
-
import { assertEx as
|
|
3797
|
-
import { asTimePayload as
|
|
4695
|
+
import { assertEx as assertEx30 } from "@xylabs/sdk-js";
|
|
4696
|
+
import { asTimePayload as asTimePayload3, TimeSchema as TimeSchema2 } from "@xyo-network/xl1-protocol";
|
|
3798
4697
|
async function xl1BlockNumberToEthBlockNumber(context, xl1BlockNumber) {
|
|
3799
4698
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber);
|
|
3800
4699
|
const hydratedBlock = await hydrateBlock(context.store, blockHash);
|
|
3801
|
-
const timePayload =
|
|
4700
|
+
const timePayload = asTimePayload3(hydratedBlock[1].find((p) => p.schema === TimeSchema2), {
|
|
3802
4701
|
required: true
|
|
3803
4702
|
});
|
|
3804
|
-
return
|
|
4703
|
+
return assertEx30(timePayload.ethereum, () => "No ethereum timestamp found on block");
|
|
3805
4704
|
}
|
|
3806
4705
|
__name(xl1BlockNumberToEthBlockNumber, "xl1BlockNumberToEthBlockNumber");
|
|
3807
4706
|
|
|
@@ -3842,6 +4741,7 @@ export {
|
|
|
3842
4741
|
BalancesStepSummarySchema,
|
|
3843
4742
|
BasisPointsZod,
|
|
3844
4743
|
BlockRewardViewerMoniker,
|
|
4744
|
+
BlockRunnerMoniker,
|
|
3845
4745
|
BlockValidationError,
|
|
3846
4746
|
BlockViewerMoniker,
|
|
3847
4747
|
BridgeConfigZod,
|
|
@@ -3851,7 +4751,6 @@ export {
|
|
|
3851
4751
|
ChainContractViewerMoniker,
|
|
3852
4752
|
ChainIndexingServiceStateSchema,
|
|
3853
4753
|
ChainStakeViewerMoniker,
|
|
3854
|
-
ChainViewerMoniker,
|
|
3855
4754
|
ConfigZod,
|
|
3856
4755
|
DEFAULT_WALLET_PATH,
|
|
3857
4756
|
DataLakeRunnerMoniker,
|
|
@@ -3866,9 +4765,11 @@ export {
|
|
|
3866
4765
|
HydratedBlockValidationError,
|
|
3867
4766
|
HydratedCache,
|
|
3868
4767
|
JSONSchemaMetaSchema,
|
|
4768
|
+
LoggerStatusReporter,
|
|
3869
4769
|
LruCacheMap,
|
|
3870
4770
|
MemoryMap,
|
|
3871
4771
|
MemoryPermissionsStore,
|
|
4772
|
+
MempoolRunnerMoniker,
|
|
3872
4773
|
MempoolViewerMoniker,
|
|
3873
4774
|
MnemonicStringZod,
|
|
3874
4775
|
NetworkStakeStepRewardViewerMoniker,
|
|
@@ -3884,15 +4785,17 @@ export {
|
|
|
3884
4785
|
ProviderFactoryLocator,
|
|
3885
4786
|
QualifiedZod,
|
|
3886
4787
|
RewardMultipliers,
|
|
4788
|
+
RuntimeStatusMonitor,
|
|
3887
4789
|
SchemasStepSummarySchema,
|
|
3888
4790
|
SimpleAccountBalanceViewer,
|
|
3889
4791
|
SimpleBlockRewardViewer,
|
|
3890
4792
|
SimpleBlockViewer,
|
|
3891
|
-
SimpleChainStakeViewer,
|
|
3892
4793
|
SimpleDataLakeRunner,
|
|
3893
4794
|
SimpleDataLakeViewer,
|
|
3894
4795
|
SimpleMempoolRunner,
|
|
3895
4796
|
SimpleMempoolViewer,
|
|
4797
|
+
SimpleStakeEventsViewer,
|
|
4798
|
+
SimpleStakeViewer,
|
|
3896
4799
|
SimpleTimeSyncViewer,
|
|
3897
4800
|
SimpleXyoClient,
|
|
3898
4801
|
SimpleXyoGateway,
|
|
@@ -3911,6 +4814,7 @@ export {
|
|
|
3911
4814
|
StepViewerMoniker,
|
|
3912
4815
|
TODO,
|
|
3913
4816
|
TimeSyncViewerMoniker,
|
|
4817
|
+
TransactionBuilder,
|
|
3914
4818
|
TransferBalanceViewerMoniker,
|
|
3915
4819
|
TransfersStepSummarySchema,
|
|
3916
4820
|
TypedDataDomainZod,
|
|
@@ -3925,8 +4829,14 @@ export {
|
|
|
3925
4829
|
XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS,
|
|
3926
4830
|
XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS,
|
|
3927
4831
|
Xl1CommonConfigSchema,
|
|
4832
|
+
XyoConnectionMoniker,
|
|
4833
|
+
XyoRunnerMoniker,
|
|
3928
4834
|
XyoViewerMoniker,
|
|
4835
|
+
activeStakeAtTimeByAddress,
|
|
4836
|
+
activeStakeAtTimeByPosition,
|
|
3929
4837
|
allHashesPresent,
|
|
4838
|
+
allStakersForRange,
|
|
4839
|
+
allStakersForStep,
|
|
3930
4840
|
asAddressPairPayload,
|
|
3931
4841
|
asBalancesStepSummary,
|
|
3932
4842
|
asBalancesStepSummaryWithStorageMeta,
|
|
@@ -3944,20 +4854,28 @@ export {
|
|
|
3944
4854
|
balancesSummary,
|
|
3945
4855
|
blockFromBlockNumber,
|
|
3946
4856
|
blockPayloadsFromHydratedBlock,
|
|
4857
|
+
blockRangeSteps,
|
|
4858
|
+
buildRandomTransaction,
|
|
3947
4859
|
buildTransaction,
|
|
3948
4860
|
buildUnsignedTransaction,
|
|
3949
4861
|
bundledPayloadToHydratedBlock,
|
|
3950
4862
|
bundledPayloadToHydratedTransaction,
|
|
3951
4863
|
calculateFramesFromRange,
|
|
4864
|
+
chainStepRewardAddress,
|
|
3952
4865
|
completedStepRewardAddress,
|
|
3953
4866
|
confirmSubmittedTransaction,
|
|
3954
4867
|
contextCache,
|
|
3955
4868
|
crackOperation,
|
|
3956
4869
|
crackOperations,
|
|
3957
4870
|
creatableProvider,
|
|
4871
|
+
createDeclarationIntent,
|
|
4872
|
+
createTransferPayload,
|
|
3958
4873
|
deepCalculateFramesFromRange,
|
|
3959
4874
|
derivedReceiveAddress,
|
|
3960
4875
|
elevatedPayloads,
|
|
4876
|
+
externalBlockNumberFromXL1BlockNumber,
|
|
4877
|
+
externalBlockRangeFromStep,
|
|
4878
|
+
externalBlockRangeFromXL1BlockRange,
|
|
3961
4879
|
extractElevatedHashes,
|
|
3962
4880
|
extractElevatedHashesFromScript,
|
|
3963
4881
|
findMostRecentBlock,
|
|
@@ -4001,10 +4919,15 @@ export {
|
|
|
4001
4919
|
isZodError,
|
|
4002
4920
|
labeledCreatableProvider,
|
|
4003
4921
|
labeledCreatableProviderFactory,
|
|
4922
|
+
mapToMapType,
|
|
4923
|
+
mergeTransfers,
|
|
4924
|
+
mergedAddRemoveStakeEventsByPosition,
|
|
4004
4925
|
netBalancesForPayloads,
|
|
4005
4926
|
netSchemasForPayloads,
|
|
4006
4927
|
netTransfersForPayloads,
|
|
4928
|
+
networkStakeStepRewardPositionWeight,
|
|
4007
4929
|
parseSignedBigInt,
|
|
4930
|
+
payloadMapFromStore,
|
|
4008
4931
|
prettifyZodError,
|
|
4009
4932
|
readPayloadMapFromStore,
|
|
4010
4933
|
registerCreatableProviderFactories,
|
|
@@ -4015,7 +4938,12 @@ export {
|
|
|
4015
4938
|
signEIP712Message,
|
|
4016
4939
|
signTransaction,
|
|
4017
4940
|
stepBlockRange,
|
|
4941
|
+
stepRewardBlock,
|
|
4942
|
+
stepRewardTotal,
|
|
4018
4943
|
stepTransferIndex,
|
|
4944
|
+
stepsRewardTotal,
|
|
4945
|
+
stepsRewardTotalGenesisPeriod,
|
|
4946
|
+
stepsRewardTotalRange,
|
|
4019
4947
|
timeBudget,
|
|
4020
4948
|
toPositiveBigInt,
|
|
4021
4949
|
toSignedBigInt,
|
|
@@ -4039,6 +4967,7 @@ export {
|
|
|
4039
4967
|
unflattenHydratedBlock,
|
|
4040
4968
|
unflattenHydratedTransaction,
|
|
4041
4969
|
verifyEIP712Message,
|
|
4970
|
+
weightedStakeForRangeByPosition,
|
|
4042
4971
|
withContextCacheResponse,
|
|
4043
4972
|
xl1BlockNumberToEthBlockNumber
|
|
4044
4973
|
};
|