Skip to content

Fix/burn fee thresholds cleanup#111

Merged
Junman140 merged 5 commits intoPi-Defi-world:mainfrom
sudo-robi:fix/burn-fee-thresholds-cleanup
Mar 30, 2026
Merged

Fix/burn fee thresholds cleanup#111
Junman140 merged 5 commits intoPi-Defi-world:mainfrom
sudo-robi:fix/burn-fee-thresholds-cleanup

Conversation

@sudo-robi
Copy link
Copy Markdown
Contributor

@sudo-robi sudo-robi commented Mar 27, 2026

closes #33

This PR corrects the burn fee threshold logic for reserve weights. The previous implementation used values 15 and 21, which were not consistent with the intended percentage-of-target calculation. The new logic applies a high burn fee below 85% of target, a lower burn fee above 115%, and the base fee in between. Named constants are introduced for clarity, and focused unit tests are added to cover all threshold scenarios. All tests pass.

Summary by CodeRabbit

  • Tests

    • Added comprehensive Jest coverage for burn-fee calculations across low/normal/high reserve scenarios, including exact threshold boundary cases.
  • Refactor

    • Replaced fixed cutoffs with named reserve-percentage bands for clearer, maintainable fee decisions.
  • Chores

    • Reordered queue constants for clarity and expanded test environment fallbacks for CI/local runs.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 27, 2026

@sudo-robi 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! 🚀

Learn more about application limits

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24d925e4-3e69-4e5e-bf5b-67509f13aaf6

📥 Commits

Reviewing files that changed from the base of the PR and between fb02032 and 11fa513.

📒 Files selected for processing (1)
  • src/config/rabbitmq.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/config/rabbitmq.ts

📝 Walkthrough

Walkthrough

Corrected reserve-threshold comparisons in the burn-fee calculation, added explicit 85%/115% threshold constants, added Jest tests for below/at/within/above-threshold cases, reordered a RabbitMQ queue entry, and expanded test environment fallback variables for CI/local runs.

Changes

Cohort / File(s) Summary
Fee Policy Service
src/services/feePolicy/feePolicyService.ts
Introduced LOW_RESERVE_THRESHOLD_PCT = 85 and HIGH_RESERVE_THRESHOLD_PCT = 115; replaced previous numeric cutoff checks with comparisons to these constants and preserved control flow in getBurnFeeBps.
Fee Policy Tests
src/services/feePolicy/__tests__/feePolicyService.test.ts
Added new Jest suite for getBurnFeeBps with typed mocks for reserveTracker and config; tests cover below 85%, at 85%, between thresholds, at 115%, and above 115% expected burn fee bps.
RabbitMQ Config
src/config/rabbitmq.ts
Reordered entries in exported QUEUES map so AUDIT_LOGS appears before USDC_CONVERT_AND_MINT_DLQ; key/value unchanged.
Jest Setup / Env Defaults
tests/jest.setup.ts
Expanded fallback environment defaults for CI/local when .env is missing (DATABASE_URL, MONGODB_URI, RABBITMQ_URL, plus JWT_SECRET and API_KEY_SALT) using

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through numbers in the night,
Found thresholds hiding out of sight.
Eighty-five and one-fifteen now stand tall,
Fees dance true, no more oddfall.
🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes out-of-scope changes: RabbitMQ queue reordering in rabbitmq.ts and jest.setup.ts environment variable additions unrelated to burn fee thresholds. Remove unrelated changes to src/config/rabbitmq.ts and tests/jest.setup.ts to keep the PR focused on the burn fee threshold fix from issue #33.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title refers to the main change (burn fee threshold correction), clearly identifying the primary objective of the PR.
Linked Issues check ✅ Passed The PR correctly implements the threshold fix from issue #33 by replacing pctOfTarget < 15 and > 21 with proper 85% and 115% boundary checks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/services/feePolicy/__tests__/feePolicyService.test.ts (1)

24-95: Consider adding edge case tests for completeness.

The threshold tests are well-designed, but the suite could benefit from additional edge cases that exist in getBurnFeeBps:

  • Currency not found in reserve status
  • targetWeight <= 0 guard
📝 Optional: Additional edge case tests
it("returns base burn fee when currency is not found", async () => {
  mockGetReserveStatus.mockResolvedValueOnce({
    currencies: [
      { currency: "USD", targetWeight: 40, actualWeight: 40 },
    ],
  });

  await expect(getBurnFeeBps("NGN")).resolves.toBe(10);
});

it("returns base burn fee when targetWeight is zero", async () => {
  mockGetReserveStatus.mockResolvedValueOnce({
    currencies: [
      { currency: "NGN", targetWeight: 0, actualWeight: 40 },
    ],
  });

  await expect(getBurnFeeBps("NGN")).resolves.toBe(10);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/feePolicy/__tests__/feePolicyService.test.ts` around lines 24 -
95, Tests for getBurnFeeBps are missing edge cases for when the requested
currency is absent from reserve status and when targetWeight is non-positive;
add two unit tests in src/services/feePolicy/__tests__/feePolicyService.test.ts
that mock mockGetReserveStatus to return a currencies list without the requested
currency and another where the matching currency has targetWeight <= 0, then
assert getBurnFeeBps("NGN") resolves to the base burn fee (10) in both cases;
reference the existing test patterns and the getBurnFeeBps function to place and
structure these new tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/services/feePolicy/__tests__/feePolicyService.test.ts`:
- Around line 24-95: Tests for getBurnFeeBps are missing edge cases for when the
requested currency is absent from reserve status and when targetWeight is
non-positive; add two unit tests in
src/services/feePolicy/__tests__/feePolicyService.test.ts that mock
mockGetReserveStatus to return a currencies list without the requested currency
and another where the matching currency has targetWeight <= 0, then assert
getBurnFeeBps("NGN") resolves to the base burn fee (10) in both cases; reference
the existing test patterns and the getBurnFeeBps function to place and structure
these new tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f3187e6-e173-469c-8091-44254383afda

📥 Commits

Reviewing files that changed from the base of the PR and between 785aa65 and 8f800da.

📒 Files selected for processing (2)
  • src/services/feePolicy/__tests__/feePolicyService.test.ts
  • src/services/feePolicy/feePolicyService.ts

@Junman140
Copy link
Copy Markdown
Member

@sudo-robi test failed

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/jest.setup.ts (1)

3-11: ⚠️ Potential issue | 🟡 Minor

Dead code: Lines 8-11 are unreachable.

The ||= operator only assigns when the left-hand side is falsy. Since lines 3-6 already assign values to DATABASE_URL, MONGODB_URI, RABBITMQ_URL, and JWT_SECRET, lines 8-11 will never execute—they are dead code.

Remove the duplicate assignments to avoid confusion:

🧹 Proposed fix to remove dead code
 // Defaults for CI and local `pnpm test` when .env is absent.
 // Must match .github/workflows/ci.yml postgres service (POSTGRES_USER/PASSWORD).
 process.env.DATABASE_URL ||= "postgresql://postgres:postgres@localhost:5432/acbu_test";
 process.env.MONGODB_URI ||= "mongodb://localhost:27017/acbu_test";
 process.env.RABBITMQ_URL ||= "amqp://guest:guest@localhost:5672";
 process.env.JWT_SECRET ||= "test-jwt-secret-for-ci";
 process.env.API_KEY_SALT ||= "test-api-key-salt";
-process.env.DATABASE_URL ||= "postgresql://test:test@localhost:5432/acbu_test";
-process.env.MONGODB_URI ||= "mongodb://localhost:27017/acbu_test";
-process.env.RABBITMQ_URL ||= "amqp://localhost:5672";
-process.env.JWT_SECRET ||= "test-secret";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/jest.setup.ts` around lines 3 - 11, Remove the duplicate fallback
assignments that never run: delete the second set of process.env assignments for
DATABASE_URL, MONGODB_URI, RABBITMQ_URL, and JWT_SECRET and keep only the
initial ||= fallbacks (ensure API_KEY_SALT remains set once); this removes dead
code and preserves the intended conditional environment variable initialization
for DATABASE_URL, MONGODB_URI, RABBITMQ_URL, JWT_SECRET, and API_KEY_SALT.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/config/rabbitmq.ts`:
- Around line 114-116: The QUEUES object contains a duplicated key AUDIT_LOGS
(declared twice with the same value); remove the redundant entry so AUDIT_LOGS
appears only once in QUEUES to avoid silent overwrites and the Biome lint
violation—locate the QUEUES object and delete the duplicate AUDIT_LOGS line
(keep a single AUDIT_LOGS: "audit_logs" entry).

In `@tests/jest.setup.ts`:
- Line 3: The failing Prettier formatting is on the assignment to
process.env.DATABASE_URL in tests/jest.setup.ts; run your project's formatter
(e.g., Prettier) on this file or the repo to apply the expected style so the
line 'process.env.DATABASE_URL ||=
"postgresql://postgres:postgres@localhost:5432/acbu_test";' is reformatted to
match project rules, then stage the updated file and push the change; ensure you
target the statement that references process.env.DATABASE_URL so the same token
names remain unchanged.

---

Outside diff comments:
In `@tests/jest.setup.ts`:
- Around line 3-11: Remove the duplicate fallback assignments that never run:
delete the second set of process.env assignments for DATABASE_URL, MONGODB_URI,
RABBITMQ_URL, and JWT_SECRET and keep only the initial ||= fallbacks (ensure
API_KEY_SALT remains set once); this removes dead code and preserves the
intended conditional environment variable initialization for DATABASE_URL,
MONGODB_URI, RABBITMQ_URL, JWT_SECRET, and API_KEY_SALT.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: afb87fe4-bc06-4c17-b9d3-7e499fa12dfd

📥 Commits

Reviewing files that changed from the base of the PR and between 8f800da and fb02032.

📒 Files selected for processing (2)
  • src/config/rabbitmq.ts
  • tests/jest.setup.ts

@@ -1,3 +1,10 @@
// Defaults for CI and local `pnpm test` when .env is absent.
// Must match .github/workflows/ci.yml postgres service (POSTGRES_USER/PASSWORD).
process.env.DATABASE_URL ||= "postgresql://postgres:postgres@localhost:5432/acbu_test";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix formatting issue flagged by Prettier.

Static analysis indicates a formatting issue on this line. Run your formatter to resolve it.

🧰 Tools
🪛 ESLint

[error] 3-3: Insert ⏎·

(prettier/prettier)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/jest.setup.ts` at line 3, The failing Prettier formatting is on the
assignment to process.env.DATABASE_URL in tests/jest.setup.ts; run your
project's formatter (e.g., Prettier) on this file or the repo to apply the
expected style so the line 'process.env.DATABASE_URL ||=
"postgresql://postgres:postgres@localhost:5432/acbu_test";' is reformatted to
match project rules, then stage the updated file and push the change; ensure you
target the statement that references process.env.DATABASE_URL so the same token
names remain unchanged.

@Junman140
Copy link
Copy Markdown
Member

@sudo-robi cl failed

@sudo-robi
Copy link
Copy Markdown
Contributor Author

@Junman140 ci has been resolved

@Junman140 Junman140 merged commit c0b2a5b into Pi-Defi-world:main Mar 30, 2026
2 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.

Fee thresholds likely wrong

2 participants