Table of Contents |
---|
Links
Wrapping Wiki: FIO Token and Domain NFT wrapping
Overview of development environment: [FIP-17.a] FIO Token Wrapping
Wrap use case: Wrap
Unwrap use case: Unwrap
Overview
Oracle code will be run by designated FIO Chain BPs with access to:
Oracles will:
On the FIO Chain
Monitor specific account by inspecting every block and looking for FIO contract
wraptokens
actionExecute ERC20
wrap
action to mint wFIO to the designated account
On the Ethereum Chain
Monitor Ethereum smart contract for inbound transfers of ERC-20 wFIO
Execute FIO contract
unwrap
action to transfer FIO to the designated account
Oracle Go Prototype
The original Oracle prototype code was written in Go and is located at: https://github.com/blockpane/fio.oracle
The FIO wrapping/unwrapping contract
The FIO wrapping/unwrapping contract specification is detailed in FIP 17.a: https://github.com/fioprotocol/fips/blob/master/fip-0017a.md
Github
fio.oracle
contract: https://github.com/fioprotocol/fio.contracts/tree/oracle/tokenwrap/contracts/fio.oracle
The Ethereum ERC20 wrapping/unwrapping contract
The Ethereum wrapping/unwrapping contract specification is detailed on the wiki: fio.erc20 - wFIO Contract Specification
Github
fio.erc20
repository: https://github.com/fioprotocol/fio.erc20
Misc. Requirements
...
Issue
...
Summary
...
Decision
...
Storage of latest block number
...
The Oracle is getting the latest action from FIO history every 5 seconds. But when we restart the server, we read the all latest actions and calling wrap function from the start. Of course, it doesn't mint again but I think wrapping time can be long in this case. To prevent this problem, we need to save the latest block number to database or any external storage.what do you think about my suggest?
...
Casey Gardiner should we track block number in the oracleledger
table?
Suggest that Oracles store a log file of all the transactions locally. If they then go down they can grab a time stamp or transaction ID from the log file to know which transactions have not yet been processed.
If an oracle server crashes and the logs are lost, then the oracle would have to re-process all transactions (and rebuild the log file). This would be a one time process.
Decision: We will start with using log files, but will ask BPs their opinion on this solution.
...
Admin front-end UI
...
Is there a need for a front-end UI to review different transactions, or can we just rely on table lookups, etc.?
Pawel Mastalerz thoughts?
...
Process a single transaction at a time
...
Given the complexity of validating wrap and unwrap transactions all the way through to finality, both Todd and Alex have suggested that we limit oracles to only process a single transaction at a time
Functionality
There are two main use cases that concern the Oracle, Wrap and Unwrap. These are detailed below.
Watchdog routines
In addition to wrap/unwrap, the Oracle should also have certain watchdog/monitoring routines that ensure the processes and routines executed by the Oracle healthy. For example:
Make sure a loop didn’t get stuck.
Ensure there are no blocked channels.
Ensure the health of the daemon itself.
Wrap
...
Table of Contents |
---|
Links
Wrapping Wiki: FIO Token and Domain NFT wrapping
Overview of development environment: [FIP-17.a] FIO Token Wrapping
Wrap use case: Wrap
Unwrap use case: Unwrap
Overview
Oracle code will be run by designated FIO Chain BPs with access to:
Oracles will:
On the FIO Chain
Monitor specific account by inspecting every block and looking for FIO contract
wraptokens
actionExecute ERC20
wrap
action to mint wFIO to the designated account
On the Ethereum Chain
Monitor Ethereum smart contract for inbound transfers of ERC-20 wFIO
Execute FIO contract
unwrap
action to transfer FIO to the designated account
Oracle Go Prototype
The original Oracle prototype code was written in Go and is located at: https://github.com/blockpane/fio.oracle
The FIO wrapping/unwrapping contract
The FIO wrapping/unwrapping contract specification is detailed in FIP 17.a: https://github.com/fioprotocol/fips/blob/master/fip-0017a.md
Github
fio.oracle
contract: https://github.com/fioprotocol/fio.contracts/tree/oracle/tokenwrap/contracts/fio.oracle
The Ethereum ERC20 wrapping/unwrapping contract
The Ethereum wrapping/unwrapping contract specification is detailed on the wiki: fio.erc20 - wFIO Contract Specification
Github
fio.erc20
repository: https://github.com/fioprotocol/fio.erc20
Misc. Requirements
Issue | Summary | Decision |
---|---|---|
Storage of latest block number | The Oracle is getting the latest action from FIO history every 5 seconds. But when we restart the server, we read the all latest actions and calling wrap function from the start. Of course, it doesn't mint again but I think wrapping time can be long in this case. To prevent this problem, we need to save the latest block number to database or any external storage.what do you think about my suggest? | Casey Gardiner should we track block number in the
|
Admin front-end UI | Is there a need for a front-end UI to review different transactions, or can we just rely on table lookups, etc.? | Pawel Mastalerz thoughts? |
Process a single transaction at a time | Given the complexity of validating wrap and unwrap transactions all the way through to finality, both Todd and Alex have suggested that we limit oracles to only process a single transaction at a time | |
Functionality
There are two main use cases that concern the Oracle, Wrap and Unwrap. These are detailed below.
Watchdog routines
In addition to wrap/unwrap, the Oracle should also have certain watchdog/monitoring routines that ensure the processes and routines executed by the Oracle healthy. For example:
Make sure a loop didn’t get stuck.
Ensure there are no blocked channels.
Ensure the health of the daemon itself.
Wrap
Wrap creates wFIO on the Ethereum chain.
See the following page for an overview of the Wrap use case: Wrap
Functionality | |||||
---|---|---|---|---|---|
Oracle Initialization |
| ||||
Alice (via dApp) calls | Example: Calling | ||||
|
| ||||
Oracle monitors | Every 5 seconds Oracle polls the
TBD:
| ||||
|
| ||||
Oracle validates the FIO chain |
| ||||
Responding to invalid |
| ||||
Oracle executes |
| ||||
|
| ||||
| Example of three oracles calling wrap:
| ||||
ERC-20 | TBD: Adam to document how the contract handles invalid failed transactions. Put link to content here. Adam Androulidakis | ||||
Responding to invalid ERC-20 | TBD: Any kind of recovery? Just send a failure message to the user and note that their FIO is stuck in the FIO wrapping account? Pawel Mastalerz | ||||
|
|
Exception handling
Error condition | Trigger | Type | fields:name | fields:value | Error message | Oracle Action |
---|---|---|---|---|---|---|
Invalid chain | Chain passed to | Oracle triggers TBD: How do other oracle get notified when a transaction is getting unwound? TBD: What if one oracle approves the transaction and another oracle rejects? | ||||
Invalid Ethereum address | Public address passed to | Oracle triggers | ||||
Unwrap
Unwrap converts wFIO on Ethereum chain to FIO Tokens on FIO chain.
See the following page for an overview of the Wrap Unwrap use case: Wrap Unwrap
Functionality | |
---|---|
Oracle Initialization |
|
...
Invalid chain
...
Chain passed to wraptokens
action is not Ethereum (Note: this restriction is not enforced in the FIO Contract to allow for wrapping chain expansion without deployment of code)
...
Oracle triggers unwraptokens
action to send FIO back to originating address
TBD: How do other oracle get notified when a transaction is getting unwound?
TBD: What if one oracle approves the transaction and another oracle rejects?
...
Invalid Ethereum address
...
Public address passed to wraptokens
action is not a valid Ethereum address (Note: this restriction is not enforced in the FIO Contract to allow for wrapping chain expansion without deployment of code)
...
Oracle triggers unwraptokens
action to send FIO back to originating address
Unwrap
Unwrap converts wFIO on Ethereum chain to FIO Tokens on FIO chain.
See the following page for an overview of the Unwrap use case: Unwrap
Functionality | Alice (dApp) executes unwrap(fio address, amount);
| ||
---|---|---|---|
Oracle monitors |
| ||
Oracle validates | Validation includes:
| ||
If exceptions are found, Oracle takes action to unwind transaction | See Exception handling below | ||
Alice (via dApp) calls | Example: Calling | ||
|
| Oracle monitors |
Code Block |
---|
curl -s -XPOST http://44.242.158.42:8080/v1/history/get_actions -d '{
"account_name": "o2ouxipw2rt4",
"pos": -1
}'
|
Retrieve all actions
For each action, if
block_num
>actionIndex
then validate and process the action (call ERC-20wrap
)Set
actionIndex
=block_num
of most recent wraptokens action
Code Block |
---|
const actionIdx = config.oracleCache.get("actionIndex");
const dataLen = Object.keys(data.data.actions).length;
var array = Array();
for (var i = 0; i<dataLen;i++){
if (data.data.actions[i].block_num > actionIdx) {
array.push(data.data.actions[i]);
}
config.oracleCache.set("actionIndex", data.data.actions[dataLen-1].block_num)
}
return array; |
TBD:
Since there eventually may be very many transactions, it may make sense to walk backward through the table using "pos" and "offset". Maybe you grab the most recent 5 actions and see if any of them are new. If ALL of them are new, then you need to grab the next 5 actions, etc.
Finality:
TBD: Should the oracle monitor FIO chain for finality by ensuring block number is after the last_irreversible_block?
Oracle validates the FIO chain wraptokens
transaction.
See “Exception handling” below
Check the actions to confirm it is a wrapping action:
Code Block |
---|
if (wrapData[i].action_trace.act.data.memo == "Token Wrapping") |
TBD: If exceptions are found, what actions does the Oracle take unwind
wraptokens
action?
Oracle executes wrap
on fio.erc20
contract on Ethereum chain
wrap(ethaddress, FIO (SUF) amount, obtid);
ex. wrap(“0x00000000000”, 10000000, “0x123456789”);
fio.erc20
contract actions:
ethereum wallet provider (usually truffle/hd-wallet-provider) set to use oracles ethereum private key
wFIO recipient eth address, wFIO amount to mint (must match what was wrapped on FIO chain exactly), and the obtid of the FIO transaction are provided as parameters to wrap action
Transaction is executed
address provided receives wrapped FIO assets
event emitted:
wrapped(address ethaddress, uint256 amount, uint256 obtid);
Oracle validates wrap
transaction
Oracles monitor all
wrap
transactions in process to ensure consensus has been reached.Decision: Based on 5/13 discussion with Luke/Pawel/Dev team, only limited monitoring of the transaction on the Ethereum chain is required.
All of the following do NOT need to be monitored or tracked by the Oracle:
A transaction gets stuck in a pre-consensus state.
A transaction disappears (e.g., ending up on a fork, etc.)
It is common to have transactions go into a mempool, and then transaction ends up in an uncle (orphan) block. If the transaction in the uncle block has not been validated elsewhere, then it should be returned to the mempool. But, there are situations where it can disappear from the mempool.
Waiting to make sure the block has reached finality.
TBD: Only process one transaction at a time to reduce complexity?
Once all Oracles have submitted wrap
, the wFIO Tokens will be minted and transferred to designated Ethereum public address
Example of three oracles calling wrap:
Code Block |
---|
Using these oracle, we call the wrap function on FIO token contract using web3.js like below.
instance.wrap[accounts[5], 10000, "99e20de9bb9f178f3ff1328c089925daff1d5dcb1da7dceaad7fc5126a08eaf5". {from: accounts[1]});
instance.wrap[accounts[5], 10000, "99e20de9bb9f178f3ff1328c089925daff1d5dcb1da7dceaad7fc5126a08eaf5". {from: accounts[2]});
instance.wrap[accounts[5], 10000, "99e20de9bb9f178f3ff1328c089925daff1d5dcb1da7dceaad7fc5126a08eaf5". {from: accounts[3]});
|
The last oracle call the _mint function, then the same amount of asset will be mint to designated ERC20 address.
After mint, the event is emitted then we can receive the event and alert to user about wrapping result.
Does the oracle do any kind of monitoring or validation of the overall transaction (post consensus?)
Decision: Based on 5/13 discussion with Luke/Pawel/Dev team, no additional monitoring of the transaction on the Ethereum chain is required.
TBD: What happens if the Oracle does not have enough ETH to cover the transaction? Does it roll back? Does it stay in the queue?
Exception handling
...
Error condition
...
Trigger
...
Type
...
fields:name
...
fields:value
...
Error message
...
Oracle Action
Registered Oracles call | unwrap(fio address, amount); | ||
ERC-20 | TBD: Adam to document how the contract handles invalid failed transactions. Put link to content here. Adam Androulidakis | ||
|
| ||
Oracle monitors |
| ||
Oracle validates |
| ||
If exceptions are found, Oracle takes action to unwind transaction |
| ||
|
| ||
Oracle executes |
| ||
| fio.oracle contract Actions:
| ||
Responding to invalid |
| ||
Oracle validates |
| ||
Once all Oracles have submitted |
|
Exception handling
Error condition | Trigger | Type | fields:name | fields:value | Error message | Oracle Action |
---|---|---|---|---|---|---|
Invalid FIO Address | FIO Address passed in with ERC-20 is not valid or does not exist | Oracle triggers a ERC20
| ||||