---
# System prepended metadata

title: 'v1: USDS migration functions callflow'
tags: [Gnosis Chain]

---



(Deprecated)
# Before the upgrade

Caller: BridgeRouterOwner `0x42F38ec5A75acCEc50054671233dfAC9C0E7A3F6` (same as the bridge owner)
```
router.setRoute(DAI,address(XDaiBridgePeripheralForDaiPreUsdsUpgrade));
router.setRoute(USDS,address(XDaiBridgePeripheralForUsdsPreUsdsUpgrade));
```

### Relay tokens

```mermaid
graph TD
    User([User]) -->|"relayTokens: DAI"| BridgeRouter
    User -->|"relayTokens: USDS"| BridgeRouter
    User -->|"relayTokens: Other ERC20"| BridgeRouter
    User -->|"relayTokens: ETH"| BridgeRouter

    subgraph "BridgeRouter Contract"
        BridgeRouter[BridgeRouter]
    end

    subgraph "Pre-Upgrade Peripherals"
        DaiPeripheral[XDaiBridgePeripheralForDaiPreUsdsUpgrade]
        UsdsPeripheral[XDaiBridgePeripheralForUsdsPreUsdsUpgrade]
    end

    BridgeRouter -->|DAI| DaiPeripheral
    BridgeRouter -->|USDS| UsdsPeripheral
    BridgeRouter -->|Other ERC20| OmniBridge[Foreign OmniBridge]
    BridgeRouter -->|ETH| WETHRouter[WETH OmniBridge Router]

    DaiPeripheral --> XDaiForeignBridge
    UsdsPeripheral -->|"Convert USDS to DAI"| XDaiForeignBridge

    subgraph "Omnibridge contract"
        OmniBridge --> OmniBridgeHome[Mint bridged token on Gnosis Chain]
        WETHRouter --> OmniBridgeHome
    end
    subgraph "XDaiForeignBridge Contract (Pre-Upgrade)"
        XDaiForeignBridge[XDaiForeignBridge] -->|"DAI as collateral"| GnosisChain[Mint xDAI on Gnosis Chain]
    end
```

### To claim token

```mermaid
graph TD


    subgraph "BridgeRouter Contract"
        BridgeRouter[BridgeRouter]
    end


    subgraph "XDaiForeignBridge Contact"
        XDaiForeignBridge[XDaiForeignBridge] -->|DAI as collateral| GnosisChain[unlock DAI to recipient]
    end

    subgraph "ForeignAMB Contract"
        ForeignAMB[ForeignAMB] --> Action[Unlock token to recipient]
    end

    %% For claim operations (pre-upgrade)
    User -->|executeSignatures| BridgeRouter
    User -.->|revert executeSignaturesUSDS| BridgeRouter
    User -->|safeExecuteSignaturesWithAutoGasLimit| BridgeRouter
    BridgeRouter -->|executeSignatures| XDaiForeignBridge
    BridgeRouter -->|safeExecuteSignaturesWithAutoGasLimit| ForeignAMB[Foreign AMB]

```


Relay DAI

1. DAI.approve(BridgeRouter, amount) 
-> [BridgeRouter.relayTokens(DAI, receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L44) 
-> [XDaiBridgePeripheralForDaiPreUsdsUpgrade.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/XDaiBridgePeripheralForDaiPreUsdsUpgrade.sol#L36) 
-> [xDAIForeignBridge.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/xdaibridge/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol#L64) 


Claim DAI:
1. [BridgeRouter.executeSignatures(message, signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L81) 
-> [xDAIForeignBridge.executeSignatures(message, signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/xdaibridge/contracts/upgradeable_contracts/BasicForeignBridge.sol#L22) 
-> (internal) [onExecuteMessage](https://github.com/gnosischain/tokenbridge-contracts/blob/xdaibridge/contracts/upgradeable_contracts/erc20_to_native/XDaiForeignBridge.sol#L80-L91) |Here is where the DAI is transferred 


Relay USDS:
1. USDS.approve(BridgeRouter, amount) 
-> [BridgeRouter.relayTokens(USDS, receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L47) 
-> [XDaiBridgePeripheralForUsdsPreUsdsUpgrade.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/XDaiBridgePeripheralForUsdsPreUsdsUpgrade.sol#L36) |Here is where USDS is swap to DAI
-> [xDAIForeignBridge.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/xdaibridge/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol#L64) 

Claim USDS:

1. [BridgeRouter.executeSignaturesUSDS(message,signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L105-L109) 
    -> revert


XDaiForeignBridge's current implementation: https://etherscan.io/address/0x166124b75c798cedf1b43655e9b5284ebd5203db
Code: https://github.com/gnosischain/tokenbridge-contracts/tree/xdaibridge/contracts/upgradeable_contracts/erc20_to_native


# Upgrade
```mermaid
graph TD

    subgraph "Upgrade Step 2"
        UpgradeBundledTx[Execute BundledSafeTx by bridge governors]
        UpgradeBundledTx -->|Disable interest for DAI, Enable interest for USDS| XDaiForeignBridge
        UpgradeBundledTx -->|Set USDS as collateral token| XDaiForeignBridge
        UpgradeBundledTx -->|Set DAI route| BridgeRouter --> |DAI| XDaiBridgePeripheral
        UpgradeBundledTx -->|Set USDS route| BridgeRouter --> |USDS| XDaiForeignBridge
    end

    subgraph "Pre upgrade configuration"
        PreConfig[Pre-Upgrade Configuration]
        PreConfig -->|Set DAI route to| BridgeRouterPreUpgrade[BridgeRouter] -->|DAI| DaiPeripheralPre[XDaiBridgePeripheralForDaiPreUsdsUpgrade]
        PreConfig  -->|Set USDS route to| BridgeRouterPreUpgrade[BridgeRouter] -->|USDS |UsdsPeripheralPre[XDaiBridgePeripheralForUsdsPreUsdsUpgrade]
        PreConfig -->|DAI as collateral| XDaiForeignBridgeDaiCollateral[XDaiForeignBridge]
    end
    PreConfig -->|Upgrade| UpgradeBundledTx


```


Test for the upgrade is written in [here](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/test/foundry/BridgeRouter.t.sol#L531-L537)

## Function calls during the proxy upgrade
>> The function calls during the upgrade is a bundled Safe transaction, that will be signed by [bridge governors](https://docs.gnosischain.com/bridges/management/#bridge-governance).


### Call on xDAI Foreign Bridge contract

BRIDGE_PROXY=`0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016`

Caller: Bridge Owner `0x42F38ec5A75acCEc50054671233dfAC9C0E7A3F6`

```solidity
   uint256 initialVersion = 8
   address newImpl = # TODO: deploy
   bridgeProxy.upgradeTo(initialVersion + 1, address(newImpl));

   // disable interested for DAI and swap sDAI -> sUSDS
   bridgeProxy.swapSDAIToUSDS();
   bridgeProxy.initializeInterest(
      address(USDS): 0xdC035D45d973E3EC169d2276DDab16f1e407384F,
      minCashThreshold: 1000000000000000000000000,
      minInterestPaid: 1000000000000000000000,
      gnosisInterestReceiver: 0x670daeaF0F1a5e336090504C68179670B5059088
   );
   bridgeProxy.invest(address(USDS));
```


### Update routes on BridgeRouter 
Caller: BridgeRouterOwner `0x42F38ec5A75acCEc50054671233dfAC9C0E7A3F6` (same as the bridge owner)

ROUTER_ADDRESS= # TODO deploy
XDAI_BRIDGE_PERIPHERAL= # TODO deploy
XDAI_FOREIGNBRIDGE_PROXY=`0x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016`

```solidity
router.setRoute(address(DAI), address(xDAIBridgeperipheral));
router.setRoute(address(USDS), xDAIForeignBridgeProxy);
```
# After the upgrade
### Relay token

```mermaid
graph TD
    User([User]) -->|"relayTokens: DAI"| BridgeRouter
    User -->|"relayTokens: USDS"| BridgeRouter
    User -->|"relayTokens: Other ERC20"| BridgeRouter
    User -->|"relayTokens: ETH"| BridgeRouter

    subgraph "BridgeRouter Contract"
        BridgeRouter[BridgeRouter]
    end
    subgraph "Post-Upgrade Peripheral"
        UsdsPeripheral[XDaiBridgePeripheral]
    end

    BridgeRouter -->|DAI| UsdsPeripheral
    BridgeRouter -->|USDS| XDaiForeignBridge
    BridgeRouter -->|Other ERC20| OmniBridge[Foreign OmniBridge]
    BridgeRouter -->|ETH| WETHRouter[WETH OmniBridge Router]


    UsdsPeripheral -->|"Convert DAI to USDS"| XDaiForeignBridge

    subgraph "Omnibridge contract"
        OmniBridge --> OmniBridgeHome[Mint bridged token on Gnosis Chain]
        WETHRouter --> OmniBridgeHome
    end
    subgraph "XDaiForeignBridge Contract (Post-Upgrade)"
        XDaiForeignBridge[XDaiForeignBridge] -->|"USDS as collateral"| GnosisChain[Mint xDAI on Gnosis Chain]
    end
```

### To claim token

```mermaid
graph TD


    subgraph "BridgeRouter Contract"
        BridgeRouter[BridgeRouter]
    end


    subgraph "XDaiForeignBridge Contact"
        XDaiForeignBridge[XDaiForeignBridge] -->|exeucteSignatures| DAI[unlock DAI to recipient]
        XDaiForeignBridge[XDaiForeignBridge] -->|exeucteSignaturesUSDS| Ethereum[unlock USDS to recipient]

    end

    subgraph "ForeignAMB Contract"
        ForeignAMB[ForeignAMB] --> Action[Unlock token to recipient]
    end

    %% For claim operations (pre-upgrade)
    User -->|executeSignatures| BridgeRouter
    User -->|executeSignaturesUSDS| BridgeRouter
    User -->|safeExecuteSignaturesWithAutoGasLimit| BridgeRouter
    BridgeRouter -->|executeSignatures| XDaiForeignBridge
    BridgeRouter -->|executeSignaturesUSDS| XDaiForeignBridge
    BridgeRouter -->|safeExecuteSignaturesWithAutoGasLimit| ForeignAMB[Foreign AMB]

```





Relay DAI:
1. DAI.approve(BridgeRouter, amount)
-> [BridgeRouter.relayTokens(DAI, receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L44)
-> [XDaiBridgePeripheral.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/XDaiBridgePeripheral.sol#L35)
-> [xDAIForeignBridge.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol#L64)


Claim DAI:
1. [BridgeRouter.executeSignatures(message, signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L85) 
    -> [xDAIForeignBridge.executeSignatures(message, signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/BasicForeignBridge.sol#L22)
    -> (internal)[onExecuteMessage](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/XDaiForeignBridge.sol#L146-L156) |Here is where USDS is swap to DAI 
    
    
Relay USDS:
1. USDS.approve(bridgeRouter, amount)
-> [BridgeRouter.relayTokens(USDS, receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L47) 
-> [xDAIForeignBridge.relayTokens(receiver, amount)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/ForeignBridgeErcToNative.sol#L64)

Claim USDS:

1. [BridgeRouter.executeSignaturesUSDS(message, signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/BridgeRouter.sol#L111)
    -> [xDAIForeigbBridge.executeSignaturesUSDS(message,signatures)](https://github.com/gnosischain/tokenbridge-contracts/blob/feat/xdai-usds-migration/contracts/upgradeable_contracts/erc20_to_native/XDaiForeignBridge.sol#L113)
    
    
    
    
