Monitoring USDC depegging risk with this software that I have written

Discussion in 'Crypto Assets' started by Market_Observer, May 25, 2022.

  1. After UST stablecoin depegged and crashed 2 weeks ago, fear spread to other stablecoins. The most dominant stablecoin, USDT, was briefly depegged. If the biggest stablecoin is in danger, the risk to the other smaller stablecoins cannot be ignored.

    Some will say there is no need to worry about USDC. USDC was one of the beneficiaries after the stablecoins turmoil. Investors took out funds from USDT and transferred them to USDC because of its perceived higher safety. Market capitalization of USDT has declined almost 12% versus growth of almost 7% in USDC in the past 1 month.

    [​IMG]
    If there is one thing that the 2008 financial crisis and Anchor/Luna/UST total collapse has taught me, it is that the thing that causes the greatest financial damage is what we think is safe but turns out otherwise. Therefore, prudent risk management means we should monitor what is deemed safe, even though the probability of a bad event happening is extremely low.

    The metrics I use for monitoring USDC de-pegging risk

    • Curve 3pool balance proportion
      If the USDC proportion exceeds 50% of the 3pool liquidity pool, go to risk-on mode. Risk-on means getting ready to sell if conditions deteriorate.
    • Market price of USDC
      If USDC price falls to $0.995, go to risk-on mode. Usually, when a stablecoin depegs, the rebound action will be quick. Be extra alert if the rebound is slow in response.
    • Market capitalization of USDC
      If USDC market capitalization suffers a weekly decline of more than 5%, start paying more attention.
    I wrote software (source code to be provided) to monitor the de-pegging risk of USDC. When the criteria are met, a telegram message will be sent to myself.

    I will explain the workings of the source code in the following paragraphs. You can ignore them if you are not into programming or are already an experienced Web3 programmer.

    The 3pool balance data is extracted on-chain using Web3.py (python library for interacting with Ethereum smart contracts). Only Ethereum nodes can interact with Ethereum smart contract. Setting up an Ethereum node on your PC is difficult and costly. The solution is to use a middleman node. Thankfully, Infuria provides this service.

    Before the script can interact with Ethereum smart contract, one has to set up an account with Infuria, and then obtain a URL endpoint. You can watch this video on how to do it.

    Assign the URL endpoint into infuria_url variable in the function get_3pool_liquidity_balance_percentage().

    The next step before one can interact with a smart contract is to find out its address and ABI (Application Binary Interface). I found out the address of the 3pool smart contract on Curve Finance. There are several smart contracts on Curve. Don't choose the wrong one. From the address, the smart contract source code and ABI can usually be found on Etherscan.

    This is the link where you can read the Curve smart contract source code which runs 3pool.
    https://etherscan.io/address/0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7#code

    Reading the source code will be useful if one needs to interact with the smart contract. From the source code, the relevant function to call in our context is balances() which returns the stablecoin balance in the liquidity pool.

    upload_2022-5-26_9-40-26.png

    The market cap and price data is extracted from Defi Llama through REST API. I love Defi Llama APIs because they are free of charge. The source of the price data feed is Chainlink. Chainlink data have to be reliable and accurate because smart contracts run on them. Inaccurate data can lead to wrong decisions made by smart contracts. The consequences can be disastrous if huge sums of money are involved. Imagine your funds getting liquidated by a DeFi smart contract because of an inaccurate price feed.

    upload_2022-5-26_9-41-52.png

    The software will send a telegram message to alert me when the risk criteria is met. send_telegram_message() uses the python-telegram-bot library. I created my own telegram bot. My telegram user account will send the alert message to this bot which will instantly notify me on receiving this alert. Visit the links for instructions on extracting the bot token and user chat_id in order to send the telegram message through `send_telegram_message().

    upload_2022-5-26_9-42-15.png

    Finally, the source code can be downloaded here.
     
  2. maxinger

    maxinger

    [​IMG]

    nice colorful round sweets.
    soon people will be selling such sweets.
     
  3. Ed48

    Ed48

    Are any stablecoins risk-free? Is it worth the risk of holding them over good old USD?
     
  4. USD is much safer, of course. Hold what makes you comfortable.
    If USDC stablecoin is as safe as USD, I won't be motivated to write software to monitor the risk of holding this stablecoin.
     
    Ed48 likes this.
  5. GUSD is the safest of them all. Then USDC.

    after that I wouldn’t hold any of them