136 lines
6.8 KiB
Solidity
136 lines
6.8 KiB
Solidity
|
// SPDX-License-Identifier: MIT
|
||
|
// Copied from https://github.com/Uniswap/permit2/blob/main/src/interfaces/ISignatureTransfer.sol
|
||
|
|
||
|
pragma solidity ^0.8.20;
|
||
|
|
||
|
/// @title SignatureTransfer
|
||
|
/// @notice Handles ERC20 token transfers through signature based actions
|
||
|
/// @dev Requires user's token approval on the Permit2 contract
|
||
|
interface ISignatureTransfer {
|
||
|
/// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
|
||
|
/// @param maxAmount The maximum amount a spender can request to transfer
|
||
|
error InvalidAmount(uint256 maxAmount);
|
||
|
|
||
|
/// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
|
||
|
/// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
|
||
|
error LengthMismatch();
|
||
|
|
||
|
/// @notice Emits an event when the owner successfully invalidates an unordered nonce.
|
||
|
event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);
|
||
|
|
||
|
/// @notice The token and amount details for a transfer signed in the permit transfer signature
|
||
|
struct TokenPermissions {
|
||
|
// ERC20 token address
|
||
|
address token;
|
||
|
// the maximum amount that can be spent
|
||
|
uint256 amount;
|
||
|
}
|
||
|
|
||
|
/// @notice The signed permit message for a single token transfer
|
||
|
struct PermitTransferFrom {
|
||
|
TokenPermissions permitted;
|
||
|
// a unique value for every token owner's signature to prevent signature replays
|
||
|
uint256 nonce;
|
||
|
// deadline on the permit signature
|
||
|
uint256 deadline;
|
||
|
}
|
||
|
|
||
|
/// @notice Specifies the recipient address and amount for batched transfers.
|
||
|
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
|
||
|
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
|
||
|
struct SignatureTransferDetails {
|
||
|
// recipient address
|
||
|
address to;
|
||
|
// spender requested amount
|
||
|
uint256 requestedAmount;
|
||
|
}
|
||
|
|
||
|
/// @notice Used to reconstruct the signed permit message for multiple token transfers
|
||
|
/// @dev Do not need to pass in spender address as it is required that it is msg.sender
|
||
|
/// @dev Note that a user still signs over a spender address
|
||
|
struct PermitBatchTransferFrom {
|
||
|
// the tokens and corresponding amounts permitted for a transfer
|
||
|
TokenPermissions[] permitted;
|
||
|
// a unique value for every token owner's signature to prevent signature replays
|
||
|
uint256 nonce;
|
||
|
// deadline on the permit signature
|
||
|
uint256 deadline;
|
||
|
}
|
||
|
|
||
|
function DOMAIN_SEPARATOR() external view returns (bytes32);
|
||
|
|
||
|
/// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
|
||
|
/// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
|
||
|
/// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
|
||
|
/// @dev It returns a uint256 bitmap
|
||
|
/// @dev The index, or wordPosition is capped at type(uint248).max
|
||
|
function nonceBitmap(address, uint256) external view returns (uint256);
|
||
|
|
||
|
/// @notice Transfers a token using a signed permit message
|
||
|
/// @dev Reverts if the requested amount is greater than the permitted signed amount
|
||
|
/// @param permit The permit data signed over by the owner
|
||
|
/// @param owner The owner of the tokens to transfer
|
||
|
/// @param transferDetails The spender's requested transfer details for the permitted token
|
||
|
/// @param signature The signature to verify
|
||
|
function permitTransferFrom(
|
||
|
PermitTransferFrom memory permit,
|
||
|
SignatureTransferDetails calldata transferDetails,
|
||
|
address owner,
|
||
|
bytes calldata signature
|
||
|
) external;
|
||
|
|
||
|
/// @notice Transfers a token using a signed permit message
|
||
|
/// @notice Includes extra data provided by the caller to verify signature over
|
||
|
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
|
||
|
/// @dev Reverts if the requested amount is greater than the permitted signed amount
|
||
|
/// @param permit The permit data signed over by the owner
|
||
|
/// @param owner The owner of the tokens to transfer
|
||
|
/// @param transferDetails The spender's requested transfer details for the permitted token
|
||
|
/// @param witness Extra data to include when checking the user signature
|
||
|
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
|
||
|
/// @param signature The signature to verify
|
||
|
function permitWitnessTransferFrom(
|
||
|
PermitTransferFrom memory permit,
|
||
|
SignatureTransferDetails calldata transferDetails,
|
||
|
address owner,
|
||
|
bytes32 witness,
|
||
|
string calldata witnessTypeString,
|
||
|
bytes calldata signature
|
||
|
) external;
|
||
|
|
||
|
/// @notice Transfers multiple tokens using a signed permit message
|
||
|
/// @param permit The permit data signed over by the owner
|
||
|
/// @param owner The owner of the tokens to transfer
|
||
|
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
|
||
|
/// @param signature The signature to verify
|
||
|
function permitTransferFrom(
|
||
|
PermitBatchTransferFrom memory permit,
|
||
|
SignatureTransferDetails[] calldata transferDetails,
|
||
|
address owner,
|
||
|
bytes calldata signature
|
||
|
) external;
|
||
|
|
||
|
/// @notice Transfers multiple tokens using a signed permit message
|
||
|
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
|
||
|
/// @notice Includes extra data provided by the caller to verify signature over
|
||
|
/// @param permit The permit data signed over by the owner
|
||
|
/// @param owner The owner of the tokens to transfer
|
||
|
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
|
||
|
/// @param witness Extra data to include when checking the user signature
|
||
|
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
|
||
|
/// @param signature The signature to verify
|
||
|
function permitWitnessTransferFrom(
|
||
|
PermitBatchTransferFrom memory permit,
|
||
|
SignatureTransferDetails[] calldata transferDetails,
|
||
|
address owner,
|
||
|
bytes32 witness,
|
||
|
string calldata witnessTypeString,
|
||
|
bytes calldata signature
|
||
|
) external;
|
||
|
|
||
|
/// @notice Invalidates the bits specified in mask for the bitmap at the word position
|
||
|
/// @dev The wordPos is maxed at type(uint248).max
|
||
|
/// @param wordPos A number to index the nonceBitmap at
|
||
|
/// @param mask A bitmap masked against msg.sender's current bitmap at the word position
|
||
|
function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
|
||
|
}
|