Docs

Reference

Contract reference

Functions, structs, and enums.


Source of truth: CoverGate.sol, compiled with Solidity 0.8.28. See Deployment for addresses.

Enums#

Kind: Swap (0), Transfer (1).

Status: None (0), Open (1), Active (2), Delivered (3), Failed (4), Cancelled (5).

Structs#

solidity
struct Agent {
    address operator;
    uint256 bond;
    uint256 locked;
    uint64 delivered;
    uint64 failed;
    uint256 compensationPaid;
}

struct Task {
    address user;
    address agent;
    Kind kind;
    Status status;
    uint64 deadline;
    address tokenIn;
    uint256 amountIn;
    address tokenOut;
    uint256 minOut;
    address recipient;
    uint256 fee;
    uint256 compensation;
}

Agent functions#

register#

solidity
function register(address agent, string calldata name) external

The caller becomes the operator of agent. The name is only emitted in the event. Reverts with AlreadyRegistered or, for the zero address, UnknownAgent.

deposit#

solidity
function deposit(address agent, uint256 amount) external

Adds USDG to the bond. Anyone can call it. Needs an approval. Reverts with UnknownAgent.

withdraw#

solidity
function withdraw(address agent, uint256 amount) external

Sends free bond to the operator. Operator only. Reverts with NotOperator or BondLocked.

Task functions#

createTask#

solidity
function createTask(Task calldata terms) external returns (uint256 id)

Pulls amountIn of tokenIn and fee of USDG from the caller and opens a task. The contract sets user and status itself, so those fields are ignored.

Requires a registered agent, a future deadline, and amountIn and compensation above zero. A Swap also needs tokenOut set and different from tokenIn, and minOut above zero. A Transfer needs a recipient. Otherwise it reverts with UnknownAgent or BadTask.

cancel#

solidity
function cancel(uint256 id) external

Refunds an Open task in full. Only the user who created it. Reverts with NotUser or WrongStatus.

accept#

solidity
function accept(uint256 id) external

Locks the compensation and moves the task to Active. Agent key or operator, before the deadline. Reverts with NotAgent, WrongStatus, PastDeadline, or BondTooLow.

executeSwap#

solidity
function executeSwap(uint256 id, address router, bytes calldata data) external

Runs data on router, then sends all output and any unused input to the user, and pays the fee to the operator. Agent key or operator, while Active, up to the deadline. Reverts with NotAgent, WrongStatus, PastDeadline, BadTask, BadRouter, SwapFailed, or BelowMinOut.

executeTransfer#

solidity
function executeTransfer(uint256 id) external

Sends the escrow to the recipient and pays the fee to the operator. Same access and timing as executeSwap. Reverts with NotAgent, WrongStatus, PastDeadline, or BadTask.

claimFailure#

solidity
function claimFailure(uint256 id) external

Settles an Active task after its deadline. Anyone can call it. Refunds the user, pays the compensation from the bond, and updates the record. Reverts with WrongStatus or NotPastDeadline.

Views#

FunctionReturns
agent(address key)The Agent struct
task(uint256 id)The Task struct
isRouter(address router)Whether the router is allowed
taskCount()The number of tasks, and the latest id. Ids start at 1
bondToken()The token used for bonds, fees, and compensation