Skip to content

Commit

Permalink
Add more frxETH/WETH fork tests
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 committed Sep 27, 2023
1 parent a39dba7 commit 6a0a4cb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 36 deletions.
76 changes: 52 additions & 24 deletions contracts/test/_fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,18 +1733,8 @@ async function convexOETHMetaVaultFixture(
weth,
} = fixture;

await impersonateAndFundAddress(
weth.address,
[
"0x8EB8a3b98659Cce290402893d0123abb75E3ab28",
"0x741AA7CFB2c7bF2A1E7D4dA2e3Df6a56cA4131F3",
"0x57757E3D981446D585Af0D9Ae4d7DF6D64647806",
"0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3",
"0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44",
],
// Josh is loaded with weth
josh.getAddress()
);
// Load up josh with WETH
mintWETH(weth, josh, "1000000");

// Get some CRV from most loaded contracts/wallets
await impersonateAndFundAddress(
Expand Down Expand Up @@ -1860,23 +1850,32 @@ async function convexFrxEthFixture(
) {
const fixture = await oethDefaultFixture();

const { convexFrxEthWethStrategy, oethVault, josh, strategist, weth } =
fixture;
const {
convexFrxEthWethStrategy,
oethVault,
josh,
strategist,
frxETH,
weth,
} = fixture;

// Get some WETH from most loaded contracts/wallets
// Get some frxETH from most loaded contracts/wallets
await impersonateAndFundAddress(
weth.address,
frxETH.address,
[
"0x8EB8a3b98659Cce290402893d0123abb75E3ab28",
"0x741AA7CFB2c7bF2A1E7D4dA2e3Df6a56cA4131F3",
"0x57757E3D981446D585Af0D9Ae4d7DF6D64647806",
"0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3",
"0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44",
"0xa1F8A6807c402E4A15ef4EBa36528A3FED24E577",
"0x9c3B46C0Ceb5B9e304FCd6D88Fc50f7DD24B31Bc",
"0x4d9f9D15101EEC665F77210cB999639f760F831E",
"0x47D5E1679Fe5f0D9f0A657c6715924e33Ce05093",
"0x2F08F4645d2fA1fB12D2db8531c0c2EA0268BdE2",
],
// Josh is loaded with weth
// Josh is loaded with frxETH
josh.getAddress()
);

// Load up josh with WETH
mintWETH(weth, josh, "1000000");

// Get some CRV from most loaded contracts/wallets
await impersonateAndFundAddress(
addresses.mainnet.CRV,
Expand All @@ -1891,6 +1890,11 @@ async function convexFrxEthFixture(
josh.getAddress()
);

// Diabled default strategy for frxETH
await oethVault
.connect(strategist)
.setAssetDefaultStrategy(frxETH.address, addresses.zero);

// Impersonate the OETH Vault
fixture.oethVaultSigner = await impersonateAndFundContract(oethVault.address);

Expand All @@ -1914,8 +1918,7 @@ async function convexFrxEthFixture(
// Approve the Vault to transfer WETH
await weth.connect(josh).approve(oethVault.address, wethAmount);

// Mint OETH with WETH
// This will sit in the vault, not the strategy
// Mint OETH with WETH. This will sit in the vault, not the strategy
await oethVault.connect(josh).mint(weth.address, wethAmount, 0);

// Add WETH to the Curve pool
Expand All @@ -1931,6 +1934,31 @@ async function convexFrxEthFixture(
}
}

// mint some OETH using frxETH is configured
if (config?.frxEthMintAmount > 0) {
const frxEthAmount = parseUnits(config.frxEthMintAmount.toString());
await oethVault.connect(josh).rebase();
await oethVault.connect(josh).allocate();

// Approve the Vault to transfer frxETH
await frxETH.connect(josh).approve(oethVault.address, frxEthAmount);

// Mint OETH with frxETH. This will sit in the vault, not the strategy
await oethVault.connect(josh).mint(frxETH.address, frxEthAmount, 0);

// Add frxETH to the Curve pool
if (config?.depositToStrategy) {
// The strategist deposits the frxETH to the strategy
await oethVault
.connect(strategist)
.depositToStrategy(
convexFrxEthWethStrategy.address,
[frxETH.address],
[frxEthAmount]
);
}
}

return fixture;
}

Expand Down
28 changes: 16 additions & 12 deletions contracts/test/strategies/convex-frxeth.fork-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ forkOnlyDescribe("ForkTest: Convex frxETH/WETH Strategy", function () {
});
});

describe("with some WETH in the vault", () => {
describe("with some WETH and frxETH in the vault", () => {
const loadFixture = createFixtureLoader(convexFrxEthFixture, {
wethMintAmount: 5000,
frxEthMintAmount: 4000,
depositToStrategy: false,
});
beforeEach(async () => {
Expand All @@ -136,7 +137,6 @@ forkOnlyDescribe("ForkTest: Convex frxETH/WETH Strategy", function () {
convexFrxEthWethStrategy,
oeth,
curveFrxEthWethPool,
oethVault,
oethVaultSigner,
weth,
} = fixture;
Expand All @@ -146,12 +146,6 @@ forkOnlyDescribe("ForkTest: Convex frxETH/WETH Strategy", function () {
const oethSupplyBefore = await oeth.totalSupply();
const curveBalancesBefore = await curveFrxEthWethPool.get_balances();

log(
`Vault weth balance ${formatUnits(
await weth.balanceOf(oethVault.address)
)}`
);

// Vault transfers WETH to strategy
await weth
.connect(oethVaultSigner)
Expand Down Expand Up @@ -204,25 +198,29 @@ forkOnlyDescribe("ForkTest: Convex frxETH/WETH Strategy", function () {
await expect(tx).to.revertedWith("Caller is not the Vault");
}
});
it("Only vault can deposit all WETH to strategy", async function () {
it("Only vault can deposit frxETH and WETH assets to the strategy", async function () {
const {
convexFrxEthWethStrategy,
curveFrxEthWethPool,
oethVaultSigner,
strategist,
timelock,
josh,
frxETH,
weth,
} = fixture;

const depositAmount = parseUnits("50");
const wethDepositAmount = parseUnits("5000");
const frxEthDepositAmount = parseUnits("4000");
await weth
.connect(oethVaultSigner)
.transfer(convexFrxEthWethStrategy.address, depositAmount);
.transfer(convexFrxEthWethStrategy.address, wethDepositAmount);
await frxETH
.connect(oethVaultSigner)
.transfer(convexFrxEthWethStrategy.address, frxEthDepositAmount);

for (const signer of [strategist, timelock, josh]) {
const tx = convexFrxEthWethStrategy.connect(signer).depositAll();

await expect(tx).to.revertedWith("Caller is not the Vault");
}

Expand All @@ -235,6 +233,12 @@ forkOnlyDescribe("ForkTest: Convex frxETH/WETH Strategy", function () {
_asset: weth.address,
_pToken: curveFrxEthWethPool.address,
});
await expect(tx)
.to.emit(convexFrxEthWethStrategy, "Deposit")
.withNamedArgs({
_asset: frxETH.address,
_pToken: curveFrxEthWethPool.address,
});
});
});

Expand Down

0 comments on commit 6a0a4cb

Please sign in to comment.