Skip to content

Commit 17cee5f

Browse files
authored
Merge pull request #18 from SocketDotTech/update-new-release
Update contracts and scripts for Itchy palms devnet release
2 parents 95190bc + 2aae2a3 commit 17cee5f

17 files changed

Lines changed: 170 additions & 262 deletions

.env.sample

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ BASE_SEPOLIA_RPC="https://sepolia.base.org"
88
# EVMx key addresses
99
# Find the most up to date addresses at:
1010
# https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json
11-
ADDRESS_RESOLVER="0x4846430BB142385e581C894AE92a4CF0722aEC21"
12-
FEES_MANAGER="0x9745623Aaa299500F93d2B1B4Efb7b3EC5e60FFc"
13-
ARBITRUM_FEES_PLUG="0x9E263f6c7C199d9c147E30764A8cae1175184CB8"
11+
ADDRESS_RESOLVER="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e"
12+
FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C"
13+
ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b"
14+
ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3"
1415

1516
# Add your deployer private key here
1617
# or remove it from this file if it is already an env var
1718
PRIVATE_KEY="0x"
19+
WALLET_ADDRESS="0x"
1820

1921
# Set app related values after deployment on EVMx
2022
APP_GATEWAY="0x"

lib/socket-protocol

script/SetupScript.sol

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ pragma solidity ^0.8.0;
44
import {Script} from "forge-std/Script.sol";
55
import {console} from "forge-std/console.sol";
66
import {DepositFees} from "socket-protocol/script/helpers/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/FeesManager.sol";
7+
import {FeesPlug} from "socket-protocol/contracts/evmx/payload-delivery/FeesPlug.sol";
8+
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/utils/common/Constants.sol";
9+
import {FeesManager} from "socket-protocol/contracts/evmx/payload-delivery/FeesManager.sol";
1110

1211
interface IAppGateway {
1312
function deployContracts(uint32 chainId) external;
@@ -30,30 +29,21 @@ abstract contract SetupScript is Script {
3029
uint32 opSepChainId = 11155420;
3130
uint32[2] chainIds = [opSepChainId, arbSepChainId];
3231

33-
Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});
34-
Fees deployFees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether});
32+
uint256 fees = 30 ether;
33+
uint256 deployFees = 10 ether;
3534
FeesManager feesManager = FeesManager(payable(feesManagerAddress));
3635
FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia));
3736

38-
function checkDepositedFees(uint32 chainId) internal returns (uint256 availableFees) {
37+
function checkDepositedFees() internal returns (uint256 availableFees) {
3938
vm.createSelectFork(rpcEVMx);
4039

41-
(uint256 deposited, uint256 blocked) =
42-
feesManager.appGatewayFeeBalances(appGatewayAddress, chainId, ETH_ADDRESS);
40+
availableFees = feesManager.getAvailableCredits(appGatewayAddress);
4341
console.log("App Gateway:", appGatewayAddress);
44-
console.log("Deposited fees:", deposited);
45-
console.log("Blocked fees:", blocked);
46-
47-
availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
4842
console.log("Available fees:", availableFees);
4943
}
5044

5145
function _withdrawAppFees(uint32 chainId) internal {
52-
// EVMX Check available fees
53-
vm.createSelectFork(rpcEVMx);
54-
55-
uint256 availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
56-
console.log("Available fees:", availableFees);
46+
uint256 availableFees = checkDepositedFees();
5747

5848
if (availableFees > 0) {
5949
// Switch to Arbitrum Sepolia to get gas price
@@ -126,7 +116,7 @@ abstract contract SetupScript is Script {
126116
// Standard flow
127117
// Each implementation script will call these functions
128118
function _run(uint32 chainId) internal {
129-
uint256 availableFees = checkDepositedFees(chainId);
119+
uint256 availableFees = checkDepositedFees();
130120

131121
if (availableFees > 0) {
132122
executeScriptSpecificLogic();

script/run-evmx-apps.sh

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ prepare_deployment() {
8888
export ARB_SEP_CHAIN_ID=421614
8989
export OP_SEP_CHAIN_ID=11155420
9090
export ETH_ADDRESS=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
91-
export DEPLOY_FEES_AMOUNT=500000000000000 # 0.0005 ETH in wei
92-
export FEES_AMOUNT="1000000000000000" # 0.001 ETH in wei
91+
export DEPLOY_FEES_AMOUNT=10000000000000000000 # 10 ETH in wei
92+
export FEES_AMOUNT=30000000000000000000 # 30 ETH in wei
93+
export TEST_USDC_AMOUNT="100000000" # 100 TEST USDC
9394
export GAS_BUFFER="100000000" # 0.1 Gwei in wei
94-
export GAS_LIMIT="3000000" # Gas limit estimate
95+
export GAS_LIMIT="50000000000" # Gas limit estimate
9596
export EVMX_VERIFIER_URL="https://evmx.cloud.blockscout.com/api"
9697
export EVMX_API_BASE_URL="https://api-evmx-devnet.socket.tech"
9798
}
@@ -113,11 +114,12 @@ deploy_appgateway() {
113114
--verify \
114115
--verifier-url "$EVMX_VERIFIER_URL" \
115116
--verifier blockscout \
116-
--constructor-args "$ADDRESS_RESOLVER" "($ARB_SEP_CHAIN_ID, $ETH_ADDRESS, $deploy_fees)"); then
117+
--constructor-args "$ADDRESS_RESOLVER" "$deploy_fees"); then
117118
echo -e "${RED}Error:${NC} Contract deployment failed."
118119
exit 1
119120
fi
120121

122+
parse_txhash "$output" "evmx.cloud"
121123
# Extract the deployed address
122124
local appgateway
123125
appgateway=$(echo "$output" | grep "Deployed to:" | awk '{print $3}')
@@ -137,6 +139,10 @@ function parse_txhash() {
137139
local path=$2
138140
local txhash
139141
txhash=$(echo "$output" | grep "^transactionHash" | awk '{print $2}')
142+
if [ -z "$txhash" ]; then
143+
txhash=$(echo "$output" | grep -i "Transaction hash:" | awk '{print $3}')
144+
fi
145+
140146
# Check if txhash is empty or invalid
141147
if [ -z "$txhash" ] || ! [[ "$txhash" =~ ^0x[0-9a-fA-F]{64}$ ]]; then
142148
echo -e "${RED}Error:${NC} Failed to extract valid transactionHash from output."
@@ -261,7 +267,7 @@ fetch_forwarder_and_onchain_address() {
261267
# Retrieve forwarder address with timeout
262268
local forwarder
263269
local attempts=0
264-
local max_attempts=12 # 60 seconds / 5 second sleep = 12 attempts
270+
local max_attempts=30 # 60 seconds / 2 second sleep = 30 attempts
265271
local width=50 # Width of the progress bar
266272
local bar
267273

@@ -296,7 +302,7 @@ fetch_forwarder_and_onchain_address() {
296302
# Print progress bar on the same line
297303
printf "\r${YELLOW}Waiting for forwarder:${NC} [%-${width}s] %d%%" "$bar" "$percent"
298304

299-
sleep 5
305+
sleep 2
300306
attempts=$((attempts + 1))
301307
done
302308

@@ -341,75 +347,71 @@ fetch_forwarder_and_onchain_address() {
341347
check_available_fees() {
342348
local max_attempts=12 # 60 seconds / 5-second interval
343349
local attempt=0
344-
local available_fees=0
350+
local available_fees="0"
345351
local output
346352
local width=50
347353
local bar
348-
349-
while true; do
354+
while [ $attempt -lt $max_attempts ]; do
350355
if ! output=$(cast call "$FEES_MANAGER" \
351-
"getAvailableFees(uint32,address,address)(uint256)" \
352-
"$ARB_SEP_CHAIN_ID" "$APP_GATEWAY" "$ETH_ADDRESS" \
356+
"getAvailableCredits(address)(uint256)" \
357+
"$APP_GATEWAY" \
353358
--rpc-url "$EVMX_RPC" 2>/dev/null); then
359+
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
354360
echo -e "${RED}Error:${NC} Failed to retrieve available fees."
355361
exit 1
356362
else
357363
# Extract the fees value
358364
available_fees=$(echo "$output" | awk '{print $1}')
359-
360365
# Validate the fees value is a number
361366
if ! [[ "$available_fees" =~ ^[0-9]+$ ]]; then
367+
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
362368
echo -e "${RED}Error:${NC} Invalid fee value received."
363369
exit 1
364370
fi
365371
fi
366-
367372
# Check if we got non-zero fees
368-
if [ "$available_fees" -ne 0 ]; then
369-
if [ $attempt -ne 0 ]; then
370-
printf "\n" # New line after progress bar only if not first attempt
371-
fi
372-
break
373-
fi
374-
375-
# Check if we've exceeded maximum attempts
376-
if [ $attempt -ge $max_attempts ]; then
377-
printf "\n" # New line before error message
378-
echo -e "${RED}Error:${NC} No funds available after 60 seconds."
379-
exit 1
373+
if [ "$available_fees" != "0" ]; then
374+
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
375+
echo -e "Funds available: $available_fees wei"
376+
return 0
380377
fi
381-
382378
# Calculate progress bar
383379
local progress=$(( (attempt * width) / max_attempts ))
384380
local percent=$(( (attempt * 100) / max_attempts ))
385381
bar=$(printf "#%.0s" $(seq 1 $progress))
386-
387382
# Print progress bar on the same line
388383
printf "\r${YELLOW}Checking fees:${NC} [%-${width}s] %d%%" "$bar" "$percent"
389-
390384
sleep 5
391385
attempt=$((attempt + 1))
392386
done
393-
394-
echo -e "Funds available: $available_fees wei"
395-
return 0
387+
# If we get here, we've exceeded maximum attempts
388+
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
389+
echo -e "${RED}Error:${NC} No funds available after 60 seconds."
390+
exit 1
396391
}
397392

398393
# Function to deposit funds
399394
deposit_funds() {
400395
echo -e "${CYAN}Depositing funds${NC}"
401396

397+
# Mint test USDC
398+
if ! send_transaction "$ARBITRUM_TEST_USDC" "mint(address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$WALLET_ADDRESS" "$TEST_USDC_AMOUNT"; then
399+
echo -e "${RED}Error:${NC} Failed to mint test USDC."
400+
return 1
401+
fi
402+
403+
# Approve USDC for FeesPlug
404+
if ! send_transaction "$ARBITRUM_TEST_USDC" "approve(address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$ARBITRUM_FEES_PLUG" "$TEST_USDC_AMOUNT"; then
405+
echo -e "${RED}Error:${NC} Failed to approve test USDC to FeesPlug."
406+
return 1
407+
fi
408+
402409
# Deposit funds
403-
# Note: This is a special case that needs value parameter
404-
if ! output=$(cast send "$ARBITRUM_FEES_PLUG" \
405-
--rpc-url "$ARBITRUM_SEPOLIA_RPC" \
406-
--private-key "$PRIVATE_KEY" \
407-
--value "$FEES_AMOUNT" \
408-
"deposit(address,address,uint256)" "$ETH_ADDRESS" "$APP_GATEWAY" "$FEES_AMOUNT"); then
409-
echo -e "${RED}Error:${NC} Failed to deposit fees."
410-
exit 1
410+
if ! send_transaction "$ARBITRUM_FEES_PLUG" "depositToFeeAndNative(address,address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$ARBITRUM_TEST_USDC" "$APP_GATEWAY" "$TEST_USDC_AMOUNT"; then
411+
echo -e "${RED}Error:${NC} Failed to deposit to fees and native."
412+
return 1
411413
fi
412-
parse_txhash "$output" "arbitrum-sepolia"
414+
413415
check_available_fees
414416
}
415417

@@ -420,43 +422,41 @@ withdraw_funds() {
420422
# Get available fees from EVMX chain
421423
local output
422424
if ! output=$(cast call "$FEES_MANAGER" \
423-
"getAvailableFees(uint32,address,address)(uint256)" \
424-
"$ARB_SEP_CHAIN_ID" "$APP_GATEWAY" "$ETH_ADDRESS" \
425-
--rpc-url "$EVMX_RPC"); then
426-
echo -e "${RED}Error:${NC} Failed to get available fees."
425+
"getAvailableCredits(address)(uint256)" \
426+
"$APP_GATEWAY" \
427+
--rpc-url "$EVMX_RPC" 2>/dev/null); then
428+
echo -e "${RED}Error:${NC} Failed to retrieve available fees."
427429
exit 1
428430
fi
429431

430432
local available_fees
431433
available_fees=$(echo "$output" | awk '{print $1}')
432-
433-
# Ensure it's a valid integer before proceeding
434+
# Validate the fees value is a number
434435
if ! [[ "$available_fees" =~ ^[0-9]+$ ]]; then
435-
echo -e "${RED}Error:${NC} Invalid available fees value: $available_fees"
436+
echo -e "${RED}Error:${NC} Invalid fee value received."
436437
exit 1
437438
fi
438439

439440
echo "Available Fees: $available_fees wei"
440-
441441
# Check if there are funds to withdraw
442-
if [ "$available_fees" -gt 0 ]; then
442+
if [ "$available_fees" != "0" ]; then
443443
# Fetch gas price on Arbitrum Sepolia
444444
local arb_gas_price
445445
arb_gas_price=$(cast base-fee --rpc-url "$ARBITRUM_SEPOLIA_RPC")
446-
447446
# Add buffer to gas price
448-
local gas_price=$((arb_gas_price + GAS_BUFFER))
449-
local estimated_gas_cost=$((GAS_LIMIT * gas_price))
450-
447+
local gas_price
448+
local estimated_gas_cost
449+
gas_price=$(echo "$arb_gas_price + $GAS_BUFFER" | bc)
450+
estimated_gas_cost=$(echo "$GAS_LIMIT * $gas_price" | bc)
451451
# Calculate withdrawal amount
452452
local amount_to_withdraw=0
453-
if [ "$available_fees" -gt "$estimated_gas_cost" ]; then
454-
amount_to_withdraw=$((available_fees - estimated_gas_cost))
453+
if (( $(echo "$available_fees > $estimated_gas_cost" | bc -l) )); then
454+
amount_to_withdraw=$(echo "$available_fees - $estimated_gas_cost" | bc)
455455
fi
456-
457-
if [ "$amount_to_withdraw" -gt 0 ]; then
456+
echo "Withdrawing $amount_to_withdraw wei"
457+
if (( $(echo "$amount_to_withdraw > 0" | bc -l) )); then
458458
# Withdraw funds using send_transaction
459-
if ! send_transaction "$APP_GATEWAY" "withdrawFeeTokens(uint32,address,uint256,address)" "$EVMX_RPC" "evmx.cloud" "$ARB_SEP_CHAIN_ID" "$ETH_ADDRESS" "$amount_to_withdraw" "$SENDER_ADDRESS"; then
459+
if ! send_transaction "$APP_GATEWAY" "withdrawFeeTokens(uint32,address,uint256,address)" "$EVMX_RPC" "evmx.cloud" "$ARB_SEP_CHAIN_ID" "$ARBITRUM_TEST_USDC" "$amount_to_withdraw" "$SENDER_ADDRESS"; then
460460
echo -e "${RED}Error:${NC} Failed to withdraw fees."
461461
exit 1
462462
fi
@@ -474,7 +474,7 @@ withdraw_funds() {
474474
await_events() {
475475
local expected_new_events=$1 # Number of new events to expect
476476
local event=$2 # Event ABI
477-
local timeout=60 # Maximum wait time in seconds
477+
local timeout=180 # Maximum wait time in seconds
478478
local interval=2 # Check every 2 seconds
479479
local elapsed=0 # Time elapsed
480480

@@ -621,7 +621,7 @@ run_read_tests() {
621621
echo -e "${RED}Error:${NC} Failed to trigger parallel read"
622622
return 1
623623
fi
624-
await_events 10
624+
await_events 10 "ValueRead(address,uint256,uint256)"
625625

626626
# 2. Trigger Alternating Read between chains
627627
if ! send_transaction "$APP_GATEWAY" "triggerAltRead(address,address)" "$EVMX_RPC" "evmx.cloud" "$OP_FORWARDER" "$ARB_FORWARDER"; then
@@ -1099,6 +1099,7 @@ main() {
10991099
# Scheduler Tests function
11001100
run_scheduler_tests_func() {
11011101
deploy_appgateway schedule ScheduleAppGateway
1102+
deposit_funds
11021103
read_timeouts
11031104
trigger_timeouts
11041105
echo -e "${CYAN}Waiting for the highest timeout before reading logs...${NC}"

src/deploy/DeployOnchain.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity >=0.7.0 <0.9.0;
33

4-
import "socket-protocol/contracts/base/PlugBase.sol";
4+
import "socket-protocol/contracts/protocol/base/PlugBase.sol";
55

66
/**
77
* @title NoPlugNoInititialize

0 commit comments

Comments
 (0)