[COMPLETE] Unwrap FIO Token Prototype
This effort prototypes a simplified end-to-end flow of moving from WFIO to FIO.
Use case
Unwrap FIO Token:
Alice (dApp) executes ERC20
approve
sending amount and FIO AddressSend FIO Address as hash?
Add on to end of approve?
Oracle monitors
approve
Oracle calls
burnFrom
from Alice’s accountOracle calls fio.oracle
unwraptokens
which transfers FIO to Alice
Assumptions
Assume there is a single Oracle managing all transactions. Do NOT worry about multisigs, approvals, etc.
No validation on either chain is required.
Diagram link: https://app.diagrams.net/#G1ETfA3K6VTa-rhqcH7gJmRsFUIiGS2kDn
Discussions and Todo
Need to create a dapp to interact with erc20 contract. Currently using: https://oneclickdapp.com/matrix-second
The complexity of this depends on how we structure the ERC20 contract. If we update the contract with all of the fields needed (e.g., passing in a FIO Address to
approve
) we may be able to use a simple contract explorer.
Passing FIO Address into approve
Discussed using (hashed) FIO Address versus FIO Public Key.
A hashed address will generally be smaller and is a known fixed size.
To use a FIO Pub Key we would need to convert the pub key to a raw ecc pubkey so we can fit it in 32 bytes, otherwise it's 56 -> padded to 64 and we end up adding even more gas
The “standard” in FIO is to use FIO Pub Key
The oracle does a validation check on the FIO Address
Decided that we would pass in a (hashed) FIO Address to the ERC20 contract
TBD: Does the oracle pass a FIO pub key into unwrap tokens?
How to pass in FIO Address
The current approach does not modify the ERC20
approve
function. It appends the hashed FIO Address to the transaction:Convert the i128 hash to bytes, left pad with zeros until it's 32 bytes long, tack it onto the end of the transaction data, sign and send
Here is the encoding: https://github.com/blockpane/fio.oracle/blob/main/internal/util/eth.go#L206
An example of sending the data: https://github.com/blockpane/fio.oracle/blob/main/internal/util/eth.go#L423
TBD: Should we create a modified
approve
function that accepts a FIO Address, or use the above process and leave the encoding to the dApp?