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
6 changes: 6 additions & 0 deletions scripts/unlocked_funds/.env.devnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RPC_URL=http://localhost:8545
NETWORK=devnet
BATCHER_PAYMENT_SERVICE_ADDRESS=0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650
# Anvil address 6
PRIVATE_KEY=0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
SLEEP_SECONDS=3600
5 changes: 5 additions & 0 deletions scripts/unlocked_funds/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RPC_URL=
NETWORK=
BATCHER_PAYMENT_SERVICE_ADDRESS
PRIVATE_KEY=
SLEEP_SECONDS=
51 changes: 51 additions & 0 deletions scripts/unlocked_funds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Unlocked Funds Test Script

## Overview

The `test_unlocked_funds.sh` script tests the unlocked funds flow in the Aligned protocol by continuously cycling between locking and unlocking funds while submitting proofs.

## Usage

**Important: This script must be run from the root of the repository.**

```bash
./scripts/unlocked_funds/test_unlocked_funds.sh <env_file_path>
```

## Required Environment Variables

The script requires an environment file with the following variables:

- `RPC_URL` - RPC endpoint URL for the blockchain network
- `NETWORK` - Network identifier (e.g., holesky, mainnet)
- `BATCHER_PAYMENT_SERVICE_ADDRESS` - Contract address of the batcher payment service
- `PRIVATE_KEY` - Private key for transaction signing
- `SLEEP_SECONDS` - Sleep duration between cycles (in seconds)

## How It Works

1. **Initial Setup**: Locks funds using the batcher payment service contract
2. **Continuous Loop**:
- Submits a proof to Aligned (runs in background)
- Waits 5 minutes
- Unlocks funds from the contract
- Sleeps for the configured duration
- Locks funds again
- Repeats the cycle

## Test Files

The script uses test files located at:
- `./scripts/test_files/circom_groth16_bn256_script/proof.json`
- `./scripts/test_files/circom_groth16_bn256_script/public.json`
- `./scripts/test_files/circom_groth16_bn256_script/verification_key.json`

## Success Criteria

The test is considered successful when the `UserFundsUnlocked` event is detected in the proof submission output.

## Dependencies

- `aligned` CLI tool
- `cast` (from Foundry)
- Bash shell environment
87 changes: 87 additions & 0 deletions scripts/unlocked_funds/test_unlocked_funds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

# ENV VARIABLES:
# - RPC_URL
# - NETWORK
# - BATCHER_PAYMENT_SERVICE_ADDRESS
# - PRIVATE_KEY
# - SLEEP_SECONDS

# Load env file from $1 path
source "$1"

### FUNCTIONS ###

# Function to log with timestamp and severity
function log() {
local severity=$1
local message=$2
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')

echo "[$timestamp] [$severity] $message"
}

# Function to send a proof to Aligned
function send_proof() {
log "INFO" "⏳ Sending proof to Aligned..."

submit=$(aligned submit \
--rpc_url $RPC_URL \
--network $NETWORK \
--private_key $PRIVATE_KEY \
--proving_system CircomGroth16Bn256 \
--proof ./scripts/test_files/circom_groth16_bn256_script/proof.json \
--public_input ./scripts/test_files/circom_groth16_bn256_script/public.json \
--vk ./scripts/test_files/circom_groth16_bn256_script/verification_key.json \
--custom_fee_estimate 64 \
2>&1)

# Check if UserFundsUnlocked appears in the output
if echo "$submit" | grep -q "UserFundsUnlocked"; then
log "INFO" "✅ Test successful - UserFundsUnlocked event detected"
else
log "ERROR" "❌ Test failed - UserFundsUnlocked event not detected"
log "ERROR" "Submit output: $submit"
fi
}


# Function to unlock funds
function unlock_funds() {
log "INFO" "⏳ Unlocking funds..."
output=$(cast send $BATCHER_PAYMENT_SERVICE_ADDRESS "unlock()" \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY 2>&1)

if echo "$output" | grep -q "status.*1 (success)"; then
log "INFO" "✅ Unlock transaction successful"
else
log "ERROR" "❌ Unlock transaction failed"
fi
}

# Function to lock funds
function lock_funds() {
log "INFO" "⏳ Locking funds..."
output=$(cast send $BATCHER_PAYMENT_SERVICE_ADDRESS "lock()" \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY 2>&1)

if echo "$output" | grep -q "status.*1 (success)"; then
log "INFO" "✅ Lock transaction successful"
else
log "ERROR" "❌ Lock transaction failed"
fi
}

### MAIN LOOP ###
log "INFO" "🚀 Running..."
lock_funds
while true
do
send_proof &
sleep 300
unlock_funds
sleep $SLEEP_SECONDS
lock_funds
done