From 1cde0643d5d7f1841329044df4981b4284a29d99 Mon Sep 17 00:00:00 2001 From: Ana Julia Date: Mon, 19 Aug 2024 10:46:03 -0300 Subject: [PATCH] checkpoint --- src/BaseStaking.sol | 7 ++++--- src/DelegateStaking.sol | 6 +++++- src/Staking.sol | 3 ++- test/DelegateStaking.t.sol | 7 ++++--- test/Staking.t.sol | 3 +-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/BaseStaking.sol b/src/BaseStaking.sol index 2a5f443..4619840 100644 --- a/src/BaseStaking.sol +++ b/src/BaseStaking.sol @@ -181,9 +181,6 @@ abstract contract BaseStaking is OwnableUpgradeable, ERC20VotesUpgradeable { function convertToShares( uint256 assets ) public view virtual returns (uint256) { - console.log("totoal supply", totalSupply()); - console.log("total assets", _totalAssets()); - console.log("assets", assets); uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? assets : assets.mulDivDown(supply, _totalAssets()); @@ -241,6 +238,10 @@ abstract contract BaseStaking is OwnableUpgradeable, ERC20VotesUpgradeable { ) internal returns (uint256 shares) { shares = _previewWithdraw(amount); + console.log("balance ", balanceOf(user)); + console.log("needs ", shares); + console.log("to withdraw", amount); + // Decrease the amount from the total locked totalLocked[user] -= amount; diff --git a/src/DelegateStaking.sol b/src/DelegateStaking.sol index 9d3f35f..d3fc920 100644 --- a/src/DelegateStaking.sol +++ b/src/DelegateStaking.sol @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.26; +import {console} from "@forge-std/console.sol"; import {EnumerableSetLib} from "@solady/utils/EnumerableSetLib.sol"; import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol"; @@ -143,7 +144,7 @@ contract DelegateStaking is BaseStaking { nextStakeId = 1; // mint dead shares to avoid inflation attack - uint256 amount = 1000e18; + uint256 amount = 10_000e18; // Calculate the amount of shares to mint uint256 shares = convertToShares(amount); @@ -285,9 +286,12 @@ contract DelegateStaking is BaseStaking { require(shares > 0, UserHasNoShares()); uint256 assets = convertToAssets(shares); + console.log("user assets", assets); uint256 locked = totalLocked[user]; + console.log("locked", locked); // need the first branch as convertToAssets rounds down amount = locked >= assets ? 0 : assets - locked; + console.log("max withdrawable", amount); } } diff --git a/src/Staking.sol b/src/Staking.sol index 35e43af..f930e33 100644 --- a/src/Staking.sol +++ b/src/Staking.sol @@ -142,7 +142,8 @@ contract Staking is BaseStaking { nextStakeId = 1; // mint dead shares to avoid inflation attack - uint256 amount = 1000e18; + uint256 amount = 10_000e18; + // Calculate the amount of shares to mint uint256 shares = convertToShares(amount); diff --git a/test/DelegateStaking.t.sol b/test/DelegateStaking.t.sol index 9743247..6a71b53 100644 --- a/test/DelegateStaking.t.sol +++ b/test/DelegateStaking.t.sol @@ -727,10 +727,11 @@ contract Stake is DelegateStakingTest { delegate.unstake(bobStakeId, bobAmount - 1e5); // Alice earn less than bob - assertGt( + assertApproxEqRel( govToken.balanceOf(bob), - aliceBalanceAfterAttack, - "Alice earn more than Bob after the attack" + bobAmount, + 0.01e18, + "Bob must received the money back" ); } diff --git a/test/Staking.t.sol b/test/Staking.t.sol index 5687f3a..37e13e3 100644 --- a/test/Staking.t.sol +++ b/test/Staking.t.sol @@ -1715,8 +1715,7 @@ contract ViewFunctions is StakingTest { _jumpAhead(_jump); - // depositor 2 stakes and collect rewards from distirbutor - _mintGovToken(_depositoron2, _amount2); + _mintGovToken(_depositor2, _amount2); _setKeyper(_depositor2, true); _stake(_depositor2, _amount2);