fix(settlement): env-configurable anchor threshold default 1.0 -> 0.01#126
Merged
Conversation
Audit (commit 04fc972) found settlement never fires: epochs run ~0.0025 USDT each but the anchor only processes epochs >= the threshold. CORRECTION to the audit task premise: the threshold was NOT hardcoded — it was already parseFloat(process.env.MIN_ANCHOR_REVENUE_USDT || '1.0') at line 30. This commit only lowers the DEFAULT to 0.01 and documents the env override. Caveats (in code comment): - 0.01 still will NOT catch today's ~0.0025 USDT phantom epochs; it fires once a paying wallet pushes an epoch's real revenue >= 0.01 USDT. - To force settlement for a test, set Railway MIN_ANCHOR_REVENUE_USDT=0.0001. - Hot wallet must hold USDT (or MATIC for the 0-value anchor-tx fallback). Adds scripts/test-payment-loop.mjs — end-to-end deposit->credit->call->billing-> epoch->settlement verifier, written against the REAL schema (credit_balances, revenue_events_v2.method/client_id, settlement_batches) — the earlier draft referenced columns that do not exist. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
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.
Follow-up to audit PR #125 (merged as 04fc972).
Problem
Settlement never fires: epochs run ~0.0025 USDT each, and the anchor only processes epochs at/above the threshold.
Correction to the premise
The threshold was not hardcoded —
settlement_anchor_job.js:30was alreadyparseFloat(process.env.MIN_ANCHOR_REVENUE_USDT || '1.0'). This PR only lowers the default to 0.01 and documents the env override. The Railway env varMIN_ANCHOR_REVENUE_USDTwas already the real lever.Honest caveats (also in code comment)
MIN_ANCHOR_REVENUE_USDT=0.0001.Also
scripts/test-payment-loop.mjs— end-to-end verifier written against the real schema (credit_balances,revenue_events_v2.method/client_id,settlement_batches). The version in the original task spec referenced columns that don't exist (credits,revenue_events_v2.wallet_address,rpc_method,epochs.call_count/tx_hash) and would have crashed.Note: "Secret Scan" CI check is a pre-existing false positive (naive grep matching
sk_live_key-generation code in api_keys.js); not introduced here.🤖 Generated with Claude Code