CoWSwapAdapter

Git Source

Inherits: TokenSwapAdapter

Adapter for executing and completing token swaps using CoWSwap protocol.

State Variables

_COWSWAP_ADAPTER_STORAGE

CONSTANTS ///

Storage slot for CoWSwapAdapter specific data.

bytes32 internal constant _COWSWAP_ADAPTER_STORAGE =
    bytes32(uint256(keccak256("cove.basketmanager.cowswapadapter.storage")) - 1);

cloneImplementation

Address of the clone implementation used for creating CoWSwapClone contracts.

address public immutable cloneImplementation;

Functions

constructor

Constructor to initialize the CoWSwapAdapter with the clone implementation address.

constructor(address cloneImplementation_) payable;

Parameters

NameTypeDescription
cloneImplementation_addressThe address of the clone implementation contract.

executeTokenSwap

Executes a series of token swaps by creating orders on the CoWSwap protocol.

function executeTokenSwap(ExternalTrade[] calldata externalTrades, bytes calldata) external payable override;

Parameters

NameTypeDescription
externalTradesExternalTrade[]The external trades to execute.
<none>bytes

completeTokenSwap

Completes the token swaps by claiming the tokens from the CoWSwapClone contracts.

function completeTokenSwap(ExternalTrade[] calldata externalTrades)
    external
    payable
    override
    returns (uint256[2][] memory claimedAmounts);

Parameters

NameTypeDescription
externalTradesExternalTrade[]The external trades that were executed and need to be settled.

Returns

NameTypeDescription
claimedAmountsuint256[2][]A 2D array containing the claimed amounts of sell and buy tokens for each trade.

_createOrder

Internal function to create an order on the CoWSwap protocol.

function _createOrder(
    address sellToken,
    address buyToken,
    uint256 sellAmount,
    uint256 buyAmount,
    uint32 validTo
)
    internal;

Parameters

NameTypeDescription
sellTokenaddressThe address of the token to sell.
buyTokenaddressThe address of the token to buy.
sellAmountuint256The amount of the sell token.
buyAmountuint256The minimum amount of the buy token.
validTouint32The timestamp until which the order is valid.

_cowswapAdapterStorage

Internal function to retrieve the storage for the CoWSwapAdapter.

function _cowswapAdapterStorage() internal pure returns (CoWSwapAdapterStorage storage s);

Returns

NameTypeDescription
sCoWSwapAdapterStorageThe storage struct for the CoWSwapAdapter.

Events

OrderCreated

EVENTS ///

Emitted when a new order is created.

event OrderCreated(
    address indexed sellToken,
    address indexed buyToken,
    uint256 sellAmount,
    uint256 buyAmount,
    uint32 validTo,
    address swapContract
);

Parameters

NameTypeDescription
sellTokenaddressThe address of the token to be sold.
buyTokenaddressThe address of the token to be bought.
sellAmountuint256The amount of the sell token.
buyAmountuint256The amount of the buy token.
validTouint32The timestamp until which the order is valid.
swapContractaddressThe address of the swap contract.

TokenSwapCompleted

Emitted when a token swap is completed.

event TokenSwapCompleted(
    address indexed sellToken,
    address indexed buyToken,
    uint256 claimedSellAmount,
    uint256 claimedBuyAmount,
    address swapContract
);

Parameters

NameTypeDescription
sellTokenaddressThe address of the token sold.
buyTokenaddressThe address of the token bought.
claimedSellAmountuint256The amount of sell tokens claimed.
claimedBuyAmountuint256The amount of buy tokens claimed.
swapContractaddressThe address of the swap contract.

Structs

CoWSwapAdapterStorage

STRUCTS ///

Structure to store adapter-specific data.

struct CoWSwapAdapterStorage {
    uint32 orderValidTo;
}