Skip to content

Commit

Permalink
node/hack: Print potential USD stablecoins that appear depegged (#4130)
Browse files Browse the repository at this point in the history
* node/hack: Print potential USD stablecoins that appear depegged

* PR feedback
  • Loading branch information
djb15 authored Oct 8, 2024
1 parent c9690c9 commit f475e0d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions node/hack/governor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ import { arrayify, zeroPad } from "ethers/lib/utils";
const MinNotional = 0;
// Price change tolerance in %. Fallback to 30%
const PriceDeltaTolerance = process.env.PRICE_TOLERANCE ? Math.min(100, Math.max(0, parseInt(process.env.PRICE_TOLERANCE))) : 30;
// The percentage by which the price deviates from $1 to be considered depegged
const usdDepegPercentage = process.env.DEPEG_PERCENTAGE ? Math.min(100, Math.max(0, parseInt(process.env.DEPEG_PERCENTAGE))) : 10;
const usdPeggedStablecoins = [
"USD", // Matches with USDT, USDC, BUSD, etc.
"PAX", // Pax Dollar
"DAI", // Dai
"RSV", // Reserve
"VAI", // Vai
"FRAX", // Frax
"FEI", // Fei
];
const expectedUSDDepeggs = [
"2-00000000000000000000000045804880de22913dafe09f4980848ece6ecbaf78-PAXG", // This is PaxGold and not pegged to $1
"2-000000000000000000000000d13cfd3133239a3c73a9e535a5c4dadee36b395c-VAI", // This is Vaiot, not the VAI stablecoin
"5-000000000000000000000000ee327f889d5947c1dc1934bb208a1e792f953e96-frxETH", // Frax ETH
"23-0000000000000000000000009d2f299715d94d8a7e6f5eaa8e654e8c74a988a7-FXS", // Frax Share
"2-0000000000000000000000003432b6a60d23ca0dfca7761b7ab56459d9c964d0-FXS", // Frax Share
"23-00000000000000000000000051318b7d00db7acc4026c88c3952b66278b6a67f-PLS", // Plutus DAO
"3-0100000000000000000000000000000000000000000000000000000075757364-UST", // Terra USD
"2-000000000000000000000000dfdb7f72c1f195c5951a234e8db9806eb0635346-NFD", // Feisty Doge NFT
"2-00000000000000000000000000c5ca160a968f47e7272a0cfcda36428f386cb6-USDEBT", // US Debt Meme coin
"4-00000000000000000000000011a38e06699b238d6d9a0c7a01f3ac63a07ad318-USDFI", // USDFI is a protocol, not a stablecoin
]

const axios = require("axios");
const fs = require("fs");
Expand Down Expand Up @@ -54,6 +77,7 @@ if (fs.existsSync(IncludeFileName)) {
var existingTokenPrices = {};
var existingTokenKeys: string[] = [];
var newTokenKeys = {};
var depeggedUSDStablecoins = [];

fs.readFile("../../pkg/governor/generated_mainnet_tokens.go", "utf8", function(_, doc) {
var matches = doc.matchAll(/{chain: (?<chain>[0-9]+).+addr: "(?<addr>[0-9a-fA-F]+)".*symbol: "(?<symbol>.*)", coin.*price: (?<price>.*)}.*\n/g);
Expand Down Expand Up @@ -174,6 +198,18 @@ axios
}
}

// This token looks like a USD stablecoin
if (usdPeggedStablecoins.findIndex(element => data.Symbol.toLowerCase().includes(element.toLowerCase()) || data.CoinGeckoId.toLowerCase().includes(element.toLowerCase())) != -1 ) {
// The token price has deviated significantly from $1
if (data.TokenPrice > 1 * ((100 + usdDepegPercentage) / 100) || data.TokenPrice < 1 * ((100 - usdDepegPercentage) / 100)) {
var uniqueIdentifier = chain + "-" + wormholeAddr + "-" + data.Symbol;
// Skip tokens that are not expected to be pegged to $1
if (!expectedUSDDepeggs.includes(uniqueIdentifier)) {
depeggedUSDStablecoins.push(uniqueIdentifier + " = " + data.TokenPrice);
}
}
}

// This is a new token
if (existingTokenPrices[chain] == undefined || existingTokenPrices[chain][wormholeAddr] == undefined) {
addedTokens.push(chain + "-" + wormholeAddr + "-" + data.Symbol);
Expand Down Expand Up @@ -268,6 +304,9 @@ axios
changedContent += "\n\nTokens with invalid symbols = " + failedInputValidationTokens.length + ":\n<WH_chain_id>-<WH_token_addr>-<token_symbol>\n\n";
changedContent += JSON.stringify(failedInputValidationTokens, null, 1);

changedContent += "\n\nPotentially depegged USD stablecoins (>" + usdDepegPercentage + "%) = " + depeggedUSDStablecoins.length + ":\n<WH_chain_id>-<WH_token_addr>-<token_symbol> = <token_price>\n\n";
changedContent += JSON.stringify(depeggedUSDStablecoins, null, 1);

changedContent += "\n\nTokens with significant price drops (>" + PriceDeltaTolerance + "%) = " + significantPriceChanges.length + ":\n\n"
changedContent += JSON.stringify(significantPriceChanges, null, 1);
changedContent += "\n```";
Expand Down

0 comments on commit f475e0d

Please sign in to comment.