Skip to main content

SelfPermit.sol

Read code on GitHub

Functionality to call permit on any EIP-2612-compliant token

Details

These functions are expected to be embedded in multicalls to allow EOAs to approve a contract and call a function that requires an approval in a single transaction

Methods

selfPermit

Permits this contract to spend a given token from msg.sender

Solidity
function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this)

Parameters

NameTypeDescription
tokenaddressAddress of the token spent
valueuint256Amount that can be spent of token
deadlineuint256A timestamp, the current blocktime must be less than or equal to this timestamp
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

selfPermitAllowed

Permits this contract to spend the sender's tokens for permit signatures that have the allowed parameter

Solidity
function selfPermitAllowed(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this)

Parameters

NameTypeDescription
tokenaddressAddress of the token spent
nonceuint256Current nonce of the owner
expiryuint256Timestamp at which the permit is no longer valid
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

selfPermitAllowedIfNecessary

Permits this contract to spend the sender's tokens for permit signatures that have the allowed parameter

Solidity
function selfPermitAllowedIfNecessary(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this) Can be used instead of #selfPermitAllowed to prevent calls from failing due to a frontrun of a call to #selfPermitAllowed

Parameters

NameTypeDescription
tokenaddressAddress of the token spent
nonceuint256Current nonce of the owner
expiryuint256Timestamp at which the permit is no longer valid
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v

selfPermitIfNecessary

Permits this contract to spend a given token from msg.sender

Solidity
function selfPermitIfNecessary(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable
Details

owner is always msg.sender and the spender is always address(this) Can be used instead of #selfPermit to prevent calls from failing due to a frontrun of a call to #selfPermit

Parameters

NameTypeDescription
tokenaddressAddress of the token spent
valueuint256Amount that can be spent of token
deadlineuint256A timestamp, the current blocktime must be less than or equal to this timestamp
vuint8Must produce valid secp256k1 signature from the holder along with r and s
rbytes32Must produce valid secp256k1 signature from the holder along with v and s
sbytes32Must produce valid secp256k1 signature from the holder along with r and v