@curvefi/api 2.63.0 → 2.63.2
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/boosting.js +247 -645
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +19 -19
- package/lib/constants/coins/arbitrum.js +5 -5
- package/lib/constants/coins/aurora.js +5 -5
- package/lib/constants/coins/avalanche.js +6 -6
- package/lib/constants/coins/base.js +5 -5
- package/lib/constants/coins/bsc.js +5 -5
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +9 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/fraxtal.js +5 -5
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/mantle.js +5 -5
- package/lib/constants/coins/moonbeam.js +5 -5
- package/lib/constants/coins/optimism.js +5 -5
- package/lib/constants/coins/polygon.js +6 -6
- package/lib/constants/coins/xdai.js +5 -5
- package/lib/constants/coins/xlayer.js +5 -5
- package/lib/constants/coins/zksync.js +5 -5
- package/lib/constants/pools/arbitrum.js +1 -1
- package/lib/constants/pools/aurora.js +1 -1
- package/lib/constants/pools/avalanche.js +1 -1
- package/lib/constants/pools/base.js +1 -1
- package/lib/constants/pools/bsc.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +2 -2
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/fraxtal.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/mantle.js +1 -1
- package/lib/constants/pools/moonbeam.js +1 -1
- package/lib/constants/pools/optimism.js +1 -1
- package/lib/constants/pools/polygon.js +1 -1
- package/lib/constants/pools/xdai.js +1 -1
- package/lib/constants/pools/xlayer.js +1 -1
- package/lib/constants/pools/zksync.js +1 -1
- package/lib/constants/tricryptoDeployImplementations.js +1 -1
- package/lib/constants/utils.js +18 -19
- package/lib/constants/volumeNetworks.js +1 -1
- package/lib/curve.d.ts +10 -6
- package/lib/curve.js +534 -909
- package/lib/dao.js +351 -705
- package/lib/external-api.js +127 -256
- package/lib/factory/common.js +4 -4
- package/lib/factory/constants-crypto.js +33 -33
- package/lib/factory/constants.js +34 -34
- package/lib/factory/deploy.js +542 -907
- package/lib/factory/factory-api.js +205 -269
- package/lib/factory/factory-crypto.js +202 -342
- package/lib/factory/factory-tricrypto.js +164 -286
- package/lib/factory/factory-twocrypto.js +151 -269
- package/lib/factory/factory.js +245 -385
- package/lib/index.js +109 -198
- package/lib/interfaces.d.ts +46 -6
- package/lib/pools/PoolTemplate.js +1774 -3027
- package/lib/pools/gaugePool.js +112 -251
- package/lib/pools/mixins/common.js +22 -93
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
- package/lib/pools/mixins/depositMixins.js +160 -386
- package/lib/pools/mixins/depositWrappedMixins.js +79 -205
- package/lib/pools/mixins/poolBalancesMixin.js +24 -87
- package/lib/pools/mixins/swapMixins.js +139 -324
- package/lib/pools/mixins/swapWrappedMixins.js +111 -265
- package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
- package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
- package/lib/pools/mixins/withdrawMixins.js +139 -359
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
- package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
- package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
- package/lib/pools/poolConstructor.js +11 -31
- package/lib/pools/utils.js +301 -469
- package/lib/route-finder.worker.d.ts +9 -0
- package/lib/route-finder.worker.js +112 -0
- package/lib/route-graph.worker.d.ts +11 -0
- package/lib/route-graph.worker.js +334 -0
- package/lib/router.js +323 -912
- package/lib/utils.d.ts +8 -7
- package/lib/utils.js +540 -927
- package/package.json +3 -2
package/lib/dao.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,714 +7,371 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
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
10
|
import { curve } from "./curve.js";
|
|
49
11
|
import { Contract } from "ethers";
|
|
50
12
|
import { _getAllGauges, _getDaoProposalList, _getDaoProposal } from './external-api.js';
|
|
51
13
|
import { _getAddress, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, BN, } from './utils.js';
|
|
52
14
|
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
|
|
53
15
|
// ----------------- Refactored boosting stuff -----------------
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
export
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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));
|
|
16
|
+
export const crvSupplyStats = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
if (curve.chainId !== 1)
|
|
18
|
+
throw Error("Ethereum-only method");
|
|
19
|
+
const crvContract = curve.contracts[curve.constants.ALIASES.crv].multicallContract;
|
|
20
|
+
const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
21
|
+
const csContract = curve.contracts[curve.constants.ALIASES.circulating_supply].multicallContract;
|
|
22
|
+
const [_circulating, _locked, _veCrv] = yield curve.multicallProvider.all([
|
|
23
|
+
csContract.circulating_supply(),
|
|
24
|
+
crvContract.balanceOf(curve.constants.ALIASES.voting_escrow),
|
|
25
|
+
veContract.totalSupply(),
|
|
26
|
+
]);
|
|
27
|
+
return {
|
|
28
|
+
circulating: curve.formatUnits(_circulating),
|
|
29
|
+
locked: curve.formatUnits(_locked),
|
|
30
|
+
total: curve.formatUnits(_circulating + _locked),
|
|
31
|
+
veCrv: curve.formatUnits(_veCrv),
|
|
32
|
+
averageLockTime: toBN(_veCrv).div(toBN(_locked)).times(4).toFixed(4), // years
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
export const userCrv = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
if (curve.chainId !== 1)
|
|
37
|
+
throw Error("Ethereum-only method");
|
|
38
|
+
address = _getAddress(address);
|
|
39
|
+
const _balance = yield curve.contracts[curve.constants.ALIASES.crv].contract.balanceOf(address);
|
|
40
|
+
return curve.formatUnits(_balance);
|
|
41
|
+
});
|
|
42
|
+
export const userVeCrv = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
if (curve.chainId !== 1)
|
|
44
|
+
throw Error("Ethereum-only method");
|
|
45
|
+
address = _getAddress(address);
|
|
46
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
47
|
+
const [_veCrv, _veCrvTotal, _locked] = yield curve.multicallProvider.all([
|
|
48
|
+
contract.balanceOf(address),
|
|
49
|
+
contract.totalSupply(),
|
|
50
|
+
contract.locked(address),
|
|
51
|
+
]);
|
|
52
|
+
const _lockedCrv = _locked[0];
|
|
53
|
+
const _unlockTime = _locked[1];
|
|
54
|
+
return {
|
|
55
|
+
veCrv: curve.formatUnits(_veCrv),
|
|
56
|
+
veCrvPct: toBN(_veCrv).div(toBN(_veCrvTotal)).times(100).toString(),
|
|
57
|
+
lockedCrv: curve.formatUnits(_lockedCrv),
|
|
58
|
+
unlockTime: Number(curve.formatUnits(_unlockTime, 0)) * 1000,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
export const crvLockIsApproved = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
if (curve.chainId !== 1)
|
|
63
|
+
throw Error("Ethereum-only method");
|
|
64
|
+
return yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow);
|
|
65
|
+
});
|
|
66
|
+
export const crvLockApproveEstimateGas = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
if (curve.chainId !== 1)
|
|
68
|
+
throw Error("Ethereum-only method");
|
|
69
|
+
return yield ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
|
|
70
|
+
});
|
|
71
|
+
export const crvLockApprove = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
if (curve.chainId !== 1)
|
|
73
|
+
throw Error("Ethereum-only method");
|
|
74
|
+
return yield ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
|
|
75
|
+
});
|
|
76
|
+
export const calcCrvUnlockTime = (days, start = Date.now()) => {
|
|
77
|
+
const week = 86400 * 7;
|
|
78
|
+
const now = Number(start) / 1000;
|
|
79
|
+
const unlockTime = now + (86400 * Number(days));
|
|
167
80
|
return Math.floor(unlockTime / week) * week * 1000;
|
|
168
81
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
export
|
|
211
|
-
return
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
};
|
|
82
|
+
const _createCrvLock = (amount, days, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
if (curve.chainId !== 1)
|
|
84
|
+
throw Error("Ethereum-only method");
|
|
85
|
+
const crvBalance = yield userCrv();
|
|
86
|
+
if (BN(crvBalance).lt(amount))
|
|
87
|
+
throw Error(`Not enough CRV. Wallet balance: ${crvBalance}, required: ${amount}`);
|
|
88
|
+
if (!(yield crvLockIsApproved(amount)))
|
|
89
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
90
|
+
const _amount = parseUnits(amount);
|
|
91
|
+
const unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
|
|
92
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
93
|
+
const gas = yield contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions);
|
|
94
|
+
if (estimateGas)
|
|
95
|
+
return smartNumber(gas);
|
|
96
|
+
yield curve.updateFeeData();
|
|
97
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
98
|
+
return (yield contract.create_lock(_amount, unlockTime, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
99
|
+
});
|
|
100
|
+
export const createCrvLockEstimateGas = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
return yield _createCrvLock(amount, Number(days), true);
|
|
102
|
+
});
|
|
103
|
+
export const createCrvLock = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
return yield _createCrvLock(amount, Number(days), false);
|
|
105
|
+
});
|
|
106
|
+
const _increaseCrvLockedAmount = (amount, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
if (curve.chainId !== 1)
|
|
108
|
+
throw Error("Ethereum-only method");
|
|
109
|
+
const crvBalance = yield userCrv();
|
|
110
|
+
if (BN(crvBalance).lt(amount))
|
|
111
|
+
throw Error(`Not enough CRV. Wallet balance: ${crvBalance}, required: ${amount}`);
|
|
112
|
+
if (!(yield crvLockIsApproved(amount)))
|
|
113
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
114
|
+
const _amount = parseUnits(amount);
|
|
115
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
116
|
+
const gas = yield contract.increase_amount.estimateGas(_amount, curve.constantOptions);
|
|
117
|
+
if (estimateGas)
|
|
118
|
+
return smartNumber(gas);
|
|
119
|
+
yield curve.updateFeeData();
|
|
120
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
121
|
+
return (yield contract.increase_amount(_amount, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
122
|
+
});
|
|
123
|
+
export const increaseCrvLockedAmountEstimateGas = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
return yield _increaseCrvLockedAmount(amount, true);
|
|
125
|
+
});
|
|
126
|
+
export const increaseCrvLockedAmount = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
return yield _increaseCrvLockedAmount(amount, false);
|
|
128
|
+
});
|
|
129
|
+
const _increaseCrvUnlockTime = (days, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
if (curve.chainId !== 1)
|
|
131
|
+
throw Error("Ethereum-only method");
|
|
132
|
+
const { unlockTime } = yield userVeCrv();
|
|
133
|
+
const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
|
|
134
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
135
|
+
const gas = yield contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions);
|
|
136
|
+
if (estimateGas)
|
|
137
|
+
return smartNumber(gas);
|
|
138
|
+
yield curve.updateFeeData();
|
|
139
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
140
|
+
return (yield contract.increase_unlock_time(newUnlockTime, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
141
|
+
});
|
|
142
|
+
export const increaseCrvUnlockTimeEstimateGas = (days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
+
return yield _increaseCrvUnlockTime(Number(days), true);
|
|
144
|
+
});
|
|
145
|
+
export const increaseCrvUnlockTime = (days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
|
+
return yield _increaseCrvUnlockTime(Number(days), false);
|
|
147
|
+
});
|
|
148
|
+
const _withdrawLockedCrv = (estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
+
if (curve.chainId !== 1)
|
|
150
|
+
throw Error("Ethereum-only method");
|
|
151
|
+
const { unlockTime } = yield userVeCrv();
|
|
152
|
+
if (unlockTime > Date.now())
|
|
153
|
+
throw Error("The lock haven't expired yet");
|
|
154
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
155
|
+
const gas = yield contract.withdraw.estimateGas(curve.constantOptions);
|
|
156
|
+
if (estimateGas)
|
|
157
|
+
return smartNumber(gas);
|
|
158
|
+
yield curve.updateFeeData();
|
|
159
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
160
|
+
return (yield contract.withdraw(Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
161
|
+
});
|
|
162
|
+
export const withdrawLockedCrvEstimateGas = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
return yield _withdrawLockedCrv(true);
|
|
164
|
+
});
|
|
165
|
+
export const withdrawLockedCrv = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
166
|
+
return yield _withdrawLockedCrv(false);
|
|
167
|
+
});
|
|
168
|
+
export const claimableFees = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
address = _getAddress(address);
|
|
170
|
+
const contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
|
|
171
|
+
return curve.formatUnits(yield contract.claim(address, curve.constantOptions));
|
|
172
|
+
});
|
|
173
|
+
const _claimFees = (address, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
address = _getAddress(address);
|
|
175
|
+
const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
|
|
176
|
+
const gas = yield contract.claim.estimateGas(address, curve.constantOptions);
|
|
177
|
+
if (estimateGas)
|
|
178
|
+
return smartNumber(gas);
|
|
179
|
+
yield curve.updateFeeData();
|
|
180
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
181
|
+
return (yield contract.claim(address, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
182
|
+
});
|
|
183
|
+
export const claimFeesEstimateGas = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
return yield _claimFees(address, true);
|
|
185
|
+
});
|
|
186
|
+
export const claimFees = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
return yield _claimFees(address, false);
|
|
188
|
+
});
|
|
410
189
|
// ----------------- Gauge weights -----------------
|
|
411
|
-
|
|
190
|
+
const _extractNetworkFromPoolUrl = (poolUrl) => {
|
|
412
191
|
if (!poolUrl)
|
|
413
192
|
return "unknown";
|
|
414
193
|
return poolUrl.split("/")[4];
|
|
415
194
|
};
|
|
416
|
-
export
|
|
417
|
-
var
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
}
|
|
195
|
+
export const getVotingGaugeList = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
196
|
+
var _a;
|
|
197
|
+
if (curve.chainId !== 1)
|
|
198
|
+
throw Error("Ethereum-only method");
|
|
199
|
+
const gaugeData = Object.values(yield _getAllGauges());
|
|
200
|
+
const res = [];
|
|
201
|
+
for (let i = 0; i < gaugeData.length; i++) {
|
|
202
|
+
if ((gaugeData[i].is_killed || gaugeData[i].hasNoCrv) && Number(gaugeData[i].gauge_controller.gauge_relative_weight) === 0)
|
|
203
|
+
continue;
|
|
204
|
+
res.push({
|
|
205
|
+
poolUrl: gaugeData[i].poolUrls.swap[0],
|
|
206
|
+
network: _extractNetworkFromPoolUrl(gaugeData[i].poolUrls.swap[0]),
|
|
207
|
+
gaugeAddress: gaugeData[i].gauge,
|
|
208
|
+
poolAddress: gaugeData[i].swap,
|
|
209
|
+
lpTokenAddress: gaugeData[i].swap_token,
|
|
210
|
+
poolName: gaugeData[i].shortName,
|
|
211
|
+
totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
|
|
212
|
+
relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
|
|
213
|
+
isKilled: (_a = gaugeData[i].is_killed) !== null && _a !== void 0 ? _a : false,
|
|
506
214
|
});
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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
|
-
}); };
|
|
676
|
-
var _executeVote = function (type, id, estimateGas) {
|
|
677
|
-
if (estimateGas === void 0) { estimateGas = false; }
|
|
678
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
679
|
-
var contractAddress, contract, gas, gasLimit;
|
|
680
|
-
return __generator(this, function (_a) {
|
|
681
|
-
switch (_a.label) {
|
|
682
|
-
case 0:
|
|
683
|
-
if (curve.chainId !== 1)
|
|
684
|
-
throw Error("Ethereum-only method");
|
|
685
|
-
contractAddress = type === "PARAMETER" ? curve.constants.ALIASES.voting_parameter : curve.constants.ALIASES.voting_ownership;
|
|
686
|
-
contract = curve.contracts[contractAddress].contract;
|
|
687
|
-
return [4 /*yield*/, contract.executeVote.estimateGas(id, curve.constantOptions)];
|
|
688
|
-
case 1:
|
|
689
|
-
gas = _a.sent();
|
|
690
|
-
if (estimateGas)
|
|
691
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
692
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
693
|
-
case 2:
|
|
694
|
-
_a.sent();
|
|
695
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
696
|
-
return [4 /*yield*/, contract.executeVote(id, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
697
|
-
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
698
|
-
}
|
|
215
|
+
}
|
|
216
|
+
return res;
|
|
217
|
+
});
|
|
218
|
+
export const userGaugeVotes = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
219
|
+
var _b;
|
|
220
|
+
if (curve.chainId !== 1)
|
|
221
|
+
throw Error("Ethereum-only method");
|
|
222
|
+
address = _getAddress(address);
|
|
223
|
+
const gcMulticallContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
224
|
+
const veMulticallContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
225
|
+
const gaugeData = Object.values(yield _getAllGauges());
|
|
226
|
+
const calls = [veMulticallContract.balanceOf(address)];
|
|
227
|
+
for (const d of gaugeData) {
|
|
228
|
+
calls.push(gcMulticallContract.vote_user_slopes(address, d.gauge));
|
|
229
|
+
}
|
|
230
|
+
const [veCrvBalance, ...votes] = yield curve.multicallProvider.all(calls);
|
|
231
|
+
const res = { gauges: [], powerUsed: "0.0", veCrvUsed: "0.0" };
|
|
232
|
+
let powerUsed = BigInt(0);
|
|
233
|
+
let veCrvUsed = BigInt(0);
|
|
234
|
+
for (let i = 0; i < votes.length; i++) {
|
|
235
|
+
if (votes[i][1] === BigInt(0))
|
|
236
|
+
continue;
|
|
237
|
+
let dt = votes[i][2] - BigInt(Math.floor(Date.now() / 1000));
|
|
238
|
+
if (dt < BigInt(0))
|
|
239
|
+
dt = BigInt(0);
|
|
240
|
+
res.gauges.push({
|
|
241
|
+
userPower: curve.formatUnits(votes[i][1], 2),
|
|
242
|
+
userVeCrv: curve.formatUnits(votes[i][0] * dt, 18),
|
|
243
|
+
userFutureVeCrv: curve.formatUnits(veCrvBalance * votes[i][1] / BigInt(10000), 18),
|
|
244
|
+
expired: dt === BigInt(0),
|
|
245
|
+
gaugeData: {
|
|
246
|
+
poolUrl: gaugeData[i].poolUrls.swap[0],
|
|
247
|
+
network: _extractNetworkFromPoolUrl(gaugeData[i].poolUrls.swap[0]),
|
|
248
|
+
gaugeAddress: gaugeData[i].gauge,
|
|
249
|
+
poolAddress: gaugeData[i].swap,
|
|
250
|
+
lpTokenAddress: gaugeData[i].swap_token,
|
|
251
|
+
poolName: gaugeData[i].shortName,
|
|
252
|
+
totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
|
|
253
|
+
relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
|
|
254
|
+
isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
|
|
255
|
+
},
|
|
699
256
|
});
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
257
|
+
powerUsed += votes[i][1];
|
|
258
|
+
veCrvUsed += votes[i][0] * dt;
|
|
259
|
+
}
|
|
260
|
+
res.powerUsed = curve.formatUnits(powerUsed, 2);
|
|
261
|
+
res.veCrvUsed = curve.formatUnits(veCrvUsed.toString(), 18);
|
|
262
|
+
return res;
|
|
263
|
+
});
|
|
264
|
+
export const voteForGaugeNextTime = (gauge) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
if (curve.chainId !== 1)
|
|
266
|
+
throw Error("Ethereum-only method");
|
|
267
|
+
const _lastVote = yield curve.contracts[curve.constants.ALIASES.gauge_controller].contract.last_user_vote(curve.signerAddress, gauge, curve.constantOptions);
|
|
268
|
+
return (Number(_lastVote) + (10 * 86400)) * 1000;
|
|
269
|
+
});
|
|
270
|
+
const _voteForGauge = (gauge, power, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
271
|
+
if (curve.chainId !== 1)
|
|
272
|
+
throw Error("Ethereum-only method");
|
|
273
|
+
const gcContract = curve.contracts[curve.constants.ALIASES.gauge_controller].contract;
|
|
274
|
+
const gcMulticallContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
275
|
+
const _power = parseUnits(power, 2);
|
|
276
|
+
const [_powerUsed, _vote_slopes] = yield curve.multicallProvider.all([
|
|
277
|
+
gcMulticallContract.vote_user_power(curve.signerAddress),
|
|
278
|
+
gcMulticallContract.vote_user_slopes(curve.signerAddress, gauge),
|
|
279
|
+
]);
|
|
280
|
+
const _freePower = BigInt(10000) - _powerUsed;
|
|
281
|
+
if (_power > _freePower + _vote_slopes[1])
|
|
282
|
+
throw Error(`User have only ${curve.formatUnits(_freePower, 2)} % free power. Trying to use ${curve.formatUnits(_power, 2)}`);
|
|
283
|
+
const nextVoteTime = yield voteForGaugeNextTime(gauge);
|
|
284
|
+
if (Date.now() < nextVoteTime)
|
|
285
|
+
throw Error(`User can't change vote for this gauge earlier than ${new Date(nextVoteTime)}`);
|
|
286
|
+
const gas = yield gcContract.vote_for_gauge_weights.estimateGas(gauge, _power, curve.constantOptions);
|
|
287
|
+
if (estimateGas)
|
|
288
|
+
return smartNumber(gas);
|
|
289
|
+
yield curve.updateFeeData();
|
|
290
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
291
|
+
return (yield gcContract.vote_for_gauge_weights(gauge, _power, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
292
|
+
});
|
|
293
|
+
export const voteForGaugeEstimateGas = (gauge, power) => __awaiter(void 0, void 0, void 0, function* () {
|
|
294
|
+
return yield _voteForGauge(gauge, power, true);
|
|
295
|
+
});
|
|
296
|
+
export const voteForGauge = (gauge, power) => __awaiter(void 0, void 0, void 0, function* () {
|
|
297
|
+
return yield _voteForGauge(gauge, power, false);
|
|
298
|
+
});
|
|
299
|
+
// ----------------- Proposals -----------------
|
|
300
|
+
export const getProposalList = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
+
return yield _getDaoProposalList();
|
|
302
|
+
});
|
|
303
|
+
export const getProposal = (type, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
304
|
+
return yield _getDaoProposal(type, id);
|
|
305
|
+
});
|
|
306
|
+
export const userProposalVotes = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
+
if (curve.chainId !== 1)
|
|
308
|
+
throw Error("Ethereum-only method");
|
|
309
|
+
address = _getAddress(address);
|
|
310
|
+
const proposalList = yield _getDaoProposalList();
|
|
311
|
+
const calls = [];
|
|
312
|
+
for (const proposal of proposalList) {
|
|
313
|
+
if (proposal.voteType == "PARAMETER") {
|
|
314
|
+
calls.push(curve.contracts[curve.constants.ALIASES.voting_parameter].multicallContract.getVoterState(proposal.voteId, address));
|
|
707
315
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
export var executeVote = function (type, id) { return __awaiter(void 0, void 0, void 0, function () {
|
|
711
|
-
return __generator(this, function (_a) {
|
|
712
|
-
switch (_a.label) {
|
|
713
|
-
case 0: return [4 /*yield*/, _executeVote(type, id, false)];
|
|
714
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
316
|
+
else {
|
|
317
|
+
calls.push(curve.contracts[curve.constants.ALIASES.voting_ownership].multicallContract.getVoterState(proposal.voteId, address));
|
|
715
318
|
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
319
|
+
}
|
|
320
|
+
const userState = (yield curve.multicallProvider.all(calls)).map(Number);
|
|
321
|
+
const userProposalList = [];
|
|
322
|
+
const voteEnum = {
|
|
323
|
+
1: "yes",
|
|
324
|
+
2: "no",
|
|
325
|
+
3: "even",
|
|
326
|
+
};
|
|
327
|
+
for (let i = 0; i < proposalList.length; i++) {
|
|
328
|
+
if (userState[i] > 0)
|
|
329
|
+
userProposalList.push(Object.assign(Object.assign({}, proposalList[i]), { userVote: voteEnum[userState[i]] }));
|
|
330
|
+
}
|
|
331
|
+
return userProposalList;
|
|
332
|
+
});
|
|
333
|
+
const _voteForProposal = (type, id, support, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
334
|
+
if (curve.chainId !== 1)
|
|
335
|
+
throw Error("Ethereum-only method");
|
|
336
|
+
const contractAddress = type === "PARAMETER" ? curve.constants.ALIASES.voting_parameter : curve.constants.ALIASES.voting_ownership;
|
|
337
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
338
|
+
const yesPct = support ? BigInt(Math.pow(10, 18)) : BigInt(0);
|
|
339
|
+
const noPct = BigInt(Math.pow(10, 18)) - yesPct;
|
|
340
|
+
const gas = yield contract.votePct.estimateGas(id, yesPct, noPct, true, curve.constantOptions);
|
|
341
|
+
if (estimateGas)
|
|
342
|
+
return smartNumber(gas);
|
|
343
|
+
yield curve.updateFeeData();
|
|
344
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
345
|
+
return (yield contract.votePct(id, yesPct, noPct, false, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
346
|
+
});
|
|
347
|
+
export const voteForProposalEstimateGas = (type, id, support) => __awaiter(void 0, void 0, void 0, function* () {
|
|
348
|
+
return yield _voteForProposal(type, id, support, true);
|
|
349
|
+
});
|
|
350
|
+
export const voteForProposal = (type, id, support) => __awaiter(void 0, void 0, void 0, function* () {
|
|
351
|
+
return yield _voteForProposal(type, id, support, false);
|
|
352
|
+
});
|
|
353
|
+
const _executeVote = (type, id, estimateGas = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
354
|
+
if (curve.chainId !== 1)
|
|
355
|
+
throw Error("Ethereum-only method");
|
|
356
|
+
const contractAddress = type === "PARAMETER" ? curve.constants.ALIASES.voting_parameter : curve.constants.ALIASES.voting_ownership;
|
|
357
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
358
|
+
const gas = yield contract.executeVote.estimateGas(id, curve.constantOptions);
|
|
359
|
+
if (estimateGas)
|
|
360
|
+
return smartNumber(gas);
|
|
361
|
+
yield curve.updateFeeData();
|
|
362
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
363
|
+
return (yield contract.executeVote(id, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
364
|
+
});
|
|
365
|
+
export const executeVoteEstimateGas = (type, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
366
|
+
return yield _executeVote(type, id, true);
|
|
367
|
+
});
|
|
368
|
+
export const executeVote = (type, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
369
|
+
return yield _executeVote(type, id, false);
|
|
370
|
+
});
|
|
371
|
+
export const isCanVoteExecute = (type, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
372
|
+
if (curve.chainId !== 1)
|
|
373
|
+
throw Error("Ethereum-only method");
|
|
374
|
+
const contractAddress = type === "PARAMETER" ? curve.constants.ALIASES.voting_parameter : curve.constants.ALIASES.voting_ownership;
|
|
375
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
376
|
+
return yield contract.canExecute(id, Object.assign({}, curve.options));
|
|
377
|
+
});
|