Skip to content
Verified contractPartialMIT

TransferGuard

Address0xc65ada73d983c21b67c60d79e4f8e8a0eccbc781
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.35

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.35+commit.47b9dedd
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,499,931
Creation transaction
0x52fb1d2834…127abd6ffe

contracts/solverVault/guards/TransferGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC20} from '@openzeppelin/token/ERC20/IERC20.sol';
import {IVaultGuard} from '../IVaultGuard.sol';

/**
 * @title TransferGuard
 * @notice Lets a {SolverVault} send ERC20s (`transfer`) or native (empty calldata) only to a fixed set
 * of deposit addresses we own, such as our NEAR Intents account's POA bridge deposit address.
 * @dev The set is fixed at deployment. To change it, deploy a new guard and re-register it. POA deposit
 * addresses are derived per NEAR account and are the same on every EVM chain, so identical constructor
 * arguments work everywhere.
 *
 * Register it for `(token, IERC20.transfer.selector)` for each token we deposit, and for
 * `(recipient, 0x00000000)` for native deposits. Which tokens a venue credits, and its minimums, are the
 * signer's policy: a token the venue doesn't list is lost once sent.
 */
contract TransferGuard is IVaultGuard {
    mapping(address => bool) public isRecipient;

    constructor(address[] memory recipients) {
        require(recipients.length > 0, 'No recipients');
        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), 'Invalid recipient');
            isRecipient[recipients[i]] = true;
        }
    }

    function check(address, address target, uint256 value, bytes calldata data) external view {
        if (data.length == 0) {
            require(isRecipient[target], 'Recipient not allowed');
            return;
        }
        require(bytes4(data[:4]) == IERC20.transfer.selector, 'Selector not allowed');
        require(value == 0, 'No value');
        (address to,) = abi.decode(data[4:], (address, uint256));
        require(isRecipient[to], 'Recipient not allowed');
    }

    /// @dev This call moves vault funds out; it always needs a signature.
    function permissionlessSafe(address, bytes4) external pure returns (bool) {
        return false;
    }
}

contracts/solverVault/IVaultGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @notice An ERC20 allowance one {SolverVault-execute} call grants its target, restored to its prior value after.
struct Approval {
    address token;
    uint256 amount;
}

/**
 * @notice Venue rules for one `(target, selector)` the vault may call. Reverts to reject.
 * @dev The vault enforces what is generic (auth, replay, call-scoped approvals). A guard enforces what
 * only the calldata shows: above all, that any claim, repayment or deposit the call creates lands at
 * an address we control. Amounts are the signer's policy.
 */
interface IVaultGuard {
    function check(address vault, address target, uint256 value, bytes calldata data) external view;

    /// @notice Whether anyone may trigger `(target, selector)` without a signature, through
    /// {SolverVault-executePermissionless}. Only for calls that send nothing out of the vault and land every
    /// proceed in it (e.g. OIF `finalise`). Never for anything that pulls vault funds, such as a fill: the vault
    /// may hold a standing approval to that target.
    function permissionlessSafe(address target, bytes4 selector) external view returns (bool);
}

lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "@openzeppelin-upgradeable/proxy/=lib/openzeppelin-contracts-upgradeable/contracts/proxy/",
    "@openzeppelin-upgradeable/access/=lib/openzeppelin-contracts-upgradeable/contracts/access/",
    "@openzeppelin-upgradeable/token/=lib/openzeppelin-contracts-upgradeable/contracts/token/",
    "@openzeppelin-upgradeable/utils/=lib/openzeppelin-contracts-upgradeable/contracts/utils/",
    "openzeppelin-contracts/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/token/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/",
    "@openzeppelin/proxy/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/",
    "@openzeppelin/access/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/",
    "@openzeppelin/interfaces/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/interfaces/",
    "@openzeppelin/utils/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/",
    "@openzeppelin/governance/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/governance/",
    "@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
    "@layerzerolabs/lz-evm-oapp-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/oapp/",
    "@layerzerolabs/lz-evm-protocol-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/protocol/",
    "@layerzerolabs/lz-evm-messagelib-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/messagelib/",
    "@pythnetwork/=lib/pyth-sdk-solidity/",
    "@money-market/=contracts/moneyMarket/src/",
    "@money-market-scripts/=contracts/moneyMarket/scripts/",
    "@money-market-tests/=contracts/moneyMarket/tests/",
    "@contracts/=contracts/",
    "solidity-utils/=lib/solidity-utils/src/",
    "@pyth-lazer/=lib/pyth-crosschain/lazer/contracts/evm/src/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.