@curvefi/api 2.52.5 → 2.53.1

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/dao.js ADDED
@@ -0,0 +1,675 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { curve } from "./curve.js";
49
+ import { Contract } from "ethers";
50
+ import { _getAllGauges, _getDaoProposalList, _getDaoProposal } from './external-api.js';
51
+ import { _getAddress, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, BN, } from './utils.js';
52
+ import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
53
+ // ----------------- Refactored boosting stuff -----------------
54
+ export var crvSupplyStats = function () { return __awaiter(void 0, void 0, void 0, function () {
55
+ var crvContract, veContract, csContract, _a, _circulating, _locked, _veCrv;
56
+ return __generator(this, function (_b) {
57
+ switch (_b.label) {
58
+ case 0:
59
+ if (curve.chainId !== 1)
60
+ throw Error("Ethereum-only method");
61
+ crvContract = curve.contracts[curve.constants.ALIASES.crv].multicallContract;
62
+ veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
63
+ csContract = curve.contracts[curve.constants.ALIASES.circulating_supply].multicallContract;
64
+ return [4 /*yield*/, curve.multicallProvider.all([
65
+ csContract.circulating_supply(),
66
+ crvContract.balanceOf(curve.constants.ALIASES.voting_escrow),
67
+ veContract.totalSupply(),
68
+ ])];
69
+ case 1:
70
+ _a = _b.sent(), _circulating = _a[0], _locked = _a[1], _veCrv = _a[2];
71
+ return [2 /*return*/, {
72
+ circulating: curve.formatUnits(_circulating),
73
+ locked: curve.formatUnits(_locked),
74
+ total: curve.formatUnits(_circulating + _locked),
75
+ veCrv: curve.formatUnits(_veCrv),
76
+ averageLockTime: toBN(_veCrv).div(toBN(_locked)).times(4).toFixed(4), // years
77
+ }];
78
+ }
79
+ });
80
+ }); };
81
+ export var userCrv = function (address) {
82
+ if (address === void 0) { address = ""; }
83
+ return __awaiter(void 0, void 0, void 0, function () {
84
+ var _balance;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ if (curve.chainId !== 1)
89
+ throw Error("Ethereum-only method");
90
+ address = _getAddress(address);
91
+ return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.crv].contract.balanceOf(address)];
92
+ case 1:
93
+ _balance = _a.sent();
94
+ return [2 /*return*/, curve.formatUnits(_balance)];
95
+ }
96
+ });
97
+ });
98
+ };
99
+ export var userVeCrv = function (address) {
100
+ if (address === void 0) { address = ""; }
101
+ return __awaiter(void 0, void 0, void 0, function () {
102
+ var contract, _a, _veCrv, _veCrvTotal, _locked, _lockedCrv, _unlockTime;
103
+ return __generator(this, function (_b) {
104
+ switch (_b.label) {
105
+ case 0:
106
+ if (curve.chainId !== 1)
107
+ throw Error("Ethereum-only method");
108
+ address = _getAddress(address);
109
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
110
+ return [4 /*yield*/, curve.multicallProvider.all([
111
+ contract.balanceOf(address),
112
+ contract.totalSupply(),
113
+ contract.locked(address),
114
+ ])];
115
+ case 1:
116
+ _a = _b.sent(), _veCrv = _a[0], _veCrvTotal = _a[1], _locked = _a[2];
117
+ _lockedCrv = _locked[0];
118
+ _unlockTime = _locked[1];
119
+ return [2 /*return*/, {
120
+ veCrv: curve.formatUnits(_veCrv),
121
+ veCrvPct: toBN(_veCrv).div(toBN(_veCrvTotal)).times(100).toString(),
122
+ lockedCrv: curve.formatUnits(_lockedCrv),
123
+ unlockTime: Number(curve.formatUnits(_unlockTime, 0)) * 1000,
124
+ }];
125
+ }
126
+ });
127
+ });
128
+ };
129
+ export var crvLockIsApproved = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ if (curve.chainId !== 1)
134
+ throw Error("Ethereum-only method");
135
+ return [4 /*yield*/, hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow)];
136
+ case 1: return [2 /*return*/, _a.sent()];
137
+ }
138
+ });
139
+ }); };
140
+ export var crvLockApproveEstimateGas = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0:
144
+ if (curve.chainId !== 1)
145
+ throw Error("Ethereum-only method");
146
+ return [4 /*yield*/, ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false)];
147
+ case 1: return [2 /*return*/, _a.sent()];
148
+ }
149
+ });
150
+ }); };
151
+ export var crvLockApprove = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0:
155
+ if (curve.chainId !== 1)
156
+ throw Error("Ethereum-only method");
157
+ return [4 /*yield*/, ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false)];
158
+ case 1: return [2 /*return*/, _a.sent()];
159
+ }
160
+ });
161
+ }); };
162
+ export var calcCrvUnlockTime = function (days, start) {
163
+ if (start === void 0) { start = Date.now(); }
164
+ var week = 86400 * 7;
165
+ var now = Number(start) / 1000;
166
+ var unlockTime = now + (86400 * Number(days));
167
+ return Math.floor(unlockTime / week) * week * 1000;
168
+ };
169
+ var _createCrvLock = function (amount, days, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
170
+ var crvBalance, _amount, unlockTime, contract, gas, gasLimit;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0:
174
+ if (curve.chainId !== 1)
175
+ throw Error("Ethereum-only method");
176
+ return [4 /*yield*/, userCrv()];
177
+ case 1:
178
+ crvBalance = _a.sent();
179
+ if (BN(crvBalance).lt(amount))
180
+ throw Error("Not enough CRV. Wallet balance: ".concat(crvBalance, ", required: ").concat(amount));
181
+ return [4 /*yield*/, crvLockIsApproved(amount)];
182
+ case 2:
183
+ if (!(_a.sent()))
184
+ throw Error("Token allowance is needed to estimate gas");
185
+ _amount = parseUnits(amount);
186
+ unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
187
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
188
+ return [4 /*yield*/, contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)];
189
+ case 3:
190
+ gas = _a.sent();
191
+ if (estimateGas)
192
+ return [2 /*return*/, smartNumber(gas)];
193
+ return [4 /*yield*/, curve.updateFeeData()];
194
+ case 4:
195
+ _a.sent();
196
+ gasLimit = mulBy1_3(DIGas(gas));
197
+ return [4 /*yield*/, contract.create_lock(_amount, unlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
198
+ case 5: return [2 /*return*/, (_a.sent()).hash];
199
+ }
200
+ });
201
+ }); };
202
+ export var createCrvLockEstimateGas = function (amount, days) { return __awaiter(void 0, void 0, void 0, function () {
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0: return [4 /*yield*/, _createCrvLock(amount, Number(days), true)];
206
+ case 1: return [2 /*return*/, _a.sent()];
207
+ }
208
+ });
209
+ }); };
210
+ export var createCrvLock = function (amount, days) { return __awaiter(void 0, void 0, void 0, function () {
211
+ return __generator(this, function (_a) {
212
+ switch (_a.label) {
213
+ case 0: return [4 /*yield*/, _createCrvLock(amount, Number(days), false)];
214
+ case 1: return [2 /*return*/, _a.sent()];
215
+ }
216
+ });
217
+ }); };
218
+ var _increaseCrvLockedAmount = function (amount, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
219
+ var crvBalance, _amount, contract, gas, gasLimit;
220
+ return __generator(this, function (_a) {
221
+ switch (_a.label) {
222
+ case 0:
223
+ if (curve.chainId !== 1)
224
+ throw Error("Ethereum-only method");
225
+ return [4 /*yield*/, userCrv()];
226
+ case 1:
227
+ crvBalance = _a.sent();
228
+ if (BN(crvBalance).lt(amount))
229
+ throw Error("Not enough CRV. Wallet balance: ".concat(crvBalance, ", required: ").concat(amount));
230
+ return [4 /*yield*/, crvLockIsApproved(amount)];
231
+ case 2:
232
+ if (!(_a.sent()))
233
+ throw Error("Token allowance is needed to estimate gas");
234
+ _amount = parseUnits(amount);
235
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
236
+ return [4 /*yield*/, contract.increase_amount.estimateGas(_amount, curve.constantOptions)];
237
+ case 3:
238
+ gas = _a.sent();
239
+ if (estimateGas)
240
+ return [2 /*return*/, smartNumber(gas)];
241
+ return [4 /*yield*/, curve.updateFeeData()];
242
+ case 4:
243
+ _a.sent();
244
+ gasLimit = mulBy1_3(DIGas(gas));
245
+ return [4 /*yield*/, contract.increase_amount(_amount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
246
+ case 5: return [2 /*return*/, (_a.sent()).hash];
247
+ }
248
+ });
249
+ }); };
250
+ export var increaseCrvLockedAmountEstimateGas = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
251
+ return __generator(this, function (_a) {
252
+ switch (_a.label) {
253
+ case 0: return [4 /*yield*/, _increaseCrvLockedAmount(amount, true)];
254
+ case 1: return [2 /*return*/, _a.sent()];
255
+ }
256
+ });
257
+ }); };
258
+ export var increaseCrvLockedAmount = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
259
+ return __generator(this, function (_a) {
260
+ switch (_a.label) {
261
+ case 0: return [4 /*yield*/, _increaseCrvLockedAmount(amount, false)];
262
+ case 1: return [2 /*return*/, _a.sent()];
263
+ }
264
+ });
265
+ }); };
266
+ var _increaseCrvUnlockTime = function (days, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
267
+ var unlockTime, newUnlockTime, contract, gas, gasLimit;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ if (curve.chainId !== 1)
272
+ throw Error("Ethereum-only method");
273
+ return [4 /*yield*/, userVeCrv()];
274
+ case 1:
275
+ unlockTime = (_a.sent()).unlockTime;
276
+ newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
277
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
278
+ return [4 /*yield*/, contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)];
279
+ case 2:
280
+ gas = _a.sent();
281
+ if (estimateGas)
282
+ return [2 /*return*/, smartNumber(gas)];
283
+ return [4 /*yield*/, curve.updateFeeData()];
284
+ case 3:
285
+ _a.sent();
286
+ gasLimit = mulBy1_3(DIGas(gas));
287
+ return [4 /*yield*/, contract.increase_unlock_time(newUnlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
288
+ case 4: return [2 /*return*/, (_a.sent()).hash];
289
+ }
290
+ });
291
+ }); };
292
+ export var increaseCrvUnlockTimeEstimateGas = function (days) { return __awaiter(void 0, void 0, void 0, function () {
293
+ return __generator(this, function (_a) {
294
+ switch (_a.label) {
295
+ case 0: return [4 /*yield*/, _increaseCrvUnlockTime(Number(days), true)];
296
+ case 1: return [2 /*return*/, _a.sent()];
297
+ }
298
+ });
299
+ }); };
300
+ export var increaseCrvUnlockTime = function (days) { return __awaiter(void 0, void 0, void 0, function () {
301
+ return __generator(this, function (_a) {
302
+ switch (_a.label) {
303
+ case 0: return [4 /*yield*/, _increaseCrvUnlockTime(Number(days), false)];
304
+ case 1: return [2 /*return*/, _a.sent()];
305
+ }
306
+ });
307
+ }); };
308
+ var _withdrawLockedCrv = function (estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
309
+ var unlockTime, contract, gas, gasLimit;
310
+ return __generator(this, function (_a) {
311
+ switch (_a.label) {
312
+ case 0:
313
+ if (curve.chainId !== 1)
314
+ throw Error("Ethereum-only method");
315
+ return [4 /*yield*/, userVeCrv()];
316
+ case 1:
317
+ unlockTime = (_a.sent()).unlockTime;
318
+ if (unlockTime > Date.now())
319
+ throw Error("The lock haven't expired yet");
320
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
321
+ return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
322
+ case 2:
323
+ gas = _a.sent();
324
+ if (estimateGas)
325
+ return [2 /*return*/, smartNumber(gas)];
326
+ return [4 /*yield*/, curve.updateFeeData()];
327
+ case 3:
328
+ _a.sent();
329
+ gasLimit = mulBy1_3(DIGas(gas));
330
+ return [4 /*yield*/, contract.withdraw(__assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
331
+ case 4: return [2 /*return*/, (_a.sent()).hash];
332
+ }
333
+ });
334
+ }); };
335
+ export var withdrawLockedCrvEstimateGas = function () { return __awaiter(void 0, void 0, void 0, function () {
336
+ return __generator(this, function (_a) {
337
+ switch (_a.label) {
338
+ case 0: return [4 /*yield*/, _withdrawLockedCrv(true)];
339
+ case 1: return [2 /*return*/, _a.sent()];
340
+ }
341
+ });
342
+ }); };
343
+ export var withdrawLockedCrv = function () { return __awaiter(void 0, void 0, void 0, function () {
344
+ return __generator(this, function (_a) {
345
+ switch (_a.label) {
346
+ case 0: return [4 /*yield*/, _withdrawLockedCrv(false)];
347
+ case 1: return [2 /*return*/, _a.sent()];
348
+ }
349
+ });
350
+ }); };
351
+ export var claimableFees = function (address) {
352
+ if (address === void 0) { address = ""; }
353
+ return __awaiter(void 0, void 0, void 0, function () {
354
+ var contract, _a, _b;
355
+ return __generator(this, function (_c) {
356
+ switch (_c.label) {
357
+ case 0:
358
+ address = _getAddress(address);
359
+ contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
360
+ _b = (_a = curve).formatUnits;
361
+ return [4 /*yield*/, contract.claim(address, curve.constantOptions)];
362
+ case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
363
+ }
364
+ });
365
+ });
366
+ };
367
+ var _claimFees = function (address, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
368
+ var contract, gas, gasLimit;
369
+ return __generator(this, function (_a) {
370
+ switch (_a.label) {
371
+ case 0:
372
+ address = _getAddress(address);
373
+ contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
374
+ return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
375
+ case 1:
376
+ gas = _a.sent();
377
+ if (estimateGas)
378
+ return [2 /*return*/, smartNumber(gas)];
379
+ return [4 /*yield*/, curve.updateFeeData()];
380
+ case 2:
381
+ _a.sent();
382
+ gasLimit = mulBy1_3(DIGas(gas));
383
+ return [4 /*yield*/, contract.claim(address, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
384
+ case 3: return [2 /*return*/, (_a.sent()).hash];
385
+ }
386
+ });
387
+ }); };
388
+ export var claimFeesEstimateGas = function (address) {
389
+ if (address === void 0) { address = ""; }
390
+ return __awaiter(void 0, void 0, void 0, function () {
391
+ return __generator(this, function (_a) {
392
+ switch (_a.label) {
393
+ case 0: return [4 /*yield*/, _claimFees(address, true)];
394
+ case 1: return [2 /*return*/, _a.sent()];
395
+ }
396
+ });
397
+ });
398
+ };
399
+ export var claimFees = function (address) {
400
+ if (address === void 0) { address = ""; }
401
+ return __awaiter(void 0, void 0, void 0, function () {
402
+ return __generator(this, function (_a) {
403
+ switch (_a.label) {
404
+ case 0: return [4 /*yield*/, _claimFees(address, false)];
405
+ case 1: return [2 /*return*/, _a.sent()];
406
+ }
407
+ });
408
+ });
409
+ };
410
+ // ----------------- Gauge weights -----------------
411
+ var _extractNetworkFromPoolUrl = function (poolUrl) {
412
+ if (!poolUrl)
413
+ return "unknown";
414
+ return poolUrl.split("/")[4];
415
+ };
416
+ export var getVotingGaugeList = function () { return __awaiter(void 0, void 0, void 0, function () {
417
+ var gaugeData, _a, _b, res, i;
418
+ var _c;
419
+ return __generator(this, function (_d) {
420
+ switch (_d.label) {
421
+ case 0:
422
+ if (curve.chainId !== 1)
423
+ throw Error("Ethereum-only method");
424
+ _b = (_a = Object).values;
425
+ return [4 /*yield*/, _getAllGauges()];
426
+ case 1:
427
+ gaugeData = _b.apply(_a, [_d.sent()]);
428
+ res = [];
429
+ for (i = 0; i < gaugeData.length; i++) {
430
+ if ((gaugeData[i].is_killed || gaugeData[i].hasNoCrv) && Number(gaugeData[i].gauge_controller.gauge_relative_weight) === 0)
431
+ continue;
432
+ res.push({
433
+ poolUrl: gaugeData[i].poolUrls.swap[0],
434
+ network: _extractNetworkFromPoolUrl(gaugeData[i].poolUrls.swap[0]),
435
+ gaugeAddress: gaugeData[i].gauge,
436
+ poolAddress: gaugeData[i].swap,
437
+ lpTokenAddress: gaugeData[i].swap_token,
438
+ poolName: gaugeData[i].shortName,
439
+ totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
440
+ relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
441
+ isKilled: (_c = gaugeData[i].is_killed) !== null && _c !== void 0 ? _c : false,
442
+ });
443
+ }
444
+ return [2 /*return*/, res];
445
+ }
446
+ });
447
+ }); };
448
+ export var userGaugeVotes = function (address) {
449
+ if (address === void 0) { address = ""; }
450
+ return __awaiter(void 0, void 0, void 0, function () {
451
+ var gcMulticallContract, veMulticallContract, gaugeData, _a, _b, calls, _i, gaugeData_1, d, _c, veCrvBalance, votes, res, powerUsed, veCrvUsed, i, dt;
452
+ var _d;
453
+ return __generator(this, function (_e) {
454
+ switch (_e.label) {
455
+ case 0:
456
+ if (curve.chainId !== 1)
457
+ throw Error("Ethereum-only method");
458
+ address = _getAddress(address);
459
+ gcMulticallContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
460
+ veMulticallContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
461
+ _b = (_a = Object).values;
462
+ return [4 /*yield*/, _getAllGauges()];
463
+ case 1:
464
+ gaugeData = _b.apply(_a, [_e.sent()]);
465
+ calls = [veMulticallContract.balanceOf(address)];
466
+ for (_i = 0, gaugeData_1 = gaugeData; _i < gaugeData_1.length; _i++) {
467
+ d = gaugeData_1[_i];
468
+ calls.push(gcMulticallContract.vote_user_slopes(address, d.gauge));
469
+ }
470
+ return [4 /*yield*/, curve.multicallProvider.all(calls)];
471
+ case 2:
472
+ _c = _e.sent(), veCrvBalance = _c[0], votes = _c.slice(1);
473
+ res = { gauges: [], powerUsed: "0.0", veCrvUsed: "0.0" };
474
+ powerUsed = BigInt(0);
475
+ veCrvUsed = BigInt(0);
476
+ for (i = 0; i < votes.length; i++) {
477
+ if (votes[i][1] === BigInt(0))
478
+ continue;
479
+ dt = votes[i][2] - BigInt(Math.floor(Date.now() / 1000));
480
+ if (dt < BigInt(0))
481
+ dt = BigInt(0);
482
+ res.gauges.push({
483
+ userPower: curve.formatUnits(votes[i][1], 2),
484
+ userVeCrv: curve.formatUnits(votes[i][0] * dt, 18),
485
+ userFutureVeCrv: curve.formatUnits(veCrvBalance * votes[i][1] / BigInt(10000), 18),
486
+ expired: dt === BigInt(0),
487
+ gaugeData: {
488
+ poolUrl: gaugeData[i].poolUrls.swap[0],
489
+ network: _extractNetworkFromPoolUrl(gaugeData[i].poolUrls.swap[0]),
490
+ gaugeAddress: gaugeData[i].gauge,
491
+ poolAddress: gaugeData[i].swap,
492
+ lpTokenAddress: gaugeData[i].swap_token,
493
+ poolName: gaugeData[i].shortName,
494
+ totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
495
+ relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
496
+ isKilled: (_d = gaugeData[i].is_killed) !== null && _d !== void 0 ? _d : false,
497
+ },
498
+ });
499
+ powerUsed += votes[i][1];
500
+ veCrvUsed += votes[i][0] * dt;
501
+ }
502
+ res.powerUsed = curve.formatUnits(powerUsed, 2);
503
+ res.veCrvUsed = curve.formatUnits(veCrvUsed.toString(), 18);
504
+ return [2 /*return*/, res];
505
+ }
506
+ });
507
+ });
508
+ };
509
+ export var voteForGaugeNextTime = function (gauge) { return __awaiter(void 0, void 0, void 0, function () {
510
+ var _lastVote;
511
+ return __generator(this, function (_a) {
512
+ switch (_a.label) {
513
+ case 0:
514
+ if (curve.chainId !== 1)
515
+ throw Error("Ethereum-only method");
516
+ return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gauge_controller].contract.last_user_vote(curve.signerAddress, gauge, curve.constantOptions)];
517
+ case 1:
518
+ _lastVote = _a.sent();
519
+ return [2 /*return*/, (Number(_lastVote) + (10 * 86400)) * 1000];
520
+ }
521
+ });
522
+ }); };
523
+ var _voteForGauge = function (gauge, power, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
524
+ var gcContract, gcMulticallContract, _power, _a, _powerUsed, _vote_slopes, _freePower, nextVoteTime, gas, gasLimit;
525
+ return __generator(this, function (_b) {
526
+ switch (_b.label) {
527
+ case 0:
528
+ if (curve.chainId !== 1)
529
+ throw Error("Ethereum-only method");
530
+ gcContract = curve.contracts[curve.constants.ALIASES.gauge_controller].contract;
531
+ gcMulticallContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
532
+ _power = parseUnits(power, 2);
533
+ return [4 /*yield*/, curve.multicallProvider.all([
534
+ gcMulticallContract.vote_user_power(curve.signerAddress),
535
+ gcMulticallContract.vote_user_slopes(curve.signerAddress, gauge),
536
+ ])];
537
+ case 1:
538
+ _a = _b.sent(), _powerUsed = _a[0], _vote_slopes = _a[1];
539
+ _freePower = BigInt(10000) - _powerUsed;
540
+ if (_power > _freePower + _vote_slopes[1])
541
+ throw Error("User have only ".concat(curve.formatUnits(_freePower, 2), " % free power. Trying to use ").concat(curve.formatUnits(_power, 2)));
542
+ return [4 /*yield*/, voteForGaugeNextTime(gauge)];
543
+ case 2:
544
+ nextVoteTime = _b.sent();
545
+ if (Date.now() < nextVoteTime)
546
+ throw Error("User can't change vote for this gauge earlier than ".concat(new Date(nextVoteTime)));
547
+ return [4 /*yield*/, gcContract.vote_for_gauge_weights.estimateGas(gauge, _power, curve.constantOptions)];
548
+ case 3:
549
+ gas = _b.sent();
550
+ if (estimateGas)
551
+ return [2 /*return*/, smartNumber(gas)];
552
+ return [4 /*yield*/, curve.updateFeeData()];
553
+ case 4:
554
+ _b.sent();
555
+ gasLimit = mulBy1_3(DIGas(gas));
556
+ return [4 /*yield*/, gcContract.vote_for_gauge_weights(gauge, _power, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
557
+ case 5: return [2 /*return*/, (_b.sent()).hash];
558
+ }
559
+ });
560
+ }); };
561
+ export var voteForGaugeEstimateGas = function (gauge, power) { return __awaiter(void 0, void 0, void 0, function () {
562
+ return __generator(this, function (_a) {
563
+ switch (_a.label) {
564
+ case 0: return [4 /*yield*/, _voteForGauge(gauge, power, true)];
565
+ case 1: return [2 /*return*/, _a.sent()];
566
+ }
567
+ });
568
+ }); };
569
+ export var voteForGauge = function (gauge, power) { return __awaiter(void 0, void 0, void 0, function () {
570
+ return __generator(this, function (_a) {
571
+ switch (_a.label) {
572
+ case 0: return [4 /*yield*/, _voteForGauge(gauge, power, false)];
573
+ case 1: return [2 /*return*/, _a.sent()];
574
+ }
575
+ });
576
+ }); };
577
+ // ----------------- Proposals -----------------
578
+ export var getProposalList = function () { return __awaiter(void 0, void 0, void 0, function () {
579
+ return __generator(this, function (_a) {
580
+ switch (_a.label) {
581
+ case 0: return [4 /*yield*/, _getDaoProposalList()];
582
+ case 1: return [2 /*return*/, _a.sent()];
583
+ }
584
+ });
585
+ }); };
586
+ export var getProposal = function (type, id) { return __awaiter(void 0, void 0, void 0, function () {
587
+ return __generator(this, function (_a) {
588
+ switch (_a.label) {
589
+ case 0: return [4 /*yield*/, _getDaoProposal(type, id)];
590
+ case 1: return [2 /*return*/, _a.sent()];
591
+ }
592
+ });
593
+ }); };
594
+ export var userProposalVotes = function (address) {
595
+ if (address === void 0) { address = ""; }
596
+ return __awaiter(void 0, void 0, void 0, function () {
597
+ var proposalList, calls, _i, proposalList_1, proposal, userState, userProposalList, voteEnum, i;
598
+ return __generator(this, function (_a) {
599
+ switch (_a.label) {
600
+ case 0:
601
+ if (curve.chainId !== 1)
602
+ throw Error("Ethereum-only method");
603
+ address = _getAddress(address);
604
+ return [4 /*yield*/, _getDaoProposalList()];
605
+ case 1:
606
+ proposalList = _a.sent();
607
+ calls = [];
608
+ for (_i = 0, proposalList_1 = proposalList; _i < proposalList_1.length; _i++) {
609
+ proposal = proposalList_1[_i];
610
+ if (proposal.voteType == "PARAMETER") {
611
+ calls.push(curve.contracts[curve.constants.ALIASES.voting_parameter].multicallContract.getVoterState(proposal.voteId, address));
612
+ }
613
+ else {
614
+ calls.push(curve.contracts[curve.constants.ALIASES.voting_ownership].multicallContract.getVoterState(proposal.voteId, address));
615
+ }
616
+ }
617
+ return [4 /*yield*/, curve.multicallProvider.all(calls)];
618
+ case 2:
619
+ userState = (_a.sent()).map(Number);
620
+ userProposalList = [];
621
+ voteEnum = {
622
+ 1: "yes",
623
+ 2: "no",
624
+ 3: "even",
625
+ };
626
+ for (i = 0; i < proposalList.length; i++) {
627
+ if (userState[i] > 0)
628
+ userProposalList.push(__assign(__assign({}, proposalList[i]), { userVote: voteEnum[userState[i]] }));
629
+ }
630
+ return [2 /*return*/, userProposalList];
631
+ }
632
+ });
633
+ });
634
+ };
635
+ var _voteForProposal = function (type, id, support, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
636
+ var contractAddress, contract, yesPct, noPct, gas, gasLimit;
637
+ return __generator(this, function (_a) {
638
+ switch (_a.label) {
639
+ case 0:
640
+ if (curve.chainId !== 1)
641
+ throw Error("Ethereum-only method");
642
+ contractAddress = type === "PARAMETER" ? curve.constants.ALIASES.voting_parameter : curve.constants.ALIASES.voting_ownership;
643
+ contract = curve.contracts[contractAddress].contract;
644
+ yesPct = support ? BigInt(Math.pow(10, 18)) : BigInt(0);
645
+ noPct = BigInt(Math.pow(10, 18)) - yesPct;
646
+ return [4 /*yield*/, contract.votePct.estimateGas(id, yesPct, noPct, true, curve.constantOptions)];
647
+ case 1:
648
+ gas = _a.sent();
649
+ if (estimateGas)
650
+ return [2 /*return*/, smartNumber(gas)];
651
+ return [4 /*yield*/, curve.updateFeeData()];
652
+ case 2:
653
+ _a.sent();
654
+ gasLimit = mulBy1_3(DIGas(gas));
655
+ return [4 /*yield*/, contract.votePct(id, yesPct, noPct, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
656
+ case 3: return [2 /*return*/, (_a.sent()).hash];
657
+ }
658
+ });
659
+ }); };
660
+ export var voteForProposalEstimateGas = function (type, id, support) { return __awaiter(void 0, void 0, void 0, function () {
661
+ return __generator(this, function (_a) {
662
+ switch (_a.label) {
663
+ case 0: return [4 /*yield*/, _voteForProposal(type, id, support, true)];
664
+ case 1: return [2 /*return*/, _a.sent()];
665
+ }
666
+ });
667
+ }); };
668
+ export var voteForProposal = function (type, id, support) { return __awaiter(void 0, void 0, void 0, function () {
669
+ return __generator(this, function (_a) {
670
+ switch (_a.label) {
671
+ case 0: return [4 /*yield*/, _voteForProposal(type, id, support, false)];
672
+ case 1: return [2 /*return*/, _a.sent()];
673
+ }
674
+ });
675
+ }); };