Skip to content

Commit a6ba2b0

Browse files
authored
test and deploy complements (#6)
* test and deploy scripts complements * tests and deploys cpmplement * ci: use stable foundry toolchain
1 parent 8c4a3d7 commit a6ba2b0

38 files changed

+1658
-747
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install Foundry
2424
uses: foundry-rs/foundry-toolchain@v1
2525
with:
26-
version: nightly
26+
version: stable
2727

2828
- name: Show Forge version
2929
run: |

foundry.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"lib/forge-std": {
3+
"rev": "77041d2ce690e692d6e03cc812b57d1ddaa4d505"
4+
},
5+
"lib/openzeppelin-contracts": {
6+
"rev": "e4f70216d759d8e6a64144a9e1f7bbeed78e7079"
7+
},
8+
"lib/openzeppelin-contracts-upgradeable": {
9+
"rev": "60b305a8f3ff0c7688f02ac470417b6bbf1c4d27"
10+
}
11+
}

script/Event/deployEvent.s.sol

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Vm.sol";
5+
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
6+
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
7+
8+
import {EmptyContract} from "../../src/utils/EmptyContract.sol";
9+
import {BLSApkRegistry} from "../../src/bls/BLSApkRegistry.sol";
10+
import {EventManager} from "../../src/core/EventManager.sol";
11+
import {console, Script} from "forge-std/Script.sol";
12+
13+
contract deployEventScript is Script {
14+
EmptyContract public emptyContract;
15+
16+
ProxyAdmin public blsApkRegistryProxyAdmin;
17+
ProxyAdmin public eventManagerAdmin;
18+
19+
BLSApkRegistry public blsApkRegistry;
20+
BLSApkRegistry public blsApkRegistryImplementation;
21+
22+
EventManager public eventManager;
23+
EventManager public eventManagerImplementation;
24+
25+
function run() public {
26+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
27+
address relayerManagerAddr = vm.envAddress("RELAYER_MANAGER");
28+
29+
address deployerAddress = vm.addr(deployerPrivateKey);
30+
vm.startBroadcast(deployerPrivateKey);
31+
32+
// Deploy BLSApkRegistry proxy and delegate to a empty contract first
33+
emptyContract = new EmptyContract();
34+
TransparentUpgradeableProxy proxyBlsApkRegistry =
35+
new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
36+
blsApkRegistry = BLSApkRegistry(address(proxyBlsApkRegistry));
37+
blsApkRegistryImplementation = new BLSApkRegistry();
38+
blsApkRegistryProxyAdmin = ProxyAdmin(getProxyAdminAddress(address(proxyBlsApkRegistry)));
39+
40+
// Deploy EventManager proxy and delegate to a empty contract first
41+
TransparentUpgradeableProxy proxyEventManager =
42+
new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
43+
eventManager = EventManager(address(proxyEventManager));
44+
eventManagerImplementation = new EventManager();
45+
eventManagerAdmin = ProxyAdmin(getProxyAdminAddress(address(proxyEventManager)));
46+
47+
// Upgrade and initialize the implementations
48+
blsApkRegistryProxyAdmin.upgradeAndCall(
49+
ITransparentUpgradeableProxy(address(blsApkRegistry)),
50+
address(blsApkRegistryImplementation),
51+
abi.encodeWithSelector(
52+
BLSApkRegistry.initialize.selector, deployerAddress, relayerManagerAddr, address(proxyEventManager)
53+
)
54+
);
55+
56+
eventManagerAdmin.upgradeAndCall(
57+
ITransparentUpgradeableProxy(address(eventManager)),
58+
address(eventManagerImplementation),
59+
abi.encodeWithSelector(
60+
EventManager.initialize.selector, deployerAddress, proxyBlsApkRegistry, deployerAddress
61+
)
62+
);
63+
64+
console.log("deploy proxyBlsApkRegistry:", address(proxyBlsApkRegistry));
65+
console.log("deploy proxyEventManager:", address(proxyEventManager));
66+
string memory path = "deployed_addresses.json";
67+
string memory data = string(
68+
abi.encodePacked(
69+
'{"proxyBlsApkRegistry": "',
70+
vm.toString(address(proxyBlsApkRegistry)),
71+
'", ',
72+
'"proxyEventManager": "',
73+
vm.toString(address(proxyEventManager)),
74+
'"}'
75+
)
76+
);
77+
vm.writeJson(data, path);
78+
vm.stopBroadcast();
79+
}
80+
81+
function getProxyAdminAddress(address proxy) internal view returns (address) {
82+
address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
83+
Vm vm = Vm(CHEATCODE_ADDRESS);
84+
85+
bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT);
86+
return address(uint160(uint256(adminSlot)));
87+
}
88+
}

script/Event/deployEventPod.s.sol

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Vm.sol";
5+
import {console, Script} from "forge-std/Script.sol";
6+
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
7+
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
8+
9+
import {EmptyContract} from "../../src/utils/EmptyContract.sol";
10+
import {EventPod} from "../../src/pod/EventPod.sol";
11+
import {EventManager} from "../../src/core/EventManager.sol";
12+
13+
import {IEventManager} from "../../src/interfaces/IEventManager.sol";
14+
import {IEventPod} from "../../src/interfaces/IEventPod.sol";
15+
16+
contract deployEventPodScript is Script {
17+
EmptyContract public emptyContract;
18+
19+
ProxyAdmin public eventPodAdmin;
20+
EventPod public eventPod;
21+
EventPod public eventPodImplementation;
22+
23+
function run() public {
24+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
25+
address eventManagerAddr = vm.envAddress("ORACLE_MANAGER");
26+
27+
address deployerAddress = vm.addr(deployerPrivateKey);
28+
29+
vm.startBroadcast(deployerPrivateKey);
30+
31+
emptyContract = new EmptyContract();
32+
TransparentUpgradeableProxy proxyEventPod =
33+
new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
34+
eventPod = EventPod(address(proxyEventPod));
35+
eventPodImplementation = new EventPod();
36+
eventPodAdmin = ProxyAdmin(getProxyAdminAddress(address(proxyEventPod)));
37+
38+
console.log("eventPodImplementation===", address(eventPodImplementation));
39+
40+
eventPodAdmin.upgradeAndCall(
41+
ITransparentUpgradeableProxy(address(eventPod)),
42+
address(eventPodImplementation),
43+
abi.encodeWithSelector(EventPod.initialize.selector, deployerAddress, eventManagerAddr)
44+
);
45+
46+
// EventManager(eventManagerAddr).addEventPodToFillWhitelist(proxyEventPod);
47+
48+
console.log("deploy proxyEventPod:", address(proxyEventPod));
49+
string memory path = "deployed_addresses.json";
50+
string memory data = string(
51+
abi.encodePacked(
52+
'{"proxyEventPod": "',
53+
vm.toString(address(proxyEventPod)),
54+
'", ',
55+
'"eventPodImplementation": "',
56+
vm.toString(address(eventPodImplementation)),
57+
'"}'
58+
)
59+
);
60+
vm.writeJson(data, path);
61+
vm.stopBroadcast();
62+
}
63+
64+
function getProxyAdminAddress(address proxy) internal view returns (address) {
65+
address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
66+
Vm vm = Vm(CHEATCODE_ADDRESS);
67+
68+
bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT);
69+
return address(uint160(uint256(adminSlot)));
70+
}
71+
}

script/Event/upgradeEventPod.s.sol

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import "forge-std/Vm.sol";
5+
import {console, Script} from "forge-std/Script.sol";
6+
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
7+
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
8+
9+
import {EmptyContract} from "../../src/utils/EmptyContract.sol";
10+
import {EventPod} from "../../src/pod/EventPod.sol";
11+
import {IEventManager} from "../../src/interfaces/IEventManager.sol";
12+
import {IEventPod} from "../../src/interfaces/IEventPod.sol";
13+
14+
contract upgradeEventPodScript is Script {
15+
address public ORACLE_POD = vm.envAddress("ORACLE_POD");
16+
17+
function run() public {
18+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
19+
address deployerAddress = vm.addr(deployerPrivateKey);
20+
21+
console.log("Deployer address:", deployerAddress);
22+
console.log("Event Pod Proxy:", ORACLE_POD);
23+
24+
address proxyAdminAddress = getProxyAdminAddress(ORACLE_POD);
25+
console.log("Calculated Event Pod Proxy Admin:", proxyAdminAddress);
26+
27+
ProxyAdmin messageManagerProxyAdmin = ProxyAdmin(proxyAdminAddress);
28+
29+
vm.startBroadcast(deployerPrivateKey);
30+
31+
EventPod newEventPodImplementation = new EventPod();
32+
33+
console.log("New EventPod implementation:", address(newEventPodImplementation));
34+
35+
messageManagerProxyAdmin.upgradeAndCall(
36+
ITransparentUpgradeableProxy(ORACLE_POD), address(newEventPodImplementation), ""
37+
);
38+
39+
console.log("Upgrade completed successfully!");
40+
vm.stopBroadcast();
41+
}
42+
43+
function getProxyAdminAddress(address proxy) internal view returns (address) {
44+
address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
45+
Vm vm = Vm(CHEATCODE_ADDRESS);
46+
47+
bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT);
48+
return address(uint160(uint256(adminSlot)));
49+
}
50+
}

script/deployOracle.s.sol renamed to script/Oracle/deployOracle.s.sol

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import "forge-std/Vm.sol";
55
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
66
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
77

8-
import { EmptyContract } from "../src/utils/EmptyContract.sol";
9-
import { BLSApkRegistry } from "../src/bls/BLSApkRegistry.sol";
10-
import { OracleManager } from "../src/core/OracleManager.sol";
11-
import { console, Script } from "forge-std/Script.sol";
8+
import {EmptyContract} from "../../src/utils/EmptyContract.sol";
9+
import {BLSApkRegistry} from "../../src/bls/BLSApkRegistry.sol";
10+
import {OracleManager} from "../../src/core/OracleManager.sol";
11+
import {console, Script} from "forge-std/Script.sol";
1212

1313
contract deployOracleScript is Script {
1414
EmptyContract public emptyContract;
@@ -24,53 +24,56 @@ contract deployOracleScript is Script {
2424

2525
function run() public {
2626
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
27-
address relayerManagerAddr = vm.envAddress("RELAYER_MANAGER");
27+
address relayerManagerAddr = vm.envAddress("RELAYER_MANAGER");
2828

2929
address deployerAddress = vm.addr(deployerPrivateKey);
3030
vm.startBroadcast(deployerPrivateKey);
3131

32+
// Deploy BLSApkRegistry proxy and delegate to a empty contract first
3233
emptyContract = new EmptyContract();
33-
TransparentUpgradeableProxy proxyBlsApkRegistry = new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
34+
TransparentUpgradeableProxy proxyBlsApkRegistry =
35+
new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
3436
blsApkRegistry = BLSApkRegistry(address(proxyBlsApkRegistry));
3537
blsApkRegistryImplementation = new BLSApkRegistry();
3638
blsApkRegistryProxyAdmin = ProxyAdmin(getProxyAdminAddress(address(proxyBlsApkRegistry)));
3739

38-
39-
TransparentUpgradeableProxy proxyOracleManager = new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
40+
// Deploy OracleManager proxy and delegate to a empty contract first
41+
TransparentUpgradeableProxy proxyOracleManager =
42+
new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
4043
oracleManager = OracleManager(address(proxyOracleManager));
4144
oracleManagerImplementation = new OracleManager();
4245
oracleManagerAdmin = ProxyAdmin(getProxyAdminAddress(address(proxyOracleManager)));
4346

44-
47+
// Upgrade and initialize the implementations
4548
blsApkRegistryProxyAdmin.upgradeAndCall(
4649
ITransparentUpgradeableProxy(address(blsApkRegistry)),
4750
address(blsApkRegistryImplementation),
4851
abi.encodeWithSelector(
49-
BLSApkRegistry.initialize.selector,
50-
deployerAddress,
51-
relayerManagerAddr,
52-
address(proxyOracleManager)
52+
BLSApkRegistry.initialize.selector, deployerAddress, relayerManagerAddr, address(proxyOracleManager)
5353
)
5454
);
5555

5656
oracleManagerAdmin.upgradeAndCall(
5757
ITransparentUpgradeableProxy(address(oracleManager)),
5858
address(oracleManagerImplementation),
5959
abi.encodeWithSelector(
60-
OracleManager.initialize.selector,
61-
deployerAddress,
62-
proxyBlsApkRegistry,
63-
deployerAddress
60+
OracleManager.initialize.selector, deployerAddress, proxyBlsApkRegistry, deployerAddress
6461
)
6562
);
6663

6764
console.log("deploy proxyBlsApkRegistry:", address(proxyBlsApkRegistry));
6865
console.log("deploy proxyOracleManager:", address(proxyOracleManager));
6966
string memory path = "deployed_addresses.json";
70-
string memory data = string(abi.encodePacked(
71-
'{"proxyBlsApkRegistry": "', vm.toString(address(proxyBlsApkRegistry)), '", ',
72-
'"proxyOracleManager": "', vm.toString(address(proxyOracleManager)), '"}'
73-
));
67+
string memory data = string(
68+
abi.encodePacked(
69+
'{"proxyBlsApkRegistry": "',
70+
vm.toString(address(proxyBlsApkRegistry)),
71+
'", ',
72+
'"proxyOracleManager": "',
73+
vm.toString(address(proxyOracleManager)),
74+
'"}'
75+
)
76+
);
7477
vm.writeJson(data, path);
7578
vm.stopBroadcast();
7679
}

script/deployOraclePod.s.sol renamed to script/Oracle/deployOraclePod.s.sol

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
pragma solidity ^0.8.20;
33

44
import "forge-std/Vm.sol";
5-
import { console, Script } from "forge-std/Script.sol";
5+
import {console, Script} from "forge-std/Script.sol";
66
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
77
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
88

9-
import { EmptyContract } from "../src/utils/EmptyContract.sol";
10-
import { OraclePod } from "../src/pod/OraclePod.sol";
11-
import { OracleManager } from "../src/core/OracleManager.sol";
12-
13-
import { IOracleManager } from "../src/interfaces/IOracleManager.sol";
14-
import { IOraclePod } from "../src/interfaces/IOraclePod.sol";
9+
import {EmptyContract} from "../../src/utils/EmptyContract.sol";
10+
import {OraclePod} from "../../src/pod/OraclePod.sol";
11+
import {OracleManager} from "../../src/core/OracleManager.sol";
1512

13+
import {IOracleManager} from "../../src/interfaces/IOracleManager.sol";
14+
import {IOraclePod} from "../../src/interfaces/IOraclePod.sol";
1615

1716
contract deployOraclePodScript is Script {
1817
EmptyContract public emptyContract;
@@ -30,7 +29,8 @@ contract deployOraclePodScript is Script {
3029
vm.startBroadcast(deployerPrivateKey);
3130

3231
emptyContract = new EmptyContract();
33-
TransparentUpgradeableProxy proxyOraclePod = new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
32+
TransparentUpgradeableProxy proxyOraclePod =
33+
new TransparentUpgradeableProxy(address(emptyContract), deployerAddress, "");
3434
oraclePod = OraclePod(address(proxyOraclePod));
3535
oraclePodImplementation = new OraclePod();
3636
oraclePodAdmin = ProxyAdmin(getProxyAdminAddress(address(proxyOraclePod)));
@@ -40,22 +40,23 @@ contract deployOraclePodScript is Script {
4040
oraclePodAdmin.upgradeAndCall(
4141
ITransparentUpgradeableProxy(address(oraclePod)),
4242
address(oraclePodImplementation),
43-
abi.encodeWithSelector(
44-
OraclePod.initialize.selector,
45-
deployerAddress,
46-
oracleManagerAddr
47-
)
43+
abi.encodeWithSelector(OraclePod.initialize.selector, deployerAddress, oracleManagerAddr)
4844
);
4945

50-
// OracleManager(oracleManagerAddr).addOraclePodToFillWhitelist(proxyOraclePod);
51-
46+
// OracleManager(oracleManagerAddr).addOraclePodToFillWhitelist(proxyOraclePod);
5247

5348
console.log("deploy proxyOraclePod:", address(proxyOraclePod));
5449
string memory path = "deployed_addresses.json";
55-
string memory data = string(abi.encodePacked(
56-
'{"proxyOraclePod": "', vm.toString(address(proxyOraclePod)), '", ',
57-
'"oraclePodImplementation": "', vm.toString(address(oraclePodImplementation)), '"}'
58-
));
50+
string memory data = string(
51+
abi.encodePacked(
52+
'{"proxyOraclePod": "',
53+
vm.toString(address(proxyOraclePod)),
54+
'", ',
55+
'"oraclePodImplementation": "',
56+
vm.toString(address(oraclePodImplementation)),
57+
'"}'
58+
)
59+
);
5960
vm.writeJson(data, path);
6061
vm.stopBroadcast();
6162
}

0 commit comments

Comments
 (0)