Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yieltoken uni migration #154

Merged
merged 4 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion contracts/libs/LibFoundry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {LibCurve} from "../libs/LibCurve.sol";
import {LibWeightedAverage} from "../libs/LibWeightedAverage.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "hardhat/console.sol";

library LibFoundry {
event Mint(
Expand Down Expand Up @@ -53,15 +54,24 @@ library LibFoundry {
address sender = LibMeta.msgSender();
MeTokenInfo memory meTokenInfo = s.meTokens[meToken];
HubInfo memory hubInfo = s.hubs[meTokenInfo.hubId];

console.log(
"## handleMint meTokenInfo.targetHubId:%s hubInfo.updating:%s block.timestamp > hubInfo.endTime:%s",
meTokenInfo.targetHubId,
hubInfo.updating,
block.timestamp > hubInfo.endTime
);
// Handling changes
if (hubInfo.updating && block.timestamp > hubInfo.endTime) {
LibHub.finishUpdate(meTokenInfo.hubId);
} else if (meTokenInfo.targetHubId != 0) {
if (block.timestamp > meTokenInfo.endTime) {
console.log(
"## LIBFOUNDRY FINISH RESUBSCRIBE > meTokenInfo.endTime "
);
hubInfo = s.hubs[meTokenInfo.targetHubId];
meTokenInfo = LibMeToken.finishResubscribe(meToken);
} else if (block.timestamp > meTokenInfo.startTime) {
console.log("## LIBFOUNDRY poke > meTokenInfo.startTime ");
// Handle migration actions if needed
IMigration(meTokenInfo.migration).poke(meToken);
meTokenInfo = s.meTokens[meToken];
Expand Down
7 changes: 5 additions & 2 deletions contracts/migrations/UniswapSingleTransferMigration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {ISwapRouter} from "@uniswap/v3-periphery/contracts/interfaces/ISwapRoute
import {HubInfo} from "../libs/LibHub.sol";
import {MeTokenInfo} from "../libs/LibMeToken.sol";
import {Vault} from "../vaults/Vault.sol";
import "hardhat/console.sol";

/// @title Vault migrator from erc20 to erc20 (non-lp)
/// @author Carter Carlson (@cartercarlson), Chris Robison (@cbobrobison), Parv Garg (@parv3213)
Expand Down Expand Up @@ -56,7 +57,7 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
{
MeTokenInfo memory meTokenInfo = IMeTokenRegistryFacet(diamond)
.getMeTokenInfo(meToken);

console.log("## initMigration uni ");
require(
IHubFacet(diamond).getHubInfo(meTokenInfo.hubId).asset !=
IHubFacet(diamond).getHubInfo(meTokenInfo.targetHubId).asset,
Expand All @@ -75,6 +76,7 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
MeTokenInfo memory meTokenInfo = IMeTokenRegistryFacet(diamond)
.getMeTokenInfo(meToken);

console.log("## poke uni ");
if (
usts.fee != 0 && // make sure meToken is in a state of resubscription
block.timestamp > meTokenInfo.startTime && // swap can only happen after resubscribe
Expand All @@ -83,6 +85,7 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
ISingleAssetVault(
IHubFacet(diamond).getHubInfo(meTokenInfo.hubId).vault
).startMigration(meToken);
console.log("## poke WILL START SWAP !!!! uni ");
usts.started = true;
_swap(meToken);
}
Expand All @@ -100,7 +103,7 @@ contract UniswapSingleTransferMigration is ReentrancyGuard, Vault, IMigration {
HubInfo memory targetHubInfo = IHubFacet(diamond).getHubInfo(
meTokenInfo.targetHubId
);

console.log("## finishMigration uni ");
uint256 amountOut;
if (!_uniswapSingleTransfers[meToken].started) {
ISingleAssetVault(
Expand Down
7 changes: 7 additions & 0 deletions contracts/vaults/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {IHubFacet} from "../interfaces/IHubFacet.sol";
import {IMeTokenRegistryFacet} from "../interfaces/IMeTokenRegistryFacet.sol";
import {IMigrationRegistry} from "../interfaces/IMigrationRegistry.sol";
import {IVault} from "../interfaces/IVault.sol";
import "hardhat/console.sol";

/// @title MeTokens Basic Vault
/// @author Carter Carlson (@cartercarlson), Parv Garg (@parv3213), @zgorizzo69
Expand All @@ -34,6 +35,12 @@ contract Vault is IVault, ReentrancyGuard {
uint256 feeAmount
) external virtual override nonReentrant {
require(msg.sender == diamond, "!diamond");
console.log(
"## asset:%s address(this):%s depositAmount:%s",
asset,
address(this),
depositAmount
);
IERC20(asset).safeTransferFrom(from, address(this), depositAmount);
if (feeAmount > 0) {
accruedFees[asset] += feeAmount;
Expand Down
7 changes: 5 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ const config: HardhatUserConfig = {
},
mocha: {
delay: true,
timeout: 60000, // Here is 2min but can be whatever timeout is suitable for you.
timeout: 120000, // Here is 2min but can be whatever timeout is suitable for you.
},
namedAccounts: {
SwapRouter: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
Quoter: "0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6",
UNIV3Factory: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
DAI: {
default: "0x6B175474E89094C44Da98b954EedeAC495271d0F", // here this will by default take the first account as deployer
1: "0x6B175474E89094C44Da98b954EedeAC495271d0F", // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
Expand All @@ -108,7 +111,7 @@ const config: HardhatUserConfig = {
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
accounts,
blockNumber: 13310410,
blockNumber: 14448329,
},
gas: "auto",
timeout: 1800000,
Expand Down
3 changes: 0 additions & 3 deletions test/contracts/vaults/VaultYearn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ describe("Vault with Yearn Token", () => {
const tokenDeposited = ethers.utils.parseEther(
tokenDepositedInETH.toString()
);
/* after(async () => {
await resetFork(13310410);
}); */
before(async () => {
({ DAI, DAIWhale, YDAI, YDAIWhale } = await getNamedAccounts());

Expand Down
Loading