zellic-audit
Initial commit
f998fcd
raw
history blame
117 kB
{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts/access/AccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(account),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n"
},
"@openzeppelin/contracts/access/IAccessControl.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"@openzeppelin/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n"
},
"@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
},
"@openzeppelin/contracts/utils/math/Math.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n enum Rounding {\n Down, // Toward negative infinity\n Up, // Toward infinity\n Zero // Toward zero\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds up instead\n * of rounding down.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n * with further edits by Uniswap Labs also under MIT license.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod0 := mul(x, y)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n // See https://cs.stackexchange.com/q/138556/92363.\n\n // Does not overflow because the denominator cannot be zero at this stage in the function.\n uint256 twos = denominator & (~denominator + 1);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n // in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(\n uint256 x,\n uint256 y,\n uint256 denominator,\n Rounding rounding\n ) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10, rounded down, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10**64) {\n value /= 10**64;\n result += 64;\n }\n if (value >= 10**32) {\n value /= 10**32;\n result += 32;\n }\n if (value >= 10**16) {\n value /= 10**16;\n result += 16;\n }\n if (value >= 10**8) {\n value /= 10**8;\n result += 8;\n }\n if (value >= 10**4) {\n value /= 10**4;\n result += 4;\n }\n if (value >= 10**2) {\n value /= 10**2;\n result += 2;\n }\n if (value >= 10**1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256, rounded down, of a positive value.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Strings.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./math/Math.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), _SYMBOLS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n"
},
"@rari-capital/solmate/src/tokens/ERC20.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-only\npragma solidity >=0.8.0;\n\n/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.\n/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)\n/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)\n/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.\nabstract contract ERC20 {\n /*//////////////////////////////////////////////////////////////\n EVENTS\n //////////////////////////////////////////////////////////////*/\n\n event Transfer(address indexed from, address indexed to, uint256 amount);\n\n event Approval(address indexed owner, address indexed spender, uint256 amount);\n\n /*//////////////////////////////////////////////////////////////\n METADATA STORAGE\n //////////////////////////////////////////////////////////////*/\n\n string public name;\n\n string public symbol;\n\n uint8 public immutable decimals;\n\n /*//////////////////////////////////////////////////////////////\n ERC20 STORAGE\n //////////////////////////////////////////////////////////////*/\n\n uint256 public totalSupply;\n\n mapping(address => uint256) public balanceOf;\n\n mapping(address => mapping(address => uint256)) public allowance;\n\n /*//////////////////////////////////////////////////////////////\n EIP-2612 STORAGE\n //////////////////////////////////////////////////////////////*/\n\n uint256 internal immutable INITIAL_CHAIN_ID;\n\n bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;\n\n mapping(address => uint256) public nonces;\n\n /*//////////////////////////////////////////////////////////////\n CONSTRUCTOR\n //////////////////////////////////////////////////////////////*/\n\n constructor(\n string memory _name,\n string memory _symbol,\n uint8 _decimals\n ) {\n name = _name;\n symbol = _symbol;\n decimals = _decimals;\n\n INITIAL_CHAIN_ID = block.chainid;\n INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();\n }\n\n /*//////////////////////////////////////////////////////////////\n ERC20 LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function approve(address spender, uint256 amount) public virtual returns (bool) {\n allowance[msg.sender][spender] = amount;\n\n emit Approval(msg.sender, spender, amount);\n\n return true;\n }\n\n function transfer(address to, uint256 amount) public virtual returns (bool) {\n balanceOf[msg.sender] -= amount;\n\n // Cannot overflow because the sum of all user\n // balances can't exceed the max uint256 value.\n unchecked {\n balanceOf[to] += amount;\n }\n\n emit Transfer(msg.sender, to, amount);\n\n return true;\n }\n\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual returns (bool) {\n uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.\n\n if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;\n\n balanceOf[from] -= amount;\n\n // Cannot overflow because the sum of all user\n // balances can't exceed the max uint256 value.\n unchecked {\n balanceOf[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n return true;\n }\n\n /*//////////////////////////////////////////////////////////////\n EIP-2612 LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public virtual {\n require(deadline >= block.timestamp, \"PERMIT_DEADLINE_EXPIRED\");\n\n // Unchecked because the only math done is incrementing\n // the owner's nonce which cannot realistically overflow.\n unchecked {\n address recoveredAddress = ecrecover(\n keccak256(\n abi.encodePacked(\n \"\\x19\\x01\",\n DOMAIN_SEPARATOR(),\n keccak256(\n abi.encode(\n keccak256(\n \"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\"\n ),\n owner,\n spender,\n value,\n nonces[owner]++,\n deadline\n )\n )\n )\n ),\n v,\n r,\n s\n );\n\n require(recoveredAddress != address(0) && recoveredAddress == owner, \"INVALID_SIGNER\");\n\n allowance[recoveredAddress][spender] = value;\n }\n\n emit Approval(owner, spender, value);\n }\n\n function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {\n return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();\n }\n\n function computeDomainSeparator() internal view virtual returns (bytes32) {\n return\n keccak256(\n abi.encode(\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\n keccak256(bytes(name)),\n keccak256(\"1\"),\n block.chainid,\n address(this)\n )\n );\n }\n\n /*//////////////////////////////////////////////////////////////\n INTERNAL MINT/BURN LOGIC\n //////////////////////////////////////////////////////////////*/\n\n function _mint(address to, uint256 amount) internal virtual {\n totalSupply += amount;\n\n // Cannot overflow because the sum of all user\n // balances can't exceed the max uint256 value.\n unchecked {\n balanceOf[to] += amount;\n }\n\n emit Transfer(address(0), to, amount);\n }\n\n function _burn(address from, uint256 amount) internal virtual {\n balanceOf[from] -= amount;\n\n // Cannot underflow because a user's balance\n // will never be larger than the total supply.\n unchecked {\n totalSupply -= amount;\n }\n\n emit Transfer(from, address(0), amount);\n }\n}\n"
},
"contracts/interface/IERC4626.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-only\npragma solidity ^0.8.14;\n\nimport {ERC20} from \"@rari-capital/solmate/src/tokens/ERC20.sol\";\n\n/// @title ERC4626 interface\n/// See: https://eips.ethereum.org/EIPS/eip-4626\nabstract contract IERC4626 is ERC20 {\n /*////////////////////////////////////////////////////////\n Events\n ////////////////////////////////////////////////////////*/\n\n /// @notice `sender` has exchanged `assets` for `positions`,\n /// and transferred those `positions` to `receiver`.\n event Deposit(\n address indexed sender,\n address indexed receiver,\n uint256 assets,\n uint256 positions\n );\n\n /// @notice `sender` has exchanged `positions` for `assets`,\n /// and transferred those `assets` to `receiver`.\n event Withdraw(\n address indexed sender,\n address indexed receiver,\n uint256 assets,\n uint256 positions\n );\n\n /*////////////////////////////////////////////////////////\n Vault properties\n ////////////////////////////////////////////////////////*/\n\n /// @notice The address of the underlying ERC20 token used for\n /// the Vault for accounting, depositing, and withdrawing.\n function asset() external view virtual returns (address asset);\n\n /// @notice Total amount of the underlying asset that\n /// is \"managed\" by Vault.\n function totalAssets() external view virtual returns (uint256 totalAssets);\n\n /*////////////////////////////////////////////////////////\n Deposit/Withdrawal Logic\n ////////////////////////////////////////////////////////*/\n\n /// @notice Mints `positions` Vault positions to `receiver` by\n /// depositing exactly `assets` of underlying tokens.\n function deposit(uint256 assets, address receiver)\n external\n virtual\n returns (uint256 positions);\n\n /// @notice Mints exactly `positions` Vault positions to `receiver`\n /// by depositing `assets` of underlying tokens.\n function mint(uint256 positions, address receiver)\n external\n virtual\n returns (uint256 assets);\n\n /// @notice Redeems `positions` from `owner` and sends `assets`\n /// of underlying tokens to `receiver`.\n function withdraw(\n uint256 assets,\n address receiver,\n address owner\n ) external virtual returns (uint256 positions);\n\n /// @notice Redeems `positions` from `owner` and sends `assets`\n /// of underlying tokens to `receiver`.\n function redeem(\n uint256 positions,\n address receiver,\n address owner\n ) external virtual returns (uint256 assets);\n\n /*////////////////////////////////////////////////////////\n Vault Accounting Logic\n ////////////////////////////////////////////////////////*/\n\n /// @notice The amount of positions that the vault would\n /// exchange for the amount of assets provided, in an\n /// ideal scenario where all the conditions are met.\n function convertToShares(uint256 assets)\n external\n view\n virtual\n returns (uint256 positions);\n\n /// @notice The amount of assets that the vault would\n /// exchange for the amount of positions provided, in an\n /// ideal scenario where all the conditions are met.\n function convertToAssets(uint256 positions)\n external\n view\n virtual\n returns (uint256 assets);\n\n /// @notice Total number of underlying assets that can\n /// be deposited by `owner` into the Vault, where `owner`\n /// corresponds to the input parameter `receiver` of a\n /// `deposit` call.\n function maxDeposit(address owner)\n external\n view\n virtual\n returns (uint256 maxAssets);\n\n /// @notice Allows an on-chain or off-chain user to simulate\n /// the effects of their deposit at the current block, given\n /// current on-chain conditions.\n function previewDeposit(uint256 assets)\n external\n view\n virtual\n returns (uint256 positions);\n\n /// @notice Total number of underlying positions that can be minted\n /// for `owner`, where `owner` corresponds to the input\n /// parameter `receiver` of a `mint` call.\n function maxMint(address owner)\n external\n view\n virtual\n returns (uint256 maxPositions);\n\n /// @notice Allows an on-chain or off-chain user to simulate\n /// the effects of their mint at the current block, given\n /// current on-chain conditions.\n function previewMint(uint256 positions)\n external\n view\n virtual\n returns (uint256 assets);\n\n /// @notice Total number of underlying assets that can be\n /// withdrawn from the Vault by `owner`, where `owner`\n /// corresponds to the input parameter of a `withdraw` call.\n function maxWithdraw(address owner)\n external\n view\n virtual\n returns (uint256 maxAssets);\n\n /// @notice Allows an on-chain or off-chain user to simulate\n /// the effects of their withdrawal at the current block,\n /// given current on-chain conditions.\n function previewWithdraw(uint256 assets)\n external\n view\n virtual\n returns (uint256 positions);\n\n /// @notice Total number of underlying positions that can be\n /// redeemed from the Vault by `owner`, where `owner` corresponds\n /// to the input parameter of a `redeem` call.\n function maxRedeem(address owner)\n external\n view\n virtual\n returns (uint256 maxPositions);\n\n /// @notice Allows an on-chain or off-chain user to simulate\n /// the effects of their redeemption at the current block,\n /// given current on-chain conditions.\n function previewRedeem(uint256 positions)\n external\n view\n virtual\n returns (uint256 assets);\n}\n"
},
"contracts/interface/ILayerZeroEndpoint.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.14;\n\nimport \"./ILayerZeroUserApplicationConfig.sol\";\n\ninterface ILayerZeroEndpoint is ILayerZeroUserApplicationConfig {\n // @notice send a LayerZero message to the specified address at a LayerZero endpoint.\n // @param _dstChainId - the destination chain identifier\n // @param _destination - the address on destination chain (in bytes). address length/format may vary by chains\n // @param _payload - a custom bytes payload to send to the destination contract\n // @param _refundAddress - if the source transaction is cheaper than the amount of value passed, refund the additional amount to this address\n // @param _zroPaymentAddress - the address of the ZRO token holder who would pay for the transaction\n // @param _adapterParams - parameters for custom functionality. e.g. receive airdropped native gas from the relayer on destination\n function send(\n uint16 _dstChainId,\n bytes calldata _destination,\n bytes calldata _payload,\n address payable _refundAddress,\n address _zroPaymentAddress,\n bytes calldata _adapterParams\n ) external payable;\n\n // @notice used by the messaging library to publish verified payload\n // @param _srcChainId - the source chain identifier\n // @param _srcAddress - the source contract (as bytes) at the source chain\n // @param _dstAddress - the address on destination chain\n // @param _nonce - the unbound message ordering nonce\n // @param _gasLimit - the gas limit for external contract execution\n // @param _payload - verified payload to send to the destination contract\n function receivePayload(\n uint16 _srcChainId,\n bytes calldata _srcAddress,\n address _dstAddress,\n uint64 _nonce,\n uint256 _gasLimit,\n bytes calldata _payload\n ) external;\n\n // @notice get the inboundNonce of a lzApp from a source chain which could be EVM or non-EVM chain\n // @param _srcChainId - the source chain identifier\n // @param _srcAddress - the source chain contract address\n function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress)\n external\n view\n returns (uint64);\n\n // @notice get the outboundNonce from this source chain which, consequently, is always an EVM\n // @param _srcAddress - the source chain contract address\n function getOutboundNonce(uint16 _dstChainId, address _srcAddress)\n external\n view\n returns (uint64);\n\n // @notice gets a quote in source native gas, for the amount that send() requires to pay for message delivery\n // @param _dstChainId - the destination chain identifier\n // @param _userApplication - the user app address on this EVM chain\n // @param _payload - the custom message to send over LayerZero\n // @param _payInZRO - if false, user app pays the protocol fee in native token\n // @param _adapterParam - parameters for the adapter service, e.g. send some dust native token to dstChain\n function estimateFees(\n uint16 _dstChainId,\n address _userApplication,\n bytes calldata _payload,\n bool _payInZRO,\n bytes calldata _adapterParam\n ) external view returns (uint256 nativeFee, uint256 zroFee);\n\n // @notice get this Endpoint's immutable source identifier\n function getChainId() external view returns (uint16);\n\n // @notice the interface to retry failed message on this Endpoint destination\n // @param _srcChainId - the source chain identifier\n // @param _srcAddress - the source chain contract address\n // @param _payload - the payload to be retried\n function retryPayload(\n uint16 _srcChainId,\n bytes calldata _srcAddress,\n bytes calldata _payload\n ) external;\n\n // @notice query if any STORED payload (message blocking) at the endpoint.\n // @param _srcChainId - the source chain identifier\n // @param _srcAddress - the source chain contract address\n function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress)\n external\n view\n returns (bool);\n\n // @notice query if the _libraryAddress is valid for sending msgs.\n // @param _userApplication - the user app address on this EVM chain\n function getSendLibraryAddress(address _userApplication)\n external\n view\n returns (address);\n\n // @notice query if the _libraryAddress is valid for receiving msgs.\n // @param _userApplication - the user app address on this EVM chain\n function getReceiveLibraryAddress(address _userApplication)\n external\n view\n returns (address);\n\n // @notice query if the non-reentrancy guard for send() is on\n // @return true if the guard is on. false otherwise\n function isSendingPayload() external view returns (bool);\n\n // @notice query if the non-reentrancy guard for receive() is on\n // @return true if the guard is on. false otherwise\n function isReceivingPayload() external view returns (bool);\n\n // @notice get the configuration of the LayerZero messaging library of the specified version\n // @param _version - messaging library version\n // @param _chainId - the chainId for the pending config change\n // @param _userApplication - the contract address of the user application\n // @param _configType - type of configuration. every messaging library has its own convention.\n function getConfig(\n uint16 _version,\n uint16 _chainId,\n address _userApplication,\n uint256 _configType\n ) external view returns (bytes memory);\n\n // @notice get the send() LayerZero messaging library version\n // @param _userApplication - the contract address of the user application\n function getSendVersion(address _userApplication)\n external\n view\n returns (uint16);\n\n // @notice get the lzReceive() LayerZero messaging library version\n // @param _userApplication - the contract address of the user application\n function getReceiveVersion(address _userApplication)\n external\n view\n returns (uint16);\n}\n"
},
"contracts/interface/ILayerZeroReceiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.14;\n\ninterface ILayerZeroReceiver {\n // @notice LayerZero endpoint will invoke this function to deliver the message on the destination\n // @param _srcChainId - the source endpoint identifier\n // @param _srcAddress - the source sending contract address from the source chain\n // @param _nonce - the ordered message nonce\n // @param _payload - the signed payload is the UA bytes has encoded to be sent\n function lzReceive(\n uint16 _srcChainId,\n bytes calldata _srcAddress,\n uint64 _nonce,\n bytes calldata _payload\n ) external;\n}\n"
},
"contracts/interface/ILayerZeroUserApplicationConfig.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.14;\n\ninterface ILayerZeroUserApplicationConfig {\n // @notice set the configuration of the LayerZero messaging library of the specified version\n // @param _version - messaging library version\n // @param _chainId - the chainId for the pending config change\n // @param _configType - type of configuration. every messaging library has its own convention.\n // @param _config - configuration in the bytes. can encode arbitrary content.\n function setConfig(\n uint16 _version,\n uint16 _chainId,\n uint256 _configType,\n bytes calldata _config\n ) external;\n\n // @notice set the send() LayerZero messaging library version to _version\n // @param _version - new messaging library version\n function setSendVersion(uint16 _version) external;\n\n // @notice set the lzReceive() LayerZero messaging library version to _version\n // @param _version - new messaging library version\n function setReceiveVersion(uint16 _version) external;\n\n // @notice Only when the UA needs to resume the message flow in blocking mode and clear the stored payload\n // @param _srcChainId - the chainId of the source chain\n // @param _srcAddress - the contract address of the source contract at the source chain\n function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress)\n external;\n}\n"
},
"contracts/interface/ISource.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\npragma solidity ^0.8.14;\n\ninterface IController {\n function chainId() external returns (uint16);\n\n function stateSync(bytes memory _payload) external payable;\n}\n"
},
"contracts/interface/layerzero/IStateHandler.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\npragma solidity ^0.8.14;\n\ninterface IStateHandler {\n function dispatchState(\n uint16 dstChainId,\n bytes memory data,\n bytes memory adapterParam\n ) external payable;\n}\n"
},
"contracts/layerzero/stateHandler.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8.14;\n\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"../lzApp/NonblockingLzApp.sol\";\n\nimport {IController} from \"../interface/ISource.sol\";\nimport {StateData, CallbackType, PayloadState, TransactionType, InitData, ReturnData} from \"../types/lzTypes.sol\";\n\n/**\n * @title State Handler\n * @author Zeropoint Labs.\n *\n * Contract to handle state transfer between chains using layerzero.\n */\ncontract StateHandler is NonblockingLzApp, AccessControl {\n /* ================ Constants =================== */\n bytes32 public constant CORE_CONTRACTS_ROLE =\n keccak256(\"CORE_CONTRACTS_ROLE\");\n bytes32 public constant PROCESSOR_CONTRACTS_ROLE =\n keccak256(\"PROCESSOR_CONTRACTS_ROLE\");\n\n /* ================ State Variables =================== */\n IController public sourceContract;\n IController public destinationContract;\n uint256 public totalPayloads;\n\n /// @dev maps state received to source_chain, destination_chain and txId\n mapping(uint256 => bytes) public payload;\n\n /// @dev maps payload to unique id\n mapping(uint256 => PayloadState) public payloadProcessed;\n\n /// @dev prevents layerzero relayer from replaying payload\n mapping(uint16 => mapping(uint64 => bool)) public isValid;\n\n /* ================ Events =================== */\n event StateReceived(\n uint16 srcChainId,\n uint16 dstChainId,\n uint256 txId,\n uint256 payloadId\n );\n event StateUpdated(uint256 payloadId);\n event StateProcessed(uint256 payloadId);\n\n /* ================ Constructor =================== */\n /**\n * @param endpoint_ is the layer zero endpoint for respective chain.\n */\n constructor(address endpoint_) NonblockingLzApp(endpoint_) {\n _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());\n }\n\n /* ================ External Functions =================== */\n /**\n * @notice receive enables processing native token transfers into the smart contract.\n * @dev socket.tech fails without a native receive function.\n */\n receive() external payable {}\n\n /**\n * PREVILAGED ADMIN ONLY FUNCTION\n *\n * @dev would update the router and destination contracts to the state handler\n * @param source_ represents the address of super router on respective chain.\n * @param destination_ represents the super destination on respective chain.\n * @dev set source or destination contract as controller\n * @dev StateHandler doesn't care about sameChainId communication (uses directDep/With for that)\n * @dev SuperRouter needs its StateHandler and SuperDestination needs its StateHandler\n * @dev Source's StateHandler IController is SuperRouter, Destination's StateHandler IController is SuperDestination\n */\n function setHandlerController(IController source_, IController destination_)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n sourceContract = source_;\n destinationContract = destination_;\n }\n\n /**\n * PREVILAGED PROCESSOR ONLY FUNCTION\n * @dev updates the state_data value to the exact amounts post bridge and swap slippage.\n */\n function updateState(uint256 payloadId, uint256[] calldata finalAmounts)\n external\n onlyRole(PROCESSOR_CONTRACTS_ROLE)\n {\n require(\n payloadId <= totalPayloads &&\n payloadProcessed[payloadId] == PayloadState.STORED,\n \"State Handler: Invalid Payload ID or Status\"\n );\n StateData memory stateData = abi.decode(\n payload[payloadId],\n (StateData)\n );\n require(\n stateData.flag == CallbackType.INIT,\n \"State Handler: Invalid Payload Flag\"\n );\n\n InitData memory data = abi.decode(stateData.params, (InitData));\n\n uint256 l1 = data.amounts.length;\n uint256 l2 = finalAmounts.length;\n require(l1 == l2, \"State Handler: Invalid Lengths\");\n\n for (uint256 i = 0; i < l1; i++) {\n uint256 newAmount = finalAmounts[i];\n uint256 maxAmount = data.amounts[i];\n require(newAmount <= maxAmount, \"State Handler: Negative Slippage\");\n\n uint256 minAmount = (maxAmount * (10000 - data.maxSlippage[i])) /\n 10000;\n require(\n newAmount >= minAmount,\n \"State Handler: Slippage Out Of Bounds\"\n );\n }\n\n data.amounts = finalAmounts;\n stateData.params = abi.encode(data);\n\n payload[payloadId] = abi.encode(stateData);\n payloadProcessed[payloadId] = PayloadState.UPDATED;\n\n emit StateUpdated(payloadId);\n }\n\n /**\n * ANYONE CAN INITATE PROCESSING\n *\n * note: update this logic to support no-state-update for withdrawals\n * @dev would execute the received state_messages from super router on source chain.\n * @param payloadId represents the payload id.\n */\n function processPayload(uint256 payloadId, bytes memory safeGasParam)\n external\n payable\n {\n require(\n payloadId <= totalPayloads,\n \"State Handler: Invalid Payload ID\"\n );\n bytes memory _payload = payload[payloadId];\n StateData memory data = abi.decode(_payload, (StateData));\n\n if (data.txType == TransactionType.WITHDRAW) {\n if (data.flag == CallbackType.INIT) {\n require(\n payloadProcessed[payloadId] == PayloadState.STORED,\n \"State Handler: Invalid Payload State\"\n );\n try\n destinationContract.stateSync{value: msg.value}(_payload)\n {} catch {\n InitData memory initData = abi.decode(\n data.params,\n (InitData)\n );\n dispatchState(\n initData.srcChainId,\n abi.encode(\n StateData(\n TransactionType.WITHDRAW,\n CallbackType.RETURN,\n abi.encode(\n ReturnData(\n false,\n initData.srcChainId,\n initData.dstChainId,\n initData.txId,\n initData.amounts\n )\n )\n )\n ),\n safeGasParam\n );\n }\n } else {\n require(\n payloadProcessed[payloadId] == PayloadState.STORED,\n \"State Handler: Invalid Payload State\"\n );\n sourceContract.stateSync{value: msg.value}(_payload);\n }\n } else {\n if (data.flag == CallbackType.INIT) {\n require(\n payloadProcessed[payloadId] == PayloadState.UPDATED,\n \"State Handler: Invalid Payload State\"\n );\n destinationContract.stateSync{value: msg.value}(_payload);\n } else {\n require(\n payloadProcessed[payloadId] == PayloadState.STORED,\n \"State Handler: Invalid Payload State\"\n );\n sourceContract.stateSync{value: msg.value}(_payload);\n }\n }\n\n payloadProcessed[payloadId] = PayloadState.PROCESSED;\n emit StateProcessed(payloadId);\n }\n\n /// @dev allows users to send state to a destination chain contract.\n /// @param dstChainId represents chain id of the destination chain.\n /// @param data represents the state info to be sent.\n /// Note: Add gas calculation to front-end\n /// Note the length of srcAmounts & vaultIds should always be equal.\n function dispatchState(\n uint16 dstChainId,\n bytes memory data,\n bytes memory adapterParam\n ) public payable onlyRole(CORE_CONTRACTS_ROLE) {\n _lzSend(\n dstChainId,\n data,\n payable(_msgSender()),\n address(0x0),\n adapterParam\n );\n }\n\n /* ================ Internal Functions =================== */\n function _nonblockingLzReceive(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) internal override {\n StateData memory data = abi.decode(_payload, (StateData));\n\n if (data.flag == CallbackType.INIT) {\n InitData memory initData = abi.decode(data.params, (InitData));\n require(\n !isValid[_srcChainId][_nonce],\n \"State Handler: Duplicate Payload\"\n );\n\n totalPayloads++;\n payload[totalPayloads] = _payload;\n isValid[_srcChainId][_nonce] = true;\n\n emit StateReceived(\n initData.srcChainId,\n initData.dstChainId,\n initData.txId,\n totalPayloads\n );\n } else {\n ReturnData memory returnData = abi.decode(\n data.params,\n (ReturnData)\n );\n require(\n !isValid[_srcChainId][_nonce],\n \"State Handler: Duplicate Payload\"\n );\n\n totalPayloads++;\n payload[totalPayloads] = _payload;\n isValid[_srcChainId][_nonce] = true;\n\n emit StateReceived(_srcChainId, 0, returnData.txId, totalPayloads);\n }\n }\n}\n"
},
"contracts/lzApp/LzApp.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.14;\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"../interface/ILayerZeroReceiver.sol\";\nimport \"../interface/ILayerZeroUserApplicationConfig.sol\";\nimport \"../interface/ILayerZeroEndpoint.sol\";\n\n/*\n * a generic LzReceiver implementation\n */\nabstract contract LzApp is\n Ownable,\n ILayerZeroReceiver,\n ILayerZeroUserApplicationConfig\n{\n ILayerZeroEndpoint public immutable lzEndpoint;\n\n mapping(uint16 => bytes) public trustedRemoteLookup;\n\n event SetTrustedRemote(uint16 _srcChainId, bytes _srcAddress);\n\n constructor(address _endpoint) {\n lzEndpoint = ILayerZeroEndpoint(_endpoint);\n }\n\n function lzReceive(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) public virtual override {\n // lzReceive must be called by the endpoint for security\n require(\n _msgSender() == address(lzEndpoint),\n \"LzApp: invalid endpoint caller\"\n );\n\n bytes memory trustedRemote = trustedRemoteLookup[_srcChainId];\n // if will still block the message pathway from (srcChainId, srcAddress). should not receive message from untrusted remote.\n require(\n _srcAddress.length == trustedRemote.length &&\n keccak256(_srcAddress) == keccak256(trustedRemote),\n \"LzApp: invalid source sending contract\"\n );\n\n _blockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);\n }\n\n // abstract function - the default behaviour of LayerZero is blocking. See: NonblockingLzApp if you dont need to enforce ordered messaging\n function _blockingLzReceive(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) internal virtual;\n\n function _lzSend(\n uint16 _dstChainId,\n bytes memory _payload,\n address payable _refundAddress,\n address _zroPaymentAddress,\n bytes memory _adapterParams\n ) internal virtual {\n bytes memory trustedRemote = trustedRemoteLookup[_dstChainId];\n require(\n trustedRemote.length != 0,\n \"LzApp: destination chain is not a trusted source\"\n );\n lzEndpoint.send{value: msg.value}(\n _dstChainId,\n trustedRemote,\n _payload,\n _refundAddress,\n _zroPaymentAddress,\n _adapterParams\n );\n }\n\n //---------------------------UserApplication config----------------------------------------\n function getConfig(\n uint16 _version,\n uint16 _chainId,\n address,\n uint256 _configType\n ) external view returns (bytes memory) {\n return\n lzEndpoint.getConfig(\n _version,\n _chainId,\n address(this),\n _configType\n );\n }\n\n // generic config for LayerZero user Application\n function setConfig(\n uint16 _version,\n uint16 _chainId,\n uint256 _configType,\n bytes calldata _config\n ) external override onlyOwner {\n lzEndpoint.setConfig(_version, _chainId, _configType, _config);\n }\n\n function setSendVersion(uint16 _version) external override onlyOwner {\n lzEndpoint.setSendVersion(_version);\n }\n\n function setReceiveVersion(uint16 _version) external override onlyOwner {\n lzEndpoint.setReceiveVersion(_version);\n }\n\n function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress)\n external\n override\n onlyOwner\n {\n lzEndpoint.forceResumeReceive(_srcChainId, _srcAddress);\n }\n\n // allow owner to set it multiple times.\n function setTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress)\n external\n onlyOwner\n {\n trustedRemoteLookup[_srcChainId] = _srcAddress;\n emit SetTrustedRemote(_srcChainId, _srcAddress);\n }\n\n //--------------------------- VIEW FUNCTION ----------------------------------------\n\n function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress)\n external\n view\n returns (bool)\n {\n bytes memory trustedSource = trustedRemoteLookup[_srcChainId];\n return keccak256(trustedSource) == keccak256(_srcAddress);\n }\n}\n"
},
"contracts/lzApp/NonblockingLzApp.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.14;\n\nimport \"./LzApp.sol\";\n\n/*\n * the default LayerZero messaging behaviour is blocking, i.e. any failed message will block the channel\n * this abstract class try-catch all fail messages and store locally for future retry. hence, non-blocking\n * NOTE: if the srcAddress is not configured properly, it will still block the message pathway from (srcChainId, srcAddress)\n */\nabstract contract NonblockingLzApp is LzApp {\n constructor(address _endpoint) LzApp(_endpoint) {}\n\n mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32)))\n public failedMessages;\n\n event MessageFailed(\n uint16 _srcChainId,\n bytes _srcAddress,\n uint64 _nonce,\n bytes _payload\n );\n\n // overriding the virtual function in LzReceiver\n function _blockingLzReceive(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) internal virtual override {\n // try-catch all errors/exceptions\n try\n this.nonblockingLzReceive(\n _srcChainId,\n _srcAddress,\n _nonce,\n _payload\n )\n {\n // do nothing\n } catch {\n // error / exception\n failedMessages[_srcChainId][_srcAddress][_nonce] = keccak256(\n _payload\n );\n emit MessageFailed(_srcChainId, _srcAddress, _nonce, _payload);\n }\n }\n\n function nonblockingLzReceive(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) public virtual {\n // only internal transaction\n require(\n _msgSender() == address(this),\n \"NonblockingLzApp: caller must be LzApp\"\n );\n _nonblockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);\n }\n\n //@notice override this function\n function _nonblockingLzReceive(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) internal virtual;\n\n function retryMessage(\n uint16 _srcChainId,\n bytes memory _srcAddress,\n uint64 _nonce,\n bytes memory _payload\n ) public payable virtual {\n // assert there is message to retry\n bytes32 payloadHash = failedMessages[_srcChainId][_srcAddress][_nonce];\n require(\n payloadHash != bytes32(0),\n \"NonblockingLzApp: no stored message\"\n );\n require(\n keccak256(_payload) == payloadHash,\n \"NonblockingLzApp: invalid payload\"\n );\n // clear the stored message\n failedMessages[_srcChainId][_srcAddress][_nonce] = bytes32(0);\n // execute the message. revert if it fails again\n _nonblockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);\n }\n}\n"
},
"contracts/socket/liquidityHandler.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8.14;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n/**\n * @title Liquidity Handler.\n * @author Zeropoint Labs.\n * @dev bridges tokens from Chain A -> Chain B\n */\nabstract contract LiquidityHandler {\n /* ================ Write Functions =================== */\n\n /**\n * @dev dispatches tokens via the socket bridge.\n *\n * @param _txData represents the api response data from socket api.\n * @param _to represents the socket registry implementation address.\n * @param _allowanceTarget represents the allowance target (zero address for native tokens)\n * @param _token represents the ERC20 token to be transferred (zero address for native tokens)\n * @param _amount represents the amount of tokens to be bridged.\n *\n * Note: refer https://docs.socket.tech/socket-api/v2/guides/socket-smart-contract-integration\n * Note: All the inputs are in array for processing multiple transactions.\n */\n function dispatchTokens(\n address _to,\n bytes memory _txData,\n address _token,\n address _allowanceTarget,\n uint256 _amount,\n address _owner,\n uint256 _nativeAmount\n ) internal virtual {\n /// @dev if allowance target is zero address represents non-native tokens.\n if (_allowanceTarget != address(0)) {\n if (_owner != address(this)) {\n require(\n IERC20(_token).allowance(_owner, address(this)) >= _amount,\n \"Bridge Error: Insufficient approvals\"\n );\n IERC20(_token).transferFrom(_owner, address(this), _amount);\n }\n IERC20(_token).approve(_allowanceTarget, _amount);\n unchecked {\n (bool success, ) = payable(_to).call{value: _nativeAmount}(\n _txData\n );\n require(success, \"Bridge Error: Failed To Execute Tx Data (1)\");\n }\n } else {\n require(msg.value >= _amount, \"Liq Handler: Insufficient Amount\");\n unchecked {\n (bool success, ) = payable(_to).call{\n value: _amount + _nativeAmount\n }(_txData);\n require(success, \"Bridge Error: Failed To Execute Tx Data (2)\");\n }\n }\n }\n}\n"
},
"contracts/SuperDestination.sol": {
"content": "/**\n * SPDX-License-Identifier: Apache-2.0\n */\npragma solidity ^0.8.14;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/access/AccessControl.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport {IERC4626} from \"./interface/IERC4626.sol\";\n\nimport {StateHandler} from \"./layerzero/stateHandler.sol\";\nimport {LiquidityHandler} from \"./socket/liquidityHandler.sol\";\n\nimport {StateData, TransactionType, CallbackType, InitData, ReturnData} from \"./types/lzTypes.sol\";\nimport {LiqRequest} from \"./types/socketTypes.sol\";\nimport {IStateHandler} from \"./interface/layerzero/IStateHandler.sol\";\n\n/**\n * @title Super Destination\n * @author Zeropoint Labs.\n *\n * Deposits/Withdraw users funds from an input valid vault.\n * extends Socket's Liquidity Handler.\n * @notice access controlled is expected to be removed due to contract sizing.\n */\ncontract SuperDestination is AccessControl, LiquidityHandler {\n using SafeERC20 for IERC20;\n\n /* ================ Constants =================== */\n bytes32 public constant ROUTER_ROLE = keccak256(\"ROUTER_ROLE\");\n\n /* ================ State Variables =================== */\n\n /**\n * @notice state variable are all declared public to avoid creating functions to expose.\n *\n * @dev stateHandler points to the state handler interface deployed in the respective chain.\n * @dev safeGasParam is used while sending layerzero message from destination to router.\n * @dev chainId represents the layerzero chain id of the specific chain.\n */\n IStateHandler public stateHandler;\n bytes public safeGasParam;\n uint16 public chainId;\n\n /**\n * @dev bridge id is mapped to a bridge address (to prevent interaction with unauthorized bridges)\n * @dev maps state data to its unique id for record keeping.\n * @dev maps a vault id to its address.\n */\n mapping(uint8 => address) public bridgeAddress;\n mapping(uint256 => StateData) public dstState;\n mapping(uint256 => IERC4626) public vault;\n mapping(uint16 => address) public shareHandler;\n\n /* ================ Events =================== */\n\n event VaultAdded(uint256 id, IERC4626 vault);\n event TokenDistributorAdded(address routerAddress, uint16 chainId);\n event Processed(\n uint16 srcChainID,\n uint16 dstChainId,\n uint256 txId,\n uint256 amounts,\n uint256 vaultId\n );\n event SafeGasParamUpdated(bytes oldParam, bytes newParam);\n event SetBridgeAddress(uint256 bridgeId, address bridgeAddress);\n\n /* ================ Constructor =================== */\n /**\n * @notice deploy stateHandler before SuperDestination\n *\n * @param chainId_ Layerzero chain id\n * @param stateHandler_ State handler address deployed\n *\n * @dev sets caller as the admin of the contract.\n */\n constructor(uint16 chainId_, IStateHandler stateHandler_) {\n chainId = chainId_;\n stateHandler = stateHandler_;\n _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());\n }\n\n /* ================ Write Functions =================== */\n receive() external payable {}\n\n /**\n * @dev handles the state when received from the source chain.\n *\n * @param _payload represents the payload id associated with the transaction.\n *\n * Note: called by external keepers when state is ready.\n */\n function stateSync(bytes memory _payload) external payable {\n require(\n msg.sender == address(stateHandler),\n \"Destination: request denied\"\n );\n StateData memory stateData = abi.decode(_payload, (StateData));\n InitData memory data = abi.decode(stateData.params, (InitData));\n\n for (uint256 i = 0; i < data.vaultIds.length; i++) {\n if (stateData.txType == TransactionType.DEPOSIT) {\n if (\n IERC20(vault[data.vaultIds[i]].asset()).balanceOf(\n address(this)\n ) >= data.amounts[i]\n ) {\n processDeposit(data);\n } else {\n revert(\"Destination: Bridge Tokens Pending\");\n }\n } else {\n processWithdrawal(data);\n }\n }\n }\n\n /**\n * PREVILAGED admin ONLY FUNCTION.\n * @dev Soon to be moved to a factory contract. (Post Wormhole Implementation)\n *\n * @param _vaultAddress address of ERC4626 interface compilant Vault\n * @param _vaultId represents the unique vault id added to a vault.\n *\n * Note The whitelisting of vault prevents depositing funds to malicious vaults.\n */\n function addVault(\n IERC4626[] memory _vaultAddress,\n uint256[] memory _vaultId\n ) external onlyRole(DEFAULT_ADMIN_ROLE) {\n require(\n _vaultAddress.length == _vaultId.length,\n \"Destination: Invalid Length\"\n );\n for (uint256 i = 0; i < _vaultAddress.length; i++) {\n require(\n _vaultAddress[i] != IERC4626(address(0)),\n \"Destination: Zero Vault Address\"\n );\n\n uint256 id = _vaultId[i];\n vault[id] = _vaultAddress[i];\n\n uint256 currentAllowance = IERC20(_vaultAddress[i].asset()).allowance(address(this), address(_vaultAddress[i]));\n if(currentAllowance == 0) {\n ///@dev pre-approve, only one type of asset is needed anyway\n IERC20(_vaultAddress[i].asset()).safeApprove(\n address(_vaultAddress[i]),\n type(uint256).max\n );\n }\n\n emit VaultAdded(id, _vaultAddress[i]);\n }\n }\n\n /**\n * PREVILAGED admin ONLY FUNCTION.\n *\n * @dev whitelists the router contract of different chains.\n * @param _positionsHandler represents the address of router contract.\n * @param _srcChainId represents the chainId of the source contract.\n */\n function setSrcTokenDistributor(\n address _positionsHandler,\n uint16 _srcChainId\n ) external onlyRole(DEFAULT_ADMIN_ROLE) {\n require(_positionsHandler != address(0), \"Destination: Zero Address\");\n require(_srcChainId != 0, \"Destination: Invalid Chain Id\");\n\n shareHandler[_srcChainId] = _positionsHandler;\n\n /// @dev because directDeposit/Withdraw is only happening from the sameChain, we can use this param\n _setupRole(ROUTER_ROLE, _positionsHandler);\n emit TokenDistributorAdded(_positionsHandler, _srcChainId);\n }\n\n /**\n * PREVILAGED admin ONLY FUNCTION.\n *\n * @dev adds the gas overrides for layerzero.\n * @param _param represents adapterParams V2.0 of layerzero\n */\n function updateSafeGasParam(bytes memory _param)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n require(_param.length != 0, \"Destination: Invalid Gas Override\");\n bytes memory oldParam = safeGasParam;\n safeGasParam = _param;\n\n emit SafeGasParamUpdated(oldParam, _param);\n }\n\n /**\n * PREVILAGED admin ONLY FUNCTION.\n * @dev allows admin to set the bridge address for an bridge id.\n * @param _bridgeId represents the bridge unqiue identifier.\n * @param _bridgeAddress represents the bridge address.\n */\n function setBridgeAddress(\n uint8[] memory _bridgeId,\n address[] memory _bridgeAddress\n ) external onlyRole(DEFAULT_ADMIN_ROLE) {\n for (uint256 i = 0; i < _bridgeId.length; i++) {\n address x = _bridgeAddress[i];\n uint8 y = _bridgeId[i];\n require(x != address(0), \"Router: Zero Bridge Address\");\n\n bridgeAddress[y] = x;\n emit SetBridgeAddress(y, x);\n }\n }\n\n /**\n * PREVILAGED router ONLY FUNCTION.\n *\n * @dev process same chain id deposits\n * @param srcSender represents address of the depositing user.\n * @param _vaultIds array of vaultIds on the chain to make a deposit\n * @param _amounts array of amounts to be deposited in each corresponding _vaultIds\n */\n function directDeposit(\n address srcSender,\n LiqRequest calldata liqData,\n uint256[] memory _vaultIds,\n uint256[] memory _amounts\n )\n external\n payable\n onlyRole(ROUTER_ROLE)\n returns (uint256[] memory dstAmounts)\n {\n uint256 loopLength = _vaultIds.length;\n uint256 expAmount = addValues(_amounts);\n\n /// note: checking balance\n address collateral = IERC4626(vault[_vaultIds[0]]).asset();\n uint256 balanceBefore = IERC20(collateral)\n .balanceOf(address(this));\n\n /// note: handle the collateral token transfers.\n if (liqData.txData.length == 0) {\n require(\n IERC20(liqData.token).allowance(srcSender, address(this)) >=\n liqData.amount,\n \"Destination: Insufficient Allowance\"\n );\n IERC20(liqData.token).safeTransferFrom(\n srcSender,\n address(this),\n liqData.amount\n );\n } else {\n dispatchTokens(\n bridgeAddress[liqData.bridgeId],\n liqData.txData,\n liqData.token,\n liqData.allowanceTarget,\n liqData.amount,\n srcSender,\n liqData.nativeAmount\n );\n }\n\n uint256 balanceAfter = IERC20(collateral)\n .balanceOf(address(this));\n require(\n balanceAfter - balanceBefore >= expAmount,\n \"Destination: Invalid State & Liq Data\"\n );\n\n dstAmounts = new uint256[](loopLength);\n\n for (uint256 i = 0; i < loopLength; i++) {\n IERC4626 v = vault[_vaultIds[i]];\n require(v.asset() == address(collateral), \"Destination: Invalid Collateral\");\n dstAmounts[i] = v.deposit(_amounts[i], address(this));\n }\n }\n\n /**\n * PREVILAGED router ONLY FUNCTION.\n *\n * @dev process withdrawal of collateral from a vault\n * @param _user represents address of the depositing user.\n * @param _vaultIds array of vaultIds on the chain to make a deposit\n * @param _amounts array of amounts to be deposited in each corresponding _vaultIds\n */\n function directWithdraw(\n address _user,\n uint256[] memory _vaultIds,\n uint256[] memory _amounts,\n LiqRequest memory _liqData\n )\n external\n payable\n onlyRole(ROUTER_ROLE)\n returns (uint256[] memory dstAmounts)\n {\n uint256 len1 = _liqData.txData.length;\n address receiver = len1 == 0 ? address(_user) : address(this);\n dstAmounts = new uint256[](_vaultIds.length);\n \n address collateral = IERC4626(vault[_vaultIds[0]]).asset();\n\n for (uint256 i = 0; i < _vaultIds.length; i++) {\n IERC4626 v = vault[_vaultIds[i]];\n require(v.asset() == address(collateral), \"Destination: Invalid Collateral\");\n dstAmounts[i] = v.redeem(_amounts[i], receiver, address(this));\n }\n\n if (len1 != 0) {\n require(\n _liqData.amount <= addValues(dstAmounts),\n \"Destination: Invalid Liq Request\"\n );\n\n dispatchTokens(\n bridgeAddress[_liqData.bridgeId],\n _liqData.txData,\n _liqData.token,\n _liqData.allowanceTarget,\n _liqData.amount,\n address(this),\n _liqData.nativeAmount\n );\n }\n }\n\n /* ================ Development Only Functions =================== */\n\n /**\n * PREVILAGED admin ONLY FUNCTION.\n * @notice should be removed after end-to-end testing.\n * @dev allows admin to withdraw lost tokens in the smart contract.\n */\n function withdrawToken(address _tokenContract, uint256 _amount)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n IERC20 tokenContract = IERC20(_tokenContract);\n\n // transfer the token from address of this contract\n // to address of the user (executing the withdrawToken() function)\n tokenContract.safeTransfer(msg.sender, _amount);\n }\n\n /**\n * PREVILAGED admin ONLY FUNCTION.\n * @dev allows admin to withdraw lost native tokens in the smart contract.\n */\n function withdrawNativeToken(uint256 _amount)\n external\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n payable(msg.sender).transfer(_amount);\n }\n\n /* ================ ERC4626 View Functions =================== */\n\n /**\n * @dev SuperDestination may need to know state of funds deployed to 3rd party Vaults\n * @dev API may need to know state of funds deployed\n */\n function previewDepositTo(uint256 vaultId, uint256 assets)\n public\n view\n returns (uint256)\n {\n return vault[vaultId].convertToShares(assets);\n }\n\n /**\n * @notice positionBalance() -> .vaultIds&destAmounts\n * @return how much of an asset + interest (accrued) is to withdraw from the Vault\n */\n function previewWithdrawFrom(uint256 vaultId, uint256 assets)\n public\n view\n returns (uint256)\n {\n return vault[vaultId].previewWithdraw(assets);\n }\n\n /**\n * @notice Returns data for single deposit into this vault from SuperRouter (maps user to its balance accross vaults)\n */\n function positionBalance(uint256 positionId)\n public\n view\n returns (uint256[] memory vaultIds, uint256[] memory destAmounts)\n {\n InitData memory initData = abi.decode(\n dstState[positionId].params,\n (InitData)\n );\n\n return (\n initData.vaultIds,\n initData.amounts /// @dev amount of tokens bridged from source (input to vault.deposit())\n );\n }\n\n /* ================ Internal Functions =================== */\n\n /**\n * @dev process valid deposit data and deposit collateral.\n * @dev What if vault.asset() isn't the same as bridged token?\n * @param data represents state data from router of another chain\n */\n function processDeposit(InitData memory data) internal {\n /// @dev Ordering dependency vaultIds need to match dstAmounts (shadow matched to user)\n uint256[] memory dstAmounts = new uint256[](data.vaultIds.length);\n for (uint256 i = 0; i < data.vaultIds.length; i++) {\n IERC4626 v = vault[data.vaultIds[i]];\n\n dstAmounts[i] = v.deposit(data.amounts[i], address(this));\n /// @notice dstAmounts is equal to POSITIONS returned by v(ault)'s deposit while data.amounts is equal to ASSETS (tokens) bridged\n emit Processed(\n data.srcChainId,\n data.dstChainId,\n data.txId,\n data.amounts[i],\n data.vaultIds[i]\n );\n }\n /// Note Step-4: Send Data to Source to issue superform positions.\n stateHandler.dispatchState{value: msg.value}(\n data.srcChainId,\n abi.encode(\n StateData(\n TransactionType.DEPOSIT,\n CallbackType.RETURN,\n abi.encode(ReturnData(true, data.srcChainId, chainId, data.txId, dstAmounts))\n )\n ),\n safeGasParam\n );\n }\n\n /**\n * @dev process valid withdrawal data and remove collateral.\n * @param data represents state data from router of another chain\n */\n function processWithdrawal(InitData memory data) internal {\n uint256[] memory dstAmounts = new uint256[](data.vaultIds.length);\n LiqRequest memory _liqData = abi.decode(data.liqData, (LiqRequest));\n \n for (uint256 i = 0; i < data.vaultIds.length; i++) {\n if (_liqData.txData.length != 0) {\n IERC4626 v = vault[data.vaultIds[i]];\n /// Note Redeem Vault positions (we operate only on positions, not assets)\n dstAmounts[i] = v.redeem(\n data.amounts[i],\n address(this),\n address(this)\n );\n\n uint256 balanceBefore = IERC20(v.asset()).balanceOf(\n address(this)\n );\n /// Note Send Tokens to Source Chain\n /// FEAT Note: We could also allow to pass additional chainId arg here\n /// FEAT Note: Requires multiple ILayerZeroEndpoints to be mapped\n dispatchTokens(\n bridgeAddress[_liqData.bridgeId],\n _liqData.txData,\n _liqData.token,\n _liqData.allowanceTarget,\n dstAmounts[i],\n address(this),\n _liqData.nativeAmount\n );\n uint256 balanceAfter = IERC20(v.asset()).balanceOf(\n address(this)\n );\n\n /// note: balance validation to prevent draining contract.\n require(\n balanceAfter >= balanceBefore - dstAmounts[i],\n \"Destination: Invalid Liq Request\"\n );\n } else {\n IERC4626 v = vault[data.vaultIds[i]];\n /// Note Redeem Vault positions (we operate only on positions, not assets)\n dstAmounts[i] = v.redeem(\n data.amounts[i],\n address(data.user),\n address(this)\n );\n }\n\n emit Processed(\n data.srcChainId,\n data.dstChainId,\n data.txId,\n dstAmounts[i],\n data.vaultIds[i]\n );\n }\n }\n\n function addValues(uint256[] memory amounts)\n internal\n pure\n returns (uint256)\n {\n uint256 total;\n for (uint256 i = 0; i < amounts.length; i++) {\n total += amounts[i];\n }\n return total;\n }\n}\n"
},
"contracts/types/lzTypes.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\n\npragma solidity ^0.8.14;\n\n/// @notice We should optimize those types more\nenum TransactionType {\n DEPOSIT,\n WITHDRAW\n}\n\nenum CallbackType {\n INIT,\n RETURN\n}\n\nenum PayloadState {\n STORED,\n UPDATED,\n PROCESSED\n}\n\nstruct StateReq {\n uint16 dstChainId;\n uint256[] amounts;\n uint256[] vaultIds;\n uint256[] maxSlippage;\n bytes adapterParam;\n uint256 msgValue;\n}\n\n/// Created during deposit by contract from Liq+StateReqs\n/// @dev using this for communication between src & dst transfers\nstruct StateData {\n TransactionType txType;\n CallbackType flag;\n bytes params;\n}\n\nstruct InitData {\n uint16 srcChainId;\n uint16 dstChainId;\n address user;\n uint256[] vaultIds;\n uint256[] amounts;\n uint256[] maxSlippage;\n uint256 txId;\n bytes liqData;\n}\n\nstruct ReturnData {\n bool status;\n uint16 srcChainId;\n uint16 dstChainId;\n uint256 txId;\n uint256[] amounts;\n}\n"
},
"contracts/types/socketTypes.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.8.14;\n\nstruct LiqRequest {\n uint8 bridgeId;\n bytes txData;\n address token;\n address allowanceTarget; /// @dev should check with socket.\n uint256 amount;\n uint256 nativeAmount;\n}\n\nstruct BridgeRequest {\n uint256 id;\n uint256 optionalNativeAmount;\n address inputToken;\n bytes data;\n}\n\nstruct MiddlewareRequest {\n uint256 id;\n uint256 optionalNativeAmount;\n address inputToken;\n bytes data;\n}\n\nstruct UserRequest {\n address receiverAddress;\n uint256 toChainId;\n uint256 amount;\n MiddlewareRequest middlewareRequest;\n BridgeRequest bridgeRequest;\n}\n\nstruct LiqStruct {\n address inputToken;\n address bridge;\n UserRequest socketInfo;\n}\n\n//[\"0x092A9faFA20bdfa4b2EE721FE66Af64d94BB9FAF\",\"1\",\"3000000\",[\"0\",\"0\",\"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174\",\"0x\"],[\"7\",\"0\",\"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174\",\"0x00000000000000000000000076b22b8c1079a44f1211d867d68b1eda76a635a7000000000000000000000000000000000000000000000000000000000003db5400000000000000000000000000000000000000000000000000000000002a3a8f0000000000000000000000000000000000000000000000000000017fc2482f6800000000000000000000000000000000000000000000000000000000002a3a8f0000000000000000000000000000000000000000000000000000017fc2482f680000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174\"]]\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}