@curvefi/api 2.63.0 → 2.63.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/boosting.js +247 -645
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +19 -19
- package/lib/constants/coins/arbitrum.js +5 -5
- package/lib/constants/coins/aurora.js +5 -5
- package/lib/constants/coins/avalanche.js +6 -6
- package/lib/constants/coins/base.js +5 -5
- package/lib/constants/coins/bsc.js +5 -5
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +9 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/fraxtal.js +5 -5
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/mantle.js +5 -5
- package/lib/constants/coins/moonbeam.js +5 -5
- package/lib/constants/coins/optimism.js +5 -5
- package/lib/constants/coins/polygon.js +6 -6
- package/lib/constants/coins/xdai.js +5 -5
- package/lib/constants/coins/xlayer.js +5 -5
- package/lib/constants/coins/zksync.js +5 -5
- package/lib/constants/pools/arbitrum.js +1 -1
- package/lib/constants/pools/aurora.js +1 -1
- package/lib/constants/pools/avalanche.js +1 -1
- package/lib/constants/pools/base.js +1 -1
- package/lib/constants/pools/bsc.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +2 -2
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/fraxtal.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/mantle.js +1 -1
- package/lib/constants/pools/moonbeam.js +1 -1
- package/lib/constants/pools/optimism.js +1 -1
- package/lib/constants/pools/polygon.js +1 -1
- package/lib/constants/pools/xdai.js +1 -1
- package/lib/constants/pools/xlayer.js +1 -1
- package/lib/constants/pools/zksync.js +1 -1
- package/lib/constants/tricryptoDeployImplementations.js +1 -1
- package/lib/constants/utils.js +18 -19
- package/lib/constants/volumeNetworks.js +1 -1
- package/lib/curve.d.ts +10 -6
- package/lib/curve.js +534 -909
- package/lib/dao.js +351 -705
- package/lib/external-api.js +127 -256
- package/lib/factory/common.js +4 -4
- package/lib/factory/constants-crypto.js +33 -33
- package/lib/factory/constants.js +34 -34
- package/lib/factory/deploy.js +542 -907
- package/lib/factory/factory-api.js +205 -269
- package/lib/factory/factory-crypto.js +202 -342
- package/lib/factory/factory-tricrypto.js +164 -286
- package/lib/factory/factory-twocrypto.js +151 -269
- package/lib/factory/factory.js +245 -385
- package/lib/index.js +109 -198
- package/lib/interfaces.d.ts +46 -6
- package/lib/pools/PoolTemplate.js +1774 -3027
- package/lib/pools/gaugePool.js +112 -251
- package/lib/pools/mixins/common.js +22 -93
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
- package/lib/pools/mixins/depositMixins.js +160 -386
- package/lib/pools/mixins/depositWrappedMixins.js +79 -205
- package/lib/pools/mixins/poolBalancesMixin.js +24 -87
- package/lib/pools/mixins/swapMixins.js +139 -324
- package/lib/pools/mixins/swapWrappedMixins.js +111 -265
- package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
- package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
- package/lib/pools/mixins/withdrawMixins.js +139 -359
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
- package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
- package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
- package/lib/pools/poolConstructor.js +11 -31
- package/lib/pools/utils.js +301 -469
- package/lib/route-finder.worker.d.ts +9 -0
- package/lib/route-finder.worker.js +112 -0
- package/lib/route-graph.worker.d.ts +11 -0
- package/lib/route-graph.worker.js +334 -0
- package/lib/router.js +323 -912
- package/lib/utils.d.ts +8 -7
- package/lib/utils.js +540 -927
- package/package.json +3 -2
package/lib/pools/gaugePool.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,37 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
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;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
10
|
import { curve } from "../curve.js";
|
|
49
11
|
import { DIGas, ensureAllowance, ensureAllowanceEstimateGas, getCoinsData, hasAllowance, mulBy1_3, parseUnits, smartNumber, } from "../utils.js";
|
|
50
|
-
|
|
51
|
-
|
|
12
|
+
export class GaugePool {
|
|
13
|
+
constructor(address, poolName) {
|
|
52
14
|
this.address = address;
|
|
53
15
|
this.poolName = poolName;
|
|
54
16
|
this.estimateGas = {
|
|
@@ -57,229 +19,128 @@ var GaugePool = /** @class */ (function () {
|
|
|
57
19
|
depositReward: this.depositRewardEstimateGas.bind(this),
|
|
58
20
|
};
|
|
59
21
|
}
|
|
60
|
-
|
|
61
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
case 1:
|
|
69
|
-
_a.trys.push([1, 3, , 4]);
|
|
70
|
-
return [4 /*yield*/, curve.contracts[this.address].contract.manager()];
|
|
71
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
72
|
-
case 3:
|
|
73
|
-
e_1 = _a.sent();
|
|
74
|
-
return [2 /*return*/, curve.constants.ZERO_ADDRESS];
|
|
75
|
-
case 4: return [2 /*return*/];
|
|
22
|
+
gaugeManager() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (!this.address || this.address === curve.constants.ZERO_ADDRESS) {
|
|
25
|
+
return curve.constants.ZERO_ADDRESS;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
try {
|
|
29
|
+
return yield curve.contracts[this.address].contract.manager();
|
|
76
30
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
GaugePool.prototype.gaugeDistributors = function () {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var gaugeContract, gaugeMulticallContract, rewardCount, _a, _b, _c, calls, i, rewardTokens, i, rewardData, gaugeDistributors, i;
|
|
83
|
-
return __generator(this, function (_d) {
|
|
84
|
-
switch (_d.label) {
|
|
85
|
-
case 0: return [4 /*yield*/, curve.contracts[this.address].contract];
|
|
86
|
-
case 1:
|
|
87
|
-
gaugeContract = _d.sent();
|
|
88
|
-
return [4 /*yield*/, curve.contracts[this.address].multicallContract];
|
|
89
|
-
case 2:
|
|
90
|
-
gaugeMulticallContract = _d.sent();
|
|
91
|
-
_a = Number;
|
|
92
|
-
_c = (_b = curve).formatUnits;
|
|
93
|
-
return [4 /*yield*/, gaugeContract.reward_count(curve.constantOptions)];
|
|
94
|
-
case 3:
|
|
95
|
-
rewardCount = _a.apply(void 0, [_c.apply(_b, [_d.sent(), 0])]);
|
|
96
|
-
calls = [];
|
|
97
|
-
for (i = 0; i < rewardCount; i++) {
|
|
98
|
-
calls.push(gaugeMulticallContract.reward_tokens(i));
|
|
99
|
-
}
|
|
100
|
-
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
101
|
-
case 4:
|
|
102
|
-
rewardTokens = _d.sent();
|
|
103
|
-
calls = [];
|
|
104
|
-
for (i = 0; i < rewardCount; i++) {
|
|
105
|
-
calls.push(gaugeMulticallContract.reward_data(rewardTokens[i]));
|
|
106
|
-
}
|
|
107
|
-
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
108
|
-
case 5:
|
|
109
|
-
rewardData = _d.sent();
|
|
110
|
-
gaugeDistributors = {};
|
|
111
|
-
for (i = 0; i < rewardCount; i++) {
|
|
112
|
-
gaugeDistributors[rewardTokens[i]] = rewardData[i].distributor;
|
|
113
|
-
}
|
|
114
|
-
return [2 /*return*/, gaugeDistributors];
|
|
31
|
+
catch (e) {
|
|
32
|
+
return curve.constants.ZERO_ADDRESS;
|
|
115
33
|
}
|
|
116
|
-
}
|
|
34
|
+
}
|
|
117
35
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
36
|
+
}
|
|
37
|
+
gaugeDistributors() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const gaugeContract = yield curve.contracts[this.address].contract;
|
|
40
|
+
const gaugeMulticallContract = yield curve.contracts[this.address].multicallContract;
|
|
41
|
+
const rewardCount = Number(curve.formatUnits(yield gaugeContract.reward_count(curve.constantOptions), 0));
|
|
42
|
+
let calls = [];
|
|
43
|
+
for (let i = 0; i < rewardCount; i++) {
|
|
44
|
+
calls.push(gaugeMulticallContract.reward_tokens(i));
|
|
45
|
+
}
|
|
46
|
+
const rewardTokens = yield curve.multicallProvider.all(calls);
|
|
47
|
+
calls = [];
|
|
48
|
+
for (let i = 0; i < rewardCount; i++) {
|
|
49
|
+
calls.push(gaugeMulticallContract.reward_data(rewardTokens[i]));
|
|
50
|
+
}
|
|
51
|
+
const rewardData = yield curve.multicallProvider.all(calls);
|
|
52
|
+
const gaugeDistributors = {};
|
|
53
|
+
for (let i = 0; i < rewardCount; i++) {
|
|
54
|
+
gaugeDistributors[rewardTokens[i]] = rewardData[i].distributor;
|
|
55
|
+
}
|
|
56
|
+
return gaugeDistributors;
|
|
137
57
|
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return [4 /*yield*/, curve.contracts[this.address].contract.add_reward.estimateGas(_reward_token, _distributor, __assign({}, curve.constantOptions))];
|
|
148
|
-
case 1:
|
|
149
|
-
gas = _a.sent();
|
|
150
|
-
if (estimateGas)
|
|
151
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
152
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
153
|
-
return [4 /*yield*/, curve.contracts[this.address].contract.add_reward(_reward_token, _distributor, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
154
|
-
case 2: return [2 /*return*/, (_a.sent()).hash];
|
|
155
|
-
case 3: throw Error("Pool ".concat(this.poolName, " does not have gauge"));
|
|
58
|
+
}
|
|
59
|
+
gaugeVersion() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
if (!this.address || this.address === curve.constants.ZERO_ADDRESS) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
try {
|
|
66
|
+
return yield curve.contracts[this.address].contract.version();
|
|
156
67
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
160
|
-
GaugePool.prototype.addRewardEstimateGas = function (rewardToken, distributor) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
-
return __generator(this, function (_a) {
|
|
163
|
-
switch (_a.label) {
|
|
164
|
-
case 0: return [4 /*yield*/, this._addReward(rewardToken, distributor, true)];
|
|
165
|
-
case 1:
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
return [2 /*return*/, _a.sent()];
|
|
68
|
+
catch (e) {
|
|
69
|
+
return null;
|
|
168
70
|
}
|
|
169
|
-
}
|
|
71
|
+
}
|
|
170
72
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
73
|
+
}
|
|
74
|
+
_addReward(_reward_token, _distributor, estimateGas = false) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
if (this.address !== curve.constants.ZERO_ADDRESS && this.address) {
|
|
77
|
+
const gas = yield curve.contracts[this.address].contract.add_reward.estimateGas(_reward_token, _distributor, Object.assign({}, curve.constantOptions));
|
|
78
|
+
if (estimateGas)
|
|
79
|
+
return smartNumber(gas);
|
|
80
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
81
|
+
return (yield curve.contracts[this.address].contract.add_reward(_reward_token, _distributor, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
82
|
+
}
|
|
83
|
+
throw Error(`Pool ${this.poolName} does not have gauge`);
|
|
182
84
|
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
186
|
-
|
|
187
|
-
return
|
|
188
|
-
switch (_a.label) {
|
|
189
|
-
case 0:
|
|
190
|
-
versionsWithDepositReward = ['v6.1.0'];
|
|
191
|
-
return [4 /*yield*/, this.gaugeVersion()];
|
|
192
|
-
case 1:
|
|
193
|
-
version = _a.sent();
|
|
194
|
-
return [2 /*return*/, version ? versionsWithDepositReward.includes(version) : Boolean(version)];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
85
|
+
}
|
|
86
|
+
addRewardEstimateGas(rewardToken, distributor) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
return yield this._addReward(rewardToken, distributor, true);
|
|
197
90
|
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
case 0: return [4 /*yield*/, hasAllowance([rewardToken], [amount], curve.signerAddress, this.address)];
|
|
204
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
205
|
-
}
|
|
206
|
-
});
|
|
91
|
+
}
|
|
92
|
+
addReward(rewardToken, distributor) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
return yield this._addReward(rewardToken, distributor);
|
|
207
96
|
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
97
|
+
}
|
|
98
|
+
isDepositRewardAvailable() {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const versionsWithDepositReward = ['v6.1.0'];
|
|
101
|
+
const version = yield this.gaugeVersion();
|
|
102
|
+
return version ? versionsWithDepositReward.includes(version) : Boolean(version);
|
|
217
103
|
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
-
return
|
|
222
|
-
switch (_a.label) {
|
|
223
|
-
case 0: return [4 /*yield*/, ensureAllowance([rewardToken], [amount], this.address)];
|
|
224
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
225
|
-
}
|
|
226
|
-
});
|
|
104
|
+
}
|
|
105
|
+
depositRewardIsApproved(rewardToken, amount) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
return yield hasAllowance([rewardToken], [amount], curve.signerAddress, this.address);
|
|
227
108
|
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
var contract, decimals, _amount, gas, gasLimit;
|
|
233
|
-
return __generator(this, function (_a) {
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0:
|
|
236
|
-
if (!!estimateGas) return [3 /*break*/, 2];
|
|
237
|
-
return [4 /*yield*/, ensureAllowance([rewardToken], [amount], this.address)];
|
|
238
|
-
case 1:
|
|
239
|
-
_a.sent();
|
|
240
|
-
_a.label = 2;
|
|
241
|
-
case 2:
|
|
242
|
-
contract = curve.contracts[this.address].contract;
|
|
243
|
-
return [4 /*yield*/, getCoinsData(rewardToken)];
|
|
244
|
-
case 3:
|
|
245
|
-
decimals = (_a.sent())[0].decimals;
|
|
246
|
-
_amount = parseUnits(amount, decimals);
|
|
247
|
-
return [4 /*yield*/, contract.deposit_reward_token.estimateGas(rewardToken, _amount, epoch, __assign({}, curve.constantOptions))];
|
|
248
|
-
case 4:
|
|
249
|
-
gas = _a.sent();
|
|
250
|
-
if (estimateGas)
|
|
251
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
252
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
253
|
-
return [4 /*yield*/, contract.deposit_reward_token(rewardToken, _amount, epoch, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
254
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
255
|
-
}
|
|
256
|
-
});
|
|
109
|
+
}
|
|
110
|
+
depositRewardApproveEstimateGas(rewardToken, amount) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
return yield ensureAllowanceEstimateGas([rewardToken], [amount], this.address);
|
|
257
113
|
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
261
|
-
return
|
|
262
|
-
switch (_a.label) {
|
|
263
|
-
case 0: return [4 /*yield*/, this._depositReward(rewardToken, amount, epoch, true)];
|
|
264
|
-
case 1:
|
|
265
|
-
// @ts-ignore
|
|
266
|
-
return [2 /*return*/, _a.sent()];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
114
|
+
}
|
|
115
|
+
depositRewardApprove(rewardToken, amount) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return yield ensureAllowance([rewardToken], [amount], this.address);
|
|
269
118
|
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
119
|
+
}
|
|
120
|
+
_depositReward(rewardToken, amount, epoch, estimateGas = false) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
if (!estimateGas)
|
|
123
|
+
yield ensureAllowance([rewardToken], [amount], this.address);
|
|
124
|
+
const contract = curve.contracts[this.address].contract;
|
|
125
|
+
const decimals = (yield getCoinsData(rewardToken))[0].decimals;
|
|
126
|
+
const _amount = parseUnits(amount, decimals);
|
|
127
|
+
const gas = yield contract.deposit_reward_token.estimateGas(rewardToken, _amount, epoch, Object.assign({}, curve.constantOptions));
|
|
128
|
+
if (estimateGas)
|
|
129
|
+
return smartNumber(gas);
|
|
130
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
131
|
+
return (yield contract.deposit_reward_token(rewardToken, _amount, epoch, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
|
|
281
132
|
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
133
|
+
}
|
|
134
|
+
depositRewardEstimateGas(rewardToken, amount, epoch) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
return yield this._depositReward(rewardToken, amount, epoch, true);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
depositReward(rewardToken, amount, epoch) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
return yield this._depositReward(rewardToken, amount, epoch);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -7,105 +7,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
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;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
};
|
|
46
10
|
import { PoolTemplate } from "../PoolTemplate.js";
|
|
47
11
|
import { curve } from "../../curve.js";
|
|
48
12
|
import { fromBN, toBN } from "../../utils.js";
|
|
49
13
|
export function _calcExpectedAmounts(_lpTokenAmount) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
case 2:
|
|
63
|
-
_balance = _b.sent();
|
|
64
|
-
coinBalancesBN.push(toBN(_balance, this.wrappedDecimals[i]));
|
|
65
|
-
_b.label = 3;
|
|
66
|
-
case 3:
|
|
67
|
-
i++;
|
|
68
|
-
return [3 /*break*/, 1];
|
|
69
|
-
case 4:
|
|
70
|
-
_a = toBN;
|
|
71
|
-
return [4 /*yield*/, curve.contracts[this.lpToken].contract.totalSupply(curve.constantOptions)];
|
|
72
|
-
case 5:
|
|
73
|
-
totalSupplyBN = _a.apply(void 0, [_b.sent()]);
|
|
74
|
-
expectedAmountsBN = [];
|
|
75
|
-
for (_i = 0, coinBalancesBN_1 = coinBalancesBN; _i < coinBalancesBN_1.length; _i++) {
|
|
76
|
-
coinBalance = coinBalancesBN_1[_i];
|
|
77
|
-
expectedAmountsBN.push(coinBalance.times(toBN(_lpTokenAmount)).div(totalSupplyBN));
|
|
78
|
-
}
|
|
79
|
-
return [2 /*return*/, expectedAmountsBN.map(function (amount, i) { return fromBN(amount, _this.wrappedDecimals[i]); })];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const coinBalancesBN = [];
|
|
16
|
+
for (let i = 0; i < this.wrappedCoinAddresses.length; i++) {
|
|
17
|
+
const _balance = yield curve.contracts[this.address].contract.balances(i, curve.constantOptions);
|
|
18
|
+
coinBalancesBN.push(toBN(_balance, this.wrappedDecimals[i]));
|
|
19
|
+
}
|
|
20
|
+
const totalSupplyBN = toBN(yield curve.contracts[this.lpToken].contract.totalSupply(curve.constantOptions));
|
|
21
|
+
const expectedAmountsBN = [];
|
|
22
|
+
for (const coinBalance of coinBalancesBN) {
|
|
23
|
+
expectedAmountsBN.push(coinBalance.times(toBN(_lpTokenAmount)).div(totalSupplyBN));
|
|
24
|
+
}
|
|
25
|
+
return expectedAmountsBN.map((amount, i) => fromBN(amount, this.wrappedDecimals[i]));
|
|
82
26
|
});
|
|
83
27
|
}
|
|
84
28
|
export function _calcExpectedUnderlyingAmountsMeta(_lpTokenAmount) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!basePool.isMeta) return [3 /*break*/, 3];
|
|
96
|
-
return [4 /*yield*/, _calcExpectedUnderlyingAmountsMeta.call(basePool, _expectedMetaCoinAmount)];
|
|
97
|
-
case 2:
|
|
98
|
-
_a = _b.sent();
|
|
99
|
-
return [3 /*break*/, 5];
|
|
100
|
-
case 3: return [4 /*yield*/, _calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
101
|
-
case 4:
|
|
102
|
-
_a = _b.sent();
|
|
103
|
-
_b.label = 5;
|
|
104
|
-
case 5:
|
|
105
|
-
_basePoolExpectedAmounts = _a;
|
|
106
|
-
_expectedUnderlyingAmounts.splice.apply(_expectedUnderlyingAmounts, __spreadArray([this.metaCoinIdx, 0], _basePoolExpectedAmounts, false));
|
|
107
|
-
return [2 /*return*/, _expectedUnderlyingAmounts];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const _expectedWrappedAmounts = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
31
|
+
const [_expectedMetaCoinAmount] = _expectedWrappedAmounts.splice(this.metaCoinIdx, 1);
|
|
32
|
+
const _expectedUnderlyingAmounts = _expectedWrappedAmounts;
|
|
33
|
+
const basePool = new PoolTemplate(this.basePool);
|
|
34
|
+
const _basePoolExpectedAmounts = basePool.isMeta ?
|
|
35
|
+
yield _calcExpectedUnderlyingAmountsMeta.call(basePool, _expectedMetaCoinAmount) :
|
|
36
|
+
yield _calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount);
|
|
37
|
+
_expectedUnderlyingAmounts.splice(this.metaCoinIdx, 0, ..._basePoolExpectedAmounts);
|
|
38
|
+
return _expectedUnderlyingAmounts;
|
|
110
39
|
});
|
|
111
40
|
}
|