-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eth price syncer using Chainlink oracle #731
base: main
Are you sure you want to change the base?
Conversation
…h client and price retrieval functions
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
4 Skipped Deployments
|
📦 Next.js Bundle Analysis for @blobscan/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
…p in getPriceByTimestamp function
…PriceByTimestamp function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see this implemented! I've left you some suggestions and a request to improve the documentation for this PR.
@@ -0,0 +1,8 @@ | |||
-- CreateTable | |||
CREATE TABLE "eth_price" ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we are going to save the price in USD, right? Then let's better rename it:
CREATE TABLE "eth_price" ( | |
CREATE TABLE "ethusd_price" ( |
@@ -301,6 +301,14 @@ model OverallStats { | |||
@@map("overall_stats") | |||
} | |||
|
|||
model ETHPrice { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model ETHPrice { | |
model EthUsdPrice { |
}, | ||
}); | ||
|
||
this.logger.info(`Fetched price data: ${JSON.stringify(priceData)}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.logger.info(`Fetched price data: ${JSON.stringify(priceData)}`); | |
this.logger.info(`Fetched price data: ${JSON.stringify(priceData)} USD`); |
@@ -60,6 +60,7 @@ nextjs: | |||
| `WEAVEVM_API_KEY` | API key required to authenticate requests to the WeaveVM blob storage reference updater endpoint | No | (empty) | | |||
| `STATS_SYNCER_DAILY_CRON_PATTERN` | Cron pattern for the daily stats job | No | `30 0 * * * *` | | |||
| `STATS_SYNCER_OVERALL_CRON_PATTERN` | Cron pattern for the overall stats job | No | `*/15 * * * *` | | |||
| `ETH_PRICE_SYNCER_CRON_PATTERN` | Cron pattern for the ETH price job | No | `0 * * * *` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `ETH_PRICE_SYNCER_CRON_PATTERN` | Cron pattern for the ETH price job | No | `0 * * * *` | | |
| `ETH_PRICE_SYNCER_CRON_PATTERN` | Cron pattern for the job that periodically stores ETH price in database | No | `0 * * * *` | |
@@ -83,6 +83,9 @@ export const env = createEnv({ | |||
.url() | |||
.default("http://localhost:4318"), | |||
|
|||
// ETH Price |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ETH Price | |
// ETH Price (default: every minute) |
...mainnet, | ||
rpcUrls: { | ||
default: { | ||
http: [process.env.RPC_URL!], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new variable? If so, remember adding it to the documentation
}); | ||
|
||
if (response === null) { | ||
throw new Error(`No data found for target timestamp: ${targetTimestamp}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error(`No data found for target timestamp: ${targetTimestamp}`); | |
throw new Error(`Could not retrieve ETH price from Chainlink oracle using timestamp: ${targetTimestamp}`); |
* @param tolerance The maximum difference between the target timestamp and the timestamp of the data. | ||
* @returns The price of the asset at the given timestamp. | ||
**/ | ||
export async function getPriceByTimestamp({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you improve this documentation? What I really miss from this PR is a comment that explains the process that you've implemented for querying an oracle using a timestamp. Also explaining the relation with other functions (such as getPhaseAggregators or getClosestRoundData) and adding a link to some external documentation to learn more about the protocol would be helpful.
Checklist
Description
Adds package to fetch the ETH price at a given timestamp.
We need this to complete #685
Related Issue (Optional)
#617