diff --git a/.github/workflows/aave-bad-debt.yml b/.github/workflows/aave-bad-debt.yml index 412bb6c..72e2499 100644 --- a/.github/workflows/aave-bad-debt.yml +++ b/.github/workflows/aave-bad-debt.yml @@ -13,15 +13,40 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.10' + cache: 'pip' # caching pip dependencies - name: Install dependencies run: | python -m pip install --upgrade pip if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run script + - name: Run Aave V3 Mainnet run: python bad-debt-trigger.py env: TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} PROTOCOL: "Aave V3 Mainnet" DEBT_THRESHOLD_RATIO: "1" - DATA_URL: "https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/ethereum_aave%20v3.json" # https://github.com/Risk-DAO/simulation-results/blob/main/bad-debt/latest/ethereum_aave%20v3.json \ No newline at end of file + DATA_URL: "https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/ethereum_aave%20v3.json" + - name: Run Aave V3 Arbitrum + run: python bad-debt-trigger.py + env: + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + PROTOCOL: "Aave V3 Arbitrum" + DEBT_THRESHOLD_RATIO: "1" + DATA_URL: "https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/arbitrum_aave%20v3.json" + - name: Run Aave V3 Polygon + run: python bad-debt-trigger.py + env: + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + PROTOCOL: "Aave V3 Polygon" + DEBT_THRESHOLD_RATIO: "1" + DATA_URL: "https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/polygon_aave%20v3.json" + - name: Run Aave V3 Optimism + run: python bad-debt-trigger.py + env: + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + PROTOCOL: "Aave V3 Optimism" + DEBT_THRESHOLD_RATIO: "1" + DATA_URL: "https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/optimism_aave%20v3.json" \ No newline at end of file diff --git a/README.md b/README.md index 21bff2c..bbbb5ba 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,3 @@ Alerting Telegram bot for bad debt data from Risk DAO. It's a simple Python scri - `DEBT_THRESHOLD` in dollars after which an alert will be sent to Telegram chat. Optional value. - `DEBT_THRESHOLD_RATIO` in percent after which an alert will be sent to Telegram chat. Default value is 100%. - `DATA_URL` link to the data source in JSON format. [Link](https://github.com/Risk-DAO/simulation-results/tree/main/bad-debt/latest) to all RiskDAO data sources. Example data URL for [Sonne Finance](https://raw.githubusercontent.com/Risk-DAO/simulation-results/main/bad-debt/latest/optimism_sonne.json). - -## Custom alerts - -### USDR Treasury - -There is a special workflow for USDR Treasury. It checks if the USDR Treasury in DAI is below a given ratio threshold it will send Telegram message to a defined chat. diff --git a/usdr-treasury-trigger.py b/usdr-treasury-trigger.py deleted file mode 100644 index 58df07a..0000000 --- a/usdr-treasury-trigger.py +++ /dev/null @@ -1,63 +0,0 @@ -import os, requests, datetime, locale -import asyncio, telegram - - -def get_dai_in_treasury(): - dai_address = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063" - url = f"https://api.polygonscan.com/api?module=account&action=tokenbalance&contractaddress={dai_address}&address={treasury_address}&tag=latest&apikey={api_key}" - - response = requests.get(url) - - if response.status_code == 200: - balance = int(response.json()["result"]) / 10**18 - print(f"The balance of Treasury in DAI is {balance}") - return balance - else: - print(f"Request failed with status code {response.status_code}") - return 0 - - -def get_usdr_total_supply(): - token_address = "0x40379a439d4f6795b6fc9aa5687db461677a2dba" - url = f"https://api.polygonscan.com/api?module=stats&action=tokensupply&contractaddress={token_address}&apikey={api_key}" - - response = requests.get(url) - - if response.status_code == 200: - supply = int(response.json()["result"]) / 10**9 - print(f"The total supply of {token_address} is {supply}") - return supply - else: - print(f"Request failed with status code {response.status_code}") - return 0 - - -api_key = os.environ["POLYGON_KEY"] -locale.setlocale(locale.LC_ALL, "en_US.UTF-8") - -treasury_address = "0x6ef682f0223687c625e6c4a115f544a80c37da33" - -dai_in_treasury = get_dai_in_treasury() -usdr_total_supply = get_usdr_total_supply() - -# ratio of dai in treasury to total supply of usdr -ratio_of_dai_to_usdr = round(dai_in_treasury / usdr_total_supply * 100, 2) -print( - f"The ratio of DAI in treasury to total supply of USDR is {ratio_of_dai_to_usdr}%" -) - -threshold_ratio = float(os.getenv("USDR_DAI_THRESHOLD_RATIO", 100)) - -date = datetime.datetime.now() -formatted_date = date.strftime("%Y-%m-%d %H:%M:%S") -message = f"⚠️ USDR treasury has {ratio_of_dai_to_usdr}% of DAI at {formatted_date} ⚠️\nDAI in treasury: {dai_in_treasury:,.2f}\nTotal supply of USDR: {usdr_total_supply:,.2f}" -print(message) - -if ratio_of_dai_to_usdr < threshold_ratio: - bot = telegram.Bot(token=os.environ["TELEGRAM_TOKEN"]) - chat_ids = os.environ["TELEGRAM_USDR_CHAT_ID"].split(",") - print(f"Sending Telegram message") - for chat_id in chat_ids: - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - loop.run_until_complete(bot.send_message(chat_id=chat_id, text=message))