@xyo-network/xl1-providers 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.
- package/package.json +34 -16
- package/src/NodeXyoViewer.ts +0 -36
- package/src/SimpleNetworkStakeViewer.ts +0 -69
- package/src/SimpleStepRewards/SimpleStepRewardsByPositionViewer.ts +0 -118
- package/src/SimpleStepRewards/SimpleStepRewardsByStakerViewer.ts +0 -117
- package/src/SimpleStepRewards/SimpleStepRewardsByStepViewer.ts +0 -121
- package/src/SimpleStepRewards/SimpleStepRewardsTotalViewer.ts +0 -61
- package/src/SimpleStepRewards/SimpleStepRewardsViewer.ts +0 -83
- package/src/SimpleStepRewards/index.ts +0 -5
- package/src/SimpleStepRewards/primitives/index.ts +0 -3
- package/src/SimpleStepRewards/primitives/networkStakeStepRewardEarned.ts +0 -39
- package/src/SimpleStepRewards/primitives/networkStakeStepRewardEarnedForPosition.ts +0 -49
- package/src/SimpleStepRewards/primitives/networkStakeStepRewardEarnedForStaker.ts +0 -45
- package/src/SimpleStepViewer.ts +0 -104
- package/src/SimpleXyoConnectionRunner.ts +0 -54
- package/src/SimpleXyoConnectionViewer.ts +0 -47
- package/src/SimpleXyoViewer.ts +0 -473
- package/src/buildLocalGateway.ts +0 -114
- package/src/buildProviderLocator.ts +0 -150
- package/src/buildProviderLocatorV2.ts +0 -113
- package/src/buildSimpleXyoSignerV2.ts +0 -13
- package/src/index.ts +0 -11
- package/src/registerHelpers.ts +0 -80
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/xl1-providers",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.13",
|
|
4
4
|
"description": "XYO Layer One API",
|
|
5
5
|
"homepage": "https://xylabs.com",
|
|
6
6
|
"bugs": {
|
|
@@ -23,17 +23,14 @@
|
|
|
23
23
|
".": {
|
|
24
24
|
"browser": {
|
|
25
25
|
"types": "./dist/browser/index.d.ts",
|
|
26
|
-
"source": "./src/index.ts",
|
|
27
26
|
"default": "./dist/browser/index.mjs"
|
|
28
27
|
},
|
|
29
28
|
"node": {
|
|
30
29
|
"types": "./dist/node/index.d.ts",
|
|
31
|
-
"source": "./src/index.ts",
|
|
32
30
|
"default": "./dist/node/index.mjs"
|
|
33
31
|
},
|
|
34
32
|
"neutral": {
|
|
35
33
|
"types": "./dist/neutral/index.d.ts",
|
|
36
|
-
"source": "./src/index.ts",
|
|
37
34
|
"default": "./dist/neutral/index.mjs"
|
|
38
35
|
}
|
|
39
36
|
},
|
|
@@ -44,10 +41,10 @@
|
|
|
44
41
|
"types": "./dist/neutral/index.d.ts",
|
|
45
42
|
"files": [
|
|
46
43
|
"dist",
|
|
47
|
-
"src",
|
|
48
44
|
"!**/*.bench.*",
|
|
49
45
|
"!**/*.spec.*",
|
|
50
|
-
"!**/*.test.*"
|
|
46
|
+
"!**/*.test.*",
|
|
47
|
+
"README.md"
|
|
51
48
|
],
|
|
52
49
|
"scripts": {
|
|
53
50
|
"build-tests": "tsc --noEmit --lib dom,esnext",
|
|
@@ -58,22 +55,41 @@
|
|
|
58
55
|
},
|
|
59
56
|
"dependencies": {
|
|
60
57
|
"@opentelemetry/api": "^1.9.1",
|
|
61
|
-
"@xyo-network/xl1-protocol-lib": "~1.26.
|
|
62
|
-
"@xyo-network/xl1-protocol-sdk": "~1.26.
|
|
63
|
-
"@xyo-network/xl1-rpc": "~1.26.
|
|
58
|
+
"@xyo-network/xl1-protocol-lib": "~1.26.13",
|
|
59
|
+
"@xyo-network/xl1-protocol-sdk": "~1.26.13",
|
|
60
|
+
"@xyo-network/xl1-rpc": "~1.26.13"
|
|
64
61
|
},
|
|
65
62
|
"devDependencies": {
|
|
63
|
+
"@firebase/app": "0.x",
|
|
64
|
+
"@firebase/app-compat": "0.x",
|
|
65
|
+
"@firebase/app-types": "0.x",
|
|
66
|
+
"@firebase/util": "1.x",
|
|
67
|
+
"@metamask/providers": "^22",
|
|
66
68
|
"@types/node": "^25.5.0",
|
|
67
|
-
"@xylabs/
|
|
68
|
-
"@xylabs/
|
|
69
|
-
"@xylabs/ts-scripts-
|
|
70
|
-
"@xylabs/
|
|
71
|
-
"@
|
|
72
|
-
"
|
|
73
|
-
"
|
|
69
|
+
"@xylabs/geo": "^5",
|
|
70
|
+
"@xylabs/sdk-js": "~5.0.91",
|
|
71
|
+
"@xylabs/ts-scripts-common": "~7.6.13",
|
|
72
|
+
"@xylabs/ts-scripts-yarn3": "~7.6.13",
|
|
73
|
+
"@xylabs/tsconfig": "~7.6.13",
|
|
74
|
+
"@xyo-network/sdk-js": "^5.3.22",
|
|
75
|
+
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
76
|
+
"ajv": "^8",
|
|
77
|
+
"axios": "^1.14.0",
|
|
78
|
+
"cosmiconfig": ">=9",
|
|
79
|
+
"dotenv": "~17.4.0",
|
|
80
|
+
"esbuild": ">=0.18",
|
|
81
|
+
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0",
|
|
74
82
|
"ethers": "^6.16.0",
|
|
83
|
+
"firebase": "^12",
|
|
84
|
+
"lru-cache": "^11",
|
|
85
|
+
"mapbox-gl": "^3",
|
|
86
|
+
"mongodb": "^6 || ^7",
|
|
87
|
+
"rollup": "^3.29.4 || ^4",
|
|
88
|
+
"tslib": "^2.8.1",
|
|
75
89
|
"typescript": "~5.9.3",
|
|
90
|
+
"vite": "^8.0.3",
|
|
76
91
|
"vitest": "~4.1.2",
|
|
92
|
+
"webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0",
|
|
77
93
|
"zod": "~4.3.6"
|
|
78
94
|
},
|
|
79
95
|
"peerDependencies": {
|
|
@@ -81,6 +97,8 @@
|
|
|
81
97
|
"@xyo-network/sdk-js": "^5",
|
|
82
98
|
"axios": "^1",
|
|
83
99
|
"ethers": "^6",
|
|
100
|
+
"mongodb": "^6 || ^7",
|
|
101
|
+
"typescript": ">=4.9.5",
|
|
84
102
|
"zod": "^4"
|
|
85
103
|
},
|
|
86
104
|
"packageManager": "yarn@4.6.0",
|
package/src/NodeXyoViewer.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
ArchivistInstance, ModuleIdentifier, NodeInstance,
|
|
4
|
-
} from '@xyo-network/sdk-js'
|
|
5
|
-
import { asAttachableArchivistInstance } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { XyoViewer } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import { creatableProvider } from '@xyo-network/xl1-protocol-sdk'
|
|
8
|
-
|
|
9
|
-
import { SimpleXyoViewer, SimpleXyoViewerParams } from './SimpleXyoViewer.ts'
|
|
10
|
-
|
|
11
|
-
/** @deprecated use SimpleXyoViewer instead */
|
|
12
|
-
export interface NodeXyoViewerParams extends SimpleXyoViewerParams {
|
|
13
|
-
node: NodeInstance
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@creatableProvider()
|
|
17
|
-
/** @deprecated use SimpleXyoViewer instead */
|
|
18
|
-
|
|
19
|
-
/** XYO viewer implementation for Node.js environments. */
|
|
20
|
-
export class NodeXyoViewer extends SimpleXyoViewer<NodeXyoViewerParams> implements XyoViewer {
|
|
21
|
-
protected static readonly finalizedArchivistPath: ModuleIdentifier = 'XYOChain:Chain:Finalized'
|
|
22
|
-
|
|
23
|
-
protected get node() {
|
|
24
|
-
return this.params.node
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected static getArchivist = async (node: NodeInstance, identifier: ModuleIdentifier) => {
|
|
28
|
-
const archivist = await node.resolve(identifier)
|
|
29
|
-
return assertEx(asAttachableArchivistInstance(archivist), () => `Could not resolve ${identifier} to an archivist instance`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected static async getFinalizedArchivistFromNode(node: NodeInstance): Promise<ArchivistInstance> {
|
|
33
|
-
const resolved = await this.getArchivist(node, this.finalizedArchivistPath)
|
|
34
|
-
return assertEx(resolved, () => `Could not resolve finalized archivist at ${this.finalizedArchivistPath}`)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
FinalizationViewer,
|
|
4
|
-
FinalizationViewerMoniker,
|
|
5
|
-
NetworkStakeStepRewardsViewer,
|
|
6
|
-
NetworkStakeStepRewardsViewerMoniker,
|
|
7
|
-
NetworkStakeViewer, NetworkStakeViewerMoniker,
|
|
8
|
-
StakeTotalsViewer,
|
|
9
|
-
StakeTotalsViewerMoniker,
|
|
10
|
-
StakeViewer,
|
|
11
|
-
StakeViewerMoniker,
|
|
12
|
-
XL1RangeMultipliers,
|
|
13
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
14
|
-
import {
|
|
15
|
-
AbstractCreatableProvider,
|
|
16
|
-
creatableProvider, CreatableProviderParams,
|
|
17
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
18
|
-
|
|
19
|
-
/** Configuration params for SimpleNetworkStakeViewer. */
|
|
20
|
-
export interface SimpleNetworkStakeViewerParams extends CreatableProviderParams {
|
|
21
|
-
rewardMultipliers?: XL1RangeMultipliers
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Provider that views network-wide staking information including step rewards and active stake totals. */
|
|
25
|
-
@creatableProvider()
|
|
26
|
-
export class SimpleNetworkStakeViewer extends AbstractCreatableProvider<SimpleNetworkStakeViewerParams> implements NetworkStakeViewer {
|
|
27
|
-
static readonly defaultMoniker = NetworkStakeViewerMoniker
|
|
28
|
-
static readonly dependencies = [NetworkStakeStepRewardsViewerMoniker]
|
|
29
|
-
static readonly monikers = [NetworkStakeViewerMoniker]
|
|
30
|
-
moniker = SimpleNetworkStakeViewer.defaultMoniker
|
|
31
|
-
|
|
32
|
-
private _finalizationViewer!: FinalizationViewer
|
|
33
|
-
private _stake!: StakeViewer
|
|
34
|
-
private _stakeTotals!: StakeTotalsViewer
|
|
35
|
-
private _stepRewardsViewer?: NetworkStakeStepRewardsViewer
|
|
36
|
-
|
|
37
|
-
get stepRewards(): NetworkStakeStepRewardsViewer {
|
|
38
|
-
return assertEx(this._stepRewardsViewer, () => 'Step rewards viewer not initialized')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected get finalizationViewer() {
|
|
42
|
-
return this._finalizationViewer
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected get rewardMultipliers() {
|
|
46
|
-
return this.params.rewardMultipliers
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
protected get stake() {
|
|
50
|
-
return this._stake
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
protected get stakeTotals() {
|
|
54
|
-
return this._stakeTotals
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async active(blockNumber?: number): Promise<[bigint, number]> {
|
|
58
|
-
const resolvedBlockNumber = blockNumber ?? (await this.finalizationViewer.headNumber())
|
|
59
|
-
return [await this.stakeTotals.active(resolvedBlockNumber), resolvedBlockNumber]
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
override async createHandler() {
|
|
63
|
-
await super.createHandler()
|
|
64
|
-
this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker)
|
|
65
|
-
this._stake = await this.locator.getInstance(StakeViewerMoniker)
|
|
66
|
-
this._stakeTotals = await this.locator.getInstance(StakeTotalsViewerMoniker)
|
|
67
|
-
this._stepRewardsViewer = await this.locator.getInstance(NetworkStakeStepRewardsViewerMoniker)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { isArray } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
AttoXL1,
|
|
5
|
-
BlockViewer,
|
|
6
|
-
FinalizationViewer,
|
|
7
|
-
NetworkStakeStepRewardsByPositionViewer,
|
|
8
|
-
NetworkStakeStepRewardsByPositionViewerOptions,
|
|
9
|
-
StakeViewer,
|
|
10
|
-
XL1RangeMultipliers,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import {
|
|
13
|
-
asAttoXL1, asXL1BlockRange, BlockViewerMoniker, FinalizationViewerMoniker, NetworkStakeStepRewardsByPositionViewerMoniker,
|
|
14
|
-
StakeViewerMoniker,
|
|
15
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
16
|
-
import {
|
|
17
|
-
AbstractCreatableProvider,
|
|
18
|
-
blockRangeSteps,
|
|
19
|
-
creatableProvider,
|
|
20
|
-
CreatableProviderParams,
|
|
21
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
22
|
-
|
|
23
|
-
import { networkStakeStepRewardEarnedForPosition } from './primitives/index.ts'
|
|
24
|
-
|
|
25
|
-
/** Configuration params for SimpleStepRewardsByPositionViewer. */
|
|
26
|
-
export interface SimpleStepRewardsByPositionViewerParams extends CreatableProviderParams {
|
|
27
|
-
rewardMultipliers?: XL1RangeMultipliers
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Viewer for network stake step rewards broken down by staking position. */
|
|
31
|
-
@creatableProvider()
|
|
32
|
-
export class SimpleStepRewardsByPositionViewer extends
|
|
33
|
-
AbstractCreatableProvider<SimpleStepRewardsByPositionViewerParams> implements NetworkStakeStepRewardsByPositionViewer {
|
|
34
|
-
static readonly defaultMoniker = NetworkStakeStepRewardsByPositionViewerMoniker
|
|
35
|
-
static readonly dependencies = [BlockViewerMoniker]
|
|
36
|
-
static readonly monikers = [NetworkStakeStepRewardsByPositionViewerMoniker]
|
|
37
|
-
moniker = SimpleStepRewardsByPositionViewer.defaultMoniker
|
|
38
|
-
|
|
39
|
-
private _blockViewer!: BlockViewer
|
|
40
|
-
private _finalizationViewer!: FinalizationViewer
|
|
41
|
-
private _stakeViewer!: StakeViewer
|
|
42
|
-
|
|
43
|
-
get rewardMultipliers() {
|
|
44
|
-
return this.params.rewardMultipliers ?? {}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected get blockViewer() {
|
|
48
|
-
return this._blockViewer!
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected get finalizationViewer() {
|
|
52
|
-
return this._finalizationViewer!
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected get stakeViewer() {
|
|
56
|
-
return this._stakeViewer!
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async bonus({ range, positions }: NetworkStakeStepRewardsByPositionViewerOptions = {}): Promise<Record<number, AttoXL1>> {
|
|
60
|
-
const total = await this.total({ range, positions })
|
|
61
|
-
const earned = await this.earned({ range, positions })
|
|
62
|
-
const result: Record<number, AttoXL1> = {}
|
|
63
|
-
for (const pos of Object.keys(total).map(Number)) {
|
|
64
|
-
result[pos] = asAttoXL1(total[pos] - (earned[pos] ?? 0n))
|
|
65
|
-
}
|
|
66
|
-
return result
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
claimed(_options?: NetworkStakeStepRewardsByPositionViewerOptions | undefined): Promisable<Record<number, AttoXL1>> {
|
|
70
|
-
throw new Error('Method [claimed] not implemented.')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
override async createHandler() {
|
|
74
|
-
await super.createHandler()
|
|
75
|
-
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker)
|
|
76
|
-
this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker)
|
|
77
|
-
this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async earned({ range, positions }: NetworkStakeStepRewardsByPositionViewerOptions = {}): Promise<Record<number, AttoXL1>> {
|
|
81
|
-
return await this.calculateRewards({ range, positions })
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async total({ range, positions }: NetworkStakeStepRewardsByPositionViewerOptions = {}): Promise<Record<number, AttoXL1>> {
|
|
85
|
-
return await this.calculateRewards({ range, positions }, this.rewardMultipliers)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
unclaimed(_options: NetworkStakeStepRewardsByPositionViewerOptions = {}): Promisable<Record<number, AttoXL1>> {
|
|
89
|
-
throw new Error('Method [unclaimed] not implemented.')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
protected async calculateRewards(
|
|
93
|
-
{ range, positions }: NetworkStakeStepRewardsByPositionViewerOptions = {},
|
|
94
|
-
rewardMultipliers?: XL1RangeMultipliers,
|
|
95
|
-
): Promise<Record<number, AttoXL1>> {
|
|
96
|
-
const result: Record<number, AttoXL1> = {}
|
|
97
|
-
const steps = blockRangeSteps(asXL1BlockRange(
|
|
98
|
-
range ?? [0, (await this.finalizationViewer.head())[1]],
|
|
99
|
-
{ name: 'NodeStepRewardsByPositionViewer' },
|
|
100
|
-
), [3, 4, 5, 6, 7])
|
|
101
|
-
for (const step of steps) {
|
|
102
|
-
if (isArray(positions)) {
|
|
103
|
-
for (const positionId of positions) {
|
|
104
|
-
const position = await this.stakeViewer.stakeById(positionId)
|
|
105
|
-
result[positionId] = asAttoXL1((result[positionId] ?? 0n) + (await networkStakeStepRewardEarnedForPosition(
|
|
106
|
-
this.context,
|
|
107
|
-
this.blockViewer,
|
|
108
|
-
this.stakeViewer.stakeEvents,
|
|
109
|
-
step,
|
|
110
|
-
position,
|
|
111
|
-
rewardMultipliers,
|
|
112
|
-
))[0])
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return result
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { Address, Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { isArray } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
AttoXL1,
|
|
5
|
-
BlockViewer,
|
|
6
|
-
FinalizationViewer,
|
|
7
|
-
NetworkStakeStepRewardsByStakerViewer,
|
|
8
|
-
NetworkStakeStepRewardsByStakerViewerOptions,
|
|
9
|
-
StakeViewer,
|
|
10
|
-
XL1RangeMultipliers,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import {
|
|
13
|
-
asAttoXL1, asXL1BlockRange, BlockViewerMoniker, FinalizationViewerMoniker, NetworkStakeStepRewardsByStakerViewerMoniker,
|
|
14
|
-
StakeViewerMoniker,
|
|
15
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
16
|
-
import {
|
|
17
|
-
AbstractCreatableProvider,
|
|
18
|
-
blockRangeSteps,
|
|
19
|
-
creatableProvider,
|
|
20
|
-
CreatableProviderParams,
|
|
21
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
22
|
-
|
|
23
|
-
import { networkStakeStepRewardEarnedForStaker } from './primitives/index.ts'
|
|
24
|
-
|
|
25
|
-
/** Configuration params for SimpleStepRewardsByStakerViewer. */
|
|
26
|
-
export interface SimpleStepRewardsByStakerViewerParams extends CreatableProviderParams {
|
|
27
|
-
rewardMultipliers?: XL1RangeMultipliers
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Viewer for network stake step rewards broken down by staker address. */
|
|
31
|
-
@creatableProvider()
|
|
32
|
-
export class SimpleStepRewardsByStakerViewer extends
|
|
33
|
-
AbstractCreatableProvider<SimpleStepRewardsByStakerViewerParams> implements NetworkStakeStepRewardsByStakerViewer {
|
|
34
|
-
static readonly defaultMoniker = NetworkStakeStepRewardsByStakerViewerMoniker
|
|
35
|
-
static readonly dependencies = [BlockViewerMoniker]
|
|
36
|
-
static readonly monikers = [NetworkStakeStepRewardsByStakerViewerMoniker]
|
|
37
|
-
moniker = SimpleStepRewardsByStakerViewer.defaultMoniker
|
|
38
|
-
|
|
39
|
-
private _blockViewer!: BlockViewer
|
|
40
|
-
private _finalizationViewer!: FinalizationViewer
|
|
41
|
-
private _stakeViewer!: StakeViewer
|
|
42
|
-
|
|
43
|
-
get rewardMultipliers() {
|
|
44
|
-
return this.params.rewardMultipliers ?? {}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected get blockViewer() {
|
|
48
|
-
return this._blockViewer
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected get finalizationViewer() {
|
|
52
|
-
return this._finalizationViewer
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected get stakeViewer() {
|
|
56
|
-
return this._stakeViewer
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async bonus({ range, stakers }: NetworkStakeStepRewardsByStakerViewerOptions = {}): Promise<Record<Address, AttoXL1>> {
|
|
60
|
-
const total = await this.total({ range, stakers })
|
|
61
|
-
const earned = await this.earned({ range, stakers })
|
|
62
|
-
const result: Record<Address, AttoXL1> = {}
|
|
63
|
-
for (const staker of Object.keys(total) as Address[]) {
|
|
64
|
-
result[staker] = asAttoXL1(total[staker] - (earned[staker] ?? 0n))
|
|
65
|
-
}
|
|
66
|
-
return result
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
claimed(_options?: NetworkStakeStepRewardsByStakerViewerOptions | undefined): Promisable<Record<Address, AttoXL1>> {
|
|
70
|
-
throw new Error('Method [claimed] not implemented.')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
override async createHandler() {
|
|
74
|
-
await super.createHandler()
|
|
75
|
-
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker)
|
|
76
|
-
this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker)
|
|
77
|
-
this._stakeViewer = await this.locator.getInstance(StakeViewerMoniker)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async earned(options: NetworkStakeStepRewardsByStakerViewerOptions = {}): Promise<Record<Address, AttoXL1>> {
|
|
81
|
-
return await this.calculateRewards(options)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async total(options: NetworkStakeStepRewardsByStakerViewerOptions = {}): Promise<Record<Address, AttoXL1>> {
|
|
85
|
-
return await this.calculateRewards(options, this.rewardMultipliers)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
unclaimed(_options: NetworkStakeStepRewardsByStakerViewerOptions = {}): Promisable<Record<Address, AttoXL1>> {
|
|
89
|
-
throw new Error('Method [unclaimed] not implemented.')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
protected async calculateRewards(
|
|
93
|
-
{ range, stakers }: NetworkStakeStepRewardsByStakerViewerOptions = {},
|
|
94
|
-
rewardMultipliers?: XL1RangeMultipliers,
|
|
95
|
-
): Promise<Record<Address, AttoXL1>> {
|
|
96
|
-
const result: Record<Address, AttoXL1> = {}
|
|
97
|
-
const steps = blockRangeSteps(asXL1BlockRange(
|
|
98
|
-
range ?? [0, (await this.finalizationViewer.headNumber())],
|
|
99
|
-
{ name: 'NodeStepRewardsByStakerViewer' },
|
|
100
|
-
), [3, 4, 5, 6, 7])
|
|
101
|
-
for (const step of steps) {
|
|
102
|
-
if (isArray(stakers)) {
|
|
103
|
-
for (const staker of stakers) {
|
|
104
|
-
result[staker] = asAttoXL1((result[staker] ?? 0n) + (await networkStakeStepRewardEarnedForStaker(
|
|
105
|
-
this.context,
|
|
106
|
-
this.blockViewer,
|
|
107
|
-
this.stakeViewer,
|
|
108
|
-
step,
|
|
109
|
-
staker,
|
|
110
|
-
rewardMultipliers,
|
|
111
|
-
))[0])
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return result
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
AttoXL1,
|
|
4
|
-
BlockViewer,
|
|
5
|
-
FinalizationViewer,
|
|
6
|
-
NetworkStakeStepRewardsByStepViewer,
|
|
7
|
-
NetworkStakeStepRewardsByStepViewerOptions,
|
|
8
|
-
StakeViewer,
|
|
9
|
-
StepIdentityString,
|
|
10
|
-
XL1RangeMultipliers,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
12
|
-
import {
|
|
13
|
-
asAttoXL1, asXL1BlockRange, BlockViewerMoniker, FinalizationViewerMoniker, NetworkStakeStepRewardsByStepViewerMoniker,
|
|
14
|
-
StakeViewerMoniker,
|
|
15
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
16
|
-
import type { CreatableProviderParams } from '@xyo-network/xl1-protocol-sdk'
|
|
17
|
-
import {
|
|
18
|
-
AbstractCreatableProvider,
|
|
19
|
-
blockRangeSteps,
|
|
20
|
-
creatableProvider, toStepIdentityString,
|
|
21
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
22
|
-
|
|
23
|
-
import { networkStakeStepRewardEarned } from './primitives/index.ts'
|
|
24
|
-
|
|
25
|
-
/** Configuration params for SimpleStepRewardsByStepViewer. */
|
|
26
|
-
export interface SimpleStepRewardsByStepViewerParams extends CreatableProviderParams {
|
|
27
|
-
rewardMultipliers?: XL1RangeMultipliers
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Viewer for network stake step rewards broken down by step identity. */
|
|
31
|
-
@creatableProvider()
|
|
32
|
-
export class SimpleStepRewardsByStepViewer extends
|
|
33
|
-
AbstractCreatableProvider<SimpleStepRewardsByStepViewerParams> implements NetworkStakeStepRewardsByStepViewer {
|
|
34
|
-
static readonly defaultMoniker = NetworkStakeStepRewardsByStepViewerMoniker
|
|
35
|
-
static readonly dependencies = [BlockViewerMoniker]
|
|
36
|
-
static readonly monikers = [NetworkStakeStepRewardsByStepViewerMoniker]
|
|
37
|
-
moniker = SimpleStepRewardsByStepViewer.defaultMoniker
|
|
38
|
-
|
|
39
|
-
private _blockViewer!: BlockViewer
|
|
40
|
-
private _finalizationViewer!: FinalizationViewer
|
|
41
|
-
private _stakeViewer!: StakeViewer
|
|
42
|
-
|
|
43
|
-
get rewardMultipliers() {
|
|
44
|
-
return this.params.rewardMultipliers ?? {}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected get blockViewer() {
|
|
48
|
-
return this._blockViewer
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected get finalizationViewer() {
|
|
52
|
-
return this._finalizationViewer
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected get stakeViewer() {
|
|
56
|
-
return this._stakeViewer
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async bonus({ range, steps }: NetworkStakeStepRewardsByStepViewerOptions = {}): Promise<Record<StepIdentityString, AttoXL1>> {
|
|
60
|
-
const total = await this.total({ range, steps })
|
|
61
|
-
const earned = await this.earned({ range, steps })
|
|
62
|
-
const result: Record<StepIdentityString, AttoXL1> = {}
|
|
63
|
-
for (const stepString of Object.keys(total) as StepIdentityString[]) {
|
|
64
|
-
result[stepString] = asAttoXL1(total[stepString] - (earned[stepString] ?? 0n))
|
|
65
|
-
}
|
|
66
|
-
return result
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
claimed(_options?: NetworkStakeStepRewardsByStepViewerOptions | undefined): Promisable<Record<StepIdentityString, AttoXL1>> {
|
|
70
|
-
throw new Error('Method [claimed] not implemented.')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
override async createHandler() {
|
|
74
|
-
await super.createHandler()
|
|
75
|
-
this._blockViewer = await this.locator.getInstance(BlockViewerMoniker)
|
|
76
|
-
this._finalizationViewer = await this.locator.getInstance(FinalizationViewerMoniker)
|
|
77
|
-
this._stakeViewer = await this.locator.getInstance<StakeViewer>(StakeViewerMoniker)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async earned({ range, steps }: NetworkStakeStepRewardsByStepViewerOptions = {}): Promise<Record<StepIdentityString, AttoXL1>> {
|
|
81
|
-
const result: Record<StepIdentityString, AttoXL1> = {}
|
|
82
|
-
const resolvedSteps = steps ?? blockRangeSteps(asXL1BlockRange(
|
|
83
|
-
range ?? [0, await this.finalizationViewer.headNumber()],
|
|
84
|
-
{ name: 'NodeStepRewardsByStepViewer' },
|
|
85
|
-
), [3, 4, 5, 6, 7])
|
|
86
|
-
for (const step of resolvedSteps) {
|
|
87
|
-
const stepIdentityString = toStepIdentityString(step)
|
|
88
|
-
result[stepIdentityString] = asAttoXL1((result[stepIdentityString] ?? 0n) + (await networkStakeStepRewardEarned(
|
|
89
|
-
this.context,
|
|
90
|
-
this.blockViewer,
|
|
91
|
-
this.stakeViewer,
|
|
92
|
-
step,
|
|
93
|
-
))[0])
|
|
94
|
-
}
|
|
95
|
-
return result
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async total({ range, steps }: NetworkStakeStepRewardsByStepViewerOptions = {}): Promise<Record<StepIdentityString, AttoXL1>> {
|
|
99
|
-
const result: Record<StepIdentityString, AttoXL1> = {}
|
|
100
|
-
const resolvedSteps = steps ?? blockRangeSteps(asXL1BlockRange(
|
|
101
|
-
range ?? [0, (await this.finalizationViewer.head())[1]],
|
|
102
|
-
{ name: 'NodeStepRewardsByStepViewer' },
|
|
103
|
-
), [3, 4, 5, 6, 7])
|
|
104
|
-
for (const step of resolvedSteps) {
|
|
105
|
-
const stepIdentityString = toStepIdentityString(step)
|
|
106
|
-
result[stepIdentityString] = asAttoXL1((result[stepIdentityString] ?? 0n)
|
|
107
|
-
+ (await networkStakeStepRewardEarned(
|
|
108
|
-
this.context,
|
|
109
|
-
this.blockViewer,
|
|
110
|
-
this.stakeViewer,
|
|
111
|
-
step,
|
|
112
|
-
this.rewardMultipliers,
|
|
113
|
-
))[0])
|
|
114
|
-
}
|
|
115
|
-
return result
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
unclaimed(_options: NetworkStakeStepRewardsByStepViewerOptions = {}): Promisable<Record<StepIdentityString, AttoXL1>> {
|
|
119
|
-
throw new Error('Method [unclaimed] ot implemented.')
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
AttoXL1,
|
|
4
|
-
NetworkStakeStepRewardsRangeOptions,
|
|
5
|
-
NetworkStakeStepRewardsTotalViewer,
|
|
6
|
-
XL1RangeMultipliers,
|
|
7
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
8
|
-
import { asAttoXL1, NetworkStakeStepRewardsTotalViewerMoniker } from '@xyo-network/xl1-protocol-lib'
|
|
9
|
-
import {
|
|
10
|
-
AbstractCreatableProvider,
|
|
11
|
-
creatableProvider,
|
|
12
|
-
CreatableProviderParams,
|
|
13
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
14
|
-
|
|
15
|
-
/** Configuration params for SimpleStepRewardsTotalViewer. */
|
|
16
|
-
export interface SimpleStepRewardsTotalViewerParams extends CreatableProviderParams {
|
|
17
|
-
rewardMultipliers?: XL1RangeMultipliers
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Viewer for aggregated total network stake step rewards across all positions. */
|
|
21
|
-
@creatableProvider()
|
|
22
|
-
export class SimpleStepRewardsTotalViewer extends
|
|
23
|
-
AbstractCreatableProvider<SimpleStepRewardsTotalViewerParams> implements NetworkStakeStepRewardsTotalViewer {
|
|
24
|
-
static readonly defaultMoniker = NetworkStakeStepRewardsTotalViewerMoniker
|
|
25
|
-
static readonly dependencies = []
|
|
26
|
-
static readonly monikers = [NetworkStakeStepRewardsTotalViewerMoniker]
|
|
27
|
-
moniker = SimpleStepRewardsTotalViewer.defaultMoniker
|
|
28
|
-
|
|
29
|
-
get rewardMultipliers() {
|
|
30
|
-
return this.params.rewardMultipliers ?? {}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async bonus({ range }: NetworkStakeStepRewardsRangeOptions = {}): Promise<AttoXL1> {
|
|
34
|
-
const total = await this.total({ range })
|
|
35
|
-
const earned = await this.earned({ range })
|
|
36
|
-
return asAttoXL1(total - earned)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
claimed(_options?: NetworkStakeStepRewardsRangeOptions | undefined): Promisable<AttoXL1> {
|
|
40
|
-
throw new Error('Method [claimed] not implemented.')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async earned(options: NetworkStakeStepRewardsRangeOptions = {}): Promise<AttoXL1> {
|
|
44
|
-
return await this.calculateRewards(options)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async total(options: NetworkStakeStepRewardsRangeOptions = {}): Promise<AttoXL1> {
|
|
48
|
-
return await this.calculateRewards(options, this.rewardMultipliers)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
unclaimed(_options: NetworkStakeStepRewardsRangeOptions = {}): Promisable<AttoXL1> {
|
|
52
|
-
throw new Error('Method [unclaimed] not implemented.')
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected calculateRewards(
|
|
56
|
-
_options: NetworkStakeStepRewardsRangeOptions = {},
|
|
57
|
-
_rewardMultipliers?: XL1RangeMultipliers,
|
|
58
|
-
): Promise<AttoXL1> {
|
|
59
|
-
throw new Error('Method [calculateRewards] not implemented.')
|
|
60
|
-
}
|
|
61
|
-
}
|