Skip to content
Verified contractPartialMIT

DepositAddressFactory

Address0x1df43ab501f8b0d604f9a58a41a51744f2f8cd22
Balance

0 ETH

 

Transactions

21,943

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,586,730
Creation transaction
0x9d88af06f3…3d41c73036

67 files

The source code is large: one file is shown at a time. Choose a file in the list.

contracts/DepositAddressFactory.sol

// SPDX-License-Identifier: MIT
// ABOUTME: Factory for deterministic deposit addresses using EIP-1167 minimal proxies.
// ABOUTME: Computes addresses before deployment and sweeps deposited funds to a depository.
pragma solidity ^0.8.28;

import {LibClone} from "solady/utils/LibClone.sol";
import {IDepositAddressFactory} from "./interfaces/IDepositAddressFactory.sol";
import {DepositAddress} from "./DepositAddress.sol";

/// @title DepositAddressFactory
/// @author Relay Protocol
/// @notice Deploys deterministic EIP-1167 minimal proxies for deposit collection
///         and sweeps funds to a hardcoded depository
contract DepositAddressFactory is IDepositAddressFactory {
  /// @notice The depository contract that receives all swept funds
  address public immutable DEPOSITORY;

  /// @notice The DepositAddress implementation used by all proxies
  address public immutable IMPLEMENTATION;

  /// @notice Deploy a new factory with a fixed depository
  /// @dev Deploys the DepositAddress implementation internally so it trusts this factory as msg.sender
  constructor(address _depository) {
    DEPOSITORY = _depository;
    IMPLEMENTATION = address(new DepositAddress(_depository));
  }

  /// @inheritdoc IDepositAddressFactory
  function computeDepositAddress(
    bytes32 orderId,
    address depositor
  ) external view returns (address) {
    bytes32 salt = _salt(orderId, depositor);
    return
      LibClone.predictDeterministicAddress(IMPLEMENTATION, salt, address(this));
  }

  /// @inheritdoc IDepositAddressFactory
  function sweep(
    bytes32 orderId,
    address depositor,
    address[] calldata tokens
  ) external {
    bytes32 salt = _salt(orderId, depositor);
    address proxy = LibClone.predictDeterministicAddress(
      IMPLEMENTATION,
      salt,
      address(this)
    );

    // Deploy the proxy if it hasn't been deployed yet
    if (proxy.code.length == 0) {
      proxy = LibClone.cloneDeterministic(IMPLEMENTATION, salt);
      emit ProxyDeployed(orderId, proxy);
    }

    _sweepProxy(proxy, depositor, tokens, orderId);
  }

  /// @notice Compute the CREATE2 salt from orderId and depositor
  /// @return The keccak256 hash of the packed orderId and depositor
  function _salt(
    bytes32 orderId,
    address depositor
  ) internal pure returns (bytes32) {
    return keccak256(abi.encodePacked(orderId, depositor));
  }

  /// @notice Sweep all tokens from a proxy to the depository
  function _sweepProxy(
    address proxy,
    address depositor,
    address[] calldata tokens,
    bytes32 orderId
  ) internal {
    for (uint256 i; i < tokens.length; ++i) {
      DepositAddress(payable(proxy)).sweep(tokens[i], depositor, orderId);
    }
  }
}
Compiler settingsShow
{
  "metadata": {
    "appendCBOR": false,
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.