Skip to content

Commit

Permalink
test: add yieldDeposit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xashu committed May 21, 2024
1 parent 58d3eea commit 3be73a8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
8 changes: 6 additions & 2 deletions test/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ contract BaseTest is Test {
AaveYieldAggregator public aaveYieldAggregator;
BlankYieldAggregator public blankYieldAggregator;

address public receiver = address(999);
address public owner = address(1);
uint8 public defaultCurveType = 0;
address public owner = makeAddr("owner");
address public addrAlice = makeAddr("addrAlice");
address public addrBob = makeAddr("addrBob");
address public referralReceiver = makeAddr("referralReceiver");
address public yieldReceiver = makeAddr("yieldReceiver");

/**
* @dev Below are the related token/contract addresses on the Optimism mainnet.
Expand Down
11 changes: 3 additions & 8 deletions test/unit/SharesFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { IYieldAggregator } from "contracts/interface/IYieldAggregator.sol";
import { BaseTest } from "../BaseTest.t.sol";

contract SharesFactoryTests is BaseTest {
uint8 public defaultCurveType = 0;
address public addrAlice = address(2);
address public addrBob = address(3);
address public referralReceiver = address(4);

function setUp() public {
createFactory();
_setUpShare();
Expand Down Expand Up @@ -331,11 +326,11 @@ contract SharesFactoryTests is BaseTest {

vm.prank(addrAlice);
vm.expectRevert(bytes("Ownable: caller is not the owner"));
sharesFactory.claimYield(maxAmount, receiver);
sharesFactory.claimYield(maxAmount, yieldReceiver);

vm.prank(owner);
vm.expectRevert(bytes("Insufficient yield"));
sharesFactory.claimYield(maxAmount + 1, receiver);
sharesFactory.claimYield(maxAmount + 1, yieldReceiver);
}

function test_getBuyPriceAfterFeeFailed() public {
Expand Down Expand Up @@ -377,7 +372,7 @@ contract SharesFactoryTests is BaseTest {

function test_safeTransferETHWithZero() public {
vm.prank(owner);
sharesFactory.claimYield(0, receiver);
sharesFactory.claimYield(0, yieldReceiver);
}

/*
Expand Down
62 changes: 45 additions & 17 deletions test/unit/YieldAggregator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

pragma solidity 0.8.25;

import { SharesFactoryV1 } from "contracts/core/SharesFactoryV1.sol";
import { console } from "forge-std/console.sol";
import { BaseTest } from "../BaseTest.t.sol";

contract YieldAggregatorTests is BaseTest {
uint8 public curveType = 0;
address public addrAlice = address(1);
address public addrBob = address(2);
address public referralReceiver = address(3);
uint256 public defaultYieldBuffer = 1e12;

function setUp() public {
Expand All @@ -26,22 +22,54 @@ contract YieldAggregatorTests is BaseTest {
}

function test_setYieldBuffer() public {
// TODO: fix below
_testBuyShares();
vm.prank(owner);
aaveYieldAggregator.setYieldBuffer(1e11);
assertEq(aaveYieldAggregator.yieldBuffer(), 1e11);

vm.warp(YIELD_CLAIM_TIME);
uint256 depositedETHAmount = sharesFactory.depositedETHAmount();
uint256 maxYield = aaveYieldAggregator.yieldMaxClaimable(depositedETHAmount);
assertEq(depositedETHAmount, 10000227777777775);
vm.prank(addrAlice);
vm.expectRevert(bytes("Ownable: caller is not the owner"));
aaveYieldAggregator.setYieldBuffer(1e11);
}

uint256 withdrawableETHAmount = aWETH.balanceOf(address(sharesFactory));
uint256 yieldBuffer = withdrawableETHAmount - depositedETHAmount - maxYield;
assertEq(yieldBuffer, defaultYieldBuffer);
function test_yieldDepost() public {
// Mock eth balance, and call yieldDeposit
vm.deal(address(aaveYieldAggregator), 10 ether);
vm.prank(address(sharesFactory));
aaveYieldAggregator.yieldDeposit();
assertTrue(aWETH.balanceOf(address(sharesFactory)) == 10 ether);
assertTrue(address(aaveYieldAggregator).balance == 0);

// Migrate to BlankYieldAggregator
// Mock eth balance, and call yieldDeposit
vm.prank(owner);
aaveYieldAggregator.setYieldBuffer(1e11);
uint256 maxYieldAfter = aaveYieldAggregator.yieldMaxClaimable(depositedETHAmount);
assertEq(maxYieldAfter - maxYield, 1e12 - 1e11);
sharesFactory.migrate(address(blankYieldAggregator));
vm.deal(address(blankYieldAggregator), 10 ether);
vm.prank(address(sharesFactory));
blankYieldAggregator.yieldDeposit();
assertTrue(address(sharesFactory).balance == 20 ether);
assertTrue(address(blankYieldAggregator).balance == 0);

vm.expectRevert(bytes("Only factory"));
aaveYieldAggregator.yieldDeposit();
}

function test_yieldWithdraw() public {
// Sell shares
// Claim yield
// Migrate YieldAggregator
// Check aWETH / ETH balance
}

function test_yieldBalanceOf() public {

}

function test_yieldToken() public {

}

function test_yieldMaxClaimable() public {

}

function _testBuyShares() public {
Expand Down

0 comments on commit 3be73a8

Please sign in to comment.