Deploying Extensions

Overview

Extensions add additional functionality to a vault. Extensions can range from allowing every possible transaction, all the way to explicitly locking down the functionality of a vault to a single smart contract function call.

This allows a large spectrum of strategies to be built, however the degree of trust in a vault operator grows substantially as they move away from clearly defined and relatively secure permissions.

An example of a tightly scoped extension that requires less trust in the operator is functionality that enables trading on Uniswap with a pre-approved pair of tokens.

As you can see the extension checks tokens in/out along with verifies that the recipient of tokens is the vault. No other Uniswap actions are allowed.

function swapExactInputSingle(
    ISwapRouter.ExactInputSingleParams memory params
) external returns (uint256) {
    require(
        params.tokenIn == token0 || params.tokenIn == token1,
        "token not allowed"
    );
    require(
        params.tokenOut == token0 || params.tokenOut == token1,
        "token not allowed"
    );

    require(params.recipient == address(this), "unauthorized recipient");

    // optionally handle validation
    return swapRouter.exactInputSingle(params);
}

Deployment

In this example we are using Arbitrum to keep costs low, while still having a real testing environment with actual liquidity and trading activity. The script we are going to run is called CreateUniswapSinglePair. If you desire to deploy on a different network, it's important to replace the hardcoded addresses with correct addresses for the respective network:

The UniswapSinglePair extensions contract enables all the functionality of Uniswap v3 (swapping, managing liquidity, etc.) but limits it to a specific pair of tokens (WETH and USDC in our case).

At this point make sure you have both the address for your vault, and the address for this uniswap single pair extension contract.

Last updated

Was this helpful?