@xyo-network/xl1-protocol-sdk 1.26.11 → 1.26.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/package.json +29 -16
  2. package/src/ChainContextHelpers.ts +0 -50
  3. package/src/CreatableProvider/AbstractCreatableProvider.ts +0 -97
  4. package/src/CreatableProvider/CreatableProvider.ts +0 -102
  5. package/src/CreatableProvider/CreatableProviderRegistry.ts +0 -94
  6. package/src/CreatableProvider/GetInstanceOptions.ts +0 -11
  7. package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +0 -24
  8. package/src/CreatableProvider/ProviderFactory.ts +0 -138
  9. package/src/CreatableProvider/ProviderFactoryLocator.ts +0 -170
  10. package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +0 -70
  11. package/src/CreatableProvider/index.ts +0 -8
  12. package/src/SignedBigInt.ts +0 -59
  13. package/src/_internal/context/getTestProviderContext.ts +0 -13
  14. package/src/_internal/context/index.ts +0 -1
  15. package/src/_internal/index.ts +0 -2
  16. package/src/actor/ActorV3.ts +0 -177
  17. package/src/actor/index.ts +0 -1
  18. package/src/amount/ShiftedBigInt.ts +0 -73
  19. package/src/amount/XL1Amount.ts +0 -103
  20. package/src/amount/index.ts +0 -4
  21. package/src/amount/splitOnDecimal.ts +0 -6
  22. package/src/amount/splitOnDecimalToString.ts +0 -40
  23. package/src/block/hydrate/allHashesPresent.ts +0 -8
  24. package/src/block/hydrate/blockPayloadsFromHydratedBlock.ts +0 -12
  25. package/src/block/hydrate/flattenHydratedBlock.ts +0 -28
  26. package/src/block/hydrate/flattenHydratedBlocks.ts +0 -7
  27. package/src/block/hydrate/hydrateBlock.ts +0 -43
  28. package/src/block/hydrate/index.ts +0 -7
  29. package/src/block/hydrate/transactionsFromHydratedBlock.ts +0 -7
  30. package/src/block/hydrate/tryHydrateBlock.ts +0 -26
  31. package/src/block/index.ts +0 -2
  32. package/src/block/primitives/blockFromBlockNumber.ts +0 -69
  33. package/src/block/primitives/frames/calculateFramesFromRange.ts +0 -30
  34. package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +0 -28
  35. package/src/block/primitives/frames/index.ts +0 -2
  36. package/src/block/primitives/hashFromBlockNumber.ts +0 -9
  37. package/src/block/primitives/index.ts +0 -7
  38. package/src/block/primitives/model.ts +0 -18
  39. package/src/block/primitives/payloads/ChainWindow.ts +0 -7
  40. package/src/block/primitives/payloads/index.ts +0 -1
  41. package/src/block/primitives/toStepIdentityString.ts +0 -6
  42. package/src/block/primitives/validateTransactionOpcodes.ts +0 -45
  43. package/src/config/Actor.ts +0 -32
  44. package/src/config/Actors.ts +0 -9
  45. package/src/config/Base.ts +0 -27
  46. package/src/config/Chain.ts +0 -23
  47. package/src/config/Config.ts +0 -24
  48. package/src/config/DataLake/DataLake.ts +0 -12
  49. package/src/config/DataLake/DataLakeRemoteConfig.ts +0 -11
  50. package/src/config/DataLake/RestDataLakeConfig.ts +0 -18
  51. package/src/config/DataLake/RouterDataLakeConfig.ts +0 -22
  52. package/src/config/DataLake/index.ts +0 -4
  53. package/src/config/DeepPartial.ts +0 -4
  54. package/src/config/Evm.ts +0 -38
  55. package/src/config/HostActor.ts +0 -32
  56. package/src/config/Log.ts +0 -25
  57. package/src/config/Provider.ts +0 -20
  58. package/src/config/Providers.ts +0 -9
  59. package/src/config/Remote.ts +0 -59
  60. package/src/config/Telemetry.ts +0 -49
  61. package/src/config/UsageMeta.ts +0 -46
  62. package/src/config/Validation.ts +0 -29
  63. package/src/config/index.ts +0 -12
  64. package/src/config/storage/Storage.ts +0 -16
  65. package/src/config/storage/driver/Mongo.ts +0 -53
  66. package/src/config/storage/driver/index.ts +0 -1
  67. package/src/config/storage/index.ts +0 -2
  68. package/src/constants.ts +0 -4
  69. package/src/context/Actor.ts +0 -20
  70. package/src/context/HostActor.ts +0 -20
  71. package/src/context/getEmptyProviderContext.ts +0 -19
  72. package/src/context/index.ts +0 -3
  73. package/src/createDeclarationPayload.ts +0 -15
  74. package/src/createTransferPayload.ts +0 -16
  75. package/src/driver/cache/LruCacheMap.ts +0 -48
  76. package/src/driver/cache/index.ts +0 -1
  77. package/src/driver/index.ts +0 -2
  78. package/src/driver/memory/MemoryMap.ts +0 -48
  79. package/src/driver/memory/index.ts +0 -1
  80. package/src/eip-712/Payloads/EIP712Data.ts +0 -35
  81. package/src/eip-712/Payloads/EIP712Signature.ts +0 -32
  82. package/src/eip-712/Payloads/index.ts +0 -2
  83. package/src/eip-712/Types.ts +0 -41
  84. package/src/eip-712/index.ts +0 -4
  85. package/src/eip-712/sign.ts +0 -19
  86. package/src/eip-712/spec/fixtures.ts +0 -27
  87. package/src/eip-712/verify.ts +0 -20
  88. package/src/getFileConfig.ts +0 -36
  89. package/src/index.ts +0 -27
  90. package/src/instances/Address.ts +0 -16
  91. package/src/instances/BoundWitness.ts +0 -13
  92. package/src/instances/Data.ts +0 -4
  93. package/src/instances/Fees.ts +0 -9
  94. package/src/instances/HydratedBoundWitness.ts +0 -16
  95. package/src/instances/Object.ts +0 -6
  96. package/src/instances/Payload.ts +0 -7
  97. package/src/instances/Signature.ts +0 -12
  98. package/src/instances/block/BlockFields.ts +0 -18
  99. package/src/instances/block/HydratedBlock.ts +0 -10
  100. package/src/instances/block/index.ts +0 -1
  101. package/src/instances/index.ts +0 -10
  102. package/src/instances/modifiers/BlockWindowInstance.ts +0 -8
  103. package/src/instances/modifiers/BlockWindowState.ts +0 -6
  104. package/src/instances/modifiers/Signed.ts +0 -9
  105. package/src/instances/modifiers/Validatable.ts +0 -6
  106. package/src/instances/modifiers/index.ts +0 -4
  107. package/src/instances/transaction/HydratedTransaction.ts +0 -9
  108. package/src/instances/transaction/TransactionFields.ts +0 -22
  109. package/src/instances/transaction/index.ts +0 -1
  110. package/src/isInternetAvailable.ts +0 -11
  111. package/src/model/ChainFork/ChainForkStatic.ts +0 -9
  112. package/src/model/ChainFork/index.ts +0 -1
  113. package/src/model/ChainIdentity.ts +0 -6
  114. package/src/model/ChainStore.ts +0 -16
  115. package/src/model/CreatableProviderContext.ts +0 -6
  116. package/src/model/CreatableProviderContext.zod.ts +0 -55
  117. package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +0 -15
  118. package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +0 -15
  119. package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +0 -19
  120. package/src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts +0 -19
  121. package/src/model/PayloadBundle/index.ts +0 -4
  122. package/src/model/index.ts +0 -6
  123. package/src/multipliers.ts +0 -18
  124. package/src/payloads/AddressPairPayload.ts +0 -27
  125. package/src/payloads/index.ts +0 -4
  126. package/src/payloads/netBalancesForPayloads.ts +0 -24
  127. package/src/payloads/netSchemasForPayloads.ts +0 -24
  128. package/src/payloads/netTransfersForPayloads.ts +0 -27
  129. package/src/primitives/block/index.ts +0 -2
  130. package/src/primitives/block/range/blockRangeSteps.ts +0 -23
  131. package/src/primitives/block/range/index.ts +0 -1
  132. package/src/primitives/block/rate/blockRate.ts +0 -77
  133. package/src/primitives/block/rate/index.ts +0 -4
  134. package/src/primitives/block/rate/stepRate.ts +0 -37
  135. package/src/primitives/block/rate/timeHelpers.ts +0 -61
  136. package/src/primitives/block/rate/timeRate.ts +0 -121
  137. package/src/primitives/chain/getWindowedChain.ts +0 -50
  138. package/src/primitives/chain/index.ts +0 -3
  139. package/src/primitives/chain/step/chainStepRewardAddress.ts +0 -30
  140. package/src/primitives/chain/step/index.ts +0 -4
  141. package/src/primitives/chain/step/stepRewardBlock.ts +0 -13
  142. package/src/primitives/chain/step/stepRewardTotal.ts +0 -46
  143. package/src/primitives/chain/step/stepsRewardTotal.ts +0 -37
  144. package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +0 -32
  145. package/src/primitives/chain/time/externalBlockRangeFromStep.ts +0 -21
  146. package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +0 -17
  147. package/src/primitives/chain/time/index.ts +0 -3
  148. package/src/primitives/datalake/addDataLakePayloads.ts +0 -18
  149. package/src/primitives/datalake/addDataLakePayloadsToPayloads.ts +0 -24
  150. package/src/primitives/datalake/index.ts +0 -2
  151. package/src/primitives/index.ts +0 -13
  152. package/src/primitives/mapToMapType.ts +0 -35
  153. package/src/primitives/payload/index.ts +0 -1
  154. package/src/primitives/payload/mergeTransfers.ts +0 -16
  155. package/src/primitives/readPayloadMapFromStore.ts +0 -58
  156. package/src/primitives/rewardFromBlockNumber.ts +0 -19
  157. package/src/primitives/rewards/index.ts +0 -1
  158. package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +0 -26
  159. package/src/primitives/stake/activeStakeAtTimeByAddress.ts +0 -27
  160. package/src/primitives/stake/activeStakeAtTimeByPosition.ts +0 -25
  161. package/src/primitives/stake/allStakersForRange.ts +0 -32
  162. package/src/primitives/stake/allStakersForStep.ts +0 -24
  163. package/src/primitives/stake/index.ts +0 -6
  164. package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +0 -15
  165. package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +0 -17
  166. package/src/primitives/stake/weightedStakeForRangeByPosition.ts +0 -69
  167. package/src/primitives/state/findMostRecentBlock.ts +0 -44
  168. package/src/primitives/state/hydratedBlockByNumber.ts +0 -25
  169. package/src/primitives/state/index.ts +0 -2
  170. package/src/primitives/step/completedStepRewardAddress.ts +0 -10
  171. package/src/primitives/step/derivedReceiveAddress.ts +0 -9
  172. package/src/primitives/step/index.ts +0 -4
  173. package/src/primitives/step/stepBlockRange.ts +0 -9
  174. package/src/primitives/step/stepTransferIndex.ts +0 -19
  175. package/src/primitives/transaction/elevatedPayloads.ts +0 -24
  176. package/src/primitives/transaction/index.ts +0 -1
  177. package/src/primitives/uncle/findBestUncle.ts +0 -9
  178. package/src/primitives/uncle/findUncles.ts +0 -75
  179. package/src/primitives/uncle/index.ts +0 -3
  180. package/src/primitives/uncle/scoreUncle.ts +0 -7
  181. package/src/services/AccountTransfersService.ts +0 -13
  182. package/src/services/BlockProducerService.ts +0 -11
  183. package/src/services/Chain/BaseChainService.ts +0 -4
  184. package/src/services/Chain/ChainHeadService.ts +0 -8
  185. package/src/services/Chain/ChainService.ts +0 -6
  186. package/src/services/Chain/index.ts +0 -3
  187. package/src/services/Election.ts +0 -14
  188. package/src/services/NetworkStakeService.ts +0 -4
  189. package/src/services/Params.ts +0 -13
  190. package/src/services/PendingTransactionsService.ts +0 -7
  191. package/src/services/SchemasService.ts +0 -11
  192. package/src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts +0 -50
  193. package/src/services/StakeIntentService/StakeIntentService.ts +0 -35
  194. package/src/services/StakeIntentService/index.ts +0 -2
  195. package/src/services/index.ts +0 -8
  196. package/src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts +0 -93
  197. package/src/simple/StakeEventsViewer/index.ts +0 -1
  198. package/src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts +0 -116
  199. package/src/simple/StakeTotalsViewer/index.ts +0 -1
  200. package/src/simple/StakeViewer/SimpleStakeViewer.ts +0 -164
  201. package/src/simple/StakeViewer/index.ts +0 -1
  202. package/src/simple/TransactionViewer/SimpleTransactionViewer.ts +0 -100
  203. package/src/simple/TransactionViewer/index.ts +0 -1
  204. package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +0 -271
  205. package/src/simple/accountBalance/index.ts +0 -1
  206. package/src/simple/block/SimpleBlockViewer.ts +0 -231
  207. package/src/simple/block/index.ts +0 -1
  208. package/src/simple/blockInvalidation/SimpleBlockInvalidationViewer.ts +0 -197
  209. package/src/simple/blockInvalidation/index.ts +0 -1
  210. package/src/simple/blockReward/SimpleBlockRewardViewer.ts +0 -27
  211. package/src/simple/blockReward/index.ts +0 -1
  212. package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +0 -194
  213. package/src/simple/blockValidation/index.ts +0 -1
  214. package/src/simple/chainContractViewer/SimpleChainContractViewer.ts +0 -92
  215. package/src/simple/chainContractViewer/index.ts +0 -1
  216. package/src/simple/client/SimpleXyoClient.ts +0 -14
  217. package/src/simple/client/index.ts +0 -1
  218. package/src/simple/datalake/AbstractRestDataLake.ts +0 -70
  219. package/src/simple/datalake/AbstractSimpleDataLake.ts +0 -62
  220. package/src/simple/datalake/RestDataLakeRunner.ts +0 -54
  221. package/src/simple/datalake/RestDataLakeViewer.ts +0 -22
  222. package/src/simple/datalake/SimpleDataLakeRunner.ts +0 -44
  223. package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -24
  224. package/src/simple/datalake/index.ts +0 -4
  225. package/src/simple/finalization/SimpleFinalizationRunner.ts +0 -45
  226. package/src/simple/finalization/SimpleFinalizationViewer.ts +0 -123
  227. package/src/simple/finalization/index.ts +0 -2
  228. package/src/simple/gateway/SimpleXyoGateway.ts +0 -30
  229. package/src/simple/gateway/SimpleXyoGatewayRunner.ts +0 -137
  230. package/src/simple/gateway/index.ts +0 -2
  231. package/src/simple/index.ts +0 -22
  232. package/src/simple/mempool/SimpleMempoolRunner.ts +0 -390
  233. package/src/simple/mempool/SimpleMempoolViewer.ts +0 -215
  234. package/src/simple/mempool/index.ts +0 -2
  235. package/src/simple/network/SimpleXyoNetwork.ts +0 -48
  236. package/src/simple/network/index.ts +0 -1
  237. package/src/simple/network/lib/FailedNetworkStatusPayloads.ts +0 -16
  238. package/src/simple/network/lib/StatusNetworks.ts +0 -32
  239. package/src/simple/network/lib/index.ts +0 -2
  240. package/src/simple/permissions/SimpleXyoPermissions.ts +0 -82
  241. package/src/simple/permissions/index.ts +0 -2
  242. package/src/simple/permissions/store/MemoryPermissions.ts +0 -32
  243. package/src/simple/permissions/store/PermissionsStore.ts +0 -17
  244. package/src/simple/permissions/store/index.ts +0 -2
  245. package/src/simple/runner/SimpleXyoRunner.ts +0 -41
  246. package/src/simple/runner/index.ts +0 -1
  247. package/src/simple/signer/SimpleXyoSigner.ts +0 -78
  248. package/src/simple/signer/index.ts +0 -1
  249. package/src/simple/timeSync2/SimpleTimeSyncViewer.ts +0 -132
  250. package/src/simple/timeSync2/index.ts +0 -1
  251. package/src/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.ts +0 -197
  252. package/src/simple/transactionInvalidation/index.ts +0 -1
  253. package/src/simple/transactionValidation/SimpleTransactionValidationViewer.ts +0 -173
  254. package/src/simple/transactionValidation/index.ts +0 -1
  255. package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +0 -207
  256. package/src/simple/windowedBlock/index.ts +0 -1
  257. package/src/status/RuntimeStatusMonitor.ts +0 -120
  258. package/src/status/ServiceStatus.ts +0 -21
  259. package/src/status/index.ts +0 -2
  260. package/src/summary/index.ts +0 -2
  261. package/src/summary/model/BalancesStepSummary.ts +0 -35
  262. package/src/summary/model/SchemasStepSummary.ts +0 -33
  263. package/src/summary/model/StepSummary.ts +0 -20
  264. package/src/summary/model/TransfersSummary.ts +0 -36
  265. package/src/summary/model/index.ts +0 -4
  266. package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +0 -94
  267. package/src/summary/primitives/balances/balancesSummary.ts +0 -48
  268. package/src/summary/primitives/balances/index.ts +0 -2
  269. package/src/summary/primitives/index.ts +0 -3
  270. package/src/summary/primitives/schemas/index.ts +0 -2
  271. package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +0 -86
  272. package/src/summary/primitives/schemas/schemasSummary.ts +0 -44
  273. package/src/summary/primitives/transfers/index.ts +0 -2
  274. package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +0 -109
  275. package/src/summary/primitives/transfers/transfersSummary.ts +0 -52
  276. package/src/test/BuildBlockOptions.ts +0 -81
  277. package/src/test/buildBlock.ts +0 -105
  278. package/src/test/buildGenesisBlock.ts +0 -29
  279. package/src/test/buildNextBlock.ts +0 -37
  280. package/src/test/buildRandomChain.ts +0 -92
  281. package/src/test/buildRandomGenesisBlock.ts +0 -47
  282. package/src/test/createGenesisBlock.ts +0 -41
  283. package/src/test/createProducerChainStakeIntentTransaction.ts +0 -48
  284. package/src/test/getSimpleBlockViewerLocator.ts +0 -41
  285. package/src/test/getTestProviderContext.ts +0 -8
  286. package/src/test/index.ts +0 -2
  287. package/src/time/index.ts +0 -1
  288. package/src/time/primitives/index.ts +0 -1
  289. package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +0 -13
  290. package/src/transaction/TransactionBuilder.ts +0 -164
  291. package/src/transaction/buildRandomTransaction.ts +0 -38
  292. package/src/transaction/buildTransaction.ts +0 -68
  293. package/src/transaction/buildUnsignedTransaction.ts +0 -56
  294. package/src/transaction/confirmSubmittedTransaction.ts +0 -42
  295. package/src/transaction/hydrateTransaction.ts +0 -117
  296. package/src/transaction/index.ts +0 -9
  297. package/src/transaction/primitives/index.ts +0 -4
  298. package/src/transaction/primitives/transactionBlockByteCount.ts +0 -10
  299. package/src/transaction/primitives/transactionElevatedPayloads.ts +0 -18
  300. package/src/transaction/primitives/transactionOperations.ts +0 -13
  301. package/src/transaction/primitives/transactionRequiredGas.ts +0 -22
  302. package/src/transaction/script.ts +0 -48
  303. package/src/transaction/signTransaction.ts +0 -32
  304. package/src/utils/HydratedCache.ts +0 -39
  305. package/src/utils/index.ts +0 -2
  306. package/src/utils/isZodError.ts +0 -11
  307. package/src/validation/index.ts +0 -2
  308. package/src/validation/lib/getUrl.ts +0 -7
  309. package/src/validation/lib/index.ts +0 -2
  310. package/src/validation/lib/isLocalhost.ts +0 -9
  311. package/src/validation/schema/Address.ts +0 -2
  312. package/src/validation/schema/Mnemonic.ts +0 -21
  313. package/src/validation/schema/index.ts +0 -2
  314. package/src/wallet/generateXyoBaseWalletFromPhrase.ts +0 -13
  315. package/src/wallet/index.ts +0 -2
  316. package/src/wallet/paths.ts +0 -17
@@ -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)
@@ -1,4 +0,0 @@
1
- export * from './AddressPairPayload.ts'
2
- export * from './netBalancesForPayloads.ts'
3
- export * from './netSchemasForPayloads.ts'
4
- export * from './netTransfersForPayloads.ts'
@@ -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,2 +0,0 @@
1
- export * from './range/index.ts'
2
- export * from './rate/index.ts'
@@ -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,4 +0,0 @@
1
- export * from './blockRate.ts'
2
- export * from './stepRate.ts'
3
- export * from './timeHelpers.ts'
4
- export * from './timeRate.ts'
@@ -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
- }
@@ -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
- }