From 9bb72d70204fe45513f86653f52c8d55158c837d Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Thu, 19 Dec 2024 12:52:58 +1300 Subject: [PATCH] Add WalletProxyHook --- contracts/hooks/WalletProxyHook.sol | 12 ++++++ contracts/hooks/interfaces/IWalletProxy.sol | 12 ++++++ foundry_test/hooks/EIP4337Hook.t.sol | 41 +++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 contracts/hooks/WalletProxyHook.sol create mode 100644 contracts/hooks/interfaces/IWalletProxy.sol create mode 100644 foundry_test/hooks/EIP4337Hook.t.sol diff --git a/contracts/hooks/WalletProxyHook.sol b/contracts/hooks/WalletProxyHook.sol new file mode 100644 index 0000000..4e7cddf --- /dev/null +++ b/contracts/hooks/WalletProxyHook.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity 0.8.18; + +import {IWalletProxy} from './interfaces/IWalletProxy.sol'; +import {Implementation} from '../modules/commons/Implementation.sol'; + +contract WalletProxyHook is IWalletProxy, Implementation { + /// @inheritdoc IWalletProxy + function PROXY_getImplementation() public view returns (address) { + return _getImplementation(); + } +} diff --git a/contracts/hooks/interfaces/IWalletProxy.sol b/contracts/hooks/interfaces/IWalletProxy.sol new file mode 100644 index 0000000..41e5393 --- /dev/null +++ b/contracts/hooks/interfaces/IWalletProxy.sol @@ -0,0 +1,12 @@ +// Copyright Immutable Pty Ltd 2018 - 2023 +// SPDX-License-Identifier: Apache 2.0 +// https://github.com/immutable/contracts/blob/a04f7ecb8a79ad8f1b67f73f770e0545deb6cba2/contracts/allowlist/IWalletProxy.sol +pragma solidity 0.8.18; + +// Interface to retrieve the implemention stored inside the Proxy contract +/// Interface for Passport Wallet's proxy contract. +interface IWalletProxy { + // Returns the current implementation address used by the proxy contract + // solhint-disable-next-line func-name-mixedcase + function PROXY_getImplementation() external view returns (address); +} \ No newline at end of file diff --git a/foundry_test/hooks/EIP4337Hook.t.sol b/foundry_test/hooks/EIP4337Hook.t.sol new file mode 100644 index 0000000..67906f1 --- /dev/null +++ b/foundry_test/hooks/EIP4337Hook.t.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity 0.8.18; + +import 'contracts/hooks/WalletProxyHook.sol'; +import 'contracts/hooks/interfaces/IWalletProxy.sol'; +import 'contracts/modules/commons/ModuleAuth.sol'; +import 'contracts/modules/commons/ModuleCalls.sol'; +import 'contracts/modules/commons/ModuleHooks.sol'; +import 'contracts/modules/MainModule.sol'; +import 'contracts/modules/MainModuleUpgradable.sol'; +import 'contracts/Factory.sol'; + +import 'foundry_test/base/AdvTest.sol'; + +contract WalletProxyHookTest is AdvTest { + ModuleHooks private template; + ModuleHooks private walletMod; + WalletProxyHook private wallet; + + function setUp() external { + Factory factory = new Factory(); + template = new ModuleHooks(); + walletMod = ModuleHooks(payable(factory.deploy(address(template), bytes32(0)))); + WalletProxyHook hook = new WalletProxyHook(); + + // Add hook + vm.prank(address(walletMod)); + walletMod.addHook(IWalletProxy.PROXY_getImplementation.selector, address(hook)); + + wallet = WalletProxyHook(address(walletMod)); + vm.label(address(wallet), 'wallet'); + } + + // + // Get Implementation + // + + function test_PROXY_getImplementation() external { + assertEq(wallet.PROXY_getImplementation(), address(template)); + } +}