Protocol Integration

You can integrate with most of the protocols with Labyrinth protocol, to allow anonymous transactions for the users. Your users will be using their shielded account instead of a public account to interact with your protocol.

For this, you'll have to write and deploy a stateless contract that acts as a logic layer between the Labyrinth core and the target protocol that you're integrating. We call these contracts Adaptors. The reason is that these contracts take input assets from the user's shielded account, convert those assets to some other (output) assets, and return these output assets back to Labyrinth. The interaction basically converts from one asset to another. Some examples:

  • When WETH with USDC on Uniswap you're converting your WETH (input) to USDC (ouput).

  • When staking WETH on Lido you convert your WETH (input) to wstETH (output).

  • When lending USDT on Aave, you convert it to aUSDT.

Adaptor Contracts

These are the smart contacts that implement the IAdaptorinterface:

interface IAdaptor {
    function handleAssets(
        uint24[] calldata inAssetIds,
        uint256[] calldata inValues,
        bytes calldata payload
        returns (uint24[] memory outAssetIds, uint256[] memory outValues);

The interface only requires the implementation of the convert method as seen above.

  • inAssetIds is the list of asset ids of the assets given to this contract.

  • inValues is the corresponding value of the specified asset ids in that order.

  • payload is an arbitrary data passed on that might be required as, for example, user input for the necessary operation.

Note that handleAssets function is delegatecalled by the Labyrinth's AdaptorHandler contract. At the time of call, the AdaptorHandler holds exactly the amount of assets that were specified by the inAssetIds and inValues. So, you don't need to do any ERC-20 operation like transferFrom(...) or anything to get the assets - you already have it.

Simply do any necessary operation within the handleAssets(...) method and return any output assets by returning outAssetIds and outValues. Please make sure that after performing your convert operation you only exactly have those assets (outAssetIds) and exactly those amount of the assets (outValues).


UniswapV3 integration with Labyrinth

Last updated