@curvefi/api 2.27.0 → 2.28.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/constants/coins/xdai.js +2 -0
- package/lib/factory/factory-api.js +4 -1
- package/lib/factory/factory-crypto.js +2 -1
- package/lib/factory/factory.js +2 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/pools/PoolTemplate.js +1 -1
- package/lib/router.js +14 -2
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +44 -33
- package/package.json +1 -1
|
@@ -14,6 +14,8 @@ exports.COINS_XDAI = (0, utils_1.lowerCaseValues)({
|
|
|
14
14
|
'wbtc': '0x8e5bBbb09Ed1ebdE8674Cda39A0c169401db4252',
|
|
15
15
|
// --- ETH ---
|
|
16
16
|
'weth': '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1',
|
|
17
|
+
// --- EUR ---
|
|
18
|
+
'eure': '0xcB444e90D8198415266c6a2724b7900fb12FC56E',
|
|
17
19
|
});
|
|
18
20
|
exports.cTokensXDai = []; //.map((a) => a.toLowerCase());
|
|
19
21
|
exports.yTokensXDai = []; //.map((a) => a.toLowerCase());
|
|
@@ -178,10 +178,13 @@ function getFactoryPoolsDataFromApi(isCrypto) {
|
|
|
178
178
|
common_1.setFactoryZapContracts.call(this, isCrypto);
|
|
179
179
|
FACTORY_POOLS_DATA = {};
|
|
180
180
|
rawPoolList.forEach(function (pool) {
|
|
181
|
+
var nativeToken = _this.constants.NATIVE_TOKEN;
|
|
181
182
|
var coinAddresses = pool.coins.map(function (c) { return c.address; });
|
|
183
|
+
if (_this.chainId === 137) {
|
|
184
|
+
coinAddresses = coinAddresses.map(function (a) { return a === "0x0000000000000000000000000000000000001010" ? nativeToken.wrappedAddress : a; });
|
|
185
|
+
}
|
|
182
186
|
var coinNames = pool.coins.map(function (c) { return c.symbol; });
|
|
183
187
|
var coinDecimals = pool.coins.map(function (c) { return Number(c.decimals); });
|
|
184
|
-
var nativeToken = _this.constants.NATIVE_TOKEN;
|
|
185
188
|
if (isCrypto) {
|
|
186
189
|
var wrappedCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.symbol ? nativeToken.wrappedSymbol : c.symbol; });
|
|
187
190
|
var underlyingCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.wrappedSymbol ? nativeToken.symbol : c.symbol; });
|
|
@@ -219,6 +219,7 @@ function getCryptoFactorySymbolsAndNames(factoryTokenAddresses) {
|
|
|
219
219
|
function getCryptoFactoryCoinAddresses(factorySwapAddresses) {
|
|
220
220
|
return __awaiter(this, void 0, void 0, function () {
|
|
221
221
|
var factoryMulticallContract, calls, _i, factorySwapAddresses_3, addr;
|
|
222
|
+
var _this = this;
|
|
222
223
|
return __generator(this, function (_a) {
|
|
223
224
|
switch (_a.label) {
|
|
224
225
|
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.crypto_factory].multicallContract];
|
|
@@ -230,7 +231,7 @@ function getCryptoFactoryCoinAddresses(factorySwapAddresses) {
|
|
|
230
231
|
calls.push(factoryMulticallContract.get_coins(addr));
|
|
231
232
|
}
|
|
232
233
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
233
|
-
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses.map(function (addr) { return addr.toLowerCase(); }); })];
|
|
234
|
+
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); })];
|
|
234
235
|
}
|
|
235
236
|
});
|
|
236
237
|
});
|
package/lib/factory/factory.js
CHANGED
|
@@ -244,6 +244,7 @@ function getFactoryReferenceAssets(factorySwapAddresses) {
|
|
|
244
244
|
function getFactoryCoinAddresses(factorySwapAddresses) {
|
|
245
245
|
return __awaiter(this, void 0, void 0, function () {
|
|
246
246
|
var factoryMulticallContract, calls, _i, factorySwapAddresses_5, addr;
|
|
247
|
+
var _this = this;
|
|
247
248
|
return __generator(this, function (_a) {
|
|
248
249
|
switch (_a.label) {
|
|
249
250
|
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
|
|
@@ -257,7 +258,7 @@ function getFactoryCoinAddresses(factorySwapAddresses) {
|
|
|
257
258
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
258
259
|
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses
|
|
259
260
|
.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
|
|
260
|
-
.map(function (addr) { return addr.toLowerCase(); }); })];
|
|
261
|
+
.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.address : addr.toLowerCase(); }); })];
|
|
261
262
|
}
|
|
262
263
|
});
|
|
263
264
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -52,9 +52,10 @@ declare const curve: {
|
|
|
52
52
|
getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
53
53
|
hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
|
|
54
54
|
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string) => Promise<string[]>;
|
|
55
|
-
|
|
55
|
+
getCoinsData: (...coins: string[] | string[][]) => Promise<{
|
|
56
56
|
name: string;
|
|
57
57
|
symbol: string;
|
|
58
|
+
decimals: number;
|
|
58
59
|
}[]>;
|
|
59
60
|
factory: {
|
|
60
61
|
deployPlainPool: (name: string, symbol: string, coins: string[], A: number, fee: number, assetType: 0 | 2 | 1 | 3, implementationIdx: 0 | 2 | 1 | 3) => Promise<ethers.ContractTransaction>;
|
package/lib/index.js
CHANGED
|
@@ -132,7 +132,7 @@ var curve = {
|
|
|
132
132
|
getAllowance: utils_2.getAllowance,
|
|
133
133
|
hasAllowance: utils_2.hasAllowance,
|
|
134
134
|
ensureAllowance: utils_2.ensureAllowance,
|
|
135
|
-
|
|
135
|
+
getCoinsData: utils_2.getCoinsData,
|
|
136
136
|
factory: {
|
|
137
137
|
deployPlainPool: deploy_1.deployStablePlainPool,
|
|
138
138
|
deployMetaPool: deploy_1.deployStableMetaPool,
|
|
@@ -182,7 +182,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
182
182
|
return [2 /*return*/, String(totalLiquidity_1)];
|
|
183
183
|
}
|
|
184
184
|
catch (err) {
|
|
185
|
-
console.log(err.message);
|
|
185
|
+
console.log(this.id, err.message);
|
|
186
186
|
}
|
|
187
187
|
_d.label = 2;
|
|
188
188
|
case 2: return [4 /*yield*/, this.statsUnderlyingBalances()];
|
package/lib/router.js
CHANGED
|
@@ -532,7 +532,7 @@ var swapExpected = function (inputCoin, outputCoin, amount) { return __awaiter(v
|
|
|
532
532
|
}); };
|
|
533
533
|
exports.swapExpected = swapExpected;
|
|
534
534
|
var swapPriceImpact = function (inputCoin, outputCoin, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
535
|
-
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, route, _amount, _output, smallAmountIntBN, amountIntBN, contract, _smallAmount, _c, _route, _swapParams, _factorySwapAddresses, _smallOutput, priceImpactBN;
|
|
535
|
+
var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, route, _amount, _output, smallAmountIntBN, amountIntBN, contract, _smallAmount, _c, _route, _swapParams, _factorySwapAddresses, _smallOutput, e_1, priceImpactBN;
|
|
536
536
|
return __generator(this, function (_d) {
|
|
537
537
|
switch (_d.label) {
|
|
538
538
|
case 0:
|
|
@@ -550,9 +550,21 @@ var swapPriceImpact = function (inputCoin, outputCoin, amount) { return __awaite
|
|
|
550
550
|
contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.registry_exchange].contract;
|
|
551
551
|
_smallAmount = (0, utils_1.fromBN)(smallAmountIntBN.div(Math.pow(10, inputCoinDecimals)), inputCoinDecimals);
|
|
552
552
|
_c = _getExchangeMultipleArgs(inputCoinAddress, route), _route = _c._route, _swapParams = _c._swapParams, _factorySwapAddresses = _c._factorySwapAddresses;
|
|
553
|
-
|
|
553
|
+
_d.label = 2;
|
|
554
554
|
case 2:
|
|
555
|
+
_d.trys.push([2, 4, , 6]);
|
|
556
|
+
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _smallAmount, _factorySwapAddresses, curve_1.curve.constantOptions)];
|
|
557
|
+
case 3:
|
|
558
|
+
_smallOutput = _d.sent();
|
|
559
|
+
return [3 /*break*/, 6];
|
|
560
|
+
case 4:
|
|
561
|
+
e_1 = _d.sent();
|
|
562
|
+
_smallAmount = ethers_1.ethers.utils.parseUnits("1", inputCoinDecimals); // Dirty hack
|
|
563
|
+
return [4 /*yield*/, contract.get_exchange_multiple_amount(_route, _swapParams, _smallAmount, _factorySwapAddresses, curve_1.curve.constantOptions)];
|
|
564
|
+
case 5:
|
|
555
565
|
_smallOutput = _d.sent();
|
|
566
|
+
return [3 /*break*/, 6];
|
|
567
|
+
case 6:
|
|
556
568
|
priceImpactBN = (0, utils_1._get_price_impact)(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
557
569
|
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4)))];
|
|
558
570
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -35,7 +35,8 @@ export declare const getTVL: (chainId?: number) => Promise<number>;
|
|
|
35
35
|
export declare const _setContracts: (address: string, abi: any) => void;
|
|
36
36
|
export declare const _get_small_x: (_x: ethers.BigNumber, _y: ethers.BigNumber, x_decimals: number, y_decimals: number) => BigNumber;
|
|
37
37
|
export declare const _get_price_impact: (_x: ethers.BigNumber, _y: ethers.BigNumber, _small_x: ethers.BigNumber, _small_y: ethers.BigNumber, x_decimals: number, y_decimals: number) => BigNumber;
|
|
38
|
-
export declare const
|
|
38
|
+
export declare const getCoinsData: (...coins: string[] | string[][]) => Promise<{
|
|
39
39
|
name: string;
|
|
40
40
|
symbol: string;
|
|
41
|
+
decimals: number;
|
|
41
42
|
}[]>;
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.
|
|
62
|
+
exports.getCoinsData = exports._get_price_impact = exports._get_small_x = exports._setContracts = 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
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var ethcall_1 = require("ethcall");
|
|
@@ -675,37 +675,48 @@ var _get_price_impact = function (_x, _y, _small_x, _small_y, x_decimals, y_deci
|
|
|
675
675
|
return (0, exports.BN)(1).minus(rateBN.div(smallRateBN)).times(100);
|
|
676
676
|
};
|
|
677
677
|
exports._get_price_impact = _get_price_impact;
|
|
678
|
-
var
|
|
679
|
-
var
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
678
|
+
var getCoinsData = function () {
|
|
679
|
+
var coins = [];
|
|
680
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
681
|
+
coins[_i] = arguments[_i];
|
|
682
|
+
}
|
|
683
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
684
|
+
var coinAddresses, ethIndex, contractCalls, _a, coinAddresses_3, coinAddr, coinContract, _response, res;
|
|
685
|
+
return __generator(this, function (_b) {
|
|
686
|
+
switch (_b.label) {
|
|
687
|
+
case 0:
|
|
688
|
+
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
689
|
+
coins = coins[0];
|
|
690
|
+
coins = coins;
|
|
691
|
+
coinAddresses = (0, exports._getCoinAddressesNoCheck)(coins);
|
|
692
|
+
console.log(coinAddresses);
|
|
693
|
+
ethIndex = (0, exports.getEthIndex)(coinAddresses);
|
|
694
|
+
if (ethIndex !== -1) {
|
|
695
|
+
coinAddresses.splice(ethIndex, 1);
|
|
696
|
+
}
|
|
697
|
+
contractCalls = [];
|
|
698
|
+
for (_a = 0, coinAddresses_3 = coinAddresses; _a < coinAddresses_3.length; _a++) {
|
|
699
|
+
coinAddr = coinAddresses_3[_a];
|
|
700
|
+
coinContract = new ethcall_1.Contract(coinAddr, ERC20_json_1.default);
|
|
701
|
+
contractCalls.push(coinContract.name(), coinContract.symbol(), coinContract.decimals());
|
|
702
|
+
}
|
|
703
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
704
|
+
case 1:
|
|
705
|
+
_response = _b.sent();
|
|
706
|
+
if (ethIndex !== -1) {
|
|
707
|
+
_response.splice.apply(_response, __spreadArray([ethIndex * 2, 0], ['Ethereum', 'ETH', 18], false));
|
|
708
|
+
}
|
|
709
|
+
res = [];
|
|
710
|
+
coins.forEach(function (address, i) {
|
|
711
|
+
res.push({
|
|
712
|
+
name: _response.shift(),
|
|
713
|
+
symbol: _response.shift(),
|
|
714
|
+
decimals: Number(ethers_1.ethers.utils.formatUnits(_response.shift(), 0)),
|
|
715
|
+
});
|
|
705
716
|
});
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
717
|
+
return [2 /*return*/, res];
|
|
718
|
+
}
|
|
719
|
+
});
|
|
709
720
|
});
|
|
710
|
-
}
|
|
711
|
-
exports.
|
|
721
|
+
};
|
|
722
|
+
exports.getCoinsData = getCoinsData;
|