@curvefi/api 2.32.0 → 2.33.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.
Files changed (59) hide show
  1. package/lib/boosting.js +385 -135
  2. package/lib/constants/aliases.js +22 -11
  3. package/lib/constants/coins/arbitrum.js +5 -5
  4. package/lib/constants/coins/aurora.js +5 -5
  5. package/lib/constants/coins/avalanche.js +6 -6
  6. package/lib/constants/coins/celo.js +5 -5
  7. package/lib/constants/coins/ethereum.js +10 -9
  8. package/lib/constants/coins/fantom.js +7 -7
  9. package/lib/constants/coins/kava.js +5 -5
  10. package/lib/constants/coins/moonbeam.js +5 -5
  11. package/lib/constants/coins/optimism.js +5 -5
  12. package/lib/constants/coins/polygon.js +6 -6
  13. package/lib/constants/coins/xdai.js +5 -5
  14. package/lib/constants/pools/arbitrum.js +1 -1
  15. package/lib/constants/pools/aurora.js +1 -1
  16. package/lib/constants/pools/avalanche.js +1 -1
  17. package/lib/constants/pools/celo.js +1 -1
  18. package/lib/constants/pools/ethereum.js +1 -1
  19. package/lib/constants/pools/fantom.js +1 -1
  20. package/lib/constants/pools/kava.js +1 -1
  21. package/lib/constants/pools/moonbeam.js +1 -1
  22. package/lib/constants/pools/optimism.js +1 -1
  23. package/lib/constants/pools/polygon.js +1 -1
  24. package/lib/constants/pools/xdai.js +1 -1
  25. package/lib/constants/utils.js +19 -18
  26. package/lib/curve.js +506 -282
  27. package/lib/external-api.js +132 -45
  28. package/lib/factory/common.js +3 -3
  29. package/lib/factory/constants-crypto.js +21 -21
  30. package/lib/factory/constants.js +32 -31
  31. package/lib/factory/deploy.js +336 -176
  32. package/lib/factory/factory-api.js +256 -180
  33. package/lib/factory/factory-crypto.js +309 -163
  34. package/lib/factory/factory.d.ts +1 -1
  35. package/lib/factory/factory.js +336 -186
  36. package/lib/index.js +98 -44
  37. package/lib/interfaces.d.ts +5 -0
  38. package/lib/pools/PoolTemplate.js +2879 -1468
  39. package/lib/pools/mixins/common.js +106 -22
  40. package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
  41. package/lib/pools/mixins/depositMixins.js +413 -144
  42. package/lib/pools/mixins/depositWrappedMixins.js +223 -72
  43. package/lib/pools/mixins/poolBalancesMixin.js +98 -22
  44. package/lib/pools/mixins/swapMixins.js +347 -125
  45. package/lib/pools/mixins/swapWrappedMixins.js +270 -88
  46. package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
  47. package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
  48. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
  49. package/lib/pools/mixins/withdrawMixins.js +385 -122
  50. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
  51. package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
  52. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
  53. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
  54. package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
  55. package/lib/pools/poolConstructor.js +25 -5
  56. package/lib/pools/utils.js +488 -299
  57. package/lib/router.js +675 -212
  58. package/lib/utils.js +675 -354
  59. package/package.json +1 -2
package/lib/boosting.js CHANGED
@@ -1,152 +1,402 @@
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
+ };
1
48
  import { Contract } from "ethers";
2
49
  import { curve } from "./curve.js";
3
50
  import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
4
51
  import { _getBalances, _prepareAddresses, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3 } from "./utils.js";
5
52
  import { _ensureAllowance, toBN, toStringFromBN, parseUnits } from './utils.js';
6
- export const getCrv = async (...addresses) => {
7
- addresses = _prepareAddresses(addresses);
8
- const rawBalances = (await _getBalances([curve.constants.ALIASES.crv], addresses));
9
- const balances = {};
10
- for (const address of addresses) {
11
- balances[address] = rawBalances[address].shift();
53
+ export var getCrv = function () {
54
+ var addresses = [];
55
+ for (var _i = 0; _i < arguments.length; _i++) {
56
+ addresses[_i] = arguments[_i];
12
57
  }
13
- return addresses.length === 1 ? balances[addresses[0]] : balances;
14
- };
15
- export const getLockedAmountAndUnlockTime = async (...addresses) => {
16
- addresses = _prepareAddresses(addresses);
17
- const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
18
- const contractCalls = addresses.map((address) => veContract.locked(address));
19
- const response = (await curve.multicallProvider.all(contractCalls)).map((value) => [curve.formatUnits(value[0]), Number(curve.formatUnits(value[1], 0)) * 1000]);
20
- const result = {};
21
- addresses.forEach((addr, i) => {
22
- result[addr] = { lockedAmount: response[i][0], unlockTime: response[i][1] };
23
- });
24
- return addresses.length === 1 ? result[addresses[0]] : result;
25
- };
26
- export const getVeCrv = async (...addresses) => {
27
- addresses = _prepareAddresses(addresses);
28
- const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
29
- const contractCalls = addresses.map((address) => veContract.balanceOf(address));
30
- const response = (await curve.multicallProvider.all(contractCalls)).map((value) => curve.formatUnits(value));
31
- const result = {};
32
- addresses.forEach((addr, i) => {
33
- result[addr] = response[i];
34
- });
35
- return addresses.length === 1 ? result[addresses[0]] : result;
58
+ return __awaiter(void 0, void 0, void 0, function () {
59
+ var rawBalances, balances, _a, addresses_1, address;
60
+ return __generator(this, function (_b) {
61
+ switch (_b.label) {
62
+ case 0:
63
+ addresses = _prepareAddresses(addresses);
64
+ return [4 /*yield*/, _getBalances([curve.constants.ALIASES.crv], addresses)];
65
+ case 1:
66
+ rawBalances = (_b.sent());
67
+ balances = {};
68
+ for (_a = 0, addresses_1 = addresses; _a < addresses_1.length; _a++) {
69
+ address = addresses_1[_a];
70
+ balances[address] = rawBalances[address].shift();
71
+ }
72
+ return [2 /*return*/, addresses.length === 1 ? balances[addresses[0]] : balances];
73
+ }
74
+ });
75
+ });
36
76
  };
37
- export const getVeCrvPct = async (...addresses) => {
38
- addresses = _prepareAddresses(addresses);
39
- const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
40
- const contractCalls = [veContract.totalSupply()];
41
- addresses.forEach((address) => {
42
- contractCalls.push(veContract.balanceOf(address));
43
- });
44
- const response = (await curve.multicallProvider.all(contractCalls)).map((value) => toBN(value));
45
- const [veTotalSupply] = response.splice(0, 1);
46
- const resultBN = {};
47
- addresses.forEach((acct, i) => {
48
- resultBN[acct] = response[i].div(veTotalSupply).times(100);
49
- });
50
- const result = {};
51
- for (const entry of Object.entries(resultBN)) {
52
- result[entry[0]] = toStringFromBN(entry[1]);
77
+ export var getLockedAmountAndUnlockTime = function () {
78
+ var addresses = [];
79
+ for (var _i = 0; _i < arguments.length; _i++) {
80
+ addresses[_i] = arguments[_i];
53
81
  }
54
- return addresses.length === 1 ? result[addresses[0]] : result;
55
- };
56
- export const isApproved = async (amount) => {
57
- return await hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow);
58
- };
59
- export const approveEstimateGas = async (amount) => {
60
- return await ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
61
- };
62
- export const approve = async (amount) => {
63
- return await ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
82
+ return __awaiter(void 0, void 0, void 0, function () {
83
+ var veContract, contractCalls, response, result;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0:
87
+ addresses = _prepareAddresses(addresses);
88
+ veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
89
+ contractCalls = addresses.map(function (address) { return veContract.locked(address); });
90
+ return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
91
+ case 1:
92
+ response = (_a.sent()).map(function (value) { return [curve.formatUnits(value[0]), Number(curve.formatUnits(value[1], 0)) * 1000]; });
93
+ result = {};
94
+ addresses.forEach(function (addr, i) {
95
+ result[addr] = { lockedAmount: response[i][0], unlockTime: response[i][1] };
96
+ });
97
+ return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
98
+ }
99
+ });
100
+ });
64
101
  };
65
- export const createLockEstimateGas = async (amount, days) => {
66
- const crvBalance = await getCrv();
67
- if (Number(crvBalance) < Number(amount)) {
68
- throw Error(`Not enough . Actual: ${crvBalance}, required: ${amount}`);
69
- }
70
- if (!(await hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow))) {
71
- throw Error("Token allowance is needed to estimate gas");
102
+ export var getVeCrv = function () {
103
+ var addresses = [];
104
+ for (var _i = 0; _i < arguments.length; _i++) {
105
+ addresses[_i] = arguments[_i];
72
106
  }
73
- const _amount = parseUnits(amount);
74
- const unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
75
- return Number(await curve.contracts[curve.constants.ALIASES.voting_escrow].contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions));
76
- };
77
- export const calcUnlockTime = (days, start = Date.now()) => {
78
- const week = 86400 * 7;
79
- const now = start / 1000;
80
- const unlockTime = now + (86400 * days);
81
- return Math.floor(unlockTime / week) * week * 1000;
82
- };
83
- export const createLock = async (amount, days) => {
84
- const _amount = parseUnits(amount);
85
- const unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
86
- await _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false);
87
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
88
- await curve.updateFeeData();
89
- const gasLimit = mulBy1_3(await contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions));
90
- return (await contract.create_lock(_amount, unlockTime, { ...curve.options, gasLimit })).hash;
107
+ return __awaiter(void 0, void 0, void 0, function () {
108
+ var veContract, contractCalls, response, result;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0:
112
+ addresses = _prepareAddresses(addresses);
113
+ veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
114
+ contractCalls = addresses.map(function (address) { return veContract.balanceOf(address); });
115
+ return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
116
+ case 1:
117
+ response = (_a.sent()).map(function (value) { return curve.formatUnits(value); });
118
+ result = {};
119
+ addresses.forEach(function (addr, i) {
120
+ result[addr] = response[i];
121
+ });
122
+ return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
123
+ }
124
+ });
125
+ });
91
126
  };
92
- export const increaseAmountEstimateGas = async (amount) => {
93
- const crvBalance = await getCrv();
94
- if (Number(crvBalance) < Number(amount)) {
95
- throw Error(`Not enough. Actual: ${crvBalance}, required: ${amount}`);
127
+ export var getVeCrvPct = function () {
128
+ var addresses = [];
129
+ for (var _i = 0; _i < arguments.length; _i++) {
130
+ addresses[_i] = arguments[_i];
96
131
  }
97
- if (!(await hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow))) {
98
- throw Error("Token allowance is needed to estimate gas");
99
- }
100
- const _amount = parseUnits(amount);
101
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
102
- return Number(await contract.increase_amount.estimateGas(_amount, curve.constantOptions));
103
- };
104
- export const increaseAmount = async (amount) => {
105
- const _amount = parseUnits(amount);
106
- await _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false);
107
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
108
- await curve.updateFeeData();
109
- const gasLimit = mulBy1_3(await contract.increase_amount.estimateGas(_amount, curve.constantOptions));
110
- return (await contract.increase_amount(_amount, { ...curve.options, gasLimit })).hash;
111
- };
112
- export const increaseUnlockTimeEstimateGas = async (days) => {
113
- const { unlockTime } = await getLockedAmountAndUnlockTime();
114
- const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
115
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
116
- return Number(await contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions));
117
- };
118
- export const increaseUnlockTime = async (days) => {
119
- const { unlockTime } = await getLockedAmountAndUnlockTime();
120
- const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
121
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
122
- await curve.updateFeeData();
123
- const gasLimit = mulBy1_3(await contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions));
124
- return (await contract.increase_unlock_time(newUnlockTime, { ...curve.options, gasLimit })).hash;
125
- };
126
- export const withdrawLockedCrvEstimateGas = async () => {
127
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
128
- return Number(await contract.withdraw.estimateGas(curve.constantOptions));
132
+ return __awaiter(void 0, void 0, void 0, function () {
133
+ var veContract, contractCalls, response, veTotalSupply, resultBN, result, _a, _b, entry;
134
+ return __generator(this, function (_c) {
135
+ switch (_c.label) {
136
+ case 0:
137
+ addresses = _prepareAddresses(addresses);
138
+ veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
139
+ contractCalls = [veContract.totalSupply()];
140
+ addresses.forEach(function (address) {
141
+ contractCalls.push(veContract.balanceOf(address));
142
+ });
143
+ return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
144
+ case 1:
145
+ response = (_c.sent()).map(function (value) { return toBN(value); });
146
+ veTotalSupply = response.splice(0, 1)[0];
147
+ resultBN = {};
148
+ addresses.forEach(function (acct, i) {
149
+ resultBN[acct] = response[i].div(veTotalSupply).times(100);
150
+ });
151
+ result = {};
152
+ for (_a = 0, _b = Object.entries(resultBN); _a < _b.length; _a++) {
153
+ entry = _b[_a];
154
+ result[entry[0]] = toStringFromBN(entry[1]);
155
+ }
156
+ return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
157
+ }
158
+ });
159
+ });
129
160
  };
130
- export const withdrawLockedCrv = async () => {
131
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
132
- await curve.updateFeeData();
133
- const gasLimit = mulBy1_3(await contract.withdraw.estimateGas(curve.constantOptions));
134
- return (await contract.withdraw({ ...curve.options, gasLimit })).hash;
161
+ export var isApproved = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
162
+ return __generator(this, function (_a) {
163
+ switch (_a.label) {
164
+ case 0: return [4 /*yield*/, hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow)];
165
+ case 1: return [2 /*return*/, _a.sent()];
166
+ }
167
+ });
168
+ }); };
169
+ export var approveEstimateGas = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
170
+ return __generator(this, function (_a) {
171
+ switch (_a.label) {
172
+ case 0: return [4 /*yield*/, ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false)];
173
+ case 1: return [2 /*return*/, _a.sent()];
174
+ }
175
+ });
176
+ }); };
177
+ export var approve = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0: return [4 /*yield*/, ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false)];
181
+ case 1: return [2 /*return*/, _a.sent()];
182
+ }
183
+ });
184
+ }); };
185
+ export var createLockEstimateGas = function (amount, days) { return __awaiter(void 0, void 0, void 0, function () {
186
+ var crvBalance, _amount, unlockTime, _a;
187
+ return __generator(this, function (_b) {
188
+ switch (_b.label) {
189
+ case 0: return [4 /*yield*/, getCrv()];
190
+ case 1:
191
+ crvBalance = _b.sent();
192
+ if (Number(crvBalance) < Number(amount)) {
193
+ throw Error("Not enough . Actual: ".concat(crvBalance, ", required: ").concat(amount));
194
+ }
195
+ return [4 /*yield*/, hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow)];
196
+ case 2:
197
+ if (!(_b.sent())) {
198
+ throw Error("Token allowance is needed to estimate gas");
199
+ }
200
+ _amount = parseUnits(amount);
201
+ unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
202
+ _a = Number;
203
+ return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.voting_escrow].contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)];
204
+ case 3: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
205
+ }
206
+ });
207
+ }); };
208
+ export var calcUnlockTime = function (days, start) {
209
+ if (start === void 0) { start = Date.now(); }
210
+ var week = 86400 * 7;
211
+ var now = start / 1000;
212
+ var unlockTime = now + (86400 * days);
213
+ return Math.floor(unlockTime / week) * week * 1000;
135
214
  };
136
- export const claimableFees = async (address = "") => {
137
- address = address || curve.signerAddress;
138
- const contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
139
- return curve.formatUnits(await contract.claim(address, curve.constantOptions));
215
+ export var createLock = function (amount, days) { return __awaiter(void 0, void 0, void 0, function () {
216
+ var _amount, unlockTime, contract, gasLimit, _a;
217
+ return __generator(this, function (_b) {
218
+ switch (_b.label) {
219
+ case 0:
220
+ _amount = parseUnits(amount);
221
+ unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
222
+ return [4 /*yield*/, _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false)];
223
+ case 1:
224
+ _b.sent();
225
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
226
+ return [4 /*yield*/, curve.updateFeeData()];
227
+ case 2:
228
+ _b.sent();
229
+ _a = mulBy1_3;
230
+ return [4 /*yield*/, contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)];
231
+ case 3:
232
+ gasLimit = _a.apply(void 0, [_b.sent()]);
233
+ return [4 /*yield*/, contract.create_lock(_amount, unlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
234
+ case 4: return [2 /*return*/, (_b.sent()).hash];
235
+ }
236
+ });
237
+ }); };
238
+ export var increaseAmountEstimateGas = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
239
+ var crvBalance, _amount, contract, _a;
240
+ return __generator(this, function (_b) {
241
+ switch (_b.label) {
242
+ case 0: return [4 /*yield*/, getCrv()];
243
+ case 1:
244
+ crvBalance = _b.sent();
245
+ if (Number(crvBalance) < Number(amount)) {
246
+ throw Error("Not enough. Actual: ".concat(crvBalance, ", required: ").concat(amount));
247
+ }
248
+ return [4 /*yield*/, hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow)];
249
+ case 2:
250
+ if (!(_b.sent())) {
251
+ throw Error("Token allowance is needed to estimate gas");
252
+ }
253
+ _amount = parseUnits(amount);
254
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
255
+ _a = Number;
256
+ return [4 /*yield*/, contract.increase_amount.estimateGas(_amount, curve.constantOptions)];
257
+ case 3: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
258
+ }
259
+ });
260
+ }); };
261
+ export var increaseAmount = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
262
+ var _amount, contract, gasLimit, _a;
263
+ return __generator(this, function (_b) {
264
+ switch (_b.label) {
265
+ case 0:
266
+ _amount = parseUnits(amount);
267
+ return [4 /*yield*/, _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false)];
268
+ case 1:
269
+ _b.sent();
270
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
271
+ return [4 /*yield*/, curve.updateFeeData()];
272
+ case 2:
273
+ _b.sent();
274
+ _a = mulBy1_3;
275
+ return [4 /*yield*/, contract.increase_amount.estimateGas(_amount, curve.constantOptions)];
276
+ case 3:
277
+ gasLimit = _a.apply(void 0, [_b.sent()]);
278
+ return [4 /*yield*/, contract.increase_amount(_amount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
279
+ case 4: return [2 /*return*/, (_b.sent()).hash];
280
+ }
281
+ });
282
+ }); };
283
+ export var increaseUnlockTimeEstimateGas = function (days) { return __awaiter(void 0, void 0, void 0, function () {
284
+ var unlockTime, newUnlockTime, contract, _a;
285
+ return __generator(this, function (_b) {
286
+ switch (_b.label) {
287
+ case 0: return [4 /*yield*/, getLockedAmountAndUnlockTime()];
288
+ case 1:
289
+ unlockTime = (_b.sent()).unlockTime;
290
+ newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
291
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
292
+ _a = Number;
293
+ return [4 /*yield*/, contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)];
294
+ case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
295
+ }
296
+ });
297
+ }); };
298
+ export var increaseUnlockTime = function (days) { return __awaiter(void 0, void 0, void 0, function () {
299
+ var unlockTime, newUnlockTime, contract, gasLimit, _a;
300
+ return __generator(this, function (_b) {
301
+ switch (_b.label) {
302
+ case 0: return [4 /*yield*/, getLockedAmountAndUnlockTime()];
303
+ case 1:
304
+ unlockTime = (_b.sent()).unlockTime;
305
+ newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
306
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
307
+ return [4 /*yield*/, curve.updateFeeData()];
308
+ case 2:
309
+ _b.sent();
310
+ _a = mulBy1_3;
311
+ return [4 /*yield*/, contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)];
312
+ case 3:
313
+ gasLimit = _a.apply(void 0, [_b.sent()]);
314
+ return [4 /*yield*/, contract.increase_unlock_time(newUnlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
315
+ case 4: return [2 /*return*/, (_b.sent()).hash];
316
+ }
317
+ });
318
+ }); };
319
+ export var withdrawLockedCrvEstimateGas = function () { return __awaiter(void 0, void 0, void 0, function () {
320
+ var contract, _a;
321
+ return __generator(this, function (_b) {
322
+ switch (_b.label) {
323
+ case 0:
324
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
325
+ _a = Number;
326
+ return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
327
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
328
+ }
329
+ });
330
+ }); };
331
+ export var withdrawLockedCrv = function () { return __awaiter(void 0, void 0, void 0, function () {
332
+ var contract, gasLimit, _a;
333
+ return __generator(this, function (_b) {
334
+ switch (_b.label) {
335
+ case 0:
336
+ contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
337
+ return [4 /*yield*/, curve.updateFeeData()];
338
+ case 1:
339
+ _b.sent();
340
+ _a = mulBy1_3;
341
+ return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
342
+ case 2:
343
+ gasLimit = _a.apply(void 0, [_b.sent()]);
344
+ return [4 /*yield*/, contract.withdraw(__assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
345
+ case 3: return [2 /*return*/, (_b.sent()).hash];
346
+ }
347
+ });
348
+ }); };
349
+ export var claimableFees = function (address) {
350
+ if (address === void 0) { address = ""; }
351
+ return __awaiter(void 0, void 0, void 0, function () {
352
+ var contract, _a, _b;
353
+ return __generator(this, function (_c) {
354
+ switch (_c.label) {
355
+ case 0:
356
+ address = address || curve.signerAddress;
357
+ contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
358
+ _b = (_a = curve).formatUnits;
359
+ return [4 /*yield*/, contract.claim(address, curve.constantOptions)];
360
+ case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
361
+ }
362
+ });
363
+ });
140
364
  };
141
- export const claimFeesEstimateGas = async (address = "") => {
142
- address = address || curve.signerAddress;
143
- const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
144
- return Number(await contract.claim.estimateGas(address, curve.constantOptions));
365
+ export var claimFeesEstimateGas = function (address) {
366
+ if (address === void 0) { address = ""; }
367
+ return __awaiter(void 0, void 0, void 0, function () {
368
+ var contract, _a;
369
+ return __generator(this, function (_b) {
370
+ switch (_b.label) {
371
+ case 0:
372
+ address = address || curve.signerAddress;
373
+ contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
374
+ _a = Number;
375
+ return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
376
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
377
+ }
378
+ });
379
+ });
145
380
  };
146
- export const claimFees = async (address = "") => {
147
- address = address || curve.signerAddress;
148
- const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
149
- await curve.updateFeeData();
150
- const gasLimit = mulBy1_3(await contract.claim.estimateGas(address, curve.constantOptions));
151
- return (await contract.claim(address, { ...curve.options, gasLimit })).hash;
381
+ export var claimFees = function (address) {
382
+ if (address === void 0) { address = ""; }
383
+ return __awaiter(void 0, void 0, void 0, function () {
384
+ var contract, gasLimit, _a;
385
+ return __generator(this, function (_b) {
386
+ switch (_b.label) {
387
+ case 0:
388
+ address = address || curve.signerAddress;
389
+ contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
390
+ return [4 /*yield*/, curve.updateFeeData()];
391
+ case 1:
392
+ _b.sent();
393
+ _a = mulBy1_3;
394
+ return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
395
+ case 2:
396
+ gasLimit = _a.apply(void 0, [_b.sent()]);
397
+ return [4 /*yield*/, contract.claim(address, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
398
+ case 3: return [2 /*return*/, (_b.sent()).hash];
399
+ }
400
+ });
401
+ });
152
402
  };