@xyo-network/xl1-protocol-sdk 1.26.12 → 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/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +2 -2
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +1 -1
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +1 -1
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +10 -10
- package/dist/neutral/transaction/TransactionBuilder.d.ts +4 -4
- package/dist/neutral/transaction/signTransaction.d.ts +1 -1
- package/package.json +24 -14
- 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
package/src/model/ChainStore.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Payload, ReadArchivist, WriteArchivist,
|
|
3
|
-
} from '@xyo-network/sdk-js'
|
|
4
|
-
|
|
5
|
-
/** ChainStoreWrite interface. */
|
|
6
|
-
export interface ChainStoreWrite {
|
|
7
|
-
chainMap: WriteArchivist<Payload>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** ChainStoreRead interface. */
|
|
11
|
-
export interface ChainStoreRead {
|
|
12
|
-
chainMap: ReadArchivist<Payload>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** ChainStore type. */
|
|
16
|
-
export type ChainStore = ChainStoreRead & ChainStoreWrite
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
zodAsFactory, zodIsFactory, zodToFactory,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { CachingContext } from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
import { CachingContextZod } from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
import { z } from 'zod'
|
|
7
|
-
|
|
8
|
-
import { type BaseConfig, BaseConfigZod } from '../config/index.ts'
|
|
9
|
-
import type { ProviderFactoryLocatorInstance } from '../CreatableProvider/index.ts'
|
|
10
|
-
import type { RuntimeStatusMonitor } from '../status/index.ts'
|
|
11
|
-
|
|
12
|
-
/** RuntimeStatusMonitorZod constant. */
|
|
13
|
-
export const RuntimeStatusMonitorZod = z.custom<RuntimeStatusMonitor>(val => val && typeof val === 'object')
|
|
14
|
-
|
|
15
|
-
/** ProviderFactoryLocatorZod constant. */
|
|
16
|
-
export const ProviderFactoryLocatorZod: z.ZodType<ProviderFactoryLocatorInstance> = z.lazy(() =>
|
|
17
|
-
z.custom<ProviderFactoryLocatorInstance>(val => val && typeof val === 'object' && 'context' in val && 'registry' in val))
|
|
18
|
-
|
|
19
|
-
/** CreatableProviderContextType type. */
|
|
20
|
-
export type CreatableProviderContextType = CachingContext & {
|
|
21
|
-
_id?: string
|
|
22
|
-
config: BaseConfig
|
|
23
|
-
locator: ProviderFactoryLocatorInstance
|
|
24
|
-
statusReporter?: RuntimeStatusMonitor
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** BaseConfigContextZod constant. */
|
|
28
|
-
export const BaseConfigContextZod = CachingContextZod.extend({
|
|
29
|
-
config: BaseConfigZod.loose(),
|
|
30
|
-
locator: ProviderFactoryLocatorZod.optional(),
|
|
31
|
-
})
|
|
32
|
-
/** BaseConfigContext type. */
|
|
33
|
-
export type BaseConfigContext = z.infer<typeof BaseConfigContextZod>
|
|
34
|
-
|
|
35
|
-
/** CreatableProviderContextZod constant. */
|
|
36
|
-
export const CreatableProviderContextZod: z.ZodType<CreatableProviderContextType> = z.lazy(() =>
|
|
37
|
-
BaseConfigContextZod.extend({
|
|
38
|
-
_id: z.string().optional(),
|
|
39
|
-
locator: ProviderFactoryLocatorZod,
|
|
40
|
-
statusReporter: RuntimeStatusMonitorZod.optional(),
|
|
41
|
-
}))
|
|
42
|
-
|
|
43
|
-
/** Type guard that checks if a value is a valid BaseConfigContext. */
|
|
44
|
-
export const isBaseConfigContext = zodIsFactory(BaseConfigContextZod)
|
|
45
|
-
/** Converts a value to BaseConfigContext, throwing if invalid. */
|
|
46
|
-
export const asBaseConfigContext = zodAsFactory(BaseConfigContextZod, 'asBaseConfigContext')
|
|
47
|
-
/** toBaseConfigContext constant. */
|
|
48
|
-
export const toBaseConfigContext = zodToFactory(BaseConfigContextZod, 'toBaseConfigContext')
|
|
49
|
-
|
|
50
|
-
/** Type guard that checks if a value is a valid CreatableProviderContext. */
|
|
51
|
-
export const isCreatableProviderContext = zodIsFactory(CreatableProviderContextZod)
|
|
52
|
-
/** Converts a value to CreatableProviderContext, throwing if invalid. */
|
|
53
|
-
export const asCreatableProviderContext = zodAsFactory(CreatableProviderContextZod, 'asCreatableProviderContext')
|
|
54
|
-
/** toCreatableProviderContext constant. */
|
|
55
|
-
export const toCreatableProviderContext = zodToFactory(CreatableProviderContextZod, 'toCreatableProviderContext')
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PayloadBundle } from '@xyo-network/sdk-js'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
import { asSignedBlockBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
|
|
6
|
-
/** bundledPayloadToHydratedBlock constant. */
|
|
7
|
-
export const bundledPayloadToHydratedBlock = async (
|
|
8
|
-
payload: PayloadBundle,
|
|
9
|
-
): Promise<SignedHydratedBlockWithHashMeta | undefined> => {
|
|
10
|
-
const withHashMeta = await PayloadBuilder.addHashMeta(payload.payloads)
|
|
11
|
-
const tx = asSignedBlockBoundWitnessWithHashMeta(withHashMeta.find(p => p._hash === payload.root))
|
|
12
|
-
if (tx) {
|
|
13
|
-
return [tx, withHashMeta.filter(p => p._hash !== payload.root)]
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PayloadBundle } from '@xyo-network/sdk-js'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import type { SignedHydratedTransactionWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
4
|
-
import { asSignedTransactionBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
|
|
6
|
-
/** bundledPayloadToHydratedTransaction constant. */
|
|
7
|
-
export const bundledPayloadToHydratedTransaction = async (
|
|
8
|
-
payload: PayloadBundle,
|
|
9
|
-
): Promise<SignedHydratedTransactionWithHashMeta | undefined> => {
|
|
10
|
-
const withHashMeta = await PayloadBuilder.addHashMeta(payload.payloads)
|
|
11
|
-
const tx = asSignedTransactionBoundWitnessWithHashMeta(withHashMeta.find(p => p._hash === payload.root))
|
|
12
|
-
if (tx) {
|
|
13
|
-
return [tx, withHashMeta.filter(p => p._hash !== payload.root)]
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { type PayloadBundle, PayloadBundleSchema } from '@xyo-network/sdk-js'
|
|
3
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
|
-
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
|
|
6
|
-
import { flattenHydratedBlock } from '../../block/index.ts'
|
|
7
|
-
|
|
8
|
-
/** hydratedBlockToPayloadBundle constant. */
|
|
9
|
-
export const hydratedBlockToPayloadBundle = (transaction: SignedHydratedBlockWithHashMeta): PayloadBundle => {
|
|
10
|
-
const root = transaction[0]._hash
|
|
11
|
-
return bundle(root, transaction)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const bundle = (root: Hash, transaction: SignedHydratedBlockWithHashMeta) => {
|
|
15
|
-
const payloads = flattenHydratedBlock(transaction).flatMap(p => PayloadBuilder.omitStorageMeta(p))
|
|
16
|
-
return new PayloadBuilder<PayloadBundle>({ schema: PayloadBundleSchema })
|
|
17
|
-
.fields({ payloads, root })
|
|
18
|
-
.build()
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
-
import { type PayloadBundle, PayloadBundleSchema } from '@xyo-network/sdk-js'
|
|
3
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
|
-
import type { SignedHydratedTransactionWithHashMeta } from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
|
|
6
|
-
import { flattenHydratedTransaction } from '../../transaction/index.ts'
|
|
7
|
-
|
|
8
|
-
/** hydratedTransactionToPayloadBundle constant. */
|
|
9
|
-
export const hydratedTransactionToPayloadBundle = (transaction: SignedHydratedTransactionWithHashMeta): PayloadBundle => {
|
|
10
|
-
const root = transaction[0]._hash
|
|
11
|
-
return bundle(root, transaction)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const bundle = (root: Hash, transaction: SignedHydratedTransactionWithHashMeta) => {
|
|
15
|
-
const payloads = flattenHydratedTransaction(transaction).flatMap(p => PayloadBuilder.omitStorageMeta(p))
|
|
16
|
-
return new PayloadBuilder<PayloadBundle>({ schema: PayloadBundleSchema })
|
|
17
|
-
.fields({ payloads, root })
|
|
18
|
-
.build()
|
|
19
|
-
}
|
package/src/model/index.ts
DELETED
package/src/multipliers.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { XL1BlockRangeKey, XL1RangeMultipliers } from '@xyo-network/xl1-protocol-lib'
|
|
2
|
-
import { asAttoXL1 } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
import { XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK } from './constants.ts'
|
|
5
|
-
|
|
6
|
-
/** XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS constant. */
|
|
7
|
-
export const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS = asAttoXL1(1_343_884_111_859_145_740_576_652n)
|
|
8
|
-
/** XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS constant. */
|
|
9
|
-
export const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS = asAttoXL1(100_000_000_000_000_000_000_000_000n)
|
|
10
|
-
/** XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS constant. */
|
|
11
|
-
export const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS
|
|
12
|
-
= XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS + XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS
|
|
13
|
-
|
|
14
|
-
/** RewardMultipliers constant. */
|
|
15
|
-
export const RewardMultipliers: XL1RangeMultipliers = {
|
|
16
|
-
[`0|${XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK}` as XL1BlockRangeKey]:
|
|
17
|
-
[XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS, XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_EARNED_REWARDS],
|
|
18
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import { AsObjectFactory } from '@xylabs/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
asSchema, isPayloadOfSchemaType, type Payload,
|
|
5
|
-
} from '@xyo-network/sdk-js'
|
|
6
|
-
|
|
7
|
-
/** Schema identifier for AddressPair payloads. */
|
|
8
|
-
export const AddressPairSchema = asSchema('network.xyo.address.pair', true)
|
|
9
|
-
/** Schema type for AddressPair payloads. */
|
|
10
|
-
export type AddressPairSchema = typeof AddressPairSchema
|
|
11
|
-
|
|
12
|
-
/** AddressFields interface. */
|
|
13
|
-
export interface AddressFields {
|
|
14
|
-
addresses: [Address, Address]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** AddressPairPayload type. */
|
|
18
|
-
export type AddressPairPayload = Payload<AddressFields, AddressPairSchema>
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Identity function for determining if an object is an AddressPairPayload
|
|
22
|
-
*/
|
|
23
|
-
export const isAddressPairPayload = isPayloadOfSchemaType<AddressPairPayload>(AddressPairSchema)
|
|
24
|
-
/** Converts a value to AddressPairPayload, throwing if invalid. */
|
|
25
|
-
export const asAddressPairPayload = AsObjectFactory.create(isAddressPairPayload)
|
|
26
|
-
/** Optionally converts a value to AddressPairPayload if valid. */
|
|
27
|
-
export const asOptionalAddressPairPayload = AsObjectFactory.createOptional(isAddressPairPayload)
|
package/src/payloads/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Address, type Hex, hexToBigInt, toAddress,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { span } from '@xylabs/sdk-js'
|
|
5
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { BaseContext } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import { isTransfer } from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
/** netBalancesForPayloads constant. */
|
|
10
|
-
export const netBalancesForPayloads = (context: BaseContext, payloads: Payload[]) => {
|
|
11
|
-
return span('netBalancesForPayloads', () => {
|
|
12
|
-
const balances: Record<Address, bigint> = {}
|
|
13
|
-
for (const payload of payloads) {
|
|
14
|
-
if (isTransfer(payload)) {
|
|
15
|
-
const { from } = payload
|
|
16
|
-
for (let [address, amount] of Object.entries(payload.transfers) as [Address, Hex][]) {
|
|
17
|
-
balances[toAddress(address)] = (balances[toAddress(address)] ?? 0n) + hexToBigInt(amount)
|
|
18
|
-
balances[toAddress(from)] = (balances[toAddress(from)] ?? 0n) - hexToBigInt(amount)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return balances
|
|
23
|
-
}, context.traceProvider)
|
|
24
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Address, type Hex, hexToBigInt, toAddress,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { span } from '@xylabs/sdk-js'
|
|
5
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { BaseContext } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import { isTransfer } from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
/** netSchemasForPayloads constant. */
|
|
10
|
-
export const netSchemasForPayloads = (context: BaseContext, payloads: Payload[]) => {
|
|
11
|
-
return span('netSchemasForPayloads', () => {
|
|
12
|
-
const balances: Record<Address, bigint> = {}
|
|
13
|
-
for (const payload of payloads) {
|
|
14
|
-
if (isTransfer(payload)) {
|
|
15
|
-
const { from } = payload
|
|
16
|
-
for (let [address, amount] of Object.entries(payload.transfers) as [Address, Hex][]) {
|
|
17
|
-
balances[toAddress(address)] = (balances[toAddress(address)] ?? 0n) + hexToBigInt(amount)
|
|
18
|
-
balances[toAddress(from)] = (balances[toAddress(from)] ?? 0n) - hexToBigInt(amount)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return balances
|
|
23
|
-
}, context.traceProvider)
|
|
24
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Address, type Hex, hexToBigInt,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import { span } from '@xylabs/sdk-js'
|
|
5
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { BaseContext } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import { isTransfer } from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
|
|
9
|
-
// the net transfer amounts for the specified accounts only
|
|
10
|
-
/** NetTransfersForPayloads helper function. */
|
|
11
|
-
export function netTransfersForPayloads(context: BaseContext, payloads: Payload[]): Record<Address, Record<Address, bigint>> {
|
|
12
|
-
return span('netTransfersForPayloads', () => {
|
|
13
|
-
const transfers: Record<Address, Record<Address, bigint>> = {}
|
|
14
|
-
for (const payload of payloads) {
|
|
15
|
-
if (isTransfer(payload)) {
|
|
16
|
-
const { from } = payload
|
|
17
|
-
transfers[from] = transfers[from] ?? {}
|
|
18
|
-
for (let [to, amount] of Object.entries(payload.transfers) as [Address, Hex][]) {
|
|
19
|
-
transfers[to] = transfers[to] ?? {}
|
|
20
|
-
transfers[to][from] = (transfers[to][from] ?? 0n) + hexToBigInt(amount)
|
|
21
|
-
transfers[from][to] = (transfers[from][to] ?? 0n) - hexToBigInt(amount)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return transfers
|
|
26
|
-
}, context.traceProvider)
|
|
27
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
StepIdentity,
|
|
3
|
-
XL1BlockRange,
|
|
4
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
5
|
-
import { asXL1BlockNumber, StepSizes } from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
|
|
7
|
-
/** BlockRangeSteps helper function. */
|
|
8
|
-
export function blockRangeSteps(range: XL1BlockRange, steps: number[]): StepIdentity[] {
|
|
9
|
-
const result: StepIdentity[] = []
|
|
10
|
-
for (const step of steps) {
|
|
11
|
-
const stepSize = StepSizes[step]
|
|
12
|
-
// we add stepSize twice to get to the start of the next full step
|
|
13
|
-
const startOfFirstStepCandidate = range[0] - (range[0] % stepSize) + stepSize
|
|
14
|
-
const startOfFirstStep = asXL1BlockNumber(
|
|
15
|
-
startOfFirstStepCandidate,
|
|
16
|
-
{ name: 'blockRangeSteps' },
|
|
17
|
-
)
|
|
18
|
-
for (let block = startOfFirstStep; block <= range[1]; block = asXL1BlockNumber(block + stepSize, { name: 'blockRangeSteps' })) {
|
|
19
|
-
result.push({ step, block })
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './blockRangeSteps.ts'
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { isDefined, isFalsy } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
BlockViewer,
|
|
4
|
-
HydratedBlock, TimeDurations, XL1BlockNumber, XL1BlockRange, XL1BlockRate,
|
|
5
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
import { asXL1BlockRange } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
|
|
8
|
-
import { rateMultipliers, timeDurations } from './timeHelpers.ts'
|
|
9
|
-
|
|
10
|
-
/** blockRate constant. */
|
|
11
|
-
export const blockRate = (
|
|
12
|
-
startBlock: HydratedBlock,
|
|
13
|
-
endBlock: HydratedBlock,
|
|
14
|
-
timeUnit?: keyof TimeDurations,
|
|
15
|
-
): XL1BlockRate => {
|
|
16
|
-
const startingBlock = startBlock[0]
|
|
17
|
-
const endingBlock = endBlock[0]
|
|
18
|
-
|
|
19
|
-
const heightDifference = endingBlock.block - startingBlock.block
|
|
20
|
-
const timeDifference = endingBlock.$epoch - startingBlock.$epoch
|
|
21
|
-
|
|
22
|
-
if (timeDifference === 0) {
|
|
23
|
-
throw new Error('Time difference must be greater than 0')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const rate = heightDifference / timeDifference
|
|
27
|
-
|
|
28
|
-
const timeUnitValue = isDefined(timeUnit) ? timeUnit : 'millis'
|
|
29
|
-
const returnedTimeDifference = isDefined(timeUnit) ? timeDurations(timeDifference)[timeUnit] : timeDifference
|
|
30
|
-
const timePerBlock = returnedTimeDifference / heightDifference
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
range: asXL1BlockRange([startingBlock.block, endingBlock.block], true),
|
|
34
|
-
span: heightDifference,
|
|
35
|
-
rate: isDefined(timeUnit) ? rate * rateMultipliers[timeUnit] : rate,
|
|
36
|
-
timeUnit: timeUnitValue,
|
|
37
|
-
timeDifference: returnedTimeDifference,
|
|
38
|
-
timePerBlock,
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** getBlockRateBlocks constant. */
|
|
43
|
-
export const getBlockRateBlocks = async (
|
|
44
|
-
viewer: BlockViewer,
|
|
45
|
-
startBlockHeight: XL1BlockNumber,
|
|
46
|
-
endBlockHeight: XL1BlockNumber,
|
|
47
|
-
): Promise<{ endingBlock: HydratedBlock; startingBlock: HydratedBlock }> => {
|
|
48
|
-
if (endBlockHeight <= startBlockHeight) {
|
|
49
|
-
console.error('startBlockHeight', startBlockHeight)
|
|
50
|
-
console.error('endBlockHeight', endBlockHeight)
|
|
51
|
-
throw new Error('End block height must be greater than start block height')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const startingBlock = await viewer.blockByNumber(startBlockHeight)
|
|
55
|
-
const endingBlock = await viewer.blockByNumber(endBlockHeight)
|
|
56
|
-
|
|
57
|
-
if (isFalsy(startingBlock) || isFalsy(endingBlock)) {
|
|
58
|
-
throw new Error('Could not retrieve blocks for speed calculation')
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return { startingBlock, endingBlock }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** calculateBlockRate constant. */
|
|
65
|
-
export const calculateBlockRate = async (
|
|
66
|
-
viewer: BlockViewer,
|
|
67
|
-
range: XL1BlockRange,
|
|
68
|
-
timeUnit?: keyof TimeDurations,
|
|
69
|
-
): Promise<XL1BlockRate> => {
|
|
70
|
-
const [startBlockHeight, endBlockHeight] = range
|
|
71
|
-
const { startingBlock, endingBlock } = await getBlockRateBlocks(
|
|
72
|
-
viewer,
|
|
73
|
-
startBlockHeight,
|
|
74
|
-
endBlockHeight,
|
|
75
|
-
)
|
|
76
|
-
return blockRate(startingBlock, endingBlock, timeUnit)
|
|
77
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
BlockViewer,
|
|
4
|
-
TimeDurations, XL1BlockNumber, XL1BlockRate,
|
|
5
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
import {
|
|
7
|
-
asXL1BlockRange, isValidStep, StepSizes,
|
|
8
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
|
|
10
|
-
import { calculateBlockRate } from './blockRate.ts'
|
|
11
|
-
|
|
12
|
-
/** stepRate constant. */
|
|
13
|
-
export const stepRate = async (
|
|
14
|
-
viewer: BlockViewer,
|
|
15
|
-
start: XL1BlockNumber,
|
|
16
|
-
step: typeof StepSizes[number],
|
|
17
|
-
count = 1,
|
|
18
|
-
timeUnit?: keyof TimeDurations,
|
|
19
|
-
): Promise<XL1BlockRate> => {
|
|
20
|
-
const end = start + step * count
|
|
21
|
-
const range = asXL1BlockRange([start, end], true)
|
|
22
|
-
|
|
23
|
-
return await calculateBlockRate(viewer, range, timeUnit)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** calculateStepSizeRate constant. */
|
|
27
|
-
export const calculateStepSizeRate = async (
|
|
28
|
-
viewer: BlockViewer,
|
|
29
|
-
start: XL1BlockNumber,
|
|
30
|
-
stepIndex: number,
|
|
31
|
-
count = 1,
|
|
32
|
-
timeUnit?: keyof TimeDurations,
|
|
33
|
-
) => {
|
|
34
|
-
assertEx(isValidStep(stepIndex), () => `Invalid step index: ${stepIndex}`)
|
|
35
|
-
const step = StepSizes[stepIndex]
|
|
36
|
-
return await stepRate(viewer, start, step, count, timeUnit)
|
|
37
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { SingleTimeConfig, TimeDurations } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
/** rateMultipliers constant. */
|
|
5
|
-
export const rateMultipliers: TimeDurations = {
|
|
6
|
-
millis: 1,
|
|
7
|
-
seconds: 1000,
|
|
8
|
-
minutes: 1000 * 60,
|
|
9
|
-
hours: 1000 * 60 * 60,
|
|
10
|
-
days: 1000 * 60 * 60 * 24,
|
|
11
|
-
weeks: 1000 * 60 * 60 * 24 * 7,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** timeDurations constant. */
|
|
15
|
-
export const timeDurations = (timeInMs: number): TimeDurations => ({
|
|
16
|
-
millis: timeInMs,
|
|
17
|
-
seconds: timeInMs / 1000,
|
|
18
|
-
minutes: timeInMs / (1000 * 60),
|
|
19
|
-
hours: timeInMs / (1000 * 60 * 60),
|
|
20
|
-
days: timeInMs / (1000 * 60 * 60 * 24),
|
|
21
|
-
weeks: timeInMs / (1000 * 60 * 60 * 24 * 7),
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
/** getTimeConfigInMilliseconds constant. */
|
|
25
|
-
export const getTimeConfigInMilliseconds = (timeConfig: SingleTimeConfig): number => {
|
|
26
|
-
const assertedTimeConfig = assertEx(isDefined(timeConfig) ? timeConfig : undefined, () => 'Time configuration must be provided')
|
|
27
|
-
// Convert all time units to milliseconds
|
|
28
|
-
let totalMilliseconds = 0
|
|
29
|
-
|
|
30
|
-
if ('years' in assertedTimeConfig) {
|
|
31
|
-
totalMilliseconds += assertedTimeConfig.years * 31_536_000_000 // 1 year = 31,536,000,000 milliseconds
|
|
32
|
-
return totalMilliseconds
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if ('months' in assertedTimeConfig) {
|
|
36
|
-
totalMilliseconds += assertedTimeConfig.months * 2_592_000_000 // 1 month = 2,592,000,000 milliseconds
|
|
37
|
-
return totalMilliseconds
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if ('weeks' in assertedTimeConfig) {
|
|
41
|
-
totalMilliseconds += assertedTimeConfig.weeks * 604_800_000 // 1 week = 604,800,000 milliseconds
|
|
42
|
-
return totalMilliseconds
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if ('days' in assertedTimeConfig) {
|
|
46
|
-
totalMilliseconds += assertedTimeConfig.days * 86_400_000 // 1 day = 86,400,000 milliseconds
|
|
47
|
-
return totalMilliseconds
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if ('hours' in assertedTimeConfig) {
|
|
51
|
-
totalMilliseconds += assertedTimeConfig.hours * 3_600_000 // 1 hour = 3,600,000 milliseconds
|
|
52
|
-
return totalMilliseconds
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if ('minutes' in assertedTimeConfig) {
|
|
56
|
-
totalMilliseconds += assertedTimeConfig.minutes * 60_000 // 1 minute = 60,000 milliseconds
|
|
57
|
-
return totalMilliseconds
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return totalMilliseconds
|
|
61
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertEx, isDefined, isDefinedNotNull,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
BlockBoundWitness,
|
|
6
|
-
BlockViewer,
|
|
7
|
-
SingleTimeConfig,
|
|
8
|
-
TimeDurations,
|
|
9
|
-
XL1BlockNumber,
|
|
10
|
-
XL1BlockRate,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import { asXL1BlockNumber, asXL1BlockRange } from '@xyo-network/xl1-protocol-lib'
|
|
13
|
-
|
|
14
|
-
import { calculateBlockRate } from './blockRate.ts'
|
|
15
|
-
import { getTimeConfigInMilliseconds } from './timeHelpers.ts'
|
|
16
|
-
|
|
17
|
-
/** DEFAULT_TOLERANCE_MS constant. */
|
|
18
|
-
export const DEFAULT_TOLERANCE_MS = 30_000 // 30 seconds
|
|
19
|
-
/** DEFAULT_MAX_ATTEMPTS constant. */
|
|
20
|
-
export const DEFAULT_MAX_ATTEMPTS = 10
|
|
21
|
-
|
|
22
|
-
/** calculateTimeRate constant. */
|
|
23
|
-
export const calculateTimeRate = async (
|
|
24
|
-
viewer: BlockViewer,
|
|
25
|
-
timeConfig: SingleTimeConfig,
|
|
26
|
-
startBlockNumber?: XL1BlockNumber,
|
|
27
|
-
timeUnit?: keyof TimeDurations,
|
|
28
|
-
// default tolerance of 30 seconds to cut down on iterations
|
|
29
|
-
toleranceMs = DEFAULT_TOLERANCE_MS,
|
|
30
|
-
// maximum recursive attempts to prevent infinite loops
|
|
31
|
-
maxAttempts = DEFAULT_MAX_ATTEMPTS,
|
|
32
|
-
): Promise<XL1BlockRate> => {
|
|
33
|
-
// check the time config has only one key
|
|
34
|
-
assertEx(Object.keys(timeConfig ?? {}).length === 1, () => 'Only one time unit should be specified in timeConfig')
|
|
35
|
-
|
|
36
|
-
// resolve the starting block
|
|
37
|
-
const startBlock = isDefinedNotNull(startBlockNumber) ? await viewer.blockByNumber(startBlockNumber) : null
|
|
38
|
-
const resolvedStartBlock = isDefinedNotNull(startBlock)
|
|
39
|
-
? startBlock[0]
|
|
40
|
-
: (await viewer.currentBlock())[0]
|
|
41
|
-
|
|
42
|
-
const timeInMilliseconds = getTimeConfigInMilliseconds(timeConfig)
|
|
43
|
-
assertEx(timeInMilliseconds > 0, () => 'Time duration must be greater than zero')
|
|
44
|
-
|
|
45
|
-
// Estimate blocks per milliseconds (bpm) based on average block time
|
|
46
|
-
const blocksPerMillisecondRate = 1 / (12 * 1000) // Approximate average block time of 12 seconds
|
|
47
|
-
|
|
48
|
-
// Calculate the number of blocks in the given time duration
|
|
49
|
-
const initialBlocksInDuration = Math.floor(blocksPerMillisecondRate * timeInMilliseconds)
|
|
50
|
-
|
|
51
|
-
// Recursively find the proper end block
|
|
52
|
-
const endBlockNumber = await findEndBlockRecursive(
|
|
53
|
-
viewer,
|
|
54
|
-
resolvedStartBlock,
|
|
55
|
-
timeInMilliseconds,
|
|
56
|
-
initialBlocksInDuration,
|
|
57
|
-
toleranceMs,
|
|
58
|
-
maxAttempts,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
return await calculateBlockRate(
|
|
62
|
-
viewer,
|
|
63
|
-
asXL1BlockRange([endBlockNumber, resolvedStartBlock.block], true),
|
|
64
|
-
timeUnit,
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const findEndBlockRecursive = async (
|
|
69
|
-
viewer: BlockViewer,
|
|
70
|
-
startBlock: BlockBoundWitness,
|
|
71
|
-
targetTimeMs: number,
|
|
72
|
-
estimatedBlocksBack: number,
|
|
73
|
-
toleranceMs: number,
|
|
74
|
-
attemptsRemaining: number,
|
|
75
|
-
): Promise<XL1BlockNumber> => {
|
|
76
|
-
console.log(`Attempts remaining: ${attemptsRemaining}, Estimated blocks back: ${estimatedBlocksBack}`)
|
|
77
|
-
assertEx(attemptsRemaining >= 0, () => 'Maximum attempts reached while searching for end block')
|
|
78
|
-
|
|
79
|
-
const startBlockEpoch = startBlock.$epoch
|
|
80
|
-
const estimatedEndBlockNumber = asXL1BlockNumber(startBlock.block - estimatedBlocksBack, true)
|
|
81
|
-
if (estimatedEndBlockNumber < 0) {
|
|
82
|
-
throw new Error('Estimated end block number is less than zero')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Fetch the estimated end block
|
|
86
|
-
const endBlock = await viewer.blockByNumber(estimatedEndBlockNumber)
|
|
87
|
-
const resolvedEndBlock = assertEx(
|
|
88
|
-
isDefined(endBlock?.[0]) ? endBlock[0] : undefined,
|
|
89
|
-
() => `Could not retrieve block ${estimatedEndBlockNumber} for time rate calculation`,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
const endBlockEpoch = resolvedEndBlock.$epoch
|
|
93
|
-
const actualTimeDifference = startBlockEpoch - endBlockEpoch
|
|
94
|
-
|
|
95
|
-
// Check if we're within tolerance
|
|
96
|
-
const timeDelta = Math.abs(actualTimeDifference - targetTimeMs)
|
|
97
|
-
if (timeDelta <= toleranceMs) {
|
|
98
|
-
return resolvedEndBlock.block
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Calculate adjustment factor and recursively search
|
|
102
|
-
let adjustedBlocksBack: number
|
|
103
|
-
if (actualTimeDifference < targetTimeMs) {
|
|
104
|
-
// Need to go further back
|
|
105
|
-
const adjustmentFactor = targetTimeMs / actualTimeDifference
|
|
106
|
-
adjustedBlocksBack = Math.floor(estimatedBlocksBack * adjustmentFactor)
|
|
107
|
-
} else {
|
|
108
|
-
// Need to come forward
|
|
109
|
-
const adjustmentFactor = actualTimeDifference / targetTimeMs
|
|
110
|
-
adjustedBlocksBack = Math.floor(estimatedBlocksBack / adjustmentFactor)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return await findEndBlockRecursive(
|
|
114
|
-
viewer,
|
|
115
|
-
startBlock,
|
|
116
|
-
targetTimeMs,
|
|
117
|
-
adjustedBlocksBack,
|
|
118
|
-
toleranceMs,
|
|
119
|
-
attemptsRemaining - 1,
|
|
120
|
-
)
|
|
121
|
-
}
|