@curvefi/api 2.21.3 → 2.21.5
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/pools/PoolTemplate.d.ts +3 -2
- package/lib/pools/PoolTemplate.js +180 -32
- 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
|
@@ -105,6 +105,7 @@ export declare class PoolTemplate {
|
|
|
105
105
|
cryptoSeedAmounts(amount1: number | string): Promise<string[]>;
|
|
106
106
|
depositBalancedAmounts(): Promise<string[]>;
|
|
107
107
|
depositExpected(amounts: (number | string)[]): Promise<string>;
|
|
108
|
+
private _balancedAmountsWithSameValue;
|
|
108
109
|
depositBonus(amounts: (number | string)[]): Promise<string>;
|
|
109
110
|
depositIsApproved(amounts: (number | string)[]): Promise<boolean>;
|
|
110
111
|
private depositApproveEstimateGas;
|
|
@@ -156,14 +157,14 @@ export declare class PoolTemplate {
|
|
|
156
157
|
private depositAndStakeApproveEstimateGas;
|
|
157
158
|
depositAndStakeApprove(amounts: (number | string)[]): Promise<string[]>;
|
|
158
159
|
private depositAndStakeEstimateGas;
|
|
159
|
-
depositAndStake(amounts: (number | string)[]): Promise<string>;
|
|
160
|
+
depositAndStake(amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
160
161
|
depositAndStakeWrappedExpected(amounts: (number | string)[]): Promise<string>;
|
|
161
162
|
depositAndStakeWrappedBonus(amounts: (number | string)[]): Promise<string>;
|
|
162
163
|
depositAndStakeWrappedIsApproved(amounts: (number | string)[]): Promise<boolean>;
|
|
163
164
|
private depositAndStakeWrappedApproveEstimateGas;
|
|
164
165
|
depositAndStakeWrappedApprove(amounts: (number | string)[]): Promise<string[]>;
|
|
165
166
|
private depositAndStakeWrappedEstimateGas;
|
|
166
|
-
depositAndStakeWrapped(amounts: (number | string)[]): Promise<string>;
|
|
167
|
+
depositAndStakeWrapped(amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
167
168
|
private _depositAndStake;
|
|
168
169
|
withdrawExpected(lpTokenAmount: number | string): Promise<string[]>;
|
|
169
170
|
withdrawIsApproved(lpTokenAmount: number | string): Promise<boolean>;
|
|
@@ -1046,7 +1046,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1046
1046
|
});
|
|
1047
1047
|
});
|
|
1048
1048
|
};
|
|
1049
|
-
// Used by mixin. Don't delete it!!!
|
|
1050
1049
|
this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1051
1050
|
var promises, _i, _c, addr;
|
|
1052
1051
|
return __generator(this, function (_d) {
|
|
@@ -1062,7 +1061,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1062
1061
|
}
|
|
1063
1062
|
});
|
|
1064
1063
|
}); };
|
|
1065
|
-
// Used by mixin. Don't delete it!!!
|
|
1066
1064
|
// NOTE! It may crash!
|
|
1067
1065
|
this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1068
1066
|
var promises, _i, _c, addr;
|
|
@@ -1282,6 +1280,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1282
1280
|
});
|
|
1283
1281
|
});
|
|
1284
1282
|
};
|
|
1283
|
+
// OVERRIDE
|
|
1285
1284
|
PoolTemplate.prototype.depositBalancedAmounts = function () {
|
|
1286
1285
|
return __awaiter(this, void 0, void 0, function () {
|
|
1287
1286
|
return __generator(this, function (_c) {
|
|
@@ -1299,11 +1298,64 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1299
1298
|
});
|
|
1300
1299
|
});
|
|
1301
1300
|
};
|
|
1302
|
-
//
|
|
1301
|
+
// | balanced[i] / sum(balanced[j]) = balance[i] / sum(balance[j]) |
|
|
1302
|
+
// | sum(pj * balanced[j]) = sum(aj * pj) |
|
|
1303
|
+
//
|
|
1304
|
+
// --- Answer ---
|
|
1305
|
+
// balanced[i] = sum(aj * pj) / sum(rj * pj / ri)
|
|
1306
|
+
//
|
|
1307
|
+
// totalValueBN = sum(aj * pj)
|
|
1308
|
+
// totalBalanceBN = sum(balance[j])
|
|
1309
|
+
// ratiosBN[i] = balancesBN[i] / totalBalanceBN = ri = balance[i] / sum(balance[j])
|
|
1310
|
+
// denominatorBN = sum(rj * pj / ri)
|
|
1311
|
+
PoolTemplate.prototype._balancedAmountsWithSameValue = function (amountsBN, pricesBN, balancesBN) {
|
|
1312
|
+
var valuesBN = amountsBN.map(function (aBN, i) { return aBN.times(pricesBN[i]); });
|
|
1313
|
+
var totalValueBN = valuesBN.reduce(function (v1BN, v2BN) { return v1BN.plus(v2BN); });
|
|
1314
|
+
var totalBalanceBN = balancesBN.reduce(function (b1BN, b2BN) { return b1BN.plus(b2BN); });
|
|
1315
|
+
var ratiosBN = balancesBN.map(function (bBN) { return bBN.div(totalBalanceBN); });
|
|
1316
|
+
var balancedAmountsBN = [];
|
|
1317
|
+
var _loop_1 = function (i) {
|
|
1318
|
+
var denominatorBN = ratiosBN.map(function (rBN, j) { return rBN.times(pricesBN[j])
|
|
1319
|
+
.div(ratiosBN[i]); }).reduce(function (xBN, yBN) { return xBN.plus(yBN); });
|
|
1320
|
+
balancedAmountsBN.push(totalValueBN.div(denominatorBN));
|
|
1321
|
+
};
|
|
1322
|
+
for (var i = 0; i < amountsBN.length; i++) {
|
|
1323
|
+
_loop_1(i);
|
|
1324
|
+
}
|
|
1325
|
+
return balancedAmountsBN.map(String);
|
|
1326
|
+
};
|
|
1303
1327
|
PoolTemplate.prototype.depositBonus = function (amounts) {
|
|
1304
1328
|
return __awaiter(this, void 0, void 0, function () {
|
|
1305
|
-
|
|
1306
|
-
|
|
1329
|
+
var amountsBN, prices, _c, pricesBN, balancesBN, balancedAmounts, expectedBN, _d, balancedExpectedBN, _e;
|
|
1330
|
+
return __generator(this, function (_f) {
|
|
1331
|
+
switch (_f.label) {
|
|
1332
|
+
case 0:
|
|
1333
|
+
amountsBN = amounts.map(utils_1.BN);
|
|
1334
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
1335
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
1336
|
+
case 1:
|
|
1337
|
+
_c = _f.sent();
|
|
1338
|
+
return [3 /*break*/, 3];
|
|
1339
|
+
case 2:
|
|
1340
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
1341
|
+
_f.label = 3;
|
|
1342
|
+
case 3:
|
|
1343
|
+
prices = _c;
|
|
1344
|
+
pricesBN = prices.map(utils_1.BN);
|
|
1345
|
+
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
1346
|
+
case 4:
|
|
1347
|
+
balancesBN = (_f.sent()).map(utils_1.BN);
|
|
1348
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1349
|
+
_d = utils_1.BN;
|
|
1350
|
+
return [4 /*yield*/, this.depositExpected(amounts)];
|
|
1351
|
+
case 5:
|
|
1352
|
+
expectedBN = _d.apply(void 0, [_f.sent()]);
|
|
1353
|
+
_e = utils_1.BN;
|
|
1354
|
+
return [4 /*yield*/, this.depositExpected(balancedAmounts)];
|
|
1355
|
+
case 6:
|
|
1356
|
+
balancedExpectedBN = _e.apply(void 0, [_f.sent()]);
|
|
1357
|
+
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1358
|
+
}
|
|
1307
1359
|
});
|
|
1308
1360
|
});
|
|
1309
1361
|
};
|
|
@@ -1376,11 +1428,30 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1376
1428
|
});
|
|
1377
1429
|
});
|
|
1378
1430
|
};
|
|
1379
|
-
// OVERRIDE
|
|
1380
1431
|
PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
|
|
1381
1432
|
return __awaiter(this, void 0, void 0, function () {
|
|
1382
|
-
|
|
1383
|
-
|
|
1433
|
+
var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
|
|
1434
|
+
return __generator(this, function (_e) {
|
|
1435
|
+
switch (_e.label) {
|
|
1436
|
+
case 0:
|
|
1437
|
+
amountsBN = amounts.map(utils_1.BN);
|
|
1438
|
+
return [4 /*yield*/, this._wrappedPrices()];
|
|
1439
|
+
case 1:
|
|
1440
|
+
pricesBN = (_e.sent()).map(utils_1.BN);
|
|
1441
|
+
return [4 /*yield*/, this.stats.wrappedBalances()];
|
|
1442
|
+
case 2:
|
|
1443
|
+
balancesBN = (_e.sent()).map(utils_1.BN);
|
|
1444
|
+
balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
|
|
1445
|
+
_c = utils_1.BN;
|
|
1446
|
+
return [4 /*yield*/, this.depositWrappedExpected(amounts)];
|
|
1447
|
+
case 3:
|
|
1448
|
+
expectedBN = _c.apply(void 0, [_e.sent()]);
|
|
1449
|
+
_d = utils_1.BN;
|
|
1450
|
+
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
1451
|
+
case 4:
|
|
1452
|
+
balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
|
|
1453
|
+
return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
|
|
1454
|
+
}
|
|
1384
1455
|
});
|
|
1385
1456
|
});
|
|
1386
1457
|
};
|
|
@@ -1823,13 +1894,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1823
1894
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1824
1895
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1825
1896
|
}
|
|
1826
|
-
return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
|
|
1897
|
+
return [4 /*yield*/, this._depositAndStake(amounts, 1, true, true)];
|
|
1827
1898
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1828
1899
|
}
|
|
1829
1900
|
});
|
|
1830
1901
|
});
|
|
1831
1902
|
};
|
|
1832
|
-
PoolTemplate.prototype.depositAndStake = function (amounts) {
|
|
1903
|
+
PoolTemplate.prototype.depositAndStake = function (amounts, slippage) {
|
|
1904
|
+
if (slippage === void 0) { slippage = 0.1; }
|
|
1833
1905
|
return __awaiter(this, void 0, void 0, function () {
|
|
1834
1906
|
return __generator(this, function (_c) {
|
|
1835
1907
|
switch (_c.label) {
|
|
@@ -1837,7 +1909,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1837
1909
|
if (this.gauge === ethers_1.ethers.constants.AddressZero) {
|
|
1838
1910
|
throw Error("depositAndStake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1839
1911
|
}
|
|
1840
|
-
return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
|
|
1912
|
+
return [4 /*yield*/, this._depositAndStake(amounts, slippage, true, false)];
|
|
1841
1913
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1842
1914
|
}
|
|
1843
1915
|
});
|
|
@@ -1972,13 +2044,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1972
2044
|
}
|
|
1973
2045
|
if (this.isPlain || this.isFake)
|
|
1974
2046
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1975
|
-
return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
|
|
2047
|
+
return [4 /*yield*/, this._depositAndStake(amounts, 1, false, true)];
|
|
1976
2048
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1977
2049
|
}
|
|
1978
2050
|
});
|
|
1979
2051
|
});
|
|
1980
2052
|
};
|
|
1981
|
-
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts) {
|
|
2053
|
+
PoolTemplate.prototype.depositAndStakeWrapped = function (amounts, slippage) {
|
|
2054
|
+
if (slippage === void 0) { slippage = 0.1; }
|
|
1982
2055
|
return __awaiter(this, void 0, void 0, function () {
|
|
1983
2056
|
return __generator(this, function (_c) {
|
|
1984
2057
|
switch (_c.label) {
|
|
@@ -1988,15 +2061,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1988
2061
|
}
|
|
1989
2062
|
if (this.isPlain || this.isFake)
|
|
1990
2063
|
throw Error("depositAndStakeWrapped method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
1991
|
-
return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
|
|
2064
|
+
return [4 /*yield*/, this._depositAndStake(amounts, slippage, false, false)];
|
|
1992
2065
|
case 1: return [2 /*return*/, _c.sent()];
|
|
1993
2066
|
}
|
|
1994
2067
|
});
|
|
1995
2068
|
});
|
|
1996
2069
|
};
|
|
1997
|
-
PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
|
|
2070
|
+
PoolTemplate.prototype._depositAndStake = function (amounts, slippage, isUnderlying, estimateGas) {
|
|
1998
2071
|
return __awaiter(this, void 0, void 0, function () {
|
|
1999
|
-
var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying,
|
|
2072
|
+
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, i, _gas, gasLimit;
|
|
2000
2073
|
return __generator(this, function (_q) {
|
|
2001
2074
|
switch (_q.label) {
|
|
2002
2075
|
case 0:
|
|
@@ -2058,16 +2131,18 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2058
2131
|
_l = (_k = ethers_1.ethers.utils).parseUnits;
|
|
2059
2132
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
2060
2133
|
case 13:
|
|
2061
|
-
_j = _l.apply(_k, [_q.sent()])
|
|
2134
|
+
_j = _l.apply(_k, [_q.sent()]);
|
|
2062
2135
|
return [3 /*break*/, 16];
|
|
2063
2136
|
case 14:
|
|
2064
2137
|
_o = (_m = ethers_1.ethers.utils).parseUnits;
|
|
2065
2138
|
return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
|
|
2066
2139
|
case 15:
|
|
2067
|
-
_j = _o.apply(_m, [_q.sent()])
|
|
2140
|
+
_j = _o.apply(_m, [_q.sent()]);
|
|
2068
2141
|
_q.label = 16;
|
|
2069
2142
|
case 16:
|
|
2070
|
-
|
|
2143
|
+
_expectedLpTokenAmount = _j;
|
|
2144
|
+
minAmountBN = (0, utils_1.toBN)(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
2145
|
+
_minMintAmount = (0, utils_1.fromBN)(minAmountBN);
|
|
2071
2146
|
ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
|
|
2072
2147
|
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
2073
2148
|
for (i = 0; i < 5; i++) {
|
|
@@ -2194,11 +2269,32 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2194
2269
|
});
|
|
2195
2270
|
});
|
|
2196
2271
|
};
|
|
2197
|
-
// OVERRIDE
|
|
2198
2272
|
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
2199
2273
|
return __awaiter(this, void 0, void 0, function () {
|
|
2200
|
-
|
|
2201
|
-
|
|
2274
|
+
var prices, _c, value, lpTokenAmount, balancedAmounts, balancedValue;
|
|
2275
|
+
return __generator(this, function (_d) {
|
|
2276
|
+
switch (_d.label) {
|
|
2277
|
+
case 0:
|
|
2278
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
2279
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2280
|
+
case 1:
|
|
2281
|
+
_c = _d.sent();
|
|
2282
|
+
return [3 /*break*/, 3];
|
|
2283
|
+
case 2:
|
|
2284
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
2285
|
+
_d.label = 3;
|
|
2286
|
+
case 3:
|
|
2287
|
+
prices = _c;
|
|
2288
|
+
value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2289
|
+
return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
|
|
2290
|
+
case 4:
|
|
2291
|
+
lpTokenAmount = _d.sent();
|
|
2292
|
+
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2293
|
+
case 5:
|
|
2294
|
+
balancedAmounts = _d.sent();
|
|
2295
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2296
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2297
|
+
}
|
|
2202
2298
|
});
|
|
2203
2299
|
});
|
|
2204
2300
|
};
|
|
@@ -2288,7 +2384,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2288
2384
|
return __generator(this, function (_c) {
|
|
2289
2385
|
switch (_c.label) {
|
|
2290
2386
|
case 0:
|
|
2291
|
-
if (this.isCrypto)
|
|
2387
|
+
if (this.isCrypto || this.isPlain || this.isFake)
|
|
2292
2388
|
throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2293
2389
|
return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
|
|
2294
2390
|
case 1: return [2 /*return*/, _c.sent()];
|
|
@@ -2296,11 +2392,25 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2296
2392
|
});
|
|
2297
2393
|
});
|
|
2298
2394
|
};
|
|
2299
|
-
// OVERRIDE
|
|
2300
2395
|
PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
|
|
2301
2396
|
return __awaiter(this, void 0, void 0, function () {
|
|
2302
|
-
|
|
2303
|
-
|
|
2397
|
+
var prices, value, lpTokenAmount, _c, balancedAmounts, balancedValue;
|
|
2398
|
+
return __generator(this, function (_d) {
|
|
2399
|
+
switch (_d.label) {
|
|
2400
|
+
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
2401
|
+
case 1:
|
|
2402
|
+
prices = _d.sent();
|
|
2403
|
+
value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2404
|
+
_c = Number;
|
|
2405
|
+
return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
|
|
2406
|
+
case 2:
|
|
2407
|
+
lpTokenAmount = _c.apply(void 0, [_d.sent()]);
|
|
2408
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
2409
|
+
case 3:
|
|
2410
|
+
balancedAmounts = _d.sent();
|
|
2411
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2412
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2413
|
+
}
|
|
2304
2414
|
});
|
|
2305
2415
|
});
|
|
2306
2416
|
};
|
|
@@ -2346,11 +2456,34 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2346
2456
|
});
|
|
2347
2457
|
});
|
|
2348
2458
|
};
|
|
2349
|
-
// OVERRIDE
|
|
2350
2459
|
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2351
2460
|
return __awaiter(this, void 0, void 0, function () {
|
|
2352
|
-
|
|
2353
|
-
|
|
2461
|
+
var prices, _c, coinPrice, amount, _d, value, balancedAmounts, balancedValue;
|
|
2462
|
+
return __generator(this, function (_e) {
|
|
2463
|
+
switch (_e.label) {
|
|
2464
|
+
case 0:
|
|
2465
|
+
if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
|
|
2466
|
+
return [4 /*yield*/, this._underlyingPrices()];
|
|
2467
|
+
case 1:
|
|
2468
|
+
_c = _e.sent();
|
|
2469
|
+
return [3 /*break*/, 3];
|
|
2470
|
+
case 2:
|
|
2471
|
+
_c = this.underlyingCoins.map(function () { return 1; });
|
|
2472
|
+
_e.label = 3;
|
|
2473
|
+
case 3:
|
|
2474
|
+
prices = _c;
|
|
2475
|
+
coinPrice = prices[this._getCoinIdx(coin)];
|
|
2476
|
+
_d = Number;
|
|
2477
|
+
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
2478
|
+
case 4:
|
|
2479
|
+
amount = _d.apply(void 0, [_e.sent()]);
|
|
2480
|
+
value = amount * coinPrice;
|
|
2481
|
+
return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
|
|
2482
|
+
case 5:
|
|
2483
|
+
balancedAmounts = _e.sent();
|
|
2484
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2485
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2486
|
+
}
|
|
2354
2487
|
});
|
|
2355
2488
|
});
|
|
2356
2489
|
};
|
|
@@ -2435,11 +2568,26 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2435
2568
|
});
|
|
2436
2569
|
});
|
|
2437
2570
|
};
|
|
2438
|
-
// OVERRIDE
|
|
2439
2571
|
PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
|
|
2440
2572
|
return __awaiter(this, void 0, void 0, function () {
|
|
2441
|
-
|
|
2442
|
-
|
|
2573
|
+
var prices, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
|
|
2574
|
+
return __generator(this, function (_d) {
|
|
2575
|
+
switch (_d.label) {
|
|
2576
|
+
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
2577
|
+
case 1:
|
|
2578
|
+
prices = _d.sent();
|
|
2579
|
+
coinPrice = prices[this._getCoinIdx(coin, false)];
|
|
2580
|
+
_c = Number;
|
|
2581
|
+
return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
2582
|
+
case 2:
|
|
2583
|
+
amount = _c.apply(void 0, [_d.sent()]);
|
|
2584
|
+
value = amount * coinPrice;
|
|
2585
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
|
|
2586
|
+
case 3:
|
|
2587
|
+
balancedAmounts = _d.sent();
|
|
2588
|
+
balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
|
|
2589
|
+
return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
|
|
2590
|
+
}
|
|
2443
2591
|
});
|
|
2444
2592
|
});
|
|
2445
2593
|
};
|
|
@@ -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
|
-
};
|