Verified contractExactApache-2.0
EthConverter
Address0x42a8606a0e1e8ff081638cb341ffb02ed45e146c
- Balance
0 ETH
- Transactions
14
- 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
- osaka
- Via IR
- yes
- License
- Apache-2.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,330,626
- Creation transaction
- 0x2ca2cb0790…7610a2ccc7
98 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/EthConverter.solmain7.79 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 B
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 B
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol12.18 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol739 B
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol9.39 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/ShortStrings.sol4.28 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/SlotDerivation.sol5.32 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4.18 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/Strings.sol14.83 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/TransientSlot.sol5.07 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol7.82 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol6.61 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol3.7 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 B
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/math/Math.sol29.66 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2.61 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/structs/BitMaps.sol2.02 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/structs/Checkpoints.sol21.43 KB
- lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol12.89 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/IEscapeHatch.sol3.58 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/IFeeJuicePortal.sol1.18 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/IRollup.sol13.11 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/ISequencerRewardCalculator.sol2.17 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/ISlasher.sol530 B
- lib/aztec-packages/l1-contracts/src/core/interfaces/IStaking.sol5.72 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/IValidatorSelection.sol2.98 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/IVerifier.sol225 B
- lib/aztec-packages/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol7.21 KB
- lib/aztec-packages/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol4.6 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/ConstantsGen.sol1.55 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/DataStructures.sol1.96 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/Errors.sol16.7 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/HatchMath.sol575 B
- lib/aztec-packages/l1-contracts/src/core/libraries/SlashRoundLib.sol1.93 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/StakingQueue.sol2.31 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/TimeLib.sol6.05 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/compressed-data/CheckpointLog.sol4.15 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/compressed-data/StakingQueueConfig.sol2.87 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/compressed-data/Tips.sol2.19 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/compressed-data/fees/FeeConfig.sol5.17 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/compressed-data/fees/FeeStructs.sol5.18 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/crypto/Hash.sol3.03 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/crypto/SampleLib.sol3.77 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/AttestationLib.sol8.66 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/BlobLib.sol11.87 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/CoordinationSignatureLib.sol3.19 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/FeeLib.sol24.27 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/FieldLib.sol889 B
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/ProposeLib.sol28.01 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/ProposedHeaderLib.sol2.24 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/RewardLib.sol20.85 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/STFLib.sol25.95 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/SequencerRewardCalculatorLib.sol5.93 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/StakingLib.sol51.03 KB
- lib/aztec-packages/l1-contracts/src/core/libraries/rollup/ValidatorSelectionLib.sol37.95 KB
- lib/aztec-packages/l1-contracts/src/core/reward-boost/RewardBooster.sol5.04 KB
- lib/aztec-packages/l1-contracts/src/core/slashing/Slasher.sol2.91 KB
- lib/aztec-packages/l1-contracts/src/governance/Bn254LibWrapper.sol752 B
- lib/aztec-packages/l1-contracts/src/governance/GSE.sol39.93 KB
- lib/aztec-packages/l1-contracts/src/governance/GSEPayload.sol6.29 KB
- lib/aztec-packages/l1-contracts/src/governance/Governance.sol32.6 KB
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IBn254LibWrapper.sol459 B
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IEmpire.sol1.3 KB
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IGovernance.sol3.91 KB
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IGovernanceProposer.sol359 B
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IPayload.sol597 B
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IProposerPayload.sol327 B
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IRegistry.sol1.21 KB
- lib/aztec-packages/l1-contracts/src/governance/interfaces/IRewardDistributor.sol1.28 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/AddressSnapshotLib.sol9.83 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/CheckpointedUintLib.sol3.02 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/ConfigurationLib.sol5 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/DepositDelegationLib.sol10.98 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/Errors.sol4.49 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/ProposalLib.sol8.54 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/compressed-data/Ballot.sol2.33 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/compressed-data/Configuration.sol4.5 KB
- lib/aztec-packages/l1-contracts/src/governance/libraries/compressed-data/Proposal.sol6.35 KB
- lib/aztec-packages/l1-contracts/src/governance/proposer/EmpireBase.sol12.69 KB
- lib/aztec-packages/l1-contracts/src/governance/proposer/GovernanceProposer.sol4.25 KB
- lib/aztec-packages/l1-contracts/src/shared/libraries/BN254Lib.sol10.21 KB
- lib/aztec-packages/l1-contracts/src/shared/libraries/CompressedTimeMath.sol1.27 KB
- lib/aztec-packages/l1-contracts/src/shared/libraries/SignatureLib.sol983 B
- lib/aztec-packages/l1-contracts/src/shared/libraries/TimeMath.sol3.54 KB
- src/interfaces/ICapacityProvider.sol1.87 KB
- src/interfaces/IEthConverter.sol5.79 KB
- src/interfaces/ITokenPortal.sol11.07 KB
- src/interfaces/ITokenUtilization.sol3.24 KB
- src/interfaces/IWETH.sol878 B
- src/libraries/OutboxUtils.sol4.06 KB
src/EthConverter.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.28;
import {IRollup} from "@aztec/core/interfaces/IRollup.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol";
import {Ownable} from "@oz/access/Ownable.sol";
import {SafeCast} from "@oz/utils/math/SafeCast.sol";
import {IEthConverter} from "./interfaces/IEthConverter.sol";
import {ITokenPortal} from "./interfaces/ITokenPortal.sol";
import {IWETH} from "./interfaces/IWETH.sol";
import {OutboxUtils, OutboxMessageMetadata} from "./libraries/OutboxUtils.sol";
/// @title EthConverter
/// @author Nyx.money
/// @notice Converts between ETH and WETH. Can issue deposit/withdraw of WETH attributed to the
/// user interacting with the converter contract to allow for proper tracking.
contract EthConverter is IEthConverter, Ownable {
using OutboxUtils for IOutbox;
using OutboxUtils for OutboxMessageMetadata;
using SafeCast for uint256;
/// @notice The wrapped ether contract
IWETH public immutable WETH;
/// @notice The Aztec registry this converter is bound to
IRegistry public immutable REGISTRY;
/// @notice The weth portal for deposits and withdrawals
ITokenPortal public immutable PORTAL;
/// @inheritdoc IEthConverter
IRollup public rollup;
/// @notice Aztec rollup version
uint256 public rollupVersion;
/// @notice Aztec outbox for L2 -> L1 messages
IOutbox public outbox;
/// @inheritdoc IEthConverter
bytes32 public l2Bridge;
/// @notice Construct the eth converter for weth portal
/// @param registry - The Aztec registry this converter is bound to
/// @param portal - The weth portal for deposit/withdraw
/// @param owner - Converter owner with admin capabilities
constructor(IRegistry registry, ITokenPortal portal, address owner) Ownable(owner) {
REGISTRY = registry;
WETH = IWETH(address(portal.underlying()));
PORTAL = portal;
// The portal only ever pulls what this contract wrapped or withdrew in the same call, and
// nothing is held between calls, so a standing approval is okay.
WETH.approve(address(portal), type(uint256).max);
}
/// @notice Accepts ether from the wrapped ether contract only
receive() external payable {
require(msg.sender == address(WETH), UnexpectedEth());
}
/// @notice Initialize the converter with an Aztec rollup
/// @param rollupVersion_ - Aztec rollup version
/// @param l2Bridge_ - The L2 bridge this converter is paired with
function initialize(uint256 rollupVersion_, bytes32 l2Bridge_) external onlyOwner {
rollupVersion = rollupVersion_;
rollup = IRollup(address(REGISTRY.getRollup(rollupVersion_)));
assert(rollup.getVersion() == rollupVersion_);
outbox = rollup.getOutbox();
l2Bridge = l2Bridge_;
require(address(PORTAL.rollup()) == address(rollup), TokenPortalRollupMismatch(PORTAL, rollup));
}
/// @inheritdoc IEthConverter
function depositEthToAztecPrivate(bytes32 claimSecretHash)
external
payable
returns (bytes32 message, uint256 leafIndex)
{
require(msg.value > 0, ZeroAmount());
WETH.deposit{value: msg.value}();
// Attributed to msg.sender, so limits and tracking are for the depositor
// rather than on this contract
return PORTAL.depositToAztecPrivate(msg.value.toUint128(), claimSecretHash, msg.sender);
}
/// @inheritdoc IEthConverter
function withdrawEth(
address recipient,
uint128 amount,
bytes32 claimSecretHash,
bool withCaller,
address cancelCallerOnL1,
uint64 unwrapValidDurationSeconds,
uint64 withdrawValidDurationSeconds,
OutboxMessageMetadata calldata withdrawWethMessage,
OutboxMessageMetadata calldata unwrapMessage
) external {
bytes32 unwrapMessageId = unwrapMessage.computeMessageId();
if (unwrapMessage.isExpired(unwrapValidDurationSeconds, rollup)) {
revert OrderExpired(unwrapMessageId);
}
_consumeOutboxMessage(
recipient,
amount,
claimSecretHash,
withCaller ? msg.sender : address(0),
cancelCallerOnL1,
unwrapValidDurationSeconds,
unwrapMessage
);
// Attributed to recipient, so limits and tracking are for the depositor
// rather than on this contract
PORTAL.withdraw(
address(this),
amount,
true,
address(this),
claimSecretHash,
withdrawValidDurationSeconds,
withdrawWethMessage,
recipient
);
WETH.withdraw(amount);
(bool sent,) = recipient.call{value: amount}("");
require(sent, EthTransferFailed());
emit EthWithdrawal(unwrapMessageId, recipient, amount);
}
// solhint-disable function-max-lines
/// @inheritdoc IEthConverter
function cancelWithdrawEth(
address recipient,
uint128 amount,
bytes32 claimSecretHash,
address callerOnL1,
bool cancelWithCaller,
uint64 unwrapValidDurationSeconds,
uint64 withdrawValidDurationSeconds,
OutboxMessageMetadata calldata withdrawWethMessage,
OutboxMessageMetadata calldata unwrapMessage
) external returns (bytes32 message, uint256 leafIndex) {
bytes32 unwrapMessageId = unwrapMessage.computeMessageId();
if (!unwrapMessage.isExpired(unwrapValidDurationSeconds, rollup)) {
revert OrderNotExpired(unwrapMessageId);
}
_consumeOutboxMessage(
recipient,
amount,
claimSecretHash,
callerOnL1,
cancelWithCaller ? msg.sender : address(0),
unwrapValidDurationSeconds,
unwrapMessage
);
// Cancel if portal withdraw is expired otherwise, withdraw and send back to L2
if (withdrawWethMessage.isExpired(withdrawValidDurationSeconds, rollup)) {
(message, leafIndex) = PORTAL.cancelWithdraw(
address(this),
amount,
address(this),
true,
claimSecretHash,
withdrawValidDurationSeconds,
withdrawWethMessage
);
} else {
PORTAL.withdraw(
address(this),
amount,
true,
address(this),
claimSecretHash,
withdrawValidDurationSeconds,
withdrawWethMessage,
recipient
);
(message, leafIndex) = PORTAL.depositToAztecPrivate(amount, claimSecretHash, recipient);
}
emit EthWithdrawalCanceled(unwrapMessageId, recipient, amount, message, leafIndex);
}
// solhint-enable function-max-lines
function _consumeOutboxMessage(
address recipient,
uint128 amount,
bytes32 claimSecretHash,
address callerOnL1,
address cancelCallerOnL1,
uint64 validDurationSeconds,
OutboxMessageMetadata calldata messageMetadata
) internal {
outbox.consume(
// solhint-disable-next-line gas-small-strings
OutboxUtils.buildMessage(
l2Bridge,
rollupVersion,
address(this),
"withdrawEth(address,uint128,bytes32,address,address,uint64)",
abi.encode(recipient, amount, claimSecretHash, callerOnL1, cancelCallerOnL1, validDurationSeconds)
),
messageMetadata
);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"@aztec-blob-lib/=lib/aztec-packages/l1-contracts/src/core/libraries/rollup/",
"@test/=lib/aztec-packages/l1-contracts/test/",
"@openzeppelin/=lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/",
"@oz/=lib/aztec-packages/l1-contracts/lib/openzeppelin-contracts/contracts/",
"@aztec/=lib/aztec-packages/l1-contracts/src/",
"@aztectest/=lib/aztec-packages/l1-contracts/test/",
"@permit2/=lib/permit2/src/",
"forge-std/=lib/aztec-packages/l1-contracts/lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.