IAllowanceTransfer

Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts

Requires user's token approval on the Permit2 contract from https://github.com/Uniswap/permit2/blob/main/src/interfaces/ISignatureTransfer.sol. Copyright (c) 2022 Uniswap Labs

DOMAIN_SEPARATOR

function DOMAIN_SEPARATOR() external view returns (bytes32)

AllowanceExpired

error AllowanceExpired(uint256 deadline)

Thrown when an allowance on a token has expired.

Parameters

NameTypeDescription
deadlineuint256The timestamp at which the allowed amount is no longer valid

InsufficientAllowance

error InsufficientAllowance(uint256 amount)

Thrown when an allowance on a token has been depleted.

Parameters

NameTypeDescription
amountuint256The maximum amount allowed

ExcessiveInvalidation

error ExcessiveInvalidation()

Thrown when too many nonces are invalidated.

NonceInvalidation

event NonceInvalidation(address owner, address token, address spender, uint48 newNonce, uint48 oldNonce)

Emits an event when the owner successfully invalidates an ordered nonce.

Approval

event Approval(address owner, address token, address spender, uint160 amount, uint48 expiration)

Emits an event when the owner successfully sets permissions on a token for the spender.

Permit

event Permit(address owner, address token, address spender, uint160 amount, uint48 expiration, uint48 nonce)

Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.

Lockdown

event Lockdown(address owner, address token, address spender)

Emits an event when the owner sets the allowance back to 0 with the lockdown function.

PermitDetails

The permit data for a token

struct PermitDetails {
  address token;
  uint160 amount;
  uint48 expiration;
  uint48 nonce;
}

PermitSingle

The permit message signed for a single token allownce

struct PermitSingle {
  struct IAllowanceTransfer.PermitDetails details;
  address spender;
  uint256 sigDeadline;
}

PermitBatch

The permit message signed for multiple token allowances

struct PermitBatch {
  struct IAllowanceTransfer.PermitDetails[] details;
  address spender;
  uint256 sigDeadline;
}

PackedAllowance

The saved permissions

This info is saved per owner, per token, per spender and all signed over in the permit message Setting amount to type(uint160).max sets an unlimited approval

struct PackedAllowance {
  uint160 amount;
  uint48 expiration;
  uint48 nonce;
}

TokenSpenderPair

A token spender pair.

struct TokenSpenderPair {
  address token;
  address spender;
}

AllowanceTransferDetails

Details for a token transfer.

struct AllowanceTransferDetails {
  address from;
  address to;
  uint160 amount;
  address token;
}

allowance

function allowance(address user, address token, address spender) external view returns (uint160 amount, uint48 expiration, uint48 nonce)

A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval. The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress]spenderAddress

The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.

approve

function approve(address token, address spender, uint160 amount, uint48 expiration) external

Approves the spender to use up to amount of the specified token up until the expiration

The packed allowance also holds a nonce, which will stay unchanged in approve Setting amount to type(uint160).max sets an unlimited approval

Parameters

NameTypeDescription
tokenaddressThe token to approve
spenderaddressThe spender address to approve
amountuint160The approved amount of the token
expirationuint48The timestamp at which the approval is no longer valid

permit

function permit(address owner, struct IAllowanceTransfer.PermitSingle permitSingle, bytes signature) external

Permit a spender to a given amount of the owners token via the owner's EIP-712 signature

May fail if the owner's nonce was invalidated in-flight by invalidateNonce

Parameters

NameTypeDescription
owneraddressThe owner of the tokens being approved
permitSinglestruct IAllowanceTransfer.PermitSingleData signed over by the owner specifying the terms of approval
signaturebytesThe owner's signature over the permit data

permit

function permit(address owner, struct IAllowanceTransfer.PermitBatch permitBatch, bytes signature) external

Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature

May fail if the owner's nonce was invalidated in-flight by invalidateNonce

Parameters

NameTypeDescription
owneraddressThe owner of the tokens being approved
permitBatchstruct IAllowanceTransfer.PermitBatchData signed over by the owner specifying the terms of approval
signaturebytesThe owner's signature over the permit data

transferFrom

function transferFrom(address from, address to, uint160 amount, address token) external

Transfer approved tokens from one address to another

Requires the from address to have approved at least the desired amount of tokens to msg.sender.

Parameters

NameTypeDescription
fromaddressThe address to transfer from
toaddressThe address of the recipient
amountuint160The amount of the token to transfer
tokenaddressThe token address to transfer

transferFrom

function transferFrom(struct IAllowanceTransfer.AllowanceTransferDetails[] transferDetails) external

Transfer approved tokens in a batch

Requires the from addresses to have approved at least the desired amount of tokens to msg.sender.

Parameters

NameTypeDescription
transferDetailsstruct IAllowanceTransfer.AllowanceTransferDetailsArray of owners, recipients, amounts, and tokens for the transfers

lockdown

function lockdown(struct IAllowanceTransfer.TokenSpenderPair[] approvals) external

Enables performing a "lockdown" of the sender's Permit2 identity by batch revoking approvals

Parameters

NameTypeDescription
approvalsstruct IAllowanceTransfer.TokenSpenderPairArray of approvals to revoke.

invalidateNonces

function invalidateNonces(address token, address spender, uint48 newNonce) external

Invalidate nonces for a given (token, spender) pair

Can't invalidate more than 2**16 nonces per transaction.

Parameters

NameTypeDescription
tokenaddressThe token to invalidate nonces for
spenderaddressThe spender to invalidate nonces for
newNonceuint48The new nonce to set. Invalidates all nonces less than it.