Health factor#201
Open
OluRemiFour wants to merge 2 commits into
Open
Conversation
|
@OluRemiFour Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
Author
|
Done, Close: #201 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close: #58
Summary
Health-Factor Alert Channel — Complete
alerts/src/schema.sql
hf_threshold REAL DEFAULT NULL — user-configured alert trigger, NULL = APY-only subscriber
hf_breached INTEGER DEFAULT 0 — tracks whether we're inside an active breach window (prevents spam)
alerts/src/stellar.ts
Extended ReserveRates interface with optional cFactor? and lFactor?
Parses them from reserveRaw.config.c_factor / l_factor (falls back to 0.9 / 1.0)
alerts/src/email.ts
New sendHealthFactorAlert() — rich HTML email showing current HF vs threshold, with liquidation risk copy and CTA
alerts/src/index.ts — the core logic:
Subscribe route: accepts optional hf_threshold, validates >= 1.0, stores in D1
Cron handleCron: for every bracket, computes currentHf = (cFactor × lev) / ((lev−1) / lFactor), then:
HF subscribers: sends alert when currentHf < threshold AND hf_breached = 0, sets hf_breached = 1. Resets to 0 when HF heals — exactly one email per breach window
APY subscribers: unchanged — 24h cooldown still applies
frontend/index.html
New "Health Factor Threshold (Optional)" in the alert modal
Modal title updated to "Position Alerts"
frontend/src/main.ts
Reads and validates the threshold input (must be ≥ 1.0 or empty)
Conditionally includes hf_threshold in the /subscribe POST body
Clears the field on successful subscription
Related Issue
Closes #58
Checks
Notes for Reviewers