Skip to content

Commit

Permalink
Both SimpleVault and Safe guards compile
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Dec 30, 2024
1 parent 2a8f76d commit 7483cfa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
19 changes: 18 additions & 1 deletion contracts/guard/src/GuardV0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@ pragma solidity ^0.8.0;
import "@openzeppelin/access/Ownable.sol";
import "./lib/Path.sol";
import "./IGuard.sol";
import "./GuardV0Base.sol";

/**
* Prototype guard implementation.
*
* - Hardcoded actions for Uniswap v2, v3, 1delta
*
*/
contract GuardV0 is IGuard, GuardV0Base, Ownable {
contract GuardV0 is GuardV0Base, Ownable {

constructor() Ownable() {
}

/**
* Specify a modifier for guard owner
*/
modifier onlyGuardOwner() override {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}

/**
* Get the address of the proto DAO
*/
function getGovernanceAddress() override public view returns (address) {
return owner();
}

}
15 changes: 13 additions & 2 deletions contracts/guard/src/GuardV0Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import "./IGuard.sol";
/**
* Prototype guard implementation.
*
* - Hardcoded actions for Uniswap v2, v3, 1delta
* - Hardcoded actions for Uniswap v2, v3, 1delta, Aave
*
* - Abstract base contract to deal with different ownership modifiers and initialisers (Safe, OpenZeppelin)
*
*/
abstract contract GuardV0Base {
abstract contract GuardV0Base is IGuard {
using Path for bytes;
using BytesLib for bytes;

Expand Down Expand Up @@ -247,10 +249,19 @@ abstract contract GuardV0Base {
allowAsset(token, notes);
}

// Satisfy IGuard
function validateCall(
address sender,
address target,
bytes calldata callDataWithSelector
) external view {
_validateCallInternal(sender, target, callDataWithSelector);
}

function _validateCallInternal(
address sender,
address target,
bytes calldata callDataWithSelector
) public view {

if(sender == getGovernanceAddress()) {
Expand Down
6 changes: 5 additions & 1 deletion contracts/guard/src/IGuard.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
pragma solidity ^0.8.0;

interface IGuard {
function validateCall(address sender, address target, bytes memory callDataWithSelector) external;

/**
* Revert if the smart contract call is not allowed
*/
function validateCall(address sender, address target, bytes memory callDataWithSelector) external view;
}
2 changes: 1 addition & 1 deletion contracts/guard/src/MockGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract MockGuard is IGuard {
address sender,
address target,
bytes calldata callDataWithSelector
) external view {
) public view {
// Don't revert
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/safe-integration/src/TradingStrategyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract TradingStrategyModule is Module, GuardV0Base {

// Check that the asset manager can perform this function.
// Will revert() on error
validateCall(msg.sender, target, callData);
_validateCallInternal(msg.sender, target, callData);

// Inherit from Module contract,
// execute a tx on behalf of Gnosis
Expand Down

0 comments on commit 7483cfa

Please sign in to comment.