PeggedTokenBridgeV2

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/security/Pausable.sol": {
      "content": "// 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());
    }
}
"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// 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;
    }
}
"
    },
    "contracts/interfaces/IPeggedToken.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity >=0.8.0;\r
\r
interface IPeggedToken {\r
    function mint(address _to, uint256 _amount) external;\r
\r
    function burn(address _from, uint256 _amount) external;\r
}\r
"
    },
    "contracts/interfaces/IPeggedTokenBurnFrom.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity >=0.8.0;\r
\r
// used for pegged token with openzeppelin ERC20Burnable interface\r
// only compatible with PeggedTokenBridgeV2\r
interface IPeggedTokenBurnFrom {\r
    function mint(address _to, uint256 _amount) external;\r
\r
    function burnFrom(address _from, uint256 _amount) external;\r
}\r
"
    },
    "contracts/interfaces/ISigsVerifier.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity >=0.8.0;\r
\r
interface ISigsVerifier {\r
    /**\r
     * @notice Verifies that a message is signed by a quorum among the signers.\r
     * @param _msg signed message\r
     * @param _sigs list of signatures sorted by signer addresses in ascending order\r
     * @param _signers sorted list of current signers\r
     * @param _powers powers of current signers\r
     */\r
    function verifySigs(\r
        bytes memory _msg,\r
        bytes[] calldata _sigs,\r
        address[] calldata _signers,\r
        uint256[] calldata _powers\r
    ) external view;\r
}\r
"
    },
    "contracts/libraries/Pb.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity 0.8.17;\r
\r
// runtime proto sol library\r
library Pb {\r
    enum WireType {\r
        Varint,\r
        Fixed64,\r
        LengthDelim,\r
        StartGroup,\r
        EndGroup,\r
        Fixed32\r
    }\r
\r
    struct Buffer {\r
        uint256 idx; // the start index of next read. when idx=b.length, we're done\r
        bytes b; // hold serialized proto msg, readonly\r
    }\r
\r
    // create a new in-memory Buffer object from raw msg bytes\r
    function fromBytes(bytes memory raw) internal pure returns (Buffer memory buf) {\r
        buf.b = raw;\r
        buf.idx = 0;\r
    }\r
\r
    // whether there are unread bytes\r
    function hasMore(Buffer memory buf) internal pure returns (bool) {\r
        return buf.idx < buf.b.length;\r
    }\r
\r
    // decode current field number and wiretype\r
    function decKey(Buffer memory buf) internal pure returns (uint256 tag, WireType wiretype) {\r
        uint256 v = decVarint(buf);\r
        tag = v / 8;\r
        wiretype = WireType(v & 7);\r
    }\r
\r
    // count tag occurrences, return an array due to no memory map support\r
    // have to create array for (maxtag+1) size. cnts[tag] = occurrences\r
    // should keep buf.idx unchanged because this is only a count function\r
    function cntTags(Buffer memory buf, uint256 maxtag) internal pure returns (uint256[] memory cnts) {\r
        uint256 originalIdx = buf.idx;\r
        cnts = new uint256[](maxtag + 1); // protobuf's tags are from 1 rather than 0\r
        uint256 tag;\r
        WireType wire;\r
        while (hasMore(buf)) {\r
            (tag, wire) = decKey(buf);\r
            cnts[tag] += 1;\r
            skipValue(buf, wire);\r
        }\r
        buf.idx = originalIdx;\r
    }\r
\r
    // read varint from current buf idx, move buf.idx to next read, return the int value\r
    function decVarint(Buffer memory buf) internal pure returns (uint256 v) {\r
        bytes10 tmp; // proto int is at most 10 bytes (7 bits can be used per byte)\r
        bytes memory bb = buf.b; // get buf.b mem addr to use in assembly\r
        v = buf.idx; // use v to save one additional uint variable\r
        assembly {\r
            tmp := mload(add(add(bb, 32), v)) // load 10 bytes from buf.b[buf.idx] to tmp\r
        }\r
        uint256 b; // store current byte content\r
        v = 0; // reset to 0 for return value\r
        for (uint256 i = 0; i < 10; i++) {\r
            assembly {\r
                b := byte(i, tmp) // don't use tmp[i] because it does bound check and costs extra\r
            }\r
            v |= (b & 0x7F) << (i * 7);\r
            if (b & 0x80 == 0) {\r
                buf.idx += i + 1;\r
                return v;\r
            }\r
        }\r
        revert(); // i=10, invalid varint stream\r
    }\r
\r
    // read length delimited field and return bytes\r
    function decBytes(Buffer memory buf) internal pure returns (bytes memory b) {\r
        uint256 len = decVarint(buf);\r
        uint256 end = buf.idx + len;\r
        require(end <= buf.b.length); // avoid overflow\r
        b = new bytes(len);\r
        bytes memory bufB = buf.b; // get buf.b mem addr to use in assembly\r
        uint256 bStart;\r
        uint256 bufBStart = buf.idx;\r
        assembly {\r
            bStart := add(b, 32)\r
            bufBStart := add(add(bufB, 32), bufBStart)\r
        }\r
        for (uint256 i = 0; i < len; i += 32) {\r
            assembly {\r
                mstore(add(bStart, i), mload(add(bufBStart, i)))\r
            }\r
        }\r
        buf.idx = end;\r
    }\r
\r
    // return packed ints\r
    function decPacked(Buffer memory buf) internal pure returns (uint256[] memory t) {\r
        uint256 len = decVarint(buf);\r
        uint256 end = buf.idx + len;\r
        require(end <= buf.b.length); // avoid overflow\r
        // array in memory must be init w/ known length\r
        // so we have to create a tmp array w/ max possible len first\r
        uint256[] memory tmp = new uint256[](len);\r
        uint256 i = 0; // count how many ints are there\r
        while (buf.idx < end) {\r
            tmp[i] = decVarint(buf);\r
            i++;\r
        }\r
        t = new uint256[](i); // init t with correct length\r
        for (uint256 j = 0; j < i; j++) {\r
            t[j] = tmp[j];\r
        }\r
        return t;\r
    }\r
\r
    // move idx pass current value field, to beginning of next tag or msg end\r
    function skipValue(Buffer memory buf, WireType wire) internal pure {\r
        if (wire == WireType.Varint) {\r
            decVarint(buf);\r
        } else if (wire == WireType.LengthDelim) {\r
            uint256 len = decVarint(buf);\r
            buf.idx += len; // skip len bytes value data\r
            require(buf.idx <= buf.b.length); // avoid overflow\r
        } else {\r
            revert();\r
        } // unsupported wiretype\r
    }\r
\r
    // type conversion help utils\r
    function _bool(uint256 x) internal pure returns (bool v) {\r
        return x != 0;\r
    }\r
\r
    function _uint256(bytes memory b) internal pure returns (uint256 v) {\r
        require(b.length <= 32); // b's length must be smaller than or equal to 32\r
        assembly {\r
            v := mload(add(b, 32))\r
        } // load all 32bytes to v\r
        v = v >> (8 * (32 - b.length)); // only first b.length is valid\r
    }\r
\r
    function _address(bytes memory b) internal pure returns (address v) {\r
        v = _addressPayable(b);\r
    }\r
\r
    function _addressPayable(bytes memory b) internal pure returns (address payable v) {\r
        require(b.length == 20);\r
        //load 32bytes then shift right 12 bytes\r
        assembly {\r
            v := div(mload(add(b, 32)), 0x1000000000000000000000000)\r
        }\r
    }\r
\r
    function _bytes32(bytes memory b) internal pure returns (bytes32 v) {\r
        require(b.length == 32);\r
        assembly {\r
            v := mload(add(b, 32))\r
        }\r
    }\r
\r
    // uint[] to uint8[]\r
    function uint8s(uint256[] memory arr) internal pure returns (uint8[] memory t) {\r
        t = new uint8[](arr.length);\r
        for (uint256 i = 0; i < t.length; i++) {\r
            t[i] = uint8(arr[i]);\r
        }\r
    }\r
\r
    function uint32s(uint256[] memory arr) internal pure returns (uint32[] memory t) {\r
        t = new uint32[](arr.length);\r
        for (uint256 i = 0; i < t.length; i++) {\r
            t[i] = uint32(arr[i]);\r
        }\r
    }\r
\r
    function uint64s(uint256[] memory arr) internal pure returns (uint64[] memory t) {\r
        t = new uint64[](arr.length);\r
        for (uint256 i = 0; i < t.length; i++) {\r
            t[i] = uint64(arr[i]);\r
        }\r
    }\r
\r
    function bools(uint256[] memory arr) internal pure returns (bool[] memory t) {\r
        t = new bool[](arr.length);\r
        for (uint256 i = 0; i < t.length; i++) {\r
            t[i] = arr[i] != 0;\r
        }\r
    }\r
}\r
"
    },
    "contracts/libraries/PbPegged.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
// Code generated by protoc-gen-sol. DO NOT EDIT.\r
// source: contracts/libraries/proto/pegged.proto\r
pragma solidity 0.8.17;\r
import "./Pb.sol";\r
\r
library PbPegged {\r
    using Pb for Pb.Buffer; // so we can call Pb funcs on Buffer obj\r
\r
    struct Mint {\r
        address token; // tag: 1\r
        address account; // tag: 2\r
        uint256 amount; // tag: 3\r
        address depositor; // tag: 4\r
        uint64 refChainId; // tag: 5\r
        bytes32 refId; // tag: 6\r
    } // end struct Mint\r
\r
    function decMint(bytes memory raw) internal pure returns (Mint memory m) {\r
        Pb.Buffer memory buf = Pb.fromBytes(raw);\r
\r
        uint256 tag;\r
        Pb.WireType wire;\r
        while (buf.hasMore()) {\r
            (tag, wire) = buf.decKey();\r
            if (false) {}\r
            // solidity has no switch/case\r
            else if (tag == 1) {\r
                m.token = Pb._address(buf.decBytes());\r
            } else if (tag == 2) {\r
                m.account = Pb._address(buf.decBytes());\r
            } else if (tag == 3) {\r
                m.amount = Pb._uint256(buf.decBytes());\r
            } else if (tag == 4) {\r
                m.depositor = Pb._address(buf.decBytes());\r
            } else if (tag == 5) {\r
                m.refChainId = uint64(buf.decVarint());\r
            } else if (tag == 6) {\r
                m.refId = Pb._bytes32(buf.decBytes());\r
            } else {\r
                buf.skipValue(wire);\r
            } // skip value of unknown tag\r
        }\r
    } // end decoder Mint\r
\r
    struct Withdraw {\r
        address token; // tag: 1\r
        address receiver; // tag: 2\r
        uint256 amount; // tag: 3\r
        address burnAccount; // tag: 4\r
        uint64 refChainId; // tag: 5\r
        bytes32 refId; // tag: 6\r
    } // end struct Withdraw\r
\r
    function decWithdraw(bytes memory raw) internal pure returns (Withdraw memory m) {\r
        Pb.Buffer memory buf = Pb.fromBytes(raw);\r
\r
        uint256 tag;\r
        Pb.WireType wire;\r
        while (buf.hasMore()) {\r
            (tag, wire) = buf.decKey();\r
            if (false) {}\r
            // solidity has no switch/case\r
            else if (tag == 1) {\r
                m.token = Pb._address(buf.decBytes());\r
            } else if (tag == 2) {\r
                m.receiver = Pb._address(buf.decBytes());\r
            } else if (tag == 3) {\r
                m.amount = Pb._uint256(buf.decBytes());\r
            } else if (tag == 4) {\r
                m.burnAccount = Pb._address(buf.decBytes());\r
            } else if (tag == 5) {\r
                m.refChainId = uint64(buf.decVarint());\r
            } else if (tag == 6) {\r
                m.refId = Pb._bytes32(buf.decBytes());\r
            } else {\r
                buf.skipValue(wire);\r
            } // skip value of unknown tag\r
        }\r
    } // end decoder Withdraw\r
}\r
"
    },
    "contracts/pegged-bridge/PeggedTokenBridgeV2.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity 0.8.17;\r
\r
import "../interfaces/ISigsVerifier.sol";\r
import "../interfaces/IPeggedToken.sol";\r
import "../interfaces/IPeggedTokenBurnFrom.sol";\r
import "../libraries/PbPegged.sol";\r
import "../safeguard/Pauser.sol";\r
import "../safeguard/VolumeControl.sol";\r
import "../safeguard/DelayedTransfer.sol";\r
\r
/**\r
 * @title The bridge contract to mint and burn pegged tokens\r
 * @dev Work together with OriginalTokenVault deployed at remote chains.\r
 */\r
contract PeggedTokenBridgeV2 is Pauser, VolumeControl, DelayedTransfer {\r
    ISigsVerifier public immutable sigsVerifier;\r
\r
    mapping(bytes32 => bool) public records;\r
    mapping(address => uint256) public supplies;\r
\r
    mapping(address => uint256) public minBurn;\r
    mapping(address => uint256) public maxBurn;\r
\r
    event Mint(\r
        bytes32 mintId,\r
        address token,\r
        address account,\r
        uint256 amount,\r
        // ref_chain_id defines the reference chain ID, taking values of:\r
        // 1. The common case: the chain ID on which the remote corresponding deposit or burn happened;\r
        // 2. Refund for wrong burn: this chain ID on which the burn happened\r
        uint64 refChainId,\r
        // ref_id defines a unique reference ID, taking values of:\r
        // 1. The common case of deposit/burn-mint: the deposit or burn ID on the remote chain;\r
        // 2. Refund for wrong burn: the burn ID on this chain\r
        bytes32 refId,\r
        address depositor\r
    );\r
    event Burn(\r
        bytes32 burnId,\r
        address token,\r
        address account,\r
        uint256 amount,\r
        uint64 toChainId,\r
        address toAccount,\r
        uint64 nonce\r
    );\r
    event MinBurnUpdated(address token, uint256 amount);\r
    event MaxBurnUpdated(address token, uint256 amount);\r
    event SupplyUpdated(address token, uint256 supply);\r
\r
    constructor(ISigsVerifier _sigsVerifier) {\r
        sigsVerifier = _sigsVerifier;\r
    }\r
\r
    /**\r
     * @notice Mint tokens triggered by deposit at a remote chain's OriginalTokenVault.\r
     * @param _request The serialized Mint protobuf.\r
     * @param _sigs The list of signatures sorted by signing addresses in ascending order. A relay must be signed-off by\r
     * +2/3 of the sigsVerifier's current signing power to be delivered.\r
     * @param _signers The sorted list of signers.\r
     * @param _powers The signing powers of the signers.\r
     */\r
    function mint(\r
        bytes calldata _request,\r
        bytes[] calldata _sigs,\r
        address[] calldata _signers,\r
        uint256[] calldata _powers\r
    ) external whenNotPaused returns (bytes32) {\r
        bytes32 domain = keccak256(abi.encodePacked(block.chainid, address(this), "Mint"));\r
        sigsVerifier.verifySigs(abi.encodePacked(domain, _request), _sigs, _signers, _powers);\r
        PbPegged.Mint memory request = PbPegged.decMint(_request);\r
        bytes32 mintId = keccak256(\r
            // len = 20 + 20 + 32 + 20 + 8 + 32 + 20 = 152\r
            abi.encodePacked(\r
                request.account,\r
                request.token,\r
                request.amount,\r
                request.depositor,\r
                request.refChainId,\r
                request.refId,\r
                address(this)\r
            )\r
        );\r
        require(records[mintId] == false, "record exists");\r
        records[mintId] = true;\r
        _updateVolume(request.token, request.amount);\r
        uint256 delayThreshold = delayThresholds[request.token];\r
        if (delayThreshold > 0 && request.amount > delayThreshold) {\r
            _addDelayedTransfer(mintId, request.account, request.token, request.amount);\r
        } else {\r
            IPeggedToken(request.token).mint(request.account, request.amount);\r
        }\r
        supplies[request.token] += request.amount;\r
        emit Mint(\r
            mintId,\r
            request.token,\r
            request.account,\r
            request.amount,\r
            request.refChainId,\r
            request.refId,\r
            request.depositor\r
        );\r
        return mintId;\r
    }\r
\r
    /**\r
     * @notice Burn pegged tokens to trigger a cross-chain withdrawal of the original tokens at a remote chain's\r
     * OriginalTokenVault, or mint at another remote chain\r
     * NOTE: This function DOES NOT SUPPORT fee-on-transfer / rebasing tokens.\r
     * @param _token The pegged token address.\r
     * @param _amount The amount to burn.\r
     * @param _toChainId If zero, withdraw from original vault; otherwise, the remote chain to mint tokens.\r
     * @param _toAccount The account to receive tokens on the remote chain\r
     * @param _nonce A number to guarantee unique depositId. Can be timestamp in practice.\r
     */\r
    function burn(\r
        address _token,\r
        uint256 _amount,\r
        uint64 _toChainId,\r
        address _toAccount,\r
        uint64 _nonce\r
    ) external whenNotPaused returns (bytes32) {\r
        bytes32 burnId = _burn(_token, _amount, _toChainId, _toAccount, _nonce);\r
        IPeggedToken(_token).burn(msg.sender, _amount);\r
        return burnId;\r
    }\r
\r
    // same with `burn` above, use openzeppelin ERC20Burnable interface\r
    function burnFrom(\r
        address _token,\r
        uint256 _amount,\r
        uint64 _toChainId,\r
        address _toAccount,\r
        uint64 _nonce\r
    ) external whenNotPaused returns (bytes32) {\r
        bytes32 burnId = _burn(_token, _amount, _toChainId, _toAccount, _nonce);\r
        IPeggedTokenBurnFrom(_token).burnFrom(msg.sender, _amount);\r
        return burnId;\r
    }\r
\r
    function _burn(\r
        address _token,\r
        uint256 _amount,\r
        uint64 _toChainId,\r
        address _toAccount,\r
        uint64 _nonce\r
    ) internal returns (bytes32) {\r
        require(_amount > minBurn[_token], "amount too small");\r
        require(maxBurn[_token] == 0 || _amount <= maxBurn[_token], "amount too large");\r
        supplies[_token] -= _amount;\r
        bytes32 burnId = keccak256(\r
            // len = 20 + 20 + 32 + 8 + 20 + 8 + 8 + 20 = 136\r
            abi.encodePacked(\r
                msg.sender,\r
                _token,\r
                _amount,\r
                _toChainId,\r
                _toAccount,\r
                _nonce,\r
                uint64(block.chainid),\r
                address(this)\r
            )\r
        );\r
        require(records[burnId] == false, "record exists");\r
        records[burnId] = true;\r
        emit Burn(burnId, _token, msg.sender, _amount, _toChainId, _toAccount, _nonce);\r
        return burnId;\r
    }\r
\r
    function executeDelayedTransfer(bytes32 id) external whenNotPaused {\r
        delayedTransfer memory transfer = _executeDelayedTransfer(id);\r
        IPeggedToken(transfer.token).mint(transfer.receiver, transfer.amount);\r
    }\r
\r
    function setMinBurn(address[] calldata _tokens, uint256[] calldata _amounts) external onlyGovernor {\r
        require(_tokens.length == _amounts.length, "length mismatch");\r
        for (uint256 i = 0; i < _tokens.length; i++) {\r
            minBurn[_tokens[i]] = _amounts[i];\r
            emit MinBurnUpdated(_tokens[i], _amounts[i]);\r
        }\r
    }\r
\r
    function setMaxBurn(address[] calldata _tokens, uint256[] calldata _amounts) external onlyGovernor {\r
        require(_tokens.length == _amounts.length, "length mismatch");\r
        for (uint256 i = 0; i < _tokens.length; i++) {\r
            maxBurn[_tokens[i]] = _amounts[i];\r
            emit MaxBurnUpdated(_tokens[i], _amounts[i]);\r
        }\r
    }\r
\r
    function setSupply(address _token, uint256 _supply) external onlyOwner {\r
        supplies[_token] = _supply;\r
        emit SupplyUpdated(_token, _supply);\r
    }\r
\r
    function increaseSupply(address _token, uint256 _delta) external onlyOwner {\r
        supplies[_token] += _delta;\r
        emit SupplyUpdated(_token, supplies[_token]);\r
    }\r
\r
    function decreaseSupply(address _token, uint256 _delta) external onlyOwner {\r
        supplies[_token] -= _delta;\r
        emit SupplyUpdated(_token, supplies[_token]);\r
    }\r
}\r
"
    },
    "contracts/safeguard/DelayedTransfer.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity 0.8.17;\r
\r
import "./Governor.sol";\r
\r
abstract contract DelayedTransfer is Governor {\r
    struct delayedTransfer {\r
        address receiver;\r
        address token;\r
        uint256 amount;\r
        uint256 timestamp;\r
    }\r
    mapping(bytes32 => delayedTransfer) public delayedTransfers;\r
    mapping(address => uint256) public delayThresholds;\r
    uint256 public delayPeriod; // in seconds\r
\r
    event DelayedTransferAdded(bytes32 id);\r
    event DelayedTransferExecuted(bytes32 id, address receiver, address token, uint256 amount);\r
\r
    event DelayPeriodUpdated(uint256 period);\r
    event DelayThresholdUpdated(address token, uint256 threshold);\r
\r
    function setDelayThresholds(address[] calldata _tokens, uint256[] calldata _thresholds) external onlyGovernor {\r
        require(_tokens.length == _thresholds.length, "length mismatch");\r
        for (uint256 i = 0; i < _tokens.length; i++) {\r
            delayThresholds[_tokens[i]] = _thresholds[i];\r
            emit DelayThresholdUpdated(_tokens[i], _thresholds[i]);\r
        }\r
    }\r
\r
    function setDelayPeriod(uint256 _period) external onlyGovernor {\r
        delayPeriod = _period;\r
        emit DelayPeriodUpdated(_period);\r
    }\r
\r
    function _addDelayedTransfer(\r
        bytes32 id,\r
        address receiver,\r
        address token,\r
        uint256 amount\r
    ) internal {\r
        require(delayedTransfers[id].timestamp == 0, "delayed transfer already exists");\r
        delayedTransfers[id] = delayedTransfer({\r
            receiver: receiver,\r
            token: token,\r
            amount: amount,\r
            timestamp: block.timestamp\r
        });\r
        emit DelayedTransferAdded(id);\r
    }\r
\r
    // caller needs to do the actual token transfer\r
    function _executeDelayedTransfer(bytes32 id) internal returns (delayedTransfer memory) {\r
        delayedTransfer memory transfer = delayedTransfers[id];\r
        require(transfer.timestamp > 0, "delayed transfer not exist");\r
        require(block.timestamp > transfer.timestamp + delayPeriod, "delayed transfer still locked");\r
        delete delayedTransfers[id];\r
        emit DelayedTransferExecuted(id, transfer.receiver, transfer.token, transfer.amount);\r
        return transfer;\r
    }\r
}\r
"
    },
    "contracts/safeguard/Governor.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity 0.8.17;\r
\r
import "./Ownable.sol";\r
\r
abstract contract Governor is Ownable {\r
    mapping(address => bool) public governors;\r
\r
    event GovernorAdded(address account);\r
    event GovernorRemoved(address account);\r
\r
    modifier onlyGovernor() {\r
        require(isGovernor(msg.sender), "Caller is not governor");\r
        _;\r
    }\r
\r
    constructor() {\r
        _addGovernor(msg.sender);\r
    }\r
\r
    function isGovernor(address _account) public view returns (bool) {\r
        return governors[_account];\r
    }\r
\r
    function addGovernor(address _account) public onlyOwner {\r
        _addGovernor(_account);\r
    }\r
\r
    function removeGovernor(address _account) public onlyOwner {\r
        _removeGovernor(_account);\r
    }\r
\r
    function renounceGovernor() public {\r
        _removeGovernor(msg.sender);\r
    }\r
\r
    function _addGovernor(address _account) private {\r
        require(!isGovernor(_account), "Account is already governor");\r
        governors[_account] = true;\r
        emit GovernorAdded(_account);\r
    }\r
\r
    function _removeGovernor(address _account) private {\r
        require(isGovernor(_account), "Account is not governor");\r
        governors[_account] = false;\r
        emit GovernorRemoved(_account);\r
    }\r
}\r
"
    },
    "contracts/safeguard/Ownable.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity ^0.8.0;\r
\r
/**\r
 * @dev Contract module which provides a basic access control mechanism, where\r
 * there is an account (an owner) that can be granted exclusive access to\r
 * specific functions.\r
 *\r
 * By default, the owner account will be the one that deploys the contract. This\r
 * can later be changed with {transferOwnership}.\r
 *\r
 * This module is used through inheritance. It will make available the modifier\r
 * `onlyOwner`, which can be applied to your functions to restrict their use to\r
 * the owner.\r
 *\r
 * This adds a normal func that setOwner if _owner is address(0). So we can't allow\r
 * renounceOwnership. So we can support Proxy based upgradable contract\r
 */\r
abstract contract Ownable {\r
    address private _owner;\r
\r
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r
\r
    /**\r
     * @dev Initializes the contract setting the deployer as the initial owner.\r
     */\r
    constructor() {\r
        _setOwner(msg.sender);\r
    }\r
\r
    /**\r
     * @dev Only to be called by inherit contracts, in their init func called by Proxy\r
     * we require _owner == address(0), which is only possible when it's a delegateCall\r
     * because constructor sets _owner in contract state.\r
     */\r
    function initOwner() internal {\r
        require(_owner == address(0), "owner already set");\r
        _setOwner(msg.sender);\r
    }\r
\r
    /**\r
     * @dev Returns the address of the current owner.\r
     */\r
    function owner() public view virtual returns (address) {\r
        return _owner;\r
    }\r
\r
    /**\r
     * @dev Throws if called by any account other than the owner.\r
     */\r
    modifier onlyOwner() {\r
        require(owner() == msg.sender, "Ownable: caller is not the owner");\r
        _;\r
    }\r
\r
    /**\r
     * @dev Transfers ownership of the contract to a new account (`newOwner`).\r
     * Can only be called by the current owner.\r
     */\r
    function transferOwnership(address newOwner) public virtual onlyOwner {\r
        require(newOwner != address(0), "Ownable: new owner is the zero address");\r
        _setOwner(newOwner);\r
    }\r
\r
    function _setOwner(address newOwner) private {\r
        address oldOwner = _owner;\r
        _owner = newOwner;\r
        emit OwnershipTransferred(oldOwner, newOwner);\r
    }\r
}\r
"
    },
    "contracts/safeguard/Pauser.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity 0.8.17;\r
\r
import "@openzeppelin/contracts/security/Pausable.sol";\r
import "./Ownable.sol";\r
\r
abstract contract Pauser is Ownable, Pausable {\r
    mapping(address => bool) public pausers;\r
\r
    event PauserAdded(address account);\r
    event PauserRemoved(address account);\r
\r
    constructor() {\r
        _addPauser(msg.sender);\r
    }\r
\r
    modifier onlyPauser() {\r
        require(isPauser(msg.sender), "Caller is not pauser");\r
        _;\r
    }\r
\r
    function pause() public onlyPauser {\r
        _pause();\r
    }\r
\r
    function unpause() public onlyPauser {\r
        _unpause();\r
    }\r
\r
    function isPauser(address account) public view returns (bool) {\r
        return pausers[account];\r
    }\r
\r
    function addPauser(address account) public onlyOwner {\r
        _addPauser(account);\r
    }\r
\r
    function removePauser(address account) public onlyOwner {\r
        _removePauser(account);\r
    }\r
\r
    function renouncePauser() public {\r
        _removePauser(msg.sender);\r
    }\r
\r
    function _addPauser(address account) private {\r
        require(!isPauser(account), "Account is already pauser");\r
        pausers[account] = true;\r
        emit PauserAdded(account);\r
    }\r
\r
    function _removePauser(address account) private {\r
        require(isPauser(account), "Account is not pauser");\r
        pausers[account] = false;\r
        emit PauserRemoved(account);\r
    }\r
}\r
"
    },
    "contracts/safeguard/VolumeControl.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-only\r
\r
pragma solidity 0.8.17;\r
\r
import "./Governor.sol";\r
\r
abstract contract VolumeControl is Governor {\r
    uint256 public epochLength; // seconds\r
    mapping(address => uint256) public epochVolumes; // key is token\r
    mapping(address => uint256) public epochVolumeCaps; // key is token\r
    mapping(address => uint256) public lastOpTimestamps; // key is token\r
\r
    event EpochLengthUpdated(uint256 length);\r
    event EpochVolumeUpdated(address token, uint256 cap);\r
\r
    function setEpochLength(uint256 _length) external onlyGovernor {\r
        epochLength = _length;\r
        emit EpochLengthUpdated(_length);\r
    }\r
\r
    function setEpochVolumeCaps(address[] calldata _tokens, uint256[] calldata _caps) external onlyGovernor {\r
        require(_tokens.length == _caps.length, "length mismatch");\r
        for (uint256 i = 0; i < _tokens.length; i++) {\r
            epochVolumeCaps[_tokens[i]] = _caps[i];\r
            emit EpochVolumeUpdated(_tokens[i], _caps[i]);\r
        }\r
    }\r
\r
    function _updateVolume(address _token, uint256 _amount) internal {\r
        if (epochLength == 0) {\r
            return;\r
        }\r
        uint256 cap = epochVolumeCaps[_token];\r
        if (cap == 0) {\r
            return;\r
        }\r
        uint256 volume = epochVolumes[_token];\r
        uint256 timestamp = block.timestamp;\r
        uint256 epochStartTime = (timestamp / epochLength) * epochLength;\r
        if (lastOpTimestamps[_token] < epochStartTime) {\r
            volume = _amount;\r
        } else {\r
            volume += _amount;\r
        }\r
        require(volume <= cap, "volume exceeds cap");\r
        epochVolumes[_token] = volume;\r
        lastOpTimestamps[_token] = timestamp;\r
    }\r
}\r
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 800
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "metadata": {
      "useLiteralContent": true
    }
  }
}}

Tags:
Multisig, Voting, Upgradeable, Multi-Signature, Factory|addr:0x9009a3171c92a733943118958312013989660943|verified:true|block:23726562|tx:0xc8cd5ace499599bc1a239d8a55d918fd0cf3c688020578f39747066cfc320ff2|first_check:1762270247

Submitted on: 2025-11-04 16:30:50

Comments

Log in to comment.

No comments yet.