Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions internal/migrations/erc20-bridge/001-actions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ CREATE OR REPLACE ACTION sepolia_wallet_balance($wallet_address TEXT) PUBLIC VIE

CREATE OR REPLACE ACTION sepolia_admin_bridge_tokens($amount TEXT) PUBLIC {
-- Calculate 1% fee and lock it in our treasury
$numAmount := $amount::NUMERIC(78, 0);
$fee := $numAmount * 0.01;
$num_amount := $amount::NUMERIC(78, 0);
$fee := $num_amount * 0.01;
sepolia_bridge.lock($fee);
Comment on lines +26 to 28
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.


$treasury_address := '0xDe5B2aBce299eBdC3567895B1B4b02Ca2c33C94A';
sepolia_bridge.unlock($treasury_address, $fee);

-- Bridge the rest to users
sepolia_bridge.bridge($numAmount - $fee);
sepolia_bridge.bridge($num_amount - $fee);
};

-- MAINNET
Expand All @@ -43,6 +46,10 @@ CREATE OR REPLACE ACTION mainnet_admin_bridge_tokens($amount TEXT) PUBLIC {
$fee := $numAmount * 0.01;
mainnet_bridge.lock($fee);

-- TODO: update when we have treasury address on mainnet
-- $treasury_address := ''
-- sepolia_bridge.unlock($treasury_address, $fee);

-- Bridge the rest to users
mainnet_bridge.bridge($numAmount - $fee);
};
Loading