Last active
April 24, 2021 03:01
-
-
Save kmbarry1/41d65733746ed60189b471826b770be5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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