Skip to content

Conversation

@gfournieriExec
Copy link
Contributor

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new depositAndMatchOrders function that combines token deposit and order matching operations into a single atomic transaction, improving the user experience for builders by eliminating separate approve, deposit, and match steps.

Key changes:

  • Added IexecPocoDepositAndMatchTokenFacet contract with the combined deposit and match functionality
  • Created interface IexecPocoDepositAndMatch to define the new API
  • Integrated the new facet into the diamond proxy deployment and upgrade scripts

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
contracts/facets/IexecPocoDepositAndMatchTokenFacet.sol Core implementation of the deposit and match functionality with balance checking and atomic execution
contracts/interfaces/IexecPocoDepositAndMatchToken.sol Interface definition for the new depositAndMatchOrders function and DepositAndMatch event
contracts/IexecInterfaceToken.sol Integration of the new interface into the main token interface
test/byContract/IexecPocoDepositAndMatch/IexecPocoDepositAndMatchTokenFacet.test.ts Comprehensive test suite covering various scenarios including partial balances, error cases, and event verification
scripts/upgrades/apply-deposit-match-upgrade.ts Deployment script for adding the new facet to the diamond proxy
deploy/0_deploy.ts Updated deployment configuration to include the new facet
abis/contracts/interfaces/IexecPocoDepositAndMatch.json Generated ABI for the interface
abis/contracts/facets/IexecPocoDepositAndMatchTokenFacet.json Generated ABI for the facet implementation
abis/contracts/IexecInterfaceToken.json Updated ABI including the new deposit and match function

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.05%. Comparing base (950ec4e) to head (3d55cbe).

Files with missing lines Patch % Lines
...acts/facets/IexecPocoDepositAndMatchTokenFacet.sol 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #293      +/-   ##
==========================================
+ Coverage   84.85%   85.05%   +0.20%     
==========================================
  Files          37       38       +1     
  Lines        1241     1265      +24     
  Branches      235      238       +3     
==========================================
+ Hits         1053     1076      +23     
- Misses        188      189       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gfournieriExec gfournieriExec marked this pull request as draft October 17, 2025 12:53
Copy link
Contributor

@Le-Caignec Le-Caignec left a comment

Choose a reason for hiding this comment

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

Personally, I would have chosen to add this function to the Poco1 facet, so that it would be at the same level as matchOrder.
But I don’t have a strong opinion on this — maybe it will make our deployments easier if we don’t have too many facets to manage.

Comment on lines 48 to 49
require(_requestorder.requester == msg.sender, "DepositAndMatch: Caller must be requester");

Copy link
Contributor

Choose a reason for hiding this comment

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

can we use custom error here 🙏🏼

Comment on lines +42 to +47
function depositAndMatchOrders(
IexecLibOrders_v5.AppOrder calldata _apporder,
IexecLibOrders_v5.DatasetOrder calldata _datasetorder,
IexecLibOrders_v5.WorkerpoolOrder calldata _workerpoolorder,
IexecLibOrders_v5.RequestOrder calldata _requestorder
) external override returns (bytes32 dealId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about making this function payable?
It would help reduce gas costs by allowing the SDK (client) to calculate off-chain the exact amount needed to add to the account.
It would also allow us to call our internal _deposit function directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure to understand the point
we deal with rlc token not eth ?

Comment on lines 100 to 103
require(
$.m_baseToken.transferFrom(depositor, address(this), amount),
"DepositAndMatch: Token transfer failed"
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Custom Error ?

uint256 depositedAmount = 0;
if (currentBalance < dealCost) {
uint256 requiredDeposit = dealCost - currentBalance;
_depositTokens(msg.sender, requiredDeposit);
Copy link
Contributor

Choose a reason for hiding this comment

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

by using this internal function we read the storage twice time (PocoStorageLib.getPocoStorage())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gas reduction of 10, idk if it's worth it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

buy puttin the $ as an input of the internal function
but reductin off 156 by removing the internal fct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solution in mind

if (currentBalance < dealCost) {
            unchecked {
                // Safe: currentBalance < dealCost, so dealCost - currentBalance cannot underflow
                depositedAmount = dealCost - currentBalance;
            }
            if (!$.m_baseToken.transferFrom(msg.sender, address(this), depositedAmount)) {
                revert DepositAndMatch_TokenTransferFailed();
            }
            // Safe: adding to balance cannot realistically overflow
            unchecked {
                $.m_balances[msg.sender] = currentBalance + depositedAmount;
                $.m_totalSupply += depositedAmount;
            }
            emit Transfer(address(0), msg.sender, depositedAmount);
        }

gas max : 879232 => 878754 = - 478

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 13:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

* @dev Referenced in the SDK with the current path `contracts/IexecInterfaceToken.sol`.
* Changing the name or the path would cause a breaking change in the SDK.
*/
// TODO Remove this interface when it's not used in the middleware anymore.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO Remove this interface when it's not used in the middleware anymore.
// TODO Remove interface `IexecAccessorsABILegacy` when it's not used in the middleware anymore.

Copy link
Member

Choose a reason for hiding this comment

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

To rewrite with new utility functions in proxy-tools.ts.

* @dev This facet allows builders to deposit RLC tokens and match orders in a single transaction,
* significantly improving the user experience by eliminating the need for separate approve+deposit+match transactions
*/
contract IexecPocoDepositAndMatchTokenFacet is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
contract IexecPocoDepositAndMatchTokenFacet is
contract IexecDepositAndMatchOrdersFacet is

/**
* @notice Thrown when the caller is not the requester in the request order
*/
error DepositAndMatch_CallerMustBeRequester();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
error DepositAndMatch_CallerMustBeRequester();
error CallerMustBeRequester();

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.

3 participants