Smart contracts for fast withdrawals from optimstic rollups to Ethereum. Arbitrum support is fully functional on Rinkeby.
Contract | Address | Network |
---|---|---|
BridgeBackBetterV1 | 0xc0Debb5984B470c3B0e2B547c5971248f03e89B5 | Ethereum Rinkeby |
ArbitrumWithdrawalV1 | 0x4BcEbBc55A796754451084e714069B841E89F27a | Arbitrum Rinkeby |
There are 2 contracts -- 1 on Ethereum and 1 on Arbitrum:
- Ethereum: The main contract that handles providing liquidity and interactions with node operators.
- Arbitrum: The withdrawal contract that receives ETH from users on Arbitrum and emits an event for node operators to listen to.
- Node operator bonds ETH and runs their off-chain script to listen for
WithdrawalInitiated
events on Arbitrum. - Liquidity provider delegates ETH to a node operator of their choice.
- User calls
withdraw()
on the Arbitrum withdrawal contract, which starts the 7-day withdrawal from Arbitrum to Ethereum and emits an event. - Node operator hears this event, runs off-chain logic to determine if this withdrawal is valid, and calls
verifyWithdrawal()
on the main Ethereum contract if it determines it is valid. - Main contract sends ETH from the node operator's delegators to the user's wallet on Ethereum and gives the node operator and stakers (liquidity providers) a small fee.
- The withdrawer's ETH from Arbitrum arrives to the main contract after 7 days (node operator initiates transaction to claim it).
- If the withdrawal doesn't go through to Ethereum (i.e., it gets challenged), the node operator who incorrectly validated the withdrawal gets their bond slashed. Stakers who delegated to that node operator cover any remaining losses if the bond wasn't high enough to cover the full withdrawal amount.
- Node operators bonding ETH has a 7-day cooldown (time when you can't unbond).
- Stakers delegating ETH to a node operator also have a 7-day cooldown (time when you can't undelegate).
- Accounting happens when withdrawing from the pool -- a counter of fees is incremented for the node operator that verifies a withdrawal, and the delegators for that pool get a portion of that fee when they undelegate. Since it's not a direct, tiny fee for each delegator, delegators are incentivized to withdraw after their 7-day cooldown and redelegate again (depending on if the portion of their fees accumulated during those 7 days is greater than the gas fee for the undelegate transaction).)
- Clone the repo and install dependencies.
git clone [email protected]:TR-Finance/BridgeBackBetter.git
cd BridgeBackBetter
npm install
- Copy
.env.example
into.env
and replace the variables with your own API keys and private keys (make accounts at Alchemy, Etherscan, and Arbiscam).
ETHEREUM_RINKEBY_PROVIDER_URL
: JSON-RPC endpoint for Rinkeby on Ethereum
ARBITRUM_RINKEBY_PROVIDER_URL
: JSON-RPC endpoint for Rinkeby on Arbitrum
RINKEBY_PRIVATE_KEY
: Private key of a wallet you want to use on Rinkeby
ETHERSCAN_API_KEY
: API key from Etherscan to verify smart contract sourcesARBISCAN_API_KEY
: API key from Arbiscan to verify smart contract sources
Make any edits you want to the contracts and then re-deploy them by doing the following:
-
Add the Arbitrum Rinkeby network to MetaMask (see here for the values to enter), and make sure you have some ETH on Ethereum Rinkeby and Arbitrum Rinkeby for gas. You can use this faucet to get some ETH on Ethereum Rinkeby and then bridge some of it over using https://bridge.arbitrum.io.
-
Deploy the contracts to the testnet for Ethereum and Arbitrum. Take note of the addresses of the new contracts so you can use them in the next steps (they'll be printed to console).
npx hardhat run scripts/deployEthereum.ts --network rinkeby
npx hardhat run scripts/deployArbitrum.ts --network arbitrumTestnet
-
Set your .env variables (
ADDRESS_RINKEBY_BridgeBackBetterV1
andADDRESS_RINKEBY_ArbitrumWithdrawalV1
) to the new addresses. Also updatesrc/constants/addresses.ts
in the frontend package if you're using the frontend. -
Verify the contract sources on Etherscan and Arbiscan so you can debug them more easily.
npx hardhat verify --network rinkeby <ADDRESS OF BridgeBackBetterV1> "100000000000000000" "100000000000000000"
npx hardhat verify --network arbitrumTestnet <ADDRESS of ArbitrumWithdrawalV1>
- Run the node operator script that will listen for withdrawals on Arbitrum and tell the contract on Ethereum to front the funds. Note that this locks up a small amount of ETH as a bond and can be withdrawn after 7 days.
npx hardhat runNodeOperator --bond-amount 0.0000003 --network rinkeby
- Leave the node operator script running and, in a separate terminal, delegate ether to it. This will be used to front the funds for fast withdrawals, and will also lock up another small amount of ETH for 7 days.
npx hardhat delegateEther --node-operator-address <YOUR WALLET ADDRESS> --amount 0.0000005 --network rinkeby
- Run our Hardhat task to perform the fast withdrawal.
npx hardhat initiateWithdrawal --amount 0.0000001 --network arbitrumTestnet