Implement an simple oracle which can communicate with the world. One application using my oracle is user allows to save ETH into hodl saver and the same amount of ETH will sent back when ETH price is above threshold user set.
cd solidity
npm install
cd backend
pip3 install -r requirements.txt
- Setup config file.
- Deploy all smart contract and register related address.
- Deploy all smart contract with owner.
- Smart contract, oracle register, regists address.
- Smart contract, hodl register, regists address.
- Smart contract, hodl storage, regists allower.
- Smart contract, oracle fee wallet, registers client address.
- Execute daemon in oracle_node_client_daemon.py.
- Deposit some eth into HodlOracle by deposit function.
- Interested user set threshold and transfer ETH to HodlSaver by deposit function.
- Execute trigger function in HodlOracle smart contract. If ETH price is above threshold, money will send back to user who deposit ETH in step 5, otherwise, no action will execute.
- Oracle owner can execute payback function for transfer money all record into oracle fee wallet.
- Repeat step 6.
- Execute trigger function in HodlOracle (called by HodlOracle owner).
- Run __queryNode in OracleBase (called by HodlOracle contract address).
Because __queryNode has permission check, it only allowes HodlOracle owner or HodlOracle itself. - Execute querySentNode in OracleCore (called by HodlOracle contract address).
- Emit ToOracleNode.
Emit ToOracleNode will trigger node to execute request outside. We'll discuss the flow later. - Return qureyID back.
- OracleNode execute some requests.
- Execute function, resultSentBack, in OracleCore (called by OracleCore owner).
- Run __callback in HodlOracle (called by OracleCore contract address).
- Deposit fee wallet in OracleBase.
- resultSentBack should change the owner for seperating the setting.
- Users should deposit ETH into oracle fee wallet for paying transaction fee and oracle fee.
- In functions, trigger and __callback, should check whether the address has enough money in wallet.
- Before executing real logic in above function, substract the total trasaction fee in wallet and update it.
Note: It means I use all trasaction fee instead of real transaction fee. - Smart contract should emit event for recording all information.
- I want other people can also take responsibility for running node client. So maybe they need to stake some money inside the wallet in order to avoid some illegal activities. And before the money in wallet exceeds client's staking, I should pay back ETH in wallet to other clients where they help to call oracle.
It implies below things.- The function which pay back to all clients is needed.
- All receipts need to be recorded for sent back money.
- Implement smart contract with on chain handler class.
- c_function is for eth transaction.
- l_function is for eth call which means it doesn't need transaction.
- Implement smart contract class.
The architecture is based on server/client model. Server takes responsibility with collecting different command, stop and attach, from client. Users should use with statement for server because there is something need to do after server is terminated.
- Add new smart contract file.
- Update migration script.
- Add two file under src/subfolder. For example, folder, oracle_wallet, has two files, oracle_wallet.py and oracle_wallet_onchain_handler.py
- Update src/utils/my_deployer.py to check how to update.
- Update contract name to target_contract_name in config.conf.template and travisCI/test_config.conf.