-
Notifications
You must be signed in to change notification settings - Fork 5
/
UpgradableModularAccount.sol
43 lines (37 loc) · 1.73 KB
/
UpgradableModularAccount.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import {BasicModularAccount} from "./BasicModularAccount.sol";
import {ModuleInstaller} from "../contracts/extensions/ModuleInstaller.sol";
import {HookInstaller} from "../contracts/extensions/HookInstaller.sol";
import {ValidatorInstaller} from "../contracts/extensions/ValidatorInstaller.sol";
contract UpgradableModularAccount is BasicModularAccount, ValidatorInstaller, HookInstaller, ModuleInstaller {
//
event Upgraded(address indexed oldImplementation, address indexed newImplementation);
/**
* @dev Storage slot with the address of the current implementation:
* https://github.com/SoulWallet/SoulWalletCore/blob/main/test/dev/SoulWalletProxy.sol
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1
*/
bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
function upgradeTo(address newImplementation) external {
_onlySelfOrModule();
bool isContract;
assembly ("memory-safe") {
isContract := gt(extcodesize(newImplementation), 0)
}
if (!isContract) {
revert("new implementation is not a contract");
}
address oldImplementation;
assembly ("memory-safe") {
oldImplementation := and(sload(_IMPLEMENTATION_SLOT), 0xffffffffffffffffffffffffffffffffffffffff)
}
if (oldImplementation == newImplementation) {
revert("new implementation is the same as old one");
}
assembly ("memory-safe") {
sstore(_IMPLEMENTATION_SLOT, newImplementation)
}
emit Upgraded(oldImplementation, newImplementation);
}
}