@xyo-network/xl1-protocol-sdk 1.16.21 → 1.16.23

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 (137) hide show
  1. package/dist/neutral/ChainServiceCollectionV2.d.ts +3 -3
  2. package/dist/neutral/ChainServiceCollectionV2.d.ts.map +1 -1
  3. package/dist/neutral/block/primitives/index.d.ts +0 -1
  4. package/dist/neutral/block/primitives/index.d.ts.map +1 -1
  5. package/dist/neutral/config/Chain.d.ts +1 -0
  6. package/dist/neutral/config/Chain.d.ts.map +1 -1
  7. package/dist/neutral/config/Config.d.ts +2 -0
  8. package/dist/neutral/config/Config.d.ts.map +1 -1
  9. package/dist/neutral/config/Producer.d.ts +1 -0
  10. package/dist/neutral/config/Producer.d.ts.map +1 -1
  11. package/dist/neutral/index.d.ts +2 -0
  12. package/dist/neutral/index.d.ts.map +1 -1
  13. package/dist/neutral/index.mjs +794 -240
  14. package/dist/neutral/index.mjs.map +1 -1
  15. package/dist/neutral/model/summary.d.ts +5 -0
  16. package/dist/neutral/model/summary.d.ts.map +1 -1
  17. package/dist/neutral/payloads/index.d.ts +1 -0
  18. package/dist/neutral/payloads/index.d.ts.map +1 -1
  19. package/dist/neutral/payloads/netSchemasForPayloads.d.ts +4 -0
  20. package/dist/neutral/payloads/netSchemasForPayloads.d.ts.map +1 -0
  21. package/dist/neutral/payloads/summary/SchemasStepSummary.d.ts +18 -0
  22. package/dist/neutral/payloads/summary/SchemasStepSummary.d.ts.map +1 -0
  23. package/dist/neutral/payloads/summary/index.d.ts +1 -0
  24. package/dist/neutral/payloads/summary/index.d.ts.map +1 -1
  25. package/dist/neutral/primitives/summary/index.d.ts +2 -1
  26. package/dist/neutral/primitives/summary/index.d.ts.map +1 -1
  27. package/dist/neutral/primitives/summary/schemas/index.d.ts +3 -0
  28. package/dist/neutral/primitives/summary/schemas/index.d.ts.map +1 -0
  29. package/dist/neutral/primitives/summary/schemas/schemasStepSummaryFromRange.d.ts +6 -0
  30. package/dist/neutral/primitives/summary/schemas/schemasStepSummaryFromRange.d.ts.map +1 -0
  31. package/dist/neutral/primitives/summary/schemas/schemasSummary.d.ts +4 -0
  32. package/dist/neutral/primitives/summary/schemas/schemasSummary.d.ts.map +1 -0
  33. package/dist/neutral/primitives/summary/transfers/transfersStepSummaryFromRange.d.ts.map +1 -1
  34. package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts +3 -2
  35. package/dist/neutral/primitives/summary/transfers/transfersSummary.d.ts.map +1 -1
  36. package/dist/neutral/primitives/timeBudget.d.ts +1 -1
  37. package/dist/neutral/primitives/timeBudget.d.ts.map +1 -1
  38. package/dist/neutral/services/SchemasService.d.ts +9 -0
  39. package/dist/neutral/services/SchemasService.d.ts.map +1 -0
  40. package/dist/neutral/services/StakeIntentService/ChainIndexingServiceStateSchema.d.ts +2 -2
  41. package/dist/neutral/services/StakeIntentService/ChainIndexingServiceStateSchema.d.ts.map +1 -1
  42. package/dist/neutral/services/index.d.ts +1 -1
  43. package/dist/neutral/services/index.d.ts.map +1 -1
  44. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
  45. package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
  46. package/dist/neutral/utils/index.d.ts +2 -0
  47. package/dist/neutral/utils/index.d.ts.map +1 -0
  48. package/dist/neutral/utils/isZodError.d.ts +4 -0
  49. package/dist/neutral/utils/isZodError.d.ts.map +1 -0
  50. package/dist/neutral/validation/block/HydratedBlockStateValidationFunction.d.ts +2 -2
  51. package/dist/neutral/validation/block/HydratedBlockStateValidationFunction.d.ts.map +1 -1
  52. package/dist/neutral/viewers/AccountBalance.d.ts +60 -12
  53. package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
  54. package/dist/neutral/zod/ArrayBuffer.d.ts +4 -0
  55. package/dist/neutral/zod/ArrayBuffer.d.ts.map +1 -0
  56. package/dist/neutral/zod/BlockBoundWitness.d.ts +44 -0
  57. package/dist/neutral/zod/BlockBoundWitness.d.ts.map +1 -0
  58. package/dist/neutral/zod/BoundWitness.d.ts +123 -0
  59. package/dist/neutral/zod/BoundWitness.d.ts.map +1 -0
  60. package/dist/neutral/zod/Chain.d.ts +4 -0
  61. package/dist/neutral/zod/Chain.d.ts.map +1 -0
  62. package/dist/neutral/zod/HydratedBlock.d.ts +133 -0
  63. package/dist/neutral/zod/HydratedBlock.d.ts.map +1 -0
  64. package/dist/neutral/zod/HydratedTransaction.d.ts +210 -0
  65. package/dist/neutral/zod/HydratedTransaction.d.ts.map +1 -0
  66. package/dist/neutral/zod/Permission.d.ts +53 -0
  67. package/dist/neutral/zod/Permission.d.ts.map +1 -0
  68. package/dist/neutral/zod/RewardsRangeOptions.d.ts +11 -0
  69. package/dist/neutral/zod/RewardsRangeOptions.d.ts.map +1 -0
  70. package/dist/neutral/zod/Sequence.d.ts +9 -0
  71. package/dist/neutral/zod/Sequence.d.ts.map +1 -0
  72. package/dist/neutral/zod/Stake.d.ts +62 -0
  73. package/dist/neutral/zod/Stake.d.ts.map +1 -0
  74. package/dist/neutral/zod/TimeDomain.d.ts +3 -0
  75. package/dist/neutral/zod/TimeDomain.d.ts.map +1 -0
  76. package/dist/neutral/zod/TransactionBoundWitness.d.ts +75 -0
  77. package/dist/neutral/zod/TransactionBoundWitness.d.ts.map +1 -0
  78. package/dist/neutral/zod/TransactionFees.d.ts +53 -0
  79. package/dist/neutral/zod/TransactionFees.d.ts.map +1 -0
  80. package/dist/neutral/zod/TransferPair.d.ts +3 -0
  81. package/dist/neutral/zod/TransferPair.d.ts.map +1 -0
  82. package/dist/neutral/zod/index.d.ts +15 -0
  83. package/dist/neutral/zod/index.d.ts.map +1 -0
  84. package/package.json +4 -4
  85. package/src/ChainServiceCollectionV2.ts +3 -3
  86. package/src/block/primitives/index.ts +0 -1
  87. package/src/config/Chain.ts +8 -0
  88. package/src/config/Producer.ts +6 -0
  89. package/src/index.ts +2 -0
  90. package/src/model/summary.ts +5 -0
  91. package/src/payloads/index.ts +1 -0
  92. package/src/payloads/netSchemasForPayloads.ts +22 -0
  93. package/src/payloads/summary/SchemasStepSummary.ts +26 -0
  94. package/src/payloads/summary/index.ts +1 -0
  95. package/src/primitives/summary/balances/balancesSummary.ts +1 -1
  96. package/src/primitives/summary/index.ts +2 -1
  97. package/src/primitives/summary/schemas/index.ts +2 -0
  98. package/src/primitives/summary/schemas/schemasStepSummaryFromRange.ts +83 -0
  99. package/src/primitives/summary/schemas/schemasSummary.ts +33 -0
  100. package/src/primitives/summary/transfers/transfersStepSummaryFromRange.ts +8 -6
  101. package/src/primitives/summary/transfers/transfersSummary.ts +11 -7
  102. package/src/primitives/timeBudget.ts +21 -2
  103. package/src/services/SchemasService.ts +9 -0
  104. package/src/services/index.ts +1 -1
  105. package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +5 -5
  106. package/src/simple/chainStake/SimpleChainStakeViewer.ts +1 -1
  107. package/src/utils/index.ts +1 -0
  108. package/src/utils/isZodError.ts +9 -0
  109. package/src/validation/block/HydratedBlockStateValidationFunction.ts +2 -2
  110. package/src/viewers/AccountBalance.ts +17 -15
  111. package/src/zod/ArrayBuffer.ts +42 -0
  112. package/src/zod/BlockBoundWitness.ts +36 -0
  113. package/src/zod/BoundWitness.ts +56 -0
  114. package/src/zod/Chain.ts +5 -0
  115. package/src/zod/HydratedBlock.ts +32 -0
  116. package/src/zod/HydratedTransaction.ts +37 -0
  117. package/src/zod/Permission.ts +23 -0
  118. package/src/zod/RewardsRangeOptions.ts +10 -0
  119. package/src/zod/Sequence.ts +15 -0
  120. package/src/zod/Stake.ts +43 -0
  121. package/src/zod/TimeDomain.ts +7 -0
  122. package/src/zod/TransactionBoundWitness.ts +42 -0
  123. package/src/zod/TransactionFees.ts +45 -0
  124. package/src/zod/TransferPair.ts +6 -0
  125. package/src/zod/index.ts +14 -0
  126. package/dist/neutral/block/primitives/transfers/index.d.ts +0 -3
  127. package/dist/neutral/block/primitives/transfers/index.d.ts.map +0 -1
  128. package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts +0 -6
  129. package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +0 -1
  130. package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts +0 -5
  131. package/dist/neutral/block/primitives/transfers/transfersSummary.d.ts.map +0 -1
  132. package/dist/neutral/services/AccountBalanceService.d.ts +0 -4
  133. package/dist/neutral/services/AccountBalanceService.d.ts.map +0 -1
  134. package/src/block/primitives/transfers/index.ts +0 -2
  135. package/src/block/primitives/transfers/transfersStepSummaryFromRange.ts +0 -98
  136. package/src/block/primitives/transfers/transfersSummary.ts +0 -44
  137. package/src/services/AccountBalanceService.ts +0 -4
@@ -1,28 +1,30 @@
1
1
  import type {
2
2
  Address, Hash, Promisable,
3
3
  } from '@xylabs/sdk-js'
4
- import type { Signed } from '@xyo-network/boundwitness-model'
5
- import type { WithStorageMeta } from '@xyo-network/payload-model'
6
- import type {
7
- AttoXL1,
8
- BlockBoundWitness, TransactionBoundWitness, Transfer,
9
- XL1BlockRange,
4
+ import { WithHashMetaZod } from '@xyo-network/payload-model'
5
+ import {
6
+ type AttoXL1,
7
+ TransferZod,
8
+ type XL1BlockRange,
10
9
  } from '@xyo-network/xl1-protocol'
10
+ import z from 'zod'
11
11
 
12
- export type AccountBalanceHistoryItem = [
13
- WithStorageMeta<Signed<BlockBoundWitness>> /* block */,
14
- WithStorageMeta<Signed<TransactionBoundWitness>> | null,
15
- WithStorageMeta<Transfer>, /* the actual transfer payload */
16
- ]
12
+ import { BlockBoundWitnessZod, TransactionBoundWitnessZod } from '../zod/index.ts'
17
13
 
18
- export interface AccountBalancesViewerMethods {
19
- accountBalances(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AttoXL1>>>
20
- accountBalancesHistories(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
21
- }
14
+ export const AccountBalanceHistoryItemZod = z.tuple([
15
+ WithHashMetaZod(BlockBoundWitnessZod),
16
+ WithHashMetaZod(TransactionBoundWitnessZod).nullable(),
17
+ WithHashMetaZod(TransferZod),
18
+ ])
19
+
20
+ export type AccountBalanceHistoryItem = z.infer<typeof AccountBalanceHistoryItemZod>
22
21
 
23
22
  export interface AccountBalanceViewerMethods {
24
23
  accountBalance(address: Address, headOrRange?: Hash | XL1BlockRange): Promisable<AttoXL1>
25
24
  accountBalanceHistory(address: Address, headOrRange?: Hash | XL1BlockRange): Promisable<AccountBalanceHistoryItem[]>
25
+
26
+ accountsBalances(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AttoXL1>>>
27
+ accountsBalancesHistory(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
26
28
  }
27
29
 
28
30
  export interface AccountBalanceViewer extends AccountBalanceViewerMethods {}
@@ -0,0 +1,42 @@
1
+ import * as z from 'zod'
2
+
3
+ function base64Encode(u8: Uint8Array): string {
4
+ // Node
5
+ if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {
6
+ return Buffer.from(u8).toString('base64')
7
+ }
8
+
9
+ // Browser
10
+ let binary = ''
11
+ const chunk = 0x80_00
12
+ for (let i = 0; i < u8.length; i += chunk) {
13
+ // eslint-disable-next-line unicorn/prefer-code-point
14
+ binary += String.fromCharCode(...u8.subarray(i, i + chunk))
15
+ }
16
+ return btoa(binary)
17
+ }
18
+
19
+ /** Base64 decode that works in Node and browsers -> Uint8Array */
20
+ function base64Decode(b64: string): Uint8Array {
21
+ // Node
22
+ if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {
23
+ return new Uint8Array(Buffer.from(b64, 'base64'))
24
+ }
25
+
26
+ // Browser
27
+ const binary = atob(b64)
28
+ const u8 = new Uint8Array(binary.length)
29
+ // eslint-disable-next-line unicorn/prefer-code-point
30
+ for (let i = 0; i < binary.length; i++) u8[i] = binary.charCodeAt(i)
31
+ return u8
32
+ }
33
+
34
+ export const ArrayBufferToJsonZod = z.instanceof(ArrayBuffer).transform((x) => {
35
+ const u8 = new Uint8Array(x)
36
+ return base64Encode(u8)
37
+ })
38
+
39
+ export const JsonToArrayBufferZod = z.string().transform((x) => {
40
+ const u8 = base64Decode(x)
41
+ return u8.buffer
42
+ })
@@ -0,0 +1,36 @@
1
+ import { HashZod } from '@xylabs/sdk-js'
2
+ import { StorageMetaZod } from '@xyo-network/payload-model'
3
+ import { XL1BlockNumberZod } from '@xyo-network/xl1-protocol'
4
+ import * as z from 'zod'
5
+
6
+ import {
7
+ SignedBoundWitnessZod,
8
+ UnsignedBoundWitnessZod,
9
+ } from './BoundWitness.ts'
10
+ import { ChainZod } from './Chain.ts'
11
+
12
+ const BlockBoundWitnessFieldsZod = z.object({
13
+ block: XL1BlockNumberZod,
14
+ chain: ChainZod,
15
+ previous: HashZod.nullable(),
16
+ protocol: z.number(),
17
+ step_hashes: z.array(HashZod).optional(),
18
+ })
19
+
20
+ const BlockBoundWitnessMetaZod = z.object({ $epoch: z.number() })
21
+
22
+ export const BlockBoundWitnessZod = UnsignedBoundWitnessZod
23
+ // eslint-disable-next-line sonarjs/deprecation
24
+ .merge(StorageMetaZod.partial())
25
+ // eslint-disable-next-line sonarjs/deprecation
26
+ .merge(BlockBoundWitnessFieldsZod)
27
+ // eslint-disable-next-line sonarjs/deprecation
28
+ .merge(BlockBoundWitnessMetaZod)
29
+
30
+ export const SignedBlockBoundWitnessZod = SignedBoundWitnessZod
31
+ // eslint-disable-next-line sonarjs/deprecation
32
+ .merge(StorageMetaZod.partial())
33
+ // eslint-disable-next-line sonarjs/deprecation
34
+ .merge(BlockBoundWitnessFieldsZod)
35
+ // eslint-disable-next-line sonarjs/deprecation
36
+ .merge(BlockBoundWitnessMetaZod)
@@ -0,0 +1,56 @@
1
+ import {
2
+ AddressZod, HashZod, HexZod,
3
+ } from '@xylabs/sdk-js'
4
+ import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
5
+ import {
6
+ PayloadZod, SchemaZod, StorageMetaZod,
7
+ } from '@xyo-network/payload-model'
8
+ import * as z from 'zod'
9
+
10
+ const BoundWitnessRequiredFieldsZod = z.object({
11
+ addresses: z.array(AddressZod),
12
+ payload_hashes: z.array(HashZod),
13
+ payload_schemas: z.array(SchemaZod),
14
+ previous_hashes: z.array(HashZod.nullable()),
15
+ })
16
+
17
+ const BoundWitnessMetaZod = z.object({
18
+ $destination: AddressZod.optional(),
19
+ $sourceQuery: HashZod.optional(),
20
+ $signatures: z.array(z.union([HexZod, z.null()])),
21
+ })
22
+
23
+ export const BoundWitnessZod = PayloadZod
24
+ .extend({ schema: z.literal(BoundWitnessSchema) })
25
+ .extend(BoundWitnessRequiredFieldsZod.shape)
26
+ .extend(BoundWitnessMetaZod.shape)
27
+ .refine(data => data.$signatures.length === data.addresses.length, { message: '$signatures length must equal addresses length' })
28
+
29
+ export type BoundWitness = z.infer<typeof BoundWitnessZod>
30
+
31
+ export const AnyBoundWitnessZod = BoundWitnessZod
32
+ .catchall(z.any())
33
+
34
+ export type AnyBoundWitness = z.infer<typeof AnyBoundWitnessZod>
35
+
36
+ export const UnsignedBoundWitnessZod = BoundWitnessZod.refine(data => data.$signatures.includes(null), { message: 'all $signatures must be null' })
37
+
38
+ export type UnsignedBoundWitness = z.infer<typeof UnsignedBoundWitnessZod>
39
+
40
+ export const AnyUnsignedBoundWitnessZod = UnsignedBoundWitnessZod
41
+ .catchall(z.any())
42
+
43
+ export type AnyUnsignedBoundWitness = z.infer<typeof AnyUnsignedBoundWitnessZod>
44
+
45
+ export const UnsignedBoundWitnessWithStorageMetaZod = UnsignedBoundWitnessZod
46
+ .safeExtend(BoundWitnessRequiredFieldsZod.shape)
47
+ .safeExtend(BoundWitnessMetaZod.shape)
48
+ .safeExtend(StorageMetaZod.shape)
49
+
50
+ export const SignedBoundWitnessZod = BoundWitnessZod.refine(data => !data.$signatures.includes(null), { message: 'all $signatures must not be null' })
51
+
52
+ export const SignedBoundWitnessWithStorageMetaZod = UnsignedBoundWitnessWithStorageMetaZod
53
+
54
+ export const AnySignedBoundWitnessZod = UnsignedBoundWitnessZod.catchall(z.any())
55
+
56
+ export const AnySignedBoundWitnessWithStorageMetaZod = UnsignedBoundWitnessWithStorageMetaZod.catchall(z.any())
@@ -0,0 +1,5 @@
1
+ import { AddressRegEx, toAddress } from '@xylabs/sdk-js'
2
+ import type { ChainId } from '@xyo-network/xl1-protocol'
3
+ import * as z from 'zod'
4
+
5
+ export const ChainZod = z.string().toLowerCase().regex(AddressRegEx).transform<ChainId>(v => toAddress(v) as ChainId)
@@ -0,0 +1,32 @@
1
+ import { PayloadZodLoose, WithStorageMetaZod } from '@xyo-network/payload-model'
2
+ import * as z from 'zod'
3
+
4
+ import {
5
+ BlockBoundWitnessZod,
6
+ SignedBlockBoundWitnessZod,
7
+ } from './BlockBoundWitness.ts'
8
+
9
+ export const HydratedBlockZod = z.tuple([
10
+ BlockBoundWitnessZod,
11
+ z.array(PayloadZodLoose),
12
+ ])
13
+
14
+ export const HydratedBlockWithStorageMetaZod = z.tuple([
15
+ WithStorageMetaZod(BlockBoundWitnessZod),
16
+ z.array(WithStorageMetaZod(PayloadZodLoose)),
17
+ ])
18
+
19
+ export const SignedHydratedBlockZod = z.tuple([
20
+ SignedBlockBoundWitnessZod,
21
+ z.array(PayloadZodLoose),
22
+ ])
23
+
24
+ export const SignedHydratedBlockToJsonZod = z.tuple([
25
+ SignedBlockBoundWitnessZod,
26
+ z.array(PayloadZodLoose),
27
+ ])
28
+
29
+ export const SignedHydratedBlockWithStorageMetaZod = z.tuple([
30
+ WithStorageMetaZod(SignedBlockBoundWitnessZod),
31
+ z.array(WithStorageMetaZod(PayloadZodLoose)),
32
+ ])
@@ -0,0 +1,37 @@
1
+ import type { JsonObject } from '@xylabs/sdk-js'
2
+ import { asAnyPayload, PayloadZodLoose } from '@xyo-network/payload-model'
3
+ import { asSignedHydratedTransaction } from '@xyo-network/xl1-protocol'
4
+ import * as z from 'zod'
5
+
6
+ import { SignedTransactionBoundWitnessZod, TransactionBoundWitnessZod } from './TransactionBoundWitness.ts'
7
+
8
+ export const HydratedTransactionZod = z.tuple([
9
+ TransactionBoundWitnessZod,
10
+ z.array(PayloadZodLoose),
11
+ ])
12
+
13
+ export const UnsignedHydratedTransactionZod = z.tuple([
14
+ TransactionBoundWitnessZod,
15
+ z.array(PayloadZodLoose),
16
+ ])
17
+
18
+ export const SignedHydratedTransactionZod = z.tuple([
19
+ SignedTransactionBoundWitnessZod,
20
+ z.array(PayloadZodLoose),
21
+ ])
22
+
23
+ export const SignedHydratedTransactionToJsonZod = SignedHydratedTransactionZod.transform(([
24
+ tx,
25
+ payloads,
26
+ ]) => asSignedHydratedTransaction([
27
+ tx as JsonObject,
28
+ payloads.map(payload => payload as JsonObject),
29
+ ]))
30
+
31
+ export const JsonToSignedHydratedTransactionZod = SignedHydratedTransactionZod.transform(([
32
+ tx,
33
+ payloads,
34
+ ]) => ([
35
+ asSignedHydratedTransaction(tx),
36
+ payloads.map(p => asAnyPayload(p)),
37
+ ]))
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod'
2
+
3
+ export const CaveatTypesZod = z.enum(['chain', 'expiration', 'filteredResponse', 'rateLimit', 'restrictReturnedAccounts'])
4
+
5
+ export const CaveatsZod = z.object({
6
+ type: CaveatTypesZod,
7
+ value: z.json(),
8
+ })
9
+
10
+ export const PermissionZod = z.object({
11
+ parentCapability: z.string(),
12
+ caveats: CaveatsZod.array().optional(),
13
+ invoker: z.string(),
14
+ })
15
+
16
+ export const InvokerPermissionZod = PermissionZod.extend({ date: z.number().optional() })
17
+
18
+ export const PermissionRequestZod = z.record(z.string(), z.record(z.string(), z.any()))
19
+
20
+ export const RequestedPermissionZod = z.object({
21
+ parentCapability: z.string(),
22
+ date: z.number().optional(),
23
+ })
@@ -0,0 +1,10 @@
1
+ import { AddressZod } from '@xylabs/sdk-js'
2
+ import { BlockRangeZod, StepIdentityZod } from '@xyo-network/xl1-protocol'
3
+ import { z } from 'zod'
4
+
5
+ export const RewardsRangeOptionsZod = z.object({
6
+ positions: z.array(z.number()).optional(),
7
+ range: BlockRangeZod.optional(),
8
+ steps: z.array(StepIdentityZod).optional(),
9
+ stakers: z.array(AddressZod).optional(),
10
+ })
@@ -0,0 +1,15 @@
1
+ import { HexRegExMinMax, toHex } from '@xylabs/sdk-js'
2
+ import type { LocalSequence, QualifiedSequence } from '@xyo-network/payload-model'
3
+ import { SequenceConstants } from '@xyo-network/payload-model'
4
+ import * as z from 'zod'
5
+
6
+ const LocalSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.localSequenceBytes, SequenceConstants.localSequenceBytes))
7
+ export const LocalSequenceToStringZod = z.string().regex(LocalSequenceRegex)
8
+ export const LocalSequenceFromStringZod = z.string().regex(LocalSequenceRegex).transform<LocalSequence>(v => toHex(v) as LocalSequence)
9
+
10
+ const QualifiedSequenceRegex = new RegExp(HexRegExMinMax(SequenceConstants.qualifiedSequenceBytes, SequenceConstants.qualifiedSequenceBytes))
11
+ export const QualifiedSequenceToStringZod = z.string().regex(QualifiedSequenceRegex)
12
+ export const QualifiedSequenceFromStringZod = z.string().regex(QualifiedSequenceRegex).transform<QualifiedSequence>(v => toHex(v) as QualifiedSequence)
13
+
14
+ export const SequenceToStringZod = z.union([LocalSequenceToStringZod, QualifiedSequenceToStringZod])
15
+ export const SequenceFromStringZod = z.union([LocalSequenceFromStringZod, QualifiedSequenceFromStringZod])
@@ -0,0 +1,43 @@
1
+ import { AddressZod, HexZod } from '@xylabs/sdk-js'
2
+ import type { PositionId } from '@xyo-network/xl1-protocol'
3
+ import * as z from 'zod'
4
+
5
+ import {
6
+ AttoToJsonZod, AttoZod, JsonToAttoZod,
7
+ } from './TransactionFees.ts'
8
+
9
+ export const StakeZod = z.object({
10
+ amount: AttoZod,
11
+ // the block number when the stake was added
12
+ addBlock: z.number(),
13
+ // the unique id for the stake item
14
+ id: z.number(),
15
+ // the block number when the stake was removed (set to 0 if not removed)
16
+ removeBlock: z.number(),
17
+ // the address that is being staked
18
+ staked: AddressZod,
19
+ // the address that owns the stake
20
+ staker: AddressZod,
21
+ // the block number when the stake was withdrawn (set to 0 if not withdrawn)
22
+ withdrawBlock: z.number(),
23
+ })
24
+
25
+ export const StakeToJsonZod = StakeZod.transform(val => ({
26
+ addBlock: val.addBlock,
27
+ amount: AttoToJsonZod.parse(val.amount),
28
+ id: val.id,
29
+ removeBlock: val.removeBlock,
30
+ staked: AddressZod.parse(val.staked),
31
+ staker: AddressZod.parse(val.staker),
32
+ withdrawBlock: val.withdrawBlock,
33
+ }))
34
+
35
+ export const JsonToStakeZod = StakeZod.extend({ amount: HexZod }).transform(val => ({
36
+ addBlock: val.addBlock,
37
+ amount: JsonToAttoZod.parse(val.amount),
38
+ id: val.id as PositionId,
39
+ removeBlock: val.removeBlock,
40
+ staked: val.staked,
41
+ staker: val.staker,
42
+ withdrawBlock: val.withdrawBlock,
43
+ }))
@@ -0,0 +1,7 @@
1
+ import * as z from 'zod'
2
+
3
+ export const TimeDomainZod = z.union([
4
+ z.literal('xl1'),
5
+ z.literal('epoch'),
6
+ z.literal('ethereum'),
7
+ ])
@@ -0,0 +1,42 @@
1
+ import { StorageMetaZod } from '@xyo-network/payload-model'
2
+ import { BlockNumberZod } from '@xyo-network/xl1-protocol'
3
+ import * as z from 'zod'
4
+
5
+ import { SignedBoundWitnessZod, UnsignedBoundWitnessZod } from './BoundWitness.ts'
6
+ import { ChainZod } from './Chain.ts'
7
+ import { TransactionFeesHexZod } from './TransactionFees.ts'
8
+
9
+ export const BlockStartZod = z.object({ nbf: BlockNumberZod })
10
+ export const BlockEndZod = z.object({ exp: BlockNumberZod })
11
+ export const BlockDurationZod = z.object({ nbf: BlockNumberZod, exp: BlockNumberZod })
12
+ export const BlockScriptsZod = z.object({ script: z.array(z.string()).optional() })
13
+
14
+ export const WithTransactionFeesZod = z.object({ fees: TransactionFeesHexZod })
15
+
16
+ const TransactionBoundWitnessFields = z.object({ chain: ChainZod, from: ChainZod })
17
+
18
+ // It seems like zod marked all of merge as deprecated even though just multiple merges should have been deprecated
19
+
20
+ export const TransactionBoundWitnessZod = UnsignedBoundWitnessZod
21
+ // eslint-disable-next-line sonarjs/deprecation
22
+ .merge(StorageMetaZod.partial())
23
+ // eslint-disable-next-line sonarjs/deprecation
24
+ .merge(BlockDurationZod)
25
+ // eslint-disable-next-line sonarjs/deprecation
26
+ .merge(WithTransactionFeesZod)
27
+ // eslint-disable-next-line sonarjs/deprecation
28
+ .merge(TransactionBoundWitnessFields)
29
+ // eslint-disable-next-line sonarjs/deprecation
30
+ .merge(BlockScriptsZod)
31
+
32
+ export const SignedTransactionBoundWitnessZod = SignedBoundWitnessZod
33
+ // eslint-disable-next-line sonarjs/deprecation
34
+ .merge(StorageMetaZod.partial())
35
+ // eslint-disable-next-line sonarjs/deprecation
36
+ .merge(BlockDurationZod)
37
+ // eslint-disable-next-line sonarjs/deprecation
38
+ .merge(WithTransactionFeesZod)
39
+ // eslint-disable-next-line sonarjs/deprecation
40
+ .merge(TransactionBoundWitnessFields)
41
+ // eslint-disable-next-line sonarjs/deprecation
42
+ .merge(BlockScriptsZod.partial())
@@ -0,0 +1,45 @@
1
+ import {
2
+ BigIntToJsonZod, HexZod, JsonToBigIntZod,
3
+ } from '@xylabs/sdk-js'
4
+ import { asAttoXL1 } from '@xyo-network/xl1-protocol'
5
+ import * as z from 'zod'
6
+
7
+ export const AttoZod = z.bigint()
8
+ export const JsonToAttoZod = JsonToBigIntZod.transform(v => asAttoXL1(v))
9
+ // eslint-disable-next-line unicorn/prefer-export-from
10
+ export const AttoToJsonZod = BigIntToJsonZod
11
+
12
+ export const TransactionFeesHexZod = z.object({
13
+ base: HexZod,
14
+ gasLimit: HexZod,
15
+ gasPrice: HexZod,
16
+ priority: HexZod,
17
+ })
18
+
19
+ export type TransactionFeesHexZodType = z.infer<typeof TransactionFeesHexZod>
20
+
21
+ export const TransactionFeesBigIntZod = z.object({
22
+ base: AttoZod,
23
+ gasLimit: AttoZod,
24
+ gasPrice: AttoZod,
25
+ priority: AttoZod,
26
+ })
27
+
28
+ export type TransactionFeesBigIntZodType = z.infer<typeof TransactionFeesBigIntZod>
29
+
30
+ export const TransactionFeesJsonToBigIntZod = TransactionFeesHexZod.transform(val => ({
31
+ base: JsonToBigIntZod.parse(val.base),
32
+ gasLimit: JsonToBigIntZod.parse(val.gasLimit),
33
+ gasPrice: JsonToBigIntZod.parse(val.gasPrice),
34
+ priority: JsonToBigIntZod.parse(val.priority),
35
+ }))
36
+
37
+ export const TransactionFeesBigIntToJsonZod = TransactionFeesBigIntZod.transform(val => ({
38
+ base: BigIntToJsonZod.parse(val.base),
39
+ gasLimit: BigIntToJsonZod.parse(val.gasLimit),
40
+ gasPrice: BigIntToJsonZod.parse(val.gasPrice),
41
+ priority: BigIntToJsonZod.parse(val.priority),
42
+ }))
43
+
44
+ export type TransactionFeesJsonToBigIntZodType = z.infer<typeof TransactionFeesJsonToBigIntZod>
45
+ export type TransactionFeesBigIntToJsonZodType = z.infer<typeof TransactionFeesBigIntToJsonZod>
@@ -0,0 +1,6 @@
1
+ import { AddressZod } from '@xylabs/sdk-js'
2
+ import z from 'zod'
3
+
4
+ export const TransferPairZod = z.tuple([
5
+ AddressZod, AddressZod,
6
+ ])
@@ -0,0 +1,14 @@
1
+ export * from './ArrayBuffer.ts'
2
+ export * from './BlockBoundWitness.ts'
3
+ export * from './BoundWitness.ts'
4
+ export * from './Chain.ts'
5
+ export * from './HydratedBlock.ts'
6
+ export * from './HydratedTransaction.ts'
7
+ export * from './Permission.ts'
8
+ export * from './RewardsRangeOptions.ts'
9
+ export * from './Sequence.ts'
10
+ export * from './Stake.ts'
11
+ export * from './TimeDomain.ts'
12
+ export * from './TransactionBoundWitness.ts'
13
+ export * from './TransactionFees.ts'
14
+ export * from './TransferPair.ts'
@@ -1,3 +0,0 @@
1
- export * from './transfersStepSummaryFromRange.ts';
2
- export * from './transfersSummary.ts';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/block/primitives/transfers/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,uBAAuB,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { WithStorageMeta } from '@xyo-network/payload-model';
2
- import type { XL1BlockRange } from '@xyo-network/xl1-protocol';
3
- import type { TransfersStepSummaryContext } from '../../../model/index.ts';
4
- import type { TransfersStepSummary } from '../../../payloads/index.ts';
5
- export declare function transfersStepSummaryFromRange(context: TransfersStepSummaryContext, range: XL1BlockRange): Promise<WithStorageMeta<TransfersStepSummary>>;
6
- //# sourceMappingURL=transfersStepSummaryFromRange.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transfersStepSummaryFromRange.d.ts","sourceRoot":"","sources":["../../../../../src/block/primitives/transfers/transfersStepSummaryFromRange.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAG9D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAUtE,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,2BAA2B,EACpC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC,CA0EhD"}
@@ -1,5 +0,0 @@
1
- import type { Address, Hash } from '@xylabs/sdk-js';
2
- import type { TransfersStepSummaryContext } from '../../../model/index.ts';
3
- export declare function transfersSummary(transferContext: TransfersStepSummaryContext): Promise<Partial<Record<Address, Partial<Record<Address, bigint>>>>>;
4
- export declare function transfersSummaryKey(frameHeadHash: Hash, frameSize: number): string;
5
- //# sourceMappingURL=transfersSummary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transfersSummary.d.ts","sourceRoot":"","sources":["../../../../../src/block/primitives/transfers/transfersSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAOnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAM1E,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,2BAA2B,GAC3C,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAwBrE;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAEzE"}
@@ -1,4 +0,0 @@
1
- import type { AccountBalancesViewerMethods, AccountBalanceViewerMethods } from '../viewers/index.ts';
2
- export interface AccountBalanceService extends AccountBalancesViewerMethods, AccountBalanceViewerMethods {
3
- }
4
- //# sourceMappingURL=AccountBalanceService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccountBalanceService.d.ts","sourceRoot":"","sources":["../../../src/services/AccountBalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAEpG,MAAM,WAAW,qBAAsB,SAAQ,4BAA4B,EAAE,2BAA2B;CACvG"}
@@ -1,2 +0,0 @@
1
- export * from './transfersStepSummaryFromRange.ts'
2
- export * from './transfersSummary.ts'
@@ -1,98 +0,0 @@
1
- /* eslint-disable max-statements */
2
- import { type Address } from '@xylabs/sdk-js'
3
- import { assertEx } from '@xylabs/sdk-js'
4
- import { PayloadBuilder } from '@xyo-network/payload-builder'
5
- import type { WithStorageMeta } from '@xyo-network/payload-model'
6
- import { isAnyPayload } from '@xyo-network/payload-model'
7
- import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
8
- import { StepSizes } from '@xyo-network/xl1-protocol'
9
-
10
- import type { TransfersStepSummaryContext } from '../../../model/index.ts'
11
- import type { TransfersStepSummary } from '../../../payloads/index.ts'
12
- import { netTransfersForPayloads, TransfersStepSummarySchema } from '../../../payloads/index.ts'
13
- import {
14
- parseSignedBigInt, type SignedBigInt, toSignedBigInt,
15
- } from '../../../SignedBigInt.ts'
16
- import { hydrateBlock } from '../../hydrate/index.ts'
17
- import { deepCalculateFramesFromRange } from '../frames/index.ts'
18
- import { hashFromBlockNumber } from '../hashFromBlockNumber.ts'
19
- import { transfersSummaryKey } from './transfersSummary.ts'
20
-
21
- export async function transfersStepSummaryFromRange(
22
- context: TransfersStepSummaryContext,
23
- range: XL1BlockRange,
24
- ): Promise<WithStorageMeta<TransfersStepSummary>> {
25
- // console.log(`transfersStepSummaryFromRange: head=${context.head}, range=${range[0]}-${range[1]}`)
26
- const frameHeadHash = await hashFromBlockNumber(context, range[1])
27
- const frameSize = range[1] - range[0] + 1
28
- const [headHash] = await context.head()
29
-
30
- let result: TransfersStepSummary | undefined = undefined
31
-
32
- if (frameSize === 1) {
33
- const hash = await hashFromBlockNumber(context, range[0])
34
- const [, payloads] = await hydrateBlock(context.store, hash)
35
- const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
36
- for (const [from, toMap] of Object.entries(netTransfersForPayloads(payloads))) {
37
- transfers[from as Address] = transfers[from as Address] ?? {}
38
- for (const [to, amount] of Object.entries(toMap)) {
39
- transfers[from as Address][to as Address] = toSignedBigInt(amount)
40
- }
41
- }
42
- result = {
43
- schema: TransfersStepSummarySchema, hash: headHash, stepSize: -1, transfers,
44
- }
45
- } else {
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- const step = (StepSizes as any).indexOf(frameSize)
48
- assertEx(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes.join(', ')}`)
49
-
50
- const key = transfersSummaryKey(frameHeadHash, frameSize)
51
-
52
- const summaryResult = await context.summaryMap.get(key)
53
- if (isAnyPayload(summaryResult)) {
54
- result = summaryResult as WithStorageMeta<TransfersStepSummary>
55
- } else {
56
- await context.stepSemaphores[step].acquire()
57
- // We do not have it, so lets build it
58
- try {
59
- const subRanges = deepCalculateFramesFromRange(range, step - 1)
60
- const promises = subRanges.map(subRange => transfersStepSummaryFromRange(
61
- context,
62
- subRange,
63
- ))
64
- const subResults = await Promise.all(promises)
65
-
66
- // add them all up
67
- const bigIntBalances: Record<Address, Record<Address, bigint>> = {}
68
- for (const subResult of subResults) {
69
- for (const [from, toMap] of Object.entries(subResult.transfers)) {
70
- bigIntBalances[from as Address] = bigIntBalances[from as Address] ?? {}
71
- for (const [to, transfer] of Object.entries(toMap)) {
72
- bigIntBalances[from as Address][to as Address] = (bigIntBalances[from as Address][to as Address] ?? 0n) + parseSignedBigInt(transfer)
73
- }
74
- }
75
- }
76
-
77
- const transfers: Record<Address, Record<Address, SignedBigInt>> = {}
78
- for (const [from, toMap] of Object.entries(bigIntBalances)) {
79
- transfers[from as Address] = transfers[from as Address] ?? {}
80
- for (const [to, transfer] of Object.entries(toMap)) {
81
- transfers[from as Address][to as Address] = toSignedBigInt(transfer)
82
- }
83
- }
84
-
85
- result = {
86
- schema: TransfersStepSummarySchema, hash: frameHeadHash, stepSize: frameSize, transfers,
87
- }
88
-
89
- await context.summaryMap.set(key, result)
90
- } finally {
91
- context.stepSemaphores[step].release()
92
- }
93
- }
94
- }
95
- // console.log(`transfersStepSummaryFromRange-result: head=${context.head}, range=${range[0]}-${range[1]}: ${toSafeJsonString(result, 10)}`)
96
- const finalResult = await PayloadBuilder.addStorageMeta(result)
97
- return finalResult
98
- }