Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- BridgeUpgradeable
- Optimization enabled
- true
- Compiler version
- v0.8.2+commit.661d1103
- Optimization runs
- 50
- Verified at
- 2022-11-15T06:54:37.381318Z
contracts/BridgeUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "./interfaces/IVoterUpgradeable.sol"; import "./interfaces/IERC20Upgradeable.sol"; import "./interfaces/IDepositExecute.sol"; import "./interfaces/ILiquidityPool.sol"; import "./interfaces/IERCHandler.sol"; import "./interfaces/IERCHandlerDecimals.sol"; import "./interfaces/IGenericHandler.sol"; import "./interfaces/ISequencerHandler.sol"; import "./interfaces/IWETH.sol"; /// @title Facilitates deposits, creation and voting of deposit proposals, and deposit executions. /// @author Router Protocol contract BridgeUpgradeable is Initializable, PausableUpgradeable, AccessControlUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable { /// @notice Fetches source chain Id. function fetch_chainID() public view virtual returns (uint8) { return _chainID; } /// @notice Fetches the value of expiry. function fetch_expiry() public view virtual returns (uint256) { return _expiry; } /// @notice Fetches if whitelisting is enabled. function fetch_whitelistEnabled() public view virtual returns (bool) { return _whitelistEnabled; } /// @notice Fetches deposit nonce with respect to destination chainId `_id`. /// @param _id Destination chainId /// @return Returns deposit nonce function fetch_depositCounts(uint8 _id) public view virtual returns (uint64) { return _depositCounts[_id]; } /// @notice Fetches handler address with respect to resource Id `_id`. /// @param _id Resource Id /// @return Returns handler address function fetch_resourceIDToHandlerAddress(bytes32 _id) public view virtual returns (address) { return _resourceIDToHandlerAddress[_id]; } /// @notice Fetches Proposal Id with respect to proposal hash `_id`. /// @param _id Proposal hash /// @return Returns Proposal Id function fetch_proposals(bytes32 _id) public view virtual returns (uint256) { return _proposals[_id]; } /// @notice Fetches if `_beneficiary` is whitelisted. /// @param _beneficiary Address of the beneficiary /// @return Returns true if `_beneficiary` is whitelisted function fetch_whitelist(address _beneficiary) public view virtual returns (bool) { return _whitelist[_beneficiary]; } /// @notice Gets the proposal hash /// @param chainID Chain ID deposit originated from. /// @param depositNonce ID of proposal generated by proposal's origin Bridge contract. /// @param dataHash Hash of data to be provided when deposit proposal is executed. /// @return Returns proposal hash // CRITICAL: dont change below code function GetProposalHash( uint8 chainID, uint64 depositNonce, bytes32 dataHash ) public pure virtual returns (bytes32) { bytes32 proposalHash = keccak256(abi.encodePacked(chainID, depositNonce, dataHash)); return proposalHash; } /// @notice Returns true if caller has voted on the proposal. /// @param chainID Chain ID deposit originated from. /// @param depositNonce ID of proposal generated by proposal's origin Bridge contract. /// @param dataHash Hash of data to be provided when deposit proposal is executed. /// @return Returns true if caller has voted on the proposal. // CRITICAL: dont change below code function HasVotedOnProposal( uint8 chainID, uint64 depositNonce, bytes32 dataHash ) public view virtual returns (bool) { bytes32 proposalHash = keccak256(abi.encodePacked(chainID, depositNonce, dataHash)); uint256 id = _proposals[proposalHash]; return _voter.Voted(id, msg.sender); } function isNonceExecuted(uint8 srcChainId, uint64 depositNonce) external view returns (bool) { return _isNonceExecuted[srcChainId][depositNonce]; } function getNonceCheckpoint(uint8 srcChainId) external view returns (uint64) { return _nonceCheckpoint[srcChainId]; } // View Functions // Data Structure Starts uint8 private _chainID; uint256 private _expiry; bool private _whitelistEnabled; bytes32 public constant FEE_SETTER_ROLE = keccak256("FEE_SETTER_ROLE"); bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); bytes32 public constant RESOURCE_SETTER = keccak256("RESOURCE_SETTER"); bytes32 public constant EMERGENCY_ROLE = keccak256("EMERGENCY_ROLE"); uint256 public totalRelayers; uint64 public _quorum; IVoterUpgradeable public _voter; // enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } mapping(uint8 => uint64) private _depositCounts; mapping(bytes32 => address) private _resourceIDToHandlerAddress; mapping(bytes32 => uint256) private _proposals; mapping(address => bool) private _whitelist; mapping(uint256 => proposalStruct) private _proposalDetails; struct proposalStruct { uint8 chainID; uint64 depositNonce; bytes32 dataHash; bytes32 resourceID; } mapping(address => bool) private _genericWhitelist; mapping(uint8 => bool) private _unsupportedChains; mapping(address => bool) private _sequencerWhitelist; // srcChainId + depositNonce => executed to store if a nonce is already executed mapping(uint8 => mapping(uint64 => bool)) private _isNonceExecuted; // srcChainId => nonceCheckpoint => so that up till this nonce, no tx can be executed. // To prevent double spending. mapping(uint8 => uint64) private _nonceCheckpoint; // Data Structure Ends event quorumChanged(uint64 quorum); event expiryChanged(uint256 expiry); event ProposalEvent( uint8 originChainID, uint64 depositNonce, IVoterUpgradeable.ProposalStatus status, bytes32 dataHash ); event SequencerEvent( uint8 originChainID, uint64 depositNonce, IVoterUpgradeable.ProposalStatus status, bytes32 dataHash ); event ProposalVote( uint8 originChainID, uint64 depositNonce, IVoterUpgradeable.ProposalStatus status, bytes32 dataHash ); event Deposit( uint8 indexed destinationChainID, bytes32 indexed resourceID, uint64 indexed depositNonce, uint256 widgetID ); event Stake(address indexed staker, uint256 amount, address pool); event Unstake(address indexed unstaker, uint256 amount, address pool); event FeeSetterAdded(address feeSetter); event FeeSetterRemoved(address feeSetter); event AddedWhitelist(address whitelistAddress); event RemovedWhitelist(address whitelistAddress); event WhitelistingSetting(bool status); event AdminWithdraw(address handler, address tokenAddress, address recipient, uint256 amountOrTokenID); event Settlement( uint8 indexed originChainID, uint64 indexed depositNonce, address settlementToken, uint256 settlementAmount, IVoterUpgradeable.ProposalStatus status ); /// @notice RelayerAdded Event /// @notice Creates a event when Relayer Role is granted. /// @param relayer Address of relayer. event RelayerAdded(address relayer); /// @notice RelayerRemoved Event /// @notice Creates a event when Relayer Role is revoked. /// @param relayer Address of relayer. event RelayerRemoved(address relayer); event UnsupportedChain(uint8 indexed destinationChainID, bool isUnsupported); // Modifier Section Starts modifier onlyAdminOrRelayer() { require( hasRole(DEFAULT_ADMIN_ROLE, msg.sender) || hasRole(RELAYER_ROLE, msg.sender), "sender is not relayer or admin" ); _; } modifier isWhitelisted() { if (_whitelistEnabled) { require(_whitelist[msg.sender], "address is not whitelisted"); } _; } modifier isWhitelistEnabled() { require(_whitelistEnabled, "BridgeUpgradeable: White listing is not enabled"); _; } modifier notUnsupportedChain(uint8 chainId) { require(!_unsupportedChains[chainId], "BridgeUpgradeable: Unsupported chain"); _; } modifier isResourceID(bytes32 _id) { require(_resourceIDToHandlerAddress[_id] != address(0), "BridgeUpgradeable: No handler for resourceID"); _; } modifier isProposalExists( uint8 chainID, uint64 depositNonce, bytes32 dataHash ) { // CRITICAL: dont change below code bytes32 proposalHash = keccak256(abi.encodePacked(chainID, depositNonce, dataHash)); require(_proposals[proposalHash] != 0, "BridgeUpgradeable: Proposal Does Not Exists"); _; } // Modifier Section ends receive() external payable {} // Upgrade Section Starts /// @notice Initializes Bridge, creates and grants {msg.sender} the admin role, /// creates and grants {initialRelayers} the relayer role. /// @param chainID ID of chain the Bridge contract exists on. /// @param quorum Number of votes needed for a deposit proposal to be considered passed. function initialize( uint8 chainID, uint256 quorum, uint256 expiry, address voter ) external initializer { __AccessControl_init(); __Pausable_init(); // Constructor Fx _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); _voter = IVoterUpgradeable(voter); _chainID = chainID; _quorum = uint64(quorum); _expiry = expiry; // Constructor Fx } function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(DEFAULT_ADMIN_ROLE) {} // Upgrade Section Ends // Access Control Section Starts /// @notice grantRole function /// @dev Overrides the grant role in accessControl contract. /// @dev If RELAYER_ROLE is granted then it would mint 1 voting token as voting weights. /// @dev The Token minted would be notional and non transferable type. /// @param role Hash of the role being granted /// @param account address to which role is being granted function grantRole(bytes32 role, address account) public virtual override nonReentrant onlyRole(getRoleAdmin(role)) { super.grantRole(role, account); if (role == RELAYER_ROLE && _voter.balanceOf(account) == 0 ether) { _voter.mint(account); totalRelayers = totalRelayers + 1; emit RelayerAdded(account); } } /// @notice revokeRole function /// @dev Overrides the grant role in accessControl contract. /// @dev If RELAYER_ROLE is revoked then it would burn 1 voting token as voting weights. /// @dev The Token burned would be notional and non transferable type. /// @param role Hash of the role being revoked /// @param account address to which role is being revoked function revokeRole(bytes32 role, address account) public virtual override nonReentrant onlyRole(getRoleAdmin(role)) { super.revokeRole(role, account); if (role == RELAYER_ROLE && _voter.balanceOf(account) == 1 ether) { _voter.burn(account); totalRelayers = totalRelayers - 1; emit RelayerRemoved(account); } } // Access Control Section Ends // Whitelist Section Starts /// @dev Adds single address to _whitelist. /// @param _beneficiary Address to be added to the _whitelist function addToWhitelist(address _beneficiary) public virtual onlyRole(DEFAULT_ADMIN_ROLE) isWhitelistEnabled { _whitelist[_beneficiary] = true; emit AddedWhitelist(_beneficiary); } /// @dev Removes single address from _whitelist. /// @param _beneficiary Address to be removed to the _whitelist function removeFromWhitelist(address _beneficiary) public virtual onlyRole(DEFAULT_ADMIN_ROLE) isWhitelistEnabled { _whitelist[_beneficiary] = false; emit RemovedWhitelist(_beneficiary); } /// @dev setWhitelisting whitelisting process. function setWhitelisting(bool value) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _whitelistEnabled = value; emit WhitelistingSetting(value); } /// @dev setUnsupportedChain unsupporting chain process. function setUnsupportedChain(uint8 destChainId, bool isUnsupported) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _unsupportedChains[destChainId] = isUnsupported; emit UnsupportedChain(destChainId, isUnsupported); } // Whitelist Section Ends // Pause Section Starts /// @notice Pauses deposits, proposal creation and voting, and deposit executions. /// @notice Only callable by an address that currently has the admin role. function pause() public virtual onlyRole(PAUSER_ROLE) whenNotPaused { _pause(); } /// @notice Unpauses deposits, proposal creation and voting, and deposit executions. /// @notice Only callable by an address that currently has the admin role. function unpause() public virtual onlyRole(PAUSER_ROLE) whenPaused { _unpause(); } // Pause Section Ends // Ancilary Admin Functions Starts /// @notice Modifies the nonce checkpoint for execute proposal for a dest chainid. /// @notice Only callable by an address that currently has the admin role. /// @param srcChainID chainId for the transaction origin chain. /// @param nonceCheckpoint the nonce checkpoint to be updated in the mapping function adminSetNonceCheckpoint(uint8 srcChainID, uint64 nonceCheckpoint) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { require(nonceCheckpoint > 0, "nonce checkpoint != 0"); _nonceCheckpoint[srcChainID] = nonceCheckpoint; } /// @notice Modifies the number of votes required for a proposal to be considered passed. /// @notice Only callable by an address that currently has the admin role. /// @param newQuorum Value {newQuorum} will be changed to. /// @notice Emits {quorumChanged} event. function adminChangeQuorum(uint256 newQuorum) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _quorum = uint64(newQuorum); emit quorumChanged(_quorum); } /// @notice Modifies the block expiry for a proposal. /// @notice Only callable by an address that currently has the admin role. /// @param newExpiry will be new value of _expiry. /// @notice Emits {expiryChanged} event. function adminChangeExpiry(uint256 newExpiry) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { _expiry = newExpiry; emit expiryChanged(newExpiry); } /// @notice Sets a new resource for handler contracts that use the IERCHandler interface, /// and maps the {handlerAddress} to {resourceID} in {_resourceIDToHandlerAddress}. /// @notice Only callable by an address that currently has the resource setter role. /// @param handlerAddress Address of handler resource will be set for. /// @param resourceID ResourceID to be used when making deposits. /// @param tokenAddress Address of contract to be called when a deposit is made and a deposited is executed. function adminSetResource( address handlerAddress, bytes32 resourceID, address tokenAddress ) public virtual onlyRole(RESOURCE_SETTER) { _resourceIDToHandlerAddress[resourceID] = handlerAddress; IERCHandler handler = IERCHandler(handlerAddress); handler.setResource(resourceID, tokenAddress); } // /// @notice Sets token decimals for handler contracts that use the IERCHandlerDecimals interface. // /// @notice Destination Chain id should not be unsupported. // /// @notice Only callable by an address that currently has the resource setter role. // /// @param handlerAddress Address of handler resource will be set for. // /// @param tokenAddress token contracts for setting config. // /// @param destinationChainID destinationChainIDs to be used when setting config. // /// @param decimals decimals for tokens on target chain. // function adminSetTokenDecimals( // address handlerAddress, // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) public virtual onlyRole(RESOURCE_SETTER) { // require( // tokenAddress.length == destinationChainID.length && tokenAddress.length == decimals.length, // "BridgeUpgradeable setTokenDecimals: Array length mismatch" // ); // IERCHandlerDecimals handler = IERCHandlerDecimals(handlerAddress); // handler.setTokenDecimals(tokenAddress, destinationChainID, decimals); // } /// @notice Sets one split address for handler contracts that use the IERCHandler interface. /// @notice Only callable by an address that currently has the admin role. /// @param handlerAddress Address of handler resource will be set for. /// @param contractAddress Contract address of OneSplit function adminSetOneSplitAddress(address handlerAddress, address contractAddress) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { IERCHandler handler = IERCHandler(handlerAddress); handler.setOneSplitAddress(contractAddress); } /// @notice Creates new liquidity pool /// @notice Only callable by an address that currently has the admin role. /// @param handlerAddress Address of handler resource will be set for. /// @param tokenAddress Address of token for which pool needs to be created. /// @param lpAddress Liquidity Pool Address function adminSetLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, address handlerAddress, address tokenAddress, address lpAddress ) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { IERCHandler handler = IERCHandler(handlerAddress); // handler.setLiquidityPool(name, symbol, decimals, tokenAddress, lpAddress); handler.setLiquidityPool(tokenAddress, lpAddress); } /// @notice Creates new liquidity pool owner /// @notice Only callable by an address that currently has the admin role. /// @param handlerAddress Address of handler resource will be set for. /// @param oldOwner Address of old owner of LP /// @param newOwner Address of new owner for LP /// @param tokenAddress Address of token for which pool needs to be created. /// @param lpAddress Liquidity Pool Address function adminSetLiquidityPoolOwner( address handlerAddress, address oldOwner, address newOwner, address tokenAddress, address lpAddress ) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { IERCHandler handler = IERCHandler(handlerAddress); handler.setLiquidityPoolOwner(oldOwner, newOwner, tokenAddress, lpAddress); } /// @notice Sets a new resource for handler contracts that use the IGenericHandler interface, /// and maps the {handlerAddress} to {resourceID} in {_resourceIDToHandlerAddress}. /// @notice Only callable by an address that currently has the resource setter role. /// @param handlerAddress Address of handler resource will be set for. /// @param resourceID ResourceID to be used when making deposits. function adminSetGenericResource(address handlerAddress, bytes32 resourceID) public virtual onlyRole(RESOURCE_SETTER) { _resourceIDToHandlerAddress[resourceID] = handlerAddress; _genericWhitelist[handlerAddress] = true; } /** @notice Sets a new resource for handler contracts that use the ISequencerHandler interface, and maps the {handlerAddress} to {resourceID} in {_resourceIDToHandlerAddress}. @notice Only callable by an address that currently has the admin role. @param handlerAddress Address of sequencer handler resource will be set for. @param resourceID ResourceID to be used when making deposits. */ function adminSetSequencerResource(address handlerAddress, bytes32 resourceID) public virtual onlyRole(RESOURCE_SETTER) { _resourceIDToHandlerAddress[resourceID] = handlerAddress; _sequencerWhitelist[handlerAddress] = true; } /// @notice Sets a resource as burnable for handler contracts that use the IERCHandler interface. /// @notice Only callable by an address that currently has the admin role. /// @param handlerAddress Address of handler resource will be set for. /// @param tokenAddress Address of contract to be called when a deposit is made and a deposited is executed. /// @param status Boolean flag to change burnable status. function adminSetBurnable( address handlerAddress, address tokenAddress, bool status ) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { IERCHandler handler = IERCHandler(handlerAddress); handler.setBurnable(tokenAddress, status); } /// @notice Used to manually withdraw funds from ERC safes. /// @param handlerAddress Address of handler to withdraw from. /// @param tokenAddress Address of token to withdraw. /// @param recipient Address to withdraw tokens to. /// @param amount the amount of ERC20 tokens to withdraw. function adminWithdraw( address handlerAddress, address tokenAddress, address recipient, uint256 amount ) public virtual nonReentrant onlyRole(EMERGENCY_ROLE) { IERCHandler handler = IERCHandler(handlerAddress); handler.withdraw(tokenAddress, recipient, amount); emit AdminWithdraw(handlerAddress, tokenAddress, recipient, amount); } /// @notice Used to manually withdraw funds from ERC safes. /// @param handlerAddress Address of handler to withdraw from. /// @param tokenAddress Address of token to withdraw. /// @param recipient Address to withdraw tokens to. /// @param amount the amount of ERC20 tokens to withdraw. function adminWithdrawFees( address handlerAddress, address tokenAddress, address recipient, uint256 amount ) public virtual nonReentrant onlyRole(EMERGENCY_ROLE) { IERCHandler handler = IERCHandler(handlerAddress); handler.withdrawFees(tokenAddress, recipient, amount); emit AdminWithdraw(handlerAddress, tokenAddress, recipient, amount); } /// @notice Used to set feeStatus /// @notice Only callable by admin. function adminSetFeeStatus(bytes32 resourceID, bool status) public virtual onlyRole(DEFAULT_ADMIN_ROLE) { address handlerAddress = _resourceIDToHandlerAddress[resourceID]; IERCHandler handler = IERCHandler(handlerAddress); handler.toggleFeeStatus(status); } // Fee Function Starts // /// @notice Used to set fee // /// @notice Only callable by feeSetter. // function setBridgeFee( // bytes32 resourceID, // uint8 destinationChainID, // address feeTokenAddress, // uint256 transferFee, // uint256 exchangeFee, // bool accepted // ) public virtual notUnsupportedChain(destinationChainID) onlyRole(FEE_SETTER_ROLE) { // address handlerAddress = _resourceIDToHandlerAddress[resourceID]; // IERCHandler handler = IERCHandler(handlerAddress); // require(handler.getFeeStatus(), "fee is not enabled"); // handler.setBridgeFee(destinationChainID, feeTokenAddress, transferFee, exchangeFee, accepted); // } /// @notice Used to get bridge fee function getBridgeFee( bytes32 resourceID, uint8 destChainID, address feeTokenAddress ) public view notUnsupportedChain(destChainID) returns (uint256, uint256) { address handlerAddress = _resourceIDToHandlerAddress[resourceID]; IERCHandler handler = IERCHandler(handlerAddress); return handler.getBridgeFee(destChainID, feeTokenAddress); } // Fee Function Ends // Deposit Function Starts /// @notice Initiates a cross-chain transfer for ERC-20 tokens /// @param destinationChainID Destination ChainId /// @param resourceID ResourceID to be used when making deposits. /// @param data Data required for the transfer /// @param flags Identifiers for Dex /// @param path Array of tokens to be swapped to get to the destination token /// @param feeTokenAddress Address of the fee token function deposit( uint8 destinationChainID, bytes32 resourceID, bytes calldata data, uint256[] memory flags, address[] memory path, bytes[] calldata dataTx, address feeTokenAddress ) public virtual notUnsupportedChain(destinationChainID) nonReentrant whenNotPaused isWhitelisted { _deposit(destinationChainID, resourceID, data, flags, path, dataTx, feeTokenAddress); } /// @notice Initiates a cross-chain transfer for native tokens /// @param destinationChainID Destination ChainId /// @param resourceID ResourceID to be used when making deposits. /// @param data Data required for the transfer /// @param flags Identifiers for Dex /// @param path Array of tokens to be swapped to get to the destination token /// @param feeTokenAddress Address of the fee token function depositETH( uint8 destinationChainID, bytes32 resourceID, bytes calldata data, uint256[] memory flags, address[] memory path, bytes[] calldata dataTx, address feeTokenAddress ) public payable virtual notUnsupportedChain(destinationChainID) nonReentrant whenNotPaused isWhitelisted { IERCHandler ercHandler = IERCHandler(_resourceIDToHandlerAddress[resourceID]); require(address(ercHandler) != address(0), "resourceID not mapped to handler"); require(msg.value > 0, "depositETH: No native assets transferred"); address weth = ercHandler._WETH(); IWETH(weth).deposit{ value: msg.value }(); require(IWETH(weth).transfer(msg.sender, msg.value)); _deposit(destinationChainID, resourceID, data, flags, path, dataTx, feeTokenAddress); } /// @notice Used notify bridge for generic deposit /// @notice Can only be called by Generic handler /// @param _destChainID Destination ChainId /// @param _resourceID ResourceID to be used when making deposits. function genericDeposit(uint8 _destChainID, bytes32 _resourceID) external notUnsupportedChain(_destChainID) whenNotPaused returns (uint64) { require( _genericWhitelist[_resourceIDToHandlerAddress[_resourceID]] == true || _sequencerWhitelist[_resourceIDToHandlerAddress[_resourceID]] == true, "Bridge: Contract neither sequencer nor generic handler" ); require( _resourceIDToHandlerAddress[_resourceID] == msg.sender, "Bridge: Resource ID does not match with the handler" ); uint64 depositNonce = ++_depositCounts[_destChainID]; emit Deposit(_destChainID, _resourceID, depositNonce, 0); return depositNonce; } /// @notice This is a private function and Initiates a cross-chain transfer for ERC-20 and native tokens /// @param destinationChainID Destination ChainId /// @param resourceID ResourceID to be used when making deposits. /// @param data Data required for the transfer /// @param flags Identifiers for Dex /// @param path Array of tokens to be swapped to get to the destination token /// @param feeTokenAddress Address of the fee token function _deposit( uint8 destinationChainID, bytes32 resourceID, bytes calldata data, uint256[] memory flags, address[] memory path, bytes[] calldata dataTx, address feeTokenAddress ) private { IDepositExecute.SwapInfo memory swapDetails = unpackDepositData(data); swapDetails.depositer = msg.sender; swapDetails.flags = flags; swapDetails.path = path; swapDetails.feeTokenAddress = feeTokenAddress; swapDetails.dataTx = dataTx; swapDetails.handler = _resourceIDToHandlerAddress[resourceID]; require(swapDetails.handler != address(0), "resourceID not mapped to handler"); swapDetails.depositNonce = ++_depositCounts[destinationChainID]; IDepositExecute depositHandler = IDepositExecute(swapDetails.handler); depositHandler.deposit(resourceID, destinationChainID, swapDetails.depositNonce, swapDetails); // call Gateway contract emit Deposit(destinationChainID, resourceID, swapDetails.depositNonce, swapDetails.widgetID); } /// @notice This is an internal function to decode the data for transfer /// @param data Data required to be decoded /// @return depositData function unpackDepositData(bytes calldata data) internal pure returns (IDepositExecute.SwapInfo memory depositData) { IDepositExecute.SwapInfo memory swapDetails; uint256 isDestNative; ( swapDetails.srcTokenAmount, swapDetails.srcStableTokenAmount, swapDetails.destStableTokenAmount, swapDetails.destTokenAmount, isDestNative, swapDetails.lenRecipientAddress, swapDetails.lenSrcTokenAddress, swapDetails.lenDestTokenAddress ) = abi.decode(data, (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256)); //Note: to avoid stack too deep error, we are decoding it again. (, , , , , , , , swapDetails.widgetID) = abi.decode( data, (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) ); swapDetails.isDestNative = isDestNative == 0 ? false : true; swapDetails.index = 288; // 32 * 6 -> 9 bytes memory recipient = bytes(data[swapDetails.index:swapDetails.index + swapDetails.lenRecipientAddress]); swapDetails.index = swapDetails.index + swapDetails.lenRecipientAddress; bytes memory srcToken = bytes(data[swapDetails.index:swapDetails.index + swapDetails.lenSrcTokenAddress]); swapDetails.index = swapDetails.index + swapDetails.lenSrcTokenAddress; bytes memory destStableToken = bytes( data[swapDetails.index:swapDetails.index + swapDetails.lenDestTokenAddress] ); swapDetails.index = swapDetails.index + swapDetails.lenDestTokenAddress; bytes memory destToken = bytes(data[swapDetails.index:swapDetails.index + swapDetails.lenDestTokenAddress]); bytes20 srcTokenAddress; bytes20 destStableTokenAddress; bytes20 destTokenAddress; bytes20 recipientAddress; assembly { srcTokenAddress := mload(add(srcToken, 0x20)) destStableTokenAddress := mload(add(destStableToken, 0x20)) destTokenAddress := mload(add(destToken, 0x20)) recipientAddress := mload(add(recipient, 0x20)) } swapDetails.srcTokenAddress = srcTokenAddress; swapDetails.destStableTokenAddress = address(destStableTokenAddress); swapDetails.destTokenAddress = destTokenAddress; swapDetails.recipient = address(recipientAddress); return swapDetails; } // Deposit Function Ends /// @notice Allows staking into liquidity pools. /// @notice Only callable when Bridge is not paused. /// @param handler handler address /// @param tokenAddress Asset which needs to be staked. /// @param amount Amount that needs to be staked. /// @notice Emits {Stake} event. function stake( address handler, address tokenAddress, uint256 amount ) public virtual whenNotPaused { ILiquidityPool depositHandler = ILiquidityPool(handler); depositHandler.stake(msg.sender, tokenAddress, amount); emit Stake(msg.sender, amount, tokenAddress); } /// @notice Allows staking ETH into liquidity pools. /// @notice Only callable when Bridge is not paused. /// @param handler handler address /// @notice Emits {Stake} event. function stakeETH(address handler) public payable virtual nonReentrant whenNotPaused { ILiquidityPool depositHandler = ILiquidityPool(handler); IERCHandler ercHandler = IERCHandler(handler); address WETH = ercHandler._WETH(); uint256 amount = msg.value; require(amount > 0, "stakeETH: insufficient eth provided"); IWETH(WETH).deposit{ value: amount }(); require(IWETH(WETH).transfer(handler, amount)); depositHandler.stakeETH(msg.sender, WETH, amount); emit Stake(msg.sender, amount, WETH); } /// @notice Allows unstaking from liquidity pools. /// @notice Only callable when Bridge is not paused. /// @param handler handler address /// @param tokenAddress Asset which needs to be unstaked. /// @param amount Amount that needs to be unstaked. /// @notice Emits {Unstake} event. function unstake( address handler, address tokenAddress, uint256 amount ) public virtual whenNotPaused { ILiquidityPool depositHandler = ILiquidityPool(handler); depositHandler.unstake(msg.sender, tokenAddress, amount); emit Unstake(msg.sender, amount, tokenAddress); } /// @notice Allows unstaking ETH from liquidity pools. /// @notice Only callable when Bridge is not paused. /// @param handler handler address /// @param amount Amount that needs to be unstaked. /// @notice Emits {Unstake} event. function unstakeETH(address handler, uint256 amount) public virtual nonReentrant whenNotPaused { ILiquidityPool depositHandler = ILiquidityPool(handler); IERCHandler ercHandler = IERCHandler(handler); address WETH = ercHandler._WETH(); depositHandler.unstakeETH(msg.sender, WETH, amount); emit Unstake(msg.sender, amount, WETH); } // Stating/UnStaking Function Ends // Voting Function starts /// @notice Returns a proposal. /// @param originChainID Chain ID deposit originated from. /// @param depositNonce ID of proposal generated by proposal's origin Bridge contract. /// @param resourceId resource Id for the asset. /// @param dataHash Hash of data to be provided when deposit proposal is executed. function getProposal( uint8 originChainID, uint64 depositNonce, bytes32 resourceId, bytes32 dataHash ) public view virtual returns (IVoterUpgradeable.issueStruct memory status) { // CRITICAL: dont change below code bytes32 proposalHash = keccak256(abi.encodePacked(originChainID, depositNonce, dataHash, resourceId)); return _voter.fetchIssueMap(_proposals[proposalHash]); } /// @notice When called, {msg.sender} will be marked as voting in favor of proposal. /// @notice Only callable by relayers when Bridge is not paused. /// @param chainID ID of chain deposit originated from. /// @param depositNonce ID of deposited generated by origin Bridge contract. /// @param dataHash Hash of data provided when deposit was made. /// @notice Proposal must not have already been passed or executed. /// @notice {msg.sender} must not have already voted on proposal. /// @notice Emits {ProposalEvent} event with status indicating the proposal status. /// @notice Emits {ProposalVote} event. function voteProposal( uint8 chainID, uint64 depositNonce, bytes32 resourceID, bytes32 dataHash ) public virtual isResourceID(resourceID) onlyRole(RELAYER_ROLE) whenNotPaused { require( (!_isNonceExecuted[chainID][depositNonce]) && (_nonceCheckpoint[chainID] < depositNonce), "nonce expired" ); // CRITICAL: dont change below code bytes32 proposalHash = keccak256(abi.encodePacked(chainID, depositNonce, dataHash, resourceID)); if (_proposals[proposalHash] == 0) { uint256 id = _voter.createProposal(block.number + _expiry, _quorum); _proposals[proposalHash] = id; emit ProposalEvent(chainID, depositNonce, IVoterUpgradeable.ProposalStatus.Active, dataHash); } else if (_voter.fetchIsExpired(_proposals[proposalHash])) { _voter.setStatus(_proposals[proposalHash]); emit ProposalEvent(chainID, depositNonce, _voter.getStatus(_proposals[proposalHash]), dataHash); return; } if (_voter.getStatus(_proposals[proposalHash]) != IVoterUpgradeable.ProposalStatus.Cancelled) { _voter.vote(_proposals[proposalHash], 1, msg.sender); emit ProposalVote(chainID, depositNonce, _voter.getStatus(_proposals[proposalHash]), dataHash); if (_voter.getStatus(_proposals[proposalHash]) == IVoterUpgradeable.ProposalStatus.Passed) { emit ProposalEvent(chainID, depositNonce, _voter.getStatus(_proposals[proposalHash]), dataHash); } } } /// @notice Cancels a deposit proposal. /// @notice Only callable by admin when Bridge is not paused. /// @param chainID ID of chain deposit originated from. /// @param depositNonce ID of deposited generated by origin Bridge contract. /// @param resourceID resourceID for the asset. /// @param dataHash Hash of data originally provided when deposit was made. function cancelProposal( uint8 chainID, uint64 depositNonce, bytes32 resourceID, bytes32 dataHash ) public onlyRole(DEFAULT_ADMIN_ROLE) whenNotPaused { // CRITICAL: dont change below code bytes32 proposalHash = keccak256(abi.encodePacked(chainID, depositNonce, dataHash, resourceID)); IVoterUpgradeable.ProposalStatus currentStatus = _voter.getStatus(_proposals[proposalHash]); require(currentStatus == IVoterUpgradeable.ProposalStatus.Cancelled, "Proposal must be cancelled"); delete _proposals[proposalHash]; } /// @notice Executes a deposit proposal that is considered passed using a specified handler contract. /// @notice Only callable by relayers when Bridge is not paused. /// @param chainID ID of chain deposit originated from. /// @param resourceID ResourceID to be used when making deposits. /// @param depositNonce ID of deposited generated by origin Bridge contract. /// @param data Data originally provided when deposit was made. /// @notice Proposal must have Passed status. /// @notice Hash of {data} must equal proposal's {dataHash}. /// @notice Emits {ProposalEvent} event with status {Executed}. // Request from router function executeProposal( uint8 chainID, uint64 depositNonce, bytes calldata data, bytes32 resourceID, uint256[] memory flags, address[] memory path, bytes[] memory dataTx ) public virtual onlyRole(RELAYER_ROLE) whenNotPaused { require( (!_isNonceExecuted[chainID][depositNonce]) && (_nonceCheckpoint[chainID] < depositNonce), "nonce issue" ); bytes32 dataHash = keccak256(abi.encodePacked(_resourceIDToHandlerAddress[resourceID], data)); // CRITICAL: dont change below code bytes32 proposalHash = keccak256(abi.encodePacked(chainID, depositNonce, dataHash, resourceID)); if (_genericWhitelist[_resourceIDToHandlerAddress[resourceID]]) { IGenericHandler genericHandler = IGenericHandler(_resourceIDToHandlerAddress[resourceID]); genericHandler.executeProposal(data); emit ProposalEvent(chainID, depositNonce, IVoterUpgradeable.ProposalStatus.Executed, dataHash); } else if (_sequencerWhitelist[_resourceIDToHandlerAddress[resourceID]]) { ISequencerHandler sequencerHandler = ISequencerHandler(_resourceIDToHandlerAddress[resourceID]); sequencerHandler.executeProposal(data); emit SequencerEvent(chainID, depositNonce, IVoterUpgradeable.ProposalStatus.Executed, dataHash); } else { address settlementToken; IDepositExecute.SwapInfo memory swapDetails = unpackDepositData(data); swapDetails.dataTx = dataTx; swapDetails.flags = flags; swapDetails.path = path; swapDetails.index = chainID; swapDetails.depositNonce = depositNonce; IDepositExecute depositHandler = IDepositExecute(_resourceIDToHandlerAddress[resourceID]); (settlementToken, swapDetails.returnAmount) = depositHandler.executeProposal(swapDetails, resourceID); emit Settlement( chainID, depositNonce, settlementToken, swapDetails.returnAmount, IVoterUpgradeable.ProposalStatus.Executed ); emit ProposalEvent(chainID, depositNonce, IVoterUpgradeable.ProposalStatus.Executed, dataHash); } IVoterUpgradeable.ProposalStatus currentStatus = _voter.getStatus(_proposals[proposalHash]); require(currentStatus == IVoterUpgradeable.ProposalStatus.Passed, "Proposal must have Passed status"); _voter.executeProposal(_proposals[proposalHash]); _isNonceExecuted[chainID][depositNonce] = true; } // Voting Function ends }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure( address newImplementation, bytes memory data, bool forceCall ) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlotUpgradeable.BooleanSlot storage rollbackTesting = StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; _functionDelegateCall( newImplementation, abi.encodeWithSignature("upgradeTo(address)", oldImplementation) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _upgradeTo(newImplementation); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { __Context_init_unchained(); __ERC165_init_unchained(); __AccessControl_init_unchained(); } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @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) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @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 revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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 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; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { __ERC1967Upgrade_init_unchained(); __UUPSUpgradeable_init_unchained(); } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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; } uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.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 AddressUpgradeable { /** * @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 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); } } } }
contracts/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERC20Upgradeable { function transfer(address, uint256) external; function decimals() external view returns (uint8); }
contracts/interfaces/IGenericHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler that handles generic deposits and deposit executions. /// @author Router Protocol. interface IGenericHandler { function genericDeposit( uint8 _destChainID, bytes4 _selector, bytes calldata _data, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); function executeProposal(bytes calldata data) external; /// @notice Function to replay a transaction which was stuck due to underpricing of gas /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayGenericDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
contracts/interfaces/IERCHandlerDecimals.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandlerDecimals { function setTokenDecimals( address[] calldata tokenAddress, uint8[] calldata destinationChainID, uint8[] calldata decimals ) external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { __ERC165_init_unchained(); } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
contracts/interfaces/IDepositExecute.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface IDepositExecute { struct SwapInfo { address feeTokenAddress; uint64 depositNonce; uint256 index; uint256 returnAmount; address recipient; address stableTokenAddress; address handler; uint256 srcTokenAmount; uint256 srcStableTokenAmount; uint256 destStableTokenAmount; uint256 destTokenAmount; uint256 lenRecipientAddress; uint256 lenSrcTokenAddress; uint256 lenDestTokenAddress; bytes20 srcTokenAddress; address srcStableTokenAddress; bytes20 destTokenAddress; address destStableTokenAddress; bytes[] dataTx; uint256[] flags; address[] path; address depositer; bool isDestNative; uint256 widgetID; } /// @notice It is intended that deposit are made using the Bridge contract. /// @param destinationChainID Chain ID deposit is expected to be bridged to. /// @param depositNonce This value is generated as an ID by the Bridge contract. /// @param swapDetails Swap details function deposit( bytes32 resourceID, uint8 destinationChainID, uint64 depositNonce, SwapInfo calldata swapDetails ) external; /// @notice It is intended that proposals are executed by the Bridge contract. function executeProposal(SwapInfo calldata swapDetails, bytes32 resourceID) external returns (address, uint256); }
contracts/interfaces/IERCHandler.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /// @title Interface to be used with handlers that support ERC20s and ERC721s. /// @author Router Protocol. interface IERCHandler { function withdrawFees( address tokenAddress, address recipient, uint256 amount ) external; function getBridgeFee(uint8 destinationChainID, address feeTokenAddress) external view returns (uint256, uint256); function setBridgeFee( uint8 destinationChainID, address feeTokenAddress, uint256 transferFee, uint256 exchangeFee, bool accepted ) external; function toggleFeeStatus(bool status) external; function getFeeStatus() external view returns (bool); function _ETH() external view returns (address); function _WETH() external view returns (address); function resourceIDToTokenContractAddress(bytes32 resourceID) external view returns (address); /// @notice Correlates {resourceID} with {contractAddress}. /// @param resourceID ResourceID to be used when making deposits. /// @param contractAddress Address of contract to be called when a deposit is made and a deposited is executed. function setResource(bytes32 resourceID, address contractAddress) external; // function setTokenDecimals( // address[] calldata tokenAddress, // uint8[] calldata destinationChainID, // uint8[] calldata decimals // ) external; /// @notice Sets oneSplitAddress for the handler /// @param contractAddress Address of oneSplit contract function setOneSplitAddress(address contractAddress) external; /// @notice Correlates {resourceID} with {contractAddress}. /// @param contractAddress Address of contract for qhich liquidity pool needs to be created. function setLiquidityPool(address contractAddress, address lpAddress) external; // function setLiquidityPool( // string memory name, // string memory symbol, // uint8 decimals, // address contractAddress, // address lpAddress // ) external; /// @notice Sets liquidity pool owner for an existing LP. /// @dev Can only be set by the bridge /// @param oldOwner Address of the old owner of LP /// @param newOwner Address of the new owner for LP /// @param tokenAddress Address of ERC20 token /// @param lpAddress Address of LP function setLiquidityPoolOwner( address oldOwner, address newOwner, address tokenAddress, address lpAddress ) external; /// @notice Marks {contractAddress} as mintable/burnable. /// @param contractAddress Address of contract to be used when making or executing deposits. /// @param status Boolean flag for burnanble status. function setBurnable(address contractAddress, bool status) external; /// @notice Used to manually release funds from ERC safes. /// @param tokenAddress Address of token contract to release. /// @param recipient Address to release tokens to. /// @param amountOrTokenID Either the amount of ERC20 tokens or the ERC721 token ID to release. function withdraw( address tokenAddress, address recipient, uint256 amountOrTokenID ) external; }
contracts/interfaces/ILiquidityPool.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; /// @title Interface for handler contracts that support deposits and deposit executions. /// @author Router Protocol. interface ILiquidityPool { /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stake( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param depositor stakes liquidity in the pool . /// @param tokenAddress staking token for which liquidity needs to be added. /// @param amount Amount that needs to be staked. function stakeETH( address depositor, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstake( address unstaker, address tokenAddress, uint256 amount ) external; /// @notice Staking should be done by using bridge contract. /// @param unstaker removes liquidity from the pool. /// @param tokenAddress staking token of which liquidity needs to be removed. /// @param amount Amount that needs to be unstaked. function unstakeETH( address unstaker, address tokenAddress, uint256 amount ) external; }
contracts/interfaces/ISequencerHandler.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; /** @title Interface for handler that handles sequencer deposits and deposit executions. @author Router Protocol. */ interface ISequencerHandler { /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithERC( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls as well as ERC20 cross-chain calls at once. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _erc20 data regarding the transaction for erc20. /// @param _swapData data regarding the swapDetails for erc20 transaction. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. /// @param _isTransferFirst sequence for erc20 and generic call. True for prioritizing erc20 over generic call. function genericDepositWithETH( uint8 _destChainID, bytes memory _erc20, bytes calldata _swapData, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken, bool _isTransferFirst ) external payable returns (uint64); /// @notice Function fired to trigger Cross Chain Communication. /// @dev Used to transact generic calls. /// @dev Can only be used when the contract is not paused and the dest chain is not unsupported. /// @dev Only callable by crosstalk contracts on supported chains and only when contract is not paused. /// @param _destChainID chainId of the destination chain defined by Router Protocol. /// @param _generic data for generic cross-chain call. /// @param _gasLimit gas limit for the call. /// @param _gasPrice gas price for the call. /// @param _feeToken fee token for payment of fees. function genericDeposit( uint8 _destChainID, bytes memory _generic, uint256 _gasLimit, uint256 _gasPrice, address _feeToken ) external returns (uint64); /// @notice Function Executes a cross chain request on destination chain. /// @dev Can only be triggered by bridge. /// @param _data Cross chain data recived from relayer consisting of the deposit record. function executeProposal(bytes calldata _data) external returns (bool); /// @notice Function to replay a transaction which was stuck due to underpricing of gas. /// @param _destChainID Destination ChainID /// @param _depositNonce Nonce for the transaction. /// @param _gasLimit Gas limit allowed for the transaction. /// @param _gasPrice Gas Price for the transaction. function replayDeposit( uint8 _destChainID, uint64 _depositNonce, uint256 _gasLimit, uint256 _gasPrice ) external; /// @notice Fetches chainID for the native chain function fetch_chainID() external view returns (uint8); }
contracts/interfaces/IVoterUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.2; /** @title Interface to be used with handlers that support ERC20s and ERC721s. @author Router Protocol. */ interface IVoterUpgradeable { enum ProposalStatus { Inactive, Active, Passed, Executed, Cancelled } struct issueStruct { ProposalStatus status; uint256 startBlock; uint256 endBlock; uint64 quorum; uint256 maxVotes; uint8 resultOption; } function Voted(uint256, address) external view returns (bool); function mint(address) external; function burn(address account) external; function balanceOf(address) external view returns (uint256); function fetchIssueMap(uint256 _issue) external view returns (issueStruct memory issue); function fetchIsExpired(uint256 _issue) external view returns (bool status); function createProposal(uint256 endBlock, uint64 quorum) external returns (uint256 id); function setStatus(uint256 issueId) external returns (bool success); function getStatus(uint256 issueId) external view returns (ProposalStatus status); function vote( uint256 issueId, uint8 option, address relayer ) external returns (bool success); function executeProposal(uint256 issueId) external returns (bool success); }
contracts/interfaces/IWETH.sol
// SPDX-License-Identifier: MIT pragma solidity >=0.8.2; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; function transferFrom( address src, address dst, uint256 wad ) external returns (bool); function approve(address guy, uint256 wad) external returns (bool); }
Contract ABI
[{"type":"event","name":"AddedWhitelist","inputs":[{"type":"address","name":"whitelistAddress","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"AdminChanged","inputs":[{"type":"address","name":"previousAdmin","internalType":"address","indexed":false},{"type":"address","name":"newAdmin","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"AdminWithdraw","inputs":[{"type":"address","name":"handler","internalType":"address","indexed":false},{"type":"address","name":"tokenAddress","internalType":"address","indexed":false},{"type":"address","name":"recipient","internalType":"address","indexed":false},{"type":"uint256","name":"amountOrTokenID","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"BeaconUpgraded","inputs":[{"type":"address","name":"beacon","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Deposit","inputs":[{"type":"uint8","name":"destinationChainID","internalType":"uint8","indexed":true},{"type":"bytes32","name":"resourceID","internalType":"bytes32","indexed":true},{"type":"uint64","name":"depositNonce","internalType":"uint64","indexed":true},{"type":"uint256","name":"widgetID","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"FeeSetterAdded","inputs":[{"type":"address","name":"feeSetter","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"FeeSetterRemoved","inputs":[{"type":"address","name":"feeSetter","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"ProposalEvent","inputs":[{"type":"uint8","name":"originChainID","internalType":"uint8","indexed":false},{"type":"uint64","name":"depositNonce","internalType":"uint64","indexed":false},{"type":"uint8","name":"status","internalType":"enum IVoterUpgradeable.ProposalStatus","indexed":false},{"type":"bytes32","name":"dataHash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"ProposalVote","inputs":[{"type":"uint8","name":"originChainID","internalType":"uint8","indexed":false},{"type":"uint64","name":"depositNonce","internalType":"uint64","indexed":false},{"type":"uint8","name":"status","internalType":"enum IVoterUpgradeable.ProposalStatus","indexed":false},{"type":"bytes32","name":"dataHash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"RelayerAdded","inputs":[{"type":"address","name":"relayer","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RelayerRemoved","inputs":[{"type":"address","name":"relayer","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RemovedWhitelist","inputs":[{"type":"address","name":"whitelistAddress","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"SequencerEvent","inputs":[{"type":"uint8","name":"originChainID","internalType":"uint8","indexed":false},{"type":"uint64","name":"depositNonce","internalType":"uint64","indexed":false},{"type":"uint8","name":"status","internalType":"enum IVoterUpgradeable.ProposalStatus","indexed":false},{"type":"bytes32","name":"dataHash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"event","name":"Settlement","inputs":[{"type":"uint8","name":"originChainID","internalType":"uint8","indexed":true},{"type":"uint64","name":"depositNonce","internalType":"uint64","indexed":true},{"type":"address","name":"settlementToken","internalType":"address","indexed":false},{"type":"uint256","name":"settlementAmount","internalType":"uint256","indexed":false},{"type":"uint8","name":"status","internalType":"enum IVoterUpgradeable.ProposalStatus","indexed":false}],"anonymous":false},{"type":"event","name":"Stake","inputs":[{"type":"address","name":"staker","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"pool","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Unstake","inputs":[{"type":"address","name":"unstaker","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"pool","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"UnsupportedChain","inputs":[{"type":"uint8","name":"destinationChainID","internalType":"uint8","indexed":true},{"type":"bool","name":"isUnsupported","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"implementation","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"WhitelistingSetting","inputs":[{"type":"bool","name":"status","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"expiryChanged","inputs":[{"type":"uint256","name":"expiry","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"quorumChanged","inputs":[{"type":"uint64","name":"quorum","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"EMERGENCY_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"FEE_SETTER_ROLE","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"GetProposalHash","inputs":[{"type":"uint8","name":"chainID","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"},{"type":"bytes32","name":"dataHash","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"HasVotedOnProposal","inputs":[{"type":"uint8","name":"chainID","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"},{"type":"bytes32","name":"dataHash","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"PAUSER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"RELAYER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"RESOURCE_SETTER","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"_quorum","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IVoterUpgradeable"}],"name":"_voter","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addToWhitelist","inputs":[{"type":"address","name":"_beneficiary","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminChangeExpiry","inputs":[{"type":"uint256","name":"newExpiry","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminChangeQuorum","inputs":[{"type":"uint256","name":"newQuorum","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetBurnable","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"bool","name":"status","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetFeeStatus","inputs":[{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"bool","name":"status","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetGenericResource","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetLiquidityPool","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"address","name":"lpAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetLiquidityPoolOwner","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"address","name":"oldOwner","internalType":"address"},{"type":"address","name":"newOwner","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"address","name":"lpAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetNonceCheckpoint","inputs":[{"type":"uint8","name":"srcChainID","internalType":"uint8"},{"type":"uint64","name":"nonceCheckpoint","internalType":"uint64"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetOneSplitAddress","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"address","name":"contractAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetResource","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"address","name":"tokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSetSequencerResource","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminWithdraw","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminWithdrawFees","inputs":[{"type":"address","name":"handlerAddress","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelProposal","inputs":[{"type":"uint8","name":"chainID","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"bytes32","name":"dataHash","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deposit","inputs":[{"type":"uint8","name":"destinationChainID","internalType":"uint8"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256[]","name":"flags","internalType":"uint256[]"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"bytes[]","name":"dataTx","internalType":"bytes[]"},{"type":"address","name":"feeTokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"depositETH","inputs":[{"type":"uint8","name":"destinationChainID","internalType":"uint8"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256[]","name":"flags","internalType":"uint256[]"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"bytes[]","name":"dataTx","internalType":"bytes[]"},{"type":"address","name":"feeTokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"executeProposal","inputs":[{"type":"uint8","name":"chainID","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"uint256[]","name":"flags","internalType":"uint256[]"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"bytes[]","name":"dataTx","internalType":"bytes[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"fetch_chainID","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"fetch_depositCounts","inputs":[{"type":"uint8","name":"_id","internalType":"uint8"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"fetch_expiry","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"fetch_proposals","inputs":[{"type":"bytes32","name":"_id","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"fetch_resourceIDToHandlerAddress","inputs":[{"type":"bytes32","name":"_id","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"fetch_whitelist","inputs":[{"type":"address","name":"_beneficiary","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"fetch_whitelistEnabled","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"genericDeposit","inputs":[{"type":"uint8","name":"_destChainID","internalType":"uint8"},{"type":"bytes32","name":"_resourceID","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBridgeFee","inputs":[{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"uint8","name":"destChainID","internalType":"uint8"},{"type":"address","name":"feeTokenAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"getNonceCheckpoint","inputs":[{"type":"uint8","name":"srcChainId","internalType":"uint8"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"status","internalType":"struct IVoterUpgradeable.issueStruct","components":[{"type":"uint8","name":"status","internalType":"enum IVoterUpgradeable.ProposalStatus"},{"type":"uint256","name":"startBlock","internalType":"uint256"},{"type":"uint256","name":"endBlock","internalType":"uint256"},{"type":"uint64","name":"quorum","internalType":"uint64"},{"type":"uint256","name":"maxVotes","internalType":"uint256"},{"type":"uint8","name":"resultOption","internalType":"uint8"}]}],"name":"getProposal","inputs":[{"type":"uint8","name":"originChainID","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"},{"type":"bytes32","name":"resourceId","internalType":"bytes32"},{"type":"bytes32","name":"dataHash","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"uint8","name":"chainID","internalType":"uint8"},{"type":"uint256","name":"quorum","internalType":"uint256"},{"type":"uint256","name":"expiry","internalType":"uint256"},{"type":"address","name":"voter","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isNonceExecuted","inputs":[{"type":"uint8","name":"srcChainId","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeFromWhitelist","inputs":[{"type":"address","name":"_beneficiary","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setUnsupportedChain","inputs":[{"type":"uint8","name":"destChainId","internalType":"uint8"},{"type":"bool","name":"isUnsupported","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setWhitelisting","inputs":[{"type":"bool","name":"value","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"stake","inputs":[{"type":"address","name":"handler","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"stakeETH","inputs":[{"type":"address","name":"handler","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalRelayers","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unstake","inputs":[{"type":"address","name":"handler","internalType":"address"},{"type":"address","name":"tokenAddress","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unstakeETH","inputs":[{"type":"address","name":"handler","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"upgradeTo","inputs":[{"type":"address","name":"newImplementation","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"upgradeToAndCall","inputs":[{"type":"address","name":"newImplementation","internalType":"address"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"voteProposal","inputs":[{"type":"uint8","name":"chainID","internalType":"uint8"},{"type":"uint64","name":"depositNonce","internalType":"uint64"},{"type":"bytes32","name":"resourceID","internalType":"bytes32"},{"type":"bytes32","name":"dataHash","internalType":"bytes32"}]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x60a06040523060601b60805234801561001757600080fd5b5060805160601c615bf96200004c60003960008181611a6001528181611aa001528181611ea10152611ee10152615bf96000f3fe6080604052600436106102f65760003560e01c80637bd3af5011610197578063b2c0f640116100ed578063dfff261b11610090578063dfff261b14610a23578063e43252d714610a5d578063e63ab1e914610a7d578063e7ad01f914610a9f578063e934768314610abf578063ebc2693914610af3578063f19ba3f814610b28578063fe79b9a914610b48576102fd565b8063b2c0f64014610925578063bb5ba77e14610948578063bf6eac2f14610961578063c3cf4c8014610981578063c794c698146109a1578063cb10f215146109c1578063d547741f146109e1578063db618e2a14610a01576102fd565b80637bd3af50146107545780637d026d96146107745780638456cb591461079457806385802129146107a9578063862159ab146107c95780638ab1d681146107e05780638ac4c1841461080057806391d1485414610820578063926d7d7f14610840578063946fe3e8146108625780639be8eb5314610875578063a07e338d14610895578063a217fddf146108c3578063a42570df146108d8578063a5285090146108f8576102fd565b80633f4ba83a1161024c5780633f4ba83a1461055457806343cee7191461056957806349b9ac5e146105895780634d98a61b146105c25780634f1ef286146105d857806350d1882e146105eb5780635af5f7ba146106225780635bc51147146106425780635c975abb1461067c57806360829f8a14610694578063611336d6146106b45780636369f9e9146106d45780636495c503146106f4578063700803b514610714578063780cf00414610734576102fd565b806301ffc9a7146103025780630e5f06e5146103375780631dd7e81f146103715780631ff013f114610393578063200a99f5146103b357806320df4359146103fc578063248a9ca31461042c5780632becbe311461044c5780632e09305c1461046c5780632f2ff15d1461047f57806336568abe1461049f5780633659cfe6146104bf5780633c047803146104df5780633db9b42a146104ff5780633dd301d914610534576102fd565b366102fd57005b600080fd5b34801561030e57600080fd5b5061032261031d366004614cba565b610b68565b60405190151581526020015b60405180910390f35b34801561034357600080fd5b50610322610352366004614928565b6001600160a01b03166000908152610167602052604090205460ff1690565b34801561037d57600080fd5b5061039161038c366004614b21565b610ba1565b005b34801561039f57600080fd5b506103916103ae366004615042565b610c01565b3480156103bf57600080fd5b506103226103ce366004614fe6565b60ff918216600090815261016c602090815260408083206001600160401b0394909416835292905220541690565b34801561040857600080fd5b5061041e600080516020615b4683398151915281565b60405190815260200161032e565b34801561043857600080fd5b5061041e610447366004614c34565b611440565b34801561045857600080fd5b50610391610467366004614a52565b611455565b61039161047a366004614ec0565b61155d565b34801561048b57600080fd5b5061039161049a366004614c4c565b611829565b3480156104ab57600080fd5b506103916104ba366004614c4c565b6119d7565b3480156104cb57600080fd5b506103916104da366004614928565b611a55565b3480156104eb57600080fd5b506103916104fa366004614b21565b611b1e565b34801561050b57600080fd5b506101635461052790600160401b90046001600160a01b031681565b60405161032e9190615549565b34801561054057600080fd5b5061032261054f366004615013565b611c9d565b34801561056057600080fd5b50610391611d72565b34801561057557600080fd5b50610391610584366004614ec0565b611db5565b34801561059557600080fd5b50610163546105aa906001600160401b031681565b6040516001600160401b03909116815260200161032e565b3480156105ce57600080fd5b506101605461041e565b6103916105e6366004614b82565b611e96565b3480156105f757600080fd5b50610527610606366004614c34565b600090815261016560205260409020546001600160a01b031690565b34801561062e57600080fd5b5061039161063d366004614bfc565b611f4c565b34801561064e57600080fd5b506105aa61065d366004614e5a565b60ff16600090815261016460205260409020546001600160401b031690565b34801561068857600080fd5b5060335460ff16610322565b3480156106a057600080fd5b506103916106af366004614ae1565b611fa2565b3480156106c057600080fd5b506103916106cf366004614b21565b612072565b3480156106e057600080fd5b506103916106ef366004614998565b6120d1565b34801561070057600080fd5b5061039161070f366004614fe6565b61214b565b34801561072057600080fd5b506105aa61072f366004614ea3565b6121de565b34801561074057600080fd5b5061039161074f366004614a52565b61242a565b34801561076057600080fd5b5061039161076f366004615042565b61249f565b34801561078057600080fd5b5061039161078f366004614c34565b612615565b3480156107a057600080fd5b50610391612657565b3480156107b557600080fd5b506103916107c4366004614aa2565b61269b565b3480156107d557600080fd5b5061041e6101625481565b3480156107ec57600080fd5b506103916107fb366004614928565b6126e0565b34801561080c57600080fd5b5061039161081b366004614960565b612760565b34801561082c57600080fd5b5061032261083b366004614c4c565b6127d2565b34801561084c57600080fd5b5061041e600080516020615b8683398151915281565b610391610870366004614928565b6127fd565b34801561088157600080fd5b50610391610890366004614c34565b612a9d565b3480156108a157600080fd5b5061041e6108b0366004614c34565b6000908152610166602052604090205490565b3480156108cf57600080fd5b5061041e600081565b3480156108e457600080fd5b506103916108f3366004615087565b612afd565b34801561090457600080fd5b50610918610913366004615042565b61314e565b60405161032e91906158e2565b34801561093157600080fd5b5061015f5460405160ff909116815260200161032e565b34801561095457600080fd5b506101615460ff16610322565b34801561096d57600080fd5b5061039161097c366004614ae1565b61324c565b34801561098d57600080fd5b5061039161099c366004614e76565b61330e565b3480156109ad57600080fd5b5061041e6109bc366004615013565b613375565b3480156109cd57600080fd5b506103916109dc366004614b4c565b6133ae565b3480156109ed57600080fd5b506103916109fc366004614c4c565b613419565b348015610a0d57600080fd5b5061041e600080516020615b2683398151915281565b348015610a2f57600080fd5b506105aa610a3e366004614e5a565b60ff16600090815261016d60205260409020546001600160401b031690565b348015610a6957600080fd5b50610391610a78366004614928565b6135bc565b348015610a8957600080fd5b5061041e600080516020615ba683398151915281565b348015610aab57600080fd5b50610391610aba3660046149e2565b61363f565b348015610acb57600080fd5b5061041e7fe6ad9a47fbda1dc18de1eb5eeb7d935e5e81b4748f3cfc61e233e64f8818206081565b348015610aff57600080fd5b50610b13610b0e366004614c94565b6136ca565b6040805192835260208301919091520161032e565b348015610b3457600080fd5b50610391610b43366004614c70565b6137a9565b348015610b5457600080fd5b50610391610b63366004614f9d565b6137f9565b60006001600160e01b03198216637965db0b60e01b1480610b9957506301ffc9a760e01b6001600160e01b03198316145b90505b919050565b600080516020615b26833981519152610bbb81335b61392b565b5060009081526101656020908152604080832080546001600160a01b039095166001600160a01b031990951685179055928252610169905220805460ff19166001179055565b6000828152610165602052604090205482906001600160a01b0316610c825760405162461bcd60e51b815260206004820152602c60248201527f4272696467655570677261646561626c653a204e6f2068616e646c657220666f60448201526b1c881c995cdbdd5c98d9525160a21b60648201526084015b60405180910390fd5b600080516020615b86833981519152610c9b8133610bb6565b60335460ff1615610cbe5760405162461bcd60e51b8152600401610c799061579c565b60ff808716600090815261016c602090815260408083206001600160401b038a16845290915290205416158015610d13575060ff8616600090815261016d60205260409020546001600160401b038087169116105b610d4f5760405162461bcd60e51b815260206004820152600d60248201526c1b9bdb98d948195e1c1a5c9959609a1b6044820152606401610c79565b600086868587604051602001610d689493929190615512565b60408051601f1981840301815291815281516020928301206000818152610166909352912054909150610e8c576101635461016054600091600160401b90046001600160a01b03169063ba831b9c90610dc190436159e9565b6101635460405160e084901b6001600160e01b031916815260048101929092526001600160401b03166024820152604401602060405180830381600087803b158015610e0c57600080fd5b505af1158015610e20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e449190614d6d565b600083815261016660205260409081902082905551909150600080516020615b6683398151915290610e7e908a908a906001908a90615939565b60405180910390a150611085565b6101635460008281526101666020526040908190205490516345737d1d60e11b81526004810191909152600160401b9091046001600160a01b031690638ae6fa3a9060240160206040518083038186803b158015610ee957600080fd5b505afa158015610efd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f219190614c18565b15611085576101635460008281526101666020526040908190205490516369ba1a7560e01b81526004810191909152600160401b9091046001600160a01b0316906369ba1a7590602401602060405180830381600087803b158015610f8557600080fd5b505af1158015610f99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fbd9190614c18565b50610163546000828152610166602052604090819020549051632e31150760e11b81526004810191909152600080516020615b668339815191529189918991600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561102e57600080fd5b505afa158015611042573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110669190614ce2565b876040516110779493929190615939565b60405180910390a150611438565b6004610163546000838152610166602052604090819020549051632e31150760e11b81526004810191909152600160401b9091046001600160a01b031690635c622a0e9060240160206040518083038186803b1580156110e457600080fd5b505afa1580156110f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111c9190614ce2565b600481111561113b57634e487b7160e01b600052602160045260246000fd5b1461143657610163546000828152610166602052604090819020549051630ce7fb8360e11b8152600481019190915260016024820152336044820152600160401b9091046001600160a01b0316906319cff70690606401602060405180830381600087803b1580156111ac57600080fd5b505af11580156111c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e49190614c18565b50610163546000828152610166602052604090819020549051632e31150760e11b815260048101919091527f25f8daaa4635a7729927ba3f5b3d59cc3320aca7c32c9db4e7ca7b95743436409189918991600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561126757600080fd5b505afa15801561127b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129f9190614ce2565b876040516112b09493929190615939565b60405180910390a16002610163546000838152610166602052604090819020549051632e31150760e11b81526004810191909152600160401b9091046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561131757600080fd5b505afa15801561132b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061134f9190614ce2565b600481111561136e57634e487b7160e01b600052602160045260246000fd5b141561143657610163546000828152610166602052604090819020549051632e31150760e11b81526004810191909152600080516020615b668339815191529189918991600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b1580156113e457600080fd5b505afa1580156113f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061141c9190614ce2565b8760405161142d9493929190615939565b60405180910390a15b505b505050505050565b60009081526097602052604090206001015490565b600261012d5414156114795760405162461bcd60e51b8152600401610c7990615889565b600261012d55600080516020615b468339815191526114988133610bb6565b6040516372aee27360e11b815285906001600160a01b0382169063e55dc4e6906114ca9088908890889060040161555d565b600060405180830381600087803b1580156114e457600080fd5b505af11580156114f8573d6000803e3d6000fd5b5050604080516001600160a01b038a8116825289811660208301528816818301526060810187905290517f7d3706b5a5b55581dd829778c6dc22a79c5e0909849ef3174c169b718978d8aa9350908190036080019150a15050600161012d5550505050565b60ff808a16600090815261016a60205260409020548a9116156115925760405162461bcd60e51b8152600401610c79906157fa565b600261012d5414156115b65760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff16156115df5760405162461bcd60e51b8152600401610c799061579c565b6101615460ff161561161b57336000908152610167602052604090205460ff1661161b5760405162461bcd60e51b8152600401610c79906157c6565b600089815261016560205260409020546001600160a01b0316806116515760405162461bcd60e51b8152600401610c7990615718565b600034116116b25760405162461bcd60e51b815260206004820152602860248201527f6465706f7369744554483a204e6f206e617469766520617373657473207472616044820152671b9cd9995c9c995960c21b6064820152608401610c79565b6000816001600160a01b031663e0af36166040518163ffffffff1660e01b815260040160206040518083038186803b1580156116ed57600080fd5b505afa158015611701573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117259190614944565b9050806001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561176257600080fd5b505af1158015611776573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038516935063a9059cbb92506117a9915033903490600401615581565b602060405180830381600087803b1580156117c357600080fd5b505af11580156117d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117fb9190614c18565b61180457600080fd5b6118158c8c8c8c8c8c8c8c8c61398f565b5050600161012d5550505050505050505050565b600261012d54141561184d5760405162461bcd60e51b8152600401610c7990615889565b600261012d5561185c82611440565b6118668133610bb6565b6118708383613b45565b600080516020615b86833981519152831480156119115750610163546040516370a0823160e01b8152600160401b9091046001600160a01b0316906370a08231906118bf908590600401615549565b60206040518083038186803b1580156118d757600080fd5b505afa1580156118eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061190f9190614d6d565b155b156119cc57610163546040516335313c2160e11b8152600160401b9091046001600160a01b031690636a6278429061194d908590600401615549565b600060405180830381600087803b15801561196757600080fd5b505af115801561197b573d6000803e3d6000fd5b5050505061016254600161198f91906159e9565b610162556040517f03580ee9f53a62b7cb409a2cb56f9be87747dd15017afc5cef6eef321e4fb2c5906119c3908490615549565b60405180910390a15b5050600161012d5550565b6001600160a01b0381163314611a475760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610c79565b611a518282613b67565b5050565b306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161415611a9e5760405162461bcd60e51b8152600401610c7990615680565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611ad0613bce565b6001600160a01b031614611af65760405162461bcd60e51b8152600401610c79906156cc565b611aff81613bfc565b60408051600080825260208201909252611b1b91839190613c08565b50565b600261012d541415611b425760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff1615611b6b5760405162461bcd60e51b8152600401610c799061579c565b600082905060008390506000816001600160a01b031663e0af36166040518163ffffffff1660e01b815260040160206040518083038186803b158015611bb057600080fd5b505afa158015611bc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611be89190614944565b604051631a7f5a4160e31b81529091506001600160a01b0384169063d3fad20890611c1b9033908590899060040161555d565b600060405180830381600087803b158015611c3557600080fd5b505af1158015611c49573d6000803e3d6000fd5b50505050336001600160a01b03167f379bc14156b62673a2efd113a5b989c8240c2018bf1fa01ee2d3d5915f769d4b8583604051611c889291906155be565b60405180910390a25050600161012d55505050565b600080848484604051602001611cb5939291906154e0565b60408051808303601f1901815282825280516020918201206000818152610166909252919020546101635463030b0f8d60e01b845291935091600160401b9091046001600160a01b03169063030b0f8d90611d1690849033906004016155be565b60206040518083038186803b158015611d2e57600080fd5b505afa158015611d42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d669190614c18565b925050505b9392505050565b600080516020615ba6833981519152611d8b8133610bb6565b60335460ff16611dad5760405162461bcd60e51b8152600401610c7990615652565b611b1b613d48565b60ff808a16600090815261016a60205260409020548a911615611dea5760405162461bcd60e51b8152600401610c79906157fa565b600261012d541415611e0e5760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff1615611e375760405162461bcd60e51b8152600401610c799061579c565b6101615460ff1615611e7357336000908152610167602052604090205460ff16611e735760405162461bcd60e51b8152600401610c79906157c6565b611e848a8a8a8a8a8a8a8a8a61398f565b5050600161012d555050505050505050565b306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161415611edf5760405162461bcd60e51b8152600401610c7990615680565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611f11613bce565b6001600160a01b031614611f375760405162461bcd60e51b8152600401610c79906156cc565b611f4082613bfc565b611a5182826001613c08565b6000611f588133610bb6565b610161805460ff19168315159081179091556040519081527f78e648f9aa0bf2a4400dc354b571bbbf0d423305d9b78e94a9014ab03ff8bb7b906020015b60405180910390a15050565b60335460ff1615611fc55760405162461bcd60e51b8152600401610c799061579c565b6040516330414fc560e11b815283906001600160a01b038216906360829f8a90611ff79033908790879060040161555d565b600060405180830381600087803b15801561201157600080fd5b505af1158015612025573d6000803e3d6000fd5b50505050336001600160a01b03167f379bc14156b62673a2efd113a5b989c8240c2018bf1fa01ee2d3d5915f769d4b83856040516120649291906155be565b60405180910390a250505050565b600080516020615b2683398151915261208b8133610bb6565b5060009081526101656020908152604080832080546001600160a01b039095166001600160a01b03199095168517905592825261016b905220805460ff19166001179055565b60006120dd8133610bb6565b60405163e0169b1360e01b81526001600160a01b038481166004830152838116602483015285919082169063e0169b13906044015b600060405180830381600087803b15801561212c57600080fd5b505af1158015612140573d6000803e3d6000fd5b505050505050505050565b60006121578133610bb6565b6000826001600160401b0316116121a85760405162461bcd60e51b815260206004820152601560248201527406e6f6e636520636865636b706f696e7420213d203605c1b6044820152606401610c79565b5060ff91909116600090815261016d60205260409020805467ffffffffffffffff19166001600160401b03909216919091179055565b60ff808316600090815261016a60205260408120549091849116156122155760405162461bcd60e51b8152600401610c79906157fa565b60335460ff16156122385760405162461bcd60e51b8152600401610c799061579c565b600083815261016560209081526040808320546001600160a01b0316835261016990915290205460ff1615156001148061229d5750600083815261016560209081526040808320546001600160a01b0316835261016b90915290205460ff1615156001145b6123085760405162461bcd60e51b815260206004820152603660248201527f4272696467653a20436f6e7472616374206e6569746865722073657175656e6360448201527532b9103737b91033b2b732b934b1903430b7323632b960511b6064820152608401610c79565b600083815261016560205260409020546001600160a01b0316331461238b5760405162461bcd60e51b815260206004820152603360248201527f4272696467653a205265736f7572636520494420646f6573206e6f74206d617460448201527231b4103bb4ba34103a3432903430b7323632b960691b6064820152608401610c79565b60ff8416600090815261016460205260408120805482906123b4906001600160401b0316615a8b565b91906101000a8154816001600160401b0302191690836001600160401b0316021790559050806001600160401b0316848660ff167fc9745c10b9322d1d4b7bf22f00dc660872b611832eedcfffdbcdc09ebafcb313600060405161241a91815260200190565b60405180910390a4949350505050565b600261012d54141561244e5760405162461bcd60e51b8152600401610c7990615889565b600261012d55600080516020615b4683398151915261246d8133610bb6565b604051636ce5768960e11b815285906001600160a01b0382169063d9caed12906114ca9088908890889060040161555d565b60006124ab8133610bb6565b60335460ff16156124ce5760405162461bcd60e51b8152600401610c799061579c565b6000858584866040516020016124e79493929190615512565b60408051808303601f19018152828252805160209182012061016354600082815261016690935292822054632e31150760e11b85526004850152935091600160401b9091046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561255757600080fd5b505afa15801561256b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061258f9190614ce2565b905060048160048111156125b357634e487b7160e01b600052602160045260246000fd5b146125fd5760405162461bcd60e51b815260206004820152601a602482015279141c9bdc1bdcd85b081b5d5cdd0818994818d85b98d95b1b195960321b6044820152606401610c79565b50600090815261016660205260408120555050505050565b60006126218133610bb6565b6101608290556040518281527fa2b67627a88e010182419ae858fcf3ca4374ad08cbbd6fe10bebcf8b26d3b5fe90602001611f96565b600080516020615ba68339815191526126708133610bb6565b60335460ff16156126935760405162461bcd60e51b8152600401610c799061579c565b611b1b613dae565b60006126a78133610bb6565b604051631764b06b60e21b81526001600160a01b0384811660048301528315156024830152859190821690635d92c1ac90604401612112565b60006126ec8133610bb6565b6101615460ff1661270f5760405162461bcd60e51b8152600401610c799061574d565b6001600160a01b0382166000908152610167602052604090819020805460ff19169055517f441e43beaf2db8af6e1f9f7a6b9f0dcc36fcf83a2904264c9ab624068242efff90611f96908490615549565b600061276c8133610bb6565b60405163e7c308fd60e01b815283906001600160a01b0382169063e7c308fd9061279a908690600401615549565b600060405180830381600087803b1580156127b457600080fd5b505af11580156127c8573d6000803e3d6000fd5b5050505050505050565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600261012d5414156128215760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff161561284a5760405162461bcd60e51b8152600401610c799061579c565b600081905060008290506000816001600160a01b031663e0af36166040518163ffffffff1660e01b815260040160206040518083038186803b15801561288f57600080fd5b505afa1580156128a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c79190614944565b905034806129235760405162461bcd60e51b815260206004820152602360248201527f7374616b654554483a20696e73756666696369656e74206574682070726f766960448201526219195960ea1b6064820152608401610c79565b816001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b15801561295e57600080fd5b505af1158015612972573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038616935063a9059cbb92506129a5915088908590600401615581565b602060405180830381600087803b1580156129bf57600080fd5b505af11580156129d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129f79190614c18565b612a0057600080fd5b60405163f4e480e160e01b81526001600160a01b0385169063f4e480e190612a309033908690869060040161555d565b600060405180830381600087803b158015612a4a57600080fd5b505af1158015612a5e573d6000803e3d6000fd5b50505050336001600160a01b03167fcc2e01638b08266366840f4a2ac8755c01e6932f730d5b707835cf4e23a152458284604051611c889291906155be565b6000612aa98133610bb6565b610163805467ffffffffffffffff19166001600160401b038481169190911791829055604051911681527f99c317e8206747b01304c113e5c93aee8a0d136eca391733b384fc0f878f6e0690602001611f96565b600080516020615b86833981519152612b168133610bb6565b60335460ff1615612b395760405162461bcd60e51b8152600401610c799061579c565b60ff808a16600090815261016c602090815260408083206001600160401b038d16845290915290205416158015612b8e575060ff8916600090815261016d60205260409020546001600160401b03808a169116105b612bc85760405162461bcd60e51b815260206004820152600b60248201526a6e6f6e636520697373756560a81b6044820152606401610c79565b600085815261016560209081526040808320549051612bf7926001600160a01b03909216918b918b910161542d565b60405160208183030381529060405280519060200120905060008a8a8389604051602001612c289493929190615512565b60408051601f19818403018152918152815160209283012060008a81526101658452828120546001600160a01b0316815261016990935291205490915060ff1615612d135760008781526101656020526040908190205490516330faa25960e01b81526001600160a01b039091169081906330faa25990612caf908d908d90600401615610565b600060405180830381600087803b158015612cc957600080fd5b505af1158015612cdd573d6000803e3d6000fd5b50505050600080516020615b668339815191528c8c600386604051612d059493929190615939565b60405180910390a150612f6e565b600087815261016560209081526040808320546001600160a01b0316835261016b90915290205460ff1615612e0d5760008781526101656020526040908190205490516330faa25960e01b81526001600160a01b039091169081906330faa25990612d84908d908d90600401615610565b602060405180830381600087803b158015612d9e57600080fd5b505af1158015612db2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dd69190614c18565b507f515e6a8cc9a22ef1fc441f36516f147da819924307b2404120e78a4d605985288c8c600386604051612d059493929190615939565b600080612e1a8b8b613e06565b61024081018790526102608101899052610280810188905260ff8e166040808301919091526001600160401b038e1660208084019190915260008c8152610165909152819020549051635f624fbd60e01b81529192506001600160a01b0316908190635f624fbd90612e929085908e906004016158c0565b6040805180830381600087803b158015612eab57600080fd5b505af1158015612ebf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ee39190614bcf565b836060018181525081945050508c6001600160401b03168e60ff167ff3eebc917bbcdbb3122520c3cdb2a3e3955672aeb3612717f0c7b2872ed296e78585606001516003604051612f369392919061559a565b60405180910390a3600080516020615b668339815191528e8e600388604051612f629493929190615939565b60405180910390a15050505b6101635460008281526101666020526040808220549051632e31150760e11b815260048101919091529091600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b158015612fcb57600080fd5b505afa158015612fdf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130039190614ce2565b9050600281600481111561302757634e487b7160e01b600052602160045260246000fd5b146130745760405162461bcd60e51b815260206004820181905260248201527f50726f706f73616c206d757374206861766520506173736564207374617475736044820152606401610c79565b610163546000838152610166602052604090819020549051630d61b51960e01b81526004810191909152600160401b9091046001600160a01b031690630d61b51990602401602060405180830381600087803b1580156130d357600080fd5b505af11580156130e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061310b9190614c18565b50505060ff909916600090815261016c602090815260408083206001600160401b03909b16835299905297909720805460ff191660011790555050505050505050565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091526000858584866040516020016131999493929190615512565b60408051808303601f19018152828252805160209182012061016354600082815261016690935292909120546307336bcb60e21b845260048401529250600160401b90046001600160a01b031690631ccdaf2c9060240160c06040518083038186803b15801561320857600080fd5b505afa15801561321c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132409190614cfc565b9150505b949350505050565b60335460ff161561326f5760405162461bcd60e51b8152600401610c799061579c565b60405163bf6eac2f60e01b815283906001600160a01b0382169063bf6eac2f906132a19033908790879060040161555d565b600060405180830381600087803b1580156132bb57600080fd5b505af11580156132cf573d6000803e3d6000fd5b50505050336001600160a01b03167fcc2e01638b08266366840f4a2ac8755c01e6932f730d5b707835cf4e23a1524583856040516120649291906155be565b600061331a8133610bb6565b60ff8316600081815261016a6020908152604091829020805460ff191686151590811790915591519182527f8b367b8e5c490bcc4378a8f54d118e435bc9b33d1022a2efdeffc598739a05c8910160405180910390a2505050565b60008084848460405160200161338d939291906154e0565b60408051808303601f19018152919052805160209091012095945050505050565b600080516020615b268339815191526133c78133610bb6565b600083815261016560205260409081902080546001600160a01b0319166001600160a01b0387169081179091559051635c7d1b9b60e11b815285919063b8fa37369061211290879087906004016155be565b600261012d54141561343d5760405162461bcd60e51b8152600401610c7990615889565b600261012d5561344c82611440565b6134568133610bb6565b613460838361409e565b600080516020615b868339815191528314801561350a5750610163546040516370a0823160e01b8152600160401b9091046001600160a01b0316906370a08231906134af908590600401615549565b60206040518083038186803b1580156134c757600080fd5b505afa1580156134db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134ff9190614d6d565b670de0b6b3a7640000145b156119cc576101635460405163226bf2d160e21b8152600160401b9091046001600160a01b0316906389afcb4490613546908590600401615549565b600060405180830381600087803b15801561356057600080fd5b505af1158015613574573d6000803e3d6000fd5b505050506001610162546135889190615a20565b610162556040517f10e1f7ce9fd7d1b90a66d13a2ab3cb8dd7f29f3f8d520b143b063ccfbab6906b906119c3908490615549565b60006135c88133610bb6565b6101615460ff166135eb5760405162461bcd60e51b8152600401610c799061574d565b6001600160a01b0382166000908152610167602052604090819020805460ff19166001179055517f2373c347d35d91064d64b63157cb8aee2bd652a41983ca2e8a3e7348bfeff92f90611f96908490615549565b600061364b8133610bb6565b60405163e4cd10db60e01b81526001600160a01b03868116600483015285811660248301528481166044830152838116606483015287919082169063e4cd10db90608401600060405180830381600087803b1580156136a957600080fd5b505af11580156136bd573d6000803e3d6000fd5b5050505050505050505050565b60ff808316600090815261016a602052604081205490918291859116156137035760405162461bcd60e51b8152600401610c79906157fa565b6000868152610165602052604090819020549051639e601b3160e01b815260ff871660048201526001600160a01b0386811660248301529091169081908190639e601b3190604401604080518083038186803b15801561376257600080fd5b505afa158015613776573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379a9190614d85565b94509450505050935093915050565b60006137b58133610bb6565b6000838152610165602052604090819020549051636be1dc2b60e01b815283151560048201526001600160a01b039091169081908190636be1dc2b90602401612112565b600054610100900460ff166138145760005460ff1615613818565b303b155b61387b5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c79565b600054610100900460ff161580156138a6576000805460ff1961ff0019909116610100171660011790555b6138ae6140bb565b6138b66140fc565b6138c1600033614133565b610163805461015f805460ff191660ff8916179055600160401b600160e01b031916600160401b6001600160a01b038516021767ffffffffffffffff19166001600160401b0386161790556101608390558015613924576000805461ff00191690555b5050505050565b61393582826127d2565b611a515761394d816001600160a01b0316601461413d565b61395883602061413d565b604051602001613969929190615471565b60408051601f198184030181529082905262461bcd60e51b8252610c799160040161563f565b600061399b8888613e06565b336102a0820152610260810187905261028081018690526001600160a01b038316815290506139ca8385615a37565b610240820152600089815261016560205260409020546001600160a01b031660c08201819052613a0c5760405162461bcd60e51b8152600401610c7990615718565b60ff8a166000908152610164602052604081208054909190613a36906001600160401b0316615a8b565b91906101000a8154816001600160401b0302191690836001600160401b03160217905581602001906001600160401b031690816001600160401b03168152505060008160c001519050806001600160a01b0316634a2661608b8d8560200151866040518563ffffffff1660e01b8152600401613ab594939291906155d5565b600060405180830381600087803b158015613acf57600080fd5b505af1158015613ae3573d6000803e3d6000fd5b5050505081602001516001600160401b03168a8c60ff167fc9745c10b9322d1d4b7bf22f00dc660872b611832eedcfffdbcdc09ebafcb313856102e00151604051613b3091815260200190565b60405180910390a45050505050505050505050565b613b4e82611440565b613b588133610bb6565b613b62838361431e565b505050565b613b7182826127d2565b15611a515760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b6000611a518133610bb6565b6000613c12613bce565b9050613c1d846143a4565b600083511180613c2a5750815b15613c3b57613c398484614449565b505b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143805460ff1661392457805460ff19166001178155604051613cb6908690613c87908590602401615549565b60408051601f198184030181529190526020810180516001600160e01b0316631b2ce7f360e11b179052614449565b50805460ff19168155613cc7613bce565b6001600160a01b0316826001600160a01b031614613d3f5760405162461bcd60e51b815260206004820152602f60248201527f45524331393637557067726164653a207570677261646520627265616b73206660448201526e75727468657220757067726164657360881b6064820152608401610c79565b61392485614534565b60335460ff16613d6a5760405162461bcd60e51b8152600401610c7990615652565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613da49190615549565b60405180910390a1565b60335460ff1615613dd15760405162461bcd60e51b8152600401610c799061579c565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613d973390565b613e0e614607565b613e16614607565b6000613e2484860186614da8565b6101a08a015261018089015261016088015261014087019190915261012086019190915261010085019190915260e08401919091529050613e6784860186614dfc565b6102e08b0152505086159550613e84945050505050576001613e87565b60005b15156102c08301526101206040830181905261016083015160009187918790613eb090836159e9565b92613ebd939291906159c1565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101608401516040850151919250613f08916159e9565b6040840181905261018084015160009188918890613f2690836159e9565b92613f33939291906159c1565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101808501516040860151919250613f7e916159e9565b604085018190526101a085015160009189918990613f9c90836159e9565b92613fa9939291906159c1565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101a08601516040870151919250613ff4916159e9565b604086018190526101a08601516000918a918a9061401290836159e9565b9261401f939291906159c1565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505050602093840151928401519084015194909301516001600160601b03199283166101c0880152606093841c61022088015291909316610200860152901c60808401525090949350505050565b6140a782611440565b6140b18133610bb6565b613b628383613b67565b600054610100900460ff166140e25760405162461bcd60e51b8152600401610c799061583e565b6140ea614574565b6140f2614574565b6140fa614574565b565b600054610100900460ff166141235760405162461bcd60e51b8152600401610c799061583e565b61412b614574565b6140fa61459b565b611a51828261431e565b6060600061414c836002615a01565b6141579060026159e9565b6001600160401b0381111561417c57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156141a6576020820181803683370190505b509050600360fc1b816000815181106141cf57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061420c57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506000614230846002615a01565b61423b9060016159e9565b90505b60018111156142cf576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061427d57634e487b7160e01b600052603260045260246000fd5b1a60f81b8282815181106142a157634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c936142c881615a74565b905061423e565b508315611d6b5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c79565b61432882826127d2565b611a515760008281526097602090815260408083206001600160a01b03851684529091529020805460ff191660011790556143603390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b803b6144085760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610c79565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0392909216919091179055565b6060823b6144a85760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610c79565b600080846001600160a01b0316846040516144c39190615455565b600060405180830381855af49150503d80600081146144fe576040519150601f19603f3d011682016040523d82523d6000602084013e614503565b606091505b509150915061452b8282604051806060016040528060278152602001615bc6602791396145ce565b95945050505050565b61453d816143a4565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b600054610100900460ff166140fa5760405162461bcd60e51b8152600401610c799061583e565b600054610100900460ff166145c25760405162461bcd60e51b8152600401610c799061583e565b6033805460ff19169055565b606083156145dd575081611d6b565b8251156145ed5782518084602001fd5b8160405162461bcd60e51b8152600401610c79919061563f565b604080516103008101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052610100820183905261012082018390526101408201839052610160820183905261018082018390526101a082018390526101c082018390526101e0820183905261020082018390526102208201839052610240820181905261026082018190526102808201526102a081018290526102c081018290526102e081019190915290565b60006146dd6146d88461599e565b61596e565b83815290506020808201908360005b86811015614713576147018883358801614899565b845292820192908201906001016146ec565b505050509392505050565b8035610b9c81615ade565b600082601f830112614739578081fd5b813560206147496146d88361599e565b8281528181019085830183850287018401881015614765578586fd5b855b8581101561478c57813561477a81615ade565b84529284019290840190600101614767565b5090979650505050505050565b60008083601f8401126147aa578182fd5b5081356001600160401b038111156147c0578182fd5b60208301915083602080830285010111156147da57600080fd5b9250929050565b600082601f8301126147f1578081fd5b611d6b838335602085016146ca565b600082601f830112614810578081fd5b813560206148206146d88361599e565b828152818101908583018385028701840188101561483c578586fd5b855b8581101561478c5781358452928401929084019060010161483e565b60008083601f84011261486b578182fd5b5081356001600160401b03811115614881578182fd5b6020830191508360208285010111156147da57600080fd5b600082601f8301126148a9578081fd5b81356001600160401b038111156148c2576148c2615ac8565b6148d5601f8201601f191660200161596e565b8181528460208386010111156148e9578283fd5b816020850160208301379081016020019190915292915050565b805160058110610b9c57600080fd5b8035610b9c81615b01565b8035610b9c81615b16565b600060208284031215614939578081fd5b8135611d6b81615ade565b600060208284031215614955578081fd5b8151611d6b81615ade565b60008060408385031215614972578081fd5b823561497d81615ade565b9150602083013561498d81615ade565b809150509250929050565b6000806000606084860312156149ac578081fd5b83356149b781615ade565b925060208401356149c781615ade565b915060408401356149d781615ade565b809150509250925092565b600080600080600060a086880312156149f9578283fd5b8535614a0481615ade565b94506020860135614a1481615ade565b93506040860135614a2481615ade565b92506060860135614a3481615ade565b91506080860135614a4481615ade565b809150509295509295909350565b60008060008060808587031215614a67578182fd5b8435614a7281615ade565b93506020850135614a8281615ade565b92506040850135614a9281615ade565b9396929550929360600135925050565b600080600060608486031215614ab6578081fd5b8335614ac181615ade565b92506020840135614ad181615ade565b915060408401356149d781615af3565b600080600060608486031215614af5578081fd5b8335614b0081615ade565b92506020840135614b1081615ade565b929592945050506040919091013590565b60008060408385031215614b33578182fd5b8235614b3e81615ade565b946020939093013593505050565b600080600060608486031215614b60578081fd5b8335614b6b81615ade565b92506020840135915060408401356149d781615ade565b60008060408385031215614b94578182fd5b8235614b9f81615ade565b915060208301356001600160401b03811115614bb9578182fd5b614bc585828601614899565b9150509250929050565b60008060408385031215614be1578182fd5b8251614bec81615ade565b6020939093015192949293505050565b600060208284031215614c0d578081fd5b8135611d6b81615af3565b600060208284031215614c29578081fd5b8151611d6b81615af3565b600060208284031215614c45578081fd5b5035919050565b60008060408385031215614c5e578182fd5b82359150602083013561498d81615ade565b60008060408385031215614c82578182fd5b82359150602083013561498d81615af3565b600080600060608486031215614ca8578081fd5b8335925060208401356149c781615b16565b600060208284031215614ccb578081fd5b81356001600160e01b031981168114611d6b578182fd5b600060208284031215614cf3578081fd5b611d6b82614903565b600060c08284031215614d0d578081fd5b614d1760c061596e565b614d2083614903565b815260208301516020820152604083015160408201526060830151614d4481615b01565b60608201526080838101519082015260a0830151614d6181615b16565b60a08201529392505050565b600060208284031215614d7e578081fd5b5051919050565b60008060408385031215614d97578182fd5b505080516020909101519092909150565b600080600080600080600080610100898b031215614dc4578586fd5b505086359860208801359850604088013597606081013597506080810135965060a0810135955060c0810135945060e0013592509050565b60008060008060008060008060006101208a8c031215614e1a578283fd5b505087359960208901359950604089013598606081013598506080810135975060a0810135965060c0810135955060e08101359450610100013592509050565b600060208284031215614e6b578081fd5b8135611d6b81615b16565b60008060408385031215614e88578182fd5b8235614e9381615b16565b9150602083013561498d81615af3565b60008060408385031215614eb5578182fd5b8235614b3e81615b16565b600080600080600080600080600060e08a8c031215614edd578283fd5b614ee68a61491d565b985060208a0135975060408a01356001600160401b0380821115614f08578485fd5b614f148d838e0161485a565b909950975060608c0135915080821115614f2c578485fd5b614f388d838e01614800565b965060808c0135915080821115614f4d578485fd5b614f598d838e01614729565b955060a08c0135915080821115614f6e578485fd5b50614f7b8c828d01614799565b9094509250614f8e905060c08b0161471e565b90509295985092959850929598565b60008060008060808587031215614fb2578182fd5b8435614fbd81615b16565b935060208501359250604085013591506060850135614fdb81615ade565b939692955090935050565b60008060408385031215614ff8578182fd5b823561500381615b16565b9150602083013561498d81615b01565b600080600060608486031215615027578081fd5b833561503281615b16565b92506020840135614b1081615b01565b60008060008060808587031215615057578182fd5b843561506281615b16565b9350602085013561507281615b01565b93969395505050506040820135916060013590565b60008060008060008060008060e0898b0312156150a2578182fd5b6150ab8961491d565b97506150b960208a01614912565b965060408901356001600160401b03808211156150d4578384fd5b6150e08c838d0161485a565b909850965060608b0135955060808b01359150808211156150ff578384fd5b61510b8c838d01614800565b945060a08b0135915080821115615120578384fd5b61512c8c838d01614729565b935060c08b0135915080821115615141578283fd5b5061514e8b828c016147e1565b9150509295985092959890939650565b6001600160a01b03169052565b6000815180845260208085019450808401835b838110156151a35781516001600160a01b03168752958201959082019060010161517e565b509495945050505050565b6000815180845260208085018081965082840281019150828601855b858110156151f45782840389526151e284835161523e565b988501989350908401906001016151ca565b5091979650505050505050565b6000815180845260208085019450808401835b838110156151a357815187529582019590820190600101615214565b6001600160601b0319169052565b60008151808452615256816020860160208601615a44565b601f01601f19169290920160200192915050565b6005811061528857634e487b7160e01b600052602160045260246000fd5b9052565b600061030061529c84845161515e565b60208301516152b660208601826001600160401b03169052565b50604083015160408501526060830151606085015260808301516152dd608086018261515e565b5060a08301516152f060a086018261515e565b5060c083015161530360c086018261515e565b5060e08381015190850152610100808401519085015261012080840151908501526101408084015190850152610160808401519085015261018080840151908501526101a080840151908501526101c08084015161536382870182615230565b50506101e0808401516153788287018261515e565b50506102008084015161538d82870182615230565b5050610220808401516153a28287018261515e565b50506102408084015182828701526153bc838701826151ae565b9250505061026080840151858303828701526153d88382615201565b9250505061028080840151858303828701526153f4838261516b565b925050506102a08084015161540b8287018261515e565b50506102c0838101511515908501526102e09283015192909301919091525090565b606084901b6001600160601b0319168152600082846014840137910160140190815292915050565b60008251615467818460208701615a44565b9190910192915050565b600076020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b825283516154a3816017850160208801615a44565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516154d4816028840160208801615a44565b01602801949350505050565b60f89390931b6001600160f81b031916835260c09190911b6001600160c01b0319166001830152600982015260290190565b60f89490941b6001600160f81b031916845260c09290921b6001600160c01b03191660018401526009830152602982015260490190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03841681526020810183905260608101613244604083018461526a565b9182526001600160a01b0316602082015260400190565b600085825260ff851660208301526001600160401b038416604083015260806060830152615606608083018461528c565b9695505050505050565b60006020825282602083015282846040840137818301604090810191909152601f909201601f19160101919050565b600060208252611d6b602083018461523e565b60208082526014908201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604082015260600190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b6020808252818101527f7265736f757263654944206e6f74206d617070656420746f2068616e646c6572604082015260600190565b6020808252602f908201527f4272696467655570677261646561626c653a205768697465206c697374696e6760408201526e081a5cc81b9bdd08195b98589b1959608a1b606082015260800190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252601a90820152791859191c995cdcc81a5cc81b9bdd081dda1a5d195b1a5cdd195960321b604082015260600190565b60208082526024908201527f4272696467655570677261646561626c653a20556e737570706f7274656420636040820152633430b4b760e11b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6000604082526158d3604083018561528c565b90508260208301529392505050565b600060c0820190506158f582845161526a565b60208301516020830152604083015160408301526001600160401b0360608401511660608301526080830151608083015260ff60a08401511660a083015292915050565b60ff851681526001600160401b03841660208201526080810161595f604083018561526a565b82606083015295945050505050565b604051601f8201601f191681016001600160401b038111828210171561599657615996615ac8565b604052919050565b60006001600160401b038211156159b7576159b7615ac8565b5060209081020190565b600080858511156159d0578182fd5b838611156159dc578182fd5b5050820193919092039150565b600082198211156159fc576159fc615ab2565b500190565b6000816000190483118215151615615a1b57615a1b615ab2565b500290565b600082821015615a3257615a32615ab2565b500390565b6000611d6b3684846146ca565b60005b83811015615a5f578181015183820152602001615a47565b83811115615a6e576000848401525b50505050565b600081615a8357615a83615ab2565b506000190190565b60006001600160401b0380831681811415615aa857615aa8615ab2565b6001019392505050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114611b1b57600080fd5b8015158114611b1b57600080fd5b6001600160401b0381168114611b1b57600080fd5b60ff81168114611b1b57600080fdfe8b9e7a9f25b0aca3f51c01b8fee30790fb16f4d4deded8385ae6643d054bb078bf233dd2aafeb4d50879c4aa5c81e96d92f6e6945c906a58f9f2d1c1631b4b26968626a768e76ba1363efe44e322a6c4900c5f084e0b45f35e294dfddaa9e0d5e2b7fb3b832174769106daebcfd6d1970523240dda11281102db9363b83b0dc465d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a164736f6c6343000802000a
Deployed ByteCode
0x6080604052600436106102f65760003560e01c80637bd3af5011610197578063b2c0f640116100ed578063dfff261b11610090578063dfff261b14610a23578063e43252d714610a5d578063e63ab1e914610a7d578063e7ad01f914610a9f578063e934768314610abf578063ebc2693914610af3578063f19ba3f814610b28578063fe79b9a914610b48576102fd565b8063b2c0f64014610925578063bb5ba77e14610948578063bf6eac2f14610961578063c3cf4c8014610981578063c794c698146109a1578063cb10f215146109c1578063d547741f146109e1578063db618e2a14610a01576102fd565b80637bd3af50146107545780637d026d96146107745780638456cb591461079457806385802129146107a9578063862159ab146107c95780638ab1d681146107e05780638ac4c1841461080057806391d1485414610820578063926d7d7f14610840578063946fe3e8146108625780639be8eb5314610875578063a07e338d14610895578063a217fddf146108c3578063a42570df146108d8578063a5285090146108f8576102fd565b80633f4ba83a1161024c5780633f4ba83a1461055457806343cee7191461056957806349b9ac5e146105895780634d98a61b146105c25780634f1ef286146105d857806350d1882e146105eb5780635af5f7ba146106225780635bc51147146106425780635c975abb1461067c57806360829f8a14610694578063611336d6146106b45780636369f9e9146106d45780636495c503146106f4578063700803b514610714578063780cf00414610734576102fd565b806301ffc9a7146103025780630e5f06e5146103375780631dd7e81f146103715780631ff013f114610393578063200a99f5146103b357806320df4359146103fc578063248a9ca31461042c5780632becbe311461044c5780632e09305c1461046c5780632f2ff15d1461047f57806336568abe1461049f5780633659cfe6146104bf5780633c047803146104df5780633db9b42a146104ff5780633dd301d914610534576102fd565b366102fd57005b600080fd5b34801561030e57600080fd5b5061032261031d366004614cba565b610b68565b60405190151581526020015b60405180910390f35b34801561034357600080fd5b50610322610352366004614928565b6001600160a01b03166000908152610167602052604090205460ff1690565b34801561037d57600080fd5b5061039161038c366004614b21565b610ba1565b005b34801561039f57600080fd5b506103916103ae366004615042565b610c01565b3480156103bf57600080fd5b506103226103ce366004614fe6565b60ff918216600090815261016c602090815260408083206001600160401b0394909416835292905220541690565b34801561040857600080fd5b5061041e600080516020615b4683398151915281565b60405190815260200161032e565b34801561043857600080fd5b5061041e610447366004614c34565b611440565b34801561045857600080fd5b50610391610467366004614a52565b611455565b61039161047a366004614ec0565b61155d565b34801561048b57600080fd5b5061039161049a366004614c4c565b611829565b3480156104ab57600080fd5b506103916104ba366004614c4c565b6119d7565b3480156104cb57600080fd5b506103916104da366004614928565b611a55565b3480156104eb57600080fd5b506103916104fa366004614b21565b611b1e565b34801561050b57600080fd5b506101635461052790600160401b90046001600160a01b031681565b60405161032e9190615549565b34801561054057600080fd5b5061032261054f366004615013565b611c9d565b34801561056057600080fd5b50610391611d72565b34801561057557600080fd5b50610391610584366004614ec0565b611db5565b34801561059557600080fd5b50610163546105aa906001600160401b031681565b6040516001600160401b03909116815260200161032e565b3480156105ce57600080fd5b506101605461041e565b6103916105e6366004614b82565b611e96565b3480156105f757600080fd5b50610527610606366004614c34565b600090815261016560205260409020546001600160a01b031690565b34801561062e57600080fd5b5061039161063d366004614bfc565b611f4c565b34801561064e57600080fd5b506105aa61065d366004614e5a565b60ff16600090815261016460205260409020546001600160401b031690565b34801561068857600080fd5b5060335460ff16610322565b3480156106a057600080fd5b506103916106af366004614ae1565b611fa2565b3480156106c057600080fd5b506103916106cf366004614b21565b612072565b3480156106e057600080fd5b506103916106ef366004614998565b6120d1565b34801561070057600080fd5b5061039161070f366004614fe6565b61214b565b34801561072057600080fd5b506105aa61072f366004614ea3565b6121de565b34801561074057600080fd5b5061039161074f366004614a52565b61242a565b34801561076057600080fd5b5061039161076f366004615042565b61249f565b34801561078057600080fd5b5061039161078f366004614c34565b612615565b3480156107a057600080fd5b50610391612657565b3480156107b557600080fd5b506103916107c4366004614aa2565b61269b565b3480156107d557600080fd5b5061041e6101625481565b3480156107ec57600080fd5b506103916107fb366004614928565b6126e0565b34801561080c57600080fd5b5061039161081b366004614960565b612760565b34801561082c57600080fd5b5061032261083b366004614c4c565b6127d2565b34801561084c57600080fd5b5061041e600080516020615b8683398151915281565b610391610870366004614928565b6127fd565b34801561088157600080fd5b50610391610890366004614c34565b612a9d565b3480156108a157600080fd5b5061041e6108b0366004614c34565b6000908152610166602052604090205490565b3480156108cf57600080fd5b5061041e600081565b3480156108e457600080fd5b506103916108f3366004615087565b612afd565b34801561090457600080fd5b50610918610913366004615042565b61314e565b60405161032e91906158e2565b34801561093157600080fd5b5061015f5460405160ff909116815260200161032e565b34801561095457600080fd5b506101615460ff16610322565b34801561096d57600080fd5b5061039161097c366004614ae1565b61324c565b34801561098d57600080fd5b5061039161099c366004614e76565b61330e565b3480156109ad57600080fd5b5061041e6109bc366004615013565b613375565b3480156109cd57600080fd5b506103916109dc366004614b4c565b6133ae565b3480156109ed57600080fd5b506103916109fc366004614c4c565b613419565b348015610a0d57600080fd5b5061041e600080516020615b2683398151915281565b348015610a2f57600080fd5b506105aa610a3e366004614e5a565b60ff16600090815261016d60205260409020546001600160401b031690565b348015610a6957600080fd5b50610391610a78366004614928565b6135bc565b348015610a8957600080fd5b5061041e600080516020615ba683398151915281565b348015610aab57600080fd5b50610391610aba3660046149e2565b61363f565b348015610acb57600080fd5b5061041e7fe6ad9a47fbda1dc18de1eb5eeb7d935e5e81b4748f3cfc61e233e64f8818206081565b348015610aff57600080fd5b50610b13610b0e366004614c94565b6136ca565b6040805192835260208301919091520161032e565b348015610b3457600080fd5b50610391610b43366004614c70565b6137a9565b348015610b5457600080fd5b50610391610b63366004614f9d565b6137f9565b60006001600160e01b03198216637965db0b60e01b1480610b9957506301ffc9a760e01b6001600160e01b03198316145b90505b919050565b600080516020615b26833981519152610bbb81335b61392b565b5060009081526101656020908152604080832080546001600160a01b039095166001600160a01b031990951685179055928252610169905220805460ff19166001179055565b6000828152610165602052604090205482906001600160a01b0316610c825760405162461bcd60e51b815260206004820152602c60248201527f4272696467655570677261646561626c653a204e6f2068616e646c657220666f60448201526b1c881c995cdbdd5c98d9525160a21b60648201526084015b60405180910390fd5b600080516020615b86833981519152610c9b8133610bb6565b60335460ff1615610cbe5760405162461bcd60e51b8152600401610c799061579c565b60ff808716600090815261016c602090815260408083206001600160401b038a16845290915290205416158015610d13575060ff8616600090815261016d60205260409020546001600160401b038087169116105b610d4f5760405162461bcd60e51b815260206004820152600d60248201526c1b9bdb98d948195e1c1a5c9959609a1b6044820152606401610c79565b600086868587604051602001610d689493929190615512565b60408051601f1981840301815291815281516020928301206000818152610166909352912054909150610e8c576101635461016054600091600160401b90046001600160a01b03169063ba831b9c90610dc190436159e9565b6101635460405160e084901b6001600160e01b031916815260048101929092526001600160401b03166024820152604401602060405180830381600087803b158015610e0c57600080fd5b505af1158015610e20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e449190614d6d565b600083815261016660205260409081902082905551909150600080516020615b6683398151915290610e7e908a908a906001908a90615939565b60405180910390a150611085565b6101635460008281526101666020526040908190205490516345737d1d60e11b81526004810191909152600160401b9091046001600160a01b031690638ae6fa3a9060240160206040518083038186803b158015610ee957600080fd5b505afa158015610efd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f219190614c18565b15611085576101635460008281526101666020526040908190205490516369ba1a7560e01b81526004810191909152600160401b9091046001600160a01b0316906369ba1a7590602401602060405180830381600087803b158015610f8557600080fd5b505af1158015610f99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fbd9190614c18565b50610163546000828152610166602052604090819020549051632e31150760e11b81526004810191909152600080516020615b668339815191529189918991600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561102e57600080fd5b505afa158015611042573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110669190614ce2565b876040516110779493929190615939565b60405180910390a150611438565b6004610163546000838152610166602052604090819020549051632e31150760e11b81526004810191909152600160401b9091046001600160a01b031690635c622a0e9060240160206040518083038186803b1580156110e457600080fd5b505afa1580156110f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111c9190614ce2565b600481111561113b57634e487b7160e01b600052602160045260246000fd5b1461143657610163546000828152610166602052604090819020549051630ce7fb8360e11b8152600481019190915260016024820152336044820152600160401b9091046001600160a01b0316906319cff70690606401602060405180830381600087803b1580156111ac57600080fd5b505af11580156111c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e49190614c18565b50610163546000828152610166602052604090819020549051632e31150760e11b815260048101919091527f25f8daaa4635a7729927ba3f5b3d59cc3320aca7c32c9db4e7ca7b95743436409189918991600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561126757600080fd5b505afa15801561127b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129f9190614ce2565b876040516112b09493929190615939565b60405180910390a16002610163546000838152610166602052604090819020549051632e31150760e11b81526004810191909152600160401b9091046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561131757600080fd5b505afa15801561132b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061134f9190614ce2565b600481111561136e57634e487b7160e01b600052602160045260246000fd5b141561143657610163546000828152610166602052604090819020549051632e31150760e11b81526004810191909152600080516020615b668339815191529189918991600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b1580156113e457600080fd5b505afa1580156113f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061141c9190614ce2565b8760405161142d9493929190615939565b60405180910390a15b505b505050505050565b60009081526097602052604090206001015490565b600261012d5414156114795760405162461bcd60e51b8152600401610c7990615889565b600261012d55600080516020615b468339815191526114988133610bb6565b6040516372aee27360e11b815285906001600160a01b0382169063e55dc4e6906114ca9088908890889060040161555d565b600060405180830381600087803b1580156114e457600080fd5b505af11580156114f8573d6000803e3d6000fd5b5050604080516001600160a01b038a8116825289811660208301528816818301526060810187905290517f7d3706b5a5b55581dd829778c6dc22a79c5e0909849ef3174c169b718978d8aa9350908190036080019150a15050600161012d5550505050565b60ff808a16600090815261016a60205260409020548a9116156115925760405162461bcd60e51b8152600401610c79906157fa565b600261012d5414156115b65760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff16156115df5760405162461bcd60e51b8152600401610c799061579c565b6101615460ff161561161b57336000908152610167602052604090205460ff1661161b5760405162461bcd60e51b8152600401610c79906157c6565b600089815261016560205260409020546001600160a01b0316806116515760405162461bcd60e51b8152600401610c7990615718565b600034116116b25760405162461bcd60e51b815260206004820152602860248201527f6465706f7369744554483a204e6f206e617469766520617373657473207472616044820152671b9cd9995c9c995960c21b6064820152608401610c79565b6000816001600160a01b031663e0af36166040518163ffffffff1660e01b815260040160206040518083038186803b1580156116ed57600080fd5b505afa158015611701573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117259190614944565b9050806001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561176257600080fd5b505af1158015611776573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038516935063a9059cbb92506117a9915033903490600401615581565b602060405180830381600087803b1580156117c357600080fd5b505af11580156117d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117fb9190614c18565b61180457600080fd5b6118158c8c8c8c8c8c8c8c8c61398f565b5050600161012d5550505050505050505050565b600261012d54141561184d5760405162461bcd60e51b8152600401610c7990615889565b600261012d5561185c82611440565b6118668133610bb6565b6118708383613b45565b600080516020615b86833981519152831480156119115750610163546040516370a0823160e01b8152600160401b9091046001600160a01b0316906370a08231906118bf908590600401615549565b60206040518083038186803b1580156118d757600080fd5b505afa1580156118eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061190f9190614d6d565b155b156119cc57610163546040516335313c2160e11b8152600160401b9091046001600160a01b031690636a6278429061194d908590600401615549565b600060405180830381600087803b15801561196757600080fd5b505af115801561197b573d6000803e3d6000fd5b5050505061016254600161198f91906159e9565b610162556040517f03580ee9f53a62b7cb409a2cb56f9be87747dd15017afc5cef6eef321e4fb2c5906119c3908490615549565b60405180910390a15b5050600161012d5550565b6001600160a01b0381163314611a475760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610c79565b611a518282613b67565b5050565b306001600160a01b037f000000000000000000000000ee45c6e967333659e6f7312d3b81a1f79d821731161415611a9e5760405162461bcd60e51b8152600401610c7990615680565b7f000000000000000000000000ee45c6e967333659e6f7312d3b81a1f79d8217316001600160a01b0316611ad0613bce565b6001600160a01b031614611af65760405162461bcd60e51b8152600401610c79906156cc565b611aff81613bfc565b60408051600080825260208201909252611b1b91839190613c08565b50565b600261012d541415611b425760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff1615611b6b5760405162461bcd60e51b8152600401610c799061579c565b600082905060008390506000816001600160a01b031663e0af36166040518163ffffffff1660e01b815260040160206040518083038186803b158015611bb057600080fd5b505afa158015611bc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611be89190614944565b604051631a7f5a4160e31b81529091506001600160a01b0384169063d3fad20890611c1b9033908590899060040161555d565b600060405180830381600087803b158015611c3557600080fd5b505af1158015611c49573d6000803e3d6000fd5b50505050336001600160a01b03167f379bc14156b62673a2efd113a5b989c8240c2018bf1fa01ee2d3d5915f769d4b8583604051611c889291906155be565b60405180910390a25050600161012d55505050565b600080848484604051602001611cb5939291906154e0565b60408051808303601f1901815282825280516020918201206000818152610166909252919020546101635463030b0f8d60e01b845291935091600160401b9091046001600160a01b03169063030b0f8d90611d1690849033906004016155be565b60206040518083038186803b158015611d2e57600080fd5b505afa158015611d42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d669190614c18565b925050505b9392505050565b600080516020615ba6833981519152611d8b8133610bb6565b60335460ff16611dad5760405162461bcd60e51b8152600401610c7990615652565b611b1b613d48565b60ff808a16600090815261016a60205260409020548a911615611dea5760405162461bcd60e51b8152600401610c79906157fa565b600261012d541415611e0e5760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff1615611e375760405162461bcd60e51b8152600401610c799061579c565b6101615460ff1615611e7357336000908152610167602052604090205460ff16611e735760405162461bcd60e51b8152600401610c79906157c6565b611e848a8a8a8a8a8a8a8a8a61398f565b5050600161012d555050505050505050565b306001600160a01b037f000000000000000000000000ee45c6e967333659e6f7312d3b81a1f79d821731161415611edf5760405162461bcd60e51b8152600401610c7990615680565b7f000000000000000000000000ee45c6e967333659e6f7312d3b81a1f79d8217316001600160a01b0316611f11613bce565b6001600160a01b031614611f375760405162461bcd60e51b8152600401610c79906156cc565b611f4082613bfc565b611a5182826001613c08565b6000611f588133610bb6565b610161805460ff19168315159081179091556040519081527f78e648f9aa0bf2a4400dc354b571bbbf0d423305d9b78e94a9014ab03ff8bb7b906020015b60405180910390a15050565b60335460ff1615611fc55760405162461bcd60e51b8152600401610c799061579c565b6040516330414fc560e11b815283906001600160a01b038216906360829f8a90611ff79033908790879060040161555d565b600060405180830381600087803b15801561201157600080fd5b505af1158015612025573d6000803e3d6000fd5b50505050336001600160a01b03167f379bc14156b62673a2efd113a5b989c8240c2018bf1fa01ee2d3d5915f769d4b83856040516120649291906155be565b60405180910390a250505050565b600080516020615b2683398151915261208b8133610bb6565b5060009081526101656020908152604080832080546001600160a01b039095166001600160a01b03199095168517905592825261016b905220805460ff19166001179055565b60006120dd8133610bb6565b60405163e0169b1360e01b81526001600160a01b038481166004830152838116602483015285919082169063e0169b13906044015b600060405180830381600087803b15801561212c57600080fd5b505af1158015612140573d6000803e3d6000fd5b505050505050505050565b60006121578133610bb6565b6000826001600160401b0316116121a85760405162461bcd60e51b815260206004820152601560248201527406e6f6e636520636865636b706f696e7420213d203605c1b6044820152606401610c79565b5060ff91909116600090815261016d60205260409020805467ffffffffffffffff19166001600160401b03909216919091179055565b60ff808316600090815261016a60205260408120549091849116156122155760405162461bcd60e51b8152600401610c79906157fa565b60335460ff16156122385760405162461bcd60e51b8152600401610c799061579c565b600083815261016560209081526040808320546001600160a01b0316835261016990915290205460ff1615156001148061229d5750600083815261016560209081526040808320546001600160a01b0316835261016b90915290205460ff1615156001145b6123085760405162461bcd60e51b815260206004820152603660248201527f4272696467653a20436f6e7472616374206e6569746865722073657175656e6360448201527532b9103737b91033b2b732b934b1903430b7323632b960511b6064820152608401610c79565b600083815261016560205260409020546001600160a01b0316331461238b5760405162461bcd60e51b815260206004820152603360248201527f4272696467653a205265736f7572636520494420646f6573206e6f74206d617460448201527231b4103bb4ba34103a3432903430b7323632b960691b6064820152608401610c79565b60ff8416600090815261016460205260408120805482906123b4906001600160401b0316615a8b565b91906101000a8154816001600160401b0302191690836001600160401b0316021790559050806001600160401b0316848660ff167fc9745c10b9322d1d4b7bf22f00dc660872b611832eedcfffdbcdc09ebafcb313600060405161241a91815260200190565b60405180910390a4949350505050565b600261012d54141561244e5760405162461bcd60e51b8152600401610c7990615889565b600261012d55600080516020615b4683398151915261246d8133610bb6565b604051636ce5768960e11b815285906001600160a01b0382169063d9caed12906114ca9088908890889060040161555d565b60006124ab8133610bb6565b60335460ff16156124ce5760405162461bcd60e51b8152600401610c799061579c565b6000858584866040516020016124e79493929190615512565b60408051808303601f19018152828252805160209182012061016354600082815261016690935292822054632e31150760e11b85526004850152935091600160401b9091046001600160a01b031690635c622a0e9060240160206040518083038186803b15801561255757600080fd5b505afa15801561256b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061258f9190614ce2565b905060048160048111156125b357634e487b7160e01b600052602160045260246000fd5b146125fd5760405162461bcd60e51b815260206004820152601a602482015279141c9bdc1bdcd85b081b5d5cdd0818994818d85b98d95b1b195960321b6044820152606401610c79565b50600090815261016660205260408120555050505050565b60006126218133610bb6565b6101608290556040518281527fa2b67627a88e010182419ae858fcf3ca4374ad08cbbd6fe10bebcf8b26d3b5fe90602001611f96565b600080516020615ba68339815191526126708133610bb6565b60335460ff16156126935760405162461bcd60e51b8152600401610c799061579c565b611b1b613dae565b60006126a78133610bb6565b604051631764b06b60e21b81526001600160a01b0384811660048301528315156024830152859190821690635d92c1ac90604401612112565b60006126ec8133610bb6565b6101615460ff1661270f5760405162461bcd60e51b8152600401610c799061574d565b6001600160a01b0382166000908152610167602052604090819020805460ff19169055517f441e43beaf2db8af6e1f9f7a6b9f0dcc36fcf83a2904264c9ab624068242efff90611f96908490615549565b600061276c8133610bb6565b60405163e7c308fd60e01b815283906001600160a01b0382169063e7c308fd9061279a908690600401615549565b600060405180830381600087803b1580156127b457600080fd5b505af11580156127c8573d6000803e3d6000fd5b5050505050505050565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600261012d5414156128215760405162461bcd60e51b8152600401610c7990615889565b600261012d5560335460ff161561284a5760405162461bcd60e51b8152600401610c799061579c565b600081905060008290506000816001600160a01b031663e0af36166040518163ffffffff1660e01b815260040160206040518083038186803b15801561288f57600080fd5b505afa1580156128a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c79190614944565b905034806129235760405162461bcd60e51b815260206004820152602360248201527f7374616b654554483a20696e73756666696369656e74206574682070726f766960448201526219195960ea1b6064820152608401610c79565b816001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b15801561295e57600080fd5b505af1158015612972573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038616935063a9059cbb92506129a5915088908590600401615581565b602060405180830381600087803b1580156129bf57600080fd5b505af11580156129d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129f79190614c18565b612a0057600080fd5b60405163f4e480e160e01b81526001600160a01b0385169063f4e480e190612a309033908690869060040161555d565b600060405180830381600087803b158015612a4a57600080fd5b505af1158015612a5e573d6000803e3d6000fd5b50505050336001600160a01b03167fcc2e01638b08266366840f4a2ac8755c01e6932f730d5b707835cf4e23a152458284604051611c889291906155be565b6000612aa98133610bb6565b610163805467ffffffffffffffff19166001600160401b038481169190911791829055604051911681527f99c317e8206747b01304c113e5c93aee8a0d136eca391733b384fc0f878f6e0690602001611f96565b600080516020615b86833981519152612b168133610bb6565b60335460ff1615612b395760405162461bcd60e51b8152600401610c799061579c565b60ff808a16600090815261016c602090815260408083206001600160401b038d16845290915290205416158015612b8e575060ff8916600090815261016d60205260409020546001600160401b03808a169116105b612bc85760405162461bcd60e51b815260206004820152600b60248201526a6e6f6e636520697373756560a81b6044820152606401610c79565b600085815261016560209081526040808320549051612bf7926001600160a01b03909216918b918b910161542d565b60405160208183030381529060405280519060200120905060008a8a8389604051602001612c289493929190615512565b60408051601f19818403018152918152815160209283012060008a81526101658452828120546001600160a01b0316815261016990935291205490915060ff1615612d135760008781526101656020526040908190205490516330faa25960e01b81526001600160a01b039091169081906330faa25990612caf908d908d90600401615610565b600060405180830381600087803b158015612cc957600080fd5b505af1158015612cdd573d6000803e3d6000fd5b50505050600080516020615b668339815191528c8c600386604051612d059493929190615939565b60405180910390a150612f6e565b600087815261016560209081526040808320546001600160a01b0316835261016b90915290205460ff1615612e0d5760008781526101656020526040908190205490516330faa25960e01b81526001600160a01b039091169081906330faa25990612d84908d908d90600401615610565b602060405180830381600087803b158015612d9e57600080fd5b505af1158015612db2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dd69190614c18565b507f515e6a8cc9a22ef1fc441f36516f147da819924307b2404120e78a4d605985288c8c600386604051612d059493929190615939565b600080612e1a8b8b613e06565b61024081018790526102608101899052610280810188905260ff8e166040808301919091526001600160401b038e1660208084019190915260008c8152610165909152819020549051635f624fbd60e01b81529192506001600160a01b0316908190635f624fbd90612e929085908e906004016158c0565b6040805180830381600087803b158015612eab57600080fd5b505af1158015612ebf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ee39190614bcf565b836060018181525081945050508c6001600160401b03168e60ff167ff3eebc917bbcdbb3122520c3cdb2a3e3955672aeb3612717f0c7b2872ed296e78585606001516003604051612f369392919061559a565b60405180910390a3600080516020615b668339815191528e8e600388604051612f629493929190615939565b60405180910390a15050505b6101635460008281526101666020526040808220549051632e31150760e11b815260048101919091529091600160401b90046001600160a01b031690635c622a0e9060240160206040518083038186803b158015612fcb57600080fd5b505afa158015612fdf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130039190614ce2565b9050600281600481111561302757634e487b7160e01b600052602160045260246000fd5b146130745760405162461bcd60e51b815260206004820181905260248201527f50726f706f73616c206d757374206861766520506173736564207374617475736044820152606401610c79565b610163546000838152610166602052604090819020549051630d61b51960e01b81526004810191909152600160401b9091046001600160a01b031690630d61b51990602401602060405180830381600087803b1580156130d357600080fd5b505af11580156130e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061310b9190614c18565b50505060ff909916600090815261016c602090815260408083206001600160401b03909b16835299905297909720805460ff191660011790555050505050505050565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091526000858584866040516020016131999493929190615512565b60408051808303601f19018152828252805160209182012061016354600082815261016690935292909120546307336bcb60e21b845260048401529250600160401b90046001600160a01b031690631ccdaf2c9060240160c06040518083038186803b15801561320857600080fd5b505afa15801561321c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132409190614cfc565b9150505b949350505050565b60335460ff161561326f5760405162461bcd60e51b8152600401610c799061579c565b60405163bf6eac2f60e01b815283906001600160a01b0382169063bf6eac2f906132a19033908790879060040161555d565b600060405180830381600087803b1580156132bb57600080fd5b505af11580156132cf573d6000803e3d6000fd5b50505050336001600160a01b03167fcc2e01638b08266366840f4a2ac8755c01e6932f730d5b707835cf4e23a1524583856040516120649291906155be565b600061331a8133610bb6565b60ff8316600081815261016a6020908152604091829020805460ff191686151590811790915591519182527f8b367b8e5c490bcc4378a8f54d118e435bc9b33d1022a2efdeffc598739a05c8910160405180910390a2505050565b60008084848460405160200161338d939291906154e0565b60408051808303601f19018152919052805160209091012095945050505050565b600080516020615b268339815191526133c78133610bb6565b600083815261016560205260409081902080546001600160a01b0319166001600160a01b0387169081179091559051635c7d1b9b60e11b815285919063b8fa37369061211290879087906004016155be565b600261012d54141561343d5760405162461bcd60e51b8152600401610c7990615889565b600261012d5561344c82611440565b6134568133610bb6565b613460838361409e565b600080516020615b868339815191528314801561350a5750610163546040516370a0823160e01b8152600160401b9091046001600160a01b0316906370a08231906134af908590600401615549565b60206040518083038186803b1580156134c757600080fd5b505afa1580156134db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134ff9190614d6d565b670de0b6b3a7640000145b156119cc576101635460405163226bf2d160e21b8152600160401b9091046001600160a01b0316906389afcb4490613546908590600401615549565b600060405180830381600087803b15801561356057600080fd5b505af1158015613574573d6000803e3d6000fd5b505050506001610162546135889190615a20565b610162556040517f10e1f7ce9fd7d1b90a66d13a2ab3cb8dd7f29f3f8d520b143b063ccfbab6906b906119c3908490615549565b60006135c88133610bb6565b6101615460ff166135eb5760405162461bcd60e51b8152600401610c799061574d565b6001600160a01b0382166000908152610167602052604090819020805460ff19166001179055517f2373c347d35d91064d64b63157cb8aee2bd652a41983ca2e8a3e7348bfeff92f90611f96908490615549565b600061364b8133610bb6565b60405163e4cd10db60e01b81526001600160a01b03868116600483015285811660248301528481166044830152838116606483015287919082169063e4cd10db90608401600060405180830381600087803b1580156136a957600080fd5b505af11580156136bd573d6000803e3d6000fd5b5050505050505050505050565b60ff808316600090815261016a602052604081205490918291859116156137035760405162461bcd60e51b8152600401610c79906157fa565b6000868152610165602052604090819020549051639e601b3160e01b815260ff871660048201526001600160a01b0386811660248301529091169081908190639e601b3190604401604080518083038186803b15801561376257600080fd5b505afa158015613776573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379a9190614d85565b94509450505050935093915050565b60006137b58133610bb6565b6000838152610165602052604090819020549051636be1dc2b60e01b815283151560048201526001600160a01b039091169081908190636be1dc2b90602401612112565b600054610100900460ff166138145760005460ff1615613818565b303b155b61387b5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c79565b600054610100900460ff161580156138a6576000805460ff1961ff0019909116610100171660011790555b6138ae6140bb565b6138b66140fc565b6138c1600033614133565b610163805461015f805460ff191660ff8916179055600160401b600160e01b031916600160401b6001600160a01b038516021767ffffffffffffffff19166001600160401b0386161790556101608390558015613924576000805461ff00191690555b5050505050565b61393582826127d2565b611a515761394d816001600160a01b0316601461413d565b61395883602061413d565b604051602001613969929190615471565b60408051601f198184030181529082905262461bcd60e51b8252610c799160040161563f565b600061399b8888613e06565b336102a0820152610260810187905261028081018690526001600160a01b038316815290506139ca8385615a37565b610240820152600089815261016560205260409020546001600160a01b031660c08201819052613a0c5760405162461bcd60e51b8152600401610c7990615718565b60ff8a166000908152610164602052604081208054909190613a36906001600160401b0316615a8b565b91906101000a8154816001600160401b0302191690836001600160401b03160217905581602001906001600160401b031690816001600160401b03168152505060008160c001519050806001600160a01b0316634a2661608b8d8560200151866040518563ffffffff1660e01b8152600401613ab594939291906155d5565b600060405180830381600087803b158015613acf57600080fd5b505af1158015613ae3573d6000803e3d6000fd5b5050505081602001516001600160401b03168a8c60ff167fc9745c10b9322d1d4b7bf22f00dc660872b611832eedcfffdbcdc09ebafcb313856102e00151604051613b3091815260200190565b60405180910390a45050505050505050505050565b613b4e82611440565b613b588133610bb6565b613b62838361431e565b505050565b613b7182826127d2565b15611a515760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b6000611a518133610bb6565b6000613c12613bce565b9050613c1d846143a4565b600083511180613c2a5750815b15613c3b57613c398484614449565b505b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143805460ff1661392457805460ff19166001178155604051613cb6908690613c87908590602401615549565b60408051601f198184030181529190526020810180516001600160e01b0316631b2ce7f360e11b179052614449565b50805460ff19168155613cc7613bce565b6001600160a01b0316826001600160a01b031614613d3f5760405162461bcd60e51b815260206004820152602f60248201527f45524331393637557067726164653a207570677261646520627265616b73206660448201526e75727468657220757067726164657360881b6064820152608401610c79565b61392485614534565b60335460ff16613d6a5760405162461bcd60e51b8152600401610c7990615652565b6033805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613da49190615549565b60405180910390a1565b60335460ff1615613dd15760405162461bcd60e51b8152600401610c799061579c565b6033805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613d973390565b613e0e614607565b613e16614607565b6000613e2484860186614da8565b6101a08a015261018089015261016088015261014087019190915261012086019190915261010085019190915260e08401919091529050613e6784860186614dfc565b6102e08b0152505086159550613e84945050505050576001613e87565b60005b15156102c08301526101206040830181905261016083015160009187918790613eb090836159e9565b92613ebd939291906159c1565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101608401516040850151919250613f08916159e9565b6040840181905261018084015160009188918890613f2690836159e9565b92613f33939291906159c1565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101808501516040860151919250613f7e916159e9565b604085018190526101a085015160009189918990613f9c90836159e9565b92613fa9939291906159c1565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101a08601516040870151919250613ff4916159e9565b604086018190526101a08601516000918a918a9061401290836159e9565b9261401f939291906159c1565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505050602093840151928401519084015194909301516001600160601b03199283166101c0880152606093841c61022088015291909316610200860152901c60808401525090949350505050565b6140a782611440565b6140b18133610bb6565b613b628383613b67565b600054610100900460ff166140e25760405162461bcd60e51b8152600401610c799061583e565b6140ea614574565b6140f2614574565b6140fa614574565b565b600054610100900460ff166141235760405162461bcd60e51b8152600401610c799061583e565b61412b614574565b6140fa61459b565b611a51828261431e565b6060600061414c836002615a01565b6141579060026159e9565b6001600160401b0381111561417c57634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f1916602001820160405280156141a6576020820181803683370190505b509050600360fc1b816000815181106141cf57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061420c57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053506000614230846002615a01565b61423b9060016159e9565b90505b60018111156142cf576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061427d57634e487b7160e01b600052603260045260246000fd5b1a60f81b8282815181106142a157634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535060049490941c936142c881615a74565b905061423e565b508315611d6b5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c79565b61432882826127d2565b611a515760008281526097602090815260408083206001600160a01b03851684529091529020805460ff191660011790556143603390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b803b6144085760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610c79565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b0319166001600160a01b0392909216919091179055565b6060823b6144a85760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608401610c79565b600080846001600160a01b0316846040516144c39190615455565b600060405180830381855af49150503d80600081146144fe576040519150601f19603f3d011682016040523d82523d6000602084013e614503565b606091505b509150915061452b8282604051806060016040528060278152602001615bc6602791396145ce565b95945050505050565b61453d816143a4565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b600054610100900460ff166140fa5760405162461bcd60e51b8152600401610c799061583e565b600054610100900460ff166145c25760405162461bcd60e51b8152600401610c799061583e565b6033805460ff19169055565b606083156145dd575081611d6b565b8251156145ed5782518084602001fd5b8160405162461bcd60e51b8152600401610c79919061563f565b604080516103008101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052610100820183905261012082018390526101408201839052610160820183905261018082018390526101a082018390526101c082018390526101e0820183905261020082018390526102208201839052610240820181905261026082018190526102808201526102a081018290526102c081018290526102e081019190915290565b60006146dd6146d88461599e565b61596e565b83815290506020808201908360005b86811015614713576147018883358801614899565b845292820192908201906001016146ec565b505050509392505050565b8035610b9c81615ade565b600082601f830112614739578081fd5b813560206147496146d88361599e565b8281528181019085830183850287018401881015614765578586fd5b855b8581101561478c57813561477a81615ade565b84529284019290840190600101614767565b5090979650505050505050565b60008083601f8401126147aa578182fd5b5081356001600160401b038111156147c0578182fd5b60208301915083602080830285010111156147da57600080fd5b9250929050565b600082601f8301126147f1578081fd5b611d6b838335602085016146ca565b600082601f830112614810578081fd5b813560206148206146d88361599e565b828152818101908583018385028701840188101561483c578586fd5b855b8581101561478c5781358452928401929084019060010161483e565b60008083601f84011261486b578182fd5b5081356001600160401b03811115614881578182fd5b6020830191508360208285010111156147da57600080fd5b600082601f8301126148a9578081fd5b81356001600160401b038111156148c2576148c2615ac8565b6148d5601f8201601f191660200161596e565b8181528460208386010111156148e9578283fd5b816020850160208301379081016020019190915292915050565b805160058110610b9c57600080fd5b8035610b9c81615b01565b8035610b9c81615b16565b600060208284031215614939578081fd5b8135611d6b81615ade565b600060208284031215614955578081fd5b8151611d6b81615ade565b60008060408385031215614972578081fd5b823561497d81615ade565b9150602083013561498d81615ade565b809150509250929050565b6000806000606084860312156149ac578081fd5b83356149b781615ade565b925060208401356149c781615ade565b915060408401356149d781615ade565b809150509250925092565b600080600080600060a086880312156149f9578283fd5b8535614a0481615ade565b94506020860135614a1481615ade565b93506040860135614a2481615ade565b92506060860135614a3481615ade565b91506080860135614a4481615ade565b809150509295509295909350565b60008060008060808587031215614a67578182fd5b8435614a7281615ade565b93506020850135614a8281615ade565b92506040850135614a9281615ade565b9396929550929360600135925050565b600080600060608486031215614ab6578081fd5b8335614ac181615ade565b92506020840135614ad181615ade565b915060408401356149d781615af3565b600080600060608486031215614af5578081fd5b8335614b0081615ade565b92506020840135614b1081615ade565b929592945050506040919091013590565b60008060408385031215614b33578182fd5b8235614b3e81615ade565b946020939093013593505050565b600080600060608486031215614b60578081fd5b8335614b6b81615ade565b92506020840135915060408401356149d781615ade565b60008060408385031215614b94578182fd5b8235614b9f81615ade565b915060208301356001600160401b03811115614bb9578182fd5b614bc585828601614899565b9150509250929050565b60008060408385031215614be1578182fd5b8251614bec81615ade565b6020939093015192949293505050565b600060208284031215614c0d578081fd5b8135611d6b81615af3565b600060208284031215614c29578081fd5b8151611d6b81615af3565b600060208284031215614c45578081fd5b5035919050565b60008060408385031215614c5e578182fd5b82359150602083013561498d81615ade565b60008060408385031215614c82578182fd5b82359150602083013561498d81615af3565b600080600060608486031215614ca8578081fd5b8335925060208401356149c781615b16565b600060208284031215614ccb578081fd5b81356001600160e01b031981168114611d6b578182fd5b600060208284031215614cf3578081fd5b611d6b82614903565b600060c08284031215614d0d578081fd5b614d1760c061596e565b614d2083614903565b815260208301516020820152604083015160408201526060830151614d4481615b01565b60608201526080838101519082015260a0830151614d6181615b16565b60a08201529392505050565b600060208284031215614d7e578081fd5b5051919050565b60008060408385031215614d97578182fd5b505080516020909101519092909150565b600080600080600080600080610100898b031215614dc4578586fd5b505086359860208801359850604088013597606081013597506080810135965060a0810135955060c0810135945060e0013592509050565b60008060008060008060008060006101208a8c031215614e1a578283fd5b505087359960208901359950604089013598606081013598506080810135975060a0810135965060c0810135955060e08101359450610100013592509050565b600060208284031215614e6b578081fd5b8135611d6b81615b16565b60008060408385031215614e88578182fd5b8235614e9381615b16565b9150602083013561498d81615af3565b60008060408385031215614eb5578182fd5b8235614b3e81615b16565b600080600080600080600080600060e08a8c031215614edd578283fd5b614ee68a61491d565b985060208a0135975060408a01356001600160401b0380821115614f08578485fd5b614f148d838e0161485a565b909950975060608c0135915080821115614f2c578485fd5b614f388d838e01614800565b965060808c0135915080821115614f4d578485fd5b614f598d838e01614729565b955060a08c0135915080821115614f6e578485fd5b50614f7b8c828d01614799565b9094509250614f8e905060c08b0161471e565b90509295985092959850929598565b60008060008060808587031215614fb2578182fd5b8435614fbd81615b16565b935060208501359250604085013591506060850135614fdb81615ade565b939692955090935050565b60008060408385031215614ff8578182fd5b823561500381615b16565b9150602083013561498d81615b01565b600080600060608486031215615027578081fd5b833561503281615b16565b92506020840135614b1081615b01565b60008060008060808587031215615057578182fd5b843561506281615b16565b9350602085013561507281615b01565b93969395505050506040820135916060013590565b60008060008060008060008060e0898b0312156150a2578182fd5b6150ab8961491d565b97506150b960208a01614912565b965060408901356001600160401b03808211156150d4578384fd5b6150e08c838d0161485a565b909850965060608b0135955060808b01359150808211156150ff578384fd5b61510b8c838d01614800565b945060a08b0135915080821115615120578384fd5b61512c8c838d01614729565b935060c08b0135915080821115615141578283fd5b5061514e8b828c016147e1565b9150509295985092959890939650565b6001600160a01b03169052565b6000815180845260208085019450808401835b838110156151a35781516001600160a01b03168752958201959082019060010161517e565b509495945050505050565b6000815180845260208085018081965082840281019150828601855b858110156151f45782840389526151e284835161523e565b988501989350908401906001016151ca565b5091979650505050505050565b6000815180845260208085019450808401835b838110156151a357815187529582019590820190600101615214565b6001600160601b0319169052565b60008151808452615256816020860160208601615a44565b601f01601f19169290920160200192915050565b6005811061528857634e487b7160e01b600052602160045260246000fd5b9052565b600061030061529c84845161515e565b60208301516152b660208601826001600160401b03169052565b50604083015160408501526060830151606085015260808301516152dd608086018261515e565b5060a08301516152f060a086018261515e565b5060c083015161530360c086018261515e565b5060e08381015190850152610100808401519085015261012080840151908501526101408084015190850152610160808401519085015261018080840151908501526101a080840151908501526101c08084015161536382870182615230565b50506101e0808401516153788287018261515e565b50506102008084015161538d82870182615230565b5050610220808401516153a28287018261515e565b50506102408084015182828701526153bc838701826151ae565b9250505061026080840151858303828701526153d88382615201565b9250505061028080840151858303828701526153f4838261516b565b925050506102a08084015161540b8287018261515e565b50506102c0838101511515908501526102e09283015192909301919091525090565b606084901b6001600160601b0319168152600082846014840137910160140190815292915050565b60008251615467818460208701615a44565b9190910192915050565b600076020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b825283516154a3816017850160208801615a44565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516154d4816028840160208801615a44565b01602801949350505050565b60f89390931b6001600160f81b031916835260c09190911b6001600160c01b0319166001830152600982015260290190565b60f89490941b6001600160f81b031916845260c09290921b6001600160c01b03191660018401526009830152602982015260490190565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03841681526020810183905260608101613244604083018461526a565b9182526001600160a01b0316602082015260400190565b600085825260ff851660208301526001600160401b038416604083015260806060830152615606608083018461528c565b9695505050505050565b60006020825282602083015282846040840137818301604090810191909152601f909201601f19160101919050565b600060208252611d6b602083018461523e565b60208082526014908201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604082015260600190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b6020808252818101527f7265736f757263654944206e6f74206d617070656420746f2068616e646c6572604082015260600190565b6020808252602f908201527f4272696467655570677261646561626c653a205768697465206c697374696e6760408201526e081a5cc81b9bdd08195b98589b1959608a1b606082015260800190565b60208082526010908201526f14185d5cd8589b194e881c185d5cd95960821b604082015260600190565b6020808252601a90820152791859191c995cdcc81a5cc81b9bdd081dda1a5d195b1a5cdd195960321b604082015260600190565b60208082526024908201527f4272696467655570677261646561626c653a20556e737570706f7274656420636040820152633430b4b760e11b606082015260800190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6000604082526158d3604083018561528c565b90508260208301529392505050565b600060c0820190506158f582845161526a565b60208301516020830152604083015160408301526001600160401b0360608401511660608301526080830151608083015260ff60a08401511660a083015292915050565b60ff851681526001600160401b03841660208201526080810161595f604083018561526a565b82606083015295945050505050565b604051601f8201601f191681016001600160401b038111828210171561599657615996615ac8565b604052919050565b60006001600160401b038211156159b7576159b7615ac8565b5060209081020190565b600080858511156159d0578182fd5b838611156159dc578182fd5b5050820193919092039150565b600082198211156159fc576159fc615ab2565b500190565b6000816000190483118215151615615a1b57615a1b615ab2565b500290565b600082821015615a3257615a32615ab2565b500390565b6000611d6b3684846146ca565b60005b83811015615a5f578181015183820152602001615a47565b83811115615a6e576000848401525b50505050565b600081615a8357615a83615ab2565b506000190190565b60006001600160401b0380831681811415615aa857615aa8615ab2565b6001019392505050565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114611b1b57600080fd5b8015158114611b1b57600080fd5b6001600160401b0381168114611b1b57600080fd5b60ff81168114611b1b57600080fdfe8b9e7a9f25b0aca3f51c01b8fee30790fb16f4d4deded8385ae6643d054bb078bf233dd2aafeb4d50879c4aa5c81e96d92f6e6945c906a58f9f2d1c1631b4b26968626a768e76ba1363efe44e322a6c4900c5f084e0b45f35e294dfddaa9e0d5e2b7fb3b832174769106daebcfd6d1970523240dda11281102db9363b83b0dc465d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a164736f6c6343000802000a