Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
WIP: fixing yield
Browse files Browse the repository at this point in the history
  • Loading branch information
fiando committed Nov 22, 2024
1 parent 31bdc6b commit 0facc2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
27 changes: 13 additions & 14 deletions src/Eduena.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract Eduena is ERC20, ReentrancyGuard {

USDe.safeTransferFrom(msg.sender, address(this), amount);
_stake(amount);
updateYield();
}

function _stake(uint256 amount) internal {
Expand All @@ -74,7 +75,7 @@ contract Eduena is ERC20, ReentrancyGuard {
_burn(recipient, shares);
sUSDe.transfer(recipient, amount);
emit Withdraw(msg.sender, amount);
// updateYield();
updateYield();
}

function distribute(
Expand All @@ -90,21 +91,19 @@ contract Eduena is ERC20, ReentrancyGuard {
}

//FIXME: Fix the logic of this function
function updateYield() public {
if (lastAssetValueInUSDe == 0) {
lastAssetValueInUSDe = sUSDe.previewRedeem(
sUSDe.balanceOf(address(this))
);
}

if (lastAssetValueInUSDe > 0) {
uint256 yield = sUSDe.previewRedeem(
sUSDe.balanceOf(address(this))
) - lastAssetValueInUSDe;
function updateYield() private {
uint256 currentAssetValueInUSDe = sUSDe.previewRedeem(
sUSDe.balanceOf(address(this))
);
console.log(lastAssetValueInUSDe);
console.log(currentAssetValueInUSDe);

if (currentAssetValueInUSDe < lastAssetValueInUSDe) {
totalUnclaimedYieldInUSDe = 0;
} else {
uint256 yield = currentAssetValueInUSDe - lastAssetValueInUSDe;
totalUnclaimedYieldInUSDe += yield;

console.log(totalUnclaimedYieldInUSDe);

_mint(address(this), _calculateShares(yield));
emit YieldUpdated(
sUSDe.previewRedeem(sUSDe.balanceOf(address(this))),
Expand Down
13 changes: 11 additions & 2 deletions test/Eduena.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ contract EduenaTest is Test {
eduena.deposit(amount);
vm.stopPrank();

//test yield

address rewarder = address(0x456);
uint256 reward = 10000 ether;

deal(address(usde), rewarder, reward);
vm.startPrank(rewarder);
usde.transfer(address(susde), reward);
vm.stopPrank();

amount = 1000;

deal(address(usde), user, amount);
vm.startPrank(user);
usde.approve(address(eduena), amount);
eduena.deposit(amount);
vm.stopPrank();

}

function testWithdraw() public {
Expand All @@ -74,7 +83,7 @@ contract EduenaTest is Test {
vm.startPrank(user);
eduena.withdraw(withdrawAmount);
vm.stopPrank();

assertEq(usde.balanceOf(user), 0);
assertEq(eduena.totalSupply(), 0);
assertEq(susde.balanceOf(address(eduena)), 0);
Expand Down

0 comments on commit 0facc2b

Please sign in to comment.