diff --git a/contracts/exchangeIssuance/FlashMintHyETH.sol b/contracts/exchangeIssuance/FlashMintHyETH.sol index fce75f07..4e80436d 100644 --- a/contracts/exchangeIssuance/FlashMintHyETH.sol +++ b/contracts/exchangeIssuance/FlashMintHyETH.sol @@ -35,7 +35,6 @@ import { ISetToken } from "../interfaces/ISetToken.sol"; import { IWETH} from "../interfaces/IWETH.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { DEXAdapterV2 } from "./DEXAdapterV2.sol"; -import "hardhat/console.sol"; /** @@ -146,15 +145,6 @@ contract FlashMintHyETH is Ownable, ReentrancyGuard { issuanceModule = _issuanceModule; stETH = _stETH; - address[] memory path = new address[](2); - path[0] = address(_stETH); - path[1] = DEXAdapterV2.ETH_ADDRESS; - swapData[address(_stETH)][address(0)] = DEXAdapterV2.SwapData({ - path: path, - fees: new uint24[](0), - pool: _stEthETHPool, - exchange: DEXAdapterV2.Exchange.Curve - }); IERC20(address(_stETH)).approve(_stEthETHPool, MAX_UINT256); } @@ -190,11 +180,9 @@ contract FlashMintHyETH is Ownable, ReentrancyGuard { function approveSetToken(ISetToken _setToken) external isSetToken(_setToken) { address[] memory _components = _setToken.getComponents(); for (uint256 i = 0; i < _components.length; ++i) { - console.log("Approving %s", _components[i]); IERC20(_components[i]).approve(address(issuanceModule), MAX_UINT256); } - console.log("Approving setToken %s", address(_setToken)); - _setToken.approve(address(issuanceModule), MAX_UINT256); + _setToken.approve(address(issuanceModule), MAX_UINT256); } function approveToken(IERC20 _token, address _spender, uint256 _allowance) external onlyOwner { @@ -207,6 +195,7 @@ contract FlashMintHyETH is Ownable, ReentrancyGuard { ) external payable nonReentrant returns (uint256) { (address[] memory components, uint256[] memory positions, ) = IDebtIssuanceModule(issuanceModule).getRequiredComponentIssuanceUnits(_setToken, _amountSetToken); + uint256 ethBalanceBefore = address(this).balance; for (uint256 i = 0; i < components.length; i++) { if(_isInstadapp(components[i])){ _depositIntoInstadapp(IERC4626(components[i]), positions[i]); @@ -223,9 +212,7 @@ contract FlashMintHyETH is Ownable, ReentrancyGuard { } } issuanceModule.issue(_setToken, _amountSetToken, msg.sender); - // Assumes no eth was stored in this token previously, otherwise it can be stolen - // TODO: maybe add check - msg.sender.sendValue(address(this).balance); + msg.sender.sendValue(msg.value.sub(ethBalanceBefore.sub(address(this).balance))); } function redeemExactSetForETH( @@ -247,7 +234,6 @@ contract FlashMintHyETH is Ownable, ReentrancyGuard { } IPendleMarketV3 market = pendleMarkets[IPendlePrincipalToken(components[i])]; if(market != IPendleMarketV3(address(0))){ - console.log("Withdrawing from Pendle"); _withdrawFromPendle(IPendlePrincipalToken(components[i]), positions[i], market); continue; } diff --git a/test/integration/ethereum/flashMintHyETH.spec.ts b/test/integration/ethereum/flashMintHyETH.spec.ts index b82bc8b2..614037dd 100644 --- a/test/integration/ethereum/flashMintHyETH.spec.ts +++ b/test/integration/ethereum/flashMintHyETH.spec.ts @@ -21,6 +21,7 @@ import { ADDRESS_ZERO, MAX_UINT_256 } from "@utils/constants"; import { ether } from "@utils/index"; const expect = getWaffleExpect(); +const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; if (process.env.INTEGRATIONTEST) { describe("FlashMintHyETH - Integration Test", async () => { @@ -32,7 +33,7 @@ if (process.env.INTEGRATIONTEST) { let debtIssuanceModule: IDebtIssuanceModule; // const collateralTokenAddress = addresses.tokens.stEth; - setBlockNumber(19740000, false); + setBlockNumber(19740000, true); before(async () => { [owner] = await getAccounts(); @@ -108,13 +109,12 @@ if (process.env.INTEGRATIONTEST) { addresses.tokens.pendleRswEth0624, addresses.tokens.acrossWethLP, ]; - console.log("components", components); const positions = [ - ethers.utils.parseEther("0.25"), - ethers.utils.parseEther("0.25"), - ethers.utils.parseEther("0.25"), - ethers.utils.parseEther("0.25"), - ethers.utils.parseEther("0.25"), + ethers.utils.parseEther("0.2"), + ethers.utils.parseEther("0.2"), + ethers.utils.parseEther("0.2"), + ethers.utils.parseEther("0.2"), + ethers.utils.parseEther("0.2"), ]; const modules = [addresses.setFork.debtIssuanceModuleV2]; const tokenName = "IndexCoop High Yield ETH"; @@ -148,6 +148,12 @@ if (process.env.INTEGRATIONTEST) { addresses.tokens.instadappEthV2, MAX_UINT_256, ); + await flashMintHyETH.setSwapData(addresses.tokens.stEth, ADDRESS_ZERO, { + path: [addresses.tokens.stEth, ETH_ADDRESS], + fees: [], + pool: addresses.dexes.curve.pools.stEthEth, + exchange: 4, + }); const eEthPendleToken = IPendlePrincipalToken__factory.connect( addresses.tokens.pendleEEth0624, @@ -231,13 +237,10 @@ if (process.env.INTEGRATIONTEST) { it("Can issue set token from eth", async () => { const setTokenAmount = ether(1); const setTokenBalanceBefore = await setToken.balanceOf(owner.address); - const ethBalanceBefore = await owner.wallet.getBalance(); - const maxEthIn = ether(2); + const maxEthIn = ether(1.01); await flashMintHyETH.issueExactSetFromETH(setToken.address, setTokenAmount, { value: maxEthIn, }); - const ethSpent = ethBalanceBefore.sub(await owner.wallet.getBalance()); - console.log("ethSpent", ethSpent.toString()); const setTokenBalanceAfter = await setToken.balanceOf(owner.address); expect(setTokenBalanceAfter).to.eq(setTokenBalanceBefore.add(setTokenAmount)); }); @@ -251,7 +254,7 @@ if (process.env.INTEGRATIONTEST) { const setTokenBalanceAfterIssuance = await setToken.balanceOf(owner.address); expect(setTokenBalanceAfterIssuance).to.eq(setTokenBalanceBefore.add(setTokenAmount)); await setToken.approve(flashMintHyETH.address, setTokenAmount); - const minETHOut = ether(0.9); + const minETHOut = ether(0.99); await flashMintHyETH.redeemExactSetForETH(setToken.address, setTokenAmount, minETHOut); const setTokenBalanceAfterRedemption = await setToken.balanceOf(owner.address); expect(setTokenBalanceAfterRedemption).to.eq(setTokenBalanceBefore);