@curvefi/api 2.31.0 → 2.31.1
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 +137 -402
- package/lib/constants/aliases.d.ts +11 -11
- package/lib/constants/aliases.js +12 -15
- package/lib/constants/coins/arbitrum.js +6 -9
- package/lib/constants/coins/aurora.js +6 -9
- package/lib/constants/coins/avalanche.js +7 -10
- package/lib/constants/coins/celo.js +6 -9
- package/lib/constants/coins/ethereum.js +10 -13
- package/lib/constants/coins/fantom.js +8 -11
- package/lib/constants/coins/kava.js +6 -9
- package/lib/constants/coins/moonbeam.js +6 -9
- package/lib/constants/coins/optimism.js +6 -9
- package/lib/constants/coins/polygon.js +7 -10
- package/lib/constants/coins/xdai.js +6 -9
- package/lib/constants/pools/arbitrum.d.ts +2 -4
- package/lib/constants/pools/arbitrum.js +22 -28
- package/lib/constants/pools/aurora.d.ts +2 -4
- package/lib/constants/pools/aurora.js +6 -12
- package/lib/constants/pools/avalanche.d.ts +2 -4
- package/lib/constants/pools/avalanche.js +21 -27
- package/lib/constants/pools/celo.d.ts +2 -4
- package/lib/constants/pools/celo.js +2 -5
- package/lib/constants/pools/ethereum.js +247 -253
- package/lib/constants/pools/fantom.d.ts +2 -4
- package/lib/constants/pools/fantom.js +28 -34
- package/lib/constants/pools/index.d.ts +11 -11
- package/lib/constants/pools/index.js +12 -25
- package/lib/constants/pools/kava.d.ts +2 -4
- package/lib/constants/pools/kava.js +2 -5
- package/lib/constants/pools/moonbeam.d.ts +2 -4
- package/lib/constants/pools/moonbeam.js +6 -12
- package/lib/constants/pools/optimism.d.ts +2 -4
- package/lib/constants/pools/optimism.js +9 -15
- package/lib/constants/pools/polygon.d.ts +2 -4
- package/lib/constants/pools/polygon.js +22 -28
- package/lib/constants/pools/xdai.d.ts +2 -4
- package/lib/constants/pools/xdai.js +24 -30
- package/lib/constants/utils.js +20 -29
- package/lib/curve.d.ts +9 -7
- package/lib/curve.js +397 -615
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +47 -140
- package/lib/factory/common.js +6 -10
- package/lib/factory/constants-crypto.js +48 -54
- package/lib/factory/constants.js +274 -280
- package/lib/factory/deploy.d.ts +8 -8
- package/lib/factory/deploy.js +177 -347
- package/lib/factory/factory-api.js +195 -278
- package/lib/factory/factory-crypto.js +170 -323
- package/lib/factory/factory.js +195 -350
- package/lib/index.d.ts +24 -25
- package/lib/index.js +87 -143
- package/lib/interfaces.d.ts +5 -5
- package/lib/interfaces.js +1 -2
- package/lib/pools/PoolTemplate.js +1516 -2929
- package/lib/pools/index.d.ts +2 -2
- package/lib/pools/index.js +3 -7
- package/lib/pools/mixins/common.d.ts +3 -4
- package/lib/pools/mixins/common.js +23 -112
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
- package/lib/pools/mixins/depositMixins.d.ts +1 -1
- package/lib/pools/mixins/depositMixins.js +144 -417
- package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/depositWrappedMixins.js +72 -227
- package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -1
- package/lib/pools/mixins/poolBalancesMixin.js +25 -105
- package/lib/pools/mixins/swapMixins.d.ts +1 -1
- package/lib/pools/mixins/swapMixins.js +127 -353
- package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/swapWrappedMixins.js +90 -276
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawExpectedMixins.js +26 -110
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
- package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawMixins.js +123 -390
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinMixins.js +124 -390
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
- package/lib/pools/poolConstructor.d.ts +1 -1
- package/lib/pools/poolConstructor.js +77 -101
- package/lib/pools/utils.js +298 -500
- package/lib/router.d.ts +2 -2
- package/lib/router.js +390 -653
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +377 -731
- package/package.json +8 -8
package/lib/utils.js
CHANGED
|
@@ -1,809 +1,455 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
-
};
|
|
58
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getCoinsData = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getVolume = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getRewardsFromApi = 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
|
-
var axios_1 = __importDefault(require("axios"));
|
|
64
|
-
var ethers_1 = require("ethers");
|
|
65
|
-
var ethcall_1 = require("ethcall");
|
|
66
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
67
|
-
var curve_1 = require("./curve");
|
|
68
|
-
var external_api_1 = require("./external-api");
|
|
69
|
-
var ERC20_json_1 = __importDefault(require("./constants/abis/ERC20.json"));
|
|
70
|
-
exports.ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
71
|
-
exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { Contract } from 'ethers';
|
|
3
|
+
import { Contract as MulticallContract } from "ethcall";
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
import { curve, NETWORK_CONSTANTS } from "./curve.js";
|
|
6
|
+
import { _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes, _getPoolsFromApi, _getSubgraphData } from "./external-api.js";
|
|
7
|
+
import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
|
|
8
|
+
export const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
9
|
+
export const MAX_ALLOWANCE = (2n ** 256n) - 1n;
|
|
72
10
|
// Formatting numbers
|
|
73
|
-
|
|
11
|
+
export const _cutZeros = (strn) => {
|
|
74
12
|
return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
|
|
75
13
|
};
|
|
76
|
-
|
|
77
|
-
var checkNumber = function (n) {
|
|
14
|
+
export const checkNumber = (n) => {
|
|
78
15
|
if (Number(n) !== Number(n))
|
|
79
|
-
throw Error(
|
|
16
|
+
throw Error(`${n} is not a number`); // NaN
|
|
80
17
|
return n;
|
|
81
18
|
};
|
|
82
|
-
|
|
83
|
-
var formatNumber = function (n, decimals) {
|
|
84
|
-
if (decimals === void 0) { decimals = 18; }
|
|
19
|
+
export const formatNumber = (n, decimals = 18) => {
|
|
85
20
|
if (Number(n) !== Number(n))
|
|
86
|
-
throw Error(
|
|
87
|
-
|
|
21
|
+
throw Error(`${n} is not a number`); // NaN
|
|
22
|
+
const [integer, fractional] = String(n).split(".");
|
|
88
23
|
return !fractional ? integer : integer + "." + fractional.slice(0, decimals);
|
|
89
24
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (decimals === void 0) { decimals = 18; }
|
|
93
|
-
return ethers_1.ethers.utils.parseUnits((0, exports.formatNumber)(n, decimals), decimals);
|
|
25
|
+
export const parseUnits = (n, decimals = 18) => {
|
|
26
|
+
return curve.parseUnits(formatNumber(n, decimals), decimals);
|
|
94
27
|
};
|
|
95
|
-
exports.parseUnits = parseUnits;
|
|
96
28
|
// bignumber.js
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
exports.toBN = toBN;
|
|
104
|
-
var toStringFromBN = function (bn, decimals) {
|
|
105
|
-
if (decimals === void 0) { decimals = 18; }
|
|
29
|
+
export const BN = (val) => new BigNumber(checkNumber(val));
|
|
30
|
+
export const toBN = (n, decimals = 18) => {
|
|
31
|
+
return BN(curve.formatUnits(n, decimals));
|
|
32
|
+
};
|
|
33
|
+
export const toStringFromBN = (bn, decimals = 18) => {
|
|
106
34
|
return bn.toFixed(decimals);
|
|
107
35
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (decimals === void 0) { decimals = 18; }
|
|
111
|
-
return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
|
|
36
|
+
export const fromBN = (bn, decimals = 18) => {
|
|
37
|
+
return curve.parseUnits(toStringFromBN(bn, decimals), decimals);
|
|
112
38
|
};
|
|
113
|
-
exports.fromBN = fromBN;
|
|
114
39
|
// -------------------
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
exports.getEthIndex = getEthIndex;
|
|
40
|
+
export const isEth = (address) => address.toLowerCase() === ETH_ADDRESS.toLowerCase();
|
|
41
|
+
export const getEthIndex = (addresses) => addresses.map((address) => address.toLowerCase()).indexOf(ETH_ADDRESS.toLowerCase());
|
|
42
|
+
export const mulBy1_3 = (n) => n * 130n / 100n;
|
|
119
43
|
// coins can be either addresses or symbols
|
|
120
|
-
|
|
121
|
-
var coins = [];
|
|
122
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
123
|
-
coins[_i] = arguments[_i];
|
|
124
|
-
}
|
|
44
|
+
export const _getCoinAddressesNoCheck = (...coins) => {
|
|
125
45
|
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
126
46
|
coins = coins[0];
|
|
127
47
|
coins = coins;
|
|
128
|
-
return coins.map(
|
|
48
|
+
return coins.map((c) => c.toLowerCase()).map((c) => curve.constants.COINS[c] || c);
|
|
129
49
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
for (
|
|
134
|
-
coins[_i] = arguments[_i];
|
|
135
|
-
}
|
|
136
|
-
var coinAddresses = exports._getCoinAddressesNoCheck.apply(void 0, coins);
|
|
137
|
-
var availableAddresses = __spreadArray(__spreadArray([], Object.keys(curve_1.curve.constants.DECIMALS), true), curve_1.curve.constants.GAUGES, true);
|
|
138
|
-
for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
|
|
139
|
-
var coinAddr = coinAddresses_1[_a];
|
|
50
|
+
export const _getCoinAddresses = (...coins) => {
|
|
51
|
+
const coinAddresses = _getCoinAddressesNoCheck(...coins);
|
|
52
|
+
const availableAddresses = [...Object.keys(curve.constants.DECIMALS), ...curve.constants.GAUGES];
|
|
53
|
+
for (const coinAddr of coinAddresses) {
|
|
140
54
|
if (!availableAddresses.includes(coinAddr))
|
|
141
|
-
throw Error(
|
|
55
|
+
throw Error(`Coin with address '${coinAddr}' is not available`);
|
|
142
56
|
}
|
|
143
57
|
return coinAddresses;
|
|
144
58
|
};
|
|
145
|
-
|
|
146
|
-
var _getCoinDecimals = function () {
|
|
147
|
-
var coinAddresses = [];
|
|
148
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
149
|
-
coinAddresses[_i] = arguments[_i];
|
|
150
|
-
}
|
|
59
|
+
export const _getCoinDecimals = (...coinAddresses) => {
|
|
151
60
|
if (coinAddresses.length == 1 && Array.isArray(coinAddresses[0]))
|
|
152
61
|
coinAddresses = coinAddresses[0];
|
|
153
62
|
coinAddresses = coinAddresses;
|
|
154
|
-
return coinAddresses.map(
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
for (_i = 0, coinAddresses_2 = coinAddresses; _i < coinAddresses_2.length; _i++) {
|
|
173
|
-
coinAddr = coinAddresses_2[_i];
|
|
174
|
-
_loop_1(coinAddr);
|
|
175
|
-
}
|
|
176
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
177
|
-
case 1:
|
|
178
|
-
_response = _e.sent();
|
|
179
|
-
if (!(ethIndex !== -1)) return [3 /*break*/, 6];
|
|
180
|
-
ethBalances = [];
|
|
181
|
-
_a = 0, addresses_1 = addresses;
|
|
182
|
-
_e.label = 2;
|
|
183
|
-
case 2:
|
|
184
|
-
if (!(_a < addresses_1.length)) return [3 /*break*/, 5];
|
|
185
|
-
address = addresses_1[_a];
|
|
186
|
-
_c = (_b = ethBalances).push;
|
|
187
|
-
return [4 /*yield*/, curve_1.curve.provider.getBalance(address)];
|
|
188
|
-
case 3:
|
|
189
|
-
_c.apply(_b, [_e.sent()]);
|
|
190
|
-
_e.label = 4;
|
|
191
|
-
case 4:
|
|
192
|
-
_a++;
|
|
193
|
-
return [3 /*break*/, 2];
|
|
194
|
-
case 5:
|
|
195
|
-
_response.splice.apply(_response, __spreadArray([ethIndex * addresses.length, 0], ethBalances, false));
|
|
196
|
-
_e.label = 6;
|
|
197
|
-
case 6:
|
|
198
|
-
_balances = {};
|
|
199
|
-
addresses.forEach(function (address, i) {
|
|
200
|
-
_balances[address] = coins.map(function (_, j) { return _response[i + (j * addresses.length)]; });
|
|
201
|
-
});
|
|
202
|
-
balances = {};
|
|
203
|
-
for (_d = 0, addresses_2 = addresses; _d < addresses_2.length; _d++) {
|
|
204
|
-
address = addresses_2[_d];
|
|
205
|
-
balances[address] = _balances[address].map(function (b, i) { return ethers_1.ethers.utils.formatUnits(b, decimals[i]); });
|
|
206
|
-
}
|
|
207
|
-
return [2 /*return*/, balances];
|
|
63
|
+
return coinAddresses.map((coinAddr) => curve.constants.DECIMALS[coinAddr.toLowerCase()] ?? 18); // 18 for gauges
|
|
64
|
+
};
|
|
65
|
+
export const _getBalances = async (coins, addresses) => {
|
|
66
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
67
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
68
|
+
const ethIndex = getEthIndex(coinAddresses);
|
|
69
|
+
if (ethIndex !== -1) {
|
|
70
|
+
coinAddresses.splice(ethIndex, 1);
|
|
71
|
+
}
|
|
72
|
+
const contractCalls = [];
|
|
73
|
+
for (const coinAddr of coinAddresses) {
|
|
74
|
+
contractCalls.push(...addresses.map((address) => curve.contracts[coinAddr].multicallContract.balanceOf(address)));
|
|
75
|
+
}
|
|
76
|
+
const _response = await curve.multicallProvider.all(contractCalls);
|
|
77
|
+
if (ethIndex !== -1) {
|
|
78
|
+
const ethBalances = [];
|
|
79
|
+
for (const address of addresses) {
|
|
80
|
+
ethBalances.push(await curve.provider.getBalance(address));
|
|
208
81
|
}
|
|
82
|
+
_response.splice(ethIndex * addresses.length, 0, ...ethBalances);
|
|
83
|
+
}
|
|
84
|
+
const _balances = {};
|
|
85
|
+
addresses.forEach((address, i) => {
|
|
86
|
+
_balances[address] = coins.map((_, j) => _response[i + (j * addresses.length)]);
|
|
209
87
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
88
|
+
const balances = {};
|
|
89
|
+
for (const address of addresses) {
|
|
90
|
+
balances[address] = _balances[address].map((b, i) => curve.formatUnits(b, decimals[i]));
|
|
91
|
+
}
|
|
92
|
+
return balances;
|
|
93
|
+
};
|
|
94
|
+
export const _prepareAddresses = (addresses) => {
|
|
213
95
|
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
214
96
|
addresses = addresses[0];
|
|
215
|
-
if (addresses.length === 0 &&
|
|
216
|
-
addresses = [
|
|
97
|
+
if (addresses.length === 0 && curve.signerAddress !== '')
|
|
98
|
+
addresses = [curve.signerAddress];
|
|
217
99
|
addresses = addresses;
|
|
218
|
-
return addresses.filter(
|
|
100
|
+
return addresses.filter((val, idx, arr) => arr.indexOf(val) === idx);
|
|
219
101
|
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
102
|
+
export const getBalances = async (coins, ...addresses) => {
|
|
103
|
+
addresses = _prepareAddresses(addresses);
|
|
104
|
+
const balances = await _getBalances(coins, addresses);
|
|
105
|
+
return addresses.length === 1 ? balances[addresses[0]] : balances;
|
|
106
|
+
};
|
|
107
|
+
export const _getAllowance = async (coins, address, spender) => {
|
|
108
|
+
const _coins = [...coins];
|
|
109
|
+
const ethIndex = getEthIndex(_coins);
|
|
110
|
+
if (ethIndex !== -1) {
|
|
111
|
+
_coins.splice(ethIndex, 1);
|
|
225
112
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
});
|
|
113
|
+
let allowance;
|
|
114
|
+
if (_coins.length === 1) {
|
|
115
|
+
allowance = [await curve.contracts[_coins[0]].contract.allowance(address, spender, curve.constantOptions)];
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const contractCalls = _coins.map((coinAddr) => curve.contracts[coinAddr].multicallContract.allowance(address, spender));
|
|
119
|
+
allowance = await curve.multicallProvider.all(contractCalls);
|
|
120
|
+
}
|
|
121
|
+
if (ethIndex !== -1) {
|
|
122
|
+
allowance.splice(ethIndex, 0, MAX_ALLOWANCE);
|
|
123
|
+
}
|
|
124
|
+
return allowance;
|
|
239
125
|
};
|
|
240
|
-
exports.getBalances = getBalances;
|
|
241
|
-
var _getAllowance = function (coins, address, spender) { return __awaiter(void 0, void 0, void 0, function () {
|
|
242
|
-
var _coins, ethIndex, allowance, contractCalls;
|
|
243
|
-
return __generator(this, function (_a) {
|
|
244
|
-
switch (_a.label) {
|
|
245
|
-
case 0:
|
|
246
|
-
_coins = __spreadArray([], coins, true);
|
|
247
|
-
ethIndex = (0, exports.getEthIndex)(_coins);
|
|
248
|
-
if (ethIndex !== -1) {
|
|
249
|
-
_coins.splice(ethIndex, 1);
|
|
250
|
-
}
|
|
251
|
-
if (!(_coins.length === 1)) return [3 /*break*/, 2];
|
|
252
|
-
return [4 /*yield*/, curve_1.curve.contracts[_coins[0]].contract.allowance(address, spender, curve_1.curve.constantOptions)];
|
|
253
|
-
case 1:
|
|
254
|
-
allowance = [_a.sent()];
|
|
255
|
-
return [3 /*break*/, 4];
|
|
256
|
-
case 2:
|
|
257
|
-
contractCalls = _coins.map(function (coinAddr) { return curve_1.curve.contracts[coinAddr].multicallContract.allowance(address, spender); });
|
|
258
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
259
|
-
case 3:
|
|
260
|
-
allowance = _a.sent();
|
|
261
|
-
_a.label = 4;
|
|
262
|
-
case 4:
|
|
263
|
-
if (ethIndex !== -1) {
|
|
264
|
-
allowance.splice(ethIndex, 0, exports.MAX_ALLOWANCE);
|
|
265
|
-
}
|
|
266
|
-
return [2 /*return*/, allowance];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
}); };
|
|
270
|
-
exports._getAllowance = _getAllowance;
|
|
271
126
|
// coins can be either addresses or symbols
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
279
|
-
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
280
|
-
case 1:
|
|
281
|
-
_allowance = _a.sent();
|
|
282
|
-
return [2 /*return*/, _allowance.map(function (a, i) { return ethers_1.ethers.utils.formatUnits(a, decimals[i]); })];
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}); };
|
|
286
|
-
exports.getAllowance = getAllowance;
|
|
127
|
+
export const getAllowance = async (coins, address, spender) => {
|
|
128
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
129
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
130
|
+
const _allowance = await _getAllowance(coinAddresses, address, spender);
|
|
131
|
+
return _allowance.map((a, i) => curve.formatUnits(a, decimals[i]));
|
|
132
|
+
};
|
|
287
133
|
// coins can be either addresses or symbols
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, gasLimit, _c, _d;
|
|
308
|
-
return __generator(this, function (_e) {
|
|
309
|
-
switch (_e.label) {
|
|
310
|
-
case 0:
|
|
311
|
-
address = curve_1.curve.signerAddress;
|
|
312
|
-
return [4 /*yield*/, (0, exports._getAllowance)(coins, address, spender)];
|
|
313
|
-
case 1:
|
|
314
|
-
allowance = _e.sent();
|
|
315
|
-
txHashes = [];
|
|
316
|
-
i = 0;
|
|
317
|
-
_e.label = 2;
|
|
318
|
-
case 2:
|
|
319
|
-
if (!(i < allowance.length)) return [3 /*break*/, 10];
|
|
320
|
-
if (!allowance[i].lt(amounts[i])) return [3 /*break*/, 9];
|
|
321
|
-
contract = curve_1.curve.contracts[coins[i]].contract;
|
|
322
|
-
_approveAmount = isMax ? exports.MAX_ALLOWANCE : amounts[i];
|
|
323
|
-
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
324
|
-
case 3:
|
|
325
|
-
_e.sent();
|
|
326
|
-
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 6];
|
|
327
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
328
|
-
case 4:
|
|
329
|
-
gasLimit_1 = (_e.sent()).mul(130).div(100);
|
|
330
|
-
_b = (_a = txHashes).push;
|
|
331
|
-
return [4 /*yield*/, contract.approve(spender, ethers_1.ethers.BigNumber.from(0), __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1 }))];
|
|
332
|
-
case 5:
|
|
333
|
-
_b.apply(_a, [(_e.sent()).hash]);
|
|
334
|
-
_e.label = 6;
|
|
335
|
-
case 6: return [4 /*yield*/, contract.estimateGas.approve(spender, _approveAmount, curve_1.curve.constantOptions)];
|
|
336
|
-
case 7:
|
|
337
|
-
gasLimit = (_e.sent()).mul(130).div(100);
|
|
338
|
-
_d = (_c = txHashes).push;
|
|
339
|
-
return [4 /*yield*/, contract.approve(spender, _approveAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
340
|
-
case 8:
|
|
341
|
-
_d.apply(_c, [(_e.sent()).hash]);
|
|
342
|
-
_e.label = 9;
|
|
343
|
-
case 9:
|
|
344
|
-
i++;
|
|
345
|
-
return [3 /*break*/, 2];
|
|
346
|
-
case 10: return [2 /*return*/, txHashes];
|
|
134
|
+
export const hasAllowance = async (coins, amounts, address, spender) => {
|
|
135
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
136
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
137
|
+
const _allowance = await _getAllowance(coinAddresses, address, spender);
|
|
138
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
139
|
+
return _allowance.map((a, i) => a >= _amounts[i]).reduce((a, b) => a && b);
|
|
140
|
+
};
|
|
141
|
+
export const _ensureAllowance = async (coins, amounts, spender, isMax = true) => {
|
|
142
|
+
const address = curve.signerAddress;
|
|
143
|
+
const allowance = await _getAllowance(coins, address, spender);
|
|
144
|
+
const txHashes = [];
|
|
145
|
+
for (let i = 0; i < allowance.length; i++) {
|
|
146
|
+
if (allowance[i] < amounts[i]) {
|
|
147
|
+
const contract = curve.contracts[coins[i]].contract;
|
|
148
|
+
const _approveAmount = isMax ? MAX_ALLOWANCE : amounts[i];
|
|
149
|
+
await curve.updateFeeData();
|
|
150
|
+
if (allowance[i] > 0n) {
|
|
151
|
+
const gasLimit = mulBy1_3(await contract.approve.estimateGas(spender, 0n, curve.constantOptions));
|
|
152
|
+
txHashes.push((await contract.approve(spender, 0n, { ...curve.options, gasLimit })).hash);
|
|
347
153
|
}
|
|
348
|
-
|
|
349
|
-
|
|
154
|
+
const gasLimit = mulBy1_3(await contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions));
|
|
155
|
+
txHashes.push((await contract.approve(spender, _approveAmount, { ...curve.options, gasLimit })).hash);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return txHashes;
|
|
350
159
|
};
|
|
351
|
-
exports._ensureAllowance = _ensureAllowance;
|
|
352
160
|
// coins can be either addresses or symbols
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
allowance = _c.sent();
|
|
367
|
-
gas = 0;
|
|
368
|
-
i = 0;
|
|
369
|
-
_c.label = 2;
|
|
370
|
-
case 2:
|
|
371
|
-
if (!(i < allowance.length)) return [3 /*break*/, 7];
|
|
372
|
-
if (!allowance[i].lt(_amounts[i])) return [3 /*break*/, 6];
|
|
373
|
-
contract = curve_1.curve.contracts[coinAddresses[i]].contract;
|
|
374
|
-
_approveAmount = isMax ? exports.MAX_ALLOWANCE : _amounts[i];
|
|
375
|
-
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 4];
|
|
376
|
-
_a = gas;
|
|
377
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
378
|
-
case 3:
|
|
379
|
-
gas = _a + (_c.sent()).toNumber();
|
|
380
|
-
_c.label = 4;
|
|
381
|
-
case 4:
|
|
382
|
-
_b = gas;
|
|
383
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, _approveAmount, curve_1.curve.constantOptions)];
|
|
384
|
-
case 5:
|
|
385
|
-
gas = _b + (_c.sent()).toNumber();
|
|
386
|
-
_c.label = 6;
|
|
387
|
-
case 6:
|
|
388
|
-
i++;
|
|
389
|
-
return [3 /*break*/, 2];
|
|
390
|
-
case 7: return [2 /*return*/, gas];
|
|
161
|
+
export const ensureAllowanceEstimateGas = async (coins, amounts, spender, isMax = true) => {
|
|
162
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
163
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
164
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
165
|
+
const address = curve.signerAddress;
|
|
166
|
+
const allowance = await _getAllowance(coinAddresses, address, spender);
|
|
167
|
+
let gas = 0;
|
|
168
|
+
for (let i = 0; i < allowance.length; i++) {
|
|
169
|
+
if (allowance[i] < _amounts[i]) {
|
|
170
|
+
const contract = curve.contracts[coinAddresses[i]].contract;
|
|
171
|
+
const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
172
|
+
if (allowance[i] > 0n) {
|
|
173
|
+
gas += Number(await contract.approve.estimateGas(spender, 0n, curve.constantOptions));
|
|
391
174
|
}
|
|
392
|
-
|
|
393
|
-
|
|
175
|
+
gas += Number(await contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return gas;
|
|
394
179
|
};
|
|
395
|
-
exports.ensureAllowanceEstimateGas = ensureAllowanceEstimateGas;
|
|
396
180
|
// coins can be either addresses or symbols
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
switch (_a.label) {
|
|
403
|
-
case 0:
|
|
404
|
-
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
405
|
-
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
406
|
-
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
407
|
-
return [4 /*yield*/, (0, exports._ensureAllowance)(coinAddresses, _amounts, spender, isMax)];
|
|
408
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
});
|
|
181
|
+
export const ensureAllowance = async (coins, amounts, spender, isMax = true) => {
|
|
182
|
+
const coinAddresses = _getCoinAddresses(coins);
|
|
183
|
+
const decimals = _getCoinDecimals(coinAddresses);
|
|
184
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
185
|
+
return await _ensureAllowance(coinAddresses, _amounts, spender, isMax);
|
|
412
186
|
};
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
};
|
|
421
|
-
exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
|
|
422
|
-
var _getTokenAddressBySwapAddress = function (swapAddress) {
|
|
423
|
-
var poolsData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
424
|
-
var res = Object.entries(poolsData).filter(function (_a) {
|
|
425
|
-
var _ = _a[0], poolData = _a[1];
|
|
426
|
-
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|
|
427
|
-
});
|
|
187
|
+
export const getPoolNameBySwapAddress = (swapAddress) => {
|
|
188
|
+
const poolsData = { ...curve.constants.POOLS_DATA, ...curve.constants.FACTORY_POOLS_DATA, ...curve.constants.CRYPTO_FACTORY_POOLS_DATA };
|
|
189
|
+
return Object.entries(poolsData).filter(([_, poolData]) => poolData.swap_address.toLowerCase() === swapAddress.toLowerCase())[0][0];
|
|
190
|
+
};
|
|
191
|
+
const _getTokenAddressBySwapAddress = (swapAddress) => {
|
|
192
|
+
const poolsData = { ...curve.constants.POOLS_DATA, ...curve.constants.FACTORY_POOLS_DATA, ...curve.constants.CRYPTO_FACTORY_POOLS_DATA };
|
|
193
|
+
const res = Object.entries(poolsData).filter(([_, poolData]) => poolData.swap_address.toLowerCase() === swapAddress.toLowerCase());
|
|
428
194
|
if (res.length === 0)
|
|
429
195
|
return "";
|
|
430
196
|
return res[0][1].token_address;
|
|
431
197
|
};
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
priceDict[lpTokenAddress.toLowerCase()] = pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0;
|
|
456
|
-
for (_c = 0, _d = pool.coins; _c < _d.length; _c++) {
|
|
457
|
-
coin = _d[_c];
|
|
458
|
-
if (typeof coin.usdPrice === "number")
|
|
459
|
-
priceDict[coin.address.toLowerCase()] = coin.usdPrice;
|
|
460
|
-
}
|
|
461
|
-
for (_e = 0, _f = (_h = pool.gaugeRewards) !== null && _h !== void 0 ? _h : []; _e < _f.length; _e++) {
|
|
462
|
-
coin = _f[_e];
|
|
463
|
-
if (typeof coin.tokenPrice === "number")
|
|
464
|
-
priceDict[coin.tokenAddress.toLowerCase()] = coin.tokenPrice;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return [2 /*return*/, priceDict];
|
|
198
|
+
export const _getUsdPricesFromApi = async () => {
|
|
199
|
+
const network = curve.constants.NETWORK_NAME;
|
|
200
|
+
const promises = [
|
|
201
|
+
_getPoolsFromApi(network, "main"),
|
|
202
|
+
_getPoolsFromApi(network, "crypto"),
|
|
203
|
+
_getPoolsFromApi(network, "factory"),
|
|
204
|
+
_getPoolsFromApi(network, "factory-crypto"),
|
|
205
|
+
];
|
|
206
|
+
const allTypesExtendedPoolData = await Promise.all(promises);
|
|
207
|
+
const priceDict = {};
|
|
208
|
+
for (const extendedPoolData of allTypesExtendedPoolData) {
|
|
209
|
+
for (const pool of extendedPoolData.poolData) {
|
|
210
|
+
const lpTokenAddress = pool.lpTokenAddress ?? pool.address;
|
|
211
|
+
const totalSupply = pool.totalSupply / (10 ** 18);
|
|
212
|
+
priceDict[lpTokenAddress.toLowerCase()] = pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0;
|
|
213
|
+
for (const coin of pool.coins) {
|
|
214
|
+
if (typeof coin.usdPrice === "number")
|
|
215
|
+
priceDict[coin.address.toLowerCase()] = coin.usdPrice;
|
|
216
|
+
}
|
|
217
|
+
for (const coin of pool.gaugeRewards ?? []) {
|
|
218
|
+
if (typeof coin.tokenPrice === "number")
|
|
219
|
+
priceDict[coin.tokenAddress.toLowerCase()] = coin.tokenPrice;
|
|
220
|
+
}
|
|
469
221
|
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
allTypesExtendedPoolData = _e.sent();
|
|
489
|
-
apyDict = {};
|
|
490
|
-
for (_i = 0, allTypesExtendedPoolData_2 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_2.length; _i++) {
|
|
491
|
-
extendedPoolData = allTypesExtendedPoolData_2[_i];
|
|
492
|
-
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
493
|
-
pool = _b[_a];
|
|
494
|
-
if (pool.gaugeAddress) {
|
|
495
|
-
if (!pool.gaugeCrvApy) {
|
|
496
|
-
apyDict[pool.gaugeAddress.toLowerCase()] = [0, 0];
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
apyDict[pool.gaugeAddress.toLowerCase()] = [(_c = pool.gaugeCrvApy[0]) !== null && _c !== void 0 ? _c : 0, (_d = pool.gaugeCrvApy[1]) !== null && _d !== void 0 ? _d : 0];
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
222
|
+
}
|
|
223
|
+
return priceDict;
|
|
224
|
+
};
|
|
225
|
+
export const _getCrvApyFromApi = async () => {
|
|
226
|
+
const network = curve.constants.NETWORK_NAME;
|
|
227
|
+
const promises = [
|
|
228
|
+
_getPoolsFromApi(network, "main"),
|
|
229
|
+
_getPoolsFromApi(network, "crypto"),
|
|
230
|
+
_getPoolsFromApi(network, "factory"),
|
|
231
|
+
_getPoolsFromApi(network, "factory-crypto"),
|
|
232
|
+
];
|
|
233
|
+
const allTypesExtendedPoolData = await Promise.all(promises);
|
|
234
|
+
const apyDict = {};
|
|
235
|
+
for (const extendedPoolData of allTypesExtendedPoolData) {
|
|
236
|
+
for (const pool of extendedPoolData.poolData) {
|
|
237
|
+
if (pool.gaugeAddress) {
|
|
238
|
+
if (!pool.gaugeCrvApy) {
|
|
239
|
+
apyDict[pool.gaugeAddress.toLowerCase()] = [0, 0];
|
|
503
240
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
});
|
|
507
|
-
}); };
|
|
508
|
-
exports._getCrvApyFromApi = _getCrvApyFromApi;
|
|
509
|
-
var _getRewardsFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
510
|
-
var network, promises, allTypesExtendedPoolData, rewardsDict, _i, allTypesExtendedPoolData_3, extendedPoolData, _a, _b, pool;
|
|
511
|
-
return __generator(this, function (_c) {
|
|
512
|
-
switch (_c.label) {
|
|
513
|
-
case 0:
|
|
514
|
-
network = curve_1.curve.constants.NETWORK_NAME;
|
|
515
|
-
promises = [
|
|
516
|
-
(0, external_api_1._getPoolsFromApi)(network, "main"),
|
|
517
|
-
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
518
|
-
(0, external_api_1._getPoolsFromApi)(network, "factory"),
|
|
519
|
-
(0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
|
|
520
|
-
];
|
|
521
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
522
|
-
case 1:
|
|
523
|
-
allTypesExtendedPoolData = _c.sent();
|
|
524
|
-
rewardsDict = {};
|
|
525
|
-
for (_i = 0, allTypesExtendedPoolData_3 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_3.length; _i++) {
|
|
526
|
-
extendedPoolData = allTypesExtendedPoolData_3[_i];
|
|
527
|
-
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
528
|
-
pool = _b[_a];
|
|
529
|
-
if (pool.gaugeAddress) {
|
|
530
|
-
rewardsDict[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
241
|
+
else {
|
|
242
|
+
apyDict[pool.gaugeAddress.toLowerCase()] = [pool.gaugeCrvApy[0] ?? 0, pool.gaugeCrvApy[1] ?? 0];
|
|
533
243
|
}
|
|
534
|
-
|
|
244
|
+
}
|
|
535
245
|
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
return [2 /*return*/, 1];
|
|
555
|
-
chainName = {
|
|
556
|
-
1: 'ethereum',
|
|
557
|
-
10: 'optimistic-ethereum',
|
|
558
|
-
100: 'xdai',
|
|
559
|
-
137: 'polygon-pos',
|
|
560
|
-
250: 'fantom',
|
|
561
|
-
1284: 'moonbeam',
|
|
562
|
-
2222: 'kava',
|
|
563
|
-
42220: 'celo',
|
|
564
|
-
43114: 'avalanche',
|
|
565
|
-
42161: 'arbitrum-one',
|
|
566
|
-
1313161554: 'aurora',
|
|
567
|
-
}[curve_1.curve.chainId];
|
|
568
|
-
nativeTokenName = {
|
|
569
|
-
1: 'ethereum',
|
|
570
|
-
10: 'ethereum',
|
|
571
|
-
100: 'xdai',
|
|
572
|
-
137: 'matic-network',
|
|
573
|
-
250: 'fantom',
|
|
574
|
-
1284: 'moonbeam',
|
|
575
|
-
2222: 'kava',
|
|
576
|
-
42220: 'celo',
|
|
577
|
-
43114: 'avalanche-2',
|
|
578
|
-
42161: 'ethereum',
|
|
579
|
-
1313161554: 'ethereum',
|
|
580
|
-
}[curve_1.curve.chainId];
|
|
581
|
-
if (chainName === undefined) {
|
|
582
|
-
throw Error('curve object is not initialized');
|
|
583
|
-
}
|
|
584
|
-
assetId = {
|
|
585
|
-
'CRV': 'curve-dao-token',
|
|
586
|
-
'EUR': 'stasis-eurs',
|
|
587
|
-
'BTC': 'bitcoin',
|
|
588
|
-
'ETH': 'ethereum',
|
|
589
|
-
'LINK': 'link',
|
|
590
|
-
}[assetId.toUpperCase()] || assetId;
|
|
591
|
-
assetId = (0, exports.isEth)(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
592
|
-
// No EURT on Coingecko Polygon
|
|
593
|
-
if (curve_1.curve.chainId === 137 && assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt) {
|
|
594
|
-
chainName = 'ethereum';
|
|
595
|
-
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
596
|
-
}
|
|
597
|
-
// CRV
|
|
598
|
-
if (assetId.toLowerCase() === curve_1.curve.constants.ALIASES.crv) {
|
|
599
|
-
assetId = 'curve-dao-token';
|
|
600
|
-
}
|
|
601
|
-
if (!((((_a = _usdRatesCache[assetId]) === null || _a === void 0 ? void 0 : _a.time) || 0) + 600000 < Date.now())) return [3 /*break*/, 3];
|
|
602
|
-
url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
603
|
-
"https://api.coingecko.com/api/v3/simple/price?ids=".concat(assetId, "&vs_currencies=usd") :
|
|
604
|
-
"https://api.coingecko.com/api/v3/simple/token_price/".concat(chainName, "?contract_addresses=").concat(assetId, "&vs_currencies=usd");
|
|
605
|
-
return [4 /*yield*/, axios_1.default.get(url)];
|
|
606
|
-
case 2:
|
|
607
|
-
response = _c.sent();
|
|
608
|
-
try {
|
|
609
|
-
_usdRatesCache[assetId] = { 'rate': (_b = response.data[assetId]['usd']) !== null && _b !== void 0 ? _b : 0, 'time': Date.now() };
|
|
610
|
-
}
|
|
611
|
-
catch (err) { // TODO pay attention!
|
|
612
|
-
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|
|
613
|
-
}
|
|
614
|
-
_c.label = 3;
|
|
615
|
-
case 3: return [2 /*return*/, _usdRatesCache[assetId]['rate']];
|
|
246
|
+
}
|
|
247
|
+
return apyDict;
|
|
248
|
+
};
|
|
249
|
+
export const _getRewardsFromApi = async () => {
|
|
250
|
+
const network = curve.constants.NETWORK_NAME;
|
|
251
|
+
const promises = [
|
|
252
|
+
_getPoolsFromApi(network, "main"),
|
|
253
|
+
_getPoolsFromApi(network, "crypto"),
|
|
254
|
+
_getPoolsFromApi(network, "factory"),
|
|
255
|
+
_getPoolsFromApi(network, "factory-crypto"),
|
|
256
|
+
];
|
|
257
|
+
const allTypesExtendedPoolData = await Promise.all(promises);
|
|
258
|
+
const rewardsDict = {};
|
|
259
|
+
for (const extendedPoolData of allTypesExtendedPoolData) {
|
|
260
|
+
for (const pool of extendedPoolData.poolData) {
|
|
261
|
+
if (pool.gaugeAddress) {
|
|
262
|
+
rewardsDict[pool.gaugeAddress.toLowerCase()] = pool.gaugeRewards;
|
|
263
|
+
}
|
|
616
264
|
}
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
265
|
+
}
|
|
266
|
+
return rewardsDict;
|
|
267
|
+
};
|
|
268
|
+
const _usdRatesCache = {};
|
|
269
|
+
export const _getUsdRate = async (assetId) => {
|
|
270
|
+
if (curve.chainId === 1 && assetId.toLowerCase() === '0x8762db106b2c2a0bccb3a80d1ed41273552616e8')
|
|
271
|
+
return 0; // RSR
|
|
272
|
+
const pricesFromApi = await _getUsdPricesFromApi();
|
|
273
|
+
if (assetId.toLowerCase() in pricesFromApi)
|
|
274
|
+
return pricesFromApi[assetId.toLowerCase()];
|
|
275
|
+
if (assetId === 'USD' || (curve.chainId === 137 && (assetId.toLowerCase() === curve.constants.COINS.am3crv.toLowerCase())))
|
|
276
|
+
return 1;
|
|
277
|
+
let chainName = {
|
|
278
|
+
1: 'ethereum',
|
|
279
|
+
10: 'optimistic-ethereum',
|
|
280
|
+
100: 'xdai',
|
|
281
|
+
137: 'polygon-pos',
|
|
282
|
+
250: 'fantom',
|
|
283
|
+
1284: 'moonbeam',
|
|
284
|
+
2222: 'kava',
|
|
285
|
+
42220: 'celo',
|
|
286
|
+
43114: 'avalanche',
|
|
287
|
+
42161: 'arbitrum-one',
|
|
288
|
+
1313161554: 'aurora',
|
|
289
|
+
}[curve.chainId];
|
|
290
|
+
const nativeTokenName = {
|
|
291
|
+
1: 'ethereum',
|
|
292
|
+
10: 'ethereum',
|
|
293
|
+
100: 'xdai',
|
|
294
|
+
137: 'matic-network',
|
|
295
|
+
250: 'fantom',
|
|
296
|
+
1284: 'moonbeam',
|
|
297
|
+
2222: 'kava',
|
|
298
|
+
42220: 'celo',
|
|
299
|
+
43114: 'avalanche-2',
|
|
300
|
+
42161: 'ethereum',
|
|
301
|
+
1313161554: 'ethereum',
|
|
302
|
+
}[curve.chainId];
|
|
303
|
+
if (chainName === undefined) {
|
|
304
|
+
throw Error('curve object is not initialized');
|
|
305
|
+
}
|
|
306
|
+
assetId = {
|
|
307
|
+
'CRV': 'curve-dao-token',
|
|
308
|
+
'EUR': 'stasis-eurs',
|
|
309
|
+
'BTC': 'bitcoin',
|
|
310
|
+
'ETH': 'ethereum',
|
|
311
|
+
'LINK': 'link',
|
|
312
|
+
}[assetId.toUpperCase()] || assetId;
|
|
313
|
+
assetId = isEth(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
314
|
+
// No EURT on Coingecko Polygon
|
|
315
|
+
if (curve.chainId === 137 && assetId.toLowerCase() === curve.constants.COINS.eurt) {
|
|
316
|
+
chainName = 'ethereum';
|
|
317
|
+
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
318
|
+
}
|
|
319
|
+
// CRV
|
|
320
|
+
if (assetId.toLowerCase() === curve.constants.ALIASES.crv) {
|
|
321
|
+
assetId = 'curve-dao-token';
|
|
322
|
+
}
|
|
323
|
+
if ((_usdRatesCache[assetId]?.time || 0) + 600000 < Date.now()) {
|
|
324
|
+
const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
325
|
+
`https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
|
|
326
|
+
`https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${assetId}&vs_currencies=usd`;
|
|
327
|
+
const response = await axios.get(url);
|
|
328
|
+
try {
|
|
329
|
+
_usdRatesCache[assetId] = { 'rate': response.data[assetId]['usd'] ?? 0, 'time': Date.now() };
|
|
628
330
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
331
|
+
catch (err) { // TODO pay attention!
|
|
332
|
+
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return _usdRatesCache[assetId]['rate'];
|
|
336
|
+
};
|
|
337
|
+
export const getUsdRate = async (coin) => {
|
|
338
|
+
const [coinAddress] = _getCoinAddressesNoCheck(coin);
|
|
339
|
+
return await _getUsdRate(coinAddress);
|
|
340
|
+
};
|
|
341
|
+
const _getNetworkName = (network = curve.chainId) => {
|
|
342
|
+
if (typeof network === "number" && NETWORK_CONSTANTS[network]) {
|
|
343
|
+
return NETWORK_CONSTANTS[network].NAME;
|
|
636
344
|
}
|
|
637
|
-
else if (typeof network === "string" && Object.values(
|
|
345
|
+
else if (typeof network === "string" && Object.values(NETWORK_CONSTANTS).map((n) => n.NAME).includes(network)) {
|
|
638
346
|
return network;
|
|
639
347
|
}
|
|
640
348
|
else {
|
|
641
|
-
throw Error(
|
|
349
|
+
throw Error(`Wrong network name or id: ${network}`);
|
|
642
350
|
}
|
|
643
351
|
};
|
|
644
|
-
|
|
645
|
-
if (network ===
|
|
646
|
-
if (typeof network === "number" && curve_1.NETWORK_CONSTANTS[network]) {
|
|
352
|
+
const _getChainId = (network = curve.chainId) => {
|
|
353
|
+
if (typeof network === "number" && NETWORK_CONSTANTS[network]) {
|
|
647
354
|
return network;
|
|
648
355
|
}
|
|
649
|
-
else if (typeof network === "string" && Object.values(
|
|
650
|
-
|
|
651
|
-
return Number(Object.keys(
|
|
356
|
+
else if (typeof network === "string" && Object.values(NETWORK_CONSTANTS).map((n) => n.NAME).includes(network)) {
|
|
357
|
+
const idx = Object.values(NETWORK_CONSTANTS).map((n) => n.NAME).indexOf(network);
|
|
358
|
+
return Number(Object.keys(NETWORK_CONSTANTS)[idx]);
|
|
652
359
|
}
|
|
653
360
|
else {
|
|
654
|
-
throw Error(
|
|
361
|
+
throw Error(`Wrong network name or id: ${network}`);
|
|
655
362
|
}
|
|
656
363
|
};
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
(0, external_api_1._getPoolsFromApi)(network, "crypto"),
|
|
668
|
-
(0, external_api_1._getPoolsFromApi)(network, "factory"),
|
|
669
|
-
(0, external_api_1._getPoolsFromApi)(network, "factory-crypto"),
|
|
670
|
-
];
|
|
671
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
672
|
-
case 1:
|
|
673
|
-
allTypesExtendedPoolData = _a.sent();
|
|
674
|
-
return [2 /*return*/, allTypesExtendedPoolData.reduce(function (sum, data) { var _a, _b; return sum + ((_b = (_a = data.tvl) !== null && _a !== void 0 ? _a : data.tvlAll) !== null && _b !== void 0 ? _b : 0); }, 0)];
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
});
|
|
364
|
+
export const getTVL = async (network = curve.chainId) => {
|
|
365
|
+
network = _getNetworkName(network);
|
|
366
|
+
const promises = [
|
|
367
|
+
_getPoolsFromApi(network, "main"),
|
|
368
|
+
_getPoolsFromApi(network, "crypto"),
|
|
369
|
+
_getPoolsFromApi(network, "factory"),
|
|
370
|
+
_getPoolsFromApi(network, "factory-crypto"),
|
|
371
|
+
];
|
|
372
|
+
const allTypesExtendedPoolData = await Promise.all(promises);
|
|
373
|
+
return allTypesExtendedPoolData.reduce((sum, data) => sum + (data.tvl ?? data.tvlAll ?? 0), 0);
|
|
678
374
|
};
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
_i = 0, factoryPoolsData_1 = factoryPoolsData;
|
|
704
|
-
_e.label = 2;
|
|
705
|
-
case 2:
|
|
706
|
-
if (!(_i < factoryPoolsData_1.length)) return [3 /*break*/, 7];
|
|
707
|
-
pool = factoryPoolsData_1[_i];
|
|
708
|
-
lpToken = _getTokenAddressBySwapAddress(pool.poolAddress);
|
|
709
|
-
if (!lpToken) return [3 /*break*/, 4];
|
|
710
|
-
return [4 /*yield*/, (0, exports._getUsdRate)(lpToken)];
|
|
711
|
-
case 3:
|
|
712
|
-
_b = _e.sent();
|
|
713
|
-
return [3 /*break*/, 5];
|
|
714
|
-
case 4:
|
|
715
|
-
_b = 0;
|
|
716
|
-
_e.label = 5;
|
|
717
|
-
case 5:
|
|
718
|
-
lpPrice = _b;
|
|
719
|
-
volume += pool.volume * lpPrice;
|
|
720
|
-
_e.label = 6;
|
|
721
|
-
case 6:
|
|
722
|
-
_i++;
|
|
723
|
-
return [3 /*break*/, 2];
|
|
724
|
-
case 7: return [2 /*return*/, { totalVolume: volume, cryptoVolume: 0, cryptoShare: 0 }];
|
|
725
|
-
case 8: return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
726
|
-
case 9:
|
|
727
|
-
_c = _e.sent(), totalVolume = _c.totalVolume, cryptoVolume = _c.cryptoVolume, cryptoShare = _c.cryptoShare;
|
|
728
|
-
return [2 /*return*/, { totalVolume: totalVolume, cryptoVolume: cryptoVolume, cryptoShare: cryptoShare }];
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
});
|
|
375
|
+
export const getVolume = async (network = curve.chainId) => {
|
|
376
|
+
network = _getNetworkName(network);
|
|
377
|
+
if (["moonbeam", "kava", "celo", "aurora"].includes(network)) {
|
|
378
|
+
const chainId = _getChainId(network);
|
|
379
|
+
if (curve.chainId !== chainId)
|
|
380
|
+
throw Error("To get volume for Moonbeam, Kava, Celo or Aurora connect to the network first");
|
|
381
|
+
const [mainPoolsData, factoryPoolsData] = await Promise.all([
|
|
382
|
+
_getLegacyAPYsAndVolumes(network),
|
|
383
|
+
_getFactoryAPYsAndVolumes(network),
|
|
384
|
+
]);
|
|
385
|
+
let volume = 0;
|
|
386
|
+
for (const id in mainPoolsData) {
|
|
387
|
+
volume += mainPoolsData[id].volume ?? 0;
|
|
388
|
+
}
|
|
389
|
+
for (const pool of factoryPoolsData) {
|
|
390
|
+
const lpToken = _getTokenAddressBySwapAddress(pool.poolAddress);
|
|
391
|
+
const lpPrice = lpToken ? await _getUsdRate(lpToken) : 0;
|
|
392
|
+
volume += pool.volume * lpPrice;
|
|
393
|
+
}
|
|
394
|
+
return { totalVolume: volume, cryptoVolume: 0, cryptoShare: 0 };
|
|
395
|
+
}
|
|
396
|
+
const { totalVolume, cryptoVolume, cryptoShare } = await _getSubgraphData(network);
|
|
397
|
+
return { totalVolume, cryptoVolume, cryptoShare };
|
|
732
398
|
};
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
multicallContract: new ethcall_1.Contract(address, abi),
|
|
399
|
+
export const _setContracts = (address, abi) => {
|
|
400
|
+
curve.contracts[address] = {
|
|
401
|
+
contract: new Contract(address, abi, curve.signer || curve.provider),
|
|
402
|
+
multicallContract: new MulticallContract(address, abi),
|
|
738
403
|
};
|
|
739
404
|
};
|
|
740
|
-
exports._setContracts = _setContracts;
|
|
741
405
|
// Find k for which x * k = target_x or y * k = target_y
|
|
742
406
|
// k = max(target_x / x, target_y / y)
|
|
743
407
|
// small_x = x * k
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
return
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
var smallRateBN = small_y_BN.div(small_x_BN);
|
|
408
|
+
export const _get_small_x = (_x, _y, x_decimals, y_decimals) => {
|
|
409
|
+
const target_x = BN(10 ** (x_decimals > 5 ? x_decimals - 3 : x_decimals));
|
|
410
|
+
const target_y = BN(10 ** (y_decimals > 5 ? y_decimals - 3 : y_decimals));
|
|
411
|
+
const x_int_BN = toBN(_x, 0);
|
|
412
|
+
const y_int_BN = toBN(_y, 0);
|
|
413
|
+
const k = BigNumber.max(target_x.div(x_int_BN), target_y.div(y_int_BN));
|
|
414
|
+
return BigNumber.min(x_int_BN.times(k), BN(10 ** x_decimals));
|
|
415
|
+
};
|
|
416
|
+
export const _get_price_impact = (_x, _y, _small_x, _small_y, x_decimals, y_decimals) => {
|
|
417
|
+
const x_BN = toBN(_x, x_decimals);
|
|
418
|
+
const y_BN = toBN(_y, y_decimals);
|
|
419
|
+
const small_x_BN = toBN(_small_x, x_decimals);
|
|
420
|
+
const small_y_BN = toBN(_small_y, y_decimals);
|
|
421
|
+
const rateBN = y_BN.div(x_BN);
|
|
422
|
+
const smallRateBN = small_y_BN.div(small_x_BN);
|
|
760
423
|
if (rateBN.gt(smallRateBN))
|
|
761
|
-
return
|
|
762
|
-
return
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
424
|
+
return BN(0);
|
|
425
|
+
return BN(1).minus(rateBN.div(smallRateBN)).times(100);
|
|
426
|
+
};
|
|
427
|
+
export const getCoinsData = async (...coins) => {
|
|
428
|
+
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
429
|
+
coins = coins[0];
|
|
430
|
+
coins = coins;
|
|
431
|
+
const coinAddresses = _getCoinAddressesNoCheck(coins);
|
|
432
|
+
console.log(coinAddresses);
|
|
433
|
+
const ethIndex = getEthIndex(coinAddresses);
|
|
434
|
+
if (ethIndex !== -1) {
|
|
435
|
+
coinAddresses.splice(ethIndex, 1);
|
|
769
436
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
for (_a = 0, coinAddresses_3 = coinAddresses; _a < coinAddresses_3.length; _a++) {
|
|
786
|
-
coinAddr = coinAddresses_3[_a];
|
|
787
|
-
coinContract = new ethcall_1.Contract(coinAddr, ERC20_json_1.default);
|
|
788
|
-
contractCalls.push(coinContract.name(), coinContract.symbol(), coinContract.decimals());
|
|
789
|
-
}
|
|
790
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
791
|
-
case 1:
|
|
792
|
-
_response = _b.sent();
|
|
793
|
-
if (ethIndex !== -1) {
|
|
794
|
-
_response.splice.apply(_response, __spreadArray([ethIndex * 2, 0], ['Ethereum', 'ETH', 18], false));
|
|
795
|
-
}
|
|
796
|
-
res = [];
|
|
797
|
-
coins.forEach(function (address, i) {
|
|
798
|
-
res.push({
|
|
799
|
-
name: _response.shift(),
|
|
800
|
-
symbol: _response.shift(),
|
|
801
|
-
decimals: Number(ethers_1.ethers.utils.formatUnits(_response.shift(), 0)),
|
|
802
|
-
});
|
|
803
|
-
});
|
|
804
|
-
return [2 /*return*/, res];
|
|
805
|
-
}
|
|
437
|
+
const contractCalls = [];
|
|
438
|
+
for (const coinAddr of coinAddresses) {
|
|
439
|
+
const coinContract = new MulticallContract(coinAddr, ERC20Abi);
|
|
440
|
+
contractCalls.push(coinContract.name(), coinContract.symbol(), coinContract.decimals());
|
|
441
|
+
}
|
|
442
|
+
const _response = await curve.multicallProvider.all(contractCalls);
|
|
443
|
+
if (ethIndex !== -1) {
|
|
444
|
+
_response.splice(ethIndex * 2, 0, ...['Ethereum', 'ETH', 18]);
|
|
445
|
+
}
|
|
446
|
+
const res = [];
|
|
447
|
+
coins.forEach((address, i) => {
|
|
448
|
+
res.push({
|
|
449
|
+
name: _response.shift(),
|
|
450
|
+
symbol: _response.shift(),
|
|
451
|
+
decimals: Number(curve.formatUnits(_response.shift(), 0)),
|
|
806
452
|
});
|
|
807
453
|
});
|
|
454
|
+
return res;
|
|
808
455
|
};
|
|
809
|
-
exports.getCoinsData = getCoinsData;
|