-
Notifications
You must be signed in to change notification settings - Fork 0
/
delegateCall.sol
44 lines (34 loc) · 936 Bytes
/
delegateCall.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
44
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Impl1 {
uint256 public counter;
function increment() external {
counter += 1;
}
}
contract Impl2 {
uint256 public counter;
function increment() external {
counter += 100;
}
}
contract Proxy {
uint256 public counter;
address public owner;
address public impl;
constructor() {
owner = msg.sender;
}
function changeOwner(address _newOwner) external {
require(msg.sender == owner, "only Owner");
owner = _newOwner;
}
function setImplementation(address _newImpl) external {
require(msg.sender == owner, "only Owner");
impl = _newImpl;
}
function increment() external returns(bool, bytes memory) {
(bool flag, bytes memory data) = impl.delegatecall(abi.encodeWithSignature("increment()"));
return (flag, data);
}
}