@berachain/berajs 0.2.6 → 0.2.7
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/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/actions/exports.cjs +1 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.d.cts +10 -5
- package/dist/actions/exports.d.ts +10 -5
- package/dist/actions/exports.mjs +1 -1
- package/dist/actions/exports.mjs.map +1 -1
- package/dist/chunk-2YBHAMDV.cjs.map +1 -1
- package/dist/{chunk-HWOGQSNL.cjs → chunk-4436B2EF.cjs} +3 -3
- package/dist/chunk-4436B2EF.cjs.map +1 -0
- package/dist/chunk-57RINXU6.cjs.map +1 -1
- package/dist/chunk-74WA35RI.cjs.map +1 -1
- package/dist/{chunk-IBJOI5SN.mjs → chunk-7VQA45R5.mjs} +3 -3
- package/dist/{chunk-IBJOI5SN.mjs.map → chunk-7VQA45R5.mjs.map} +1 -1
- package/dist/chunk-CF3LFNXG.cjs.map +1 -1
- package/dist/chunk-DDEQFR3M.cjs.map +1 -1
- package/dist/chunk-DK42F2ZM.cjs.map +1 -1
- package/dist/chunk-I7M43BB4.cjs.map +1 -1
- package/dist/chunk-LNVR4BW6.cjs.map +1 -1
- package/dist/chunk-NMH7LHPW.cjs.map +1 -1
- package/dist/chunk-NVHV2LDK.cjs.map +1 -1
- package/dist/chunk-OIYXOKTT.cjs.map +1 -1
- package/dist/chunk-OUD27MU7.cjs.map +1 -1
- package/dist/chunk-RWOICHRW.cjs.map +1 -1
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -1
- package/dist/chunk-XNJLSA6P.cjs.map +1 -1
- package/dist/contexts/exports.cjs.map +1 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-CmiPJmsr.d.ts → getValidatorQueuedOperatorAddress-B5T8_BMr.d.ts} +3 -3
- package/dist/{getValidatorQueuedOperatorAddress-BdDYHycN.d.cts → getValidatorQueuedOperatorAddress-BtCefJyH.d.cts} +3 -3
- package/dist/{global.d-CwT1Phzf.d.cts → global.d-6aSWIkV_.d.cts} +1 -1
- package/dist/{global.d-3GQMgC9k.d.ts → global.d-SU9Epq0M.d.ts} +1 -1
- package/dist/hooks/exports.cjs +2 -2
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.d.cts +4 -4
- package/dist/hooks/exports.d.ts +4 -4
- package/dist/hooks/exports.mjs +1 -1
- package/dist/types/exports.cjs.map +1 -1
- package/dist/types/exports.d.cts +1 -1
- package/dist/types/exports.d.ts +1 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/package.json +38 -39
- package/src/abi/exports.ts +0 -0
- package/src/abi/pyth/pyth.ts +0 -0
- package/src/actions/dex/getPoolHistoricalData.ts +0 -0
- package/src/actions/exports.ts +1 -0
- package/src/actions/governance/getAllProposals.ts +0 -0
- package/src/actions/governance/getProposalDetails.ts +0 -0
- package/src/actions/honey/getHoneyFees.ts +0 -0
- package/src/actions/honey/getHoneyPreview.ts +0 -0
- package/src/actions/pol/getBGTGlobalInfo.ts +0 -0
- package/src/actions/pol/getBgtTokenTotalBoosts.ts +0 -0
- package/src/actions/pol/getBgtTokenTotalSupply.ts +0 -0
- package/src/actions/pol/getGlobalCuttingBoard.ts +0 -0
- package/src/actions/pol/getMarkets.ts +0 -0
- package/src/actions/pol/getRewardVaults.ts +0 -0
- package/src/actions/pol/getUserVaultsBalance.ts +0 -0
- package/src/actions/pol/getUserVaultsReward.ts +0 -0
- package/src/actions/pol/getVaultsSupply.ts +0 -0
- package/src/actions/tokens/getAllowances.ts +0 -0
- package/src/actions/tokens/getTokenInformation.ts +0 -0
- package/src/actions/tokens/getTokens.ts +0 -0
- package/src/actions/tokens/getWalletBalances.ts +0 -0
- package/src/actions/validators/getUserActiveValidators.ts +2 -2
- package/src/actions/validators/utils/__tests__/validatorUtils.integration.test.ts +20 -4
- package/src/actions/validators/utils/aggregateValidatorIncentives.ts +64 -0
- package/src/actions/validators/utils/aggregateValidatorIncentives.unit.test.ts +270 -0
- package/src/contexts/exports.ts +0 -0
- package/src/enum/exports.ts +0 -0
- package/src/enum/polling.ts +0 -0
- package/src/enum/txnEnum.ts +0 -0
- package/src/errors/getErrorMessage.ts +0 -0
- package/src/hooks/dex/useCreatePool.ts +0 -0
- package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +0 -0
- package/src/hooks/dex/usePoolHistoricalData.ts +0 -0
- package/src/hooks/exports.ts +0 -0
- package/src/hooks/perps/usePythUpdateFee.ts +0 -0
- package/src/hooks/pol/useBgtUnstakedBalance.ts +0 -0
- package/src/hooks/pol/usePollGlobalData.ts +0 -0
- package/src/hooks/pol/usePollMarkets.ts +0 -0
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +0 -0
- package/src/hooks/pol/useRewardVault.ts +0 -0
- package/src/hooks/pol/useRewardVaults.ts +0 -0
- package/src/hooks/pol/useUserVaultInfo.ts +0 -0
- package/src/hooks/pol/useUserVaults.ts +0 -0
- package/src/hooks/pol/useVaultValidators.ts +0 -0
- package/src/hooks/tokens/usePollAllowances.ts +0 -0
- package/src/hooks/tokens/usePollBalance.ts +0 -0
- package/src/hooks/tokens/usePollWalletBalances.ts +0 -0
- package/src/hooks/tokens/useTokenInformation.ts +0 -0
- package/src/hooks/tokens/useTokens.ts +0 -0
- package/src/hooks/useContractWrite/index.ts +0 -0
- package/src/hooks/useContractWrite/stateReducer.ts +0 -0
- package/src/hooks/useContractWrite/types.ts +0 -0
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +0 -0
- package/src/hooks/usePrevious.ts +0 -0
- package/src/hooks/validators/useApiValidator.ts +0 -0
- package/src/hooks/validators/useUserActiveValidators.ts +0 -0
- package/src/hooks/validators/useValidatorEstimatedBgtPerYear.ts +0 -0
- package/src/types/dex.d.ts +0 -0
- package/src/types/exports.ts +0 -0
- package/src/types/global.d.ts +0 -0
- package/src/types/pol.d.ts +1 -1
- package/src/types/staking.d.ts +0 -0
- package/src/utils/exports.ts +0 -0
- package/src/utils/filter.ts +0 -0
- package/src/utils/formatInputTokenValue.ts +0 -0
- package/src/utils/formatNumber.ts +0 -0
- package/src/utils/truncateHash.ts +0 -0
- package/dist/chunk-HWOGQSNL.cjs.map +0 -1
|
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
|
|
|
3
3
|
import { parseBaseArgs } from "../../../../utils/parseBaseArgs";
|
|
4
4
|
import { getTokenCurrentPrices } from "../../../prices/getTokenCurrentPrices";
|
|
5
5
|
import { getAllValidators } from "../../getAllValidators";
|
|
6
|
+
import { getApiValidator } from "../../getApiValidator";
|
|
6
7
|
import {
|
|
7
8
|
getValidatorBoostApy,
|
|
8
9
|
getValidatorReturnPerBgt,
|
|
@@ -22,13 +23,28 @@ describe("getValidatorBoostApy", async () => {
|
|
|
22
23
|
throw new Error("BGT price not found");
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const val = valRes?.validators.validators?.[0];
|
|
27
|
+
if (!val) {
|
|
28
|
+
throw new Error("No validators found");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { validator } = await getApiValidator({
|
|
32
|
+
id: val.id,
|
|
33
|
+
chainId: config.chainId,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (!validator) {
|
|
37
|
+
throw new Error("Validator not found");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
it("should return the correct boost apy", () => {
|
|
28
41
|
const returnPerBgt = getValidatorReturnPerBgt(validator);
|
|
29
42
|
expect(returnPerBgt).toBeDefined();
|
|
30
43
|
expect(returnPerBgt).not.toBeNaN();
|
|
31
|
-
const boostApy = getValidatorBoostApy({
|
|
44
|
+
const boostApy = getValidatorBoostApy({
|
|
45
|
+
validator: validator,
|
|
46
|
+
bgtPrice,
|
|
47
|
+
});
|
|
32
48
|
expect(boostApy).toBeDefined();
|
|
33
49
|
expect(boostApy).not.toBeNaN();
|
|
34
50
|
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApiMinimalVaultIncentiveFragment,
|
|
3
|
+
ApiValidatorRewardAllocationWeightFragment,
|
|
4
|
+
} from "@berachain/graphql/pol/api";
|
|
5
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
6
|
+
|
|
7
|
+
export function aggregateValidatorIncentives({
|
|
8
|
+
rewardAllocationWeights,
|
|
9
|
+
activeOnly = true,
|
|
10
|
+
}: {
|
|
11
|
+
rewardAllocationWeights: ApiValidatorRewardAllocationWeightFragment[];
|
|
12
|
+
activeOnly?: boolean;
|
|
13
|
+
}): ApiMinimalVaultIncentiveFragment[] {
|
|
14
|
+
const map = rewardAllocationWeights
|
|
15
|
+
.filter((x) => x?.receivingVault)
|
|
16
|
+
|
|
17
|
+
.reduce((acc, rv) => {
|
|
18
|
+
for (const incentive of rv.receivingVault?.activeIncentives ?? []) {
|
|
19
|
+
if (activeOnly && incentive.remainingAmount === "0") {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const incentiveRate = new BigNumber(incentive.incentiveRate).times(
|
|
23
|
+
rv.percentage,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const incentiveRateUsd = new BigNumber(
|
|
27
|
+
incentive.incentiveRateUsd,
|
|
28
|
+
).times(rv.percentage);
|
|
29
|
+
|
|
30
|
+
const token = incentive.token.address.toLowerCase();
|
|
31
|
+
|
|
32
|
+
const existing = acc.get(token);
|
|
33
|
+
if (existing) {
|
|
34
|
+
acc.set(token, {
|
|
35
|
+
...existing,
|
|
36
|
+
incentiveRate: new BigNumber(existing.incentiveRate)
|
|
37
|
+
.plus(incentiveRate)
|
|
38
|
+
.toString(),
|
|
39
|
+
incentiveRateUsd: new BigNumber(existing.incentiveRateUsd)
|
|
40
|
+
.plus(incentiveRateUsd)
|
|
41
|
+
.toString(),
|
|
42
|
+
remainingAmount: new BigNumber(existing.remainingAmount)
|
|
43
|
+
.plus(incentive.remainingAmount)
|
|
44
|
+
.toString(),
|
|
45
|
+
remainingAmountUsd: new BigNumber(existing.remainingAmountUsd)
|
|
46
|
+
.plus(incentive.remainingAmountUsd)
|
|
47
|
+
.toString(),
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
acc.set(token, {
|
|
51
|
+
...incentive,
|
|
52
|
+
tokenAddress: incentive.token.address,
|
|
53
|
+
token: incentive.token,
|
|
54
|
+
incentiveRate: incentiveRate.toString(),
|
|
55
|
+
incentiveRateUsd: incentiveRateUsd.toString(),
|
|
56
|
+
remainingAmount: incentive.remainingAmount,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return acc;
|
|
61
|
+
}, new Map<string, ApiMinimalVaultIncentiveFragment>());
|
|
62
|
+
|
|
63
|
+
return Array.from(map.values());
|
|
64
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import BigNumber from "@berachain/utils/pkg/bignumber.js";
|
|
2
|
+
|
|
3
|
+
import type { MinimalERC20 } from "../../../types/dex";
|
|
4
|
+
import { getHoneyToken, wBeraToken } from "../../../utils/tokens";
|
|
5
|
+
import { aggregateValidatorIncentives } from "./aggregateValidatorIncentives";
|
|
6
|
+
|
|
7
|
+
function createIncentive({
|
|
8
|
+
token,
|
|
9
|
+
remainingAmount,
|
|
10
|
+
price,
|
|
11
|
+
}: {
|
|
12
|
+
token: Omit<MinimalERC20, "chainId">;
|
|
13
|
+
remainingAmount: string;
|
|
14
|
+
price: number;
|
|
15
|
+
}) {
|
|
16
|
+
return {
|
|
17
|
+
token: token,
|
|
18
|
+
remainingAmount: remainingAmount,
|
|
19
|
+
remainingAmountUsd: new BigNumber(remainingAmount).times(price).toString(),
|
|
20
|
+
incentiveRate: new BigNumber(1).times(price).toString(),
|
|
21
|
+
incentiveRateUsd: price.toString(),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("aggregateValidatorIncentives", () => {
|
|
26
|
+
const price1 = 1;
|
|
27
|
+
const price2 = 2;
|
|
28
|
+
const incentive1 = createIncentive({
|
|
29
|
+
token: wBeraToken,
|
|
30
|
+
remainingAmount: "1",
|
|
31
|
+
price: price1,
|
|
32
|
+
});
|
|
33
|
+
const incentive2 = createIncentive({
|
|
34
|
+
token: getHoneyToken({}),
|
|
35
|
+
remainingAmount: "1",
|
|
36
|
+
price: price2,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns empty array for empty rewardAllocationWeights", () => {
|
|
40
|
+
const incentives = aggregateValidatorIncentives({
|
|
41
|
+
rewardAllocationWeights: [],
|
|
42
|
+
});
|
|
43
|
+
expect(incentives).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("aggregates same token across two vaults with equal weights", () => {
|
|
47
|
+
const incentives = aggregateValidatorIncentives({
|
|
48
|
+
rewardAllocationWeights: [
|
|
49
|
+
{
|
|
50
|
+
percentage: 0.5,
|
|
51
|
+
receivingVault: {
|
|
52
|
+
activeIncentives: [incentive1],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
percentage: 0.5,
|
|
57
|
+
receivingVault: {
|
|
58
|
+
activeIncentives: [incentive1],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(incentives).toHaveLength(1);
|
|
65
|
+
expect(incentives[0]?.token.address).toBe(wBeraToken.address);
|
|
66
|
+
expect(incentives[0]?.remainingAmount).toBe("2");
|
|
67
|
+
expect(incentives[0]?.remainingAmountUsd).toBe("2");
|
|
68
|
+
expect(incentives[0]?.incentiveRate).toBe("1");
|
|
69
|
+
// 1*0.5 + 1*0.5 = 1
|
|
70
|
+
expect(incentives[0]?.incentiveRateUsd).toBe("1");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("aggregates two different tokens across vaults", () => {
|
|
74
|
+
const incentives = aggregateValidatorIncentives({
|
|
75
|
+
rewardAllocationWeights: [
|
|
76
|
+
{
|
|
77
|
+
percentage: 0.5,
|
|
78
|
+
receivingVault: {
|
|
79
|
+
activeIncentives: [incentive1],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
percentage: 0.5,
|
|
84
|
+
receivingVault: {
|
|
85
|
+
activeIncentives: [incentive2],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(incentives).toHaveLength(2);
|
|
92
|
+
|
|
93
|
+
const wBeraResult = incentives.find(
|
|
94
|
+
(i) => i.token.address === wBeraToken.address,
|
|
95
|
+
);
|
|
96
|
+
const honeyResult = incentives.find(
|
|
97
|
+
(i) => i.token.address === getHoneyToken({}).address,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(wBeraResult).toBeDefined();
|
|
101
|
+
expect(wBeraResult?.remainingAmount).toBe("1");
|
|
102
|
+
expect(wBeraResult?.incentiveRate).toBe("0.5");
|
|
103
|
+
|
|
104
|
+
expect(honeyResult).toBeDefined();
|
|
105
|
+
expect(honeyResult?.remainingAmount).toBe("1");
|
|
106
|
+
expect(honeyResult?.incentiveRate).toBe("1");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("aggregates same token + different token in one vault", () => {
|
|
110
|
+
const incentives = aggregateValidatorIncentives({
|
|
111
|
+
rewardAllocationWeights: [
|
|
112
|
+
{
|
|
113
|
+
percentage: 0.5,
|
|
114
|
+
receivingVault: {
|
|
115
|
+
activeIncentives: [incentive1],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
percentage: 0.5,
|
|
120
|
+
receivingVault: {
|
|
121
|
+
activeIncentives: [incentive1, incentive2],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(incentives).toHaveLength(2);
|
|
128
|
+
|
|
129
|
+
const wBeraResult = incentives.find(
|
|
130
|
+
(i) => i.token.address === wBeraToken.address,
|
|
131
|
+
);
|
|
132
|
+
const honeyResult = incentives.find(
|
|
133
|
+
(i) => i.token.address === getHoneyToken({}).address,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(wBeraResult).toBeDefined();
|
|
137
|
+
expect(wBeraResult?.remainingAmount).toBe("2");
|
|
138
|
+
expect(wBeraResult?.remainingAmountUsd).toBe("2");
|
|
139
|
+
expect(wBeraResult?.incentiveRate).toBe("1");
|
|
140
|
+
// 1*0.5 + 1*0.5 = 1
|
|
141
|
+
expect(wBeraResult?.incentiveRateUsd).toBe("1");
|
|
142
|
+
|
|
143
|
+
expect(honeyResult).toBeDefined();
|
|
144
|
+
expect(honeyResult?.remainingAmount).toBe("1");
|
|
145
|
+
expect(honeyResult?.remainingAmountUsd).toBe("2");
|
|
146
|
+
// 2*0.5 = 1
|
|
147
|
+
expect(honeyResult?.incentiveRate).toBe("1");
|
|
148
|
+
expect(honeyResult?.incentiveRateUsd).toBe("1");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("filters out incentives with zero remainingAmount", () => {
|
|
152
|
+
const zeroIncentive = createIncentive({
|
|
153
|
+
token: wBeraToken,
|
|
154
|
+
remainingAmount: "0",
|
|
155
|
+
price: price1,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const incentives = aggregateValidatorIncentives({
|
|
159
|
+
rewardAllocationWeights: [
|
|
160
|
+
{
|
|
161
|
+
percentage: 1,
|
|
162
|
+
receivingVault: {
|
|
163
|
+
activeIncentives: [zeroIncentive],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
expect(incentives).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("skips allocations with null receivingVault", () => {
|
|
173
|
+
const incentives = aggregateValidatorIncentives({
|
|
174
|
+
rewardAllocationWeights: [
|
|
175
|
+
{
|
|
176
|
+
percentage: 0.5,
|
|
177
|
+
receivingVault: null,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
percentage: 0.5,
|
|
181
|
+
receivingVault: {
|
|
182
|
+
activeIncentives: [incentive1],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
expect(incentives).toHaveLength(1);
|
|
189
|
+
expect(incentives[0]?.token.address).toBe(wBeraToken.address);
|
|
190
|
+
expect(incentives[0]?.remainingAmount).toBe("1");
|
|
191
|
+
expect(incentives[0]?.incentiveRate).toBe("0.5");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("applies percentage weights correctly to incentiveRate", () => {
|
|
195
|
+
const incentives = aggregateValidatorIncentives({
|
|
196
|
+
rewardAllocationWeights: [
|
|
197
|
+
{
|
|
198
|
+
percentage: 0.3,
|
|
199
|
+
receivingVault: {
|
|
200
|
+
activeIncentives: [incentive1],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
percentage: 0.7,
|
|
205
|
+
receivingVault: {
|
|
206
|
+
activeIncentives: [incentive1],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expect(incentives).toHaveLength(1);
|
|
213
|
+
expect(incentives[0]?.remainingAmount).toBe("2");
|
|
214
|
+
// incentiveRate: 1*0.3 + 1*0.7 = 1
|
|
215
|
+
expect(incentives[0]?.incentiveRate).toBe("1");
|
|
216
|
+
// incentiveRateUsd: 1*0.3 + 1*0.7 = 1
|
|
217
|
+
expect(incentives[0]?.incentiveRateUsd).toBe("1");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("handles single allocation with 100% weight", () => {
|
|
221
|
+
const incentives = aggregateValidatorIncentives({
|
|
222
|
+
rewardAllocationWeights: [
|
|
223
|
+
{
|
|
224
|
+
percentage: 1,
|
|
225
|
+
receivingVault: {
|
|
226
|
+
activeIncentives: [incentive1],
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
expect(incentives).toHaveLength(1);
|
|
233
|
+
expect(incentives[0]?.token.address).toBe(wBeraToken.address);
|
|
234
|
+
expect(incentives[0]?.remainingAmount).toBe("1");
|
|
235
|
+
expect(incentives[0]?.incentiveRate).toBe("1");
|
|
236
|
+
expect(incentives[0]?.incentiveRateUsd).toBe("1");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("handles vault with empty activeIncentives", () => {
|
|
240
|
+
const incentives = aggregateValidatorIncentives({
|
|
241
|
+
rewardAllocationWeights: [
|
|
242
|
+
{
|
|
243
|
+
percentage: 1,
|
|
244
|
+
receivingVault: {
|
|
245
|
+
activeIncentives: [],
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
expect(incentives).toEqual([]);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("keeps token metadata as nested object", () => {
|
|
255
|
+
const incentives = aggregateValidatorIncentives({
|
|
256
|
+
rewardAllocationWeights: [
|
|
257
|
+
{
|
|
258
|
+
percentage: 1,
|
|
259
|
+
receivingVault: {
|
|
260
|
+
activeIncentives: [incentive1],
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
expect(incentives[0]?.token.symbol).toBe(wBeraToken.symbol);
|
|
267
|
+
expect(incentives[0]?.token.name).toBe(wBeraToken.name);
|
|
268
|
+
expect(incentives[0]?.token.decimals).toBe(wBeraToken.decimals);
|
|
269
|
+
});
|
|
270
|
+
});
|
package/src/contexts/exports.ts
CHANGED
|
File without changes
|
package/src/enum/exports.ts
CHANGED
|
File without changes
|
package/src/enum/polling.ts
CHANGED
|
File without changes
|
package/src/enum/txnEnum.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/hooks/exports.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/hooks/usePrevious.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/types/dex.d.ts
CHANGED
|
File without changes
|
package/src/types/exports.ts
CHANGED
|
File without changes
|
package/src/types/global.d.ts
CHANGED
|
File without changes
|
package/src/types/pol.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type IncentiveReward = {
|
|
|
18
18
|
available_at: number;
|
|
19
19
|
};
|
|
20
20
|
export interface IncentiveRewardChunksWithValidatorData {
|
|
21
|
-
validator: ApiValidatorFragment | undefined;
|
|
21
|
+
validator: ApiValidatorInListFragment | ApiValidatorFragment | undefined;
|
|
22
22
|
maxTimestamp: number | undefined;
|
|
23
23
|
minTimestamp: number | undefined;
|
|
24
24
|
totalValue: number;
|
package/src/types/staking.d.ts
CHANGED
|
File without changes
|
package/src/utils/exports.ts
CHANGED
|
File without changes
|
package/src/utils/filter.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/snowbera/Documents/workspace/monobera/packages/berajs/dist/chunk-HWOGQSNL.cjs","../src/actions/bend/getConvertToAssets.ts","../src/actions/clients/BeraApolloClient.ts","../src/actions/governance/parseProposalBody.ts","../src/actions/governance/getProposalFromTx.ts"],"names":["getConvertToAssets","sharesAmount","vaultAddress","publicClient","convertToAssets","metaMorphoAbi","formatEther","BeraApolloClient","ApolloClient","options","queryName","getQueryName","endpoint","tags","executeQuery","res","BeraTracing"],"mappings":"AAAA,q+CAAyC,wDAAyD,wDAAsE,wDAAuJ,wDAAgE,wDAA+E,4BCAjZ,8EAEX,MAQlD,SAAsBA,EAAAA,CAAmB,CACvC,YAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CACF,CAAA,CAAyE,CACvE,IAAMC,CAAAA,CAAkB,MAAMD,CAAAA,CAAa,YAAA,CAAa,CACtD,OAAA,CAASD,CAAAA,CACT,GAAA,CAAKG,+BAAAA,CACL,YAAA,CAAc,iBAAA,CACd,IAAA,CAAM,CAACJ,CAAY,CACrB,CAAC,CAAA,CACD,MAAO,CAAE,GAAA,CAAKG,CAAAA,CAAiB,SAAA,CAAWE,+BAAAA,CAA2B,CAAE,CACzE,CCtBA,wCAMO,sDAEmB,IAYbC,EAAAA,CAAN,MAAA,QAA+BC,oBAAa,CAIvC,WAEV,CACEC,CAAAA,CAMA,CACA,KAAA,CAAMA,CAAO,CAAA,CACb,IAAA,CAAK,GAAA,CAAMA,CAAAA,CAAQ,GACrB,CAEA,MAAM,KAAA,CAKJA,CAAAA,CAIC,CACD,IAAMC,CAAAA,CAAYC,EAAAA,CAAaF,CAAAA,CAAQ,KAAK,CAAA,CACtCG,CAAAA,CAAW,CACf,GAAA,CAAK,IAAA,CAAK,GAAA,CACV,IAAA,CAAM,SACR,CAAA,CAEMC,CAAAA,CAAO,CACX,gBAAA,CAAkB,OAAA,CAClB,sBAAA,CAAwBD,CAAAA,CAAS,GAAA,CACjC,uBAAA,CAAyBA,CAAAA,CAAS,IAAA,CAClC,4BAAA,CAA8BF,CAChC,CAAA,CAEA,GAAI,CACF,IAAMI,CAAAA,CAAe,CAAA,CAAA,EACnB,KAAA,CAAM,KAAA,CACJL,CACF,CAAA,CAEIM,CAAAA,CAAM,MAAMC,mBAAAA,CAAY,SAAA,CAC5B,CACE,IAAA,CAAM,CAAA,QAAA,EAAWN,CAAS,CAAA,CAAA;ACNQ;ACyBxC","file":"/Users/snowbera/Documents/workspace/monobera/packages/berajs/dist/chunk-HWOGQSNL.cjs","sourcesContent":[null,"import { type Address, formatEther, type PublicClient } from \"viem\";\n\nimport { metaMorphoV11Abi as metaMorphoAbi } from \"@berachain/abis/bend-metamorpho/metaMorphoV11\";\n\nexport interface GetConvertToAssetsProps {\n sharesAmount: bigint;\n vaultAddress: Address;\n publicClient: PublicClient;\n}\n\nexport async function getConvertToAssets({\n sharesAmount,\n vaultAddress,\n publicClient,\n}: GetConvertToAssetsProps): Promise<{ raw: bigint; formatted: string }> {\n const convertToAssets = await publicClient.readContract({\n address: vaultAddress,\n abi: metaMorphoAbi,\n functionName: \"convertToAssets\",\n args: [sharesAmount],\n });\n return { raw: convertToAssets, formatted: formatEther(convertToAssets) };\n}\n","import {\n ApolloClient,\n type DocumentNode,\n type ErrorLike,\n type OperationVariables,\n ServerError,\n} from \"@apollo/client\";\n\nimport { appConfig } from \"@berachain/config/internal\";\n\nimport { BeraError } from \"../../errors/BeraError\";\nimport { BeraTracing } from \"../../errors/BeraTracing\";\nimport { RequestError } from \"../../errors/RequestError\";\n\n/**\n * This is a wrapper around the ApolloClient that throws a BeraError if the query returns an error or no data.\n *\n * It's mostly a typescript helper that keeps data always defined since we use errorPolicy: \"none\" by default.\n * Such setting will throw an error if the query returns an error, rather than returning an object with undefined data and an error property.\n */\nexport class BeraApolloClient extends ApolloClient {\n /**\n * The URL of the endpoint. Used for error reporting only.\n */\n protected url: string;\n\n constructor(\n options: ApolloClient.Options & {\n /**\n * The URL of the endpoint. Used for error reporting only.\n */\n url: string;\n },\n ) {\n super(options);\n this.url = options.url;\n }\n\n async query<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n // We handle errors in our custom logic so we don't need to pass errorPolicy here\n options: Omit<ApolloClient.QueryOptions<TData, TVariables>, \"errorPolicy\">,\n ): Promise<{\n // Only data is returned and we're sure it's not undefined due to errorPolicy\n data: TData;\n }> {\n const queryName = getQueryName(options.query);\n const endpoint = {\n url: this.url,\n type: \"graphql\",\n } as const;\n\n const tags = {\n \"operation.type\": \"query\",\n \"operation.source.url\": endpoint.url,\n \"operation.source.type\": endpoint.type,\n \"operation.source.queryName\": queryName,\n };\n\n try {\n const executeQuery = () =>\n super.query<TData, TVariables>(\n options as ApolloClient.QueryOptions<TData, TVariables>,\n );\n\n const res = await BeraTracing.startSpan(\n {\n name: `GraphQL ${queryName}`,\n op: \"BeraApolloClient.query\",\n attributes: tags,\n },\n executeQuery,\n );\n\n if (res.error || res.data === undefined) {\n throw new BeraError({\n level: \"fatal\",\n tags,\n message:\n \"Bera Apollo Client: No data returned from query, but error should be thrown since errorPolicy is none\",\n });\n }\n\n return { data: res.data } as const;\n } catch (error) {\n !appConfig.env.isProduction &&\n console.error(\"BeraApolloClient error\", error);\n\n if (ServerError.is(error)) {\n throw new RequestError({\n // reason: error,\n response: error.response,\n cause: error,\n statusCode: error.statusCode,\n endpoint,\n tags,\n });\n }\n if (error instanceof TypeError) {\n throw new RequestError({\n level: \"fatal\",\n reason: \"TypeError\",\n response: error,\n cause: error,\n endpoint,\n tags,\n });\n }\n throw new RequestError({\n response: error as ErrorLike,\n tags,\n cause: error,\n endpoint,\n });\n }\n }\n}\n\nfunction getQueryName(queryDefinition: DocumentNode) {\n const likelyNode = queryDefinition.definitions.find(\n (def) => def.kind === (\"OperationDefinition\" as const),\n );\n\n return likelyNode?.name?.value;\n}\n","import graymatter from \"gray-matter\";\n\nimport type { ProposalSelectionFragment } from \"@berachain/graphql/governance\";\n\nconst parseLegacyBody = (\n s: string,\n): { type: string | null; title: string; content: string } => {\n const pattern = /#(?:([\\w-]+)# )?(.+)\\n([\\s\\S]*)/;\n const match = s.match(pattern);\n\n if (match) {\n const type = match[1] || null;\n const title = match[2];\n const content = match[3].replace(\"\\n\", \"<br />\");\n return {\n type,\n title,\n content,\n };\n }\n\n throw new Error(\"Invalid proposal body\");\n};\n\nexport const parseProposalBody = (\n proposal?: Pick<ProposalSelectionFragment, \"description\">,\n): graymatter.GrayMatterFile<string> & {\n isFrontMatter: boolean;\n} => {\n if (!proposal) {\n return {\n isFrontMatter: false,\n data: { title: \"Loading...\" },\n content: \"\",\n matter: \"\",\n language: \"\",\n orig: \"\",\n stringify: () => \"\",\n };\n }\n\n const body = proposal?.description ?? \"\";\n\n if (graymatter.test(body)) {\n return { ...graymatter(body), isFrontMatter: true };\n }\n\n try {\n const legacyBody = parseLegacyBody(body);\n\n return {\n isFrontMatter: false,\n data: { title: legacyBody.title },\n content: legacyBody.content,\n matter: \"\",\n language: \"\",\n orig: body,\n stringify: () => body,\n };\n } catch {\n return {\n isFrontMatter: false,\n data: {\n title: proposal?.description?.split(\"\\n\")[0].slice(0, 100),\n },\n content: body,\n matter: \"\",\n language: \"\",\n orig: body,\n stringify: () => body,\n };\n }\n};\n","import {\n type Address,\n type PublicClient,\n parseEventLogs,\n type TransactionReceipt,\n} from \"viem\";\n\nimport { berachainGovernanceAbi as governanceAbi } from \"@berachain/abis/gov/berachainGovernance\";\n\nimport {\n type ExecutableCallSubsetFragment,\n ProposalStatus,\n type ProposalWithVotesFragment,\n} from \"@berachain/graphql/governance\";\n\nimport { assertPublicClient } from \"../../errors/assert\";\nimport { parseProposalBody } from \"./parseProposalBody\";\n\nexport async function getProposalFromTx(\n args: {\n publicClient: PublicClient | undefined;\n } & (\n | {\n tx: TransactionReceipt;\n }\n | {\n txHash: Address;\n }\n ),\n): Promise<ProposalWithVotesFragment | null> {\n assertPublicClient(args.publicClient);\n\n let tx: TransactionReceipt;\n\n if (\"tx\" in args) {\n tx = args.tx;\n } else {\n tx = await args.publicClient.getTransactionReceipt({ hash: args.txHash });\n }\n\n const creationEvent = tx?.logs\n ? parseEventLogs({\n abi: governanceAbi,\n logs: tx.logs,\n eventName: \"ProposalCreated\",\n })?.at(0)\n : undefined;\n\n if (!tx || !creationEvent) {\n return null;\n }\n\n const block = await args.publicClient.getBlock({\n blockNumber: tx.blockNumber,\n });\n const fm = parseProposalBody({\n description: creationEvent?.args.description as string,\n });\n\n return {\n id: String(creationEvent.args.proposalId),\n proposalId: String(creationEvent?.args.proposalId),\n createdAt: block.timestamp.toString(),\n title: fm.data.title,\n createdAtBlock: block.timestamp.toString(),\n voteStartAt: String(creationEvent?.args.voteStart),\n voteEndAt: String(creationEvent?.args.voteEnd),\n proposer: creationEvent?.args.proposer,\n description: fm.content,\n unverifiedForumLink: fm.data.forumLink,\n pollResult: {\n for: \"0\",\n forVotersCount: 0,\n forPercentage: \"0\",\n against: \"0\",\n againstVotersCount: 0,\n againstPercentage: \"0\",\n abstain: \"0\",\n abstainVotersCount: 0,\n abstainPercentage: \"0\",\n total: \"0\",\n totalVotersCount: 0,\n totalTowardsQuorum: \"0\",\n },\n status: ProposalStatus.Pending,\n quorum: null,\n topics: fm.data.topics,\n votes: [],\n executableCalls: creationEvent?.args.targets.map(\n (target, index) =>\n ({\n __typename: \"ExecutableCall\",\n id: `${tx.transactionHash}-${index}`,\n target: target as Address,\n value: String(creationEvent?.args.values[index]),\n calldata: creationEvent?.args.calldatas[index],\n }) satisfies ExecutableCallSubsetFragment,\n ),\n timelock: undefined,\n } satisfies ProposalWithVotesFragment;\n}\n"]}
|