@curvefi/api 2.4.1 → 2.4.2
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 +0 -2
- package/lib/pools/PoolTemplate.js +14 -141
- 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 +19 -0
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -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 || this.isPlain) {
|
|
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");
|
|
@@ -128,6 +129,24 @@ var getPool = function (poolId) {
|
|
|
128
129
|
else {
|
|
129
130
|
Object.assign(Pool.prototype, withdrawMixins_1.withdrawPlainMixin);
|
|
130
131
|
}
|
|
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
|
+
}
|
|
131
150
|
// withdrawWrapped and withdrawWrappedEstimateGas
|
|
132
151
|
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
133
152
|
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|