forked from uniswapfoundation/v4-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteract.sh
More file actions
192 lines (162 loc) · 6.65 KB
/
interact.sh
File metadata and controls
192 lines (162 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
# Script to interact with the deployed Kraken hook and test authorization
# Usage: ./interact.sh
set -e
echo "🔑 Loading environment variables..."
if [ ! -f .env ]; then
echo "❌ Error: .env file not found"
echo "Please run extract-addresses.sh first to create .env file"
exit 1
fi
source .env
# Verify required environment variables
required_vars=(
"PRIVATE_KEY"
"POOL_MANAGER_ADDRESS"
"HOOK_ADDRESS"
"TOKEN0_ADDRESS"
"TOKEN1_ADDRESS"
"POOL_SWAP_TEST_ADDRESS"
"POOL_MODIFY_LIQUIDITY_TEST_ADDRESS"
)
echo "🔍 Checking required environment variables..."
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
echo "❌ Error: $var not found in .env file"
exit 1
fi
if [ "$var" == "PRIVATE_KEY" ]; then
echo "✅ $var: [***]"
else
echo "✅ $var: ${!var}"
fi
done
echo ""
echo "🏊 Setting up pool interaction..."
# Extract wallet address from private key
WALLET_ADDRESS=$(cast wallet address --private-key $PRIVATE_KEY)
echo "📧 Wallet Address: $WALLET_ADDRESS"
echo ""
echo "💰 Checking token balances..."
# Check Token0 balance
TOKEN0_BALANCE=$(cast call $TOKEN0_ADDRESS "balanceOf(address)(uint256)" $WALLET_ADDRESS --rpc-url https://rpc-gel-sepolia.inkonchain.com)
TOKEN0_BALANCE_DEC=$(cast --to-dec $TOKEN0_BALANCE 2>/dev/null || echo $TOKEN0_BALANCE)
echo "🪙 Token0 Balance: $TOKEN0_BALANCE_DEC"
# Check Token1 balance
TOKEN1_BALANCE=$(cast call $TOKEN1_ADDRESS "balanceOf(address)(uint256)" $WALLET_ADDRESS --rpc-url https://rpc-gel-sepolia.inkonchain.com)
TOKEN1_BALANCE_DEC=$(cast --to-dec $TOKEN1_BALANCE 2>/dev/null || echo $TOKEN1_BALANCE)
echo "🪙 Token1 Balance: $TOKEN1_BALANCE_DEC"
echo ""
echo "🔓 Approving tokens for PoolSwapTest..."
# Approve Token0 for PoolSwapTest
echo "Approving Token0..."
cast send $TOKEN0_ADDRESS \
"approve(address,uint256)" \
$POOL_SWAP_TEST_ADDRESS \
1000000000000000000000 \
--private-key $PRIVATE_KEY \
--rpc-url https://rpc-gel-sepolia.inkonchain.com
# Approve Token1 for PoolSwapTest
echo "Approving Token1..."
cast send $TOKEN1_ADDRESS \
"approve(address,uint256)" \
$POOL_SWAP_TEST_ADDRESS \
1000000000000000000000 \
--private-key $PRIVATE_KEY \
--rpc-url https://rpc-gel-sepolia.inkonchain.com
echo ""
echo "🏊 Creating pool if it doesn't exist..."
# Create pool key struct data
# PoolKey: currency0, currency1, fee, tickSpacing, hooks
POOL_KEY_DATA=$(cast abi-encode \
"f(address,address,uint24,int24,address)" \
$TOKEN0_ADDRESS \
$TOKEN1_ADDRESS \
$POOL_FEE \
$TICK_SPACING \
$HOOK_ADDRESS)
echo "Pool Key Data: $POOL_KEY_DATA"
# Try to initialize the pool (this may fail if already initialized, which is OK)
echo "🔄 Attempting to initialize pool..."
INIT_RESULT=$(cast send $POOL_MODIFY_LIQUIDITY_TEST_ADDRESS \
--private-key $PRIVATE_KEY \
--rpc-url https://rpc-gel-sepolia.inkonchain.com \
--gas-limit 3000000 \
"initializePool((address,address,uint24,int24,address),uint160)" \
"($TOKEN0_ADDRESS,$TOKEN1_ADDRESS,$POOL_FEE,$TICK_SPACING,$HOOK_ADDRESS)" \
79228162514264337593543950336 2>&1)
if echo "$INIT_RESULT" | grep -q "status.*1 (success)" || echo "$INIT_RESULT" | grep -q "blockHash"; then
echo "✅ Pool initialized successfully"
else
echo "⚠️ Pool initialization failed (might already be initialized)"
fi
echo ""
echo "💧 Adding initial liquidity..."
# Add liquidity to the pool
cast send $POOL_MODIFY_LIQUIDITY_TEST_ADDRESS \
--private-key $PRIVATE_KEY \
--rpc-url https://rpc-gel-sepolia.inkonchain.com \
--gas-limit 3000000 \
"modifyLiquidity((address,address,uint24,int24,address),int24,int24,int256,bytes)" \
"($TOKEN0_ADDRESS,$TOKEN1_ADDRESS,$POOL_FEE,$TICK_SPACING,$HOOK_ADDRESS)" \
-- -600 \
600 \
1000000000000000000 \
"0x" || echo "⚠️ Liquidity addition failed"
echo ""
echo "🔄 Testing swap with Kraken hook authorization..."
# Perform a swap that will trigger the beforeSwap hook
echo "🚀 Executing swap to test Kraken hook..."
echo "This will test if the wallet address has proper attestation..."
# Swap parameters: zeroForOne=true, amountSpecified=-100000000000000000 (0.1 token), sqrtPriceLimitX96=0
SWAP_RESULT=$(cast send $POOL_SWAP_TEST_ADDRESS \
--private-key $PRIVATE_KEY \
--rpc-url https://rpc-gel-sepolia.inkonchain.com \
--gas-limit 3000000 \
"swap((address,address,uint24,int24,address),bool,int256,uint160,bytes)" \
"($TOKEN0_ADDRESS,$TOKEN1_ADDRESS,$POOL_FEE,$TICK_SPACING,$HOOK_ADDRESS)" \
true \
-- -100000000000000000 \
0 \
"0x" 2>&1)
echo "$SWAP_RESULT"
if echo "$SWAP_RESULT" | grep -q "Transaction successful" || echo "$SWAP_RESULT" | grep -q "blockHash"; then
echo ""
echo "🎉 SUCCESS! Swap completed successfully!"
echo "✅ The Kraken hook authorized the transaction"
echo "✅ Your wallet address ($WALLET_ADDRESS) has valid attestation"
echo ""
echo "💰 Updated token balances:"
# Check updated balances
TOKEN0_BALANCE_NEW=$(cast call $TOKEN0_ADDRESS "balanceOf(address)(uint256)" $WALLET_ADDRESS --rpc-url https://rpc-gel-sepolia.inkonchain.com)
TOKEN0_BALANCE_NEW_DEC=$(cast --to-dec $TOKEN0_BALANCE_NEW 2>/dev/null || echo $TOKEN0_BALANCE_NEW)
echo "🪙 Token0 Balance: $TOKEN0_BALANCE_NEW_DEC"
TOKEN1_BALANCE_NEW=$(cast call $TOKEN1_ADDRESS "balanceOf(address)(uint256)" $WALLET_ADDRESS --rpc-url https://rpc-gel-sepolia.inkonchain.com)
TOKEN1_BALANCE_NEW_DEC=$(cast --to-dec $TOKEN1_BALANCE_NEW 2>/dev/null || echo $TOKEN1_BALANCE_NEW)
echo "🪙 Token1 Balance: $TOKEN1_BALANCE_NEW_DEC"
else
echo ""
echo "❌ SWAP FAILED!"
if echo "$SWAP_RESULT" | grep -q "AttestationNotFound\|AttestationExpired\|AttestationRevoked"; then
echo "🔒 Authorization failed: Your wallet address does not have valid attestation"
echo "📋 Wallet Address: $WALLET_ADDRESS"
echo "🔑 Required Schema UID: 0x8ffa68bde25f7b88e042ea3dff55ff27217b7d1c4bf24f57967b285c5ffe4c8b"
echo ""
echo "💡 To fix this:"
echo "1. Get a valid attestation for your wallet address"
echo "2. Ensure the attestation uses the correct schema UID"
echo "3. Make sure the attestation is not expired or revoked"
else
echo "🔍 Error details:"
echo "$SWAP_RESULT"
fi
fi
echo ""
echo "📋 Interaction Summary:"
echo " - Hook Address: $HOOK_ADDRESS"
echo " - Wallet Address: $WALLET_ADDRESS"
echo " - Pool: $TOKEN0_ADDRESS / $TOKEN1_ADDRESS"
echo " - Pool Fee: $POOL_FEE"
echo " - Network: INK Sepolia (Chain ID: $CHAIN_ID)"
echo ""
echo "🔗 Explorer: https://explorer-sepolia.inkonchain.com/address/$HOOK_ADDRESS"