bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 7쪽
nstructions detailed in the section
Specifying chains
.
Important:
You must specify in your token's
data.json
file a section for
lisk-sepolia
and/or
lisk
.
This PR
shows the changes necessary to add the LSK token to the Superchain Token Registry.
The change you need to submit is particularly simple if your token has already been added to the Superchain Token Registry.
For example,
this PR
shows the change required for cbETH, which was already on Superchain Token Registry and relies on the Base standard bridge.
Step 3: Await final approval
Reviews are regularly conducted by the Lisk team and you should receive a reply within 24-72 hours (depending on if the PR is opened on a weekday, weekend or holiday).
Footnotes
The
IOptimismMintableERC20
interface is a superset of the
standard ERC-20 interface
and includes functions that allow the bridge to properly verify deposits/withdrawals and mint/burn tokens as needed.
All bridged versions of tokens must implement this interface in order to be bridged with the
Standard Bridge
system.
Native tokens do not need to implement this interface.
↩
Superchain Token List
The Standard Bridge
Adding your token to the Superchain Token List
Step 1: Deploy your token on Lisk
Step 2: Submit details of your token
Step 3: Await final approval
## /guides/using-oracle-data/redstone-pull
On this page
This page will explain how you can access oracle data using
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
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
to fetch the data.
For an overview of the different modules that RedStone offers to receive oracle data, go to
Oracles > RedStone
.
Hardhat
is used in this guide to create the smart contract.
In case you want to use Foundry, check out the
RedStone docs
for instructions.
Dependencies
ethers ^5.7.2
hardhat ^2.14.0
Install the evm connector
Install the
@redstone-finance/evm-connector
package.
npm
install
@redstone-finance/evm-connector
Import the evm connector
// SPDX-License-Identifier: UNLICENSED
pragma
solidity
^
0.8.9
;
/**
* Imports the EVM connector
*/
import
"@redstone-finance/evm-connector/contracts/data-services/RapidDemoConsumerBase.sol"
;
contract
YourContract
is
RapidDemoConsumerBase
{
// ...
}
Get oracle data
Get the oracle data using the functions provided by the EVM connector.
Get a single value
To get a single price feed, use the function
getOracleNumericValueFromTxMsg()
and provide the data feed ID as a parameter.
// SPDX-License-Identifier: UNLICENSED
pragma
solidity
^
0.8.9
;
/**
* Imports the EVM connector
*/
import
"@redstone-finance/evm-connector/contracts/data-services/RapidDemoConsumerBase.sol"
;
contract
YourContract
is
RapidDemoConsumerBase
{
// ...
/**
* Returns the latest price of ETH
*/
function
getLatestEthPrice
(
)
public
view
returns
(
uint256
)
{
bytes32
dataFeedId
=
bytes32
(
"ETH"
)
;
return
getOracleNumericValueFromTxMsg
(
dataFeedId
)
;
}
}
Get multiple values
To get data from multiple price feeds, use the function
getOracleNumericValuesFromTxMsg()
and provide the data feed ID array as a parameter.
/**
* Returns the latest prices of ETH and BTC
*/
function
getLatestEthBtcPrices
(
)
public
view
returns
(
uint256
[
]
memory
)
{
bytes32
[
]
memory
dataFeedIds
=
new
bytes32
[
]
(
2
)
;
dataFeedIds
[
0
]
=
bytes32
(
"ETH"
)
;
dataFeedIds
[
1
]
=
bytes32
(
"BTC"
)
;
uint256
[
]
memory
values
=
getOracleNumericValuesFromTxMsg
(
dataFeedIds
)
;
return
values
;
}
Testing
In order to test the EVM connector related functions in your contract, it is necessary to wrap the contract using the
WrapperBuilder
provided by the
@redstone-finance/evm-connector
package.
test/YourContract.ts
import
{
expect
}
from
"chai"
;
import
{
ethers
}
from
"hardhat"
;
import
{
WrapperBuilder
}
from
"@redstone-finance/evm-connector"
;
describe
(
"YourContract"
,
function
(
)
{
describe
(
"RedStone"
,
function
(
)
{
it
(
"Get ETH price securely"
,
async
function
(
)
{
const
YourContract
=
await
ethers
.
getContractFactory
(
"YourContract"
)
;
const
contract
=
await
YourContract
.
deploy
(
)
;
const
wrappedContract
=
WrapperBuilder
.
wrap
(
contract
)
.
usingDataService
(
{
dataFeeds
:
[
"ETH"
]
,
}
)
;
// Interact with the contract (getting oracle value securely)
const
ethPriceFromContract
=
await
wrappedContract
.
getLatestEthPrice
(
)
;
console
.
log
(
"Latest ETH price:"
)
;
console
.
log
(
{
ethPriceFromContract
}
)
;
}
)
;
}
)
;
}
)
;
Now run the test:
npx hardhat
test
This should output the latest ETH price in the console:
Latest ETH price:
{ ethPriceFromContract: BigNumber { value: "250255087192" } }
Deploying on Lisk
To deploy the smart contract on Lisk Sepolia or Lisk Mainnet, follow the guides
Deploying a smart contract with Hardhat
, or
Deploying a smart contract with Foundry
How to pull oracle data from RedStone
Dependencies
Install the evm connector
Import the evm connector
Get oracle data
Testing
Deploying on Lisk
## /guides/using-oracle-data/redstone-push
On this page
This page will explain how you can access oracle data using
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
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.
Data feeds on Lisk
The following Aggregators are available on Lisk Mainnet for RedStone Push:
L2PriceFeedWithoutRounds
ETH/USD token pair
address:
0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2
LSK/USD token pair
address:
0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96
USDT/USD token pair
address:
0xd2176Dd57D1e200c0A8ec9e575A129b511DBD3AD
USDC/USD token pair
address:
0xb4e6A7861067674AC398a26DD73A3c524C602184
WBTC/USD token pair
address:
0x13da43eA89fB692bdB6666F053FeE70aC61A53cd
BTC/USD token pair
address:
0xd50f47a9173d67c3CfCb6a28CA8d60230bE0f5f0
wstETH/ETH token pair
address
0x731f330542734B4059334ca8e1Da30AF358b41b2
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.
Import
To use the RedStone data inside your contract, import the
AggregatorV3Interface
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.
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
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
, 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.
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
, or
Deploying a 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.
Footnotes
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
L2PriceFeedWithoutRounds
Import
Reading data
Deploying on Lisk
## /guides/deploying-smart-contract/with-Foundry
On this page
In this guide, we discuss the basics of the
Foundry
development toolchain and will describe how to create and deploy a smart contract with Foundry to the
Lisk Sepolia
testnet.
note
You can deploy a contract on
Lisk
mainnet by adopting the same process.
For deploying to mainnet, ensure that your wallet has enough ETH.
The subsequent text contains commands for both Lisk and Lisk Sepolia for your ease.
For more information, see the
available Lisk networks
and
how to connect a wallet with them
.
Foundry is a powerful suite of tools to develop, test, and debug your smart contracts.
It comprises several individual tools such as:
forge
: is a command-line tool that is shipped with Foundry.
Forge tests, builds, and deploys your smart contracts.
cast
: is a command-line tool for performing RPC calls e.g., interacting with contracts, sending transactions, and getting onchain data.
anvil
: is a local testnet node, designed for testing contract behavior from a frontend or over RPC in a local development environment.
chisel
: is a Solidity
REPL
, for trying out Solidity snippets on a local or forked network.
Prerequisites
To build with Foundry, you need:
A basic understanding of
Solidity
.
Have Foundry installed on your system.
To do that, perform the following steps:
From the command line, run:
curl
-L
https://foundry.paradigm.xyz
|
bash
After that, to install the latest (nightly) build of Foundry, run:
foundryup
For more information, see the Foundry Book's
Installation guide
.
Wallet funds
Deploying contracts
to the blockchain requires a
gas fee
.
Therefore, you will need to fund your wallet with ETH to cover such gas fees.
For this guide, you will be deploying a contract to the Lisk Sepolia Testnet.
You can deposit the required tokens by using the
Lisk Sepolia Bridge
.
In case your wallet doesn't hold enough
SepoliaETH
, use one of the available faucets for the
Ethereum Sepolia
Testnet like
https://sepoliafaucet.com
to receive free Testnet ETH.
Then, use the aforementioned Lisk Bridge to send tokens from the
Ethereum Sepolia Testnet
to the
Lisk Sepolia Testnet
.
Creating a project
The first step of deploying smart contracts to Lisk is to set up your development environment by creating a Foundry project.
You can separately create a new directory and then initialize a Foundry project, or you can let Foundry create a directory and initiate a Foundry project by running the following command:
forge init foundry_app
&&
cd
foundry_app
This command will create a
foundry_app
and will change the terminal's working directory to the aforementioned folder as well.
Execution logs of the
forge init
command
Initializing /XYZ/L2/25/foundry_app/foundry_app...
Installing forge-std in /XYZ/L2/25/foundry_app/foundry_app/lib/forge-std (url: Some("https://github.com/foundry-rs/forge-std"), tag: None)
Cloning into '/XYZ/L2/25/foundry_app/foundry_app/lib/forge-std'...
remote: Enumerating objects: 2181, done.
remote: Counting objects: 100% (2177/2177), done.
remote: Compressing objects: 100% (737/737), done.
remote: Total 2181 (delta 1446), reused 2066 (delta 1373), pack-reused 4
Receiving objects: 100% (2181/2181), 614.11 KiB | 766.00 KiB/s, done.
Resolving deltas: 100% (1446/1446), done.
Submodule 'lib/ds-test' (https://github.com/dapphub/ds-test) registered for path 'lib/ds-test'
Cloning into '/XYZ/L2/25/foundry_app/foundry_app/lib/forge-std/lib/ds-test'...
remote: Enumerating objects: 313, done.
remote: Counting objects: 100% (171/171), done.
remote: Compressing objects: 100% (79/79), done.
remote: Total 313 (delta 91), reused 132 (delta 83), pack-reused 142
Receiving objects: 100% (313/313), 71.35 KiB | 521.00 KiB/s, done.
Resolving deltas: 100% (130/130), done.
Installed forge-std v1.7.6
Initialized forge project
By default, any application built with Foundry will have a similar directory structure to the following:
.
├── .github
├── lib
├── script
│ └── Counter.s.sol
├── src
│ └── Counter.sol
├──
test
│ └── Counter.t.sol
├── .gitignore
├── .gitmodules
├── foundry.toml
└── README.md
For now, delete the files present in the
script/Counter.s.sol
,
src/Counter.sol
, and
test/Counter.t.sol
as we will be creating a contract, and relevant test code ourselves in the following guide.
Creating
the smart contract
For ease and security, we’ll use the
ERC721
contract provided by the
OpenZeppelin Contracts library
to create a simple ERC-721 smart contract.
With OpenZeppelin, we don’t need to write the entire ERC-721 contract.
Instead, we can import the library contract and use its functions from the get-go.
To install the OpenZeppelin Contracts library to your project, run:
forge
install
openzeppelin/openzeppelin-contracts
Inside the
src
folder, create a smart contract called
NFT.sol
and add the code below to the newly created file.
src/NFT.sol
// SPDX-License-Identifier: MIT
pragma
solidity
^
0.8.23
;
import
"openzeppelin-contracts/contracts/token/ERC721/ERC721.sol"
;
contract
NFT
is
ERC721
{
uint256
public
currentTokenId
;
// The following will create an ERC721 Token called Lisk.
constructor
(
)
ERC721
(
"Lisk"
,
"LSK"
)
{
}
// For simplicity, we will only implement the mint function of the Lisk token.
function
mint
(
address
recipient
)
public
payable
returns
(
uint256
)
{
uint256
newItemId
=
++
currentTokenId
;
_safeMint
(
recipient
,
newItemId
)
;
return
newItemId
;
}
}
Compiling
the smart contract
Once the smart contract's code is ready, it must be compiled using Foundry, to do that, simply run:
forge build
If the smart contract doesn't have any errors, you will see the following output on the terminal:
[⠢] Compiling...
[⠰] Compiling 1 files with 0.8.24
[⠔] Solc 0.8.24 finished in 40.36ms
Compiler run successful!
Testing
the smart contract
By testing the smart contract, you can verify that the smart contract behaves as expected and that it is free of bugs, before deploying it to Lisk.
Foundry provides a rich testing framework to support you in writing tests for smart contracts.
See
Tests - Foundry Book
for examples and references regarding the testing framework.
To test the
NFT
smart contract, create a new file
NFT.t.sol
under the
test/
directory, and add the following content:
foundry_app/test/NFT.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma
solidity
^
0.8.20
;
import
{
Test
,
console
}
from
"forge-std/Test.sol"
;
import
{
NFT
}
from
"../src/NFT.sol"
;
contract
NFTTest
is
Test
{
NFT
public
lsk
;
// Create dummy addresses for alice and bob
address
alice
=
makeAddr
(
"alice"
)
;
address
bob
=
makeAddr
(
"bob"
)
;
// Initialize the NFT contract's object
function
setUp
(
)
public
{
lsk
=
new
NFT
(
)
;
}
// Pass the address of alice and bob to see whether the mint function successfully passes
function
testMintPass
(
)
public
{
lsk
.
mint
(
alice
)
;
lsk
.
mint
(
bob
)
;
}
// To intentionally create a failing test, let's compare the addresses of alice and bob
function
testMintFail
(
)
public
{
assertEq
(
alice
,
bob
)
;
}
}
To run the tests, execute the following command. The
-vv
flag will output detailed information about the tests run using the following command.
forge
test
-vv
The output should look like this:
[⠢] Compiling...
No files changed, compilation skipped
Ran 2 tests for test/NFT.t.sol:NFTTest
[FAIL. Reason: assertion failed] testMintFail() (gas: 147160)
L프로젝트로 돌아가기