Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto report #89

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ remappings = [
fs_permissions = [{ access = "read", path = "./"}]

[fuzz]
runs = 10_000
runs = 10_00
max_test_rejects = 1_000_000

[invariant]
Expand Down
28 changes: 25 additions & 3 deletions src/TokenizedStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ contract TokenizedStrategy {
// Strategy Status
uint8 entered; // To prevent reentrancy. Use uint8 for gas savings.
bool shutdown; // Bool that can be used to stop deposits into the strategy.
bool autoReport; // Should the strategy auto report each deposit/withdraw.
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -497,6 +498,10 @@ contract TokenizedStrategy {
) external nonReentrant returns (uint256 shares) {
// Get the storage slot for all following calls.
StrategyData storage S = _strategyStorage();

// Check if we should first accumulate profits.
if(S.autoReport && S.lastReport != block.timestamp) _report(S);

// Checking max deposit will also check if shutdown.
require(
assets <= _maxDeposit(S, receiver),
Expand Down Expand Up @@ -524,6 +529,10 @@ contract TokenizedStrategy {
) external nonReentrant returns (uint256 assets) {
// Get the storage slot for all following calls.
StrategyData storage S = _strategyStorage();

// Check if we should first accumulate profits.
if(S.autoReport && S.lastReport != block.timestamp) _report(S);

// Checking max mint will also check if shutdown.
require(shares <= _maxMint(S, receiver), "ERC4626: mint more than max");
// Check for rounding error.
Expand Down Expand Up @@ -570,6 +579,10 @@ contract TokenizedStrategy {
) public nonReentrant returns (uint256 shares) {
// Get the storage slot for all following calls.
StrategyData storage S = _strategyStorage();

// Check if we should first accumulate profits.
if(S.autoReport && S.lastReport != block.timestamp) _report(S);

require(
assets <= _maxWithdraw(S, owner),
"ERC4626: withdraw more than max"
Expand Down Expand Up @@ -620,6 +633,10 @@ contract TokenizedStrategy {
) public nonReentrant returns (uint256) {
// Get the storage slot for all following calls.
StrategyData storage S = _strategyStorage();

// Check if we should first accumulate profits.
if(S.autoReport && S.lastReport != block.timestamp) _report(S);

require(
shares <= _maxRedeem(S, owner),
"ERC4626: redeem more than max"
Expand Down Expand Up @@ -1059,11 +1076,12 @@ contract TokenizedStrategy {
external
nonReentrant
onlyKeepers
returns (uint256 profit, uint256 loss)
returns (uint256, uint256)
{
// Cache storage pointer since its used repeatedly.
StrategyData storage S = _strategyStorage();
return _report(_strategyStorage());
}

function _report(StrategyData storage S) internal returns (uint256 profit, uint256 loss) {
// Tell the strategy to report the real total assets it has.
// It should do all reward selling and redepositing now and
// account for deployed and loose `asset` so we can accurately
Expand Down Expand Up @@ -1594,6 +1612,10 @@ contract TokenizedStrategy {
emit UpdateProfitMaxUnlockTime(_profitMaxUnlockTime);
}

function setAutoReport(bool _autoReport) external onlyManagement {
_strategyStorage().autoReport = _autoReport;
}

/*//////////////////////////////////////////////////////////////
ERC20 METHODS
//////////////////////////////////////////////////////////////*/
Expand Down
Loading