@xyo-network/xl1-protocol-sdk 1.15.7 → 1.15.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/block/primitives/balances/balancesStepSummaryFromRange.d.ts +2 -2
- package/dist/neutral/block/primitives/balances/balancesStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/block/primitives/blockFromBlockNumber.d.ts +2 -2
- package/dist/neutral/block/primitives/blockFromBlockNumber.d.ts.map +1 -1
- package/dist/neutral/block/primitives/frames/calculateFramesFromRange.d.ts +4 -4
- package/dist/neutral/block/primitives/frames/calculateFramesFromRange.d.ts.map +1 -1
- package/dist/neutral/block/primitives/frames/deepCalculateFramesFromRange.d.ts +2 -2
- package/dist/neutral/block/primitives/frames/deepCalculateFramesFromRange.d.ts.map +1 -1
- package/dist/neutral/block/primitives/frames/index.d.ts +0 -1
- package/dist/neutral/block/primitives/frames/index.d.ts.map +1 -1
- package/dist/neutral/block/primitives/hashFromBlockNumber.d.ts +2 -1
- package/dist/neutral/block/primitives/hashFromBlockNumber.d.ts.map +1 -1
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts +2 -2
- package/dist/neutral/block/primitives/transfers/transfersStepSummaryFromRange.d.ts.map +1 -1
- package/dist/neutral/constants.d.ts +3 -0
- package/dist/neutral/constants.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +2 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +33 -160
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/ChainContext/ChainStakeContext.d.ts +2 -0
- package/dist/neutral/model/ChainContext/ChainStakeContext.d.ts.map +1 -1
- package/dist/neutral/multipliers.d.ts +5 -0
- package/dist/neutral/multipliers.d.ts.map +1 -0
- package/dist/neutral/time/primitives/xl1BlockNumberToEthBlockNumber.d.ts +2 -1
- package/dist/neutral/time/primitives/xl1BlockNumberToEthBlockNumber.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/block/primitives/balances/balancesStepSummaryFromRange.ts +2 -2
- package/src/block/primitives/balances/balancesSummary.ts +3 -3
- package/src/block/primitives/blockFromBlockNumber.ts +5 -2
- package/src/block/primitives/frames/calculateFramesFromRange.ts +10 -11
- package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +5 -5
- package/src/block/primitives/frames/index.ts +0 -1
- package/src/block/primitives/frames/spec/calculateFramesFromRange.spec.ts +10 -7
- package/src/block/primitives/frames/spec/deepCalculateFramesFromRange.spec.ts +10 -10
- package/src/block/primitives/hashFromBlockNumber.ts +2 -1
- package/src/block/primitives/transfers/transfersStepSummaryFromRange.ts +3 -2
- package/src/block/primitives/transfers/transfersSummary.ts +3 -3
- package/src/constants.ts +2 -0
- package/src/index.ts +2 -1
- package/src/model/ChainContext/ChainStakeContext.ts +2 -0
- package/src/multipliers.ts +16 -0
- package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +2 -1
- package/dist/neutral/block/primitives/frames/BlockNumberRange.d.ts +0 -2
- package/dist/neutral/block/primitives/frames/BlockNumberRange.d.ts.map +0 -1
- package/dist/neutral/steps/index.d.ts +0 -2
- package/dist/neutral/steps/index.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/addressStakeWeight.d.ts +0 -4
- package/dist/neutral/steps/primitives/addressStakeWeight.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/claimedRewards.d.ts +0 -3
- package/dist/neutral/steps/primitives/claimedRewards.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/index.d.ts +0 -7
- package/dist/neutral/steps/primitives/index.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/stakersAsOfBlock.d.ts +0 -4
- package/dist/neutral/steps/primitives/stakersAsOfBlock.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/startingStakes.d.ts +0 -4
- package/dist/neutral/steps/primitives/startingStakes.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/totalStakeWeight.d.ts +0 -4
- package/dist/neutral/steps/primitives/totalStakeWeight.d.ts.map +0 -1
- package/dist/neutral/steps/primitives/unclaimedRewards.d.ts +0 -4
- package/dist/neutral/steps/primitives/unclaimedRewards.d.ts.map +0 -1
- package/src/block/primitives/frames/BlockNumberRange.ts +0 -1
- package/src/steps/index.ts +0 -1
- package/src/steps/primitives/addressStakeWeight.ts +0 -51
- package/src/steps/primitives/claimedRewards.ts +0 -5
- package/src/steps/primitives/index.ts +0 -6
- package/src/steps/primitives/stakersAsOfBlock.ts +0 -18
- package/src/steps/primitives/startingStakes.ts +0 -30
- package/src/steps/primitives/totalStakeWeight.ts +0 -35
- package/src/steps/primitives/unclaimedRewards.ts +0 -6
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ChainIdentity } from '../ChainIdentity.ts';
|
|
2
2
|
import type { ChainStakeRead, ChainStakeWrite } from '../ChainStake/index.ts';
|
|
3
|
+
import type { StakeEventsRead } from '../StakeEvents.ts';
|
|
3
4
|
export interface ChainStakeContextWrite extends ChainIdentity {
|
|
4
5
|
stake: ChainStakeWrite;
|
|
5
6
|
}
|
|
6
7
|
export interface ChainStakeContextRead extends ChainIdentity {
|
|
8
|
+
events: StakeEventsRead;
|
|
7
9
|
stake: ChainStakeRead;
|
|
8
10
|
}
|
|
9
11
|
export type ChainStakeContext = ChainStakeContextRead & ChainStakeContextWrite;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChainStakeContext.d.ts","sourceRoot":"","sources":["../../../../src/model/ChainContext/ChainStakeContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"ChainStakeContext.d.ts","sourceRoot":"","sources":["../../../../src/model/ChainContext/ChainStakeContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC3D,KAAK,EAAE,eAAe,CAAA;CACvB;AAED,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,cAAc,CAAA;CACtB;AAED,MAAM,MAAM,iBAAiB,GAAG,qBAAqB,GAAG,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { XL1RangeMultipliers } from '@xyo-network/xl1-protocol';
|
|
2
|
+
export declare const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS: import("@xyo-network/xl1-protocol").AttoXL1;
|
|
3
|
+
export declare const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS: import("@xyo-network/xl1-protocol").AttoXL1;
|
|
4
|
+
export declare const RewardMultipliers: XL1RangeMultipliers;
|
|
5
|
+
//# sourceMappingURL=multipliers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipliers.d.ts","sourceRoot":"","sources":["../../src/multipliers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAStF,eAAO,MAAM,gDAAgD,6CAAgD,CAAA;AAC7G,eAAO,MAAM,sDAAsD,6CAA8C,CAAA;AAEjH,eAAO,MAAM,iBAAiB,EAAE,mBAG/B,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { XL1BlockNumber } from '@xyo-network/xl1-protocol';
|
|
1
2
|
import type { ChainContextRead } from '../../model/index.ts';
|
|
2
|
-
export declare function xl1BlockNumberToEthBlockNumber(context: ChainContextRead, xl1BlockNumber:
|
|
3
|
+
export declare function xl1BlockNumberToEthBlockNumber(context: ChainContextRead, xl1BlockNumber: XL1BlockNumber): Promise<number>;
|
|
3
4
|
//# sourceMappingURL=xl1BlockNumberToEthBlockNumber.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xl1BlockNumberToEthBlockNumber.d.ts","sourceRoot":"","sources":["../../../../src/time/primitives/xl1BlockNumberToEthBlockNumber.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xl1BlockNumberToEthBlockNumber.d.ts","sourceRoot":"","sources":["../../../../src/time/primitives/xl1BlockNumberToEthBlockNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAI/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,wBAAsB,8BAA8B,CAAC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAK/H"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/xl1-protocol-sdk",
|
|
4
|
-
"version": "1.15.
|
|
4
|
+
"version": "1.15.9",
|
|
5
5
|
"description": "XYO Layer One SDK Protocol",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -55,17 +55,17 @@
|
|
|
55
55
|
"@xyo-network/typechain": "~4.0.10",
|
|
56
56
|
"@xyo-network/wallet": "~5.1.6",
|
|
57
57
|
"@xyo-network/wallet-model": "~5.1.6",
|
|
58
|
-
"@xyo-network/xl1-protocol": "~1.12.
|
|
58
|
+
"@xyo-network/xl1-protocol": "~1.12.78",
|
|
59
59
|
"async-mutex": "~0.5.0",
|
|
60
60
|
"zod": "~4.1.12"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@types/node": "~24.
|
|
63
|
+
"@types/node": "~24.8.1",
|
|
64
64
|
"@xylabs/ts-scripts-yarn3": "~7.1.8",
|
|
65
65
|
"@xylabs/tsconfig": "~7.1.8",
|
|
66
66
|
"@xyo-network/account": "~5.1.6",
|
|
67
67
|
"@xyo-network/boundwitness-validator": "~5.1.6",
|
|
68
|
-
"eslint": "^9.
|
|
68
|
+
"eslint": "^9.38.0",
|
|
69
69
|
"typescript": "~5.9.3",
|
|
70
70
|
"vitest": "~3.2.4"
|
|
71
71
|
},
|
|
@@ -4,6 +4,7 @@ import { type Address } from '@xylabs/hex'
|
|
|
4
4
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
5
|
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
6
6
|
import { isAnyPayload } from '@xyo-network/payload-model'
|
|
7
|
+
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
7
8
|
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
8
9
|
|
|
9
10
|
import { netBalancesForPayloads } from '../../../payload/index.ts'
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
parseSignedBigInt, type SignedBigInt, toSignedBigInt,
|
|
12
13
|
} from '../../../SignedBigInt.ts'
|
|
13
14
|
import { hydrateBlock } from '../../hydrate/index.ts'
|
|
14
|
-
import type { BlockNumberRange } from '../frames/index.ts'
|
|
15
15
|
import { deepCalculateFramesFromRange } from '../frames/index.ts'
|
|
16
16
|
import { hashFromBlockNumber } from '../hashFromBlockNumber.ts'
|
|
17
17
|
import type { BalanceStepSummaryContext } from '../model.ts'
|
|
@@ -19,7 +19,7 @@ import { type BalancesStepSummary, BalancesStepSummarySchema } from '../payloads
|
|
|
19
19
|
|
|
20
20
|
export async function balancesStepSummaryFromRange(
|
|
21
21
|
context: BalanceStepSummaryContext,
|
|
22
|
-
range:
|
|
22
|
+
range: XL1BlockRange,
|
|
23
23
|
): Promise<WithStorageMeta<BalancesStepSummary>> {
|
|
24
24
|
// console.log(`balanceStepSummaryFromRange: head=${head}, range=${range[0]}-${range[1]}`)
|
|
25
25
|
const frameHeadHash = await hashFromBlockNumber(context, range[1])
|
|
@@ -2,7 +2,7 @@ import type { Address } from '@xylabs/hex'
|
|
|
2
2
|
import { asAddress } from '@xylabs/hex'
|
|
3
3
|
import { spanRootAsync } from '@xylabs/telemetry'
|
|
4
4
|
import { isDefined } from '@xylabs/typeof'
|
|
5
|
-
import { asBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { asBlockBoundWitnessWithStorageMeta, asXL1BlockNumber } from '@xyo-network/xl1-protocol'
|
|
6
6
|
|
|
7
7
|
import { parseSignedBigInt } from '../../../SignedBigInt.ts'
|
|
8
8
|
import { deepCalculateFramesFromRange } from '../frames/index.ts'
|
|
@@ -16,8 +16,8 @@ export async function balancesSummary(
|
|
|
16
16
|
const head = await context.head()
|
|
17
17
|
const headResult = await context.store.chainMap.get(head)
|
|
18
18
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta(headResult, () => `Head block not found for hash: ${context.head}`, { required: true })
|
|
19
|
-
const rangeStart = isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0
|
|
20
|
-
const ranges = deepCalculateFramesFromRange([rangeStart, headBoundWitness.block])
|
|
19
|
+
const rangeStart = asXL1BlockNumber(isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0)
|
|
20
|
+
const ranges = deepCalculateFramesFromRange([rangeStart, asXL1BlockNumber(headBoundWitness.block)])
|
|
21
21
|
const summaries = await Promise.all(ranges.map(range => balancesStepSummaryFromRange(context, range)))
|
|
22
22
|
const balances: Partial<Record<Address, bigint>> = {}
|
|
23
23
|
for (let summary of summaries) {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { asHash, type Hash } from '@xylabs/hex'
|
|
2
2
|
import { toSafeJsonString } from '@xylabs/object'
|
|
3
3
|
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
4
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
4
|
+
import type { BlockBoundWitness, XL1BlockNumber } from '@xyo-network/xl1-protocol'
|
|
5
5
|
import { asBlockBoundWitnessWithStorageMeta, StepSizes } from '@xyo-network/xl1-protocol'
|
|
6
6
|
|
|
7
7
|
import type { ChainContextRead } from '../../model/index.ts'
|
|
8
8
|
|
|
9
|
-
export async function blockFromBlockNumber(context: ChainContextRead, blockNumber:
|
|
9
|
+
export async function blockFromBlockNumber(context: ChainContextRead, blockNumber: XL1BlockNumber): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
10
10
|
const head = await context.head()
|
|
11
11
|
const result = await context.store.chainMap.get(head)
|
|
12
12
|
let currentBlock = asBlockBoundWitnessWithStorageMeta(result, () => `Head block not found for hash: ${head}`, { required: true })
|
|
13
|
+
if (currentBlock.block < blockNumber) {
|
|
14
|
+
throw new Error(`Error: Block number ${blockNumber} is greater than head ${currentBlock.block}.`)
|
|
15
|
+
}
|
|
13
16
|
while (currentBlock.block > blockNumber) {
|
|
14
17
|
let jumpHash: Hash | null = currentBlock.previous
|
|
15
18
|
let jumpBlockNumber = currentBlock.block - 1
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
2
|
+
import { asXL1BlockNumber, stepSize } from '@xyo-network/xl1-protocol'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function calculateFramesFromRange(range: BlockNumberRange, step: number): [
|
|
4
|
+
export function calculateFramesFromRange(range: XL1BlockRange, step: number): [
|
|
6
5
|
// ranges of fitted frames
|
|
7
|
-
|
|
6
|
+
XL1BlockRange[],
|
|
8
7
|
// ranges of remaining blocks
|
|
9
|
-
|
|
8
|
+
XL1BlockRange[]] {
|
|
10
9
|
const size = stepSize(step)
|
|
11
10
|
let start = (Math.trunc(range[0] / size)) * size
|
|
12
|
-
const fitted:
|
|
13
|
-
const remaining:
|
|
11
|
+
const fitted: XL1BlockRange[] = []
|
|
12
|
+
const remaining: XL1BlockRange[] = []
|
|
14
13
|
|
|
15
14
|
// if the start is not aligned with the range, add a remaining block
|
|
16
15
|
if (start !== range[0]) {
|
|
17
16
|
start += size
|
|
18
|
-
remaining.push([range[0], Math.min(start - 1, range[1])])
|
|
17
|
+
remaining.push([range[0], asXL1BlockNumber(Math.min(start - 1, range[1]))])
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
for (let i = start; i <= range[1]; i += size) {
|
|
22
21
|
if ((i + size - 1) <= range[1]) {
|
|
23
|
-
fitted.push([i, Math.min(i + size - 1, range[1])])
|
|
22
|
+
fitted.push([asXL1BlockNumber(i), asXL1BlockNumber(Math.min(i + size - 1, range[1]))])
|
|
24
23
|
} else {
|
|
25
|
-
remaining.push([i, range[1]])
|
|
24
|
+
remaining.push([asXL1BlockNumber(i), range[1]])
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
return [fitted, remaining]
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
1
2
|
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
2
3
|
|
|
3
|
-
import type { BlockNumberRange } from './BlockNumberRange.ts'
|
|
4
4
|
import { calculateFramesFromRange } from './calculateFramesFromRange.ts'
|
|
5
5
|
|
|
6
|
-
export function deepCalculateFramesFromRange(range:
|
|
7
|
-
const fitted:
|
|
8
|
-
let remaining:
|
|
6
|
+
export function deepCalculateFramesFromRange(range: XL1BlockRange, startingStep = StepSizes.length - 1): XL1BlockRange[] {
|
|
7
|
+
const fitted: XL1BlockRange[] = []
|
|
8
|
+
let remaining: XL1BlockRange[] = [range]
|
|
9
9
|
|
|
10
10
|
for (let step = startingStep; step >= 0; step--) {
|
|
11
|
-
const newRemaining:
|
|
11
|
+
const newRemaining: XL1BlockRange[] = []
|
|
12
12
|
for (const range of remaining) {
|
|
13
13
|
const [newFittedFrames, newRemainingFrames] = calculateFramesFromRange(range, step)
|
|
14
14
|
fitted.push(...newFittedFrames)
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
2
|
+
import {
|
|
3
|
+
asXL1BlockNumber, stepSize, XL1_BLOCK_NUMBER_ZERO,
|
|
4
|
+
} from '@xyo-network/xl1-protocol'
|
|
2
5
|
import {
|
|
3
6
|
describe, expect, it,
|
|
4
7
|
} from 'vitest'
|
|
@@ -8,7 +11,7 @@ import { calculateFramesFromRange } from '../calculateFramesFromRange.ts'
|
|
|
8
11
|
describe('calculateFramesFromRange', () => {
|
|
9
12
|
it('handles range aligned with step size', () => {
|
|
10
13
|
const step = 1 // 105
|
|
11
|
-
const range:
|
|
14
|
+
const range: XL1BlockRange = [XL1_BLOCK_NUMBER_ZERO, asXL1BlockNumber(stepSize(step) - 1)]
|
|
12
15
|
const [fitted, remaining] = calculateFramesFromRange(range, step)
|
|
13
16
|
|
|
14
17
|
expect(fitted).toEqual([[0, 30]])
|
|
@@ -17,7 +20,7 @@ describe('calculateFramesFromRange', () => {
|
|
|
17
20
|
|
|
18
21
|
it('handles range starting at step boundary but incomplete', () => {
|
|
19
22
|
const step = 1
|
|
20
|
-
const range:
|
|
23
|
+
const range: XL1BlockRange = [asXL1BlockNumber(stepSize(step)), asXL1BlockNumber(stepSize(step) + 1)]
|
|
21
24
|
const [fitted, remaining] = calculateFramesFromRange(range, step)
|
|
22
25
|
|
|
23
26
|
expect(fitted).toEqual([])
|
|
@@ -28,7 +31,7 @@ describe('calculateFramesFromRange', () => {
|
|
|
28
31
|
const step = 1
|
|
29
32
|
const multiplier = 2
|
|
30
33
|
const additional = 1
|
|
31
|
-
const range:
|
|
34
|
+
const range: XL1BlockRange = [asXL1BlockNumber(stepSize(step)), asXL1BlockNumber((stepSize(step) + additional) * multiplier)]
|
|
32
35
|
const [fitted, remaining] = calculateFramesFromRange(range, step)
|
|
33
36
|
|
|
34
37
|
expect(fitted).toEqual([[31, 61]])
|
|
@@ -39,7 +42,7 @@ describe('calculateFramesFromRange', () => {
|
|
|
39
42
|
const step = 5
|
|
40
43
|
const multiplier = 2
|
|
41
44
|
const additional = 17
|
|
42
|
-
const range:
|
|
45
|
+
const range: XL1BlockRange = [asXL1BlockNumber(stepSize(step)), asXL1BlockNumber((stepSize(step) + additional) * multiplier)]
|
|
43
46
|
const [fitted, remaining] = calculateFramesFromRange(range, step)
|
|
44
47
|
|
|
45
48
|
expect(fitted).toEqual([[510_511, 1_021_021]])
|
|
@@ -50,7 +53,7 @@ describe('calculateFramesFromRange', () => {
|
|
|
50
53
|
const step = 1
|
|
51
54
|
const multiplier = 2
|
|
52
55
|
const additional = 1
|
|
53
|
-
const range:
|
|
56
|
+
const range: XL1BlockRange = [asXL1BlockNumber(stepSize(step) - additional), asXL1BlockNumber((stepSize(step) + additional) * multiplier)]
|
|
54
57
|
const [fitted, remaining] = calculateFramesFromRange(range, step)
|
|
55
58
|
|
|
56
59
|
expect(fitted).toEqual([[31, 61]])
|
|
@@ -61,7 +64,7 @@ describe('calculateFramesFromRange', () => {
|
|
|
61
64
|
const step = 5
|
|
62
65
|
const multiplier = 2
|
|
63
66
|
const additional = 17
|
|
64
|
-
const range:
|
|
67
|
+
const range: XL1BlockRange = [asXL1BlockNumber(stepSize(step) - additional), asXL1BlockNumber((stepSize(step) + additional) * multiplier)]
|
|
65
68
|
const [fitted, remaining] = calculateFramesFromRange(range, step)
|
|
66
69
|
|
|
67
70
|
expect(fitted).toEqual([[510_511, 1_021_021]])
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { asXL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
1
2
|
import {
|
|
2
3
|
describe, expect, it,
|
|
3
4
|
} from 'vitest'
|
|
4
5
|
|
|
5
|
-
import type { BlockNumberRange } from '../BlockNumberRange.ts'
|
|
6
6
|
import { deepCalculateFramesFromRange } from '../deepCalculateFramesFromRange.ts'
|
|
7
7
|
|
|
8
8
|
describe('deepCalculateFramesFromRange', () => {
|
|
9
9
|
it('calculates frames for a simple range with one step level', () => {
|
|
10
|
-
const range
|
|
10
|
+
const range = asXL1BlockRange([0, 9])
|
|
11
11
|
const result = deepCalculateFramesFromRange(range)
|
|
12
12
|
|
|
13
13
|
// With step 0 (size 10), this should fit in one frame
|
|
@@ -15,7 +15,7 @@ describe('deepCalculateFramesFromRange', () => {
|
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
it('calculates frames for a range spanning multiple step sizes', () => {
|
|
18
|
-
const range
|
|
18
|
+
const range = asXL1BlockRange([0, 250])
|
|
19
19
|
const result = deepCalculateFramesFromRange(range)
|
|
20
20
|
|
|
21
21
|
expect(result).toContainEqual([0, 210])
|
|
@@ -25,49 +25,49 @@ describe('deepCalculateFramesFromRange', () => {
|
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it('calculates frames for range with multiple step levels - [0, 1500]', () => {
|
|
28
|
-
const range
|
|
28
|
+
const range = asXL1BlockRange([0, 1500])
|
|
29
29
|
const result = deepCalculateFramesFromRange(range)
|
|
30
30
|
expect(result).toMatchSnapshot(result)
|
|
31
31
|
expect(result.length).toEqual(19)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
it('calculates frames for range with multiple step levels - [0, 3000]', () => {
|
|
35
|
-
const range
|
|
35
|
+
const range = asXL1BlockRange([0, 3000])
|
|
36
36
|
const result = deepCalculateFramesFromRange(range)
|
|
37
37
|
expect(result).toMatchSnapshot(result)
|
|
38
38
|
expect(result.length).toEqual(31)
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
it('calculates frames for range with multiple step levels = [45, 1599]', () => {
|
|
42
|
-
const range
|
|
42
|
+
const range = asXL1BlockRange([45, 1599])
|
|
43
43
|
const result = deepCalculateFramesFromRange(range)
|
|
44
44
|
expect(result).toMatchSnapshot(result)
|
|
45
45
|
expect(result.length).toEqual(43)
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
it('calculates frames for range with multiple step levels = [45, 3333]', () => {
|
|
49
|
-
const range
|
|
49
|
+
const range = asXL1BlockRange([45, 3333])
|
|
50
50
|
const result = deepCalculateFramesFromRange(range)
|
|
51
51
|
expect(result).toMatchSnapshot(result)
|
|
52
52
|
expect(result.length).toEqual(85)
|
|
53
53
|
})
|
|
54
54
|
|
|
55
55
|
it('calculates frames for range with multiple step levels - [23_145, 230_102_040]', () => {
|
|
56
|
-
const range
|
|
56
|
+
const range = asXL1BlockRange([23_145, 230_102_040])
|
|
57
57
|
const result = deepCalculateFramesFromRange(range)
|
|
58
58
|
expect(result).toMatchSnapshot(result)
|
|
59
59
|
expect(result.length).toEqual(742)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
it('calculates frames for range with multiple step levels - [23_145, 34_548_554_394]', () => {
|
|
63
|
-
const range
|
|
63
|
+
const range = asXL1BlockRange([23_145, 34_548_554_394])
|
|
64
64
|
const result = deepCalculateFramesFromRange(range)
|
|
65
65
|
expect(result).toMatchSnapshot(result)
|
|
66
66
|
expect(result.length).toEqual(1468)
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
it('calculates frames for range with multiple step levels - [23_145, 4_598_734_539_845]', () => {
|
|
70
|
-
const range
|
|
70
|
+
const range = asXL1BlockRange([23_145, 4_598_734_539_845])
|
|
71
71
|
const result = deepCalculateFramesFromRange(range)
|
|
72
72
|
expect(result).toMatchSnapshot(result)
|
|
73
73
|
expect(result.length).toEqual(2445)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Hash } from '@xylabs/hex'
|
|
2
|
+
import type { XL1BlockNumber } from '@xyo-network/xl1-protocol'
|
|
2
3
|
|
|
3
4
|
import type { ChainContextRead } from '../../model/index.ts'
|
|
4
5
|
import { blockFromBlockNumber } from './blockFromBlockNumber.ts'
|
|
5
6
|
|
|
6
|
-
export async function hashFromBlockNumber(context: ChainContextRead, blockNumber:
|
|
7
|
+
export async function hashFromBlockNumber(context: ChainContextRead, blockNumber: XL1BlockNumber): Promise<Hash> {
|
|
7
8
|
return (await blockFromBlockNumber(context, blockNumber))._hash
|
|
8
9
|
}
|
|
@@ -4,6 +4,7 @@ import { type Address } from '@xylabs/hex'
|
|
|
4
4
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
5
|
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
6
6
|
import { isAnyPayload } from '@xyo-network/payload-model'
|
|
7
|
+
import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
7
8
|
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
8
9
|
|
|
9
10
|
import { netTransfersForPayloads } from '../../../payload/index.ts'
|
|
@@ -11,14 +12,14 @@ import {
|
|
|
11
12
|
parseSignedBigInt, type SignedBigInt, toSignedBigInt,
|
|
12
13
|
} from '../../../SignedBigInt.ts'
|
|
13
14
|
import { hydrateBlock } from '../../hydrate/index.ts'
|
|
14
|
-
import {
|
|
15
|
+
import { deepCalculateFramesFromRange } from '../frames/index.ts'
|
|
15
16
|
import { hashFromBlockNumber } from '../hashFromBlockNumber.ts'
|
|
16
17
|
import type { TransfersStepSummaryContext } from '../model.ts'
|
|
17
18
|
import { type TransfersStepSummary, TransfersStepSummarySchema } from '../payloads/index.ts'
|
|
18
19
|
|
|
19
20
|
export async function transfersStepSummaryFromRange(
|
|
20
21
|
context: TransfersStepSummaryContext,
|
|
21
|
-
range:
|
|
22
|
+
range: XL1BlockRange,
|
|
22
23
|
): Promise<WithStorageMeta<TransfersStepSummary>> {
|
|
23
24
|
// console.log(`transfersStepSummaryFromRange: head=${head}, range=${range[0]}-${range[1]}`)
|
|
24
25
|
const frameHeadHash = await hashFromBlockNumber(context, range[1])
|
|
@@ -2,7 +2,7 @@ import type { Address } from '@xylabs/hex'
|
|
|
2
2
|
import { asAddress } from '@xylabs/hex'
|
|
3
3
|
import { spanRootAsync } from '@xylabs/telemetry'
|
|
4
4
|
import { isDefined } from '@xylabs/typeof'
|
|
5
|
-
import { asBlockBoundWitnessWithStorageMeta } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { asBlockBoundWitnessWithStorageMeta, asXL1BlockNumber } from '@xyo-network/xl1-protocol'
|
|
6
6
|
|
|
7
7
|
import { parseSignedBigInt } from '../../../SignedBigInt.ts'
|
|
8
8
|
import { deepCalculateFramesFromRange } from '../frames/index.ts'
|
|
@@ -17,8 +17,8 @@ export async function transfersSummary(
|
|
|
17
17
|
const head = await context.head()
|
|
18
18
|
const headResult = await context.store.chainMap.get(head)
|
|
19
19
|
const headBoundWitness = asBlockBoundWitnessWithStorageMeta(headResult, () => `Head block not found for hash: ${context.head}`, { required: true })
|
|
20
|
-
const rangeStart = isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0
|
|
21
|
-
const ranges = deepCalculateFramesFromRange([rangeStart, headBoundWitness.block])
|
|
20
|
+
const rangeStart = asXL1BlockNumber(isDefined(context.windowSize) ? Math.max(headBoundWitness.block - context.windowSize + 1, 0) : 0)
|
|
21
|
+
const ranges = deepCalculateFramesFromRange([rangeStart, asXL1BlockNumber(headBoundWitness.block)])
|
|
22
22
|
const summaries = await Promise.all(ranges.map(range => transfersStepSummaryFromRange(context, range)))
|
|
23
23
|
const transfers: Partial<Record<Address, Partial<Record<Address, bigint>>>> = {}
|
|
24
24
|
for (let summary of summaries) {
|
package/src/constants.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -2,12 +2,13 @@ export * from './block/index.ts'
|
|
|
2
2
|
export * from './ChainServiceCollection.ts'
|
|
3
3
|
export * from './ChainServiceCollectionV2.ts'
|
|
4
4
|
export * from './config/index.ts'
|
|
5
|
+
export * from './constants.ts'
|
|
5
6
|
export * from './instances/index.ts'
|
|
6
7
|
export * from './map/index.ts'
|
|
7
8
|
export * from './model/index.ts'
|
|
9
|
+
export * from './multipliers.ts'
|
|
8
10
|
export * from './payload/index.ts'
|
|
9
11
|
export * from './SignedBigInt.ts'
|
|
10
|
-
export * from './steps/index.ts'
|
|
11
12
|
export * from './time/index.ts'
|
|
12
13
|
export * from './transaction/index.ts'
|
|
13
14
|
export * from './validation/index.ts'
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ChainIdentity } from '../ChainIdentity.ts'
|
|
2
2
|
import type { ChainStakeRead, ChainStakeWrite } from '../ChainStake/index.ts'
|
|
3
|
+
import type { StakeEventsRead } from '../StakeEvents.ts'
|
|
3
4
|
|
|
4
5
|
export interface ChainStakeContextWrite extends ChainIdentity {
|
|
5
6
|
stake: ChainStakeWrite
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export interface ChainStakeContextRead extends ChainIdentity {
|
|
10
|
+
events: StakeEventsRead
|
|
9
11
|
stake: ChainStakeRead
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { XL1BlockRangeKey, XL1RangeMultipliers } from '@xyo-network/xl1-protocol'
|
|
2
|
+
import {
|
|
3
|
+
asAttoXL1,
|
|
4
|
+
asXL1,
|
|
5
|
+
XL1Amount,
|
|
6
|
+
} from '@xyo-network/xl1-protocol'
|
|
7
|
+
|
|
8
|
+
import { XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK } from './constants.ts'
|
|
9
|
+
|
|
10
|
+
export const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS = asAttoXL1(1_105_508_843_867_301_885_042_548n)
|
|
11
|
+
export const XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS = XL1Amount.fromXL1(asXL1(100_000_000n)).atto
|
|
12
|
+
|
|
13
|
+
export const RewardMultipliers: XL1RangeMultipliers = {
|
|
14
|
+
[`0|${XL1_NETWORK_STAKING_GENESIS_PERIOD_END_XL1_BLOCK}` as XL1BlockRangeKey]:
|
|
15
|
+
[XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_BONUS_REWARDS, XL1_NETWORK_STAKING_GENESIS_PERIOD_TOTAL_REWARDS],
|
|
16
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { XL1BlockNumber } from '@xyo-network/xl1-protocol'
|
|
2
3
|
import { asTimePayload, TimeSchema } from '@xyo-network/xl1-protocol'
|
|
3
4
|
|
|
4
5
|
import { hashFromBlockNumber, hydrateBlock } from '../../block/index.ts'
|
|
5
6
|
import type { ChainContextRead } from '../../model/index.ts'
|
|
6
7
|
|
|
7
|
-
export async function xl1BlockNumberToEthBlockNumber(context: ChainContextRead, xl1BlockNumber:
|
|
8
|
+
export async function xl1BlockNumberToEthBlockNumber(context: ChainContextRead, xl1BlockNumber: XL1BlockNumber): Promise<number> {
|
|
8
9
|
const blockHash = await hashFromBlockNumber(context, xl1BlockNumber)
|
|
9
10
|
const hydratedBlock = await hydrateBlock(context.store, blockHash)
|
|
10
11
|
const timePayload = asTimePayload(hydratedBlock[1].find(p => p.schema === TimeSchema), { required: true })
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BlockNumberRange.d.ts","sourceRoot":"","sources":["../../../../../src/block/primitives/frames/BlockNumberRange.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/steps/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Address } from '@xylabs/hex';
|
|
2
|
-
import type { AddressStakingV2 } from '@xyo-network/typechain';
|
|
3
|
-
export declare function addressStakeWeight(stakeContract: AddressStakingV2, staked: Address, by: Address, startEthBlock: number, endEthBlock: number): Promise<bigint>;
|
|
4
|
-
//# sourceMappingURL=addressStakeWeight.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addressStakeWeight.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/addressStakeWeight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,gBAAgB,EAC/B,MAAM,EAAE,OAAO,EACf,EAAE,EAAE,OAAO,EACX,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAwCjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"claimedRewards.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/claimedRewards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,UAE/C"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './addressStakeWeight.ts';
|
|
2
|
-
export * from './claimedRewards.ts';
|
|
3
|
-
export * from './stakersAsOfBlock.ts';
|
|
4
|
-
export * from './startingStakes.ts';
|
|
5
|
-
export * from './totalStakeWeight.ts';
|
|
6
|
-
export * from './unclaimedRewards.ts';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Address } from '@xylabs/hex';
|
|
2
|
-
import type { AddressStakingV2 } from '@xyo-network/typechain';
|
|
3
|
-
export declare function stakersAsOfBlock(stakeContract: AddressStakingV2, staked: Address, ethBlock: number): Promise<Address[]>;
|
|
4
|
-
//# sourceMappingURL=stakersAsOfBlock.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stakersAsOfBlock.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/stakersAsOfBlock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAM9D,wBAAsB,gBAAgB,CAAC,aAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAU7H"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Address } from '@xylabs/hex';
|
|
2
|
-
import type { AddressStakingV2 } from '@xyo-network/typechain';
|
|
3
|
-
export declare function startingStakes(stakeContract: AddressStakingV2, staked: Address, ethBlock: number): Promise<Record<Address, bigint>>;
|
|
4
|
-
//# sourceMappingURL=startingStakes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"startingStakes.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/startingStakes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,wBAAsB,cAAc,CAAC,aAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAyBzI"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Address } from '@xylabs/hex';
|
|
2
|
-
import type { AddressStakingV2 } from '@xyo-network/typechain';
|
|
3
|
-
export declare function totalStakeWeight(stakeContract: AddressStakingV2, staked: Address, startEthBlock: number, endEthBlock: number): Promise<bigint>;
|
|
4
|
-
//# sourceMappingURL=totalStakeWeight.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"totalStakeWeight.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/totalStakeWeight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAK9D,wBAAsB,gBAAgB,CAAC,aAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BpJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unclaimedRewards.d.ts","sourceRoot":"","sources":["../../../../src/steps/primitives/unclaimedRewards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAEtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type BlockNumberRange = [number, number]
|
package/src/steps/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './primitives/index.ts'
|