@curvefi/api 2.21.2 → 2.21.4
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/constants/coins/fantom.js +1 -1
- package/lib/constants/pools/fantom.js +4 -4
- package/lib/pools/PoolTemplate.d.ts +4 -0
- package/lib/pools/PoolTemplate.js +207 -57
- package/lib/pools/poolConstructor.js +0 -31
- package/lib/utils.d.ts +4 -4
- package/lib/utils.js +19 -19
- package/package.json +1 -1
- package/lib/pools/mixins/depositBonusMixins.d.ts +0 -5
- package/lib/pools/mixins/depositBonusMixins.js +0 -190
- package/lib/pools/mixins/withdrawBonusMixins.d.ts +0 -7
- package/lib/pools/mixins/withdrawBonusMixins.js +0 -216
|
@@ -17,7 +17,7 @@ exports.COINS_FANTOM = (0, utils_1.lowerCaseValues)({
|
|
|
17
17
|
'dai+usdc': '0x27e611fd27b276acbd5ffd632e5eaebec9761e40',
|
|
18
18
|
'frax': '0xdc301622e621166bd8e82f2ca0a26c13ad0be355',
|
|
19
19
|
// --- BTC ---
|
|
20
|
-
'
|
|
20
|
+
'wbtc': '0x321162Cd933E2Be498Cd2267a90534A804051b11',
|
|
21
21
|
'renbtc': '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
|
|
22
22
|
// --- ETH ---
|
|
23
23
|
'eth': '0x74b23882a30290451A17c44f4F05243b6b58C76d',
|
|
@@ -85,8 +85,8 @@ exports.POOLS_DATA_FANTOM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
85
85
|
// old_gauge: '0x6600e98b71dabfD4A8Cac03b302B0189Adb86Afb',
|
|
86
86
|
// gauge_address: '0xBdFF0C27dd073C119ebcb1299a68A6A92aE607F0',
|
|
87
87
|
gauge_address: '0xbC38bD19227F91424eD4132F630f51C9A42Fa338',
|
|
88
|
-
underlying_coins: ['
|
|
89
|
-
wrapped_coins: ['
|
|
88
|
+
underlying_coins: ['WBTC', 'renBTC'],
|
|
89
|
+
wrapped_coins: ['WBTC', 'renBTC'],
|
|
90
90
|
underlying_coin_addresses: [
|
|
91
91
|
'0x321162Cd933E2Be498Cd2267a90534A804051b11',
|
|
92
92
|
'0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
|
|
@@ -111,8 +111,8 @@ exports.POOLS_DATA_FANTOM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
111
111
|
gauge_address: '0x319E268f0A4C85D404734ee7958857F5891506d7',
|
|
112
112
|
is_crypto: true,
|
|
113
113
|
is_plain: true,
|
|
114
|
-
underlying_coins: ['fUSDT', '
|
|
115
|
-
wrapped_coins: ['fUSDT', '
|
|
114
|
+
underlying_coins: ['fUSDT', 'WBTC', 'ETH'],
|
|
115
|
+
wrapped_coins: ['fUSDT', 'WBTC', 'ETH'],
|
|
116
116
|
underlying_coin_addresses: [
|
|
117
117
|
'0x049d68029688eAbF473097a2fC38ef61633A3C7A',
|
|
118
118
|
'0x321162Cd933E2Be498Cd2267a90534A804051b11',
|
|
@@ -57,6 +57,7 @@ export declare class PoolTemplate {
|
|
|
57
57
|
};
|
|
58
58
|
stats: {
|
|
59
59
|
parameters: () => Promise<{
|
|
60
|
+
lpTokenSupply: string;
|
|
60
61
|
virtualPrice: string;
|
|
61
62
|
fee: string;
|
|
62
63
|
adminFee: string;
|
|
@@ -66,6 +67,8 @@ export declare class PoolTemplate {
|
|
|
66
67
|
future_A_time?: number;
|
|
67
68
|
initial_A_time?: number;
|
|
68
69
|
gamma?: string;
|
|
70
|
+
price_oracle?: string[];
|
|
71
|
+
price_scale?: string[];
|
|
69
72
|
}>;
|
|
70
73
|
underlyingBalances: () => Promise<string[]>;
|
|
71
74
|
wrappedBalances: () => Promise<string[]>;
|
|
@@ -102,6 +105,7 @@ export declare class PoolTemplate {
|
|
|
102
105
|
cryptoSeedAmounts(amount1: number | string): Promise<string[]>;
|
|
103
106
|
depositBalancedAmounts(): Promise<string[]>;
|
|
104
107
|
depositExpected(amounts: (number | string)[]): Promise<string>;
|
|
108
|
+
private _balancedAmountsWithSameValue;
|
|
105
109
|
depositBonus(amounts: (number | string)[]): Promise<string>;
|
|
106
110
|
depositIsApproved(amounts: (number | string)[]): Promise<boolean>;
|
|
107
111
|
private depositApproveEstimateGas;
|
|
@@ -74,8 +74,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
74
74
|
function PoolTemplate(id) {
|
|
75
75
|
var _this = this;
|
|
76
76
|
this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
77
|
-
var multicallContract, lpMulticallContract, calls,
|
|
78
|
-
var _g, _h;
|
|
77
|
+
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;
|
|
78
|
+
var _f, _g, _h;
|
|
79
79
|
return __generator(this, function (_j) {
|
|
80
80
|
switch (_j.label) {
|
|
81
81
|
case 0:
|
|
@@ -83,52 +83,80 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
83
83
|
lpMulticallContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
84
84
|
calls = [
|
|
85
85
|
multicallContract.get_virtual_price(),
|
|
86
|
-
lpMulticallContract.totalSupply(),
|
|
87
86
|
multicallContract.fee(),
|
|
88
87
|
multicallContract.admin_fee(),
|
|
89
88
|
multicallContract.A(),
|
|
89
|
+
lpMulticallContract.totalSupply(),
|
|
90
90
|
];
|
|
91
|
-
if (this.isCrypto)
|
|
91
|
+
if (this.isCrypto) {
|
|
92
92
|
calls.push(multicallContract.gamma());
|
|
93
|
+
if (this.wrappedCoins.length === 2) {
|
|
94
|
+
calls.push(multicallContract.price_oracle());
|
|
95
|
+
calls.push(multicallContract.price_scale());
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
for (i = 0; i < this.wrappedCoins.length - 1; i++) {
|
|
99
|
+
calls.push(multicallContract.price_oracle(i));
|
|
100
|
+
calls.push(multicallContract.price_scale(i));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
93
104
|
additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
|
|
94
105
|
if ('initial_A' in multicallContract) {
|
|
95
106
|
additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
|
|
96
107
|
}
|
|
97
|
-
|
|
108
|
+
_virtualPrice = ethers_1.ethers.BigNumber.from(0);
|
|
109
|
+
_fee = ethers_1.ethers.BigNumber.from(0);
|
|
98
110
|
_j.label = 1;
|
|
99
111
|
case 1:
|
|
100
|
-
_j.trys.push([1, 3, ,
|
|
112
|
+
_j.trys.push([1, 3, , 8]);
|
|
101
113
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
102
114
|
case 2:
|
|
103
|
-
|
|
104
|
-
return [3 /*break*/,
|
|
115
|
+
_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);
|
|
116
|
+
return [3 /*break*/, 8];
|
|
105
117
|
case 3:
|
|
106
118
|
e_1 = _j.sent();
|
|
107
119
|
calls.shift();
|
|
120
|
+
if (!this.isCrypto) return [3 /*break*/, 5];
|
|
121
|
+
calls.shift();
|
|
108
122
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
109
123
|
case 4:
|
|
110
|
-
|
|
111
|
-
return [3 /*break*/,
|
|
112
|
-
case 5:
|
|
113
|
-
|
|
124
|
+
_g = (_j.sent()), _adminFee = _g[0], _A = _g[1], _lpTokenSupply = _g[2], _gamma = _g[3], _prices = _g.slice(4);
|
|
125
|
+
return [3 /*break*/, 7];
|
|
126
|
+
case 5: return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
127
|
+
case 6:
|
|
128
|
+
_h = (_j.sent()), _fee = _h[0], _adminFee = _h[1], _A = _h[2], _lpTokenSupply = _h[3], _gamma = _h[4], _prices = _h.slice(5);
|
|
129
|
+
_j.label = 7;
|
|
130
|
+
case 7: return [3 /*break*/, 8];
|
|
131
|
+
case 8:
|
|
132
|
+
_c = [
|
|
114
133
|
ethers_1.ethers.utils.formatUnits(_virtualPrice),
|
|
115
|
-
ethers_1.ethers.utils.formatUnits(_lpTokenSupply),
|
|
116
134
|
ethers_1.ethers.utils.formatUnits(_fee, 8),
|
|
117
135
|
ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
|
|
118
136
|
ethers_1.ethers.utils.formatUnits(_A, 0),
|
|
137
|
+
ethers_1.ethers.utils.formatUnits(_lpTokenSupply),
|
|
119
138
|
_gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
|
|
120
|
-
], virtualPrice =
|
|
139
|
+
], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], lpTokenSupply = _c[4], gamma = _c[5];
|
|
140
|
+
if (this.isCrypto) {
|
|
141
|
+
prices = _prices.map(function (_p) { return ethers_1.ethers.utils.formatUnits(_p); });
|
|
142
|
+
priceOracle = [];
|
|
143
|
+
priceScale = [];
|
|
144
|
+
for (i = 0; i < this.wrappedCoins.length - 1; i++) {
|
|
145
|
+
priceOracle.push(prices.shift());
|
|
146
|
+
priceScale.push(prices.shift());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
121
149
|
A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
|
|
122
150
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
|
|
123
|
-
case
|
|
124
|
-
|
|
125
|
-
|
|
151
|
+
case 9:
|
|
152
|
+
_d = _j.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
|
|
153
|
+
_e = [
|
|
126
154
|
_future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
|
|
127
155
|
_initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
|
|
128
156
|
_future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
|
|
129
157
|
_initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
|
|
130
|
-
], future_A =
|
|
131
|
-
return [2 /*return*/, {
|
|
158
|
+
], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
|
|
159
|
+
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 }];
|
|
132
160
|
}
|
|
133
161
|
});
|
|
134
162
|
}); };
|
|
@@ -1254,6 +1282,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1254
1282
|
});
|
|
1255
1283
|
});
|
|
1256
1284
|
};
|
|
1285
|
+
// OVERRIDE
|
|
1257
1286
|
PoolTemplate.prototype.depositBalancedAmounts = function () {
|
|
1258
1287
|
return __awaiter(this, void 0, void 0, function () {
|
|
1259
1288
|
return __generator(this, function (_c) {
|
|
@@ -1271,11 +1300,56 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1271
1300
|
});
|
|
1272
1301
|
});
|
|
1273
1302
|
};
|
|
1274
|
-
//
|
|
1303
|
+
// | balanced[i] / sum(balanced[j]) = balance[i] / sum(balance[j]) |
|
|
1304
|
+
// | sum(pj * balanced[j]) = sum(aj * pj) |
|
|
1305
|
+
//
|
|
1306
|
+
// --- Answer ---
|
|
1307
|
+
// balanced[i] = sum(aj * pj) / sum(rj * pj / ri)
|
|
1308
|
+
//
|
|
1309
|
+
// totalValueBN = sum(aj * pj)
|
|
1310
|
+
// totalBalanceBN = sum(balance[j])
|
|
1311
|
+
// ratiosBN[i] = balancesBN[i] / totalBalanceBN = ri = balance[i] / sum(balance[j])
|
|
1312
|
+
// denominatorBN = sum(rj * pj / ri)
|
|
1313
|
+
PoolTemplate.prototype._balancedAmountsWithSameValue = function (amountsBN, pricesBN, balancesBN) {
|
|
1314
|
+
var valuesBN = amountsBN.map(function (aBN, i) { return aBN.times(pricesBN[i]); });
|
|
1315
|
+
var totalValueBN = valuesBN.reduce(function (v1BN, v2BN) { return v1BN.plus(v2BN); });
|
|
1316
|
+
var totalBalanceBN = balancesBN.reduce(function (b1BN, b2BN) { return b1BN.plus(b2BN); });
|
|
1317
|
+
var ratiosBN = balancesBN.map(function (bBN) { return bBN.div(totalBalanceBN); });
|
|
1318
|
+
var balancedAmountsBN = [];
|
|
1319
|
+
var _loop_1 = function (i) {
|
|
1320
|
+
var denominatorBN = ratiosBN.map(function (rBN, j) { return rBN.times(pricesBN[j])
|
|
1321
|
+
.div(ratiosBN[i]); }).reduce(function (xBN, yBN) { return xBN.plus(yBN); });
|
|
1322
|
+
balancedAmountsBN.push(totalValueBN.div(denominatorBN));
|
|
1323
|
+
};
|
|
1324
|
+
for (var i = 0; i < amountsBN.length; i++) {
|
|
1325
|
+
_loop_1(i);
|
|
1326
|
+
}
|
|
1327
|
+
return balancedAmountsBN.map(String);
|
|
1328
|
+
};
|
|
1275
1329
|
PoolTemplate.prototype.depositBonus = function (amounts) {
|
|
1276
1330
|
return __awaiter(this, void 0, void 0, function () {
|
|
1277
|
-
|
|
1278
|
-
|
|
1331
|
+
var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
|
|
1332
|
+
return __generator(this, function (_e) {
|
|
1333
|
+
switch (_e.label) {
|
|
1334
|
+
case 0:
|
|
1335
|
+
amountsBN = amounts.map(utils_1.BN);
|
|
1336
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
1337
|
+
case 1:
|
|
1338
|
+
pricesBN = (_e.sent()).map(utils_1.BN);
|
|
1339
|
+
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
1340
|
+
case 2:
|
|
1341
|
+
balancesBN = (_e.sent()).map(utils_1.BN);
|
|
1342
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1343
|
+
_c = utils_1.BN;
|
|
1344
|
+
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1345
|
+
case 3:
|
|
1346
|
+
expectedBN = _c.apply(void 0, [_e.sent()]);
|
|
1347
|
+
_d = utils_1.BN;
|
|
1348
|
+
return [4 /*yield*/, this.depositExpected(balancedAmounts)];
|
|
1349
|
+
case 4:
|
|
1350
|
+
balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
|
|
1351
|
+
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1352
|
+
}
|
|
1279
1353
|
});
|
|
1280
1354
|
});
|
|
1281
1355
|
};
|
|
@@ -1348,11 +1422,30 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1348
1422
|
});
|
|
1349
1423
|
});
|
|
1350
1424
|
};
|
|
1351
|
-
// OVERRIDE
|
|
1352
1425
|
PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
|
|
1353
1426
|
return __awaiter(this, void 0, void 0, function () {
|
|
1354
|
-
|
|
1355
|
-
|
|
1427
|
+
var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
|
|
1428
|
+
return __generator(this, function (_e) {
|
|
1429
|
+
switch (_e.label) {
|
|
1430
|
+
case 0:
|
|
1431
|
+
amountsBN = amounts.map(utils_1.BN);
|
|
1432
|
+
return [4 /*yield*/, this._wrappedPrices()];
|
|
1433
|
+
case 1:
|
|
1434
|
+
pricesBN = (_e.sent()).map(utils_1.BN);
|
|
1435
|
+
return [4 /*yield*/, this.stats.wrappedBalances()];
|
|
1436
|
+
case 2:
|
|
1437
|
+
balancesBN = (_e.sent()).map(utils_1.BN);
|
|
1438
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1439
|
+
_c = utils_1.BN;
|
|
1440
|
+
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
1441
|
+
case 3:
|
|
1442
|
+
expectedBN = _c.apply(void 0, [_e.sent()]);
|
|
1443
|
+
_d = utils_1.BN;
|
|
1444
|
+
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
1445
|
+
case 4:
|
|
1446
|
+
balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
|
|
1447
|
+
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1448
|
+
}
|
|
1356
1449
|
});
|
|
1357
1450
|
});
|
|
1358
1451
|
};
|
|
@@ -1969,8 +2062,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1969
2062
|
PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
|
|
1970
2063
|
return __awaiter(this, void 0, void 0, function () {
|
|
1971
2064
|
var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _minMintAmount, _j, _k, _l, _m, _o, ethIndex, value, i, _gas, gasLimit;
|
|
1972
|
-
return __generator(this, function (
|
|
1973
|
-
switch (
|
|
2065
|
+
return __generator(this, function (_q) {
|
|
2066
|
+
switch (_q.label) {
|
|
1974
2067
|
case 0:
|
|
1975
2068
|
coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.wrappedCoinAddresses, true);
|
|
1976
2069
|
coins = isUnderlying ? this.underlyingCoins : this.wrappedCoinAddresses;
|
|
@@ -1983,14 +2076,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1983
2076
|
_e = (_d = Object).values;
|
|
1984
2077
|
return [4 /*yield*/, this.walletUnderlyingCoinBalances()];
|
|
1985
2078
|
case 1:
|
|
1986
|
-
_c = _e.apply(_d, [
|
|
2079
|
+
_c = _e.apply(_d, [_q.sent()]);
|
|
1987
2080
|
return [3 /*break*/, 4];
|
|
1988
2081
|
case 2:
|
|
1989
2082
|
_g = (_f = Object).values;
|
|
1990
2083
|
return [4 /*yield*/, this.walletWrappedCoinBalances()];
|
|
1991
2084
|
case 3:
|
|
1992
|
-
_c = _g.apply(_f, [
|
|
1993
|
-
|
|
2085
|
+
_c = _g.apply(_f, [_q.sent()]);
|
|
2086
|
+
_q.label = 4;
|
|
1994
2087
|
case 4:
|
|
1995
2088
|
balances = _c;
|
|
1996
2089
|
for (i = 0; i < balances.length; i++) {
|
|
@@ -2001,12 +2094,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2001
2094
|
if (!isUnderlying) return [3 /*break*/, 6];
|
|
2002
2095
|
return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
|
|
2003
2096
|
case 5:
|
|
2004
|
-
_h =
|
|
2097
|
+
_h = _q.sent();
|
|
2005
2098
|
return [3 /*break*/, 8];
|
|
2006
2099
|
case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
|
|
2007
2100
|
case 7:
|
|
2008
|
-
_h =
|
|
2009
|
-
|
|
2101
|
+
_h = _q.sent();
|
|
2102
|
+
_q.label = 8;
|
|
2010
2103
|
case 8:
|
|
2011
2104
|
allowance = _h;
|
|
2012
2105
|
if (estimateGas && !allowance) {
|
|
@@ -2016,12 +2109,12 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2016
2109
|
if (!isUnderlying) return [3 /*break*/, 10];
|
|
2017
2110
|
return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
|
|
2018
2111
|
case 9:
|
|
2019
|
-
|
|
2112
|
+
_q.sent();
|
|
2020
2113
|
return [3 /*break*/, 12];
|
|
2021
2114
|
case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
|
|
2022
2115
|
case 11:
|
|
2023
|
-
|
|
2024
|
-
|
|
2116
|
+
_q.sent();
|
|
2117
|
+
_q.label = 12;
|
|
2025
2118
|
case 12:
|
|
2026
2119
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
|
|
2027
2120
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
|
|
@@ -2030,14 +2123,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2030
2123
|
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
2031
2124
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
2032
2125
|
case 13:
|
|
2033
|
-
_j = _l.apply(_k, [
|
|
2126
|
+
_j = _l.apply(_k, [_q.sent()]).mul(99).div(100);
|
|
2034
2127
|
return [3 /*break*/, 16];
|
|
2035
2128
|
case 14:
|
|
2036
2129
|
_o = (_m = ethers_1.ethers.utils).parseUnits;
|
|
2037
2130
|
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
2038
2131
|
case 15:
|
|
2039
|
-
_j = _o.apply(_m, [
|
|
2040
|
-
|
|
2132
|
+
_j = _o.apply(_m, [_q.sent()]).mul(99).div(100);
|
|
2133
|
+
_q.label = 16;
|
|
2041
2134
|
case 16:
|
|
2042
2135
|
_minMintAmount = _j;
|
|
2043
2136
|
ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
|
|
@@ -2048,15 +2141,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2048
2141
|
}
|
|
2049
2142
|
return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
2050
2143
|
case 17:
|
|
2051
|
-
_gas = (
|
|
2144
|
+
_gas = (_q.sent());
|
|
2052
2145
|
if (estimateGas)
|
|
2053
2146
|
return [2 /*return*/, _gas.toNumber()];
|
|
2054
2147
|
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
2055
2148
|
case 18:
|
|
2056
|
-
|
|
2149
|
+
_q.sent();
|
|
2057
2150
|
gasLimit = _gas.mul(200).div(100);
|
|
2058
2151
|
return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
|
|
2059
|
-
case 19: return [2 /*return*/, (
|
|
2152
|
+
case 19: return [2 /*return*/, (_q.sent()).hash];
|
|
2060
2153
|
}
|
|
2061
2154
|
});
|
|
2062
2155
|
});
|
|
@@ -2166,11 +2259,24 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2166
2259
|
});
|
|
2167
2260
|
});
|
|
2168
2261
|
};
|
|
2169
|
-
// OVERRIDE
|
|
2170
2262
|
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
2171
2263
|
return __awaiter(this, void 0, void 0, function () {
|
|
2264
|
+
var prices, value, lpTokenAmount, balancedAmounts, balancedValue;
|
|
2172
2265
|
return __generator(this, function (_c) {
|
|
2173
|
-
|
|
2266
|
+
switch (_c.label) {
|
|
2267
|
+
case 0: return [4 /*yield*/, this._underlyingPrices()];
|
|
2268
|
+
case 1:
|
|
2269
|
+
prices = _c.sent();
|
|
2270
|
+
value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2271
|
+
return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
|
|
2272
|
+
case 2:
|
|
2273
|
+
lpTokenAmount = _c.sent();
|
|
2274
|
+
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2275
|
+
case 3:
|
|
2276
|
+
balancedAmounts = _c.sent();
|
|
2277
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2278
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2279
|
+
}
|
|
2174
2280
|
});
|
|
2175
2281
|
});
|
|
2176
2282
|
};
|
|
@@ -2260,7 +2366,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2260
2366
|
return __generator(this, function (_c) {
|
|
2261
2367
|
switch (_c.label) {
|
|
2262
2368
|
case 0:
|
|
2263
|
-
if (this.isCrypto)
|
|
2369
|
+
if (this.isCrypto || this.isPlain || this.isFake)
|
|
2264
2370
|
throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2265
2371
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
|
|
2266
2372
|
case 1: return [2 /*return*/, _c.sent()];
|
|
@@ -2268,11 +2374,25 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2268
2374
|
});
|
|
2269
2375
|
});
|
|
2270
2376
|
};
|
|
2271
|
-
// OVERRIDE
|
|
2272
2377
|
PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
|
|
2273
2378
|
return __awaiter(this, void 0, void 0, function () {
|
|
2274
|
-
|
|
2275
|
-
|
|
2379
|
+
var prices, value, lpTokenAmount, _c, balancedAmounts, balancedValue;
|
|
2380
|
+
return __generator(this, function (_d) {
|
|
2381
|
+
switch (_d.label) {
|
|
2382
|
+
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
2383
|
+
case 1:
|
|
2384
|
+
prices = _d.sent();
|
|
2385
|
+
value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2386
|
+
_c = Number;
|
|
2387
|
+
return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
|
|
2388
|
+
case 2:
|
|
2389
|
+
lpTokenAmount = _c.apply(void 0, [_d.sent()]);
|
|
2390
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
2391
|
+
case 3:
|
|
2392
|
+
balancedAmounts = _d.sent();
|
|
2393
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2394
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2395
|
+
}
|
|
2276
2396
|
});
|
|
2277
2397
|
});
|
|
2278
2398
|
};
|
|
@@ -2318,11 +2438,26 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2318
2438
|
});
|
|
2319
2439
|
});
|
|
2320
2440
|
};
|
|
2321
|
-
// OVERRIDE
|
|
2322
2441
|
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2323
2442
|
return __awaiter(this, void 0, void 0, function () {
|
|
2324
|
-
|
|
2325
|
-
|
|
2443
|
+
var prices, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
|
|
2444
|
+
return __generator(this, function (_d) {
|
|
2445
|
+
switch (_d.label) {
|
|
2446
|
+
case 0: return [4 /*yield*/, this._underlyingPrices()];
|
|
2447
|
+
case 1:
|
|
2448
|
+
prices = _d.sent();
|
|
2449
|
+
coinPrice = prices[this._getCoinIdx(coin)];
|
|
2450
|
+
_c = Number;
|
|
2451
|
+
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
2452
|
+
case 2:
|
|
2453
|
+
amount = _c.apply(void 0, [_d.sent()]);
|
|
2454
|
+
value = amount * coinPrice;
|
|
2455
|
+
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2456
|
+
case 3:
|
|
2457
|
+
balancedAmounts = _d.sent();
|
|
2458
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2459
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2460
|
+
}
|
|
2326
2461
|
});
|
|
2327
2462
|
});
|
|
2328
2463
|
};
|
|
@@ -2407,11 +2542,26 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2407
2542
|
});
|
|
2408
2543
|
});
|
|
2409
2544
|
};
|
|
2410
|
-
// OVERRIDE
|
|
2411
2545
|
PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
|
|
2412
2546
|
return __awaiter(this, void 0, void 0, function () {
|
|
2413
|
-
|
|
2414
|
-
|
|
2547
|
+
var prices, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
|
|
2548
|
+
return __generator(this, function (_d) {
|
|
2549
|
+
switch (_d.label) {
|
|
2550
|
+
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
2551
|
+
case 1:
|
|
2552
|
+
prices = _d.sent();
|
|
2553
|
+
coinPrice = prices[this._getCoinIdx(coin, false)];
|
|
2554
|
+
_c = Number;
|
|
2555
|
+
return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
2556
|
+
case 2:
|
|
2557
|
+
amount = _c.apply(void 0, [_d.sent()]);
|
|
2558
|
+
value = amount * coinPrice;
|
|
2559
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
2560
|
+
case 3:
|
|
2561
|
+
balancedAmounts = _d.sent();
|
|
2562
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2563
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2564
|
+
}
|
|
2415
2565
|
});
|
|
2416
2566
|
});
|
|
2417
2567
|
};
|
|
@@ -2645,17 +2795,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2645
2795
|
return [3 /*break*/, 5];
|
|
2646
2796
|
case 3:
|
|
2647
2797
|
_d = (_c = ethers_1.ethers.utils).formatUnits;
|
|
2648
|
-
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply()];
|
|
2798
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
|
|
2649
2799
|
case 4:
|
|
2650
2800
|
totalLp = _d.apply(_c, [_f.sent()]);
|
|
2651
2801
|
_f.label = 5;
|
|
2652
2802
|
case 5: return [2 /*return*/, {
|
|
2653
2803
|
lpUser: userLpTotalBalanceBN.toString(),
|
|
2654
2804
|
lpTotal: totalLp,
|
|
2655
|
-
lpShare: userLpTotalBalanceBN.div(totalLp).times(100).toString(),
|
|
2805
|
+
lpShare: (0, utils_1.BN)(totalLp).gt(0) ? userLpTotalBalanceBN.div(totalLp).times(100).toString() : '0',
|
|
2656
2806
|
gaugeUser: userLpBalance.gauge,
|
|
2657
2807
|
gaugeTotal: gaugeLp,
|
|
2658
|
-
gaugeShare: withGauge ? (0, utils_1.BN)(
|
|
2808
|
+
gaugeShare: !withGauge ? undefined : (0, utils_1.BN)(gaugeLp).gt(0) ? (0, utils_1.BN)(userLpBalance.gauge).div(gaugeLp).times(100).toString() : '0',
|
|
2659
2809
|
}];
|
|
2660
2810
|
}
|
|
2661
2811
|
});
|
|
@@ -20,13 +20,11 @@ var curve_1 = require("../curve");
|
|
|
20
20
|
var PoolTemplate_1 = require("./PoolTemplate");
|
|
21
21
|
var poolBalancesMixin_1 = require("./mixins/poolBalancesMixin");
|
|
22
22
|
var depositBalancedAmountsMixins_1 = require("./mixins/depositBalancedAmountsMixins");
|
|
23
|
-
var depositBonusMixins_1 = require("./mixins/depositBonusMixins");
|
|
24
23
|
var depositMixins_1 = require("./mixins/depositMixins");
|
|
25
24
|
var depositWrappedMixins_1 = require("./mixins/depositWrappedMixins");
|
|
26
25
|
var withdrawExpectedMixins_1 = require("./mixins/withdrawExpectedMixins");
|
|
27
26
|
var withdrawMixins_1 = require("./mixins/withdrawMixins");
|
|
28
27
|
var withdrawWrappedMixins_1 = require("./mixins/withdrawWrappedMixins");
|
|
29
|
-
var withdrawBonusMixins_1 = require("./mixins/withdrawBonusMixins");
|
|
30
28
|
var withdrawImbalanceMixins_1 = require("./mixins/withdrawImbalanceMixins");
|
|
31
29
|
var withdrawImbalanceWrappedMixins_1 = require("./mixins/withdrawImbalanceWrappedMixins");
|
|
32
30
|
var withdrawOneCoinExpectedMixins_1 = require("./mixins/withdrawOneCoinExpectedMixins");
|
|
@@ -70,17 +68,6 @@ var getPool = function (poolId) {
|
|
|
70
68
|
Object.assign(Pool.prototype, depositBalancedAmountsMixins_1.depositWrappedBalancedAmountsMixin);
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
|
-
// depositBonus and depositWrappedBonus
|
|
74
|
-
if (poolDummy.isCrypto) {
|
|
75
|
-
Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusCryptoMixin);
|
|
76
|
-
if (!poolDummy.isPlain && !poolDummy.isFake)
|
|
77
|
-
Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusCryptoMixin);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusMixin);
|
|
81
|
-
if (!poolDummy.isPlain && !poolDummy.isFake)
|
|
82
|
-
Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusMixin);
|
|
83
|
-
}
|
|
84
71
|
// deposit and depositEstimateGas
|
|
85
72
|
if (poolDummy.isMetaFactory) {
|
|
86
73
|
Object.assign(Pool.prototype, depositMixins_1.depositMetaFactoryMixin);
|
|
@@ -129,24 +116,6 @@ var getPool = function (poolId) {
|
|
|
129
116
|
else {
|
|
130
117
|
Object.assign(Pool.prototype, withdrawMixins_1.withdrawPlainMixin);
|
|
131
118
|
}
|
|
132
|
-
// withdrawImbalanceBonus and withdrawOneCoinBonus
|
|
133
|
-
if (!poolDummy.isCrypto) {
|
|
134
|
-
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawImbalanceBonusMixin);
|
|
135
|
-
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinBonusMixin);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinCryptoBonusMixin);
|
|
139
|
-
}
|
|
140
|
-
// withdrawImbalanceWrappedBonus and withdrawOneCoinWrappedBonus
|
|
141
|
-
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
142
|
-
if (!poolDummy.isCrypto) {
|
|
143
|
-
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawImbalanceWrappedBonusMixin);
|
|
144
|
-
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinWrappedBonusMixin);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinWrappedCryptoBonusMixin);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
119
|
// withdrawWrapped and withdrawWrappedEstimateGas
|
|
151
120
|
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
152
121
|
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
package/lib/utils.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import BigNumber from 'bignumber.js';
|
|
|
3
3
|
import { IDict } from './interfaces';
|
|
4
4
|
export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
5
5
|
export declare const MAX_ALLOWANCE: ethers.BigNumber;
|
|
6
|
-
export declare const BN: (val: number | string) => BigNumber;
|
|
7
|
-
export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
|
|
8
|
-
export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
|
|
9
|
-
export declare const fromBN: (bn: BigNumber, decimals?: number) => ethers.BigNumber;
|
|
10
6
|
export declare const _cutZeros: (strn: string) => string;
|
|
11
7
|
export declare const checkNumber: (n: number | string) => number | string;
|
|
12
8
|
export declare const formatNumber: (n: number | string, decimals?: number) => string;
|
|
13
9
|
export declare const parseUnits: (n: number | string, decimals?: number) => ethers.BigNumber;
|
|
10
|
+
export declare const BN: (val: number | string) => BigNumber;
|
|
11
|
+
export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
|
|
12
|
+
export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
|
|
13
|
+
export declare const fromBN: (bn: BigNumber, decimals?: number) => ethers.BigNumber;
|
|
14
14
|
export declare const isEth: (address: string) => boolean;
|
|
15
15
|
export declare const getEthIndex: (addresses: string[]) => number;
|
|
16
16
|
export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.
|
|
62
|
+
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
@@ -69,24 +69,6 @@ var external_api_1 = require("./external-api");
|
|
|
69
69
|
var ERC20_json_1 = __importDefault(require("./constants/abis/ERC20.json"));
|
|
70
70
|
exports.ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
71
71
|
exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
|
|
72
|
-
// bignumber.js
|
|
73
|
-
var BN = function (val) { return new bignumber_js_1.default(val); };
|
|
74
|
-
exports.BN = BN;
|
|
75
|
-
var toBN = function (n, decimals) {
|
|
76
|
-
if (decimals === void 0) { decimals = 18; }
|
|
77
|
-
return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals));
|
|
78
|
-
};
|
|
79
|
-
exports.toBN = toBN;
|
|
80
|
-
var toStringFromBN = function (bn, decimals) {
|
|
81
|
-
if (decimals === void 0) { decimals = 18; }
|
|
82
|
-
return bn.toFixed(decimals);
|
|
83
|
-
};
|
|
84
|
-
exports.toStringFromBN = toStringFromBN;
|
|
85
|
-
var fromBN = function (bn, decimals) {
|
|
86
|
-
if (decimals === void 0) { decimals = 18; }
|
|
87
|
-
return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
|
|
88
|
-
};
|
|
89
|
-
exports.fromBN = fromBN;
|
|
90
72
|
// Formatting numbers
|
|
91
73
|
var _cutZeros = function (strn) {
|
|
92
74
|
return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
|
|
@@ -111,6 +93,24 @@ var parseUnits = function (n, decimals) {
|
|
|
111
93
|
return ethers_1.ethers.utils.parseUnits((0, exports.formatNumber)(n, decimals), decimals);
|
|
112
94
|
};
|
|
113
95
|
exports.parseUnits = parseUnits;
|
|
96
|
+
// bignumber.js
|
|
97
|
+
var BN = function (val) { return new bignumber_js_1.default((0, exports.checkNumber)(val)); };
|
|
98
|
+
exports.BN = BN;
|
|
99
|
+
var toBN = function (n, decimals) {
|
|
100
|
+
if (decimals === void 0) { decimals = 18; }
|
|
101
|
+
return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals));
|
|
102
|
+
};
|
|
103
|
+
exports.toBN = toBN;
|
|
104
|
+
var toStringFromBN = function (bn, decimals) {
|
|
105
|
+
if (decimals === void 0) { decimals = 18; }
|
|
106
|
+
return bn.toFixed(decimals);
|
|
107
|
+
};
|
|
108
|
+
exports.toStringFromBN = toStringFromBN;
|
|
109
|
+
var fromBN = function (bn, decimals) {
|
|
110
|
+
if (decimals === void 0) { decimals = 18; }
|
|
111
|
+
return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
|
|
112
|
+
};
|
|
113
|
+
exports.fromBN = fromBN;
|
|
114
114
|
// -------------------
|
|
115
115
|
var isEth = function (address) { return address.toLowerCase() === exports.ETH_ADDRESS.toLowerCase(); };
|
|
116
116
|
exports.isEth = isEth;
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { PoolTemplate } from "../PoolTemplate";
|
|
2
|
-
export declare const depositBonusMixin: PoolTemplate;
|
|
3
|
-
export declare const depositWrappedBonusMixin: PoolTemplate;
|
|
4
|
-
export declare const depositBonusCryptoMixin: PoolTemplate;
|
|
5
|
-
export declare const depositWrappedBonusCryptoMixin: PoolTemplate;
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.depositWrappedBonusCryptoMixin = exports.depositBonusCryptoMixin = exports.depositWrappedBonusMixin = exports.depositBonusMixin = void 0;
|
|
40
|
-
var ethers_1 = require("ethers");
|
|
41
|
-
var curve_1 = require("../../curve");
|
|
42
|
-
var utils_1 = require("../../utils");
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
exports.depositBonusMixin = {
|
|
45
|
-
depositBonus: function (amounts) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var totalAmount, expected, _a, poolBalances, poolTotalBalance, poolBalancesRatios, balancedAmounts, balancedExpected, _b;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
|
|
52
|
-
_a = Number;
|
|
53
|
-
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
54
|
-
case 1:
|
|
55
|
-
expected = _a.apply(void 0, [_c.sent()]);
|
|
56
|
-
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
57
|
-
case 2:
|
|
58
|
-
poolBalances = (_c.sent()).map(Number);
|
|
59
|
-
poolTotalBalance = poolBalances.reduce(function (a, b) { return a + b; });
|
|
60
|
-
poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalBalance; });
|
|
61
|
-
balancedAmounts = poolBalancesRatios.map(function (r) { return r * totalAmount; });
|
|
62
|
-
_b = Number;
|
|
63
|
-
return [4 /*yield*/, this.depositExpected(balancedAmounts)];
|
|
64
|
-
case 3:
|
|
65
|
-
balancedExpected = _b.apply(void 0, [_c.sent()]);
|
|
66
|
-
return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
exports.depositWrappedBonusMixin = {
|
|
74
|
-
depositWrappedBonus: function (amounts) {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var vp, basePoolAddress, _a, _b, _c, prices, totalValue, expected, _d, poolBalances, poolValues, poolTotalValue, poolRatios, balancedValues, balancedAmounts, balancedExpected, _e;
|
|
77
|
-
return __generator(this, function (_f) {
|
|
78
|
-
switch (_f.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
vp = 1;
|
|
81
|
-
if (!this.isMeta) return [3 /*break*/, 2];
|
|
82
|
-
basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
|
|
83
|
-
_a = Number;
|
|
84
|
-
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
85
|
-
return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
|
|
86
|
-
case 1:
|
|
87
|
-
vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
|
|
88
|
-
_f.label = 2;
|
|
89
|
-
case 2:
|
|
90
|
-
prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
|
|
91
|
-
totalValue = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
92
|
-
_d = Number;
|
|
93
|
-
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
94
|
-
case 3:
|
|
95
|
-
expected = _d.apply(void 0, [_f.sent()]);
|
|
96
|
-
return [4 /*yield*/, this.stats.wrappedBalances()];
|
|
97
|
-
case 4:
|
|
98
|
-
poolBalances = (_f.sent()).map(Number);
|
|
99
|
-
poolValues = poolBalances.map(function (b, i) { return b * prices[i]; });
|
|
100
|
-
poolTotalValue = poolValues.reduce(function (a, b) { return a + b; });
|
|
101
|
-
poolRatios = poolValues.map(function (b) { return b / poolTotalValue; });
|
|
102
|
-
balancedValues = poolRatios.map(function (r) { return r * totalValue; });
|
|
103
|
-
balancedAmounts = balancedValues.map(function (a, i) { return a / prices[i]; });
|
|
104
|
-
_e = Number;
|
|
105
|
-
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
106
|
-
case 5:
|
|
107
|
-
balancedExpected = _e.apply(void 0, [_f.sent()]);
|
|
108
|
-
return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
exports.depositBonusCryptoMixin = {
|
|
116
|
-
depositBonus: function (amounts) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var prices, totalAmountUSD, expected, _a, poolBalances, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _b;
|
|
119
|
-
return __generator(this, function (_c) {
|
|
120
|
-
switch (_c.label) {
|
|
121
|
-
case 0: return [4 /*yield*/, this._underlyingPrices()];
|
|
122
|
-
case 1:
|
|
123
|
-
prices = _c.sent();
|
|
124
|
-
totalAmountUSD = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
125
|
-
_a = Number;
|
|
126
|
-
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
127
|
-
case 2:
|
|
128
|
-
expected = _a.apply(void 0, [_c.sent()]);
|
|
129
|
-
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
130
|
-
case 3:
|
|
131
|
-
poolBalances = (_c.sent()).map(Number);
|
|
132
|
-
poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices[i]; });
|
|
133
|
-
poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
|
|
134
|
-
poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
|
|
135
|
-
balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
|
|
136
|
-
balancedAmounts = balancedAmountsUSD.map(function (a, i) { return a / prices[i]; });
|
|
137
|
-
_b = Number;
|
|
138
|
-
return [4 /*yield*/, this.depositExpected(balancedAmounts)];
|
|
139
|
-
case 4:
|
|
140
|
-
balancedExpected = _b.apply(void 0, [_c.sent()]);
|
|
141
|
-
return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
exports.depositWrappedBonusCryptoMixin = {
|
|
149
|
-
depositWrappedBonus: function (amounts) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var prices, vp, basePoolAddress, _a, _b, _c, totalAmountUSD, expected, _d, poolBalances, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _e;
|
|
152
|
-
return __generator(this, function (_f) {
|
|
153
|
-
switch (_f.label) {
|
|
154
|
-
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
155
|
-
case 1:
|
|
156
|
-
prices = _f.sent();
|
|
157
|
-
vp = 1;
|
|
158
|
-
if (!this.isMeta) return [3 /*break*/, 3];
|
|
159
|
-
basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
|
|
160
|
-
_a = Number;
|
|
161
|
-
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
162
|
-
return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
|
|
163
|
-
case 2:
|
|
164
|
-
vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
|
|
165
|
-
_f.label = 3;
|
|
166
|
-
case 3:
|
|
167
|
-
prices = prices.map(function (p, i) { return i === prices.length - 1 ? p * vp : p; });
|
|
168
|
-
totalAmountUSD = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
169
|
-
_d = Number;
|
|
170
|
-
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
171
|
-
case 4:
|
|
172
|
-
expected = _d.apply(void 0, [_f.sent()]);
|
|
173
|
-
return [4 /*yield*/, this.stats.wrappedBalances()];
|
|
174
|
-
case 5:
|
|
175
|
-
poolBalances = (_f.sent()).map(Number);
|
|
176
|
-
poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices[i]; });
|
|
177
|
-
poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
|
|
178
|
-
poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
|
|
179
|
-
balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
|
|
180
|
-
balancedAmounts = balancedAmountsUSD.map(function (a, i) { return a / prices[i]; });
|
|
181
|
-
_e = Number;
|
|
182
|
-
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
183
|
-
case 6:
|
|
184
|
-
balancedExpected = _e.apply(void 0, [_f.sent()]);
|
|
185
|
-
return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
},
|
|
190
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PoolTemplate } from "../PoolTemplate";
|
|
2
|
-
export declare const withdrawImbalanceBonusMixin: PoolTemplate;
|
|
3
|
-
export declare const withdrawImbalanceWrappedBonusMixin: PoolTemplate;
|
|
4
|
-
export declare const withdrawOneCoinBonusMixin: PoolTemplate;
|
|
5
|
-
export declare const withdrawOneCoinWrappedBonusMixin: PoolTemplate;
|
|
6
|
-
export declare const withdrawOneCoinCryptoBonusMixin: PoolTemplate;
|
|
7
|
-
export declare const withdrawOneCoinWrappedCryptoBonusMixin: PoolTemplate;
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.withdrawOneCoinWrappedCryptoBonusMixin = exports.withdrawOneCoinCryptoBonusMixin = exports.withdrawOneCoinWrappedBonusMixin = exports.withdrawOneCoinBonusMixin = exports.withdrawImbalanceWrappedBonusMixin = exports.withdrawImbalanceBonusMixin = void 0;
|
|
40
|
-
var ethers_1 = require("ethers");
|
|
41
|
-
var curve_1 = require("../../curve");
|
|
42
|
-
var utils_1 = require("../../utils");
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
exports.withdrawImbalanceBonusMixin = {
|
|
45
|
-
withdrawImbalanceBonus: function (amounts) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var totalAmount, lpTokenAmount, balancedAmounts, balancedTotalAmount;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
|
|
52
|
-
return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
|
|
53
|
-
case 1:
|
|
54
|
-
lpTokenAmount = _a.sent();
|
|
55
|
-
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
56
|
-
case 2:
|
|
57
|
-
balancedAmounts = _a.sent();
|
|
58
|
-
balancedTotalAmount = balancedAmounts.map(Number).reduce(function (a, b) { return a + b; });
|
|
59
|
-
return [2 /*return*/, String((totalAmount - balancedTotalAmount) / Math.max(totalAmount, balancedTotalAmount) * 100)];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
exports.withdrawImbalanceWrappedBonusMixin = {
|
|
67
|
-
withdrawImbalanceWrappedBonus: function (amounts) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
-
var vp, basePoolAddress, _a, _b, _c, prices, totalValue, lpTokenAmount, _d, balancedAmounts, balancedTotalValue;
|
|
70
|
-
return __generator(this, function (_e) {
|
|
71
|
-
switch (_e.label) {
|
|
72
|
-
case 0:
|
|
73
|
-
vp = 1;
|
|
74
|
-
if (!this.isMeta) return [3 /*break*/, 2];
|
|
75
|
-
basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
|
|
76
|
-
_a = Number;
|
|
77
|
-
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
78
|
-
return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
|
|
79
|
-
case 1:
|
|
80
|
-
vp = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]);
|
|
81
|
-
_e.label = 2;
|
|
82
|
-
case 2:
|
|
83
|
-
prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
|
|
84
|
-
totalValue = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
85
|
-
_d = Number;
|
|
86
|
-
return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
|
|
87
|
-
case 3:
|
|
88
|
-
lpTokenAmount = _d.apply(void 0, [_e.sent()]);
|
|
89
|
-
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
90
|
-
case 4:
|
|
91
|
-
balancedAmounts = _e.sent();
|
|
92
|
-
balancedTotalValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
93
|
-
return [2 /*return*/, String((totalValue - balancedTotalValue) / Math.max(totalValue, balancedTotalValue) * 100)];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
exports.withdrawOneCoinBonusMixin = {
|
|
101
|
-
withdrawOneCoinBonus: function (lpTokenAmount, coin) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
-
var totalAmount, _a, balancedAmounts, balancedTotalAmount;
|
|
104
|
-
return __generator(this, function (_b) {
|
|
105
|
-
switch (_b.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
_a = Number;
|
|
108
|
-
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
109
|
-
case 1:
|
|
110
|
-
totalAmount = _a.apply(void 0, [_b.sent()]);
|
|
111
|
-
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
112
|
-
case 2:
|
|
113
|
-
balancedAmounts = _b.sent();
|
|
114
|
-
balancedTotalAmount = balancedAmounts.map(Number).reduce(function (a, b) { return a + b; });
|
|
115
|
-
return [2 /*return*/, String((totalAmount - balancedTotalAmount) / Math.max(totalAmount, balancedTotalAmount) * 100)];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
exports.withdrawOneCoinWrappedBonusMixin = {
|
|
123
|
-
withdrawOneCoinWrappedBonus: function (lpTokenAmount, coin) {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var vp, basePoolAddress, _a, _b, _c, prices, coinAmount, _d, totalValue, balancedAmounts, balancedTotalValue;
|
|
126
|
-
return __generator(this, function (_e) {
|
|
127
|
-
switch (_e.label) {
|
|
128
|
-
case 0:
|
|
129
|
-
vp = 1;
|
|
130
|
-
if (!this.isMeta) return [3 /*break*/, 2];
|
|
131
|
-
basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
|
|
132
|
-
_a = Number;
|
|
133
|
-
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
134
|
-
return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
|
|
135
|
-
case 1:
|
|
136
|
-
vp = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]);
|
|
137
|
-
_e.label = 2;
|
|
138
|
-
case 2:
|
|
139
|
-
prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
|
|
140
|
-
_d = Number;
|
|
141
|
-
return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
142
|
-
case 3:
|
|
143
|
-
coinAmount = _d.apply(void 0, [_e.sent()]);
|
|
144
|
-
totalValue = coinAmount * prices[this._getCoinIdx(coin, false)];
|
|
145
|
-
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
146
|
-
case 4:
|
|
147
|
-
balancedAmounts = _e.sent();
|
|
148
|
-
balancedTotalValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
149
|
-
return [2 /*return*/, String((totalValue - balancedTotalValue) / Math.max(totalValue, balancedTotalValue) * 100)];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
exports.withdrawOneCoinCryptoBonusMixin = {
|
|
157
|
-
withdrawOneCoinBonus: function (lpTokenAmount, coin) {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
159
|
-
var prices, coinPrice, totalAmount, _a, totalAmountUSD, balancedAmounts, balancedTotalAmountsUSD;
|
|
160
|
-
return __generator(this, function (_b) {
|
|
161
|
-
switch (_b.label) {
|
|
162
|
-
case 0: return [4 /*yield*/, this._underlyingPrices()];
|
|
163
|
-
case 1:
|
|
164
|
-
prices = _b.sent();
|
|
165
|
-
coinPrice = prices[this._getCoinIdx(coin)];
|
|
166
|
-
_a = Number;
|
|
167
|
-
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
168
|
-
case 2:
|
|
169
|
-
totalAmount = _a.apply(void 0, [_b.sent()]);
|
|
170
|
-
totalAmountUSD = totalAmount * coinPrice;
|
|
171
|
-
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
172
|
-
case 3:
|
|
173
|
-
balancedAmounts = _b.sent();
|
|
174
|
-
balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
|
|
175
|
-
return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / Math.max(totalAmountUSD, balancedTotalAmountsUSD) * 100)];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
// @ts-ignore
|
|
182
|
-
exports.withdrawOneCoinWrappedCryptoBonusMixin = {
|
|
183
|
-
withdrawOneCoinWrappedBonus: function (lpTokenAmount, coin) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var vp, basePoolAddress, _a, _b, _c, prices, coinPrice, totalAmount, _d, totalAmountUSD, balancedAmounts, balancedTotalAmountsUSD;
|
|
186
|
-
return __generator(this, function (_e) {
|
|
187
|
-
switch (_e.label) {
|
|
188
|
-
case 0:
|
|
189
|
-
vp = 1;
|
|
190
|
-
if (!this.isMeta) return [3 /*break*/, 2];
|
|
191
|
-
basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
|
|
192
|
-
_a = Number;
|
|
193
|
-
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
194
|
-
return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
|
|
195
|
-
case 1:
|
|
196
|
-
vp = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]);
|
|
197
|
-
_e.label = 2;
|
|
198
|
-
case 2: return [4 /*yield*/, this._wrappedPrices()];
|
|
199
|
-
case 3:
|
|
200
|
-
prices = (_e.sent()).map(function (p, i, arr) { return i === arr.length - 1 ? p * vp : p; });
|
|
201
|
-
coinPrice = prices[this._getCoinIdx(coin, false)];
|
|
202
|
-
_d = Number;
|
|
203
|
-
return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
204
|
-
case 4:
|
|
205
|
-
totalAmount = _d.apply(void 0, [_e.sent()]);
|
|
206
|
-
totalAmountUSD = totalAmount * coinPrice;
|
|
207
|
-
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
208
|
-
case 5:
|
|
209
|
-
balancedAmounts = _e.sent();
|
|
210
|
-
balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
|
|
211
|
-
return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / Math.max(totalAmountUSD, balancedTotalAmountsUSD) * 100)];
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
},
|
|
216
|
-
};
|