generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26aea23
commit 1d24929
Showing
6 changed files
with
1,070 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useState } from "react"; | ||
import { StatDisplay } from "./AggregatorV3Consumer"; | ||
import { formatUnits } from "viem"; | ||
import { useContractRead } from "wagmi"; | ||
import Denominations from "~~/utils/contract-helpers/Denominations"; | ||
import FeedRegistry from "~~/utils/contract-helpers/FeedRegistry"; | ||
|
||
/** | ||
* @dev figure out how to interact with mainnet | ||
* even tho we are on sepolia | ||
*/ | ||
|
||
const { baseOptions, quoteOptions } = Denominations; | ||
|
||
export const FeedRegistryDisplay = () => { | ||
const [base, setBase] = useState(baseOptions.BTC); | ||
const [quote, setQuote] = useState(quoteOptions.USD); | ||
|
||
const { data: description } = useContractRead({ | ||
address: FeedRegistry.address, | ||
abi: FeedRegistry.abi, | ||
functionName: "description", | ||
args: [base, quote], | ||
chainId: 1, // force request on mainnet | ||
}); | ||
|
||
const { data: roundData } = useContractRead({ | ||
address: FeedRegistry.address, | ||
abi: FeedRegistry.abi, | ||
functionName: "latestRoundData", | ||
args: [base, quote], | ||
chainId: 1, // force request on mainnet | ||
}); | ||
|
||
let price; | ||
// handle typescript rage | ||
if (Array.isArray(roundData) && typeof roundData[1] === "bigint") { | ||
price = roundData[1]; | ||
console.log("$" + formatUnits(price, 8)); | ||
} else { | ||
console.error("Unexpected data format"); | ||
} | ||
|
||
return ( | ||
<div className="bg-base-100 rounded-xl p-10 shadow-lg"> | ||
<h3 className="text-2xl md:text-3xl text-center mb-6 font-bold">FeedRegistry</h3> | ||
|
||
{!price || !description ? ( | ||
<p>loading...</p> | ||
) : ( | ||
<div className="mb-5 flex gap-4 flex-wrap"> | ||
<StatDisplay title="description()" value={"ETH"} type="string" /> | ||
<StatDisplay title="latestRoundData().answer" value={price?.toString()} type="int256" /> | ||
</div> | ||
)} | ||
|
||
<div className="mb-5"> | ||
<div> | ||
<label className="text-xl ml-4">Base Asset</label> | ||
</div> | ||
<select | ||
className="select select-bordered w-full text-center bg-base-200" | ||
value={base} | ||
onChange={e => setBase(e.target.value)} | ||
> | ||
{Object.entries(baseOptions).map(([key, value]) => ( | ||
<option key={key} value={value}> | ||
{key} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
|
||
<div> | ||
<div> | ||
<label className="text-xl ml-4">Quote Asset</label> | ||
</div> | ||
<select | ||
value={quote} | ||
className="select select-bordered w-full text-center bg-base-200" | ||
onChange={e => setQuote(e.target.value)} | ||
> | ||
{Object.entries(quoteOptions).map(([key, value]) => ( | ||
<option key={key} value={value}> | ||
{key} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const toEthereumAddress = (iso4217Code: number): string => { | ||
return `0x${iso4217Code.toString(16).padStart(40, "0")}`; | ||
}; | ||
|
||
// Ethereum address for fiat currency derived from ISO 4217 numeric code!! | ||
const Denominations = { | ||
baseOptions: { | ||
LINK: "0x514910771AF9Ca656af840dff83E8264EcF986CA", | ||
ETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", | ||
BTC: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", | ||
}, | ||
quoteOptions: { | ||
USD: toEthereumAddress(840), | ||
GBP: toEthereumAddress(826), | ||
EUR: toEthereumAddress(978), | ||
JPY: toEthereumAddress(392), | ||
KRW: toEthereumAddress(410), | ||
CNY: toEthereumAddress(156), | ||
AUD: toEthereumAddress(36), | ||
CAD: toEthereumAddress(124), | ||
CHF: toEthereumAddress(756), | ||
ARS: toEthereumAddress(32), | ||
PHP: toEthereumAddress(608), | ||
NZD: toEthereumAddress(554), | ||
SGD: toEthereumAddress(702), | ||
NGN: toEthereumAddress(566), | ||
ZAR: toEthereumAddress(710), | ||
RUB: toEthereumAddress(643), | ||
INR: toEthereumAddress(356), | ||
BRL: toEthereumAddress(986), | ||
}, | ||
}; | ||
|
||
export default Denominations; |
Oops, something went wrong.