Skip to content

Reference

Smart contract reference

DeleqMandateGuard: address, verification, every function, event, error and reason bit, gas and invariants.

#Deployment

ContractDeleqMandateGuard (with the internal library DeleqLimitMath, inlined)
NetworkRobinhood Chain, chain id 4663
Address0x57dd851d840b1f0a2896dc1524c398c4574ff3c1
Creationblock 122,213,192 · 0xc7cad03d8f45fef6cc0833d85bcb90bfa167b3d8b76cef4a5cfb89aaa17de403
VerificationBlockscout (verified source) · Sourcify (exact match, creation and runtime)
Compilersolc 0.8.28, optimizer 200 runs, EVM paris, no via-IR, no metadata hash
Admin, fee, upgradeNone. No constructor arguments, no payable function, no receive().

Check that the address runs exactly this repository's build:

shell
npm run verify-deployment -- --guard 0x57dd851d840b1f0a2896dc1524c398c4574ff3c1 --guard-tx 0xc7cad03d8f45fef6cc0833d85bcb90bfa167b3d8b76cef4a5cfb89aaa17de403
# prints MATCH when the runtime code and the creation input equal this build

#Types

solidity
struct MandateInit {
    address agent;
    uint64 validFrom;          // 0 = now
    uint64 expiry;
    uint32 maxActionsPerDay;   // 0 = no count limit
    bytes32 label;
    TokenInit[] tokens;        // { address token; uint128 perTxCap; uint128 dailyCap; }
    address[] recipients;
    address[] routers;
}

struct SwapOrder {
    address router;
    address tokenIn;
    address tokenOut;
    uint24 fee;                // Uniswap v3 fee tier
    uint256 amountIn;
    uint256 minOut;            // must be > 0
    bytes32 ref;               // free reference, only logged
}

These match the tuples in the signatures below, which are generated from the compiled ABI (selectors included). getMandate returns Mandate: owner, agent, validFrom, expiry, maxActionsPerDay, version, paused, revoked, label, createdAt, actions.

#Write functions

#agentPause0xaf82695dnonpayable

function agentPause(uint256 id) external
Who may call
Agent of the mandate
Effect
The agent's own kill switch: pauses the mandate. Only the owner can unpause.
Emits
Paused
Reverts with
NotAgent, AlreadyRevoked

#createMandate0x52e7a162nonpayable

function createMandate((address agent, uint64 validFrom, uint64 expiry, uint32 maxActionsPerDay, bytes32 label, (address token, uint128 perTxCap, uint128 dailyCap)[] tokens, address[] recipients, address[] routers) init) external returns (uint256 id)
Who may call
Anyone (the caller becomes the owner)
Effect
Creates a mandate for init.agent with tokens and caps, recipients, routers, window (validFrom 0 = now), actions per day and a label. Returns the new id.
Emits
MandateCreated, then TokenRuleSet / RecipientSet / RouterSet per entry
Reverts with
BadAgent (zero, the caller or the guard), BadWindow, BadCaps (perTx > daily), BadAddress (no code, zero, owner as recipient), TooMany (16 tokens, 32 recipients, 4 routers, 64 mandates per owner)

#executeSwapV30xe83c1ff4nonpayable

function executeSwapV3(uint256 id, (address router, address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint256 minOut, bytes32 ref) o) external returns (uint64 actionNo, uint256 amountOut)
Who may call
Agent of the mandate
Effect
Pulls amountIn from the owner, approves exactly that to an allowlisted SwapRouter02-compatible router, calls exactInputSingle with recipient = owner, measures what the owner received, resets the approval to 0 and reverts if anything is left in the guard.
Emits
SwapExecuted
Reverts with
Rejected(reasons), Reentrancy, TokenCallFailed, FeeOnTransferNotSupported, SwapShortfall, LeftoverBalance (and the router's own revert)

#executeTransfer0x4b52dbefnonpayable

function executeTransfer(uint256 id, address token, address to, uint256 amount, bytes32 ref) external returns (uint64 actionNo)
Who may call
Agent of the mandate
Effect
Moves amount of token from the owner to an allowlisted recipient with transferFrom, after the same checks as checkTransfer. The recipient must receive exactly amount. ref is only logged.
Emits
TransferExecuted
Reverts with
Rejected(reasons), Reentrancy, TokenCallFailed, FeeOnTransferNotSupported

#pause0x136439ddnonpayable

function pause(uint256 id) external
Who may call
Owner of the mandate
Effect
Stops every execute from the next call on. No-op when already paused.
Emits
Paused
Reverts with
NotOwner, AlreadyRevoked

#revoke0x20c5429bnonpayable

function revoke(uint256 id) external
Who may call
Owner of the mandate
Effect
Ends the mandate for good. Nothing can execute or change under it afterwards.
Emits
Revoked
Reverts with
NotOwner, AlreadyRevoked

#setMaxActionsPerDay0x574cefb3nonpayable

function setMaxActionsPerDay(uint256 id, uint32 maxActionsPerDay) external
Who may call
Owner of the mandate
Effect
Sets the number of actions per UTC day (0 = no count limit).
Emits
MaxActionsSet
Reverts with
NotOwner, AlreadyRevoked

#setRecipient0xfeab4914nonpayable

function setRecipient(uint256 id, address recipient, bool allowed) external
Who may call
Owner of the mandate
Effect
Allows or removes a recipient.
Emits
RecipientSet
Reverts with
NotOwner, AlreadyRevoked, BadAddress, TooMany

#setRouter0x45d97a5cnonpayable

function setRouter(uint256 id, address router, bool allowed) external
Who may call
Owner of the mandate
Effect
Allows or removes a swap router (must have code).
Emits
RouterSet
Reverts with
NotOwner, AlreadyRevoked, BadAddress, TooMany

#setTokenRule0xd0eca727nonpayable

function setTokenRule(uint256 id, address token, uint128 perTxCap, uint128 dailyCap, bool listed) external
Who may call
Owner of the mandate
Effect
Adds, changes or removes (listed = false, caps 0) a token rule.
Emits
TokenRuleSet
Reverts with
NotOwner, AlreadyRevoked, BadAddress, BadCaps, TooMany

#setWindow0xd3825590nonpayable

function setWindow(uint256 id, uint64 validFrom, uint64 expiry) external
Who may call
Owner of the mandate
Effect
Changes validFrom and expiry (expiry in the future, at most 730 days after validFrom).
Emits
WindowSet
Reverts with
NotOwner, AlreadyRevoked, BadWindow

#unpause0xfabc1cbcnonpayable

function unpause(uint256 id) external
Who may call
Owner of the mandate
Effect
Lifts a pause (the owner's or the agent's).
Emits
Unpaused
Reverts with
NotOwner, AlreadyRevoked

#Read functions

#MAX_DURATION0xb1724b46view

function MAX_DURATION() external view returns (uint256)
Who may call
Constant
Effect
730 days from validFrom to expiry.

#MAX_MANDATES_PER_OWNER0x89de33d6view

function MAX_MANDATES_PER_OWNER() external view returns (uint256)
Who may call
Constant
Effect
64 mandates per owner address, revoked ones included.

#MAX_RECIPIENTS0xa6980ce2view

function MAX_RECIPIENTS() external view returns (uint256)
Who may call
Constant
Effect
32 recipients per mandate.

#MAX_ROUTERS0xb769625aview

function MAX_ROUTERS() external view returns (uint256)
Who may call
Constant
Effect
4 routers per mandate.

#MAX_TOKENS0xf47c84c5view

function MAX_TOKENS() external view returns (uint256)
Who may call
Constant
Effect
16 tokens per mandate.

#actionsToday0x1ab593f3view

function actionsToday(uint256 id) external view returns (uint32 used, uint32 limit)
Who may call
Anyone (view)
Effect
Actions executed today and the per-day limit (0 = none).

#checkSwap0x5dd22f5aview

function checkSwap(uint256 id, address caller, (address router, address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint256 minOut, bytes32 ref) o) external view returns (uint256)
Who may call
Anyone (view)
Effect
Reason bits executeSwapV3 would fail with right now if sent by caller.

#checkTransfer0x83e8161dview

function checkTransfer(uint256 id, address caller, address token, address to, uint256 amount) external view returns (uint256)
Who may call
Anyone (view)
Effect
Reason bits executeTransfer would fail with right now if sent by caller. 0 = it would pass the guard.

#getMandate0xa8e64c8aview

function getMandate(uint256 id) external view returns ((address owner, address agent, uint64 validFrom, uint64 expiry, uint32 maxActionsPerDay, uint32 version, bool paused, bool revoked, bytes32 label, uint64 createdAt, uint64 actions))
Who may call
Anyone (view)
Effect
The Mandate struct (owner, agent, window, maxActionsPerDay, version, paused, revoked, label, createdAt, actions).

#isRecipient0x4ace9440view

function isRecipient(uint256 id, address who) external view returns (bool)
Who may call
Anyone (view)
Effect
Whether an address is an allowed recipient.

#isRouter0x4658367aview

function isRouter(uint256 id, address who) external view returns (bool)
Who may call
Anyone (view)
Effect
Whether an address is an allowed router.

#mandateCount0x60b5662eview

function mandateCount() external view returns (uint256)
Who may call
Anyone (view)
Effect
Number of mandates ever created (ids start at 1).

#mandatesOfAgent0x6ece7d0eview

function mandatesOfAgent(address agent) external view returns (uint256[])
Who may call
Anyone (view)
Effect
Ids of every mandate naming an agent.

#mandatesOfOwner0x23258670view

function mandatesOfOwner(address owner_) external view returns (uint256[])
Who may call
Anyone (view)
Effect
Ids of every mandate an owner created (revoked ones included).

#recipientsOf0xbbc57cf1view

function recipientsOf(uint256 id) external view returns (address[])
Who may call
Anyone (view)
Effect
Allowed recipients of a mandate.

#routersOf0xe6fe6502view

function routersOf(uint256 id) external view returns (address[])
Who may call
Anyone (view)
Effect
Allowed routers of a mandate.

#spentToday0xe7312bf3view

function spentToday(uint256 id, address token) external view returns (uint256 spent, uint256 left)
Who may call
Anyone (view)
Effect
Spent on the current UTC day and what is left under the daily cap, for one token.

#tokenRule0x58882317view

function tokenRule(uint256 id, address token) external view returns ((uint128 perTxCap, uint128 dailyCap, bool listed))
Who may call
Anyone (view)
Effect
perTxCap, dailyCap and listed for one token.

#tokensOf0xa2eb8927view

function tokensOf(uint256 id) external view returns (address[])
Who may call
Anyone (view)
Effect
Listed tokens of a mandate.

#Events

MandateCreated

event MandateCreated(uint256 indexed id, address indexed owner, address indexed agent, uint64 validFrom, uint64 expiry, uint32 maxActionsPerDay, bytes32 label)

A mandate was created. Indexed by id, owner and agent.

topic0 0x29ca54c1af18312e33e59442d9c5e0911218e39eaabbed737940398dce6f945b

MaxActionsSet

event MaxActionsSet(uint256 indexed id, uint32 maxActionsPerDay, uint32 version)

The actions-per-day limit changed.

topic0 0x241892570e24420445cb1481bd577dd4eecda8eb10f74083a52a40c7998bf1d4

Paused

event Paused(uint256 indexed id, address indexed by)

Paused by the owner or the agent (by).

topic0 0xabdb1c9133626eb4f8c5f2ec7e3c60a969a2fb148a0c341a3cf6597242c8f8f5

RecipientSet

event RecipientSet(uint256 indexed id, address indexed recipient, bool allowed, uint32 version)

A recipient was allowed or removed.

topic0 0x87448bbcdebcd4a4942635fb8cb1e9c6c2064d4063c58be02e5df58d0f75e62d

Revoked

event Revoked(uint256 indexed id)

The mandate ended for good.

topic0 0x61e27b0bfd8e18e6b92ec32ce1c28bb698d27bfe93e84c7e94d4db0a3135c760

RouterSet

event RouterSet(uint256 indexed id, address indexed router, bool allowed, uint32 version)

A router was allowed or removed.

topic0 0xe33eb114824a5593990001c3eb186c2ab05896f10b065526b1668fad643364ee

SwapExecuted

event SwapExecuted(uint256 indexed id, uint64 indexed actionNo, address indexed agent, address router, address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint256 amountOut, uint64 day, uint256 spentToday, bytes32 ref)

An agent swap. amountOut is what the owner actually received (measured, not the router's return value).

topic0 0x0cb56b23aacc0dae4c79abbee249fdc14e54c6666d81797d9a3200507b3737d2

TokenRuleSet

event TokenRuleSet(uint256 indexed id, address indexed token, uint128 perTxCap, uint128 dailyCap, bool listed, uint32 version)

A token rule was added, changed or removed; version is the mandate's version after the change.

topic0 0x57d501fae8b2b5cfe682feb1f32c521720c2d4f2f0c0a6061145208a9ae262da

TransferExecuted

event TransferExecuted(uint256 indexed id, uint64 indexed actionNo, address indexed agent, address token, address to, uint256 amount, uint64 day, uint256 spentToday, bytes32 ref)

An agent payment. actionNo counts the mandate's actions, day is the UTC day, spentToday includes this amount. Everything a receipt needs.

topic0 0xbdb072e4a2934f54b2476b814a82c6bf9a0cef25fbd13403ba2e13bcbf162fba

Unpaused

event Unpaused(uint256 indexed id)

The owner lifted a pause.

topic0 0x9dd715fed52c25e642f97653bb4c4339ad98fe6d6e130348be82ae5d86383a8c

WindowSet

event WindowSet(uint256 indexed id, uint64 validFrom, uint64 expiry, uint32 version)

The validity window changed.

topic0 0x9b9506a8863e0438e14810f795287e3817fdba062464319c986086a8c2095804

#Errors

ErrorWhen
AlreadyRevoked()The mandate is revoked.
BadAddress()Zero address, the guard, the owner as recipient, or a token/router without code.
BadAgent()Agent is zero, the owner, or the guard.
BadCaps()perTxCap above dailyCap, or caps on a removed token.
BadWindow()Expiry not after validFrom, not in the future, or more than 730 days after validFrom.
FeeOnTransferNotSupported(uint256 sent, uint256 received)The receiver got a different amount than was sent.
LeftoverBalance(address token, uint256 leftover)The router did not take the whole amountIn.
NotAgent()The caller is not the mandate's agent (agentPause).
NotOwner()The caller is not the mandate's owner (or the mandate does not exist).
Reentrancy()A token or router called back into an execute.
Rejected(uint256 reasons)An execute failed the checks; reasons is the same bitmask checkTransfer / checkSwap return.
SwapShortfall(uint256 received, uint256 minOut)The owner received less than minOut.
TokenCallFailed(address token)The token reverted, returned false, or did not answer balanceOf.
TooMany()A list or the per-owner mandate limit is full.

#Reason bits

Order of evaluation: unknown mandate (stops), revoked, paused, not started, expired, not the agent, daily action count; then for a payment the recipient, for a swap the router, same token, output token listed and minimum output; then the spent token: listed, zero amount, per-tx cap, daily cap, and the owner's allowance and balance (read with staticcall; a token that does not answer sets TOKEN_UNREADABLE). Several bits can be set at once.

BitNameShown asMeaning
0UNKNOWN_MANDATEUnknown mandateThere is no mandate with this number.
1REVOKEDRevokedThe owner revoked this mandate. Nothing can run under it again.
2PAUSEDPausedThe mandate is paused by the owner (or by the agent itself).
3NOT_STARTEDNot startedThe mandate's start time has not been reached.
4EXPIREDExpiredThe mandate's end time has passed.
5NOT_AGENTNot the agentOnly the agent address named in the mandate can act under it.
6ZERO_AMOUNTZero amountThe amount is zero.
7TOKEN_NOT_ALLOWEDToken not allowedThe mandate does not list this token for spending.
8RECIPIENT_NOT_ALLOWEDRecipient not allowedThe recipient is not on the mandate's allowlist.
9OVER_PER_TXOver per-tx capThe amount is above the per-transaction cap for this token.
10OVER_DAILYOver daily capToday's spend plus this amount would pass the daily cap (UTC day).
11DAILY_COUNTDaily action limitThe mandate's number of actions per UTC day is used up.
12ROUTER_NOT_ALLOWEDRouter not allowedThe swap router is not on the mandate's allowlist.
13TOKEN_OUT_NOT_ALLOWEDOutput token not allowedThe token the swap would buy is not listed in the mandate.
14LOW_ALLOWANCEAllowance too lowThe owner's ERC-20 allowance to the guard is below the amount.
15LOW_BALANCEBalance too lowThe owner's wallet holds less than the amount.
16NO_MIN_OUTNo minimum outputA swap needs a minimum output above zero.
17SAME_TOKENSame tokenThe swap sells and buys the same token.
18TOKEN_UNREADABLEToken unreadableThe token did not answer balanceOf / allowance like an ERC-20.

#Gas

CallGasNote
deployment2,955,030mainnet creation transaction (forge estimate 2,954,194); runtime 13,365 bytes
createMandate638,8242 tokens, 1 recipient, 1 router
executeTransfer57,434median; up to 167,905 on a first spend of the day with cold storage
executeSwapV3250,572median with the test router; 240–280 k on the Robinhood Chain fork with SwapRouter02
checkTransfer30,422view (free through eth_call)
checkSwap33,562view
pause / unpause / revoke≈ 31,000state change
setRecipient104,815adding a new recipient
setTokenRule≈ 28,600–48,500change / add

Gas is paid in ETH; at the gas prices seen on Robinhood Chain on 24 Nov 2026 (about 0.02 gwei) these are tiny amounts.

#Invariants

Checked by an invariant suite (random owners, agents, strangers, pauses and time jumps across UTC days, 64 runs × 48 calls) and by unit and fork tests:

  • The guard holds no token balance and no router allowance between transactions.
  • No UTC day ever moves more than the daily cap of a token.
  • Nothing moves while the mandate is paused, and nobody but the agent ever moves anything.
  • Owner funds only leave to an allowlisted recipient or into a swap whose output returns to the owner.

#DeleqLimitMath

An internal library (inlined into the guard): the reason-bit constants (R_UNKNOWN_MANDATE … R_TOKEN_UNREADABLE), dayOf(ts) (timestamp / 86,400), spentOn (a stale day reads as 0), amountBits, stateBits, countBits and remaining. The site's TypeScript engine mirrors it; a unit test reads the bit positions from the Solidity file.