Skip to content

Feature: oft adapter step2 - bridge limits and fees in OFTAdapter#10

Open
blueogin wants to merge 39 commits intofeat/oft-adapter-step1from
feat/oft-adapter-step2
Open

Feature: oft adapter step2 - bridge limits and fees in OFTAdapter#10
blueogin wants to merge 39 commits intofeat/oft-adapter-step1from
feat/oft-adapter-step2

Conversation

@blueogin
Copy link
Collaborator

Description

This PR inclues smart contracts which implementes bridge limits and fees in GoodDollarOFTAdapter.sol

About #7

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • PR title matches follow: (Feature|Bug|Chore) Task Name
  • My code follows the style guidelines of this project
  • I have followed all the instructions described in the initial task (check Definitions of Done)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added reference to a related issue in the repository
  • I have added a detailed description of the changes proposed in the pull request. I am as descriptive as possible, assisting reviewers as much as possible.
  • I have added screenshots related to my pull request (for frontend tasks)
  • I have pasted a gif showing the feature.
  • @mentions of the person or team responsible for reviewing proposed changes

…ncluding removal of outdated scripts and addition of remapping file
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In GoodDollarOFTAdapter._credit the requestId is derived from block.timestamp, _to, _srcEid, and _amount, which makes it impossible to deterministically pre-approve off-chain (you can’t know the timestamp ahead of time); consider either passing a requestId from the message payload or changing the approval model so it’s usable in practice.
  • The BridgeFees struct includes minFee and maxFee, but _takeFee and _credit currently only use fee and ignore the min/max fields; either enforce these bounds in the fee calculation or remove the unused fields to avoid confusion.
  • The approvedRequests mapping in GoodDollarOFTAdapter is write-only and never cleared, so approved entries will accumulate indefinitely; consider adding a mechanism to delete or expire approvals after use to avoid unbounded storage growth.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `GoodDollarOFTAdapter._credit` the `requestId` is derived from `block.timestamp`, `_to`, `_srcEid`, and `_amount`, which makes it impossible to deterministically pre-approve off-chain (you can’t know the timestamp ahead of time); consider either passing a requestId from the message payload or changing the approval model so it’s usable in practice.
- The `BridgeFees` struct includes `minFee` and `maxFee`, but `_takeFee` and `_credit` currently only use `fee` and ignore the min/max fields; either enforce these bounds in the fee calculation or remove the unused fields to avoid confusion.
- The `approvedRequests` mapping in `GoodDollarOFTAdapter` is write-only and never cleared, so approved entries will accumulate indefinitely; consider adding a mechanism to delete or expire approvals after use to avoid unbounded storage growth.

## Individual Comments

### Comment 1
<location> `packages/bridge-contracts/contracts/oft/GoodDollarOFTAdapter.sol:183-190` </location>
<code_context>
+     * @param amount The amount to calculate fee from
+     * @return fee The calculated fee amount
+     */
+    function _takeFee(uint256 amount) internal view returns (uint256 fee) {
+        fee = (amount * bridgeFees.fee) / 10000;
+    }
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Bridge fee calculation ignores `minFee`/`maxFee` fields of `BridgeFees`.

`BridgeFees` exposes `minFee` and `maxFee`, but `_takeFee` only uses the BPS value and never enforces these bounds. This can mislead integrators into assuming on-chain caps that don’t exist.

If these fields should be enforced, consider clamping the computed fee, e.g.:
```solidity
uint256 raw = (amount * bridgeFees.fee) / 10000;
if (bridgeFees.minFee > 0 && raw < bridgeFees.minFee) fee = bridgeFees.minFee;
else if (bridgeFees.maxFee > 0 && raw > bridgeFees.maxFee) fee = bridgeFees.maxFee;
else fee = raw;
```
If they’re informational only, consider renaming or removing them to avoid implying enforcement in this function.

```suggestion
    /**
     * @notice Calculates the fee amount from the given amount
     * @param amount The amount to calculate fee from
     * @return fee The calculated fee amount
     */
    function _takeFee(uint256 amount) internal view returns (uint256 fee) {
        uint256 raw = (amount * bridgeFees.fee) / 10000;
        uint256 minFee = bridgeFees.minFee;
        uint256 maxFee = bridgeFees.maxFee;

        if (minFee > 0 && raw < minFee) {
            fee = minFee;
        } else if (maxFee > 0 && raw > maxFee) {
            fee = maxFee;
        } else {
            fee = raw;
        }
    }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

… by integrating IMessagePassingBridge structures, enhancing modularity and clarity
@openzeppelin-code
Copy link

openzeppelin-code bot commented Jan 23, 2026

Feature: oft adapter step2 - bridge limits and fees in OFTAdapter

Generated at commit: 077cff05784e4036d25a64be9e63f557dabc4bc9

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
0
1
0
9
37
47
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@sirpy sirpy changed the base branch from master to feat/oft-adapter-step1 February 2, 2026 07:26
@sirpy sirpy self-requested a review February 2, 2026 07:35
Copy link
Contributor

@sirpy sirpy left a comment

Choose a reason for hiding this comment

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

There are no tests. If you would have added tests then you would see _enforcelimits isnt used

…lidating parameters and ensuring checks on both sending and receiving sides
…llarOFTAdapter contract for improved fee management
…ed bridge limits management for improved cross-chain transfer functionality
…FTAdapter for improved modularity and clarity in bridge limits management
… in GoodDollarOFTAdapter for improved clarity and maintainability of bridge limits and account tracking
…by consolidating checks for approved requests on both sending and receiving sides
…r to streamline logic for sending and receiving operations
…nhance request approval mechanism with bytes32 identifiers for improved cross-chain transfer management
…by introducing a structured Request type and improving limit enforcement checks for both sending and receiving operations
…rOFTAdapter, adding predictNextGuid function for improved GUID prediction in cross-chain messaging
…include receiver address for improved GUID prediction in cross-chain messaging
…n and improving bridge limit checks in tests for better cross-chain messaging functionality
… by replacing structured Request type with a boolean mapping for improved clarity and efficiency
…est handling in GoodDollarOFTAdapter, enhancing error management and limit enforcement for cross-chain transfers
…ating validation logic for improved clarity and efficiency in bridging operations
…s to align with updated initialization for improved fee management
…improved error handling in cross-chain transfers
@sirpy sirpy changed the base branch from feat/oft-adapter-step1 to master February 24, 2026 16:38
@sirpy sirpy changed the base branch from master to feat/oft-adapter-step1 February 24, 2026 16:39
uint256 _amountLD,
uint32 /* _srcEid */
) internal virtual override returns (uint256 amountReceivedLD) {
if (_to == address(0x0)) _to = address(0xdead); // _mint(...) does not support address(0x0)
Copy link
Contributor

Choose a reason for hiding this comment

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

do not support sending to address 0 to begin with

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay

Copy link
Contributor

Choose a reason for hiding this comment

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

where do you prevent address 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

address 0 check is already available in GoodDollar(SuperGoodDollar)
you can check here:
https://github.com/GoodDollar/GoodProtocol/blob/b88e1566a1b6bb2c091e606a0608bc60ef3c443c/contracts/token/superfluid/SuperToken.sol#L276

Copy link
Contributor

Choose a reason for hiding this comment

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

we need to prevent sending to address 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will add an address-zero check in the _send function of GoodDollarOFTAdapter to prevent bridging to the zero address from the sender side.

blueogin added 4 commits March 2, 2026 10:26
…er for improved optimistic period handling in cross-chain transfers
… for bridge limits and streamline limit checks for improved clarity and efficiency in bridging operations
…llarOFTAdapter for clarity, removing redundant comments and enhancing descriptions of key functionalities
…unction in GoodDollarOFTAdapter for improved code clarity
@blueogin blueogin requested a review from sirpy March 4, 2026 13:55
…r to remove owner restriction, enhancing accessibility for request approvals
…r to allow owner approval during optimistic window, enhancing flexibility in request handling
@blueogin blueogin requested a review from sirpy March 16, 2026 15:53
…o zero address, enhancing error handling in messaging operations
…eroEndpointMock, MockGoodDollar, and NameServiceMock to enhance testing capabilities
…FTAdapter to ensure functionality and reliability in various scenarios
…ork to validate deployment and configuration functionalities
…rning GoodDollar tokens, enabling cross-chain transfers via LayerZero
@blueogin
Copy link
Collaborator Author

Hi @sirpy
Could you please review?

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.

2 participants