diff --git a/.gitmodules b/.gitmodules index 566c6bf..024e485 100644 --- a/.gitmodules +++ b/.gitmodules @@ -12,6 +12,6 @@ [submodule "lib/erc3156"] path = lib/erc3156 url = https://github.com/alcueca/erc3156 -[submodule "lib/erc3156pp"] - path = lib/erc3156pp - url = https://github.com/alcueca/erc3156pp +[submodule "lib/erc7399"] + path = lib/erc7399 + url = https://github.com/alcueca/erc7399 diff --git a/README.md b/README.md index bfdef51..4529207 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Foundry Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license] -[gitpod]: https://gitpod.io/#https://github.com/alcueca/erc3156pp-wrappers +[gitpod]: https://gitpod.io/#https://github.com/alcueca/erc7399-wrappers [gitpod-badge]: https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-FFB45B?logo=gitpod -[gha]: https://github.com/alcueca/erc3156pp-wrappers/actions -[gha-badge]: https://github.com/alcueca/erc3156pp-wrappers/actions/workflows/ci.yml/badge.svg +[gha]: https://github.com/alcueca/erc7399-wrappers/actions +[gha-badge]: https://github.com/alcueca/erc7399-wrappers/actions/workflows/ci.yml/badge.svg [foundry]: https://getfoundry.sh/ [foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg [license]: https://opensource.org/licenses/MIT diff --git a/lib/erc3156pp b/lib/erc3156pp deleted file mode 160000 index 56ba9df..0000000 --- a/lib/erc3156pp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 56ba9dfdee8ad34150bc77de2bb67c950a1bb415 diff --git a/lib/erc7399 b/lib/erc7399 new file mode 160000 index 0000000..6f3740b --- /dev/null +++ b/lib/erc7399 @@ -0,0 +1 @@ +Subproject commit 6f3740b8267d1b24874a8e63ca607b076c21b149 diff --git a/lib/prb-test b/lib/prb-test index 1e9ead2..8d76ad6 160000 --- a/lib/prb-test +++ b/lib/prb-test @@ -1 +1 @@ -Subproject commit 1e9ead2f7bfaedda3038081c16484b0d7d0b2712 +Subproject commit 8d76ad63d1bfa0b16bb880cfe4620a9e7e6aaa19 diff --git a/package.json b/package.json index adcc06d..08da8dd 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@alcueca/erc3156pp-wrappers", + "name": "@alcueca/erc7399-wrappers", "description": "Wrappers for existing Flash Lenders to be accessible as ERC3156++ Flash Lenders", "version": "1.0.0", "author": { diff --git a/src/BaseWrapper.sol b/src/BaseWrapper.sol index ffc3562..59cfbd9 100644 --- a/src/BaseWrapper.sol +++ b/src/BaseWrapper.sol @@ -2,12 +2,12 @@ // Thanks to ultrasecr.eth pragma solidity ^0.8.0; -import { IERC3156PPFlashLender } from "lib/erc3156pp/src/interfaces/IERC3156PPFlashLender.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC7399 } from "lib/erc7399/src/interfaces/IERC7399.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import { TransferHelper } from "./utils/TransferHelper.sol"; -abstract contract BaseWrapper is IERC3156PPFlashLender { +abstract contract BaseWrapper is IERC7399 { using TransferHelper for IERC20; event GasUsed(uint256 gasUsed); @@ -23,8 +23,8 @@ abstract contract BaseWrapper is IERC3156PPFlashLender { uint256 public expectedGas; - /// @inheritdoc IERC3156PPFlashLender - function flashLoan( + /// @inheritdoc IERC7399 + function flash( address loanReceiver, IERC20 asset, uint256 amount, @@ -91,9 +91,9 @@ abstract contract BaseWrapper is IERC3156PPFlashLender { } /// @dev Measure and record gas used in flash loans - function setExpectedGas(IERC20 asset) external returns (uint256 gasUsed){ + function setExpectedGas(IERC20 asset) external returns (uint256 gasUsed) { uint256 gasLeftBefore = gasleft(); - this.flashLoan(address(this), asset, 10 ** asset.decimals(), "", this.gasCallback); + this.flash(address(this), asset, 10 ** asset.decimals(), "", this.gasCallback); gasUsed = gasLeftBefore - gasleft(); expectedGas = gasUsed; diff --git a/src/aave/AaveWrapper.sol b/src/aave/AaveWrapper.sol index 0581d3f..60a4528 100644 --- a/src/aave/AaveWrapper.sol +++ b/src/aave/AaveWrapper.sol @@ -8,7 +8,7 @@ import { ReserveConfiguration } from "./interfaces/ReserveConfiguration.sol"; import { IPoolAddressesProvider } from "./interfaces/IPoolAddressesProvider.sol"; import { IFlashLoanSimpleReceiver } from "./interfaces/IFlashLoanSimpleReceiver.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import { FixedPointMathLib } from "lib/solmate/src/utils/FixedPointMathLib.sol"; import { BaseWrapper } from "../BaseWrapper.sol"; diff --git a/src/balancer/BalancerWrapper.sol b/src/balancer/BalancerWrapper.sol index d3f6bfa..4046dd3 100644 --- a/src/balancer/BalancerWrapper.sol +++ b/src/balancer/BalancerWrapper.sol @@ -8,7 +8,7 @@ import { IFlashLoaner } from "./interfaces/IFlashLoaner.sol"; import { Arrays } from "../utils/Arrays.sol"; import { FixedPointMathLib } from "lib/solmate/src/utils/FixedPointMathLib.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import { BaseWrapper } from "../BaseWrapper.sol"; diff --git a/src/erc3156/ERC3156Wrapper.sol b/src/erc3156/ERC3156Wrapper.sol index c524e33..e0349d9 100644 --- a/src/erc3156/ERC3156Wrapper.sol +++ b/src/erc3156/ERC3156Wrapper.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import { IERC3156FlashLender } from "lib/erc3156/contracts/interfaces/IERC3156FlashLender.sol"; import { IERC3156FlashBorrower } from "lib/erc3156/contracts/interfaces/IERC3156FlashBorrower.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import { BaseWrapper } from "../BaseWrapper.sol"; diff --git a/src/uniswapV3/UniswapV3Wrapper.sol b/src/uniswapV3/UniswapV3Wrapper.sol index 39635b5..bd1d97a 100644 --- a/src/uniswapV3/UniswapV3Wrapper.sol +++ b/src/uniswapV3/UniswapV3Wrapper.sol @@ -6,7 +6,7 @@ import { IUniswapV3FlashCallback } from "./interfaces/callback/IUniswapV3FlashCa import { IUniswapV3Pool } from "./interfaces/IUniswapV3Pool.sol"; import { PoolAddress } from "./interfaces/PoolAddress.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import { BaseWrapper } from "../BaseWrapper.sol"; @@ -112,9 +112,11 @@ contract UniswapV3Wrapper is BaseWrapper, IUniswapV3FlashCallback { require(msg.sender == address(_activePool), "UniswapV3Wrapper: Only active pool"); uint256 fee = fee0 > 0 ? fee0 : fee1; - IERC20 asset = IERC20(fee0 > 0 ? IUniswapV3Pool(msg.sender).token0() : IUniswapV3Pool(msg.sender).token1()); // TODO: Wouldn't it be cheaper to pass this on `params`? + IERC20 asset = IERC20(fee0 > 0 ? IUniswapV3Pool(msg.sender).token0() : IUniswapV3Pool(msg.sender).token1()); // TODO: + // Wouldn't it be cheaper to pass this on `params`? (uint256 amount, bytes memory data) = abi.decode(params, (uint256, bytes)); - // uint256 amount = asset.balanceOf(address(this)); // TODO: This is not the amount we borrowed, but the amount we have in the contract. We should use the amount in data or calculate a delta + // uint256 amount = asset.balanceOf(address(this)); // TODO: This is not the amount we borrowed, but the amount + // we have in the contract. We should use the amount in data or calculate a delta bridgeToCallback(asset, amount, fee, data); } diff --git a/src/utils/TransferHelper.sol b/src/utils/TransferHelper.sol index 95c6084..a8e337f 100644 --- a/src/utils/TransferHelper.sol +++ b/src/utils/TransferHelper.sol @@ -2,7 +2,7 @@ // Taken from https://github.com/Uniswap/uniswap-lib/blob/master/src/libraries/TransferHelper.sol pragma solidity ^0.8.0; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import "./RevertMsgExtractor.sol"; // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false diff --git a/test/AaveWrapper.t.sol b/test/AaveWrapper.t.sol index 7c300a4..4b7bdf2 100644 --- a/test/AaveWrapper.t.sol +++ b/test/AaveWrapper.t.sol @@ -52,7 +52,7 @@ contract AaveWrapperTest is PRBTest, StdCheats { // Test the return values (bytes32 callbackReturn) = abi.decode(result, (bytes32)); - assertEq(uint256(callbackReturn), uint256(borrower.ERC3156PP_CALLBACK_SUCCESS()), "Callback failed"); + assertEq(uint256(callbackReturn), uint256(borrower.ERC7399_CALLBACK_SUCCESS()), "Callback failed"); // Test the borrower state assertEq(borrower.flashInitiator(), address(borrower)); diff --git a/test/BalancerWrapper.t.sol b/test/BalancerWrapper.t.sol index 3c94962..c50121a 100644 --- a/test/BalancerWrapper.t.sol +++ b/test/BalancerWrapper.t.sol @@ -55,7 +55,7 @@ contract BalancerWrapperTest is PRBTest, StdCheats { // Test the return values (bytes32 callbackReturn) = abi.decode(result, (bytes32)); - assertEq(uint256(callbackReturn), uint256(borrower.ERC3156PP_CALLBACK_SUCCESS()), "Callback failed"); + assertEq(uint256(callbackReturn), uint256(borrower.ERC7399_CALLBACK_SUCCESS()), "Callback failed"); // Test the borrower state assertEq(borrower.flashInitiator(), address(borrower)); diff --git a/test/BaseWrapper.t.sol b/test/BaseWrapper.t.sol index 01c8b40..c7cabb1 100644 --- a/test/BaseWrapper.t.sol +++ b/test/BaseWrapper.t.sol @@ -5,7 +5,7 @@ import { PRBTest } from "@prb/test/PRBTest.sol"; import { console2 } from "forge-std/console2.sol"; import { StdCheats } from "forge-std/StdCheats.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; import { FlashBorrower } from "./FlashBorrower.sol"; import { BaseWrapper } from "src/BaseWrapper.sol"; @@ -45,7 +45,7 @@ contract BaseWrapperTest is PRBTest, StdCheats { // Test the return values (bytes32 callbackReturn) = abi.decode(result, (bytes32)); - assertEq(uint256(callbackReturn), uint256(borrower.ERC3156PP_CALLBACK_SUCCESS()), "Callback failed"); + assertEq(uint256(callbackReturn), uint256(borrower.ERC7399_CALLBACK_SUCCESS()), "Callback failed"); // Test the wrapper state (return bytes should be cleaned up) assertEq(vm.load(address(wrapper), bytes32(uint256(0))), ""); diff --git a/test/ERC3156Wrapper.t.sol b/test/ERC3156Wrapper.t.sol index 8f8b4d0..7ddc829 100644 --- a/test/ERC3156Wrapper.t.sol +++ b/test/ERC3156Wrapper.t.sol @@ -54,7 +54,7 @@ contract ERC3156WrapperTest is PRBTest, StdCheats { // Test the return values (bytes32 callbackReturn) = abi.decode(result, (bytes32)); - assertEq(uint256(callbackReturn), uint256(borrower.ERC3156PP_CALLBACK_SUCCESS()), "Callback failed"); + assertEq(uint256(callbackReturn), uint256(borrower.ERC7399_CALLBACK_SUCCESS()), "Callback failed"); // Test the borrower state assertEq(borrower.flashInitiator(), address(borrower)); @@ -71,7 +71,7 @@ contract ERC3156WrapperTest is PRBTest, StdCheats { uint256 loan = 1e18; uint256 fee = wrapper.flashFee(dai, loan); dai.transfer(address(wrapper), fee); - + uint256 expectedGas = wrapper.setExpectedGas(dai); console2.log(expectedGas, "expectedGas"); diff --git a/test/FlashBorrower.sol b/test/FlashBorrower.sol index 8e6a078..2caaa97 100644 --- a/test/FlashBorrower.sol +++ b/test/FlashBorrower.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { IERC3156PPFlashLender } from "lib/erc3156pp/src/interfaces/IERC3156PPFlashLender.sol"; -import { IERC20 } from "lib/erc3156pp/src/interfaces/IERC20.sol"; +import { IERC7399 } from "lib/erc7399/src/interfaces/IERC7399.sol"; +import { IERC20 } from "lib/erc7399/src/interfaces/IERC20.sol"; contract LoanReceiver { function retrieve(IERC20 asset) external { @@ -11,8 +11,8 @@ contract LoanReceiver { } contract FlashBorrower { - bytes32 public constant ERC3156PP_CALLBACK_SUCCESS = keccak256("ERC3156PP_CALLBACK_SUCCESS"); - IERC3156PPFlashLender lender; + bytes32 public constant ERC7399_CALLBACK_SUCCESS = keccak256("ERC7399_CALLBACK_SUCCESS"); + IERC7399 lender; LoanReceiver loanReceiver; uint256 public flashBalance; @@ -21,7 +21,7 @@ contract FlashBorrower { uint256 public flashAmount; uint256 public flashFee; - constructor(IERC3156PPFlashLender lender_) { + constructor(IERC7399 lender_) { lender = lender_; loanReceiver = new LoanReceiver(); } @@ -49,7 +49,7 @@ contract FlashBorrower { flashBalance = IERC20(asset).balanceOf(address(this)); asset.transfer(paymentReceiver, amount + fee); - return abi.encode(ERC3156PP_CALLBACK_SUCCESS); + return abi.encode(ERC7399_CALLBACK_SUCCESS); } function onSteal( @@ -72,7 +72,7 @@ contract FlashBorrower { // do nothing - return abi.encode(ERC3156PP_CALLBACK_SUCCESS); + return abi.encode(ERC7399_CALLBACK_SUCCESS); } function onReenter( @@ -100,7 +100,7 @@ contract FlashBorrower { flashAmount += amount; flashFee += fee; - return abi.encode(ERC3156PP_CALLBACK_SUCCESS); + return abi.encode(ERC7399_CALLBACK_SUCCESS); } function onFlashLoanVoid( @@ -129,18 +129,18 @@ contract FlashBorrower { } function flashBorrow(IERC20 asset, uint256 amount) public returns (bytes memory) { - return lender.flashLoan(address(loanReceiver), asset, amount, "", this.onFlashLoan); + return lender.flash(address(loanReceiver), asset, amount, "", this.onFlashLoan); } function flashBorrowAndSteal(IERC20 asset, uint256 amount) public returns (bytes memory) { - return lender.flashLoan(address(loanReceiver), asset, amount, "", this.onSteal); + return lender.flash(address(loanReceiver), asset, amount, "", this.onSteal); } function flashBorrowAndReenter(IERC20 asset, uint256 amount) public returns (bytes memory) { - return lender.flashLoan(address(loanReceiver), asset, amount, "", this.onReenter); + return lender.flash(address(loanReceiver), asset, amount, "", this.onReenter); } function flashBorrowVoid(IERC20 asset, uint256 amount) public returns (bytes memory) { - return lender.flashLoan(address(loanReceiver), asset, amount, "", this.onFlashLoanVoid); + return lender.flash(address(loanReceiver), asset, amount, "", this.onFlashLoanVoid); } } diff --git a/test/UniswapV3Wrapper.t.sol b/test/UniswapV3Wrapper.t.sol index 73544a2..bbf3127 100644 --- a/test/UniswapV3Wrapper.t.sol +++ b/test/UniswapV3Wrapper.t.sol @@ -60,7 +60,7 @@ contract UniswapV3WrapperTest is PRBTest, StdCheats { // Test the return values (bytes32 callbackReturn) = abi.decode(result, (bytes32)); - assertEq(uint256(callbackReturn), uint256(borrower.ERC3156PP_CALLBACK_SUCCESS()), "Callback failed"); + assertEq(uint256(callbackReturn), uint256(borrower.ERC7399_CALLBACK_SUCCESS()), "Callback failed"); // Test the borrower state assertEq(borrower.flashInitiator(), address(borrower), "flashInitiator");