@curvefi/api 1.25.2 → 2.0.0
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 +775 -589
- package/docs/v1/README.md +916 -0
- package/lib/boosting.d.ts +12 -12
- package/lib/boosting.js +23 -23
- package/lib/constants/abis/{json/2pool → 2pool}/swap.json +0 -0
- package/lib/constants/abis/{json/3pool → 3pool}/swap.json +0 -0
- package/lib/constants/abis/{json/4pool → 4pool}/swap.json +0 -0
- package/lib/constants/abis/{json/ERC20.json → ERC20.json} +0 -0
- package/lib/constants/abis/{json/aave → aave}/rewards.json +0 -0
- package/lib/constants/abis/{json/aave → aave}/swap.json +0 -0
- package/lib/constants/abis/{json/address_provider.json → address_provider.json} +0 -0
- package/lib/constants/abis/{json/ankreth → ankreth}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/ankreth → ankreth}/swap.json +0 -0
- package/lib/constants/abis/{json/atricrypto3 → atricrypto3}/swap.json +0 -0
- package/lib/constants/abis/{json/atricrypto3 → atricrypto3}/zap.json +0 -0
- package/lib/constants/abis/{json/bbtc → bbtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/bbtc → bbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/busd → busd}/deposit.json +0 -0
- package/lib/constants/abis/{json/busd → busd}/swap.json +0 -0
- package/lib/constants/abis/{json/cERC20.json → cERC20.json} +0 -0
- package/lib/constants/abis/{json/compound → compound}/deposit.json +0 -0
- package/lib/constants/abis/{json/compound → compound}/swap.json +0 -0
- package/lib/constants/abis/{json/crveth → crveth}/swap.json +0 -0
- package/lib/constants/abis/{json/deposit_and_stake.json → deposit_and_stake.json} +0 -0
- package/lib/constants/abis/{json/dusd → dusd}/deposit.json +0 -0
- package/lib/constants/abis/{json/dusd → dusd}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/dusd → dusd}/swap.json +0 -0
- package/lib/constants/abis/{json/eurs → eurs}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/eurs → eurs}/swap.json +0 -0
- package/lib/constants/abis/{json/eursusd → eursusd}/swap.json +0 -0
- package/lib/constants/abis/{json/eurt → eurt}/swap.json +0 -0
- package/lib/constants/abis/{json/eurtusd → eurtusd}/deposit.json +0 -0
- package/lib/constants/abis/{json/eurtusd → eurtusd}/swap.json +0 -0
- package/lib/constants/abis/{json/factory-crypto → factory-crypto}/factory-crypto-pool-2.json +0 -0
- package/lib/constants/abis/{json/factory-crypto.json → factory-crypto.json} +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/DepositZapMetaBtcPolygon.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/DepositZapMetaUsdPolygon.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTC.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCBalances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCBalancesRen.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCRen.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaUSD.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaUSDBalances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Balances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Basic.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2ETH.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Optimized.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Balances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Basic.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3ETH.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Optimized.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Balances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Basic.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4ETH.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Optimized.json +0 -0
- package/lib/constants/abis/{json/factory.json → factory.json} +0 -0
- package/lib/constants/abis/{json/factoryPools → factoryPools}/deposit.json +0 -0
- package/lib/constants/abis/{json/factoryPools → factoryPools}/rewards.json +0 -0
- package/lib/constants/abis/{json/factoryPools → factoryPools}/swap.json +0 -0
- package/lib/constants/abis/{json/gauge.json → gauge.json} +0 -0
- package/lib/constants/abis/{json/gauge_factory.json → gauge_factory.json} +0 -0
- package/lib/constants/abis/{json/gauge_rewards_only.json → gauge_rewards_only.json} +0 -0
- package/lib/constants/abis/{json/gauge_synthetix.json → gauge_synthetix.json} +0 -0
- package/lib/constants/abis/{json/gauge_v2.json → gauge_v2.json} +0 -0
- package/lib/constants/abis/{json/gauge_v3.json → gauge_v3.json} +0 -0
- package/lib/constants/abis/{json/gauge_v4.json → gauge_v4.json} +0 -0
- package/lib/constants/abis/{json/gauge_v5.json → gauge_v5.json} +0 -0
- package/lib/constants/abis/{json/gaugecontroller.json → gaugecontroller.json} +0 -0
- package/lib/constants/abis/{json/gusd → gusd}/deposit.json +0 -0
- package/lib/constants/abis/{json/gusd → gusd}/swap.json +0 -0
- package/lib/constants/abis/{json/hbtc → hbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/husd → husd}/deposit.json +0 -0
- package/lib/constants/abis/{json/husd → husd}/swap.json +0 -0
- package/lib/constants/abis/{json/ib → ib}/swap.json +0 -0
- package/lib/constants/abis/{json/iearn → iearn}/deposit.json +0 -0
- package/lib/constants/abis/{json/iearn → iearn}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/iearn → iearn}/swap.json +0 -0
- package/lib/constants/abis/{json/link → link}/swap.json +0 -0
- package/lib/constants/abis/{json/minter.json → minter.json} +0 -0
- package/lib/constants/abis/{json/musd → musd}/deposit.json +0 -0
- package/lib/constants/abis/{json/musd → musd}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/musd → musd}/swap.json +0 -0
- package/lib/constants/abis/{json/obtc → obtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/obtc → obtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/obtc → obtc}/swap.json +0 -0
- package/lib/constants/abis/{json/paave → paave}/rewards.json +0 -0
- package/lib/constants/abis/{json/pax → pax}/deposit.json +0 -0
- package/lib/constants/abis/{json/pax → pax}/swap.json +0 -0
- package/lib/constants/abis/{json/pbtc → pbtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/pbtc → pbtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/pbtc → pbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/rai → rai}/deposit.json +0 -0
- package/lib/constants/abis/{json/rai → rai}/swap.json +0 -0
- package/lib/constants/abis/{json/registry_exchange.json → registry_exchange.json} +0 -0
- package/lib/constants/abis/{json/ren → ren}/swap.json +0 -0
- package/lib/constants/abis/{json/ren-polygon → ren-polygon}/swap.json +0 -0
- package/lib/constants/abis/{json/reth → reth}/swap.json +0 -0
- package/lib/constants/abis/{json/router.json → router.json} +0 -0
- package/lib/constants/abis/{json/rsv → rsv}/deposit.json +0 -0
- package/lib/constants/abis/{json/rsv → rsv}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/rsv → rsv}/swap.json +0 -0
- package/lib/constants/abis/{json/saave → saave}/swap.json +0 -0
- package/lib/constants/abis/{json/sbtc → sbtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/sbtc → sbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/seth → seth}/swap.json +0 -0
- package/lib/constants/abis/{json/steth → steth}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/steth → steth}/swap.json +0 -0
- package/lib/constants/abis/{json/streamer.json → streamer.json} +0 -0
- package/lib/constants/abis/{json/susdv2 → susdv2}/deposit.json +0 -0
- package/lib/constants/abis/{json/susdv2 → susdv2}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/susdv2 → susdv2}/swap.json +0 -0
- package/lib/constants/abis/{json/tbtc → tbtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/tbtc → tbtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/tbtc → tbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/tricrypto2 → tricrypto2}/deposit.json +0 -0
- package/lib/constants/abis/{json/tricrypto2 → tricrypto2}/swap.json +0 -0
- package/lib/constants/abis/{json/usdk → usdk}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdk → usdk}/swap.json +0 -0
- package/lib/constants/abis/{json/usdn → usdn}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdn → usdn}/swap.json +0 -0
- package/lib/constants/abis/{json/usdp → usdp}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdp → usdp}/swap.json +0 -0
- package/lib/constants/abis/{json/usdt → usdt}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdt → usdt}/swap.json +0 -0
- package/lib/constants/abis/{json/ust → ust}/deposit.json +0 -0
- package/lib/constants/abis/{json/ust → ust}/swap.json +0 -0
- package/lib/constants/abis/{json/votingescrow.json → votingescrow.json} +0 -0
- package/lib/constants/abis/{json/yERC20.json → yERC20.json} +0 -0
- package/lib/constants/aliases.d.ts +2 -24
- package/lib/constants/aliases.js +5 -4
- package/lib/constants/{coins-ethereum.d.ts → coins/ethereum.d.ts} +0 -9
- package/lib/constants/{coins-ethereum.js → coins/ethereum.js} +12 -23
- package/lib/constants/{coins-polygon.d.ts → coins/polygon.d.ts} +0 -12
- package/lib/constants/{coins-polygon.js → coins/polygon.js} +8 -20
- package/lib/constants/pools/ethereum.d.ts +2 -0
- package/lib/constants/{abis/abis-ethereum.js → pools/ethereum.js} +517 -1012
- package/lib/constants/pools/index.d.ts +3 -0
- package/lib/constants/pools/index.js +7 -0
- package/lib/constants/pools/polygon.d.ts +4 -0
- package/lib/constants/{abis/abis-polygon.js → pools/polygon.js} +52 -80
- package/lib/constants/utils.d.ts +5 -0
- package/lib/constants/utils.js +69 -0
- package/lib/curve.d.ts +10 -32
- package/lib/curve.js +188 -232
- package/lib/external-api.d.ts +3 -2
- package/lib/external-api.js +18 -1
- package/lib/factory/constants.d.ts +15 -15
- package/lib/factory/constants.js +19 -19
- package/lib/factory/factory-api.d.ts +2 -2
- package/lib/factory/factory-api.js +34 -49
- package/lib/factory/factory-crypto.d.ts +2 -2
- package/lib/factory/factory-crypto.js +23 -31
- package/lib/factory/factory.d.ts +2 -2
- package/lib/factory/factory.js +53 -66
- package/lib/index.d.ts +36 -53
- package/lib/index.js +27 -35
- package/lib/interfaces.d.ts +25 -67
- package/lib/pools/PoolTemplate.d.ts +210 -0
- package/lib/pools/PoolTemplate.js +2292 -0
- package/lib/pools/index.d.ts +3 -0
- package/lib/pools/index.js +7 -0
- package/lib/pools/mixins/common.d.ts +3 -0
- package/lib/pools/mixins/common.js +77 -0
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +5 -0
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +145 -0
- package/lib/pools/mixins/depositBonusMixins.d.ts +5 -0
- package/lib/pools/mixins/depositBonusMixins.js +164 -0
- package/lib/pools/mixins/depositMixins.d.ts +5 -0
- package/lib/pools/mixins/depositMixins.js +373 -0
- package/lib/pools/mixins/depositWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/depositWrappedMixins.js +243 -0
- package/lib/pools/mixins/poolBalancesMixin.d.ts +4 -0
- package/lib/pools/mixins/poolBalancesMixin.js +129 -0
- package/lib/pools/mixins/swapMixins.d.ts +4 -0
- package/lib/pools/mixins/swapMixins.js +313 -0
- package/lib/pools/mixins/swapWrappedMixins.d.ts +4 -0
- package/lib/pools/mixins/swapWrappedMixins.js +297 -0
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +6 -0
- package/lib/pools/mixins/withdrawExpectedMixins.js +164 -0
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawImbalanceMixins.js +348 -0
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +207 -0
- package/lib/pools/mixins/withdrawMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawMixins.js +347 -0
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +104 -0
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawOneCoinMixins.js +347 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +72 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +205 -0
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawWrappedMixins.js +206 -0
- package/lib/pools/poolConstructor.d.ts +2 -0
- package/lib/pools/poolConstructor.js +228 -0
- package/lib/pools/utils.d.ts +4 -0
- package/lib/pools/utils.js +85 -0
- package/lib/router.d.ts +12 -0
- package/lib/router.js +624 -0
- package/lib/utils.d.ts +10 -16
- package/lib/utils.js +33 -126
- package/package.json +1 -1
- package/lib/constants/abis/abis-ethereum.d.ts +0 -4
- package/lib/constants/abis/abis-polygon.d.ts +0 -4
- package/lib/constants/abis/json/aRewards.json +0 -1
- package/lib/constants/abis/json/compound/migration.json +0 -57
- package/lib/constants/abis/json/compound/oldSwap.json +0 -688
- package/lib/constants/abis/json/ren/adapter.json +0 -1
- package/lib/constants/abis/json/sbtc/adapter.json +0 -1
- package/lib/pools.d.ts +0 -267
- package/lib/pools.js +0 -4752
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.withdrawWrapped3argsMixin = exports.withdrawWrapped2argsMixin = void 0;
|
|
51
|
+
var ethers_1 = require("ethers");
|
|
52
|
+
var curve_1 = require("../../curve");
|
|
53
|
+
var utils_1 = require("../../utils");
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
function _withdrawWrappedCheck(lpTokenAmount) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var lpTokenBalance;
|
|
58
|
+
return __generator(this, function (_b) {
|
|
59
|
+
switch (_b.label) {
|
|
60
|
+
case 0: return [4 /*yield*/, this.wallet.lpTokenBalances()];
|
|
61
|
+
case 1:
|
|
62
|
+
lpTokenBalance = (_b.sent())['lpToken'];
|
|
63
|
+
if (Number(lpTokenBalance) < Number(lpTokenAmount)) {
|
|
64
|
+
throw Error("Not enough LP tokens. Actual: ".concat(lpTokenBalance, ", required: ").concat(lpTokenAmount));
|
|
65
|
+
}
|
|
66
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
67
|
+
case 2:
|
|
68
|
+
_b.sent();
|
|
69
|
+
return [2 /*return*/, (0, utils_1.parseUnits)(lpTokenAmount)];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function _withdrawWrappedMinAmounts(_lpTokenAmount, slippage) {
|
|
75
|
+
if (slippage === void 0) { slippage = 0.5; }
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var expectedAmounts, _expectedAmounts, minRecvAmountsBN;
|
|
78
|
+
var _this = this;
|
|
79
|
+
return __generator(this, function (_b) {
|
|
80
|
+
switch (_b.label) {
|
|
81
|
+
case 0: return [4 /*yield*/, this.withdrawWrappedExpected(ethers_1.ethers.utils.formatUnits(_lpTokenAmount))];
|
|
82
|
+
case 1:
|
|
83
|
+
expectedAmounts = _b.sent();
|
|
84
|
+
_expectedAmounts = expectedAmounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, _this.wrappedDecimals[i]); });
|
|
85
|
+
minRecvAmountsBN = _expectedAmounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, _this.wrappedDecimals[i]).times(100 - slippage).div(100); });
|
|
86
|
+
return [2 /*return*/, minRecvAmountsBN.map(function (a, i) { return (0, utils_1.fromBN)(a, _this.wrappedDecimals[i]); })];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
exports.withdrawWrapped2argsMixin = {
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
_withdrawWrapped: function (_lpTokenAmount, slippage, estimateGas) {
|
|
95
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var _minAmounts, contract, gas, gasLimit;
|
|
98
|
+
return __generator(this, function (_b) {
|
|
99
|
+
switch (_b.label) {
|
|
100
|
+
case 0: return [4 /*yield*/, _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage)];
|
|
101
|
+
case 1:
|
|
102
|
+
_minAmounts = _b.sent();
|
|
103
|
+
contract = curve_1.curve.contracts[this.address].contract;
|
|
104
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
|
|
105
|
+
case 2:
|
|
106
|
+
gas = _b.sent();
|
|
107
|
+
if (estimateGas)
|
|
108
|
+
return [2 /*return*/, gas.toNumber()];
|
|
109
|
+
gasLimit = gas.mul(130).div(100);
|
|
110
|
+
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
111
|
+
case 3: return [2 /*return*/, (_b.sent()).hash];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
withdrawWrappedEstimateGas: function (lpTokenAmount) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var _lpTokenAmount;
|
|
119
|
+
return __generator(this, function (_b) {
|
|
120
|
+
switch (_b.label) {
|
|
121
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
122
|
+
case 1:
|
|
123
|
+
_lpTokenAmount = _b.sent();
|
|
124
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, 0.1, true)];
|
|
125
|
+
case 2:
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
return [2 /*return*/, _b.sent()];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
withdrawWrapped: function (lpTokenAmount, slippage) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var _lpTokenAmount;
|
|
135
|
+
return __generator(this, function (_b) {
|
|
136
|
+
switch (_b.label) {
|
|
137
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
138
|
+
case 1:
|
|
139
|
+
_lpTokenAmount = _b.sent();
|
|
140
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, slippage)];
|
|
141
|
+
case 2:
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
return [2 /*return*/, _b.sent()];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
exports.withdrawWrapped3argsMixin = {
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
_withdrawWrapped: function (_lpTokenAmount, slippage, estimateGas) {
|
|
153
|
+
if (estimateGas === void 0) { estimateGas = false; }
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var _minAmounts, contract, gas, gasLimit;
|
|
156
|
+
return __generator(this, function (_b) {
|
|
157
|
+
switch (_b.label) {
|
|
158
|
+
case 0: return [4 /*yield*/, _withdrawWrappedMinAmounts.call(this, _lpTokenAmount, slippage)];
|
|
159
|
+
case 1:
|
|
160
|
+
_minAmounts = _b.sent();
|
|
161
|
+
contract = curve_1.curve.contracts[this.address].contract;
|
|
162
|
+
return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, false, curve_1.curve.constantOptions)];
|
|
163
|
+
case 2:
|
|
164
|
+
gas = _b.sent();
|
|
165
|
+
if (estimateGas)
|
|
166
|
+
return [2 /*return*/, gas.toNumber()];
|
|
167
|
+
gasLimit = gas.mul(130).div(100);
|
|
168
|
+
return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, false, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
169
|
+
case 3: return [2 /*return*/, (_b.sent()).hash];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
withdrawWrappedEstimateGas: function (lpTokenAmount) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
+
var _lpTokenAmount;
|
|
177
|
+
return __generator(this, function (_b) {
|
|
178
|
+
switch (_b.label) {
|
|
179
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
180
|
+
case 1:
|
|
181
|
+
_lpTokenAmount = _b.sent();
|
|
182
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, 0.1, true)];
|
|
183
|
+
case 2:
|
|
184
|
+
// @ts-ignore
|
|
185
|
+
return [2 /*return*/, _b.sent()];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
withdrawWrapped: function (lpTokenAmount, slippage) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
192
|
+
var _lpTokenAmount;
|
|
193
|
+
return __generator(this, function (_b) {
|
|
194
|
+
switch (_b.label) {
|
|
195
|
+
case 0: return [4 /*yield*/, _withdrawWrappedCheck.call(this, lpTokenAmount)];
|
|
196
|
+
case 1:
|
|
197
|
+
_lpTokenAmount = _b.sent();
|
|
198
|
+
return [4 /*yield*/, this._withdrawWrapped(_lpTokenAmount, slippage)];
|
|
199
|
+
case 2:
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
return [2 /*return*/, _b.sent()];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getPool = void 0;
|
|
19
|
+
var curve_1 = require("../curve");
|
|
20
|
+
var PoolTemplate_1 = require("./PoolTemplate");
|
|
21
|
+
var poolBalancesMixin_1 = require("./mixins/poolBalancesMixin");
|
|
22
|
+
var depositBalancedAmountsMixins_1 = require("./mixins/depositBalancedAmountsMixins");
|
|
23
|
+
var depositBonusMixins_1 = require("./mixins/depositBonusMixins");
|
|
24
|
+
var depositMixins_1 = require("./mixins/depositMixins");
|
|
25
|
+
var depositWrappedMixins_1 = require("./mixins/depositWrappedMixins");
|
|
26
|
+
var withdrawExpectedMixins_1 = require("./mixins/withdrawExpectedMixins");
|
|
27
|
+
var withdrawMixins_1 = require("./mixins/withdrawMixins");
|
|
28
|
+
var withdrawWrappedMixins_1 = require("./mixins/withdrawWrappedMixins");
|
|
29
|
+
var withdrawImbalanceMixins_1 = require("./mixins/withdrawImbalanceMixins");
|
|
30
|
+
var withdrawImbalanceWrappedMixins_1 = require("./mixins/withdrawImbalanceWrappedMixins");
|
|
31
|
+
var withdrawOneCoinExpectedMixins_1 = require("./mixins/withdrawOneCoinExpectedMixins");
|
|
32
|
+
var withdrawOneCoinMixins_1 = require("./mixins/withdrawOneCoinMixins");
|
|
33
|
+
var withdrawOneCoinWrappedExpectedMixins_1 = require("./mixins/withdrawOneCoinWrappedExpectedMixins");
|
|
34
|
+
var withdrawOneCoinWrappedMixins_1 = require("./mixins/withdrawOneCoinWrappedMixins");
|
|
35
|
+
var swapMixins_1 = require("./mixins/swapMixins");
|
|
36
|
+
var swapWrappedMixins_1 = require("./mixins/swapWrappedMixins");
|
|
37
|
+
var getPool = function (poolId) {
|
|
38
|
+
var poolDummy = new PoolTemplate_1.PoolTemplate(poolId);
|
|
39
|
+
var Pool = /** @class */ (function (_super) {
|
|
40
|
+
__extends(Pool, _super);
|
|
41
|
+
function Pool() {
|
|
42
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
43
|
+
}
|
|
44
|
+
return Pool;
|
|
45
|
+
}(PoolTemplate_1.PoolTemplate));
|
|
46
|
+
// statsBalances
|
|
47
|
+
if (poolId === "atricrypto3") {
|
|
48
|
+
Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesAtricrypto3Mixin);
|
|
49
|
+
}
|
|
50
|
+
else if (poolDummy.isMeta) {
|
|
51
|
+
Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesMetaMixin);
|
|
52
|
+
}
|
|
53
|
+
else if (poolDummy.useLending.reduce(function (x, y) { return x || y; })) {
|
|
54
|
+
Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesLendingMixin);
|
|
55
|
+
}
|
|
56
|
+
// depositBalancedAmounts
|
|
57
|
+
if (poolDummy.isCrypto) {
|
|
58
|
+
Object.assign(Pool.prototype, depositBalancedAmountsMixins_1.depositBalancedAmountsCryptoMixin);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
Object.assign(Pool.prototype, depositBalancedAmountsMixins_1.depositBalancedAmountsMixin);
|
|
62
|
+
}
|
|
63
|
+
// depositWrappedBalancedAmounts
|
|
64
|
+
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
65
|
+
if (poolDummy.isCrypto) {
|
|
66
|
+
Object.assign(Pool.prototype, depositBalancedAmountsMixins_1.depositWrappedBalancedAmountsCryptoMixin);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
Object.assign(Pool.prototype, depositBalancedAmountsMixins_1.depositWrappedBalancedAmountsMixin);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// depositBonus and depositWrappedBonus
|
|
73
|
+
if (poolDummy.isCrypto) {
|
|
74
|
+
Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusCryptoMixin);
|
|
75
|
+
if (!poolDummy.isFake)
|
|
76
|
+
Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusCryptoMixin);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusMixin);
|
|
80
|
+
if (!poolDummy.isFake)
|
|
81
|
+
Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusMixin);
|
|
82
|
+
}
|
|
83
|
+
// deposit and depositEstimateGas
|
|
84
|
+
if (poolDummy.isMetaFactory) {
|
|
85
|
+
Object.assign(Pool.prototype, depositMixins_1.depositMetaFactoryMixin);
|
|
86
|
+
}
|
|
87
|
+
else if (poolDummy.zap && poolId !== 'susd') {
|
|
88
|
+
Object.assign(Pool.prototype, depositMixins_1.depositZapMixin);
|
|
89
|
+
}
|
|
90
|
+
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
91
|
+
Object.assign(Pool.prototype, depositMixins_1.depositLendingOrCryptoMixin);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
Object.assign(Pool.prototype, depositMixins_1.depositPlainMixin);
|
|
95
|
+
}
|
|
96
|
+
// depositWrapped and depositWrappedEstimateGas
|
|
97
|
+
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
98
|
+
Object.assign(Pool.prototype, depositWrappedMixins_1.depositWrapped3argsMixin);
|
|
99
|
+
}
|
|
100
|
+
else if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
101
|
+
Object.assign(Pool.prototype, depositWrappedMixins_1.depositWrapped2argsMixin);
|
|
102
|
+
}
|
|
103
|
+
// withdrawExpected
|
|
104
|
+
if (poolId === 'atricrypto3') {
|
|
105
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedAtricrypto3Mixin);
|
|
106
|
+
}
|
|
107
|
+
else if (poolDummy.isMeta) {
|
|
108
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedMetaMixin);
|
|
109
|
+
}
|
|
110
|
+
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
111
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedLendingOrCryptoMixin);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedMixin);
|
|
115
|
+
}
|
|
116
|
+
// withdraw and withdrawEstimateGas
|
|
117
|
+
if (poolDummy.isMetaFactory) {
|
|
118
|
+
Object.assign(Pool.prototype, withdrawMixins_1.withdrawMetaFactoryMixin);
|
|
119
|
+
}
|
|
120
|
+
else if (poolDummy.zap && poolId !== 'susd') {
|
|
121
|
+
Object.assign(Pool.prototype, withdrawMixins_1.withdrawZapMixin);
|
|
122
|
+
}
|
|
123
|
+
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
124
|
+
Object.assign(Pool.prototype, withdrawMixins_1.withdrawLendingOrCryptoMixin);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
Object.assign(Pool.prototype, withdrawMixins_1.withdrawPlainMixin);
|
|
128
|
+
}
|
|
129
|
+
// withdrawWrapped and withdrawWrappedEstimateGas
|
|
130
|
+
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
131
|
+
Object.assign(Pool.prototype, withdrawWrappedMixins_1.withdrawWrapped3argsMixin);
|
|
132
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawWrappedExpectedMixin);
|
|
133
|
+
}
|
|
134
|
+
else if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
135
|
+
Object.assign(Pool.prototype, withdrawWrappedMixins_1.withdrawWrapped2argsMixin);
|
|
136
|
+
Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawWrappedExpectedMixin);
|
|
137
|
+
}
|
|
138
|
+
// withdrawImbalance and withdrawImbalanceEstimateGas
|
|
139
|
+
if (!poolDummy.isCrypto) {
|
|
140
|
+
if (poolDummy.isMetaFactory) {
|
|
141
|
+
Object.assign(Pool.prototype, withdrawImbalanceMixins_1.withdrawImbalanceMetaFactoryMixin);
|
|
142
|
+
}
|
|
143
|
+
else if (poolDummy.zap && poolId !== 'susd') {
|
|
144
|
+
Object.assign(Pool.prototype, withdrawImbalanceMixins_1.withdrawImbalanceZapMixin);
|
|
145
|
+
}
|
|
146
|
+
else if (poolDummy.isLending) {
|
|
147
|
+
Object.assign(Pool.prototype, withdrawImbalanceMixins_1.withdrawImbalanceLendingMixin);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
Object.assign(Pool.prototype, withdrawImbalanceMixins_1.withdrawImbalancePlainMixin);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// withdrawImbalanceWrapped and withdrawImbalanceWrappedEstimateGas
|
|
154
|
+
if (!poolDummy.isCrypto) {
|
|
155
|
+
if (poolDummy.isLending && !poolDummy.zap) {
|
|
156
|
+
Object.assign(Pool.prototype, withdrawImbalanceWrappedMixins_1.withdrawImbalanceWrapped3argsMixin);
|
|
157
|
+
}
|
|
158
|
+
else if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
159
|
+
Object.assign(Pool.prototype, withdrawImbalanceWrappedMixins_1.withdrawImbalanceWrapped2argsMixin);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// withdrawOneCoinExpected
|
|
163
|
+
if (poolDummy.isMetaFactory) {
|
|
164
|
+
Object.assign(Pool.prototype, withdrawOneCoinExpectedMixins_1.withdrawOneCoinExpectedMetaFactoryMixin);
|
|
165
|
+
}
|
|
166
|
+
else if ((!poolDummy.isCrypto && poolDummy.zap) || poolDummy.isMeta) { // including susd
|
|
167
|
+
Object.assign(Pool.prototype, withdrawOneCoinExpectedMixins_1.withdrawOneCoinExpectedZapMixin);
|
|
168
|
+
}
|
|
169
|
+
else if (poolId === 'ib') {
|
|
170
|
+
Object.assign(Pool.prototype, withdrawOneCoinExpectedMixins_1.withdrawOneCoinExpected3argsMixin);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
Object.assign(Pool.prototype, withdrawOneCoinExpectedMixins_1.withdrawOneCoinExpected2argsMixin);
|
|
174
|
+
}
|
|
175
|
+
// withdrawOneCoin and withdrawOneCoinEstimateGas
|
|
176
|
+
if (poolDummy.isMetaFactory) {
|
|
177
|
+
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinMetaFactoryMixin);
|
|
178
|
+
}
|
|
179
|
+
else if (poolDummy.zap) { // including susd
|
|
180
|
+
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinZapMixin);
|
|
181
|
+
}
|
|
182
|
+
else if (poolDummy.isLending || poolDummy.isCrypto) {
|
|
183
|
+
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinLendingOrCryptoMixin);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
Object.assign(Pool.prototype, withdrawOneCoinMixins_1.withdrawOneCoinPlainMixin);
|
|
187
|
+
}
|
|
188
|
+
// withdrawOneCoinWrappedExpected
|
|
189
|
+
if (!poolDummy.isPlain && !poolDummy.isFake && !(poolDummy.isLending && poolDummy.zap)) {
|
|
190
|
+
if (poolId === "ib") {
|
|
191
|
+
Object.assign(Pool.prototype, withdrawOneCoinWrappedExpectedMixins_1.withdrawOneCoinWrappedExpected3argsMixin);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
Object.assign(Pool.prototype, withdrawOneCoinWrappedExpectedMixins_1.withdrawOneCoinWrappedExpected2argsMixin);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// withdrawOneCoinWrapped and withdrawOneCoinWrappedEstimateGas
|
|
198
|
+
if (!poolDummy.isPlain && !poolDummy.isFake && !(poolDummy.isLending && poolDummy.zap)) {
|
|
199
|
+
if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
|
|
200
|
+
Object.assign(Pool.prototype, withdrawOneCoinWrappedMixins_1.withdrawOneCoinWrappedLendingOrCryptoMixin);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
Object.assign(Pool.prototype, withdrawOneCoinWrappedMixins_1.withdrawOneCoinWrappedMixin);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// swap and swapEstimateGas
|
|
207
|
+
if (poolId === 'tricrypto2') {
|
|
208
|
+
Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
|
|
209
|
+
}
|
|
210
|
+
else if (curve_1.curve.chainId === 137 && poolDummy.isMetaFactory) {
|
|
211
|
+
Object.assign(Pool.prototype, swapMixins_1.swapMetaFactoryMixin);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
Object.assign(Pool.prototype, swapMixins_1.swapMixin);
|
|
215
|
+
}
|
|
216
|
+
// swapWrapped and swapWrappedEstimateGas
|
|
217
|
+
if (!poolDummy.isPlain && !poolDummy.isFake) {
|
|
218
|
+
Object.assign(Pool.prototype, swapWrappedMixins_1.swapWrappedExpectedAndApproveMixin);
|
|
219
|
+
if (poolId === 'tricrypto2') {
|
|
220
|
+
Object.assign(Pool.prototype, swapWrappedMixins_1.swapWrappedTricrypto2Mixin);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
Object.assign(Pool.prototype, swapWrappedMixins_1.swapWrappedMixin);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return new Pool(poolId);
|
|
227
|
+
};
|
|
228
|
+
exports.getPool = getPool;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.getUserPoolList = exports.getCryptoFactoryPoolList = exports.getFactoryPoolList = exports.getPoolList = void 0;
|
|
49
|
+
var curve_1 = require("../curve");
|
|
50
|
+
var poolConstructor_1 = require("./poolConstructor");
|
|
51
|
+
var getPoolList = function () { return Object.keys(curve_1.curve.constants.POOLS_DATA); };
|
|
52
|
+
exports.getPoolList = getPoolList;
|
|
53
|
+
var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
|
|
54
|
+
exports.getFactoryPoolList = getFactoryPoolList;
|
|
55
|
+
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
56
|
+
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
57
|
+
var getUserPoolList = function (address) { return __awaiter(void 0, void 0, void 0, function () {
|
|
58
|
+
var poolNames, promises, _i, poolNames_1, poolName, pool, userPoolList, balances, i;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (!address)
|
|
63
|
+
address = curve_1.curve.signerAddress;
|
|
64
|
+
address = address;
|
|
65
|
+
poolNames = __spreadArray(__spreadArray(__spreadArray([], (0, exports.getPoolList)(), true), (0, exports.getFactoryPoolList)(), true), (0, exports.getCryptoFactoryPoolList)(), true);
|
|
66
|
+
promises = [];
|
|
67
|
+
for (_i = 0, poolNames_1 = poolNames; _i < poolNames_1.length; _i++) {
|
|
68
|
+
poolName = poolNames_1[_i];
|
|
69
|
+
pool = (0, poolConstructor_1.getPool)(poolName);
|
|
70
|
+
promises.push(pool.wallet.lpTokenBalances(address)); // TODO optimization
|
|
71
|
+
}
|
|
72
|
+
userPoolList = [];
|
|
73
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
74
|
+
case 1:
|
|
75
|
+
balances = (_a.sent()).map(function (lpBalance) { return Object.values(lpBalance).map(Number).reduce(function (a, b) { return a + b; }); });
|
|
76
|
+
for (i = 0; i < poolNames.length; i++) {
|
|
77
|
+
if (balances[i] > 0) {
|
|
78
|
+
userPoolList.push(poolNames[i]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return [2 /*return*/, userPoolList];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); };
|
|
85
|
+
exports.getUserPoolList = getUserPoolList;
|
package/lib/router.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IRouteStep } from "./interfaces";
|
|
2
|
+
export declare const _findAllRoutes: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
|
|
3
|
+
export declare const getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<{
|
|
4
|
+
route: IRouteStep[];
|
|
5
|
+
output: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const swapExpected: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<string>;
|
|
8
|
+
export declare const swapIsApproved: (inputCoin: string, amount: number | string) => Promise<boolean>;
|
|
9
|
+
export declare const swapApproveEstimateGas: (inputCoin: string, amount: number | string) => Promise<number>;
|
|
10
|
+
export declare const swapApprove: (inputCoin: string, amount: number | string) => Promise<string[]>;
|
|
11
|
+
export declare const swapEstimateGas: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number>;
|
|
12
|
+
export declare const swap: (inputCoin: string, outputCoin: string, amount: number | string, slippage?: number) => Promise<string>;
|