CoWSwapAdapter
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
Name | Type | Description |
---|---|---|
cloneImplementation_ | address | The 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
Name | Type | Description |
---|---|---|
externalTrades | ExternalTrade[] | 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
Name | Type | Description |
---|---|---|
externalTrades | ExternalTrade[] | The external trades that were executed and need to be settled. |
Returns
Name | Type | Description |
---|---|---|
claimedAmounts | uint256[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
Name | Type | Description |
---|---|---|
sellToken | address | The address of the token to sell. |
buyToken | address | The address of the token to buy. |
sellAmount | uint256 | The amount of the sell token. |
buyAmount | uint256 | The minimum amount of the buy token. |
validTo | uint32 | The 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
Name | Type | Description |
---|---|---|
s | CoWSwapAdapterStorage | The 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
Name | Type | Description |
---|---|---|
sellToken | address | The address of the token to be sold. |
buyToken | address | The address of the token to be bought. |
sellAmount | uint256 | The amount of the sell token. |
buyAmount | uint256 | The amount of the buy token. |
validTo | uint32 | The timestamp until which the order is valid. |
swapContract | address | The 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
Name | Type | Description |
---|---|---|
sellToken | address | The address of the token sold. |
buyToken | address | The address of the token bought. |
claimedSellAmount | uint256 | The amount of sell tokens claimed. |
claimedBuyAmount | uint256 | The amount of buy tokens claimed. |
swapContract | address | The address of the swap contract. |
Structs
CoWSwapAdapterStorage
STRUCTS ///
Structure to store adapter-specific data.
struct CoWSwapAdapterStorage {
uint32 orderValidTo;
}