@curvefi/api 2.26.4 → 2.28.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/lib/constants/coins/xdai.js +2 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/pools/PoolTemplate.js +2 -2
- package/lib/pools/utils.js +2 -2
- 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());
|
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()];
|
|
@@ -1187,7 +1187,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1187
1187
|
};
|
|
1188
1188
|
}
|
|
1189
1189
|
PoolTemplate.prototype.rewardsOnly = function () {
|
|
1190
|
-
if (curve_1.curve.chainId === 2222
|
|
1190
|
+
if (curve_1.curve.chainId === 2222)
|
|
1191
1191
|
return true; // TODO remove this for Kava and Celo
|
|
1192
1192
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
1193
1193
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
package/lib/pools/utils.js
CHANGED
|
@@ -182,7 +182,7 @@ var _getUserClaimable = function (pools, address, useCache) { return __awaiter(v
|
|
|
182
182
|
for (_i = 0, poolsToFetch_3 = poolsToFetch; _i < poolsToFetch_3.length; _i++) {
|
|
183
183
|
poolId = poolsToFetch_3[_i];
|
|
184
184
|
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
185
|
-
if (curve_1.curve.chainId === 2222 ||
|
|
185
|
+
if (curve_1.curve.chainId === 2222 || pool.gauge === ethers_1.ethers.constants.AddressZero) { // TODO remove this for Kava
|
|
186
186
|
hasCrvReward.push(false);
|
|
187
187
|
continue;
|
|
188
188
|
}
|
|
@@ -324,7 +324,7 @@ var _getUserClaimableUseApi = function (pools, address, useCache) { return __awa
|
|
|
324
324
|
for (_i = 0, poolsToFetch_5 = poolsToFetch; _i < poolsToFetch_5.length; _i++) {
|
|
325
325
|
poolId = poolsToFetch_5[_i];
|
|
326
326
|
pool = (0, poolConstructor_1.getPool)(poolId);
|
|
327
|
-
if (curve_1.curve.chainId === 2222 ||
|
|
327
|
+
if (curve_1.curve.chainId === 2222 || pool.gauge === ethers_1.ethers.constants.AddressZero) { // TODO remove this for Kava
|
|
328
328
|
hasCrvReward.push(false);
|
|
329
329
|
continue;
|
|
330
330
|
}
|
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;
|