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 and app.omnify.finance/bridges

OmniBridge banner

Migrating and Returning assets

The process of migrating and returning assets using OmniBridge is very straightforward. Start by downloading the OmniBridge interface from our github repo. You can find a list of all Omnify services' tiers and fees at omnify.finance/fees.

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

Bridging

1

Define OmniBridge variable

IBridges99 public omnibridge = IBridges99(0x27Efe83C0629D5c3B1C3554EaB3E2B3645d2465e);
2

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.

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 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"

You can dynamically deduce the payload as such:

    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);

Check out migrateAssets in our OmniBridge contract source code For a more detailed approach on how to dynamically generate the payload.

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

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

Lets explain quote and its structure

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

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

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 .

uint256 bridgeFee = omnibridge.bridgeFee();
4

Migrate Assets

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

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
);

Bridging through OmniBridge is complete, Good Job! 👏

Last updated