Skip to content

Commit

Permalink
Contract code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoopmann committed Apr 28, 2024
1 parent f106e87 commit 0b59e55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
20 changes: 3 additions & 17 deletions contracts/exchangeIssuance/FlashMintHyETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/**
Expand Down Expand Up @@ -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);

}
Expand Down Expand Up @@ -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 {
Expand All @@ -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]);
Expand All @@ -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(
Expand All @@ -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;
}
Expand Down
27 changes: 15 additions & 12 deletions test/integration/ethereum/flashMintHyETH.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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();
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
});
Expand All @@ -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);
Expand Down

0 comments on commit 0b59e55

Please sign in to comment.