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: pass the storage pointer #74

Merged
merged 8 commits into from
Jan 27, 2024
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ docs/
.env

node_modules/
.gas-snapshot
.gas-snapshot
lcov.info
25 changes: 20 additions & 5 deletions src/BaseStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
_;
}

/**
* @dev Require that the msg.sender is this address.
*/
function _onlySelf() internal view {
require(msg.sender == address(this), "!self");
}
Expand All @@ -83,7 +86,7 @@
//////////////////////////////////////////////////////////////*/

/**
* This is the address of the TokenizedStrategy implementation
* @dev This is the address of the TokenizedStrategy implementation
* contract that will be used by all strategies to handle the
* accounting, logic, storage etc.
*
Expand All @@ -95,7 +98,7 @@
* and always be checked before any integration with the Strategy.
*/
// NOTE: This is a holder address based on expected deterministic location for testing
address public constant tokenizedStrategyAddress =

Check warning on line 101 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Constant name must be in capitalized SNAKE_CASE
0x2e234DAe75C793f67A35089C9d99245E1C58470b;

/*//////////////////////////////////////////////////////////////
Expand All @@ -103,7 +106,7 @@
//////////////////////////////////////////////////////////////*/

/**
* This variable is set to address(this) during initialization of each strategy.
* @dev This variable is set to address(this) during initialization of each strategy.
*
* This can be used to retrieve storage data within the strategy
* contract as if it were a linked library.
Expand All @@ -116,8 +119,10 @@
*/
ITokenizedStrategy internal immutable TokenizedStrategy;

// Underlying asset the Strategy is earning yield on.
// Stored here for cheap retrievals within the strategy.
/**
* @dev Underlying asset the Strategy is earning yield on.
* Stored here for cheap retrievals within the strategy.
*/
ERC20 internal immutable asset;

/**
Expand Down Expand Up @@ -148,7 +153,7 @@
// Store the tokenizedStrategyAddress at the standard implementation
// address storage slot so etherscan picks up the interface. This gets
// stored on initialization and never updated.
assembly {

Check warning on line 156 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Avoid to use inline assembly. It is acceptable only in rare cases
sstore(
// keccak256('eip1967.proxy.implementation' - 1)
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc,
Expand Down Expand Up @@ -249,7 +254,7 @@
*
* @param _totalIdle The current amount of idle funds that are available to deploy.
*/
function _tend(uint256 _totalIdle) internal virtual {}

Check warning on line 257 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Code contains empty blocks

/**
* @dev Optional trigger to override if tend() will be used by the strategy.
Expand Down Expand Up @@ -348,7 +353,7 @@
*
* @param _amount The amount of asset to attempt to free.
*/
function _emergencyWithdraw(uint256 _amount) internal virtual {}

Check warning on line 356 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Code contains empty blocks

/*//////////////////////////////////////////////////////////////
TokenizedStrategy HOOKS
Expand Down Expand Up @@ -450,12 +455,12 @@
bytes memory _calldata
) internal returns (bytes memory) {
// Delegate call the tokenized strategy with provided calldata.
(bool success, bytes memory result) = tokenizedStrategyAddress

Check warning on line 458 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Avoid to use low level calls
.delegatecall(_calldata);

// If the call reverted. Return the error.
if (!success) {
assembly {

Check warning on line 463 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Avoid to use inline assembly. It is acceptable only in rare cases
let ptr := mload(0x40)
let size := returndatasize()
returndatacopy(ptr, 0, size)
Expand All @@ -467,12 +472,22 @@
return result;
}

// execute a function on the TokenizedStrategy and return any value.
/**
* @dev execute a function on the TokenizedStrategy and return any value.
*
* This fallback function will be execute when any of the standard functions
* defined in the TokenizedStrategy are called since they wont be defined in
* this contract.
*
* It will delegatecall the TokenizedStrategy implementation with the exact
* calldata and return any relevant values.
*
*/
fallback() external {

Check warning on line 486 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

When fallback is not payable you will not be able to receive ether

Check warning on line 486 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Fallback function must be simple
// load our target address
address _tokenizedStrategyAddress = tokenizedStrategyAddress;
// Execute external function using delegatecall and return any value.
assembly {

Check warning on line 490 in src/BaseStrategy.sol

View workflow job for this annotation

GitHub Actions / solidity

Avoid to use inline assembly. It is acceptable only in rare cases
// Copy function selector and any arguments.
calldatacopy(0, 0, calldatasize())
// Execute function delegatecall.
Expand Down
Loading
Loading