Verified contractPartialApache-2.0
DepositSubsidy
Address0x4b39c6fc7c86cc8fb0ca334a0d1331493e106faa
- Balance
0 ETH
- Transactions
5
- Compiler
solc 0.8.30
- Same code
2 more contracts
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 1 runs
- EVM version
- osaka
- License
- Apache-2.0
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,391,549
- Creation transaction
- 0xd457b6497e…7167c0ca9e
124 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/periphery/DepositSubsidy.solmain15.73 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol739 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol9.39 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/ReentrancyGuardTransient.sol2.06 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/ShortStrings.sol4.28 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/SlotDerivation.sol5.32 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4.18 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/Strings.sol14.83 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/TransientSlot.sol5.07 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol7.82 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol6.61 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol3.7 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/math/Math.sol29.66 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2.61 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/structs/BitMaps.sol2.02 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/structs/Checkpoints.sol21.43 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol12.89 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IEscapeHatch.sol3.58 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol1.18 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IRollup.sol13.11 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/ISequencerRewardCalculator.sol2.17 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/ISlasher.sol530 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IStaking.sol5.72 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IValidatorSelection.sol2.98 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IVerifier.sol225 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol7.21 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol4.6 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/ConstantsGen.sol1.55 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/DataStructures.sol1.96 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/Errors.sol16.7 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/HatchMath.sol575 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/SlashRoundLib.sol1.93 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/StakingQueue.sol2.31 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/TimeLib.sol6.05 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/compressed-data/CheckpointLog.sol4.15 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/compressed-data/StakingQueueConfig.sol2.87 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/compressed-data/Tips.sol2.19 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/compressed-data/fees/FeeConfig.sol5.17 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/compressed-data/fees/FeeStructs.sol5.18 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/crypto/Hash.sol3.03 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/crypto/MerkleLib.sol2.91 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/crypto/SampleLib.sol3.77 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/AttestationLib.sol8.66 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/BlobLib.sol11.87 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/CoordinationSignatureLib.sol3.19 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/FeeLib.sol24.27 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/FieldLib.sol889 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/ProposeLib.sol28.01 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/ProposedHeaderLib.sol2.24 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/RewardLib.sol20.85 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/STFLib.sol25.95 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/SequencerRewardCalculatorLib.sol5.93 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/StakingLib.sol51.03 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/ValidatorSelectionLib.sol37.95 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/reward-boost/RewardBooster.sol5.04 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/slashing/Slasher.sol2.91 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/Bn254LibWrapper.sol752 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/GSE.sol39.93 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/GSEPayload.sol6.29 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/Governance.sol32.6 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IBn254LibWrapper.sol459 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IEmpire.sol1.3 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IGovernance.sol3.91 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IGovernanceProposer.sol359 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IPayload.sol597 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IProposerPayload.sol327 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IRegistry.sol1.21 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/interfaces/IRewardDistributor.sol1.28 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/AddressSnapshotLib.sol9.83 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/CheckpointedUintLib.sol3.02 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/ConfigurationLib.sol5 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/DepositDelegationLib.sol10.98 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/Errors.sol4.49 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/ProposalLib.sol8.54 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/compressed-data/Ballot.sol2.33 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/compressed-data/Configuration.sol4.5 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/libraries/compressed-data/Proposal.sol6.35 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/proposer/EmpireBase.sol12.69 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/governance/proposer/GovernanceProposer.sol4.25 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/mock/libraries/BlobLib.sol5.65 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/shared/libraries/BN254Lib.sol10.21 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/shared/libraries/CompressedTimeMath.sol1.27 KB
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/shared/libraries/SignatureLib.sol983 B
- node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/shared/libraries/TimeMath.sol3.54 KB
- node_modules/@openzeppelin/contracts/access/Ownable.sol3.1 KB
- node_modules/@openzeppelin/contracts/interfaces/IERC1271.sol656 B
- node_modules/@openzeppelin/contracts/interfaces/IERC1363.sol4.45 KB
- node_modules/@openzeppelin/contracts/interfaces/IERC165.sol193 B
- node_modules/@openzeppelin/contracts/interfaces/IERC20.sol182 B
- node_modules/@openzeppelin/contracts/proxy/Clones.sol14.52 KB
- node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol2.78 KB
- node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol13.31 KB
- node_modules/@openzeppelin/contracts/utils/Context.sol963 B
- node_modules/@openzeppelin/contracts/utils/Create2.sol4.37 KB
- node_modules/@openzeppelin/contracts/utils/Errors.sol896 B
- node_modules/@openzeppelin/contracts/utils/LowLevelCall.sol5.55 KB
- node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol871 B
- src/core/interfaces/IOxidePortal.sol2.61 KB
- src/core/interfaces/IProverSubsidy.sol294 B
- src/core/lib/Errors.sol3.09 KB
- src/core/lib/ProverClaimLib.sol4.67 KB
- src/generated/OxideConstants.gen.sol1.42 KB
- src/periphery/Errors.sol10.42 KB
- src/periphery/EthUsdMinOutLib.sol848 B
- src/periphery/Intent.sol857 B
- src/periphery/RecoveryCommitmentLib.sol707 B
- src/periphery/SIPABase.sol5.88 KB
- src/periphery/SIPAFactory.sol4.3 KB
- src/periphery/ThreePoolLib.sol2.29 KB
- src/periphery/interfaces/AggregatorV3Interface.sol314 B
- src/periphery/interfaces/ICurve3Pool.sol266 B
- src/periphery/interfaces/IForwardingTable.sol1.29 KB
- src/periphery/interfaces/IOperationExecutor.sol368 B
- src/periphery/interfaces/ISIPA.sol380 B
src/periphery/DepositSubsidy.sol
// SPDX-License-Identifier: Apache-2.0
// Copyright 2025 Aztec Labs.
pragma solidity >=0.8.27;
import {Ownable} from "@oz/access/Ownable.sol";
import {ReentrancyGuardTransient} from "@oz/utils/ReentrancyGuardTransient.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@oz/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@oz/utils/math/Math.sol";
import {ISIPA} from "./interfaces/ISIPA.sol";
import {IOperationExecutor} from "./interfaces/IOperationExecutor.sol";
import {SIPAFactory} from "./SIPAFactory.sol";
import {IForwardingTable} from "./interfaces/IForwardingTable.sol";
import {IOxidePortal} from "@core/interfaces/IOxidePortal.sol";
import {USDC, USDT} from "./ThreePoolLib.sol";
import {AggregatorV3Interface} from "./interfaces/AggregatorV3Interface.sol";
import {EthUsdMinOutLib} from "./EthUsdMinOutLib.sol";
import {Errors} from "@periphery/Errors.sol";
import {OxideConstants} from "@generated/OxideConstants.gen.sol";
import {Intent, Intents} from "@periphery/Intent.sol";
contract DepositSubsidy is Ownable, ReentrancyGuardTransient {
using SafeERC20 for IERC20;
// solhint-disable oxide/no-comments
struct Config {
// Relayer profit on top of the priced gas, in token units.
uint128 targetRelayerProfit;
// Maximum subsidy for one sweep, in token units.
uint128 maxSubsidyPerOperation;
// Minimum amount the portal credits on L2 for a sweep to get a subsidy, in token units.
uint128 minCreditedAmount;
}
// What the subsidy reads during one call. _pricedGas prices the call from it.
struct Meter {
// Gas left when the call starts.
uint256 startGas;
// Gas that the call used from its start to the end of the sweep, the eligibility check and, for an eligible sweep,
// the price feed read.
uint256 frameGas;
// The call deployed the SIPA, so the ceiling includes SWEEP_GAS_DEPLOY_ALLOWANCE.
bool deployed;
// The call is a relayer transaction: a code-free EOA sent the sweep through EXECUTOR, with the payout in TOKEN.
// The subsidy pays only a relayer transaction, for all of its gas.
bool relayerTransaction;
// The executor held no TOKEN before the sweep. This selects the refund of the executor's TOKEN balance.
bool executorStartedEmpty;
// Gas that the executor used before it called the subsidy.
uint256 executorHeadGas;
// Gas of the calldata of this call. The transaction carries this calldata inside the executor call.
uint256 calldataGas;
}
// solhint-enable oxide/no-comments
struct SweepGasCeiling {
Intent intent;
uint256 gas;
}
address public immutable PORTAL;
IERC20 public immutable TOKEN;
uint8 public immutable TOKEN_DECIMALS;
uint256 public immutable ROLLUP_VERSION;
IOperationExecutor public immutable EXECUTOR;
SIPAFactory public immutable SIPA_FACTORY;
AggregatorV3Interface public immutable PRICE_FEED;
uint256 internal constant MAX_PRICE_AGE = EthUsdMinOutLib.MAX_PRICE_AGE;
uint8 public constant FEED_DECIMALS = 8;
uint256 public constant SWEEP_GAS_SWAP_USDC_HOP = 132_000;
uint256 public constant SWEEP_GAS_SWAP_USDT_HOP = 136_000;
uint256 public constant SWEEP_GAS_DEPLOY_ALLOWANCE = 82_000;
// solhint-disable oxide/no-comments
// Gas of a relayer transaction that no meter reads.
// The base gas of every transaction.
uint256 public constant TX_INTRINSIC_GAS = 21_000;
// The executor's entry, the executor's calldata outside the sweep call, the call to the subsidy, the subsidy's
// pricing and payment after frameGas, and the executor's payout to the relayer.
uint256 public constant EXECUTOR_PATH_GAS = 32_500;
// The executor's payout to a relayer that holds no TOKEN writes a new balance (20,000 gas) instead of changing one
// (2,900 gas). EXECUTOR_PATH_GAS does not include this difference.
uint256 public constant FRESH_BALANCE_GAS = 17_100;
// EIP-3529 gas refunds for one storage slot. The EVM gives them back at the end of the transaction, and no contract
// can read them, so the subsidy subtracts them from the gas that it measures. See "Gas refunds" in README.md.
// A slot that held a value at the start of the transaction is zero at the end.
uint256 public constant CLEARED_SLOT_REFUND = 4800;
// A slot that was zero at the start of the transaction gets a value and goes back to zero: 20,000 - 100.
uint256 public constant RESTORED_ZERO_SLOT_REFUND = 19_900;
// A slot that held a value at the start of the transaction changes and goes back to that value: 5,000 - 2,100 - 100.
uint256 public constant RESTORED_SLOT_REFUND = 2800;
// solhint-enable oxide/no-comments
Config public $depositConfig;
mapping(Intent intent => uint256 gas) public $sweepGasCeilings;
event DepositConfigSet(uint128 targetRelayerProfit, uint128 maxSubsidyPerOperation, uint128 minCreditedAmount);
event SweepGasCeilingSet(Intent indexed intent, uint256 gas);
constructor(
address _owner,
address _portal,
IOperationExecutor _executor,
AggregatorV3Interface _priceFeed,
SIPAFactory _sipaFactory,
SweepGasCeiling[] memory _initialCeilings
) Ownable(_owner) {
require(address(_priceFeed).code.length > 0, Errors.DepositSubsidy__FeedWithoutCode());
// solhint-disable oxide/no-comments
// The subsidy expects a Chainlink ETH/USD feed, which has 8 decimals.
// solhint-enable oxide/no-comments
uint8 feedDecimals = _priceFeed.decimals();
require(feedDecimals == FEED_DECIMALS, Errors.DepositSubsidy__UnexpectedFeedDecimals(feedDecimals));
PORTAL = _portal;
EXECUTOR = _executor;
SIPA_FACTORY = _sipaFactory;
IERC20 token = IOxidePortal(_portal).UNDERLYING();
TOKEN = token;
TOKEN_DECIMALS = IERC20Metadata(address(token)).decimals();
ROLLUP_VERSION = IOxidePortal(_portal).ROLLUP_VERSION();
PRICE_FEED = _priceFeed;
for (uint256 i = 0; i < _initialCeilings.length; i++) {
_setSweepGasCeiling(_initialCeilings[i].intent, _initialCeilings[i].gas);
}
}
function setDepositConfig(uint128 _targetRelayerProfit, uint128 _maxSubsidyPerOperation, uint128 _minCreditedAmount)
external
onlyOwner
{
$depositConfig = Config({
targetRelayerProfit: _targetRelayerProfit,
maxSubsidyPerOperation: _maxSubsidyPerOperation,
minCreditedAmount: _minCreditedAmount
});
emit DepositConfigSet(_targetRelayerProfit, _maxSubsidyPerOperation, _minCreditedAmount);
}
function setSweepGasCeiling(Intent _intent, uint256 _gas) external onlyOwner {
_setSweepGasCeiling(_intent, _gas);
}
function deployAndSweepForSubsidy(
IForwardingTable _table,
Intent _intent,
bytes32 _recoveryCommitment,
bool _resweepable,
address _token,
address _relayer,
bytes calldata _intentData,
bytes calldata _proofs
) external nonReentrant returns (uint256 subsidy) {
Meter memory meter = _openMeter(gasleft(), _relayer);
address sipa;
(sipa, meter.deployed) =
_deploySIPAIfAbsent(_table, _intent, keccak256(_intentData), _recoveryCommitment, _resweepable);
subsidy = _sweepForSubsidy(ISIPA(sipa), _token, _relayer, _intentData, _proofs, meter);
}
function sweepForSubsidy(
ISIPA _sipa,
address _token,
address _relayer,
bytes calldata _intentData,
bytes calldata _proofs
) external nonReentrant returns (uint256 subsidy) {
Meter memory meter = _openMeter(gasleft(), _relayer);
subsidy = _sweepForSubsidy(_sipa, _token, _relayer, _intentData, _proofs, meter);
}
function _setSweepGasCeiling(Intent _intent, uint256 _gas) internal {
$sweepGasCeilings[_intent] = _gas;
emit SweepGasCeilingSet(_intent, _gas);
}
function _openMeter(uint256 _startGas, address _relayer) internal view returns (Meter memory meter) {
meter.startGas = _startGas;
if (msg.sender != address(EXECUTOR) || _relayer != address(EXECUTOR)) {
return meter;
}
IOperationExecutor.ExecutionContext memory context = EXECUTOR.executionContext();
if (!context.direct || address(context.payoutToken) != address(TOKEN)) {
return meter;
}
meter.relayerTransaction = true;
meter.executorStartedEmpty = context.startedEmpty;
meter.executorHeadGas = context.headGas;
meter.calldataGas = _calldataGas();
}
function _sweepForSubsidy(
ISIPA _sipa,
address _token,
address _relayer,
bytes calldata _intentData,
bytes calldata _proofs,
Meter memory _meter
) internal returns (uint256 subsidy) {
Intent intent = SIPA_FACTORY.sipaIntentOf(address(_sipa));
require(intent != Intents.NONE, Errors.DepositSubsidy__NotASIPA(address(_sipa)));
uint256 fee = _routedFee(_sipa);
uint256 ceiling = _sweepGasCeilingFor(intent, _token, _meter.deployed);
bool eligible = _sweepAndMeasureCredit(_sipa, _token, _relayer, _intentData, _proofs)
>= $depositConfig.minCreditedAmount && _meter.relayerTransaction && ceiling != 0;
uint256 tokenWeiPerEth = eligible ? _tokenWeiPerEth() : 0;
_meter.frameGas = _meter.startGas - gasleft();
uint256 pricedGas = eligible ? _pricedGas(ceiling, _token, _meter) : 0;
subsidy = _quoteSubsidy(fee, pricedGas, tokenWeiPerEth);
if (subsidy > 0) {
TOKEN.safeTransfer(_relayer, subsidy);
}
}
function _routedFee(ISIPA _sipa) internal view returns (uint256 fee) {
IOxidePortal portal;
(portal, fee,) = _sipa.route(address(TOKEN));
require(address(portal) == PORTAL, Errors.DepositSubsidy__SIPABoundToAnotherPortal(address(_sipa)));
}
function _deploySIPAIfAbsent(
IForwardingTable _table,
Intent _intent,
bytes32 _intentHash,
bytes32 _recoveryCommitment,
bool _resweepable
) internal returns (address sipa, bool deployed) {
require(SIPA_FACTORY.approvedTable(address(_table)), Errors.DepositSubsidy__TableNotApproved(address(_table)));
address implementation = SIPA_FACTORY.implementationFor(_intent);
require(implementation != address(0), Errors.DepositSubsidy__NoImplementationForIntent(_intent));
sipa =
SIPA_FACTORY.predictSIPA(implementation, _intentHash, _recoveryCommitment, ROLLUP_VERSION, _resweepable, _table);
deployed = sipa.code.length == 0;
if (deployed) {
SIPA_FACTORY.deploySIPA(implementation, _intentHash, _recoveryCommitment, ROLLUP_VERSION, _resweepable, _table);
}
}
function _sweepAndMeasureCredit(
ISIPA _sipa,
address _token,
address _relayer,
bytes calldata _intentData,
bytes calldata _proofs
) internal returns (uint256) {
uint256 portalBefore = TOKEN.balanceOf(PORTAL);
_sipa.sweep(_token, _relayer, _intentData, _proofs);
uint256 portalAfter = TOKEN.balanceOf(PORTAL);
return portalAfter > portalBefore ? portalAfter - portalBefore : 0;
}
function _pricedGas(uint256 _ceiling, address _token, Meter memory _meter) internal view returns (uint256) {
// solhint-disable-next-line oxide/no-comments
// A relayer transaction is paid its whole gas, so add the gas outside this call.
uint256 gross = _meter.frameGas + TX_INTRINSIC_GAS + _meter.calldataGas + _meter.executorHeadGas + EXECUTOR_PATH_GAS;
if (TOKEN.balanceOf(tx.origin) == 0) {
// solhint-disable-next-line oxide/no-comments
// The payout writes a new balance for a relayer with no TOKEN, outside the sweep, so the ceiling grows too.
gross += FRESH_BALANCE_GAS;
_ceiling += FRESH_BALANCE_GAS;
}
// solhint-disable-next-line oxide/no-comments
// The refunds of the sweep, and of the executor's TOKEN balance, which pays the fee and the subsidy out.
uint256 refund =
_sweepRefund(_token) + (_meter.executorStartedEmpty ? RESTORED_ZERO_SLOT_REFUND : RESTORED_SLOT_REFUND);
// solhint-disable-next-line oxide/no-comments
// The EVM gives back at most one fifth of the gas that the transaction used.
refund = Math.min(refund, gross / 5);
return Math.min(gross - refund, _ceiling);
}
function _sweepRefund(address _token) internal view returns (uint256 refund) {
// solhint-disable oxide/no-comments
// The SIPA's TOKEN balance: cleared if the SIPA held TOKEN, or zero again if the swap brought TOKEN in.
// The SIPA's allowance to the portal, which the portal spends in full.
// solhint-enable oxide/no-comments
refund = (_token == address(TOKEN) ? CLEARED_SLOT_REFUND : RESTORED_ZERO_SLOT_REFUND) + RESTORED_ZERO_SLOT_REFUND;
if (_token != address(TOKEN)) {
// solhint-disable-next-line oxide/no-comments
// The SIPA's balance of the swapped token is cleared, and the 3pool spends the SIPA's allowance in full.
refund += CLEARED_SLOT_REFUND + RESTORED_ZERO_SLOT_REFUND + RESTORED_ZERO_SLOT_REFUND;
}
}
function _sweepGasCeilingFor(Intent _intent, address _token, bool _deployed) internal view returns (uint256) {
uint256 ceiling = $sweepGasCeilings[_intent];
if (ceiling == 0) {
return 0;
}
if (_deployed) {
ceiling += SWEEP_GAS_DEPLOY_ALLOWANCE;
}
if (_token == address(TOKEN)) {
return ceiling;
}
if (_token == address(USDC)) {
return ceiling + SWEEP_GAS_SWAP_USDC_HOP;
}
if (_token == address(USDT)) {
return ceiling + SWEEP_GAS_SWAP_USDT_HOP;
}
return 0;
}
function _calldataGas() internal pure returns (uint256) {
uint256 size = msg.data.length;
uint256 nonZero;
assembly ("memory-safe") {
let lowBits := 0x0101010101010101010101010101010101010101010101010101010101010101
for { let offset := 0 } lt(offset, size) { offset := add(offset, 32) } {
let word := calldataload(offset)
word := or(word, shr(4, word))
word := or(word, shr(2, word))
word := or(word, shr(1, word))
nonZero := add(nonZero, shr(248, mul(and(word, lowBits), lowBits)))
}
}
return nonZero * 16 + (size - nonZero) * 4;
}
function quoteSubsidy(uint256 _fee, uint256 _reimbursableGas) public view returns (uint256) {
if (_reimbursableGas == 0) {
return 0;
}
return _quoteSubsidy(_fee, _reimbursableGas, _tokenWeiPerEth());
}
function _quoteSubsidy(uint256 _fee, uint256 _reimbursableGas, uint256 _tokenPerEth) internal view returns (uint256) {
Config memory cfg = $depositConfig;
if (_reimbursableGas == 0) {
return 0;
}
uint256 gasPrice = Math.min(tx.gasprice, block.basefee + OxideConstants.MAX_PRIORITY_FEE_WEI);
uint256 gasCost = Math.mulDiv(_reimbursableGas * gasPrice, _tokenPerEth, 1e18);
// solhint-disable oxide/no-comments
// The fee caps the profit, so a farmer who relays their own sweep gains nothing. One targetRelayerProfit
// applies to every SIPA implementation, and each implementation has its own DEPOSIT_FEE. Thus the cap is
// here, for each sweep, and not in setDepositConfig.
// solhint-enable oxide/no-comments
uint256 targetPayout = gasCost + Math.min(cfg.targetRelayerProfit, _fee);
if (targetPayout <= _fee) {
return 0;
}
uint256 subsidy = Math.min(targetPayout - _fee, cfg.maxSubsidyPerOperation);
return Math.min(subsidy, TOKEN.balanceOf(address(this)));
}
function _tokenWeiPerEth() internal view returns (uint256) {
(, int256 usdPerEth,, uint256 updatedAt,) = PRICE_FEED.latestRoundData();
if (usdPerEth < 0 || updatedAt > block.timestamp || block.timestamp - updatedAt > MAX_PRICE_AGE) {
return 0;
}
return Math.mulDiv(uint256(usdPerEth), 10 ** TOKEN_DECIMALS, 10 ** FEED_DECIMALS);
}
function defund() external onlyOwner {
TOKEN.safeTransfer(owner(), TOKEN.balanceOf(address(this)));
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 1,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"@core/=src/core/",
"@periphery/=src/periphery/",
"@generated/=src/generated/",
"@aztec/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/",
"@aztec-blob-lib/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/mock/libraries/",
"@zkpassport/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/circuits/src/solidity/src/",
"@oz/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:@openzeppelin/contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
"node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:@openzeppelin/contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
"@uniswap/universal-router/=node_modules/@uniswap/universal-router/",
"@uniswap/v4-core/=node_modules/@uniswap/v4-core/",
"@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/",
"@uniswap/v2-core/=node_modules/@uniswap/v2-core/",
"@account-abstraction/contracts/=node_modules/@account-abstraction/contracts/",
"@nitro-validator/=.deps/nitro-validator/src/",
"@solarity/libs/=.deps/solidity-lib/contracts/libs/",
"@test/=test/",
"forge-std/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/forge-std/src/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
"node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
"node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/",
"node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/lib/erc4626-tests/",
"node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/lib/erc4626-tests/",
"node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"node_modules/@uniswap/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
"node_modules/@uniswap/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
"node_modules/@uniswap/v4-periphery/lib/permit2/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
"node_modules/@uniswap/v4-periphery/lib/permit2/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
"node_modules/@uniswap/v4-periphery/lib/permit2/:solmate/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/",
"node_modules/@uniswap/v4-periphery/lib/permit2/:solmate/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/:solmate/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/",
"node_modules/@uniswap/v4-periphery/lib/v4-core/:solmate/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/",
"node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:openzeppelin-contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/",
"node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:openzeppelin-contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/",
"node_modules/@uniswap/universal-router/:@uniswap/v3-core/=node_modules/@uniswap/universal-router/node_modules/@uniswap/v3-core/",
"node_modules/@uniswap/universal-router/:@uniswap/v3-core/=node_modules/@uniswap/universal-router/node_modules/@uniswap/v3-core/",
"node_modules/@uniswap/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
"node_modules/@uniswap/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
"node_modules/@uniswap/v4-core/:solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
"node_modules/@uniswap/v4-core/:solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
"@account-abstraction/=node_modules/@account-abstraction/",
"@aztec-foundation/=node_modules/@aztec-foundation/",
"@openzeppelin/=node_modules/@openzeppelin/",
"@uniswap/=node_modules/@uniswap/",
"base64-sol/=node_modules/base64-sol/",
"circuits/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/circuits/",
"ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
"erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-gas-snapshot/",
"halmos-cheatcodes/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/lib/halmos-cheatcodes/",
"openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
"permit2/=node_modules/@uniswap/v4-periphery/lib/permit2/",
"solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
"v4-core/=node_modules/@uniswap/v4-periphery/lib/v4-core/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.