diff --git a/basic/21-aave-uni-loan/README-CN.md b/basic/21-aave-uni-loan/README-CN.md index cb8c67d04..ba5883c4e 100644 --- a/basic/21-aave-uni-loan/README-CN.md +++ b/basic/21-aave-uni-loan/README-CN.md @@ -2,15 +2,15 @@ 基于 Hardhat 测试框架,通过样例合约的演示,了解如何在 AAVE 上进行借贷,在 Uniswap 上进行兑换,并通过 AAVE 和 Uniswap 进行做多和做空。 ## 合约交互 -### AAVE 合约 -Lending Pool Addresses Provider 是 AAVE 交互的入口,通过它可以和 AAVE 进行交互。 -同时因为 AAVE 会更新 LendingPool / ProtocolDataProvider / PriceOracle 合约的地址以便修复发现的 Bug ,而通过 Lending Pool Addresses Provider 可以获取这三个合约的最新的地址,而不必修改代码: -- LendingPool: 负责 存入/借贷 功能 -- ProtocolDataProvider: 提供 用户/池子 中相关的借贷信息 +### AAVE V3 合约 +Pool Addresses Provider 是 AAVE V3 交互的入口,通过它可以和 AAVE V3 进行交互。 +同时因为 AAVE 会更新 Pool / PoolDataProvider / PriceOracle 合约的地址以便修复发现的 Bug ,而通过 Lending Pool Addresses Provider 可以获取这三个合约的最新的地址,而不必修改代码: +- Pool 负责 存入/借贷 功能 +- PoolDataProvider: 提供 用户/池子 中相关的借贷信息 - PriceOracle: 价格预言机 -### uniswapv2 合约 -UniswapV2 的交互入口为 Router02,通过它可以完成和 UniswapV2 的所有交互 +### uniswap V3 合约 +Uniswap V3 的交互入口为 SwapRouter,通过它可以完成和 Uniswap V3 的所有交互 ## 功能要点 @@ -30,12 +30,12 @@ AaveApe 合约主要有四个功能,分别是 ### 做空 从 AAVE 借出资产 B 后,Ape 进行如下操作做空 B。 -- 通过 Uniswap V2, 把借出的资产 B 全部兑换为 资产 A +- 通过 Uniswap V3, 把借出的资产 B 全部兑换为 资产 A - 把兑换出的资产 A 继续存入 AAVE ### 赎回 -通过 AAVE V2 的闪电贷偿还从 AAVE 借出的资产. +通过 AAVE V3 的闪电贷偿还从 AAVE 借出的资产. 详细逻辑, 参考 [aave-ape](https://azfuller20.medium.com/aave-ape-with-%EF%B8%8F-scaffold-eth-c687874c079e ) ## 操作步骤 @@ -59,7 +59,7 @@ hardhat run scripts/deploy.js --network matic - 验证合约 ```shell // contract verify -npx hardhat verify --network matic 0xddb2d92d5a0EDcb03c013322c7BAe92734AA4597 "0xd05e3E715d945B59290df0ae8eF85c1BdB684744" "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506" +npx hardhat verify --network matic 0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb" "0xE592427A0AEce92De3Edee1F18E0157C05861564" ``` - 进行借贷 @@ -81,10 +81,12 @@ hardhat run scripts/query.js --network matic - aave-ape 借贷 : https://azfuller20.medium.com/lend-with-aave-v2-20bacceedade - hardhat fork 主网 : https://hardhat.org/hardhat-network/guides/mainnet-forking.html - quick swap: https://github.com/QuickSwap -- uniswapper 接口调用 : https://azfuller20.medium.com/swap-with-uniswap-wip-f15923349b3d +- uniswap v3 接口调用 : https://solidity-by-example.org/defi/uniswap-v3-swap/ - ds-math 安全数学库: https://medium.com/dapphub/introducing-ds-math-an-innovative-safe-math-library-d58bc88313da -- aave 官方文档: https://docs.aave.com/developers/the-core-protocol/protocol-overview#main-contracts -- aave polygon graph: https://thegraph.com/legacy-explorer/subgraph/aave/aave-v2-matic +- aave 官方文档: https://docs.aave.com/developers/getting-started/contracts-overview +- aave polygon graph: https://thegraph.com/hosted-service/subgraph/aave/protocol-v3-polygon - scaffold 挑战: https://medium.com/@austin_48503/%EF%B8%8Fethereum-dev-speed-run-bd72bcba6a4c - scaffold-eth 任务: https://speedrunethereum.com/ -- aave 闪电贷: https://github.com/johngrantuk/aaveFlashLoan \ No newline at end of file +- aave 闪电贷: https://github.com/johngrantuk/aaveFlashLoan +- aave 合约地址: https://docs.aave.com/developers/deployed-contracts/v3-mainnet +- uniswap 合约地址: https://docs.uniswap.org/contracts/v3/reference/deployments \ No newline at end of file diff --git a/basic/21-aave-uni-loan/README.md b/basic/21-aave-uni-loan/README.md index fa18e4a25..4cc1692b5 100644 --- a/basic/21-aave-uni-loan/README.md +++ b/basic/21-aave-uni-loan/README.md @@ -6,33 +6,33 @@ a simple contract that lets you create and unwind leveraged positions on Aave The Aave Ape combines two Defi protocols, Aave (for lending) and Uniswap (for swapping). **AAVE** -Interacting with Aave starts with the Lending Pool Addresses Provider — this is the source of truth for Aave V2’s latest contract addresses: -- LendingPool: where the depositing & borrowing happens 🏦 -- ProtocolDataProvider: provides easy-to-access information about reserves & users 📊 +Interacting with Aave starts with the Pool Addresses Provider — this is the source of truth for Aave V3’s latest contract addresses: +- Pool: where the depositing & borrowing happens 🏦 +- PoolDataProvider: provides easy-to-access information about reserves & users 📊 - PriceOracle: provides secure price feeds 💱 -**uniswapv2** -Interacting with Uniswap V2 all happens through the Uniswap Router02. +**uniswap V3** +Interacting with Uniswap V3 all happens through the Uniswap SwapRouter. **key point** -We can create a constructor that lets us set the two addresses we need (the AddressesProvider and the Router). Once we then have the addresses and the interfaces, we can create helper functions to instantiate contracts so that we can interact with them, and fetch Aave reserve data from the ProtocolDataProvider. +We can create a constructor that lets us set the two addresses we need (the PoolAddressesProvider and the Router). Once we then have the addresses and the interfaces, we can create helper functions to instantiate contracts so that we can interact with them, and fetch Aave reserve data from the PoolDataProvider. Assuming you have an apeAsset you want to go long and a borrowAsset you want to go short this ape function lets a user carry out the following steps in one transaction - Calculate the maximum amount the user is able to borrow in the borrowAsset, based on their collateral (this relies on getAvailableBorrowInAsset) -- Borrow that amount of borrowAsset from Aave V2 on behalf of the user +- Borrow that amount of borrowAsset from Aave V3 on behalf of the user This requires the user to have delegated credit to the Aave Ape contract, so that it can borrow from Aave on the user’s behalf — see more about Credit Delegation - Approve the borrowAsset for trading on Uniswap -- Swap the borrowAsset for the maximum available amount of the apeAsset via Uniswap V2 +- Swap the borrowAsset for the maximum available amount of the apeAsset via Uniswap V3 - Deposit the apeAsset back into Aave on behalf of the user **unwindApe** -Borrow the amount needed to repay their borrowAsset debt via a flashloan from Aave V2. +Borrow the amount needed to repay their borrowAsset debt via a flashloan from Aave V3. For more detail , please visit [aave-ape](https://azfuller20.medium.com/aave-ape-with-%EF%B8%8F-scaffold-eth-c687874c079e ) ## operating steps @@ -41,7 +41,7 @@ For more detail , please visit [aave-ape](https://azfuller20.medium.com/aave-ape hardhat run --network matic scripts/deploy.js // contract verify -npx hardhat verify --network matic 0xddb2d92d5a0EDcb03c013322c7BAe92734AA4597 "0xd05e3E715d945B59290df0ae8eF85c1BdB684744" "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506" +npx hardhat verify --network matic 0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb" "0xE592427A0AEce92De3Edee1F18E0157C05861564" // open maxposition on aave hardhat run --network matic scripts/loan.js @@ -55,14 +55,16 @@ hardhat run --network matic scripts/loan.js - aave-ape medium : https://azfuller20.medium.com/lend-with-aave-v2-20bacceedade - hardhat forkmainnet : https://hardhat.org/hardhat-network/guides/mainnet-forking.html - quick swap: https://github.com/QuickSwap -- uniswapper : https://azfuller20.medium.com/swap-with-uniswap-wip-f15923349b3d +- uniswap v3 swap : https://solidity-by-example.org/defi/uniswap-v3-swap/ - https://github.com/austintgriffith/scaffold-eth/tree/defi-rtokens - https://github.com/austintgriffith/scaffold-eth/tree/unifactory - https://github.com/austintgriffith/scaffold-eth/tree/clr-dev - https://medium.com/dapphub/introducing-ds-math-an-innovative-safe-math-library-d58bc88313da -- aave official doc: https://docs.aave.com/developers/the-core-protocol/protocol-overview#main-contracts -- aave polygon graph: https://thegraph.com/legacy-explorer/subgraph/aave/aave-v2-matic +- aave official doc: https://docs.aave.com/developers/getting-started/contracts-overview +- aave polygon graph: https://thegraph.com/hosted-service/subgraph/aave/protocol-v3-polygon - scaffold chanllenge https://medium.com/@austin_48503/%EF%B8%8Fethereum-dev-speed-run-bd72bcba6a4c - scaffold-eth task: https://speedrunethereum.com/ - aave flashloan: https://github.com/johngrantuk/aaveFlashLoan - axios query subgraph: https://gist.github.com/alejoacosta74/55044445dec594f33c10c432b39f1116 +- aave deployed contract addresses: https://docs.aave.com/developers/deployed-contracts/v3-mainnet +- uniswap deployed contract addresses: https://docs.uniswap.org/contracts/v3/reference/deployments diff --git a/basic/21-aave-uni-loan/contracts/AaveApe.sol b/basic/21-aave-uni-loan/contracts/AaveApe.sol index c9a71a965..24aabd78b 100644 --- a/basic/21-aave-uni-loan/contracts/AaveApe.sol +++ b/basic/21-aave-uni-loan/contracts/AaveApe.sol @@ -46,7 +46,7 @@ contract AaveApe is AaveUniswapBase { // Approve the Uniswap Router on the borrowed asset IERC20(borrowAsset).approve(UNISWAP_ROUTER_ADDRESS, borrowAmount); - //we will set the uniswap pool fee to 0.3%. + //we will set the uniswap pool fee to 0.3%. best for most pairs uint24 poolFee = 3000; // Execute trade on Uniswap @@ -176,7 +176,7 @@ contract AaveApe is AaveUniswapBase { IERC20(apeAsset).approve(UNISWAP_ROUTER_ADDRESS, maxCollateralAmount); // unsiwap v3 swap - //we will set the uniswap pool fee to 0.3%. + //we will set the uniswap pool fee to 0.3%. best for most pairs uint24 poolFee = 3000; // Execute trade on Uniswap diff --git a/basic/21-aave-uni-loan/contracts/AaveUniswapBase.sol b/basic/21-aave-uni-loan/contracts/AaveUniswapBase.sol index e119c0d75..650a038ea 100644 --- a/basic/21-aave-uni-loan/contracts/AaveUniswapBase.sol +++ b/basic/21-aave-uni-loan/contracts/AaveUniswapBase.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.0; -import {IERC20} from './dependencies/openzeppelin/contracts/IERC20.sol'; -import {SafeMath} from './dependencies/openzeppelin/contracts/SafeMath.sol'; +import {IERC20} from './interfaces/IERC20.sol'; +import {SafeMath} from './libraries/SafeMath.sol'; import "./interfaces/IPool.sol"; import "./interfaces/IPoolAddressesProvider.sol"; import "./interfaces/IPoolDataProvider.sol"; @@ -24,7 +24,7 @@ contract AaveUniswapBase { UNISWAP_ROUTER_ADDRESS = uniswapRouterAddress; } - address public immutable _lendingPoolAddress =0xE0fBa4Fc209b4948668006B2bE61711b7f465bAe; + // address public immutable _lendingPoolAddress =0xE0fBa4Fc209b4948668006B2bE61711b7f465bAe; function LENDING_POOL() public view returns (IPool) { address _lendingPoolAddress = ADDRESSES_PROVIDER.getPool(); return IPool(_lendingPoolAddress); diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/AccessControl.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/AccessControl.sol deleted file mode 100644 index 3b3e7c311..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/AccessControl.sol +++ /dev/null @@ -1,216 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import './IAccessControl.sol'; -import './Context.sol'; -import './Strings.sol'; -import './ERC165.sol'; - -/** - * @dev Contract module that allows children to implement role-based access - * control mechanisms. This is a lightweight version that doesn't allow enumerating role - * members except through off-chain means by accessing the contract event logs. Some - * applications may benefit from on-chain enumerability, for those cases see - * {AccessControlEnumerable}. - * - * Roles are referred to by their `bytes32` identifier. These should be exposed - * in the external API and be unique. The best way to achieve this is by - * using `public constant` hash digests: - * - * ``` - * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); - * ``` - * - * Roles can be used to represent a set of permissions. To restrict access to a - * function call, use {hasRole}: - * - * ``` - * function foo() public { - * require(hasRole(MY_ROLE, msg.sender)); - * ... - * } - * ``` - * - * Roles can be granted and revoked dynamically via the {grantRole} and - * {revokeRole} functions. Each role has an associated admin role, and only - * accounts that have a role's admin role can call {grantRole} and {revokeRole}. - * - * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means - * that only accounts with this role will be able to grant or revoke other - * roles. More complex role relationships can be created by using - * {_setRoleAdmin}. - * - * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to - * grant and revoke this role. Extra precautions should be taken to secure - * accounts that have been granted it. - */ -abstract contract AccessControl is Context, IAccessControl, ERC165 { - struct RoleData { - mapping(address => bool) members; - bytes32 adminRole; - } - - mapping(bytes32 => RoleData) private _roles; - - bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; - - /** - * @dev Modifier that checks that an account has a specific role. Reverts - * with a standardized message including the required role. - * - * The format of the revert reason is given by the following regular expression: - * - * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ - * - * _Available since v4.1._ - */ - modifier onlyRole(bytes32 role) { - _checkRole(role, _msgSender()); - _; - } - - /** - * @dev See {IERC165-supportsInterface}. - */ - function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { - return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); - } - - /** - * @dev Returns `true` if `account` has been granted `role`. - */ - function hasRole(bytes32 role, address account) public view override returns (bool) { - return _roles[role].members[account]; - } - - /** - * @dev Revert with a standard message if `account` is missing `role`. - * - * The format of the revert reason is given by the following regular expression: - * - * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ - */ - function _checkRole(bytes32 role, address account) internal view { - if (!hasRole(role, account)) { - revert( - string( - abi.encodePacked( - 'AccessControl: account ', - Strings.toHexString(uint160(account), 20), - ' is missing role ', - Strings.toHexString(uint256(role), 32) - ) - ) - ); - } - } - - /** - * @dev Returns the admin role that controls `role`. See {grantRole} and - * {revokeRole}. - * - * To change a role's admin, use {_setRoleAdmin}. - */ - function getRoleAdmin(bytes32 role) public view override returns (bytes32) { - return _roles[role].adminRole; - } - - /** - * @dev Grants `role` to `account`. - * - * If `account` had not been already granted `role`, emits a {RoleGranted} - * event. - * - * Requirements: - * - * - the caller must have ``role``'s admin role. - */ - function grantRole( - bytes32 role, - address account - ) public virtual override onlyRole(getRoleAdmin(role)) { - _grantRole(role, account); - } - - /** - * @dev Revokes `role` from `account`. - * - * If `account` had been granted `role`, emits a {RoleRevoked} event. - * - * Requirements: - * - * - the caller must have ``role``'s admin role. - */ - function revokeRole( - bytes32 role, - address account - ) public virtual override onlyRole(getRoleAdmin(role)) { - _revokeRole(role, account); - } - - /** - * @dev Revokes `role` from the calling account. - * - * Roles are often managed via {grantRole} and {revokeRole}: this function's - * purpose is to provide a mechanism for accounts to lose their privileges - * if they are compromised (such as when a trusted device is misplaced). - * - * If the calling account had been granted `role`, emits a {RoleRevoked} - * event. - * - * Requirements: - * - * - the caller must be `account`. - */ - function renounceRole(bytes32 role, address account) public virtual override { - require(account == _msgSender(), 'AccessControl: can only renounce roles for self'); - - _revokeRole(role, account); - } - - /** - * @dev Grants `role` to `account`. - * - * If `account` had not been already granted `role`, emits a {RoleGranted} - * event. Note that unlike {grantRole}, this function doesn't perform any - * checks on the calling account. - * - * [WARNING] - * ==== - * This function should only be called from the constructor when setting - * up the initial roles for the system. - * - * Using this function in any other way is effectively circumventing the admin - * system imposed by {AccessControl}. - * ==== - */ - function _setupRole(bytes32 role, address account) internal virtual { - _grantRole(role, account); - } - - /** - * @dev Sets `adminRole` as ``role``'s admin role. - * - * Emits a {RoleAdminChanged} event. - */ - function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { - bytes32 previousAdminRole = getRoleAdmin(role); - _roles[role].adminRole = adminRole; - emit RoleAdminChanged(role, previousAdminRole, adminRole); - } - - function _grantRole(bytes32 role, address account) private { - if (!hasRole(role, account)) { - _roles[role].members[account] = true; - emit RoleGranted(role, account, _msgSender()); - } - } - - function _revokeRole(bytes32 role, address account) private { - if (hasRole(role, account)) { - _roles[role].members[account] = false; - emit RoleRevoked(role, account, _msgSender()); - } - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Address.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Address.sol deleted file mode 100644 index 9a6bb205a..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Address.sol +++ /dev/null @@ -1,220 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts v4.4.1 (utils/Address.sol) - -pragma solidity ^0.8.0; - -/** - * @dev Collection of functions related to the address type - */ -library Address { - /** - * @dev Returns true if `account` is a contract. - * - * [IMPORTANT] - * ==== - * It is unsafe to assume that an address for which this function returns - * false is an externally-owned account (EOA) and not a contract. - * - * Among others, `isContract` will return false for the following - * types of addresses: - * - * - an externally-owned account - * - a contract in construction - * - an address where a contract will be created - * - an address where a contract lived, but was destroyed - * ==== - */ - function isContract(address account) internal view returns (bool) { - // This method relies on extcodesize, which returns 0 for contracts in - // construction, since the code is only stored at the end of the - // constructor execution. - - uint256 size; - assembly { - size := extcodesize(account) - } - return size > 0; - } - - /** - * @dev Replacement for Solidity's `transfer`: sends `amount` wei to - * `recipient`, forwarding all available gas and reverting on errors. - * - * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost - * of certain opcodes, possibly making contracts go over the 2300 gas limit - * imposed by `transfer`, making them unable to receive funds via - * `transfer`. {sendValue} removes this limitation. - * - * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. - * - * IMPORTANT: because control is transferred to `recipient`, care must be - * taken to not create reentrancy vulnerabilities. Consider using - * {ReentrancyGuard} or the - * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. - */ - function sendValue(address payable recipient, uint256 amount) internal { - require(address(this).balance >= amount, 'Address: insufficient balance'); - - (bool success, ) = recipient.call{value: amount}(''); - require(success, 'Address: unable to send value, recipient may have reverted'); - } - - /** - * @dev Performs a Solidity function call using a low level `call`. A - * plain `call` is an unsafe replacement for a function call: use this - * function instead. - * - * If `target` reverts with a revert reason, it is bubbled up by this - * function (like regular Solidity function calls). - * - * Returns the raw returned data. To convert to the expected return value, - * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. - * - * Requirements: - * - * - `target` must be a contract. - * - calling `target` with `data` must not revert. - * - * _Available since v3.1._ - */ - function functionCall(address target, bytes memory data) internal returns (bytes memory) { - return functionCall(target, data, 'Address: low-level call failed'); - } - - /** - * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with - * `errorMessage` as a fallback revert reason when `target` reverts. - * - * _Available since v3.1._ - */ - function functionCall( - address target, - bytes memory data, - string memory errorMessage - ) internal returns (bytes memory) { - return functionCallWithValue(target, data, 0, errorMessage); - } - - /** - * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], - * but also transferring `value` wei to `target`. - * - * Requirements: - * - * - the calling contract must have an ETH balance of at least `value`. - * - the called Solidity function must be `payable`. - * - * _Available since v3.1._ - */ - function functionCallWithValue( - address target, - bytes memory data, - uint256 value - ) internal returns (bytes memory) { - return functionCallWithValue(target, data, value, 'Address: low-level call with value failed'); - } - - /** - * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but - * with `errorMessage` as a fallback revert reason when `target` reverts. - * - * _Available since v3.1._ - */ - function functionCallWithValue( - address target, - bytes memory data, - uint256 value, - string memory errorMessage - ) internal returns (bytes memory) { - require(address(this).balance >= value, 'Address: insufficient balance for call'); - require(isContract(target), 'Address: call to non-contract'); - - (bool success, bytes memory returndata) = target.call{value: value}(data); - return verifyCallResult(success, returndata, errorMessage); - } - - /** - * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], - * but performing a static call. - * - * _Available since v3.3._ - */ - function functionStaticCall( - address target, - bytes memory data - ) internal view returns (bytes memory) { - return functionStaticCall(target, data, 'Address: low-level static call failed'); - } - - /** - * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], - * but performing a static call. - * - * _Available since v3.3._ - */ - function functionStaticCall( - address target, - bytes memory data, - string memory errorMessage - ) internal view returns (bytes memory) { - require(isContract(target), 'Address: static call to non-contract'); - - (bool success, bytes memory returndata) = target.staticcall(data); - return verifyCallResult(success, returndata, errorMessage); - } - - /** - * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], - * but performing a delegate call. - * - * _Available since v3.4._ - */ - function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { - return functionDelegateCall(target, data, 'Address: low-level delegate call failed'); - } - - /** - * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], - * but performing a delegate call. - * - * _Available since v3.4._ - */ - function functionDelegateCall( - address target, - bytes memory data, - string memory errorMessage - ) internal returns (bytes memory) { - require(isContract(target), 'Address: delegate call to non-contract'); - - (bool success, bytes memory returndata) = target.delegatecall(data); - return verifyCallResult(success, returndata, errorMessage); - } - - /** - * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the - * revert reason using the provided one. - * - * _Available since v4.3._ - */ - function verifyCallResult( - bool success, - bytes memory returndata, - string memory errorMessage - ) internal pure returns (bytes memory) { - if (success) { - return returndata; - } else { - // Look for revert reason and bubble it up if present - if (returndata.length > 0) { - // The easiest way to bubble the revert reason is using memory via assembly - - assembly { - let returndata_size := mload(returndata) - revert(add(32, returndata), returndata_size) - } - } else { - revert(errorMessage); - } - } - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Context.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Context.sol deleted file mode 100644 index 01377c6d8..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Context.sol +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -/* - * @dev Provides information about the current execution context, including the - * sender of the transaction and its data. While these are generally available - * via msg.sender and msg.data, they should not be accessed in such a direct - * manner, since when dealing with GSN meta-transactions the account sending and - * paying for execution may not be the actual sender (as far as an application - * is concerned). - * - * This contract is only required for intermediate, library-like contracts. - */ -abstract contract Context { - function _msgSender() internal view virtual returns (address payable) { - return payable(msg.sender); - } - - function _msgData() internal view virtual returns (bytes memory) { - this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 - return msg.data; - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/ERC165.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/ERC165.sol deleted file mode 100644 index 3f34e13d7..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/ERC165.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import './IERC165.sol'; - -/** - * @dev Implementation of the {IERC165} interface. - * - * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check - * for the additional interface id that will be supported. For example: - * - * ```solidity - * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { - * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); - * } - * ``` - * - * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. - */ -abstract contract ERC165 is IERC165 { - /** - * @dev See {IERC165-supportsInterface}. - */ - function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { - return interfaceId == type(IERC165).interfaceId; - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/ERC20.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/ERC20.sol deleted file mode 100644 index cc52c0608..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/ERC20.sol +++ /dev/null @@ -1,328 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import './Context.sol'; -import './IERC20.sol'; -import './SafeMath.sol'; -import './Address.sol'; - -/** - * @dev Implementation of the {IERC20} interface. - * - * This implementation is agnostic to the way tokens are created. This means - * that a supply mechanism has to be added in a derived contract using {_mint}. - * For a generic mechanism see {ERC20PresetMinterPauser}. - * - * TIP: For a detailed writeup see our guide - * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How - * to implement supply mechanisms]. - * - * We have followed general OpenZeppelin guidelines: functions revert instead - * of returning `false` on failure. This behavior is nonetheless conventional - * and does not conflict with the expectations of ERC20 applications. - * - * Additionally, an {Approval} event is emitted on calls to {transferFrom}. - * This allows applications to reconstruct the allowance for all accounts just - * by listening to said events. Other implementations of the EIP may not emit - * these events, as it isn't required by the specification. - * - * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} - * functions have been added to mitigate the well-known issues around setting - * allowances. See {IERC20-approve}. - */ -contract ERC20 is Context, IERC20 { - using SafeMath for uint256; - using Address for address; - - mapping(address => uint256) private _balances; - - mapping(address => mapping(address => uint256)) private _allowances; - - uint256 private _totalSupply; - - string private _name; - string private _symbol; - uint8 private _decimals; - - /** - * @dev Sets the values for {name} and {symbol}, initializes {decimals} with - * a default value of 18. - * - * To select a different value for {decimals}, use {_setupDecimals}. - * - * All three of these values are immutable: they can only be set once during - * construction. - */ - constructor(string memory name, string memory symbol) { - _name = name; - _symbol = symbol; - _decimals = 18; - } - - /** - * @dev Returns the name of the token. - */ - function name() public view returns (string memory) { - return _name; - } - - /** - * @dev Returns the symbol of the token, usually a shorter version of the - * name. - */ - function symbol() public view returns (string memory) { - return _symbol; - } - - /** - * @dev Returns the number of decimals used to get its user representation. - * For example, if `decimals` equals `2`, a balance of `505` tokens should - * be displayed to a user as `5,05` (`505 / 10 ** 2`). - * - * Tokens usually opt for a value of 18, imitating the relationship between - * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is - * called. - * - * NOTE: This information is only used for _display_ purposes: it in - * no way affects any of the arithmetic of the contract, including - * {IERC20-balanceOf} and {IERC20-transfer}. - */ - function decimals() public view returns (uint8) { - return _decimals; - } - - /** - * @dev See {IERC20-totalSupply}. - */ - function totalSupply() public view override returns (uint256) { - return _totalSupply; - } - - /** - * @dev See {IERC20-balanceOf}. - */ - function balanceOf(address account) public view override returns (uint256) { - return _balances[account]; - } - - /** - * @dev See {IERC20-transfer}. - * - * Requirements: - * - * - `recipient` cannot be the zero address. - * - the caller must have a balance of at least `amount`. - */ - function transfer(address recipient, uint256 amount) public virtual override returns (bool) { - _transfer(_msgSender(), recipient, amount); - return true; - } - - /** - * @dev See {IERC20-allowance}. - */ - function allowance( - address owner, - address spender - ) public view virtual override returns (uint256) { - return _allowances[owner][spender]; - } - - /** - * @dev See {IERC20-approve}. - * - * Requirements: - * - * - `spender` cannot be the zero address. - */ - function approve(address spender, uint256 amount) public virtual override returns (bool) { - _approve(_msgSender(), spender, amount); - return true; - } - - /** - * @dev See {IERC20-transferFrom}. - * - * Emits an {Approval} event indicating the updated allowance. This is not - * required by the EIP. See the note at the beginning of {ERC20}; - * - * Requirements: - * - `sender` and `recipient` cannot be the zero address. - * - `sender` must have a balance of at least `amount`. - * - the caller must have allowance for ``sender``'s tokens of at least - * `amount`. - */ - function transferFrom( - address sender, - address recipient, - uint256 amount - ) public virtual override returns (bool) { - _transfer(sender, recipient, amount); - _approve( - sender, - _msgSender(), - _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance') - ); - return true; - } - - /** - * @dev Atomically increases the allowance granted to `spender` by the caller. - * - * This is an alternative to {approve} that can be used as a mitigation for - * problems described in {IERC20-approve}. - * - * Emits an {Approval} event indicating the updated allowance. - * - * Requirements: - * - * - `spender` cannot be the zero address. - */ - function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { - _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); - return true; - } - - /** - * @dev Atomically decreases the allowance granted to `spender` by the caller. - * - * This is an alternative to {approve} that can be used as a mitigation for - * problems described in {IERC20-approve}. - * - * Emits an {Approval} event indicating the updated allowance. - * - * Requirements: - * - * - `spender` cannot be the zero address. - * - `spender` must have allowance for the caller of at least - * `subtractedValue`. - */ - function decreaseAllowance( - address spender, - uint256 subtractedValue - ) public virtual returns (bool) { - _approve( - _msgSender(), - spender, - _allowances[_msgSender()][spender].sub( - subtractedValue, - 'ERC20: decreased allowance below zero' - ) - ); - return true; - } - - /** - * @dev Moves tokens `amount` from `sender` to `recipient`. - * - * This is internal function is equivalent to {transfer}, and can be used to - * e.g. implement automatic token fees, slashing mechanisms, etc. - * - * Emits a {Transfer} event. - * - * Requirements: - * - * - `sender` cannot be the zero address. - * - `recipient` cannot be the zero address. - * - `sender` must have a balance of at least `amount`. - */ - function _transfer(address sender, address recipient, uint256 amount) internal virtual { - require(sender != address(0), 'ERC20: transfer from the zero address'); - require(recipient != address(0), 'ERC20: transfer to the zero address'); - - _beforeTokenTransfer(sender, recipient, amount); - - _balances[sender] = _balances[sender].sub(amount, 'ERC20: transfer amount exceeds balance'); - _balances[recipient] = _balances[recipient].add(amount); - emit Transfer(sender, recipient, amount); - } - - /** @dev Creates `amount` tokens and assigns them to `account`, increasing - * the total supply. - * - * Emits a {Transfer} event with `from` set to the zero address. - * - * Requirements - * - * - `to` cannot be the zero address. - */ - function _mint(address account, uint256 amount) internal virtual { - require(account != address(0), 'ERC20: mint to the zero address'); - - _beforeTokenTransfer(address(0), account, amount); - - _totalSupply = _totalSupply.add(amount); - _balances[account] = _balances[account].add(amount); - emit Transfer(address(0), account, amount); - } - - /** - * @dev Destroys `amount` tokens from `account`, reducing the - * total supply. - * - * Emits a {Transfer} event with `to` set to the zero address. - * - * Requirements - * - * - `account` cannot be the zero address. - * - `account` must have at least `amount` tokens. - */ - function _burn(address account, uint256 amount) internal virtual { - require(account != address(0), 'ERC20: burn from the zero address'); - - _beforeTokenTransfer(account, address(0), amount); - - _balances[account] = _balances[account].sub(amount, 'ERC20: burn amount exceeds balance'); - _totalSupply = _totalSupply.sub(amount); - emit Transfer(account, address(0), amount); - } - - /** - * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. - * - * This is internal function is equivalent to `approve`, and can be used to - * e.g. set automatic allowances for certain subsystems, etc. - * - * Emits an {Approval} event. - * - * Requirements: - * - * - `owner` cannot be the zero address. - * - `spender` cannot be the zero address. - */ - function _approve(address owner, address spender, uint256 amount) internal virtual { - require(owner != address(0), 'ERC20: approve from the zero address'); - require(spender != address(0), 'ERC20: approve to the zero address'); - - _allowances[owner][spender] = amount; - emit Approval(owner, spender, amount); - } - - /** - * @dev Sets {decimals} to a value other than the default one of 18. - * - * WARNING: This function should only be called from the constructor. Most - * applications that interact with token contracts will not expect - * {decimals} to ever change, and may work incorrectly if it does. - */ - function _setupDecimals(uint8 decimals_) internal { - _decimals = decimals_; - } - - /** - * @dev Hook that is called before any transfer of tokens. This includes - * minting and burning. - * - * Calling conditions: - * - * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens - * will be to transferred to `to`. - * - when `from` is zero, `amount` tokens will be minted for `to`. - * - when `to` is zero, `amount` of ``from``'s tokens will be burned. - * - `from` and `to` are never both zero. - * - * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. - */ - function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IAccessControl.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IAccessControl.sol deleted file mode 100644 index 2b63934d2..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IAccessControl.sol +++ /dev/null @@ -1,91 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -/** - * @dev External interface of AccessControl declared to support ERC165 detection. - */ -interface IAccessControl { - /** - * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` - * - * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite - * {RoleAdminChanged} not being emitted signaling this. - * - * _Available since v3.1._ - */ - event RoleAdminChanged( - bytes32 indexed role, - bytes32 indexed previousAdminRole, - bytes32 indexed newAdminRole - ); - - /** - * @dev Emitted when `account` is granted `role`. - * - * `sender` is the account that originated the contract call, an admin role - * bearer except when using {AccessControl-_setupRole}. - */ - event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); - - /** - * @dev Emitted when `account` is revoked `role`. - * - * `sender` is the account that originated the contract call: - * - if using `revokeRole`, it is the admin role bearer - * - if using `renounceRole`, it is the role bearer (i.e. `account`) - */ - event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); - - /** - * @dev Returns `true` if `account` has been granted `role`. - */ - function hasRole(bytes32 role, address account) external view returns (bool); - - /** - * @dev Returns the admin role that controls `role`. See {grantRole} and - * {revokeRole}. - * - * To change a role's admin, use {AccessControl-_setRoleAdmin}. - */ - function getRoleAdmin(bytes32 role) external view returns (bytes32); - - /** - * @dev Grants `role` to `account`. - * - * If `account` had not been already granted `role`, emits a {RoleGranted} - * event. - * - * Requirements: - * - * - the caller must have ``role``'s admin role. - */ - function grantRole(bytes32 role, address account) external; - - /** - * @dev Revokes `role` from `account`. - * - * If `account` had been granted `role`, emits a {RoleRevoked} event. - * - * Requirements: - * - * - the caller must have ``role``'s admin role. - */ - function revokeRole(bytes32 role, address account) external; - - /** - * @dev Revokes `role` from the calling account. - * - * Roles are often managed via {grantRole} and {revokeRole}: this function's - * purpose is to provide a mechanism for accounts to lose their privileges - * if they are compromised (such as when a trusted device is misplaced). - * - * If the calling account had been granted `role`, emits a {RoleRevoked} - * event. - * - * Requirements: - * - * - the caller must be `account`. - */ - function renounceRole(bytes32 role, address account) external; -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC165.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC165.sol deleted file mode 100644 index c7c8e53d0..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC165.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -/** - * @dev Interface of the ERC165 standard, as defined in the - * https://eips.ethereum.org/EIPS/eip-165[EIP]. - * - * Implementers can declare support of contract interfaces, which can then be - * queried by others ({ERC165Checker}). - * - * For an implementation, see {ERC165}. - */ -interface IERC165 { - /** - * @dev Returns true if this contract implements the interface defined by - * `interfaceId`. See the corresponding - * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] - * to learn more about how these ids are created. - * - * This function call must use less than 30 000 gas. - */ - function supportsInterface(bytes4 interfaceId) external view returns (bool); -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol deleted file mode 100644 index 6bd0685ab..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import {IERC20} from './IERC20.sol'; - -interface IERC20Detailed is IERC20 { - function name() external view returns (string memory); - - function symbol() external view returns (string memory); - - function decimals() external view returns (uint8); -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Ownable.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Ownable.sol deleted file mode 100644 index a65c2ceb9..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Ownable.sol +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import './Context.sol'; - -/** - * @dev Contract module which provides a basic access control mechanism, where - * there is an account (an owner) that can be granted exclusive access to - * specific functions. - * - * By default, the owner account will be the one that deploys the contract. This - * can later be changed with {transferOwnership}. - * - * This module is used through inheritance. It will make available the modifier - * `onlyOwner`, which can be applied to your functions to restrict their use to - * the owner. - */ -contract Ownable is Context { - address private _owner; - - event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); - - /** - * @dev Initializes the contract setting the deployer as the initial owner. - */ - constructor() { - address msgSender = _msgSender(); - _owner = msgSender; - emit OwnershipTransferred(address(0), msgSender); - } - - /** - * @dev Returns the address of the current owner. - */ - function owner() public view returns (address) { - return _owner; - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(_owner == _msgSender(), 'Ownable: caller is not the owner'); - _; - } - - /** - * @dev Leaves the contract without owner. It will not be possible to call - * `onlyOwner` functions anymore. Can only be called by the current owner. - * - * NOTE: Renouncing ownership will leave the contract without an owner, - * thereby removing any functionality that is only available to the owner. - */ - function renounceOwnership() public virtual onlyOwner { - emit OwnershipTransferred(_owner, address(0)); - _owner = address(0); - } - - /** - * @dev Transfers ownership of the contract to a new account (`newOwner`). - * Can only be called by the current owner. - */ - function transferOwnership(address newOwner) public virtual onlyOwner { - require(newOwner != address(0), 'Ownable: new owner is the zero address'); - emit OwnershipTransferred(_owner, newOwner); - _owner = newOwner; - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeCast.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeCast.sol deleted file mode 100644 index a2ec21970..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeCast.sol +++ /dev/null @@ -1,255 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol) -pragma solidity ^0.8.0; - -/** - * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow - * checks. - * - * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can - * easily result in undesired exploitation or bugs, since developers usually - * assume that overflows raise errors. `SafeCast` restores this intuition by - * reverting the transaction when such an operation overflows. - * - * Using this library instead of the unchecked operations eliminates an entire - * class of bugs, so it's recommended to use it always. - * - * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing - * all math on `uint256` and `int256` and then downcasting. - */ -library SafeCast { - /** - * @dev Returns the downcasted uint224 from uint256, reverting on - * overflow (when the input is greater than largest uint224). - * - * Counterpart to Solidity's `uint224` operator. - * - * Requirements: - * - * - input must fit into 224 bits - */ - function toUint224(uint256 value) internal pure returns (uint224) { - require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); - return uint224(value); - } - - /** - * @dev Returns the downcasted uint128 from uint256, reverting on - * overflow (when the input is greater than largest uint128). - * - * Counterpart to Solidity's `uint128` operator. - * - * Requirements: - * - * - input must fit into 128 bits - */ - function toUint128(uint256 value) internal pure returns (uint128) { - require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); - return uint128(value); - } - - /** - * @dev Returns the downcasted uint96 from uint256, reverting on - * overflow (when the input is greater than largest uint96). - * - * Counterpart to Solidity's `uint96` operator. - * - * Requirements: - * - * - input must fit into 96 bits - */ - function toUint96(uint256 value) internal pure returns (uint96) { - require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); - return uint96(value); - } - - /** - * @dev Returns the downcasted uint64 from uint256, reverting on - * overflow (when the input is greater than largest uint64). - * - * Counterpart to Solidity's `uint64` operator. - * - * Requirements: - * - * - input must fit into 64 bits - */ - function toUint64(uint256 value) internal pure returns (uint64) { - require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); - return uint64(value); - } - - /** - * @dev Returns the downcasted uint32 from uint256, reverting on - * overflow (when the input is greater than largest uint32). - * - * Counterpart to Solidity's `uint32` operator. - * - * Requirements: - * - * - input must fit into 32 bits - */ - function toUint32(uint256 value) internal pure returns (uint32) { - require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); - return uint32(value); - } - - /** - * @dev Returns the downcasted uint16 from uint256, reverting on - * overflow (when the input is greater than largest uint16). - * - * Counterpart to Solidity's `uint16` operator. - * - * Requirements: - * - * - input must fit into 16 bits - */ - function toUint16(uint256 value) internal pure returns (uint16) { - require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); - return uint16(value); - } - - /** - * @dev Returns the downcasted uint8 from uint256, reverting on - * overflow (when the input is greater than largest uint8). - * - * Counterpart to Solidity's `uint8` operator. - * - * Requirements: - * - * - input must fit into 8 bits. - */ - function toUint8(uint256 value) internal pure returns (uint8) { - require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); - return uint8(value); - } - - /** - * @dev Converts a signed int256 into an unsigned uint256. - * - * Requirements: - * - * - input must be greater than or equal to 0. - */ - function toUint256(int256 value) internal pure returns (uint256) { - require(value >= 0, 'SafeCast: value must be positive'); - return uint256(value); - } - - /** - * @dev Returns the downcasted int128 from int256, reverting on - * overflow (when the input is less than smallest int128 or - * greater than largest int128). - * - * Counterpart to Solidity's `int128` operator. - * - * Requirements: - * - * - input must fit into 128 bits - * - * _Available since v3.1._ - */ - function toInt128(int256 value) internal pure returns (int128) { - require( - value >= type(int128).min && value <= type(int128).max, - "SafeCast: value doesn't fit in 128 bits" - ); - return int128(value); - } - - /** - * @dev Returns the downcasted int64 from int256, reverting on - * overflow (when the input is less than smallest int64 or - * greater than largest int64). - * - * Counterpart to Solidity's `int64` operator. - * - * Requirements: - * - * - input must fit into 64 bits - * - * _Available since v3.1._ - */ - function toInt64(int256 value) internal pure returns (int64) { - require( - value >= type(int64).min && value <= type(int64).max, - "SafeCast: value doesn't fit in 64 bits" - ); - return int64(value); - } - - /** - * @dev Returns the downcasted int32 from int256, reverting on - * overflow (when the input is less than smallest int32 or - * greater than largest int32). - * - * Counterpart to Solidity's `int32` operator. - * - * Requirements: - * - * - input must fit into 32 bits - * - * _Available since v3.1._ - */ - function toInt32(int256 value) internal pure returns (int32) { - require( - value >= type(int32).min && value <= type(int32).max, - "SafeCast: value doesn't fit in 32 bits" - ); - return int32(value); - } - - /** - * @dev Returns the downcasted int16 from int256, reverting on - * overflow (when the input is less than smallest int16 or - * greater than largest int16). - * - * Counterpart to Solidity's `int16` operator. - * - * Requirements: - * - * - input must fit into 16 bits - * - * _Available since v3.1._ - */ - function toInt16(int256 value) internal pure returns (int16) { - require( - value >= type(int16).min && value <= type(int16).max, - "SafeCast: value doesn't fit in 16 bits" - ); - return int16(value); - } - - /** - * @dev Returns the downcasted int8 from int256, reverting on - * overflow (when the input is less than smallest int8 or - * greater than largest int8). - * - * Counterpart to Solidity's `int8` operator. - * - * Requirements: - * - * - input must fit into 8 bits. - * - * _Available since v3.1._ - */ - function toInt8(int256 value) internal pure returns (int8) { - require( - value >= type(int8).min && value <= type(int8).max, - "SafeCast: value doesn't fit in 8 bits" - ); - return int8(value); - } - - /** - * @dev Converts an unsigned uint256 into a signed int256. - * - * Requirements: - * - * - input must be less than or equal to maxInt256. - */ - function toInt256(uint256 value) internal pure returns (int256) { - // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive - require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); - return int256(value); - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol deleted file mode 100644 index 93db74c11..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol +++ /dev/null @@ -1,87 +0,0 @@ -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) - -pragma solidity ^0.8.0; - -import './IERC20.sol'; -import './Address.sol'; - -/** - * @title SafeERC20 - * @dev Wrappers around ERC20 operations that throw on failure (when the token - * contract returns false). Tokens that return no value (and instead revert or - * throw on failure) are also supported, non-reverting calls are assumed to be - * successful. - * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, - * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. - */ -library SafeERC20 { - using Address for address; - - function safeTransfer(IERC20 token, address to, uint256 value) internal { - _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); - } - - function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { - _callOptionalReturn( - token, - abi.encodeWithSelector(token.transferFrom.selector, from, to, value) - ); - } - - /** - * @dev Deprecated. This function has issues similar to the ones found in - * {IERC20-approve}, and its usage is discouraged. - * - * Whenever possible, use {safeIncreaseAllowance} and - * {safeDecreaseAllowance} instead. - */ - function safeApprove(IERC20 token, address spender, uint256 value) internal { - // safeApprove should only be called when setting an initial allowance, - // or when resetting it to zero. To increase and decrease it, use - // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' - require( - (value == 0) || (token.allowance(address(this), spender) == 0), - 'SafeERC20: approve from non-zero to non-zero allowance' - ); - _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); - } - - function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { - uint256 newAllowance = token.allowance(address(this), spender) + value; - _callOptionalReturn( - token, - abi.encodeWithSelector(token.approve.selector, spender, newAllowance) - ); - } - - function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { - unchecked { - uint256 oldAllowance = token.allowance(address(this), spender); - require(oldAllowance >= value, 'SafeERC20: decreased allowance below zero'); - uint256 newAllowance = oldAllowance - value; - _callOptionalReturn( - token, - abi.encodeWithSelector(token.approve.selector, spender, newAllowance) - ); - } - } - - /** - * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement - * on the return value: the return value is optional (but if data is returned, it must not be false). - * @param token The token targeted by the call. - * @param data The call data (encoded using abi.encode or one of its variants). - */ - function _callOptionalReturn(IERC20 token, bytes memory data) private { - // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since - // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that - // the target address contains contract code and also asserts for success in the low-level call. - - bytes memory returndata = address(token).functionCall(data, 'SafeERC20: low-level call failed'); - if (returndata.length > 0) { - // Return data is optional - require(abi.decode(returndata, (bool)), 'SafeERC20: ERC20 operation did not succeed'); - } - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Strings.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Strings.sol deleted file mode 100644 index 89c8b98a3..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/Strings.sol +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -/** - * @dev String operations. - */ -library Strings { - bytes16 private constant _HEX_SYMBOLS = '0123456789abcdef'; - - /** - * @dev Converts a `uint256` to its ASCII `string` decimal representation. - */ - function toString(uint256 value) internal pure returns (string memory) { - // Inspired by OraclizeAPI's implementation - MIT licence - // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol - - if (value == 0) { - return '0'; - } - uint256 temp = value; - uint256 digits; - while (temp != 0) { - digits++; - temp /= 10; - } - bytes memory buffer = new bytes(digits); - while (value != 0) { - digits -= 1; - buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); - value /= 10; - } - return string(buffer); - } - - /** - * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. - */ - function toHexString(uint256 value) internal pure returns (string memory) { - if (value == 0) { - return '0x00'; - } - uint256 temp = value; - uint256 length = 0; - while (temp != 0) { - length++; - temp >>= 8; - } - return toHexString(value, length); - } - - /** - * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. - */ - function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { - bytes memory buffer = new bytes(2 * length + 2); - buffer[0] = '0'; - buffer[1] = 'x'; - for (uint256 i = 2 * length + 1; i > 1; --i) { - buffer[i] = _HEX_SYMBOLS[value & 0xf]; - value >>= 4; - } - require(value == 0, 'Strings: hex length insufficient'); - return string(buffer); - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/AdminUpgradeabilityProxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/AdminUpgradeabilityProxy.sol deleted file mode 100644 index c686cc741..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/AdminUpgradeabilityProxy.sol +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import './BaseAdminUpgradeabilityProxy.sol'; - -/** - * @title AdminUpgradeabilityProxy - * @dev Extends from BaseAdminUpgradeabilityProxy with a constructor for - * initializing the implementation, admin, and init data. - */ -contract AdminUpgradeabilityProxy is BaseAdminUpgradeabilityProxy, UpgradeabilityProxy { - /** - * Contract constructor. - * @param _logic address of the initial implementation. - * @param _admin Address of the proxy administrator. - * @param _data Data to send as msg.data to the implementation to initialize the proxied contract. - * It should include the signature and the parameters of the function to be called, as described in - * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. - * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. - */ - constructor( - address _logic, - address _admin, - bytes memory _data - ) payable UpgradeabilityProxy(_logic, _data) { - assert(ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)); - _setAdmin(_admin); - } - - /** - * @dev Only fall back when the sender is not the admin. - */ - function _willFallback() internal override(BaseAdminUpgradeabilityProxy, Proxy) { - BaseAdminUpgradeabilityProxy._willFallback(); - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol deleted file mode 100644 index 2f65f3697..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/BaseAdminUpgradeabilityProxy.sol +++ /dev/null @@ -1,125 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import './UpgradeabilityProxy.sol'; - -/** - * @title BaseAdminUpgradeabilityProxy - * @dev This contract combines an upgradeability proxy with an authorization - * mechanism for administrative tasks. - * All external functions in this contract must be guarded by the - * `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity - * feature proposal that would enable this to be done automatically. - */ -contract BaseAdminUpgradeabilityProxy is BaseUpgradeabilityProxy { - /** - * @dev Emitted when the administration has been transferred. - * @param previousAdmin Address of the previous admin. - * @param newAdmin Address of the new admin. - */ - event AdminChanged(address previousAdmin, address newAdmin); - - /** - * @dev Storage slot with the admin of the contract. - * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is - * validated in the constructor. - */ - bytes32 internal constant ADMIN_SLOT = - 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; - - /** - * @dev Modifier to check whether the `msg.sender` is the admin. - * If it is, it will run the function. Otherwise, it will delegate the call - * to the implementation. - */ - modifier ifAdmin() { - if (msg.sender == _admin()) { - _; - } else { - _fallback(); - } - } - - /** - * @return The address of the proxy admin. - */ - function admin() external ifAdmin returns (address) { - return _admin(); - } - - /** - * @return The address of the implementation. - */ - function implementation() external ifAdmin returns (address) { - return _implementation(); - } - - /** - * @dev Changes the admin of the proxy. - * Only the current admin can call this function. - * @param newAdmin Address to transfer proxy administration to. - */ - function changeAdmin(address newAdmin) external ifAdmin { - require(newAdmin != address(0), 'Cannot change the admin of a proxy to the zero address'); - emit AdminChanged(_admin(), newAdmin); - _setAdmin(newAdmin); - } - - /** - * @dev Upgrade the backing implementation of the proxy. - * Only the admin can call this function. - * @param newImplementation Address of the new implementation. - */ - function upgradeTo(address newImplementation) external ifAdmin { - _upgradeTo(newImplementation); - } - - /** - * @dev Upgrade the backing implementation of the proxy and call a function - * on the new implementation. - * This is useful to initialize the proxied contract. - * @param newImplementation Address of the new implementation. - * @param data Data to send as msg.data in the low level call. - * It should include the signature and the parameters of the function to be called, as described in - * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. - */ - function upgradeToAndCall( - address newImplementation, - bytes calldata data - ) external payable ifAdmin { - _upgradeTo(newImplementation); - (bool success, ) = newImplementation.delegatecall(data); - require(success); - } - - /** - * @return adm The admin slot. - */ - function _admin() internal view returns (address adm) { - bytes32 slot = ADMIN_SLOT; - //solium-disable-next-line - assembly { - adm := sload(slot) - } - } - - /** - * @dev Sets the address of the proxy admin. - * @param newAdmin Address of the new proxy admin. - */ - function _setAdmin(address newAdmin) internal { - bytes32 slot = ADMIN_SLOT; - //solium-disable-next-line - assembly { - sstore(slot, newAdmin) - } - } - - /** - * @dev Only fall back when the sender is not the admin. - */ - function _willFallback() internal virtual override { - require(msg.sender != _admin(), 'Cannot call fallback function from the proxy admin'); - super._willFallback(); - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol deleted file mode 100644 index a0d9b80f0..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/BaseUpgradeabilityProxy.sol +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import './Proxy.sol'; -import '../contracts/Address.sol'; - -/** - * @title BaseUpgradeabilityProxy - * @dev This contract implements a proxy that allows to change the - * implementation address to which it will delegate. - * Such a change is called an implementation upgrade. - */ -contract BaseUpgradeabilityProxy is Proxy { - /** - * @dev Emitted when the implementation is upgraded. - * @param implementation Address of the new implementation. - */ - event Upgraded(address indexed implementation); - - /** - * @dev Storage slot with the address of the current implementation. - * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is - * validated in the constructor. - */ - bytes32 internal constant IMPLEMENTATION_SLOT = - 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; - - /** - * @dev Returns the current implementation. - * @return impl Address of the current implementation - */ - function _implementation() internal view override returns (address impl) { - bytes32 slot = IMPLEMENTATION_SLOT; - //solium-disable-next-line - assembly { - impl := sload(slot) - } - } - - /** - * @dev Upgrades the proxy to a new implementation. - * @param newImplementation Address of the new implementation. - */ - function _upgradeTo(address newImplementation) internal { - _setImplementation(newImplementation); - emit Upgraded(newImplementation); - } - - /** - * @dev Sets the implementation address of the proxy. - * @param newImplementation Address of the new implementation. - */ - function _setImplementation(address newImplementation) internal { - require( - Address.isContract(newImplementation), - 'Cannot set a proxy implementation to a non-contract address' - ); - - bytes32 slot = IMPLEMENTATION_SLOT; - - //solium-disable-next-line - assembly { - sstore(slot, newImplementation) - } - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/Initializable.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/Initializable.sol deleted file mode 100644 index 805bdd741..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/Initializable.sol +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -/** - * @title Initializable - * - * @dev Helper contract to support initializer functions. To use it, replace - * the constructor with a function that has the `initializer` modifier. - * WARNING: Unlike constructors, initializer functions must be manually - * invoked. This applies both to deploying an Initializable contract, as well - * as extending an Initializable contract via inheritance. - * WARNING: When used with inheritance, manual care must be taken to not invoke - * a parent initializer twice, or ensure that all initializers are idempotent, - * because this is not dealt with automatically as with constructors. - */ -contract Initializable { - /** - * @dev Indicates that the contract has been initialized. - */ - bool private initialized; - - /** - * @dev Indicates that the contract is in the process of being initialized. - */ - bool private initializing; - - /** - * @dev Modifier to use in the initializer function of a contract. - */ - modifier initializer() { - require( - initializing || isConstructor() || !initialized, - 'Contract instance has already been initialized' - ); - - bool isTopLevelCall = !initializing; - if (isTopLevelCall) { - initializing = true; - initialized = true; - } - - _; - - if (isTopLevelCall) { - initializing = false; - } - } - - /// @dev Returns true if and only if the function is running in the constructor - function isConstructor() private view returns (bool) { - // extcodesize checks the size of the code stored in an address, and - // address returns the current address. Since the code is still not - // deployed when running a constructor, any checks on its code size will - // yield zero, making it an effective way to detect if a contract is - // under construction or not. - uint256 cs; - //solium-disable-next-line - assembly { - cs := extcodesize(address()) - } - return cs == 0; - } - - // Reserved storage space to allow for layout changes in the future. - uint256[50] private ______gap; -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/InitializableAdminUpgradeabilityProxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/InitializableAdminUpgradeabilityProxy.sol deleted file mode 100644 index 33ebadc27..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/InitializableAdminUpgradeabilityProxy.sol +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import './BaseAdminUpgradeabilityProxy.sol'; -import './InitializableUpgradeabilityProxy.sol'; - -/** - * @title InitializableAdminUpgradeabilityProxy - * @dev Extends from BaseAdminUpgradeabilityProxy with an initializer for - * initializing the implementation, admin, and init data. - */ -contract InitializableAdminUpgradeabilityProxy is - BaseAdminUpgradeabilityProxy, - InitializableUpgradeabilityProxy -{ - /** - * Contract initializer. - * @param logic address of the initial implementation. - * @param admin Address of the proxy administrator. - * @param data Data to send as msg.data to the implementation to initialize the proxied contract. - * It should include the signature and the parameters of the function to be called, as described in - * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. - * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. - */ - function initialize(address logic, address admin, bytes memory data) public payable { - require(_implementation() == address(0)); - InitializableUpgradeabilityProxy.initialize(logic, data); - assert(ADMIN_SLOT == bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)); - _setAdmin(admin); - } - - /** - * @dev Only fall back when the sender is not the admin. - */ - function _willFallback() internal override(BaseAdminUpgradeabilityProxy, Proxy) { - BaseAdminUpgradeabilityProxy._willFallback(); - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/InitializableUpgradeabilityProxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/InitializableUpgradeabilityProxy.sol deleted file mode 100644 index 519ab5394..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/InitializableUpgradeabilityProxy.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import './BaseUpgradeabilityProxy.sol'; - -/** - * @title InitializableUpgradeabilityProxy - * @dev Extends BaseUpgradeabilityProxy with an initializer for initializing - * implementation and init data. - */ -contract InitializableUpgradeabilityProxy is BaseUpgradeabilityProxy { - /** - * @dev Contract initializer. - * @param _logic Address of the initial implementation. - * @param _data Data to send as msg.data to the implementation to initialize the proxied contract. - * It should include the signature and the parameters of the function to be called, as described in - * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. - * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. - */ - function initialize(address _logic, bytes memory _data) public payable { - require(_implementation() == address(0)); - assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)); - _setImplementation(_logic); - if (_data.length > 0) { - (bool success, ) = _logic.delegatecall(_data); - require(success); - } - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol deleted file mode 100644 index 4a22797b7..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/Proxy.sol +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -/** - * @title Proxy - * @dev Implements delegation of calls to other contracts, with proper - * forwarding of return values and bubbling of failures. - * It defines a fallback function that delegates all calls to the address - * returned by the abstract _implementation() internal function. - */ -abstract contract Proxy { - /** - * @dev Fallback function. - * Will run if no other function in the contract matches the call data. - * Implemented entirely in `_fallback`. - */ - fallback() external payable { - _fallback(); - } - - /** - * @return The Address of the implementation. - */ - function _implementation() internal view virtual returns (address); - - /** - * @dev Delegates execution to an implementation contract. - * This is a low level function that doesn't return to its internal call site. - * It will return to the external caller whatever the implementation returns. - * @param implementation Address to delegate. - */ - function _delegate(address implementation) internal { - //solium-disable-next-line - assembly { - // Copy msg.data. We take full control of memory in this inline assembly - // block because it will not return to Solidity code. We overwrite the - // Solidity scratch pad at memory position 0. - calldatacopy(0, 0, calldatasize()) - - // Call the implementation. - // out and outsize are 0 because we don't know the size yet. - let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) - - // Copy the returned data. - returndatacopy(0, 0, returndatasize()) - - switch result - // delegatecall returns 0 on error. - case 0 { - revert(0, returndatasize()) - } - default { - return(0, returndatasize()) - } - } - } - - /** - * @dev Function that is run as the first thing in the fallback function. - * Can be redefined in derived contracts to add functionality. - * Redefinitions must call super._willFallback(). - */ - function _willFallback() internal virtual {} - - /** - * @dev fallback implementation. - * Extracted to enable manual triggering. - */ - function _fallback() internal { - _willFallback(); - _delegate(_implementation()); - } -} diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/UpgradeabilityProxy.sol b/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/UpgradeabilityProxy.sol deleted file mode 100644 index e6dce7c09..000000000 --- a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/upgradeability/UpgradeabilityProxy.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.0; - -import './BaseUpgradeabilityProxy.sol'; - -/** - * @title UpgradeabilityProxy - * @dev Extends BaseUpgradeabilityProxy with a constructor for initializing - * implementation and init data. - */ -contract UpgradeabilityProxy is BaseUpgradeabilityProxy { - /** - * @dev Contract constructor. - * @param _logic Address of the initial implementation. - * @param _data Data to send as msg.data to the implementation to initialize the proxied contract. - * It should include the signature and the parameters of the function to be called, as described in - * https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector-and-argument-encoding. - * This parameter is optional, if no data is given the initialization call to proxied contract will be skipped. - */ - constructor(address _logic, bytes memory _data) payable { - assert(IMPLEMENTATION_SLOT == bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)); - _setImplementation(_logic); - if (_data.length > 0) { - (bool success, ) = _logic.delegatecall(_data); - require(success); - } - } -} diff --git a/basic/21-aave-uni-loan/contracts/interfaces/IAToken.sol b/basic/21-aave-uni-loan/contracts/interfaces/IAToken.sol index 1379dff68..ff31f42ad 100644 --- a/basic/21-aave-uni-loan/contracts/interfaces/IAToken.sol +++ b/basic/21-aave-uni-loan/contracts/interfaces/IAToken.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; -import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol'; +import {IERC20} from './IERC20.sol'; import {IScaledBalanceToken} from './IScaledBalanceToken.sol'; import {IInitializableAToken} from './IInitializableAToken.sol'; diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC20.sol b/basic/21-aave-uni-loan/contracts/interfaces/IERC20.sol similarity index 100% rename from basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/IERC20.sol rename to basic/21-aave-uni-loan/contracts/interfaces/IERC20.sol diff --git a/basic/21-aave-uni-loan/contracts/interfaces/IInitializableDebtToken.sol b/basic/21-aave-uni-loan/contracts/interfaces/IInitializableDebtToken.sol index 33196edec..e4c7d6c3d 100644 --- a/basic/21-aave-uni-loan/contracts/interfaces/IInitializableDebtToken.sol +++ b/basic/21-aave-uni-loan/contracts/interfaces/IInitializableDebtToken.sol @@ -60,4 +60,9 @@ interface IInitializableDebtToken { * @param amount The maximum amount being delegated. */ function approveDelegation(address delegatee, uint256 amount) external; + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); } diff --git a/basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeMath.sol b/basic/21-aave-uni-loan/contracts/libraries/SafeMath.sol similarity index 100% rename from basic/21-aave-uni-loan/contracts/dependencies/openzeppelin/contracts/SafeMath.sol rename to basic/21-aave-uni-loan/contracts/libraries/SafeMath.sol diff --git a/basic/21-aave-uni-loan/hardhat.config.js b/basic/21-aave-uni-loan/hardhat.config.js index c06aec749..ca737f8eb 100644 --- a/basic/21-aave-uni-loan/hardhat.config.js +++ b/basic/21-aave-uni-loan/hardhat.config.js @@ -25,7 +25,7 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { * @type import('hardhat/config').HardhatUserConfig */ module.exports = { - defaultNetwork: "ropsten", + defaultNetwork: "matic", networks: { hardhat: { forking: { @@ -34,7 +34,7 @@ module.exports = { } }, localhost: { - url: "http://localhost:8545" + url: "http://127.0.0.1:8545" }, ropsten: { url: "https://ropsten.infura.io/v3/" + process.env.INFURA_ID, diff --git a/basic/21-aave-uni-loan/package.json b/basic/21-aave-uni-loan/package.json index 78794b51d..80a7897d4 100644 --- a/basic/21-aave-uni-loan/package.json +++ b/basic/21-aave-uni-loan/package.json @@ -14,7 +14,6 @@ "eslint-plugin-prettier": "^3.4.1", "eslint-plugin-promise": "^5.1.0", "ethereum-waffle": "^3.4.0", - "ethers": "^5.4.7", "fs": "0.0.1-security", "hardhat": "^2.22.2", "hardhat-gas-reporter": "^1.0.4", diff --git a/basic/21-aave-uni-loan/scripts/deploy.js b/basic/21-aave-uni-loan/scripts/deploy.js index 665de30c5..7d503ea8a 100644 --- a/basic/21-aave-uni-loan/scripts/deploy.js +++ b/basic/21-aave-uni-loan/scripts/deploy.js @@ -2,7 +2,6 @@ const fs = require("fs"); const chalk = require("chalk"); const { config, ethers, tenderly } = require("hardhat"); -const { utils } = require("ethers"); const R = require("ramda"); const main = async () => { @@ -22,9 +21,9 @@ const main = async () => { } let maticConfig = { - lendingPoolAddressesProvider: "0xd05e3E715d945B59290df0ae8eF85c1BdB684744", - //sushi - uniswapRouterAddress: "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506" + lendingPoolAddressesProvider: "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb", + //uniswap + uniswapRouterAddress: "0xE592427A0AEce92De3Edee1F18E0157C05861564" } // Kovan Aave has a dedicated mock Uniswap contract... https://kovan.etherscan.io/address/0xC18451d36aA370fDACe8d45839bF975F48f7AEa1#readContract @@ -33,7 +32,7 @@ const main = async () => { uniswapRouterAddress: "0xfcd87315f0e4067070ade8682fcdbc3006631441" } - let deployConfig = mainnetConfig + let deployConfig = maticConfig console.log("lendingPoolAddressesProvider ", deployConfig.lendingPoolAddressesProvider) const aaveApe = await deploy("AaveApe",[deployConfig.lendingPoolAddressesProvider, deployConfig.uniswapRouterAddress]) @@ -89,7 +88,8 @@ const abiEncodeArgs = (deployed, contractArgs) => { ) { return ""; } - const encoded = utils.defaultAbiCoder.encode( + + const encoded = ethers.utils.defaultAbiCoder.encode( deployed.interface.deploy.inputs, contractArgs ); diff --git a/basic/21-aave-uni-loan/scripts/loan.js b/basic/21-aave-uni-loan/scripts/loan.js index 8e0646bd0..cb9ad254f 100644 --- a/basic/21-aave-uni-loan/scripts/loan.js +++ b/basic/21-aave-uni-loan/scripts/loan.js @@ -1,20 +1,35 @@ require('@nomiclabs/hardhat-waffle'); const { use, expect } = require('chai'); -// https://docs.aave.com/developers/deployed-contracts/v3-mainnet/ethereum-mainnet -let daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'; -let wethAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'; //weth +//https://docs.aave.com/developers/deployed-contracts/v3-mainnet/ethereum-mainnet +// let daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'; +// let wethAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'; //weth +// let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'; + +// let lendingPoolAddressesProviderAddress = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'; + +// //uniswap v3 router +// let uniswapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564'; + +// let wethGatewayAddress = '0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9'; //WrappedTokenGatewayV3 + +// // Fill in your address +// const aaveApeAddress = '0x4Dd5336F3C0D70893A7a86c6aEBe9B953E87c891'; + +//https://docs.aave.com/developers/deployed-contracts/v3-mainnet/polygon +let daiAddress = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'; +let wethAddress = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'; //wmatic let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'; -let lendingPoolAddressesProviderAddress = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'; +let lendingPoolAddressesProviderAddress = '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb'; //uniswap v3 router let uniswapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564'; -let wethGatewayAddress = '0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9'; //WrappedTokenGatewayV3 +let wethGatewayAddress = '0xC1E320966c485ebF2A0A2A6d3c0Dc860A156eB1B'; //WrappedTokenGatewayV3 // Fill in your address -const aaveApeAddress = '0x4Dd5336F3C0D70893A7a86c6aEBe9B953E87c891'; +const aaveApeAddress = '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA'; const depositEthInAave = async (pooladdress, _userAddress, _amount) => { const ethGateway = await ethers.getContractAt('IWrappedTokenGatewayV3', wethGatewayAddress); @@ -89,9 +104,7 @@ main = async () => { // variable debt let interestRateMode = 2; - //0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 await depositEthInAave(lendingpool.address, deployer.address, '0.1'); - await delegateCreditToTheApe(daiAddress, interestRateMode); let result = await aaveApe.getAvailableBorrowInAsset(daiAddress, deployer.address); @@ -99,13 +112,14 @@ main = async () => { console.log('begin ape'); //tx = await aaveApe['ape'](wethAddress, daiAddress, interestRateMode) + tx = await aaveApe['superApe'](wethAddress, daiAddress, interestRateMode, 1); await tx.wait(); let aToken = await getAToken(wethAddress); let debtToken = await getDebtToken(daiAddress, interestRateMode, true); // console.log("debtToken: ", debtToken) - + tx = await aToken.approve(aaveApe.address, ethers.constants.MaxUint256); await tx.wait(); console.log('atoken approve successfully. '); @@ -114,7 +128,7 @@ main = async () => { console.log('aBalanceBefore: ', aBalanceBefore.toString()); let debtBalanceBefore = await debtToken.balanceOf(userAddress); console.log('debtBalanceBefore: ', debtBalanceBefore.toString()); - + tx = await aaveApe['unwindApe'](wethAddress, daiAddress, interestRateMode); await tx.wait(); @@ -124,6 +138,8 @@ main = async () => { console.log('debtBalanceAfter: ', debtBalanceAfter.toString()); await aToken.approve(wethGatewayAddress,ethers.constants.MaxUint256 ) + console.log('atoken approve successfully. '); + await withdrawEthInAave(lendingpool.address, userAddress, aBalanceAfter) }; diff --git a/basic/21-aave-uni-loan/scripts/query.js b/basic/21-aave-uni-loan/scripts/query.js index a0cec3932..7632744eb 100644 --- a/basic/21-aave-uni-loan/scripts/query.js +++ b/basic/21-aave-uni-loan/scripts/query.js @@ -7,22 +7,22 @@ let exp = BigNumber.from("10").pow(18); let exp1 = BigNumber.from("10").pow(27); // matic address -//https://docs.aave.com/developers/v/2.0/deployed-contracts/matic-polygon-market -let daiAddress = '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063'; -let wmaticAddress = '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'; //wmatic +//https://docs.aave.com/developers/deployed-contracts/v3-mainnet/polygon +let daiAddress = '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'; +let wmaticAddress = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270'; //wmatic let wethAddress = '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'; //weth - let wbtcAddress = '0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6'; //weth -let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'; + let wbtcAddress = '0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6'; //wbtc +let usdcAddress = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'; -let lendingPoolAddressesProviderAddress = '0xd05e3E715d945B59290df0ae8eF85c1BdB684744'; +let lendingPoolAddressesProviderAddress = '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb'; //sushi -let uniswapRouterAddress = '0x1b02da8cb0d097eb8d57a175b88c7d8b47997506'; +let uniswapRouterAddress = '0xE592427A0AEce92De3Edee1F18E0157C05861564'; -let wethGatewayAddress = '0xbEadf48d62aCC944a06EEaE0A9054A90E5A7dc97'; +let wethGatewayAddress = '0xC1E320966c485ebF2A0A2A6d3c0Dc860A156eB1B'; // Fill in your address -const aaveApeAddress = '0xddb2d92d5a0EDcb03c013322c7BAe92734AA4597'; +const aaveApeAddress = '0x4699f609F4FD97A3cf74CB63EFf5cd1200Dfe3dA'; const getAToken = async (_asset) => { @@ -34,9 +34,9 @@ const getAToken = async (_asset) => { }; const getLendingPool = async () => { - const lendingPoolAddressesProvider = await ethers.getContractAt('ILendingPoolAddressesProvider', lendingPoolAddressesProviderAddress); - let lendingPoolAddress = await lendingPoolAddressesProvider['getLendingPool'](); - let lendingPool = await ethers.getContractAt('ILendingPool', lendingPoolAddress); + const lendingPoolAddressesProvider = await ethers.getContractAt('IPoolAddressesProvider', lendingPoolAddressesProviderAddress); + let lendingPoolAddress = await lendingPoolAddressesProvider['getPool'](); + let lendingPool = await ethers.getContractAt('IPool', lendingPoolAddress); return lendingPool; }; @@ -96,8 +96,8 @@ const querySql = ` const url = { - matic: 'https://api.thegraph.com/subgraphs/name/aave/aave-v2-matic', - mainnet: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v2', + matic: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3-polygon', + mainnet: 'https://api.thegraph.com/subgraphs/name/aave/protocol-v3', } const getInterest = async (url, graphQuery,variables,interestRateMode) => { @@ -167,7 +167,10 @@ const getInterest = async (url, graphQuery,variables,interestRateMode) => { // console.log("Stable Debt: ",stableDebt) } - tota_interest[symbol] = (total_repay[symbol]["amount"] + currentDebt - total_borrow[symbol]["amount"]) / 10 ** total_borrow[symbol]["decimals"] + tota_interest[symbol] = ( + total_repay[symbol]["amount"] + + currentDebt + - total_borrow[symbol]["amount"]) / 10 ** total_borrow[symbol]["decimals"] } @@ -178,15 +181,14 @@ const getInterest = async (url, graphQuery,variables,interestRateMode) => { main = async () => { const [deployer] = await ethers.getSigners(); let fish = process.env.TARGET_ADDRESS.toLowerCase() - console.log(fish) + console.log("target:", fish) - const aaveApe = await ethers.getContractAt('AaveApe', aaveApeAddress); const lendingPool = await getLendingPool(); console.log('lendingPool:', lendingPool.address); - let reserveData = await aaveApe.getAaveAssetReserveData(usdcAddress); - //console.log("usdc reserveData: " , reserveData ) + let reserveData = await aaveApe.getAaveAssetReserveData(daiAddress); + //console.log("dai reserveData: " , reserveData ) // variable debt let interestRateMode = 2; @@ -196,24 +198,24 @@ main = async () => { // console.log("userdata: ", useraccount); console.log("healthFactor: ", useraccount.healthFactor.mul(BigNumber.from("100")).div(exp).toString()); - console.log("totalCollateralETH: ", useraccount.totalCollateralETH.div(exp).toString()); - console.log("currentLiquidationThreshold: ", useraccount.currentLiquidationThreshold.toString()); - console.log("ltv: ", useraccount.ltv.toString()); - - let reserveData1 = await lendingPool.getReserveData(usdcAddress); - console.log("usdc borrow variable rate: ", reserveData1.currentVariableBorrowRate.mul(BigNumber.from("10000")).div(exp1).toString()); + console.log("totalCollateralBase: %f USD", useraccount.totalCollateralBase.mul(BigNumber.from(100)).div(10**8).toNumber() / 100); + console.log("currentLiquidationThreshold: %f %", useraccount.currentLiquidationThreshold.toNumber() / 100); + console.log("ltv: %f %", useraccount.ltv.toNumber() / 100); + + let reserveData1 = await lendingPool.getReserveData(daiAddress); + console.log("dai borrow variable rate: %f %", reserveData1.currentVariableBorrowRate.mul(BigNumber.from("10000")).div(exp1).toNumber() / 100); //console.log("usdc borrow stable rate: ", reserveData1.currentStableBorrowRate.mul(BigNumber.from("10000")).div(exp1).toString()); - console.log("usdc deposit rate: ", reserveData1.currentLiquidityRate.mul(BigNumber.from("10000")).div(exp1).toString()); - console.log("usdc borrow index: ", reserveData1.variableBorrowIndex.mul(BigNumber.from("10000")).div(exp1).toString()); + console.log("dai supply rate: %f %", reserveData1.currentLiquidityRate.mul(BigNumber.from("10000")).div(exp1).toNumber() / 100); + console.log("dai borrow index: ", reserveData1.variableBorrowIndex.mul(BigNumber.from("10000")).div(exp1).toNumber() / 100); - let result = await aaveApe.getAvailableBorrowInAsset(usdcAddress, fish); - console.log('available borrow usdc: ', result.toString()); + let result = await aaveApe.getAvailableBorrowInAsset(daiAddress, fish); + console.log('user available borrow dai: %f USD', result.mul(BigNumber.from(1000)).div(exp).toNumber() / 1000); - let aToken = await getAToken(wethAddress); - let aTokenbtc = await getAToken(wbtcAddress); + let aToken = await getAToken(wmaticAddress); + // let aTokenbtc = await getAToken(wbtcAddress); // console.log("aToken: ", aToken) - let debtToken = await getDebtToken(usdcAddress, interestRateMode, true); + let debtToken = await getDebtToken(daiAddress, interestRateMode, true); // console.log("debtToken: ", debtToken) // let aBalanceBefore = await aToken.balanceOf(fish); diff --git a/basic/21-aave-uni-loan/test/test.js b/basic/21-aave-uni-loan/test/test.js index ae472ce56..314056eb3 100644 --- a/basic/21-aave-uni-loan/test/test.js +++ b/basic/21-aave-uni-loan/test/test.js @@ -1,29 +1,32 @@ require("@nomiclabs/hardhat-waffle"); const { use, expect } = require("chai"); +// ethereum mainnet addresses let daiAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F" let wethAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" -let usdcAddress = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" +let usdcAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" -let lendingPoolAddressesProviderAddress = "0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5" -let uniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D" +let lendingPoolAddressesProviderAddress = "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e" +let uniswapRouterAddress = "0xE592427A0AEce92De3Edee1F18E0157C05861564" -let wethGatewayAddress = "0xDcD33426BA191383f1c9B431A342498fdac73488" +let wethGatewayAddress = "0x893411580e590D62dDBca8a703d61Cc4A8c7b2b9" -const depositEthInAave = async (_userAddress, _amount) => { +const depositEthInAave = async (_poolAddress, _userAddress, _amount) => { - const ethGateway = await ethers.getContractAt('WETHGateway', wethGatewayAddress) + const ethGateway = await ethers.getContractAt('IWrappedTokenGatewayV3', wethGatewayAddress) let metadata = { value: ethers.utils.parseEther(_amount) } - let ethDeposit = await ethGateway['depositETH'](_userAddress, 0, metadata) + + let ethDeposit = await ethGateway.depositETH(_poolAddress, _userAddress, 0, metadata) + // console.log('eth deposit successfully'); } const getLendingPool = async () => { - const lendingPoolAddressesProvider = await ethers.getContractAt('ILendingPoolAddressesProvider', lendingPoolAddressesProviderAddress) - let lendingPoolAddress = await lendingPoolAddressesProvider['getLendingPool']() - let lendingPool = await ethers.getContractAt('ILendingPool', lendingPoolAddress) + const lendingPoolAddressesProvider = await ethers.getContractAt('IPoolAddressesProvider', lendingPoolAddressesProviderAddress) + let lendingPoolAddress = await lendingPoolAddressesProvider['getPool']() + let lendingPool = await ethers.getContractAt('IPool', lendingPoolAddress) return lendingPool } @@ -67,10 +70,10 @@ describe("AaveApe", function () { const AaveApe = await ethers.getContractFactory("AaveApe"); aaveApe = await AaveApe.deploy(lendingPoolAddressesProviderAddress, uniswapRouterAddress); - const [user] = await ethers.getSigners(); - userAddress = user.address - + userAddress = user.address; + const lendingpool = await getLendingPool(); + pooladdress = lendingpool.address; }); describe("Address verification", function () { @@ -80,10 +83,10 @@ describe("AaveApe", function () { }) it("LENDING_POOL", async function () { - const _lendingPoolAddressesProvider = await ethers.getContractAt('ILendingPoolAddressesProvider', lendingPoolAddressesProviderAddress) - _lendingPoolAddress = await _lendingPoolAddressesProvider['getLendingPool']() - expect(await aaveApe.LENDING_POOL()).to.equal(_lendingPoolAddress); - }) + const _lendingPoolAddressesProvider = await ethers.getContractAt('IPoolAddressesProvider', lendingPoolAddressesProviderAddress) + _lendingPoolAddress = await _lendingPoolAddressesProvider['getPool']() + expect(await aaveApe.LENDING_POOL()).to.equal(_lendingPoolAddress); + }) }) @@ -96,7 +99,7 @@ describe("AaveApe", function () { it("Revert if the user has not delegated credit to the Ape", async function () { - await depositEthInAave(userAddress, "5") + await depositEthInAave(pooladdress, userAddress, "5") await expect(aaveApe['ape'](wethAddress, daiAddress, 2)).to.be.reverted; }) @@ -104,7 +107,7 @@ describe("AaveApe", function () { it("Succeeds if the user has collateral & has delegated credit", async function () { let interestRateMode = 2 - await depositEthInAave(userAddress, "5") + await depositEthInAave(pooladdress, userAddress, "5") await delegateCreditToTheApe(daiAddress, interestRateMode) let aToken = await getAToken(wethAddress) @@ -133,7 +136,7 @@ describe("AaveApe", function () { let interestRateMode = 2 - await depositEthInAave(userAddress, "5") + await depositEthInAave(pooladdress, userAddress, "5") await delegateCreditToTheApe(daiAddress, interestRateMode) await aaveApe['ape'](wethAddress, daiAddress, interestRateMode) await expect(aaveApe['unwindApe'](wethAddress, daiAddress, interestRateMode)).to.be.reverted; @@ -144,7 +147,7 @@ describe("AaveApe", function () { let interestRateMode = 2 - await depositEthInAave(userAddress, "5") + await depositEthInAave(pooladdress, userAddress, "5") await delegateCreditToTheApe(daiAddress, interestRateMode) // Go long USDC, which we don't have deposited @@ -159,7 +162,7 @@ describe("AaveApe", function () { let interestRateMode = 2 - await depositEthInAave(userAddress, "5") + await depositEthInAave(pooladdress, userAddress, "5") await delegateCreditToTheApe(daiAddress, interestRateMode) await aaveApe['ape'](wethAddress, daiAddress, interestRateMode)