Introduction -
Router Nitro is a bridge built using our cross-chain primitive “Reverse Verification” flow, which enables high-speed and low-cost transfers.
The reverse verification flow is created using the application-specific bridging construct enabled by our chain. This primitive can be used by other applications to make them more efficient in the future.
Moreover, Router Nitro enables the flow of arbitrary instructions along with asset transfers, thus expanding the realm of composability within the DeFi ecosystem across diverse blockchain networks.
Flows of Router Nitro which enables its swapping -
1) Forwarder Flow — It uses a trustless optimistic approach to handle cross-chain asset transfers and has an entity called the forwarder that provides the users with their desired assets on the destination chain.
2)Burn and Mint flow — For certain tokens, the bridge has mint/burn rights, which allows the bridge to burn the tokens on one chain and mint them on another.
3) USDC circle flow — This flow uses Circle’s CCTP infra to provide cross-chain transfers of USDC. The flow works for USDC transfers on chains where CCTP is live.
Talking about the Architecture -
Building via Router Nitro is a 3-Step Process-
A)Get The Quote-
1)Router Nitro enables you to interact with the Smart Contract and initiate Cross-Chain Token Transfers. The first step in this process is to request a Quote, which provides you with essential details about the proposed Token Transfer.
2)We Define a Path Finder API URL For The Nitro Testnet, the point where we send our Quote Request.
3)Another step is creating a getQuote
function which uses the axios
library to make an HTTP Get Request to the Nitro Path Finder API URL.
4)Later on, we call the getQuote
function by passing appropriate Parameters. Some Parameters define the details of the token transfer you wish to execute. The parameters are- fromTokenAddress
, toTokenAddress
, amount
, fromTokenChainId
, toTokenChainId
, widgetId
.
B)Check & Set Allowance-
1)This Step involves Verification and Configuration of the allowance for Token Transfer. It allows Router's Swap to safely Transfer Tokens between different Blockchains.
2)We begin by defining an ABI (Application Binary Interface) for ERC20 Tokens, which is essential for interacting with ERC20 Token Contract. The checkAndSetAllowance
function checks the current allowance, and if required, creates a new one.
3)Using the provided Token Address and ERC20 ABI Address, one can Create an instance of the ERC20 Contract. If the Current Allowance is less than the Desired Amount, we proceed to set a new allowance. We initiate an approval Transaction to the ERC20 contract, Granting Permission to Router's swap or Transfer Contract to withdraw tokens on your behalf.
4)The Code Handles the approved Transaction, monitors its status, and logs the Transaction hash upon Successful Confirmation. When the Button is clicked your signer (wallet) is set up and the checkAndSetAllowance
function is called with the required parameters. You can find it in quote.allowanceTo in the quoteData obtained from Step 1.
C)Execute The Transaction-
1)This step involves Executing a Transaction. This process involves sending a Transaction To Perform The Cross-Chain Token Transfer initiated in Steps 1 and 2.
2)The function responsible for Executing the Transaction is getTransaction
. It takes in the following parameters: fromTokenAddress
, toTokenAddress
, amount
, fromTokenChainId
, toTokenChainId
, widgetId
and quoteData
from Step 1.
3)Later on, Call the getTransaction
function with the necessary parameters to fetch the Transaction Data from the Nitro system.
4)The Send Transaction Initiates the transaction using the data obtained from the Nitro system.