-
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
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.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. 🚀 New features to boost your workflow:
|
Le-Caignec
left a comment
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.
| 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.
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.
Let's go
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.
…chOrdersFacet and update related references
… and streamline proxy linking
…s interface and IexecPoco1Facet
…date documentation
…etails and standardizing action run links
…lementation and internal deposit handling
… deployment in upgrade script
|
|
||
| import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; | ||
|
|
||
| interface IexecDepositAndMatchOrders { |
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.
Why not in IexecPoco1 ?
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.
contracts/facets/IexecPoco1Facet.sol
Outdated
| } | ||
|
|
||
| // Match the orders with the requester as sponsor | ||
| dealId = this.matchOrders(_apporder, _datasetorder, _workerpoolorder, _requestorder); |
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.
This is doing an external call, make matchOrders public and call it without this.
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.
| * @param depositor The account making the deposit | ||
| * @param amount The amount to deposit | ||
| */ | ||
| function _depositTokens(address depositor, uint256 amount) private { |
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.
Refactor and use existing functions:
IexecEscrowTokenFacet._deposit()
IexecERC20Core._mint()
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.
Will do that when we upgrade to solidity ^0.8.0
|
|
||
| ## Summary of changes | ||
|
|
||
| - Add `IexecDepositAndMatchOrdersFacet` to optimize deposit and order matching operations |
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.
| - 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 |
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 mean?
| import { tryVerify } from '../verify'; | ||
|
|
||
| async function main() { | ||
| console.log('Deploying and adding DepositAndMatchOrders facet to diamond proxy...'); |
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 up to date.
| '421614': { | ||
| IexecPoco1Facet: '0xC8dE3913fcdBC576970dCe24eE416CA25681f65f', | ||
| }, | ||
| // Arbitrum mainnet | ||
| '42161': { | ||
| IexecPoco1Facet: '0x46b555fE117DFd8D4eAC2470FA2d739c6c3a0152', | ||
| }, |
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.
We should read addresses from deployments.
| orders.workerpool, | ||
| orders.requester, | ||
| ), | ||
| ).to.be.reverted; |
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.
Specify the reason or without reason.
|
Closed in flavor of #316 |
No description provided.