@curvefi/api 2.20.0 → 2.20.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/README.md +5 -3
- package/lib/pools/PoolTemplate.js +2 -2
- package/lib/router.js +1 -1
- package/lib/utils.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,10 +17,10 @@ import curve from "@curvefi/api";
|
|
|
17
17
|
await curve.init('JsonRpc', {}, {}); // In this case JsonRpc url, privateKey, fee data and chainId will be specified automatically
|
|
18
18
|
|
|
19
19
|
// 2. Infura
|
|
20
|
-
curve.init("Infura", { network: "homestead", apiKey: <INFURA_KEY> }, { chainId: 1 });
|
|
20
|
+
await curve.init("Infura", { network: "homestead", apiKey: <INFURA_KEY> }, { chainId: 1 });
|
|
21
21
|
|
|
22
22
|
// 3. Web3 provider
|
|
23
|
-
curve.init('Web3', { externalProvider: <WEB3_PROVIDER> }, { chainId: 1 });
|
|
23
|
+
await curve.init('Web3', { externalProvider: <WEB3_PROVIDER> }, { chainId: 1 });
|
|
24
24
|
|
|
25
25
|
// Fetch factory pools
|
|
26
26
|
await curve.fetchFactoryPools();
|
|
@@ -964,12 +964,14 @@ import curve from "@curvefi/api";
|
|
|
964
964
|
|
|
965
965
|
(async () => {
|
|
966
966
|
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
|
|
967
|
+
await curve.fetchFactoryPools();
|
|
968
|
+
await curve.getCryptoFactoryPoolList();
|
|
967
969
|
|
|
968
970
|
await curve.getBalances(['DAI', 'CRV']);
|
|
969
971
|
// [ '9900.0', '100049.744832225238317557' ]
|
|
970
972
|
|
|
971
973
|
const { route, output } = await curve.router.getBestRouteAndOutput('DAI', 'CRV', '1000');
|
|
972
|
-
// OR await curve.router.
|
|
974
|
+
// OR await curve.router.getBestRouteAndOutput('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000');
|
|
973
975
|
const expected = await curve.router.expected('DAI', 'CRV', '1000');
|
|
974
976
|
// OR await curve.router.expected('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000');
|
|
975
977
|
const priceImpact = await curve.router.priceImpact('DAI', 'CRV', '1000');
|
|
@@ -2714,7 +2714,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2714
2714
|
case 2:
|
|
2715
2715
|
_smallOutput = _d.sent();
|
|
2716
2716
|
priceImpactBN = (0, utils_1._get_price_impact)(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
2717
|
-
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4))
|
|
2717
|
+
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4)))];
|
|
2718
2718
|
}
|
|
2719
2719
|
});
|
|
2720
2720
|
});
|
|
@@ -2825,7 +2825,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2825
2825
|
case 2:
|
|
2826
2826
|
_smallOutput = _d.sent();
|
|
2827
2827
|
priceImpactBN = (0, utils_1._get_price_impact)(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
2828
|
-
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4))
|
|
2828
|
+
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4)))];
|
|
2829
2829
|
}
|
|
2830
2830
|
});
|
|
2831
2831
|
});
|
package/lib/router.js
CHANGED
|
@@ -765,7 +765,7 @@ var swapPriceImpact = function (inputCoin, outputCoin, amount) { return __awaite
|
|
|
765
765
|
case 2:
|
|
766
766
|
_smallOutput = _d.sent();
|
|
767
767
|
priceImpactBN = (0, utils_1._get_price_impact)(_amount, _output, _smallAmount, _smallOutput, inputCoinDecimals, outputCoinDecimals);
|
|
768
|
-
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4))
|
|
768
|
+
return [2 /*return*/, Number((0, utils_1._cutZeros)(priceImpactBN.toFixed(4)))];
|
|
769
769
|
}
|
|
770
770
|
});
|
|
771
771
|
}); };
|
package/lib/utils.js
CHANGED
|
@@ -600,6 +600,8 @@ var _get_price_impact = function (_x, _y, _small_x, _small_y, x_decimals, y_deci
|
|
|
600
600
|
var small_y_BN = (0, exports.toBN)(_small_y, y_decimals);
|
|
601
601
|
var rateBN = y_BN.div(x_BN);
|
|
602
602
|
var smallRateBN = small_y_BN.div(small_x_BN);
|
|
603
|
+
if (rateBN.gt(smallRateBN))
|
|
604
|
+
return (0, exports.BN)(0);
|
|
603
605
|
return (0, exports.BN)(1).minus(rateBN.div(smallRateBN)).times(100);
|
|
604
606
|
};
|
|
605
607
|
exports._get_price_impact = _get_price_impact;
|