@curvefi/api 2.3.4 → 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/README.md +129 -7
- package/lib/constants/pools/ethereum.js +26 -26
- package/lib/interfaces.d.ts +9 -0
- package/lib/pools/PoolTemplate.d.ts +24 -5
- package/lib/pools/PoolTemplate.js +456 -196
- 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/lib/utils.js +1 -0
- package/package.json +1 -1
|
@@ -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 {
|
package/lib/utils.js
CHANGED
|
@@ -464,6 +464,7 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
464
464
|
throw Error('curve object is not initialized');
|
|
465
465
|
}
|
|
466
466
|
assetId = {
|
|
467
|
+
'CRV': 'curve-dao-token',
|
|
467
468
|
'EUR': curve_1.curve.constants.COINS.eurt,
|
|
468
469
|
'BTC': 'bitcoin',
|
|
469
470
|
'ETH': 'ethereum',
|