@xyo-network/xl1-protocol-sdk 1.26.12 → 1.26.14

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.
Files changed (331) hide show
  1. package/dist/neutral/config/Actors.d.ts +1 -1
  2. package/dist/neutral/config/Base.d.ts +1 -1
  3. package/dist/neutral/config/Config.d.ts +4 -4
  4. package/dist/neutral/payloads/AddressPairPayload.d.ts +1 -1
  5. package/dist/neutral/payloads/AddressPairPayload.d.ts.map +1 -1
  6. package/dist/neutral/primitives/uncle/findBestUncle.d.ts +13 -13
  7. package/dist/neutral/primitives/uncle/findUncles.d.ts +2 -2
  8. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
  9. package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +2 -2
  10. package/dist/neutral/simple/chainContractViewer/SimpleChainContractViewer.d.ts +1 -1
  11. package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +1 -1
  12. package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +1 -1
  13. package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +10 -10
  14. package/dist/neutral/transaction/TransactionBuilder.d.ts +4 -4
  15. package/dist/neutral/transaction/signTransaction.d.ts +1 -1
  16. package/package.json +24 -21
  17. package/src/ChainContextHelpers.ts +0 -50
  18. package/src/CreatableProvider/AbstractCreatableProvider.ts +0 -97
  19. package/src/CreatableProvider/CreatableProvider.ts +0 -102
  20. package/src/CreatableProvider/CreatableProviderRegistry.ts +0 -94
  21. package/src/CreatableProvider/GetInstanceOptions.ts +0 -11
  22. package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +0 -24
  23. package/src/CreatableProvider/ProviderFactory.ts +0 -138
  24. package/src/CreatableProvider/ProviderFactoryLocator.ts +0 -170
  25. package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +0 -70
  26. package/src/CreatableProvider/index.ts +0 -8
  27. package/src/SignedBigInt.ts +0 -59
  28. package/src/_internal/context/getTestProviderContext.ts +0 -13
  29. package/src/_internal/context/index.ts +0 -1
  30. package/src/_internal/index.ts +0 -2
  31. package/src/actor/ActorV3.ts +0 -177
  32. package/src/actor/index.ts +0 -1
  33. package/src/amount/ShiftedBigInt.ts +0 -73
  34. package/src/amount/XL1Amount.ts +0 -103
  35. package/src/amount/index.ts +0 -4
  36. package/src/amount/splitOnDecimal.ts +0 -6
  37. package/src/amount/splitOnDecimalToString.ts +0 -40
  38. package/src/block/hydrate/allHashesPresent.ts +0 -8
  39. package/src/block/hydrate/blockPayloadsFromHydratedBlock.ts +0 -12
  40. package/src/block/hydrate/flattenHydratedBlock.ts +0 -28
  41. package/src/block/hydrate/flattenHydratedBlocks.ts +0 -7
  42. package/src/block/hydrate/hydrateBlock.ts +0 -43
  43. package/src/block/hydrate/index.ts +0 -7
  44. package/src/block/hydrate/transactionsFromHydratedBlock.ts +0 -7
  45. package/src/block/hydrate/tryHydrateBlock.ts +0 -26
  46. package/src/block/index.ts +0 -2
  47. package/src/block/primitives/blockFromBlockNumber.ts +0 -69
  48. package/src/block/primitives/frames/calculateFramesFromRange.ts +0 -30
  49. package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +0 -28
  50. package/src/block/primitives/frames/index.ts +0 -2
  51. package/src/block/primitives/hashFromBlockNumber.ts +0 -9
  52. package/src/block/primitives/index.ts +0 -7
  53. package/src/block/primitives/model.ts +0 -18
  54. package/src/block/primitives/payloads/ChainWindow.ts +0 -7
  55. package/src/block/primitives/payloads/index.ts +0 -1
  56. package/src/block/primitives/toStepIdentityString.ts +0 -6
  57. package/src/block/primitives/validateTransactionOpcodes.ts +0 -45
  58. package/src/config/Actor.ts +0 -32
  59. package/src/config/Actors.ts +0 -9
  60. package/src/config/Base.ts +0 -27
  61. package/src/config/Chain.ts +0 -23
  62. package/src/config/Config.ts +0 -24
  63. package/src/config/DataLake/DataLake.ts +0 -12
  64. package/src/config/DataLake/DataLakeRemoteConfig.ts +0 -11
  65. package/src/config/DataLake/RestDataLakeConfig.ts +0 -18
  66. package/src/config/DataLake/RouterDataLakeConfig.ts +0 -22
  67. package/src/config/DataLake/index.ts +0 -4
  68. package/src/config/DeepPartial.ts +0 -4
  69. package/src/config/Evm.ts +0 -38
  70. package/src/config/HostActor.ts +0 -32
  71. package/src/config/Log.ts +0 -25
  72. package/src/config/Provider.ts +0 -20
  73. package/src/config/Providers.ts +0 -9
  74. package/src/config/Remote.ts +0 -59
  75. package/src/config/Telemetry.ts +0 -49
  76. package/src/config/UsageMeta.ts +0 -46
  77. package/src/config/Validation.ts +0 -29
  78. package/src/config/index.ts +0 -12
  79. package/src/config/storage/Storage.ts +0 -16
  80. package/src/config/storage/driver/Mongo.ts +0 -53
  81. package/src/config/storage/driver/index.ts +0 -1
  82. package/src/config/storage/index.ts +0 -2
  83. package/src/constants.ts +0 -4
  84. package/src/context/Actor.ts +0 -20
  85. package/src/context/HostActor.ts +0 -20
  86. package/src/context/getEmptyProviderContext.ts +0 -19
  87. package/src/context/index.ts +0 -3
  88. package/src/createDeclarationPayload.ts +0 -15
  89. package/src/createTransferPayload.ts +0 -16
  90. package/src/driver/cache/LruCacheMap.ts +0 -48
  91. package/src/driver/cache/index.ts +0 -1
  92. package/src/driver/index.ts +0 -2
  93. package/src/driver/memory/MemoryMap.ts +0 -48
  94. package/src/driver/memory/index.ts +0 -1
  95. package/src/eip-712/Payloads/EIP712Data.ts +0 -35
  96. package/src/eip-712/Payloads/EIP712Signature.ts +0 -32
  97. package/src/eip-712/Payloads/index.ts +0 -2
  98. package/src/eip-712/Types.ts +0 -41
  99. package/src/eip-712/index.ts +0 -4
  100. package/src/eip-712/sign.ts +0 -19
  101. package/src/eip-712/spec/fixtures.ts +0 -27
  102. package/src/eip-712/verify.ts +0 -20
  103. package/src/getFileConfig.ts +0 -36
  104. package/src/index.ts +0 -27
  105. package/src/instances/Address.ts +0 -16
  106. package/src/instances/BoundWitness.ts +0 -13
  107. package/src/instances/Data.ts +0 -4
  108. package/src/instances/Fees.ts +0 -9
  109. package/src/instances/HydratedBoundWitness.ts +0 -16
  110. package/src/instances/Object.ts +0 -6
  111. package/src/instances/Payload.ts +0 -7
  112. package/src/instances/Signature.ts +0 -12
  113. package/src/instances/block/BlockFields.ts +0 -18
  114. package/src/instances/block/HydratedBlock.ts +0 -10
  115. package/src/instances/block/index.ts +0 -1
  116. package/src/instances/index.ts +0 -10
  117. package/src/instances/modifiers/BlockWindowInstance.ts +0 -8
  118. package/src/instances/modifiers/BlockWindowState.ts +0 -6
  119. package/src/instances/modifiers/Signed.ts +0 -9
  120. package/src/instances/modifiers/Validatable.ts +0 -6
  121. package/src/instances/modifiers/index.ts +0 -4
  122. package/src/instances/transaction/HydratedTransaction.ts +0 -9
  123. package/src/instances/transaction/TransactionFields.ts +0 -22
  124. package/src/instances/transaction/index.ts +0 -1
  125. package/src/isInternetAvailable.ts +0 -11
  126. package/src/model/ChainFork/ChainForkStatic.ts +0 -9
  127. package/src/model/ChainFork/index.ts +0 -1
  128. package/src/model/ChainIdentity.ts +0 -6
  129. package/src/model/ChainStore.ts +0 -16
  130. package/src/model/CreatableProviderContext.ts +0 -6
  131. package/src/model/CreatableProviderContext.zod.ts +0 -55
  132. package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +0 -15
  133. package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +0 -15
  134. package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +0 -19
  135. package/src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts +0 -19
  136. package/src/model/PayloadBundle/index.ts +0 -4
  137. package/src/model/index.ts +0 -6
  138. package/src/multipliers.ts +0 -18
  139. package/src/payloads/AddressPairPayload.ts +0 -27
  140. package/src/payloads/index.ts +0 -4
  141. package/src/payloads/netBalancesForPayloads.ts +0 -24
  142. package/src/payloads/netSchemasForPayloads.ts +0 -24
  143. package/src/payloads/netTransfersForPayloads.ts +0 -27
  144. package/src/primitives/block/index.ts +0 -2
  145. package/src/primitives/block/range/blockRangeSteps.ts +0 -23
  146. package/src/primitives/block/range/index.ts +0 -1
  147. package/src/primitives/block/rate/blockRate.ts +0 -77
  148. package/src/primitives/block/rate/index.ts +0 -4
  149. package/src/primitives/block/rate/stepRate.ts +0 -37
  150. package/src/primitives/block/rate/timeHelpers.ts +0 -61
  151. package/src/primitives/block/rate/timeRate.ts +0 -121
  152. package/src/primitives/chain/getWindowedChain.ts +0 -50
  153. package/src/primitives/chain/index.ts +0 -3
  154. package/src/primitives/chain/step/chainStepRewardAddress.ts +0 -30
  155. package/src/primitives/chain/step/index.ts +0 -4
  156. package/src/primitives/chain/step/stepRewardBlock.ts +0 -13
  157. package/src/primitives/chain/step/stepRewardTotal.ts +0 -46
  158. package/src/primitives/chain/step/stepsRewardTotal.ts +0 -37
  159. package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +0 -32
  160. package/src/primitives/chain/time/externalBlockRangeFromStep.ts +0 -21
  161. package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +0 -17
  162. package/src/primitives/chain/time/index.ts +0 -3
  163. package/src/primitives/datalake/addDataLakePayloads.ts +0 -18
  164. package/src/primitives/datalake/addDataLakePayloadsToPayloads.ts +0 -24
  165. package/src/primitives/datalake/index.ts +0 -2
  166. package/src/primitives/index.ts +0 -13
  167. package/src/primitives/mapToMapType.ts +0 -35
  168. package/src/primitives/payload/index.ts +0 -1
  169. package/src/primitives/payload/mergeTransfers.ts +0 -16
  170. package/src/primitives/readPayloadMapFromStore.ts +0 -58
  171. package/src/primitives/rewardFromBlockNumber.ts +0 -19
  172. package/src/primitives/rewards/index.ts +0 -1
  173. package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +0 -26
  174. package/src/primitives/stake/activeStakeAtTimeByAddress.ts +0 -27
  175. package/src/primitives/stake/activeStakeAtTimeByPosition.ts +0 -25
  176. package/src/primitives/stake/allStakersForRange.ts +0 -32
  177. package/src/primitives/stake/allStakersForStep.ts +0 -24
  178. package/src/primitives/stake/index.ts +0 -6
  179. package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +0 -15
  180. package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +0 -17
  181. package/src/primitives/stake/weightedStakeForRangeByPosition.ts +0 -69
  182. package/src/primitives/state/findMostRecentBlock.ts +0 -44
  183. package/src/primitives/state/hydratedBlockByNumber.ts +0 -25
  184. package/src/primitives/state/index.ts +0 -2
  185. package/src/primitives/step/completedStepRewardAddress.ts +0 -10
  186. package/src/primitives/step/derivedReceiveAddress.ts +0 -9
  187. package/src/primitives/step/index.ts +0 -4
  188. package/src/primitives/step/stepBlockRange.ts +0 -9
  189. package/src/primitives/step/stepTransferIndex.ts +0 -19
  190. package/src/primitives/transaction/elevatedPayloads.ts +0 -24
  191. package/src/primitives/transaction/index.ts +0 -1
  192. package/src/primitives/uncle/findBestUncle.ts +0 -9
  193. package/src/primitives/uncle/findUncles.ts +0 -75
  194. package/src/primitives/uncle/index.ts +0 -3
  195. package/src/primitives/uncle/scoreUncle.ts +0 -7
  196. package/src/services/AccountTransfersService.ts +0 -13
  197. package/src/services/BlockProducerService.ts +0 -11
  198. package/src/services/Chain/BaseChainService.ts +0 -4
  199. package/src/services/Chain/ChainHeadService.ts +0 -8
  200. package/src/services/Chain/ChainService.ts +0 -6
  201. package/src/services/Chain/index.ts +0 -3
  202. package/src/services/Election.ts +0 -14
  203. package/src/services/NetworkStakeService.ts +0 -4
  204. package/src/services/Params.ts +0 -13
  205. package/src/services/PendingTransactionsService.ts +0 -7
  206. package/src/services/SchemasService.ts +0 -11
  207. package/src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts +0 -50
  208. package/src/services/StakeIntentService/StakeIntentService.ts +0 -35
  209. package/src/services/StakeIntentService/index.ts +0 -2
  210. package/src/services/index.ts +0 -8
  211. package/src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts +0 -93
  212. package/src/simple/StakeEventsViewer/index.ts +0 -1
  213. package/src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts +0 -116
  214. package/src/simple/StakeTotalsViewer/index.ts +0 -1
  215. package/src/simple/StakeViewer/SimpleStakeViewer.ts +0 -164
  216. package/src/simple/StakeViewer/index.ts +0 -1
  217. package/src/simple/TransactionViewer/SimpleTransactionViewer.ts +0 -100
  218. package/src/simple/TransactionViewer/index.ts +0 -1
  219. package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +0 -271
  220. package/src/simple/accountBalance/index.ts +0 -1
  221. package/src/simple/block/SimpleBlockViewer.ts +0 -231
  222. package/src/simple/block/index.ts +0 -1
  223. package/src/simple/blockInvalidation/SimpleBlockInvalidationViewer.ts +0 -197
  224. package/src/simple/blockInvalidation/index.ts +0 -1
  225. package/src/simple/blockReward/SimpleBlockRewardViewer.ts +0 -27
  226. package/src/simple/blockReward/index.ts +0 -1
  227. package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +0 -194
  228. package/src/simple/blockValidation/index.ts +0 -1
  229. package/src/simple/chainContractViewer/SimpleChainContractViewer.ts +0 -92
  230. package/src/simple/chainContractViewer/index.ts +0 -1
  231. package/src/simple/client/SimpleXyoClient.ts +0 -14
  232. package/src/simple/client/index.ts +0 -1
  233. package/src/simple/datalake/AbstractRestDataLake.ts +0 -70
  234. package/src/simple/datalake/AbstractSimpleDataLake.ts +0 -62
  235. package/src/simple/datalake/RestDataLakeRunner.ts +0 -54
  236. package/src/simple/datalake/RestDataLakeViewer.ts +0 -22
  237. package/src/simple/datalake/SimpleDataLakeRunner.ts +0 -44
  238. package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -24
  239. package/src/simple/datalake/index.ts +0 -4
  240. package/src/simple/finalization/SimpleFinalizationRunner.ts +0 -45
  241. package/src/simple/finalization/SimpleFinalizationViewer.ts +0 -123
  242. package/src/simple/finalization/index.ts +0 -2
  243. package/src/simple/gateway/SimpleXyoGateway.ts +0 -30
  244. package/src/simple/gateway/SimpleXyoGatewayRunner.ts +0 -137
  245. package/src/simple/gateway/index.ts +0 -2
  246. package/src/simple/index.ts +0 -22
  247. package/src/simple/mempool/SimpleMempoolRunner.ts +0 -390
  248. package/src/simple/mempool/SimpleMempoolViewer.ts +0 -215
  249. package/src/simple/mempool/index.ts +0 -2
  250. package/src/simple/network/SimpleXyoNetwork.ts +0 -48
  251. package/src/simple/network/index.ts +0 -1
  252. package/src/simple/network/lib/FailedNetworkStatusPayloads.ts +0 -16
  253. package/src/simple/network/lib/StatusNetworks.ts +0 -32
  254. package/src/simple/network/lib/index.ts +0 -2
  255. package/src/simple/permissions/SimpleXyoPermissions.ts +0 -82
  256. package/src/simple/permissions/index.ts +0 -2
  257. package/src/simple/permissions/store/MemoryPermissions.ts +0 -32
  258. package/src/simple/permissions/store/PermissionsStore.ts +0 -17
  259. package/src/simple/permissions/store/index.ts +0 -2
  260. package/src/simple/runner/SimpleXyoRunner.ts +0 -41
  261. package/src/simple/runner/index.ts +0 -1
  262. package/src/simple/signer/SimpleXyoSigner.ts +0 -78
  263. package/src/simple/signer/index.ts +0 -1
  264. package/src/simple/timeSync2/SimpleTimeSyncViewer.ts +0 -132
  265. package/src/simple/timeSync2/index.ts +0 -1
  266. package/src/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.ts +0 -197
  267. package/src/simple/transactionInvalidation/index.ts +0 -1
  268. package/src/simple/transactionValidation/SimpleTransactionValidationViewer.ts +0 -173
  269. package/src/simple/transactionValidation/index.ts +0 -1
  270. package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +0 -207
  271. package/src/simple/windowedBlock/index.ts +0 -1
  272. package/src/status/RuntimeStatusMonitor.ts +0 -120
  273. package/src/status/ServiceStatus.ts +0 -21
  274. package/src/status/index.ts +0 -2
  275. package/src/summary/index.ts +0 -2
  276. package/src/summary/model/BalancesStepSummary.ts +0 -35
  277. package/src/summary/model/SchemasStepSummary.ts +0 -33
  278. package/src/summary/model/StepSummary.ts +0 -20
  279. package/src/summary/model/TransfersSummary.ts +0 -36
  280. package/src/summary/model/index.ts +0 -4
  281. package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +0 -94
  282. package/src/summary/primitives/balances/balancesSummary.ts +0 -48
  283. package/src/summary/primitives/balances/index.ts +0 -2
  284. package/src/summary/primitives/index.ts +0 -3
  285. package/src/summary/primitives/schemas/index.ts +0 -2
  286. package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +0 -86
  287. package/src/summary/primitives/schemas/schemasSummary.ts +0 -44
  288. package/src/summary/primitives/transfers/index.ts +0 -2
  289. package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +0 -109
  290. package/src/summary/primitives/transfers/transfersSummary.ts +0 -52
  291. package/src/test/BuildBlockOptions.ts +0 -81
  292. package/src/test/buildBlock.ts +0 -105
  293. package/src/test/buildGenesisBlock.ts +0 -29
  294. package/src/test/buildNextBlock.ts +0 -37
  295. package/src/test/buildRandomChain.ts +0 -92
  296. package/src/test/buildRandomGenesisBlock.ts +0 -47
  297. package/src/test/createGenesisBlock.ts +0 -41
  298. package/src/test/createProducerChainStakeIntentTransaction.ts +0 -48
  299. package/src/test/getSimpleBlockViewerLocator.ts +0 -41
  300. package/src/test/getTestProviderContext.ts +0 -8
  301. package/src/test/index.ts +0 -2
  302. package/src/time/index.ts +0 -1
  303. package/src/time/primitives/index.ts +0 -1
  304. package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +0 -13
  305. package/src/transaction/TransactionBuilder.ts +0 -164
  306. package/src/transaction/buildRandomTransaction.ts +0 -38
  307. package/src/transaction/buildTransaction.ts +0 -68
  308. package/src/transaction/buildUnsignedTransaction.ts +0 -56
  309. package/src/transaction/confirmSubmittedTransaction.ts +0 -42
  310. package/src/transaction/hydrateTransaction.ts +0 -117
  311. package/src/transaction/index.ts +0 -9
  312. package/src/transaction/primitives/index.ts +0 -4
  313. package/src/transaction/primitives/transactionBlockByteCount.ts +0 -10
  314. package/src/transaction/primitives/transactionElevatedPayloads.ts +0 -18
  315. package/src/transaction/primitives/transactionOperations.ts +0 -13
  316. package/src/transaction/primitives/transactionRequiredGas.ts +0 -22
  317. package/src/transaction/script.ts +0 -48
  318. package/src/transaction/signTransaction.ts +0 -32
  319. package/src/utils/HydratedCache.ts +0 -39
  320. package/src/utils/index.ts +0 -2
  321. package/src/utils/isZodError.ts +0 -11
  322. package/src/validation/index.ts +0 -2
  323. package/src/validation/lib/getUrl.ts +0 -7
  324. package/src/validation/lib/index.ts +0 -2
  325. package/src/validation/lib/isLocalhost.ts +0 -9
  326. package/src/validation/schema/Address.ts +0 -2
  327. package/src/validation/schema/Mnemonic.ts +0 -21
  328. package/src/validation/schema/index.ts +0 -2
  329. package/src/wallet/generateXyoBaseWalletFromPhrase.ts +0 -13
  330. package/src/wallet/index.ts +0 -2
  331. package/src/wallet/paths.ts +0 -17
@@ -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
- }
@@ -1,50 +0,0 @@
1
- import {
2
- assertEx, type Hash, isDefined, isNull,
3
- spanRootAsync,
4
- } from '@xylabs/sdk-js'
5
- import type {
6
- BaseContext, BlockViewer, SignedHydratedBlockWithHashMeta,
7
- } from '@xyo-network/xl1-protocol-lib'
8
-
9
- /**
10
- * Constructs a bounded, contiguous canonical chain ending at the current head.
11
- * @param blockViewer The BlockViewer to fetch blocks from
12
- * @param maxWindowSize The maximum size of the windowed chain
13
- * @param previousChain An optional previous chain to build upon
14
- * @returns A promise that resolves to the windowed chain of blocks
15
- */
16
- export async function getWindowedChain(
17
- context: BaseContext,
18
- blockViewer: BlockViewer,
19
- maxWindowSize: number,
20
- previousChain: SignedHydratedBlockWithHashMeta[] = [],
21
- ):
22
- Promise<SignedHydratedBlockWithHashMeta[]> {
23
- return await spanRootAsync('getWindowedChain', async () => {
24
- const newChain: SignedHydratedBlockWithHashMeta[] = []
25
- const previousChainByHash = new Map<Hash, SignedHydratedBlockWithHashMeta>(previousChain.map(block => [block[0]._hash, block]))
26
- const head = await blockViewer.currentBlock()
27
- let currentBlock: SignedHydratedBlockWithHashMeta | null = head
28
- console.log('[getWindowedChain] Current Block:', currentBlock?.[0]._hash)
29
- while (currentBlock !== null && newChain.length < maxWindowSize) {
30
- const currentBlockNumber = currentBlock[0].block
31
- const nextBlock = newChain[0]
32
- if (isDefined(nextBlock)) {
33
- const nextBlockNumber = nextBlock[0].block
34
- assertEx(
35
- currentBlockNumber === nextBlockNumber - 1,
36
- () => `[getWindowedChain] Non-monotonic block sequence detected: current=${currentBlockNumber}, next=${nextBlockNumber}`,
37
- )
38
- }
39
- assertEx(
40
- currentBlockNumber <= head[0].block,
41
- () => `[getWindowedChain] Current block number (${currentBlockNumber}) exceeds head block number (${head[0].block})`,
42
- )
43
- newChain.unshift(currentBlock)
44
- const previousBlockHash: Hash | null = currentBlock[0].previous
45
- if (isNull(previousBlockHash)) break
46
- currentBlock = previousChainByHash.get(previousBlockHash) ?? await blockViewer.blockByHash(previousBlockHash)
47
- }
48
- return newChain
49
- }, context)
50
- }
@@ -1,3 +0,0 @@
1
- export * from './getWindowedChain.ts'
2
- export * from './step/index.ts'
3
- export * from './time/index.ts'
@@ -1,30 +0,0 @@
1
- import type { Address } from '@xylabs/sdk-js'
2
- import {
3
- assertEx, exists, toAddress,
4
- } from '@xylabs/sdk-js'
5
- import type {
6
- BlockViewer, CachingContext, StepIdentity,
7
- } from '@xyo-network/xl1-protocol-lib'
8
- import {
9
- asTransfer, isTransfer, XYO_STEP_REWARD_ADDRESS,
10
- } from '@xyo-network/xl1-protocol-lib'
11
-
12
- import { mergeTransfers } from '../../payload/index.ts'
13
- import { stepTransferIndex } from '../../step/index.ts'
14
- import { stepRewardBlock } from './stepRewardBlock.ts'
15
-
16
- /** ChainStepRewardAddress helper function. */
17
- export async function chainStepRewardAddress(context: CachingContext, blockViewer: BlockViewer, { block, step }: StepIdentity): Promise<Address> {
18
- const hydratedBlock = await stepRewardBlock(context, blockViewer, { block, step })
19
- const [transferIndex, transferCount] = stepTransferIndex(block, step)
20
- const [blockBw, payloads] = hydratedBlock
21
-
22
- const transfersFromPool = payloads.filter(isTransfer).map(p => asTransfer(p)).filter(exists).filter(t => t.from === XYO_STEP_REWARD_ADDRESS)
23
- const fromEntries = Object.entries(mergeTransfers(transfersFromPool)[XYO_STEP_REWARD_ADDRESS])
24
- const sortedTransferAmounts = (fromEntries).toSorted(([,a], [,b]) => a > b ? -1 : a < b ? 1 : 0)
25
- assertEx(
26
- sortedTransferAmounts.length === transferCount,
27
- () => `Step Transfers mismatch ${block} (${blockBw._hash}) [${sortedTransferAmounts.length} - ${transferCount}]`,
28
- )
29
- return toAddress(sortedTransferAmounts[transferIndex][0])
30
- }
@@ -1,4 +0,0 @@
1
- export * from './chainStepRewardAddress.ts'
2
- export * from './stepRewardBlock.ts'
3
- export * from './stepRewardTotal.ts'
4
- export * from './stepsRewardTotal.ts'
@@ -1,13 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type {
3
- BlockViewer,
4
- CachingContext,
5
- HydratedBlockWithHashMeta, StepIdentity,
6
- } from '@xyo-network/xl1-protocol-lib'
7
- import { StepSizes } from '@xyo-network/xl1-protocol-lib'
8
-
9
- /** StepRewardBlock helper function. */
10
- export async function stepRewardBlock(context: CachingContext, blockViewer: BlockViewer, { block, step }: StepIdentity): Promise<HydratedBlockWithHashMeta> {
11
- assertEx((block % StepSizes[step]) === 0, () => `Block must be the first block of the step [${StepSizes[step]}], got ${block}`)
12
- return assertEx(await blockViewer.blockByNumber(block), () => `Could not find block for block number ${block}`)
13
- }
@@ -1,46 +0,0 @@
1
- import { assertEx, isDefined } from '@xylabs/sdk-js'
2
- import type {
3
- AttoXL1, BlockViewer, CachingContext, StepIdentity, XL1BlockRange, XL1RangeMultipliers,
4
- } from '@xyo-network/xl1-protocol-lib'
5
- import {
6
- asAttoXL1, asXL1BlockRange, isTransfer,
7
- XYO_STEP_REWARD_ADDRESS,
8
- } from '@xyo-network/xl1-protocol-lib'
9
-
10
- import { withContextCacheResponse } from '../../../ChainContextHelpers.ts'
11
- import { netTransfersForPayloads } from '../../../payloads/index.ts'
12
- import { stepBlockRange, stepTransferIndex } from '../../step/index.ts'
13
- import { stepRewardBlock } from './stepRewardBlock.ts'
14
-
15
- function stepInRange(step: StepIdentity, range: XL1BlockRange): boolean {
16
- const stepRange = stepBlockRange(step)
17
- return ((stepRange[0] >= range[0]) && (stepRange[1] <= range[1]))
18
- }
19
-
20
- /** StepRewardTotal helper function. */
21
- export async function stepRewardTotal(context: CachingContext, blockViewer: BlockViewer, { block, step }: StepIdentity, multipliers: XL1RangeMultipliers): Promise<AttoXL1> {
22
- const cacheKey = `${block}|${step}|${isDefined(multipliers)}`
23
- return await withContextCacheResponse(context, 'stepRewardTotal', cacheKey, async () => {
24
- const [blockBw, payloads] = await stepRewardBlock(context, blockViewer, { block, step })
25
- assertEx(blockBw.block === block, () => `Block Mismatch: expected ${block}, got ${blockBw.block}`)
26
- const [transferIndex] = stepTransferIndex(block, step)
27
- const stepTransfer = assertEx(
28
- payloads.find(p => isTransfer(p) && p.from === XYO_STEP_REWARD_ADDRESS),
29
- () => `No step transfer found for step ${step} at block ${block} (${blockBw._hash})`,
30
- )
31
- const rewards = assertEx(
32
- netTransfersForPayloads(context, [stepTransfer])[XYO_STEP_REWARD_ADDRESS],
33
- () => `No rewards found for step reward address ${XYO_STEP_REWARD_ADDRESS} at block ${block} (${blockBw._hash})`,
34
- )
35
- const sortedTransfers = (Object.entries(rewards)).toSorted(([,a], [,b]) => a > b ? -1 : a < b ? 1 : 0)
36
- let result = asAttoXL1(sortedTransfers[transferIndex][1] * -1n)
37
- for (const [rangeKey, [numerator, denominator]] of Object.entries(multipliers)) {
38
- const rangeParts = rangeKey.split('|').map(Number)
39
- const range: XL1BlockRange = asXL1BlockRange([rangeParts[0], rangeParts[1]], { name: 'stepRewardTotal' })
40
- if (stepInRange({ block, step }, range)) {
41
- result = asAttoXL1(result + result * numerator / denominator)
42
- }
43
- }
44
- return result
45
- })
46
- }
@@ -1,37 +0,0 @@
1
- import type {
2
- AttoXL1, BlockViewer, CachingContext, StepIdentity, XL1BlockRange,
3
- XL1RangeMultipliers,
4
- } from '@xyo-network/xl1-protocol-lib'
5
- import { asAttoXL1, asXL1BlockRange } from '@xyo-network/xl1-protocol-lib'
6
-
7
- import { XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK } from '../../../constants.ts'
8
- import { blockRangeSteps } from '../../block/index.ts'
9
- import { stepRewardTotal } from './stepRewardTotal.ts'
10
-
11
- /** StepsRewardTotalGenesisPeriod helper function. */
12
- export async function stepsRewardTotalGenesisPeriod(context: CachingContext, blockViewer: BlockViewer, multipliers: XL1RangeMultipliers, stepSizes?: number[]): Promise<AttoXL1> {
13
- const range = asXL1BlockRange([0, XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK], { name: 'stepsRewardTotalGenesisPeriod' })
14
- return await stepsRewardTotalRange(context, blockViewer, range, stepSizes, multipliers)
15
- }
16
-
17
- /** StepsRewardTotalRange helper function. */
18
- export async function stepsRewardTotalRange(
19
- context: CachingContext,
20
- blockViewer: BlockViewer,
21
- range: XL1BlockRange,
22
- stepSizes: number[] = [3, 4, 5, 6],
23
- multipliers: XL1RangeMultipliers,
24
- ): Promise<AttoXL1> {
25
- const steps = blockRangeSteps(range, stepSizes)
26
- return await stepsRewardTotal(context, blockViewer, steps, multipliers)
27
- }
28
-
29
- /** StepsRewardTotal helper function. */
30
- export async function stepsRewardTotal(context: CachingContext, blockViewer: BlockViewer, steps: StepIdentity[], multipliers: XL1RangeMultipliers): Promise<AttoXL1> {
31
- let totalRewards = 0n
32
- for (const step of steps) {
33
- const stepTotal = await stepRewardTotal(context, blockViewer, step, multipliers)
34
- totalRewards += stepTotal
35
- }
36
- return asAttoXL1(totalRewards)
37
- }
@@ -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,3 +0,0 @@
1
- export * from './externalBlockNumberFromXL1BlockNumber.ts'
2
- export * from './externalBlockRangeFromStep.ts'
3
- export * from './externalBlockRangeFromXL1BlockRange.ts'
@@ -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
- }
@@ -1,2 +0,0 @@
1
- export * from './addDataLakePayloads.ts'
2
- export * from './addDataLakePayloadsToPayloads.ts'
@@ -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'