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.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.03%. Comparing base (015adb2) to head (afdc4ee).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
contracts/facets/IexecPoco1Facet.sol 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #293      +/-   ##
==========================================
+ Coverage   84.85%   85.03%   +0.18%     
==========================================
  Files          37       37              
  Lines        1241     1263      +22     
  Branches      235      238       +3     
==========================================
+ Hits         1053     1074      +21     
- 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.

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go

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.

@gfournieriExec gfournieriExec marked this pull request as ready for review October 27, 2025 15:52

import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol";

interface IexecDepositAndMatchOrders {
Copy link
Member

Choose a reason for hiding this comment

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

Why not in IexecPoco1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

// Match the orders with the requester as sponsor
dealId = this.matchOrders(_apporder, _datasetorder, _workerpoolorder, _requestorder);
Copy link
Member

Choose a reason for hiding this comment

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

This is doing an external call, make matchOrders public and call it without this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* @param depositor The account making the deposit
* @param amount The amount to deposit
*/
function _depositTokens(address depositor, uint256 amount) private {
Copy link
Member

Choose a reason for hiding this comment

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

Refactor and use existing functions:

IexecEscrowTokenFacet._deposit()
IexecERC20Core._mint()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do that when we upgrade to solidity ^0.8.0


## Summary of changes

- Add `IexecDepositAndMatchOrdersFacet` to optimize deposit and order matching operations
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
- Add `IexecDepositAndMatchOrdersFacet` to optimize deposit and order matching operations


- Add `IexecDepositAndMatchOrdersFacet` to optimize deposit and order matching operations
- Introduce functions to handle deposit and match orders in a single transaction
- Improve gas efficiency for token-based operations
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean?

import { tryVerify } from '../verify';

async function main() {
console.log('Deploying and adding DepositAndMatchOrders facet to diamond proxy...');
Copy link
Member

Choose a reason for hiding this comment

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

Not up to date.

Comment on lines +21 to +27
'421614': {
IexecPoco1Facet: '0xC8dE3913fcdBC576970dCe24eE416CA25681f65f',
},
// Arbitrum mainnet
'42161': {
IexecPoco1Facet: '0x46b555fE117DFd8D4eAC2470FA2d739c6c3a0152',
},
Copy link
Member

Choose a reason for hiding this comment

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

We should read addresses from deployments.

orders.workerpool,
orders.requester,
),
).to.be.reverted;
Copy link
Member

Choose a reason for hiding this comment

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

Specify the reason or without reason.

@gfournieriExec gfournieriExec marked this pull request as draft October 30, 2025 10:20
@gfournieriExec
Copy link
Contributor Author

Closed in flavor of #316

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