Skip to content

fix: unlock fee to treasury#1159

Merged
williamrusdyputra merged 1 commit into
mainfrom
fix/unlock-treasury
Sep 15, 2025
Merged

fix: unlock fee to treasury#1159
williamrusdyputra merged 1 commit into
mainfrom
fix/unlock-treasury

Conversation

@williamrusdyputra
Copy link
Copy Markdown
Contributor

@williamrusdyputra williamrusdyputra commented Sep 15, 2025

Related Problem

related: https://github.com/trufnetwork/truf-network/issues/1173

How Has This Been Tested?

Summary by CodeRabbit

  • New Features

    • Sepolia: Bridge fee is now automatically routed to the treasury address during admin token transfers. User-received amounts remain unchanged.
  • Chores

    • Mainnet: Added placeholders for future treasury fee routing (no functional impact yet).
  • Documentation

    • Clarified internal notes around fee handling to prepare for consistent behavior across networks.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 15, 2025

Walkthrough

Updates ERC20 bridge actions in internal/migrations/erc20-bridge/001-actions.sql: adjusts sepolia admin bridging to rename a local amount variable, introduces a treasury address, and adds a treasury unlock for the fee. Adds TODO comments/placeholders for mainnet treasury handling. Other actions remain unchanged.

Changes

Cohort / File(s) Change Summary
Sepolia admin flow updates
internal/migrations/erc20-bridge/001-actions.sql
Renamed $numAmount to $num_amount. Added $treasury_address := '0xDe5B2aBce299eBdC3567895B1B4b02Ca2c33C94A'. After locking 1% fee, added sepolia_bridge.unlock($treasury_address, $fee). Bridged amount now uses $num_amount - $fee.
Mainnet admin placeholders
internal/migrations/erc20-bridge/001-actions.sql
Inserted TODO comments and commented placeholders for a treasury address and unlock call. No active logic changes; flow remains mainnet_bridge.bridge($numAmount - $fee).
Other actions unchanged
internal/migrations/erc20-bridge/001-actions.sql
get_erc20_bridge_info, sepolia_wallet_balance, mainnet_wallet_balance unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Admin as Admin Action
  participant Sepolia as sepolia_bridge
  participant Treasury as Treasury Address

  note over Admin: sepolia_admin_bridge_tokens
  Admin->>Admin: Compute $fee = 1% of $num_amount
  Admin->>Sepolia: lock($fee)
  Sepolia-->>Admin: fee locked
  Admin->>Sepolia: unlock($treasury_address, $fee)
  Sepolia-->>Treasury: transfer fee
  Admin->>Sepolia: bridge($num_amount - $fee)
  Sepolia-->>Admin: bridge initiated
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • MicBun

Poem

A hop and a lock, then a nimble unlock,
Fees to the burrow, bridge on the clock.
Sepolia sings, mainnet takes note,
Carrots accounted in every quote.
Thump of approval—ledger in tune,
Bunny signs off: “Shipped by noon!” 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: unlock fee to treasury" is concise, uses the conventional "fix:" prefix, and accurately reflects the primary change in the diff — adding a treasury address and an unlock($treasury_address, $fee) call to route fees in sepolia_admin_bridge_tokens; it clearly communicates the main intent without unnecessary detail. This makes it easy for a reviewer scanning PR history to understand the core fix.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/unlock-treasury

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.

@holdex
Copy link
Copy Markdown

holdex Bot commented Sep 15, 2025

Bug Report Checklist

Status Commit Link Bug Author
✅ Submitted commit link @williamrusdyputra

@williamrusdyputra
Copy link
Copy Markdown
Contributor Author

williamrusdyputra commented Sep 15, 2025

@pr-time-tracker bug commit 19c6edd && bug author @williamrusdyputra

@williamrusdyputra williamrusdyputra merged commit 48b6058 into main Sep 15, 2025
5 of 6 checks passed
@williamrusdyputra williamrusdyputra deleted the fix/unlock-treasury branch September 15, 2025 05:34
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: 1

🧹 Nitpick comments (3)
internal/migrations/erc20-bridge/001-actions.sql (3)

30-35: Confirm side‑effect ordering and atomicity (lock → unlock → bridge).

If unlock succeeds but bridge fails, you’ve diverted the fee yet not bridged funds. Ensure this action is atomic or add compensations/idempotency.


49-52: Fix chain reference in TODO and prep mainnet parity.

Commented example uses sepolia_bridge.unlock; should be mainnet_bridge.unlock. Also plan the same integer-fee computation and avoid merging TODOs without a feature flag.

Apply this diff:

-  -- sepolia_bridge.unlock($treasury_address, $fee);
+  -- mainnet_bridge.unlock($treasury_address, $fee);

26-35: Naming/style consistency: prefer one convention across actions.

$num_amount (snake_case) on Sepolia vs $numAmount (camelCase) on Mainnet is inconsistent. Pick one for maintainability.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19c6edd and 069aa0c.

📒 Files selected for processing (1)
  • internal/migrations/erc20-bridge/001-actions.sql (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: acceptance-test
🔇 Additional comments (2)
internal/migrations/erc20-bridge/001-actions.sql (2)

34-34: Type consistency between $num_amount - $fee and bridge input.

After switching to integer fee, confirm sepolia_bridge.bridge(...) expects an integer amount and rejects zero/negative values; add guards if necessary.


30-31: Don't hardcode the treasury address; make it configurable and validate.

Hardcoding 0xDe5B2aBce299eBdC3567895B1B4b02Ca2c33C94A in a migration bakes env-specific state. Read the treasury address from config/state (settings table or a constants action) and validate EIP‑55 checksum/format before calling unlock(address, amount). Search shows only this occurrence and a commented TODO; no central treasury config or a CREATE OR REPLACE ACTION ... unlock(...) definition was found — confirm the action signature or add a vetted wrapper and update the migration.

Location: internal/migrations/erc20-bridge/001-actions.sql:30-31

Comment on lines +26 to 28
$num_amount := $amount::NUMERIC(78, 0);
$fee := $num_amount * 0.01;
sepolia_bridge.lock($fee);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Use integer math for 1% fee to avoid scale/rounding/type issues.

$num_amount is NUMERIC(78,0). Multiplying by 0.01 risks producing a scaled decimal that may not match downstream expectations and can silently round. Compute the fee via integer math instead.

Apply this diff:

-  $fee := $num_amount * 0.01;
+  -- 1% fee using integer arithmetic (floor)
+  $fee := FLOOR($num_amount / 100);

Also confirm policy (floor vs round/ceil) and add the same change to mainnet when enabling treasury there.


Use integer math for 1% fee to avoid scale/rounding/type issues.

Multiplying NUMERIC(78,0) by 0.01 creates scaled decimals and can silently round — compute the fee with integer arithmetic (floor) instead.

-  $fee := $num_amount * 0.01;
+  -- 1% fee using integer arithmetic (floor)
+  $fee := FLOOR($num_amount / 100);

Confirm policy (floor vs round/ceil) and apply the same change to mainnet when enabling the treasury.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$num_amount := $amount::NUMERIC(78, 0);
$fee := $num_amount * 0.01;
sepolia_bridge.lock($fee);
$num_amount := $amount::NUMERIC(78, 0);
-- 1% fee using integer arithmetic (floor)
$fee := FLOOR($num_amount / 100);
sepolia_bridge.lock($fee);
🤖 Prompt for AI Agents
internal/migrations/erc20-bridge/001-actions.sql around lines 26 to 28: the
current fee calculation multiplies NUMERIC(78,0) by 0.01 which creates scaled
decimals and risks rounding; replace it with integer arithmetic that computes
the 1% fee using floor semantics (e.g., compute fee as integer division by 100
so fee := floor($num_amount * 1 / 100) or equivalently $num_amount / 100), keep
the rest of the call to sepolia_bridge.lock($fee) unchanged, and apply the same
integer-floor logic to the mainnet/treasury migration when enabling it.

@holdex
Copy link
Copy Markdown

holdex Bot commented Sep 15, 2025

Time Submission Status

Member Status Time Action Last Update
williamrusdyputra ✅ Submitted 30min Update time Sep 15, 2025, 5:37 AM

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