-
Notifications
You must be signed in to change notification settings - Fork 14
feat: deposit and match orders #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ive facet and updating imports
… IexecPocoDepositAndMatchTokenFacet
There was a problem hiding this 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
IexecPocoDepositAndMatchTokenFacetcontract with the combined deposit and match functionality - Created interface
IexecPocoDepositAndMatchto 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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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.
| require(_requestorder.requester == msg.sender, "DepositAndMatch: Caller must be requester"); | ||
|
|
There was a problem hiding this comment.
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 🙏🏼
| 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
| require( | ||
| $.m_baseToken.transferFrom(depositor, address(this), amount), | ||
| "DepositAndMatch: Token transfer failed" | ||
| ); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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())
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Robin Le Caignec <[email protected]>
Co-authored-by: Copilot <[email protected]>
…cBlockchainComputing/PoCo into feature/deposit-matchOrders
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| contract IexecPocoDepositAndMatchTokenFacet is | |
| contract IexecDepositAndMatchOrdersFacet is |
| /** | ||
| * @notice Thrown when the caller is not the requester in the request order | ||
| */ | ||
| error DepositAndMatch_CallerMustBeRequester(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| error DepositAndMatch_CallerMustBeRequester(); | |
| error CallerMustBeRequester(); |
No description provided.