@curvefi/api 2.31.1 → 2.33.0
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 +385 -135
- package/lib/constants/abis/stable_calc.json +151 -0
- package/lib/constants/abis/wbeth/swap.json +1086 -0
- package/lib/constants/aliases.js +33 -11
- 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/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +10 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/kava.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/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/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +26 -1
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/kava.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/utils.d.ts +1 -1
- package/lib/constants/utils.js +19 -18
- package/lib/curve.js +507 -281
- package/lib/external-api.js +132 -45
- package/lib/factory/common.js +3 -3
- package/lib/factory/constants-crypto.js +21 -21
- package/lib/factory/constants.js +32 -31
- package/lib/factory/deploy.js +336 -176
- package/lib/factory/factory-api.js +256 -180
- package/lib/factory/factory-crypto.js +309 -163
- package/lib/factory/factory.d.ts +1 -1
- package/lib/factory/factory.js +336 -186
- package/lib/index.js +98 -44
- package/lib/interfaces.d.ts +1 -1
- package/lib/pools/PoolTemplate.js +2882 -1511
- package/lib/pools/mixins/common.js +106 -22
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
- package/lib/pools/mixins/depositMixins.js +413 -144
- package/lib/pools/mixins/depositWrappedMixins.js +223 -72
- package/lib/pools/mixins/poolBalancesMixin.js +98 -22
- package/lib/pools/mixins/swapMixins.js +347 -125
- package/lib/pools/mixins/swapWrappedMixins.js +270 -88
- package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
- package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
- package/lib/pools/mixins/withdrawMixins.js +385 -122
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
- package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
- package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
- package/lib/pools/poolConstructor.js +25 -5
- package/lib/pools/utils.js +488 -298
- package/lib/router.js +636 -378
- package/lib/utils.js +675 -354
- package/package.json +1 -1
|
@@ -1,737 +1,1066 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
+
if (ar || !(i in from)) {
|
|
51
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
1
57
|
import memoize from "memoizee";
|
|
2
58
|
import { _getPoolsFromApi, _getSubgraphData, _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes } from '../external-api.js';
|
|
3
59
|
import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, } from '../utils.js';
|
|
4
60
|
import { curve as _curve, curve } from "../curve.js";
|
|
5
61
|
import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
var DAY = 86400;
|
|
63
|
+
var WEEK = 7 * DAY;
|
|
64
|
+
var MONTH = 30 * DAY;
|
|
65
|
+
var YEAR = 365 * DAY;
|
|
66
|
+
var PoolTemplate = /** @class */ (function () {
|
|
67
|
+
function PoolTemplate(id) {
|
|
68
|
+
var _this = this;
|
|
69
|
+
var _c, _d;
|
|
70
|
+
this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
71
|
+
var multicallContract, lpMulticallContract, calls, i, additionalCalls, _virtualPrice, _fee, _prices, _adminFee, _A, _lpTokenSupply, _gamma, e_1, _c, virtualPrice, fee, adminFee, A, lpTokenSupply, gamma, priceOracle, priceScale, prices, i, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
|
|
72
|
+
var _f, _g, _h;
|
|
73
|
+
return __generator(this, function (_j) {
|
|
74
|
+
switch (_j.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
multicallContract = curve.contracts[this.address].multicallContract;
|
|
77
|
+
lpMulticallContract = curve.contracts[this.lpToken].multicallContract;
|
|
78
|
+
calls = [
|
|
79
|
+
multicallContract.get_virtual_price(),
|
|
80
|
+
multicallContract.fee(),
|
|
81
|
+
multicallContract.admin_fee(),
|
|
82
|
+
multicallContract.A(),
|
|
83
|
+
lpMulticallContract.totalSupply(),
|
|
84
|
+
];
|
|
85
|
+
if (this.isCrypto) {
|
|
86
|
+
calls.push(multicallContract.gamma());
|
|
87
|
+
if (this.wrappedCoins.length === 2) {
|
|
88
|
+
calls.push(multicallContract.price_oracle());
|
|
89
|
+
calls.push(multicallContract.price_scale());
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
for (i = 0; i < this.wrappedCoins.length - 1; i++) {
|
|
93
|
+
calls.push(multicallContract.price_oracle(i));
|
|
94
|
+
calls.push(multicallContract.price_scale(i));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
|
|
99
|
+
if ('initial_A' in multicallContract) {
|
|
100
|
+
additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
|
|
101
|
+
}
|
|
102
|
+
_virtualPrice = curve.parseUnits("0");
|
|
103
|
+
_fee = curve.parseUnits("0");
|
|
104
|
+
_j.label = 1;
|
|
105
|
+
case 1:
|
|
106
|
+
_j.trys.push([1, 3, , 8]);
|
|
107
|
+
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
108
|
+
case 2:
|
|
109
|
+
_f = (_j.sent()), _virtualPrice = _f[0], _fee = _f[1], _adminFee = _f[2], _A = _f[3], _lpTokenSupply = _f[4], _gamma = _f[5], _prices = _f.slice(6);
|
|
110
|
+
return [3 /*break*/, 8];
|
|
111
|
+
case 3:
|
|
112
|
+
e_1 = _j.sent();
|
|
113
|
+
calls.shift();
|
|
114
|
+
if (!this.isCrypto) return [3 /*break*/, 5];
|
|
115
|
+
calls.shift();
|
|
116
|
+
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
117
|
+
case 4:
|
|
118
|
+
_g = (_j.sent()), _adminFee = _g[0], _A = _g[1], _lpTokenSupply = _g[2], _gamma = _g[3], _prices = _g.slice(4);
|
|
119
|
+
return [3 /*break*/, 7];
|
|
120
|
+
case 5: return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
121
|
+
case 6:
|
|
122
|
+
_h = (_j.sent()), _fee = _h[0], _adminFee = _h[1], _A = _h[2], _lpTokenSupply = _h[3], _gamma = _h[4], _prices = _h.slice(5);
|
|
123
|
+
_j.label = 7;
|
|
124
|
+
case 7: return [3 /*break*/, 8];
|
|
125
|
+
case 8:
|
|
126
|
+
_c = [
|
|
127
|
+
curve.formatUnits(_virtualPrice),
|
|
128
|
+
curve.formatUnits(_fee, 8),
|
|
129
|
+
curve.formatUnits(_adminFee * _fee),
|
|
130
|
+
curve.formatUnits(_A, 0),
|
|
131
|
+
curve.formatUnits(_lpTokenSupply),
|
|
132
|
+
_gamma ? curve.formatUnits(_gamma) : undefined,
|
|
133
|
+
], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], lpTokenSupply = _c[4], gamma = _c[5];
|
|
134
|
+
if (this.isCrypto) {
|
|
135
|
+
prices = _prices.map(function (_p) { return curve.formatUnits(_p); });
|
|
136
|
+
priceOracle = [];
|
|
137
|
+
priceScale = [];
|
|
138
|
+
for (i = 0; i < this.wrappedCoins.length - 1; i++) {
|
|
139
|
+
priceOracle.push(prices.shift());
|
|
140
|
+
priceScale.push(prices.shift());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
A_PRECISION = curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
|
|
144
|
+
return [4 /*yield*/, curve.multicallProvider.all(additionalCalls)];
|
|
145
|
+
case 9:
|
|
146
|
+
_d = _j.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
|
|
147
|
+
_e = [
|
|
148
|
+
_future_A ? String(Number(curve.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
|
|
149
|
+
_initial_A ? String(Number(curve.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
|
|
150
|
+
_future_A_time ? Number(curve.formatUnits(_future_A_time, 0)) * 1000 : undefined,
|
|
151
|
+
_initial_A_time ? Number(curve.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
|
|
152
|
+
], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
|
|
153
|
+
return [2 /*return*/, { lpTokenSupply: lpTokenSupply, virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma, priceOracle: priceOracle, priceScale: priceScale }];
|
|
71
154
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
155
|
+
});
|
|
156
|
+
}); };
|
|
157
|
+
this.statsTotalLiquidity = function (useApi) {
|
|
158
|
+
if (useApi === void 0) { useApi = true; }
|
|
159
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
160
|
+
var network, poolType, poolsData, totalLiquidity_1, balances, promises, _i, _c, addr, prices, totalLiquidity;
|
|
161
|
+
var _this = this;
|
|
162
|
+
return __generator(this, function (_d) {
|
|
163
|
+
switch (_d.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
if (!useApi) return [3 /*break*/, 2];
|
|
166
|
+
network = curve.constants.NETWORK_NAME;
|
|
167
|
+
poolType = !this.isFactory && !this.isCrypto ? "main" :
|
|
168
|
+
!this.isFactory ? "crypto" :
|
|
169
|
+
!(this.isCrypto && this.isFactory) ? "factory" :
|
|
170
|
+
"factory-crypto";
|
|
171
|
+
return [4 /*yield*/, _getPoolsFromApi(network, poolType)];
|
|
172
|
+
case 1:
|
|
173
|
+
poolsData = (_d.sent()).poolData;
|
|
174
|
+
try {
|
|
175
|
+
totalLiquidity_1 = poolsData.filter(function (data) { return data.address.toLowerCase() === _this.address.toLowerCase(); })[0].usdTotal;
|
|
176
|
+
return [2 /*return*/, String(totalLiquidity_1)];
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
console.log(this.id, err.message);
|
|
180
|
+
}
|
|
181
|
+
_d.label = 2;
|
|
182
|
+
case 2: return [4 /*yield*/, this.statsUnderlyingBalances()];
|
|
183
|
+
case 3:
|
|
184
|
+
balances = _d.sent();
|
|
185
|
+
promises = [];
|
|
186
|
+
for (_i = 0, _c = this.underlyingCoinAddresses; _i < _c.length; _i++) {
|
|
187
|
+
addr = _c[_i];
|
|
188
|
+
promises.push(_getUsdRate(addr));
|
|
189
|
+
}
|
|
190
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
191
|
+
case 4:
|
|
192
|
+
prices = _d.sent();
|
|
193
|
+
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
194
|
+
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
82
198
|
};
|
|
83
|
-
this.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
199
|
+
this.statsVolume = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
200
|
+
var _c, mainPoolsData, factoryPoolsData, poolData_1, lpPrice, network, poolsData, poolData;
|
|
201
|
+
var _this = this;
|
|
202
|
+
var _d;
|
|
203
|
+
return __generator(this, function (_e) {
|
|
204
|
+
switch (_e.label) {
|
|
205
|
+
case 0:
|
|
206
|
+
if (![1284, 2222, 42220, 1313161554].includes(curve.chainId)) return [3 /*break*/, 3];
|
|
207
|
+
return [4 /*yield*/, Promise.all([
|
|
208
|
+
_getLegacyAPYsAndVolumes(curve.constants.NETWORK_NAME),
|
|
209
|
+
_getFactoryAPYsAndVolumes(curve.constants.NETWORK_NAME),
|
|
210
|
+
])];
|
|
211
|
+
case 1:
|
|
212
|
+
_c = _e.sent(), mainPoolsData = _c[0], factoryPoolsData = _c[1];
|
|
213
|
+
if (this.id in mainPoolsData) {
|
|
214
|
+
return [2 /*return*/, ((_d = mainPoolsData[this.id].volume) !== null && _d !== void 0 ? _d : 0).toString()];
|
|
215
|
+
}
|
|
216
|
+
poolData_1 = factoryPoolsData.find(function (d) { return d.poolAddress.toLowerCase() === _this.address; });
|
|
217
|
+
if (!poolData_1)
|
|
218
|
+
throw Error("Can't get Volume for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
219
|
+
return [4 /*yield*/, _getUsdRate(this.lpToken)];
|
|
220
|
+
case 2:
|
|
221
|
+
lpPrice = _e.sent();
|
|
222
|
+
return [2 /*return*/, (poolData_1.volume * lpPrice).toString()];
|
|
223
|
+
case 3:
|
|
224
|
+
network = curve.constants.NETWORK_NAME;
|
|
225
|
+
return [4 /*yield*/, _getSubgraphData(network)];
|
|
226
|
+
case 4:
|
|
227
|
+
poolsData = (_e.sent()).poolsData;
|
|
228
|
+
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
229
|
+
if (!poolData)
|
|
230
|
+
throw Error("Can't get Volume for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
231
|
+
return [2 /*return*/, poolData.volumeUSD.toString()];
|
|
97
232
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
day: mainPoolsData[this.id].apy.day.toString(),
|
|
139
|
-
week: mainPoolsData[this.id].apy.week.toString(),
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
const poolData = factoryPoolsData.find((d) => d.poolAddress.toLowerCase() === this.address);
|
|
143
|
-
if (!poolData)
|
|
144
|
-
throw Error(`Can't get base APY for ${this.name} (id: ${this.id})`);
|
|
145
|
-
return {
|
|
146
|
-
day: poolData.apy.toString(),
|
|
147
|
-
week: poolData.apy.toString(),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
const network = curve.constants.NETWORK_NAME;
|
|
151
|
-
const poolsData = (await _getSubgraphData(network)).poolsData;
|
|
152
|
-
const poolData = poolsData.find((d) => d.address.toLowerCase() === this.address);
|
|
153
|
-
if (!poolData)
|
|
154
|
-
throw Error(`Can't get base APY for ${this.name} (id: ${this.id})`);
|
|
155
|
-
return {
|
|
156
|
-
day: poolData.latestDailyApy.toString(),
|
|
157
|
-
week: poolData.latestWeeklyApy.toString(),
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
this.statsTokenApy = async (useApi = true) => {
|
|
161
|
-
if (this.rewardsOnly())
|
|
162
|
-
throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
|
|
163
|
-
const isDisabledChain = [1313161554].includes(curve.chainId); // Disable Aurora
|
|
164
|
-
if (useApi && !isDisabledChain) {
|
|
165
|
-
const crvAPYs = await _getCrvApyFromApi();
|
|
166
|
-
const poolCrvApy = crvAPYs[this.gauge] ?? [0, 0]; // new pools might be missing
|
|
167
|
-
return [poolCrvApy[0], poolCrvApy[1]];
|
|
168
|
-
}
|
|
169
|
-
const totalLiquidityUSD = await this.statsTotalLiquidity();
|
|
170
|
-
if (Number(totalLiquidityUSD) === 0)
|
|
171
|
-
return [0, 0];
|
|
172
|
-
let inflationRateBN, workingSupplyBN, totalSupplyBN;
|
|
173
|
-
if (curve.chainId !== 1) {
|
|
174
|
-
const gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
175
|
-
const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
|
|
176
|
-
const crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
|
|
177
|
-
const currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
178
|
-
[inflationRateBN, workingSupplyBN, totalSupplyBN] = (await curve.multicallProvider.all([
|
|
179
|
-
gaugeContract.inflation_rate(currentWeek),
|
|
180
|
-
gaugeContract.working_supply(),
|
|
181
|
-
lpTokenContract.totalSupply(),
|
|
182
|
-
])).map((value) => toBN(value));
|
|
183
|
-
if (inflationRateBN.eq(0)) {
|
|
184
|
-
inflationRateBN = toBN(await crvContract.balanceOf(this.gauge, curve.constantOptions)).div(WEEK);
|
|
233
|
+
});
|
|
234
|
+
}); };
|
|
235
|
+
this.statsBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
236
|
+
var _c, mainPoolsData, factoryPoolsData, poolData_2, network, poolsData, poolData;
|
|
237
|
+
var _this = this;
|
|
238
|
+
return __generator(this, function (_d) {
|
|
239
|
+
switch (_d.label) {
|
|
240
|
+
case 0:
|
|
241
|
+
if (![1284, 2222, 42220, 1313161554].includes(curve.chainId)) return [3 /*break*/, 2];
|
|
242
|
+
return [4 /*yield*/, Promise.all([
|
|
243
|
+
_getLegacyAPYsAndVolumes(curve.constants.NETWORK_NAME),
|
|
244
|
+
_getFactoryAPYsAndVolumes(curve.constants.NETWORK_NAME),
|
|
245
|
+
])];
|
|
246
|
+
case 1:
|
|
247
|
+
_c = _d.sent(), mainPoolsData = _c[0], factoryPoolsData = _c[1];
|
|
248
|
+
if (this.id in mainPoolsData) {
|
|
249
|
+
return [2 /*return*/, {
|
|
250
|
+
day: mainPoolsData[this.id].apy.day.toString(),
|
|
251
|
+
week: mainPoolsData[this.id].apy.week.toString(),
|
|
252
|
+
}];
|
|
253
|
+
}
|
|
254
|
+
poolData_2 = factoryPoolsData.find(function (d) { return d.poolAddress.toLowerCase() === _this.address; });
|
|
255
|
+
if (!poolData_2)
|
|
256
|
+
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
257
|
+
return [2 /*return*/, {
|
|
258
|
+
day: poolData_2.apy.toString(),
|
|
259
|
+
week: poolData_2.apy.toString(),
|
|
260
|
+
}];
|
|
261
|
+
case 2:
|
|
262
|
+
network = curve.constants.NETWORK_NAME;
|
|
263
|
+
return [4 /*yield*/, _getSubgraphData(network)];
|
|
264
|
+
case 3:
|
|
265
|
+
poolsData = (_d.sent()).poolsData;
|
|
266
|
+
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
267
|
+
if (!poolData)
|
|
268
|
+
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
269
|
+
return [2 /*return*/, {
|
|
270
|
+
day: poolData.latestDailyApy.toString(),
|
|
271
|
+
week: poolData.latestWeeklyApy.toString(),
|
|
272
|
+
}];
|
|
185
273
|
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
274
|
+
});
|
|
275
|
+
}); };
|
|
276
|
+
this.statsTokenApy = function (useApi) {
|
|
277
|
+
if (useApi === void 0) { useApi = true; }
|
|
278
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
279
|
+
var isDisabledChain, crvAPYs, poolCrvApy, totalLiquidityUSD, inflationRateBN, workingSupplyBN, totalSupplyBN, gaugeContract, lpTokenContract, crvContract, currentWeek, _c, gaugeContract, lpTokenContract, gaugeControllerContract, weightBN, rateBN, crvPrice, baseApyBN, boostedApyBN;
|
|
280
|
+
var _d, _e;
|
|
281
|
+
var _f;
|
|
282
|
+
return __generator(this, function (_g) {
|
|
283
|
+
switch (_g.label) {
|
|
284
|
+
case 0:
|
|
285
|
+
if (this.rewardsOnly())
|
|
286
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use stats.rewardsApy instead"));
|
|
287
|
+
isDisabledChain = [1313161554].includes(curve.chainId);
|
|
288
|
+
if (!(useApi && !isDisabledChain)) return [3 /*break*/, 2];
|
|
289
|
+
return [4 /*yield*/, _getCrvApyFromApi()];
|
|
290
|
+
case 1:
|
|
291
|
+
crvAPYs = _g.sent();
|
|
292
|
+
poolCrvApy = (_f = crvAPYs[this.gauge]) !== null && _f !== void 0 ? _f : [0, 0];
|
|
293
|
+
return [2 /*return*/, [poolCrvApy[0], poolCrvApy[1]]];
|
|
294
|
+
case 2: return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
295
|
+
case 3:
|
|
296
|
+
totalLiquidityUSD = _g.sent();
|
|
297
|
+
if (Number(totalLiquidityUSD) === 0)
|
|
298
|
+
return [2 /*return*/, [0, 0]];
|
|
299
|
+
if (!(curve.chainId !== 1)) return [3 /*break*/, 7];
|
|
300
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
301
|
+
lpTokenContract = curve.contracts[this.lpToken].multicallContract;
|
|
302
|
+
crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
|
|
303
|
+
currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
304
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
305
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
306
|
+
gaugeContract.working_supply(),
|
|
307
|
+
lpTokenContract.totalSupply(),
|
|
308
|
+
])];
|
|
309
|
+
case 4:
|
|
310
|
+
_d = (_g.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _d[0], workingSupplyBN = _d[1], totalSupplyBN = _d[2];
|
|
311
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 6];
|
|
312
|
+
_c = toBN;
|
|
313
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve.constantOptions)];
|
|
314
|
+
case 5:
|
|
315
|
+
inflationRateBN = _c.apply(void 0, [_g.sent()]).div(WEEK);
|
|
316
|
+
_g.label = 6;
|
|
317
|
+
case 6: return [3 /*break*/, 9];
|
|
318
|
+
case 7:
|
|
319
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
320
|
+
lpTokenContract = curve.contracts[this.lpToken].multicallContract;
|
|
321
|
+
gaugeControllerContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
322
|
+
weightBN = void 0;
|
|
323
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
324
|
+
gaugeContract.inflation_rate(),
|
|
325
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
326
|
+
gaugeContract.working_supply(),
|
|
327
|
+
lpTokenContract.totalSupply(),
|
|
328
|
+
])];
|
|
329
|
+
case 8:
|
|
330
|
+
_e = (_g.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingSupplyBN = _e[2], totalSupplyBN = _e[3];
|
|
331
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
332
|
+
_g.label = 9;
|
|
333
|
+
case 9:
|
|
334
|
+
if (inflationRateBN.eq(0))
|
|
335
|
+
return [2 /*return*/, [0, 0]];
|
|
336
|
+
rateBN = inflationRateBN.times(31536000).times(0.4).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD));
|
|
337
|
+
return [4 /*yield*/, _getUsdRate(curve.constants.ALIASES.crv)];
|
|
338
|
+
case 10:
|
|
339
|
+
crvPrice = _g.sent();
|
|
340
|
+
baseApyBN = rateBN.times(crvPrice);
|
|
341
|
+
boostedApyBN = baseApyBN.times(2.5);
|
|
342
|
+
return [2 /*return*/, [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()]];
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
207
346
|
};
|
|
208
|
-
this.statsRewardsApy =
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
347
|
+
this.statsRewardsApy = function (useApi) {
|
|
348
|
+
if (useApi === void 0) { useApi = true; }
|
|
349
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
350
|
+
var isDisabledChain, rewards, apy, rewardTokens, _i, rewardTokens_1, rewardToken, gaugeContract, lpTokenContract, rewardContract, totalLiquidityUSD, rewardRate, _c, rewardData, _stakedSupply, _totalSupply, stakedSupplyBN, totalSupplyBN, inflationBN, periodFinish, baseApy;
|
|
351
|
+
return __generator(this, function (_d) {
|
|
352
|
+
switch (_d.label) {
|
|
353
|
+
case 0:
|
|
354
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
355
|
+
return [2 /*return*/, []];
|
|
356
|
+
isDisabledChain = [1313161554].includes(curve.chainId);
|
|
357
|
+
if (!(curve.chainId === 1 || (useApi && !isDisabledChain))) return [3 /*break*/, 2];
|
|
358
|
+
return [4 /*yield*/, _getRewardsFromApi()];
|
|
359
|
+
case 1:
|
|
360
|
+
rewards = _d.sent();
|
|
361
|
+
if (!rewards[this.gauge])
|
|
362
|
+
return [2 /*return*/, []];
|
|
363
|
+
return [2 /*return*/, rewards[this.gauge].map(function (r) { return ({ gaugeAddress: r.gaugeAddress, tokenAddress: r.tokenAddress, symbol: r.symbol, apy: r.apy }); })];
|
|
364
|
+
case 2:
|
|
365
|
+
apy = [];
|
|
366
|
+
return [4 /*yield*/, this.rewardTokens(false)];
|
|
367
|
+
case 3:
|
|
368
|
+
rewardTokens = _d.sent();
|
|
369
|
+
_i = 0, rewardTokens_1 = rewardTokens;
|
|
370
|
+
_d.label = 4;
|
|
371
|
+
case 4:
|
|
372
|
+
if (!(_i < rewardTokens_1.length)) return [3 /*break*/, 9];
|
|
373
|
+
rewardToken = rewardTokens_1[_i];
|
|
374
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
375
|
+
lpTokenContract = curve.contracts[this.lpToken].multicallContract;
|
|
376
|
+
rewardContract = curve.contracts[this.sRewardContract || this.gauge].multicallContract;
|
|
377
|
+
return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
378
|
+
case 5:
|
|
379
|
+
totalLiquidityUSD = _d.sent();
|
|
380
|
+
return [4 /*yield*/, _getUsdRate(rewardToken.token)];
|
|
381
|
+
case 6:
|
|
382
|
+
rewardRate = _d.sent();
|
|
383
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
384
|
+
rewardContract.reward_data(rewardToken.token),
|
|
385
|
+
gaugeContract.totalSupply(),
|
|
386
|
+
lpTokenContract.totalSupply(),
|
|
387
|
+
])];
|
|
388
|
+
case 7:
|
|
389
|
+
_c = _d.sent(), rewardData = _c[0], _stakedSupply = _c[1], _totalSupply = _c[2];
|
|
390
|
+
stakedSupplyBN = toBN(_stakedSupply);
|
|
391
|
+
totalSupplyBN = toBN(_totalSupply);
|
|
392
|
+
inflationBN = toBN(rewardData.rate, rewardToken.decimals);
|
|
393
|
+
periodFinish = Number(curve.formatUnits(rewardData.period_finish, 0)) * 1000;
|
|
394
|
+
baseApy = periodFinish > Date.now() ?
|
|
395
|
+
inflationBN.times(31536000).times(rewardRate).div(stakedSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)) :
|
|
396
|
+
BN(0);
|
|
397
|
+
apy.push({
|
|
398
|
+
gaugeAddress: this.gauge,
|
|
399
|
+
tokenAddress: rewardToken.token,
|
|
400
|
+
symbol: rewardToken.symbol,
|
|
401
|
+
apy: baseApy.times(100).toNumber(),
|
|
402
|
+
});
|
|
403
|
+
_d.label = 8;
|
|
404
|
+
case 8:
|
|
405
|
+
_i++;
|
|
406
|
+
return [3 /*break*/, 4];
|
|
407
|
+
case 9: return [2 /*return*/, apy];
|
|
408
|
+
}
|
|
243
409
|
});
|
|
244
|
-
}
|
|
245
|
-
return apy;
|
|
410
|
+
});
|
|
246
411
|
};
|
|
247
|
-
this._calcLpTokenAmount = memoize(
|
|
248
|
-
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
412
|
+
this._calcLpTokenAmount = memoize(function (_amounts, isDeposit, useUnderlying) {
|
|
413
|
+
if (isDeposit === void 0) { isDeposit = true; }
|
|
414
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
415
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
416
|
+
var e_2, lpContract, _lpTotalSupply, decimals_1, amounts, seedAmounts_1, contract, basePool, e_3, lpContract, _lpTotalSupply, decimals_2, amounts_1, seedAmounts_2, _amounts18Decimals;
|
|
417
|
+
return __generator(this, function (_c) {
|
|
418
|
+
switch (_c.label) {
|
|
419
|
+
case 0:
|
|
420
|
+
if (!this.isCrypto) return [3 /*break*/, 6];
|
|
421
|
+
_c.label = 1;
|
|
422
|
+
case 1:
|
|
423
|
+
_c.trys.push([1, 3, , 6]);
|
|
424
|
+
return [4 /*yield*/, this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying)];
|
|
425
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
426
|
+
case 3:
|
|
427
|
+
e_2 = _c.sent();
|
|
428
|
+
lpContract = curve.contracts[this.lpToken].contract;
|
|
429
|
+
return [4 /*yield*/, lpContract.totalSupply(curve.constantOptions)];
|
|
430
|
+
case 4:
|
|
431
|
+
_lpTotalSupply = _c.sent();
|
|
432
|
+
if (_lpTotalSupply > curve.parseUnits("0"))
|
|
433
|
+
throw e_2; // Already seeded
|
|
434
|
+
if (this.isMeta && useUnderlying)
|
|
435
|
+
throw Error("Initial deposit for crypto meta pools must be in wrapped coins");
|
|
436
|
+
decimals_1 = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
437
|
+
amounts = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_1[i]); });
|
|
438
|
+
return [4 /*yield*/, this.cryptoSeedAmounts(amounts[0])];
|
|
439
|
+
case 5:
|
|
440
|
+
seedAmounts_1 = _c.sent();
|
|
441
|
+
amounts.forEach(function (a, i) {
|
|
442
|
+
if (!BN(a).eq(BN(seedAmounts_1[i])))
|
|
443
|
+
throw Error("Amounts must be = ".concat(seedAmounts_1));
|
|
444
|
+
});
|
|
445
|
+
return [2 /*return*/, parseUnits(Math.sqrt(Number(amounts[0]) * Number(amounts[1])))];
|
|
446
|
+
case 6:
|
|
447
|
+
_c.trys.push([6, 11, , 13]);
|
|
448
|
+
contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
|
|
449
|
+
if (!this.isMeta) return [3 /*break*/, 8];
|
|
450
|
+
basePool = new PoolTemplate(this.basePool);
|
|
451
|
+
return [4 /*yield*/, contract.calc_token_amount_meta(this.address, this.lpToken, _amounts.concat(Array(5 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, basePool.address, basePool.lpToken, isDeposit, useUnderlying)];
|
|
452
|
+
case 7: return [2 /*return*/, _c.sent()];
|
|
453
|
+
case 8: return [4 /*yield*/, contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(5 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending)];
|
|
454
|
+
case 9: return [2 /*return*/, _c.sent()];
|
|
455
|
+
case 10: return [3 /*break*/, 13];
|
|
456
|
+
case 11:
|
|
457
|
+
e_3 = _c.sent();
|
|
458
|
+
if (!isDeposit)
|
|
459
|
+
throw e_3; // Seeding is only for deposit
|
|
460
|
+
lpContract = curve.contracts[this.lpToken].contract;
|
|
461
|
+
return [4 /*yield*/, lpContract.totalSupply(curve.constantOptions)];
|
|
462
|
+
case 12:
|
|
463
|
+
_lpTotalSupply = _c.sent();
|
|
464
|
+
if (_lpTotalSupply > curve.parseUnits("0"))
|
|
465
|
+
throw e_3; // Already seeded
|
|
466
|
+
decimals_2 = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
467
|
+
amounts_1 = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_2[i]); });
|
|
468
|
+
if (this.isMeta && useUnderlying) {
|
|
469
|
+
seedAmounts_2 = this.metaUnderlyingSeedAmounts(amounts_1[0]);
|
|
470
|
+
amounts_1.forEach(function (a, i) {
|
|
471
|
+
if (!BN(a).eq(BN(seedAmounts_2[i])))
|
|
472
|
+
throw Error("Amounts must be = ".concat(seedAmounts_2));
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
if (_amounts[0] <= curve.parseUnits("0"))
|
|
477
|
+
throw Error("Initial deposit amounts must be > 0");
|
|
478
|
+
amounts_1.forEach(function (a) {
|
|
479
|
+
if (a !== amounts_1[0])
|
|
480
|
+
throw Error("Initial deposit amounts must be equal");
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
_amounts18Decimals = amounts_1.map(function (a) { return parseUnits(a); });
|
|
484
|
+
return [2 /*return*/, _amounts18Decimals.reduce(function (_a, _b) { return _a + _b; })];
|
|
485
|
+
case 13: return [2 /*return*/];
|
|
312
486
|
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// --- Getting final lpAmount ---
|
|
316
|
-
let _lpTokenFee = await this._pureCalcLpTokenAmount(_fees, !isDeposit, this.isMeta && useUnderlying);
|
|
317
|
-
if (isDeposit)
|
|
318
|
-
_lpTokenFee = _lpTokenFee * (-1n);
|
|
319
|
-
return _lpTokenAmount + _lpTokenFee;
|
|
320
|
-
}
|
|
321
|
-
catch (e) { // Seeding
|
|
322
|
-
if (!isDeposit)
|
|
323
|
-
throw e; // Seeding is only for deposit
|
|
324
|
-
const lpContract = curve.contracts[this.lpToken].contract;
|
|
325
|
-
const _lpTotalSupply = await lpContract.totalSupply(curve.constantOptions);
|
|
326
|
-
if (_lpTotalSupply > 0n)
|
|
327
|
-
throw e; // Already seeded
|
|
328
|
-
const decimals = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
329
|
-
const amounts = _amounts.map((_a, i) => curve.formatUnits(_a, decimals[i]));
|
|
330
|
-
if (this.isMeta && useUnderlying) {
|
|
331
|
-
const seedAmounts = this.metaUnderlyingSeedAmounts(amounts[0]); // Checks N coins == 2 and amounts > 0
|
|
332
|
-
amounts.forEach((a, i) => {
|
|
333
|
-
if (!BN(a).eq(BN(seedAmounts[i])))
|
|
334
|
-
throw Error(`Amounts must be = ${seedAmounts}`);
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
if (_amounts[0] <= 0n)
|
|
339
|
-
throw Error("Initial deposit amounts must be >0");
|
|
340
|
-
amounts.forEach((a) => {
|
|
341
|
-
if (a !== amounts[0])
|
|
342
|
-
throw Error("Initial deposit amounts must be equal");
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
const _amounts18Decimals = amounts.map((a) => parseUnits(a));
|
|
346
|
-
return _amounts18Decimals.reduce((_a, _b) => _a + _b);
|
|
347
|
-
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
348
489
|
}, {
|
|
349
490
|
primitive: true,
|
|
350
491
|
promise: true,
|
|
351
|
-
maxAge:
|
|
492
|
+
maxAge: 30 * 1000,
|
|
493
|
+
length: 3,
|
|
352
494
|
});
|
|
353
495
|
// ---------------- CRV PROFIT, CLAIM, BOOSTING ----------------
|
|
354
|
-
this.crvProfit =
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
496
|
+
this.crvProfit = function (address) {
|
|
497
|
+
if (address === void 0) { address = ""; }
|
|
498
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
499
|
+
var inflationRateBN, workingSupplyBN, workingBalanceBN, gaugeContract, crvContract, currentWeek, _c, gaugeContract, gaugeControllerContract, weightBN, crvPrice, dailyIncome, weeklyIncome, monthlyIncome, annualIncome;
|
|
500
|
+
var _d, _e;
|
|
501
|
+
return __generator(this, function (_f) {
|
|
502
|
+
switch (_f.label) {
|
|
503
|
+
case 0:
|
|
504
|
+
if (this.rewardsOnly())
|
|
505
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use rewardsProfit instead"));
|
|
506
|
+
address = address || curve.signerAddress;
|
|
507
|
+
if (!address)
|
|
508
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
509
|
+
if (!(curve.chainId !== 1)) return [3 /*break*/, 4];
|
|
510
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
511
|
+
crvContract = curve.contracts[curve.constants.ALIASES.crv].contract;
|
|
512
|
+
currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
513
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
514
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
515
|
+
gaugeContract.working_balances(address),
|
|
516
|
+
gaugeContract.working_supply(),
|
|
517
|
+
])];
|
|
518
|
+
case 1:
|
|
519
|
+
_d = (_f.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _d[0], workingBalanceBN = _d[1], workingSupplyBN = _d[2];
|
|
520
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 3];
|
|
521
|
+
_c = toBN;
|
|
522
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve.constantOptions)];
|
|
523
|
+
case 2:
|
|
524
|
+
inflationRateBN = _c.apply(void 0, [_f.sent()]).div(WEEK);
|
|
525
|
+
_f.label = 3;
|
|
526
|
+
case 3: return [3 /*break*/, 6];
|
|
527
|
+
case 4:
|
|
528
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
529
|
+
gaugeControllerContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
530
|
+
weightBN = void 0;
|
|
531
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
532
|
+
gaugeContract.inflation_rate(),
|
|
533
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
534
|
+
gaugeContract.working_balances(address),
|
|
535
|
+
gaugeContract.working_supply(),
|
|
536
|
+
])];
|
|
537
|
+
case 5:
|
|
538
|
+
_e = (_f.sent()).map(function (value) { return toBN(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingBalanceBN = _e[2], workingSupplyBN = _e[3];
|
|
539
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
540
|
+
_f.label = 6;
|
|
541
|
+
case 6: return [4 /*yield*/, _getUsdRate('CRV')];
|
|
542
|
+
case 7:
|
|
543
|
+
crvPrice = _f.sent();
|
|
544
|
+
if (workingSupplyBN.eq(0))
|
|
545
|
+
return [2 /*return*/, {
|
|
546
|
+
day: "0.0",
|
|
547
|
+
week: "0.0",
|
|
548
|
+
month: "0.0",
|
|
549
|
+
year: "0.0",
|
|
550
|
+
token: curve.constants.ALIASES.crv,
|
|
551
|
+
symbol: 'CRV',
|
|
552
|
+
price: crvPrice,
|
|
553
|
+
}];
|
|
554
|
+
dailyIncome = inflationRateBN.times(DAY).times(workingBalanceBN).div(workingSupplyBN);
|
|
555
|
+
weeklyIncome = inflationRateBN.times(WEEK).times(workingBalanceBN).div(workingSupplyBN);
|
|
556
|
+
monthlyIncome = inflationRateBN.times(MONTH).times(workingBalanceBN).div(workingSupplyBN);
|
|
557
|
+
annualIncome = inflationRateBN.times(YEAR).times(workingBalanceBN).div(workingSupplyBN);
|
|
558
|
+
return [2 /*return*/, {
|
|
559
|
+
day: dailyIncome.toString(),
|
|
560
|
+
week: weeklyIncome.toString(),
|
|
561
|
+
month: monthlyIncome.toString(),
|
|
562
|
+
year: annualIncome.toString(),
|
|
563
|
+
token: curve.constants.ALIASES.crv,
|
|
564
|
+
symbol: 'CRV',
|
|
565
|
+
price: crvPrice,
|
|
566
|
+
}];
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
});
|
|
410
570
|
};
|
|
411
|
-
this.boost =
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
571
|
+
this.boost = function (address) {
|
|
572
|
+
if (address === void 0) { address = ""; }
|
|
573
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
574
|
+
var gaugeContract, _c, workingBalanceBN, balanceBN, boostBN;
|
|
575
|
+
return __generator(this, function (_d) {
|
|
576
|
+
switch (_d.label) {
|
|
577
|
+
case 0:
|
|
578
|
+
if (curve.chainId !== 1)
|
|
579
|
+
throw Error("Boosting is available only on Ethereum network");
|
|
580
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
581
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
582
|
+
address = address || curve.signerAddress;
|
|
583
|
+
if (!address)
|
|
584
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
585
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
586
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
587
|
+
gaugeContract.working_balances(address),
|
|
588
|
+
gaugeContract.balanceOf(address),
|
|
589
|
+
])];
|
|
590
|
+
case 1:
|
|
591
|
+
_c = (_d.sent()).map(function (value) { return toBN(value); }), workingBalanceBN = _c[0], balanceBN = _c[1];
|
|
592
|
+
boostBN = workingBalanceBN.div(0.4).div(balanceBN);
|
|
593
|
+
return [2 /*return*/, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
});
|
|
426
597
|
};
|
|
427
|
-
this.currentCrvApy =
|
|
428
|
-
address
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
598
|
+
this.currentCrvApy = function (address) {
|
|
599
|
+
if (address === void 0) { address = ""; }
|
|
600
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
601
|
+
var _c, baseApy, maxApy, boost;
|
|
602
|
+
return __generator(this, function (_d) {
|
|
603
|
+
switch (_d.label) {
|
|
604
|
+
case 0:
|
|
605
|
+
address = address || curve.signerAddress;
|
|
606
|
+
if (!address)
|
|
607
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
608
|
+
return [4 /*yield*/, this.statsTokenApy()];
|
|
609
|
+
case 1:
|
|
610
|
+
_c = _d.sent(), baseApy = _c[0], maxApy = _c[1];
|
|
611
|
+
if (curve.chainId !== 1)
|
|
612
|
+
return [2 /*return*/, baseApy];
|
|
613
|
+
return [4 /*yield*/, this.boost(address)];
|
|
614
|
+
case 2:
|
|
615
|
+
boost = _d.sent();
|
|
616
|
+
if (boost == "2.5")
|
|
617
|
+
return [2 /*return*/, maxApy];
|
|
618
|
+
if (boost === "NaN")
|
|
619
|
+
return [2 /*return*/, NaN];
|
|
620
|
+
return [2 /*return*/, BN(baseApy).times(BN(boost)).toNumber()];
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
});
|
|
440
624
|
};
|
|
441
|
-
this.maxBoostedStake =
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
throw Error(`${this.name} doesn't have gauge`);
|
|
446
|
-
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
447
|
-
addresses = addresses[0];
|
|
448
|
-
if (addresses.length === 0 && curve.signerAddress !== '')
|
|
449
|
-
addresses = [curve.signerAddress];
|
|
450
|
-
if (addresses.length === 0)
|
|
451
|
-
throw Error("Need to connect wallet or pass addresses into args");
|
|
452
|
-
const votingEscrowContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
453
|
-
const gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
454
|
-
const contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
|
|
455
|
-
addresses.forEach((account) => {
|
|
456
|
-
contractCalls.push(votingEscrowContract.balanceOf(account));
|
|
457
|
-
});
|
|
458
|
-
const _response = await curve.multicallProvider.all(contractCalls);
|
|
459
|
-
const responseBN = _response.map((value) => toBN(value));
|
|
460
|
-
const [veTotalSupplyBN, gaugeTotalSupplyBN] = responseBN.splice(0, 2);
|
|
461
|
-
const resultBN = {};
|
|
462
|
-
addresses.forEach((acct, i) => {
|
|
463
|
-
resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
|
|
464
|
-
});
|
|
465
|
-
const result = {};
|
|
466
|
-
for (const entry of Object.entries(resultBN)) {
|
|
467
|
-
result[entry[0]] = toStringFromBN(entry[1]);
|
|
625
|
+
this.maxBoostedStake = function () {
|
|
626
|
+
var addresses = [];
|
|
627
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
628
|
+
addresses[_i] = arguments[_i];
|
|
468
629
|
}
|
|
469
|
-
return
|
|
630
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
631
|
+
var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _c, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _d, _e, entry;
|
|
632
|
+
return __generator(this, function (_f) {
|
|
633
|
+
switch (_f.label) {
|
|
634
|
+
case 0:
|
|
635
|
+
if (curve.chainId !== 1)
|
|
636
|
+
throw Error("Boosting is available only on Ethereum network");
|
|
637
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
638
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
639
|
+
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
640
|
+
addresses = addresses[0];
|
|
641
|
+
if (addresses.length === 0 && curve.signerAddress !== '')
|
|
642
|
+
addresses = [curve.signerAddress];
|
|
643
|
+
if (addresses.length === 0)
|
|
644
|
+
throw Error("Need to connect wallet or pass addresses into args");
|
|
645
|
+
votingEscrowContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
646
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
647
|
+
contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
|
|
648
|
+
addresses.forEach(function (account) {
|
|
649
|
+
contractCalls.push(votingEscrowContract.balanceOf(account));
|
|
650
|
+
});
|
|
651
|
+
return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
|
|
652
|
+
case 1:
|
|
653
|
+
_response = _f.sent();
|
|
654
|
+
responseBN = _response.map(function (value) { return toBN(value); });
|
|
655
|
+
_c = responseBN.splice(0, 2), veTotalSupplyBN = _c[0], gaugeTotalSupplyBN = _c[1];
|
|
656
|
+
resultBN = {};
|
|
657
|
+
addresses.forEach(function (acct, i) {
|
|
658
|
+
resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
|
|
659
|
+
});
|
|
660
|
+
result = {};
|
|
661
|
+
for (_d = 0, _e = Object.entries(resultBN); _d < _e.length; _d++) {
|
|
662
|
+
entry = _e[_d];
|
|
663
|
+
result[entry[0]] = toStringFromBN(entry[1]);
|
|
664
|
+
}
|
|
665
|
+
return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
});
|
|
470
669
|
};
|
|
471
670
|
// ---------------- REWARDS PROFIT, CLAIM ----------------
|
|
472
|
-
this.rewardTokens = memoize(
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
-
|
|
671
|
+
this.rewardTokens = memoize(function (useApi) {
|
|
672
|
+
if (useApi === void 0) { useApi = true; }
|
|
673
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
674
|
+
var rewards, gaugeContract, gaugeMulticallContract, rewardCount, _c, _d, _e, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, res, symbol, decimals;
|
|
675
|
+
return __generator(this, function (_f) {
|
|
676
|
+
switch (_f.label) {
|
|
677
|
+
case 0:
|
|
678
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
679
|
+
return [2 /*return*/, []];
|
|
680
|
+
if (!useApi) return [3 /*break*/, 2];
|
|
681
|
+
return [4 /*yield*/, _getRewardsFromApi()];
|
|
682
|
+
case 1:
|
|
683
|
+
rewards = _f.sent();
|
|
684
|
+
if (!rewards[this.gauge])
|
|
685
|
+
return [2 /*return*/, []];
|
|
686
|
+
rewards[this.gauge].forEach(function (r) { return _setContracts(r.tokenAddress, ERC20Abi); });
|
|
687
|
+
return [2 /*return*/, rewards[this.gauge].map(function (r) { return ({ token: r.tokenAddress, symbol: r.symbol, decimals: Number(r.decimals) }); })];
|
|
688
|
+
case 2:
|
|
689
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
690
|
+
gaugeMulticallContract = curve.contracts[this.gauge].multicallContract;
|
|
691
|
+
if (!("reward_tokens(uint256)" in gaugeContract)) return [3 /*break*/, 7];
|
|
692
|
+
rewardCount = 8;
|
|
693
|
+
if (!("reward_count()" in gaugeContract)) return [3 /*break*/, 4];
|
|
694
|
+
_c = Number;
|
|
695
|
+
_e = (_d = curve).formatUnits;
|
|
696
|
+
return [4 /*yield*/, gaugeContract.reward_count(curve.constantOptions)];
|
|
697
|
+
case 3:
|
|
698
|
+
rewardCount = _c.apply(void 0, [_e.apply(_d, [_f.sent(), 0])]);
|
|
699
|
+
_f.label = 4;
|
|
700
|
+
case 4:
|
|
701
|
+
tokenCalls = [];
|
|
702
|
+
for (i = 0; i < rewardCount; i++) {
|
|
703
|
+
tokenCalls.push(gaugeMulticallContract.reward_tokens(i));
|
|
704
|
+
}
|
|
705
|
+
return [4 /*yield*/, curve.multicallProvider.all(tokenCalls)];
|
|
706
|
+
case 5:
|
|
707
|
+
tokens = (_f.sent())
|
|
708
|
+
.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; })
|
|
709
|
+
.map(function (addr) { return addr.toLowerCase(); });
|
|
710
|
+
tokenInfoCalls = [];
|
|
711
|
+
for (_i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
712
|
+
token = tokens_1[_i];
|
|
713
|
+
_setContracts(token, ERC20Abi);
|
|
714
|
+
tokenMulticallContract = curve.contracts[token].multicallContract;
|
|
715
|
+
tokenInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
716
|
+
}
|
|
717
|
+
return [4 /*yield*/, curve.multicallProvider.all(tokenInfoCalls)];
|
|
718
|
+
case 6:
|
|
719
|
+
tokenInfo_1 = _f.sent();
|
|
720
|
+
for (i = 0; i < tokens.length; i++) {
|
|
721
|
+
curve.constants.DECIMALS[tokens[i]] = tokenInfo_1[(i * 2) + 1];
|
|
722
|
+
}
|
|
723
|
+
return [2 /*return*/, tokens.map(function (token, i) { return ({ token: token, symbol: tokenInfo_1[i * 2], decimals: tokenInfo_1[(i * 2) + 1] }); })];
|
|
724
|
+
case 7:
|
|
725
|
+
if (!('claimable_reward(address)' in gaugeContract)) return [3 /*break*/, 10];
|
|
726
|
+
rewardContract = curve.contracts[this.sRewardContract].contract;
|
|
727
|
+
method = "snx()" in rewardContract ? "snx" : "rewardsToken" // susd, tbtc : dusd, musd, rsv, sbtc
|
|
728
|
+
;
|
|
729
|
+
return [4 /*yield*/, rewardContract[method](curve.constantOptions)];
|
|
730
|
+
case 8:
|
|
731
|
+
token = (_f.sent()).toLowerCase();
|
|
732
|
+
_setContracts(token, ERC20Abi);
|
|
733
|
+
tokenMulticallContract = curve.contracts[token].multicallContract;
|
|
734
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
735
|
+
tokenMulticallContract.symbol(),
|
|
736
|
+
tokenMulticallContract.decimals(),
|
|
737
|
+
])];
|
|
738
|
+
case 9:
|
|
739
|
+
res = _f.sent();
|
|
740
|
+
symbol = res[0];
|
|
741
|
+
decimals = res[1];
|
|
742
|
+
return [2 /*return*/, [{ token: token, symbol: symbol, decimals: decimals }]];
|
|
743
|
+
case 10: return [2 /*return*/, []]; // gauge
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
});
|
|
523
747
|
}, {
|
|
524
748
|
promise: true,
|
|
525
749
|
maxAge: 30 * 60 * 1000, // 30m
|
|
526
750
|
});
|
|
527
|
-
this.rewardsProfit =
|
|
528
|
-
if (
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
751
|
+
this.rewardsProfit = function (address) {
|
|
752
|
+
if (address === void 0) { address = ""; }
|
|
753
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
754
|
+
var rewardTokens, gaugeContract, result, calls, _i, rewardTokens_2, rewardToken, res, balanceBN, totalSupplyBN, _c, rewardTokens_3, rewardToken, _rewardData, periodFinish, inflationRateBN, tokenPrice, rewardToken, sRewardContract, _d, _inflationRate, _periodFinish, _balance, _totalSupply, periodFinish, inflationRateBN, balanceBN, totalSupplyBN, tokenPrice, _e, rewardTokens_4, rewardToken, tokenPrice;
|
|
755
|
+
return __generator(this, function (_f) {
|
|
756
|
+
switch (_f.label) {
|
|
757
|
+
case 0:
|
|
758
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
759
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
760
|
+
address = address || curve.signerAddress;
|
|
761
|
+
if (!address)
|
|
762
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
763
|
+
return [4 /*yield*/, this.rewardTokens()];
|
|
764
|
+
case 1:
|
|
765
|
+
rewardTokens = _f.sent();
|
|
766
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
767
|
+
result = [];
|
|
768
|
+
if (!('reward_data(address)' in curve.contracts[this.gauge].contract)) return [3 /*break*/, 7];
|
|
769
|
+
calls = [gaugeContract.balanceOf(address), gaugeContract.totalSupply()];
|
|
770
|
+
for (_i = 0, rewardTokens_2 = rewardTokens; _i < rewardTokens_2.length; _i++) {
|
|
771
|
+
rewardToken = rewardTokens_2[_i];
|
|
772
|
+
calls.push(gaugeContract.reward_data(rewardToken.token));
|
|
773
|
+
}
|
|
774
|
+
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
775
|
+
case 2:
|
|
776
|
+
res = _f.sent();
|
|
777
|
+
balanceBN = toBN(res.shift());
|
|
778
|
+
totalSupplyBN = toBN(res.shift());
|
|
779
|
+
_c = 0, rewardTokens_3 = rewardTokens;
|
|
780
|
+
_f.label = 3;
|
|
781
|
+
case 3:
|
|
782
|
+
if (!(_c < rewardTokens_3.length)) return [3 /*break*/, 6];
|
|
783
|
+
rewardToken = rewardTokens_3[_c];
|
|
784
|
+
_rewardData = res.shift();
|
|
785
|
+
periodFinish = Number(curve.formatUnits(_rewardData.period_finish, 0)) * 1000;
|
|
786
|
+
inflationRateBN = periodFinish > Date.now() ? toBN(_rewardData.rate, rewardToken.decimals) : BN(0);
|
|
787
|
+
return [4 /*yield*/, _getUsdRate(rewardToken.token)];
|
|
788
|
+
case 4:
|
|
789
|
+
tokenPrice = _f.sent();
|
|
790
|
+
result.push({
|
|
791
|
+
day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
|
|
792
|
+
week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
|
|
793
|
+
month: inflationRateBN.times(MONTH).times(balanceBN).div(totalSupplyBN).toString(),
|
|
794
|
+
year: inflationRateBN.times(YEAR).times(balanceBN).div(totalSupplyBN).toString(),
|
|
795
|
+
token: rewardToken.token,
|
|
796
|
+
symbol: rewardToken.symbol,
|
|
797
|
+
price: tokenPrice,
|
|
798
|
+
});
|
|
799
|
+
_f.label = 5;
|
|
800
|
+
case 5:
|
|
801
|
+
_c++;
|
|
802
|
+
return [3 /*break*/, 3];
|
|
803
|
+
case 6: return [3 /*break*/, 14];
|
|
804
|
+
case 7:
|
|
805
|
+
if (!(this.sRewardContract && "rewardRate()" in _curve.contracts[this.sRewardContract].contract && "periodFinish()" && rewardTokens.length === 1)) return [3 /*break*/, 10];
|
|
806
|
+
rewardToken = rewardTokens[0];
|
|
807
|
+
sRewardContract = curve.contracts[this.sRewardContract].multicallContract;
|
|
808
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
809
|
+
sRewardContract.rewardRate(),
|
|
810
|
+
sRewardContract.periodFinish(),
|
|
811
|
+
gaugeContract.balanceOf(address),
|
|
812
|
+
gaugeContract.totalSupply(),
|
|
813
|
+
])];
|
|
814
|
+
case 8:
|
|
815
|
+
_d = _f.sent(), _inflationRate = _d[0], _periodFinish = _d[1], _balance = _d[2], _totalSupply = _d[3];
|
|
816
|
+
periodFinish = Number(_periodFinish) * 1000;
|
|
817
|
+
inflationRateBN = periodFinish > Date.now() ? toBN(_inflationRate, rewardToken.decimals) : BN(0);
|
|
818
|
+
balanceBN = toBN(_balance);
|
|
819
|
+
totalSupplyBN = toBN(_totalSupply);
|
|
820
|
+
return [4 /*yield*/, _getUsdRate(rewardToken.token)];
|
|
821
|
+
case 9:
|
|
822
|
+
tokenPrice = _f.sent();
|
|
823
|
+
result.push({
|
|
824
|
+
day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
|
|
825
|
+
week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
|
|
826
|
+
month: inflationRateBN.times(MONTH).times(balanceBN).div(totalSupplyBN).toString(),
|
|
827
|
+
year: inflationRateBN.times(YEAR).times(balanceBN).div(totalSupplyBN).toString(),
|
|
828
|
+
token: rewardToken.token,
|
|
829
|
+
symbol: rewardToken.symbol,
|
|
830
|
+
price: tokenPrice,
|
|
831
|
+
});
|
|
832
|
+
return [3 /*break*/, 14];
|
|
833
|
+
case 10:
|
|
834
|
+
if (!['aave', 'saave', 'ankreth'].includes(this.id)) return [3 /*break*/, 14];
|
|
835
|
+
_e = 0, rewardTokens_4 = rewardTokens;
|
|
836
|
+
_f.label = 11;
|
|
837
|
+
case 11:
|
|
838
|
+
if (!(_e < rewardTokens_4.length)) return [3 /*break*/, 14];
|
|
839
|
+
rewardToken = rewardTokens_4[_e];
|
|
840
|
+
return [4 /*yield*/, _getUsdRate(rewardToken.token)];
|
|
841
|
+
case 12:
|
|
842
|
+
tokenPrice = _f.sent();
|
|
843
|
+
result.push({
|
|
844
|
+
day: "0",
|
|
845
|
+
week: "0",
|
|
846
|
+
month: "0",
|
|
847
|
+
year: "0",
|
|
848
|
+
token: rewardToken.token,
|
|
849
|
+
symbol: rewardToken.symbol,
|
|
850
|
+
price: tokenPrice,
|
|
851
|
+
});
|
|
852
|
+
_f.label = 13;
|
|
853
|
+
case 13:
|
|
854
|
+
_e++;
|
|
855
|
+
return [3 /*break*/, 11];
|
|
856
|
+
case 14: return [2 /*return*/, result];
|
|
857
|
+
}
|
|
582
858
|
});
|
|
583
|
-
}
|
|
584
|
-
else if (['aave', 'saave', 'ankreth'].includes(this.id)) {
|
|
585
|
-
for (const rewardToken of rewardTokens) {
|
|
586
|
-
const tokenPrice = await _getUsdRate(rewardToken.token);
|
|
587
|
-
result.push({
|
|
588
|
-
day: "0",
|
|
589
|
-
week: "0",
|
|
590
|
-
month: "0",
|
|
591
|
-
year: "0",
|
|
592
|
-
token: rewardToken.token,
|
|
593
|
-
symbol: rewardToken.symbol,
|
|
594
|
-
price: tokenPrice,
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
return result;
|
|
859
|
+
});
|
|
599
860
|
};
|
|
600
861
|
// ---------------- ... ----------------
|
|
601
|
-
this.gaugeOptimalDeposits =
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
accounts = accounts[0];
|
|
606
|
-
const votingEscrowContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
607
|
-
const lpTokenContract = curve.contracts[this.lpToken].multicallContract;
|
|
608
|
-
const gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
609
|
-
const contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
|
|
610
|
-
accounts.forEach((account) => {
|
|
611
|
-
contractCalls.push(votingEscrowContract.balanceOf(account), lpTokenContract.balanceOf(account), gaugeContract.balanceOf(account));
|
|
612
|
-
});
|
|
613
|
-
const _response = await curve.multicallProvider.all(contractCalls);
|
|
614
|
-
const response = _response.map((value) => toBN(value));
|
|
615
|
-
const [veTotalSupply, gaugeTotalSupply] = response.splice(0, 2);
|
|
616
|
-
const votingPower = {};
|
|
617
|
-
let totalBalance = BN(0);
|
|
618
|
-
for (const acct of accounts) {
|
|
619
|
-
votingPower[acct] = response[0];
|
|
620
|
-
totalBalance = totalBalance.plus(response[1]).plus(response[2]);
|
|
621
|
-
response.splice(0, 3);
|
|
862
|
+
this.gaugeOptimalDeposits = function () {
|
|
863
|
+
var accounts = [];
|
|
864
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
865
|
+
accounts[_i] = arguments[_i];
|
|
622
866
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
867
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
868
|
+
var votingEscrowContract, lpTokenContract, gaugeContract, contractCalls, _response, response, _c, veTotalSupply, gaugeTotalSupply, votingPower, totalBalance, _d, accounts_1, acct, totalPower, optimalBN, _e, accounts_2, acct, amount, _f, accounts_3, acct, optimal, _g, _h, entry;
|
|
869
|
+
return __generator(this, function (_j) {
|
|
870
|
+
switch (_j.label) {
|
|
871
|
+
case 0:
|
|
872
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
873
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
874
|
+
if (accounts.length == 1 && Array.isArray(accounts[0]))
|
|
875
|
+
accounts = accounts[0];
|
|
876
|
+
votingEscrowContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
877
|
+
lpTokenContract = curve.contracts[this.lpToken].multicallContract;
|
|
878
|
+
gaugeContract = curve.contracts[this.gauge].multicallContract;
|
|
879
|
+
contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
|
|
880
|
+
accounts.forEach(function (account) {
|
|
881
|
+
contractCalls.push(votingEscrowContract.balanceOf(account), lpTokenContract.balanceOf(account), gaugeContract.balanceOf(account));
|
|
882
|
+
});
|
|
883
|
+
return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
|
|
884
|
+
case 1:
|
|
885
|
+
_response = _j.sent();
|
|
886
|
+
response = _response.map(function (value) { return toBN(value); });
|
|
887
|
+
_c = response.splice(0, 2), veTotalSupply = _c[0], gaugeTotalSupply = _c[1];
|
|
888
|
+
votingPower = {};
|
|
889
|
+
totalBalance = BN(0);
|
|
890
|
+
for (_d = 0, accounts_1 = accounts; _d < accounts_1.length; _d++) {
|
|
891
|
+
acct = accounts_1[_d];
|
|
892
|
+
votingPower[acct] = response[0];
|
|
893
|
+
totalBalance = totalBalance.plus(response[1]).plus(response[2]);
|
|
894
|
+
response.splice(0, 3);
|
|
895
|
+
}
|
|
896
|
+
totalPower = Object.values(votingPower).reduce(function (sum, item) { return sum.plus(item); });
|
|
897
|
+
optimalBN = Object.fromEntries(accounts.map(function (acc) { return [acc, BN(0)]; }));
|
|
898
|
+
if (totalBalance.lt(gaugeTotalSupply.times(totalPower).div(veTotalSupply))) {
|
|
899
|
+
for (_e = 0, accounts_2 = accounts; _e < accounts_2.length; _e++) {
|
|
900
|
+
acct = accounts_2[_e];
|
|
901
|
+
amount = gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply).lt(totalBalance) ?
|
|
902
|
+
gaugeTotalSupply.times(votingPower[acct]).div(veTotalSupply) : totalBalance;
|
|
903
|
+
optimalBN[acct] = amount;
|
|
904
|
+
totalBalance = totalBalance.minus(amount);
|
|
905
|
+
if (totalBalance.lte(0)) {
|
|
906
|
+
break;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
if (totalPower.lt(0)) {
|
|
912
|
+
for (_f = 0, accounts_3 = accounts; _f < accounts_3.length; _f++) {
|
|
913
|
+
acct = accounts_3[_f];
|
|
914
|
+
optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce(function (sum, item) { return sum.plus(item); })));
|
|
918
|
+
}
|
|
919
|
+
optimal = {};
|
|
920
|
+
for (_g = 0, _h = Object.entries(optimalBN); _g < _h.length; _g++) {
|
|
921
|
+
entry = _h[_g];
|
|
922
|
+
optimal[entry[0]] = toStringFromBN(entry[1]);
|
|
923
|
+
}
|
|
924
|
+
return [2 /*return*/, optimal];
|
|
635
925
|
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
if (totalPower.lt(0)) {
|
|
640
|
-
for (const acct of accounts) {
|
|
641
|
-
optimalBN[acct] = totalBalance.times(votingPower[acct]).div(totalPower);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
optimalBN[accounts[0]] = optimalBN[accounts[0]].plus(totalBalance.minus(Object.values(optimalBN).reduce((sum, item) => sum.plus(item))));
|
|
645
|
-
}
|
|
646
|
-
const optimal = {};
|
|
647
|
-
for (const entry of Object.entries(optimalBN)) {
|
|
648
|
-
optimal[entry[0]] = toStringFromBN(entry[1]);
|
|
649
|
-
}
|
|
650
|
-
return optimal;
|
|
926
|
+
});
|
|
927
|
+
});
|
|
651
928
|
};
|
|
652
|
-
this._getCoinIdx = (coin, useUnderlying
|
|
929
|
+
this._getCoinIdx = function (coin, useUnderlying) {
|
|
930
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
653
931
|
if (typeof coin === 'number') {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
if (!Number.isInteger(
|
|
932
|
+
var coins_N = useUnderlying ? _this.underlyingCoins.length : _this.wrappedCoins.length;
|
|
933
|
+
var idx_1 = coin;
|
|
934
|
+
if (!Number.isInteger(idx_1)) {
|
|
657
935
|
throw Error('Index must be integer');
|
|
658
936
|
}
|
|
659
|
-
if (
|
|
937
|
+
if (idx_1 < 0) {
|
|
660
938
|
throw Error('Index must be >= 0');
|
|
661
939
|
}
|
|
662
|
-
if (
|
|
663
|
-
throw Error(
|
|
940
|
+
if (idx_1 > coins_N - 1) {
|
|
941
|
+
throw Error("Index must be < ".concat(coins_N));
|
|
664
942
|
}
|
|
665
|
-
return
|
|
943
|
+
return idx_1;
|
|
666
944
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
945
|
+
var coinAddress = _getCoinAddresses(coin)[0];
|
|
946
|
+
var lowerCaseCoinAddresses = useUnderlying ?
|
|
947
|
+
_this.underlyingCoinAddresses.map(function (c) { return c.toLowerCase(); }) :
|
|
948
|
+
_this.wrappedCoinAddresses.map(function (c) { return c.toLowerCase(); });
|
|
949
|
+
var idx = lowerCaseCoinAddresses.indexOf(coinAddress.toLowerCase());
|
|
672
950
|
if (idx === -1) {
|
|
673
|
-
throw Error(
|
|
951
|
+
throw Error("There is no ".concat(coin, " among ").concat(_this.name, " pool ").concat(useUnderlying ? 'underlying' : 'wrapped', " coins"));
|
|
674
952
|
}
|
|
675
953
|
return idx;
|
|
676
954
|
};
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
_rates
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
955
|
+
// Used by mixins
|
|
956
|
+
this._getRates = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
957
|
+
var _rates, i, addr, _c, _d, _e, _f;
|
|
958
|
+
return __generator(this, function (_g) {
|
|
959
|
+
switch (_g.label) {
|
|
960
|
+
case 0:
|
|
961
|
+
_rates = [];
|
|
962
|
+
i = 0;
|
|
963
|
+
_g.label = 1;
|
|
964
|
+
case 1:
|
|
965
|
+
if (!(i < this.wrappedCoinAddresses.length)) return [3 /*break*/, 9];
|
|
966
|
+
addr = this.wrappedCoinAddresses[i];
|
|
967
|
+
if (!this.useLending[i]) return [3 /*break*/, 7];
|
|
968
|
+
if (!['compound', 'usdt', 'ib'].includes(this.id)) return [3 /*break*/, 3];
|
|
969
|
+
_d = (_c = _rates).push;
|
|
970
|
+
return [4 /*yield*/, curve.contracts[addr].contract.exchangeRateStored()];
|
|
971
|
+
case 2:
|
|
972
|
+
_d.apply(_c, [_g.sent()]);
|
|
973
|
+
return [3 /*break*/, 6];
|
|
974
|
+
case 3:
|
|
975
|
+
if (!['y', 'busd', 'pax'].includes(this.id)) return [3 /*break*/, 5];
|
|
976
|
+
_f = (_e = _rates).push;
|
|
977
|
+
return [4 /*yield*/, curve.contracts[addr].contract.getPricePerFullShare()];
|
|
978
|
+
case 4:
|
|
979
|
+
_f.apply(_e, [_g.sent()]);
|
|
980
|
+
return [3 /*break*/, 6];
|
|
981
|
+
case 5:
|
|
982
|
+
_rates.push(curve.parseUnits(String(Math.pow(10, 18)), 0)); // Aave ratio 1:1
|
|
983
|
+
_g.label = 6;
|
|
984
|
+
case 6: return [3 /*break*/, 8];
|
|
985
|
+
case 7:
|
|
986
|
+
_rates.push(curve.parseUnits(String(Math.pow(10, 18)), 0));
|
|
987
|
+
_g.label = 8;
|
|
988
|
+
case 8:
|
|
989
|
+
i++;
|
|
990
|
+
return [3 /*break*/, 1];
|
|
991
|
+
case 9: return [2 /*return*/, _rates];
|
|
694
992
|
}
|
|
993
|
+
});
|
|
994
|
+
}); };
|
|
995
|
+
this._balances = function (rawCoinNames, rawCoinAddresses) {
|
|
996
|
+
var addresses = [];
|
|
997
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
998
|
+
addresses[_i - 2] = arguments[_i];
|
|
695
999
|
}
|
|
696
|
-
return
|
|
1000
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
1001
|
+
var coinNames, coinAddresses, i, rawBalances, balances, _c, addresses_1, address, _d, coinNames_1, coinName;
|
|
1002
|
+
return __generator(this, function (_e) {
|
|
1003
|
+
switch (_e.label) {
|
|
1004
|
+
case 0:
|
|
1005
|
+
coinNames = [];
|
|
1006
|
+
coinAddresses = [];
|
|
1007
|
+
// removing duplicates
|
|
1008
|
+
for (i = 0; i < rawCoinAddresses.length; i++) {
|
|
1009
|
+
if (!coinAddresses.includes(rawCoinAddresses[i])) {
|
|
1010
|
+
coinNames.push(rawCoinNames[i]);
|
|
1011
|
+
coinAddresses.push(rawCoinAddresses[i]);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
addresses = _prepareAddresses(addresses);
|
|
1015
|
+
return [4 /*yield*/, _getBalances(coinAddresses, addresses)];
|
|
1016
|
+
case 1:
|
|
1017
|
+
rawBalances = _e.sent();
|
|
1018
|
+
balances = {};
|
|
1019
|
+
for (_c = 0, addresses_1 = addresses; _c < addresses_1.length; _c++) {
|
|
1020
|
+
address = addresses_1[_c];
|
|
1021
|
+
balances[address] = {};
|
|
1022
|
+
for (_d = 0, coinNames_1 = coinNames; _d < coinNames_1.length; _d++) {
|
|
1023
|
+
coinName = coinNames_1[_d];
|
|
1024
|
+
balances[address][coinName] = rawBalances[address].shift();
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
return [2 /*return*/, addresses.length === 1 ? balances[addresses[0]] : balances];
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
});
|
|
697
1031
|
};
|
|
698
|
-
this.
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
1032
|
+
this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1033
|
+
var promises, _i, _c, addr;
|
|
1034
|
+
return __generator(this, function (_d) {
|
|
1035
|
+
switch (_d.label) {
|
|
1036
|
+
case 0:
|
|
1037
|
+
promises = [];
|
|
1038
|
+
for (_i = 0, _c = this.underlyingCoinAddresses; _i < _c.length; _i++) {
|
|
1039
|
+
addr = _c[_i];
|
|
1040
|
+
promises.push(_getUsdRate(addr));
|
|
1041
|
+
}
|
|
1042
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
1043
|
+
case 1: return [2 /*return*/, _d.sent()];
|
|
706
1044
|
}
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
const rawBalances = await _getBalances(coinAddresses, addresses);
|
|
710
|
-
const balances = {};
|
|
711
|
-
for (const address of addresses) {
|
|
712
|
-
balances[address] = {};
|
|
713
|
-
for (const coinName of coinNames) {
|
|
714
|
-
balances[address][coinName] = rawBalances[address].shift();
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return addresses.length === 1 ? balances[addresses[0]] : balances;
|
|
718
|
-
};
|
|
719
|
-
this._underlyingPrices = async () => {
|
|
720
|
-
const promises = [];
|
|
721
|
-
for (const addr of this.underlyingCoinAddresses) {
|
|
722
|
-
promises.push(_getUsdRate(addr));
|
|
723
|
-
}
|
|
724
|
-
return await Promise.all(promises);
|
|
725
|
-
};
|
|
1045
|
+
});
|
|
1046
|
+
}); };
|
|
726
1047
|
// NOTE! It may crash!
|
|
727
|
-
this._wrappedPrices =
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
1048
|
+
this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1049
|
+
var promises, _i, _c, addr;
|
|
1050
|
+
return __generator(this, function (_d) {
|
|
1051
|
+
switch (_d.label) {
|
|
1052
|
+
case 0:
|
|
1053
|
+
promises = [];
|
|
1054
|
+
for (_i = 0, _c = this.wrappedCoinAddresses; _i < _c.length; _i++) {
|
|
1055
|
+
addr = _c[_i];
|
|
1056
|
+
promises.push(_getUsdRate(addr));
|
|
1057
|
+
}
|
|
1058
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
1059
|
+
case 1: return [2 /*return*/, _d.sent()];
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
}); };
|
|
1063
|
+
var poolData = __assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRYPTO_FACTORY_POOLS_DATA)[id];
|
|
735
1064
|
this.id = id;
|
|
736
1065
|
this.name = poolData.name;
|
|
737
1066
|
this.fullName = poolData.full_name;
|
|
@@ -751,15 +1080,15 @@ export class PoolTemplate {
|
|
|
751
1080
|
this.isFactory = poolData.is_factory || false;
|
|
752
1081
|
this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
|
|
753
1082
|
this.basePool = poolData.base_pool || '';
|
|
754
|
-
this.metaCoinIdx = this.isMeta ? poolData.meta_coin_idx
|
|
1083
|
+
this.metaCoinIdx = this.isMeta ? (_c = poolData.meta_coin_idx) !== null && _c !== void 0 ? _c : poolData.wrapped_coins.length - 1 : -1;
|
|
755
1084
|
this.underlyingCoins = poolData.underlying_coins;
|
|
756
1085
|
this.wrappedCoins = poolData.wrapped_coins;
|
|
757
1086
|
this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
|
|
758
1087
|
this.wrappedCoinAddresses = poolData.wrapped_coin_addresses;
|
|
759
1088
|
this.underlyingDecimals = poolData.underlying_decimals;
|
|
760
1089
|
this.wrappedDecimals = poolData.wrapped_decimals;
|
|
761
|
-
this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(()
|
|
762
|
-
this.inApi = poolData.in_api
|
|
1090
|
+
this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(function () { return false; });
|
|
1091
|
+
this.inApi = (_d = poolData.in_api) !== null && _d !== void 0 ? _d : false;
|
|
763
1092
|
this.estimateGas = {
|
|
764
1093
|
depositApprove: this.depositApproveEstimateGas.bind(this),
|
|
765
1094
|
deposit: this.depositEstimateGas.bind(this),
|
|
@@ -806,92 +1135,168 @@ export class PoolTemplate {
|
|
|
806
1135
|
allCoinBalances: this.walletAllCoinBalances.bind(this),
|
|
807
1136
|
};
|
|
808
1137
|
}
|
|
809
|
-
rewardsOnly() {
|
|
1138
|
+
PoolTemplate.prototype.rewardsOnly = function () {
|
|
810
1139
|
if (curve.chainId === 2222)
|
|
811
1140
|
return true; // TODO remove this for Kava and Celo
|
|
812
1141
|
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
813
|
-
throw Error(
|
|
814
|
-
|
|
1142
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
1143
|
+
var gaugeContract = curve.contracts[this.gauge].contract;
|
|
815
1144
|
return !('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
1145
|
+
};
|
|
1146
|
+
PoolTemplate.prototype.statsWrappedBalances = function () {
|
|
1147
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1148
|
+
var swapContract, contractCalls, _wrappedBalances;
|
|
1149
|
+
var _this = this;
|
|
1150
|
+
return __generator(this, function (_c) {
|
|
1151
|
+
switch (_c.label) {
|
|
1152
|
+
case 0:
|
|
1153
|
+
swapContract = curve.contracts[this.address].multicallContract;
|
|
1154
|
+
contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
|
|
1155
|
+
return [4 /*yield*/, curve.multicallProvider.all(contractCalls)];
|
|
1156
|
+
case 1:
|
|
1157
|
+
_wrappedBalances = _c.sent();
|
|
1158
|
+
return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return curve.formatUnits(_b, _this.wrappedDecimals[i]); })];
|
|
1159
|
+
}
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
};
|
|
823
1163
|
// OVERRIDE
|
|
824
|
-
|
|
825
|
-
return
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
1164
|
+
PoolTemplate.prototype.statsUnderlyingBalances = function () {
|
|
1165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1166
|
+
return __generator(this, function (_c) {
|
|
1167
|
+
switch (_c.label) {
|
|
1168
|
+
case 0: return [4 /*yield*/, this.statsWrappedBalances()];
|
|
1169
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1173
|
+
};
|
|
1174
|
+
PoolTemplate.prototype._pureCalcLpTokenAmount = function (_amounts, isDeposit, useUnderlying) {
|
|
1175
|
+
if (isDeposit === void 0) { isDeposit = true; }
|
|
1176
|
+
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
1177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1178
|
+
var calcContractAddress, N_coins, contract;
|
|
1179
|
+
return __generator(this, function (_c) {
|
|
1180
|
+
switch (_c.label) {
|
|
1181
|
+
case 0:
|
|
1182
|
+
calcContractAddress = this.isMeta && useUnderlying ? this.zap : this.address;
|
|
1183
|
+
N_coins = useUnderlying ? this.underlyingCoins.length : this.wrappedCoins.length;
|
|
1184
|
+
contract = curve.contracts[calcContractAddress].contract;
|
|
1185
|
+
if (!(this.isMetaFactory && useUnderlying)) return [3 /*break*/, 4];
|
|
1186
|
+
if (!contract["calc_token_amount(address,uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 2];
|
|
1187
|
+
return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, isDeposit, curve.constantOptions)];
|
|
1188
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1189
|
+
case 2: return [4 /*yield*/, contract.calc_token_amount(this.address, _amounts, curve.constantOptions)];
|
|
1190
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
1191
|
+
case 4:
|
|
1192
|
+
if (!contract["calc_token_amount(uint256[".concat(N_coins, "],bool)")]) return [3 /*break*/, 6];
|
|
1193
|
+
return [4 /*yield*/, contract.calc_token_amount(_amounts, isDeposit, curve.constantOptions)];
|
|
1194
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
1195
|
+
case 6: return [4 /*yield*/, contract.calc_token_amount(_amounts, curve.constantOptions)];
|
|
1196
|
+
case 7: return [2 /*return*/, _c.sent()];
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
};
|
|
1201
|
+
PoolTemplate.prototype.calcLpTokenAmount = function (amounts, isDeposit) {
|
|
1202
|
+
if (isDeposit === void 0) { isDeposit = true; }
|
|
1203
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1204
|
+
var _underlyingAmounts, _expected;
|
|
1205
|
+
var _this = this;
|
|
1206
|
+
return __generator(this, function (_c) {
|
|
1207
|
+
switch (_c.label) {
|
|
1208
|
+
case 0:
|
|
1209
|
+
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
1210
|
+
throw Error("".concat(this.name, " pool has ").concat(this.underlyingCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
1211
|
+
}
|
|
1212
|
+
_underlyingAmounts = amounts.map(function (amount, i) { return parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
1213
|
+
return [4 /*yield*/, this._calcLpTokenAmount(_underlyingAmounts, isDeposit, true)];
|
|
1214
|
+
case 1:
|
|
1215
|
+
_expected = _c.sent();
|
|
1216
|
+
return [2 /*return*/, curve.formatUnits(_expected)];
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1221
|
+
PoolTemplate.prototype.calcLpTokenAmountWrapped = function (amounts, isDeposit) {
|
|
1222
|
+
if (isDeposit === void 0) { isDeposit = true; }
|
|
1223
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1224
|
+
var _amounts, _expected;
|
|
1225
|
+
var _this = this;
|
|
1226
|
+
return __generator(this, function (_c) {
|
|
1227
|
+
switch (_c.label) {
|
|
1228
|
+
case 0:
|
|
1229
|
+
if (amounts.length !== this.wrappedCoinAddresses.length) {
|
|
1230
|
+
throw Error("".concat(this.name, " pool has ").concat(this.wrappedCoinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
1231
|
+
}
|
|
1232
|
+
if (this.isFake) {
|
|
1233
|
+
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
1234
|
+
}
|
|
1235
|
+
_amounts = amounts.map(function (amount, i) { return parseUnits(amount, _this.wrappedDecimals[i]); });
|
|
1236
|
+
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, isDeposit, false)];
|
|
1237
|
+
case 1:
|
|
1238
|
+
_expected = _c.sent();
|
|
1239
|
+
return [2 /*return*/, curve.formatUnits(_expected)];
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
};
|
|
861
1244
|
// ---------------- DEPOSIT ----------------
|
|
862
|
-
metaUnderlyingSeedAmounts(amount1) {
|
|
1245
|
+
PoolTemplate.prototype.metaUnderlyingSeedAmounts = function (amount1) {
|
|
863
1246
|
if (this.isCrypto)
|
|
864
|
-
throw Error(
|
|
1247
|
+
throw Error("Use cryptoSeedAmounts method for ".concat(this.name, " pool"));
|
|
865
1248
|
if (!this.isMeta)
|
|
866
1249
|
throw Error("metaUnderlyingSeedAmounts method exists only for meta stable pools");
|
|
867
|
-
|
|
1250
|
+
var amount1BN = BN(amount1);
|
|
868
1251
|
if (amount1BN.lte(0))
|
|
869
1252
|
throw Error("Initial deposit amounts must be > 0");
|
|
870
|
-
|
|
871
|
-
for (
|
|
1253
|
+
var amounts = [_cutZeros(amount1BN.toFixed(this.underlyingDecimals[0]))];
|
|
1254
|
+
for (var i = 1; i < this.underlyingDecimals.length; i++) {
|
|
872
1255
|
amounts.push(amount1BN.div(this.underlyingDecimals.length - 1).toFixed(this.underlyingDecimals[i]));
|
|
873
1256
|
}
|
|
874
1257
|
return amounts;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
1258
|
+
};
|
|
1259
|
+
PoolTemplate.prototype.cryptoSeedAmounts = function (amount1) {
|
|
1260
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1261
|
+
var decimals, amount1BN, priceScaleBN, _c;
|
|
1262
|
+
return __generator(this, function (_d) {
|
|
1263
|
+
switch (_d.label) {
|
|
1264
|
+
case 0:
|
|
1265
|
+
if (!this.isCrypto)
|
|
1266
|
+
throw Error("cryptoSeedAmounts method doesn't exist for stable pools");
|
|
1267
|
+
decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
|
|
1268
|
+
if (decimals.length > 2)
|
|
1269
|
+
throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 2");
|
|
1270
|
+
amount1BN = BN(amount1);
|
|
1271
|
+
if (amount1BN.lte(0))
|
|
1272
|
+
throw Error("Initial deposit amounts must be > 0");
|
|
1273
|
+
_c = toBN;
|
|
1274
|
+
return [4 /*yield*/, curve.contracts[this.address].contract.price_scale(curve.constantOptions)];
|
|
1275
|
+
case 1:
|
|
1276
|
+
priceScaleBN = _c.apply(void 0, [_d.sent()]);
|
|
1277
|
+
return [2 /*return*/, [_cutZeros(amount1BN.toFixed(decimals[0])), _cutZeros(amount1BN.div(priceScaleBN).toFixed(decimals[1]))]];
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
});
|
|
1281
|
+
};
|
|
888
1282
|
// OVERRIDE
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1283
|
+
PoolTemplate.prototype.depositBalancedAmounts = function () {
|
|
1284
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1285
|
+
return __generator(this, function (_c) {
|
|
1286
|
+
throw Error("depositBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
};
|
|
1290
|
+
PoolTemplate.prototype.depositExpected = function (amounts) {
|
|
1291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1292
|
+
return __generator(this, function (_c) {
|
|
1293
|
+
switch (_c.label) {
|
|
1294
|
+
case 0: return [4 /*yield*/, this.calcLpTokenAmount(amounts)];
|
|
1295
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
};
|
|
895
1300
|
// | balanced[i] / sum(balanced[j]) = balance[i] / sum(balance[j]) |
|
|
896
1301
|
// | sum(pj * balanced[j]) = sum(aj * pj) |
|
|
897
1302
|
//
|
|
@@ -902,807 +1307,1773 @@ export class PoolTemplate {
|
|
|
902
1307
|
// totalBalanceBN = sum(balance[j])
|
|
903
1308
|
// ratiosBN[i] = balancesBN[i] / totalBalanceBN = ri = balance[i] / sum(balance[j])
|
|
904
1309
|
// denominatorBN = sum(rj * pj / ri)
|
|
905
|
-
_balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
.div(ratiosBN[i])).reduce((xBN, yBN)
|
|
1310
|
+
PoolTemplate.prototype._balancedAmountsWithSameValue = function (amountsBN, pricesBN, balancesBN) {
|
|
1311
|
+
var valuesBN = amountsBN.map(function (aBN, i) { return aBN.times(pricesBN[i]); });
|
|
1312
|
+
var totalValueBN = valuesBN.reduce(function (v1BN, v2BN) { return v1BN.plus(v2BN); });
|
|
1313
|
+
var totalBalanceBN = balancesBN.reduce(function (b1BN, b2BN) { return b1BN.plus(b2BN); });
|
|
1314
|
+
var ratiosBN = balancesBN.map(function (bBN) { return bBN.div(totalBalanceBN); });
|
|
1315
|
+
var balancedAmountsBN = [];
|
|
1316
|
+
var _loop_1 = function (i) {
|
|
1317
|
+
var denominatorBN = ratiosBN.map(function (rBN, j) { return rBN.times(pricesBN[j])
|
|
1318
|
+
.div(ratiosBN[i]); }).reduce(function (xBN, yBN) { return xBN.plus(yBN); });
|
|
914
1319
|
balancedAmountsBN.push(totalValueBN.div(denominatorBN));
|
|
1320
|
+
};
|
|
1321
|
+
for (var i = 0; i < amountsBN.length; i++) {
|
|
1322
|
+
_loop_1(i);
|
|
915
1323
|
}
|
|
916
1324
|
return balancedAmountsBN.map(String);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1325
|
+
};
|
|
1326
|
+
PoolTemplate.prototype.depositBonus = function (amounts) {
|
|
1327
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1328
|
+
var amountsBN, prices, _c, pricesBN, balancesBN, balancedAmounts, expectedBN, _d, balancedExpectedBN, _e;
|
|
1329
|
+
return __generator(this, function (_f) {
|
|
1330
|
+
switch (_f.label) {
|
|
1331
|
+
case 0:
|
|
1332
|
+
amountsBN = amounts.map(BN);
|
|
1333
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
1334
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
1335
|
+
case 1:
|
|
1336
|
+
_c = _f.sent();
|
|
1337
|
+
return [3 /*break*/, 3];
|
|
1338
|
+
case 2:
|
|
1339
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
1340
|
+
_f.label = 3;
|
|
1341
|
+
case 3:
|
|
1342
|
+
prices = _c;
|
|
1343
|
+
pricesBN = prices.map(BN);
|
|
1344
|
+
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
1345
|
+
case 4:
|
|
1346
|
+
balancesBN = (_f.sent()).map(BN);
|
|
1347
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1348
|
+
_d = BN;
|
|
1349
|
+
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1350
|
+
case 5:
|
|
1351
|
+
expectedBN = _d.apply(void 0, [_f.sent()]);
|
|
1352
|
+
_e = BN;
|
|
1353
|
+
return [4 /*yield*/, this.depositExpected(balancedAmounts)];
|
|
1354
|
+
case 6:
|
|
1355
|
+
balancedExpectedBN = _e.apply(void 0, [_f.sent()]);
|
|
1356
|
+
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
});
|
|
1360
|
+
};
|
|
1361
|
+
PoolTemplate.prototype.depositIsApproved = function (amounts) {
|
|
1362
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1363
|
+
return __generator(this, function (_c) {
|
|
1364
|
+
switch (_c.label) {
|
|
1365
|
+
case 0: return [4 /*yield*/, hasAllowance(this.underlyingCoinAddresses, amounts, curve.signerAddress, this.zap || this.address)];
|
|
1366
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1367
|
+
}
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
};
|
|
1371
|
+
PoolTemplate.prototype.depositApproveEstimateGas = function (amounts) {
|
|
1372
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1373
|
+
return __generator(this, function (_c) {
|
|
1374
|
+
switch (_c.label) {
|
|
1375
|
+
case 0: return [4 /*yield*/, ensureAllowanceEstimateGas(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
|
|
1376
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
});
|
|
1380
|
+
};
|
|
1381
|
+
PoolTemplate.prototype.depositApprove = function (amounts) {
|
|
1382
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1383
|
+
return __generator(this, function (_c) {
|
|
1384
|
+
switch (_c.label) {
|
|
1385
|
+
case 0: return [4 /*yield*/, ensureAllowance(this.underlyingCoinAddresses, amounts, this.zap || this.address)];
|
|
1386
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
};
|
|
937
1391
|
// OVERRIDE
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1392
|
+
PoolTemplate.prototype.depositEstimateGas = function (amounts) {
|
|
1393
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1394
|
+
return __generator(this, function (_c) {
|
|
1395
|
+
throw Error("depositEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1396
|
+
});
|
|
1397
|
+
});
|
|
1398
|
+
};
|
|
941
1399
|
// OVERRIDE
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1400
|
+
PoolTemplate.prototype.deposit = function (amounts, slippage) {
|
|
1401
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
1402
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1403
|
+
return __generator(this, function (_c) {
|
|
1404
|
+
throw Error("deposit method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
};
|
|
945
1408
|
// ---------------- DEPOSIT WRAPPED ----------------
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
return
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1409
|
+
PoolTemplate.prototype.depositWrappedBalancedAmounts = function () {
|
|
1410
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1411
|
+
return __generator(this, function (_c) {
|
|
1412
|
+
throw Error("depositWrappedBalancedAmounts method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1413
|
+
});
|
|
1414
|
+
});
|
|
1415
|
+
};
|
|
1416
|
+
PoolTemplate.prototype.depositWrappedExpected = function (amounts) {
|
|
1417
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1418
|
+
return __generator(this, function (_c) {
|
|
1419
|
+
switch (_c.label) {
|
|
1420
|
+
case 0:
|
|
1421
|
+
if (this.isFake) {
|
|
1422
|
+
throw Error("depositWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1423
|
+
}
|
|
1424
|
+
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts)];
|
|
1425
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
};
|
|
1430
|
+
PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
|
|
1431
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1432
|
+
var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
|
|
1433
|
+
return __generator(this, function (_e) {
|
|
1434
|
+
switch (_e.label) {
|
|
1435
|
+
case 0:
|
|
1436
|
+
amountsBN = amounts.map(BN);
|
|
1437
|
+
return [4 /*yield*/, this._wrappedPrices()];
|
|
1438
|
+
case 1:
|
|
1439
|
+
pricesBN = (_e.sent()).map(BN);
|
|
1440
|
+
return [4 /*yield*/, this.stats.wrappedBalances()];
|
|
1441
|
+
case 2:
|
|
1442
|
+
balancesBN = (_e.sent()).map(BN);
|
|
1443
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1444
|
+
_c = BN;
|
|
1445
|
+
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
1446
|
+
case 3:
|
|
1447
|
+
expectedBN = _c.apply(void 0, [_e.sent()]);
|
|
1448
|
+
_d = BN;
|
|
1449
|
+
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
1450
|
+
case 4:
|
|
1451
|
+
balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
|
|
1452
|
+
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
1456
|
+
};
|
|
1457
|
+
PoolTemplate.prototype.depositWrappedIsApproved = function (amounts) {
|
|
1458
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1459
|
+
return __generator(this, function (_c) {
|
|
1460
|
+
switch (_c.label) {
|
|
1461
|
+
case 0:
|
|
1462
|
+
if (this.isFake) {
|
|
1463
|
+
throw Error("depositWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1464
|
+
}
|
|
1465
|
+
return [4 /*yield*/, hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, this.address)];
|
|
1466
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
});
|
|
1470
|
+
};
|
|
1471
|
+
PoolTemplate.prototype.depositWrappedApproveEstimateGas = function (amounts) {
|
|
1472
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1473
|
+
return __generator(this, function (_c) {
|
|
1474
|
+
switch (_c.label) {
|
|
1475
|
+
case 0:
|
|
1476
|
+
if (this.isFake) {
|
|
1477
|
+
throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1478
|
+
}
|
|
1479
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas(this.wrappedCoinAddresses, amounts, this.address)];
|
|
1480
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
});
|
|
1484
|
+
};
|
|
1485
|
+
PoolTemplate.prototype.depositWrappedApprove = function (amounts) {
|
|
1486
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1487
|
+
return __generator(this, function (_c) {
|
|
1488
|
+
switch (_c.label) {
|
|
1489
|
+
case 0:
|
|
1490
|
+
if (this.isFake) {
|
|
1491
|
+
throw Error("depositWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1492
|
+
}
|
|
1493
|
+
return [4 /*yield*/, ensureAllowance(this.wrappedCoinAddresses, amounts, this.address)];
|
|
1494
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
});
|
|
1498
|
+
};
|
|
982
1499
|
// OVERRIDE
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1500
|
+
PoolTemplate.prototype.depositWrappedEstimateGas = function (amounts) {
|
|
1501
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1502
|
+
return __generator(this, function (_c) {
|
|
1503
|
+
throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1504
|
+
});
|
|
1505
|
+
});
|
|
1506
|
+
};
|
|
986
1507
|
// OVERRIDE
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1508
|
+
PoolTemplate.prototype.depositWrapped = function (amounts, slippage) {
|
|
1509
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
1510
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1511
|
+
return __generator(this, function (_c) {
|
|
1512
|
+
throw Error("depositWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1513
|
+
});
|
|
1514
|
+
});
|
|
1515
|
+
};
|
|
990
1516
|
// ---------------- STAKING ----------------
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1517
|
+
PoolTemplate.prototype.stakeIsApproved = function (lpTokenAmount) {
|
|
1518
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1519
|
+
return __generator(this, function (_c) {
|
|
1520
|
+
switch (_c.label) {
|
|
1521
|
+
case 0:
|
|
1522
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1523
|
+
throw Error("stakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1524
|
+
}
|
|
1525
|
+
return [4 /*yield*/, hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.gauge)];
|
|
1526
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
});
|
|
1530
|
+
};
|
|
1531
|
+
PoolTemplate.prototype.stakeApproveEstimateGas = function (lpTokenAmount) {
|
|
1532
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1533
|
+
return __generator(this, function (_c) {
|
|
1534
|
+
switch (_c.label) {
|
|
1535
|
+
case 0:
|
|
1536
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1537
|
+
throw Error("stakeApproveEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1538
|
+
}
|
|
1539
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1540
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
1543
|
+
});
|
|
1544
|
+
};
|
|
1545
|
+
PoolTemplate.prototype.stakeApprove = function (lpTokenAmount) {
|
|
1546
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1547
|
+
return __generator(this, function (_c) {
|
|
1548
|
+
switch (_c.label) {
|
|
1549
|
+
case 0:
|
|
1550
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1551
|
+
throw Error("stakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1552
|
+
}
|
|
1553
|
+
return [4 /*yield*/, ensureAllowance([this.lpToken], [lpTokenAmount], this.gauge)];
|
|
1554
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1555
|
+
}
|
|
1556
|
+
});
|
|
1557
|
+
});
|
|
1558
|
+
};
|
|
1559
|
+
PoolTemplate.prototype.stakeEstimateGas = function (lpTokenAmount) {
|
|
1560
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1561
|
+
var _lpTokenAmount, _c;
|
|
1562
|
+
return __generator(this, function (_d) {
|
|
1563
|
+
switch (_d.label) {
|
|
1564
|
+
case 0:
|
|
1565
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1566
|
+
throw Error("stakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1567
|
+
}
|
|
1568
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
1569
|
+
_c = Number;
|
|
1570
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.deposit.estimateGas(_lpTokenAmount, curve.constantOptions)];
|
|
1571
|
+
case 1: return [2 /*return*/, _c.apply(void 0, [_d.sent()])];
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
});
|
|
1575
|
+
};
|
|
1576
|
+
PoolTemplate.prototype.stake = function (lpTokenAmount) {
|
|
1577
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1578
|
+
var _lpTokenAmount, gasLimit, _c;
|
|
1579
|
+
return __generator(this, function (_d) {
|
|
1580
|
+
switch (_d.label) {
|
|
1581
|
+
case 0:
|
|
1582
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1583
|
+
throw Error("stake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1584
|
+
}
|
|
1585
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
1586
|
+
return [4 /*yield*/, _ensureAllowance([this.lpToken], [_lpTokenAmount], this.gauge)];
|
|
1587
|
+
case 1:
|
|
1588
|
+
_d.sent();
|
|
1589
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
1590
|
+
case 2:
|
|
1591
|
+
_d.sent();
|
|
1592
|
+
_c = mulBy1_3;
|
|
1593
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.deposit.estimateGas(_lpTokenAmount, curve.constantOptions)];
|
|
1594
|
+
case 3:
|
|
1595
|
+
gasLimit = _c.apply(void 0, [_d.sent()]);
|
|
1596
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
1597
|
+
case 4: return [2 /*return*/, (_d.sent()).hash];
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
});
|
|
1601
|
+
};
|
|
1602
|
+
PoolTemplate.prototype.unstakeEstimateGas = function (lpTokenAmount) {
|
|
1603
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1604
|
+
var _lpTokenAmount, _c;
|
|
1605
|
+
return __generator(this, function (_d) {
|
|
1606
|
+
switch (_d.label) {
|
|
1607
|
+
case 0:
|
|
1608
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1609
|
+
throw Error("unstakeEstimateGas method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1610
|
+
}
|
|
1611
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
1612
|
+
_c = Number;
|
|
1613
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.withdraw.estimateGas(_lpTokenAmount, curve.constantOptions)];
|
|
1614
|
+
case 1: return [2 /*return*/, _c.apply(void 0, [_d.sent()])];
|
|
1615
|
+
}
|
|
1616
|
+
});
|
|
1617
|
+
});
|
|
1618
|
+
};
|
|
1619
|
+
PoolTemplate.prototype.unstake = function (lpTokenAmount) {
|
|
1620
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1621
|
+
var _lpTokenAmount, gasLimit;
|
|
1622
|
+
return __generator(this, function (_c) {
|
|
1623
|
+
switch (_c.label) {
|
|
1624
|
+
case 0:
|
|
1625
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1626
|
+
throw Error("unstake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1627
|
+
}
|
|
1628
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
1629
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
1630
|
+
case 1:
|
|
1631
|
+
_c.sent();
|
|
1632
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.withdraw.estimateGas(_lpTokenAmount, curve.constantOptions)];
|
|
1633
|
+
case 2:
|
|
1634
|
+
gasLimit = (_c.sent()) * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
|
|
1635
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
1636
|
+
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
});
|
|
1640
|
+
};
|
|
1641
|
+
PoolTemplate.prototype.claimableCrv = function (address) {
|
|
1642
|
+
if (address === void 0) { address = ""; }
|
|
1643
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1644
|
+
var _c, _d;
|
|
1645
|
+
return __generator(this, function (_e) {
|
|
1646
|
+
switch (_e.label) {
|
|
1647
|
+
case 0:
|
|
1648
|
+
if (this.rewardsOnly())
|
|
1649
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimableRewards instead"));
|
|
1650
|
+
address = address || curve.signerAddress;
|
|
1651
|
+
if (!address)
|
|
1652
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
1653
|
+
_d = (_c = curve).formatUnits;
|
|
1654
|
+
return [4 /*yield*/, curve.contracts[this.gauge].contract.claimable_tokens(address, curve.constantOptions)];
|
|
1655
|
+
case 1: return [2 /*return*/, _d.apply(_c, [_e.sent()])];
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
});
|
|
1659
|
+
};
|
|
1660
|
+
PoolTemplate.prototype.claimCrvEstimateGas = function () {
|
|
1661
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1662
|
+
var _c;
|
|
1663
|
+
return __generator(this, function (_d) {
|
|
1664
|
+
switch (_d.label) {
|
|
1665
|
+
case 0:
|
|
1666
|
+
if (this.rewardsOnly())
|
|
1667
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
|
|
1668
|
+
_c = Number;
|
|
1669
|
+
return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.minter].contract.mint.estimateGas(this.gauge, curve.constantOptions)];
|
|
1670
|
+
case 1: return [2 /*return*/, _c.apply(void 0, [_d.sent()])];
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
});
|
|
1674
|
+
};
|
|
1675
|
+
PoolTemplate.prototype.claimCrv = function () {
|
|
1676
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1677
|
+
var contract, gasLimit, _c;
|
|
1678
|
+
return __generator(this, function (_d) {
|
|
1679
|
+
switch (_d.label) {
|
|
1680
|
+
case 0:
|
|
1681
|
+
if (this.rewardsOnly())
|
|
1682
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use claimRewards instead"));
|
|
1683
|
+
contract = curve.contracts[curve.constants.ALIASES.minter].contract;
|
|
1684
|
+
_c = mulBy1_3;
|
|
1685
|
+
return [4 /*yield*/, contract.mint.estimateGas(this.gauge, curve.constantOptions)];
|
|
1686
|
+
case 1:
|
|
1687
|
+
gasLimit = _c.apply(void 0, [_d.sent()]);
|
|
1688
|
+
return [4 /*yield*/, contract.mint(this.gauge, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
1689
|
+
case 2: return [2 /*return*/, (_d.sent()).hash];
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
1692
|
+
});
|
|
1693
|
+
};
|
|
1062
1694
|
// TODO 1. Fix aave and saave error
|
|
1063
|
-
|
|
1064
|
-
if (
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1695
|
+
PoolTemplate.prototype.claimableRewards = function (address) {
|
|
1696
|
+
if (address === void 0) { address = ""; }
|
|
1697
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1698
|
+
var gaugeContract, rewardTokens, rewards, _i, rewardTokens_5, rewardToken, _amount, rewardToken, _totalAmount, _claimedAmount;
|
|
1699
|
+
return __generator(this, function (_c) {
|
|
1700
|
+
switch (_c.label) {
|
|
1701
|
+
case 0:
|
|
1702
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1703
|
+
throw Error("claimableRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1704
|
+
}
|
|
1705
|
+
address = address || curve.signerAddress;
|
|
1706
|
+
if (!address)
|
|
1707
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
1708
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1709
|
+
return [4 /*yield*/, this.rewardTokens()];
|
|
1710
|
+
case 1:
|
|
1711
|
+
rewardTokens = _c.sent();
|
|
1712
|
+
rewards = [];
|
|
1713
|
+
if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 6];
|
|
1714
|
+
_i = 0, rewardTokens_5 = rewardTokens;
|
|
1715
|
+
_c.label = 2;
|
|
1716
|
+
case 2:
|
|
1717
|
+
if (!(_i < rewardTokens_5.length)) return [3 /*break*/, 5];
|
|
1718
|
+
rewardToken = rewardTokens_5[_i];
|
|
1719
|
+
return [4 /*yield*/, gaugeContract.claimable_reward(address, rewardToken.token, curve.constantOptions)];
|
|
1720
|
+
case 3:
|
|
1721
|
+
_amount = _c.sent();
|
|
1722
|
+
rewards.push({
|
|
1723
|
+
token: rewardToken.token,
|
|
1724
|
+
symbol: rewardToken.symbol,
|
|
1725
|
+
amount: curve.formatUnits(_amount, rewardToken.decimals),
|
|
1726
|
+
});
|
|
1727
|
+
_c.label = 4;
|
|
1728
|
+
case 4:
|
|
1729
|
+
_i++;
|
|
1730
|
+
return [3 /*break*/, 2];
|
|
1731
|
+
case 5: return [3 /*break*/, 9];
|
|
1732
|
+
case 6:
|
|
1733
|
+
if (!('claimable_reward(address)' in gaugeContract && rewardTokens.length > 0)) return [3 /*break*/, 9];
|
|
1734
|
+
rewardToken = rewardTokens[0];
|
|
1735
|
+
return [4 /*yield*/, gaugeContract.claimable_reward(address, curve.constantOptions)];
|
|
1736
|
+
case 7:
|
|
1737
|
+
_totalAmount = _c.sent();
|
|
1738
|
+
return [4 /*yield*/, gaugeContract.claimed_rewards_for(address, curve.constantOptions)];
|
|
1739
|
+
case 8:
|
|
1740
|
+
_claimedAmount = _c.sent();
|
|
1741
|
+
rewards.push({
|
|
1742
|
+
token: rewardToken.token,
|
|
1743
|
+
symbol: rewardToken.symbol,
|
|
1744
|
+
amount: curve.formatUnits(_totalAmount.sub(_claimedAmount), rewardToken.decimals),
|
|
1745
|
+
});
|
|
1746
|
+
_c.label = 9;
|
|
1747
|
+
case 9: return [2 /*return*/, rewards];
|
|
1748
|
+
}
|
|
1091
1749
|
});
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
return
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1750
|
+
});
|
|
1751
|
+
};
|
|
1752
|
+
PoolTemplate.prototype.claimRewardsEstimateGas = function () {
|
|
1753
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1754
|
+
var gaugeContract, _c;
|
|
1755
|
+
return __generator(this, function (_d) {
|
|
1756
|
+
switch (_d.label) {
|
|
1757
|
+
case 0:
|
|
1758
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1759
|
+
throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1760
|
+
}
|
|
1761
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1762
|
+
if (!("claim_rewards()" in gaugeContract))
|
|
1763
|
+
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
1764
|
+
_c = Number;
|
|
1765
|
+
return [4 /*yield*/, gaugeContract.claim_rewards.estimateGas(curve.constantOptions)];
|
|
1766
|
+
case 1: return [2 /*return*/, _c.apply(void 0, [_d.sent()])];
|
|
1767
|
+
}
|
|
1768
|
+
});
|
|
1769
|
+
});
|
|
1770
|
+
};
|
|
1771
|
+
PoolTemplate.prototype.claimRewards = function () {
|
|
1772
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1773
|
+
var gaugeContract, gasLimit, _c;
|
|
1774
|
+
return __generator(this, function (_d) {
|
|
1775
|
+
switch (_d.label) {
|
|
1776
|
+
case 0:
|
|
1777
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1778
|
+
throw Error("claimRewards method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1779
|
+
}
|
|
1780
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1781
|
+
if (!("claim_rewards()" in gaugeContract))
|
|
1782
|
+
throw Error("".concat(this.name, " pool doesn't have such method"));
|
|
1783
|
+
_c = mulBy1_3;
|
|
1784
|
+
return [4 /*yield*/, gaugeContract.claim_rewards.estimateGas(curve.constantOptions)];
|
|
1785
|
+
case 1:
|
|
1786
|
+
gasLimit = _c.apply(void 0, [_d.sent()]);
|
|
1787
|
+
return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
1788
|
+
case 2: return [2 /*return*/, (_d.sent()).hash];
|
|
1789
|
+
}
|
|
1790
|
+
});
|
|
1791
|
+
});
|
|
1792
|
+
};
|
|
1793
|
+
// ---------------- DEPOSIT & STAKE ----------------
|
|
1794
|
+
PoolTemplate.prototype.depositAndStakeExpected = function (amounts) {
|
|
1795
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1796
|
+
return __generator(this, function (_c) {
|
|
1797
|
+
switch (_c.label) {
|
|
1798
|
+
case 0:
|
|
1799
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1800
|
+
throw Error("depositAndStakeExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1801
|
+
}
|
|
1802
|
+
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1803
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
});
|
|
1807
|
+
};
|
|
1808
|
+
PoolTemplate.prototype.depositAndStakeBonus = function (amounts) {
|
|
1809
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1810
|
+
return __generator(this, function (_c) {
|
|
1811
|
+
switch (_c.label) {
|
|
1812
|
+
case 0:
|
|
1813
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1814
|
+
throw Error("depositAndStakeBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1815
|
+
}
|
|
1816
|
+
return [4 /*yield*/, this.depositBonus(amounts)];
|
|
1817
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
});
|
|
1821
|
+
};
|
|
1822
|
+
PoolTemplate.prototype.depositAndStakeIsApproved = function (amounts) {
|
|
1823
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1824
|
+
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
1825
|
+
return __generator(this, function (_c) {
|
|
1826
|
+
switch (_c.label) {
|
|
1827
|
+
case 0:
|
|
1828
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1829
|
+
throw Error("depositAndStakeIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1830
|
+
}
|
|
1831
|
+
return [4 /*yield*/, hasAllowance(this.underlyingCoinAddresses, amounts, curve.signerAddress, curve.constants.ALIASES.deposit_and_stake)];
|
|
1832
|
+
case 1:
|
|
1833
|
+
coinsAllowance = _c.sent();
|
|
1834
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1835
|
+
if (!('approved_to_deposit' in gaugeContract)) return [3 /*break*/, 3];
|
|
1836
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions)];
|
|
1837
|
+
case 2:
|
|
1838
|
+
gaugeAllowance = _c.sent();
|
|
1839
|
+
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
1840
|
+
case 3: return [2 /*return*/, coinsAllowance];
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
});
|
|
1844
|
+
};
|
|
1845
|
+
PoolTemplate.prototype.depositAndStakeApproveEstimateGas = function (amounts) {
|
|
1846
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1847
|
+
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas, _c;
|
|
1848
|
+
return __generator(this, function (_d) {
|
|
1849
|
+
switch (_d.label) {
|
|
1850
|
+
case 0:
|
|
1851
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1852
|
+
throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1853
|
+
}
|
|
1854
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas(this.underlyingCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake)];
|
|
1855
|
+
case 1:
|
|
1856
|
+
approveCoinsGas = _d.sent();
|
|
1857
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1858
|
+
if (!('approved_to_deposit' in gaugeContract)) return [3 /*break*/, 4];
|
|
1859
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions)];
|
|
1860
|
+
case 2:
|
|
1861
|
+
gaugeAllowance = _d.sent();
|
|
1862
|
+
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
1863
|
+
_c = Number;
|
|
1864
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions)];
|
|
1865
|
+
case 3:
|
|
1866
|
+
approveGaugeGas = _c.apply(void 0, [_d.sent()]);
|
|
1867
|
+
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
1868
|
+
case 4: return [2 /*return*/, approveCoinsGas];
|
|
1869
|
+
}
|
|
1870
|
+
});
|
|
1871
|
+
});
|
|
1872
|
+
};
|
|
1873
|
+
PoolTemplate.prototype.depositAndStakeApprove = function (amounts) {
|
|
1874
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1875
|
+
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, _c, approveGaugeTx;
|
|
1876
|
+
return __generator(this, function (_d) {
|
|
1877
|
+
switch (_d.label) {
|
|
1878
|
+
case 0:
|
|
1879
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1880
|
+
throw Error("depositAndStakeApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1881
|
+
}
|
|
1882
|
+
return [4 /*yield*/, ensureAllowance(this.underlyingCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake)];
|
|
1883
|
+
case 1:
|
|
1884
|
+
approveCoinsTx = _d.sent();
|
|
1885
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1886
|
+
if (!('approved_to_deposit' in gaugeContract)) return [3 /*break*/, 5];
|
|
1887
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions)];
|
|
1888
|
+
case 2:
|
|
1889
|
+
gaugeAllowance = _d.sent();
|
|
1890
|
+
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
1891
|
+
_c = mulBy1_3;
|
|
1892
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions)];
|
|
1893
|
+
case 3:
|
|
1894
|
+
gasLimit = _c.apply(void 0, [_d.sent()]);
|
|
1895
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit(curve.constants.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
1896
|
+
case 4:
|
|
1897
|
+
approveGaugeTx = (_d.sent()).hash;
|
|
1898
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
1899
|
+
case 5: return [2 /*return*/, approveCoinsTx];
|
|
1900
|
+
}
|
|
1901
|
+
});
|
|
1902
|
+
});
|
|
1903
|
+
};
|
|
1904
|
+
PoolTemplate.prototype.depositAndStakeEstimateGas = function (amounts) {
|
|
1905
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1906
|
+
return __generator(this, function (_c) {
|
|
1907
|
+
switch (_c.label) {
|
|
1908
|
+
case 0:
|
|
1909
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1910
|
+
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1911
|
+
}
|
|
1912
|
+
return [4 /*yield*/, this._depositAndStake(amounts, 1, true, true)];
|
|
1913
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
});
|
|
1917
|
+
};
|
|
1918
|
+
PoolTemplate.prototype.depositAndStake = function (amounts, slippage) {
|
|
1919
|
+
if (slippage === void 0) { slippage = 0.1; }
|
|
1920
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1921
|
+
return __generator(this, function (_c) {
|
|
1922
|
+
switch (_c.label) {
|
|
1923
|
+
case 0:
|
|
1924
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1925
|
+
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1926
|
+
}
|
|
1927
|
+
return [4 /*yield*/, this._depositAndStake(amounts, slippage, true, false)];
|
|
1928
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
});
|
|
1932
|
+
};
|
|
1182
1933
|
// ---------------- DEPOSIT & STAKE WRAPPED ----------------
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1934
|
+
PoolTemplate.prototype.depositAndStakeWrappedExpected = function (amounts) {
|
|
1935
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1936
|
+
return __generator(this, function (_c) {
|
|
1937
|
+
switch (_c.label) {
|
|
1938
|
+
case 0:
|
|
1939
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1940
|
+
throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1941
|
+
}
|
|
1942
|
+
if (this.isPlain || this.isFake)
|
|
1943
|
+
throw Error("depositAndStakeWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1944
|
+
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
1945
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1948
|
+
});
|
|
1949
|
+
};
|
|
1950
|
+
PoolTemplate.prototype.depositAndStakeWrappedBonus = function (amounts) {
|
|
1951
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1952
|
+
return __generator(this, function (_c) {
|
|
1953
|
+
switch (_c.label) {
|
|
1954
|
+
case 0:
|
|
1955
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1956
|
+
throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1957
|
+
}
|
|
1958
|
+
if (this.isPlain || this.isFake)
|
|
1959
|
+
throw Error("depositAndStakeWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1960
|
+
return [4 /*yield*/, this.depositWrappedBonus(amounts)];
|
|
1961
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
});
|
|
1965
|
+
};
|
|
1966
|
+
PoolTemplate.prototype.depositAndStakeWrappedIsApproved = function (amounts) {
|
|
1967
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1968
|
+
var coinsAllowance, gaugeContract, gaugeAllowance;
|
|
1969
|
+
return __generator(this, function (_c) {
|
|
1970
|
+
switch (_c.label) {
|
|
1971
|
+
case 0:
|
|
1972
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1973
|
+
throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1974
|
+
}
|
|
1975
|
+
if (this.isPlain || this.isFake)
|
|
1976
|
+
throw Error("depositAndStakeWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1977
|
+
return [4 /*yield*/, hasAllowance(this.wrappedCoinAddresses, amounts, curve.signerAddress, curve.constants.ALIASES.deposit_and_stake)];
|
|
1978
|
+
case 1:
|
|
1979
|
+
coinsAllowance = _c.sent();
|
|
1980
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
1981
|
+
if (!('approved_to_deposit' in gaugeContract)) return [3 /*break*/, 3];
|
|
1982
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions)];
|
|
1983
|
+
case 2:
|
|
1984
|
+
gaugeAllowance = _c.sent();
|
|
1985
|
+
return [2 /*return*/, coinsAllowance && gaugeAllowance];
|
|
1986
|
+
case 3: return [2 /*return*/, coinsAllowance];
|
|
1987
|
+
}
|
|
1988
|
+
});
|
|
1989
|
+
});
|
|
1990
|
+
};
|
|
1991
|
+
PoolTemplate.prototype.depositAndStakeWrappedApproveEstimateGas = function (amounts) {
|
|
1992
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1993
|
+
var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas, _c;
|
|
1994
|
+
return __generator(this, function (_d) {
|
|
1995
|
+
switch (_d.label) {
|
|
1996
|
+
case 0:
|
|
1997
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
1998
|
+
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1999
|
+
}
|
|
2000
|
+
if (this.isPlain || this.isFake)
|
|
2001
|
+
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2002
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas(this.wrappedCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake)];
|
|
2003
|
+
case 1:
|
|
2004
|
+
approveCoinsGas = _d.sent();
|
|
2005
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
2006
|
+
if (!('approved_to_deposit' in gaugeContract)) return [3 /*break*/, 4];
|
|
2007
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions)];
|
|
2008
|
+
case 2:
|
|
2009
|
+
gaugeAllowance = _d.sent();
|
|
2010
|
+
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
2011
|
+
_c = Number;
|
|
2012
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions)];
|
|
2013
|
+
case 3:
|
|
2014
|
+
approveGaugeGas = _c.apply(void 0, [_d.sent()]);
|
|
2015
|
+
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
2016
|
+
case 4: return [2 /*return*/, approveCoinsGas];
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
});
|
|
2020
|
+
};
|
|
2021
|
+
PoolTemplate.prototype.depositAndStakeWrappedApprove = function (amounts) {
|
|
2022
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2023
|
+
var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, _c, approveGaugeTx;
|
|
2024
|
+
return __generator(this, function (_d) {
|
|
2025
|
+
switch (_d.label) {
|
|
2026
|
+
case 0:
|
|
2027
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
2028
|
+
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
2029
|
+
}
|
|
2030
|
+
if (this.isPlain || this.isFake)
|
|
2031
|
+
throw Error("depositAndStakeWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2032
|
+
return [4 /*yield*/, ensureAllowance(this.wrappedCoinAddresses, amounts, curve.constants.ALIASES.deposit_and_stake)];
|
|
2033
|
+
case 1:
|
|
2034
|
+
approveCoinsTx = _d.sent();
|
|
2035
|
+
gaugeContract = curve.contracts[this.gauge].contract;
|
|
2036
|
+
if (!('approved_to_deposit' in gaugeContract)) return [3 /*break*/, 5];
|
|
2037
|
+
return [4 /*yield*/, gaugeContract.approved_to_deposit(curve.constants.ALIASES.deposit_and_stake, curve.signerAddress, curve.constantOptions)];
|
|
2038
|
+
case 2:
|
|
2039
|
+
gaugeAllowance = _d.sent();
|
|
2040
|
+
if (!!gaugeAllowance) return [3 /*break*/, 5];
|
|
2041
|
+
_c = mulBy1_3;
|
|
2042
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions)];
|
|
2043
|
+
case 3:
|
|
2044
|
+
gasLimit = _c.apply(void 0, [_d.sent()]);
|
|
2045
|
+
return [4 /*yield*/, gaugeContract.set_approve_deposit(curve.constants.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
2046
|
+
case 4:
|
|
2047
|
+
approveGaugeTx = (_d.sent()).hash;
|
|
2048
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
|
|
2049
|
+
case 5: return [2 /*return*/, approveCoinsTx];
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
});
|
|
2053
|
+
};
|
|
2054
|
+
PoolTemplate.prototype.depositAndStakeWrappedEstimateGas = function (amounts) {
|
|
2055
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2056
|
+
return __generator(this, function (_c) {
|
|
2057
|
+
switch (_c.label) {
|
|
2058
|
+
case 0:
|
|
2059
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
2060
|
+
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
2061
|
+
}
|
|
2062
|
+
if (this.isPlain || this.isFake)
|
|
2063
|
+
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2064
|
+
return [4 /*yield*/, this._depositAndStake(amounts, 1, false, true)];
|
|
2065
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2066
|
+
}
|
|
2067
|
+
});
|
|
2068
|
+
});
|
|
2069
|
+
};
|
|
2070
|
+
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts, slippage) {
|
|
2071
|
+
if (slippage === void 0) { slippage = 0.1; }
|
|
2072
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2073
|
+
return __generator(this, function (_c) {
|
|
2074
|
+
switch (_c.label) {
|
|
2075
|
+
case 0:
|
|
2076
|
+
if (this.gauge === curve.constants.ZERO_ADDRESS) {
|
|
2077
|
+
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
2078
|
+
}
|
|
2079
|
+
if (this.isPlain || this.isFake)
|
|
2080
|
+
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2081
|
+
return [4 /*yield*/, this._depositAndStake(amounts, slippage, false, false)];
|
|
2082
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
});
|
|
2086
|
+
};
|
|
2087
|
+
PoolTemplate.prototype._depositAndStake = function (amounts, slippage, isUnderlying, estimateGas) {
|
|
2088
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2089
|
+
var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _expectedLpTokenAmount, _j, _k, _l, _m, _o, minAmountBN, _minMintAmount, ethIndex, value, maxCoins, i, _gas, gasLimit;
|
|
2090
|
+
return __generator(this, function (_q) {
|
|
2091
|
+
switch (_q.label) {
|
|
2092
|
+
case 0:
|
|
2093
|
+
coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.wrappedCoinAddresses, true);
|
|
2094
|
+
coins = isUnderlying ? this.underlyingCoins : this.wrappedCoinAddresses;
|
|
2095
|
+
decimals = isUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
|
|
2096
|
+
depositAddress = isUnderlying ? this.zap || this.address : this.address;
|
|
2097
|
+
if (amounts.length !== coinAddresses.length) {
|
|
2098
|
+
throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
|
|
2099
|
+
}
|
|
2100
|
+
if (!isUnderlying) return [3 /*break*/, 2];
|
|
2101
|
+
_e = (_d = Object).values;
|
|
2102
|
+
return [4 /*yield*/, this.walletUnderlyingCoinBalances()];
|
|
2103
|
+
case 1:
|
|
2104
|
+
_c = _e.apply(_d, [_q.sent()]);
|
|
2105
|
+
return [3 /*break*/, 4];
|
|
2106
|
+
case 2:
|
|
2107
|
+
_g = (_f = Object).values;
|
|
2108
|
+
return [4 /*yield*/, this.walletWrappedCoinBalances()];
|
|
2109
|
+
case 3:
|
|
2110
|
+
_c = _g.apply(_f, [_q.sent()]);
|
|
2111
|
+
_q.label = 4;
|
|
2112
|
+
case 4:
|
|
2113
|
+
balances = _c;
|
|
2114
|
+
for (i = 0; i < balances.length; i++) {
|
|
2115
|
+
if (Number(balances[i]) < Number(amounts[i])) {
|
|
2116
|
+
throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
if (!isUnderlying) return [3 /*break*/, 6];
|
|
2120
|
+
return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
|
|
2121
|
+
case 5:
|
|
2122
|
+
_h = _q.sent();
|
|
2123
|
+
return [3 /*break*/, 8];
|
|
2124
|
+
case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
|
|
2125
|
+
case 7:
|
|
2126
|
+
_h = _q.sent();
|
|
2127
|
+
_q.label = 8;
|
|
2128
|
+
case 8:
|
|
2129
|
+
allowance = _h;
|
|
2130
|
+
if (estimateGas && !allowance) {
|
|
2131
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
2132
|
+
}
|
|
2133
|
+
if (!!estimateGas) return [3 /*break*/, 12];
|
|
2134
|
+
if (!isUnderlying) return [3 /*break*/, 10];
|
|
2135
|
+
return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
|
|
2136
|
+
case 9:
|
|
2137
|
+
_q.sent();
|
|
2138
|
+
return [3 /*break*/, 12];
|
|
2139
|
+
case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
|
|
2140
|
+
case 11:
|
|
2141
|
+
_q.sent();
|
|
2142
|
+
_q.label = 12;
|
|
2143
|
+
case 12:
|
|
2144
|
+
_amounts = amounts.map(function (amount, i) { return parseUnits(amount, decimals[i]); });
|
|
2145
|
+
contract = curve.contracts[curve.constants.ALIASES.deposit_and_stake].contract;
|
|
2146
|
+
useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && (!this.zap || this.id == 'avaxcrypto');
|
|
2147
|
+
if (!isUnderlying) return [3 /*break*/, 14];
|
|
2148
|
+
_l = (_k = curve).parseUnits;
|
|
2149
|
+
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
2150
|
+
case 13:
|
|
2151
|
+
_j = _l.apply(_k, [_q.sent()]);
|
|
2152
|
+
return [3 /*break*/, 16];
|
|
2153
|
+
case 14:
|
|
2154
|
+
_o = (_m = curve).parseUnits;
|
|
2155
|
+
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
2156
|
+
case 15:
|
|
2157
|
+
_j = _o.apply(_m, [_q.sent()]);
|
|
2158
|
+
_q.label = 16;
|
|
2159
|
+
case 16:
|
|
2160
|
+
_expectedLpTokenAmount = _j;
|
|
2161
|
+
minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
2162
|
+
_minMintAmount = fromBN(minAmountBN);
|
|
2163
|
+
ethIndex = getEthIndex(coinAddresses);
|
|
2164
|
+
value = _amounts[ethIndex] || curve.parseUnits("0");
|
|
2165
|
+
maxCoins = curve.chainId === 137 ? 6 : 5;
|
|
2166
|
+
for (i = 0; i < maxCoins; i++) {
|
|
2167
|
+
coinAddresses[i] = coinAddresses[i] || curve.constants.ZERO_ADDRESS;
|
|
2168
|
+
_amounts[i] = _amounts[i] || curve.parseUnits("0");
|
|
2169
|
+
}
|
|
2170
|
+
return [4 /*yield*/, contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
2171
|
+
case 17:
|
|
2172
|
+
_gas = (_q.sent());
|
|
2173
|
+
if (estimateGas)
|
|
2174
|
+
return [2 /*return*/, Number(_gas)];
|
|
2175
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
2176
|
+
case 18:
|
|
2177
|
+
_q.sent();
|
|
2178
|
+
gasLimit = _gas * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
|
|
2179
|
+
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
|
|
2180
|
+
case 19: return [2 /*return*/, (_q.sent()).hash];
|
|
2181
|
+
}
|
|
2182
|
+
});
|
|
2183
|
+
});
|
|
2184
|
+
};
|
|
1312
2185
|
// ---------------- WITHDRAW ----------------
|
|
1313
2186
|
// OVERRIDE
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
2187
|
+
PoolTemplate.prototype.withdrawExpected = function (lpTokenAmount) {
|
|
2188
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2189
|
+
return __generator(this, function (_c) {
|
|
2190
|
+
throw Error("withdrawExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2191
|
+
});
|
|
2192
|
+
});
|
|
2193
|
+
};
|
|
2194
|
+
PoolTemplate.prototype.withdrawIsApproved = function (lpTokenAmount) {
|
|
2195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2196
|
+
return __generator(this, function (_c) {
|
|
2197
|
+
switch (_c.label) {
|
|
2198
|
+
case 0:
|
|
2199
|
+
if (!this.zap)
|
|
2200
|
+
return [2 /*return*/, true];
|
|
2201
|
+
return [4 /*yield*/, hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.zap)];
|
|
2202
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2205
|
+
});
|
|
2206
|
+
};
|
|
2207
|
+
PoolTemplate.prototype.withdrawApproveEstimateGas = function (lpTokenAmount) {
|
|
2208
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2209
|
+
return __generator(this, function (_c) {
|
|
2210
|
+
switch (_c.label) {
|
|
2211
|
+
case 0:
|
|
2212
|
+
if (!this.zap)
|
|
2213
|
+
return [2 /*return*/, 0];
|
|
2214
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2215
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2218
|
+
});
|
|
2219
|
+
};
|
|
2220
|
+
PoolTemplate.prototype.withdrawApprove = function (lpTokenAmount) {
|
|
2221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2222
|
+
return __generator(this, function (_c) {
|
|
2223
|
+
switch (_c.label) {
|
|
2224
|
+
case 0:
|
|
2225
|
+
if (!this.zap)
|
|
2226
|
+
return [2 /*return*/, []];
|
|
2227
|
+
return [4 /*yield*/, ensureAllowance([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2228
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2229
|
+
}
|
|
2230
|
+
});
|
|
2231
|
+
});
|
|
2232
|
+
};
|
|
1332
2233
|
// OVERRIDE
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
2234
|
+
PoolTemplate.prototype.withdrawEstimateGas = function (lpTokenAmount) {
|
|
2235
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2236
|
+
return __generator(this, function (_c) {
|
|
2237
|
+
throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2238
|
+
});
|
|
2239
|
+
});
|
|
2240
|
+
};
|
|
1336
2241
|
// OVERRIDE
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
2242
|
+
PoolTemplate.prototype.withdraw = function (lpTokenAmount, slippage) {
|
|
2243
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2245
|
+
return __generator(this, function (_c) {
|
|
2246
|
+
throw Error("withdraw method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2247
|
+
});
|
|
2248
|
+
});
|
|
2249
|
+
};
|
|
1340
2250
|
// ---------------- WITHDRAW WRAPPED ----------------
|
|
1341
2251
|
// OVERRIDE
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
2252
|
+
PoolTemplate.prototype.withdrawWrappedExpected = function (lpTokenAmount) {
|
|
2253
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2254
|
+
return __generator(this, function (_c) {
|
|
2255
|
+
throw Error("withdrawWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2256
|
+
});
|
|
2257
|
+
});
|
|
2258
|
+
};
|
|
1345
2259
|
// OVERRIDE
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
2260
|
+
PoolTemplate.prototype.withdrawWrappedEstimateGas = function (lpTokenAmount) {
|
|
2261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2262
|
+
return __generator(this, function (_c) {
|
|
2263
|
+
throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2264
|
+
});
|
|
2265
|
+
});
|
|
2266
|
+
};
|
|
1349
2267
|
// OVERRIDE
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
2268
|
+
PoolTemplate.prototype.withdrawWrapped = function (lpTokenAmount, slippage) {
|
|
2269
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2270
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2271
|
+
return __generator(this, function (_c) {
|
|
2272
|
+
throw Error("withdrawWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2273
|
+
});
|
|
2274
|
+
});
|
|
2275
|
+
};
|
|
1353
2276
|
// ---------------- WITHDRAW IMBALANCE ----------------
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
|
|
2277
|
+
PoolTemplate.prototype.withdrawImbalanceExpected = function (amounts) {
|
|
2278
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2279
|
+
return __generator(this, function (_c) {
|
|
2280
|
+
switch (_c.label) {
|
|
2281
|
+
case 0:
|
|
2282
|
+
if (this.isCrypto)
|
|
2283
|
+
throw Error("withdrawImbalanceExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2284
|
+
return [4 /*yield*/, this.calcLpTokenAmount(amounts, false)];
|
|
2285
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
});
|
|
2289
|
+
};
|
|
2290
|
+
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
2291
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2292
|
+
var prices, _c, value, lpTokenAmount, balancedAmounts, balancedValue;
|
|
2293
|
+
return __generator(this, function (_d) {
|
|
2294
|
+
switch (_d.label) {
|
|
2295
|
+
case 0:
|
|
2296
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
2297
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2298
|
+
case 1:
|
|
2299
|
+
_c = _d.sent();
|
|
2300
|
+
return [3 /*break*/, 3];
|
|
2301
|
+
case 2:
|
|
2302
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
2303
|
+
_d.label = 3;
|
|
2304
|
+
case 3:
|
|
2305
|
+
prices = _c;
|
|
2306
|
+
value = amounts.map(checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2307
|
+
return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
|
|
2308
|
+
case 4:
|
|
2309
|
+
lpTokenAmount = _d.sent();
|
|
2310
|
+
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2311
|
+
case 5:
|
|
2312
|
+
balancedAmounts = _d.sent();
|
|
2313
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2314
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
});
|
|
2318
|
+
};
|
|
2319
|
+
PoolTemplate.prototype.withdrawImbalanceIsApproved = function (amounts) {
|
|
2320
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2321
|
+
var _amounts, _maxBurnAmount;
|
|
2322
|
+
var _this = this;
|
|
2323
|
+
return __generator(this, function (_c) {
|
|
2324
|
+
switch (_c.label) {
|
|
2325
|
+
case 0:
|
|
2326
|
+
if (this.isCrypto)
|
|
2327
|
+
throw Error("withdrawImbalanceIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2328
|
+
if (!this.zap) return [3 /*break*/, 3];
|
|
2329
|
+
_amounts = amounts.map(function (amount, i) { return parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
2330
|
+
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2331
|
+
case 1:
|
|
2332
|
+
_maxBurnAmount = (_c.sent()) * curve.parseUnits("101", 0) / curve.parseUnits("100", 0);
|
|
2333
|
+
return [4 /*yield*/, hasAllowance([this.lpToken], [curve.formatUnits(_maxBurnAmount, 18)], curve.signerAddress, this.zap)];
|
|
2334
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2335
|
+
case 3: return [2 /*return*/, true];
|
|
2336
|
+
}
|
|
2337
|
+
});
|
|
2338
|
+
});
|
|
2339
|
+
};
|
|
2340
|
+
PoolTemplate.prototype.withdrawImbalanceApproveEstimateGas = function (amounts) {
|
|
2341
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2342
|
+
var _amounts, _maxBurnAmount;
|
|
2343
|
+
var _this = this;
|
|
2344
|
+
return __generator(this, function (_c) {
|
|
2345
|
+
switch (_c.label) {
|
|
2346
|
+
case 0:
|
|
2347
|
+
if (this.isCrypto)
|
|
2348
|
+
throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2349
|
+
if (!this.zap) return [3 /*break*/, 3];
|
|
2350
|
+
_amounts = amounts.map(function (amount, i) { return parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
2351
|
+
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2352
|
+
case 1:
|
|
2353
|
+
_maxBurnAmount = (_c.sent()) * curve.parseUnits("101", 0) / curve.parseUnits("100", 0);
|
|
2354
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas([this.lpToken], [curve.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
2355
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2356
|
+
case 3: return [2 /*return*/, 0];
|
|
2357
|
+
}
|
|
2358
|
+
});
|
|
2359
|
+
});
|
|
2360
|
+
};
|
|
2361
|
+
PoolTemplate.prototype.withdrawImbalanceApprove = function (amounts) {
|
|
2362
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2363
|
+
var _amounts, _maxBurnAmount;
|
|
2364
|
+
var _this = this;
|
|
2365
|
+
return __generator(this, function (_c) {
|
|
2366
|
+
switch (_c.label) {
|
|
2367
|
+
case 0:
|
|
2368
|
+
if (this.isCrypto)
|
|
2369
|
+
throw Error("withdrawImbalanceApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2370
|
+
if (!this.zap) return [3 /*break*/, 3];
|
|
2371
|
+
_amounts = amounts.map(function (amount, i) { return parseUnits(amount, _this.underlyingDecimals[i]); });
|
|
2372
|
+
return [4 /*yield*/, this._calcLpTokenAmount(_amounts, false)];
|
|
2373
|
+
case 1:
|
|
2374
|
+
_maxBurnAmount = (_c.sent()) * curve.parseUnits("101", 0) / curve.parseUnits("100", 0);
|
|
2375
|
+
return [4 /*yield*/, ensureAllowance([this.lpToken], [curve.formatUnits(_maxBurnAmount, 18)], this.zap)];
|
|
2376
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2377
|
+
case 3: return [2 /*return*/, []];
|
|
2378
|
+
}
|
|
2379
|
+
});
|
|
2380
|
+
});
|
|
2381
|
+
};
|
|
1397
2382
|
// OVERRIDE
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
2383
|
+
PoolTemplate.prototype.withdrawImbalanceEstimateGas = function (amounts) {
|
|
2384
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2385
|
+
return __generator(this, function (_c) {
|
|
2386
|
+
throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2387
|
+
});
|
|
2388
|
+
});
|
|
2389
|
+
};
|
|
1401
2390
|
// OVERRIDE
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
2391
|
+
PoolTemplate.prototype.withdrawImbalance = function (amounts, slippage) {
|
|
2392
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2393
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2394
|
+
return __generator(this, function (_c) {
|
|
2395
|
+
throw Error("withdrawImbalance method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2396
|
+
});
|
|
2397
|
+
});
|
|
2398
|
+
};
|
|
1405
2399
|
// ---------------- WITHDRAW IMBALANCE WRAPPED ----------------
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
}
|
|
2400
|
+
PoolTemplate.prototype.withdrawImbalanceWrappedExpected = function (amounts) {
|
|
2401
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2402
|
+
return __generator(this, function (_c) {
|
|
2403
|
+
switch (_c.label) {
|
|
2404
|
+
case 0:
|
|
2405
|
+
if (this.isCrypto || this.isPlain || this.isFake)
|
|
2406
|
+
throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2407
|
+
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
|
|
2408
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2409
|
+
}
|
|
2410
|
+
});
|
|
2411
|
+
});
|
|
2412
|
+
};
|
|
2413
|
+
PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
|
|
2414
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2415
|
+
var prices, value, lpTokenAmount, _c, balancedAmounts, balancedValue;
|
|
2416
|
+
return __generator(this, function (_d) {
|
|
2417
|
+
switch (_d.label) {
|
|
2418
|
+
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
2419
|
+
case 1:
|
|
2420
|
+
prices = _d.sent();
|
|
2421
|
+
value = amounts.map(checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2422
|
+
_c = Number;
|
|
2423
|
+
return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
|
|
2424
|
+
case 2:
|
|
2425
|
+
lpTokenAmount = _c.apply(void 0, [_d.sent()]);
|
|
2426
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
2427
|
+
case 3:
|
|
2428
|
+
balancedAmounts = _d.sent();
|
|
2429
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2430
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
});
|
|
2434
|
+
};
|
|
1419
2435
|
// OVERRIDE
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
2436
|
+
PoolTemplate.prototype.withdrawImbalanceWrappedEstimateGas = function (amounts) {
|
|
2437
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2438
|
+
return __generator(this, function (_c) {
|
|
2439
|
+
throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2440
|
+
});
|
|
2441
|
+
});
|
|
2442
|
+
};
|
|
1423
2443
|
// OVERRIDE
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
2444
|
+
PoolTemplate.prototype.withdrawImbalanceWrapped = function (amounts, slippage) {
|
|
2445
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2446
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2447
|
+
return __generator(this, function (_c) {
|
|
2448
|
+
throw Error("withdrawImbalanceWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2449
|
+
});
|
|
2450
|
+
});
|
|
2451
|
+
};
|
|
1427
2452
|
// ---------------- WITHDRAW ONE COIN ----------------
|
|
1428
2453
|
// OVERRIDE
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
2454
|
+
PoolTemplate.prototype._withdrawOneCoinExpected = function (_lpTokenAmount, i) {
|
|
2455
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2456
|
+
return __generator(this, function (_c) {
|
|
2457
|
+
throw Error("withdrawOneCoinExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2458
|
+
});
|
|
2459
|
+
});
|
|
2460
|
+
};
|
|
2461
|
+
PoolTemplate.prototype.withdrawOneCoinExpected = function (lpTokenAmount, coin) {
|
|
2462
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2463
|
+
var i, _lpTokenAmount, _expected;
|
|
2464
|
+
return __generator(this, function (_c) {
|
|
2465
|
+
switch (_c.label) {
|
|
2466
|
+
case 0:
|
|
2467
|
+
i = this._getCoinIdx(coin);
|
|
2468
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
2469
|
+
return [4 /*yield*/, this._withdrawOneCoinExpected(_lpTokenAmount, i)];
|
|
2470
|
+
case 1:
|
|
2471
|
+
_expected = _c.sent();
|
|
2472
|
+
return [2 /*return*/, curve.formatUnits(_expected, this.underlyingDecimals[i])];
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2475
|
+
});
|
|
2476
|
+
};
|
|
2477
|
+
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2478
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2479
|
+
var prices, _c, coinPrice, amount, _d, value, balancedAmounts, balancedValue;
|
|
2480
|
+
return __generator(this, function (_e) {
|
|
2481
|
+
switch (_e.label) {
|
|
2482
|
+
case 0:
|
|
2483
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
2484
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2485
|
+
case 1:
|
|
2486
|
+
_c = _e.sent();
|
|
2487
|
+
return [3 /*break*/, 3];
|
|
2488
|
+
case 2:
|
|
2489
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
2490
|
+
_e.label = 3;
|
|
2491
|
+
case 3:
|
|
2492
|
+
prices = _c;
|
|
2493
|
+
coinPrice = prices[this._getCoinIdx(coin)];
|
|
2494
|
+
_d = Number;
|
|
2495
|
+
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
2496
|
+
case 4:
|
|
2497
|
+
amount = _d.apply(void 0, [_e.sent()]);
|
|
2498
|
+
value = amount * coinPrice;
|
|
2499
|
+
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2500
|
+
case 5:
|
|
2501
|
+
balancedAmounts = _e.sent();
|
|
2502
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2503
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
});
|
|
2507
|
+
};
|
|
2508
|
+
PoolTemplate.prototype.withdrawOneCoinIsApproved = function (lpTokenAmount) {
|
|
2509
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2510
|
+
return __generator(this, function (_c) {
|
|
2511
|
+
switch (_c.label) {
|
|
2512
|
+
case 0:
|
|
2513
|
+
if (!this.zap)
|
|
2514
|
+
return [2 /*return*/, true];
|
|
2515
|
+
return [4 /*yield*/, hasAllowance([this.lpToken], [lpTokenAmount], curve.signerAddress, this.zap)];
|
|
2516
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2517
|
+
}
|
|
2518
|
+
});
|
|
2519
|
+
});
|
|
2520
|
+
};
|
|
2521
|
+
PoolTemplate.prototype.withdrawOneCoinApproveEstimateGas = function (lpTokenAmount) {
|
|
2522
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2523
|
+
return __generator(this, function (_c) {
|
|
2524
|
+
switch (_c.label) {
|
|
2525
|
+
case 0:
|
|
2526
|
+
if (!this.zap)
|
|
2527
|
+
return [2 /*return*/, 0];
|
|
2528
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2529
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2530
|
+
}
|
|
2531
|
+
});
|
|
2532
|
+
});
|
|
2533
|
+
};
|
|
2534
|
+
PoolTemplate.prototype.withdrawOneCoinApprove = function (lpTokenAmount) {
|
|
2535
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2536
|
+
return __generator(this, function (_c) {
|
|
2537
|
+
switch (_c.label) {
|
|
2538
|
+
case 0:
|
|
2539
|
+
if (!this.zap)
|
|
2540
|
+
return [2 /*return*/, []];
|
|
2541
|
+
return [4 /*yield*/, ensureAllowance([this.lpToken], [lpTokenAmount], this.zap)];
|
|
2542
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2543
|
+
}
|
|
2544
|
+
});
|
|
2545
|
+
});
|
|
2546
|
+
};
|
|
1462
2547
|
// OVERRIDE
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
2548
|
+
PoolTemplate.prototype.withdrawOneCoinEstimateGas = function (lpTokenAmount, coin) {
|
|
2549
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2550
|
+
return __generator(this, function (_c) {
|
|
2551
|
+
throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2552
|
+
});
|
|
2553
|
+
});
|
|
2554
|
+
};
|
|
1466
2555
|
// OVERRIDE
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
2556
|
+
PoolTemplate.prototype.withdrawOneCoin = function (lpTokenAmount, coin, slippage) {
|
|
2557
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2558
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2559
|
+
return __generator(this, function (_c) {
|
|
2560
|
+
throw Error("withdrawOneCoin method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2561
|
+
});
|
|
2562
|
+
});
|
|
2563
|
+
};
|
|
1470
2564
|
// ---------------- WITHDRAW ONE COIN WRAPPED ----------------
|
|
1471
2565
|
// OVERRIDE
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
2566
|
+
PoolTemplate.prototype._withdrawOneCoinWrappedExpected = function (_lpTokenAmount, i) {
|
|
2567
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2568
|
+
return __generator(this, function (_c) {
|
|
2569
|
+
throw Error("withdrawOneCoinWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2570
|
+
});
|
|
2571
|
+
});
|
|
2572
|
+
};
|
|
2573
|
+
PoolTemplate.prototype.withdrawOneCoinWrappedExpected = function (lpTokenAmount, coin) {
|
|
2574
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2575
|
+
var i, _lpTokenAmount, _expected;
|
|
2576
|
+
return __generator(this, function (_c) {
|
|
2577
|
+
switch (_c.label) {
|
|
2578
|
+
case 0:
|
|
2579
|
+
i = this._getCoinIdx(coin, false);
|
|
2580
|
+
_lpTokenAmount = parseUnits(lpTokenAmount);
|
|
2581
|
+
return [4 /*yield*/, this._withdrawOneCoinWrappedExpected(_lpTokenAmount, i)];
|
|
2582
|
+
case 1:
|
|
2583
|
+
_expected = _c.sent();
|
|
2584
|
+
return [2 /*return*/, curve.formatUnits(_expected, this.wrappedDecimals[i])];
|
|
2585
|
+
}
|
|
2586
|
+
});
|
|
2587
|
+
});
|
|
2588
|
+
};
|
|
2589
|
+
PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
|
|
2590
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2591
|
+
var prices, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
|
|
2592
|
+
return __generator(this, function (_d) {
|
|
2593
|
+
switch (_d.label) {
|
|
2594
|
+
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
2595
|
+
case 1:
|
|
2596
|
+
prices = _d.sent();
|
|
2597
|
+
coinPrice = prices[this._getCoinIdx(coin, false)];
|
|
2598
|
+
_c = Number;
|
|
2599
|
+
return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
2600
|
+
case 2:
|
|
2601
|
+
amount = _c.apply(void 0, [_d.sent()]);
|
|
2602
|
+
value = amount * coinPrice;
|
|
2603
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
2604
|
+
case 3:
|
|
2605
|
+
balancedAmounts = _d.sent();
|
|
2606
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2607
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
});
|
|
2611
|
+
};
|
|
1490
2612
|
// OVERRIDE
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
2613
|
+
PoolTemplate.prototype.withdrawOneCoinWrappedEstimateGas = function (lpTokenAmount, coin) {
|
|
2614
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2615
|
+
return __generator(this, function (_c) {
|
|
2616
|
+
throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2617
|
+
});
|
|
2618
|
+
});
|
|
2619
|
+
};
|
|
1494
2620
|
// OVERRIDE
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
2621
|
+
PoolTemplate.prototype.withdrawOneCoinWrapped = function (lpTokenAmount, coin, slippage) {
|
|
2622
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2623
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2624
|
+
return __generator(this, function (_c) {
|
|
2625
|
+
throw Error("withdrawOneCoinWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2626
|
+
});
|
|
2627
|
+
});
|
|
2628
|
+
};
|
|
1498
2629
|
// ---------------- WALLET BALANCES ----------------
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
2630
|
+
PoolTemplate.prototype.walletBalances = function () {
|
|
2631
|
+
var addresses = [];
|
|
2632
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2633
|
+
addresses[_i] = arguments[_i];
|
|
1502
2634
|
}
|
|
1503
|
-
|
|
1504
|
-
return
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
2635
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2636
|
+
return __generator(this, function (_c) {
|
|
2637
|
+
switch (_c.label) {
|
|
2638
|
+
case 0:
|
|
2639
|
+
if (!(this.gauge === curve.constants.ZERO_ADDRESS)) return [3 /*break*/, 2];
|
|
2640
|
+
return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken'], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([this.lpToken], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
|
|
2641
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2642
|
+
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray(['lpToken', 'gauge'], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([this.lpToken, this.gauge], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
|
|
2643
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
});
|
|
2647
|
+
};
|
|
2648
|
+
PoolTemplate.prototype.walletLpTokenBalances = function () {
|
|
2649
|
+
var addresses = [];
|
|
2650
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2651
|
+
addresses[_i] = arguments[_i];
|
|
1510
2652
|
}
|
|
1511
|
-
|
|
1512
|
-
return
|
|
2653
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2654
|
+
return __generator(this, function (_c) {
|
|
2655
|
+
switch (_c.label) {
|
|
2656
|
+
case 0:
|
|
2657
|
+
if (!(this.gauge === curve.constants.ZERO_ADDRESS)) return [3 /*break*/, 2];
|
|
2658
|
+
return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken'], [this.lpToken]], addresses, false))];
|
|
2659
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2660
|
+
case 2: return [4 /*yield*/, this._balances.apply(this, __spreadArray([['lpToken', 'gauge'], [this.lpToken, this.gauge]], addresses, false))];
|
|
2661
|
+
case 3: return [2 /*return*/, _c.sent()];
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
});
|
|
2665
|
+
};
|
|
2666
|
+
PoolTemplate.prototype.walletUnderlyingCoinBalances = function () {
|
|
2667
|
+
var addresses = [];
|
|
2668
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2669
|
+
addresses[_i] = arguments[_i];
|
|
1513
2670
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
let lpTotalBalanceBN = BN(lpBalances.lpToken);
|
|
1528
|
-
if ('gauge' in lpBalances)
|
|
1529
|
-
lpTotalBalanceBN = lpTotalBalanceBN.plus(BN(lpBalances.gauge));
|
|
1530
|
-
return lpTotalBalanceBN;
|
|
1531
|
-
}
|
|
1532
|
-
async userBalances(address = "") {
|
|
1533
|
-
address = address || curve.signerAddress;
|
|
1534
|
-
if (!address)
|
|
1535
|
-
throw Error("Need to connect wallet or pass address into args");
|
|
1536
|
-
const lpTotalBalanceBN = await this._userLpTotalBalance(address);
|
|
1537
|
-
if (lpTotalBalanceBN.eq(0))
|
|
1538
|
-
return this.underlyingCoins.map(() => "0");
|
|
1539
|
-
return await this.withdrawExpected(lpTotalBalanceBN.toFixed(18));
|
|
1540
|
-
}
|
|
1541
|
-
async userWrappedBalances(address = "") {
|
|
1542
|
-
address = address || curve.signerAddress;
|
|
1543
|
-
if (!address)
|
|
1544
|
-
throw Error("Need to connect wallet or pass address into args");
|
|
1545
|
-
const lpTotalBalanceBN = await this._userLpTotalBalance(address);
|
|
1546
|
-
if (lpTotalBalanceBN.eq(0))
|
|
1547
|
-
return this.wrappedCoins.map(() => "0");
|
|
1548
|
-
return await this.withdrawWrappedExpected(lpTotalBalanceBN.toFixed(18));
|
|
1549
|
-
}
|
|
1550
|
-
async userLiquidityUSD(address = "") {
|
|
1551
|
-
const lpBalanceBN = await this._userLpTotalBalance(address);
|
|
1552
|
-
const lpPrice = await _getUsdRate(this.lpToken);
|
|
1553
|
-
return lpBalanceBN.times(lpPrice).toFixed(8);
|
|
1554
|
-
}
|
|
1555
|
-
async baseProfit(address = "") {
|
|
1556
|
-
const apyData = await this.statsBaseApy();
|
|
1557
|
-
if (!('week' in apyData))
|
|
1558
|
-
return { day: "0", week: "0", month: "0", year: "0" };
|
|
1559
|
-
const apyBN = BN(apyData.week).div(100);
|
|
1560
|
-
const totalLiquidityBN = BN(await this.userLiquidityUSD(address));
|
|
1561
|
-
const annualProfitBN = apyBN.times(totalLiquidityBN);
|
|
1562
|
-
const monthlyProfitBN = annualProfitBN.div(12);
|
|
1563
|
-
const weeklyProfitBN = annualProfitBN.div(52);
|
|
1564
|
-
const dailyProfitBN = annualProfitBN.div(365);
|
|
1565
|
-
return {
|
|
1566
|
-
day: dailyProfitBN.toString(),
|
|
1567
|
-
week: weeklyProfitBN.toString(),
|
|
1568
|
-
month: monthlyProfitBN.toString(),
|
|
1569
|
-
year: annualProfitBN.toString(),
|
|
1570
|
-
};
|
|
1571
|
-
}
|
|
1572
|
-
async userShare(address = "") {
|
|
1573
|
-
const withGauge = this.gauge !== curve.constants.ZERO_ADDRESS;
|
|
1574
|
-
address = address || curve.signerAddress;
|
|
1575
|
-
if (!address)
|
|
1576
|
-
throw Error("Need to connect wallet or pass address into args");
|
|
1577
|
-
const userLpBalance = await this.walletLpTokenBalances(address);
|
|
1578
|
-
let userLpTotalBalanceBN = BN(userLpBalance.lpToken);
|
|
1579
|
-
if (withGauge)
|
|
1580
|
-
userLpTotalBalanceBN = userLpTotalBalanceBN.plus(BN(userLpBalance.gauge));
|
|
1581
|
-
let totalLp, gaugeLp;
|
|
1582
|
-
if (withGauge) {
|
|
1583
|
-
[totalLp, gaugeLp] = (await curve.multicallProvider.all([
|
|
1584
|
-
curve.contracts[this.lpToken].multicallContract.totalSupply(),
|
|
1585
|
-
curve.contracts[this.gauge].multicallContract.totalSupply(),
|
|
1586
|
-
])).map((_supply) => curve.formatUnits(_supply));
|
|
2671
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2672
|
+
return __generator(this, function (_c) {
|
|
2673
|
+
switch (_c.label) {
|
|
2674
|
+
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.underlyingCoinAddresses, this.underlyingCoinAddresses], addresses, false))];
|
|
2675
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
});
|
|
2679
|
+
};
|
|
2680
|
+
PoolTemplate.prototype.walletWrappedCoinBalances = function () {
|
|
2681
|
+
var addresses = [];
|
|
2682
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2683
|
+
addresses[_i] = arguments[_i];
|
|
1587
2684
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
2685
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2686
|
+
return __generator(this, function (_c) {
|
|
2687
|
+
switch (_c.label) {
|
|
2688
|
+
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([this.wrappedCoinAddresses, this.wrappedCoinAddresses], addresses, false))];
|
|
2689
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2690
|
+
}
|
|
2691
|
+
});
|
|
2692
|
+
});
|
|
2693
|
+
};
|
|
2694
|
+
PoolTemplate.prototype.walletAllCoinBalances = function () {
|
|
2695
|
+
var addresses = [];
|
|
2696
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2697
|
+
addresses[_i] = arguments[_i];
|
|
1590
2698
|
}
|
|
1591
|
-
return {
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
2699
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2700
|
+
return __generator(this, function (_c) {
|
|
2701
|
+
switch (_c.label) {
|
|
2702
|
+
case 0: return [4 /*yield*/, this._balances.apply(this, __spreadArray([__spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true), __spreadArray(__spreadArray([], this.underlyingCoinAddresses, true), this.wrappedCoinAddresses, true)], addresses, false))];
|
|
2703
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2704
|
+
}
|
|
2705
|
+
});
|
|
2706
|
+
});
|
|
2707
|
+
};
|
|
2708
|
+
// ---------------- USER BALANCES, BASE PROFIT AND SHARE ----------------
|
|
2709
|
+
PoolTemplate.prototype._userLpTotalBalance = function (address) {
|
|
2710
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2711
|
+
var lpBalances, lpTotalBalanceBN;
|
|
2712
|
+
return __generator(this, function (_c) {
|
|
2713
|
+
switch (_c.label) {
|
|
2714
|
+
case 0: return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2715
|
+
case 1:
|
|
2716
|
+
lpBalances = _c.sent();
|
|
2717
|
+
lpTotalBalanceBN = BN(lpBalances.lpToken);
|
|
2718
|
+
if ('gauge' in lpBalances)
|
|
2719
|
+
lpTotalBalanceBN = lpTotalBalanceBN.plus(BN(lpBalances.gauge));
|
|
2720
|
+
return [2 /*return*/, lpTotalBalanceBN];
|
|
2721
|
+
}
|
|
2722
|
+
});
|
|
2723
|
+
});
|
|
2724
|
+
};
|
|
2725
|
+
PoolTemplate.prototype.userBalances = function (address) {
|
|
2726
|
+
if (address === void 0) { address = ""; }
|
|
2727
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2728
|
+
var lpTotalBalanceBN;
|
|
2729
|
+
return __generator(this, function (_c) {
|
|
2730
|
+
switch (_c.label) {
|
|
2731
|
+
case 0:
|
|
2732
|
+
address = address || curve.signerAddress;
|
|
2733
|
+
if (!address)
|
|
2734
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2735
|
+
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2736
|
+
case 1:
|
|
2737
|
+
lpTotalBalanceBN = _c.sent();
|
|
2738
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2739
|
+
return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
|
|
2740
|
+
return [4 /*yield*/, this.withdrawExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2741
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
});
|
|
2745
|
+
};
|
|
2746
|
+
PoolTemplate.prototype.userWrappedBalances = function (address) {
|
|
2747
|
+
if (address === void 0) { address = ""; }
|
|
2748
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2749
|
+
var lpTotalBalanceBN;
|
|
2750
|
+
return __generator(this, function (_c) {
|
|
2751
|
+
switch (_c.label) {
|
|
2752
|
+
case 0:
|
|
2753
|
+
address = address || curve.signerAddress;
|
|
2754
|
+
if (!address)
|
|
2755
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2756
|
+
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2757
|
+
case 1:
|
|
2758
|
+
lpTotalBalanceBN = _c.sent();
|
|
2759
|
+
if (lpTotalBalanceBN.eq(0))
|
|
2760
|
+
return [2 /*return*/, this.wrappedCoins.map(function () { return "0"; })];
|
|
2761
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toFixed(18))];
|
|
2762
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
2763
|
+
}
|
|
2764
|
+
});
|
|
2765
|
+
});
|
|
2766
|
+
};
|
|
2767
|
+
PoolTemplate.prototype.userLiquidityUSD = function (address) {
|
|
2768
|
+
if (address === void 0) { address = ""; }
|
|
2769
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2770
|
+
var lpBalanceBN, lpPrice;
|
|
2771
|
+
return __generator(this, function (_c) {
|
|
2772
|
+
switch (_c.label) {
|
|
2773
|
+
case 0: return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2774
|
+
case 1:
|
|
2775
|
+
lpBalanceBN = _c.sent();
|
|
2776
|
+
return [4 /*yield*/, _getUsdRate(this.lpToken)];
|
|
2777
|
+
case 2:
|
|
2778
|
+
lpPrice = _c.sent();
|
|
2779
|
+
return [2 /*return*/, lpBalanceBN.times(lpPrice).toFixed(8)];
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
});
|
|
2783
|
+
};
|
|
2784
|
+
PoolTemplate.prototype.baseProfit = function (address) {
|
|
2785
|
+
if (address === void 0) { address = ""; }
|
|
2786
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2787
|
+
var apyData, apyBN, totalLiquidityBN, _c, annualProfitBN, monthlyProfitBN, weeklyProfitBN, dailyProfitBN;
|
|
2788
|
+
return __generator(this, function (_d) {
|
|
2789
|
+
switch (_d.label) {
|
|
2790
|
+
case 0: return [4 /*yield*/, this.statsBaseApy()];
|
|
2791
|
+
case 1:
|
|
2792
|
+
apyData = _d.sent();
|
|
2793
|
+
if (!('week' in apyData))
|
|
2794
|
+
return [2 /*return*/, { day: "0", week: "0", month: "0", year: "0" }];
|
|
2795
|
+
apyBN = BN(apyData.week).div(100);
|
|
2796
|
+
_c = BN;
|
|
2797
|
+
return [4 /*yield*/, this.userLiquidityUSD(address)];
|
|
2798
|
+
case 2:
|
|
2799
|
+
totalLiquidityBN = _c.apply(void 0, [_d.sent()]);
|
|
2800
|
+
annualProfitBN = apyBN.times(totalLiquidityBN);
|
|
2801
|
+
monthlyProfitBN = annualProfitBN.div(12);
|
|
2802
|
+
weeklyProfitBN = annualProfitBN.div(52);
|
|
2803
|
+
dailyProfitBN = annualProfitBN.div(365);
|
|
2804
|
+
return [2 /*return*/, {
|
|
2805
|
+
day: dailyProfitBN.toString(),
|
|
2806
|
+
week: weeklyProfitBN.toString(),
|
|
2807
|
+
month: monthlyProfitBN.toString(),
|
|
2808
|
+
year: annualProfitBN.toString(),
|
|
2809
|
+
}];
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
});
|
|
2813
|
+
};
|
|
2814
|
+
PoolTemplate.prototype.userShare = function (address) {
|
|
2815
|
+
if (address === void 0) { address = ""; }
|
|
2816
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2817
|
+
var withGauge, userLpBalance, userLpTotalBalanceBN, totalLp, gaugeLp, _c, _d;
|
|
2818
|
+
var _e;
|
|
2819
|
+
return __generator(this, function (_f) {
|
|
2820
|
+
switch (_f.label) {
|
|
2821
|
+
case 0:
|
|
2822
|
+
withGauge = this.gauge !== curve.constants.ZERO_ADDRESS;
|
|
2823
|
+
address = address || curve.signerAddress;
|
|
2824
|
+
if (!address)
|
|
2825
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2826
|
+
return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2827
|
+
case 1:
|
|
2828
|
+
userLpBalance = _f.sent();
|
|
2829
|
+
userLpTotalBalanceBN = BN(userLpBalance.lpToken);
|
|
2830
|
+
if (withGauge)
|
|
2831
|
+
userLpTotalBalanceBN = userLpTotalBalanceBN.plus(BN(userLpBalance.gauge));
|
|
2832
|
+
if (!withGauge) return [3 /*break*/, 3];
|
|
2833
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
2834
|
+
curve.contracts[this.lpToken].multicallContract.totalSupply(),
|
|
2835
|
+
curve.contracts[this.gauge].multicallContract.totalSupply(),
|
|
2836
|
+
])];
|
|
2837
|
+
case 2:
|
|
2838
|
+
_e = (_f.sent()).map(function (_supply) { return curve.formatUnits(_supply); }), totalLp = _e[0], gaugeLp = _e[1];
|
|
2839
|
+
return [3 /*break*/, 5];
|
|
2840
|
+
case 3:
|
|
2841
|
+
_d = (_c = curve).formatUnits;
|
|
2842
|
+
return [4 /*yield*/, curve.contracts[this.lpToken].contract.totalSupply(curve.constantOptions)];
|
|
2843
|
+
case 4:
|
|
2844
|
+
totalLp = _d.apply(_c, [_f.sent()]);
|
|
2845
|
+
_f.label = 5;
|
|
2846
|
+
case 5: return [2 /*return*/, {
|
|
2847
|
+
lpUser: userLpTotalBalanceBN.toString(),
|
|
2848
|
+
lpTotal: totalLp,
|
|
2849
|
+
lpShare: BN(totalLp).gt(0) ? userLpTotalBalanceBN.div(totalLp).times(100).toString() : '0',
|
|
2850
|
+
gaugeUser: userLpBalance.gauge,
|
|
2851
|
+
gaugeTotal: gaugeLp,
|
|
2852
|
+
gaugeShare: !withGauge ? undefined : BN(gaugeLp).gt(0) ? BN(userLpBalance.gauge).div(gaugeLp).times(100).toString() : '0',
|
|
2853
|
+
}];
|
|
2854
|
+
}
|
|
2855
|
+
});
|
|
2856
|
+
});
|
|
2857
|
+
};
|
|
1600
2858
|
// ---------------- SWAP ----------------
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
2859
|
+
PoolTemplate.prototype._swapExpected = function (i, j, _amount) {
|
|
2860
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2861
|
+
var contractAddress, contract;
|
|
2862
|
+
return __generator(this, function (_c) {
|
|
2863
|
+
switch (_c.label) {
|
|
2864
|
+
case 0:
|
|
2865
|
+
contractAddress = this.isCrypto && this.isMeta ? this.zap : this.address;
|
|
2866
|
+
contract = curve.contracts[contractAddress].contract;
|
|
2867
|
+
if (!('get_dy_underlying' in contract)) return [3 /*break*/, 2];
|
|
2868
|
+
return [4 /*yield*/, contract.get_dy_underlying(i, j, _amount, curve.constantOptions)];
|
|
2869
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2870
|
+
case 2:
|
|
2871
|
+
if (!('get_dy(address,uint256,uint256,uint256)' in contract)) return [3 /*break*/, 4];
|
|
2872
|
+
return [4 /*yield*/, contract.get_dy(this.address, i, j, _amount, curve.constantOptions)];
|
|
2873
|
+
case 3: // atricrypto3 based metapools
|
|
2874
|
+
return [2 /*return*/, _c.sent()];
|
|
2875
|
+
case 4: return [4 /*yield*/, contract.get_dy(i, j, _amount, curve.constantOptions)];
|
|
2876
|
+
case 5: return [2 /*return*/, _c.sent()];
|
|
2877
|
+
}
|
|
2878
|
+
});
|
|
2879
|
+
});
|
|
2880
|
+
};
|
|
2881
|
+
PoolTemplate.prototype.swapExpected = function (inputCoin, outputCoin, amount) {
|
|
2882
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2883
|
+
var i, j, _amount, _expected;
|
|
2884
|
+
return __generator(this, function (_c) {
|
|
2885
|
+
switch (_c.label) {
|
|
2886
|
+
case 0:
|
|
2887
|
+
i = this._getCoinIdx(inputCoin);
|
|
2888
|
+
j = this._getCoinIdx(outputCoin);
|
|
2889
|
+
_amount = parseUnits(amount, this.underlyingDecimals[i]);
|
|
2890
|
+
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2891
|
+
case 1:
|
|
2892
|
+
_expected = _c.sent();
|
|
2893
|
+
return [2 /*return*/, curve.formatUnits(_expected, this.underlyingDecimals[j])];
|
|
2894
|
+
}
|
|
2895
|
+
});
|
|
2896
|
+
});
|
|
2897
|
+
};
|
|
2898
|
+
PoolTemplate.prototype.swapPriceImpact = function (inputCoin, outputCoin, amount) {
|
|
2899
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2900
|
+
var i, j, _c, inputCoinDecimals, outputCoinDecimals, _amount, _output, smallAmountIntBN, amountIntBN, _smallAmount, _smallOutput, priceImpactBN;
|
|
2901
|
+
return __generator(this, function (_d) {
|
|
2902
|
+
switch (_d.label) {
|
|
2903
|
+
case 0:
|
|
2904
|
+
i = this._getCoinIdx(inputCoin);
|
|
2905
|
+
j = this._getCoinIdx(outputCoin);
|
|
2906
|
+
_c = [this.underlyingDecimals[i], this.underlyingDecimals[j]], inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
2907
|
+
_amount = parseUnits(amount, inputCoinDecimals);
|
|
2908
|
+
return [4 /*yield*/, this._swapExpected(i, j, _amount)];
|
|
2909
|
+
case 1:
|
|
2910
|
+
_output = _d.sent();
|
|
2911
|
+
smallAmountIntBN = _get_small_x(_amount, _output, inputCoinDecimals, outputCoinDecimals);
|
|
2912
|
+
amountIntBN = toBN(_amount, 0);
|
|
2913
|
+
if (smallAmountIntBN.gte(amountIntBN))
|
|
2914
|
+
return [2 /*return*/, 0];
|
|
2915
|
+
_smallAmount = fromBN(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
2916
|
+
return [4 /*yield*/, this._swapExpected(i, j, _smallAmount)];
|
|
2917
|
+
case 2:
|
|
2918
|
+
_smallOutput = _d.sent();
|
|
2919
|
+
priceImpactBN = _get_price_impact(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
2920
|
+
return [2 /*return*/, Number(_cutZeros(priceImpactBN.toFixed(4)))];
|
|
2921
|
+
}
|
|
2922
|
+
});
|
|
2923
|
+
});
|
|
2924
|
+
};
|
|
2925
|
+
PoolTemplate.prototype._swapContractAddress = function () {
|
|
1637
2926
|
return (this.isCrypto && this.isMeta) || (this.isMetaFactory && (new PoolTemplate(this.basePool).isLending)) ? this.zap : this.address;
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
2927
|
+
};
|
|
2928
|
+
PoolTemplate.prototype.swapIsApproved = function (inputCoin, amount) {
|
|
2929
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2930
|
+
var contractAddress, i;
|
|
2931
|
+
return __generator(this, function (_c) {
|
|
2932
|
+
switch (_c.label) {
|
|
2933
|
+
case 0:
|
|
2934
|
+
contractAddress = this._swapContractAddress();
|
|
2935
|
+
i = this._getCoinIdx(inputCoin);
|
|
2936
|
+
return [4 /*yield*/, hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress)];
|
|
2937
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
});
|
|
2941
|
+
};
|
|
2942
|
+
PoolTemplate.prototype.swapApproveEstimateGas = function (inputCoin, amount) {
|
|
2943
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2944
|
+
var contractAddress, i;
|
|
2945
|
+
return __generator(this, function (_c) {
|
|
2946
|
+
switch (_c.label) {
|
|
2947
|
+
case 0:
|
|
2948
|
+
contractAddress = this._swapContractAddress();
|
|
2949
|
+
i = this._getCoinIdx(inputCoin);
|
|
2950
|
+
return [4 /*yield*/, ensureAllowanceEstimateGas([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2951
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2952
|
+
}
|
|
2953
|
+
});
|
|
2954
|
+
});
|
|
2955
|
+
};
|
|
2956
|
+
PoolTemplate.prototype.swapApprove = function (inputCoin, amount) {
|
|
2957
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2958
|
+
var contractAddress, i;
|
|
2959
|
+
return __generator(this, function (_c) {
|
|
2960
|
+
switch (_c.label) {
|
|
2961
|
+
case 0:
|
|
2962
|
+
contractAddress = this._swapContractAddress();
|
|
2963
|
+
i = this._getCoinIdx(inputCoin);
|
|
2964
|
+
return [4 /*yield*/, ensureAllowance([this.underlyingCoinAddresses[i]], [amount], contractAddress)];
|
|
2965
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
});
|
|
2969
|
+
};
|
|
1654
2970
|
// OVERRIDE
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
2971
|
+
PoolTemplate.prototype.swapEstimateGas = function (inputCoin, outputCoin, amount) {
|
|
2972
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2973
|
+
return __generator(this, function (_c) {
|
|
2974
|
+
throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2975
|
+
});
|
|
2976
|
+
});
|
|
2977
|
+
};
|
|
1658
2978
|
// OVERRIDE
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
2979
|
+
PoolTemplate.prototype.swap = function (inputCoin, outputCoin, amount, slippage) {
|
|
2980
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
2981
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2982
|
+
return __generator(this, function (_c) {
|
|
2983
|
+
throw Error("swap method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2984
|
+
});
|
|
2985
|
+
});
|
|
2986
|
+
};
|
|
1662
2987
|
// ---------------- SWAP WRAPPED ----------------
|
|
1663
|
-
|
|
1664
|
-
return
|
|
1665
|
-
|
|
2988
|
+
PoolTemplate.prototype._swapWrappedExpected = function (i, j, _amount) {
|
|
2989
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2990
|
+
return __generator(this, function (_c) {
|
|
2991
|
+
switch (_c.label) {
|
|
2992
|
+
case 0: return [4 /*yield*/, curve.contracts[this.address].contract.get_dy(i, j, _amount, curve.constantOptions)];
|
|
2993
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
2994
|
+
}
|
|
2995
|
+
});
|
|
2996
|
+
});
|
|
2997
|
+
};
|
|
1666
2998
|
// OVERRIDE
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
2999
|
+
PoolTemplate.prototype.swapWrappedExpected = function (inputCoin, outputCoin, amount) {
|
|
3000
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3001
|
+
return __generator(this, function (_c) {
|
|
3002
|
+
throw Error("swapWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3003
|
+
});
|
|
3004
|
+
});
|
|
3005
|
+
};
|
|
3006
|
+
PoolTemplate.prototype.swapWrappedPriceImpact = function (inputCoin, outputCoin, amount) {
|
|
3007
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3008
|
+
var i, j, _c, inputCoinDecimals, outputCoinDecimals, _amount, _output, smallAmountIntBN, amountIntBN, _smallAmount, _smallOutput, priceImpactBN;
|
|
3009
|
+
return __generator(this, function (_d) {
|
|
3010
|
+
switch (_d.label) {
|
|
3011
|
+
case 0:
|
|
3012
|
+
if (this.isPlain || this.isFake) {
|
|
3013
|
+
throw Error("swapWrappedPriceImpact method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3014
|
+
}
|
|
3015
|
+
i = this._getCoinIdx(inputCoin, false);
|
|
3016
|
+
j = this._getCoinIdx(outputCoin, false);
|
|
3017
|
+
_c = [this.wrappedDecimals[i], this.wrappedDecimals[j]], inputCoinDecimals = _c[0], outputCoinDecimals = _c[1];
|
|
3018
|
+
_amount = parseUnits(amount, inputCoinDecimals);
|
|
3019
|
+
return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
|
|
3020
|
+
case 1:
|
|
3021
|
+
_output = _d.sent();
|
|
3022
|
+
smallAmountIntBN = _get_small_x(_amount, _output, inputCoinDecimals, outputCoinDecimals);
|
|
3023
|
+
amountIntBN = toBN(_amount, 0);
|
|
3024
|
+
if (smallAmountIntBN.gte(amountIntBN))
|
|
3025
|
+
return [2 /*return*/, 0];
|
|
3026
|
+
_smallAmount = fromBN(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
3027
|
+
return [4 /*yield*/, this._swapWrappedExpected(i, j, _smallAmount)];
|
|
3028
|
+
case 2:
|
|
3029
|
+
_smallOutput = _d.sent();
|
|
3030
|
+
priceImpactBN = _get_price_impact(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
3031
|
+
return [2 /*return*/, Number(_cutZeros(priceImpactBN.toFixed(4)))];
|
|
3032
|
+
}
|
|
3033
|
+
});
|
|
3034
|
+
});
|
|
3035
|
+
};
|
|
1688
3036
|
// OVERRIDE
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
3037
|
+
PoolTemplate.prototype.swapWrappedIsApproved = function (inputCoin, amount) {
|
|
3038
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3039
|
+
return __generator(this, function (_c) {
|
|
3040
|
+
throw Error("swapWrappedIsApproved method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3041
|
+
});
|
|
3042
|
+
});
|
|
3043
|
+
};
|
|
1692
3044
|
// OVERRIDE
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
3045
|
+
PoolTemplate.prototype.swapWrappedApproveEstimateGas = function (inputCoin, amount) {
|
|
3046
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3047
|
+
return __generator(this, function (_c) {
|
|
3048
|
+
throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3049
|
+
});
|
|
3050
|
+
});
|
|
3051
|
+
};
|
|
1696
3052
|
// OVERRIDE
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
3053
|
+
PoolTemplate.prototype.swapWrappedApprove = function (inputCoin, amount) {
|
|
3054
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3055
|
+
return __generator(this, function (_c) {
|
|
3056
|
+
throw Error("swapWrappedApprove method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3057
|
+
});
|
|
3058
|
+
});
|
|
3059
|
+
};
|
|
1700
3060
|
// OVERRIDE
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
3061
|
+
PoolTemplate.prototype.swapWrappedEstimateGas = function (inputCoin, outputCoin, amount) {
|
|
3062
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3063
|
+
return __generator(this, function (_c) {
|
|
3064
|
+
throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3065
|
+
});
|
|
3066
|
+
});
|
|
3067
|
+
};
|
|
1704
3068
|
// OVERRIDE
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
3069
|
+
PoolTemplate.prototype.swapWrapped = function (inputCoin, outputCoin, amount, slippage) {
|
|
3070
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
3071
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
3072
|
+
return __generator(this, function (_c) {
|
|
3073
|
+
throw Error("swapWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
3074
|
+
});
|
|
3075
|
+
});
|
|
3076
|
+
};
|
|
3077
|
+
return PoolTemplate;
|
|
3078
|
+
}());
|
|
3079
|
+
export { PoolTemplate };
|