Skip to content

Add Chronicle example #340

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

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions contracts/src/defi/chronicle-price-oracle/chroniclePriceOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/**
* @title OracleReader
* @notice A simple contract to read from Chronicle oracles
* @dev To see the full repository, visit https://github.com/chronicleprotocol/OracleReader-Example.
* @dev Addresses in this contract are hardcoded for the Sepolia testnet.
* For other supported networks, check the https://chroniclelabs.org/dashboard/oracles.
*/
contract OracleReader {
/**
* @notice The Chronicle oracle to read from.
* Chronicle_ETH_USD_3:0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603
* Network: Sepolia
*/

IChronicle public chronicle = IChronicle(address(0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603));

/**
* @notice The SelfKisser granting access to Chronicle oracles.
* SelfKisser_1:0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d
* Network: Sepolia
* For a full list of SelfKisser addresses on different Testnet networks
* please check here https://docs.chroniclelabs.org/Developers/tutorials/Remix
*/
ISelfKisser public selfKisser = ISelfKisser(address(0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d));

constructor() {
// Note to add address(this) to chronicle oracle's whitelist.
// This allows the contract to read from the chronicle oracle.
selfKisser.selfKiss(address(chronicle));
}

/**
* @notice Function to read the latest data from the Chronicle oracle.
* @return val The current value returned by the oracle.
* @return age The timestamp of the last update from the oracle.
*/
function read() external view returns (uint256 val, uint256 age) {
(val, age) = chronicle.readWithAge();
}
}

// Copied from [chronicle-std](https://github.com/chronicleprotocol/chronicle-std/blob/main/src/IChronicle.sol).
interface IChronicle {
/**
* @notice Returns the oracle's current value.
* @dev Reverts if no value set.
* @return value The oracle's current value.
*/
function read() external view returns (uint256 value);

/**
* @notice Returns the oracle's current value and its age.
* @dev Reverts if no value set.
* @return value The oracle's current value using 18 decimals places.
* @return age The value's age as a Unix Timestamp .
* */
function readWithAge() external view returns (uint256 value, uint256 age);
}

// Copied from [self-kisser](https://github.com/chronicleprotocol/self-kisser/blob/main/src/ISelfKisser.sol).
interface ISelfKisser {
/// @notice Kisses caller on address.
function selfKiss(address oracle) external;
}
1 change: 1 addition & 0 deletions src/keywords.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"/defi/dai-proxy": ["defi", "dai", "proxy"],
"/defi/constant-sum-amm": ["defi", "constant", "sum", "amm"],
"/defi/constant-product-amm": ["defi", "constant", "product", "amm"],
"/defi/chronicle-price-oracle": ["defi", "chronicle", "price", "oracle", "oracles"],
"/defi/chainlink-price-oracle": ["defi", "chainlink", "price", "oracle", "oracles"],
"/data-locations": ["data", "location", "locations", "storage", "memory", "calldata"],
"/constructor": ["constructor", "constructors", "contract", "inheritance"],
Expand Down
4 changes: 4 additions & 0 deletions src/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ export const DEFI_ROUTES = [
path: "chainlink-price-oracle",
title: "Chainlink Price Oracle",
},
{
path: "chronicle-price-oracle",
title: "Chronicle Price Oracle",
},
{
path: "dai-proxy",
title: "DAI Proxy",
Expand Down
67 changes: 67 additions & 0 deletions src/pages/defi/chronicle-price-oracle/chroniclePriceOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

/**
* @title OracleReader
* @notice A simple contract to read from Chronicle oracles
* @dev To see the full repository, visit https://github.com/chronicleprotocol/OracleReader-Example.
* @dev Addresses in this contract are hardcoded for the Sepolia testnet.
* For other supported networks, check the https://chroniclelabs.org/dashboard/oracles.
*/
contract OracleReader {
/**
* @notice The Chronicle oracle to read from.
* Chronicle_ETH_USD_3:0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603
* Network: Sepolia
*/

IChronicle public chronicle = IChronicle(address(0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603));

/**
* @notice The SelfKisser granting access to Chronicle oracles.
* SelfKisser_1:0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d
* Network: Sepolia
* For a full list of SelfKisser addresses on different Testnet networks
* please check here https://docs.chroniclelabs.org/Developers/tutorials/Remix
*/
ISelfKisser public selfKisser = ISelfKisser(address(0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d));

constructor() {
// Note to add address(this) to chronicle oracle's whitelist.
// This allows the contract to read from the chronicle oracle.
selfKisser.selfKiss(address(chronicle));
}

/**
* @notice Function to read the latest data from the Chronicle oracle.
* @return val The current value returned by the oracle.
* @return age The timestamp of the last update from the oracle.
*/
function read() external view returns (uint256 val, uint256 age) {
(val, age) = chronicle.readWithAge();
}
}

// Copied from [chronicle-std](https://github.com/chronicleprotocol/chronicle-std/blob/main/src/IChronicle.sol).
interface IChronicle {
/**
* @notice Returns the oracle's current value.
* @dev Reverts if no value set.
* @return value The oracle's current value.
*/
function read() external view returns (uint256 value);

/**
* @notice Returns the oracle's current value and its age.
* @dev Reverts if no value set.
* @return value The oracle's current value using 18 decimals places.
* @return age The value's age as a Unix Timestamp .
* */
function readWithAge() external view returns (uint256 value, uint256 age);
}

// Copied from [self-kisser](https://github.com/chronicleprotocol/self-kisser/blob/main/src/ISelfKisser.sol).
interface ISelfKisser {
/// @notice Kisses caller on address.
function selfKiss(address oracle) external;
}
86 changes: 86 additions & 0 deletions src/pages/defi/chronicle-price-oracle/index.html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// metadata
export const version = "0.8.26"
export const title = "Chronicle Price Oracle"
export const description = "Chronicle Price Oracle"
export const cyfrinLink = ""

export const keywords = ["defi", "chronicle", "price", "oracle", "oracles"]

export const codes = [
{
fileName: "chroniclePriceOracle.sol",
code: "Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4xNjsKCi8qKgogKiBAdGl0bGUgT3JhY2xlUmVhZGVyCiAqIEBub3RpY2UgQSBzaW1wbGUgY29udHJhY3QgdG8gcmVhZCBmcm9tIENocm9uaWNsZSBvcmFjbGVzCiAqIEBkZXYgVG8gc2VlIHRoZSBmdWxsIHJlcG9zaXRvcnksIHZpc2l0IGh0dHBzOi8vZ2l0aHViLmNvbS9jaHJvbmljbGVwcm90b2NvbC9PcmFjbGVSZWFkZXItRXhhbXBsZS4KICogQGRldiBBZGRyZXNzZXMgaW4gdGhpcyBjb250cmFjdCBhcmUgaGFyZGNvZGVkIGZvciB0aGUgU2Vwb2xpYSB0ZXN0bmV0LgogKiBGb3Igb3RoZXIgc3VwcG9ydGVkIG5ldHdvcmtzLCBjaGVjayB0aGUgaHR0cHM6Ly9jaHJvbmljbGVsYWJzLm9yZy9kYXNoYm9hcmQvb3JhY2xlcy4KICovCmNvbnRyYWN0IE9yYWNsZVJlYWRlciB7CiAgICAvKioKICAgICogQG5vdGljZSBUaGUgQ2hyb25pY2xlIG9yYWNsZSB0byByZWFkIGZyb20uCiAgICAqIENocm9uaWNsZV9FVEhfVVNEXzM6MHhkZDZENzYyNjJGZDdCZERlNDI4ZGNmQ2Q5NDM4NkViQWUwMTUxNjAzCiAgICAqIE5ldHdvcms6IFNlcG9saWEKICAgICovCgogICAgSUNocm9uaWNsZSBwdWJsaWMgY2hyb25pY2xlID0gSUNocm9uaWNsZShhZGRyZXNzKDB4ZGQ2RDc2MjYyRmQ3QmREZTQyOGRjZkNkOTQzODZFYkFlMDE1MTYwMykpOwoKICAgIC8qKiAKICAgICogQG5vdGljZSBUaGUgU2VsZktpc3NlciBncmFudGluZyBhY2Nlc3MgdG8gQ2hyb25pY2xlIG9y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6Ly9naXRodWIuY29tL2Nocm9uaWNsZXByb3RvY29sL3NlbGYta2lzc2VyL2Jsb2IvbWFpbi9zcmMvSVNlbGZLaXNzZXIuc29sKS4KaW50ZXJmYWNlIElTZWxmS2lzc2VyIHsKICAgIC8vLyBAbm90aWNlIEtpc3NlcyBjYWxsZXIgb24gYWRkcmVzcy4KICAgIGZ1bmN0aW9uIHNlbGZLaXNzKGFkZHJlc3Mgb3JhY2xlKSBleHRlcm5hbDsKfQ==",
},
]

const html = `<h3>ETH / USD Price Oracle</h3>
<pre><code class="language-solidity"><span class="hljs-comment">// SPDX-License-Identifier: MIT</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.16;</span>

<span class="hljs-comment">/**
* @title OracleReader
* @notice A simple contract to read from Chronicle oracles
* @dev To see the full repository, visit https://github.com/chronicleprotocol/OracleReader-Example.
* @dev Addresses in this contract are hardcoded for the Sepolia testnet.
* For other supported networks, check the https://chroniclelabs.org/dashboard/oracles.
*/</span>
<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">OracleReader</span> </span>{
<span class="hljs-comment">/**
* @notice The Chronicle oracle to read from.
* Chronicle_ETH_USD_3:0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603
* Network: Sepolia
*/</span>

IChronicle <span class="hljs-keyword">public</span> chronicle <span class="hljs-operator">=</span> IChronicle(<span class="hljs-keyword">address</span>(<span class="hljs-number">0xdd6D76262Fd7BdDe428dcfCd94386EbAe0151603</span>));

<span class="hljs-comment">/**
* @notice The SelfKisser granting access to Chronicle oracles.
* SelfKisser_1:0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d
* Network: Sepolia
* For a full list of SelfKisser addresses on different Testnet networks
* please check here https://docs.chroniclelabs.org/Developers/tutorials/Remix
*/</span>
ISelfKisser <span class="hljs-keyword">public</span> selfKisser <span class="hljs-operator">=</span> ISelfKisser(<span class="hljs-keyword">address</span>(<span class="hljs-number">0x0Dcc19657007713483A5cA76e6A7bbe5f56EA37d</span>));

<span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-comment">// Note to add address(this) to chronicle oracle&#x27;s whitelist.</span>
<span class="hljs-comment">// This allows the contract to read from the chronicle oracle.</span>
selfKisser.selfKiss(<span class="hljs-keyword">address</span>(chronicle));
}

<span class="hljs-comment">/**
* @notice Function to read the latest data from the Chronicle oracle.
* @return val The current value returned by the oracle.
* @return age The timestamp of the last update from the oracle.
*/</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">read</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span> val, <span class="hljs-keyword">uint256</span> age</span>) </span>{
(val, age) <span class="hljs-operator">=</span> chronicle.readWithAge();
}
}

<span class="hljs-comment">// Copied from [chronicle-std](https://github.com/chronicleprotocol/chronicle-std/blob/main/src/IChronicle.sol).</span>
<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IChronicle</span> </span>{
<span class="hljs-comment">/**
* @notice Returns the oracle&#x27;s current value.
* @dev Reverts if no value set.
* @return value The oracle&#x27;s current value.
*/</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">read</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span> value</span>)</span>;

<span class="hljs-comment">/**
* @notice Returns the oracle&#x27;s current value and its age.
* @dev Reverts if no value set.
* @return value The oracle&#x27;s current value using 18 decimals places.
* @return age The value&#x27;s age as a Unix Timestamp .
* */</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">readWithAge</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span> value, <span class="hljs-keyword">uint256</span> age</span>)</span>;
}

<span class="hljs-comment">// Copied from [self-kisser](https://github.com/chronicleprotocol/self-kisser/blob/main/src/ISelfKisser.sol).</span>
<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">ISelfKisser</span> </span>{
<span class="hljs-comment">/// @notice Kisses caller on address.</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">selfKiss</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> oracle</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
}
</code></pre>`

export default html
12 changes: 12 additions & 0 deletions src/pages/defi/chronicle-price-oracle/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Chronicle Price Oracle
version: 0.8.26
description: Chronicle Price Oracle
keywords: [defi, chronicle, price, oracle, oracles]
---

### ETH / USD Price Oracle

```solidity
{{{chroniclePriceOracle}}}
```
30 changes: 30 additions & 0 deletions src/pages/defi/chronicle-price-oracle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react"
import Example from "../../../components/Example"
import html, { version, title, description, cyfrinLink, codes } from "./index.html"

interface Path {
path: string
title: string
}

interface Props {
prev: Path | null
next: Path | null
}

const ExamplePage: React.FC<Props> = ({ prev, next }) => {
return (
<Example
version={version}
title={title}
description={description}
cyfrinLink={cyfrinLink}
html={html}
prev={prev}
next={next}
codes={codes}
/>
)
}

export default ExamplePage
1 change: 0 additions & 1 deletion src/pages/signature/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ uint256 _nonce: 1
- Copy the returned messageHash

2. Sign the messageHash:

- In "Deploy & Run Transactions" tab (which you're supposed to be on already)
- Select the first account
- Click on the icon after the `+` which is to sign a message, it will open a popup
Expand Down
5 changes: 5 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import component_constants from "./pages/constants"
import component_constructor from "./pages/constructor"
import component_data_locations from "./pages/data-locations"
import component_defi_chainlink_price_oracle from "./pages/defi/chainlink-price-oracle"
import component_defi_chronicle_price_oracle from "./pages/defi/chronicle-price-oracle"
import component_defi_constant_product_amm from "./pages/defi/constant-product-amm"
import component_defi_constant_sum_amm from "./pages/defi/constant-sum-amm"
import component_defi_dai_proxy from "./pages/defi/dai-proxy"
Expand Down Expand Up @@ -297,6 +298,10 @@ const routes: Route[] = [
path: "/defi/chainlink-price-oracle",
component: component_defi_chainlink_price_oracle,
},
{
path: "/defi/chronicle-price-oracle",
component: component_defi_chronicle_price_oracle,
},
{
path: "/defi/constant-product-amm",
component: component_defi_constant_product_amm,
Expand Down
8 changes: 5 additions & 3 deletions src/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@
"/defi/dai-proxy",
"/defi/constant-sum-amm",
"/defi/constant-product-amm",
"/defi/chronicle-price-oracle",
"/defi/chainlink-price-oracle"
],
"uniswap": [
Expand Down Expand Up @@ -551,10 +552,11 @@
"proxy": ["/defi/dai-proxy", "/app/upgradeable-proxy", "/app/minimal-proxy"],
"sum": ["/defi/constant-sum-amm"],
"product": ["/defi/constant-product-amm"],
"chronicle": ["/defi/chronicle-price-oracle"],
"price": ["/defi/chronicle-price-oracle", "/defi/chainlink-price-oracle"],
"oracle": ["/defi/chronicle-price-oracle", "/defi/chainlink-price-oracle"],
"oracles": ["/defi/chronicle-price-oracle", "/defi/chainlink-price-oracle"],
"chainlink": ["/defi/chainlink-price-oracle"],
"price": ["/defi/chainlink-price-oracle"],
"oracle": ["/defi/chainlink-price-oracle"],
"oracles": ["/defi/chainlink-price-oracle"],
"location": ["/data-locations"],
"locations": ["/data-locations"],
"calldata": ["/data-locations"],
Expand Down