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