@xyo-network/xl1-protocol-sdk 1.26.11 → 1.26.13
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/package.json +29 -16
- package/src/ChainContextHelpers.ts +0 -50
- package/src/CreatableProvider/AbstractCreatableProvider.ts +0 -97
- package/src/CreatableProvider/CreatableProvider.ts +0 -102
- package/src/CreatableProvider/CreatableProviderRegistry.ts +0 -94
- package/src/CreatableProvider/GetInstanceOptions.ts +0 -11
- package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +0 -24
- package/src/CreatableProvider/ProviderFactory.ts +0 -138
- package/src/CreatableProvider/ProviderFactoryLocator.ts +0 -170
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +0 -70
- package/src/CreatableProvider/index.ts +0 -8
- package/src/SignedBigInt.ts +0 -59
- package/src/_internal/context/getTestProviderContext.ts +0 -13
- package/src/_internal/context/index.ts +0 -1
- package/src/_internal/index.ts +0 -2
- package/src/actor/ActorV3.ts +0 -177
- package/src/actor/index.ts +0 -1
- package/src/amount/ShiftedBigInt.ts +0 -73
- package/src/amount/XL1Amount.ts +0 -103
- package/src/amount/index.ts +0 -4
- package/src/amount/splitOnDecimal.ts +0 -6
- package/src/amount/splitOnDecimalToString.ts +0 -40
- package/src/block/hydrate/allHashesPresent.ts +0 -8
- package/src/block/hydrate/blockPayloadsFromHydratedBlock.ts +0 -12
- package/src/block/hydrate/flattenHydratedBlock.ts +0 -28
- package/src/block/hydrate/flattenHydratedBlocks.ts +0 -7
- package/src/block/hydrate/hydrateBlock.ts +0 -43
- package/src/block/hydrate/index.ts +0 -7
- package/src/block/hydrate/transactionsFromHydratedBlock.ts +0 -7
- package/src/block/hydrate/tryHydrateBlock.ts +0 -26
- package/src/block/index.ts +0 -2
- package/src/block/primitives/blockFromBlockNumber.ts +0 -69
- package/src/block/primitives/frames/calculateFramesFromRange.ts +0 -30
- package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +0 -28
- package/src/block/primitives/frames/index.ts +0 -2
- package/src/block/primitives/hashFromBlockNumber.ts +0 -9
- package/src/block/primitives/index.ts +0 -7
- package/src/block/primitives/model.ts +0 -18
- package/src/block/primitives/payloads/ChainWindow.ts +0 -7
- package/src/block/primitives/payloads/index.ts +0 -1
- package/src/block/primitives/toStepIdentityString.ts +0 -6
- package/src/block/primitives/validateTransactionOpcodes.ts +0 -45
- package/src/config/Actor.ts +0 -32
- package/src/config/Actors.ts +0 -9
- package/src/config/Base.ts +0 -27
- package/src/config/Chain.ts +0 -23
- package/src/config/Config.ts +0 -24
- package/src/config/DataLake/DataLake.ts +0 -12
- package/src/config/DataLake/DataLakeRemoteConfig.ts +0 -11
- package/src/config/DataLake/RestDataLakeConfig.ts +0 -18
- package/src/config/DataLake/RouterDataLakeConfig.ts +0 -22
- package/src/config/DataLake/index.ts +0 -4
- package/src/config/DeepPartial.ts +0 -4
- package/src/config/Evm.ts +0 -38
- package/src/config/HostActor.ts +0 -32
- package/src/config/Log.ts +0 -25
- package/src/config/Provider.ts +0 -20
- package/src/config/Providers.ts +0 -9
- package/src/config/Remote.ts +0 -59
- package/src/config/Telemetry.ts +0 -49
- package/src/config/UsageMeta.ts +0 -46
- package/src/config/Validation.ts +0 -29
- package/src/config/index.ts +0 -12
- package/src/config/storage/Storage.ts +0 -16
- package/src/config/storage/driver/Mongo.ts +0 -53
- package/src/config/storage/driver/index.ts +0 -1
- package/src/config/storage/index.ts +0 -2
- package/src/constants.ts +0 -4
- package/src/context/Actor.ts +0 -20
- package/src/context/HostActor.ts +0 -20
- package/src/context/getEmptyProviderContext.ts +0 -19
- package/src/context/index.ts +0 -3
- package/src/createDeclarationPayload.ts +0 -15
- package/src/createTransferPayload.ts +0 -16
- package/src/driver/cache/LruCacheMap.ts +0 -48
- package/src/driver/cache/index.ts +0 -1
- package/src/driver/index.ts +0 -2
- package/src/driver/memory/MemoryMap.ts +0 -48
- package/src/driver/memory/index.ts +0 -1
- package/src/eip-712/Payloads/EIP712Data.ts +0 -35
- package/src/eip-712/Payloads/EIP712Signature.ts +0 -32
- package/src/eip-712/Payloads/index.ts +0 -2
- package/src/eip-712/Types.ts +0 -41
- package/src/eip-712/index.ts +0 -4
- package/src/eip-712/sign.ts +0 -19
- package/src/eip-712/spec/fixtures.ts +0 -27
- package/src/eip-712/verify.ts +0 -20
- package/src/getFileConfig.ts +0 -36
- package/src/index.ts +0 -27
- package/src/instances/Address.ts +0 -16
- package/src/instances/BoundWitness.ts +0 -13
- package/src/instances/Data.ts +0 -4
- package/src/instances/Fees.ts +0 -9
- package/src/instances/HydratedBoundWitness.ts +0 -16
- package/src/instances/Object.ts +0 -6
- package/src/instances/Payload.ts +0 -7
- package/src/instances/Signature.ts +0 -12
- package/src/instances/block/BlockFields.ts +0 -18
- package/src/instances/block/HydratedBlock.ts +0 -10
- package/src/instances/block/index.ts +0 -1
- package/src/instances/index.ts +0 -10
- package/src/instances/modifiers/BlockWindowInstance.ts +0 -8
- package/src/instances/modifiers/BlockWindowState.ts +0 -6
- package/src/instances/modifiers/Signed.ts +0 -9
- package/src/instances/modifiers/Validatable.ts +0 -6
- package/src/instances/modifiers/index.ts +0 -4
- package/src/instances/transaction/HydratedTransaction.ts +0 -9
- package/src/instances/transaction/TransactionFields.ts +0 -22
- package/src/instances/transaction/index.ts +0 -1
- package/src/isInternetAvailable.ts +0 -11
- package/src/model/ChainFork/ChainForkStatic.ts +0 -9
- package/src/model/ChainFork/index.ts +0 -1
- package/src/model/ChainIdentity.ts +0 -6
- package/src/model/ChainStore.ts +0 -16
- package/src/model/CreatableProviderContext.ts +0 -6
- package/src/model/CreatableProviderContext.zod.ts +0 -55
- package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +0 -15
- package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +0 -15
- package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/index.ts +0 -4
- package/src/model/index.ts +0 -6
- package/src/multipliers.ts +0 -18
- package/src/payloads/AddressPairPayload.ts +0 -27
- package/src/payloads/index.ts +0 -4
- package/src/payloads/netBalancesForPayloads.ts +0 -24
- package/src/payloads/netSchemasForPayloads.ts +0 -24
- package/src/payloads/netTransfersForPayloads.ts +0 -27
- package/src/primitives/block/index.ts +0 -2
- package/src/primitives/block/range/blockRangeSteps.ts +0 -23
- package/src/primitives/block/range/index.ts +0 -1
- package/src/primitives/block/rate/blockRate.ts +0 -77
- package/src/primitives/block/rate/index.ts +0 -4
- package/src/primitives/block/rate/stepRate.ts +0 -37
- package/src/primitives/block/rate/timeHelpers.ts +0 -61
- package/src/primitives/block/rate/timeRate.ts +0 -121
- package/src/primitives/chain/getWindowedChain.ts +0 -50
- package/src/primitives/chain/index.ts +0 -3
- package/src/primitives/chain/step/chainStepRewardAddress.ts +0 -30
- package/src/primitives/chain/step/index.ts +0 -4
- package/src/primitives/chain/step/stepRewardBlock.ts +0 -13
- package/src/primitives/chain/step/stepRewardTotal.ts +0 -46
- package/src/primitives/chain/step/stepsRewardTotal.ts +0 -37
- package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +0 -32
- package/src/primitives/chain/time/externalBlockRangeFromStep.ts +0 -21
- package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +0 -17
- package/src/primitives/chain/time/index.ts +0 -3
- package/src/primitives/datalake/addDataLakePayloads.ts +0 -18
- package/src/primitives/datalake/addDataLakePayloadsToPayloads.ts +0 -24
- package/src/primitives/datalake/index.ts +0 -2
- package/src/primitives/index.ts +0 -13
- package/src/primitives/mapToMapType.ts +0 -35
- package/src/primitives/payload/index.ts +0 -1
- package/src/primitives/payload/mergeTransfers.ts +0 -16
- package/src/primitives/readPayloadMapFromStore.ts +0 -58
- package/src/primitives/rewardFromBlockNumber.ts +0 -19
- package/src/primitives/rewards/index.ts +0 -1
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +0 -26
- package/src/primitives/stake/activeStakeAtTimeByAddress.ts +0 -27
- package/src/primitives/stake/activeStakeAtTimeByPosition.ts +0 -25
- package/src/primitives/stake/allStakersForRange.ts +0 -32
- package/src/primitives/stake/allStakersForStep.ts +0 -24
- package/src/primitives/stake/index.ts +0 -6
- package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +0 -15
- package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +0 -17
- package/src/primitives/stake/weightedStakeForRangeByPosition.ts +0 -69
- package/src/primitives/state/findMostRecentBlock.ts +0 -44
- package/src/primitives/state/hydratedBlockByNumber.ts +0 -25
- package/src/primitives/state/index.ts +0 -2
- package/src/primitives/step/completedStepRewardAddress.ts +0 -10
- package/src/primitives/step/derivedReceiveAddress.ts +0 -9
- package/src/primitives/step/index.ts +0 -4
- package/src/primitives/step/stepBlockRange.ts +0 -9
- package/src/primitives/step/stepTransferIndex.ts +0 -19
- package/src/primitives/transaction/elevatedPayloads.ts +0 -24
- package/src/primitives/transaction/index.ts +0 -1
- package/src/primitives/uncle/findBestUncle.ts +0 -9
- package/src/primitives/uncle/findUncles.ts +0 -75
- package/src/primitives/uncle/index.ts +0 -3
- package/src/primitives/uncle/scoreUncle.ts +0 -7
- package/src/services/AccountTransfersService.ts +0 -13
- package/src/services/BlockProducerService.ts +0 -11
- package/src/services/Chain/BaseChainService.ts +0 -4
- package/src/services/Chain/ChainHeadService.ts +0 -8
- package/src/services/Chain/ChainService.ts +0 -6
- package/src/services/Chain/index.ts +0 -3
- package/src/services/Election.ts +0 -14
- package/src/services/NetworkStakeService.ts +0 -4
- package/src/services/Params.ts +0 -13
- package/src/services/PendingTransactionsService.ts +0 -7
- package/src/services/SchemasService.ts +0 -11
- package/src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts +0 -50
- package/src/services/StakeIntentService/StakeIntentService.ts +0 -35
- package/src/services/StakeIntentService/index.ts +0 -2
- package/src/services/index.ts +0 -8
- package/src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts +0 -93
- package/src/simple/StakeEventsViewer/index.ts +0 -1
- package/src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts +0 -116
- package/src/simple/StakeTotalsViewer/index.ts +0 -1
- package/src/simple/StakeViewer/SimpleStakeViewer.ts +0 -164
- package/src/simple/StakeViewer/index.ts +0 -1
- package/src/simple/TransactionViewer/SimpleTransactionViewer.ts +0 -100
- package/src/simple/TransactionViewer/index.ts +0 -1
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +0 -271
- package/src/simple/accountBalance/index.ts +0 -1
- package/src/simple/block/SimpleBlockViewer.ts +0 -231
- package/src/simple/block/index.ts +0 -1
- package/src/simple/blockInvalidation/SimpleBlockInvalidationViewer.ts +0 -197
- package/src/simple/blockInvalidation/index.ts +0 -1
- package/src/simple/blockReward/SimpleBlockRewardViewer.ts +0 -27
- package/src/simple/blockReward/index.ts +0 -1
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +0 -194
- package/src/simple/blockValidation/index.ts +0 -1
- package/src/simple/chainContractViewer/SimpleChainContractViewer.ts +0 -92
- package/src/simple/chainContractViewer/index.ts +0 -1
- package/src/simple/client/SimpleXyoClient.ts +0 -14
- package/src/simple/client/index.ts +0 -1
- package/src/simple/datalake/AbstractRestDataLake.ts +0 -70
- package/src/simple/datalake/AbstractSimpleDataLake.ts +0 -62
- package/src/simple/datalake/RestDataLakeRunner.ts +0 -54
- package/src/simple/datalake/RestDataLakeViewer.ts +0 -22
- package/src/simple/datalake/SimpleDataLakeRunner.ts +0 -44
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -24
- package/src/simple/datalake/index.ts +0 -4
- package/src/simple/finalization/SimpleFinalizationRunner.ts +0 -45
- package/src/simple/finalization/SimpleFinalizationViewer.ts +0 -123
- package/src/simple/finalization/index.ts +0 -2
- package/src/simple/gateway/SimpleXyoGateway.ts +0 -30
- package/src/simple/gateway/SimpleXyoGatewayRunner.ts +0 -137
- package/src/simple/gateway/index.ts +0 -2
- package/src/simple/index.ts +0 -22
- package/src/simple/mempool/SimpleMempoolRunner.ts +0 -390
- package/src/simple/mempool/SimpleMempoolViewer.ts +0 -215
- package/src/simple/mempool/index.ts +0 -2
- package/src/simple/network/SimpleXyoNetwork.ts +0 -48
- package/src/simple/network/index.ts +0 -1
- package/src/simple/network/lib/FailedNetworkStatusPayloads.ts +0 -16
- package/src/simple/network/lib/StatusNetworks.ts +0 -32
- package/src/simple/network/lib/index.ts +0 -2
- package/src/simple/permissions/SimpleXyoPermissions.ts +0 -82
- package/src/simple/permissions/index.ts +0 -2
- package/src/simple/permissions/store/MemoryPermissions.ts +0 -32
- package/src/simple/permissions/store/PermissionsStore.ts +0 -17
- package/src/simple/permissions/store/index.ts +0 -2
- package/src/simple/runner/SimpleXyoRunner.ts +0 -41
- package/src/simple/runner/index.ts +0 -1
- package/src/simple/signer/SimpleXyoSigner.ts +0 -78
- package/src/simple/signer/index.ts +0 -1
- package/src/simple/timeSync2/SimpleTimeSyncViewer.ts +0 -132
- package/src/simple/timeSync2/index.ts +0 -1
- package/src/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.ts +0 -197
- package/src/simple/transactionInvalidation/index.ts +0 -1
- package/src/simple/transactionValidation/SimpleTransactionValidationViewer.ts +0 -173
- package/src/simple/transactionValidation/index.ts +0 -1
- package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +0 -207
- package/src/simple/windowedBlock/index.ts +0 -1
- package/src/status/RuntimeStatusMonitor.ts +0 -120
- package/src/status/ServiceStatus.ts +0 -21
- package/src/status/index.ts +0 -2
- package/src/summary/index.ts +0 -2
- package/src/summary/model/BalancesStepSummary.ts +0 -35
- package/src/summary/model/SchemasStepSummary.ts +0 -33
- package/src/summary/model/StepSummary.ts +0 -20
- package/src/summary/model/TransfersSummary.ts +0 -36
- package/src/summary/model/index.ts +0 -4
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +0 -94
- package/src/summary/primitives/balances/balancesSummary.ts +0 -48
- package/src/summary/primitives/balances/index.ts +0 -2
- package/src/summary/primitives/index.ts +0 -3
- package/src/summary/primitives/schemas/index.ts +0 -2
- package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +0 -86
- package/src/summary/primitives/schemas/schemasSummary.ts +0 -44
- package/src/summary/primitives/transfers/index.ts +0 -2
- package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +0 -109
- package/src/summary/primitives/transfers/transfersSummary.ts +0 -52
- package/src/test/BuildBlockOptions.ts +0 -81
- package/src/test/buildBlock.ts +0 -105
- package/src/test/buildGenesisBlock.ts +0 -29
- package/src/test/buildNextBlock.ts +0 -37
- package/src/test/buildRandomChain.ts +0 -92
- package/src/test/buildRandomGenesisBlock.ts +0 -47
- package/src/test/createGenesisBlock.ts +0 -41
- package/src/test/createProducerChainStakeIntentTransaction.ts +0 -48
- package/src/test/getSimpleBlockViewerLocator.ts +0 -41
- package/src/test/getTestProviderContext.ts +0 -8
- package/src/test/index.ts +0 -2
- package/src/time/index.ts +0 -1
- package/src/time/primitives/index.ts +0 -1
- package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +0 -13
- package/src/transaction/TransactionBuilder.ts +0 -164
- package/src/transaction/buildRandomTransaction.ts +0 -38
- package/src/transaction/buildTransaction.ts +0 -68
- package/src/transaction/buildUnsignedTransaction.ts +0 -56
- package/src/transaction/confirmSubmittedTransaction.ts +0 -42
- package/src/transaction/hydrateTransaction.ts +0 -117
- package/src/transaction/index.ts +0 -9
- package/src/transaction/primitives/index.ts +0 -4
- package/src/transaction/primitives/transactionBlockByteCount.ts +0 -10
- package/src/transaction/primitives/transactionElevatedPayloads.ts +0 -18
- package/src/transaction/primitives/transactionOperations.ts +0 -13
- package/src/transaction/primitives/transactionRequiredGas.ts +0 -22
- package/src/transaction/script.ts +0 -48
- package/src/transaction/signTransaction.ts +0 -32
- package/src/utils/HydratedCache.ts +0 -39
- package/src/utils/index.ts +0 -2
- package/src/utils/isZodError.ts +0 -11
- package/src/validation/index.ts +0 -2
- package/src/validation/lib/getUrl.ts +0 -7
- package/src/validation/lib/index.ts +0 -2
- package/src/validation/lib/isLocalhost.ts +0 -9
- package/src/validation/schema/Address.ts +0 -2
- package/src/validation/schema/Mnemonic.ts +0 -21
- package/src/validation/schema/index.ts +0 -2
- package/src/wallet/generateXyoBaseWalletFromPhrase.ts +0 -13
- package/src/wallet/index.ts +0 -2
- package/src/wallet/paths.ts +0 -17
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { assertEx, isArray } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
BlockNumber, BlockViewer, CachingContext, XL1BlockNumber,
|
|
4
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
import {
|
|
6
|
-
asBlockNumber, asTimePayload, isTimePayload,
|
|
7
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
import { withContextCacheResponse } from '../../../ChainContextHelpers.ts'
|
|
10
|
-
|
|
11
|
-
const functionName = 'externalBlockNumberFromXL1BlockNumber' as const
|
|
12
|
-
|
|
13
|
-
/** ExternalBlockNumberFromXL1BlockNumber helper function. */
|
|
14
|
-
export async function externalBlockNumberFromXL1BlockNumber(
|
|
15
|
-
context: CachingContext,
|
|
16
|
-
blockViewer: BlockViewer,
|
|
17
|
-
xl1BlockNumber: XL1BlockNumber,
|
|
18
|
-
externalTimeName: 'ethereum' | 'epoch',
|
|
19
|
-
externalGenesisTime?: BlockNumber,
|
|
20
|
-
): Promise<BlockNumber> {
|
|
21
|
-
const cacheKey = `${xl1BlockNumber}-${externalTimeName}-${externalGenesisTime ?? 'default'}`
|
|
22
|
-
return await withContextCacheResponse(context, functionName, cacheKey, async () => {
|
|
23
|
-
const [, payloads = []] = await blockViewer.blockByNumber(xl1BlockNumber) ?? []
|
|
24
|
-
assertEx(isArray(payloads))
|
|
25
|
-
const timePayload = asTimePayload(payloads.find(isTimePayload))
|
|
26
|
-
// the default here is the block number we know where the xl1 chain started running (first external staking - 1)
|
|
27
|
-
return asBlockNumber(
|
|
28
|
-
timePayload?.[externalTimeName] ?? externalGenesisTime ?? 23_372_716,
|
|
29
|
-
{ name: functionName },
|
|
30
|
-
) // default is xl1 mainnet genesis time
|
|
31
|
-
})
|
|
32
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BlockRange, BlockViewer, CachingContext, StepIdentity,
|
|
3
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
|
|
5
|
-
import { toStepIdentityString } from '../../../block/index.ts'
|
|
6
|
-
import { withContextCacheResponse } from '../../../ChainContextHelpers.ts'
|
|
7
|
-
import { stepBlockRange } from '../../step/index.ts'
|
|
8
|
-
import { externalBlockRangeFromXL1BlockRange } from './externalBlockRangeFromXL1BlockRange.ts'
|
|
9
|
-
|
|
10
|
-
/** ExternalBlockRangeFromStep helper function. */
|
|
11
|
-
export async function externalBlockRangeFromStep(
|
|
12
|
-
context: CachingContext,
|
|
13
|
-
blockViewer: BlockViewer,
|
|
14
|
-
stepIdentity: StepIdentity,
|
|
15
|
-
): Promise<BlockRange> {
|
|
16
|
-
const cacheKey = toStepIdentityString(stepIdentity)
|
|
17
|
-
return await withContextCacheResponse(context, 'externalBlockRangeFromStep', cacheKey, async () => {
|
|
18
|
-
const xl1BlockRange = stepBlockRange(stepIdentity)
|
|
19
|
-
return await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange)
|
|
20
|
-
})
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BlockRange, BlockViewer, CachingContext, XL1BlockRange,
|
|
3
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
|
|
5
|
-
import { externalBlockNumberFromXL1BlockNumber } from './externalBlockNumberFromXL1BlockNumber.ts'
|
|
6
|
-
|
|
7
|
-
/** ExternalBlockRangeFromXL1BlockRange helper function. */
|
|
8
|
-
export async function externalBlockRangeFromXL1BlockRange(
|
|
9
|
-
context: CachingContext,
|
|
10
|
-
blockViewer: BlockViewer,
|
|
11
|
-
xl1BlockRange: XL1BlockRange,
|
|
12
|
-
externalTimeName: 'ethereum' = 'ethereum',
|
|
13
|
-
): Promise<BlockRange> {
|
|
14
|
-
const start = await externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockRange[0], externalTimeName)
|
|
15
|
-
const end = await externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockRange[1], externalTimeName)
|
|
16
|
-
return [start, end]
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import type { DataLakeViewer, HydratedBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
import { addDataLakePayloadsToPayloads } from './addDataLakePayloadsToPayloads.ts'
|
|
5
|
-
|
|
6
|
-
/** AddDataLakePayloads helper function. */
|
|
7
|
-
export async function addDataLakePayloads<T extends HydratedBoundWitnessWithHashMeta>(
|
|
8
|
-
[boundWitness, payloads]: T,
|
|
9
|
-
dataLakeViewer?: DataLakeViewer,
|
|
10
|
-
): Promise<[T, Hash[]]> {
|
|
11
|
-
const [updatedPayloads, foundHashes] = await addDataLakePayloadsToPayloads(boundWitness.payload_hashes, payloads, dataLakeViewer)
|
|
12
|
-
return [
|
|
13
|
-
[
|
|
14
|
-
boundWitness,
|
|
15
|
-
updatedPayloads,
|
|
16
|
-
] as T,
|
|
17
|
-
foundHashes]
|
|
18
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { isUndefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Payload, WithHashMeta } from '@xyo-network/sdk-js'
|
|
4
|
-
import { isAnyPayload, PayloadBuilder } from '@xyo-network/sdk-js'
|
|
5
|
-
import type { DataLakeViewer } from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
|
|
7
|
-
/** AddDataLakePayloadsToPayloads helper function. */
|
|
8
|
-
export async function addDataLakePayloadsToPayloads<T extends WithHashMeta<Payload>>(
|
|
9
|
-
hashes: Hash[],
|
|
10
|
-
payloads: T[],
|
|
11
|
-
dataLakeViewer?: DataLakeViewer,
|
|
12
|
-
): Promise<[
|
|
13
|
-
/* Updated payloads with hash metadata */
|
|
14
|
-
T[],
|
|
15
|
-
/* Hashes of the newly added payloads */
|
|
16
|
-
Hash[],
|
|
17
|
-
]> {
|
|
18
|
-
if (isUndefined(dataLakeViewer)) return [payloads, []]
|
|
19
|
-
const missingPayloadHashes = hashes.filter(hash => !payloads.some(p => p._hash === hash))
|
|
20
|
-
const payloadsFromDataLake = await PayloadBuilder.addHashMeta(
|
|
21
|
-
await PayloadBuilder.addHashMeta((await dataLakeViewer.get(missingPayloadHashes)).filter(isAnyPayload)),
|
|
22
|
-
)
|
|
23
|
-
return [[...payloads, ...payloadsFromDataLake] as T[], payloadsFromDataLake.map(p => p._hash)]
|
|
24
|
-
}
|
package/src/primitives/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './block/index.ts'
|
|
2
|
-
export * from './chain/index.ts'
|
|
3
|
-
export * from './datalake/index.ts'
|
|
4
|
-
export * from './mapToMapType.ts'
|
|
5
|
-
export * from './payload/index.ts'
|
|
6
|
-
export * from './readPayloadMapFromStore.ts'
|
|
7
|
-
export * from './rewardFromBlockNumber.ts'
|
|
8
|
-
export * from './rewards/index.ts'
|
|
9
|
-
export * from './stake/index.ts'
|
|
10
|
-
export * from './state/index.ts'
|
|
11
|
-
export * from './step/index.ts'
|
|
12
|
-
export * from './transaction/index.ts'
|
|
13
|
-
export * from './uncle/index.ts'
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { SyncIterableMap } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
/** MapToMapType helper function. */
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './mergeTransfers.ts'
|
|
@@ -1,16 +0,0 @@
|
|
|
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-lib'
|
|
4
|
-
|
|
5
|
-
/** MergeTransfers helper function. */
|
|
6
|
-
export function mergeTransfers(transfers: Transfer[]): Record<Address, Record<Address, bigint>> {
|
|
7
|
-
const result: Record<Address, Record<Address, bigint>> = {}
|
|
8
|
-
for (const transfer of transfers) {
|
|
9
|
-
result[transfer.from] = result[transfer.from] ?? {}
|
|
10
|
-
for (const [to, value] of Object.entries(transfer.transfers)) {
|
|
11
|
-
const typedTo = toAddress(to)
|
|
12
|
-
result[transfer.from][typedTo] = (result[transfer.from][typedTo] ?? 0n) + (hexToBigInt(value))
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return result
|
|
16
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
ReadArchivist, ReadWriteArchivist,
|
|
5
|
-
WithStorageMeta,
|
|
6
|
-
} from '@xyo-network/sdk-js'
|
|
7
|
-
import type { PayloadMap, PayloadMapRead } from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
import { isReadArchivist, isReadWriteArchivist } from '../block/index.ts'
|
|
10
|
-
|
|
11
|
-
/** ReadPayloadMapFromStore helper function. */
|
|
12
|
-
export function readPayloadMapFromStore(store: ReadArchivist | PayloadMapRead): PayloadMapRead {
|
|
13
|
-
if (isReadArchivist(store)) {
|
|
14
|
-
return {
|
|
15
|
-
get: async (hash: Hash) => {
|
|
16
|
-
return (await store.get([hash]))[0]
|
|
17
|
-
},
|
|
18
|
-
getMany: async (hashes: Hash[]) => {
|
|
19
|
-
return (await store.get(hashes))
|
|
20
|
-
},
|
|
21
|
-
has: async (hash: Hash) => {
|
|
22
|
-
return isDefined((await store.get([hash]))[0])
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return store
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** PayloadMapFromStore helper function. */
|
|
30
|
-
export function payloadMapFromStore(store: ReadWriteArchivist | PayloadMap): PayloadMap {
|
|
31
|
-
if (isReadWriteArchivist(store)) {
|
|
32
|
-
return {
|
|
33
|
-
get: async (hash: Hash) => {
|
|
34
|
-
return (await store.get([hash]))[0]
|
|
35
|
-
},
|
|
36
|
-
getMany: async (hashes: Hash[]) => {
|
|
37
|
-
return (await store.get(hashes))
|
|
38
|
-
},
|
|
39
|
-
has: async (hash: Hash) => {
|
|
40
|
-
return isDefined((await store.get([hash]))[0])
|
|
41
|
-
},
|
|
42
|
-
clear: async () => {
|
|
43
|
-
return await store.clear()
|
|
44
|
-
},
|
|
45
|
-
delete: async (id: Hash) => {
|
|
46
|
-
await store.delete([id])
|
|
47
|
-
return true
|
|
48
|
-
},
|
|
49
|
-
set: async (_id: Hash, data: WithStorageMeta) => {
|
|
50
|
-
await store.insert([data])
|
|
51
|
-
},
|
|
52
|
-
setMany: async (entries: [Hash, WithStorageMeta][]) => {
|
|
53
|
-
await store.insert(entries.map(e => e[1]))
|
|
54
|
-
},
|
|
55
|
-
} satisfies PayloadMap<WithStorageMeta>
|
|
56
|
-
}
|
|
57
|
-
return store
|
|
58
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
asAttoXL1, XL1_REWARDS_BLOCKS_PER_STEP, XL1_REWARDS_CREATOR_REWARD,
|
|
3
|
-
XL1_REWARDS_MIN_BLOCK_REWARD, XL1_REWARDS_STARTING_REWARD, XL1_REWARDS_STEP_FACTOR_DENOMINATOR,
|
|
4
|
-
XL1_REWARDS_STEP_FACTOR_NUMERATOR, type XL1BlockNumber,
|
|
5
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
|
|
7
|
-
/** RewardFromBlockNumber helper function. */
|
|
8
|
-
export function rewardFromBlockNumber(blockNumber: XL1BlockNumber) {
|
|
9
|
-
if (blockNumber === 0) {
|
|
10
|
-
return XL1_REWARDS_CREATOR_REWARD
|
|
11
|
-
}
|
|
12
|
-
const step = Math.floor((blockNumber + XL1_REWARDS_BLOCKS_PER_STEP) / XL1_REWARDS_BLOCKS_PER_STEP)
|
|
13
|
-
const stepExp = BigInt(step - 1)
|
|
14
|
-
const poweredNumerator = stepExp > 0 ? XL1_REWARDS_STEP_FACTOR_NUMERATOR ** stepExp : 1n
|
|
15
|
-
const poweredDenominator = stepExp > 0 ? XL1_REWARDS_STEP_FACTOR_DENOMINATOR ** stepExp : 1n
|
|
16
|
-
let reward = (XL1_REWARDS_STARTING_REWARD * poweredNumerator) / poweredDenominator
|
|
17
|
-
// eslint-disable-next-line unicorn/prefer-math-min-max
|
|
18
|
-
return asAttoXL1((reward < XL1_REWARDS_MIN_BLOCK_REWARD) ? XL1_REWARDS_MIN_BLOCK_REWARD : reward)
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './networkStakeStepRewardPositionWeight.ts'
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BlockViewer, CachingContext, StakeEventsViewer, StepIdentity,
|
|
3
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
import { XYO_NETWORK_STAKING_ADDRESS } from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
|
|
6
|
-
import { externalBlockRangeFromStep } from '../chain/index.ts'
|
|
7
|
-
import { weightedStakeForRangeByPosition } from '../stake/index.ts'
|
|
8
|
-
|
|
9
|
-
/** NetworkStakeStepRewardPositionWeight helper function. */
|
|
10
|
-
export async function networkStakeStepRewardPositionWeight(
|
|
11
|
-
context: CachingContext,
|
|
12
|
-
blockViewer: BlockViewer,
|
|
13
|
-
stakeEventsViewer: StakeEventsViewer,
|
|
14
|
-
stepContext: StepIdentity,
|
|
15
|
-
position: number,
|
|
16
|
-
): Promise<bigint> {
|
|
17
|
-
const result = await weightedStakeForRangeByPosition(
|
|
18
|
-
context,
|
|
19
|
-
blockViewer,
|
|
20
|
-
stakeEventsViewer,
|
|
21
|
-
await externalBlockRangeFromStep(context, blockViewer, stepContext),
|
|
22
|
-
XYO_NETWORK_STAKING_ADDRESS,
|
|
23
|
-
position,
|
|
24
|
-
)
|
|
25
|
-
return result
|
|
26
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { StakeEventsViewer } from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
|
|
5
|
-
import { mergedAddRemoveStakeEventsByStaker } from './mergedAddRemoveStakeEventsByStaker.ts'
|
|
6
|
-
|
|
7
|
-
/** ActiveStakeAtTimeByAddress helper function. */
|
|
8
|
-
export async function activeStakeAtTimeByAddress(
|
|
9
|
-
chain: StakeEventsViewer,
|
|
10
|
-
staked: Address,
|
|
11
|
-
time: number,
|
|
12
|
-
staker?: Address,
|
|
13
|
-
): Promise<bigint> {
|
|
14
|
-
const stakeEvents = (await mergedAddRemoveStakeEventsByStaker(chain, [0, time], staked, staker)).toSorted((a, b) => a.time - b.time)
|
|
15
|
-
let result = 0n
|
|
16
|
-
for (const event of stakeEvents) {
|
|
17
|
-
if (event.time > time) break
|
|
18
|
-
if (event.args.staked !== staked) continue
|
|
19
|
-
if (isDefined(staker) && (event.args.staker !== staker)) continue
|
|
20
|
-
if (event.name === 'StakeAdded') {
|
|
21
|
-
result += event.args.amount
|
|
22
|
-
} else if (event.name === 'StakeRemoved') {
|
|
23
|
-
result -= event.args.amount
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { StakeEventsViewer } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
import { mergedAddRemoveStakeEventsByPosition } from './mergedAddRemoveStakeEventsByPosition.ts'
|
|
5
|
-
|
|
6
|
-
/** ActiveStakeAtTimeByPosition helper function. */
|
|
7
|
-
export async function activeStakeAtTimeByPosition(
|
|
8
|
-
chainStakeEvents: StakeEventsViewer,
|
|
9
|
-
externalTime: number,
|
|
10
|
-
position?: number,
|
|
11
|
-
): Promise<bigint> {
|
|
12
|
-
const stakeEvents = (await mergedAddRemoveStakeEventsByPosition(chainStakeEvents, [0, externalTime], position)).toSorted((a, b) => a.time - b.time)
|
|
13
|
-
let result = 0n
|
|
14
|
-
for (const event of stakeEvents) {
|
|
15
|
-
if (event.time > externalTime) break
|
|
16
|
-
if (isUndefined(position) || position === Number(event.args.id)) {
|
|
17
|
-
if (event.name === 'StakeAdded') {
|
|
18
|
-
result += event.args.amount
|
|
19
|
-
} else if (event.name === 'StakeRemoved') {
|
|
20
|
-
result -= event.args.amount
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return result
|
|
25
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Address,
|
|
3
|
-
toAddress,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type { StakeEventsViewer } from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
|
|
7
|
-
import { mergedAddRemoveStakeEventsByStaker } from './mergedAddRemoveStakeEventsByStaker.ts'
|
|
8
|
-
|
|
9
|
-
/** AllStakersForRange helper function. */
|
|
10
|
-
export async function allStakersForRange(
|
|
11
|
-
chain: StakeEventsViewer,
|
|
12
|
-
externalRange: [number, number],
|
|
13
|
-
staked: Address,
|
|
14
|
-
): Promise<Record<Address, bigint>> {
|
|
15
|
-
const mergedEvents = await mergedAddRemoveStakeEventsByStaker(chain, [0, externalRange[1]], staked)
|
|
16
|
-
const resultWithZeros: Record<Address, bigint> = {}
|
|
17
|
-
for (const event of mergedEvents) {
|
|
18
|
-
const staker = toAddress(event.args.staker)
|
|
19
|
-
resultWithZeros[staker] = resultWithZeros[staker] ?? 0n
|
|
20
|
-
if (event.name === 'StakeAdded') {
|
|
21
|
-
resultWithZeros[staker] += event.args.amount
|
|
22
|
-
} else if (event.name === 'StakeRemoved') {
|
|
23
|
-
resultWithZeros[staker] -= event.args.amount
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const nonZero = Object.entries(resultWithZeros).filter(([, amount]) => amount > 0n).map(([address]) => address)
|
|
27
|
-
const result: Record<Address, bigint> = {}
|
|
28
|
-
for (const address of nonZero) {
|
|
29
|
-
result[toAddress(address)] = resultWithZeros[toAddress(address)]
|
|
30
|
-
}
|
|
31
|
-
return result
|
|
32
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type Address } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
BlockViewer, CachingContext, StakeEventsViewer, StepIdentity,
|
|
4
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
|
|
6
|
-
import { externalBlockRangeFromXL1BlockRange } from '../chain/index.ts'
|
|
7
|
-
import { stepBlockRange } from '../step/index.ts'
|
|
8
|
-
import { allStakersForRange } from './allStakersForRange.ts'
|
|
9
|
-
|
|
10
|
-
/** AllStakersForStep helper function. */
|
|
11
|
-
export async function allStakersForStep(
|
|
12
|
-
context: CachingContext,
|
|
13
|
-
blockViewer: BlockViewer,
|
|
14
|
-
stakeEventsViewer: StakeEventsViewer,
|
|
15
|
-
stepContext: StepIdentity,
|
|
16
|
-
staked: Address,
|
|
17
|
-
): Promise<Record<Address, bigint>> {
|
|
18
|
-
const xl1BlockRange = stepBlockRange(stepContext)
|
|
19
|
-
return await allStakersForRange(
|
|
20
|
-
stakeEventsViewer,
|
|
21
|
-
await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange),
|
|
22
|
-
staked,
|
|
23
|
-
)
|
|
24
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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'
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { StakeEvent, StakeEventsViewer } from '@xyo-network/xl1-protocol-lib'
|
|
2
|
-
|
|
3
|
-
/** MergedAddRemoveStakeEventsByPosition helper function. */
|
|
4
|
-
export async function mergedAddRemoveStakeEventsByPosition(
|
|
5
|
-
chainEvents: StakeEventsViewer,
|
|
6
|
-
range: [number, number],
|
|
7
|
-
position?: number,
|
|
8
|
-
): Promise<(StakeEvent<'StakeAdded'> | StakeEvent<'StakeRemoved'>)[]> {
|
|
9
|
-
const [addedEvents, removedEvents] = await Promise.all([
|
|
10
|
-
chainEvents.stakeEvents(range, { name: 'StakeAdded', args: { id: position } }),
|
|
11
|
-
chainEvents.stakeEvents(range, { name: 'StakeRemoved', args: { id: position } }),
|
|
12
|
-
])
|
|
13
|
-
const result = [...addedEvents, ...removedEvents].toSorted((a, b) => a.time - b.time)
|
|
14
|
-
return result
|
|
15
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import type { StakeEvent, StakeEventsViewer } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
/** MergedAddRemoveStakeEventsByStaker helper function. */
|
|
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
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
BlockRange,
|
|
5
|
-
BlockViewer,
|
|
6
|
-
CachingContext,
|
|
7
|
-
StakeEventsViewer,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import { asBlockNumber } from '@xyo-network/xl1-protocol-lib'
|
|
10
|
-
|
|
11
|
-
import { withContextCacheResponse } from '../../ChainContextHelpers.ts'
|
|
12
|
-
import { mergedAddRemoveStakeEventsByPosition } from './mergedAddRemoveStakeEventsByPosition.ts'
|
|
13
|
-
|
|
14
|
-
/** WeightedStakeForRangeByPosition helper function. */
|
|
15
|
-
export async function weightedStakeForRangeByPosition(
|
|
16
|
-
context: CachingContext,
|
|
17
|
-
blockViewer: BlockViewer,
|
|
18
|
-
stakeEventsViewer: StakeEventsViewer,
|
|
19
|
-
externalRange: BlockRange, // first to last block of step
|
|
20
|
-
staked?: Address,
|
|
21
|
-
positionId?: number,
|
|
22
|
-
): Promise<bigint> {
|
|
23
|
-
const cacheKey = isDefined(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`
|
|
24
|
-
return await withContextCacheResponse(context, 'weightedStakeForRangeByPosition', cacheKey, async () => {
|
|
25
|
-
let weightedStakeSum = 0n
|
|
26
|
-
if (isDefined(positionId)) {
|
|
27
|
-
const mergedEvents = (await mergedAddRemoveStakeEventsByPosition(
|
|
28
|
-
stakeEventsViewer,
|
|
29
|
-
[0, externalRange[1]],
|
|
30
|
-
positionId,
|
|
31
|
-
)).toSorted((a, b) => a.time - b.time)
|
|
32
|
-
let currentTime = externalRange[0]
|
|
33
|
-
let currentStake = 0n // await activeStakeAtTimeByPosition(chainEvents, pos.staked, currentTime - 1, position)
|
|
34
|
-
|
|
35
|
-
// if not staking the desired address, return 0n
|
|
36
|
-
if (isDefined(staked) && mergedEvents.at(0)?.args.staked !== staked) {
|
|
37
|
-
return 0n
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (const event of mergedEvents) {
|
|
41
|
-
if (event.time > currentTime) {
|
|
42
|
-
// Add the weighted stake for the period between the range start or previous event and this event
|
|
43
|
-
weightedStakeSum += currentStake * BigInt(event.time - currentTime)
|
|
44
|
-
}
|
|
45
|
-
if (event.name === 'StakeAdded') {
|
|
46
|
-
currentStake += event.args.amount
|
|
47
|
-
} else if (event.name === 'StakeRemoved') {
|
|
48
|
-
currentStake -= event.args.amount
|
|
49
|
-
}
|
|
50
|
-
// seems that sometimes we get multiple remove events, so ensure stake doesn't go negative
|
|
51
|
-
currentStake = currentStake < 0n ? 0n : currentStake
|
|
52
|
-
currentTime = asBlockNumber(event.time, { name: 'weightedStakeForRangeByPosition' })
|
|
53
|
-
if (currentTime > externalRange[1]) {
|
|
54
|
-
break
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (externalRange[1] > currentTime) {
|
|
58
|
-
// Add the weighted stake for the period between the last event and the end of the range
|
|
59
|
-
weightedStakeSum += currentStake * BigInt(externalRange[1] - currentTime)
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
const positionCount = await stakeEventsViewer.positionCount([0, externalRange[1]])
|
|
63
|
-
for (let pos = 0; pos < positionCount; pos++) {
|
|
64
|
-
weightedStakeSum += await weightedStakeForRangeByPosition(context, blockViewer, stakeEventsViewer, externalRange, staked, pos)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return weightedStakeSum
|
|
68
|
-
})
|
|
69
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
NextOptions, Payload, ReadArchivist,
|
|
3
|
-
Sequence, WithStorageMeta,
|
|
4
|
-
} from '@xyo-network/sdk-js'
|
|
5
|
-
import type { SignedBlockBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
import { isSignedBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
|
|
8
|
-
// TODO: Use some smart value relative to DEFAULT_BLOCK_SIZE
|
|
9
|
-
// to ensure we're likely to find it in a single request
|
|
10
|
-
// without bringing back too much data
|
|
11
|
-
const DEFAULT_NEXT_OPTIONS: NextOptions = { limit: 50 }
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Iterates an archivist to find the most recent block
|
|
15
|
-
* @param chainArchivist The archivist to iterate over for the most recent chain block
|
|
16
|
-
* @param nextOptions The options to use when iterating the archivist
|
|
17
|
-
* @param maxIterations The max number of iterations to perform when finding the most recent block
|
|
18
|
-
* @returns The most recent block found in the archivist or undefined if no blocks are found
|
|
19
|
-
*/
|
|
20
|
-
export const findMostRecentBlock = async (
|
|
21
|
-
chainArchivist: ReadArchivist,
|
|
22
|
-
nextOptions: NextOptions = DEFAULT_NEXT_OPTIONS,
|
|
23
|
-
maxIterations = Number.POSITIVE_INFINITY,
|
|
24
|
-
): Promise<SignedBlockBoundWitnessWithHashMeta | undefined> => {
|
|
25
|
-
let mostRecentBlock: SignedBlockBoundWitnessWithHashMeta | undefined
|
|
26
|
-
let cursor: Sequence | undefined
|
|
27
|
-
let batch: WithStorageMeta<Payload>[]
|
|
28
|
-
let iterations = 0
|
|
29
|
-
do {
|
|
30
|
-
batch = await chainArchivist.next({
|
|
31
|
-
...nextOptions, order: 'desc', cursor,
|
|
32
|
-
})
|
|
33
|
-
const blocks = batch.filter(isSignedBlockBoundWitnessWithStorageMeta)
|
|
34
|
-
const last = blocks?.at(0)
|
|
35
|
-
if (last) {
|
|
36
|
-
mostRecentBlock = last
|
|
37
|
-
break
|
|
38
|
-
} else {
|
|
39
|
-
cursor = batch.at(-1)?._sequence
|
|
40
|
-
}
|
|
41
|
-
iterations = iterations + 1
|
|
42
|
-
} while (batch.length > 0 && iterations < maxIterations)
|
|
43
|
-
return mostRecentBlock
|
|
44
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { assertEx, spanAsync } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
ChainContextRead,
|
|
4
|
-
HydratedBlockWithHashMeta, XL1BlockNumber,
|
|
5
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
|
|
7
|
-
import { blockFromBlockNumber, hydrateBlock } from '../../block/index.ts'
|
|
8
|
-
import { withContextCacheResponse } from '../../ChainContextHelpers.ts'
|
|
9
|
-
|
|
10
|
-
/** HydratedBlockByNumber helper function. */
|
|
11
|
-
export async function hydratedBlockByNumber(context: ChainContextRead, blockNumber: XL1BlockNumber): Promise<HydratedBlockWithHashMeta | null> {
|
|
12
|
-
return await spanAsync('hydratedBlockByNumber', async () => {
|
|
13
|
-
if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`)
|
|
14
|
-
if (blockNumber > Number.MAX_SAFE_INTEGER) throw new Error(`Block number ${blockNumber} is greater than the maximum safe integer`)
|
|
15
|
-
if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`)
|
|
16
|
-
const cacheKey = `${blockNumber}`
|
|
17
|
-
return await withContextCacheResponse(context, 'hydratedBlockByNumber', cacheKey, async () => {
|
|
18
|
-
const block = assertEx(
|
|
19
|
-
await blockFromBlockNumber(context, blockNumber),
|
|
20
|
-
() => `Could not find block for block number ${blockNumber}`,
|
|
21
|
-
)
|
|
22
|
-
return await hydrateBlock(context, block._hash)
|
|
23
|
-
}, { max: 20_000 })
|
|
24
|
-
}, { ...context, timeBudgetLimit: 500 })
|
|
25
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Address, toAddress } from '@xylabs/sdk-js'
|
|
2
|
-
import { type StepIdentity, StepSizes } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
import { keccak256 } from 'ethers'
|
|
4
|
-
|
|
5
|
-
/** CompletedStepRewardAddress helper function. */
|
|
6
|
-
export function completedStepRewardAddress({ block, step }: StepIdentity): Address {
|
|
7
|
-
const resolvedStepSize = step < StepSizes.length ? StepSizes[step] : step
|
|
8
|
-
const addressKey = new TextEncoder().encode(`${block}|${resolvedStepSize}`)
|
|
9
|
-
return toAddress(keccak256(addressKey).slice(-40), { prefix: false })
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Address, toAddress } from '@xylabs/sdk-js'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import { keccak256 } from 'ethers'
|
|
4
|
-
|
|
5
|
-
/** DerivedReceiveAddress helper function. */
|
|
6
|
-
export function derivedReceiveAddress(address: Address, scope?: string): Address {
|
|
7
|
-
const addressKey = new TextEncoder().encode(isDefined(scope) ? `${scope}|${address}` : address)
|
|
8
|
-
return toAddress(keccak256(addressKey).slice(-40), { prefix: false })
|
|
9
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { StepIdentity, XL1BlockRange } from '@xyo-network/xl1-protocol-lib'
|
|
2
|
-
import { asXL1BlockRange, StepSizes } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
/** StepBlockRange helper function. */
|
|
5
|
-
export function stepBlockRange({ block, step }: StepIdentity): XL1BlockRange {
|
|
6
|
-
const stepSize = StepSizes[step]
|
|
7
|
-
const start = block - stepSize
|
|
8
|
-
return asXL1BlockRange([start, start + stepSize - 1], { name: 'stepBlockRange' })
|
|
9
|
-
}
|