Skip to content

USDSToDAIUniswapV3Swapper

Git Source

Inherits: UniswapV3Swapper

A specialized Uniswap V3 swapper that handles USDS-DAI conversions

This contract extends UniswapV3Swapper to provide seamless swapping between any token and USDS by automatically converting between DAI and USDS when needed. It uses a DAI-USDS converter for 1:1 conversions and Uniswap V3 for other token pairs.

State Variables

daiToUsdsConverter

The DAI-USDS converter contract for 1:1 conversions

IDaiUsdsConverter public immutable daiToUsdsConverter

DAI

The address of the DAI token contract

address public immutable DAI

USDS

The address of the USDS token contract

address public immutable USDS

Functions

constructor

Constructs the USDSToDAIUniswapV3Swapper contract

constructor(
    IUniswapSwapRouterLike uniswapRouter_,
    IUniswapQuoterLike quoter_,
    IDaiUsdsConverter daiToUsdsConverter_,
    address dai_,
    address usds_
)
    UniswapV3Swapper(uniswapRouter_, quoter_);
Parameters
NameTypeDescription
uniswapRouter_IUniswapSwapRouterLikeThe address of the Uniswap V3 router contract
quoter_IUniswapQuoterLikeThe address of the Uniswap V3 quoter contract
daiToUsdsConverter_IDaiUsdsConverterThe address of the DAI-USDS converter contract
dai_addressThe address of the DAI token contract
usds_addressThe address of the USDS token contract

swap

Swaps tokens with automatic USDS-DAI conversion handling

This function handles three scenarios:

  1. USDS -> Other Token: Converts USDS to DAI, then swaps DAI to target token
  2. Other Token -> USDS: Swaps input token to DAI, then converts DAI to USDS
  3. Other Token -> Other Token: Uses standard Uniswap V3 swap (via parent contract)
function swap(
    address assetIn,
    uint256 amountIn,
    address assetOut,
    uint256 minAmountOut,
    address recipient,
    bytes calldata swapperParams
)
    public
    override
    returns (uint256 amountOut);
Parameters
NameTypeDescription
assetInaddressThe address of the input token to swap from
amountInuint256The amount of input tokens to swap
assetOutaddressThe address of the output token to swap to
minAmountOutuint256The minimum amount of output tokens expected
recipientaddressThe address that will receive the output tokens
swapperParamsbytesABI-encoded SwapperParams struct containing the fee tier
Returns
NameTypeDescription
amountOutuint256The actual amount of output tokens received from the swap

getAmountOut

Quotes the amount of output tokens with USDS-DAI conversion handling

Automatically substitutes USDS with DAI for price quotes since USDS-DAI conversion is 1:1. This provides accurate pricing for swaps involving USDS.

function getAmountOut(
    address assetIn,
    uint256 amountIn,
    address assetOut,
    bytes calldata swapperParams
)
    public
    override
    returns (uint256 amountOut);
Parameters
NameTypeDescription
assetInaddressThe address of the input token
amountInuint256The amount of input tokens
assetOutaddressThe address of the output token
swapperParamsbytesABI-encoded SwapperParams struct containing the fee tier
Returns
NameTypeDescription
amountOutuint256The estimated amount of output tokens

Errors

BothAssetsUSDS

Thrown when both assets are USDS

error BothAssetsUSDS();