@xyo-network/xl1-protocol-sdk 1.17.7 → 1.18.0
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 +104 -1
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +27 -10
- 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 +8 -5
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Log.d.ts +1 -1
- package/dist/neutral/config/Services.d.ts +2 -2
- package/dist/neutral/config/Services.d.ts.map +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 +1887 -632
- 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/ChainQualification.d.ts +42 -0
- package/dist/neutral/model/ChainQualification.d.ts.map +1 -0
- package/dist/neutral/model/PayloadBundle/bundledPayloadToHydratedTransaction.d.ts +2 -2
- package/dist/neutral/model/PayloadBundle/bundledPayloadToHydratedTransaction.d.ts.map +1 -1
- package/dist/neutral/model/index.d.ts +1 -1
- package/dist/neutral/model/index.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/getWindowedChain.d.ts +26 -0
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -0
- package/dist/neutral/primitives/chain/index.d.ts +4 -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 +7 -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/primitives/uncle/findBestUncle.d.ts +24 -0
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/findUncles.d.ts +26 -0
- package/dist/neutral/primitives/uncle/findUncles.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/index.d.ts +4 -0
- package/dist/neutral/primitives/uncle/index.d.ts.map +1 -0
- package/dist/neutral/primitives/uncle/scoreUncle.d.ts +3 -0
- package/dist/neutral/primitives/uncle/scoreUncle.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 +16 -13
- 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 +65 -21
- 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/blockValidation/SimpleBlockValidationViewer.d.ts +31 -0
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -0
- package/dist/neutral/simple/blockValidation/index.d.ts +2 -0
- package/dist/neutral/simple/blockValidation/index.d.ts.map +1 -0
- 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 +6 -3
- 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 +2 -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 -5
- 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/summary/primitives/balances/balancesSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/balances/balancesSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/schemas/schemasSummary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts +2 -2
- package/dist/neutral/summary/primitives/transfers/transfersSummary.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/AccountBalance.d.ts +35 -15
- package/dist/neutral/viewers/AccountBalance.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/BlockValidation.d.ts +54 -0
- package/dist/neutral/viewers/BlockValidation.d.ts.map +1 -0
- 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/StakeIntent.d.ts +2 -2
- package/dist/neutral/viewers/StakeIntent.d.ts.map +1 -1
- package/dist/neutral/viewers/TransactionValidation.d.ts +35 -0
- package/dist/neutral/viewers/TransactionValidation.d.ts.map +1 -0
- package/dist/neutral/viewers/index.d.ts +2 -1
- package/dist/neutral/viewers/index.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/CreatableProvider/AbstractCreatableProvider.ts +60 -3
- package/src/CreatableProvider/CreatableProvider.ts +38 -11
- package/src/CreatableProvider/CreatableProviderRegistry.ts +10 -5
- package/src/CreatableProvider/ProviderFactory.ts +73 -10
- package/src/CreatableProvider/ProviderFactoryLocator.ts +79 -19
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +33 -10
- package/src/config/Bridge.ts +22 -4
- package/src/config/Chain.ts +2 -2
- package/src/config/Services.ts +4 -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/ChainQualification.ts +33 -0
- package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +2 -2
- package/src/model/index.ts +1 -1
- 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/getWindowedChain.ts +23 -0
- package/src/primitives/chain/index.ts +3 -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 +7 -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/primitives/uncle/findBestUncle.ts +8 -0
- package/src/primitives/uncle/findUncles.ts +75 -0
- package/src/primitives/uncle/index.ts +3 -0
- package/src/primitives/uncle/scoreUncle.ts +6 -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 +16 -15
- 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 +65 -42
- package/src/simple/block/SimpleBlockViewer.ts +47 -14
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +126 -0
- package/src/simple/blockValidation/index.ts +1 -0
- package/src/simple/chainStake/{SimpleChainStakeViewer.ts → SimpleStakeViewer.ts} +11 -16
- package/src/simple/chainStake/index.ts +1 -1
- package/src/simple/datalake/AbstractSimpleDataLake.ts +19 -18
- package/src/simple/datalake/SimpleDataLakeRunner.ts +4 -3
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -19
- package/src/simple/index.ts +2 -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 +27 -6
- 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 -5
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +2 -3
- package/src/summary/primitives/balances/balancesSummary.ts +12 -12
- package/src/summary/primitives/schemas/schemasSummary.ts +12 -10
- package/src/summary/primitives/transfers/transfersSummary.ts +14 -16
- 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/AccountBalance.ts +22 -14
- package/src/viewers/Block.ts +6 -1
- package/src/viewers/BlockValidation.ts +47 -0
- package/src/viewers/ChainStakeViewer.ts +1 -2
- package/src/viewers/Fork.ts +0 -1
- package/src/viewers/Stake.ts +0 -1
- package/src/viewers/StakeIntent.ts +2 -2
- package/src/viewers/TransactionValidation.ts +35 -0
- package/src/viewers/index.ts +2 -1
- package/dist/neutral/model/Qualified.d.ts +0 -6
- package/dist/neutral/model/Qualified.d.ts.map +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/model/Qualified.ts +0 -9
- 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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
+
import type {
|
|
3
|
+
AttoXL1, StepIdentity, XL1BlockRange, XL1RangeMultipliers,
|
|
4
|
+
} from '@xyo-network/xl1-protocol'
|
|
5
|
+
import {
|
|
6
|
+
asAttoXL1, asXL1BlockRange, isTransfer,
|
|
7
|
+
XYO_STEP_REWARD_ADDRESS,
|
|
8
|
+
} from '@xyo-network/xl1-protocol'
|
|
9
|
+
|
|
10
|
+
import { type ChainContextRead, withContextCacheResponse } from '../../../model/index.ts'
|
|
11
|
+
import { netTransfersForPayloads } from '../../../payloads/index.ts'
|
|
12
|
+
import { stepBlockRange, stepTransferIndex } from '../../step/index.ts'
|
|
13
|
+
import { stepRewardBlock } from './stepRewardBlock.ts'
|
|
14
|
+
|
|
15
|
+
function stepInRange(step: StepIdentity, range: XL1BlockRange): boolean {
|
|
16
|
+
const stepRange = stepBlockRange(step)
|
|
17
|
+
return ((stepRange[0] >= range[0]) && (stepRange[1] <= range[1]))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function stepRewardTotal(context: ChainContextRead, { block, step }: StepIdentity, multipliers: XL1RangeMultipliers): Promise<AttoXL1> {
|
|
21
|
+
const cacheKey = `${block}|${step}|${isDefined(multipliers)}`
|
|
22
|
+
return await withContextCacheResponse(context, 'stepRewardTotal', cacheKey, async () => {
|
|
23
|
+
const [blockBw, payloads] = await stepRewardBlock(context, { block, step })
|
|
24
|
+
assertEx(blockBw.block === block, () => `Block Mismatch: expected ${block}, got ${blockBw.block}`)
|
|
25
|
+
const [transferIndex] = stepTransferIndex(block, step)
|
|
26
|
+
const stepTransfer = assertEx(
|
|
27
|
+
payloads.find(p => isTransfer(p) && p.from === XYO_STEP_REWARD_ADDRESS),
|
|
28
|
+
() => `No step transfer found for step ${step} at block ${block} (${blockBw._hash})`,
|
|
29
|
+
)
|
|
30
|
+
const rewards = assertEx(
|
|
31
|
+
netTransfersForPayloads([stepTransfer])[XYO_STEP_REWARD_ADDRESS],
|
|
32
|
+
() => `No rewards found for step reward address ${XYO_STEP_REWARD_ADDRESS} at block ${block} (${blockBw._hash})`,
|
|
33
|
+
)
|
|
34
|
+
const sortedTransfers = (Object.entries(rewards)).toSorted(([,a], [,b]) => a > b ? -1 : a < b ? 1 : 0)
|
|
35
|
+
let result = asAttoXL1(sortedTransfers[transferIndex][1] * -1n)
|
|
36
|
+
for (const [rangeKey, [numerator, denominator]] of Object.entries(multipliers)) {
|
|
37
|
+
const rangeParts = rangeKey.split('|').map(Number)
|
|
38
|
+
const range: XL1BlockRange = asXL1BlockRange([rangeParts[0], rangeParts[1]], { name: 'stepRewardTotal' })
|
|
39
|
+
if (stepInRange({ block, step }, range)) {
|
|
40
|
+
result = asAttoXL1(result + result * numerator / denominator)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AttoXL1, StepIdentity, XL1BlockRange,
|
|
3
|
+
XL1RangeMultipliers,
|
|
4
|
+
} from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { asAttoXL1, asXL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
6
|
+
|
|
7
|
+
import { XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK } from '../../../constants.ts'
|
|
8
|
+
import type { ChainContextRead } from '../../../model/index.ts'
|
|
9
|
+
import { blockRangeSteps } from '../../block/index.ts'
|
|
10
|
+
import { stepRewardTotal } from './stepRewardTotal.ts'
|
|
11
|
+
|
|
12
|
+
export async function stepsRewardTotalGenesisPeriod(context: ChainContextRead, multipliers: XL1RangeMultipliers, stepSizes?: number[]): Promise<AttoXL1> {
|
|
13
|
+
const range = asXL1BlockRange([0, XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK], { name: 'stepsRewardTotalGenesisPeriod' })
|
|
14
|
+
return await stepsRewardTotalRange(context, range, stepSizes, multipliers)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function stepsRewardTotalRange(
|
|
18
|
+
context: ChainContextRead,
|
|
19
|
+
range: XL1BlockRange,
|
|
20
|
+
stepSizes: number[] = [3, 4, 5, 6],
|
|
21
|
+
multipliers: XL1RangeMultipliers,
|
|
22
|
+
): Promise<AttoXL1> {
|
|
23
|
+
const steps = blockRangeSteps(range, stepSizes)
|
|
24
|
+
return await stepsRewardTotal(context, steps, multipliers)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function stepsRewardTotal(context: ChainContextRead, steps: StepIdentity[], multipliers: XL1RangeMultipliers): Promise<AttoXL1> {
|
|
28
|
+
let totalRewards = 0n
|
|
29
|
+
for (const step of steps) {
|
|
30
|
+
const stepTotal = await stepRewardTotal(context, step, multipliers)
|
|
31
|
+
totalRewards += stepTotal
|
|
32
|
+
}
|
|
33
|
+
return asAttoXL1(totalRewards)
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertEx, isArray } from '@xylabs/sdk-js'
|
|
2
|
+
import type { BlockNumber, XL1BlockNumber } from '@xyo-network/xl1-protocol'
|
|
3
|
+
import {
|
|
4
|
+
asBlockNumber, asTimePayload, isTimePayload,
|
|
5
|
+
} from '@xyo-network/xl1-protocol'
|
|
6
|
+
|
|
7
|
+
import { type BaseContext, withContextCacheResponse } from '../../../model/index.ts'
|
|
8
|
+
import type { BlockViewer } from '../../../viewers/index.ts'
|
|
9
|
+
|
|
10
|
+
const functionName = 'externalBlockNumberFromXL1BlockNumber' as const
|
|
11
|
+
|
|
12
|
+
export async function externalBlockNumberFromXL1BlockNumber(
|
|
13
|
+
context: BaseContext,
|
|
14
|
+
blockViewer: BlockViewer,
|
|
15
|
+
xl1BlockNumber: XL1BlockNumber,
|
|
16
|
+
externalTimeName: 'ethereum' | 'epoch',
|
|
17
|
+
externalGenesisTime?: BlockNumber,
|
|
18
|
+
timeBudgetMs = 2000,
|
|
19
|
+
): Promise<BlockNumber> {
|
|
20
|
+
const cacheKey = `${xl1BlockNumber}-${externalTimeName}-${externalGenesisTime ?? 'default'}`
|
|
21
|
+
return await withContextCacheResponse(context, functionName, cacheKey, async () => {
|
|
22
|
+
const [, payloads = []] = await blockViewer.blockByNumber(xl1BlockNumber) ?? []
|
|
23
|
+
assertEx(isArray(payloads))
|
|
24
|
+
const timePayload = asTimePayload(payloads.find(isTimePayload))
|
|
25
|
+
// the default here is the block number we know where the xl1 chain started running (first external staking - 1)
|
|
26
|
+
return asBlockNumber(
|
|
27
|
+
timePayload?.[externalTimeName] ?? externalGenesisTime ?? 23_372_716,
|
|
28
|
+
{ name: functionName },
|
|
29
|
+
) // default is xl1 mainnet genesis time
|
|
30
|
+
}, { timeBudgetMs })
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BlockRange, StepIdentity } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
import { toStepIdentityString } from '../../../block/index.ts'
|
|
4
|
+
import { type BaseContext, withContextCacheResponse } from '../../../model/index.ts'
|
|
5
|
+
import type { BlockViewer } from '../../../viewers/index.ts'
|
|
6
|
+
import { stepBlockRange } from '../../step/index.ts'
|
|
7
|
+
import { externalBlockRangeFromXL1BlockRange } from './externalBlockRangeFromXL1BlockRange.ts'
|
|
8
|
+
|
|
9
|
+
export async function externalBlockRangeFromStep(
|
|
10
|
+
context: BaseContext,
|
|
11
|
+
blockViewer: BlockViewer,
|
|
12
|
+
stepIdentity: StepIdentity,
|
|
13
|
+
): Promise<BlockRange> {
|
|
14
|
+
const cacheKey = toStepIdentityString(stepIdentity)
|
|
15
|
+
return await withContextCacheResponse(context, 'externalBlockRangeFromStep', cacheKey, async () => {
|
|
16
|
+
const xl1BlockRange = stepBlockRange(stepIdentity)
|
|
17
|
+
return await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange)
|
|
18
|
+
}, { timeBudgetMs: 1000 })
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BlockRange, XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
import type { BaseContext } from '../../../model/index.ts'
|
|
4
|
+
import type { BlockViewer } from '../../../viewers/index.ts'
|
|
5
|
+
import { externalBlockNumberFromXL1BlockNumber } from './externalBlockNumberFromXL1BlockNumber.ts'
|
|
6
|
+
|
|
7
|
+
export async function externalBlockRangeFromXL1BlockRange(
|
|
8
|
+
context: BaseContext,
|
|
9
|
+
blockViewer: BlockViewer,
|
|
10
|
+
xl1BlockRange: XL1BlockRange,
|
|
11
|
+
externalTimeName: 'ethereum' = 'ethereum',
|
|
12
|
+
): Promise<BlockRange> {
|
|
13
|
+
const start = await externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockRange[0], externalTimeName)
|
|
14
|
+
const end = await externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockRange[1], externalTimeName)
|
|
15
|
+
return [start, end]
|
|
16
|
+
}
|
package/src/primitives/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
export * from './block/index.ts'
|
|
2
|
+
export * from './chain/index.ts'
|
|
3
|
+
export * from './mapToMapType.ts'
|
|
4
|
+
export * from './payload/index.ts'
|
|
1
5
|
export * from './readPayloadMapFromStore.ts'
|
|
2
6
|
export * from './rewardFromBlockNumber.ts'
|
|
7
|
+
export * from './rewards/index.ts'
|
|
8
|
+
export * from './stake/index.ts'
|
|
3
9
|
export * from './state/index.ts'
|
|
4
10
|
export * from './step/index.ts'
|
|
5
11
|
export * from './timeBudget.ts'
|
|
6
12
|
export * from './transaction/index.ts'
|
|
13
|
+
export * from './uncle/index.ts'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import type { SyncIterableMap } from '../map/index.ts'
|
|
4
|
+
|
|
5
|
+
export function mapToMapType<K extends {}, V extends {}>(map: Map<K, V> | SyncIterableMap<K, V>): SyncIterableMap<K, V> {
|
|
6
|
+
return {
|
|
7
|
+
get: (key: K) => map.get(key),
|
|
8
|
+
has: (key: K) => map.has(key),
|
|
9
|
+
set: (key: K, value: V) => {
|
|
10
|
+
map.set(key, value)
|
|
11
|
+
},
|
|
12
|
+
setMany: (entries: [K, V][]) => {
|
|
13
|
+
for (const [key, value] of entries) {
|
|
14
|
+
map.set(key, value)
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
delete: (key: K) => map.delete(key),
|
|
18
|
+
clear: () => map.clear(),
|
|
19
|
+
getMany: (keys: K[]) => {
|
|
20
|
+
const result: V[] = []
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const value = map.get(key)
|
|
23
|
+
if (isDefined(value)) {
|
|
24
|
+
result.push(value)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result
|
|
28
|
+
},
|
|
29
|
+
[Symbol.iterator]: function* (): Iterator<[K, V]> {
|
|
30
|
+
for (const entry of map) {
|
|
31
|
+
yield entry
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mergeTransfers.ts'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
+
import { hexToBigInt, toAddress } from '@xylabs/sdk-js'
|
|
3
|
+
import type { Transfer } from '@xyo-network/xl1-protocol'
|
|
4
|
+
|
|
5
|
+
export function mergeTransfers(transfers: Transfer[]): Record<Address, Record<Address, bigint>> {
|
|
6
|
+
const result: Record<Address, Record<Address, bigint>> = {}
|
|
7
|
+
for (const transfer of transfers) {
|
|
8
|
+
result[transfer.from] = result[transfer.from] ?? {}
|
|
9
|
+
for (const [to, value] of Object.entries(transfer.transfers)) {
|
|
10
|
+
const typedTo = toAddress(to)
|
|
11
|
+
result[transfer.from][typedTo] = (result[transfer.from][typedTo] ?? 0n) + (hexToBigInt(value))
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
@@ -1,24 +1,54 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/sdk-js'
|
|
2
2
|
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
4
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
3
|
+
import type { ReadArchivist, ReadWriteArchivist } from '@xyo-network/archivist-model'
|
|
4
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
5
|
|
|
6
|
-
import { isReadArchivist } from '../block/index.ts'
|
|
7
|
-
import type { PayloadMapRead } from '../model/index.ts'
|
|
6
|
+
import { isReadArchivist, isReadWriteArchivist } from '../block/index.ts'
|
|
7
|
+
import type { PayloadMap, PayloadMapRead } from '../model/index.ts'
|
|
8
8
|
|
|
9
|
-
export function readPayloadMapFromStore<T extends Payload>(store: ReadArchivist<T> | PayloadMapRead<T
|
|
9
|
+
export function readPayloadMapFromStore<T extends Payload>(store: ReadArchivist<T> | PayloadMapRead<WithStorageMeta<T>>): PayloadMapRead<WithStorageMeta<T>> {
|
|
10
10
|
if (isReadArchivist(store)) {
|
|
11
11
|
return {
|
|
12
|
-
get: async (hash: Hash)
|
|
12
|
+
get: async (hash: Hash) => {
|
|
13
13
|
return (await store.get([hash]))[0]
|
|
14
14
|
},
|
|
15
|
-
getMany: async (hashes: Hash[])
|
|
15
|
+
getMany: async (hashes: Hash[]) => {
|
|
16
16
|
return (await store.get(hashes))
|
|
17
17
|
},
|
|
18
|
-
has: async (hash: Hash)
|
|
18
|
+
has: async (hash: Hash) => {
|
|
19
19
|
return isDefined((await store.get([hash]))[0])
|
|
20
20
|
},
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
return store
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
export function payloadMapFromStore<T extends Payload>(store: ReadWriteArchivist<T> | PayloadMap<WithStorageMeta<T>>): PayloadMap<WithStorageMeta<T>> {
|
|
27
|
+
if (isReadWriteArchivist(store)) {
|
|
28
|
+
return {
|
|
29
|
+
get: async (hash: Hash) => {
|
|
30
|
+
return (await store.get([hash]))[0]
|
|
31
|
+
},
|
|
32
|
+
getMany: async (hashes: Hash[]) => {
|
|
33
|
+
return (await store.get(hashes))
|
|
34
|
+
},
|
|
35
|
+
has: async (hash: Hash) => {
|
|
36
|
+
return isDefined((await store.get([hash]))[0])
|
|
37
|
+
},
|
|
38
|
+
clear: async () => {
|
|
39
|
+
return await store.clear()
|
|
40
|
+
},
|
|
41
|
+
delete: async (id: Hash) => {
|
|
42
|
+
await store.delete([id])
|
|
43
|
+
return true
|
|
44
|
+
},
|
|
45
|
+
set: async (_id: Hash, data: T) => {
|
|
46
|
+
await store.insert([data])
|
|
47
|
+
},
|
|
48
|
+
setMany: async (entries: [Hash, T][]) => {
|
|
49
|
+
await store.insert(entries.map(e => e[1]))
|
|
50
|
+
},
|
|
51
|
+
} satisfies PayloadMap<WithStorageMeta<T>>
|
|
52
|
+
}
|
|
53
|
+
return store
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './networkStakeStepRewardPositionWeight.ts'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type StepIdentity } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
import type { StakedChainContextRead } from '../../model/index.ts'
|
|
4
|
+
import type { BlockViewer } from '../../viewers/index.ts'
|
|
5
|
+
import { externalBlockRangeFromStep } from '../chain/time/index.ts'
|
|
6
|
+
import { weightedStakeForRangeByPosition } from '../stake/index.ts'
|
|
7
|
+
|
|
8
|
+
export async function networkStakeStepRewardPositionWeight(
|
|
9
|
+
context: StakedChainContextRead,
|
|
10
|
+
blockViewer: BlockViewer,
|
|
11
|
+
stepContext: StepIdentity,
|
|
12
|
+
position: number,
|
|
13
|
+
): Promise<bigint> {
|
|
14
|
+
const result = await weightedStakeForRangeByPosition(
|
|
15
|
+
context,
|
|
16
|
+
blockViewer,
|
|
17
|
+
await externalBlockRangeFromStep(context, blockViewer, stepContext),
|
|
18
|
+
position,
|
|
19
|
+
)
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
+
|
|
4
|
+
import type { StakeEventsViewer } from '../../viewers/index.ts'
|
|
5
|
+
import { mergedAddRemoveStakeEventsByStaker } from './mergedAddRemoveStakeEventsByStaker.ts'
|
|
6
|
+
|
|
7
|
+
export async function activeStakeAtTimeByAddress(
|
|
8
|
+
chain: StakeEventsViewer,
|
|
9
|
+
staked: Address,
|
|
10
|
+
time: number,
|
|
11
|
+
staker?: Address,
|
|
12
|
+
): Promise<bigint> {
|
|
13
|
+
const stakeEvents = (await mergedAddRemoveStakeEventsByStaker(chain, [0, time], staked, staker)).toSorted((a, b) => a.time - b.time)
|
|
14
|
+
let result = 0n
|
|
15
|
+
for (const event of stakeEvents) {
|
|
16
|
+
if (event.time > time) break
|
|
17
|
+
if (event.args.staked !== staked) continue
|
|
18
|
+
if (isDefined(staker) && (event.args.staker !== staker)) continue
|
|
19
|
+
if (event.name === 'StakeAdded') {
|
|
20
|
+
result += event.args.amount
|
|
21
|
+
} else if (event.name === 'StakeRemoved') {
|
|
22
|
+
result -= event.args.amount
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isUndefined } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import type { StakeEventsViewer } from '../../viewers/index.ts'
|
|
4
|
+
import { mergedAddRemoveStakeEventsByPosition } from './mergedAddRemoveStakeEventsByPosition.ts'
|
|
5
|
+
|
|
6
|
+
export async function activeStakeAtTimeByPosition(
|
|
7
|
+
chainStakeEvents: StakeEventsViewer,
|
|
8
|
+
externalTime: number,
|
|
9
|
+
position?: number,
|
|
10
|
+
): Promise<bigint> {
|
|
11
|
+
const stakeEvents = (await mergedAddRemoveStakeEventsByPosition(chainStakeEvents, [0, externalTime], position)).toSorted((a, b) => a.time - b.time)
|
|
12
|
+
let result = 0n
|
|
13
|
+
for (const event of stakeEvents) {
|
|
14
|
+
if (event.time > externalTime) break
|
|
15
|
+
if (isUndefined(position) || position === Number(event.args.id)) {
|
|
16
|
+
if (event.name === 'StakeAdded') {
|
|
17
|
+
result += event.args.amount
|
|
18
|
+
} else if (event.name === 'StakeRemoved') {
|
|
19
|
+
result -= event.args.amount
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Address,
|
|
3
|
+
toAddress,
|
|
4
|
+
} from '@xylabs/sdk-js'
|
|
5
|
+
|
|
6
|
+
import type { StakeEventsViewer } from '../../viewers/index.ts'
|
|
7
|
+
import { mergedAddRemoveStakeEventsByStaker } from './mergedAddRemoveStakeEventsByStaker.ts'
|
|
8
|
+
|
|
9
|
+
export async function allStakersForRange(
|
|
10
|
+
chain: StakeEventsViewer,
|
|
11
|
+
externalRange: [number, number],
|
|
12
|
+
staked: Address,
|
|
13
|
+
): Promise<Record<Address, bigint>> {
|
|
14
|
+
const mergedEvents = await mergedAddRemoveStakeEventsByStaker(chain, [0, externalRange[1]], staked)
|
|
15
|
+
const resultWithZeros: Record<Address, bigint> = {}
|
|
16
|
+
for (const event of mergedEvents) {
|
|
17
|
+
const staker = toAddress(event.args.staker)
|
|
18
|
+
resultWithZeros[staker] = resultWithZeros[staker] ?? 0n
|
|
19
|
+
if (event.name === 'StakeAdded') {
|
|
20
|
+
resultWithZeros[staker] += event.args.amount
|
|
21
|
+
} else if (event.name === 'StakeRemoved') {
|
|
22
|
+
resultWithZeros[staker] -= event.args.amount
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const nonZero = Object.entries(resultWithZeros).filter(([, amount]) => amount > 0n).map(([address]) => address)
|
|
26
|
+
const result: Record<Address, bigint> = {}
|
|
27
|
+
for (const address of nonZero) {
|
|
28
|
+
result[toAddress(address)] = resultWithZeros[toAddress(address)]
|
|
29
|
+
}
|
|
30
|
+
return result
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Address } from '@xylabs/sdk-js'
|
|
2
|
+
import type { StepIdentity } from '@xyo-network/xl1-protocol'
|
|
3
|
+
|
|
4
|
+
import type { StakedChainContextRead } from '../../model/index.ts'
|
|
5
|
+
import type { BlockViewer } from '../../viewers/index.ts'
|
|
6
|
+
import { externalBlockRangeFromXL1BlockRange } from '../chain/time/index.ts'
|
|
7
|
+
import { stepBlockRange } from '../step/index.ts'
|
|
8
|
+
import { allStakersForRange } from './allStakersForRange.ts'
|
|
9
|
+
|
|
10
|
+
export async function allStakersForStep(
|
|
11
|
+
context: StakedChainContextRead,
|
|
12
|
+
blockViewer: BlockViewer,
|
|
13
|
+
stepContext: StepIdentity,
|
|
14
|
+
staked: Address,
|
|
15
|
+
): Promise<Record<Address, bigint>> {
|
|
16
|
+
const xl1BlockRange = stepBlockRange(stepContext)
|
|
17
|
+
return await allStakersForRange(
|
|
18
|
+
context.stake.stakeEvents,
|
|
19
|
+
await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange),
|
|
20
|
+
staked,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './activeStakeAtTimeByAddress.ts'
|
|
2
|
+
export * from './activeStakeAtTimeByPosition.ts'
|
|
3
|
+
export * from './allStakersForRange.ts'
|
|
4
|
+
export * from './allStakersForStep.ts'
|
|
5
|
+
export * from './mergedAddRemoveStakeEventsByPosition.ts'
|
|
6
|
+
export * from './weightedStakeForRangeByPosition.ts'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StakeEvent, StakeEventsViewer } from '../../viewers/index.ts'
|
|
2
|
+
|
|
3
|
+
export async function mergedAddRemoveStakeEventsByPosition(
|
|
4
|
+
chainEvents: StakeEventsViewer,
|
|
5
|
+
range: [number, number],
|
|
6
|
+
position?: number,
|
|
7
|
+
): Promise<(StakeEvent<'StakeAdded'> | StakeEvent<'StakeRemoved'>)[]> {
|
|
8
|
+
const [addedEvents, removedEvents] = await Promise.all([
|
|
9
|
+
chainEvents.stakeEvents(range, { name: 'StakeAdded', args: { id: position } }),
|
|
10
|
+
chainEvents.stakeEvents(range, { name: 'StakeRemoved', args: { id: position } }),
|
|
11
|
+
])
|
|
12
|
+
const result = [...addedEvents, ...removedEvents].toSorted((a, b) => a.time - b.time)
|
|
13
|
+
return result
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import type { StakeEvent, StakeEventsViewer } from '../../viewers/index.ts'
|
|
4
|
+
|
|
5
|
+
export async function mergedAddRemoveStakeEventsByStaker(
|
|
6
|
+
chainEvents: StakeEventsViewer,
|
|
7
|
+
range: [number, number],
|
|
8
|
+
staked: Address,
|
|
9
|
+
staker?: Address,
|
|
10
|
+
): Promise<(StakeEvent<'StakeAdded'> | StakeEvent<'StakeRemoved'>)[]> {
|
|
11
|
+
const [addedEvents, removedEvents] = await Promise.all([
|
|
12
|
+
chainEvents.stakeEvents(range, { name: 'StakeAdded', args: { staked, staker } }),
|
|
13
|
+
chainEvents.stakeEvents(range, { name: 'StakeRemoved', args: { staked, staker } }),
|
|
14
|
+
])
|
|
15
|
+
const result = [...addedEvents, ...removedEvents].toSorted((a, b) => a.time - b.time)
|
|
16
|
+
return result
|
|
17
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
2
|
+
import { asBlockNumber, type BlockRange } from '@xyo-network/xl1-protocol'
|
|
3
|
+
|
|
4
|
+
import { type StakedChainContextRead, withContextCacheResponse } from '../../model/index.ts'
|
|
5
|
+
import type { BlockViewer } from '../../viewers/index.ts'
|
|
6
|
+
import { mergedAddRemoveStakeEventsByPosition } from './mergedAddRemoveStakeEventsByPosition.ts'
|
|
7
|
+
|
|
8
|
+
export async function weightedStakeForRangeByPosition(
|
|
9
|
+
context: StakedChainContextRead,
|
|
10
|
+
blockViewer: BlockViewer,
|
|
11
|
+
externalRange: BlockRange, // first to last block of step
|
|
12
|
+
positionId?: number,
|
|
13
|
+
): Promise<bigint> {
|
|
14
|
+
const cacheKey = isDefined(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`
|
|
15
|
+
return await withContextCacheResponse(context, 'weightedStakeForRangeByPosition', cacheKey, async () => {
|
|
16
|
+
let weightedStakeSum = 0n
|
|
17
|
+
if (isDefined(positionId)) {
|
|
18
|
+
const mergedEvents = (await mergedAddRemoveStakeEventsByPosition(
|
|
19
|
+
context.stake.stakeEvents,
|
|
20
|
+
[0, externalRange[1]],
|
|
21
|
+
positionId,
|
|
22
|
+
)).toSorted((a, b) => a.time - b.time)
|
|
23
|
+
let currentTime = externalRange[0]
|
|
24
|
+
let currentStake = 0n // await activeStakeAtTimeByPosition(chainEvents, pos.staked, currentTime - 1, position)
|
|
25
|
+
for (const event of mergedEvents) {
|
|
26
|
+
if (event.time > currentTime) {
|
|
27
|
+
// Add the weighted stake for the period between the range start or previous event and this event
|
|
28
|
+
weightedStakeSum += currentStake * BigInt(event.time - currentTime)
|
|
29
|
+
}
|
|
30
|
+
if (event.name === 'StakeAdded') {
|
|
31
|
+
currentStake += event.args.amount
|
|
32
|
+
} else if (event.name === 'StakeRemoved') {
|
|
33
|
+
currentStake -= event.args.amount
|
|
34
|
+
}
|
|
35
|
+
// seems that sometimes we get multiple remove events, so ensure stake doesn't go negative
|
|
36
|
+
currentStake = currentStake < 0n ? 0n : currentStake
|
|
37
|
+
currentTime = asBlockNumber(event.time, { name: 'weightedStakeForRangeByPosition' })
|
|
38
|
+
if (currentTime > externalRange[1]) {
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (externalRange[1] > currentTime) {
|
|
43
|
+
// Add the weighted stake for the period between the last event and the end of the range
|
|
44
|
+
weightedStakeSum += currentStake * BigInt(externalRange[1] - currentTime)
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
const positionCount = await context.stake.stakeEvents.positionCount(externalRange)
|
|
48
|
+
for (let pos = 0; pos < positionCount; pos++) {
|
|
49
|
+
weightedStakeSum += await weightedStakeForRangeByPosition(context, blockViewer, externalRange, pos)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return weightedStakeSum
|
|
53
|
+
})
|
|
54
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
import { scoreUncle } from './scoreUncle.ts'
|
|
4
|
+
|
|
5
|
+
export function findBestUncle(finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], uncles: SignedHydratedBlockWithHashMeta[][]) {
|
|
6
|
+
const scores = uncles.map(uncle => ([scoreUncle(finalizedWindowedChain, uncle), uncle] as const)).toSorted((a, b) => b[0] - a[0])
|
|
7
|
+
return scores[0]?.[1] ?? finalizedWindowedChain
|
|
8
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertEx,
|
|
3
|
+
exists, type Hash,
|
|
4
|
+
} from '@xylabs/sdk-js'
|
|
5
|
+
import { isTransactionBoundWitness, type SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
6
|
+
|
|
7
|
+
import type { BaseContext } from '../../model/index.ts'
|
|
8
|
+
|
|
9
|
+
function blocksToChains(blocks: SignedHydratedBlockWithHashMeta[]) {
|
|
10
|
+
const chains: SignedHydratedBlockWithHashMeta[][] = []
|
|
11
|
+
const map = new Map<Hash, SignedHydratedBlockWithHashMeta>()
|
|
12
|
+
for (const block of blocks) {
|
|
13
|
+
map.set(block[0]._hash, block)
|
|
14
|
+
}
|
|
15
|
+
for (const block of blocks) {
|
|
16
|
+
let uncle: SignedHydratedBlockWithHashMeta[] = [block]
|
|
17
|
+
let previous = block[0].previous ? map.get(block[0].previous) : undefined
|
|
18
|
+
while (previous) {
|
|
19
|
+
if (previous[0].block === (uncle[0][0].block - 1)) {
|
|
20
|
+
uncle.unshift(previous)
|
|
21
|
+
previous = previous[0].previous ? map.get(previous[0].previous) : undefined
|
|
22
|
+
} else {
|
|
23
|
+
// block number sequence is off
|
|
24
|
+
uncle = []
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (uncle.length > 0) {
|
|
29
|
+
chains.push(uncle)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return chains
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toValidUncle(
|
|
36
|
+
_context: BaseContext,
|
|
37
|
+
finalizedWindowedChain: SignedHydratedBlockWithHashMeta[],
|
|
38
|
+
possibleUncle: SignedHydratedBlockWithHashMeta[],
|
|
39
|
+
) {
|
|
40
|
+
const finalizedWindowStartBlockNumber = finalizedWindowedChain.at(0)?.[0].block ?? -1
|
|
41
|
+
const finalizedHead = assertEx(finalizedWindowedChain.at(-1), () => 'finalizedWindowedChain is empty')
|
|
42
|
+
// prune the chain to match the finalized head
|
|
43
|
+
|
|
44
|
+
const prunedPossibleUncle = possibleUncle.filter(b => b[0].block > finalizedHead[0].block)
|
|
45
|
+
|
|
46
|
+
if (prunedPossibleUncle.length === 0) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (prunedPossibleUncle[0][0].block !== finalizedHead[0].block + 1) {
|
|
51
|
+
// uncle does not build on finalized head (block number mismatch)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (prunedPossibleUncle[0][0].previous !== finalizedHead[0]._hash) {
|
|
55
|
+
// uncle does not build on finalized head (previous hash mismatch)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
const allUncleTransactions = prunedPossibleUncle.flatMap(b => b[1]).filter(isTransactionBoundWitness)
|
|
59
|
+
const allFinalizedTransactions = finalizedWindowedChain.flatMap(b => b[1]).filter(isTransactionBoundWitness)
|
|
60
|
+
const txPossiblyBeforeWindow = allUncleTransactions.find(tx => tx.nbf < finalizedWindowStartBlockNumber)
|
|
61
|
+
if (txPossiblyBeforeWindow) {
|
|
62
|
+
// uncle has a transaction that is valid before the finalized window
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
const txExistsInWindow = allUncleTransactions.find(tx => allFinalizedTransactions.find(finalTx => finalTx._hash === tx._hash))
|
|
66
|
+
if (txExistsInWindow) {
|
|
67
|
+
// uncle has a transaction that is already in the finalized window
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
return prunedPossibleUncle
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function findUncles(context: BaseContext, finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], blocks: SignedHydratedBlockWithHashMeta[]) {
|
|
74
|
+
return blocksToChains(blocks).map(chain => toValidUncle(context, finalizedWindowedChain, chain)).filter(exists)
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
2
|
+
|
|
3
|
+
export function scoreUncle(finalizedWindowedChain: SignedHydratedBlockWithHashMeta[], blocks: SignedHydratedBlockWithHashMeta[]) {
|
|
4
|
+
// TODO: More than length check
|
|
5
|
+
return blocks.length
|
|
6
|
+
}
|
package/src/provider/DataLake.ts
CHANGED
|
@@ -2,24 +2,25 @@ import type { Hash } from '@xylabs/sdk-js'
|
|
|
2
2
|
import type { Payload, Schema } from '@xyo-network/payload-model'
|
|
3
3
|
|
|
4
4
|
import type { MapType } from '../map/index.ts'
|
|
5
|
+
import type { Provider } from '../model/index.ts'
|
|
5
6
|
|
|
6
7
|
export type DataLakeData = Payload | ArrayBuffer
|
|
7
8
|
|
|
8
|
-
export type DataLakeViewerMethods = Pick<MapType<Hash, DataLakeData>, 'get' | 'getMany' | 'has'>
|
|
9
|
-
|
|
10
|
-
export interface DataLakeViewer extends DataLakeViewerMethods {
|
|
11
|
-
allowedSchemas?: Schema[]
|
|
12
|
-
disallowedSchemas?: Schema[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
export const DataLakeViewerMoniker = 'DataLakeViewer' as const
|
|
16
10
|
export type DataLakeViewerMoniker = typeof DataLakeViewerMoniker
|
|
17
11
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
}
|
|
12
|
+
export interface DataLakeViewerMethods extends
|
|
13
|
+
Pick<MapType<Hash, DataLakeData>, 'get' | 'getMany' | 'has'> {}
|
|
21
14
|
|
|
22
|
-
export interface
|
|
15
|
+
export interface DataLakeViewer extends DataLakeViewerMethods, Provider<DataLakeViewerMoniker> {
|
|
16
|
+
allowedSchemas?: Schema[]
|
|
17
|
+
disallowedSchemas?: Schema[]
|
|
18
|
+
}
|
|
23
19
|
|
|
24
20
|
export const DataLakeRunnerMoniker = 'DataLakeRunner' as const
|
|
25
21
|
export type DataLakeRunnerMoniker = typeof DataLakeRunnerMoniker
|
|
22
|
+
|
|
23
|
+
export interface DataLakeRunnerMethods extends Pick<MapType<Hash, DataLakeData>, 'setMany' | 'set' | 'delete' | 'clear'>,
|
|
24
|
+
DataLakeViewerMethods {}
|
|
25
|
+
|
|
26
|
+
export interface DataLakeRunner extends DataLakeRunnerMethods, Provider<DataLakeRunnerMoniker> {}
|