Skip to main content

xDai Bridge

info

The xDAI bridge can be used in https://bridge.gnosischain.com by selecting DAI/xDAI.
Please avoid using the legacy xDai bridge: https://bridge.legacy.gnosischain.com/.

danger

xDAI bridge contract is undergoing a critical upgrade: DAI will be replaced with USDS as the default accepted token on Ethereum, while xDAI will continue to be minted on Gnosis Chain. Please refer to xDaiBridge-usds-migration page for more details.

The xDai bridge is a native DAI bridge from Ethereum that is used to mint and burn xDai, the native asset used for gas and transaction fees on Gnosis.

Once Dai is bridged into the xDai bridge, the xDai bridge contract on Gnosis notifies the block rewards contract. The consensus algorithm then mints xDai to the user's corresponding address on Gnosis in the next block.

Key Information

Overview

Detail
Frontend URLhttps://bridge.gnosischain.com
Trust Model4-of-7 Validator Multisig
Governance8-of-16 Multisig
Governance ParametersValidator Set, Daily Limits, Fees
Bug BountyUp to $2m
Bug ReportingImmunefi

Key Contracts

Ethereum

ContractEthereum Address
xDAI Bridge Contracteth:0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016
Validator Management Contracteth:0xe1579dEbdD2DF16Ebdb9db8694391fa74EeA201E
info

The current deployment of xDAI bridge contract is from https://github.com/gnosischain/tokenbridge-contracts/tree/xdaibridge, with the commit hash fb6bae7589a102613b48c12addb425b72836574e

References:
** Some of the information from TokenBridge Docs are outdated, please verify the information before you bridge.

Fees & Daily Limits

TypeEthereum -> GnosisGnosis -> Ethereum
Bridge Fees0%0%
Min Transfer0.005 Dai10 xDai
Daily Limit10,000,000 Dai10,000,000 xDai
Max Single Deposit9,999,999 Dai10,000,000 xDai
note

Daily Limit is reset according to the following logic: the smart contract stores total amount of processed tokens per current day and reverts on a new transfer if it exceeds the daily limit. Id of the day is calculated using the formula timestamp / (number of seconds in 1 day), where timestamp is the Unix timestamp.

Bridge Validators

Bridge Governance

How it Works

Ethereum -> Gnosis Chain.

The xDai token is minted when Dai** is transferred from Ethereum to Gnosis using the xDai Bridge. During the transfer process, a block reward contract is invoked to mint xDai to a user's account. Because contract calls are made from the consensus engine to create xDai tokens, balance updates are more difficult to trace than simple value transfers.

danger

**xDAI bridge contract is undergoing a critical upgrade: DAI will be replaced with USDS as the default accepted token on Ethereum, while xDAI will continue to be minted on Gnosis Chain. Please refer to xDaiBridge-usds-migration page for more details.

warning

Calling transfer on Foreign xDAI bridge will no longer mint xDAI on Gnosis Chain, and users must use relayTokens instead. For more detail, please check here.

  1. Users initiate the relay transaction on Ethereum by approving the bridge contract and calling the bridge contract relayTokens(address recipient, uint256 value).
  2. UserRequestForAffirmation(address recipient, uint256 value, bytes32 nonce) event is emitted from the bridge contract.
  3. Bridge validators observe the event and call executeAffirmation(address recipient, uint256 value, bytes32 nonce) function on Home xDAI bridge contract on Gnosis Chain.
  4. When enough confirmations are collected (4/7 majority), the bridge contract on Gnosis Chain calls the block reward contract to record the receiver(s) and amount(s) of xDAI to mint. Hashi acts as an additional bridge valdiator who validates transactions but no actually calling executeAffirmation on Home xDAI Bridge. For more details about how Hashi works in this case, check out here
  5. The block reward contract is called by the consensus engine to update user's xDAI balance. AddedReceiver(uint256 amount, address indexed receiver, address indexed bridge) event is emitted within the same transaction and receiver address will be credited for the equivalent xDAI amount.

User may check the balance change visually using Blockscout's coin balance history or programmatically using eth_getBalance API by querying the balance on block number where AddedReceiver event is emitted.

You can also view a receiver's address and amount of xDai received in the block reward contract's logs. Whenever the executeAffirmation method is called and enough signatures has been collected from bridge valdiators, it emits the AddedReceiver event:

AddedReceiver(
uint256 amount,
address indexed receiver,
address indexed bridge
)

Example: https://gnosis.blockscout.com/tx/0x5892a695860f6087a2d93140f05e6365142ff77fd7128e39dbc03128d5797ac4?tab=logs


Gnosis Chain -> Ethereum.

  1. User transfer xDAI to or call relayTokens(address receiver, uint256 value) on Home xDAI bridge contract on Gnosis Chain. The equivalent amount of xDAI is burned.
  2. UserRequestForSignature(address recipient, uint256 value, bytes32 nonce) event is emitted from Home xDAI bridge contract. Example
  3. Bridge validators observe the event and call submitSignature(bytes signature, bytes message) function on Home xDAI bridge contract on Gnosis Chain. Hashi acts as an additional bridge valdiator who validates transactions but no actually calling submitSignature on Home xDAI Bridge. For more details about how Hashi works in this case, check out here.
  4. After enough signatures are collected, CollectedSignatures event is emitted/
  5. Anyone can execute the withdrawal on Ethereum by calling executeSignatures(bytes message, bytes signatures) on Foreign xDAI bridge on Ethereum. To fetch the calldata value, please check the guideline below. DAI** is unlocked to the receiver on Ethereum.
  6. RelayedMessage(address recipient, uint256 value, bytes32 transactionHash) emitted on Foreign xDAI Bridge. Please be aware that after Hashi upgrade, transactionHash has been replaced with the value of nonce. Please check here for more information on how it works.

Savings xDAI

Application: https://agave.finance/sdai/

Rationale

MakerDAO’s DSR current rate is 5%. Since the increase of the DSR to ~3.5%, ~7M DAI have fled out of the xDAI bridge, as can be seen on this dashboard. Bridging the DSR yield into Gnosis Chain will help regain these deposits. In order to provide the needed catalyst for Gnosis Chain Defi to boom, interest rates on Gnosis Chain have to pick up or reach parity with Ethereum or other chains with higher borrowing demand.

Introducing Savings DAI (sDAI), a DSR(Dai Savings Rate) module in xDAI Bridge between Ethereum and Gnosis Chain.

By depositing most of the DAI in xDAI bridge into sDAI vault from Spark Protocol on Ethereum, which is a ERC4626 vault depositing all DAI into the Maker DSR, interest is accrued from Maker DSR and relayed to Gnosis Chain. xDAI holders on Gnosis Chain can mint sDAI with their xDAI, and enjoy the interest accumulating from Ethereum.

Check out the proposal from Karpatkey to Deposit DAI of the xDAI bridge in sDAI vault from Spark

Interest rate

Assuming the amount of “Savings DAI on GC” minted is lower than the one held by the bridge, then the yield will be higher than the Dai savings Rate. The bridge currently holds roughly 25M DAI and the DSR yield is 5%, assuming 25M get wrapped into sDAI and only 10M xDAI get deposited into the vault on GC, the yield will be 12.5% .

The expectation is that the sDAI rate will always be higher on GC than Mainnet, as only if almost 100% of all DAI bridged is staked will we achieve rate parity.

Considering the current 25M DAI sitting in the bridge, that represents ~1.25M yearly to incentivise GC.

DSR yield is risk-free if you are already holding DAI. All the risks derived from the collateral are borne by all DAI holders, regardless of them depositing in the DSR. Karpatkey team have written a research piece here. The only newly introduced risk is smart contract risk in how the integration is made with the sDAI vault on Ethereum and the implementation of the sDAI vault on GC.

Architecture

Ethereum

A new implementation upgrade in xDAIForeignBridge contract: SavingsDAI Connector is added as a dependency in the contract. Compare to the old implementation of the Compound Connector, the payInterest function in SavingsDai Connector is used to transfer interest received from vault to receiver address on Gnosis Chain rather than to receiver address on Ethereum.

sDAI is deployed on Ethereum. Any future DAI deposited to the Bridge will be wrapped into sDAI, with caveat that it will always keep the buffer of the minimumCashThreshold when investing.

minimumCashThreshold: This value determines what is the recommended amount of DAI that should be held in the bridge at all times, in order to create a buffer for withdrawals without added operations and thus lower gas costs.

Gnosis Chain

There are two contracts being deployed on Gnosis.

The first one is the sDAI vault, also an ERC 4626 which is the most popular standard for vaults which makes it extremely useful for Defi integrations from Lending Protocols like Agave and Spark,  to DEXes like Curve and Balancer with their boosted pools. The only modification to the standard vault (OZ implementation) is that it will allow for direct deposits and withdrawals in xDAI, rather than exclusively the ERC20 WXDAI.

The second contract is the Interest Receiver. This will be the address provided on Mainnet bridge as the interest receiver. What this contract does is quite simple, it distributes the balance it holds in xDAI and WXDAI into sDAI at a fixed block rate that gets updated every 1-2 days to adjust for interest rate changes coming from mainnet. The goal of this contract is to not make it possible to front run the bridging process of the interest, and to make sure there is a fairly frequent update of the sDAI shares value and exchange rate. This contract has the perk of being very easy to switch for a different one by simply setting a new receiver on the bridge, without impacting any of the operations. This means if we want to make modifications such as add a fee or normalize rates in the future, that will be very easy to plug-in.

Role and responsibilities

xDAI/wxDAI holder

  1. Deposit xDAI/wxDAI and get sDAI shares:
    1. xDAI/wxDAI holders can deposit xDAI/wxDAI in https://agave.finance/sdai/, in return for sDAI, and their corresponding shares in the vault are recorded.
    2. Bridge Interest Receiver receives interest from mainnet and distribute to sDAI vault.
    3. sDAI holders withdraw/redeem xDAI/wxDAI (interest+original amount) according to their shares, that has gone up because of the interest received in step 2

Keeper

  1. Call investDAI() refillBridge() payInterest(). On Ethereum, anyone is allowed to investDAI() into the sDAI vault, anyone is allowed to refillBridge() right back up to the threshold, and also anyone is allowed to payInterest(). These processes are permissionless, and it’s also costly which is why we will have a bot to automate these 3 maintenance procedures in the most efficient way possible.
  2. Keeper is maintained by Karpatkey team. Source Code

Contracts

How to claim DAI on Ethereum

  1. Fetch the value of recipient, value and nonce from UserRequestForSignature(address recipient, uint256 value, bytes32 nonce) from the transction which is emitted by Home xDAI Bridge Gnosis Chain.

  2. Go to the xDAI bridge helper contract on Gnosis Chain.

    1. Call getMessageHash(address _recipient, uint256 _value, _origTxHash) : with recipient and value from the UserRequestForSignature and _origTxHash as nonce from UserRequestForSignature (not the transaction hash!). Fetch the returned message hash.
    2. Call getMessage(bytes32 _msgHash) & getSignatures(bytes32 _msgHash) with the message hash from the previous step.
  3. Use the value returned from the previous step to call executeSignatures(bytes message, bytes signatures) on xDAI Foreign Bridge on Ethereum.