parent
d9b5131101
commit
79c9c8571a
1 changed files with 32 additions and 4 deletions
|
|
@ -125,10 +125,38 @@ seed_application_state() {
|
||||||
bootstrap_log "Approving router"
|
bootstrap_log "Approving router"
|
||||||
cast send --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \
|
cast send --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \
|
||||||
"$WETH" "approve(address,uint256)" "$SWAP_ROUTER" "$MAX_UINT" >>"$LOG_FILE" 2>&1
|
"$WETH" "approve(address,uint256)" "$SWAP_ROUTER" "$MAX_UINT" >>"$LOG_FILE" 2>&1
|
||||||
bootstrap_log "Executing initial KRK swap"
|
|
||||||
|
# Swap with retry — recenter may not position liquidity at the right tick on first call
|
||||||
|
local swap_success=false
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
bootstrap_log "KRK swap attempt $attempt/3"
|
||||||
|
local balance_before balance_after
|
||||||
|
balance_before=$(cast call --rpc-url "$ANVIL_RPC" "$KRAIKEN" "balanceOf(address)(uint256)" "$DEPLOYER_ADDR" 2>/dev/null || echo "0")
|
||||||
|
|
||||||
cast send --legacy --gas-limit 300000 --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \
|
cast send --legacy --gas-limit 300000 --rpc-url "$ANVIL_RPC" --private-key "$DEPLOYER_PK" \
|
||||||
"$SWAP_ROUTER" "exactInputSingle((address,address,uint24,address,uint256,uint256,uint160))" \
|
"$SWAP_ROUTER" "exactInputSingle((address,address,uint24,address,uint256,uint256,uint160))" \
|
||||||
"($WETH,$KRAIKEN,10000,$DEPLOYER_ADDR,1000000000000000000,0,4295128740)" >>"$LOG_FILE" 2>&1
|
"($WETH,$KRAIKEN,10000,$DEPLOYER_ADDR,1000000000000000000,0,4295128740)" >>"$LOG_FILE" 2>&1 || true
|
||||||
|
|
||||||
|
balance_after=$(cast call --rpc-url "$ANVIL_RPC" "$KRAIKEN" "balanceOf(address)(uint256)" "$DEPLOYER_ADDR" 2>/dev/null || echo "0")
|
||||||
|
|
||||||
|
if [[ "$balance_after" != "$balance_before" && "$balance_after" != "0" ]]; then
|
||||||
|
bootstrap_log "Swap successful — got KRK tokens (balance: $balance_after)"
|
||||||
|
swap_success=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
bootstrap_log "Swap returned 0 KRK — recentering and retrying"
|
||||||
|
# Mine a few blocks to advance time, then recenter
|
||||||
|
cast rpc --rpc-url "$ANVIL_RPC" evm_mine >>"$LOG_FILE" 2>&1 || true
|
||||||
|
cast rpc --rpc-url "$ANVIL_RPC" evm_mine >>"$LOG_FILE" 2>&1 || true
|
||||||
|
local recenter_pk="${TXNBOT_PRIVATE_KEY:-$DEPLOYER_PK}"
|
||||||
|
cast send --rpc-url "$ANVIL_RPC" --private-key "$recenter_pk" \
|
||||||
|
"$LIQUIDITY_MANAGER" "recenter()" >>"$LOG_FILE" 2>&1 || true
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$swap_success" != "true" ]]; then
|
||||||
|
bootstrap_log "WARNING: All swap attempts returned 0 KRK. Pool may have no liquidity at current tick."
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fund_txn_bot_wallet() {
|
fund_txn_bot_wallet() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue