Bridging Smart Contract
Last updated
Last updated
In order to integrate your DeFi protocol, you’ll need to implement an adapter in the form of a bridging contract. For example, MockDexSingularityBridge.sol
is used as the bridging contract for handling interactions between our Mock DeFi exchange and The Singularity.
There is a hard constraint imposed that limits each DeFi interaction with the Singularity to spending up to 4 notes at once. Similarly, up to 4 notes may be created as a result of a single transaction.
Take the following MockDex.sol
contract as an example:
The swap
method in our example takes an amountIn
qty worth of ETH in exchange for minAmount
qty worth of WETH. For this interaction, a single note (containing ETH) gets spent in exchange for a single newly created note (containing WETH) which the user receives.
When a user of your protocol wants to interact via the Singularity, they’ll invoke a method The defiCall
method will be invoked by _defiCall
via GeneralDefiIntegrationAssetManager.sol
that subsequently calls the defiCall
method in the bridging contract you write. Let’s convey this in code through the implementation of the defiCall
method definition within the MockDexSingularityBridge.sol
contract.
In the case of MockDex
, the assets
and outAmounts
arrays each consist of one item indicative of the assets being spent and received by the user.
NOTE: It’s important to reference values from defiParameters
that’s passed.
Once you've implemented the smart contract bridging contract, it's onto integrating your Dapp with the frontend interface for the contract.