ETH Price: $3,445.62 (-1.01%)
Gas: 10 Gwei

Contract

0x0B4E13D8019D0F762377570000D9C923f0dad82B
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x7f93a92e149999212022-06-21 2:07:49758 days ago1655777269IN
 Contract Creation
0 ETH0.0449829518.30400496

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x639D9B37...c90300E06
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
ThreeXBatchVault

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
Yes with 1000 runs

Other Settings:
default evmVersion, GNU GPLv3 license
File 1 of 18 : ThreeXBatchVault.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

import "./storage/AbstractBatchStorage.sol";
import "./storage/AbstractViewableBatchStorage.sol";
import "../../utils/ContractRegistryAccess.sol";

contract ThreeXBatchVault is AbstractBatchStorage {
  bytes32 public contractId = keccak256("ThreeXBatchStorage");
  string public name = "3X Batch Vault v1";

  constructor(IContractRegistry _contractRegistry, address client) AbstractBatchStorage(_contractRegistry, client) {}
}

File 2 of 18 : Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 3 of 18 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 4 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 5 of 18 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 18 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 7 of 18 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 8 of 18 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a / b + (a % b == 0 ? 0 : 1);
    }
}

File 9 of 18 : AbstractBatchStorage.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./AbstractClientAccess.sol";
import "../../../interfaces/IBatchStorage.sol";

abstract contract AbstractBatchStorage is IAbstractBatchStorage, AbstractClientAccess {
  using SafeERC20 for IERC20;

  /* ========== STATE VARIABLES ========== */

  /**
   * @notice BatchId => account => balance in batch
   */
  mapping(bytes32 => mapping(address => uint256)) public accountBalances;
  mapping(address => bytes32[]) public accountBatches;
  mapping(bytes32 => Batch) public batches;
  bytes32[] public batchIds;

  /**
   * @dev allowances of client => recipient => batchId => token => amount
   */
  mapping(address => mapping(address => mapping(bytes32 => mapping(address => uint256)))) public allowances;

  /* ========== CONSTRUCTOR ========== */
  constructor(IContractRegistry __contractRegistry, address _client)
    AbstractClientAccess(__contractRegistry, _client)
  {}

  /* ========== EVENTS ========== */
  /* ========== VIEWS ========== */

  function getBatch(bytes32 batchId) public view virtual returns (Batch memory) {
    return batches[batchId];
  }

  function getBatchType(bytes32 batchId) public view virtual override returns (BatchType) {
    return batches[batchId].batchType;
  }

  /**
   * @notice Get ids for all batches that a user has interacted with
   * @param _account The address for whom we want to retrieve batches
   */
  function getAccountBatches(address _account) external view virtual returns (bytes32[] memory) {
    return accountBatches[_account];
  }

  /**
   * @notice Get ids for all batches that a user has interacted with
   * @param _account The address for whom we want to retrieve batches
   */
  function getAccountBalance(bytes32 batchId, address _account) external view virtual returns (uint256) {
    return accountBalances[batchId][_account];
  }

  /* ========== MODIFIERS ========== */

  modifier onlyOwnerOf(bytes32 batchId) {
    _onlyClients();
    Batch storage batch = batches[batchId];
    require(
      batch.owner == msg.sender || delegates[batch.owner][msg.sender],
      "client does not have access to this batch"
    );
    _;
  }

  /* ========== ADMIN FUNCTIONS (CLIENT ONLY) ========== */

  function createBatch(BatchType _batchType, BatchTokens memory _tokens)
    external
    override(IAbstractBatchStorage)
    onlyClients
    returns (bytes32)
  {
    bytes32 _id = _generateId();
    batchIds.push(_id);
    Batch storage batch = batches[_id];
    batch.batchType = _batchType;
    batch.batchId = _id;
    batch.sourceToken = _tokens.sourceToken;
    batch.targetToken = _tokens.targetToken;
    batch.owner = msg.sender;
    return _id;
  }

  function deposit(
    bytes32 batchId,
    address owner,
    uint256 amount
  ) public override onlyOwnerOf(batchId) returns (uint256) {
    Batch storage batch = batches[batchId];
    // todo allow anyone to deposit to this batch, not just the client address
    return _deposit(batch, owner, amount, msg.sender);
  }

  function _deposit(
    Batch storage batch,
    address owner,
    uint256 amount,
    address sender
  ) internal returns (uint256) {
    require(!batch.claimable, "can't deposit");
    batch.sourceTokenBalance += amount;
    batch.unclaimedShares += amount;
    accountBalances[batch.batchId][owner] += amount;
    _cacheAccount(batch.batchId, owner);
    _transferFrom(batch.sourceToken, sender, address(this), amount);
    return amount;
  }

  /**
   * @notice This function checks all requirements for claiming, updates batches and balances and transfers tokens
   */

  function claim(
    bytes32 batchId,
    address owner,
    uint256 shares,
    address recipient
  ) public override onlyOwnerOf(batchId) returns (uint256, uint256) {
    Batch storage batch = batches[batchId];
    require(batch.claimable, "not yet claimable");

    uint256 claimAmount = shares == 0 ? accountBalances[batchId][owner] : shares;

    (uint256 claimableTokenBalance, uint256 claimAccountBalanceBefore, ) = previewClaim(batchId, owner, claimAmount);

    accountBalances[batchId][owner] -= claimAmount;
    batch.targetTokenBalance -= claimableTokenBalance;
    batch.unclaimedShares -= claimAmount;

    _transfer(batch.targetToken, owner, recipient, batchId, claimableTokenBalance);

    return (claimableTokenBalance, claimAccountBalanceBefore);
  }

  function previewClaim(
    bytes32 batchId,
    address owner,
    uint256 shares
  )
    public
    view
    override
    returns (
      uint256,
      uint256,
      uint256
    )
  {
    Batch memory batch = batches[batchId];
    uint256 claimAccountBalanceBefore = accountBalances[batchId][owner];

    require(shares <= batch.unclaimedShares && shares <= claimAccountBalanceBefore, "insufficient balance");

    uint256 targetTokenBalance = (batch.targetTokenBalance * shares) / batch.unclaimedShares;

    return (targetTokenBalance, claimAccountBalanceBefore, claimAccountBalanceBefore - shares);
  }

  /**
   * @notice Moves funds from unclaimed batches into the current mint/redeem batch
   * @param _sourceBatch the id of the claimable batch
   * @param _destinationBatch the id of the redeem batch
   * @param owner owner of the account balance
   * @param shares how many shares should be claimed
   */
  function moveUnclaimedIntoCurrentBatch(
    bytes32 _sourceBatch,
    bytes32 _destinationBatch,
    address owner,
    uint256 shares
  ) external override onlyOwnerOf(_sourceBatch) onlyOwnerOf(_destinationBatch) returns (uint256) {
    Batch storage sourceBatch = batches[_sourceBatch];
    Batch storage destinationBatch = batches[_destinationBatch];

    require(sourceBatch.claimable, "not yet claimable");
    require(sourceBatch.batchType != destinationBatch.batchType, "incorrect batchType");
    require(sourceBatch.targetToken == destinationBatch.sourceToken, "tokens don't match");

    (uint256 targetTokenBalance, ) = claim(_sourceBatch, owner, shares, address(0));
    return _deposit(destinationBatch, owner, targetTokenBalance, address(0));
  }

  /**
   * @notice This function allows a user to withdraw their funds from a batch before that batch has been processed
   * @param batchId From which batch should funds be withdrawn from
   * @param owner address that owns the account balance
   * @param amount amount of tokens to withdraw from batch
   * @param recipient address that will receive the token transfer. if address(0) then no transfer is made
   */
  function withdraw(
    bytes32 batchId,
    address owner,
    uint256 amount,
    address recipient
  ) public override onlyOwnerOf(batchId) returns (uint256) {
    // todo make this public so account owners can withdraw
    Batch storage batch = batches[batchId];
    require(accountBalances[batchId][owner] >= amount);
    require(batch.claimable == false, "already processed");

    //At this point the account balance is equal to the supplied token and can be used interchangeably
    accountBalances[batchId][owner] -= amount;
    batch.sourceTokenBalance -= amount;
    batch.unclaimedShares -= amount;

    _transfer(batch.sourceToken, owner, recipient, batchId, amount);
    return (amount);
  }

  /**
   * @notice approve allows the client contract to approve an address to be the recipient of a withdrawal or claim
   */
  function approve(
    IERC20 token,
    address delegatee,
    bytes32 batchId,
    uint256 amount
  ) external override(IAbstractBatchStorage) onlyOwnerOf(batchId) {
    allowances[msg.sender][delegatee][batchId][address(token)] = amount;
  }

  /**
   * @notice This function transfers the batch source tokens to the client usually for a minting or redeming operation
   * @param batchId From which batch should funds be withdrawn from
   */
  function withdrawSourceTokenFromBatch(bytes32 batchId)
    public
    override(IAbstractBatchStorage)
    onlyOwnerOf(batchId)
    returns (uint256)
  {
    Batch storage batch = batches[batchId];
    require(!batch.claimable, "already processed");
    batch.sourceToken.safeTransfer(msg.sender, batch.sourceTokenBalance);
    return (batch.sourceTokenBalance);
  }

  function depositTargetTokensIntoBatch(bytes32 batchId, uint256 amount)
    external
    override(IAbstractBatchStorage)
    onlyOwnerOf(batchId)
    returns (bool)
  {
    Batch storage batch = batches[batchId];
    require(!batch.claimable, "deposit already made"); // todo allow multiple deposits

    batch.targetToken.safeTransferFrom(msg.sender, address(this), amount);

    batch.claimable = true;
    batch.targetTokenBalance += amount;

    return true;
  }

  /* ========== INTERNAL ========== */

  /**
   * todo `clients` ultimately may withdraw tokens for a batch they create at anytime by calling withdrawSourceTokenFromBatch. tokens may be transfered out of this contract if the given recipient is a registered client or if the client has granted an allowance to a recipient to receive tokens. this means that in order to trust this contract, you must look at the clients because they can give themselves infinite allowance as a recipient of a target token from this contract. simply put, a rogue contract may infinite approve everything held by the contract and potentially send to itself.  any new client to this contract must be reviewed to ensure it does not make a claim or withdrawal for an address for which it should not. thought was given to designing this in a way to offer permissionless batch logic for any client, but greater attention would need to be given to scopes and boundaries. consider apodoting eip-1155 / eip-4626  standard interfaces for greater interoperability
   */
  function _transfer(
    IERC20 token,
    address owner,
    address recipient,
    bytes32 batchId,
    uint256 amount
  ) internal {
    if (recipient != address(0)) {
      Batch memory batch = batches[batchId];
      uint256 allowance = allowances[msg.sender][recipient][batchId][address(token)];
      bool hasAllowance = allowance >= amount;

      require(
        recipient == owner || hasAllowance || recipient == batch.owner || delegates[batch.owner][recipient],
        "won't send"
      );

      if (hasAllowance && allowance != 0) {
        allowances[msg.sender][recipient][batchId][address(token)] -= amount;
      }

      token.safeTransfer(recipient, amount);
    }
  }

  function _transferFrom(
    IERC20 token,
    address sender,
    address recipient,
    uint256 amount
  ) internal {
    if (sender != address(0) && recipient != address(0)) {
      token.safeTransferFrom(sender, recipient, amount);
    }
  }

  function _cacheAccount(bytes32 _id, address _owner) internal {
    //Save the batchId for the user so they can be retrieved to claim the batch
    if (accountBatches[_owner].length == 0 || accountBatches[_owner][accountBatches[_owner].length - 1] != _id) {
      accountBatches[_owner].push(_id);
    }
  }

  /**
   * @notice Generates the next batch id hashing the last batchId and timestamp
   */
  function _generateId() private view returns (bytes32) {
    bytes32 previousBatchId = batchIds.length > 0 ? batchIds[batchIds.length - 1] : bytes32("");
    return keccak256(abi.encodePacked(block.timestamp, previousBatchId));
  }
}

File 10 of 18 : AbstractClientAccess.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../../../utils/ContractRegistryAccess.sol";
import "../../../utils/ACLAuth.sol";
import "../../../interfaces/IACLRegistry.sol";
import "../../../interfaces/IContractRegistry.sol";
import "../../../interfaces/IBatchStorage.sol";
import "./Initializable.sol";

abstract contract AbstractClientAccess is ACLAuth, Initializable, ContractRegistryAccess, IClientBatchStorageAccess {
  // keccak("UPDATE_BATCH_STORAGE_CLIENT_ACTION")
  bytes32 constant UPDATE_BATCH_STORAGE_CLIENT_ACTION =
    0xb6f070e601e3563e164a63cf18567d22a74f31de2ff3f805afb7fa0c4d982e9c;

  constructor(IContractRegistry __contractRegistry, address _client) ContractRegistryAccess(__contractRegistry) {
    addClient(_client == address(0) ? msg.sender : _client);
    initialized = true;
  }

  /**
   * @dev  a mapping is made here when a client contract grants access to their batches to another client
   * owner => delegate => bool
   */
  mapping(address => mapping(address => bool)) public delegates;

  /**
   * @dev pendingClientAccessGrants contains mapping of current client to delegated clients that may accept a transfer after the given timestamp
   * client => newClient => validTransferAfter_timestamp
   */
  mapping(address => mapping(address => uint256)) public pendingClientAccessGrants;

  /**
   * @dev clients are allowed to use the batch storage contract. we allow many clients to use the batch contract. however, all batches are owned by the client which created the batch. clients have the ability to make claims / withdrawals and transfer tokens on behalf of depositors.
   */
  mapping(address => bool) public clients;

  function grantClientAccess(address newClient) external override onlyClients {
    pendingClientAccessGrants[msg.sender][newClient] = block.timestamp + 2 days;
  }

  function revokeClientAccess(address client) external override onlyClients {
    if (delegates[msg.sender][client]) {
      delegates[msg.sender][client] = false;
      clients[client] = false;
    }
  }

  function acceptClientAccess(address grantingAddress) external override {
    uint256 transferValidFrom = pendingClientAccessGrants[grantingAddress][msg.sender];
    require(transferValidFrom > 0 && transferValidFrom < block.timestamp, "access not valid");
    delegates[grantingAddress][msg.sender] = true;
    clients[msg.sender] = true;
  }

  /**
   * @notice DAO role can add any client. This is used to allow clients to use the batch storage contract.
   */
  function addClient(address _address) public override {
    bool hasPermission = acl().hasRole(DAO_ROLE, msg.sender) ||
      acl().hasPermission(UPDATE_BATCH_STORAGE_CLIENT_ACTION, msg.sender);
    if (!initialized || hasPermission) {
      clients[_address] = true;
    }
  }

  /**
   * @notice DAO role can remove any client. This is used to remove clients that are no longer using the batch storage contract. A client may remove itself by calling this function.
   */
  function removeClient(address _address) public override {
    bool hasPermission = acl().hasRole(DAO_ROLE, msg.sender) ||
      acl().hasPermission(UPDATE_BATCH_STORAGE_CLIENT_ACTION, msg.sender);
    if (hasPermission || (clients[msg.sender] && _address == msg.sender)) {
      clients[_address] = false;
    }
  }

  function acl() internal view returns (IACLRegistry) {
    return IACLRegistry(_getContract(keccak256("ACLRegistry")));
  }

  function _getContract(bytes32 _name)
    internal
    view
    virtual
    override(ACLAuth, ContractRegistryAccess)
    returns (address)
  {
    return IContractRegistry(_contractRegistry).getContract(_name);
  }

  modifier onlyClients() {
    _onlyClients();
    _;
  }

  function _onlyClients() internal view {
    require(clients[msg.sender], "!allowed");
  }
}

File 11 of 18 : AbstractViewableBatchStorage.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

import "../../../interfaces/IBatchStorage.sol";
import "./AbstractBatchStorage.sol";

abstract contract AbstractViewableBatchStorage {
  AbstractBatchStorage public batchStorage;

  constructor() {}

  /**
   * @notice Get ids for all batches that a user has interacted with
   * @param _account The address for whom we want to retrieve batches
   */
  function getAccountBatches(address _account) external view returns (bytes32[] memory) {
    return batchStorage.getAccountBatches(_account);
  }

  function getAccountBalance(bytes32 _id, address _owner) public view virtual returns (uint256) {
    return batchStorage.accountBalances(_id, _owner);
  }

  function getAccountBatchIds(address account) public view returns (bytes32[] memory) {
    return batchStorage.getAccountBatches(account);
  }

  function getBatch(bytes32 batchId) public view virtual returns (Batch memory) {
    return batchStorage.getBatch(batchId);
  }

  /* ========== VIEWS ========== */

  function getBatchType(bytes32 batchId) external view virtual returns (BatchType) {
    Batch memory batch = batchStorage.getBatch(batchId);
    require(batch.batchId != "");
    return batch.batchType;
  }
}

File 12 of 18 : Initializable.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

abstract contract Initializable {
  bool public initialized;
}

File 13 of 18 : IACLRegistry.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IACLRegistry {
  /**
   * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
   *
   * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
   * {RoleAdminChanged} not being emitted signaling this.
   *
   * _Available since v3.1._
   */
  event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

  /**
   * @dev Emitted when `account` is granted `role`.
   *
   * `sender` is the account that originated the contract call, an admin role
   * bearer except when using {AccessControl-_setupRole}.
   */
  event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

  /**
   * @dev Emitted when `account` is revoked `role`.
   *
   * `sender` is the account that originated the contract call:
   *   - if using `revokeRole`, it is the admin role bearer
   *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
   */
  event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

  /**
   * @dev Returns `true` if `account` has been granted `role`.
   */
  function hasRole(bytes32 role, address account) external view returns (bool);

  /**
   * @dev Returns `true` if `account` has been granted `permission`.
   */
  function hasPermission(bytes32 permission, address account) external view returns (bool);

  /**
   * @dev Returns the admin role that controls `role`. See {grantRole} and
   * {revokeRole}.
   *
   * To change a role's admin, use {AccessControl-_setRoleAdmin}.
   */
  function getRoleAdmin(bytes32 role) external view returns (bytes32);

  /**
   * @dev Grants `role` to `account`.
   *
   * If `account` had not been already granted `role`, emits a {RoleGranted}
   * event.
   *
   * Requirements:
   *
   * - the caller must have ``role``'s admin role.
   */
  function grantRole(bytes32 role, address account) external;

  /**
   * @dev Revokes `role` from `account`.
   *
   * If `account` had been granted `role`, emits a {RoleRevoked} event.
   *
   * Requirements:
   *
   * - the caller must have ``role``'s admin role.
   */
  function revokeRole(bytes32 role, address account) external;

  /**
   * @dev Revokes `role` from the calling account.
   *
   * Roles are often managed via {grantRole} and {revokeRole}: this function's
   * purpose is to provide a mechanism for accounts to lose their privileges
   * if they are compromised (such as when a trusted device is misplaced).
   *
   * If the calling account had been granted `role`, emits a {RoleRevoked}
   * event.
   *
   * Requirements:
   *
   * - the caller must be `account`.
   */
  function renounceRole(bytes32 role, address account) external;

  function setRoleAdmin(bytes32 role, bytes32 adminRole) external;

  function grantPermission(bytes32 permission, address account) external;

  function revokePermission(bytes32 permission) external;

  function requireApprovedContractOrEOA(address account) external view;

  function requireRole(bytes32 role, address account) external view;

  function requirePermission(bytes32 permission, address account) external view;

  function isRoleAdmin(bytes32 role, address account) external view;
}

File 14 of 18 : IBatchStorage.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IClientBatchStorageAccess } from "./IClientBatchStorageAccess.sol";
/**
 * @notice Defines if the Batch will mint or redeem 3X
 */
enum BatchType {
  Mint,
  Redeem
}

/**
 * @notice The Batch structure is used both for Batches of Minting and Redeeming
 * @param batchType Determines if this Batch is for Minting or Redeeming 3X
 * @param batchId bytes32 id of the batch
 * @param claimable Shows if a batch has been processed and is ready to be claimed, the suppliedToken cant be withdrawn if a batch is claimable
 * @param unclaimedShares The total amount of unclaimed shares in this batch
 * @param sourceTokenBalance The total amount of deposited token (either DAI or 3X)
 * @param claimableTokenBalance The total amount of claimable token (either sUSD or 3X)
 * @param sourceToken the token one supplies for minting/redeeming another token. the token collateral used to mint or redeem a mintable/redeemable token
 * @param targetToken the token that is claimable after providing the suppliedToken for mint/redeem. the token that a mintable/redeemable token turns into during mint/redeem
 * @param owner address of client (controller contract) that owns this batch and has access rights to it. this makes it so that all balances are isolated and not accessible by other clients that added to this contract over time
 * todo add deposit caps
 */
struct Batch {
  bytes32 id;
  BatchType batchType;
  bytes32 batchId;
  bool claimable;
  uint256 unclaimedShares;
  uint256 sourceTokenBalance;
  uint256 targetTokenBalance;
  IERC20 sourceToken;
  IERC20 targetToken;
  address owner;
}

/**
 * @notice Each type of batch (mint/redeem) have a source token and target token.
 * @param targetToken the token which is minted or redeemed for
 * @param sourceToken the token which is supplied to the batch to be minted/redeemed
 */
struct BatchTokens {
  IERC20 targetToken;
  IERC20 sourceToken;
}

interface IViewableBatchStorage {
  function getAccountBatches(address account) external view returns (bytes32[] memory);

  function getBatch(bytes32 batchId) external view returns (Batch memory);

  function getBatchIds(uint256 index) external view returns (Batch memory);

  function getAccountBalance(bytes32 batchId, address owner) external view returns (uint256);
}

interface IAbstractBatchStorage is IClientBatchStorageAccess {
  function getBatchType(bytes32 batchId) external view returns (BatchType);

  /* ========== VIEW ========== */

  function previewClaim(
    bytes32 batchId,
    address owner,
    uint256 shares
  )
    external
    view
    returns (
      uint256,
      uint256,
      uint256
    );

  /* ========== SETTER ========== */

  function claim(
    bytes32 batchId,
    address owner,
    uint256 shares,
    address recipient
  ) external returns (uint256, uint256);

  /**
   * @notice This function allows a user to withdraw their funds from a batch before that batch has been processed
   * @param batchId From which batch should funds be withdrawn from
   * @param owner address that owns the account balance
   * @param amount amount of tokens to withdraw from batch
   * @param recipient address that will receive the token transfer. if address(0) then no transfer is made
   */
  function withdraw(
    bytes32 batchId,
    address owner,
    uint256 amount,
    address recipient
  ) external returns (uint256);

  function deposit(
    bytes32 batchId,
    address owner,
    uint256 amount
  ) external returns (uint256);

  /**
   * @notice approve allows the client contract to approve an address to be the recipient of a withdrawal or claim
   */
  function approve(
    IERC20 token,
    address delegatee,
    bytes32 batchId,
    uint256 amount
  ) external;

  /**
   * @notice This function transfers the batch source tokens to the client usually for a minting or redeming operation
   * @param batchId From which batch should funds be withdrawn from
   */
  function withdrawSourceTokenFromBatch(bytes32 batchId) external returns (uint256);

  /**
   * @notice Moves funds from unclaimed batches into the current mint/redeem batch
   * @param _sourceBatch the id of the claimable batch
   * @param _destinationBatch the id of the redeem batch
   * @param owner owner of the account balance
   * @param shares how many shares should be claimed
   */
  function moveUnclaimedIntoCurrentBatch(
    bytes32 _sourceBatch,
    bytes32 _destinationBatch,
    address owner,
    uint256 shares
  ) external returns (uint256);

  function depositTargetTokensIntoBatch(bytes32 id, uint256 amount) external returns (bool);

  function createBatch(BatchType _batchType, BatchTokens memory _tokens) external returns (bytes32);
}

File 15 of 18 : IClientBatchStorageAccess.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

interface IClientBatchStorageAccess {
  function grantClientAccess(address newClient) external;

  function revokeClientAccess(address client) external;

  function acceptClientAccess(address grantingAddress) external;

  function addClient(address _address) external;

  function removeClient(address _address) external;
}

File 16 of 18 : IContractRegistry.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity >=0.6.12;

/**
 * @dev External interface of ContractRegistry.
 */
interface IContractRegistry {
  function getContract(bytes32 _name) external view returns (address);

  function getContractIdFromAddress(address _contractAddress) external view returns (bytes32);

  function addContract(
    bytes32 _name,
    address _address,
    bytes32 _version
  ) external;
}

File 17 of 18 : ACLAuth.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

import "../interfaces/IACLRegistry.sol";

/**
 *  @notice Provides modifiers and internal functions for interacting with the `ACLRegistry`
 *  @dev Derived contracts using `ACLAuth` must also inherit `ContractRegistryAccess`
 *   and override `_getContract`.
 */
abstract contract ACLAuth {
  /**
   *  @dev Equal to keccak256("Keeper")
   */
  bytes32 internal constant KEEPER_ROLE = 0x4f78afe9dfc9a0cb0441c27b9405070cd2a48b490636a7bdd09f355e33a5d7de;

  /**
   *  @dev Equal to keccak256("DAO")
   */
  bytes32 internal constant DAO_ROLE = 0xd0a4ad96d49edb1c33461cebc6fb2609190f32c904e3c3f5877edb4488dee91e;

  /**
   *  @dev Equal to keccak256("GUARDIAN_ROLE")
   */
  bytes32 internal constant GUARDIAN_ROLE = 0x55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041;

  /**
   *  @dev Equal to keccak256("ApprovedContract")
   */
  bytes32 internal constant APPROVED_CONTRACT_ROLE = 0xfb639edf4b4a4724b8b9fb42a839b712c82108c1edf1beb051bcebce8e689dc4;

  /**
   *  @dev Equal to keccak256("ACLRegistry")
   */
  bytes32 internal constant ACL_REGISTRY_ID = 0x15fa0125f52e5705da1148bfcf00974823c4381bee4314203ede255f9477b73e;

  /**
   *  @notice Require that `msg.sender` has given role
   *  @param role bytes32 role ID
   */
  modifier onlyRole(bytes32 role) {
    _requireRole(role);
    _;
  }

  /**
   *  @notice Require that `msg.sender` has at least one of the given roles
   *  @param roleA bytes32 role ID
   *  @param roleB bytes32 role ID
   */
  modifier onlyRoles(bytes32 roleA, bytes32 roleB) {
    require(_hasRole(roleA, msg.sender) == true || _hasRole(roleB, msg.sender) == true, "you dont have the right role");
    _;
  }

  /**
   *  @notice Require that `msg.sender` has given permission
   *  @param role bytes32 permission ID
   */
  modifier onlyPermission(bytes32 role) {
    _requirePermission(role);
    _;
  }

  /**
   *  @notice Require that `msg.sender` has the `ApprovedContract` role or is an EOA
   *  @dev This EOA check requires that `tx.origin == msg.sender` if caller does not have the `ApprovedContract` role.
   *  This limits compatibility with contract-based wallets for functions protected with this modifier.
   */
  modifier onlyApprovedContractOrEOA() {
    _requireApprovedContractOrEOA(msg.sender);
    _;
  }

  /**
   *  @notice Check whether a given account has been granted this bytes32 role
   *  @param role bytes32 role ID
   *  @param account address of account to check for role
   *  @return Whether account has been granted specified role.
   */
  function _hasRole(bytes32 role, address account) internal view returns (bool) {
    return _aclRegistry().hasRole(role, account);
  }

  /**
   *  @notice Require that `msg.sender` has given role
   *  @param role bytes32 role ID
   */
  function _requireRole(bytes32 role) internal view {
    _requireRole(role, msg.sender);
  }

  /**
   *  @notice Require that given account has specified role
   *  @param role bytes32 role ID
   *  @param account address of account to check for role
   */
  function _requireRole(bytes32 role, address account) internal view {
    _aclRegistry().requireRole(role, account);
  }

  /**
   *  @notice Check whether a given account has been granted this bytes32 permission
   *  @param permission bytes32 permission ID
   *  @param account address of account to check for permission
   *  @return Whether account has been granted specified permission.
   */
  function _hasPermission(bytes32 permission, address account) internal view returns (bool) {
    return _aclRegistry().hasPermission(permission, account);
  }

  /**
   *  @notice Require that `msg.sender` has specified permission
   *  @param permission bytes32 permission ID
   */
  function _requirePermission(bytes32 permission) internal view {
    _requirePermission(permission, msg.sender);
  }

  /**
   *  @notice Require that given account has specified permission
   *  @param permission bytes32 permission ID
   *  @param account address of account to check for permission
   */
  function _requirePermission(bytes32 permission, address account) internal view {
    _aclRegistry().requirePermission(permission, account);
  }

  /**
   *  @notice Require that `msg.sender` has the `ApprovedContract` role or is an EOA
   *  @dev This EOA check requires that `tx.origin == msg.sender` if caller does not have the `ApprovedContract` role.
   *  This limits compatibility with contract-based wallets for functions protected with this modifier.
   */
  function _requireApprovedContractOrEOA() internal view {
    _requireApprovedContractOrEOA(msg.sender);
  }

  /**
   *  @notice Require that `account` has the `ApprovedContract` role or is an EOA
   *  @param account address of account to check for role/EOA
   *  @dev This EOA check requires that `tx.origin == msg.sender` if caller does not have the `ApprovedContract` role.
   *  This limits compatibility with contract-based wallets for functions protected with this modifier.
   */
  function _requireApprovedContractOrEOA(address account) internal view {
    _aclRegistry().requireApprovedContractOrEOA(account);
  }

  /**
   *  @notice Return an IACLRegistry interface to the registered ACLRegistry contract
   *  @return IACLRegistry interface to ACLRegistry contract
   */
  function _aclRegistry() internal view returns (IACLRegistry) {
    return IACLRegistry(_getContract(ACL_REGISTRY_ID));
  }

  /**
   *  @notice Get a contract address by name from the contract registry
   *  @param _name bytes32 contract name
   *  @return contract address
   *  @dev Users of this abstract contract should also inherit from `ContractRegistryAccess`
   *   and override `_getContract` in their implementation.
   */
  function _getContract(bytes32 _name) internal view virtual returns (address);
}

File 18 of 18 : ContractRegistryAccess.sol
// SPDX-License-Identifier: GPL-3.0
// Docgen-SOLC: 0.8.0

pragma solidity ^0.8.0;

import "../interfaces/IContractRegistry.sol";

/**
 *  @notice Provides an internal `_getContract` helper function to access the `ContractRegistry`
 */
abstract contract ContractRegistryAccess {
  IContractRegistry internal _contractRegistry;

  constructor(IContractRegistry contractRegistry_) {
    require(address(contractRegistry_) != address(0), "Zero address");
    _contractRegistry = contractRegistry_;
  }

  /**
   *  @notice Get a contract address by bytes32 name
   *  @param _name bytes32 contract name
   *  @dev contract name should be a keccak256 hash of the name string, e.g. `keccak256("ContractName")`
   *  @return contract address
   */
  function _getContract(bytes32 _name) internal view virtual returns (address) {
    return _contractRegistry.getContract(_name);
  }

  /**
   *  @notice Get contract id from contract address.
   *  @param _contractAddress contract address
   *  @return name - keccak256 hash of the name string  e.g. `keccak256("ContractName")`
   */
  function _getContractIdFromAddress(address _contractAddress) internal view virtual returns (bytes32) {
    return _contractRegistry.getContractIdFromAddress(_contractAddress);
  }
}

Settings
{
  "evmVersion": "london",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 1000
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IContractRegistry","name":"_contractRegistry","type":"address"},{"internalType":"address","name":"client","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"grantingAddress","type":"address"}],"name":"acceptClientAccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"accountBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"accountBatches","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"addClient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"allowances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"delegatee","type":"address"},{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"batchIds","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"batches","outputs":[{"internalType":"bytes32","name":"id","type":"bytes32"},{"internalType":"enum BatchType","name":"batchType","type":"uint8"},{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"bool","name":"claimable","type":"bool"},{"internalType":"uint256","name":"unclaimedShares","type":"uint256"},{"internalType":"uint256","name":"sourceTokenBalance","type":"uint256"},{"internalType":"uint256","name":"targetTokenBalance","type":"uint256"},{"internalType":"contract IERC20","name":"sourceToken","type":"address"},{"internalType":"contract IERC20","name":"targetToken","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"claim","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"clients","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contractId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum BatchType","name":"_batchType","type":"uint8"},{"components":[{"internalType":"contract IERC20","name":"targetToken","type":"address"},{"internalType":"contract IERC20","name":"sourceToken","type":"address"}],"internalType":"struct BatchTokens","name":"_tokens","type":"tuple"}],"name":"createBatch","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"delegates","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositTargetTokensIntoBatch","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"address","name":"_account","type":"address"}],"name":"getAccountBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"getAccountBatches","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"}],"name":"getBatch","outputs":[{"components":[{"internalType":"bytes32","name":"id","type":"bytes32"},{"internalType":"enum BatchType","name":"batchType","type":"uint8"},{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"bool","name":"claimable","type":"bool"},{"internalType":"uint256","name":"unclaimedShares","type":"uint256"},{"internalType":"uint256","name":"sourceTokenBalance","type":"uint256"},{"internalType":"uint256","name":"targetTokenBalance","type":"uint256"},{"internalType":"contract IERC20","name":"sourceToken","type":"address"},{"internalType":"contract IERC20","name":"targetToken","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"internalType":"struct Batch","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"}],"name":"getBatchType","outputs":[{"internalType":"enum BatchType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newClient","type":"address"}],"name":"grantClientAccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_sourceBatch","type":"bytes32"},{"internalType":"bytes32","name":"_destinationBatch","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"moveUnclaimedIntoCurrentBatch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"pendingClientAccessGrants","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"removeClient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"client","type":"address"}],"name":"revokeClientAccess","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"batchId","type":"bytes32"}],"name":"withdrawSourceTokenFromBatch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c806361eed2a911610104578063c81e25ab116100a2578063ed09e19d11610071578063ed09e19d14610527578063ed42136f14610552578063f030024814610572578063f893a7cd1461058557600080fd5b8063c81e25ab14610449578063d030d2b3146104d3578063d954863c146104e6578063e5843242146104f957600080fd5b80639089f616116100de5780639089f616146103b65780639db95d05146103c9578063b3d346b9146103fc578063c53afcb71461040f57600080fd5b806361eed2a91461037757806368284a9c1461039a5780638291286c146103ad57600080fd5b8063348a355f116101715780634a7603d81161014b5780634a7603d8146102db5780635a0f03c5146103115780635ad8c65a1461033c5780635eddd9c91461036457600080fd5b8063348a355f1461029457806341b2ce61146102a757806343928cfd146102c857600080fd5b8063158ef93e116101ad578063158ef93e1461023f5780631f2576e01461024c57806326bc8b4f1461026157806328d3ef0b1461027457600080fd5b806305b27585146101d457806306fdde03146101fc578063155ab55214610211575b600080fd5b6101e76101e2366004612340565b610598565b60405190151581526020015b60405180910390f35b61020461070c565b6040516101f3919061238e565b61022461021f3660046123d6565b61079a565b604080519384526020840192909252908201526060016101f3565b6000546101e79060ff1681565b61025f61025a36600461240e565b610926565b005b61025f61026f36600461240e565b61099b565b61028761028236600461240e565b6109da565b6040516101f3919061242b565b61025f6102a236600461240e565b610a46565b6102ba6102b536600461246f565b610b06565b6040519081526020016101f3565b61025f6102d636600461240e565b610bf1565b6102ba6102e9366004612509565b60009182526004602090815260408084206001600160a01b0393909316845291905290205490565b6102ba61031f366004612539565b600260209081526000928352604080842090915290825290205481565b61034f61034a366004612567565b610d68565b604080519283526020830191909152016101f3565b61025f6103723660046125b1565b610f78565b6101e761038536600461240e565b60036020526000908152604090205460ff1681565b6102ba6103a8366004612567565b61106e565b6102ba60095481565b61025f6103c436600461240e565b611247565b6103ef6103d73660046125f7565b60009081526006602052604090206001015460ff1690565b6040516101f39190612648565b6102ba61040a3660046125f7565b6113d6565b6102ba61041d366004612656565b600860209081526000948552604080862082529385528385208152918452828420909152825290205481565b6104bd6104573660046125f7565b60066020819052600091825260409091208054600182015460028301546003840154600485015460058601549686015460078701546008880154600990980154969860ff9687169895979690941695929491926001600160a01b0391821692821691168a565b6040516101f39a99989796959493929190612687565b6102ba6104e13660046126eb565b6113f7565b6102ba6104f43660046123d6565b611428565b6101e7610507366004612539565b600160209081526000928352604080842090915290825290205460ff1681565b6102ba610535366004612509565b600460209081526000928352604080842090915290825290205481565b6105656105603660046125f7565b611506565b6040516101f39190612717565b6102ba6105803660046127bc565b611616565b6102ba6105933660046125f7565b611900565b6000826105a3611a49565b600081815260066020526040902060098101546001600160a01b03163314806105f3575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b6106565760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b60648201526084015b60405180910390fd5b6000858152600660205260409020600381015460ff16156106b95760405162461bcd60e51b815260206004820152601460248201527f6465706f73697420616c7265616479206d616465000000000000000000000000604482015260640161064d565b60088101546106d3906001600160a01b0316333088611aaa565b60038101805460ff191660011790556006810180548691906000906106f9908490612811565b909155506001945050505b505092915050565b600a805461071990612829565b80601f016020809104026020016040519081016040528092919081815260200182805461074590612829565b80156107925780601f1061076757610100808354040283529160200191610792565b820191906000526020600020905b81548152906001019060200180831161077557829003601f168201915b505050505081565b60008381526006602090815260408083208151610140810190925280548252600180820154859485948594909390929184019160ff16908111156107e0576107e0612610565b60018111156107f1576107f1612610565b81526002820154602080830191909152600383015460ff16151560408084019190915260048085015460608501526005850154608080860191909152600686015460a086015260078601546001600160a01b0390811660c08701526008870154811660e087015260099096015486166101009095019490945260008d8152908352818120948c1681529390915290912054908201519192509086118015906108995750808611155b6108e55760405162461bcd60e51b815260206004820152601460248201527f696e73756666696369656e742062616c616e6365000000000000000000000000604482015260640161064d565b60008260800151878460c001516108fc9190612863565b6109069190612882565b9050808261091489826128a4565b95509550955050505093509350939050565b61092e611a49565b3360009081526001602090815260408083206001600160a01b038516845290915290205460ff1615610998573360009081526001602090815260408083206001600160a01b03851684528252808320805460ff199081169091556003909252909120805490911690555b50565b6109a3611a49565b6109b0426202a300612811565b3360009081526002602090815260408083206001600160a01b039590951683529390529190912055565b6001600160a01b038116600090815260056020908152604091829020805483518184028101840190945280845260609392830182828015610a3a57602002820191906000526020600020905b815481526020019060010190808311610a26575b50505050509050919050565b6001600160a01b03811660009081526002602090815260408083203384529091529020548015801590610a7857504281105b610ac45760405162461bcd60e51b815260206004820152601060248201527f616363657373206e6f742076616c696400000000000000000000000000000000604482015260640161064d565b506001600160a01b031660009081526001602081815260408084203385528252808420805460ff19908116851790915560039092529092208054909216179055565b6000610b10611a49565b6000610b1a611b61565b6007805460018181019092557fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801829055600082815260066020526040902080820180549394509092879260ff19909116908381811115610b7d57610b7d612610565b02179055506002810182905560208401516007820180546001600160a01b039283167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915585516008840180549190931690821617909155600990910180549091163317905590505b92915050565b6000610bfb611bd2565b604051632474521560e21b81527fd0a4ad96d49edb1c33461cebc6fb2609190f32c904e3c3f5877edb4488dee91e60048201523360248201526001600160a01b0391909116906391d1485490604401602060405180830381865afa158015610c67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c8b91906128bb565b80610d295750610c99611bd2565b6040516328545c0d60e01b81527fb6f070e601e3563e164a63cf18567d22a74f31de2ff3f805afb7fa0c4d982e9c60048201523360248201526001600160a01b0391909116906328545c0d90604401602060405180830381865afa158015610d05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2991906128bb565b60005490915060ff161580610d3b5750805b15610d64576001600160a01b0382166000908152600360205260409020805460ff191660011790555b5050565b60008085610d74611a49565b600081815260066020526040902060098101546001600160a01b0316331480610dc4575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b610e225760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b6000888152600660205260409020600381015460ff16610e845760405162461bcd60e51b815260206004820152601160248201527f6e6f742079657420636c61696d61626c65000000000000000000000000000000604482015260640161064d565b60008715610e925787610eb6565b60008a81526004602090815260408083206001600160a01b038d1684529091529020545b9050600080610ec68c8c8561079a565b509150915082600460008e815260200190815260200160002060008d6001600160a01b03166001600160a01b031681526020019081526020016000206000828254610f1191906128a4565b9250508190555081846006016000828254610f2c91906128a4565b9250508190555082846004016000828254610f4791906128a4565b90915550506008840154610f67906001600160a01b03168c8b8f86611c02565b909b909a5098505050505050505050565b81610f81611a49565b600081815260066020526040902060098101546001600160a01b0316331480610fd1575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b61102f5760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b50503360009081526008602090815260408083206001600160a01b03968716845282528083209483529381528382209590941681529390925290912055565b600084611079611a49565b600081815260066020526040902060098101546001600160a01b03163314806110c9575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b6111275760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b6000878152600660209081526040808320600483528184206001600160a01b038b1685529092529091205486111561115e57600080fd5b600381015460ff16156111b35760405162461bcd60e51b815260206004820152601160248201527f616c72656164792070726f636573736564000000000000000000000000000000604482015260640161064d565b60008881526004602090815260408083206001600160a01b038b168452909152812080548892906111e59084906128a4565b925050819055508581600501600082825461120091906128a4565b925050819055508581600401600082825461121b91906128a4565b9091555050600781015461123b906001600160a01b031688878b8a611c02565b50939695505050505050565b6000611251611bd2565b604051632474521560e21b81527fd0a4ad96d49edb1c33461cebc6fb2609190f32c904e3c3f5877edb4488dee91e60048201523360248201526001600160a01b0391909116906391d1485490604401602060405180830381865afa1580156112bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112e191906128bb565b8061137f57506112ef611bd2565b6040516328545c0d60e01b81527fb6f070e601e3563e164a63cf18567d22a74f31de2ff3f805afb7fa0c4d982e9c60048201523360248201526001600160a01b0391909116906328545c0d90604401602060405180830381865afa15801561135b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137f91906128bb565b905080806113af57503360009081526003602052604090205460ff1680156113af57506001600160a01b03821633145b15610d6457506001600160a01b03166000908152600360205260409020805460ff19169055565b600781815481106113e657600080fd5b600091825260209091200154905081565b6005602052816000526040600020818154811061141357600080fd5b90600052602060002001600091509150505481565b600083611433611a49565b600081815260066020526040902060098101546001600160a01b0316331480611483575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b6114e15760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b60008681526006602052604090206114fb81878733611e37565b979650505050505050565b6040805161014081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081018290526101208101919091526000828152600660209081526040918290208251610140810190935280548352600180820154919284019160ff169081111561159557611595612610565b60018111156115a6576115a6612610565b815260028201546020820152600382015460ff16151560408201526004820154606082015260058201546080820152600682015460a082015260078201546001600160a01b0390811660c08301526008830154811660e08301526009909201549091166101009091015292915050565b600084611621611a49565b600081815260066020526040902060098101546001600160a01b0316331480611671575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b6116cf5760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b856116d8611a49565b600081815260066020526040902060098101546001600160a01b0316331480611728575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b6117865760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b6000898152600660205260408082208a83529120600382015460ff166117ee5760405162461bcd60e51b815260206004820152601160248201527f6e6f742079657420636c61696d61626c65000000000000000000000000000000604482015260640161064d565b60018082015460ff169081111561180757611807612610565b60018084015460ff169081111561182057611820612610565b0361186d5760405162461bcd60e51b815260206004820152601360248201527f696e636f72726563742062617463685479706500000000000000000000000000604482015260640161064d565b600781015460088301546001600160a01b039081169116146118d15760405162461bcd60e51b815260206004820152601260248201527f746f6b656e7320646f6e2774206d617463680000000000000000000000000000604482015260640161064d565b60006118e08c8b8b6000610d68565b5090506118f0828b836000611e37565b9c9b505050505050505050505050565b60008161190b611a49565b600081815260066020526040902060098101546001600160a01b031633148061195b575060098101546001600160a01b0316600090815260016020908152604080832033845290915290205460ff165b6119b95760405162461bcd60e51b815260206004820152602960248201527f636c69656e7420646f6573206e6f7420686176652061636365737320746f20746044820152680d0d2e640c4c2e8c6d60bb1b606482015260840161064d565b6000848152600660205260409020600381015460ff1615611a1c5760405162461bcd60e51b815260206004820152601160248201527f616c72656164792070726f636573736564000000000000000000000000000000604482015260640161064d565b60058101546007820154611a3d916001600160a01b03909116903390611f31565b60050154949350505050565b3360009081526003602052604090205460ff16611aa85760405162461bcd60e51b815260206004820152600860248201527f21616c6c6f776564000000000000000000000000000000000000000000000000604482015260640161064d565b565b6040516001600160a01b0380851660248301528316604482015260648101829052611b5b9085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152611f7f565b50505050565b6007546000908190611b74576000611ba0565b60078054611b84906001906128a4565b81548110611b9457611b946128dd565b90600052602060002001545b604080514260208201529081018290529091506060016040516020818303038152906040528051906020012091505090565b6000611bfd7f15fa0125f52e5705da1148bfcf00974823c4381bee4314203ede255f9477b73e612064565b905090565b6001600160a01b03831615611e305760008281526006602090815260408083208151610140810190925280548252600180820154929391929184019160ff1690811115611c5157611c51612610565b6001811115611c6257611c62612610565b81526002820154602080830191909152600383015460ff1615156040808401919091526004840154606084015260058401546080840152600684015460a084015260078401546001600160a01b0390811660c0850152600880860154821660e086015260099095015481166101009094019390935233600090815293825280842089841680865290835281852089865283528185208c851686529092529092205492935084831015919088161480611d175750805b80611d3857508261012001516001600160a01b0316866001600160a01b0316145b80611d6e57506101208301516001600160a01b039081166000908152600160209081526040808320938a168352929052205460ff165b611dba5760405162461bcd60e51b815260206004820152600a60248201527f776f6e27742073656e6400000000000000000000000000000000000000000000604482015260640161064d565b808015611dc657508115155b15611e18573360009081526008602090815260408083206001600160a01b038a811685529083528184208985528352818420908c16845290915281208054869290611e129084906128a4565b90915550505b611e2c6001600160a01b0389168786611f31565b5050505b5050505050565b600384015460009060ff1615611e8f5760405162461bcd60e51b815260206004820152600d60248201527f63616e2774206465706f73697400000000000000000000000000000000000000604482015260640161064d565b82856005016000828254611ea39190612811565b9250508190555082856004016000828254611ebe9190612811565b9091555050600285015460009081526004602090815260408083206001600160a01b038816845290915281208054859290611efa908490612811565b90915550506002850154611f0e90856120ef565b6007850154611f28906001600160a01b0316833086612185565b50909392505050565b6040516001600160a01b038316602482015260448101829052611f7a9084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401611af7565b505050565b6000611fd4826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166121bf9092919063ffffffff16565b805190915015611f7a5780806020019051810190611ff291906128bb565b611f7a5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161064d565b600080546040517fe16c7d98000000000000000000000000000000000000000000000000000000008152600481018490526101009091046001600160a01b03169063e16c7d9890602401602060405180830381865afa1580156120cb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610beb91906128f3565b6001600160a01b038116600090815260056020526040902054158061215657506001600160a01b03811660009081526005602052604090208054839190612138906001906128a4565b81548110612148576121486128dd565b906000526020600020015414155b15610d64576001600160a01b031660009081526005602090815260408220805460018101825590835291200155565b6001600160a01b038316158015906121a557506001600160a01b03821615155b15611b5b57611b5b6001600160a01b038516848484611aaa565b60606121ce84846000856121d8565b90505b9392505050565b6060824710156122505760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161064d565b843b61229e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161064d565b600080866001600160a01b031685876040516122ba9190612910565b60006040518083038185875af1925050503d80600081146122f7576040519150601f19603f3d011682016040523d82523d6000602084013e6122fc565b606091505b50915091506114fb828286606083156123165750816121d1565b8251156123265782518084602001fd5b8160405162461bcd60e51b815260040161064d919061238e565b6000806040838503121561235357600080fd5b50508035926020909101359150565b60005b8381101561237d578181015183820152602001612365565b83811115611b5b5750506000910152565b60208152600082518060208401526123ad816040850160208701612362565b601f01601f19169190910160400192915050565b6001600160a01b038116811461099857600080fd5b6000806000606084860312156123eb57600080fd5b8335925060208401356123fd816123c1565b929592945050506040919091013590565b60006020828403121561242057600080fd5b81356121d1816123c1565b6020808252825182820181905260009190848201906040850190845b8181101561246357835183529284019291840191600101612447565b50909695505050505050565b600080828403606081121561248357600080fd5b83356002811061249257600080fd5b92506040601f19820112156124a657600080fd5b506040516040810181811067ffffffffffffffff821117156124d857634e487b7160e01b600052604160045260246000fd5b60405260208401356124e9816123c1565b815260408401356124f9816123c1565b6020820152919491935090915050565b6000806040838503121561251c57600080fd5b82359150602083013561252e816123c1565b809150509250929050565b6000806040838503121561254c57600080fd5b8235612557816123c1565b9150602083013561252e816123c1565b6000806000806080858703121561257d57600080fd5b84359350602085013561258f816123c1565b92506040850135915060608501356125a6816123c1565b939692955090935050565b600080600080608085870312156125c757600080fd5b84356125d2816123c1565b935060208501356125e2816123c1565b93969395505050506040820135916060013590565b60006020828403121561260957600080fd5b5035919050565b634e487b7160e01b600052602160045260246000fd5b6002811061264457634e487b7160e01b600052602160045260246000fd5b9052565b60208101610beb8284612626565b6000806000806080858703121561266c57600080fd5b8435612677816123c1565b9350602085013561258f816123c1565b8a8152610140810161269c602083018c612626565b60408201999099529615156060880152608087019590955260a086019390935260c08501919091526001600160a01b0390811660e0850152908116610100840152166101209091015292915050565b600080604083850312156126fe57600080fd5b8235612709816123c1565b946020939093013593505050565b8151815260208083015161014083019161273390840182612626565b50604083015160408301526060830151612751606084018215159052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015161278a60e08401826001600160a01b03169052565b50610100838101516001600160a01b038116848301525050610120838101516001600160a01b03811684830152610704565b600080600080608085870312156127d257600080fd5b843593506020850135925060408501356127eb816123c1565b9396929550929360600135925050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612824576128246127fb565b500190565b600181811c9082168061283d57607f821691505b60208210810361285d57634e487b7160e01b600052602260045260246000fd5b50919050565b600081600019048311821515161561287d5761287d6127fb565b500290565b60008261289f57634e487b7160e01b600052601260045260246000fd5b500490565b6000828210156128b6576128b66127fb565b500390565b6000602082840312156128cd57600080fd5b815180151581146121d157600080fd5b634e487b7160e01b600052603260045260246000fd5b60006020828403121561290557600080fd5b81516121d1816123c1565b60008251612922818460208701612362565b919091019291505056fea2646970667358221220690623e64064fe1f007130e4ca03635ca2b361f7b1a642f332c98d5ab2179dfa64736f6c634300080d0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.