Skip to content

fix(settlement): env-configurable anchor threshold default 1.0 -> 0.01#126

Merged
Satelink-Protocol merged 1 commit into
mainfrom
fix-settlement-threshold
Jun 14, 2026
Merged

fix(settlement): env-configurable anchor threshold default 1.0 -> 0.01#126
Satelink-Protocol merged 1 commit into
mainfrom
fix-settlement-threshold

Conversation

@Satelink-Protocol

Copy link
Copy Markdown
Owner

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:30 was already parseFloat(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 var MIN_ANCHOR_REVENUE_USDT was already the real lever.

Honest caveats (also in code comment)

  • 0.01 still will not catch today's ~0.0025 USDT phantom epochs. It fires only once a paying wallet pushes an epoch's real revenue ≥ 0.01 USDT.
  • To prove the loop immediately, set Railway MIN_ANCHOR_REVENUE_USDT=0.0001.
  • The hot wallet must hold USDT (or MATIC for the 0-value anchor-tx fallback) or the on-chain tx still no-ops.

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

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>
@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 13, 2026 9:05am

@mintlify

mintlify Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
Satelink 🟢 Ready View Preview Jun 13, 2026, 9:09 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@Satelink-Protocol Satelink-Protocol merged commit 8fb7c1e into main Jun 14, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant