@curvefi/api 2.24.0 → 2.24.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/constants/abis/atricrypto3/base_pool_zap.json +16 -0
- package/lib/constants/coins/polygon.js +1 -1
- package/lib/factory/factory-api.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.d.ts +2 -2
- package/lib/pools/PoolTemplate.js +79 -63
- package/lib/pools/mixins/depositMixins.d.ts +1 -0
- package/lib/pools/mixins/depositMixins.js +67 -1
- package/lib/pools/mixins/swapMixins.d.ts +1 -0
- package/lib/pools/mixins/swapMixins.js +68 -1
- package/lib/pools/mixins/withdrawMixins.d.ts +1 -0
- package/lib/pools/mixins/withdrawMixins.js +65 -1
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -0
- package/lib/pools/mixins/withdrawOneCoinMixins.js +65 -1
- package/lib/pools/poolConstructor.js +27 -7
- package/lib/router.js +10 -0
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +32 -1
- package/package.json +1 -1
|
@@ -50,6 +50,10 @@
|
|
|
50
50
|
{
|
|
51
51
|
"name": "_min_dy",
|
|
52
52
|
"type": "uint256"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "_use_eth",
|
|
56
|
+
"type": "bool"
|
|
53
57
|
}
|
|
54
58
|
],
|
|
55
59
|
"outputs": [
|
|
@@ -104,6 +108,10 @@
|
|
|
104
108
|
{
|
|
105
109
|
"name": "_min_mint_amount",
|
|
106
110
|
"type": "uint256"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "_use_eth",
|
|
114
|
+
"type": "bool"
|
|
107
115
|
}
|
|
108
116
|
],
|
|
109
117
|
"outputs": [
|
|
@@ -150,6 +158,10 @@
|
|
|
150
158
|
{
|
|
151
159
|
"name": "_min_amounts",
|
|
152
160
|
"type": "uint256[6]"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"name": "_use_eth",
|
|
164
|
+
"type": "bool"
|
|
153
165
|
}
|
|
154
166
|
],
|
|
155
167
|
"outputs": [
|
|
@@ -179,6 +191,10 @@
|
|
|
179
191
|
{
|
|
180
192
|
"name": "_min_amount",
|
|
181
193
|
"type": "uint256"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"name": "_use_eth",
|
|
197
|
+
"type": "bool"
|
|
182
198
|
}
|
|
183
199
|
],
|
|
184
200
|
"outputs": [
|
|
@@ -34,7 +34,7 @@ exports.USD_COINS_POLYGON = {
|
|
|
34
34
|
amusdt: "0x60D55F02A771d515e077c9C2403a1ef324885CeC",
|
|
35
35
|
am3crv: "0xE7a24EF0C5e95Ffb0f6684b813A78F2a3AD7D171", // am3CRV
|
|
36
36
|
};
|
|
37
|
-
exports.COINS_POLYGON = (0, utils_1.lowerCaseValues)(__assign(__assign(__assign(__assign(__assign({}, exports.BTC_COINS_POLYGON), exports.ETH_COINS_POLYGON), exports.EUR_COINS_POLYGON), exports.USD_COINS_POLYGON), { crv: "0x172370d5cd63279efa6d502dab29171933a610af", matic: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" }));
|
|
37
|
+
exports.COINS_POLYGON = (0, utils_1.lowerCaseValues)(__assign(__assign(__assign(__assign(__assign({}, exports.BTC_COINS_POLYGON), exports.ETH_COINS_POLYGON), exports.EUR_COINS_POLYGON), exports.USD_COINS_POLYGON), { crv: "0x172370d5cd63279efa6d502dab29171933a610af", matic: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", wmatic: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270" }));
|
|
38
38
|
var DECIMALS_POLYGON = {
|
|
39
39
|
"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063": 18,
|
|
40
40
|
"0x2791bca1f2de4661ed88a30c99a7a9449aa84174": 6,
|
|
@@ -176,7 +176,7 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
176
176
|
poolGaugeDict = {};
|
|
177
177
|
for (_i = 0, _b = response.data.data.gauges; _i < _b.length; _i++) {
|
|
178
178
|
gaugeData = _b[_i];
|
|
179
|
-
poolGaugeDict[gaugeData.swap] = gaugeData.gauge;
|
|
179
|
+
poolGaugeDict[gaugeData.swap.toLowerCase()] = gaugeData.gauge.toLowerCase();
|
|
180
180
|
}
|
|
181
181
|
for (i = 0; i < rawPoolList.length; i++) {
|
|
182
182
|
rawPoolList[i].gaugeAddress = poolGaugeDict[rawPoolList[i].address];
|
package/lib/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ declare const curve: {
|
|
|
57
57
|
symbol: string;
|
|
58
58
|
}[]>;
|
|
59
59
|
factory: {
|
|
60
|
-
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 |
|
|
60
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 2 | 1 | 3, implementationIdx: 0 | 2 | 1 | 3) => Promise<ethers.ContractTransaction>;
|
|
61
61
|
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<ethers.ContractTransaction>;
|
|
62
62
|
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransaction>;
|
|
63
63
|
getDeployedPlainPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
@@ -65,7 +65,7 @@ declare const curve: {
|
|
|
65
65
|
getDeployedGaugeAddress: (tx: ethers.ContractTransaction) => Promise<string>;
|
|
66
66
|
fetchRecentlyDeployedPool: typeof fetchRecentlyDeployedFactoryPool;
|
|
67
67
|
estimateGas: {
|
|
68
|
-
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 |
|
|
68
|
+
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 2 | 1 | 3, implementationIdx: 0 | 2 | 1 | 3) => Promise<number>;
|
|
69
69
|
deployMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number, fee: number, implementationIdx: 0 | 1) => Promise<number>;
|
|
70
70
|
deployGauge: (poolAddress: string) => Promise<number>;
|
|
71
71
|
};
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export declare class PoolTemplate {
|
|
|
78
78
|
day: string;
|
|
79
79
|
week: string;
|
|
80
80
|
}>;
|
|
81
|
-
tokenApy: () => Promise<[baseApy:
|
|
81
|
+
tokenApy: (useApi?: boolean) => Promise<[baseApy: number, boostedApy: number]>;
|
|
82
82
|
rewardsApy: () => Promise<IReward[]>;
|
|
83
83
|
};
|
|
84
84
|
wallet: {
|
|
@@ -132,7 +132,7 @@ export declare class PoolTemplate {
|
|
|
132
132
|
claimCrvEstimateGas(): Promise<number>;
|
|
133
133
|
claimCrv(): Promise<string>;
|
|
134
134
|
boost: (address?: string) => Promise<string>;
|
|
135
|
-
currentCrvApy: (address?: string) => Promise<
|
|
135
|
+
currentCrvApy: (address?: string) => Promise<number>;
|
|
136
136
|
maxBoostedStake: (...addresses: string[]) => Promise<IDict<string> | string>;
|
|
137
137
|
rewardTokens: (() => Promise<{
|
|
138
138
|
token: string;
|
|
@@ -279,64 +279,74 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
}); };
|
|
282
|
-
this.statsTokenApy = function () {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return [
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
]
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
282
|
+
this.statsTokenApy = function (useApi) {
|
|
283
|
+
if (useApi === void 0) { useApi = true; }
|
|
284
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
285
|
+
var crvAPYs, poolCrvApy, totalLiquidityUSD, inflationRateBN, workingSupplyBN, totalSupplyBN, gaugeContract, lpTokenContract, crvContract, currentWeek, _c, gaugeContract, lpTokenContract, gaugeControllerContract, weightBN, rateBN, crvPrice, baseApyBN, boostedApyBN;
|
|
286
|
+
var _d, _e;
|
|
287
|
+
var _f;
|
|
288
|
+
return __generator(this, function (_g) {
|
|
289
|
+
switch (_g.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
if (this.rewardsOnly())
|
|
292
|
+
throw Error("".concat(this.name, " has Rewards-Only Gauge. Use getRewardsApy instead"));
|
|
293
|
+
if (!(useApi && curve_1.curve.chainId === 1)) return [3 /*break*/, 2];
|
|
294
|
+
return [4 /*yield*/, (0, utils_1._getCrvApyFromApi)()];
|
|
295
|
+
case 1:
|
|
296
|
+
crvAPYs = _g.sent();
|
|
297
|
+
poolCrvApy = (_f = crvAPYs[this.gauge]) !== null && _f !== void 0 ? _f : [0, 0];
|
|
298
|
+
return [2 /*return*/, [poolCrvApy[0], poolCrvApy[1]]];
|
|
299
|
+
case 2: return [4 /*yield*/, this.statsTotalLiquidity()];
|
|
300
|
+
case 3:
|
|
301
|
+
totalLiquidityUSD = _g.sent();
|
|
302
|
+
if (Number(totalLiquidityUSD) === 0)
|
|
303
|
+
return [2 /*return*/, [0, 0]];
|
|
304
|
+
if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 7];
|
|
305
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
306
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
307
|
+
crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
|
|
308
|
+
currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
309
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
310
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
311
|
+
gaugeContract.working_supply(),
|
|
312
|
+
lpTokenContract.totalSupply(),
|
|
313
|
+
])];
|
|
314
|
+
case 4:
|
|
315
|
+
_d = (_g.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _d[0], workingSupplyBN = _d[1], totalSupplyBN = _d[2];
|
|
316
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 6];
|
|
317
|
+
_c = utils_1.toBN;
|
|
318
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
319
|
+
case 5:
|
|
320
|
+
inflationRateBN = _c.apply(void 0, [_g.sent()]).div(WEEK);
|
|
321
|
+
_g.label = 6;
|
|
322
|
+
case 6: return [3 /*break*/, 9];
|
|
323
|
+
case 7:
|
|
324
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
325
|
+
lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
326
|
+
gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
327
|
+
weightBN = void 0;
|
|
328
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
329
|
+
gaugeContract.inflation_rate(),
|
|
330
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
331
|
+
gaugeContract.working_supply(),
|
|
332
|
+
lpTokenContract.totalSupply(),
|
|
333
|
+
])];
|
|
334
|
+
case 8:
|
|
335
|
+
_e = (_g.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _e[0], weightBN = _e[1], workingSupplyBN = _e[2], totalSupplyBN = _e[3];
|
|
336
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
337
|
+
_g.label = 9;
|
|
338
|
+
case 9:
|
|
339
|
+
rateBN = inflationRateBN.times(31536000).times(0.4).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD));
|
|
340
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.curve.constants.ALIASES.crv)];
|
|
341
|
+
case 10:
|
|
342
|
+
crvPrice = _g.sent();
|
|
343
|
+
baseApyBN = rateBN.times(crvPrice);
|
|
344
|
+
boostedApyBN = baseApyBN.times(2.5);
|
|
345
|
+
return [2 /*return*/, [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()]];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
338
348
|
});
|
|
339
|
-
}
|
|
349
|
+
};
|
|
340
350
|
this.statsRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
341
351
|
var apy, rewardTokens, _i, rewardTokens_1, rewardToken, contract, totalLiquidityUSD, rewardRate, rewardData, periodFinish, inflation, baseApy, network, promises, _c, mainPoolsRewards, allTypesExtendedPoolData, rewards, _d, _e, extendedPoolData, _f, _g, pool;
|
|
342
352
|
var _h;
|
|
@@ -648,8 +658,8 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
648
658
|
if (boost == "2.5")
|
|
649
659
|
return [2 /*return*/, maxApy];
|
|
650
660
|
if (boost === "NaN")
|
|
651
|
-
return [2 /*return*/,
|
|
652
|
-
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).
|
|
661
|
+
return [2 /*return*/, NaN];
|
|
662
|
+
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).toNumber()];
|
|
653
663
|
}
|
|
654
664
|
});
|
|
655
665
|
});
|
|
@@ -1588,11 +1598,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1588
1598
|
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.gauge)];
|
|
1589
1599
|
case 1:
|
|
1590
1600
|
_c.sent();
|
|
1591
|
-
return [4 /*yield*/, curve_1.curve.
|
|
1601
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1592
1602
|
case 2:
|
|
1603
|
+
_c.sent();
|
|
1604
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1605
|
+
case 3:
|
|
1593
1606
|
gasLimit = (_c.sent()).mul(150).div(100);
|
|
1594
1607
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1595
|
-
case
|
|
1608
|
+
case 4: return [2 /*return*/, (_c.sent()).hash];
|
|
1596
1609
|
}
|
|
1597
1610
|
});
|
|
1598
1611
|
});
|
|
@@ -1623,11 +1636,14 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1623
1636
|
throw Error("unstake method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, "). There is no gauge"));
|
|
1624
1637
|
}
|
|
1625
1638
|
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
1626
|
-
return [4 /*yield*/, curve_1.curve.
|
|
1639
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
1627
1640
|
case 1:
|
|
1641
|
+
_c.sent();
|
|
1642
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve_1.curve.constantOptions)];
|
|
1643
|
+
case 2:
|
|
1628
1644
|
gasLimit = (_c.sent()).mul(200).div(100);
|
|
1629
1645
|
return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
1630
|
-
case
|
|
1646
|
+
case 3: return [2 /*return*/, (_c.sent()).hash];
|
|
1631
1647
|
}
|
|
1632
1648
|
});
|
|
1633
1649
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate";
|
|
2
2
|
export declare const depositMetaFactoryMixin: PoolTemplate;
|
|
3
|
+
export declare const depositCryptoMetaFactoryMixin: PoolTemplate;
|
|
3
4
|
export declare const depositZapMixin: PoolTemplate;
|
|
4
5
|
export declare const depositLendingOrCryptoMixin: PoolTemplate;
|
|
5
6
|
export declare const depositPlainMixin: PoolTemplate;
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.depositPlainMixin = exports.depositLendingOrCryptoMixin = exports.depositZapMixin = exports.depositMetaFactoryMixin = void 0;
|
|
50
|
+
exports.depositPlainMixin = exports.depositLendingOrCryptoMixin = exports.depositZapMixin = exports.depositCryptoMetaFactoryMixin = exports.depositMetaFactoryMixin = void 0;
|
|
51
51
|
var utils_1 = require("../../utils");
|
|
52
52
|
var curve_1 = require("../../curve");
|
|
53
53
|
var ethers_1 = require("ethers");
|
|
@@ -174,6 +174,72 @@ exports.depositMetaFactoryMixin = {
|
|
|
174
174
|
},
|
|
175
175
|
};
|
|
176
176
|
// @ts-ignore
|
|
177
|
+
exports.depositCryptoMetaFactoryMixin = {
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
_deposit: function (_amounts, slippage, estimateGas) {
|
|
180
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
181
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
182
|
+
var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
|
|
183
|
+
return __generator(this, function (_a) {
|
|
184
|
+
switch (_a.label) {
|
|
185
|
+
case 0:
|
|
186
|
+
if (!!estimateGas) return [3 /*break*/, 2];
|
|
187
|
+
return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
|
|
188
|
+
case 1:
|
|
189
|
+
_a.sent();
|
|
190
|
+
_a.label = 2;
|
|
191
|
+
case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
|
|
192
|
+
case 3:
|
|
193
|
+
_minMintAmount = _a.sent();
|
|
194
|
+
ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
|
|
195
|
+
value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
|
|
196
|
+
contract = curve_1.curve.contracts[this.zap].contract;
|
|
197
|
+
return [4 /*yield*/, contract.estimateGas.add_liquidity(this.address, _amounts, _minMintAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
198
|
+
case 4:
|
|
199
|
+
gas = _a.sent();
|
|
200
|
+
if (estimateGas)
|
|
201
|
+
return [2 /*return*/, gas.toNumber()];
|
|
202
|
+
gasLimit = gas.mul(130).div(100);
|
|
203
|
+
return [4 /*yield*/, contract.add_liquidity(this.address, _amounts, _minMintAmount, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
|
|
204
|
+
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
depositEstimateGas: function (amounts) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
+
var _amounts;
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0: return [4 /*yield*/, _depositCheck.call(this, amounts, true)];
|
|
215
|
+
case 1:
|
|
216
|
+
_amounts = _a.sent();
|
|
217
|
+
return [4 /*yield*/, this._deposit(_amounts, 0.1, true)];
|
|
218
|
+
case 2:
|
|
219
|
+
// @ts-ignore
|
|
220
|
+
return [2 /*return*/, _a.sent()];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
deposit: function (amounts, slippage) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
var _amounts;
|
|
228
|
+
return __generator(this, function (_a) {
|
|
229
|
+
switch (_a.label) {
|
|
230
|
+
case 0: return [4 /*yield*/, _depositCheck.call(this, amounts)];
|
|
231
|
+
case 1:
|
|
232
|
+
_amounts = _a.sent();
|
|
233
|
+
return [4 /*yield*/, this._deposit(_amounts, slippage)];
|
|
234
|
+
case 2:
|
|
235
|
+
// @ts-ignore
|
|
236
|
+
return [2 /*return*/, _a.sent()];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
// @ts-ignore
|
|
177
243
|
exports.depositZapMixin = {
|
|
178
244
|
// @ts-ignore
|
|
179
245
|
_deposit: function (_amounts, slippage, estimateGas) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate";
|
|
2
2
|
export declare const swapTricrypto2Mixin: PoolTemplate;
|
|
3
3
|
export declare const swapMetaFactoryMixin: PoolTemplate;
|
|
4
|
+
export declare const swapCryptoMetaFactoryMixin: PoolTemplate;
|
|
4
5
|
export declare const swapMixin: PoolTemplate;
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.swapMixin = exports.swapMetaFactoryMixin = exports.swapTricrypto2Mixin = void 0;
|
|
50
|
+
exports.swapMixin = exports.swapCryptoMetaFactoryMixin = exports.swapMetaFactoryMixin = exports.swapTricrypto2Mixin = void 0;
|
|
51
51
|
var ethers_1 = require("ethers");
|
|
52
52
|
var curve_1 = require("../../curve");
|
|
53
53
|
var utils_1 = require("../../utils");
|
|
@@ -242,6 +242,73 @@ exports.swapMetaFactoryMixin = {
|
|
|
242
242
|
},
|
|
243
243
|
};
|
|
244
244
|
// @ts-ignore
|
|
245
|
+
exports.swapCryptoMetaFactoryMixin = {
|
|
246
|
+
// @ts-ignore
|
|
247
|
+
_swap: function (i, j, _amount, slippage, estimateGas) {
|
|
248
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
249
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
+
var contractAddress, _minRecvAmount, contract, exchangeMethod, value, gas, gasLimit;
|
|
251
|
+
return __generator(this, function (_a) {
|
|
252
|
+
switch (_a.label) {
|
|
253
|
+
case 0:
|
|
254
|
+
contractAddress = this._swapContractAddress();
|
|
255
|
+
if (!!estimateGas) return [3 /*break*/, 2];
|
|
256
|
+
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.underlyingCoinAddresses[i]], [_amount], contractAddress)];
|
|
257
|
+
case 1:
|
|
258
|
+
_a.sent();
|
|
259
|
+
_a.label = 2;
|
|
260
|
+
case 2: return [4 /*yield*/, _swapMinAmount.call(this, i, j, _amount, slippage)];
|
|
261
|
+
case 3:
|
|
262
|
+
_minRecvAmount = _a.sent();
|
|
263
|
+
contract = curve_1.curve.contracts[contractAddress].contract;
|
|
264
|
+
exchangeMethod = Object.prototype.hasOwnProperty.call(contract, 'exchange_underlying') ? 'exchange_underlying' : 'exchange';
|
|
265
|
+
value = (0, utils_1.isEth)(this.underlyingCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
266
|
+
return [4 /*yield*/, contract.estimateGas[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
267
|
+
case 4:
|
|
268
|
+
gas = _a.sent();
|
|
269
|
+
if (estimateGas)
|
|
270
|
+
return [2 /*return*/, gas.toNumber()];
|
|
271
|
+
gasLimit = gas.mul(140).div(100);
|
|
272
|
+
return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
273
|
+
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
swapEstimateGas: function (inputCoin, outputCoin, amount) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
+
var _a, i, j, _amount;
|
|
281
|
+
return __generator(this, function (_b) {
|
|
282
|
+
switch (_b.label) {
|
|
283
|
+
case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount, true)];
|
|
284
|
+
case 1:
|
|
285
|
+
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
286
|
+
return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
|
|
287
|
+
case 2:
|
|
288
|
+
// @ts-ignore
|
|
289
|
+
return [2 /*return*/, _b.sent()];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
swap: function (inputCoin, outputCoin, amount, slippage) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
var _a, i, j, _amount;
|
|
297
|
+
return __generator(this, function (_b) {
|
|
298
|
+
switch (_b.label) {
|
|
299
|
+
case 0: return [4 /*yield*/, _swapCheck.call(this, inputCoin, outputCoin, amount)];
|
|
300
|
+
case 1:
|
|
301
|
+
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
302
|
+
return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
|
|
303
|
+
case 2:
|
|
304
|
+
// @ts-ignore
|
|
305
|
+
return [2 /*return*/, _b.sent()];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
// @ts-ignore
|
|
245
312
|
exports.swapMixin = {
|
|
246
313
|
// @ts-ignore
|
|
247
314
|
_swap: function (i, j, _amount, slippage, estimateGas) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate";
|
|
2
2
|
export declare const withdrawMetaFactoryMixin: PoolTemplate;
|
|
3
|
+
export declare const withdrawCryptoMetaFactoryMixin: PoolTemplate;
|
|
3
4
|
export declare const withdrawZapMixin: PoolTemplate;
|
|
4
5
|
export declare const withdrawLendingOrCryptoMixin: PoolTemplate;
|
|
5
6
|
export declare const withdrawPlainMixin: PoolTemplate;
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.withdrawPlainMixin = exports.withdrawLendingOrCryptoMixin = exports.withdrawZapMixin = exports.withdrawMetaFactoryMixin = void 0;
|
|
50
|
+
exports.withdrawPlainMixin = exports.withdrawLendingOrCryptoMixin = exports.withdrawZapMixin = exports.withdrawCryptoMetaFactoryMixin = exports.withdrawMetaFactoryMixin = void 0;
|
|
51
51
|
var ethers_1 = require("ethers");
|
|
52
52
|
var curve_1 = require("../../curve");
|
|
53
53
|
var utils_1 = require("../../utils");
|
|
@@ -166,6 +166,70 @@ exports.withdrawMetaFactoryMixin = {
|
|
|
166
166
|
},
|
|
167
167
|
};
|
|
168
168
|
// @ts-ignore
|
|
169
|
+
exports.withdrawCryptoMetaFactoryMixin = {
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
_withdraw: function (_lpTokenAmount, slippage, estimateGas) {
|
|
172
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
var _minAmounts, contract, gas, gasLimit;
|
|
175
|
+
return __generator(this, function (_b) {
|
|
176
|
+
switch (_b.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
if (!!estimateGas) return [3 /*break*/, 2];
|
|
179
|
+
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
|
|
180
|
+
case 1:
|
|
181
|
+
_b.sent();
|
|
182
|
+
_b.label = 2;
|
|
183
|
+
case 2: return [4 /*yield*/, _withdrawMinAmounts.call(this, _lpTokenAmount, slippage)];
|
|
184
|
+
case 3:
|
|
185
|
+
_minAmounts = _b.sent();
|
|
186
|
+
contract = curve_1.curve.contracts[this.zap].contract;
|
|
187
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(this.address, _lpTokenAmount, _minAmounts, true, curve_1.curve.constantOptions)];
|
|
188
|
+
case 4:
|
|
189
|
+
gas = _b.sent();
|
|
190
|
+
if (estimateGas)
|
|
191
|
+
return [2 /*return*/, gas.toNumber()];
|
|
192
|
+
gasLimit = gas.mul(130).div(100);
|
|
193
|
+
return [4 /*yield*/, contract.remove_liquidity(this.address, _lpTokenAmount, _minAmounts, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
194
|
+
case 5: return [2 /*return*/, (_b.sent()).hash];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
withdrawEstimateGas: function (lpTokenAmount) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var _lpTokenAmount;
|
|
202
|
+
return __generator(this, function (_b) {
|
|
203
|
+
switch (_b.label) {
|
|
204
|
+
case 0: return [4 /*yield*/, _withdrawCheck.call(this, lpTokenAmount, true)];
|
|
205
|
+
case 1:
|
|
206
|
+
_lpTokenAmount = _b.sent();
|
|
207
|
+
return [4 /*yield*/, this._withdraw(_lpTokenAmount, 0.1, true)];
|
|
208
|
+
case 2:
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
return [2 /*return*/, _b.sent()];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
withdraw: function (lpTokenAmount, slippage) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
var _lpTokenAmount;
|
|
218
|
+
return __generator(this, function (_b) {
|
|
219
|
+
switch (_b.label) {
|
|
220
|
+
case 0: return [4 /*yield*/, _withdrawCheck.call(this, lpTokenAmount)];
|
|
221
|
+
case 1:
|
|
222
|
+
_lpTokenAmount = _b.sent();
|
|
223
|
+
return [4 /*yield*/, this._withdraw(_lpTokenAmount, slippage)];
|
|
224
|
+
case 2:
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
return [2 /*return*/, _b.sent()];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
// @ts-ignore
|
|
169
233
|
exports.withdrawZapMixin = {
|
|
170
234
|
// @ts-ignore
|
|
171
235
|
_withdraw: function (_lpTokenAmount, slippage, estimateGas) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate";
|
|
2
2
|
export declare const withdrawOneCoinMetaFactoryMixin: PoolTemplate;
|
|
3
|
+
export declare const withdrawOneCoinCryptoMetaFactoryMixin: PoolTemplate;
|
|
3
4
|
export declare const withdrawOneCoinZapMixin: PoolTemplate;
|
|
4
5
|
export declare const withdrawOneCoinLendingOrCryptoMixin: PoolTemplate;
|
|
5
6
|
export declare const withdrawOneCoinPlainMixin: PoolTemplate;
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.withdrawOneCoinPlainMixin = exports.withdrawOneCoinLendingOrCryptoMixin = exports.withdrawOneCoinZapMixin = exports.withdrawOneCoinMetaFactoryMixin = void 0;
|
|
50
|
+
exports.withdrawOneCoinPlainMixin = exports.withdrawOneCoinLendingOrCryptoMixin = exports.withdrawOneCoinZapMixin = exports.withdrawOneCoinCryptoMetaFactoryMixin = exports.withdrawOneCoinMetaFactoryMixin = void 0;
|
|
51
51
|
var curve_1 = require("../../curve");
|
|
52
52
|
var utils_1 = require("../../utils");
|
|
53
53
|
// @ts-ignore
|
|
@@ -166,6 +166,70 @@ exports.withdrawOneCoinMetaFactoryMixin = {
|
|
|
166
166
|
},
|
|
167
167
|
};
|
|
168
168
|
// @ts-ignore
|
|
169
|
+
exports.withdrawOneCoinCryptoMetaFactoryMixin = {
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
_withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
|
|
172
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
var _minAmount, contract, gas, gasLimit;
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
if (!!estimateGas) return [3 /*break*/, 2];
|
|
179
|
+
return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
|
|
180
|
+
case 1:
|
|
181
|
+
_a.sent();
|
|
182
|
+
_a.label = 2;
|
|
183
|
+
case 2: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
|
|
184
|
+
case 3:
|
|
185
|
+
_minAmount = _a.sent();
|
|
186
|
+
contract = curve_1.curve.contracts[this.zap].contract;
|
|
187
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, true, curve_1.curve.constantOptions)];
|
|
188
|
+
case 4:
|
|
189
|
+
gas = _a.sent();
|
|
190
|
+
if (estimateGas)
|
|
191
|
+
return [2 /*return*/, gas.toNumber()];
|
|
192
|
+
gasLimit = gas.mul(130).div(100);
|
|
193
|
+
return [4 /*yield*/, contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
194
|
+
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
withdrawOneCoinEstimateGas: function (lpTokenAmount, coin) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var _a, _lpTokenAmount, i;
|
|
202
|
+
return __generator(this, function (_b) {
|
|
203
|
+
switch (_b.label) {
|
|
204
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin, true)];
|
|
205
|
+
case 1:
|
|
206
|
+
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
207
|
+
return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, 0.1, true)];
|
|
208
|
+
case 2:
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
return [2 /*return*/, _b.sent()];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
withdrawOneCoin: function (lpTokenAmount, coin, slippage) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
var _a, _lpTokenAmount, i;
|
|
218
|
+
return __generator(this, function (_b) {
|
|
219
|
+
switch (_b.label) {
|
|
220
|
+
case 0: return [4 /*yield*/, _withdrawOneCoinCheck.call(this, lpTokenAmount, coin)];
|
|
221
|
+
case 1:
|
|
222
|
+
_a = _b.sent(), _lpTokenAmount = _a[0], i = _a[1];
|
|
223
|
+
return [4 /*yield*/, this._withdrawOneCoin(_lpTokenAmount, i, slippage)];
|
|
224
|
+
case 2:
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
return [2 /*return*/, _b.sent()];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
// @ts-ignore
|
|
169
233
|
exports.withdrawOneCoinZapMixin = {
|
|
170
234
|
// @ts-ignore
|
|
171
235
|
_withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
|
|
@@ -70,7 +70,12 @@ var getPool = function (poolId) {
|
|
|
70
70
|
}
|
|
71
71
|
// deposit and depositEstimateGas
|
|
72
72
|
if (poolDummy.isMetaFactory) {
|
|
73
|
-
|
|
73
|
+
if (poolDummy.isCrypto) {
|
|
74
|
+
Object.assign(Pool.prototype, depositMixins_1.depositCryptoMetaFactoryMixin);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
Object.assign(Pool.prototype, depositMixins_1.depositMetaFactoryMixin);
|
|
78
|
+
}
|
|
74
79
|
}
|
|
75
80
|
else if (poolDummy.zap && poolId !== 'susd') {
|
|
76
81
|
Object.assign(Pool.prototype, depositMixins_1.depositZapMixin);
|
|
@@ -83,7 +88,7 @@ var getPool = function (poolId) {
|
|
|
83
88
|
}
|
|
84
89
|
// depositWrapped and depositWrappedEstimateGas
|
|
85
90
|
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
86
|
-
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
91
|
+
if (((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) || (poolDummy.isCrypto && poolDummy.isMetaFactory)) {
|
|
87
92
|
Object.assign(Pool.prototype, depositWrappedMixins_1.depositWrapped3argsMixin);
|
|
88
93
|
}
|
|
89
94
|
else {
|
|
@@ -105,7 +110,12 @@ var getPool = function (poolId) {
|
|
|
105
110
|
}
|
|
106
111
|
// withdraw and withdrawEstimateGas
|
|
107
112
|
if (poolDummy.isMetaFactory) {
|
|
108
|
-
|
|
113
|
+
if (poolDummy.isCrypto) {
|
|
114
|
+
Object.assign(Pool.prototype, withdrawMixins_1.withdrawCryptoMetaFactoryMixin);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
Object.assign(Pool.prototype, withdrawMixins_1.withdrawMetaFactoryMixin);
|
|
118
|
+
}
|
|
109
119
|
}
|
|
110
120
|
else if (poolDummy.zap && poolId !== 'susd') {
|
|
111
121
|
Object.assign(Pool.prototype, withdrawMixins_1.withdrawZapMixin);
|
|
@@ -118,7 +128,7 @@ var getPool = function (poolId) {
|
|
|
118
128
|
}
|
|
119
129
|
// withdrawWrapped and withdrawWrappedEstimateGas
|
|
120
130
|
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
121
|
-
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
131
|
+
if (((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) || (poolDummy.isCrypto && poolDummy.isMetaFactory)) {
|
|
122
132
|
Object.assign(Pool.prototype, withdrawWrappedMixins_1.withdrawWrapped3argsMixin);
|
|
123
133
|
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawWrappedExpectedMixin);
|
|
124
134
|
}
|
|
@@ -166,7 +176,12 @@ var getPool = function (poolId) {
|
|
|
166
176
|
}
|
|
167
177
|
// withdrawOneCoin and withdrawOneCoinEstimateGas
|
|
168
178
|
if (poolDummy.isMetaFactory) {
|
|
169
|
-
|
|
179
|
+
if (poolDummy.isCrypto) {
|
|
180
|
+
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinCryptoMetaFactoryMixin);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinMetaFactoryMixin);
|
|
184
|
+
}
|
|
170
185
|
}
|
|
171
186
|
else if (poolDummy.zap) { // including susd
|
|
172
187
|
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinZapMixin);
|
|
@@ -188,7 +203,7 @@ var getPool = function (poolId) {
|
|
|
188
203
|
}
|
|
189
204
|
// withdrawOneCoinWrapped and withdrawOneCoinWrappedEstimateGas
|
|
190
205
|
if (!poolDummy.isPlain && !poolDummy.isFake && !(poolDummy.isLending && poolDummy.zap)) {
|
|
191
|
-
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
206
|
+
if (((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) || (poolDummy.isCrypto && poolDummy.isMetaFactory)) {
|
|
192
207
|
Object.assign(Pool.prototype, withdrawOneCoinWrappedMixins_1.withdrawOneCoinWrappedLendingOrCryptoMixin);
|
|
193
208
|
}
|
|
194
209
|
else {
|
|
@@ -201,7 +216,12 @@ var getPool = function (poolId) {
|
|
|
201
216
|
Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
|
|
202
217
|
}
|
|
203
218
|
else if (poolDummy.isMetaFactory && ((0, exports.getPool)(poolDummy.basePool).isLending || (0, exports.getPool)(poolDummy.basePool).isFake || poolDummy.isCrypto)) {
|
|
204
|
-
|
|
219
|
+
if (poolDummy.isCrypto) {
|
|
220
|
+
Object.assign(Pool.prototype, swapMixins_1.swapCryptoMetaFactoryMixin);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
Object.assign(Pool.prototype, swapMixins_1.swapMetaFactoryMixin);
|
|
224
|
+
}
|
|
205
225
|
}
|
|
206
226
|
else {
|
|
207
227
|
Object.assign(Pool.prototype, swapMixins_1.swapMixin);
|
package/lib/router.js
CHANGED
|
@@ -315,6 +315,13 @@ var filterRoutes = function (routes, inputCoinAddress, sortFn) {
|
|
|
315
315
|
};
|
|
316
316
|
var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.steps.length - b.steps.length; };
|
|
317
317
|
var sortByLength = function (a, b) { return a.steps.length - b.steps.length || b.minTvl - a.minTvl || b.totalTvl - a.totalTvl; };
|
|
318
|
+
// TODO REMOVE IT!!!
|
|
319
|
+
var filterMaticFactory83Route = function (routes) {
|
|
320
|
+
return routes
|
|
321
|
+
.filter(function (r) {
|
|
322
|
+
return !(r.steps.length === 1 && r.steps[0].poolId === "factory-crypto-83" && r.steps[0].inputCoinAddress === curve_1.curve.constants.NATIVE_TOKEN.address);
|
|
323
|
+
});
|
|
324
|
+
};
|
|
318
325
|
// Inspired by Dijkstra's algorithm
|
|
319
326
|
var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
320
327
|
var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_2, inCoin, routes;
|
|
@@ -548,6 +555,9 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
|
|
|
548
555
|
return [3 /*break*/, 2];
|
|
549
556
|
case 8:
|
|
550
557
|
routes = __spreadArray(__spreadArray([], ((_q = routesByTvl[outputCoinAddress]) !== null && _q !== void 0 ? _q : []), true), ((_r = routesByLength[outputCoinAddress]) !== null && _r !== void 0 ? _r : []), true);
|
|
558
|
+
// TODO REMOVE IT!!!
|
|
559
|
+
if (curve_1.curve.chainId === 137)
|
|
560
|
+
routes = filterMaticFactory83Route(routes);
|
|
551
561
|
return [2 /*return*/, routes.map(function (r) { return r.steps; })];
|
|
552
562
|
}
|
|
553
563
|
});
|
package/lib/utils.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (num
|
|
|
27
27
|
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string) => Promise<string[]>;
|
|
28
28
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
29
29
|
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
|
30
|
+
export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
|
|
30
31
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
31
32
|
export declare const getUsdRate: (coin: string) => Promise<number>;
|
|
32
33
|
export declare const getTVL: (chainId?: number) => Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
62
|
+
exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getCrvApyFromApi = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
@@ -449,6 +449,37 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
449
449
|
});
|
|
450
450
|
}); };
|
|
451
451
|
exports._getUsdPricesFromApi = _getUsdPricesFromApi;
|
|
452
|
+
var _getCrvApyFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
453
|
+
var network, promises, allTypesExtendedPoolData, apyDict, _i, allTypesExtendedPoolData_2, extendedPoolData, _a, _b, pool;
|
|
454
|
+
var _c, _d;
|
|
455
|
+
return __generator(this, function (_e) {
|
|
456
|
+
switch (_e.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
network = curve_1.curve.constants.NETWORK_NAME;
|
|
459
|
+
promises = [
|
|
460
|
+
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
461
|
+
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
462
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory"),
|
|
463
|
+
(0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
|
|
464
|
+
];
|
|
465
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
466
|
+
case 1:
|
|
467
|
+
allTypesExtendedPoolData = _e.sent();
|
|
468
|
+
apyDict = {};
|
|
469
|
+
for (_i = 0, allTypesExtendedPoolData_2 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_2.length; _i++) {
|
|
470
|
+
extendedPoolData = allTypesExtendedPoolData_2[_i];
|
|
471
|
+
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
472
|
+
pool = _b[_a];
|
|
473
|
+
if (pool.gaugeAddress) {
|
|
474
|
+
apyDict[pool.gaugeAddress] = [(_c = pool.gaugeCrvApy[0]) !== null && _c !== void 0 ? _c : 0, (_d = pool.gaugeCrvApy[1]) !== null && _d !== void 0 ? _d : 0];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return [2 /*return*/, apyDict];
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}); };
|
|
482
|
+
exports._getCrvApyFromApi = _getCrvApyFromApi;
|
|
452
483
|
var _usdRatesCache = {};
|
|
453
484
|
var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
454
485
|
var pricesFromApi, chainName, nativeTokenName, url, response;
|