{ "language": "Solidity", "sources": { "@yield-protocol/vault-v2/contracts/other/tether/TetherJoin.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\n// Audit as of 2023-02-03, commit 99464fe, https://hackmd.io/AY6oeTvVSCyLdCh1MEG7yQ\npragma solidity >=0.8.13;\n\nimport \"./IUSDT.sol\";\nimport \"../../FlashJoin.sol\";\nimport \"@yield-protocol/utils-v2/contracts/token/IERC20.sol\";\nimport \"@yield-protocol/utils-v2/contracts/access/AccessControl.sol\";\nimport \"@yield-protocol/utils-v2/contracts/token/TransferHelper.sol\";\nimport \"@yield-protocol/utils-v2/contracts/math/WDiv.sol\";\n\n/// @dev Tether includes code in its contract to apply a fee to transfers. In developing this contract,\n/// we took a selfish approach. The TetherJoin will only care about the amount that USDT that it receives,\n/// and about the amount of USDT that it sends. If fees are enabled, the TetherJoin will expect to have \n/// the amount specified in the join function arguments, and if pulling from the user, it will pull the\n/// amount that it expects to receive, plus the fee. Likewise, if sending to the user, it will send the\n/// amount specified as an argument, and it is responsibility of the receiver to deal with any shortage\n/// on receival due to fees. This aproach extends to flash loans.\ncontract TetherJoin is FlashJoin {\n using TransferHelper for IERC20;\n using WDiv for uint256;\n\n constructor(address asset_) FlashJoin(asset_) {}\n\n /// @dev Calculate the minimum of two uint256s.\n function _min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /// @dev Calculate the amount of `asset` that needs to be sent to receive `amount` of USDT.\n function _reverseFee(uint256 amount) internal view returns (uint256) {\n return _min(amount.wdiv(1e18 - IUSDT(asset).basisPointsRate() * 1e14), amount + IUSDT(asset).maximumFee());\n }\n\n /// @dev Take `asset` from `user` using `transferFrom`, minus any unaccounted `asset` in this contract, so that `amount` of USDT is received.\n function _join(address user, uint128 amount) internal override returns (uint128) {\n IERC20 token = IERC20(asset);\n uint256 _storedBalance = storedBalance;\n uint256 available = token.balanceOf(address(this)) - _storedBalance; // Fine to panic if this underflows\n unchecked {\n if (available == 0) {\n token.safeTransferFrom(user, address(this), _reverseFee(amount));\n amount = uint128(token.balanceOf(address(this)) - _storedBalance);\n } else if (available < amount) {\n token.safeTransferFrom(user, address(this), _reverseFee(amount - available));\n amount = uint128(token.balanceOf(address(this)) - _storedBalance);\n }\n storedBalance = _storedBalance + amount; // Unlikely that a uint128 added to the stored balance will make it overflow\n }\n return amount;\n }\n}" }, "@yield-protocol/vault-v2/contracts/FlashJoin.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.13;\n\nimport \"erc3156/contracts/interfaces/IERC3156FlashBorrower.sol\";\nimport \"erc3156/contracts/interfaces/IERC3156FlashLender.sol\";\nimport \"@yield-protocol/utils-v2/contracts/token/TransferHelper.sol\";\nimport \"@yield-protocol/utils-v2/contracts/math/WMul.sol\";\nimport \"@yield-protocol/utils-v2/contracts/cast/CastU256U128.sol\";\nimport \"./Join.sol\";\n\ncontract FlashJoin is Join, IERC3156FlashLender {\n using WMul for uint256;\n using CastU256U128 for uint256;\n event FlashFeeFactorSet(uint256 indexed fee);\n\n bytes32 internal constant FLASH_LOAN_RETURN = keccak256(\"ERC3156FlashBorrower.onFlashLoan\");\n uint256 public constant FLASH_LOANS_DISABLED = type(uint256).max;\n\n uint256 public flashFeeFactor = FLASH_LOANS_DISABLED; // Fee on flash loans, as a percentage in fixed point with 18 decimals. Flash loans disabled by default.\n\n constructor(address asset_) Join(asset_) {}\n\n /// @dev Set the flash loan fee factor\n function setFlashFeeFactor(uint256 flashFeeFactor_) external auth {\n flashFeeFactor = flashFeeFactor_;\n emit FlashFeeFactorSet(flashFeeFactor_);\n }\n\n /**\n * @dev From ERC-3156. The amount of currency available to be lended.\n * @param token The loan currency. It must be a FYDai contract.\n * @return The amount of `token` that can be borrowed.\n */\n function maxFlashLoan(address token) external view override returns (uint256) {\n return token == asset ? storedBalance : 0;\n }\n\n /**\n * @dev From ERC-3156. The fee to be charged for a given loan.\n * @param token The loan currency. It must be the asset.\n * @param amount The amount of tokens lent.\n * @return The amount of `token` to be charged for the loan, on top of the returned principal.\n */\n function flashFee(address token, uint256 amount) external view override returns (uint256) {\n require(token == asset, \"Unsupported currency\");\n return _flashFee(amount);\n }\n\n /**\n * @dev The fee to be charged for a given loan.\n * @param amount The amount of tokens lent.\n * @return The amount of `token` to be charged for the loan, on top of the returned principal.\n */\n function _flashFee(uint256 amount) internal view returns (uint256) {\n return amount.wmul(flashFeeFactor);\n }\n\n /**\n * @dev From ERC-3156. Loan `amount` `asset` to `receiver`, which needs to return them plus fee to this contract within the same transaction.\n * If the principal + fee are transferred to this contract, they won't be pulled from the receiver.\n * @param receiver The contract receiving the tokens, needs to implement the `onFlashLoan(address user, uint256 amount, uint256 fee, bytes calldata)` interface.\n * @param token The loan currency. Must be a fyDai contract.\n * @param amount The amount of tokens lent.\n * @param data A data parameter to be passed on to the `receiver` for any custom use.\n */\n function flashLoan(\n IERC3156FlashBorrower receiver,\n address token,\n uint256 amount,\n bytes memory data\n ) external override returns (bool) {\n require(token == asset, \"Unsupported currency\");\n uint128 _amount = amount.u128();\n uint128 _fee = _flashFee(amount).u128();\n _exit(address(receiver), _amount);\n\n require(\n receiver.onFlashLoan(msg.sender, token, _amount, _fee, data) == FLASH_LOAN_RETURN,\n \"Non-compliant borrower\"\n );\n\n _join(address(receiver), _amount + _fee);\n return true;\n }\n}\n" }, "@yield-protocol/utils-v2/contracts/access/AccessControl.sol": { "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms.\n *\n * Roles are referred to by their `bytes4` identifier. These are expected to be the \n * signatures for all the functions in the contract. Special roles should be exposed\n * in the external API and be unique:\n *\n * ```\n * bytes4 public constant ROOT = 0x00000000;\n * ```\n *\n * Roles represent restricted access to a function call. For that purpose, use {auth}:\n *\n * ```\n * function foo() public auth {\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 `ROOT`, 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 `ROOT` 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 */\ncontract AccessControl {\n struct RoleData {\n mapping (address => bool) members;\n bytes4 adminRole;\n }\n\n mapping (bytes4 => RoleData) private _roles;\n\n bytes4 public constant ROOT = 0x00000000;\n bytes4 public constant ROOT4146650865 = 0x00000000; // Collision protection for ROOT, test with ROOT12007226833()\n bytes4 public constant LOCK = 0xFFFFFFFF; // Used to disable further permissioning of a function\n bytes4 public constant LOCK8605463013 = 0xFFFFFFFF; // Collision protection for LOCK, test with LOCK10462387368()\n\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role\n *\n * `ROOT` 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(bytes4 indexed role, bytes4 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call.\n */\n event RoleGranted(bytes4 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(bytes4 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Give msg.sender the ROOT role and create a LOCK role with itself as the admin role and no members. \n * Calling setRoleAdmin(msg.sig, LOCK) means no one can grant that msg.sig role anymore.\n */\n constructor () {\n _grantRole(ROOT, msg.sender); // Grant ROOT to msg.sender\n _setRoleAdmin(LOCK, LOCK); // Create the LOCK role by setting itself as its own admin, creating an independent role tree\n }\n\n /**\n * @dev Each function in the contract has its own role, identified by their msg.sig signature.\n * ROOT can give and remove access to each function, lock any further access being granted to\n * a specific action, or even create other roles to delegate admin control over a function.\n */\n modifier auth() {\n require (_hasRole(msg.sig, msg.sender), \"Access denied\");\n _;\n }\n\n /**\n * @dev Allow only if the caller has been granted the admin role of `role`.\n */\n modifier admin(bytes4 role) {\n require (_hasRole(_getRoleAdmin(role), msg.sender), \"Only admin\");\n _;\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes4 role, address account) external view returns (bool) {\n return _hasRole(role, account);\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(bytes4 role) external view returns (bytes4) {\n return _getRoleAdmin(role);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n\n * If ``role``'s admin role is not `adminRole` emits a {RoleAdminChanged} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function setRoleAdmin(bytes4 role, bytes4 adminRole) external virtual admin(role) {\n _setRoleAdmin(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 function grantRole(bytes4 role, address account) external virtual admin(role) {\n _grantRole(role, account);\n }\n\n \n /**\n * @dev Grants all of `role` in `roles` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - For each `role` in `roles`, the caller must have ``role``'s admin role.\n */\n function grantRoles(bytes4[] memory roles, address account) external virtual {\n for (uint256 i = 0; i < roles.length; i++) {\n require (_hasRole(_getRoleAdmin(roles[i]), msg.sender), \"Only admin\");\n _grantRole(roles[i], account);\n }\n }\n\n /**\n * @dev Sets LOCK as ``role``'s admin role. LOCK has no members, so this disables admin management of ``role``.\n\n * Emits a {RoleAdminChanged} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function lockRole(bytes4 role) external virtual admin(role) {\n _setRoleAdmin(role, LOCK);\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 function revokeRole(bytes4 role, address account) external virtual admin(role) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes all of `role` in `roles` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - For each `role` in `roles`, the caller must have ``role``'s admin role.\n */\n function revokeRoles(bytes4[] memory roles, address account) external virtual {\n for (uint256 i = 0; i < roles.length; i++) {\n require (_hasRole(_getRoleAdmin(roles[i]), msg.sender), \"Only admin\");\n _revokeRole(roles[i], account);\n }\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 granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes4 role, address account) external virtual {\n require(account == msg.sender, \"Renounce only for self\");\n\n _revokeRole(role, account);\n }\n\n function _hasRole(bytes4 role, address account) internal view returns (bool) {\n return _roles[role].members[account];\n }\n\n function _getRoleAdmin(bytes4 role) internal view returns (bytes4) {\n return _roles[role].adminRole;\n }\n\n function _setRoleAdmin(bytes4 role, bytes4 adminRole) internal virtual {\n if (_getRoleAdmin(role) != adminRole) {\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, adminRole);\n }\n }\n\n function _grantRole(bytes4 role, address account) internal {\n if (!_hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, msg.sender);\n }\n }\n\n function _revokeRole(bytes4 role, address account) internal {\n if (_hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, msg.sender);\n }\n }\n}" }, "@yield-protocol/utils-v2/contracts/token/TransferHelper.sol": { "content": "// SPDX-License-Identifier: MIT\n// Taken from https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/TransferHelper.sol\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"../utils/RevertMsgExtractor.sol\";\n\n// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\n// USDT is a well known token that returns nothing for its transfer, transferFrom, and approve functions\n// and part of the reason this library exists\nlibrary TransferHelper {\n /// @notice Transfers tokens from msg.sender to a recipient\n /// @dev Errors with the underlying revert message if transfer fails\n /// @param token The contract address of the token which will be transferred\n /// @param to The recipient of the transfer\n /// @param value The value of the transfer\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));\n if (!(success && _returnTrueOrNothing(data))) revert(RevertMsgExtractor.getRevertMsg(data));\n }\n\n /// @notice Approves a spender to transfer tokens from msg.sender\n /// @dev Errors with the underlying revert message if transfer fails\n /// @param token The contract address of the token which will be approved\n /// @param spender The approved spender\n /// @param value The value of the allowance\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(IERC20.approve.selector, spender, value));\n if (!(success && _returnTrueOrNothing(data))) revert(RevertMsgExtractor.getRevertMsg(data));\n }\n\n /// @notice Transfers tokens from the targeted address to the given destination\n /// @dev Errors with the underlying revert message if transfer fails\n /// @param token The contract address of the token to be transferred\n /// @param from The originating address from which the tokens will be transferred\n /// @param to The destination address of the transfer\n /// @param value The amount to be transferred\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n (bool success, bytes memory data) = address(token).call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));\n if (!(success && _returnTrueOrNothing(data))) revert(RevertMsgExtractor.getRevertMsg(data));\n }\n\n /// @notice Transfers ETH to the recipient address\n /// @dev Errors with the underlying revert message if transfer fails\n /// @param to The destination of the transfer\n /// @param value The value to be transferred\n function safeTransferETH(address payable to, uint256 value) internal {\n (bool success, bytes memory data) = to.call{value: value}(new bytes(0));\n if (!success) revert(RevertMsgExtractor.getRevertMsg(data));\n }\n\n function _returnTrueOrNothing(bytes memory data) internal pure returns(bool) {\n return (data.length == 0 || abi.decode(data, (bool)));\n }\n}\n" }, "@yield-protocol/utils-v2/contracts/token/IERC20.sol": { "content": "// SPDX-License-Identifier: MIT\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 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 `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, 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 `sender` to `recipient` 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(address sender, address recipient, uint256 amount) external returns (bool);\n\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}" }, "@yield-protocol/utils-v2/contracts/math/WDiv.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\n\nlibrary WDiv { // Fixed point arithmetic in 18 decimal units\n // Taken from https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol\n /// @dev Divide an amount by a fixed point factor with 18 decimals\n function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {\n z = (x * 1e18) / y;\n }\n}" }, "@yield-protocol/vault-v2/contracts/other/tether/IUSDT.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n */\ninterface IUSDT {\n function name() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n function totalSupply() external returns (uint);\n\n function balances(address) external returns (uint);\n\n function balanceOf(address _owner) external returns (uint balance);\n\n function allowance(address owner, address spender) external returns (uint);\n\n function allowed(address, address) external returns (uint);\n\n function approve(address spender, uint value) external;\n\n function basisPointsRate() external view returns (uint256);\n\n function maximumFee() external view returns (uint256);\n\n function transfer(address to, uint value) external;\n\n function transferFrom(address from, address to, uint value) external;\n\n function setParams(uint newBasisPoints, uint newMaxFee) external;\n}" }, "erc3156/contracts/interfaces/IERC3156FlashBorrower.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.6.0 <0.9.0;\n\n\ninterface IERC3156FlashBorrower {\n\n /**\n * @dev Receive a flash loan.\n * @param initiator The initiator of the loan.\n * @param token The loan currency.\n * @param amount The amount of tokens lent.\n * @param fee The additional amount of tokens to repay.\n * @param data Arbitrary data structure, intended to contain user-defined parameters.\n * @return The keccak256 hash of \"ERC3156FlashBorrower.onFlashLoan\"\n */\n function onFlashLoan(\n address initiator,\n address token,\n uint256 amount,\n uint256 fee,\n bytes calldata data\n ) external returns (bytes32);\n}\n" }, "erc3156/contracts/interfaces/IERC3156FlashLender.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.6.0 <0.9.0;\nimport \"./IERC3156FlashBorrower.sol\";\n\n\ninterface IERC3156FlashLender {\n\n /**\n * @dev The amount of currency available to be lended.\n * @param token The loan currency.\n * @return The amount of `token` that can be borrowed.\n */\n function maxFlashLoan(\n address token\n ) external view returns (uint256);\n\n /**\n * @dev The fee to be charged for a given loan.\n * @param token The loan currency.\n * @param amount The amount of tokens lent.\n * @return The amount of `token` to be charged for the loan, on top of the returned principal.\n */\n function flashFee(\n address token,\n uint256 amount\n ) external view returns (uint256);\n\n /**\n * @dev Initiate a flash loan.\n * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.\n * @param token The loan currency.\n * @param amount The amount of tokens lent.\n * @param data Arbitrary data structure, intended to contain user-defined parameters.\n */\n function flashLoan(\n IERC3156FlashBorrower receiver,\n address token,\n uint256 amount,\n bytes calldata data\n ) external returns (bool);\n}" }, "@yield-protocol/utils-v2/contracts/math/WMul.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\n\nlibrary WMul {\n // Taken from https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol\n /// @dev Multiply an amount by a fixed point factor with 18 decimals, rounds down.\n function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n z = x * y;\n unchecked { z /= 1e18; }\n }\n}" }, "@yield-protocol/utils-v2/contracts/cast/CastU256U128.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\n\nlibrary CastU256U128 {\n /// @dev Safely cast an uint256 to an uint128\n function u128(uint256 x) internal pure returns (uint128 y) {\n require (x <= type(uint128).max, \"Cast overflow\");\n y = uint128(x);\n }\n}" }, "@yield-protocol/vault-v2/contracts/Join.sol": { "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.13;\n\nimport \"erc3156/contracts/interfaces/IERC3156FlashBorrower.sol\";\nimport \"erc3156/contracts/interfaces/IERC3156FlashLender.sol\";\nimport \"./interfaces/IJoin.sol\";\nimport \"./interfaces/IJoinFactory.sol\";\nimport \"@yield-protocol/utils-v2/contracts/token/IERC20.sol\";\nimport \"@yield-protocol/utils-v2/contracts/access/AccessControl.sol\";\nimport \"@yield-protocol/utils-v2/contracts/token/TransferHelper.sol\";\nimport \"@yield-protocol/utils-v2/contracts/math/WMul.sol\";\nimport \"@yield-protocol/utils-v2/contracts/cast/CastU256U128.sol\";\n\ncontract Join is IJoin, AccessControl {\n using TransferHelper for IERC20;\n using WMul for uint256;\n using CastU256U128 for uint256;\n\n address public immutable override asset;\n uint256 public override storedBalance;\n\n constructor(address asset_) {\n asset = asset_;\n }\n\n /// @dev Take `amount` `asset` from `user` using `transferFrom`, minus any unaccounted `asset` in this contract.\n function join(address user, uint128 amount) external virtual override auth returns (uint128) {\n return _join(user, amount);\n }\n\n /// @dev Take `amount` `asset` from `user` using `transferFrom`, minus any unaccounted `asset` in this contract.\n function _join(address user, uint128 amount) internal virtual returns (uint128) {\n IERC20 token = IERC20(asset);\n uint256 _storedBalance = storedBalance;\n uint256 available = token.balanceOf(address(this)) - _storedBalance; // Fine to panic if this underflows\n unchecked {\n storedBalance = _storedBalance + amount; // Unlikely that a uint128 added to the stored balance will make it overflow\n if (available < amount) token.safeTransferFrom(user, address(this), amount - available);\n }\n return amount;\n }\n\n /// @dev Transfer `amount` `asset` to `user`\n function exit(address user, uint128 amount) external virtual override auth returns (uint128) {\n return _exit(user, amount);\n }\n\n /// @dev Transfer `amount` `asset` to `user`\n function _exit(address user, uint128 amount) internal virtual returns (uint128) {\n IERC20 token = IERC20(asset);\n storedBalance -= amount;\n token.safeTransfer(user, amount);\n return amount;\n }\n\n /// @dev Retrieve any tokens other than the `asset`. Useful for airdropped tokens.\n function retrieve(IERC20 token, address to) external virtual override auth {\n require(address(token) != address(asset), \"Use exit for asset\");\n token.safeTransfer(to, token.balanceOf(address(this)));\n }\n}\n" }, "@yield-protocol/utils-v2/contracts/utils/RevertMsgExtractor.sol": { "content": "// SPDX-License-Identifier: MIT\n// Taken from https://github.com/sushiswap/BoringSolidity/blob/441e51c0544cf2451e6116fe00515e71d7c42e2c/contracts/BoringBatchable.sol\n\npragma solidity >=0.6.0;\n\n\nlibrary RevertMsgExtractor {\n /// @dev Helper function to extract a useful revert message from a failed call.\n /// If the returned data is malformed or not correctly abi encoded then this call can fail itself.\n function getRevertMsg(bytes memory returnData)\n internal pure\n returns (string memory)\n {\n // If the _res length is less than 68, then the transaction failed silently (without a revert message)\n if (returnData.length < 68) return \"Transaction reverted silently\";\n\n assembly {\n // Slice the sighash.\n returnData := add(returnData, 0x04)\n }\n return abi.decode(returnData, (string)); // All that remains is the revert string\n }\n}" }, "@yield-protocol/vault-v2/contracts/interfaces/IJoinFactory.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IJoinFactory {\n event JoinCreated(address indexed asset, address pool);\n\n function createJoin(address asset) external returns (address);\n}\n" }, "@yield-protocol/vault-v2/contracts/interfaces/IJoin.sol": { "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\nimport \"@yield-protocol/utils-v2/contracts/token/IERC20.sol\";\n\ninterface IJoin {\n /// @dev asset managed by this contract\n function asset() external view returns (address);\n\n /// @dev amount of assets held by this contract\n function storedBalance() external view returns (uint256);\n\n /// @dev Add tokens to this contract.\n function join(address user, uint128 wad) external returns (uint128);\n\n /// @dev Remove tokens to this contract.\n function exit(address user, uint128 wad) external returns (uint128);\n\n /// @dev Retrieve any tokens other than the `asset`. Useful for airdropped tokens.\n function retrieve(IERC20 token, address to) external;\n}\n" } }, "settings": { "optimizer": { "enabled": true, "runs": 100 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} } }