Skip to content

Commit

Permalink
Release 25-11-2024 (#255)
Browse files Browse the repository at this point in the history
### Includes

- #253 
- #254 
- #252
  • Loading branch information
Tschakki authored Nov 25, 2024
2 parents 0922def + 359757d commit 97b9bbc
Show file tree
Hide file tree
Showing 10 changed files with 684 additions and 44 deletions.
23 changes: 12 additions & 11 deletions docs/building-on-lisk/using-oracle-data/redstone-pull.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
title: ...with Redstone (Pull)
title: ...with RedStone (Pull)
slug: /building-on-lisk/using-oracle-data/redstone-pull
description: A guide on using Redstone Data Feeds to access real-world data such as asset prices, directly from your smart contracts on the Lisk testnet.
description: A guide on using RedStone Pull to access real-world data such as asset prices, directly from your smart contracts on the Lisk blockchain.
keywords: [
Oracle
Oracles,
Redstone,
RedStone,
price feeds,
data feeds,
smart contract,
Expand All @@ -17,25 +17,26 @@ keywords: [
dapp development,
build a dapp on Lisk,
build on Lisk,
RedStone Pull,
]
---

# Accessing real-world data using the Redstone Oracle
# Accessing real-world data using the RedStone Oracle (Pull)

This page will explain how you can access oracle data using Redstone.
This page will explain how you can access oracle data using [RedStone Pull](https://docs.redstone.finance/docs/get-started/models/redstone-pull/).

RedStone is a data ecosystem that delivers frequently updated, reliable, and diverse data for your dApp and smart contracts deployed on Lisk.

## How to pull oracle data from Redstone
## How to pull oracle data from RedStone

To create a smart contract that directly fetches the latest data from the Redstone oracle, follow this guide.
To create a smart contract that directly fetches the latest data from the RedStone oracle, follow this guide.

This guide uses the [Redstone Pull model](https://docs.redstone.finance/docs/get-started/models/redstone-pull) to fetch the data.
This guide uses the [RedStone Pull model](https://docs.redstone.finance/docs/get-started/models/redstone-pull) to fetch the data.

For an overview of the different modules that Redstone offers to receive oracle data, go to [Oracles > Redstone](../../lisk-tools/oracles#redstone).
For an overview of the different modules that RedStone offers to receive oracle data, go to [Oracles > RedStone](../../lisk-tools/oracles#redstone).

[Hardhat](https://hardhat.org/) is used in this guide to create the smart contract.
In case you want to use Foundry, check out the [Redstone docs](https://docs.redstone.finance/docs/get-started/models/redstone-pull#foundry) for instructions.
In case you want to use Foundry, check out the [RedStone docs](https://docs.redstone.finance/docs/get-started/models/redstone-pull#foundry) for instructions.

### Dependencies

Expand Down Expand Up @@ -124,7 +125,7 @@ import { ethers } from "hardhat";
import { WrapperBuilder } from "@redstone-finance/evm-connector";

describe("YourContract", function () {
describe("Redstone", function () {
describe("RedStone", function () {
it("Get ETH price securely", async function () {
const YourContract = await ethers.getContractFactory("YourContract");
const contract = await YourContract.deploy();
Expand Down
216 changes: 216 additions & 0 deletions docs/building-on-lisk/using-oracle-data/redstone-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
---
title: ...with RedStone (Push)
slug: /building-on-lisk/using-oracle-data/redstone-push
description: A guide on using RedStone Push to access real-world data such as asset prices, directly from your smart contracts on the Lisk blockchain.
keywords: [
Oracle
Oracles,
RedStone,
price feeds,
data feeds,
smart contract,
Lisk blockchain,
Lisk network,
Lisk testnet,
Lisk test network,
app development,
dapp development,
build a dapp on Lisk,
build on Lisk,
RedStone Push,
]
---

# Accessing real-world data using the RedStone Oracle (Push)

This page will explain how you can access oracle data using [RedStone Push](https://docs.redstone.finance/docs/get-started/models/redstone-push).

RedStone is a data ecosystem that delivers frequently updated, reliable, and diverse data for your dApp and smart contracts deployed on Lisk.

RedStone data feeds are compatible with Chainlink's [AggregatorV3Interface](https://docs.chain.link/data-feeds/using-data-feeds#solidity) and include the following components:

- **Aggregator contract**: An aggregator is a contract that receives periodic data updates from the oracle network.
Aggregators store aggregated data onchain so that consumers can retrieve it and act upon it within the same transaction.
These contracts have already been deployed on the Lisk network and can be directly used by consumers.
- **Consumer**: A consumer is an onchain or offchain application that uses Data Feeds.
Consumer contracts use the `AggregatorV3Interface` to call functions on the proxy contract[^1] of the Aggregator to retrieve oracle data.

[^1]: Proxy contracts are onchain proxies that point to the aggregator for a particular data feed.
Using proxies enables the underlying aggregator to be upgraded without any service interruption to consuming contracts.

## Data feeds on Lisk
The following Aggregators are available on Lisk Mainnet for RedStone Push:

- [ETH/USD L2PriceFeedWithoutRounds](https://blockscout.lisk.com/address/0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2)
- address: `0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2`
- [LSK/USD L2PriceFeedWithoutRounds](https://blockscout.lisk.com/address/0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96)
- address: `0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96`
- [USDT/USD L2PriceFeedWithoutRounds](https://blockscout.lisk.com/address/0xd2176Dd57D1e200c0A8ec9e575A129b511DBD3AD)
- address: `0xd2176Dd57D1e200c0A8ec9e575A129b511DBD3AD`
- [USDC/USD L2PriceFeedWithoutRounds](https://blockscout.lisk.com/address/0xb4e6A7861067674AC398a26DD73A3c524C602184)
- address: `0xb4e6A7861067674AC398a26DD73A3c524C602184`
- [WBTC/USD L2PriceFeedWithoutRounds](https://blockscout.lisk.com/address/0x13da43eA89fB692bdB6666F053FeE70aC61A53cd)
- address: `0x13da43eA89fB692bdB6666F053FeE70aC61A53cd`

In this guide, we will develop a Consumer contract that requests the latest spot prices from the ETH, LSK, and USDT data feeds.

:::note
RedStone Push is only fully available on Lisk Mainnet, so please make sure to deploy your Consumer contract on Lisk Mainnet as well.

In case you wish to deploy on Lisk Sepolia Testnet, check the [Tellor](./tellor.md) guide, which is available for both networks.
:::

## Import

To use the RedStone data inside your contract, import the [AggregatorV3Interface](https://docs.chain.link/data-feeds/using-data-feeds#solidity) from Chainlink, as shown in the example contract below.

Create a new constant with the type `AggregatorV3Interface` for every data feed you want to store.

In the constructor, set the above-defined constants to point to the respective data feeds.
Use the `AggregatorV3Interface()` function and pass the address of the respective data feed contract as a parameter.

```solidity title="Importing the AggregatorV3Interface"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
contract RedStoneDataConsumer {
AggregatorV3Interface internal dataFeedETH;
AggregatorV3Interface internal dataFeedLSK;
AggregatorV3Interface internal dataFeedUSDT;
/**
* Network: Lisk
* Aggregator: ETH/USD
* Address: 0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2
*/
/**
* Network: Lisk
* Aggregator: LSK/USD
* Address: 0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96
*/
/**
* Network: Lisk
* Aggregator: USDT/USD
* Address: 0xd2176Dd57D1e200c0A8ec9e575A129b511DBD3AD
*/
constructor() {
dataFeedETH = AggregatorV3Interface(
0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2
);
dataFeedLSK = AggregatorV3Interface(
0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96
);
dataFeedUSDT = AggregatorV3Interface(
0xd2176Dd57D1e200c0A8ec9e575A129b511DBD3AD
);
}
}
```

## Reading data
To read the data of the price feeds, we define the following functions in the contract:

- `getRedStoneETHDataFeedLatestAnswer()`
- `getRedStoneLSKDataFeedLatestAnswer()`
- `getRedStoneUSDTDataFeedLatestAnswer()`

Inside the functions, call the [latestRoundData](https://docs.chain.link/data-feeds/api-reference#latestrounddata) on the respective data feeds to receive the latest spot prices for the respective token.

The `latestRoundData()` function returns the following values:

- `roundId`(uint80): The round ID.
For all [data feeds](#data-feeds-on-lisk), the round is always `1`, because the contracts are without rounds, as the name suggests.
- `answer`(int256): The data that this specific feed provides.
Depending on the feed you selected, this answer provides asset prices, reserves, and other types of data.
- `startedAt`(uint256): Timestamp of when the round started.
- `updatedAt`(uint256): Timestamp of when the round was updated.
- `answeredInRound`(uint80): Deprecated - Previously used when answers could take multiple rounds to be computed.

In this example, we will only use `answer` and `updatedAt`.
The `updatedAt` value should be used to make sure that the `answer` is recent enough for your application to use it.
You can compare `updatedAt` to the latest block time (`uint256 currentTime = block.timestamp;`) to ensure you are only using the latest oracle data in your application.

:::caution
This is an example contract that uses un-audited code.
Do not use this code in production.
:::

```solidity title="Reading data feeds"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
contract RedStoneDataConsumer {
AggregatorV3Interface internal priceFeedETH;
AggregatorV3Interface internal priceFeedLSK;
AggregatorV3Interface internal priceFeedUSDT;
constructor() {
priceFeedETH = AggregatorV3Interface(
0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2
);
priceFeedLSK = AggregatorV3Interface(
0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96
);
priceFeedUSDT = AggregatorV3Interface(
0xd2176Dd57D1e200c0A8ec9e575A129b511DBD3AD
);
}
/**
* Returns the latest ETH price, and when it was updated.
*/
function getRedStoneETHDataFeedLatestAnswer() public view returns (int, uint) {
(
/* uint80 roundID */,
int answer,
uint updatedAt,
/*uint startedAt*/,
/*uint80 answeredInRound*/
) = priceFeedETH.latestRoundData();
return (answer, updatedAt);
}
/**
* Returns the latest LSK price, and when it was updated.
*/
function getRedStoneLSKDataFeedLatestAnswer() public view returns (int, uint) {
(
/* uint80 roundID */,
int answer,
uint updatedAt,
/*uint startedAt*/,
/*uint80 answeredInRound*/
) = priceFeedLSK.latestRoundData();
return (answer, updatedAt);
}
/**
* Returns the latest USDT price, and when it was updated.
*/
function getRedStoneUSDTDataFeedLatestAnswer() public view returns (int, uint) {
(
/* uint80 roundID */,
int answer,
uint updatedAt,
/*uint startedAt*/,
/*uint80 answeredInRound*/
) = priceFeedUSDT.latestRoundData();
return (answer, updatedAt);
}
}
```

## Deploying on Lisk

To deploy the smart contract on Lisk, follow the guides

- [Deploying a smart contract with Hardhat](../deploying-smart-contract/with-Hardhat), or
- [Deploying a smart contract with Foundry](../deploying-smart-contract/with-Foundry)

:::note
RedStone Push is only available on Lisk Mainnet, so please make sure to deploy your Consumer contract on Lisk Mainnet as well.

In case you wish to deploy on Lisk Sepolia Testnet, check the [Tellor](./tellor.md) guide, which is available for both networks.
:::
4 changes: 3 additions & 1 deletion docs/building-on-lisk/using-oracle-data/tellor.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: ...with Tellor
slug: /building-on-lisk/using-oracle-data/tellor
description: A guide on using Redstone Data Feeds to access real-world data such as asset prices, directly from your smart contracts on the Lisk testnet.
description: A guide on using Tellor Data Feeds to access real-world data such as asset prices, directly from your smart contracts on the Lisk blockchain.
keywords: [
Oracle
Oracles,
Expand All @@ -21,6 +21,8 @@ keywords: [
---

# Using oracle data with Tellor
This page will explain how your application can access oracle data using Tellor.

[Tellor](https://tellor.io/) is an immutable decentralized oracle protocol where parties can request the value of an offchain data point (e.g. ETH/USD, LSK/USD) and reporters compete to add this value to an onchain databank.
The inputs to this databank are secured by a network of staked reporters.

Expand Down
24 changes: 9 additions & 15 deletions docs/docs-user/exchanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ Lisk (LSK) is available for trading on various <!-- decentralized and centralize
| **Zonda** | 🟡 Ethereum | [LSK/USDT](https://zondacrypto.com/en/exchange-rate/lisk-price-usdt)<br />[LSK/EUR](https://zondacrypto.com/en/exchange-rate/lisk-price-eur)<br />[LSK/BTC](https://zondacrypto.com/en/exchange-rate/lisk-price-btc)<br />[LSK/PLN](https://zondacrypto.com/en/exchange-rate/lisk-price-pln) |


## Decentralized Exchanges (DEX)

| Name | Supported network[^1] |
| :---------------------------- | :------------------------------------------ |
| [Oku.Trade](https://oku.trade/app/lisk/trade/0xac485391eb2d7d88253a7f1ef18c37f4242d1a24) | 🟢 Lisk |
| [Velodrome](https://velodrome.finance/swap?from=0xac485391eb2d7d88253a7f1ef18c37f4242d1a24&to=0x05d032ac25d322df992303dca074ee7392c117b9&chain0=1135&chain1=1135) | 🟢 Lisk |
| [Uniswap](https://app.uniswap.org/explore/tokens/ethereum/0x6033f7f88332b8db6ad452b7c6d5bb643990ae3f) | 🟡 Ethereum |

[^1]: The LSK token is supported on both the Ethereum L1 and the Lisk L2 blockchains.
The "supported network" field indicates the blockchain being used by the exchange for deposits & withdrawals of LSK.
Please note that using the wrong network/blockchain when depositing funds to an exchange could result in lost funds.

### Coming soon
## Coming soon

| Name | Supported network |
| :----------------------- |:----------------- |
Expand All @@ -67,17 +75,3 @@ Please note that using the wrong network/blockchain when depositing funds to an
| **OkCoin** (OKX Japan) | Lisk |
| **YellowCard** (Africa) | Lisk |

## Decentralized Exchanges (DEX)

| Name | Supported network[^1] |
| :---------------------------- | :------------------------------------------ |
| [Oku.Trade](https://oku.trade/app/lisk/trade/0xac485391eb2d7d88253a7f1ef18c37f4242d1a24) | 🟢 Lisk |
| [Uniswap](https://app.uniswap.org/explore/tokens/ethereum/0x6033f7f88332b8db6ad452b7c6d5bb643990ae3f) | 🟡 Ethereum |

### Coming soon

| Name |
| :---------------------------- |
| **Velodrome** |


2 changes: 1 addition & 1 deletion docs/lisk-tools/oracles.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Interested in integration? [Get in contact](https://discord.com/invite/PVxBZKFr4
#### Supported Networks

- Lisk
- Lisk Sepolia

### Guides

- [Accessing oracle data with Redstone (Pull)](../building-on-lisk/using-oracle-data/redstone-pull.md)
- [Accessing oracle data with Redstone (Push)](../building-on-lisk/using-oracle-data/redstone-push.md)

## Tellor

Expand Down
Loading

0 comments on commit 97b9bbc

Please sign in to comment.