-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Enable deposit and match orders in a single tx #316
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
Changes from 35 commits
394908b
68c1e89
23a067f
fc6926b
0ae822a
fb844af
7f08cf3
3517bf0
47ecf74
0b8ed3e
bd2adf1
0e57654
fda1c38
6ca7c61
921df75
0c661b3
d9b56ba
b51807f
ad0130f
689e1c3
ec05830
22e3b3e
be65435
648078e
f8681d3
b229dc5
0e656ee
137dd04
c49a93e
69ebbcd
f21473b
024675e
b06e552
64d8d80
fc99890
4917773
6e36267
2e32246
14e1614
c2397f9
5fee6ac
b6a04d5
da0c7bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,7 +227,7 @@ | |
| }, | ||
| { | ||
| "internalType": "bytes", | ||
| "name": "", | ||
| "name": "data", | ||
| "type": "bytes" | ||
| } | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,8 @@ import {IexecERC20Core} from "./IexecERC20Core.sol"; | |||||||||||||||||||||
| import {FacetBase} from "./FacetBase.sol"; | ||||||||||||||||||||||
| import {IexecEscrowToken} from "../interfaces/IexecEscrowToken.sol"; | ||||||||||||||||||||||
| import {IexecTokenSpender} from "../interfaces/IexecTokenSpender.sol"; | ||||||||||||||||||||||
| import {IexecPoco1} from "../interfaces/IexecPoco1.sol"; | ||||||||||||||||||||||
| import {IexecLibOrders_v5} from "../libs/IexecLibOrders_v5.sol"; | ||||||||||||||||||||||
| import {PocoStorageLib} from "../libs/PocoStorageLib.sol"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase, IexecERC20Core { | ||||||||||||||||||||||
|
|
@@ -64,23 +66,131 @@ contract IexecEscrowTokenFacet is IexecEscrowToken, IexecTokenSpender, FacetBase | |||||||||||||||||||||
| return delta; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Token Spender (endpoint for approveAndCallback calls to the proxy) | ||||||||||||||||||||||
| /*************************************************************************** | ||||||||||||||||||||||
| * Token Spender: Atomic Approve+Deposit+Match * | ||||||||||||||||||||||
| ***************************************************************************/ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * @notice Receives approval and optionally matches orders in one transaction | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * Usage patterns: | ||||||||||||||||||||||
| * 1. Simple deposit: RLC.approveAndCall(escrow, amount, "") | ||||||||||||||||||||||
| * 2. Deposit + match: RLC.approveAndCall(escrow, amount, encodedOrders) | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * The `data` parameter should be ABI-encoded orders if matching is desired: | ||||||||||||||||||||||
| * abi.encode(appOrder, datasetOrder, workerpoolOrder, requestOrder) | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @dev Important notes: | ||||||||||||||||||||||
| * - Match orders sponsoring is NOT supported. The requester (sender) always pays for the deal. | ||||||||||||||||||||||
| * - Clients must compute the exact deal cost and deposit the right amount for the deal to be matched. | ||||||||||||||||||||||
| * The deal cost = (appPrice + datasetPrice + workerpoolPrice) * volume. | ||||||||||||||||||||||
| * - If insufficient funds are deposited, the match will fail. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @param sender The address that approved tokens (must be requester if matching) | ||||||||||||||||||||||
| * @param amount Amount of tokens approved and to be deposited | ||||||||||||||||||||||
| * @param token Address of the token (must be RLC) | ||||||||||||||||||||||
| * @param data Optional: ABI-encoded orders for matching | ||||||||||||||||||||||
| * @return success True if operation succeeded | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * @custom:example | ||||||||||||||||||||||
| * ```solidity | ||||||||||||||||||||||
| * // Compute deal cost | ||||||||||||||||||||||
| * uint256 dealCost = (appPrice + datasetPrice + workerpoolPrice) * volume; | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * // Encode orders | ||||||||||||||||||||||
| * bytes memory data = abi.encode(appOrder, datasetOrder, workerpoolOrder, requestOrder); | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
| * // One transaction does it all | ||||||||||||||||||||||
| * RLC(token).approveAndCall(iexecProxy, dealCost, data); | ||||||||||||||||||||||
| * ``` | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| function receiveApproval( | ||||||||||||||||||||||
zguesmi marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| address sender, | ||||||||||||||||||||||
| uint256 amount, | ||||||||||||||||||||||
| address token, | ||||||||||||||||||||||
| bytes calldata | ||||||||||||||||||||||
| bytes calldata data | ||||||||||||||||||||||
| ) external override returns (bool) { | ||||||||||||||||||||||
| PocoStorageLib.PocoStorage storage $ = PocoStorageLib.getPocoStorage(); | ||||||||||||||||||||||
| require(token == address($.m_baseToken), "wrong-token"); | ||||||||||||||||||||||
| _deposit(sender, amount); | ||||||||||||||||||||||
| _mint(sender, amount); | ||||||||||||||||||||||
| bytes32 dealId = bytes32(0); | ||||||||||||||||||||||
| if (data.length > 0) { | ||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have two choices here:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will check that on a later PR |
||||||||||||||||||||||
| dealId = _decodeDataAndMatchOrders(sender, data); | ||||||||||||||||||||||
|
||||||||||||||||||||||
| bytes32 dealId = bytes32(0); | |
| if (data.length > 0) { | |
| dealId = _decodeDataAndMatchOrders(sender, data); | |
| if (data.length > 0) { | |
| _decodeDataAndMatchOrders(sender, data); |
Outdated
Copilot
AI
Nov 7, 2025
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.
The variable dealId is initialized to bytes32(0) but is never used after line 120. Consider removing this variable declaration entirely since the return value from _decodeDataAndMatchOrders is not used anywhere.
| bytes32 dealId = bytes32(0); | |
| if (data.length > 0) { | |
| dealId = _decodeDataAndMatchOrders(sender, data); | |
| if (data.length > 0) { | |
| _decodeDataAndMatchOrders(sender, data); |
gfournierPro marked this conversation as resolved.
Show resolved
Hide resolved
gfournierPro marked this conversation as resolved.
Show resolved
Hide resolved
Le-Caignec marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
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.
| // Using delegatecall for safety: preserves msg.sender context | |
| // Using delegatecall for safety: preserves msg.sender context (RLC address in this case) |
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.
gfournierPro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
| // Decode the dealId from successful call | |
| dealId = abi.decode(result, (bytes32)); | |
| return 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.
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.
docs: update receiveApproval function documentation for clarity and accuracy
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.
Up here. The comment is not correct we only have 2 of them, deposit and match.
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: update comments in IexecEscrowTokenFacet for clarity on deposit and match orders