> For the complete documentation index, see [llms.txt](https://docs.fly.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fly.trade/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/bridge/bridgefacet.md).

# BridgeFacet

This is a Solidity contract that implements the `IBridge` interface. The contract has the following functions:

### updateStargateSettings():

updates the settings of the Stargate bridge.

**Input**

<table><thead><tr><th width="220.99999999999997">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">stargateSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">StargateSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct StargateSettings {
    address routerAddress;
}
</code></pre></td></tr></tbody></table>

### updateWormholeBridgeSettings():

updates the settings of the Wormhole bridge.

**Input**

<table><thead><tr><th width="271">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">wormholeBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">WormholeBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct WormholeBridgeSettings {
    address bridgeAddress;
}
</code></pre></td></tr></tbody></table>

The `updateStargateSettings` and `updateWormholeBridgeSettings` functions enforce that only the contract owner can call them, using the `enforceIsContractOwner` function from the LibDiamond library.

### updateCelerBridgeSettings():

It's a way to update and manage the settings associated with the Celer Bridge, and its execution is permissioned for the contract owner.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">celerBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">CelerBridgeSettings
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct CelerBridgeSettings {
    address messageBusAddress;
}
</code></pre></td></tr></tbody></table>

### addCelerChainIds():

The function is responsible for updating the contract's settings related to chain IDs. It utilizes a modular approach where logic for handling chain IDs is encapsulated in the `LibCeler` library. The ownership check at the beginning guarantees that only the contract owner can execute this function.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">networkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16[]
</code></pre></td><td>An array containing identifiers for networks.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">chainIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint64[]
</code></pre></td><td>An array containing chain identifiers corresponding to the networks in <code>networkIds</code>.</td></tr></tbody></table>

### addMagpieCelerBridgeAddress():

This function is responsible for adding Magpie Celer bridge addresses to the contract's settings, associating them with specific network IDs.

**Input**

<table><thead><tr><th width="297.3333333333333">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">networkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16[]
</code></pre></td><td>An array containing identifiers for networks.</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieCelerBridgeAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes32[]
</code></pre></td><td>An array of <code>bytes32</code> values representing Magpie Celer Bridge addresses.</td></tr></tbody></table>

### addMagpieStargateBridgeAddresses():

This function is responsible for adding the given bridge addresses to the corresponding network IDs.

**Input**

<table><thead><tr><th width="336">Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">networkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16[]
</code></pre></td><td>An array of identifier defined by the magpie team for each network</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieStargateBridgeAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes32[]
</code></pre></td><td>An array of magpieStargateBridge addresses for each network in the form of bytes32</td></tr></tbody></table>

### addMagpieStargateBridgeV2Address():

This function is responsible for adding the given bridge addresses to the corresponding network IDs.

**Input**

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">networkIds
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint16[]
</code></pre></td><td>An array of identifier defined by the magpie team for each network</td></tr><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">magpieStargateBridgeAddresses
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">bytes32[]
</code></pre></td><td>An array of magpieStargateBridge addresses for each network in the form of bytes32</td></tr></tbody></table>

### getWormholeTokenSequence():

This function takes a `uint64` parameter `tokenSequence` and returns a `uint64`. It calls the `getTokenSequence` function from the `LibWormhole` library, passing the `tokenSequence` as an argument. The purpose of this function is to retrieve and return a transformed version of the `tokenSequence` using the `LibWormhole` library.

**Input**:

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">tokenSequence
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">uint64
</code></pre></td><td>The token sequence defined by magpie</td></tr></tbody></table>

**Output**:

| Field | Type | Description                                |
| ----- | ---- | ------------------------------------------ |
|       |      | The token sequence receiver from wormhole. |

### bridgeIn():

This function takes a `BridgeInArgs` struct as a `calldata` parameter and does not return a value. It overrides a function declared in an interface or parent contract. It calls the `bridgeIn` function from the `LibBridge` library, passing the `bridgeInArgs` as an argument.

**Input**:

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">bridgeInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">BridgeInArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct BridgeInArgs {
    uint16 recipientNetworkId;
    BridgeArgs bridgeArgs;
    uint256 amount;
    address toAssetAddress;
    TransferKey transferKey;
}
</code></pre></td></tr></tbody></table>

### bridgeOut():

This function takes a `BridgeOutArgs` struct as a `calldata` parameter and returns a `uint256` value. It overrides a function declared in an interface or parent contract. It calls the `bridgeOut` function from the `LibBridge` library, passing the `bridgeOutArgs` as an argument.

**Input**:

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">bridgeOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">BridgeOutArgs
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">struct BridgeOutArgs {
    BridgeArgs bridgeArgs;
    Transaction transaction;
    TransferKey transferKey;
}
</code></pre></td></tr></tbody></table>
