- Update dbis_core, cross-chain-pmm-lps, explorer-monorepo, metamask-integration, pr-workspace/chains - Omit embedded publish git dirs and empty placeholders from index Made-with: Cursor
102 lines
2.9 KiB
Bash
Executable File
102 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Emit UNWIND_V3_PATH_HEX (0x-prefixed packed bytes) for Uniswap V3 exactInput, used with
|
|
# UNWIND_MODE=2 in RunMainnetAaveCwusdcUsdcQuotePushOnce.s.sol / UniswapV3ExternalUnwinder.
|
|
#
|
|
# Path layout: token0 (20) | fee0 (3 BE) | token1 (20) | fee1 (3 BE) | ... | tokenN (20)
|
|
#
|
|
# Usage (2-hop = 3 tokens, 2 fees):
|
|
# bash scripts/verify/build-uniswap-v3-exact-input-path-hex.sh \
|
|
# 0x2de5F116bFcE3d0f922d9C8351e0c5Fc24b9284a 3000 \
|
|
# 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 500 \
|
|
# 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
|
|
#
|
|
# Optional: verify each hop has a V3 pool on mainnet (read-only):
|
|
# source scripts/lib/load-project-env.sh
|
|
# VERIFY_POOLS=1 bash scripts/verify/build-uniswap-v3-exact-input-path-hex.sh ...
|
|
#
|
|
# Requires: python3
|
|
|
|
if (( $# < 3 || ($# % 2) == 0 )); then
|
|
echo "[fail] need odd arg count >= 3: ADDR0 FEE0 ADDR1 [FEE1 ADDR2 ...] ADDRN" >&2
|
|
exit 1
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROXMOX_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
|
# shellcheck disable=SC1091
|
|
source "${PROXMOX_ROOT}/scripts/lib/load-project-env.sh" 2>/dev/null || true
|
|
|
|
require_cmd() {
|
|
command -v "$1" >/dev/null 2>&1 || {
|
|
echo "[fail] missing required command: $1" >&2
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
require_cmd python3
|
|
FACTORY=0x1F98431c8aD98523631AE4a59f267346ea31F984
|
|
|
|
path_hex="$(
|
|
python3 - "$@" <<'PY'
|
|
import sys
|
|
|
|
def addr(s: str) -> bytes:
|
|
s = s.strip().lower()
|
|
if not s.startswith("0x") or len(s) != 42:
|
|
raise SystemExit(f"bad address: {s}")
|
|
return bytes.fromhex(s[2:])
|
|
|
|
def fee_u24(x: str) -> bytes:
|
|
v = int(x)
|
|
if v < 0 or v >= 1 << 24:
|
|
raise SystemExit(f"bad fee u24: {x}")
|
|
return v.to_bytes(3, "big")
|
|
|
|
args = sys.argv[1:]
|
|
if len(args) < 3 or len(args) % 2 == 0:
|
|
raise SystemExit("internal arg pattern error")
|
|
out = b""
|
|
# pairs: (addr, fee), (addr, fee), ... last addr
|
|
while len(args) >= 3:
|
|
out += addr(args[0])
|
|
out += fee_u24(args[1])
|
|
args = args[2:]
|
|
out += addr(args[0])
|
|
print("0x" + out.hex())
|
|
PY
|
|
)"
|
|
|
|
if [[ "${VERIFY_POOLS:-0}" == "1" ]]; then
|
|
require_cmd cast
|
|
RPC="${ETHEREUM_MAINNET_RPC:-}"
|
|
if [[ -z "$RPC" ]]; then
|
|
echo "[fail] VERIFY_POOLS=1 needs ETHEREUM_MAINNET_RPC" >&2
|
|
exit 1
|
|
fi
|
|
args=("$@")
|
|
while ((${#args[@]} >= 3)); do
|
|
a="${args[0]}"
|
|
fee="${args[1]}"
|
|
b="${args[2]}"
|
|
if [[ "${a,,}" < "${b,,}" ]]; then
|
|
t0="$a"
|
|
t1="$b"
|
|
else
|
|
t0="$b"
|
|
t1="$a"
|
|
fi
|
|
p="$(cast call "$FACTORY" "getPool(address,address,uint24)(address)" "$t0" "$t1" "$fee" --rpc-url "$RPC" | awk '{print $1}')"
|
|
echo "probe getPool fee=$fee pool=$p ($t0,$t1)"
|
|
if [[ "${p,,}" == "0x0000000000000000000000000000000000000000" ]]; then
|
|
echo "[warn] no pool for this hop/fee — exactInput will revert" >&2
|
|
fi
|
|
args=("${args[@]:2}")
|
|
done
|
|
fi
|
|
|
|
echo "UNWIND_V3_PATH_HEX=$path_hex"
|
|
echo "export UNWIND_MODE=2"
|
|
echo "export UNWIND_V3_PATH_HEX=$path_hex"
|