-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reorganize contracts (#68)
- Loading branch information
1 parent
3cbe2fe
commit 37f386a
Showing
18 changed files
with
302 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import {IOrders} from "./orders/IOrders.sol"; | ||
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol"; | ||
|
||
abstract contract UsesPermit2 { | ||
/// @param permit - the permit2 single token transfer details. includes a `deadline` and an unordered `nonce`. | ||
/// @param signer - the signer of the permit2 info; the owner of the tokens. | ||
/// @param signature - the signature over the permit + witness. | ||
struct Permit2 { | ||
ISignatureTransfer.PermitTransferFrom permit; | ||
address owner; | ||
bytes signature; | ||
} | ||
|
||
/// @param permit - the permit2 batch token transfer details. includes a `deadline` and an unordered `nonce`. | ||
/// @param signer - the signer of the permit2 info; the owner of the tokens. | ||
/// @param signature - the signature over the permit + witness. | ||
struct Permit2Batch { | ||
ISignatureTransfer.PermitBatchTransferFrom permit; | ||
address owner; | ||
bytes signature; | ||
} | ||
|
||
/// @notice Struct to hold the pre-hashed witness field and the witness type string. | ||
struct Witness { | ||
bytes32 witnessHash; | ||
string witnessTypeString; | ||
} | ||
|
||
/// @notice The Permit2 contract address. | ||
address immutable permit2Contract; | ||
|
||
constructor(address _permit2) { | ||
permit2Contract = _permit2; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import {OrdersPermit2} from "./OrdersPermit2.sol"; | ||
import {IOrders} from "./IOrders.sol"; | ||
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | ||
|
||
/// @notice Contract capable of processing fulfillment of intent-based Orders. | ||
abstract contract OrderDestination is IOrders, OrdersPermit2 { | ||
/// @notice Emitted when Order Outputs are sent to their recipients. | ||
/// @dev NOTE that here, Output.chainId denotes the *origin* chainId. | ||
event Filled(Output[] outputs); | ||
|
||
/// @notice Fill any number of Order(s), by transferring their Output(s). | ||
/// @dev Filler may aggregate multiple Outputs with the same (`chainId`, `recipient`, `token`) into a single Output with the summed `amount`. | ||
/// @dev NOTE that here, Output.chainId denotes the *origin* chainId. | ||
/// @param outputs - The Outputs to be transferred. | ||
/// @custom:emits Filled | ||
function fill(Output[] memory outputs) external payable { | ||
// transfer outputs | ||
_transferOutputs(outputs); | ||
|
||
// emit | ||
emit Filled(outputs); | ||
} | ||
|
||
/// @notice Fill any number of Order(s), by transferring their Output(s) via permit2 signed batch transfer. | ||
/// @dev Can only provide ERC20 tokens as Outputs. | ||
/// @dev Filler may aggregate multiple Outputs with the same (`chainId`, `recipient`, `token`) into a single Output with the summed `amount`. | ||
/// @dev the permit2 signer is the Filler providing the Outputs. | ||
/// @dev the permit2 `permitted` tokens MUST match provided Outputs. | ||
/// @dev Filler MUST submit `fill` and `intitiate` within an atomic bundle. | ||
/// @dev NOTE that here, Output.chainId denotes the *origin* chainId. | ||
/// @param outputs - The Outputs to be transferred. signed over via permit2 witness. | ||
/// @param permit2 - the permit2 details, signer, and signature. | ||
/// @custom:emits Filled | ||
function fillPermit2(Output[] memory outputs, OrdersPermit2.Permit2Batch calldata permit2) external { | ||
// transfer all tokens to the Output recipients via permit2 (includes check on nonce & deadline) | ||
_permitWitnessTransferFrom( | ||
outputWitness(outputs), _fillTransferDetails(outputs, permit2.permit.permitted), permit2 | ||
); | ||
|
||
// emit | ||
emit Filled(outputs); | ||
} | ||
|
||
/// @notice Transfer the Order Outputs to their recipients. | ||
function _transferOutputs(Output[] memory outputs) internal { | ||
uint256 value = msg.value; | ||
for (uint256 i; i < outputs.length; i++) { | ||
if (outputs[i].token == address(0)) { | ||
// this line should underflow if there's an attempt to spend more ETH than is attached to the transaction | ||
value -= outputs[i].amount; | ||
payable(outputs[i].recipient).transfer(outputs[i].amount); | ||
} else { | ||
IERC20(outputs[i].token).transferFrom(msg.sender, outputs[i].recipient, outputs[i].amount); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import {OrderDestination} from "./OrderDestination.sol"; | ||
import {OrderOrigin} from "./OrderOrigin.sol"; | ||
import {UsesPermit2} from "../UsesPermit2.sol"; | ||
|
||
contract HostOrders is OrderDestination { | ||
constructor(address _permit2) UsesPermit2(_permit2) {} | ||
} | ||
|
||
contract RollupOrders is OrderOrigin, OrderDestination { | ||
constructor(address _permit2) UsesPermit2(_permit2) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.