Skip to content

Commit 49c3591

Browse files
fix: calculations (#42)
* fix: calculations * ci: update artifacts [skip ci] * fix: updated packages * fix: removed ssv-keys * ci: update artifacts [skip ci] --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dc9eedf commit 49c3591

File tree

10 files changed

+316
-616
lines changed

10 files changed

+316
-616
lines changed

dist/api/based-apps-api/index.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { APIs } from '..';
22
import { StrategyWeight } from '../../types/weights';
33
import { Address } from 'viem';
44
export declare const getValidatorsBalance: (apis: APIs, args: Parameters<APIs["bam"]["getValidatorsByAccount"]>[0]) => Promise<{
5-
account: string;
6-
validators: never[];
7-
balance: string;
8-
} | {
95
account: string;
106
validators: `0x${string}`[];
117
balance: bigint;
@@ -44,10 +40,6 @@ export declare const getBasedAppsAPI: (apis: APIs) => {
4440
getValidatorsBalance: (args: import('../../graphql/bam/graphql').Exact<{
4541
account: import('../../graphql/bam/graphql').Scalars["String"]["input"];
4642
}>) => Promise<{
47-
account: string;
48-
validators: never[];
49-
balance: string;
50-
} | {
5143
account: string;
5244
validators: `0x${string}`[];
5345
balance: bigint;

dist/libs/api/index.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ export declare const createBasedAppsAPI: (apis: APIs) => {
3131
getValidatorsBalance: (args: import('../../graphql/bam/graphql').Exact<{
3232
account: import('../../graphql/bam/graphql').Scalars["String"]["input"];
3333
}>) => Promise<{
34-
account: string;
35-
validators: never[];
36-
balance: string;
37-
} | {
3834
account: string;
3935
validators: `0x${string}`[];
4036
balance: bigint;

dist/main.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31343,7 +31343,7 @@ const getValidatorsBalance = async (apis, args) => {
3134331343
return {
3134431344
account: args.account,
3134531345
validators: [],
31346-
balance: "0"
31346+
balance: 0n
3134731347
};
3134831348
const chunks = chunk(validators, 500);
3134931349
const results = await Promise.all(
@@ -31467,12 +31467,13 @@ const getDelegatedBalances = async (apis, args) => {
3146731467
const bAppTotalDelegatedBalances = await Promise.all(
3146831468
bAppDelegators.strategies.map(async (strategy) => {
3146931469
const delegation = (await Promise.all(
31470-
strategy.strategy.owner.delegators.map(
31471-
(d) => getValidatorsBalance(apis, {
31470+
strategy.strategy.owner.delegators.map(async (d) => {
31471+
const data = await getValidatorsBalance(apis, {
3147231472
account: d.delegator.id
31473-
})
31474-
)
31475-
)).reduce((acc, balance) => acc + BigInt(balance.balance), 0n);
31473+
});
31474+
return data.balance * BigInt(d.percentage) / 10000n;
31475+
})
31476+
)).reduce((acc, balance) => acc + balance, 0n);
3147631477
return {
3147731478
strategyId: strategy.strategy.id,
3147831479
delegation

dist/utils/keyshares.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { Operator } from '../types/operator';
2-
import { KeySharesItem } from 'ssv-keys';
2+
export interface KeySharesItem {
3+
data: {
4+
publicKey: string;
5+
operators: Array<{
6+
id: number;
7+
operatorKey: string;
8+
}>;
9+
};
10+
payload: {
11+
operatorIds: number[];
12+
};
13+
error: Error | null;
14+
}
315
export declare const isKeySharesItem: (item: unknown) => item is KeySharesItem;
416
export declare enum KeysharesValidationErrors {
517
OperatorDoesNotExist = 0,

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ssv-labs/bapps-sdk",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"author": "SSV.Labs",
55
"description": "ssv labs based apps sdk",
66
"keywords": [
@@ -70,9 +70,9 @@
7070
"@rollup/rollup-darwin-x64": "4.45.0",
7171
"@types/eslint-plugin-prettier": "3.1.3",
7272
"@types/lodash-es": "4.17.12",
73-
"@types/node": "24.0.13",
74-
"@typescript-eslint/eslint-plugin": "8.36.0",
75-
"@typescript-eslint/parser": "8.36.0",
73+
"@types/node": "24.0.14",
74+
"@typescript-eslint/eslint-plugin": "8.37.0",
75+
"@typescript-eslint/parser": "8.37.0",
7676
"@vitest/coverage-v8": "3.2.4",
7777
"@vitest/ui": "3.2.4",
7878
"commitizen": "4.3.1",
@@ -115,7 +115,6 @@
115115
"dotenv": "17.2.0",
116116
"graphql-request": "7.2.0",
117117
"lodash-es": "4.17.21",
118-
"ssv-keys": "1.2.1",
119118
"viem": "2.31.7",
120119
"zod": "4.0.5"
121120
},

pnpm-lock.yaml

Lines changed: 269 additions & 583 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ensureNoKeysharesErrors,
1515
ensureValidatorsUniqueness,
1616
isKeySharesItem,
17+
KeySharesItem,
1718
KeysharesValidationError,
1819
validateConsistentOperatorIds,
1920
validateConsistentOperatorPublicKeys,
@@ -22,7 +23,6 @@ import { sortNumbers } from '@/utils/number'
2223
import { decodeOperatorPublicKey, getOperatorIds } from '@/utils/operator'
2324
import { tryCatch } from '@/utils/try-catch'
2425
import urlJoin from '@/utils/url-join'
25-
import type { KeySharesItem } from 'ssv-keys'
2626
import { encodeAbiParameters, parseEther } from 'viem'
2727
import { describe, expect, test, vi } from 'vitest'
2828

src/api/based-apps-api/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const getValidatorsBalance = async (
1414
return {
1515
account: args.account,
1616
validators: [],
17-
balance: '0',
17+
balance: 0n,
1818
}
1919

2020
const chunks = chunk(validators, 500)
@@ -195,13 +195,14 @@ export const getDelegatedBalances = async (
195195
bAppDelegators.strategies.map(async (strategy) => {
196196
const delegation = (
197197
await Promise.all(
198-
strategy.strategy.owner.delegators.map((d) =>
199-
getValidatorsBalance(apis, {
198+
strategy.strategy.owner.delegators.map(async (d) => {
199+
const data = await getValidatorsBalance(apis, {
200200
account: d.delegator.id,
201-
}),
202-
),
201+
})
202+
return (data.balance * BigInt(d.percentage)) / 10000n
203+
}),
203204
)
204-
).reduce((acc, balance) => acc + BigInt(balance.balance), 0n)
205+
).reduce((acc, balance) => acc + balance, 0n)
205206

206207
return {
207208
strategyId: strategy.strategy.id,

src/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ interface ImportMetaEnv {
77

88
interface ImportMeta {
99
readonly env: ImportMetaEnv
10-
}
10+
}

src/utils/keyshares.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
import type { Operator } from '@/types/operator'
22
import { sortNumbers } from '@/utils/number'
33
import { getOperatorIds } from '@/utils/operator'
4-
import type { KeySharesItem } from 'ssv-keys'
4+
5+
export interface KeySharesItem {
6+
data: {
7+
publicKey: string
8+
operators: Array<{
9+
id: number
10+
operatorKey: string
11+
}>
12+
}
13+
payload: {
14+
operatorIds: number[]
15+
}
16+
error: Error | null
17+
}
518

619
export const isKeySharesItem = (item: unknown): item is KeySharesItem => {
720
return (

0 commit comments

Comments
 (0)