-
Notifications
You must be signed in to change notification settings - Fork 48
feat: implement generic wrapper #247
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 2 commits
8f1648d
1e8127f
9bfad39
14cc843
9f119d6
277be44
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| pragma solidity >=0.7.6 <0.9.0; | ||
| pragma abicoder v2; | ||
|
|
||
| import "./GPv2Settlement.sol"; | ||
| import "./interfaces/IERC20.sol"; | ||
|
|
||
| /** | ||
| * @dev Interface defining required methods for wrappers of the GPv2Settlement contract for CoW orders | ||
|
||
| * A wrapper should: | ||
| * * call the equivalent `settle` on the GPv2Settlement contract (0x9008D19f58AAbD9eD0D60971565AA8510560ab41) | ||
| * * verify that the caller is authorized via the GPv2Authentication contract. | ||
| * A wrapper may also execute, or otherwise put the blockchain in a state that needs to be established prior to settlement. | ||
| * Additionally, it needs to be approved by the GPv2Authentication contract | ||
| */ | ||
| abstract contract GPv2Wrapper { | ||
|
||
| GPv2Settlement public immutable UPSTREAM_SETTLEMENT; | ||
| GPv2Authentication public immutable AUTHENTICATOR; | ||
|
|
||
| constructor(address payable upstreamSettlement_) { | ||
| UPSTREAM_SETTLEMENT = GPv2Settlement(upstreamSettlement_); | ||
|
|
||
| // retrieve the authentication we are supposed to use from the settlement contract | ||
| AUTHENTICATOR = GPv2Settlement(upstreamSettlement_).authenticator(); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Called to initiate a wrapped call against the settlement function. See GPv2Settlement.settle() for more information. | ||
| */ | ||
| function wrappedSettle( | ||
| IERC20[] calldata tokens, | ||
| uint256[] calldata clearingPrices, | ||
| GPv2Trade.Data[] calldata trades, | ||
| GPv2Interaction.Data[][3] calldata interactions, | ||
| bytes calldata wrapperData | ||
| ) external { | ||
| // Revert if not a valid solver | ||
| if (!AUTHENTICATOR.isSolver(msg.sender)) { | ||
kaze-cow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| revert("GPv2Wrapper: not a solver"); | ||
| } | ||
|
|
||
| _wrap(tokens, clearingPrices, trades, interactions, wrapperData); | ||
| } | ||
|
|
||
| /** | ||
| * @dev The logic for the wrapper. During this function, `_internalSettle` should be called | ||
| */ | ||
| function _wrap( | ||
| IERC20[] calldata tokens, | ||
| uint256[] calldata clearingPrices, | ||
| GPv2Trade.Data[] calldata trades, | ||
| GPv2Interaction.Data[][3] calldata interactions, | ||
| bytes calldata wrapperData | ||
| ) internal virtual; | ||
|
|
||
| function _internalSettle( | ||
| IERC20[] calldata tokens, | ||
| uint256[] calldata clearingPrices, | ||
| GPv2Trade.Data[] calldata trades, | ||
| GPv2Interaction.Data[][3] calldata interactions | ||
| ) internal { | ||
| UPSTREAM_SETTLEMENT.settle(tokens, clearingPrices, trades, interactions); | ||
|
Check failure on line 75 in src/contracts/GPv2Wrapper.sol
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||||||
| // solhint-disable-next-line compiler-version | ||||||
| pragma solidity >=0.7.6 <0.9.0; | ||||||
| pragma abicoder v2; | ||||||
|
Comment on lines
+2
to
+4
Contributor
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. You can use Solidity v0.8 for the tests to get rid of the solhint disable, we already do that foll all Foundry tests. |
||||||
|
|
||||||
| import "src/contracts/GPv2Wrapper.sol"; | ||||||
|
Contributor
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. Nit: explicit imports are nicer for debugging since it lets you understand more easily where some component comes from at a glance.
Suggested change
|
||||||
|
|
||||||
| contract EmptyWrapper is GPv2Wrapper { | ||||||
| constructor(address payable upstreamSettlement_) GPv2Wrapper(upstreamSettlement_) {} | ||||||
|
|
||||||
| function _wrap( | ||||||
| IERC20[] calldata tokens, | ||||||
| uint256[] calldata clearingPrices, | ||||||
| GPv2Trade.Data[] calldata trades, | ||||||
| GPv2Interaction.Data[][3] calldata interactions, | ||||||
| bytes calldata /*wrappedData*/ | ||||||
| ) internal override { | ||||||
| _internalSettle(tokens, clearingPrices, trades, interactions); | ||||||
| } | ||||||
| } | ||||||
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.
Nit: the license preamble is unneeded, contracts in this repo usually don't specify it.