Module 4 - About Bridge Adapters
Adapters for Bridging Assets
This Module is Useful for Understanding the AssetBridgeAdapter and NitroAdapter Smart Contracts which are helpful for learning about Bridging Adapters. Refer this Repository for Smart Contracts.
Asset Bridge Adapter
This Tutorial will Guide you through the functionality of the AssetBridgeAdapter.sol
Smart Contract. This Contract is Designed to Bridge Funds and Instructions to another Blockchain. It Utilizes the RouterIntentEoaAdapterWithoutDataProvider
for Executing Transactions and Interacting with an AssetBridge for Transferring or Swapping Tokens.
-
Contract Structure - The
AssetBridgeAdapter
Contract inherits fromRouterIntentEoaAdapterWithoutDataProvider
and Integrates with anAssetBridge
for Asset Bridging Operations. It usesSafeERC20
for Secure Token Operations and follows a Structure that Separates Data Storage (AssetBridgeDataStore
) from the Main Adapter Logic. The Contract imports Several Dependencies -a)
RouterIntentEoaAdapterWithoutDataProvider
andEoaExecutorWithoutDataProvider
from@routerprotocol/intents-core
.b)
Errors
for error handling.c)
IERC20
andSafeERC20
from a utilities library.d)
IAssetBridge
interface.e)
Ownable
fromOpenZeppelin
for access control. -
Data Storage Contract - The
AssetBridgeDataStore
Contract Stores the Address of theAssetBridge
and allows the Owner to Update it. -
Main Adapter Contract - The
AssetBridgeAdapter
Contract Defines -a)
assetBridgeDataStore
to StoreAssetBridge
Address.b)
PARTNER_ID
as a Constant Identifier.c) A Constructor to Initialize the Contract and Deploy
AssetBridgeDataStore
.d)
name()
function to return the Adapter’s Name.e)
execute()
function to hHndle the Execution Logic for Bridging Tokens. -
Deployment - To Deploy the
AssetBridgeAdapter
, you need to Provide the Addresses for Native and Wrapped Native Tokens, as well as theAssetBridge
Contract. -
Functions -
a) name() - This function returns the name of the Adapter.
b) execute() - The
execute
function Performs the following Actions Based on thetxType
Decoded from the Input Data -- Transfer Token
- Directly transfers tokens using
IAssetBridge.transferToken
.
- Swap and Transfer Token
- Swaps and then transfers tokens using
IAssetBridge.swapAndTransferToken
.
-
Usage Example - To Use the
AssetBridgeAdapter
, you need to Call the Execute function with appropriate calldata.-
Example: Transfer Token
-
Example: Swap and Transfer Token
-
Conclusion
The AssetBridgeAdapter
Contract Provides a Robust Solution for Bridging Assets and Instructions across Chains. By following this Tutorial, Developers can understand the Contract’s Structure, deploy it, and use its functions effectively.
NitroAdapter
This Tutorial will Guide you through the functionality and Usage of the NitroAdapter
Smart Contract. The NitroAdapter
Contract is Designed to facilitate the Bridging of Assets and Instructions to another Blockchain. It Integrates with Both an AssetForwarder
and DexSpan
to Perform Token Deposits and Swaps.
-
Contract Structure - The
NitroAdapter
Contract inherits fromRouterIntentEoaAdapterWithoutDataProvider
and Interacts withAssetForwarder
andDexSpan
for Asset Bridging Operations. It usesSafeERC20
for Secure Token Operations and follows a Structure that Separates Data Storage (NitroDataStore
) from the Main Adapter Logic. The Contract imports Several Dependencies -a)
RouterIntentEoaAdapterWithoutDataProvider
andEoaExecutorWithoutDataProvider
from@routerprotocol/intents-core
.b)
Errors
for error handling.c)
IERC20
andSafeERC20
from a utilities library.d)
IAssetForwarder
andIDexSpan
interfaces.e)
Ownable
fromOpenZeppelin
for access control. -
Data Storage Contract - The
NitroDataStore
Contract Stores the Addresses of theAssetForwarder
andDexSpan
and allows the Owner to Update them. -
Main Adapter Contract - The
NitroAdapter
Contract Defines -a)
USDC
as the address of the USDC Token.b)
NitroDataStore
to storeAssetForwarder
andDexSpan
addresses.c)
PARTNER_ID
as a constant identifier.c) A constructor to initialize the Contract and deploy
NitroDataStore
.d)
name()
function to return the Adapter’s name.e)
execute()
function to handle the Execution Logic for Bridging Tokens. -
Deployment - To Deploy the
NitroAdapter
, you need to Provide the addresses for Native and Wrapped Native Tokens, as well as theAssetForwarder
andDexSpan
Contracts. -
Functions -
a) name() - This function returns the name of the Adapter.
b) execute() - The
execute
function Performs the following Actions Based on thetxType
Decoded from the Input Data -- iDeposit
- Directly Deposits Tokens using
IAssetForwarder.iDeposit
.
- Directly Deposits Tokens using
- Swap and Deposit
- Swaps and then Deposits Tokens using
IDexSpan.swapAndDeposit
.
- Swaps and then Deposits Tokens using
- USDC Request
- Requests USDC Deposit using
IAssetForwarder.iDepositUSDC
.
- Requests USDC Deposit using
- Swap and Deposit USDC
- Swaps and then Deposits USDC Tokens using
IDexSpan.swapAndDeposit
.
- Swaps and then Deposits USDC Tokens using
- iDeposit
-
Usage Example - To use the
NitroAdapter
, you need to Call the execute function with appropriate calldata.-
Example: iDeposit
-
Example: Swap and Deposit
-
Example: USDC Request
-
Example: Swap and Deposit USDC
-
Conclusion
The NitroAdapter
Contract provides a Robust Solution for Bridging Assets and Instructions across Chains. By following this Tutorial, Developers can Understand the Contract’s Structure, Deploy it, and use its functions Effectively.