Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ BASE_SEPOLIA_RPC="https://sepolia.base.org"
# EVMx key addresses
# Find the most up to date addresses at:
# https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json
ADDRESS_RESOLVER="0x4846430BB142385e581C894AE92a4CF0722aEC21"
FEES_MANAGER="0x9745623Aaa299500F93d2B1B4Efb7b3EC5e60FFc"
ARBITRUM_FEES_PLUG="0x9E263f6c7C199d9c147E30764A8cae1175184CB8"
ADDRESS_RESOLVER="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e"
FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C"
ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b"
ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3"

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

# Set app related values after deployment on EVMx
APP_GATEWAY="0x"
2 changes: 1 addition & 1 deletion lib/socket-protocol
Submodule socket-protocol updated 135 files
28 changes: 9 additions & 19 deletions script/SetupScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ pragma solidity ^0.8.0;
import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {DepositFees} from "socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol";
import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
import {FeesPlug} from "socket-protocol/contracts/protocol/payload-delivery/FeesPlug.sol";
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";
import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/FeesManager.sol";
import {FeesPlug} from "socket-protocol/contracts/evmx/payload-delivery/FeesPlug.sol";
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/utils/common/Constants.sol";
import {FeesManager} from "socket-protocol/contracts/evmx/payload-delivery/FeesManager.sol";

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

Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});
Fees deployFees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether});
uint256 fees = 30 ether;
uint256 deployFees = 10 ether;
FeesManager feesManager = FeesManager(payable(feesManagerAddress));
FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia));

function checkDepositedFees(uint32 chainId) internal returns (uint256 availableFees) {
function checkDepositedFees() internal returns (uint256 availableFees) {
vm.createSelectFork(rpcEVMx);

(uint256 deposited, uint256 blocked) =
feesManager.appGatewayFeeBalances(appGatewayAddress, chainId, ETH_ADDRESS);
availableFees = feesManager.getAvailableCredits(appGatewayAddress);
console.log("App Gateway:", appGatewayAddress);
console.log("Deposited fees:", deposited);
console.log("Blocked fees:", blocked);

availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
console.log("Available fees:", availableFees);
}

function _withdrawAppFees(uint32 chainId) internal {
// EVMX Check available fees
vm.createSelectFork(rpcEVMx);

uint256 availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
console.log("Available fees:", availableFees);
uint256 availableFees = checkDepositedFees();

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

if (availableFees > 0) {
executeScriptSpecificLogic();
Expand Down
121 changes: 61 additions & 60 deletions script/run-evmx-apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ prepare_deployment() {
export ARB_SEP_CHAIN_ID=421614
export OP_SEP_CHAIN_ID=11155420
export ETH_ADDRESS=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
export DEPLOY_FEES_AMOUNT=500000000000000 # 0.0005 ETH in wei
export FEES_AMOUNT="1000000000000000" # 0.001 ETH in wei
export DEPLOY_FEES_AMOUNT=10000000000000000000 # 10 ETH in wei
export FEES_AMOUNT=30000000000000000000 # 30 ETH in wei
export TEST_USDC_AMOUNT="100000000" # 100 TEST USDC
export GAS_BUFFER="100000000" # 0.1 Gwei in wei
export GAS_LIMIT="3000000" # Gas limit estimate
export GAS_LIMIT="50000000000" # Gas limit estimate
export EVMX_VERIFIER_URL="https://evmx.cloud.blockscout.com/api"
export EVMX_API_BASE_URL="https://api-evmx-devnet.socket.tech"
}
Expand All @@ -113,11 +114,12 @@ deploy_appgateway() {
--verify \
--verifier-url "$EVMX_VERIFIER_URL" \
--verifier blockscout \
--constructor-args "$ADDRESS_RESOLVER" "($ARB_SEP_CHAIN_ID, $ETH_ADDRESS, $deploy_fees)"); then
--constructor-args "$ADDRESS_RESOLVER" "$deploy_fees"); then
echo -e "${RED}Error:${NC} Contract deployment failed."
exit 1
fi

parse_txhash "$output" "evmx.cloud"
# Extract the deployed address
local appgateway
appgateway=$(echo "$output" | grep "Deployed to:" | awk '{print $3}')
Expand All @@ -137,6 +139,10 @@ function parse_txhash() {
local path=$2
local txhash
txhash=$(echo "$output" | grep "^transactionHash" | awk '{print $2}')
if [ -z "$txhash" ]; then
txhash=$(echo "$output" | grep -i "Transaction hash:" | awk '{print $3}')
fi

# Check if txhash is empty or invalid
if [ -z "$txhash" ] || ! [[ "$txhash" =~ ^0x[0-9a-fA-F]{64}$ ]]; then
echo -e "${RED}Error:${NC} Failed to extract valid transactionHash from output."
Expand Down Expand Up @@ -261,7 +267,7 @@ fetch_forwarder_and_onchain_address() {
# Retrieve forwarder address with timeout
local forwarder
local attempts=0
local max_attempts=12 # 60 seconds / 5 second sleep = 12 attempts
local max_attempts=30 # 60 seconds / 2 second sleep = 30 attempts
local width=50 # Width of the progress bar
local bar

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

sleep 5
sleep 2
attempts=$((attempts + 1))
done

Expand Down Expand Up @@ -341,75 +347,71 @@ fetch_forwarder_and_onchain_address() {
check_available_fees() {
local max_attempts=12 # 60 seconds / 5-second interval
local attempt=0
local available_fees=0
local available_fees="0"
local output
local width=50
local bar

while true; do
while [ $attempt -lt $max_attempts ]; do
if ! output=$(cast call "$FEES_MANAGER" \
"getAvailableFees(uint32,address,address)(uint256)" \
"$ARB_SEP_CHAIN_ID" "$APP_GATEWAY" "$ETH_ADDRESS" \
"getAvailableCredits(address)(uint256)" \
"$APP_GATEWAY" \
--rpc-url "$EVMX_RPC" 2>/dev/null); then
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
echo -e "${RED}Error:${NC} Failed to retrieve available fees."
exit 1
else
# Extract the fees value
available_fees=$(echo "$output" | awk '{print $1}')

# Validate the fees value is a number
if ! [[ "$available_fees" =~ ^[0-9]+$ ]]; then
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
echo -e "${RED}Error:${NC} Invalid fee value received."
exit 1
fi
fi

# Check if we got non-zero fees
if [ "$available_fees" -ne 0 ]; then
if [ $attempt -ne 0 ]; then
printf "\n" # New line after progress bar only if not first attempt
fi
break
fi

# Check if we've exceeded maximum attempts
if [ $attempt -ge $max_attempts ]; then
printf "\n" # New line before error message
echo -e "${RED}Error:${NC} No funds available after 60 seconds."
exit 1
if [ "$available_fees" != "0" ]; then
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
echo -e "Funds available: $available_fees wei"
return 0
fi

# Calculate progress bar
local progress=$(( (attempt * width) / max_attempts ))
local percent=$(( (attempt * 100) / max_attempts ))
bar=$(printf "#%.0s" $(seq 1 $progress))

# Print progress bar on the same line
printf "\r${YELLOW}Checking fees:${NC} [%-${width}s] %d%%" "$bar" "$percent"

sleep 5
attempt=$((attempt + 1))
done

echo -e "Funds available: $available_fees wei"
return 0
# If we get here, we've exceeded maximum attempts
printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar
echo -e "${RED}Error:${NC} No funds available after 60 seconds."
exit 1
}

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

# Mint test USDC
if ! send_transaction "$ARBITRUM_TEST_USDC" "mint(address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$WALLET_ADDRESS" "$TEST_USDC_AMOUNT"; then
echo -e "${RED}Error:${NC} Failed to mint test USDC."
return 1
fi

# Approve USDC for FeesPlug
if ! send_transaction "$ARBITRUM_TEST_USDC" "approve(address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$ARBITRUM_FEES_PLUG" "$TEST_USDC_AMOUNT"; then
echo -e "${RED}Error:${NC} Failed to approve test USDC to FeesPlug."
return 1
fi

# Deposit funds
# Note: This is a special case that needs value parameter
if ! output=$(cast send "$ARBITRUM_FEES_PLUG" \
--rpc-url "$ARBITRUM_SEPOLIA_RPC" \
--private-key "$PRIVATE_KEY" \
--value "$FEES_AMOUNT" \
"deposit(address,address,uint256)" "$ETH_ADDRESS" "$APP_GATEWAY" "$FEES_AMOUNT"); then
echo -e "${RED}Error:${NC} Failed to deposit fees."
exit 1
if ! send_transaction "$ARBITRUM_FEES_PLUG" "depositToFeeAndNative(address,address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$ARBITRUM_TEST_USDC" "$APP_GATEWAY" "$TEST_USDC_AMOUNT"; then
echo -e "${RED}Error:${NC} Failed to deposit to fees and native."
return 1
fi
parse_txhash "$output" "arbitrum-sepolia"

check_available_fees
}

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

local available_fees
available_fees=$(echo "$output" | awk '{print $1}')

# Ensure it's a valid integer before proceeding
# Validate the fees value is a number
if ! [[ "$available_fees" =~ ^[0-9]+$ ]]; then
echo -e "${RED}Error:${NC} Invalid available fees value: $available_fees"
echo -e "${RED}Error:${NC} Invalid fee value received."
exit 1
fi

echo "Available Fees: $available_fees wei"

# Check if there are funds to withdraw
if [ "$available_fees" -gt 0 ]; then
if [ "$available_fees" != "0" ]; then
# Fetch gas price on Arbitrum Sepolia
local arb_gas_price
arb_gas_price=$(cast base-fee --rpc-url "$ARBITRUM_SEPOLIA_RPC")

# Add buffer to gas price
local gas_price=$((arb_gas_price + GAS_BUFFER))
local estimated_gas_cost=$((GAS_LIMIT * gas_price))

local gas_price
local estimated_gas_cost
gas_price=$(echo "$arb_gas_price + $GAS_BUFFER" | bc)
estimated_gas_cost=$(echo "$GAS_LIMIT * $gas_price" | bc)
# Calculate withdrawal amount
local amount_to_withdraw=0
if [ "$available_fees" -gt "$estimated_gas_cost" ]; then
amount_to_withdraw=$((available_fees - estimated_gas_cost))
if (( $(echo "$available_fees > $estimated_gas_cost" | bc -l) )); then
amount_to_withdraw=$(echo "$available_fees - $estimated_gas_cost" | bc)
fi

if [ "$amount_to_withdraw" -gt 0 ]; then
echo "Withdrawing $amount_to_withdraw wei"
if (( $(echo "$amount_to_withdraw > 0" | bc -l) )); then
# Withdraw funds using send_transaction
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
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
echo -e "${RED}Error:${NC} Failed to withdraw fees."
exit 1
fi
Expand All @@ -474,7 +474,7 @@ withdraw_funds() {
await_events() {
local expected_new_events=$1 # Number of new events to expect
local event=$2 # Event ABI
local timeout=60 # Maximum wait time in seconds
local timeout=180 # Maximum wait time in seconds
local interval=2 # Check every 2 seconds
local elapsed=0 # Time elapsed

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

# 2. Trigger Alternating Read between chains
if ! send_transaction "$APP_GATEWAY" "triggerAltRead(address,address)" "$EVMX_RPC" "evmx.cloud" "$OP_FORWARDER" "$ARB_FORWARDER"; then
Expand Down Expand Up @@ -1099,6 +1099,7 @@ main() {
# Scheduler Tests function
run_scheduler_tests_func() {
deploy_appgateway schedule ScheduleAppGateway
deposit_funds
read_timeouts
trigger_timeouts
echo -e "${CYAN}Waiting for the highest timeout before reading logs...${NC}"
Expand Down
2 changes: 1 addition & 1 deletion src/deploy/DeployOnchain.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

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

/**
* @title NoPlugNoInititialize
Expand Down
Loading