Skip to content

Commit abb25a0

Browse files
committed
more token info in the alerts
1 parent c95ca24 commit abb25a0

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

defi/src/storeTvlInterval/staleCoins.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ export async function notifyStaleCoins() {
112112
let teamMessage: string = "";
113113
stored.forEach((d: StaleCoinData) => {
114114
if (d.usd_amount > 1e11) {
115-
console.log(`Skipping ${d.key} with TVL ${d.usd_amount} - too large for stale coin alert`);
115+
console.log(`Skipping ${d.key} (${d.symbol}) with TVL ${d.usd_amount} - too large for stale coin alert`);
116116
return; // ignore 100B+ coins
117117
}
118118
let readableTvl: string = humanizeNumber(d.usd_amount);
119119
message += `\nIn ${timeout - d.latency}h a ${d.protocol} TVL chart will lose ${readableTvl}$ (${
120120
d.percentage
121-
}%) because ${d.key} is ${d.latency}h stale`;
121+
}%) because ${d.key} (${d.symbol}) is ${d.latency}h stale`;
122122
if (d.usd_amount > 1e8 && timeout - d.latency < 13) {
123123
teamMessage += `\nIn ${timeout - d.latency}h a ${d.protocol} TVL chart will lose ${readableTvl}$ (${
124124
d.percentage
125-
}%) because ${d.key} is ${d.latency}h stale`;
125+
}%) because ${d.key} (${d.symbol}) is ${d.latency}h stale`;
126126
}
127127
});
128128

defi/src/storeTvlInterval/storeNewTvl2.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,44 @@ export default async function (
138138
}
139139
}
140140
if (storePreviousData && lastHourlyTVL / 2 > currentTvl && Math.abs(lastHourlyUsdTVLObject.SK - unixTimestamp) < 12 * HOUR) {
141+
let tvlFromMissingTokens = 0;
142+
let missingTokens: { coin: string, value: number, valueHN: string }[] = [];
143+
let highValueDrop: { coin: string, value: number, valueHN: string }[] = [];
144+
[...extraSections, "tvl"].forEach(section => {
145+
if (!lastHourlyUsdTVLObject || !lastHourlyUsdTVLObject[section]) return;
146+
Object.entries(lastHourlyUsdTVLObject[section]).forEach(([coin, tvl]) => {
147+
const currentTokenUSDTvl = usdTokenBalances[section]?.[coin]
148+
if (currentTokenUSDTvl === undefined) {
149+
tvlFromMissingTokens += Number(tvl)
150+
missingTokens.push({ coin, valueHN: humanizeNumber(tvl as any), value: tvl as number })
151+
}
152+
153+
if (tvl as number > 10e6 && typeof +currentTokenUSDTvl === 'number' && (tvl as number) / 4 > +currentTokenUSDTvl) {
154+
const diff = (tvl as number) - (+currentTokenUSDTvl || 0)
155+
highValueDrop.push({ coin, valueHN: humanizeNumber(diff as any), value: diff as number })
156+
}
157+
})
158+
})
159+
160+
missingTokens = missingTokens.sort((a, b) => b.value - a.value)
161+
let missingTokenString = missingTokens.map(token => `${token.coin}: ${token.valueHN}`).join(", ")
162+
missingTokenString = missingTokenString.length ? `missing tokens: ${missingTokenString}` : ""
163+
highValueDrop = highValueDrop.sort((a, b) => b.value - a.value)
164+
const highValueDropString = highValueDrop.map(token => `${token.coin}: ${token.valueHN}`).join(", ")
165+
if (highValueDrop.length)
166+
missingTokenString += ` high drop: ${highValueDropString}`
167+
const lastHourlyTVLHN = humanizeNumber(lastHourlyTVL)
168+
const currentTvlHN = humanizeNumber(currentTvl)
169+
170+
// if tvl was more than 50M send an high severity alert
141171
if (lastHourlyTVL > 50e6) {
142-
await sendMessage(`TVL of ${protocol.name} has dropped from ${humanizeNumber(lastHourlyTVL)} to ${humanizeNumber(currentTvl)}. check this asap`, process.env.TEAM_WEBHOOK!)
172+
await sendMessage(`TVL of ${protocol.name} has dropped from ${lastHourlyTVLHN} to ${currentTvlHN}. ${missingTokenString}`, process.env.TEAM_WEBHOOK!)
143173
}
144-
console.log(`TVL for ${protocol.name} has dropped >50% within one hour. Current tvl: ${humanizeNumber(currentTvl)}, previous tvl: ${humanizeNumber(lastHourlyTVL)}`)
174+
175+
console.log(`TVL for ${protocol.name} has dropped >50% within one hour. Current tvl: ${currentTvlHN}, previous tvl: ${lastHourlyTVLHN} . ${missingTokenString}`)
176+
145177
if (!process.env.UI_TOOL_MODE && lastHourlyTVL > 1e5) {
146-
const errorMessage = `TVL for ${protocol.name} has dropped >50% within one hour. It's been disabled.`
178+
const errorMessage = `TVL for ${protocol.name} has dropped >50% within one hour. It's been disabled. Current tvl: ${currentTvlHN}, previous tvl: ${lastHourlyTVLHN}. ${missingTokenString}`
147179
console.log(errorMessage, 'skipping db update')
148180
await sendMessage(errorMessage, process.env.SPIKE_WEBHOOK!)
149181
throw new Error(errorMessage);

0 commit comments

Comments
 (0)