-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from euler-xyz/feat/negative-yield-socialization
Feat: negative yield
- Loading branch information
Showing
3 changed files
with
272 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
import {FourSixTwoSixAggBase, FourSixTwoSixAgg, console2, EVault} from "../common/FourSixTwoSixAggBase.t.sol"; | ||
|
||
contract GulpTest is FourSixTwoSixAggBase { | ||
uint256 user1InitialBalance = 100000e18; | ||
uint256 amountToDeposit = 10000e18; | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
uint256 initialStrategyAllocationPoints = 500e18; | ||
_addStrategy(manager, address(eTST), initialStrategyAllocationPoints); | ||
|
||
assetTST.mint(user1, user1InitialBalance); | ||
|
||
// deposit into aggregator | ||
{ | ||
uint256 balanceBefore = fourSixTwoSixAgg.balanceOf(user1); | ||
uint256 totalSupplyBefore = fourSixTwoSixAgg.totalSupply(); | ||
uint256 totalAssetsDepositedBefore = fourSixTwoSixAgg.totalAssetsDeposited(); | ||
uint256 userAssetBalanceBefore = assetTST.balanceOf(user1); | ||
|
||
vm.startPrank(user1); | ||
assetTST.approve(address(fourSixTwoSixAgg), amountToDeposit); | ||
fourSixTwoSixAgg.deposit(amountToDeposit, user1); | ||
vm.stopPrank(); | ||
|
||
assertEq(fourSixTwoSixAgg.balanceOf(user1), balanceBefore + amountToDeposit); | ||
assertEq(fourSixTwoSixAgg.totalSupply(), totalSupplyBefore + amountToDeposit); | ||
assertEq(fourSixTwoSixAgg.totalAssetsDeposited(), totalAssetsDepositedBefore + amountToDeposit); | ||
assertEq(assetTST.balanceOf(user1), userAssetBalanceBefore - amountToDeposit); | ||
} | ||
|
||
// rebalance into strategy | ||
vm.warp(block.timestamp + 86400); | ||
{ | ||
FourSixTwoSixAgg.Strategy memory strategyBefore = fourSixTwoSixAgg.getStrategy(address(eTST)); | ||
|
||
assertEq(eTST.convertToAssets(eTST.balanceOf(address(fourSixTwoSixAgg))), strategyBefore.allocated); | ||
|
||
uint256 expectedStrategyCash = fourSixTwoSixAgg.totalAssetsAllocatable() * strategyBefore.allocationPoints | ||
/ fourSixTwoSixAgg.totalAllocationPoints(); | ||
|
||
vm.prank(user1); | ||
fourSixTwoSixAgg.rebalance(address(eTST)); | ||
|
||
assertEq(fourSixTwoSixAgg.totalAllocated(), expectedStrategyCash); | ||
assertEq(eTST.convertToAssets(eTST.balanceOf(address(fourSixTwoSixAgg))), expectedStrategyCash); | ||
assertEq((fourSixTwoSixAgg.getStrategy(address(eTST))).allocated, expectedStrategyCash); | ||
} | ||
} | ||
|
||
function testGulpAfterNegativeYieldEqualToInterestLeft() public { | ||
fourSixTwoSixAgg.gulp(); | ||
FourSixTwoSixAgg.ESRSlot memory ers = fourSixTwoSixAgg.getESRSlot(); | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
assertEq(ers.interestLeft, 0); | ||
|
||
vm.warp(block.timestamp + 2 days); | ||
fourSixTwoSixAgg.gulp(); | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
|
||
vm.warp(block.timestamp + 1 days); | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
uint256 yield; | ||
{ | ||
uint256 aggrCurrentStrategyShareBalance = eTST.balanceOf(address(fourSixTwoSixAgg)); | ||
uint256 aggrCurrentStrategyUnderlyingBalance = eTST.convertToAssets(aggrCurrentStrategyShareBalance); | ||
uint256 aggrNewStrategyUnderlyingBalance = aggrCurrentStrategyUnderlyingBalance * 11e17 / 1e18; | ||
yield = aggrNewStrategyUnderlyingBalance - aggrCurrentStrategyUnderlyingBalance; | ||
assetTST.mint(address(eTST), yield); | ||
eTST.skim(type(uint256).max, address(fourSixTwoSixAgg)); | ||
} | ||
vm.prank(user1); | ||
fourSixTwoSixAgg.harvest(address(eTST)); | ||
|
||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
|
||
vm.warp(block.timestamp + 1 days); | ||
// interest per day 23.809523809523 | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 23809523809523809523); | ||
fourSixTwoSixAgg.gulp(); | ||
ers = fourSixTwoSixAgg.getESRSlot(); | ||
assertEq(ers.interestLeft, yield - 23809523809523809523); | ||
|
||
// move close to end of smearing | ||
vm.warp(block.timestamp + 11 days); | ||
fourSixTwoSixAgg.gulp(); | ||
ers = fourSixTwoSixAgg.getESRSlot(); | ||
|
||
// mock a decrease of strategy balance by ers.interestLeft | ||
uint256 aggrCurrentStrategyBalance = eTST.balanceOf(address(fourSixTwoSixAgg)); | ||
uint256 aggrCurrentStrategyBalanceAfterNegYield = aggrCurrentStrategyBalance - ers.interestLeft; | ||
vm.mockCall( | ||
address(eTST), | ||
abi.encodeWithSelector(EVault.balanceOf.selector, address(fourSixTwoSixAgg)), | ||
abi.encode(aggrCurrentStrategyBalanceAfterNegYield) | ||
); | ||
vm.prank(user1); | ||
fourSixTwoSixAgg.harvest(address(eTST)); | ||
} | ||
|
||
function testGulpAfterNegativeYieldBiggerThanInterestLeft() public { | ||
fourSixTwoSixAgg.gulp(); | ||
FourSixTwoSixAgg.ESRSlot memory ers = fourSixTwoSixAgg.getESRSlot(); | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
assertEq(ers.interestLeft, 0); | ||
|
||
vm.warp(block.timestamp + 2 days); | ||
fourSixTwoSixAgg.gulp(); | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
|
||
vm.warp(block.timestamp + 1 days); | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
uint256 yield; | ||
{ | ||
uint256 aggrCurrentStrategyShareBalance = eTST.balanceOf(address(fourSixTwoSixAgg)); | ||
uint256 aggrCurrentStrategyUnderlyingBalance = eTST.convertToAssets(aggrCurrentStrategyShareBalance); | ||
uint256 aggrNewStrategyUnderlyingBalance = aggrCurrentStrategyUnderlyingBalance * 11e17 / 1e18; | ||
yield = aggrNewStrategyUnderlyingBalance - aggrCurrentStrategyUnderlyingBalance; | ||
assetTST.mint(address(eTST), yield); | ||
eTST.skim(type(uint256).max, address(fourSixTwoSixAgg)); | ||
} | ||
vm.prank(user1); | ||
fourSixTwoSixAgg.harvest(address(eTST)); | ||
|
||
assertEq(fourSixTwoSixAgg.interestAccrued(), 0); | ||
|
||
vm.warp(block.timestamp + 1 days); | ||
// interest per day 23.809523809523 | ||
assertEq(fourSixTwoSixAgg.interestAccrued(), 23809523809523809523); | ||
fourSixTwoSixAgg.gulp(); | ||
ers = fourSixTwoSixAgg.getESRSlot(); | ||
assertEq(ers.interestLeft, yield - 23809523809523809523); | ||
|
||
// move close to end of smearing | ||
vm.warp(block.timestamp + 11 days); | ||
fourSixTwoSixAgg.gulp(); | ||
ers = fourSixTwoSixAgg.getESRSlot(); | ||
|
||
// mock a decrease of strategy balance by ers.interestLeft | ||
uint256 aggrCurrentStrategyBalance = eTST.balanceOf(address(fourSixTwoSixAgg)); | ||
uint256 aggrCurrentStrategyBalanceAfterNegYield = aggrCurrentStrategyBalance - (ers.interestLeft * 2); | ||
vm.mockCall( | ||
address(eTST), | ||
abi.encodeWithSelector(EVault.balanceOf.selector, address(fourSixTwoSixAgg)), | ||
abi.encode(aggrCurrentStrategyBalanceAfterNegYield) | ||
); | ||
vm.prank(user1); | ||
fourSixTwoSixAgg.harvest(address(eTST)); | ||
} | ||
} |
Oops, something went wrong.