Permit2Lib

Git Source

Enables efficient transfers and EIP-2612/DAI permits for any token by falling back to Permit2.

State Variables

DAI_DOMAIN_SEPARATOR

The unique EIP-712 domain domain separator for the DAI token contract.

bytes32 internal constant DAI_DOMAIN_SEPARATOR = 0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;

WETH9_ADDRESS

The address for the WETH9 contract on Ethereum mainnet, encoded as a bytes32.

bytes32 internal constant WETH9_ADDRESS = 0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2;

PERMIT2

The address of the Permit2 contract the library will use.

IAllowanceTransfer internal constant PERMIT2 = IAllowanceTransfer(address(0x000000000022D473030F116dDEE9F6B43aC78BA3));

Functions

transferFrom2

Transfer a given amount of tokens from one user to another.

function transferFrom2(IERC20 token, address from, address to, uint256 amount) internal;

Parameters

NameTypeDescription
tokenIERC20The token to transfer.
fromaddressThe user to transfer from.
toaddressThe user to transfer to.
amountuint256The amount to transfer.

permit2

Permit a user to spend a given amount of another user's tokens via native EIP-2612 permit if possible, falling back to Permit2 if native permit fails or is not implemented on the token.

function permit2(
    IERC20 token,
    address owner,
    address spender,
    uint256 amount,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
)
    internal;

Parameters

NameTypeDescription
tokenIERC20The token to permit spending.
owneraddressThe user to permit spending from.
spenderaddressThe user to permit spending to.
amountuint256The amount to permit spending.
deadlineuint256The timestamp after which the signature is no longer valid.
vuint8Must produce valid secp256k1 signature from the owner along with r and s.
rbytes32Must produce valid secp256k1 signature from the owner along with v and s.
sbytes32Must produce valid secp256k1 signature from the owner along with r and v.

simplePermit2

Simple unlimited permit on the Permit2 contract.

function simplePermit2(
    IERC20 token,
    address owner,
    address spender,
    uint256 amount,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
)
    internal;

Parameters

NameTypeDescription
tokenIERC20The token to permit spending.
owneraddressThe user to permit spending from.
spenderaddressThe user to permit spending to.
amountuint256The amount to permit spending.
deadlineuint256The timestamp after which the signature is no longer valid.
vuint8Must produce valid secp256k1 signature from the owner along with r and s.
rbytes32Must produce valid secp256k1 signature from the owner along with v and s.
sbytes32Must produce valid secp256k1 signature from the owner along with r and v.