Skip to content

Commit dd7e590

Browse files
committed
Merge branch 'master' into inbox
2 parents cf89880 + b0fc57a commit dd7e590

17 files changed

Lines changed: 836 additions & 58 deletions

.env.sample

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
PRIVATE_KEY="0x"
2-
WALLET_ADDRESS="0x"
3-
4-
OFF_CHAIN_VM_RPC="https://rpc-socket-composer-testnet.t.conduit.xyz"
5-
1+
# RPCs
2+
EVMX_RPC="https://rpc-evmx.dev.socket.tech"
63
SEPOLIA_RPC="https://rpc.ankr.com/eth_sepolia/"
7-
SEPOLIA_API_KEY="empty"
8-
94
ARBITRUM_SEPOLIA_RPC="https://rpc.ankr.com/arbitrum_sepolia"
10-
ARBITRUM_API_KEY="empty"
11-
125
OPTIMISM_SEPOLIA_RPC="https://rpc.ankr.com/optimism_sepolia"
13-
OPTIMISM_API_KEY="empty"
14-
156
BASE_SEPOLIA_RPC="https://rpc.ankr.com/base_sepolia"
16-
BASE_API_KEY="empty"
177

18-
ADDRESS_RESOLVER="0x6f60df8CD3Bb76C33ebc9E2E2Fe577edD62e3938"
19-
AUCTION_MANAGER="0xDC81d1BE1E8d92C5a98a15D89A16134D74121FC2"
8+
# EVMx key addresses
9+
# Find the most up to date addresses in deployments/dev_addresses.json
10+
ADDRESS_RESOLVER="0x35a72Ef57aCC20a8e1Ef39A0f903cE23175779b1"
11+
AUCTION_MANAGER="0xA9377140B51c8c5be91e73D03e5E32DC841Cd4C0"
12+
ARBITRUM_FEES_PLUG="0xB45CD3697Bfd0F5dA17787F0e113C2807303BEAc"
13+
FEES_MANAGER="0x2C4B5dac446AB96A3dd92b6bd7ec48151BDd8f9C"
14+
15+
# Add your deployer private key here
16+
# or remove it from this file if it is already an env var
17+
PRIVATE_KEY="0x"
18+
19+
# Set app related values after deployment on EVMx
20+
DEPLOYER="0x"
21+
APP_GATEWAY="0x"
2022

21-
# Set values after deployment
22-
COUNTER_DEPLOYER=""
23-
COUNTER_APP_GATEWAY=""
23+
# FOR INFRASTRUCTURE DEPLOYMENT ONLY
24+
# Removes hardhat issues related to linting and syntax checking
25+
SOCKET_SIGNER_KEY="0000dead0000dead0000dead0000dead0000dead0000dead0000dead0000dead"

foundry.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
[profile.default]
2-
src = "src"
2+
solc_version = "0.8.22"
3+
src = "contracts"
34
out = "out"
45
libs = ["lib"]
6+
ffi = true
7+
optimizer = true
8+
optimizer_runs = 200
59
evm_version = 'paris'
10+
611
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
12+
[etherscan]
13+
7625382 = { key = "empty", url = "https://evmx2.cloud.blockscout.com/api?" }
14+
421614 = { key = "${ARBISCAN_API_KEY}", url = "https://api-sepolia.arbiscan.io/api?" }
15+
11155420 = { key = "${OPTIMISM_API_KEY}", url = "https://optimism-sepolia.blockscout.com/api?" }

lib/socket-protocol

remappings.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
ds-test/=lib/forge-std/lib/ds-test/src/
22
forge-std/=lib/forge-std/src/
3-
socket-protocol/=lib/socket-protocol/
3+
socket-protocol/=lib/socket-protocol/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {console} from "forge-std/console.sol";
6+
import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
7+
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";
8+
9+
import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol";
10+
import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol";
11+
12+
contract DeployMistakes is Script {
13+
function run() external {
14+
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
15+
address auctionManager = vm.envAddress("AUCTION_MANAGER");
16+
string memory rpc = vm.envString("EVMX_RPC");
17+
vm.createSelectFork(rpc);
18+
19+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
20+
vm.startBroadcast(deployerPrivateKey);
21+
22+
Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});
23+
24+
DeploymentMistakesDeployer deployer =
25+
new DeploymentMistakesDeployer(addressResolver, auctionManager, FAST, fees);
26+
27+
DeploymentMistakesAppGateway gateway =
28+
new DeploymentMistakesAppGateway(addressResolver, address(deployer), auctionManager, fees);
29+
30+
console.log("Contracts deployed:");
31+
console.log("DeploymentMistakesDeployer:", address(deployer));
32+
console.log("DeploymentMistakesAppGateway:", address(gateway));
33+
34+
console.log("DeploymentMistakesDeployer contract ids:");
35+
console.log("noPlugNoInititialize");
36+
console.logBytes32(deployer.noPlugNoInititialize());
37+
console.log("noPlugInitialize");
38+
console.logBytes32(deployer.noPlugInitialize());
39+
console.log("plugNoInitialize");
40+
console.logBytes32(deployer.plugNoInitialize());
41+
console.log("plugInitialize");
42+
console.logBytes32(deployer.plugInitialize());
43+
console.log("plugInitializeTwice");
44+
console.logBytes32(deployer.plugInitializeTwice());
45+
console.log("plugNoInitInitialize");
46+
console.logBytes32(deployer.plugNoInitInitialize());
47+
}
48+
}
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {console} from "forge-std/console.sol";
6+
import {DepositFees} from "socket-protocol/script/PayFeesInArbitrumETH.s.sol";
7+
import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
8+
import {FeesPlug} from "socket-protocol/contracts/protocol/payload-delivery/FeesPlug.sol";
9+
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";
10+
import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/app-gateway/FeesManager.sol";
11+
12+
import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol";
13+
import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol";
14+
import {
15+
NoPlugNoInititialize,
16+
NoPlugInitialize,
17+
PlugNoInitialize,
18+
PlugInitialize,
19+
PlugInitializeTwice,
20+
PlugNoInitInitialize
21+
} from "../../src/deployment-mistakes/DeployOnchainMistakes.sol";
22+
23+
contract RunEVMxDeploy is Script {
24+
// ----- ENVIRONMENT VARIABLES -----
25+
string rpcEVMx = vm.envString("EVMX_RPC");
26+
string rpcArbSepolia = vm.envString("ARBITRUM_SEPOLIA_RPC");
27+
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
28+
address auctionManager = vm.envAddress("AUCTION_MANAGER");
29+
address feesPlugArbSepolia = vm.envAddress("ARBITRUM_FEES_PLUG");
30+
address feesManagerAddress = vm.envAddress("FEES_MANAGER");
31+
uint256 privateKey = vm.envUint("PRIVATE_KEY");
32+
address deployerAddress = vm.envAddress("DEPLOYER");
33+
address appGatewayAddress = vm.envAddress("APP_GATEWAY");
34+
35+
// ----- SCRIPT VARIABLES -----
36+
uint32 arbSepChainId = 411614;
37+
uint32 opSepChainId = 11155420;
38+
39+
Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});
40+
FeesManager feesManager = FeesManager(payable(feesManagerAddress));
41+
FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia));
42+
43+
DeploymentMistakesDeployer deployer = DeploymentMistakesDeployer(deployerAddress);
44+
DeploymentMistakesAppGateway appGateway = DeploymentMistakesAppGateway(appGatewayAddress);
45+
address noPlugNoInititializeForwarder;
46+
address noPlugInitializeForwarder;
47+
address plugNoInitializeForwarder;
48+
address plugInitializeForwarder;
49+
address plugInitializeTwiceForwarder;
50+
address plugNoInitInitializeForwarder;
51+
52+
function checkDepositedFees(uint32 chainId) internal returns (uint256 availableFees) {
53+
vm.createSelectFork(rpcEVMx);
54+
55+
(uint256 deposited, uint256 blocked) =
56+
feesManager.appGatewayFeeBalances(appGatewayAddress, chainId, ETH_ADDRESS);
57+
console.log("App Gateway:", appGatewayAddress);
58+
console.log("Deposited fees:", deposited);
59+
console.log("Blocked fees:", blocked);
60+
61+
availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
62+
console.log("Available fees:", availableFees);
63+
}
64+
65+
function withdrawAppFees(uint32 chainId) internal {
66+
// EVMX Check available fees
67+
vm.createSelectFork(rpcEVMx);
68+
69+
uint256 availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
70+
console.log("Available fees:", availableFees);
71+
72+
if (availableFees > 0) {
73+
// Switch to Arbitrum Sepolia to get gas price
74+
vm.createSelectFork(rpcArbSepolia);
75+
76+
// Gas price from Arbitrum
77+
uint256 arbitrumGasPrice = block.basefee + 0.1 gwei; // With buffer
78+
uint256 gasLimit = 5_000_000; // Estimate
79+
uint256 estimatedGasCost = gasLimit * arbitrumGasPrice;
80+
81+
console.log("Arbitrum gas price (wei):", arbitrumGasPrice);
82+
console.log("Gas limit:", gasLimit);
83+
console.log("Estimated gas cost:", estimatedGasCost);
84+
85+
// Calculate amount to withdraw
86+
uint256 amountToWithdraw = availableFees > estimatedGasCost ? availableFees - estimatedGasCost : 0;
87+
88+
if (amountToWithdraw > 0) {
89+
// Switch back to EVMX to perform withdrawal
90+
vm.createSelectFork(rpcEVMx);
91+
vm.startBroadcast(privateKey);
92+
address sender = vm.addr(privateKey);
93+
console.log("Withdrawing amount:", amountToWithdraw);
94+
appGateway.withdrawFeeTokens(chainId, ETH_ADDRESS, amountToWithdraw, sender);
95+
vm.stopBroadcast();
96+
97+
// Switch back to Arbitrum Sepolia to check final balance
98+
vm.createSelectFork(rpcArbSepolia);
99+
console.log("Final sender balance:", sender.balance);
100+
} else {
101+
console.log("Available fees less than estimated gas cost");
102+
}
103+
}
104+
}
105+
106+
function deployOnchainContracts() internal {
107+
vm.createSelectFork(rpcEVMx);
108+
vm.startBroadcast(privateKey);
109+
deployer.deployContracts(arbSepChainId);
110+
vm.stopBroadcast();
111+
112+
console.log("Contracts deployed");
113+
}
114+
115+
function getForwarderAddresses() internal {
116+
vm.createSelectFork(rpcEVMx);
117+
118+
noPlugNoInititializeForwarder = deployer.forwarderAddresses(deployer.noPlugNoInititialize(), arbSepChainId);
119+
console.log("No Plug No Init Forwarder:", noPlugNoInititializeForwarder);
120+
121+
noPlugInitializeForwarder = deployer.forwarderAddresses(deployer.noPlugInitialize(), arbSepChainId);
122+
console.log("No Plug Init Forwarder:", noPlugInitializeForwarder);
123+
124+
plugNoInitializeForwarder = deployer.forwarderAddresses(deployer.plugNoInitialize(), arbSepChainId);
125+
console.log("Plug No Init Forwarder:", plugNoInitializeForwarder);
126+
127+
plugInitializeForwarder = deployer.forwarderAddresses(deployer.plugInitialize(), arbSepChainId);
128+
console.log("Plug Init Forwarder:", plugInitializeForwarder);
129+
130+
plugInitializeTwiceForwarder = deployer.forwarderAddresses(deployer.plugInitializeTwice(), arbSepChainId);
131+
console.log("Plug Init Init Forwarder:", plugInitializeTwiceForwarder);
132+
133+
plugNoInitInitializeForwarder = deployer.forwarderAddresses(deployer.plugNoInitInitialize(), arbSepChainId);
134+
console.log("Plug No Init Init Forwarder:", plugNoInitInitializeForwarder);
135+
}
136+
137+
function validateMistakes() internal {
138+
NoPlugNoInititialize noPlugNoInititialize = NoPlugNoInititialize(noPlugNoInititializeForwarder);
139+
NoPlugInitialize noPlugInitialize = NoPlugInitialize(noPlugInitializeForwarder);
140+
PlugNoInitialize plugNoInitialize = PlugNoInitialize(plugNoInitializeForwarder);
141+
PlugInitialize plugInitialize = PlugInitialize(plugInitializeForwarder);
142+
PlugInitializeTwice plugInitializeTwice = PlugInitializeTwice(plugInitializeTwiceForwarder);
143+
PlugNoInitInitialize plugNoInitInitialize = PlugNoInitInitialize(plugNoInitInitializeForwarder);
144+
145+
vm.createSelectFork(rpcArbSepolia);
146+
vm.startBroadcast(privateKey);
147+
148+
// NoPlugNoInititialize checks
149+
require(noPlugNoInititialize.variable() == 0, "variable should be 0");
150+
(bool success,) = noPlugNoInititializeForwarder.call(abi.encodeWithSignature("socket__()"));
151+
require(!success, "Should revert on socket__()");
152+
console.log("NoPlugNoInititialize checks passed");
153+
154+
// NoPlugInitialize checks
155+
require(noPlugInitialize.variable() == 10, "variable should be 10");
156+
(success,) = noPlugInitializeForwarder.call(abi.encodeWithSignature("socket__()"));
157+
require(!success, "Should revert on socket__()");
158+
console.log("NoPlugInitialize checks passed");
159+
160+
// PlugNoInitialize checks
161+
require(plugNoInitialize.variable() == 0, "variable should be 0");
162+
require(address(plugNoInitialize.socket__()) != address(0), "Should return socket address");
163+
console.log("PlugNoInitialize checks passed");
164+
165+
// PlugInitialize checks
166+
require(plugInitialize.variable() == 10, "variable should be 10");
167+
require(address(plugInitialize.socket__()) != address(0), "Should return socket address");
168+
console.log("PlugInitialize checks passed");
169+
170+
// PlugInitializeTwice checks
171+
require(address(plugInitializeTwice.socket__()) != address(0), "Should return socket address");
172+
require(plugInitializeTwice.variable() == 20, "variable should be 20");
173+
console.log("PlugInitializeTwice checks passed");
174+
175+
// PlugNoInitInitialize checks
176+
require(plugNoInitInitialize.variable() == 10, "variable should be 10");
177+
require(address(plugNoInitInitialize.socket__()) != address(0), "Should return socket address");
178+
console.log("PlugNoInitInitialize checks passed");
179+
180+
vm.stopBroadcast();
181+
}
182+
183+
function run() external {
184+
uint256 availableFees = checkDepositedFees(arbSepChainId);
185+
186+
if (availableFees > 0) {
187+
// Set up onchain deployments
188+
deployOnchainContracts();
189+
getForwarderAddresses();
190+
191+
validateMistakes();
192+
193+
withdrawAppFees(arbSepChainId);
194+
} else {
195+
console.log("NO AVAILABLE FEES - Please deposit fees before running this script");
196+
}
197+
}
198+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {console} from "forge-std/console.sol";
6+
import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
7+
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";
8+
9+
import {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol";
10+
import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol";
11+
12+
contract DeployEVMxContracts is Script {
13+
function run() external {
14+
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
15+
address auctionManager = vm.envAddress("AUCTION_MANAGER");
16+
string memory rpc = vm.envString("EVMX_RPC");
17+
vm.createSelectFork(rpc);
18+
19+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
20+
vm.startBroadcast(deployerPrivateKey);
21+
22+
Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});
23+
24+
RobustnessDeployer deployer = new RobustnessDeployer(addressResolver, auctionManager, FAST, fees);
25+
26+
RobustnessAppGateway gateway =
27+
new RobustnessAppGateway(addressResolver, address(deployer), auctionManager, fees);
28+
29+
console.log("Contracts deployed:");
30+
console.log("Deployer:", address(deployer));
31+
console.log("AppGateway:", address(gateway));
32+
}
33+
}

0 commit comments

Comments
 (0)