> For the complete documentation index, see [llms.txt](https://omnify.gitbook.io/omnify-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://omnify.gitbook.io/omnify-docs/deep-dive/omnibridge.md).

# OmniBridge

OmniBridge allows the migration and return of assets instantly between all of Omnify's supported networks. Each source asset is locked on the source network and has its own distinct equivalent asset on each destination network. This equivalent asset is minted upon receiving the migrated assets, and is burned when returning it to the source network. This method ensures a 1:1 peg between source and bridged assets. Accessible from [bridge.omnify.finance](http://bridge.omnify.finance) and [app.omnify.finance/bridges](https://app.omnify.finance/bridges)

<figure><img src="/files/M7Y0KitENMTRU87gntEl" alt=""><figcaption><p>OmniBridge banner</p></figcaption></figure>

### Migrating and Returning assets

The process of migrating and returning assets using OmniBridge is very straightforward. Start by downloading the [OmniBridge interface](https://github.com/OmniKobra/Omnify/blob/main/Omni/Contracts/Omnify/src/interfaces/bridgesInterface.sol) from our github repo. You can find a list of all Omnify services' tiers and fees at [omnify.finance/fees](https://omnify.finance/fees).&#x20;

{% hint style="warning" %}
OmniBridge does not support native token bridging with "msg.value". Make sure your native tokens are wrapped into their ERC20 wrap before bridging.
{% endhint %}

In this example we will be bridging USDC from Avalanche C-Chain to Binance Smart Chain.

### Bridging

{% stepper %}
{% step %}

### Define OmniBridge variable

```solidity
IBridges99 public omnibridge = IBridges99(0x27Efe83C0629D5c3B1C3554EaB3E2B3645d2465e);
```

{% endstep %}

{% step %}

### Quote network fee

Omnify uses LayerZero to send and receive cross-chain messages. LayerZero requires a network fee to process these messages and get them across to the destination networks. We can learn how much LayerZero's DVN's & Executors request to process our bridge transactions by calling `quote` with our payload from our OmniBridge contract.&#x20;

Before we call `quote` we need to know:

1. the destination chain's LayerZero ID
2. the payload message we want to send
3. and create the options that we will forward to LayerZero's DVNs & executors

(1) All networks' Layerzero IDs can be found in our [notes file](https://github.com/OmniKobra/Omnify/blob/main/Omni/notes) in our Github Repo.

#### (2) Payload message

The payload message is simply a string that contains the transaction details:

`"sourceAssetAddress.sourceChainEid.msgsenderaddress.recipientAddress.amount.assetName.assetSymbol.assetDecimals.isReturningBridgedAsset.foreignEquivalentAddress"`&#x20;

You can dynamically deduce the payload as such:

```solidity
    import "../lib/openzeppelin-contracts/contracts/utils/Strings.sol";
    import "../lib/solidity-stringutils/strings.sol";
    
    using strings for *;
    
    string public _message = '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664.30106.0x22c4D933bf8A882b065Bb5451d1Cf9991C817560.0x6BF6D002b5140b7CE0A0a4993621ecE52271e5f0.100000.USD Coin.USDC.6.';
    address _foreignEquivalent = omnibridge.lookupBridgedTokenForeignEquivalent(address(0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664), 30102);
    address _bridgedEquivalent = omnibridge.lookupForeignTokenBridgedEquivalent(_foreignEquivalent, 30102);
    bool isReturningBridgedAsset = (_bridgedEquivalent != address(0)) && (_bridgedEquivalent == address(0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664));
    if (isReturningBridgedAsset) {
        _message = string.concat(_message, "true.");
    } else {
        _message = string.concat(_message, "false.");
    }
    string _foreignEquivalentString = Strings.toHexString(uint256(uint160(_foreignEquivalent)), 20);
    _message = string.concat(_message, _foreignEquivalentString);
```

{% hint style="info" %}
Check out `migrateAssets` in our [OmniBridge contract](https://github.com/OmniKobra/Omnify/blob/main/Omni/Contracts/Omnify/src/bridges.sol) source code For a more detailed approach on how to dynamically generate the payload.
{% endhint %}

(3) Now let's get the gas limit and create the options

```solidity
uint128 public gasLimit = omnibridge.GAS_LIMIT();
bytes memory _options = omnibridge.createLzReceiveOption(gasLimit, 0);
```

Lets explain `quote` and its structure&#x20;

```solidity
function quote(
uint32 _dstEid, // destination chain layerzero id, all ids can be found at our github repo notes
string memory _message, // the message we will be sending
bytes memory _options, // the options we created
bool _payInLzToken) // false
external
view
returns (
 uint256 nativeFee,// the returned fee
 uint256 lzTokenFee); // not needed
```

We can finally call `quote` from our code

```solidity
(uint256 nativeFee, ) = omnibridge.quote(30102, _message, _options, false);
```

{% endstep %}

{% step %}

### Get Omnify fee

We are one step away from bridging our tokens, we only need to get Omnify's bridge fee, add it to LayerZero's fee and then pass it to `migrateAssets` .

```solidity
uint256 bridgeFee = omnibridge.bridgeFee();
```

{% endstep %}

{% step %}

### Migrate Assets

We now have all the properties we need to call `migrateAssets`.

```solidity
omnibridge.migrateAssets{value : nativeFee + bridgeFee}(
address(0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664), // source token address
100000, // token amount in Wei
30102, // destination network layerzero id
address(0x6BF6D002b5140b7CE0A0a4993621ecE52271e5f0) // recipient address on destination chain
);
```

{% endstep %}
{% endstepper %}

***Bridging through OmniBridge is complete, Good Job!*****&#x20;👏**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://omnify.gitbook.io/omnify-docs/deep-dive/omnibridge.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
