This project mainly helps to deploy chainlink smart contracts to Harmony and run a consumer who makes the oracle request.
Chainlink related contracts that can be deployed are:
- LinkToken - chainlink crypto currency used to pay oracle providers
- Oracle - chainlink oracle contract deployed by oracle providers
- Consumer - contract that invokes chainlink oracle request
- Node, Yarn
yarn install
truffle compile
Deploy LinkToken to Harmony testnet. Needs PRIVATE_KEY_LINK
env variable set.
node scripts/link.js
Deploy oracle contract to Harmony testnet. Needs PRIVATE_KEY_ORACLE
env variable set. Also, link token contract address from deployment above copied to the script oracle.js
.
node scripts/oracle.js
Deploy consumer contract. Make sure to copy the link token address from the link deployment to this script. Needs PRIVATE_KEY
env variable set.
node scripts/consumer.js
Funding consumer contract so that price request script next succeeds. Make sure to copy the link contract address to this script.
node scripts/fund.js
Request price from oracle
node scripts/request_price.js
For the demo, we will get the price of ONE in USDT using binance api https://api.binance.com/api/v1/ticker/price?symbol=ONEUSDT
-
Deploy oracle contract using link contract address:
0x91738e20e365abde6d48e081446917a4b5c05cb6
- Make sure to
setFulfillmentPermission
by runningoracle_more
script with correct address (that is going to fullfill the oracle request) and the newly deployed oracle contract address.
- Make sure to
-
Add the following job to your chainlink node using the oracle contract address from previous oracle deployment step.
{
"initiators": [
{
"type": "external",
"params": {
"name": "harmony",
"body": {
"endpoint": "oracle",
"addresses": ["<YOUR ORACLE CONTRACT ADDRESS HERE>"]
}
}
}
],
"tasks": [
{
"type": "httpget",
"params": {
"get": "https://api.binance.com/api/v1/ticker/price?symbol=ONEUSDT"
}
},
{
"type": "jsonparse",
"params": { "path": ["price"] }
},
{
"type": "multiply",
"params": { "times": 100000000 }
},
{
"type": "EthUint256"
},
{
"type": "harmony-adapter"
}
]
}
- Send your oracle contract address and jobId so that we can include them in the aggregator deployment and invoke price feed.
Deploy an Aggregator with oracles and jobIds for aggregating the price
node scripts/aggregator.js
After deploying the aggregator, fund the aggregator contract before running price_feed.js
using fund.js
.
Running the price feed using the aggregator contract, add your aggregator contract to price_feed.js
node scripts/price_feed.js
Node | Oracle Contract | Job Id |
---|---|---|
SNZ Pool | 0x0185b239a9d2080fd03536213413488a4b171334 | cb0aa54f6b1941ca94de3c82eb5db79b |
Stafi Protocol | 0x702d75a957a623fb7af3cf021a7c4c4223951589 | ff5dcf90d8a94e62ab9547eb9169e473 |
Validator Capital | 0x6c6184e1b23d85ca0a13d874ede26adb1fa91cbb | db6879bf38384f5699321db973ba07a5 |
Chainode Tech | 0x7694c1d0915ba4f921b8c06805f1f8b5154eab77 | ba017f71c7ad4f2686f83190cb795a08 |
Deployed at: 0x05d511aafc16c7c12e60a2ec4dbaf267ea72d420