Skip to content

Commit

Permalink
add tests, interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lorbke committed Nov 16, 2024
1 parent 4b54250 commit 9d78201
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 62 deletions.
64 changes: 3 additions & 61 deletions packages/foundry/contracts/Permit2Vault.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import "../interfaces/IPermit2.sol";
import "../interfaces/IERC20.sol";

// Trivial vault that allows users to deposit ERC20 tokens then claim them later.
contract Permit2Vault {
bool private _reentrancyGuard;
Expand Down Expand Up @@ -115,65 +118,4 @@ contract Permit2Vault {
permissions[i] = IPermit2.TokenPermissions({ token: tokens[i], amount: amounts[i] });
}
}
}

// Minimal Permit2 interface, derived from
// https://github.com/Uniswap/permit2/blob/main/src/interfaces/ISignatureTransfer.sol
interface IPermit2 {
// Token and amount in a permit message.
struct TokenPermissions {
// Token to transfer.
IERC20 token;
// Amount to transfer.
uint256 amount;
}

// The permit2 message.
struct PermitTransferFrom {
// Permitted token and maximum amount.
TokenPermissions permitted;// deadline on the permit signature
// Unique identifier for this permit.
uint256 nonce;
// Expiration for this permit.
uint256 deadline;
}

// The permit2 message for batch transfers.
struct PermitBatchTransferFrom {
// Permitted tokens and maximum amounts.
TokenPermissions[] permitted;
// Unique identifier for this permit.
uint256 nonce;
// Expiration for this permit.
uint256 deadline;
}

// Transfer details for permitTransferFrom().
struct SignatureTransferDetails {
// Recipient of tokens.
address to;
// Amount to transfer.
uint256 requestedAmount;
}

// Consume a permit2 message and transfer tokens.
function permitTransferFrom(
PermitTransferFrom calldata permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;

// Consume a batch permit2 message and transfer tokens.
function permitTransferFrom(
PermitBatchTransferFrom calldata permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
}

// Minimal ERC20 interface.
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
7 changes: 7 additions & 0 deletions packages/foundry/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

// Minimal ERC20 interface.
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
60 changes: 60 additions & 0 deletions packages/foundry/interfaces/IPermit2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import "./IERC20.sol";

// Minimal Permit2 interface, derived from
// https://github.com/Uniswap/permit2/blob/main/src/interfaces/ISignatureTransfer.sol
interface IPermit2 {
// Token and amount in a permit message.
struct TokenPermissions {
// Token to transfer.
IERC20 token;
// Amount to transfer.
uint256 amount;
}

// The permit2 message.
struct PermitTransferFrom {
// Permitted token and maximum amount.
TokenPermissions permitted;// deadline on the permit signature
// Unique identifier for this permit.
uint256 nonce;
// Expiration for this permit.
uint256 deadline;
}

// The permit2 message for batch transfers.
struct PermitBatchTransferFrom {
// Permitted tokens and maximum amounts.
TokenPermissions[] permitted;
// Unique identifier for this permit.
uint256 nonce;
// Expiration for this permit.
uint256 deadline;
}

// Transfer details for permitTransferFrom().
struct SignatureTransferDetails {
// Recipient of tokens.
address to;
// Amount to transfer.
uint256 requestedAmount;
}

// Consume a permit2 message and transfer tokens.
function permitTransferFrom(
PermitTransferFrom calldata permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;

// Consume a batch permit2 message and transfer tokens.
function permitTransferFrom(
PermitBatchTransferFrom calldata permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
}
2 changes: 1 addition & 1 deletion packages/foundry/test/Permit2Vault.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import "solmate/tokens/ERC20.sol";
import "../lib/solmate/src/tokens/ERC20.sol";
import "../contracts/Permit2Vault.sol";
import "./TestUtils.sol";

Expand Down

0 comments on commit 9d78201

Please sign in to comment.