Fix 256-bit allowance checks in mainnet PMM scripts
All checks were successful
Deploy to Phoenix / deploy (push) Successful in 10s

This commit is contained in:
defiQUG
2026-04-14 18:22:53 -07:00
parent 1ba773ed93
commit fb1d90c3d2
6 changed files with 65 additions and 12 deletions

View File

@@ -60,6 +60,13 @@ require_cmd() {
}
}
uint_lt() {
python3 - "$1" "$2" <<'PY'
import sys
print("1" if int(sys.argv[1]) < int(sys.argv[2]) else "0")
PY
}
require_cmd cast
PAIR=""
@@ -173,6 +180,8 @@ base_balance_before="$(cast call "$BASE_TOKEN" 'balanceOf(address)(uint256)' "$D
quote_balance_before="$(cast call "$QUOTE_TOKEN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_allowance_before="$(cast call "$BASE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_allowance_before="$(cast call "$QUOTE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_approval_required="$(uint_lt "$base_allowance_before" "$BASE_AMOUNT")"
quote_approval_required="$(uint_lt "$quote_allowance_before" "$QUOTE_AMOUNT")"
reserves_before="$(cast call "$POOL" 'getVaultReserve()(uint256,uint256)' --rpc-url "$RPC_URL")"
base_reserve_before="$(printf '%s\n' "$reserves_before" | sed -n '1p' | awk '{print $1}')"
quote_reserve_before="$(printf '%s\n' "$reserves_before" | sed -n '2p' | awk '{print $1}')"
@@ -214,7 +223,7 @@ fi
approve_base_tx=""
approve_quote_tx=""
if (( base_allowance_before < BASE_AMOUNT )); then
if [[ "$base_approval_required" == "1" ]]; then
approve_base_output="$(
cast send "$BASE_TOKEN" \
'approve(address,uint256)(bool)' \
@@ -225,7 +234,7 @@ if (( base_allowance_before < BASE_AMOUNT )); then
approve_base_tx="$(parse_tx_hash "$approve_base_output")"
fi
if (( quote_allowance_before < QUOTE_AMOUNT )); then
if [[ "$quote_approval_required" == "1" ]]; then
approve_quote_output="$(
cast send "$QUOTE_TOKEN" \
'approve(address,uint256)(bool)' \

View File

@@ -31,6 +31,13 @@ require_cmd() {
}
}
uint_lt() {
python3 - "$1" "$2" <<'PY'
import sys
print("1" if int(sys.argv[1]) < int(sys.argv[2]) else "0")
PY
}
require_cmd cast
INITIAL_PRICE="1000000000000000000"
@@ -114,6 +121,8 @@ base_balance_before="$(cast call "$BASE_TOKEN" 'balanceOf(address)(uint256)' "$D
quote_balance_before="$(cast call "$QUOTE_TOKEN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_allowance_before="$(cast call "$BASE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_allowance_before="$(cast call "$QUOTE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_approval_required="$(uint_lt "$base_allowance_before" "$BASE_AMOUNT")"
quote_approval_required="$(uint_lt "$quote_allowance_before" "$QUOTE_AMOUNT")"
create_gas="0"
if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
@@ -206,7 +215,7 @@ if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
exit 1
fi
if (( base_allowance_before < BASE_AMOUNT )); then
if [[ "$base_approval_required" == "1" ]]; then
approve_base_output="$(
cast send "$BASE_TOKEN" \
'approve(address,uint256)(bool)' \
@@ -217,7 +226,7 @@ if (( base_allowance_before < BASE_AMOUNT )); then
approve_base_tx="$(parse_tx_hash "$approve_base_output")"
fi
if (( quote_allowance_before < QUOTE_AMOUNT )); then
if [[ "$quote_approval_required" == "1" ]]; then
approve_quote_output="$(
cast send "$QUOTE_TOKEN" \
'approve(address,uint256)(bool)' \

View File

@@ -44,6 +44,13 @@ require_cmd() {
}
}
uint_lt() {
python3 - "$1" "$2" <<'PY'
import sys
print("1" if int(sys.argv[1]) < int(sys.argv[2]) else "0")
PY
}
require_cmd cast
PAIR=""
@@ -141,6 +148,8 @@ base_balance_before="$(cast call "$BASE_TOKEN" 'balanceOf(address)(uint256)' "$D
quote_balance_before="$(cast call "$QUOTE_TOKEN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_allowance_before="$(cast call "$BASE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_allowance_before="$(cast call "$QUOTE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_approval_required="$(uint_lt "$base_allowance_before" "$BASE_AMOUNT")"
quote_approval_required="$(uint_lt "$quote_allowance_before" "$QUOTE_AMOUNT")"
create_gas="0"
if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
@@ -216,7 +225,7 @@ if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
exit 1
fi
if (( base_allowance_before < BASE_AMOUNT )); then
if [[ "$base_approval_required" == "1" ]]; then
approve_base_output="$(
cast send "$BASE_TOKEN" \
'approve(address,uint256)(bool)' \
@@ -227,7 +236,7 @@ if (( base_allowance_before < BASE_AMOUNT )); then
approve_base_tx="$(parse_tx_hash "$approve_base_output")"
fi
if (( quote_allowance_before < QUOTE_AMOUNT )); then
if [[ "$quote_approval_required" == "1" ]]; then
approve_quote_output="$(
cast send "$QUOTE_TOKEN" \
'approve(address,uint256)(bool)' \

View File

@@ -25,6 +25,13 @@ require_cmd() {
}
}
uint_lt() {
python3 - "$1" "$2" <<'PY'
import sys
print("1" if int(sys.argv[1]) < int(sys.argv[2]) else "0")
PY
}
require_cmd cast
PAIR=""
@@ -176,6 +183,8 @@ base_balance_before="$(cast call "$BASE_TOKEN" 'balanceOf(address)(uint256)' "$D
quote_balance_before="$(cast call "$USDC_MAINNET" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_allowance_before="$(cast call "$BASE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_allowance_before="$(cast call "$USDC_MAINNET" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_approval_required="$(uint_lt "$base_allowance_before" "$BASE_AMOUNT")"
quote_approval_required="$(uint_lt "$quote_allowance_before" "$QUOTE_AMOUNT")"
create_gas="0"
if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
@@ -255,7 +264,7 @@ if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
exit 1
fi
if (( base_allowance_before < BASE_AMOUNT )); then
if [[ "$base_approval_required" == "1" ]]; then
approve_base_output="$(
cast send "$BASE_TOKEN" \
'approve(address,uint256)(bool)' \
@@ -266,7 +275,7 @@ if (( base_allowance_before < BASE_AMOUNT )); then
approve_base_tx="$(parse_tx_hash "$approve_base_output")"
fi
if (( quote_allowance_before < QUOTE_AMOUNT )); then
if [[ "$quote_approval_required" == "1" ]]; then
approve_quote_output="$(
cast send "$USDC_MAINNET" \
'approve(address,uint256)(bool)' \

View File

@@ -24,6 +24,13 @@ require_cmd() {
}
}
uint_lt() {
python3 - "$1" "$2" <<'PY'
import sys
print("1" if int(sys.argv[1]) < int(sys.argv[2]) else "0")
PY
}
require_cmd cast
PAIR=""
@@ -137,6 +144,8 @@ base_balance_before="$(cast call "$BASE_TOKEN" 'balanceOf(address)(uint256)' "$D
quote_balance_before="$(cast call "$QUOTE_TOKEN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_allowance_before="$(cast call "$BASE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_allowance_before="$(cast call "$QUOTE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_approval_required="$(uint_lt "$base_allowance_before" "$BASE_AMOUNT")"
quote_approval_required="$(uint_lt "$quote_allowance_before" "$QUOTE_AMOUNT")"
if (( base_balance_before < BASE_AMOUNT )); then
echo "[fail] insufficient base balance: have=$base_balance_before need=$BASE_AMOUNT" >&2
@@ -199,7 +208,7 @@ fi
approve_base_tx=""
approve_quote_tx=""
if (( base_allowance_before < BASE_AMOUNT )); then
if [[ "$base_approval_required" == "1" ]]; then
approve_base_output="$(
cast send "$BASE_TOKEN" \
'approve(address,uint256)(bool)' \
@@ -210,7 +219,7 @@ if (( base_allowance_before < BASE_AMOUNT )); then
approve_base_tx="$(parse_tx_hash "$approve_base_output")"
fi
if (( quote_allowance_before < QUOTE_AMOUNT )); then
if [[ "$quote_approval_required" == "1" ]]; then
approve_quote_output="$(
cast send "$QUOTE_TOKEN" \
'approve(address,uint256)(bool)' \

View File

@@ -31,6 +31,13 @@ require_cmd() {
}
}
uint_lt() {
python3 - "$1" "$2" <<'PY'
import sys
print("1" if int(sys.argv[1]) < int(sys.argv[2]) else "0")
PY
}
require_cmd cast
require_cmd python3
@@ -231,6 +238,7 @@ fi
allowance="$(cast call "$TOKEN_IN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
balance_in_before="$(cast call "$TOKEN_IN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
balance_out_before="$(cast call "$TOKEN_OUT" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
approval_required="$(uint_lt "$allowance" "$AMOUNT")"
if (( balance_in_before < AMOUNT )); then
echo "[fail] insufficient input-token balance: have=$balance_in_before need=$AMOUNT" >&2
@@ -256,7 +264,7 @@ if (( DRY_RUN == 1 )); then
echo "tokenInBalanceBefore=$balance_in_before"
echo "tokenOutBalanceBefore=$balance_out_before"
echo "allowanceBefore=$allowance"
echo "approvalRequired=$(( allowance < AMOUNT ? 1 : 0 ))"
echo "approvalRequired=$approval_required"
echo "dryRun=1"
exit 0
fi
@@ -272,7 +280,7 @@ cleanup_lock() {
}
trap cleanup_lock EXIT
if (( allowance < AMOUNT )); then
if [[ "$approval_required" == "1" ]]; then
cast send "$TOKEN_IN" \
'approve(address,uint256)(bool)' \
"$INTEGRATION" "$AMOUNT" \