Verified contractExactGPL-3.0
GasSponsoredAccount7702Cleanup
Address0xbd3574751f46fd77ac8f04a350104e3f820f85cf
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- Via IR
- yes
- License
- GPL-3.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,347,110
- Creation transaction
- 0xb7625ddbb4…1efe7d3fcc
2 files
- ../EmergencyAllowanceCleanup.solmain7.35 KB
- ../EIP7702.sol22.62 KB
../EmergencyAllowanceCleanup.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.30;
import {GasSponsoredAccount7702, IERC20Like, SafeERC20} from "./EIP7702.sol";
interface IERC20AllowanceLike is IERC20Like {
function allowance(address owner, address spender) external view returns (uint256);
}
interface IRevocationBatcherConfiguration {
function MAX_TASKS() external view returns (uint256);
function MAX_REVOKES_PER_TASK() external view returns (uint256);
function OPERATOR() external view returns (address);
function GOVERNANCE() external view returns (address);
function BEACON_STUB() external view returns (address);
function EXPECTED_DELEGATION_CODEHASH() external view returns (bytes32);
}
/// @notice Permanent implementation for clearing allowances through batch operations or wallet authorization.
/// @dev The Batcher path handles operator-identified incident positions at scale. The signed path lets an
/// allowlisted Sponsor relay an exact cleanup authorized by the wallet owner. Both paths only set
/// allowances to zero for code-bearing tokens including delisted assets, and remain available without another
/// Beacon upgrade.
contract GasSponsoredAccount7702Cleanup is GasSponsoredAccount7702 {
using SafeERC20 for IERC20Like;
bytes4 private constant _EMERGENCY_REVOKE_SUCCESS = bytes4(keccak256("AllScaleEmergencyAllowanceRevoked"));
// Expected RevocationBatcher shape, independently checked against its runtime getters.
uint256 private constant _EXPECTED_BATCHER_MAX_TASKS = 100;
uint256 private constant _MAX_EMERGENCY_REVOKES = 10;
bytes32 private constant _SIGNED_REVOKE_TYPEHASH =
keccak256("RevokeAllowances(address sponsor,bytes32 positionsHash,uint256 nonce,uint256 deadline)");
bytes32 private constant _REVOCATION_STORAGE_SLOT =
bytes32(uint256(keccak256("allscale.7702.revocation.storage")) - 1);
address public immutable REVOCATION_BATCHER;
struct RevocationStorage {
uint256 nonce;
}
event EmergencyAllowanceRevoked(
address indexed account, address indexed token, address indexed spender, uint256 previousAllowance
);
event SignedAllowanceRevocationExecuted(
address indexed account, address indexed sponsor, uint256 indexed nonce, bytes32 positionsHash, bytes32 digest
);
constructor(address globalConfig_, address revocationBatcher_) GasSponsoredAccount7702(globalConfig_) {
require(revocationBatcher_.code.length > 0, "BATCHER_NOT_CONTRACT");
IRevocationBatcherConfiguration batcher = IRevocationBatcherConfiguration(revocationBatcher_);
// Gateway shares role/stub getters. Check the Batcher surface as well.
// Deployment must additionally verify runtime code and immutable wiring.
require(
batcher.MAX_TASKS() == _EXPECTED_BATCHER_MAX_TASKS
&& batcher.MAX_REVOKES_PER_TASK() == _MAX_EMERGENCY_REVOKES,
"BATCHER_LIMITS_INVALID"
);
require(batcher.GOVERNANCE().code.length > 0, "BATCHER_GOVERNANCE_INVALID");
address beaconStub = batcher.BEACON_STUB();
require(beaconStub.code.length > 0, "BATCHER_STUB_INVALID");
require(
batcher.EXPECTED_DELEGATION_CODEHASH() == keccak256(abi.encodePacked(hex"ef0100", beaconStub)),
"BATCHER_DELEGATION_HASH_INVALID"
);
REVOCATION_BATCHER = revocationBatcher_;
}
function getRevocationNonce() external view returns (uint256) {
return _getRevocationStorage().nonce;
}
/// @notice Clears allowances authorized by a wallet signature and relayed by an allowed Sponsor.
/// @dev The EIP-712 signature is bound to this account and chain by the inherited domain separator,
/// and additionally commits to the Sponsor, exact token/spender arrays, nonce, and deadline.
/// This path intentionally remains available while the global business pause is active.
function revokeAllowancesWithSignature(
address[] calldata tokens,
address[] calldata spenders,
uint256 nonce,
uint256 deadline,
bytes calldata signature
) external nonReentrant returns (bytes4) {
require(GLOBAL_CONFIG.isSponsorAllowed(msg.sender), "SPONSOR_DENY");
_validateRevokeInputs(tokens, spenders);
_requireDeadline(deadline);
RevocationStorage storage revocationStorage = _getRevocationStorage();
require(nonce == revocationStorage.nonce, "BAD_REVOKE_NONCE");
bytes32 positionsHash = keccak256(abi.encode(tokens, spenders));
bytes32 digest = _hashTypedDataV4(
keccak256(abi.encode(_SIGNED_REVOKE_TYPEHASH, msg.sender, positionsHash, nonce, deadline))
);
require(_recover(digest, signature) == address(this), "BAD_REVOKE_SIGNER");
revocationStorage.nonce = nonce + 1;
_revokeAllowances(tokens, spenders);
emit SignedAllowanceRevocationExecuted(address(this), msg.sender, nonce, positionsHash, digest);
return _EMERGENCY_REVOKE_SUCCESS;
}
/// @notice Clears existing allowances granted to operator-identified spenders.
/// @dev Intentionally remains available while the global business pause is active. The function can
/// only set allowances to zero and cannot transfer funds or create new approvals. Tokens must be
/// code-bearing but need not be approved in GlobalConfig; spenders remain operator-selected so newly discovered
/// incident spender addresses do not require a contract upgrade.
function emergencyRevokeAllowances(address[] calldata tokens, address[] calldata spenders)
external
nonReentrant
returns (bytes4)
{
require(msg.sender == REVOCATION_BATCHER, "REVOKER_DENY");
_validateRevokeInputs(tokens, spenders);
_revokeAllowances(tokens, spenders);
return _EMERGENCY_REVOKE_SUCCESS;
}
function _getRevocationStorage() private pure returns (RevocationStorage storage revocationStorage) {
bytes32 slot = _REVOCATION_STORAGE_SLOT;
assembly ("memory-safe") {
revocationStorage.slot := slot
}
}
function _validateRevokeInputs(address[] calldata tokens, address[] calldata spenders) private pure {
uint256 length = tokens.length;
require(length != 0 && length == spenders.length, "BAD_REVOKE_LENGTH");
require(length <= _MAX_EMERGENCY_REVOKES, "TOO_MANY_REVOKES");
}
function _revokeAllowances(address[] calldata tokens, address[] calldata spenders) private {
uint256 length = tokens.length;
for (uint256 i = 0; i < length; ++i) {
address token = tokens[i];
address spender = spenders[i];
require(token != address(0) && token.code.length > 0, "INVALID_TOKEN");
require(spender != address(0), "INVALID_SPENDER");
IERC20Like tokenContract = IERC20Like(token);
uint256 previousAllowance = IERC20AllowanceLike(token).allowance(address(this), spender);
tokenContract.forceApprove(spender, 0);
require(IERC20AllowanceLike(token).allowance(address(this), spender) == 0, "REVOKE_FAILED");
emit EmergencyAllowanceRevoked(address(this), token, spender, previousAllowance);
}
}
}
../EIP7702.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.30;
interface IERC20Like {
function transfer(address to, uint256 value) external returns (bool);
function balanceOf(address owner) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
}
library SafeERC20 {
function safeTransfer(IERC20Like token, address to, uint256 value) internal {
(bool success, bytes memory data) =
address(token).call(abi.encodeWithSelector(token.transfer.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "SafeERC20:TRANSFER_FAIL");
}
/// @notice Set allowance to `value`. If the token rejects non-zero -> non-zero approve
/// (e.g. USDT mainnet), reset to 0 first then retry. Mirrors OpenZeppelin's
/// SafeERC20.forceApprove behavior without external imports.
function forceApprove(IERC20Like token, address spender, uint256 value) internal {
bytes memory approveData = abi.encodeWithSelector(token.approve.selector, spender, value);
(bool ok, bytes memory ret) = address(token).call(approveData);
bool success = ok && (ret.length == 0 || abi.decode(ret, (bool)));
if (!success) {
// Reset to 0 then approve again
(ok, ret) = address(token).call(
abi.encodeWithSelector(token.approve.selector, spender, uint256(0))
);
require(
ok && (ret.length == 0 || abi.decode(ret, (bool))),
"SafeERC20:APPROVE_RESET_FAIL"
);
(ok, ret) = address(token).call(approveData);
require(
ok && (ret.length == 0 || abi.decode(ret, (bool))),
"SafeERC20:FORCE_APPROVE_FAIL"
);
}
}
}
interface IGlobalConfig {
// flags and fee
function globalPaused() external view returns (bool);
function enforceExactNet() external view returns (bool);
function useTokenAllowlist() external view returns (bool);
function feeRecipient() external view returns (address);
function allowAdminSweep() external view returns (bool);
// allowlists
function isSponsorAllowed(address who) external view returns (bool);
function isTokenAllowed(address token) external view returns (bool);
function getAllSponsors() external view returns (address[] memory);
function getAllTokens() external view returns (address[] memory);
}
interface IRhinoDeposit {
function depositWithId(address token, uint256 amount, uint256 commitmentId) external;
}
contract GasSponsoredAccount7702 {
using SafeERC20 for IERC20Like;
// immutable global config
IGlobalConfig public immutable GLOBAL_CONFIG;
constructor(address globalConfig_) {
require(globalConfig_ != address(0), "GlobalConfigZero");
require(globalConfig_.code.length > 0, "GlobalConfigNoCode");
IGlobalConfig config = IGlobalConfig(globalConfig_);
// Fail deployment if an unrelated contract was supplied. These are every
// GlobalConfig selector consumed by the account's runtime paths.
config.globalPaused();
config.enforceExactNet();
config.useTokenAllowlist();
require(config.feeRecipient() != address(0), "GlobalConfigFeeRecipientZero");
config.allowAdminSweep();
config.isSponsorAllowed(address(this));
config.isTokenAllowed(address(this));
GLOBAL_CONFIG = config;
}
// ===== Constants =====
bytes4 private constant _MAGIC_BYTES32 = 0x1626ba7e; // EIP-1271
bytes4 private constant _INVALID_SIGNATURE = 0xffffffff;
uint256 private constant _SECP256K1_HALF_N =
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0;
// ===== Events =====
event GaslessTransferExecuted(
address indexed account,
address indexed sponsor,
address token,
address to,
uint256 grossAmount,
uint256 feeAmount,
uint256 netAmount,
address feeRecipient,
uint256 nonce,
bytes32 digest,
bytes32 indexed id
);
event GaslessApproveAndDepositExecuted(
address indexed account,
address indexed sponsor,
address token,
address depositContract,
uint256 amount,
uint256 feeAmount,
address feeRecipient,
uint256 commitmentId,
uint256 nonce,
bytes32 digest,
bytes32 indexed id
);
event TokenSwept(address indexed token, address indexed to, uint256 amount, uint256 nonce, bytes32 digest);
event ETHSwept(address indexed to, uint256 amount, uint256 nonce, bytes32 digest);
// ===== Storage (EIP-7201 style custom slot) =====
bytes32 private constant _ACCOUNT_STORAGE_SLOT =
bytes32(uint256(keccak256("allscale.7702.storage")) - 1);
struct AccountStorage {
// nonces
uint256 opNonce;
uint256 adminNonce;
// Reserved legacy guard slot: never reuse or remove.
uint256 reentrancyGuard;
// Reserved legacy EIP-712 cache: retained for layout, never trusted.
bytes32 cachedDomainSeparator;
uint256 cachedChainId;
address cachedThis;
// id anti-replay
mapping(bytes32 => bool) usedId;
}
function _getAccountStorage() private pure returns (AccountStorage storage s) {
bytes32 slot = _ACCOUNT_STORAGE_SLOT;
assembly ("memory-safe") {s.slot := slot}
}
// ===== Modifiers =====
bytes32 private constant _TRANSIENT_GUARD_SLOT = keccak256("allscale.7702.transient.reentrancy");
modifier nonReentrant() {
bytes32 slot = _TRANSIENT_GUARD_SLOT;
uint256 entered;
assembly ("memory-safe") { entered := tload(slot) }
require(entered == 0, "REENTRANCY");
assembly ("memory-safe") { tstore(slot, 1) }
_;
// Allow independent calls later in the same transaction.
assembly ("memory-safe") { tstore(slot, 0) }
}
modifier nonPaused() {
require(!GLOBAL_CONFIG.globalPaused(), "PAUSED");
_;
}
receive() external payable {}
fallback() external payable {}
// ===== EIP-712 =====
string private constant _NAME = "AllScaleEIP7702";
string private constant _VERSION = "1";
bytes32 private constant _EIP712_DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
/// An intentional future version upgrade changes the domain through this hook.
function _domainVersionHash() internal pure virtual returns (bytes32) {
return keccak256(bytes(_VERSION));
}
function _domainSeparator() internal view returns (bytes32) {
return keccak256(
abi.encode(
_EIP712_DOMAIN_TYPEHASH,
keccak256(bytes(_NAME)),
_domainVersionHash(),
block.chainid,
address(this)
)
);
}
/// Kept non-view for ABI compatibility; legacy cache is never read or written.
function domainSeparator() external returns (bytes32) {
return _domainSeparator();
}
// ---- Typed data typehashes(完整字符串,去掉省略号)----
bytes32 private constant TRANSFER_TYPEHASH = keccak256(
"GaslessTransfer(address sponsor,address token,address to,uint256 amount,uint256 feeAmount,uint256 deadline,bytes32 id)"
);
bytes32 private constant SWEEP_TOKEN_TYPEHASH = keccak256(
"SweepToken(address token,address to,uint256 amount,uint256 nonce,uint256 deadline)"
);
bytes32 private constant SWEEP_ETH_TYPEHASH = keccak256(
"SweepETH(address to,uint256 amount,uint256 nonce,uint256 deadline)"
);
bytes32 private constant APPROVE_DEPOSIT_TYPEHASH = keccak256(
"GaslessApproveAndDeposit(address sponsor,address token,address depositContract,uint256 amount,uint256 feeAmount,uint256 commitmentId,uint256 deadline,bytes32 id)"
);
// ===== Views =====
function getOpNonce() external view returns (uint256) {return _getAccountStorage().opNonce;}
function getNonce() external view returns (uint256) {return _getAccountStorage().adminNonce;}
// ===== EIP-1271 =====
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4) {
return _tryRecover(hash, signature) == address(this) ? _MAGIC_BYTES32 : _INVALID_SIGNATURE;
}
/// @dev The legacy bytes overload has no unambiguous hashing scheme. Keep
/// its selector fail-closed instead of treating arbitrary data as a
/// valid signature request.
function isValidSignature(bytes calldata, bytes calldata) external pure returns (bytes4) {
return _INVALID_SIGNATURE;
}
// ===== Internal helpers =====
function _tryRecover(bytes32 digest, bytes calldata signature) internal pure returns (address signer) {
bytes32 r;
bytes32 s;
uint8 v;
if (signature.length == 65) {
assembly ("memory-safe") {
r := calldataload(signature.offset)
s := calldataload(add(signature.offset, 32))
v := byte(0, calldataload(add(signature.offset, 64)))
}
} else if (signature.length == 64) {
bytes32 vs;
assembly ("memory-safe") {
r := calldataload(signature.offset)
vs := calldataload(add(signature.offset, 32))
}
v = uint8((uint256(vs) >> 255) + 27);
s = bytes32(uint256(vs) & ((1 << 255) - 1));
} else {
return address(0);
}
if (uint256(s) > _SECP256K1_HALF_N || (v != 27 && v != 28)) {
return address(0);
}
return ecrecover(digest, v, r, s);
}
function _hashTypedDataV4(bytes32 structHash) internal view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _domainSeparator(), structHash));
}
function _recover(bytes32 digest, bytes memory signature) internal pure returns (address) {
bytes32 r;
bytes32 s;
uint8 v;
if (signature.length == 65) {
assembly ("memory-safe") {
r := mload(add(signature, 32))
s := mload(add(signature, 64))
v := byte(0, mload(add(signature, 96)))
}
} else if (signature.length == 64) {
assembly ("memory-safe") {
r := mload(add(signature, 32))
s := mload(add(signature, 64))
}
v = uint8((uint256(s) >> 255) + 27);
s = bytes32(uint256(s) & ((1 << 255) - 1));
} else {
revert("BAD_SIG_LEN");
}
require(uint256(s) <= _SECP256K1_HALF_N, "BAD_S");
require(v == 27 || v == 28, "BAD_V");
address signer = ecrecover(digest, v, r, s);
require(signer != address(0), "ECRECOVER_ZERO");
return signer;
}
function _requireDeadline(uint256 deadline) internal view {
require(deadline >= block.timestamp, "EXPIRED");
}
function _verifyAndBumpOp(bytes32 structHash, bytes calldata signature)
internal
returns (bytes32 digest, uint256 usedNonce)
{
digest = _hashTypedDataV4(structHash);
address signer = _recover(digest, signature);
require(signer == address(this), "BadSigner");
AccountStorage storage s = _getAccountStorage();
usedNonce = s.opNonce;
unchecked {s.opNonce = usedNonce + 1;}
}
function _verifyAndBumpAdmin(bytes32 structHash, bytes calldata signature) internal returns (bytes32) {
bytes32 digest = _hashTypedDataV4(structHash);
address signer = _recover(digest, signature);
require(signer == address(this), "BadSigner");
AccountStorage storage s = _getAccountStorage();
unchecked {s.adminNonce += 1;}
return digest;
}
function _transferExactNet(IERC20Like token, address to, uint256 sendAmount) internal {
uint256 beforeBal = token.balanceOf(to);
(bool ok, bytes memory data) =
address(token).call(abi.encodeWithSelector(token.transfer.selector, to, sendAmount));
require(ok && (data.length == 0 || abi.decode(data, (bool))), "TRANSFER_FAIL");
uint256 delta = token.balanceOf(to) - beforeBal;
require(delta == sendAmount, "NET_MISMATCH");
}
/// Caps observed net debit independently of recipient exact-net policy.
/// Independently changing/rebasing balances are unsupported: increases fail
/// closed, but snapshots cannot detect a debit masked by an intervening credit.
function _requireDebitWithin(IERC20Like token, uint256 beforeBalance, uint256 maximum) internal view {
uint256 afterBalance = token.balanceOf(address(this));
require(afterBalance <= beforeBalance, "BALANCE_INCREASE");
require(beforeBalance - afterBalance <= maximum, "DEBIT_EXCEEDS_AMOUNT");
}
// ===== Business entry (global-config driven) =====
function gaslessTransfer(
address token,
address to,
uint256 amount,
uint256 feeAmount,
uint256 deadline,
bytes32 id,
bytes calldata signature
) external nonReentrant nonPaused {
require(amount > 0, "ZeroAmount");
require(token != address(0) && to != address(0), "ZeroAddr");
require(address(token).code.length > 0, "TokenNotContract");
require(feeAmount <= amount, "FeeGTAmount");
_requireDeadline(deadline);
// Sponsor allowlist
require(GLOBAL_CONFIG.isSponsorAllowed(msg.sender), "SPONSOR_DENY");
// Optional token allowlist
if (GLOBAL_CONFIG.useTokenAllowlist()) {
require(GLOBAL_CONFIG.isTokenAllowed(token), "TOKEN_DENY");
}
// id anti-replay
AccountStorage storage s = _getAccountStorage();
require(!s.usedId[id], "ID_USED");
s.usedId[id] = true;
// Verify signature & bump opNonce. opNonce no longer participates in
// the EIP-712 digest — anti-replay is provided by ``id`` + ``usedId``;
// the storage counter is kept purely for event indexing / debugging.
(bytes32 digest, uint256 usedNonce) = _verifyAndBumpOp(
keccak256(
abi.encode(
TRANSFER_TYPEHASH,
msg.sender,
token,
to,
amount,
feeAmount,
deadline,
id
)
),
signature
);
// Transfers
IERC20Like t = IERC20Like(token);
uint256 beforeBalance = t.balanceOf(address(this));
address feeRecvForEvent = GLOBAL_CONFIG.feeRecipient();
require(feeRecvForEvent != address(0), "FEE_ZERO");
if (feeAmount > 0) {
if (GLOBAL_CONFIG.enforceExactNet()) {
_transferExactNet(t, feeRecvForEvent, feeAmount);
} else {
t.safeTransfer(feeRecvForEvent, feeAmount);
}
}
uint256 net = amount - feeAmount;
if (GLOBAL_CONFIG.enforceExactNet()) {
_transferExactNet(t, to, net);
} else {
t.safeTransfer(to, net);
}
_requireDebitWithin(t, beforeBalance, amount);
emit GaslessTransferExecuted(
address(this), msg.sender, token, to, amount, feeAmount, net, feeRecvForEvent, usedNonce, digest, id
);
}
function gaslessApproveAndDeposit(
address token,
address depositContract,
uint256 amount,
uint256 feeAmount,
uint256 commitmentId,
uint256 deadline,
bytes32 id,
bytes calldata signature
) external nonReentrant nonPaused {
// ---- Param validation (same shape as gaslessTransfer) ----
require(amount > 0, "ZeroAmount");
require(token != address(0) && depositContract != address(0), "ZeroAddr");
require(address(token).code.length > 0, "TokenNotContract");
require(address(depositContract).code.length > 0, "DepositNotContract");
// ``amount`` here is the buyer's total spend; the contract splits it
// into ``feeAmount`` (skimmed to the AllScale fee wallet) and
// ``amount - feeAmount`` (forwarded to Rhino's depositWithId, which
// must equal the positive quote-time payAmount). This requires
// feeAmount < amount: reject feeAmount > amount here to prevent
// underflow; equality is rejected by ZeroDeposit below. Any revert
// atomically rolls back the fee, usedId and opNonce updates.
require(feeAmount <= amount, "FeeGTAmount");
_requireDeadline(deadline);
// ---- Sponsor allowlist ----
require(GLOBAL_CONFIG.isSponsorAllowed(msg.sender), "SPONSOR_DENY");
// ---- Optional token allowlist ----
if (GLOBAL_CONFIG.useTokenAllowlist()) {
require(GLOBAL_CONFIG.isTokenAllowed(token), "TOKEN_DENY");
}
// ---- id anti-replay ----
AccountStorage storage s = _getAccountStorage();
require(!s.usedId[id], "ID_USED");
s.usedId[id] = true;
// ---- Verify EIP-712 signature, bump opNonce ----
// opNonce no longer participates in the digest (anti-replay = ``id``);
// _verifyAndBumpOp still increments the storage counter for events.
(bytes32 digest, uint256 usedNonce) = _verifyAndBumpOp(
keccak256(
abi.encode(
APPROVE_DEPOSIT_TYPEHASH,
msg.sender,
token,
depositContract,
amount,
feeAmount,
commitmentId,
deadline,
id
)
),
signature
);
uint256 beforeBalance = IERC20Like(token).balanceOf(address(this));
// ---- AllScale Pay wallet-business fee (mirrors gaslessTransfer) ----
// Skim BEFORE the deposit leg so a deposit revert (e.g. Rhino route
// outage) atomically rolls back the fee transfer too — never leaves a
// "fee taken but bridge not started" inconsistency.
address feeRecv = address(0);
if (feeAmount > 0) {
feeRecv = GLOBAL_CONFIG.feeRecipient();
require(feeRecv != address(0), "FEE_ZERO");
if (GLOBAL_CONFIG.enforceExactNet()) {
_transferExactNet(IERC20Like(token), feeRecv, feeAmount);
} else {
IERC20Like(token).safeTransfer(feeRecv, feeAmount);
}
}
// ---- approve depositContract for the Rhino-bound portion ----
// ``amount - feeAmount`` MUST equal the quote-time payAmount Rhino
// committed to; deviating triggers Rhino-side amount-mismatch and the
// deposit will not match any commitment.
uint256 depositAmount = amount - feeAmount;
require(depositAmount > 0, "ZeroDeposit");
IERC20Like(token).forceApprove(depositContract, depositAmount);
// ---- Atomically call depositWithId ----
uint256 beforeDeposit = IERC20Like(token).balanceOf(address(this));
IRhinoDeposit(depositContract).depositWithId(token, depositAmount, commitmentId);
uint256 afterDeposit = IERC20Like(token).balanceOf(address(this));
require(beforeDeposit >= afterDeposit && beforeDeposit - afterDeposit == depositAmount, "DEPOSIT_MISMATCH");
// ---- Defense in depth: clear residual allowance to 0.
// Today Rhino.fi's depositWithId pulls the full `depositAmount` via
// transferFrom, leaving allowance at 0 organically. If the contract
// is ever upgraded to transfer less (protocol fee, partial fill),
// a non-zero allowance would otherwise persist on the user's
// EIP-7702 account and could be exploited if the deposit contract
// is later compromised. Cost is a few thousand gas, sponsored.
IERC20Like(token).forceApprove(depositContract, 0);
_requireDebitWithin(IERC20Like(token), beforeBalance, amount);
emit GaslessApproveAndDepositExecuted(
address(this),
msg.sender,
token,
depositContract,
amount,
feeAmount,
feeRecv,
commitmentId,
usedNonce,
digest,
id
);
}
// ===== Admin sweeps (受 GlobalConfig.allowAdminSweep 控制,且同样严格校验) =====
function sweepToken(address token, address to, uint256 amount, uint256 deadline, bytes calldata signature)
external nonReentrant nonPaused
{
require(GLOBAL_CONFIG.allowAdminSweep(), "ADMIN_SWEEP_OFF");
require(token != address(0) && to != address(0), "ZeroAddr");
require(address(token).code.length > 0, "TokenNotContract");
_requireDeadline(deadline);
AccountStorage storage s = _getAccountStorage();
uint256 used = s.adminNonce;
bytes32 digest = _verifyAndBumpAdmin(
keccak256(abi.encode(SWEEP_TOKEN_TYPEHASH, token, to, amount, used, deadline)), signature
);
// Owner-signed rescue deliberately permits unlisted/delisted assets.
IERC20Like t = IERC20Like(token);
uint256 beforeBalance = t.balanceOf(address(this));
if (GLOBAL_CONFIG.enforceExactNet()) {
_transferExactNet(t, to, amount);
} else {
t.safeTransfer(to, amount);
}
_requireDebitWithin(t, beforeBalance, amount);
emit TokenSwept(token, to, amount, used, digest);
}
function sweepETH(address to, uint256 amount, uint256 deadline, bytes calldata signature)
external nonReentrant nonPaused
{
require(GLOBAL_CONFIG.allowAdminSweep(), "ADMIN_SWEEP_OFF");
require(to != address(0), "ZeroAddr");
_requireDeadline(deadline);
AccountStorage storage s = _getAccountStorage();
uint256 used = s.adminNonce;
bytes32 digest = _verifyAndBumpAdmin(
keccak256(abi.encode(SWEEP_ETH_TYPEHASH, to, amount, used, deadline)), signature
);
(bool ok,) = to.call{value: amount}("");
require(ok, "ETH_SEND_FAIL");
emit ETHSwept(to, amount, used, digest);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"eip7702/=../",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.