ERC20 - ERC777 bridge
Actors
- Alice and Charlie are 2 users of a DApp and want to exchange value using an ERC20 token.
- The MainBridge contract locks tokens on the mainnet.
- The ForeignBridge contract manages the minting and burning of the equivalent tokens on the Foreign chain
- A group of validators watches the ERC20 token events to trigger intra-chain
- The list of validators (addresses) are stored in the MainBridge and ForeignBridge contracts
- A threshold is set on how many signatures are required to execute the intra-chain transfers.
- The validators sign-off on intra-chain token deposits or withdrawals.
Assumptions on trust
- Alice and Charlie trust the majority of the validators to act in their interest
- Alice and Charlie assume the minimum threshold of validators is always online to process their intra-chain conversions.
Setup
An administrator ( currently the owner of the contracts ) adds an existing ERC20 token from the Main net in the ForeignBridge. This function creates a new (ERC777) token on the Foreign net and links the Mainnet address to the newly generated token.
The validators watch these events , and start watching Transfer() events on both chains. These watches are filtered on
- Transfers towards the MainBridge on the Main net
- Transfers towards the Foreignbridge on the Foreign net
Scenario
- Alice has some 'Sample ERC20' tokens on the mainnet and goes from Main-net to Foreign-net.
- On the Foreign-net, she will send tokens to Charlie.
- Charlie then redeems his received Foreign-net tokens for Main-net tokens.
notes
- after this flow , Alice still has 9 tokens locked in the MainBridge contract
- Alice can redeem her 9 tokens using the same flow as Charlie
Token incentive for withdrawal
Alice needs the final withdrawal of her token executed on the main net - which costs gas.
Alice has 2 options:
- Alice executes the token withdrawal herself , using the validator signatures. She pays for the gas.
- Alice can incentivize someone else to do the transaction for her.
There is an incentivation scheme buit into the bridge , whereby Alice can offer a reward in tokens for anyone doing the final withdrawal transaction.
This is by offering a number of tokens as a reward to whoever executes the transaction.