@curvefi/api 2.4.0 → 2.4.3
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/aliases.js +1 -1
- package/lib/constants/pools/ethereum.js +1 -0
- package/lib/curve.js +1 -1
- package/lib/factory/constants.d.ts +8 -2
- package/lib/factory/constants.js +14 -3
- package/lib/factory/factory-api.js +4 -3
- package/lib/factory/factory-crypto.js +12 -10
- package/lib/pools/PoolTemplate.d.ts +0 -2
- package/lib/pools/PoolTemplate.js +15 -142
- package/lib/pools/mixins/depositBonusMixins.js +52 -26
- package/lib/pools/mixins/withdrawBonusMixins.d.ts +7 -0
- package/lib/pools/mixins/withdrawBonusMixins.js +216 -0
- package/lib/pools/poolConstructor.js +41 -18
- package/package.json +1 -1
package/lib/constants/aliases.js
CHANGED
|
@@ -23,7 +23,7 @@ exports.ALIASES_POLYGON = (0, utils_1.lowerCaseValues)({
|
|
|
23
23
|
"router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
|
|
24
24
|
"deposit_and_stake": "0x43FF7b96808988C9d19C1d05Ef19658B03e8a143",
|
|
25
25
|
"factory": '0x722272d36ef0da72ff51c5a65db7b870e2e8d4ee',
|
|
26
|
-
"crypto_factory":
|
|
26
|
+
"crypto_factory": "0xE5De15A9C9bBedb4F5EC13B131E61245f2983A69",
|
|
27
27
|
"registry_exchange": "",
|
|
28
28
|
});
|
|
29
29
|
exports.ALIASES_AVALANCHE = (0, utils_1.lowerCaseValues)({
|
|
@@ -1272,6 +1272,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
1272
1272
|
token_address: '0x3D229E1B4faab62F621eF2F6A610961f7BD7b23B',
|
|
1273
1273
|
gauge_address: '0x65CA7Dc5CB661fC58De57B1E1aF404649a27AD35',
|
|
1274
1274
|
is_crypto: true,
|
|
1275
|
+
is_plain: true,
|
|
1275
1276
|
underlying_coins: ['USDC', 'EURS'],
|
|
1276
1277
|
wrapped_coins: ['USDC', 'EURS'],
|
|
1277
1278
|
underlying_coin_addresses: [
|
package/lib/curve.js
CHANGED
|
@@ -451,7 +451,7 @@ var Curve = /** @class */ (function () {
|
|
|
451
451
|
return __generator(this, function (_e) {
|
|
452
452
|
switch (_e.label) {
|
|
453
453
|
case 0:
|
|
454
|
-
if (this.chainId !== 1 && this.chainId !==
|
|
454
|
+
if (this.chainId !== 1 && this.chainId !== 137)
|
|
455
455
|
return [2 /*return*/];
|
|
456
456
|
if (!useApi) return [3 /*break*/, 2];
|
|
457
457
|
_a = this.constants;
|
|
@@ -8,8 +8,14 @@ export declare const implementationBasePoolIdDictAvalanche: IDict<string>;
|
|
|
8
8
|
export declare const basePoolIdZapDictEthereum: IDict<string>;
|
|
9
9
|
export declare const basePoolIdZapDictPolygon: IDict<string>;
|
|
10
10
|
export declare const basePoolIdZapDictAvalanche: IDict<string>;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const NATIVE_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
12
|
+
export declare const NATIVE_TOKENS: {
|
|
13
|
+
[index: number]: {
|
|
14
|
+
symbol: string;
|
|
15
|
+
wrappedSymbol: string;
|
|
16
|
+
wrappedAddress: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
13
19
|
export declare const FACTORY_CONSTANTS: {
|
|
14
20
|
[index: number]: {
|
|
15
21
|
implementationABIDict: IDict<any>;
|
package/lib/factory/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FACTORY_CONSTANTS = exports.
|
|
6
|
+
exports.FACTORY_CONSTANTS = exports.NATIVE_TOKENS = exports.NATIVE_TOKEN_ADDRESS = exports.basePoolIdZapDictAvalanche = exports.basePoolIdZapDictPolygon = exports.basePoolIdZapDictEthereum = exports.implementationBasePoolIdDictAvalanche = exports.implementationBasePoolIdDictPolygon = exports.implementationBasePoolIdDictEthereum = exports.implementationABIDictAvalanche = exports.implementationABIDictPolygon = exports.implementationABIDictEthereum = void 0;
|
|
7
7
|
var swap_json_1 = __importDefault(require("../constants/abis/factoryPools/swap.json"));
|
|
8
8
|
var MetaUSD_json_1 = __importDefault(require("../constants/abis/factory-v2/MetaUSD.json"));
|
|
9
9
|
var MetaUSDBalances_json_1 = __importDefault(require("../constants/abis/factory-v2/MetaUSDBalances.json"));
|
|
@@ -121,8 +121,19 @@ exports.basePoolIdZapDictAvalanche = {
|
|
|
121
121
|
aave: "0x001E3BA199B4FF4B5B6e97aCD96daFC0E2e4156e".toLowerCase(),
|
|
122
122
|
ren: "0xEeB3DDBcc4174e0b3fd1C13aD462b95D11Ef42C3".toLowerCase(),
|
|
123
123
|
};
|
|
124
|
-
exports.
|
|
125
|
-
exports.
|
|
124
|
+
exports.NATIVE_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
125
|
+
exports.NATIVE_TOKENS = {
|
|
126
|
+
1: {
|
|
127
|
+
symbol: 'ETH',
|
|
128
|
+
wrappedSymbol: 'WETH',
|
|
129
|
+
wrappedAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
130
|
+
},
|
|
131
|
+
137: {
|
|
132
|
+
symbol: 'MATIC',
|
|
133
|
+
wrappedSymbol: 'WMATIC',
|
|
134
|
+
wrappedAddress: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
|
|
135
|
+
},
|
|
136
|
+
};
|
|
126
137
|
exports.FACTORY_CONSTANTS = {
|
|
127
138
|
1: {
|
|
128
139
|
implementationABIDict: exports.implementationABIDictEthereum,
|
|
@@ -162,10 +162,11 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
162
162
|
var coinAddresses = pool.coins.map(function (c) { return c.address.toLowerCase(); });
|
|
163
163
|
var coinNames = pool.coins.map(function (c) { return c.symbol; });
|
|
164
164
|
var coinDecimals = pool.coins.map(function (c) { return Number(c.decimals); });
|
|
165
|
+
var nativeToken = constants_1.NATIVE_TOKENS[_this.chainId];
|
|
165
166
|
if (isCrypto) {
|
|
166
|
-
var cryptoCoinNames = pool.coins.map(function (c) { return c.symbol ===
|
|
167
|
-
var underlyingCoinNames = pool.coins.map(function (c) { return c.symbol ===
|
|
168
|
-
var underlyingCoinAddresses =
|
|
167
|
+
var cryptoCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.symbol ? nativeToken.wrappedSymbol : c.symbol; });
|
|
168
|
+
var underlyingCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.wrappedSymbol ? nativeToken.symbol : c.symbol; });
|
|
169
|
+
var underlyingCoinAddresses = coinAddresses.map(function (addr) { return addr === nativeToken.wrappedAddress ? constants_1.NATIVE_TOKEN_ADDRESS : addr; });
|
|
169
170
|
FACTORY_POOLS_DATA[pool.id] = {
|
|
170
171
|
name: pool.name.split(": ")[1].trim(),
|
|
171
172
|
full_name: pool.name,
|
|
@@ -197,8 +197,9 @@ function setCryptoFactoryCoinsContracts(coinAddresses) {
|
|
|
197
197
|
}
|
|
198
198
|
function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
|
|
199
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
+
var _this = this;
|
|
200
201
|
return __generator(this, function (_a) {
|
|
201
|
-
return [2 /*return*/, coinAddresses.map(function (coins) { return coins.map(function (c) { return c === constants_1.
|
|
202
|
+
return [2 /*return*/, coinAddresses.map(function (coins) { return coins.map(function (c) { return c === constants_1.NATIVE_TOKENS[_this.chainId].wrappedAddress ? constants_1.NATIVE_TOKEN_ADDRESS : c; }); })];
|
|
202
203
|
});
|
|
203
204
|
});
|
|
204
205
|
}
|
|
@@ -221,11 +222,11 @@ function getExistingCoinAddressNameDict() {
|
|
|
221
222
|
_loop_1(poolData);
|
|
222
223
|
}
|
|
223
224
|
if (this.chainId === 1)
|
|
224
|
-
dict[
|
|
225
|
+
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "ETH";
|
|
225
226
|
if (this.chainId === 137)
|
|
226
|
-
dict[
|
|
227
|
+
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "MATIC";
|
|
227
228
|
if (this.chainId === 43114)
|
|
228
|
-
dict[
|
|
229
|
+
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "AVAX";
|
|
229
230
|
return dict;
|
|
230
231
|
}
|
|
231
232
|
function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
|
|
@@ -259,6 +260,7 @@ function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
|
|
|
259
260
|
newCoinAddresses.forEach(function (addr, i) {
|
|
260
261
|
coinAddrNamesDict[addr] = names[i];
|
|
261
262
|
});
|
|
263
|
+
coinAddrNamesDict[constants_1.NATIVE_TOKEN_ADDRESS] = constants_1.NATIVE_TOKENS[this.chainId].symbol;
|
|
262
264
|
return [2 /*return*/, coinAddrNamesDict];
|
|
263
265
|
}
|
|
264
266
|
});
|
|
@@ -266,18 +268,18 @@ function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
|
|
|
266
268
|
}
|
|
267
269
|
function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDict) {
|
|
268
270
|
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
-
var flattenedCoinAddresses, newCoinAddresses,
|
|
271
|
+
var flattenedCoinAddresses, newCoinAddresses, coinAddressDecimalsDict, _i, flattenedCoinAddresses_3, addr, calls, decimals;
|
|
270
272
|
var _this = this;
|
|
271
273
|
return __generator(this, function (_a) {
|
|
272
274
|
switch (_a.label) {
|
|
273
275
|
case 0:
|
|
274
276
|
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
275
277
|
newCoinAddresses = [];
|
|
276
|
-
|
|
278
|
+
coinAddressDecimalsDict = {};
|
|
277
279
|
for (_i = 0, flattenedCoinAddresses_3 = flattenedCoinAddresses; _i < flattenedCoinAddresses_3.length; _i++) {
|
|
278
280
|
addr = flattenedCoinAddresses_3[_i];
|
|
279
281
|
if (addr in existingCoinAddressDecimalsDict) {
|
|
280
|
-
|
|
282
|
+
coinAddressDecimalsDict[addr] = existingCoinAddressDecimalsDict[addr];
|
|
281
283
|
}
|
|
282
284
|
else {
|
|
283
285
|
newCoinAddresses.push(addr);
|
|
@@ -290,10 +292,10 @@ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDi
|
|
|
290
292
|
case 1:
|
|
291
293
|
decimals = (_a.sent()).map(function (_d) { return Number(ethers_1.ethers.utils.formatUnits(_d, 0)); });
|
|
292
294
|
newCoinAddresses.forEach(function (addr, i) {
|
|
293
|
-
|
|
295
|
+
coinAddressDecimalsDict[addr] = decimals[i];
|
|
294
296
|
});
|
|
295
|
-
|
|
296
|
-
return [2 /*return*/,
|
|
297
|
+
coinAddressDecimalsDict[constants_1.NATIVE_TOKEN_ADDRESS] = 18;
|
|
298
|
+
return [2 /*return*/, coinAddressDecimalsDict];
|
|
297
299
|
}
|
|
298
300
|
});
|
|
299
301
|
});
|
|
@@ -842,6 +842,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
842
842
|
});
|
|
843
843
|
});
|
|
844
844
|
};
|
|
845
|
+
// Used by mixin. Don't delete it!!!
|
|
845
846
|
this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
846
847
|
var promises, _i, _a, addr;
|
|
847
848
|
return __generator(this, function (_c) {
|
|
@@ -857,6 +858,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
857
858
|
}
|
|
858
859
|
});
|
|
859
860
|
}); };
|
|
861
|
+
// Used by mixin. Don't delete it!!!
|
|
860
862
|
// NOTE! It may crash!
|
|
861
863
|
this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
862
864
|
var promises, _i, _a, addr;
|
|
@@ -873,82 +875,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
873
875
|
}
|
|
874
876
|
});
|
|
875
877
|
}); };
|
|
876
|
-
this._withdrawCryptoBonus = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
|
|
877
|
-
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
878
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
879
|
-
var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
|
|
880
|
-
return __generator(this, function (_d) {
|
|
881
|
-
switch (_d.label) {
|
|
882
|
-
case 0:
|
|
883
|
-
if (!useUnderlying) return [3 /*break*/, 2];
|
|
884
|
-
return [4 /*yield*/, this._underlyingPrices()];
|
|
885
|
-
case 1:
|
|
886
|
-
_a = _d.sent();
|
|
887
|
-
return [3 /*break*/, 4];
|
|
888
|
-
case 2: return [4 /*yield*/, this._wrappedPrices()];
|
|
889
|
-
case 3:
|
|
890
|
-
_a = _d.sent();
|
|
891
|
-
_d.label = 4;
|
|
892
|
-
case 4:
|
|
893
|
-
prices = _a;
|
|
894
|
-
if (!useUnderlying) return [3 /*break*/, 6];
|
|
895
|
-
return [4 /*yield*/, this.withdrawExpected(String(lpTokenAmount))];
|
|
896
|
-
case 5:
|
|
897
|
-
_c = _d.sent();
|
|
898
|
-
return [3 /*break*/, 8];
|
|
899
|
-
case 6: return [4 /*yield*/, this.withdrawWrappedExpected(String(lpTokenAmount))];
|
|
900
|
-
case 7:
|
|
901
|
-
_c = _d.sent();
|
|
902
|
-
_d.label = 8;
|
|
903
|
-
case 8:
|
|
904
|
-
balancedAmounts = _c;
|
|
905
|
-
balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
|
|
906
|
-
return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / totalAmountUSD * 100)];
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
};
|
|
911
|
-
// TODO make the same as _withdrawCryptoBonus
|
|
912
|
-
this._withdrawBonus = function (totalAmount, expected, useUnderlying) {
|
|
913
|
-
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
914
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
915
|
-
var poolBalances, _a, poolTotalBalance, poolBalancesRatios, balancedAmounts, balancedExpected, _c, _d, _e;
|
|
916
|
-
return __generator(this, function (_f) {
|
|
917
|
-
switch (_f.label) {
|
|
918
|
-
case 0:
|
|
919
|
-
if (!useUnderlying) return [3 /*break*/, 2];
|
|
920
|
-
return [4 /*yield*/, this.stats.underlyingBalances()];
|
|
921
|
-
case 1:
|
|
922
|
-
_a = (_f.sent()).map(Number);
|
|
923
|
-
return [3 /*break*/, 4];
|
|
924
|
-
case 2: return [4 /*yield*/, this.stats.wrappedBalances()];
|
|
925
|
-
case 3:
|
|
926
|
-
_a = (_f.sent()).map(Number);
|
|
927
|
-
_f.label = 4;
|
|
928
|
-
case 4:
|
|
929
|
-
poolBalances = _a;
|
|
930
|
-
poolTotalBalance = poolBalances.reduce(function (a, b) { return a + b; });
|
|
931
|
-
poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalBalance; });
|
|
932
|
-
balancedAmounts = poolBalancesRatios.map(function (r) { return String(r * totalAmount); });
|
|
933
|
-
if (!useUnderlying) return [3 /*break*/, 6];
|
|
934
|
-
_d = Number;
|
|
935
|
-
return [4 /*yield*/, this.withdrawImbalanceExpected(balancedAmounts)];
|
|
936
|
-
case 5:
|
|
937
|
-
_c = _d.apply(void 0, [_f.sent()]);
|
|
938
|
-
return [3 /*break*/, 8];
|
|
939
|
-
case 6:
|
|
940
|
-
_e = Number;
|
|
941
|
-
return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(balancedAmounts)];
|
|
942
|
-
case 7:
|
|
943
|
-
_c = _e.apply(void 0, [_f.sent()]);
|
|
944
|
-
_f.label = 8;
|
|
945
|
-
case 8:
|
|
946
|
-
balancedExpected = _c;
|
|
947
|
-
return [2 /*return*/, String((balancedExpected - expected) / balancedExpected * 100)];
|
|
948
|
-
}
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
};
|
|
952
878
|
var poolData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA)[id];
|
|
953
879
|
this.id = id;
|
|
954
880
|
this.name = poolData.name;
|
|
@@ -1900,7 +1826,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1900
1826
|
case 12:
|
|
1901
1827
|
_amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
|
|
1902
1828
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
|
|
1903
|
-
useUnderlying = isUnderlying && (this.isLending || this.isCrypto) && !this.zap;
|
|
1829
|
+
useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && !this.zap;
|
|
1904
1830
|
if (!isUnderlying) return [3 /*break*/, 14];
|
|
1905
1831
|
_k = (_j = ethers_1.ethers.utils).parseUnits;
|
|
1906
1832
|
return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
|
|
@@ -2041,22 +1967,11 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2041
1967
|
});
|
|
2042
1968
|
});
|
|
2043
1969
|
};
|
|
1970
|
+
// OVERRIDE
|
|
2044
1971
|
PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
|
|
2045
1972
|
return __awaiter(this, void 0, void 0, function () {
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
switch (_c.label) {
|
|
2049
|
-
case 0:
|
|
2050
|
-
if (this.isCrypto)
|
|
2051
|
-
throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2052
|
-
totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
|
|
2053
|
-
_a = Number;
|
|
2054
|
-
return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
|
|
2055
|
-
case 1:
|
|
2056
|
-
expected = _a.apply(void 0, [_c.sent()]);
|
|
2057
|
-
return [4 /*yield*/, this._withdrawBonus(totalAmount, expected)];
|
|
2058
|
-
case 2: return [2 /*return*/, _c.sent()];
|
|
2059
|
-
}
|
|
1973
|
+
return __generator(this, function (_a) {
|
|
1974
|
+
throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2060
1975
|
});
|
|
2061
1976
|
});
|
|
2062
1977
|
};
|
|
@@ -2154,22 +2069,11 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2154
2069
|
});
|
|
2155
2070
|
});
|
|
2156
2071
|
};
|
|
2072
|
+
// OVERRIDE
|
|
2157
2073
|
PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
|
|
2158
2074
|
return __awaiter(this, void 0, void 0, function () {
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
switch (_c.label) {
|
|
2162
|
-
case 0:
|
|
2163
|
-
if (this.isCrypto)
|
|
2164
|
-
throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2165
|
-
totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
|
|
2166
|
-
_a = Number;
|
|
2167
|
-
return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
|
|
2168
|
-
case 1:
|
|
2169
|
-
expected = _a.apply(void 0, [_c.sent()]);
|
|
2170
|
-
return [4 /*yield*/, this._withdrawBonus(totalAmount, expected, false)];
|
|
2171
|
-
case 2: return [2 /*return*/, _c.sent()];
|
|
2172
|
-
}
|
|
2075
|
+
return __generator(this, function (_a) {
|
|
2076
|
+
throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2173
2077
|
});
|
|
2174
2078
|
});
|
|
2175
2079
|
};
|
|
@@ -2215,25 +2119,11 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2215
2119
|
});
|
|
2216
2120
|
});
|
|
2217
2121
|
};
|
|
2122
|
+
// OVERRIDE
|
|
2218
2123
|
PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
|
|
2219
2124
|
return __awaiter(this, void 0, void 0, function () {
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
switch (_c.label) {
|
|
2223
|
-
case 0:
|
|
2224
|
-
_a = Number;
|
|
2225
|
-
return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
|
|
2226
|
-
case 1:
|
|
2227
|
-
totalAmount = _a.apply(void 0, [_c.sent()]);
|
|
2228
|
-
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
2229
|
-
return [4 /*yield*/, this._underlyingPrices()];
|
|
2230
|
-
case 2:
|
|
2231
|
-
coinPrice = (_c.sent())[this._getCoinIdx(coin)];
|
|
2232
|
-
return [4 /*yield*/, this._withdrawCryptoBonus(totalAmount * coinPrice, Number(lpTokenAmount))];
|
|
2233
|
-
case 3: return [2 /*return*/, _c.sent()];
|
|
2234
|
-
case 4: return [4 /*yield*/, this._withdrawBonus(totalAmount, Number(lpTokenAmount))];
|
|
2235
|
-
case 5: return [2 /*return*/, _c.sent()];
|
|
2236
|
-
}
|
|
2125
|
+
return __generator(this, function (_a) {
|
|
2126
|
+
throw Error("withdrawOneCoinBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2237
2127
|
});
|
|
2238
2128
|
});
|
|
2239
2129
|
};
|
|
@@ -2318,28 +2208,11 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2318
2208
|
});
|
|
2319
2209
|
});
|
|
2320
2210
|
};
|
|
2211
|
+
// OVERRIDE
|
|
2321
2212
|
PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
|
|
2322
2213
|
return __awaiter(this, void 0, void 0, function () {
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
switch (_c.label) {
|
|
2326
|
-
case 0:
|
|
2327
|
-
if (this.isFake) {
|
|
2328
|
-
throw Error("".concat(this.name, " pool doesn't have this method"));
|
|
2329
|
-
}
|
|
2330
|
-
_a = Number;
|
|
2331
|
-
return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
|
|
2332
|
-
case 1:
|
|
2333
|
-
totalAmount = _a.apply(void 0, [_c.sent()]);
|
|
2334
|
-
if (!this.isCrypto) return [3 /*break*/, 4];
|
|
2335
|
-
return [4 /*yield*/, this._underlyingPrices()];
|
|
2336
|
-
case 2:
|
|
2337
|
-
coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
|
|
2338
|
-
return [4 /*yield*/, this._withdrawCryptoBonus(totalAmount * coinPrice, Number(lpTokenAmount))];
|
|
2339
|
-
case 3: return [2 /*return*/, _c.sent()];
|
|
2340
|
-
case 4: return [4 /*yield*/, this._withdrawBonus(totalAmount, Number(lpTokenAmount), false)];
|
|
2341
|
-
case 5: return [2 /*return*/, _c.sent()];
|
|
2342
|
-
}
|
|
2214
|
+
return __generator(this, function (_a) {
|
|
2215
|
+
throw Error("withdrawOneCoinWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
|
|
2343
2216
|
});
|
|
2344
2217
|
});
|
|
2345
2218
|
};
|
|
@@ -37,6 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.depositWrappedBonusCryptoMixin = exports.depositBonusCryptoMixin = exports.depositWrappedBonusMixin = exports.depositBonusMixin = void 0;
|
|
40
|
+
var ethers_1 = require("ethers");
|
|
41
|
+
var curve_1 = require("../../curve");
|
|
40
42
|
var utils_1 = require("../../utils");
|
|
41
43
|
// @ts-ignore
|
|
42
44
|
exports.depositBonusMixin = {
|
|
@@ -71,25 +73,38 @@ exports.depositBonusMixin = {
|
|
|
71
73
|
exports.depositWrappedBonusMixin = {
|
|
72
74
|
depositWrappedBonus: function (amounts) {
|
|
73
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
-
var
|
|
75
|
-
return __generator(this, function (
|
|
76
|
-
switch (
|
|
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) {
|
|
77
79
|
case 0:
|
|
78
|
-
|
|
80
|
+
vp = 1;
|
|
81
|
+
if (!this.isMeta) return [3 /*break*/, 2];
|
|
82
|
+
basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
|
|
79
83
|
_a = Number;
|
|
80
|
-
|
|
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)];
|
|
81
86
|
case 1:
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
|
|
88
|
+
_f.label = 2;
|
|
84
89
|
case 2:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
_b = Number;
|
|
90
|
-
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
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)];
|
|
91
94
|
case 3:
|
|
92
|
-
|
|
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()]);
|
|
93
108
|
return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
|
|
94
109
|
}
|
|
95
110
|
});
|
|
@@ -133,29 +148,40 @@ exports.depositBonusCryptoMixin = {
|
|
|
133
148
|
exports.depositWrappedBonusCryptoMixin = {
|
|
134
149
|
depositWrappedBonus: function (amounts) {
|
|
135
150
|
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
var prices, totalAmountUSD, expected,
|
|
137
|
-
return __generator(this, function (
|
|
138
|
-
switch (
|
|
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) {
|
|
139
154
|
case 0: return [4 /*yield*/, this._wrappedPrices()];
|
|
140
155
|
case 1:
|
|
141
|
-
prices =
|
|
142
|
-
|
|
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;
|
|
143
160
|
_a = Number;
|
|
144
|
-
|
|
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)];
|
|
145
163
|
case 2:
|
|
146
|
-
|
|
147
|
-
|
|
164
|
+
vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
|
|
165
|
+
_f.label = 3;
|
|
148
166
|
case 3:
|
|
149
|
-
|
|
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);
|
|
150
176
|
poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices[i]; });
|
|
151
177
|
poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
|
|
152
178
|
poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
|
|
153
179
|
balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
|
|
154
180
|
balancedAmounts = balancedAmountsUSD.map(function (a, i) { return a / prices[i]; });
|
|
155
|
-
|
|
181
|
+
_e = Number;
|
|
156
182
|
return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
|
|
157
|
-
case
|
|
158
|
-
balancedExpected =
|
|
183
|
+
case 6:
|
|
184
|
+
balancedExpected = _e.apply(void 0, [_f.sent()]);
|
|
159
185
|
return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
|
|
160
186
|
}
|
|
161
187
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,216 @@
|
|
|
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 (_) 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)];
|
|
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) { return i === prices.length - 1 ? p * vp : p; });
|
|
201
|
+
coinPrice = prices[this._getCoinIdx(coin)];
|
|
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
|
+
};
|
|
@@ -26,6 +26,7 @@ var depositWrappedMixins_1 = require("./mixins/depositWrappedMixins");
|
|
|
26
26
|
var withdrawExpectedMixins_1 = require("./mixins/withdrawExpectedMixins");
|
|
27
27
|
var withdrawMixins_1 = require("./mixins/withdrawMixins");
|
|
28
28
|
var withdrawWrappedMixins_1 = require("./mixins/withdrawWrappedMixins");
|
|
29
|
+
var withdrawBonusMixins_1 = require("./mixins/withdrawBonusMixins");
|
|
29
30
|
var withdrawImbalanceMixins_1 = require("./mixins/withdrawImbalanceMixins");
|
|
30
31
|
var withdrawImbalanceWrappedMixins_1 = require("./mixins/withdrawImbalanceWrappedMixins");
|
|
31
32
|
var withdrawOneCoinExpectedMixins_1 = require("./mixins/withdrawOneCoinExpectedMixins");
|
|
@@ -72,12 +73,12 @@ var getPool = function (poolId) {
|
|
|
72
73
|
// depositBonus and depositWrappedBonus
|
|
73
74
|
if (poolDummy.isCrypto) {
|
|
74
75
|
Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusCryptoMixin);
|
|
75
|
-
if (!poolDummy.isFake)
|
|
76
|
+
if (!poolDummy.isPlain && !poolDummy.isFake)
|
|
76
77
|
Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusCryptoMixin);
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
80
|
Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusMixin);
|
|
80
|
-
if (!poolDummy.isFake)
|
|
81
|
+
if (!poolDummy.isPlain && !poolDummy.isFake)
|
|
81
82
|
Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusMixin);
|
|
82
83
|
}
|
|
83
84
|
// deposit and depositEstimateGas
|
|
@@ -87,18 +88,20 @@ var getPool = function (poolId) {
|
|
|
87
88
|
else if (poolDummy.zap && poolId !== 'susd') {
|
|
88
89
|
Object.assign(Pool.prototype, depositMixins_1.depositZapMixin);
|
|
89
90
|
}
|
|
90
|
-
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
91
|
+
else if (poolDummy.isLending || (poolDummy.isCrypto && !poolDummy.isPlain)) {
|
|
91
92
|
Object.assign(Pool.prototype, depositMixins_1.depositLendingOrCryptoMixin);
|
|
92
93
|
}
|
|
93
94
|
else {
|
|
94
95
|
Object.assign(Pool.prototype, depositMixins_1.depositPlainMixin);
|
|
95
96
|
}
|
|
96
97
|
// depositWrapped and depositWrappedEstimateGas
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
99
|
+
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
100
|
+
Object.assign(Pool.prototype, depositWrappedMixins_1.depositWrapped3argsMixin);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
Object.assign(Pool.prototype, depositWrappedMixins_1.depositWrapped2argsMixin);
|
|
104
|
+
}
|
|
102
105
|
}
|
|
103
106
|
// withdrawExpected
|
|
104
107
|
if (poolDummy.isFake) {
|
|
@@ -107,7 +110,7 @@ var getPool = function (poolId) {
|
|
|
107
110
|
else if (poolDummy.isMeta) {
|
|
108
111
|
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedMetaMixin);
|
|
109
112
|
}
|
|
110
|
-
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
113
|
+
else if (poolDummy.isLending || (poolDummy.isCrypto && !poolDummy.isPlain)) {
|
|
111
114
|
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedLendingOrCryptoMixin);
|
|
112
115
|
}
|
|
113
116
|
else {
|
|
@@ -120,20 +123,40 @@ var getPool = function (poolId) {
|
|
|
120
123
|
else if (poolDummy.zap && poolId !== 'susd') {
|
|
121
124
|
Object.assign(Pool.prototype, withdrawMixins_1.withdrawZapMixin);
|
|
122
125
|
}
|
|
123
|
-
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
126
|
+
else if (poolDummy.isLending || (poolDummy.isCrypto && !poolDummy.isPlain)) {
|
|
124
127
|
Object.assign(Pool.prototype, withdrawMixins_1.withdrawLendingOrCryptoMixin);
|
|
125
128
|
}
|
|
126
129
|
else {
|
|
127
130
|
Object.assign(Pool.prototype, withdrawMixins_1.withdrawPlainMixin);
|
|
128
131
|
}
|
|
129
|
-
//
|
|
130
|
-
if (
|
|
131
|
-
Object.assign(Pool.prototype,
|
|
132
|
-
Object.assign(Pool.prototype,
|
|
132
|
+
// withdrawImbalanceBonus and withdrawOneCoinBonus
|
|
133
|
+
if (!poolDummy.isCrypto) {
|
|
134
|
+
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawImbalanceBonusMixin);
|
|
135
|
+
Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinBonusMixin);
|
|
133
136
|
}
|
|
134
|
-
else
|
|
135
|
-
Object.assign(Pool.prototype,
|
|
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
|
+
// withdrawWrapped and withdrawWrappedEstimateGas
|
|
151
|
+
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
152
|
+
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
153
|
+
Object.assign(Pool.prototype, withdrawWrappedMixins_1.withdrawWrapped3argsMixin);
|
|
154
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawWrappedExpectedMixin);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
Object.assign(Pool.prototype, withdrawWrappedMixins_1.withdrawWrapped2argsMixin);
|
|
158
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawWrappedExpectedMixin);
|
|
159
|
+
}
|
|
137
160
|
}
|
|
138
161
|
// withdrawImbalance and withdrawImbalanceEstimateGas
|
|
139
162
|
if (!poolDummy.isCrypto) {
|
|
@@ -179,7 +202,7 @@ var getPool = function (poolId) {
|
|
|
179
202
|
else if (poolDummy.zap) { // including susd
|
|
180
203
|
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinZapMixin);
|
|
181
204
|
}
|
|
182
|
-
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
205
|
+
else if (poolDummy.isLending || (poolDummy.isCrypto && !poolDummy.isPlain)) {
|
|
183
206
|
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinLendingOrCryptoMixin);
|
|
184
207
|
}
|
|
185
208
|
else {
|