@gearbox-protocol/sdk 3.0.0-prevfour.4 → 3.0.0-prevfour.6

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/lib/index.d.ts CHANGED
@@ -7,8 +7,6 @@ export * from "./core/creditManager";
7
7
  export * from "./core/creditSession";
8
8
  export * from "./core/endpoint";
9
9
  export * from "./core/eventOrTx";
10
- export * from "./core/gauge";
11
- export * from "./core/gaugeMath";
12
10
  export * from "./core/pool";
13
11
  export * from "./core/protocols";
14
12
  export * from "./core/rewardClaimer";
@@ -20,7 +18,6 @@ export * from "./payload/bot";
20
18
  export * from "./payload/creditAccount";
21
19
  export * from "./payload/creditManager";
22
20
  export * from "./payload/creditSession";
23
- export * from "./payload/gauge";
24
21
  export * from "./payload/graphPayload";
25
22
  export * from "./payload/pool";
26
23
  export * from "./payload/token";
package/lib/index.js CHANGED
@@ -23,8 +23,6 @@ __exportStar(require("./core/creditManager"), exports);
23
23
  __exportStar(require("./core/creditSession"), exports);
24
24
  __exportStar(require("./core/endpoint"), exports);
25
25
  __exportStar(require("./core/eventOrTx"), exports);
26
- __exportStar(require("./core/gauge"), exports);
27
- __exportStar(require("./core/gaugeMath"), exports);
28
26
  __exportStar(require("./core/pool"), exports);
29
27
  __exportStar(require("./core/protocols"), exports);
30
28
  __exportStar(require("./core/rewardClaimer"), exports);
@@ -36,7 +34,6 @@ __exportStar(require("./payload/bot"), exports);
36
34
  __exportStar(require("./payload/creditAccount"), exports);
37
35
  __exportStar(require("./payload/creditManager"), exports);
38
36
  __exportStar(require("./payload/creditSession"), exports);
39
- __exportStar(require("./payload/gauge"), exports);
40
37
  __exportStar(require("./payload/graphPayload"), exports);
41
38
  __exportStar(require("./payload/pool"), exports);
42
39
  __exportStar(require("./payload/token"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-prevfour.4",
3
+ "version": "3.0.0-prevfour.6",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1,40 +0,0 @@
1
- import { Address } from "viem";
2
- import { GaugeDataPayload, GaugeStakingDataPayload } from "../payload/gauge";
3
- export declare class GaugeData {
4
- readonly address: Address;
5
- readonly pool: Address;
6
- readonly poolUnderlying: Address;
7
- readonly name: string;
8
- readonly symbol: string;
9
- readonly currentEpoch: bigint;
10
- readonly epochFrozen: boolean;
11
- readonly quotaParams: Record<Address, {
12
- token: Address;
13
- minRate: bigint;
14
- maxRate: bigint;
15
- totalVotesLpSide: bigint;
16
- totalVotesCaSide: bigint;
17
- rate: bigint;
18
- quotaIncreaseFee: bigint;
19
- totalQuoted: bigint;
20
- limit: bigint;
21
- isActive: boolean;
22
- stakerVotesLpSide: bigint;
23
- stakerVotesCaSide: bigint;
24
- }>;
25
- constructor(payload: GaugeDataPayload);
26
- }
27
- interface WithDrawableGaugeItem {
28
- amount: bigint;
29
- epochsLeft: number;
30
- }
31
- export declare class GaugeStakingData {
32
- readonly availableBalance: bigint;
33
- readonly totalBalance: bigint;
34
- readonly epoch: bigint;
35
- readonly withdrawableNow: bigint;
36
- readonly withdrawableInEpochsTotal: bigint;
37
- readonly withdrawableInEpochs: Array<WithDrawableGaugeItem>;
38
- constructor(payload: GaugeStakingDataPayload);
39
- }
40
- export {};
package/lib/core/gauge.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GaugeStakingData = exports.GaugeData = void 0;
4
- const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
- class GaugeData {
6
- address;
7
- pool;
8
- poolUnderlying;
9
- name;
10
- symbol;
11
- currentEpoch;
12
- epochFrozen;
13
- quotaParams;
14
- constructor(payload) {
15
- this.address = payload.addr.toLowerCase();
16
- this.pool = payload.pool.toLowerCase();
17
- this.poolUnderlying = payload.underlying.toLowerCase();
18
- this.name = payload.name;
19
- this.symbol = payload.symbol;
20
- this.currentEpoch = BigInt(payload.currentEpoch);
21
- this.epochFrozen = payload.epochFrozen;
22
- this.quotaParams = payload.quotaParams.reduce((acc, q) => {
23
- const tokenLc = q.token.toLowerCase();
24
- acc[tokenLc] = {
25
- token: tokenLc,
26
- isActive: q.isActive,
27
- rate: BigInt(q.rate) * sdk_gov_1.PERCENTAGE_DECIMALS,
28
- minRate: BigInt(q.minRate) * sdk_gov_1.PERCENTAGE_DECIMALS,
29
- maxRate: BigInt(q.maxRate) * sdk_gov_1.PERCENTAGE_DECIMALS,
30
- quotaIncreaseFee: BigInt(q.quotaIncreaseFee),
31
- totalQuoted: q.totalQuoted,
32
- limit: q.limit,
33
- totalVotesLpSide: q.totalVotesLpSide,
34
- totalVotesCaSide: q.totalVotesCaSide,
35
- stakerVotesLpSide: q.stakerVotesLpSide,
36
- stakerVotesCaSide: q.stakerVotesCaSide,
37
- };
38
- return acc;
39
- }, {});
40
- }
41
- }
42
- exports.GaugeData = GaugeData;
43
- class GaugeStakingData {
44
- availableBalance;
45
- totalBalance;
46
- epoch;
47
- withdrawableNow;
48
- withdrawableInEpochsTotal;
49
- withdrawableInEpochs;
50
- constructor(payload) {
51
- this.availableBalance = payload.availableBalance;
52
- this.totalBalance = payload.totalBalance;
53
- this.epoch = BigInt(payload.epoch);
54
- this.withdrawableNow = payload.withdrawableAmounts.withdrawableNow;
55
- const { total, list } = payload.withdrawableAmounts.withdrawableInEpochs.reduce(({ total, list }, a, i) => {
56
- const bn = a;
57
- list.push({ amount: bn, epochsLeft: i + 1 });
58
- return { total: total + bn, list };
59
- }, { total: 0n, list: [] });
60
- this.withdrawableInEpochsTotal = total;
61
- this.withdrawableInEpochs = list;
62
- }
63
- }
64
- exports.GaugeStakingData = GaugeStakingData;
@@ -1,41 +0,0 @@
1
- import { Address } from "viem";
2
- import { GaugeData } from "./gauge";
3
- export type BaseVoteType = "raise" | "lower";
4
- export type VoteType = BaseVoteType | "remove";
5
- export interface BaseVote {
6
- amount: bigint;
7
- type: BaseVoteType;
8
- }
9
- export interface Vote {
10
- amount: bigint;
11
- type: VoteType;
12
- }
13
- export interface SingleVoteState {
14
- available: bigint;
15
- vote?: BaseVote;
16
- voteCalls: Array<Vote>;
17
- }
18
- export interface VoteProps {
19
- state: Omit<SingleVoteState, "voteCalls">;
20
- change?: Vote;
21
- }
22
- interface UnvoteProps {
23
- initialVote?: BaseVote;
24
- balanceAfter: bigint;
25
- nextVoteType: BaseVoteType;
26
- voteAfter?: Omit<SingleVoteState, "available">;
27
- }
28
- export interface GetGaugeApyProps {
29
- quota: Pick<GaugeData["quotaParams"][Address], "totalVotesCaSide" | "totalVotesLpSide" | "stakerVotesCaSide" | "stakerVotesLpSide" | "minRate" | "maxRate"> | undefined;
30
- vote?: BaseVote;
31
- voteAfter?: Omit<SingleVoteState, "available">;
32
- }
33
- export declare class GaugeMath {
34
- static vote({ change, ...rest }: VoteProps): SingleVoteState | undefined;
35
- private static addVotes;
36
- private static removeVotes;
37
- static revertVote({ balanceAfter, initialVote, nextVoteType, voteAfter, }: UnvoteProps): bigint | undefined;
38
- static getBaseVote: (v: GaugeData["quotaParams"][Address]) => BaseVote | undefined;
39
- static getGaugeApy({ quota, voteAfter, vote }: GetGaugeApyProps): bigint | null;
40
- }
41
- export {};
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GaugeMath = void 0;
4
- const math_1 = require("../utils/math");
5
- class GaugeMath {
6
- static vote({ change, ...rest }) {
7
- if (change?.type === "remove") {
8
- return this.removeVotes({ ...rest, change });
9
- }
10
- if (change) {
11
- return this.addVotes({
12
- ...rest,
13
- change: { ...change, type: change.type },
14
- });
15
- }
16
- return { ...rest.state, voteCalls: [] };
17
- }
18
- static addVotes({ state, change }) {
19
- const { available, vote } = state;
20
- if (!vote) {
21
- return {
22
- available: available - change.amount,
23
- vote: change,
24
- voteCalls: [change],
25
- };
26
- }
27
- if (vote.type === change.type) {
28
- return {
29
- available: available - change.amount,
30
- vote: { ...change, amount: vote.amount + change.amount },
31
- voteCalls: [change],
32
- };
33
- }
34
- const remove = { type: "remove", amount: vote.amount };
35
- return {
36
- available: available + vote.amount - change.amount,
37
- vote: { ...change, amount: change.amount },
38
- voteCalls: [remove, change],
39
- };
40
- }
41
- static removeVotes({ state, change }) {
42
- const { available, vote } = state;
43
- if (!vote)
44
- return { ...state, voteCalls: [] };
45
- const safeChange = math_1.BigIntMath.min(vote.amount, change.amount);
46
- const afterVote = vote.amount - safeChange;
47
- return {
48
- available: available + safeChange,
49
- vote: { ...vote, amount: afterVote },
50
- voteCalls: [{ ...change, amount: safeChange }],
51
- };
52
- }
53
- static revertVote({ balanceAfter, initialVote, nextVoteType, voteAfter, }) {
54
- // on vote type change unvote previous vote
55
- const prevUnvoted = !initialVote || initialVote.type === nextVoteType
56
- ? balanceAfter
57
- : balanceAfter + initialVote.amount;
58
- if (!voteAfter)
59
- return prevUnvoted;
60
- // change call is always last, remove is always first
61
- const [first, last = first] = voteAfter.voteCalls;
62
- const removePart = first?.type === "remove" ? first?.amount || 0n : 0n;
63
- const addPart = last?.type !== "remove" ? last?.amount || 0n : 0n;
64
- // revert current changes
65
- return prevUnvoted + addPart - removePart;
66
- }
67
- static getBaseVote = (v) => {
68
- const voteDown = v.stakerVotesCaSide;
69
- const voteUp = v.stakerVotesLpSide;
70
- if (!voteDown && !voteUp)
71
- return undefined;
72
- if (voteDown > 0) {
73
- return { type: "lower", amount: voteDown };
74
- }
75
- if (voteUp > 0) {
76
- return { type: "raise", amount: voteUp };
77
- }
78
- return undefined;
79
- };
80
- // rate = (minRate *(votesFormin + yourvotesformin) +maxRate*(votesFormax +yourvotesformax)/( votesForMin + votesForMax+yourvotes)
81
- static getGaugeApy({ quota, voteAfter, vote }) {
82
- if (!quota)
83
- return null;
84
- const first = voteAfter?.voteCalls?.[0];
85
- const last = voteAfter?.voteCalls?.[1] || first;
86
- const isRemove = first?.type === "remove";
87
- const removeCaPart = isRemove && vote?.type === "lower" ? first?.amount || 0n : 0n;
88
- const removeLpPart = isRemove && vote?.type === "raise" ? first?.amount || 0n : 0n;
89
- const caPart = last?.type === "lower" ? last?.amount || 0n : 0n;
90
- const lpPart = last?.type === "raise" ? last?.amount || 0n : 0n;
91
- const caImpact = quota.minRate * (quota.totalVotesCaSide + caPart - removeCaPart);
92
- const lpImpact = quota.maxRate * (quota.totalVotesLpSide + lpPart - removeLpPart);
93
- const total = quota.totalVotesCaSide +
94
- quota.totalVotesLpSide +
95
- caPart +
96
- lpPart -
97
- removeCaPart -
98
- removeLpPart;
99
- if (total === 0n)
100
- return quota.minRate;
101
- const r = (caImpact + lpImpact) / total;
102
- return r;
103
- }
104
- }
105
- exports.GaugeMath = GaugeMath;
@@ -1 +0,0 @@
1
- export {};
@@ -1,388 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chai_1 = require("chai");
4
- const gaugeMath_1 = require("./gaugeMath");
5
- describe("GaugeMath vote() test", () => {
6
- it("with empty state and with no changes", () => {
7
- const s = { available: 0n, voteCalls: [] };
8
- const v = { state: s };
9
- const r = gaugeMath_1.GaugeMath.vote(v);
10
- const res = { ...s, voteCalls: [] };
11
- (0, chai_1.expect)(r).to.be.eql(res);
12
- });
13
- it("remove with no prev vote", () => {
14
- const s = { available: 0n, voteCalls: [] };
15
- const v = { state: s, change: { type: "remove", amount: 10n } };
16
- const r = gaugeMath_1.GaugeMath.vote(v);
17
- const res = { ...s, voteCalls: [] };
18
- (0, chai_1.expect)(r).to.be.eql(res);
19
- });
20
- it("remove with prev vote - more than available", () => {
21
- const s = {
22
- available: 0n,
23
- vote: { type: "lower", amount: 5n },
24
- voteCalls: [],
25
- };
26
- const v = { state: s, change: { type: "remove", amount: 10n } };
27
- const r = gaugeMath_1.GaugeMath.vote(v);
28
- const res = {
29
- available: 5n,
30
- vote: { type: "lower", amount: 0n },
31
- voteCalls: [{ type: "remove", amount: 5n }],
32
- };
33
- (0, chai_1.expect)(r).to.be.eql(res);
34
- });
35
- it("remove with prev vote - eq than available", () => {
36
- const s = {
37
- available: 0n,
38
- vote: { type: "lower", amount: 5n },
39
- voteCalls: [],
40
- };
41
- const v = { state: s, change: { type: "remove", amount: 5n } };
42
- const r = gaugeMath_1.GaugeMath.vote(v);
43
- const res = {
44
- available: 5n,
45
- vote: { type: "lower", amount: 0n },
46
- voteCalls: [{ type: "remove", amount: 5n }],
47
- };
48
- (0, chai_1.expect)(r).to.be.eql(res);
49
- });
50
- it("remove with prev vote - more than available", () => {
51
- const s = {
52
- available: 0n,
53
- vote: { type: "lower", amount: 10n },
54
- voteCalls: [],
55
- };
56
- const v = { state: s, change: { type: "remove", amount: 5n } };
57
- const r = gaugeMath_1.GaugeMath.vote(v);
58
- const res = {
59
- available: 5n,
60
- vote: { type: "lower", amount: 5n },
61
- voteCalls: [{ type: "remove", amount: 5n }],
62
- };
63
- (0, chai_1.expect)(r).to.be.eql(res);
64
- });
65
- it("add to zero", () => {
66
- const s = { available: 10n, voteCalls: [] };
67
- const v = { state: s, change: { type: "lower", amount: 10n } };
68
- const r = gaugeMath_1.GaugeMath.vote(v);
69
- const res = {
70
- available: 0n,
71
- vote: { type: "lower", amount: 10n },
72
- voteCalls: [{ type: "lower", amount: 10n }],
73
- };
74
- (0, chai_1.expect)(r).to.be.eql(res);
75
- });
76
- it("add to same type", () => {
77
- const s = {
78
- available: 10n,
79
- vote: { type: "lower", amount: 5n },
80
- voteCalls: [],
81
- };
82
- const v = { state: s, change: { type: "lower", amount: 10n } };
83
- const r = gaugeMath_1.GaugeMath.vote(v);
84
- const res = {
85
- available: 0n,
86
- vote: { type: "lower", amount: 15n },
87
- voteCalls: [{ type: "lower", amount: 10n }],
88
- };
89
- (0, chai_1.expect)(r).to.be.eql(res);
90
- });
91
- it("add different type", () => {
92
- const s = {
93
- available: 10n,
94
- vote: { type: "lower", amount: 10n },
95
- voteCalls: [],
96
- };
97
- const v = { state: s, change: { type: "raise", amount: 5n } };
98
- const r = gaugeMath_1.GaugeMath.vote(v);
99
- const res = {
100
- available: 15n,
101
- vote: { type: "raise", amount: 5n },
102
- voteCalls: [
103
- { type: "remove", amount: 10n },
104
- { type: "raise", amount: 5n },
105
- ],
106
- };
107
- (0, chai_1.expect)(r).to.be.eql(res);
108
- });
109
- it("available can be negative after add", () => {
110
- const s = {
111
- available: 5n,
112
- vote: { type: "lower", amount: 5n },
113
- voteCalls: [],
114
- };
115
- const v = { state: s, change: { type: "raise", amount: 15n } };
116
- const r = gaugeMath_1.GaugeMath.vote(v);
117
- const res = {
118
- available: -5n,
119
- vote: { type: "raise", amount: 15n },
120
- voteCalls: [
121
- { type: "remove", amount: 5n },
122
- { type: "raise", amount: 15n },
123
- ],
124
- };
125
- (0, chai_1.expect)(r).to.be.eql(res);
126
- });
127
- });
128
- describe("GaugeMath revertVote() test", () => {
129
- it("if no votes before & after, should return initial amount", () => {
130
- const initialBalance = 21n;
131
- const r = gaugeMath_1.GaugeMath.revertVote({
132
- balanceAfter: initialBalance,
133
- nextVoteType: "lower",
134
- });
135
- (0, chai_1.expect)(r).to.be.eql(initialBalance);
136
- });
137
- it("if no vote after and next expected type is not changed, should return initial amount", () => {
138
- const initialBalance = 27n;
139
- const initialVote = {
140
- type: "lower",
141
- amount: 99n,
142
- };
143
- const r = gaugeMath_1.GaugeMath.revertVote({
144
- balanceAfter: initialBalance,
145
- initialVote,
146
- nextVoteType: "lower",
147
- });
148
- (0, chai_1.expect)(r).to.be.eql(initialBalance);
149
- });
150
- it("if no vote after and next expected type is changed, should revert initial vote", () => {
151
- const initialBalance = 27n;
152
- const initialVote = {
153
- type: "lower",
154
- amount: 99n,
155
- };
156
- const r = gaugeMath_1.GaugeMath.revertVote({
157
- balanceAfter: initialBalance,
158
- initialVote,
159
- nextVoteType: "raise",
160
- });
161
- (0, chai_1.expect)(r).to.be.eql(initialBalance + initialVote.amount);
162
- });
163
- it("if no vote before, should revert vote after", () => {
164
- const initialBalance = 26n;
165
- const voteBy = 5n;
166
- const voteAfter = {
167
- available: initialBalance - voteBy,
168
- vote: { type: "lower", amount: voteBy },
169
- voteCalls: [{ type: "lower", amount: voteBy }],
170
- };
171
- const balanceAfter = voteAfter.available;
172
- const r = gaugeMath_1.GaugeMath.revertVote({
173
- balanceAfter,
174
- nextVoteType: "lower",
175
- voteAfter: voteAfter,
176
- });
177
- (0, chai_1.expect)(r).to.be.eql(initialBalance);
178
- });
179
- it("if vote before type matches expected type, should revert vote after", () => {
180
- const initialBalance = 10n;
181
- const voteBy = 6n;
182
- const initialVote = {
183
- type: "lower",
184
- amount: 20n,
185
- };
186
- const voteAfter = {
187
- available: initialBalance - voteBy,
188
- vote: { type: "lower", amount: initialVote.amount + voteBy },
189
- voteCalls: [{ type: "lower", amount: voteBy }],
190
- };
191
- const balanceAfter = voteAfter.available;
192
- const r = gaugeMath_1.GaugeMath.revertVote({
193
- initialVote,
194
- balanceAfter,
195
- nextVoteType: "lower",
196
- voteAfter: voteAfter,
197
- });
198
- (0, chai_1.expect)(r).to.be.eql(initialBalance);
199
- });
200
- it("if vote before type doesn't match expected type, should revert vote before", () => {
201
- const initialBalance = 10n;
202
- const voteBy = 20n;
203
- const initialVote = {
204
- type: "raise",
205
- amount: 61n,
206
- };
207
- const voteAfter = {
208
- available: initialBalance + initialVote.amount - voteBy,
209
- vote: { type: "lower", amount: voteBy },
210
- voteCalls: [
211
- { type: "remove", amount: initialVote.amount },
212
- { type: "lower", amount: voteBy },
213
- ],
214
- };
215
- const r = gaugeMath_1.GaugeMath.revertVote({
216
- initialVote,
217
- balanceAfter: voteAfter.available,
218
- nextVoteType: "lower",
219
- voteAfter: voteAfter,
220
- });
221
- (0, chai_1.expect)(r).to.be.eql(initialBalance + initialVote.amount);
222
- });
223
- it("on remove, if vote before type matches expected type, should revert removal", () => {
224
- const initialBalance = 100n;
225
- const voteBy = 13n;
226
- const initialVote = {
227
- type: "lower",
228
- amount: 30n,
229
- };
230
- const voteAfter = {
231
- available: initialBalance + voteBy,
232
- vote: { type: "lower", amount: initialVote.amount - voteBy },
233
- voteCalls: [{ type: "remove", amount: voteBy }],
234
- };
235
- const r = gaugeMath_1.GaugeMath.revertVote({
236
- initialVote,
237
- balanceAfter: voteAfter.available,
238
- nextVoteType: "lower",
239
- voteAfter: voteAfter,
240
- });
241
- (0, chai_1.expect)(r).to.be.eql(initialBalance);
242
- });
243
- it("on remove, if vote before type doesn't match expected type, should revert vote before", () => {
244
- const initialBalance = 100n;
245
- const voteBy = 13n;
246
- const initialVote = {
247
- type: "raise",
248
- amount: 30n,
249
- };
250
- const voteAfter = {
251
- available: initialBalance + voteBy,
252
- vote: { type: "raise", amount: initialVote.amount - voteBy },
253
- voteCalls: [{ type: "remove", amount: voteBy }],
254
- };
255
- const r = gaugeMath_1.GaugeMath.revertVote({
256
- initialVote,
257
- balanceAfter: voteAfter.available,
258
- nextVoteType: "lower",
259
- voteAfter: voteAfter,
260
- });
261
- (0, chai_1.expect)(r).to.be.eql(initialBalance + initialVote.amount);
262
- });
263
- });
264
- describe("GaugeMath getGaugeApy() test", () => {
265
- it("should return null if no quota", () => {
266
- const vote = { amount: 0n, type: "lower" };
267
- const voteAfter = {
268
- vote: { amount: 5n, type: "lower" },
269
- voteCalls: [{ amount: 5n, type: "lower" }],
270
- };
271
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
272
- quota: undefined,
273
- vote,
274
- voteAfter,
275
- });
276
- (0, chai_1.expect)(r).to.be.eql(null);
277
- });
278
- it("should return min rate if total is zero", () => {
279
- const quota = {
280
- totalVotesCaSide: 0n,
281
- totalVotesLpSide: 0n,
282
- stakerVotesCaSide: 0n,
283
- stakerVotesLpSide: 0n,
284
- minRate: 12n,
285
- maxRate: 12345n,
286
- };
287
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
288
- quota,
289
- });
290
- (0, chai_1.expect)(r).to.be.eql(12n);
291
- });
292
- it("should calculate quota without votes", () => {
293
- const quota = {
294
- totalVotesCaSide: 100n,
295
- totalVotesLpSide: 100n,
296
- stakerVotesCaSide: 10n,
297
- stakerVotesLpSide: 0n,
298
- minRate: 0n,
299
- maxRate: 10000n,
300
- };
301
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
302
- quota,
303
- });
304
- (0, chai_1.expect)(r).to.be.eql(5000n);
305
- });
306
- it("should calculate quota with prev vote", () => {
307
- const quota = {
308
- totalVotesCaSide: 100n,
309
- totalVotesLpSide: 100n,
310
- stakerVotesCaSide: 10n,
311
- stakerVotesLpSide: 0n,
312
- minRate: 0n,
313
- maxRate: 10000n,
314
- };
315
- const vote = { amount: 10n, type: "lower" };
316
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
317
- quota,
318
- vote,
319
- });
320
- (0, chai_1.expect)(r).to.be.eql(5000n);
321
- });
322
- it("should calculate quota with same vote increase", () => {
323
- const quota = {
324
- totalVotesCaSide: 100n,
325
- totalVotesLpSide: 100n,
326
- stakerVotesCaSide: 10n,
327
- stakerVotesLpSide: 0n,
328
- minRate: 0n,
329
- maxRate: 10000n,
330
- };
331
- const vote = { amount: 10n, type: "lower" };
332
- const voteAfter = {
333
- vote: { amount: 20n, type: "lower" },
334
- voteCalls: [{ amount: 10n, type: "lower" }],
335
- };
336
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
337
- quota,
338
- vote,
339
- voteAfter,
340
- });
341
- (0, chai_1.expect)(r).to.be.eql(4761n);
342
- });
343
- it("should calculate quota with different vote increase", () => {
344
- const quota = {
345
- totalVotesCaSide: 100n,
346
- totalVotesLpSide: 100n,
347
- stakerVotesCaSide: 20n,
348
- stakerVotesLpSide: 0n,
349
- minRate: 0n,
350
- maxRate: 10000n,
351
- };
352
- const vote = { amount: 30n, type: "lower" };
353
- const voteAfter = {
354
- vote: { amount: 20n, type: "raise" },
355
- voteCalls: [
356
- { amount: 30n, type: "remove" },
357
- { amount: 20n, type: "raise" },
358
- ],
359
- };
360
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
361
- quota,
362
- vote,
363
- voteAfter,
364
- });
365
- (0, chai_1.expect)(r).to.be.eql(6315n);
366
- });
367
- it("should calculate quota with vote remove", () => {
368
- const quota = {
369
- totalVotesCaSide: 100n,
370
- totalVotesLpSide: 100n,
371
- stakerVotesCaSide: 20n,
372
- stakerVotesLpSide: 0n,
373
- minRate: 0n,
374
- maxRate: 10000n,
375
- };
376
- const vote = { amount: 20n, type: "lower" };
377
- const voteAfter = {
378
- vote: { amount: 0n, type: "lower" },
379
- voteCalls: [{ amount: 20n, type: "remove" }],
380
- };
381
- const r = gaugeMath_1.GaugeMath.getGaugeApy({
382
- quota,
383
- vote,
384
- voteAfter,
385
- });
386
- (0, chai_1.expect)(r).to.be.eql(5555n);
387
- });
388
- });
@@ -1,40 +0,0 @@
1
- import { Address } from "viem";
2
- export interface MultiVote {
3
- votingContract: Address;
4
- voteAmount: bigint;
5
- isIncrease: boolean;
6
- extraData: Address;
7
- }
8
- export interface GaugeQuotaParams {
9
- token: Address;
10
- minRate: number;
11
- maxRate: number;
12
- totalVotesLpSide: bigint;
13
- totalVotesCaSide: bigint;
14
- rate: number;
15
- quotaIncreaseFee: number;
16
- totalQuoted: bigint;
17
- limit: bigint;
18
- isActive: boolean;
19
- stakerVotesLpSide: bigint;
20
- stakerVotesCaSide: bigint;
21
- }
22
- export interface GaugeDataPayload {
23
- addr: Address;
24
- pool: Address;
25
- symbol: string;
26
- name: string;
27
- underlying: Address;
28
- currentEpoch: number;
29
- epochFrozen: boolean;
30
- quotaParams: readonly GaugeQuotaParams[];
31
- }
32
- export interface GaugeStakingDataPayload {
33
- availableBalance: bigint;
34
- totalBalance: bigint;
35
- epoch: number;
36
- withdrawableAmounts: {
37
- withdrawableNow: bigint;
38
- withdrawableInEpochs: readonly [bigint, bigint, bigint, bigint];
39
- };
40
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });