Skip to content

Instantly share code, notes, and snippets.

@kmbarry1
Last active April 24, 2021 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmbarry1/41d65733746ed60189b471826b770be5 to your computer and use it in GitHub Desktop.
Save kmbarry1/41d65733746ed60189b471826b770be5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Your ETH_RPC_URL envvar should point to an archive node.
# Not in principle perfectly accurate, since COL isn't necessarily monotonic.
# Also doesn't account for underwater Vaults, but these are rare (not sure
# if there has ever been one for ETH-A, in fact).
# But, should be good enough to give an idea when the problem began.
ILK_STR="ETH-A"
ILK=$(seth --to-bytes32 $(seth --from-ascii "ETH-A"))
OSM=0x81FE72B5A8d1A857d176C3E7d5Bd2679A9B85763
VAT=0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B
SPOT=0x65C79fcB50Ca1594B025960e539eD7A9a6D434A3
MAX_RAD=$(bc <<< "scale=0; (2^256 - 1) / 10^27")
START_BLOCK=8957500
FINAL_BLOCK=12262620
BLOCK=$(( ( $START_BLOCK + $FINAL_BLOCK ) / 2 ))
while [[ $BLOCK -ne $START_BLOCK ]]
do
echo "BLOCK: $BLOCK"
ILK_DATA=()
while IFS='\n' read -r LINE; do ILK_DATA+=("$LINE"); done <<< $(seth -B $BLOCK call $VAT "ilks(bytes32)(uint256,uint256,uint256,uint256,uint256)" $ILK)
ART=${ILK_DATA[0]}
RATE=${ILK_DATA[1]}
ILK_DAI=$(bc <<< "$ART * $RATE")
PRICE=$(seth -B $BLOCK -F $SPOT call $OSM "read()(uint256)")
COL=$(bc <<< "scale=0; ($ILK_DAI / $PRICE) / 10^9")
OVERFLOW=$(bc <<< "$MAX_RAD < ($COL * 10^27)")
if [[ $OVERFLOW -eq 1 ]]; then
# Overflow occurring; move BLOCK and FINAL_BLOCK earlier.
FINAL_BLOCK=$BLOCK
BLOCK=$(( ( $START_BLOCK + $FINAL_BLOCK ) / 2 ))
else
# Overflow not occurring; move BLOCK and START_BLOCK later.
START_BLOCK=$BLOCK
BLOCK=$(( ( $START_BLOCK + $FINAL_BLOCK ) / 2 ))
fi
done
echo "First overflowing block: $FINAL_BLOCK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment