Verified contractPartialUNLICENSED
BatchSeizer
Address0xf5062933dc61fd3bc4e0a271bb73458f06512d93
- Balance
0 ETH
- Transactions
48
- Compiler
solc 0.8.27
- Same code
Only this contract
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,429,599
- Creation transaction
- 0x0fd5c5d825…3d78c2eb19
94 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/BatchSeizer.solmain6.17 KB
- lib/openzeppelin-community-contracts/contracts/interfaces/IERC7540.sol7.33 KB
- lib/openzeppelin-community-contracts/contracts/interfaces/IERC7575.sol747 B
- lib/openzeppelin-community-contracts/contracts/token/ERC20/extensions/ERC7540.sol42.71 KB
- lib/openzeppelin-community-contracts/contracts/token/ERC20/extensions/ERC7540SyncDeposit.sol1.85 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/interfaces/IERC165.sol193 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/interfaces/IERC20.sol182 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol216 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/interfaces/IERC4626.sol12.21 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.8 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol13.96 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/LowLevelCall.sol5.55 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/Memory.sol6.14 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/Pausable.sol2.71 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol4.77 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/StorageSlot.sol4.18 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/introspection/ERC165.sol879 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/introspection/IERC165.sol871 B
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/math/Math.sol32.66 KB
- lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/openzeppelin-contracts/contracts/access/AccessControl.sol7.05 KB
- lib/openzeppelin-contracts/contracts/access/IAccessControl.sol3.34 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 B
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol9.44 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol6.03 KB
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-contracts/contracts/utils/Pausable.sol2.83 KB
- lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol3.38 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol912 B
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 B
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol28.31 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol12.89 KB
- src/StabilityPool7540.sol36.59 KB
- src/StableReserveVault.sol11.93 KB
- src/Treasury.sol43.59 KB
- src/Vault.sol21.68 KB
- src/Warehouse.sol30.84 KB
- src/WarehouseDeployer.sol957 B
- src/WarehousePool.sol2.85 KB
- src/WarehouseSourceAuth.sol971 B
- src/WarehouseTreasury.sol34.22 KB
- src/WarehouseVault.sol9.07 KB
- src/interfaces/IArbBuyer.sol1.24 KB
- src/interfaces/ICollateralRegistry.sol692 B
- src/interfaces/IFacilityRegistry.sol2.03 KB
- src/interfaces/IFloorSettlementExecutor.sol1.37 KB
- src/interfaces/IGreaterMarketReference.sol1.34 KB
- src/interfaces/ILiquidationEngine.sol527 B
- src/interfaces/IOracleAdapter.sol3.86 KB
- src/interfaces/IPRUSD.sol365 B
- src/interfaces/ISettlementExecutor.sol862 B
- src/interfaces/ISettlementPool7540.sol1.06 KB
- src/interfaces/IStabilityPoolRegistry.sol1.31 KB
- src/interfaces/IStabilityPoolSettlementLedger.sol1.09 KB
- src/interfaces/ITreasury.sol2.39 KB
- src/interfaces/IVault.sol2.66 KB
- src/interfaces/IWarehouse.sol1.7 KB
- src/interfaces/IWarehouseCycleSource.sol638 B
- src/interfaces/IWarehouseRegistry.sol561 B
- src/libraries/FacilityDebtMath.sol1.44 KB
- src/libraries/FacilityStatusLib.sol1.26 KB
- src/libraries/RevenueSources.sol855 B
- src/libraries/Roles.sol7.74 KB
- src/libraries/SalePricing.sol1.19 KB
- src/libraries/SettlementProfit.sol695 B
- src/libraries/SharePenalty7540.sol1.7 KB
- src/libraries/SrvLossMath.sol4.78 KB
- src/libraries/StableReserveMath.sol1.9 KB
- src/libraries/SupportedChains.sol1.17 KB
- src/libraries/TestDrain.sol1.45 KB
- src/libraries/TreasuryCow.sol23.55 KB
- src/libraries/TreasuryFold.sol21.3 KB
- src/libraries/TreasurySales.sol45.44 KB
- src/libraries/WarehouseSeizureMath.sol5.27 KB
- src/registries/CollateralRegistry.sol4.25 KB
- src/registries/FacilityRegistry.sol26.34 KB
- src/registries/PsmAssetRegistry.sol5.24 KB
- src/registries/StableReserveRegistry.sol13.56 KB
- src/registries/WarehouseRegistry.sol6.6 KB
- src/types/LotTypes.sol606 B
- src/types/ProtocolTypes.sol3.4 KB
src/BatchSeizer.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {WarehouseVault} from "./WarehouseVault.sol";
import {Roles} from "./libraries/Roles.sol";
/// @notice Batches only the bound Vault's existing, ordinary warehouse seizures.
/// @dev Both this helper and its caller require the Vault's current LIQUIDATOR_ROLE.
contract BatchSeizer is ReentrancyGuard {
struct Candidate {
address borrower;
uint256 facilityId;
uint256 expectedNonce;
}
uint256 public constant MAX_BATCH_SIZE = 20;
uint256 public constant SEIZURE_GAS = 1_500_000;
// Covers the nonce read, call setup, bounded return handling and function exit.
uint256 private constant CALL_HEADROOM = 50_000;
uint256 private constant RESULT_GAS = 10_000;
WarehouseVault public immutable vault;
error InvalidVault();
error Unauthorized(address account);
error InvalidBatchSize();
error DuplicateCandidate(uint256 first, uint256 second);
error StaleNonce();
error InsufficientGas();
/// @dev Includes gas-cap exhaustion and reverts with fewer than four bytes of data.
error UnspecifiedFailure();
error InvalidReturnData();
event SeizureResult(
uint256 indexed index,
address indexed borrower,
uint256 indexed facilityId,
uint256 expectedNonce,
bool success,
bytes32 seizureId,
bytes4 reason
);
constructor(WarehouseVault vault_) {
if (address(vault_).code.length == 0) revert InvalidVault();
vault = vault_;
}
/// @param candidates Each expectedNonce is the nonce BEFORE the proposed seizure.
/// @return successes Successful items, including zero when every item fails or is stale.
/// @return processed Visited prefix length, including stale/failed items, excluding the gas-short tail.
/// @dev Every item revert is isolated, including unexpected errors and gas-cap exhaustion.
/// Reserve every remaining result before each call. Gas-short tails are explicitly unattempted;
/// prior successes persist. Simulate/send with the same explicit gas limit, not estimateGas:
/// a low-gas simulation can return successfully with processed == 0.
function seize(Candidate[] calldata candidates)
external
nonReentrant
returns (uint256 successes, uint256 processed)
{
if (!vault.hasRole(Roles.LIQUIDATOR_ROLE, msg.sender)) {
revert Unauthorized(msg.sender);
}
if (!vault.hasRole(Roles.LIQUIDATOR_ROLE, address(this))) {
revert Unauthorized(address(this));
}
uint256 length = candidates.length;
if (length == 0 || length > MAX_BATCH_SIZE) revert InvalidBatchSize();
for (uint256 i; i < length; ++i) {
for (uint256 j; j < i; ++j) {
if (
candidates[i].borrower == candidates[j].borrower
&& candidates[i].facilityId == candidates[j].facilityId
) {
revert DuplicateCandidate(j, i);
}
}
}
// This refusal happens before any seizure, so an unusably small budget cannot lose progress.
if (gasleft() < length * RESULT_GAS + CALL_HEADROOM) revert InsufficientGas();
for (uint256 i; i < length; ++i) {
// EIP-150 must not reduce the fixed allowance. Even a call consuming all of it leaves
// enough gas to report the entire unattempted suffix and return without rolling back.
uint256 requiredGas =
SEIZURE_GAS + (SEIZURE_GAS + 62) / 63 + CALL_HEADROOM + (length - i) * RESULT_GAS;
if (gasleft() < requiredGas) {
for (uint256 j = i; j < length; ++j) {
Candidate calldata unattempted = candidates[j];
emit SeizureResult(
j,
unattempted.borrower,
unattempted.facilityId,
unattempted.expectedNonce,
false,
bytes32(0),
InsufficientGas.selector
);
}
return (successes, processed);
}
Candidate calldata candidate = candidates[i];
bool success;
bytes32 seizureId;
bytes4 reason;
if (
vault.seizureNonce(candidate.borrower, candidate.facilityId)
!= candidate.expectedNonce
) {
reason = StaleNonce.selector;
} else {
(success, seizureId, reason) = _seize(candidate);
if (success) ++successes;
}
emit SeizureResult(
i,
candidate.borrower,
candidate.facilityId,
candidate.expectedNonce,
success,
seizureId,
reason
);
++processed;
}
}
function _seize(Candidate calldata candidate)
private
returns (bool success, bytes32 seizureId, bytes4 reason)
{
bytes memory data = abi.encodeCall(
vault.seizeToWarehouse, (candidate.borrower, candidate.facilityId)
);
address target = address(vault);
uint256 allowance = SEIZURE_GAS;
uint256 size;
bytes32 result;
assembly ("memory-safe") {
mstore(0, 0)
success := call(allowance, target, 0, add(data, 32), mload(data), 0, 32)
size := returndatasize()
result := mload(0)
}
// Copy at most one word, even if a downstream contract produces enormous revert data.
if (success) {
if (size != 32) revert InvalidReturnData();
seizureId = result;
} else {
reason = size >= 4 ? bytes4(result) : UnspecifiedFailure.selector;
if (reason == bytes4(0)) reason = UnspecifiedFailure.selector;
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"lib/openzeppelin-community-contracts/contracts/:@openzeppelin/contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/",
"lib/openzeppelin-community-contracts/contracts/:@openzeppelin/contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/community-contracts/=lib/openzeppelin-community-contracts/contracts/",
"@openzeppelin7540/contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/",
"composable-cow/=lib/composable-cow/src/",
"lib/composable-cow/:@openzeppelin/=lib/composable-cow/lib/@openzeppelin/",
"lib/composable-cow/:@openzeppelin/=lib/composable-cow/lib/@openzeppelin/",
"cowprotocol/=lib/composable-cow/lib/cowprotocol/src/",
"safe/=lib/composable-cow/lib/safe/contracts/",
"@axelar-network/axelar-gmp-sdk-solidity/=lib/openzeppelin-community-contracts/lib/axelar-gmp-sdk-solidity/",
"@openzeppelin-contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/",
"@openzeppelin/=lib/composable-cow/lib/@openzeppelin/",
"@zk-email/contracts/=lib/openzeppelin-community-contracts/lib/zk-email-verify/packages/contracts/",
"@zk-email/email-tx-builder/=lib/openzeppelin-community-contracts/lib/email-tx-builder/packages/contracts/",
"ds-test/=lib/composable-cow/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"murky/=lib/composable-cow/lib/murky/src/",
"openzeppelin-community-contracts/=lib/openzeppelin-community-contracts/contracts/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/composable-cow/lib/@openzeppelin/contracts/",
"wormhole-solidity-sdk/=lib/openzeppelin-community-contracts/lib/wormhole-solidity-sdk/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.