diff --git a/scripts/deployment/add-mainnet-public-dodo-cw-liquidity.sh b/scripts/deployment/add-mainnet-public-dodo-cw-liquidity.sh index 24d8b911..19fd52e8 100755 --- a/scripts/deployment/add-mainnet-public-dodo-cw-liquidity.sh +++ b/scripts/deployment/add-mainnet-public-dodo-cw-liquidity.sh @@ -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)' \ diff --git a/scripts/deployment/deploy-mainnet-cwusdt-cwusdc-pool.sh b/scripts/deployment/deploy-mainnet-cwusdt-cwusdc-pool.sh index 66e5d9ef..130cf63f 100755 --- a/scripts/deployment/deploy-mainnet-cwusdt-cwusdc-pool.sh +++ b/scripts/deployment/deploy-mainnet-cwusdt-cwusdc-pool.sh @@ -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)' \ diff --git a/scripts/deployment/deploy-mainnet-pmm-cw-truu-pool.sh b/scripts/deployment/deploy-mainnet-pmm-cw-truu-pool.sh index c503293a..211f1853 100755 --- a/scripts/deployment/deploy-mainnet-pmm-cw-truu-pool.sh +++ b/scripts/deployment/deploy-mainnet-pmm-cw-truu-pool.sh @@ -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)' \ diff --git a/scripts/deployment/deploy-mainnet-public-dodo-wave1-pool.sh b/scripts/deployment/deploy-mainnet-public-dodo-wave1-pool.sh index 8c059044..e1656c4f 100644 --- a/scripts/deployment/deploy-mainnet-public-dodo-wave1-pool.sh +++ b/scripts/deployment/deploy-mainnet-public-dodo-wave1-pool.sh @@ -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)' \ diff --git a/scripts/deployment/replace-mainnet-public-dodo-cw-pool.sh b/scripts/deployment/replace-mainnet-public-dodo-cw-pool.sh index 54ec723d..66cbb92d 100755 --- a/scripts/deployment/replace-mainnet-public-dodo-cw-pool.sh +++ b/scripts/deployment/replace-mainnet-public-dodo-cw-pool.sh @@ -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)' \ diff --git a/scripts/deployment/run-mainnet-public-dodo-cw-swap.sh b/scripts/deployment/run-mainnet-public-dodo-cw-swap.sh index d6ea8e87..25449de2 100755 --- a/scripts/deployment/run-mainnet-public-dodo-cw-swap.sh +++ b/scripts/deployment/run-mainnet-public-dodo-cw-swap.sh @@ -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" \