Skip to content

Commit

Permalink
feat(scripts): ask the user which RPC URL to use
Browse files Browse the repository at this point in the history
  • Loading branch information
nlecoufl committed Aug 7, 2024
1 parent 90b92dc commit ebacebf
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 32 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Make the scripts executable:

chmod +x utils/Deposit.sh utils/Withdraw.sh

Make sure to add in your .env file `ARBITRUM_ETHERSCAN_API_KEY` and `ETH_NODE_URI_ARBITRUM`.

### Usage

Run the scripts with the desired parameters:
Expand All @@ -61,7 +63,7 @@ Run the scripts with the desired parameters:

| Option | Description | Default |
|--------|-------------|---------|
| `-e` | Env (local, dev)| http://localhost:5001 (local) |
| `-e` | Api Env (local, dev)| http://localhost:5001 (local) |
| `-c` | Chain ID | 42161 (Arbitrum) |
| `-i` | Token amount to deposit/withdraw | 100000000 |
| `-s` | Strategy address | 0xC0077E921C30c39cDD8b693E25Af572C10E82a05 |
Expand Down
1 change: 0 additions & 1 deletion scripts/WithdrawPayloadScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ contract WithdrawPayloadScript is Script {

function run(
bytes calldata data,
address outputTokenAddress,
uint256 inputTokenAmount,
address strategyAddress,
address routerAddress
Expand Down
68 changes: 49 additions & 19 deletions utils/Deposit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ USDA_ADDRESS="0x0000206329b97DB379d5E1Bf586BbDB969C63274" # USDA on Arbitrum

# Parse command-line options
while getopts "e:c:i:r:s:l:u:t:" opt; do
case $opt in
e) env=$OPTARG ;;
c) chainId=$OPTARG ;;
i) inputTokenAmount=$OPTARG ;;
s) strategyAddress=$OPTARG ;;
r) routerAddress=$OPTARG ;;
l) slippage=$OPTARG ;;
u) userAddress=$OPTARG ;;
t) tokenChoice=$OPTARG ;;
\?) echo "Invalid option -$OPTARG" >&2; exit 1 ;;
esac
case $opt in
e) env=$OPTARG ;;
c) chainId=$OPTARG ;;
i) inputTokenAmount=$OPTARG ;;
s) strategyAddress=$OPTARG ;;
r) routerAddress=$OPTARG ;;
l) slippage=$OPTARG ;;
u) userAddress=$OPTARG ;;
t) tokenChoice=$OPTARG ;;
\?) echo "Invalid option -$OPTARG" >&2; exit 1 ;;
esac
done

# Convert tokenChoice to lowercase
Expand Down Expand Up @@ -76,11 +76,41 @@ fi
# Print the data (for debugging purposes)
echo "Data field extracted: $data"

forge script scripts/DepositPayloadScript.s.sol \
--sender "$userAddress" \
--rpc-url fork \
--unlocked \
--evm-version shanghai \
--broadcast \
-vvvv \
--sig "run(bytes,address,uint256,address,address)" "$data" "$inputTokenAddress" "$inputTokenAmount" "$strategyAddress" "$routerAddress"
# Ask the user which RPC URL to use
echo "Which RPC URL do you want to use? (these are values from foundry.toml, check [rpc_endpoints] section and modify .env if needed)"
echo "1. arbitrum"
echo "2. fork"
read -p "Enter your choice (1 or 2): " rpc_choice

# Set the RPC URL and adjust the forge script command based on user choice
case $rpc_choice in
1)
rpc_url="arbitrum"
forge_command="forge script scripts/DepositPayloadScript.s.sol \
--sender \"$userAddress\" \
--rpc-url $rpc_url \
-i 1 \
--broadcast \
--evm-version shanghai \
-vvvv \
--sig \"run(bytes,address,uint256,address,address)\" \"$data\" \"$inputTokenAddress\" \"$inputTokenAmount\" \"$strategyAddress\" \"$routerAddress\""
;;
2)
rpc_url="fork"
forge_command="forge script scripts/DepositPayloadScript.s.sol \
--sender \"$userAddress\" \
--rpc-url $rpc_url \
--broadcast \
--unlocked \
--evm-version shanghai \
-vvvv \
--sig \"run(bytes,address,uint256,address,address)\" \"$data\" \"$inputTokenAddress\" \"$inputTokenAmount\" \"$strategyAddress\" \"$routerAddress\""
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac

# Execute the forge script command
eval "$forge_command"
65 changes: 54 additions & 11 deletions utils/Withdraw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,24 @@ esac
# Construct the URL
url="${base_url}/v1/integrators/payload/withdraw?chainId=$chainId&outputTokenAddress=$outputTokenAddress&inputTokenAmount=$inputTokenAmount&strategyAddress=$strategyAddress&userAddress=$userAddress&slippage=$slippage&ipAddress=none"

echo $url

# Call the URL and extract the data field
# Call the URL and extract the data field or error message
response=$(curl -s "$url")
data=$(echo "$response" | jq -r '.data')
if echo "$response" | jq -e '.error' > /dev/null; then
error_message=$(echo "$response" | jq -r '.message')
echo "Error from API: $error_message"
exit 1
elif echo "$response" | jq -e '.data' > /dev/null; then
data=$(echo "$response" | jq -r '.data')
if [ -z "$data" ]; then
echo "Failed to retrieve 'data' from response."
exit 1
fi
else
echo "Unexpected response format from API."
echo "Full response: $response"
exit 1
fi

# Check if the data field is empty or not
if [ -z "$data" ]; then
Expand All @@ -81,11 +94,41 @@ fi
# Print the data (for debugging purposes)
echo "Data field extracted: $data"

forge script scripts/WithdrawPayloadScript.s.sol \
--sender "$userAddress" \
--rpc-url fork \
--unlocked \
--evm-version shanghai \
--broadcast \
-vvvv \
--sig "run(bytes,address,uint256,address,address)" "$data" "$outputTokenAddress" "$inputTokenAmount" "$strategyAddress" "$routerAddress"
# Ask the user which RPC URL to use
echo "Which RPC URL do you want to use?"
echo "1. Arbitrum"
echo "2. Fork"
read -p "Enter your choice (1 or 2): " rpc_choice

# Set the RPC URL and adjust the forge script command based on user choice
case $rpc_choice in
1)
rpc_url="arbitrum"
forge_command="forge script scripts/WithdrawPayloadScript.s.sol \
--sender \"$userAddress\" \
--rpc-url $rpc_url \
-i 1 \
--evm-version shanghai \
--broadcast \
-vvvv \
--sig \"run(bytes,uint256,address,address)\" \"$data\" \"$inputTokenAmount\" \"$strategyAddress\" \"$routerAddress\""
;;
2)
rpc_url="fork"
forge_command="forge script scripts/WithdrawPayloadScript.s.sol \
--sender \"$userAddress\" \
--rpc-url $rpc_url \
--unlocked \
--broadcast \
--evm-version shanghai \
-vvvv \
--sig \"run(bytes,uint256,address,address)\" \"$data\" \"$inputTokenAmount\" \"$strategyAddress\" \"$routerAddress\""
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac

# Execute the forge script command
eval "$forge_command"

0 comments on commit ebacebf

Please sign in to comment.