In Progress Add Mock
This commit is contained in:
@@ -6,13 +6,14 @@ import "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.so
|
||||
// Why is this a library and not abstract?
|
||||
// Why not an interface?
|
||||
library PriceConverter {
|
||||
// Sepolia ETH / USD Address
|
||||
// https://docs.chain.link/data-feeds/price-feeds/addresses#Sepolia%20Testnet
|
||||
//0x694AA1769357215DE4FAC081bf1f309aDC325306
|
||||
|
||||
// We could make this public, but then we'd have to deploy it
|
||||
function getPrice() internal view returns (uint256) {
|
||||
// Sepolia ETH / USD Address
|
||||
// https://docs.chain.link/data-feeds/price-feeds/addresses#Sepolia%20Testnet
|
||||
AggregatorV3Interface priceFeed = AggregatorV3Interface(
|
||||
0x694AA1769357215DE4FAC081bf1f309aDC325306
|
||||
);
|
||||
function getPrice(
|
||||
AggregatorV3Interface priceFeed
|
||||
) internal view returns (uint256) {
|
||||
(, int256 answer, , , ) = priceFeed.latestRoundData();
|
||||
// ETH/USD rate in 18 digit
|
||||
return uint256(answer * 10000000000);
|
||||
@@ -22,9 +23,10 @@ library PriceConverter {
|
||||
|
||||
// 1000000000
|
||||
function getConversionRate(
|
||||
uint256 ethAmount
|
||||
uint256 ethAmount,
|
||||
AggregatorV3Interface priceFeed
|
||||
) internal view returns (uint256) {
|
||||
uint256 ethPrice = getPrice();
|
||||
uint256 ethPrice = getPrice(priceFeed);
|
||||
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
|
||||
// or (Both will do the same thing)
|
||||
// uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1e18; // 1 * 10 ** 18 == 1000000000000000000
|
||||
|
||||
Reference in New Issue
Block a user