@curvefi/api 2.63.0 → 2.63.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/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 +3 -1
- 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 +1 -6
- package/lib/pools/PoolTemplate.js +1773 -3025
- 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 +5 -25
- 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 +5 -4
- package/lib/utils.js +539 -918
- package/package.json +1 -1
package/lib/boosting.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,33 +7,6 @@ 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 { Contract } from "ethers";
|
|
49
11
|
import { curve } from "./curve.js";
|
|
50
12
|
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
|
|
@@ -52,617 +14,257 @@ import feeDistributorCrvUSDViewABI from "./constants/abis/fee_distributor_crvusd
|
|
|
52
14
|
import { _getBalances, _prepareAddresses, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, smartNumber, } from "./utils.js";
|
|
53
15
|
import { _ensureAllowance, toBN, toStringFromBN, parseUnits } from './utils.js';
|
|
54
16
|
import { _generateBoostingProof } from './external-api.js';
|
|
55
|
-
export
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
17
|
+
export const getCrv = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
addresses = _prepareAddresses(addresses);
|
|
19
|
+
const rawBalances = (yield _getBalances([curve.constants.ALIASES.crv], addresses));
|
|
20
|
+
const balances = {};
|
|
21
|
+
for (const address of addresses) {
|
|
22
|
+
balances[address] = rawBalances[address].shift();
|
|
59
23
|
}
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
24
|
+
return addresses.length === 1 ? balances[addresses[0]] : balances;
|
|
25
|
+
});
|
|
26
|
+
export const getLockedAmountAndUnlockTime = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
addresses = _prepareAddresses(addresses);
|
|
28
|
+
const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
29
|
+
const contractCalls = addresses.map((address) => veContract.locked(address));
|
|
30
|
+
const response = (yield curve.multicallProvider.all(contractCalls)).map((value) => [curve.formatUnits(value[0]), Number(curve.formatUnits(value[1], 0)) * 1000]);
|
|
31
|
+
const result = {};
|
|
32
|
+
addresses.forEach((addr, i) => {
|
|
33
|
+
result[addr] = { lockedAmount: response[i][0], unlockTime: response[i][1] };
|
|
34
|
+
});
|
|
35
|
+
return addresses.length === 1 ? result[addresses[0]] : result;
|
|
36
|
+
});
|
|
37
|
+
export const getVeCrv = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
addresses = _prepareAddresses(addresses);
|
|
39
|
+
const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
40
|
+
const contractCalls = addresses.map((address) => veContract.balanceOf(address));
|
|
41
|
+
const response = (yield curve.multicallProvider.all(contractCalls)).map((value) => curve.formatUnits(value));
|
|
42
|
+
const result = {};
|
|
43
|
+
addresses.forEach((addr, i) => {
|
|
44
|
+
result[addr] = response[i];
|
|
45
|
+
});
|
|
46
|
+
return addresses.length === 1 ? result[addresses[0]] : result;
|
|
47
|
+
});
|
|
48
|
+
export const getVeCrvPct = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
addresses = _prepareAddresses(addresses);
|
|
50
|
+
const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
51
|
+
const contractCalls = [veContract.totalSupply()];
|
|
52
|
+
addresses.forEach((address) => {
|
|
53
|
+
contractCalls.push(veContract.balanceOf(address));
|
|
54
|
+
});
|
|
55
|
+
const response = (yield curve.multicallProvider.all(contractCalls)).map((value) => toBN(value));
|
|
56
|
+
const [veTotalSupply] = response.splice(0, 1);
|
|
57
|
+
const resultBN = {};
|
|
58
|
+
addresses.forEach((acct, i) => {
|
|
59
|
+
resultBN[acct] = response[i].div(veTotalSupply).times(100);
|
|
60
|
+
});
|
|
61
|
+
const result = {};
|
|
62
|
+
for (const entry of Object.entries(resultBN)) {
|
|
63
|
+
result[entry[0]] = toStringFromBN(entry[1]);
|
|
83
64
|
}
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
export var getVeCrv = function () {
|
|
105
|
-
var addresses = [];
|
|
106
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
107
|
-
addresses[_i] = arguments[_i];
|
|
65
|
+
return addresses.length === 1 ? result[addresses[0]] : result;
|
|
66
|
+
});
|
|
67
|
+
export const isApproved = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
return yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow);
|
|
69
|
+
});
|
|
70
|
+
export const approveEstimateGas = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
return yield ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
|
|
72
|
+
});
|
|
73
|
+
export const approve = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
return yield ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
|
|
75
|
+
});
|
|
76
|
+
export const createLockEstimateGas = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
const crvBalance = yield getCrv();
|
|
78
|
+
if (Number(crvBalance) < Number(amount)) {
|
|
79
|
+
throw Error(`Not enough . Actual: ${crvBalance}, required: ${amount}`);
|
|
108
80
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return __generator(this, function (_a) {
|
|
112
|
-
switch (_a.label) {
|
|
113
|
-
case 0:
|
|
114
|
-
addresses = _prepareAddresses(addresses);
|
|
115
|
-
veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
116
|
-
contractCalls = addresses.map(function (address) { return veContract.balanceOf(address); });
|
|
117
|
-
return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
|
|
118
|
-
case 1:
|
|
119
|
-
response = (_a.sent()).map(function (value) { return curve.formatUnits(value); });
|
|
120
|
-
result = {};
|
|
121
|
-
addresses.forEach(function (addr, i) {
|
|
122
|
-
result[addr] = response[i];
|
|
123
|
-
});
|
|
124
|
-
return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
export var getVeCrvPct = function () {
|
|
130
|
-
var addresses = [];
|
|
131
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
132
|
-
addresses[_i] = arguments[_i];
|
|
81
|
+
if (!(yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow))) {
|
|
82
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
133
83
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
addresses.forEach(function (address) {
|
|
143
|
-
contractCalls.push(veContract.balanceOf(address));
|
|
144
|
-
});
|
|
145
|
-
return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
|
|
146
|
-
case 1:
|
|
147
|
-
response = (_c.sent()).map(function (value) { return toBN(value); });
|
|
148
|
-
veTotalSupply = response.splice(0, 1)[0];
|
|
149
|
-
resultBN = {};
|
|
150
|
-
addresses.forEach(function (acct, i) {
|
|
151
|
-
resultBN[acct] = response[i].div(veTotalSupply).times(100);
|
|
152
|
-
});
|
|
153
|
-
result = {};
|
|
154
|
-
for (_a = 0, _b = Object.entries(resultBN); _a < _b.length; _a++) {
|
|
155
|
-
entry = _b[_a];
|
|
156
|
-
result[entry[0]] = toStringFromBN(entry[1]);
|
|
157
|
-
}
|
|
158
|
-
return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
export var isApproved = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
164
|
-
return __generator(this, function (_a) {
|
|
165
|
-
switch (_a.label) {
|
|
166
|
-
case 0: return [4 /*yield*/, hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow)];
|
|
167
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}); };
|
|
171
|
-
export var approveEstimateGas = 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*/, ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false)];
|
|
175
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}); };
|
|
179
|
-
export var approve = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
180
|
-
return __generator(this, function (_a) {
|
|
181
|
-
switch (_a.label) {
|
|
182
|
-
case 0: return [4 /*yield*/, ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false)];
|
|
183
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}); };
|
|
187
|
-
export var createLockEstimateGas = function (amount, days) { return __awaiter(void 0, void 0, void 0, function () {
|
|
188
|
-
var crvBalance, _amount, unlockTime, _a;
|
|
189
|
-
return __generator(this, function (_b) {
|
|
190
|
-
switch (_b.label) {
|
|
191
|
-
case 0: return [4 /*yield*/, getCrv()];
|
|
192
|
-
case 1:
|
|
193
|
-
crvBalance = _b.sent();
|
|
194
|
-
if (Number(crvBalance) < Number(amount)) {
|
|
195
|
-
throw Error("Not enough . Actual: ".concat(crvBalance, ", required: ").concat(amount));
|
|
196
|
-
}
|
|
197
|
-
return [4 /*yield*/, hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow)];
|
|
198
|
-
case 2:
|
|
199
|
-
if (!(_b.sent())) {
|
|
200
|
-
throw Error("Token allowance is needed to estimate gas");
|
|
201
|
-
}
|
|
202
|
-
_amount = parseUnits(amount);
|
|
203
|
-
unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
|
|
204
|
-
_a = Number;
|
|
205
|
-
return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.voting_escrow].contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)];
|
|
206
|
-
case 3: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}); };
|
|
210
|
-
export var calcUnlockTime = function (days, start) {
|
|
211
|
-
if (start === void 0) { start = Date.now(); }
|
|
212
|
-
var week = 86400 * 7;
|
|
213
|
-
var now = start / 1000;
|
|
214
|
-
var unlockTime = now + (86400 * days);
|
|
84
|
+
const _amount = parseUnits(amount);
|
|
85
|
+
const unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
|
|
86
|
+
return Number(yield curve.contracts[curve.constants.ALIASES.voting_escrow].contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions));
|
|
87
|
+
});
|
|
88
|
+
export const calcUnlockTime = (days, start = Date.now()) => {
|
|
89
|
+
const week = 86400 * 7;
|
|
90
|
+
const now = start / 1000;
|
|
91
|
+
const unlockTime = now + (86400 * days);
|
|
215
92
|
return Math.floor(unlockTime / week) * week * 1000;
|
|
216
93
|
};
|
|
217
|
-
export
|
|
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
|
-
export
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
case 2:
|
|
314
|
-
_c.sent();
|
|
315
|
-
_a = mulBy1_3;
|
|
316
|
-
_b = DIGas;
|
|
317
|
-
return [4 /*yield*/, contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)];
|
|
318
|
-
case 3:
|
|
319
|
-
gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
|
|
320
|
-
return [4 /*yield*/, contract.increase_unlock_time(newUnlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
321
|
-
case 4: return [2 /*return*/, (_c.sent()).hash];
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
}); };
|
|
325
|
-
export var withdrawLockedCrvEstimateGas = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
326
|
-
var contract, _a, _b;
|
|
327
|
-
return __generator(this, function (_c) {
|
|
328
|
-
switch (_c.label) {
|
|
329
|
-
case 0:
|
|
330
|
-
contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
331
|
-
_a = Number;
|
|
332
|
-
_b = DIGas;
|
|
333
|
-
return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
|
|
334
|
-
case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [_c.sent()])])];
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}); };
|
|
338
|
-
export var withdrawLockedCrv = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
339
|
-
var contract, gasLimit, _a, _b;
|
|
340
|
-
return __generator(this, function (_c) {
|
|
341
|
-
switch (_c.label) {
|
|
342
|
-
case 0:
|
|
343
|
-
contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
344
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
345
|
-
case 1:
|
|
346
|
-
_c.sent();
|
|
347
|
-
_a = mulBy1_3;
|
|
348
|
-
_b = DIGas;
|
|
349
|
-
return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
|
|
350
|
-
case 2:
|
|
351
|
-
gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
|
|
352
|
-
return [4 /*yield*/, contract.withdraw(__assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
353
|
-
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}); };
|
|
357
|
-
export var claimableFees = function (address) {
|
|
358
|
-
if (address === void 0) { address = ""; }
|
|
359
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
360
|
-
var contract, _a, _b;
|
|
361
|
-
return __generator(this, function (_c) {
|
|
362
|
-
switch (_c.label) {
|
|
363
|
-
case 0:
|
|
364
|
-
address = address || curve.signerAddress;
|
|
365
|
-
contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
|
|
366
|
-
_b = (_a = curve).formatUnits;
|
|
367
|
-
return [4 /*yield*/, contract.claim(address, curve.constantOptions)];
|
|
368
|
-
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
};
|
|
373
|
-
export var claimFeesEstimateGas = function (address) {
|
|
374
|
-
if (address === void 0) { address = ""; }
|
|
375
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
376
|
-
var contract, _a, _b;
|
|
377
|
-
return __generator(this, function (_c) {
|
|
378
|
-
switch (_c.label) {
|
|
379
|
-
case 0:
|
|
380
|
-
address = address || curve.signerAddress;
|
|
381
|
-
contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
|
|
382
|
-
_a = Number;
|
|
383
|
-
_b = DIGas;
|
|
384
|
-
return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
|
|
385
|
-
case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [_c.sent()])])];
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
export var claimFees = function (address) {
|
|
391
|
-
if (address === void 0) { address = ""; }
|
|
392
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
393
|
-
var contract, gasLimit, _a, _b;
|
|
394
|
-
return __generator(this, function (_c) {
|
|
395
|
-
switch (_c.label) {
|
|
396
|
-
case 0:
|
|
397
|
-
if (curve.chainId !== 1) {
|
|
398
|
-
throw Error('This method is only available for the network with chainId 1');
|
|
399
|
-
}
|
|
400
|
-
address = address || curve.signerAddress;
|
|
401
|
-
contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
|
|
402
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
403
|
-
case 1:
|
|
404
|
-
_c.sent();
|
|
405
|
-
_a = mulBy1_3;
|
|
406
|
-
_b = DIGas;
|
|
407
|
-
return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
|
|
408
|
-
case 2:
|
|
409
|
-
gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
|
|
410
|
-
return [4 /*yield*/, contract.claim(address, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
411
|
-
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
};
|
|
416
|
-
export var claimableFeesCrvUSD = function (address) {
|
|
417
|
-
if (address === void 0) { address = ""; }
|
|
418
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
419
|
-
var contract, _a, _b;
|
|
420
|
-
return __generator(this, function (_c) {
|
|
421
|
-
switch (_c.label) {
|
|
422
|
-
case 0:
|
|
423
|
-
if (curve.chainId !== 1) {
|
|
424
|
-
throw Error('This method is only available for the network with chainId 1');
|
|
425
|
-
}
|
|
426
|
-
address = address || curve.signerAddress;
|
|
427
|
-
contract = new Contract(curve.constants.ALIASES.fee_distributor_crvusd, feeDistributorCrvUSDViewABI, curve.provider);
|
|
428
|
-
_b = (_a = curve).formatUnits;
|
|
429
|
-
return [4 /*yield*/, contract.claim(address, curve.constantOptions)];
|
|
430
|
-
case 1: return [2 /*return*/, _b.apply(_a, [_c.sent()])];
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
export var claimFeesCrvUSDEstimateGas = function (address) {
|
|
436
|
-
if (address === void 0) { address = ""; }
|
|
437
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
438
|
-
var contract, _a, _b;
|
|
439
|
-
return __generator(this, function (_c) {
|
|
440
|
-
switch (_c.label) {
|
|
441
|
-
case 0:
|
|
442
|
-
if (curve.chainId !== 1) {
|
|
443
|
-
throw Error('This method is only available for the network with chainId 1');
|
|
444
|
-
}
|
|
445
|
-
address = address || curve.signerAddress;
|
|
446
|
-
contract = curve.contracts[curve.constants.ALIASES.fee_distributor_crvusd].contract;
|
|
447
|
-
_a = Number;
|
|
448
|
-
_b = DIGas;
|
|
449
|
-
return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
|
|
450
|
-
case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [_c.sent()])])];
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
};
|
|
455
|
-
export var claimFeesCrvUSD = function (address) {
|
|
456
|
-
if (address === void 0) { address = ""; }
|
|
457
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
458
|
-
var contract, gasLimit, _a, _b;
|
|
459
|
-
return __generator(this, function (_c) {
|
|
460
|
-
switch (_c.label) {
|
|
461
|
-
case 0:
|
|
462
|
-
address = address || curve.signerAddress;
|
|
463
|
-
contract = curve.contracts[curve.constants.ALIASES.fee_distributor_crvusd].contract;
|
|
464
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
465
|
-
case 1:
|
|
466
|
-
_c.sent();
|
|
467
|
-
_a = mulBy1_3;
|
|
468
|
-
_b = DIGas;
|
|
469
|
-
return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
|
|
470
|
-
case 2:
|
|
471
|
-
gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
|
|
472
|
-
return [4 /*yield*/, contract.claim(address, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
473
|
-
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
};
|
|
94
|
+
export const createLock = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const _amount = parseUnits(amount);
|
|
96
|
+
const unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
|
|
97
|
+
yield _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false);
|
|
98
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
99
|
+
yield curve.updateFeeData();
|
|
100
|
+
const gasLimit = mulBy1_3(DIGas(yield contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)));
|
|
101
|
+
return (yield contract.create_lock(_amount, unlockTime, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
102
|
+
});
|
|
103
|
+
export const increaseAmountEstimateGas = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
const crvBalance = yield getCrv();
|
|
105
|
+
if (Number(crvBalance) < Number(amount)) {
|
|
106
|
+
throw Error(`Not enough. Actual: ${crvBalance}, required: ${amount}`);
|
|
107
|
+
}
|
|
108
|
+
if (!(yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow))) {
|
|
109
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
110
|
+
}
|
|
111
|
+
const _amount = parseUnits(amount);
|
|
112
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
113
|
+
return Number(yield contract.increase_amount.estimateGas(_amount, curve.constantOptions));
|
|
114
|
+
});
|
|
115
|
+
export const increaseAmount = (amount) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
const _amount = parseUnits(amount);
|
|
117
|
+
yield _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false);
|
|
118
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
119
|
+
yield curve.updateFeeData();
|
|
120
|
+
const gasLimit = mulBy1_3(DIGas(yield contract.increase_amount.estimateGas(_amount, curve.constantOptions)));
|
|
121
|
+
return (yield contract.increase_amount(_amount, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
122
|
+
});
|
|
123
|
+
export const increaseUnlockTimeEstimateGas = (days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
const { unlockTime } = yield getLockedAmountAndUnlockTime();
|
|
125
|
+
const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
|
|
126
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
127
|
+
return Number(DIGas(yield contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)));
|
|
128
|
+
});
|
|
129
|
+
export const increaseUnlockTime = (days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
const { unlockTime } = yield getLockedAmountAndUnlockTime();
|
|
131
|
+
const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
|
|
132
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
133
|
+
yield curve.updateFeeData();
|
|
134
|
+
const gasLimit = mulBy1_3(DIGas(yield contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)));
|
|
135
|
+
return (yield contract.increase_unlock_time(newUnlockTime, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
136
|
+
});
|
|
137
|
+
export const withdrawLockedCrvEstimateGas = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
139
|
+
return Number(DIGas(yield contract.withdraw.estimateGas(curve.constantOptions)));
|
|
140
|
+
});
|
|
141
|
+
export const withdrawLockedCrv = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
|
+
const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
|
|
143
|
+
yield curve.updateFeeData();
|
|
144
|
+
const gasLimit = mulBy1_3(DIGas(yield contract.withdraw.estimateGas(curve.constantOptions)));
|
|
145
|
+
return (yield contract.withdraw(Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
146
|
+
});
|
|
147
|
+
export const claimableFees = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
|
+
address = address || curve.signerAddress;
|
|
149
|
+
const contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
|
|
150
|
+
return curve.formatUnits(yield contract.claim(address, curve.constantOptions));
|
|
151
|
+
});
|
|
152
|
+
export const claimFeesEstimateGas = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
+
address = address || curve.signerAddress;
|
|
154
|
+
const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
|
|
155
|
+
return Number(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
|
|
156
|
+
});
|
|
157
|
+
export const claimFees = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
if (curve.chainId !== 1) {
|
|
159
|
+
throw Error('This method is only available for the network with chainId 1');
|
|
160
|
+
}
|
|
161
|
+
address = address || curve.signerAddress;
|
|
162
|
+
const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
|
|
163
|
+
yield curve.updateFeeData();
|
|
164
|
+
const gasLimit = mulBy1_3(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
|
|
165
|
+
return (yield contract.claim(address, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
166
|
+
});
|
|
167
|
+
export const claimableFeesCrvUSD = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
+
if (curve.chainId !== 1) {
|
|
169
|
+
throw Error('This method is only available for the network with chainId 1');
|
|
170
|
+
}
|
|
171
|
+
address = address || curve.signerAddress;
|
|
172
|
+
const contract = new Contract(curve.constants.ALIASES.fee_distributor_crvusd, feeDistributorCrvUSDViewABI, curve.provider);
|
|
173
|
+
return curve.formatUnits(yield contract.claim(address, curve.constantOptions));
|
|
174
|
+
});
|
|
175
|
+
export const claimFeesCrvUSDEstimateGas = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
+
if (curve.chainId !== 1) {
|
|
177
|
+
throw Error('This method is only available for the network with chainId 1');
|
|
178
|
+
}
|
|
179
|
+
address = address || curve.signerAddress;
|
|
180
|
+
const contract = curve.contracts[curve.constants.ALIASES.fee_distributor_crvusd].contract;
|
|
181
|
+
return Number(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
|
|
182
|
+
});
|
|
183
|
+
export const claimFeesCrvUSD = (address = "") => __awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
address = address || curve.signerAddress;
|
|
185
|
+
const contract = curve.contracts[curve.constants.ALIASES.fee_distributor_crvusd].contract;
|
|
186
|
+
yield curve.updateFeeData();
|
|
187
|
+
const gasLimit = mulBy1_3(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
|
|
188
|
+
return (yield contract.claim(address, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
189
|
+
});
|
|
478
190
|
// ------------ SIDECHAIN ------------
|
|
479
|
-
export
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
-
return
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if (curve.chainId !== 1)
|
|
560
|
-
throw Error("lastBlockNumberSent method is on ethereum network only");
|
|
561
|
-
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
562
|
-
_a = Number;
|
|
563
|
-
return [4 /*yield*/, veOracleContract.get_last_block_number_sent(chainId, curve.constantOptions)];
|
|
564
|
-
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
}); };
|
|
568
|
-
export var blockToSend = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
569
|
-
return __generator(this, function (_a) {
|
|
570
|
-
switch (_a.label) {
|
|
571
|
-
case 0:
|
|
572
|
-
if (curve.chainId !== 1)
|
|
573
|
-
throw Error("blockToSend method is on ethereum network only");
|
|
574
|
-
return [4 /*yield*/, curve.provider.getBlockNumber()];
|
|
575
|
-
case 1: return [2 /*return*/, (_a.sent()) - 128];
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
}); };
|
|
579
|
-
var _sendBlockhash = function (block, chainId, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
580
|
-
var veOracleContract, gas, gasLimit;
|
|
581
|
-
return __generator(this, function (_a) {
|
|
582
|
-
switch (_a.label) {
|
|
583
|
-
case 0:
|
|
584
|
-
if (curve.chainId !== 1)
|
|
585
|
-
throw Error("sendBlockhash method is on ethereum network only");
|
|
586
|
-
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
587
|
-
return [4 /*yield*/, veOracleContract.send_blockhash.estimateGas(block, chainId, curve.constantOptions)];
|
|
588
|
-
case 1:
|
|
589
|
-
gas = _a.sent();
|
|
590
|
-
if (estimateGas)
|
|
591
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
592
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
593
|
-
case 2:
|
|
594
|
-
_a.sent();
|
|
595
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
596
|
-
return [4 /*yield*/, veOracleContract.send_blockhash(block, chainId, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
597
|
-
case 3: return [2 /*return*/, (_a.sent()).hash];
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
}); };
|
|
601
|
-
export var sendBlockhashEstimateGas = function (block, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
602
|
-
return __generator(this, function (_a) {
|
|
603
|
-
switch (_a.label) {
|
|
604
|
-
case 0: return [4 /*yield*/, _sendBlockhash(block, chainId, true)];
|
|
605
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
}); };
|
|
609
|
-
export var sendBlockhash = function (block, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
610
|
-
return __generator(this, function (_a) {
|
|
611
|
-
switch (_a.label) {
|
|
612
|
-
case 0: return [4 /*yield*/, _sendBlockhash(block, chainId, false)];
|
|
613
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
}); };
|
|
617
|
-
var _submitProof = function (block, address, estimateGas) {
|
|
618
|
-
if (address === void 0) { address = curve.signerAddress; }
|
|
619
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
620
|
-
var proof, veOracleContract, gas, gasLimit;
|
|
621
|
-
return __generator(this, function (_a) {
|
|
622
|
-
switch (_a.label) {
|
|
623
|
-
case 0:
|
|
624
|
-
if (curve.chainId === 1)
|
|
625
|
-
throw Error("submitProof method is on ethereum network only");
|
|
626
|
-
if (address === "")
|
|
627
|
-
throw Error("Pass address you want to submit proof for");
|
|
628
|
-
return [4 /*yield*/, _generateBoostingProof(block, address)];
|
|
629
|
-
case 1:
|
|
630
|
-
proof = _a.sent();
|
|
631
|
-
veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
632
|
-
return [4 /*yield*/, veOracleContract.submit_state.estimateGas(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, curve.constantOptions)];
|
|
633
|
-
case 2:
|
|
634
|
-
gas = _a.sent();
|
|
635
|
-
if (estimateGas)
|
|
636
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
637
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
638
|
-
case 3:
|
|
639
|
-
_a.sent();
|
|
640
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
641
|
-
return [4 /*yield*/, veOracleContract.submit_state(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
642
|
-
case 4: return [2 /*return*/, (_a.sent()).hash];
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
});
|
|
646
|
-
};
|
|
647
|
-
export var submitProofEstimateGas = function (block, address) {
|
|
648
|
-
if (address === void 0) { address = curve.signerAddress; }
|
|
649
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
650
|
-
return __generator(this, function (_a) {
|
|
651
|
-
switch (_a.label) {
|
|
652
|
-
case 0: return [4 /*yield*/, _submitProof(block, address, true)];
|
|
653
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
};
|
|
658
|
-
export var submitProof = function (block, address) {
|
|
659
|
-
if (address === void 0) { address = curve.signerAddress; }
|
|
660
|
-
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*/, _submitProof(block, address, false)];
|
|
664
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
};
|
|
191
|
+
export const lastEthBlock = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
192
|
+
if (curve.chainId === 1)
|
|
193
|
+
throw Error("There is no lastBlock method on ethereum network");
|
|
194
|
+
const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
195
|
+
return Number(yield veOracleContract.last_eth_block_number(curve.constantOptions));
|
|
196
|
+
});
|
|
197
|
+
export const getAnycallBalance = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
198
|
+
if (curve.chainId === 1)
|
|
199
|
+
throw Error("There is no getAnycallBalance method on ethereum network");
|
|
200
|
+
const anycallContract = curve.contracts[curve.constants.ALIASES.anycall].contract;
|
|
201
|
+
const _balance = yield anycallContract.executionBudget(curve.constants.ALIASES.voting_escrow_oracle, curve.constantOptions);
|
|
202
|
+
return curve.formatUnits(_balance);
|
|
203
|
+
});
|
|
204
|
+
const DEFAULT_AMOUNT = (curve.chainId === 42161 || curve.chainId === 10) ? 0.00001 : 0.1;
|
|
205
|
+
const _topUpAnycall = (amount, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
206
|
+
if (curve.chainId === 1)
|
|
207
|
+
throw Error("There is no topUpAnycall method on ethereum network");
|
|
208
|
+
const anycallContract = curve.contracts[curve.constants.ALIASES.anycall].contract;
|
|
209
|
+
const value = curve.parseUnits(String(amount));
|
|
210
|
+
const gas = yield anycallContract.deposit.estimateGas(curve.constants.ALIASES.voting_escrow_oracle, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
211
|
+
if (estimateGas)
|
|
212
|
+
return smartNumber(gas);
|
|
213
|
+
yield curve.updateFeeData();
|
|
214
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
215
|
+
return (yield anycallContract.deposit(curve.constants.ALIASES.voting_escrow_oracle, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
|
|
216
|
+
});
|
|
217
|
+
export const topUpAnycallEstimateGas = (amount = DEFAULT_AMOUNT) => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
+
return yield _topUpAnycall(amount, true);
|
|
219
|
+
});
|
|
220
|
+
export const topUpAnycall = (amount = DEFAULT_AMOUNT) => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
+
return yield _topUpAnycall(amount, false);
|
|
222
|
+
});
|
|
223
|
+
export const lastBlockSent = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
+
if (curve.chainId !== 1)
|
|
225
|
+
throw Error("lastBlockNumberSent method is on ethereum network only");
|
|
226
|
+
const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
227
|
+
return Number(yield veOracleContract.get_last_block_number_sent(chainId, curve.constantOptions));
|
|
228
|
+
});
|
|
229
|
+
export const blockToSend = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
+
if (curve.chainId !== 1)
|
|
231
|
+
throw Error("blockToSend method is on ethereum network only");
|
|
232
|
+
return (yield curve.provider.getBlockNumber()) - 128;
|
|
233
|
+
});
|
|
234
|
+
const _sendBlockhash = (block, chainId, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
235
|
+
if (curve.chainId !== 1)
|
|
236
|
+
throw Error("sendBlockhash method is on ethereum network only");
|
|
237
|
+
const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
238
|
+
const gas = yield veOracleContract.send_blockhash.estimateGas(block, chainId, curve.constantOptions);
|
|
239
|
+
if (estimateGas)
|
|
240
|
+
return smartNumber(gas);
|
|
241
|
+
yield curve.updateFeeData();
|
|
242
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
243
|
+
return (yield veOracleContract.send_blockhash(block, chainId, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
244
|
+
});
|
|
245
|
+
export const sendBlockhashEstimateGas = (block, chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
246
|
+
return yield _sendBlockhash(block, chainId, true);
|
|
247
|
+
});
|
|
248
|
+
export const sendBlockhash = (block, chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
+
return yield _sendBlockhash(block, chainId, false);
|
|
250
|
+
});
|
|
251
|
+
const _submitProof = (block, address = curve.signerAddress, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
+
if (curve.chainId === 1)
|
|
253
|
+
throw Error("submitProof method is on ethereum network only");
|
|
254
|
+
if (address === "")
|
|
255
|
+
throw Error("Pass address you want to submit proof for");
|
|
256
|
+
const proof = yield _generateBoostingProof(block, address);
|
|
257
|
+
const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
|
|
258
|
+
const gas = yield veOracleContract.submit_state.estimateGas(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, curve.constantOptions);
|
|
259
|
+
if (estimateGas)
|
|
260
|
+
return smartNumber(gas);
|
|
261
|
+
yield curve.updateFeeData();
|
|
262
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
263
|
+
return (yield veOracleContract.submit_state(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
264
|
+
});
|
|
265
|
+
export const submitProofEstimateGas = (block, address = curve.signerAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
266
|
+
return yield _submitProof(block, address, true);
|
|
267
|
+
});
|
|
268
|
+
export const submitProof = (block, address = curve.signerAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
269
|
+
return yield _submitProof(block, address, false);
|
|
270
|
+
});
|