Skip to main content

Documentation Index

Fetch the complete documentation index at: https://tech.ramses.xyz/llms.txt

Use this file to discover all available pages before exploring further.

Ramses V3 uses interfaces compatible with Uniswap V3, so you can use the @uniswap/v3-periphery and @uniswap/v3-core npm packages for interface definitions. The callback function names (uniswapV3FlashCallback, etc.) remain the same for compatibility.
This guide builds a contract that calls flash on a Ramses V3 pool and arbitrages the price difference between pools with different fee tiers for the same token pair.

Flash Transactions Overview

flash withdraws specified amounts of both token0 and token1 to a recipient. The withdrawn amount plus fees must be repaid by the end of the transaction. A data parameter allows passing arbitrary abi-encoded data to the callback.
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external override lock noDelegateCall {

The Flash Callback

Inside flash, the pool calls back into msg.sender:
IUniswapV3FlashCallback(msg.sender).uniswapV3FlashCallback(fee0, fee1, data);
This is where you implement your custom logic. Three callbacks exist: uniswapV3SwapCallback, uniswapV3MintCallback, and uniswapV3FlashCallback.

Contract Setup

Inherit IUniswapV3FlashCallback and PeripheryPayments. PeripheryPayments extends other contracts we need, including LowGasSafeMath.
pragma solidity =0.7.6;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3FlashCallback.sol';
import '@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol';

import '@uniswap/v3-periphery/contracts/base/PeripheryPayments.sol';
import '@uniswap/v3-periphery/contracts/base/PeripheryImmutableState.sol';
import '@uniswap/v3-periphery/contracts/libraries/PoolAddress.sol';
import '@uniswap/v3-periphery/contracts/libraries/CallbackValidation.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';

contract PairFlash is IUniswapV3FlashCallback, PeripheryPayments {
    using LowGasSafeMath for uint256;
    using LowGasSafeMath for int256;

    ISwapRouter public immutable swapRouter;

    constructor(
        ISwapRouter _swapRouter,
        address _factory,
        address _WETH9
    ) PeripheryImmutableState(_factory, _WETH9) {
        swapRouter = _swapRouter;
    }
}