Troll Bridge - non-custodial, fast token withdrawal protocol from Optimism to Ethereum.
Native token withdrawal from Optimism takes 7 days, that hurts DeFi composability effect.
The main idea behind Troll Bridge is that the user can trade 7 days withdrawal waiting time with some private pool in exchange of some fees.
There is no way for private pool owner to cheat the user, besides private pool incentivized to clear operations ASAP, otherwise it gets penalized.
This project consists of 3 parts:
Front-end, it is written in React. It uses metamask to enable user interaction with blockchain and connects to Back-end to view user transactions history.
Back-end, it is written in Java. It uses Web3j to enable interactions with blockchain.
Smart-contracts on L1(kovan) and L2(optimism-kovan). They are written in solidity.
More detailed overview of each part
Provides service to the user :)
(small note: at the moment we were building the system there was none wss endpoint for L2(optimism-kovan))
It is doing 2 parts:
But since we were unable to use wss endpoint, we are unable to listen any events. (How we did it) So to overcome this instead of listening we requerying L2 smart contract every 5 seconds and check for new requests from users.
If we've detected 'new request' we call L1Bank.processL1WithdrawalManually function with detected 'new request' parameters and user gets his money on L1.
To make protocol 100% secure for user we had to solve several things:
Protocol has to be able to support any existing ERC20 that will be distributed on L1 and L2 (with smart contracts base provided by optimism team (OVM_L1ERC20Gateway, Abs_L2DepositedToken)).
L2Bank must know exact 'instantly withdrawal token amount' that are available on L1. This is required to handle case where, for example, user is trying to withdraw 100 tokens from L2 but there is only 50 tokens left in L1Bank, transaction should revert.
L2Bank.swap function must initiate ERC20 withdrawal to L1Bank AND trigger L1Bank function that checks if there was already processed request by operator in one transaction.
We've solved these problems by:
The purpose of those methods is to be able to send tokens between L2 and L1 and trigger call function of some another contract in one transaction.
Purpose of new methods is to work together with new methods of the contract above.
(Our small hope is that contracts above wont be neccessary and optimism team will extend their base contracts, so every ERC20 token between L1 and L2 will have these functions.)
The purpose of wrapped token (trollUSDT) is:
to extend optimism codebase and make service to work with default ERC20 (it is invisible for user, user is working as if there was none wrapped token)
to fix the (2. L2Bank must know exact 'instantly withdrawal token amount') by wrapping default ERC20 on L1 and sending it to L2Bank, persistence of wrapped token from L1 in L2Bank is a guarantee for the user that he will receive his funds as he requested it.