Skip to content

Commit

Permalink
fix: keeper (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia authored Apr 12, 2024
1 parent 19036db commit 26c43a9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
20 changes: 3 additions & 17 deletions contracts/Keeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,14 @@ contract Keeper {
* @notice Reports on a strategy.
*/
function report(address _strategy) external returns (uint256, uint256) {
// Call the target with the provided calldata.
(bool success, bytes memory result) = _strategy.call(
abi.encodeWithSelector(IStrategy.report.selector)
);

if (success) {
return abi.decode(result, (uint256, uint256));
}
return IStrategy(_strategy).report();
}

/**
* @notice Tends a strategy.
*/
function tend(address _strategy) external {
_strategy.call(abi.encodeWithSelector(IStrategy.tend.selector));
return IStrategy(_strategy).tend();
}

/**
Expand All @@ -48,13 +41,6 @@ contract Keeper {
address _vault,
address _strategy
) external returns (uint256, uint256) {
// Call the target with the provided calldata.
(bool success, bytes memory result) = _vault.call(
abi.encodeCall(IVault.process_report, _strategy)
);

if (success) {
return abi.decode(result, (uint256, uint256));
}
return IVault(_vault).process_report(_strategy);
}
}
35 changes: 35 additions & 0 deletions scripts/deploy_keeper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from ape import project, accounts, Contract, chain, networks
from hexbytes import HexBytes
from scripts.deployments import getSalt, deploy_contract


def deploy_keeper():
print("Deploying Keeper on ChainID", chain.chain_id)

if input("Do you want to continue? ") == "n":
return

keeper = project.Keeper

deployer = input("Name of account to use? ")
deployer = accounts.load(deployer)

salt = getSalt("Keeper")

print(f"Salt we are using {salt}")
print("Init balance:", deployer.balance / 1e18)

# generate and deploy
deploy_bytecode = HexBytes(
HexBytes(keeper.contract_type.deployment_bytecode.bytecode)
)

print(f"Deploying the Keeper...")

deploy_contract(deploy_bytecode, salt, deployer)

print("------------------")


def main():
deploy_keeper()
17 changes: 5 additions & 12 deletions tests/test_keeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

def test_keeper(daddy, keeper, vault, mock_tokenized, amount, user, asset, management):
strategy = mock_tokenized
# Revert on vault does not cause revert
# Revert on vault
with ape.reverts("not allowed"):
vault.process_report(strategy, sender=keeper)

tx = keeper.process_report(vault, strategy, sender=user)

profit, loss = tx.return_value
assert profit == 0
assert loss == 0
with ape.reverts("not allowed"):
keeper.process_report(vault, strategy, sender=user)

vault.add_strategy(strategy, sender=daddy)
vault.set_role(keeper, ROLES.REPORTING_MANAGER, sender=daddy)
Expand All @@ -36,11 +32,8 @@ def test_keeper(daddy, keeper, vault, mock_tokenized, amount, user, asset, manag
with ape.reverts("!keeper"):
strategy.report(sender=keeper)

tx = keeper.report(strategy, sender=user)

profit, loss = tx.return_value
assert profit == 0
assert loss == 0
with ape.reverts("!keeper"):
keeper.report(strategy, sender=user)

strategy.setKeeper(keeper, sender=management)

Expand Down

0 comments on commit 26c43a9

Please sign in to comment.