AllowanceTransfer

Git Source

Inherits: IAllowanceTransfer, EIP712

State Variables

allowance

Maps users to tokens to spender addresses and information about the approval on the token

Indexed in the order of token owner address, token address, spender address

The stored word saves the allowed amount, expiration on the allowance, and nonce

mapping(address => mapping(address => mapping(address => PackedAllowance))) public allowance;

Functions

approve

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

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

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

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

function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;

Parameters

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

permit

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

function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;

Parameters

NameTypeDescription
owneraddressThe owner of the tokens being approved
permitBatchPermitBatch
signaturebytesThe owner's signature over the permit data

transferFrom

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.

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

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

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.

function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;

Parameters

NameTypeDescription
transferDetailsAllowanceTransferDetails[]

_transfer

Internal function for transferring tokens using stored allowances

Will fail if the allowed timeframe has passed

function _transfer(address from, address to, uint160 amount, address token) private;

lockdown

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

function lockdown(TokenSpenderPair[] calldata approvals) external;

Parameters

NameTypeDescription
approvalsTokenSpenderPair[]Array of approvals to revoke.

invalidateNonces

Invalidate nonces for a given (token, spender) pair

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

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

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.

_updateApproval

Sets the new values for amount, expiration, and nonce.

Will check that the signed nonce is equal to the current nonce and then incrememnt the nonce value by 1.

Emits a Permit event.

function _updateApproval(PermitDetails memory details, address owner, address spender) private;