This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,765 additions
and
1,326 deletions.
There are no files selected for viewing
69 changes: 55 additions & 14 deletions
69
docs/limit-order-protocol/smart-contract/LimitOrderProtocol.md
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 |
---|---|---|
@@ -1,27 +1,68 @@ | ||
# LimitOrderProtocol | ||
|
||
## LimitOrderProtocol | ||
|
||
1inch Limit Order Protocol v2 | ||
The key features of the protocol are **extreme flexibility** and **high gas efficiency**, which are achieved with the following features | ||
|
||
**Basic features** | ||
|
||
- Select an asset receiver for an order. | ||
- Choose whether to allow or disallow partial and multiple fills. | ||
- Define conditions that must be met before execution can proceed (e.g. stop-loss, take-profit orders). | ||
- Specify interactions (arbitrary maker's code) to execute before and after order filling. | ||
- Choose an approval scheme for token spend (approve, permit, permit2). | ||
- Request that WETH be unwrapped to ETH either before (to sell ETH) or after the swap (to receive ETH). | ||
- Make an order private by specifying the only allowed taker's address. | ||
- Set the order's expiration date. | ||
- Assign a nonce or epoch to the order for easy cancellation later. | ||
|
||
## Derives | ||
- [OrderRFQMixin](OrderRFQMixin.md) | ||
- [OrderMixin](OrderMixin.md) | ||
- [Permitable](libraries/Permitable.md) | ||
- [PredicateHelper](helpers/PredicateHelper.md) | ||
- [NonceManager](helpers/NonceManager.md) | ||
- [ChainlinkCalculator](helpers/ChainlinkCalculator.md) | ||
- [AmountCalculator](helpers/AmountCalculator.md) | ||
- [EIP712](https://docs.openzeppelin.com/contracts/3.x/api/utils/cryptography#draft-EIP712) | ||
**Advanced features** | ||
|
||
- Define a proxy to handle transfers of assets that are not compliant with `IERC20`, allowing the swapping of non-ERC20 tokens, such as ERC721 or ERC1155. | ||
- Define functions to calculate, on-chain, the exchange rate for maker and taker assets. These functions can be used to implement dutch auctions (where the rate decreases over time) or range orders (where the rate depends on the volume already filled), among others. | ||
|
||
### RFQ orders | ||
|
||
Separate RFQ order are deprecated in v4. To create the most gas efficient order use a basic order without extensions. | ||
|
||
### Supported tokens | ||
|
||
- ERC 20 | ||
- ERC 721 | ||
- ERC 1155 | ||
- Other token standards could be supported via external extension | ||
|
||
### Functions list | ||
- [constructor(_weth) public](#constructor) | ||
- [DOMAIN_SEPARATOR() external](#domain_separator) | ||
- [pause() external](#pause) | ||
- [unpause() external](#unpause) | ||
|
||
### Functions | ||
### constructor | ||
|
||
```solidity | ||
constructor(contract IWETH _weth) public | ||
``` | ||
|
||
## Functions | ||
### DOMAIN_SEPARATOR | ||
|
||
```solidity | ||
function DOMAIN_SEPARATOR( | ||
) external returns (bytes32) | ||
function DOMAIN_SEPARATOR() external view returns (bytes32) | ||
``` | ||
|
||
_Returns the domain separator for the current chain (EIP-712)_ | ||
|
||
### pause | ||
|
||
```solidity | ||
function pause() external | ||
``` | ||
Pauses all the trading functionality in the contract. | ||
|
||
### unpause | ||
|
||
```solidity | ||
function unpause() external | ||
``` | ||
Unpauses all the trading functionality in the contract. | ||
|
26 changes: 0 additions & 26 deletions
26
docs/limit-order-protocol/smart-contract/LimitOrderProtocolPro.md
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,135 +1,159 @@ | ||
# OrderLib | ||
|
||
|
||
## OrderLib | ||
|
||
_The library provides common functionality for processing and manipulating limit orders. | ||
It provides functionality to calculate and verify order hashes, calculate trade amounts, and validate | ||
extension data associated with orders. The library also contains helper methods to get the receiver of | ||
an order and call getter functions._ | ||
|
||
### Functions list | ||
- [hash(order, domainSeparator) internal](#hash) | ||
- [getReceiver(order) internal](#getreceiver) | ||
- [calculateMakingAmount(order, extension, requestedTakingAmount, remainingMakingAmount, orderHash) internal](#calculatemakingamount) | ||
- [calculateTakingAmount(order, extension, requestedMakingAmount, remainingMakingAmount, orderHash) internal](#calculatetakingamount) | ||
- [isValidExtension(order, extension) internal](#isvalidextension) | ||
|
||
### Errors list | ||
- [MissingOrderExtension() ](#missingorderextension) | ||
- [UnexpectedOrderExtension() ](#unexpectedorderextension) | ||
- [InvalidExtensionHash() ](#invalidextensionhash) | ||
|
||
### Functions | ||
### hash | ||
|
||
## Functions | ||
### makerAssetData | ||
```solidity | ||
function makerAssetData( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
function hash(struct IOrderMixin.Order order, bytes32 domainSeparator) internal pure returns (bytes32 result) | ||
``` | ||
Calculates the hash of an order. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
| order | struct IOrderMixin.Order | The order to be hashed. | | ||
| domainSeparator | bytes32 | The domain separator to be used for the EIP-712 hashing. | | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
#### Return Values | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
result | bytes32 | The keccak256 hash of the order data. | | ||
|
||
### getReceiver | ||
|
||
### takerAssetData | ||
```solidity | ||
function takerAssetData( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
function getReceiver(struct IOrderMixin.Order order) internal pure returns (address) | ||
``` | ||
Returns the receiver address for an order. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
| order | struct IOrderMixin.Order | The order. | | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
#### Return Values | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
[0] | address | receiver The address of the receiver, either explicitly defined in the order or the maker's address if not specified. | | ||
|
||
### calculateMakingAmount | ||
|
||
### getMakingAmount | ||
```solidity | ||
function getMakingAmount( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
function calculateMakingAmount(struct IOrderMixin.Order order, bytes extension, uint256 requestedTakingAmount, uint256 remainingMakingAmount, bytes32 orderHash) internal view returns (uint256) | ||
``` | ||
Calculates the making amount based on the requested taking amount. | ||
|
||
_If getter is specified in the extension data, the getter is called to calculate the making amount, | ||
otherwise the making amount is calculated linearly._ | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
| order | struct IOrderMixin.Order | The order. | | ||
| extension | bytes | The extension data associated with the order. | | ||
| requestedTakingAmount | uint256 | The amount the taker wants to take. | | ||
| remainingMakingAmount | uint256 | The remaining amount of the asset left to fill. | | ||
| orderHash | bytes32 | The hash of the order. | | ||
|
||
### getTakingAmount | ||
```solidity | ||
function getTakingAmount( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
``` | ||
#### Return Values | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
[0] | uint256 | makingAmount The amount of the asset the maker receives. | | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
### calculateTakingAmount | ||
|
||
|
||
### predicate | ||
```solidity | ||
function predicate( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
function calculateTakingAmount(struct IOrderMixin.Order order, bytes extension, uint256 requestedMakingAmount, uint256 remainingMakingAmount, bytes32 orderHash) internal view returns (uint256) | ||
``` | ||
Calculates the taking amount based on the requested making amount. | ||
|
||
_If getter is specified in the extension data, the getter is called to calculate the taking amount, | ||
otherwise the taking amount is calculated linearly._ | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
|
||
#### Parameters | ||
|
||
### permit | ||
```solidity | ||
function permit( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
``` | ||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
| order | struct IOrderMixin.Order | The order. | | ||
| extension | bytes | The extension data associated with the order. | | ||
| requestedMakingAmount | uint256 | The amount the maker wants to receive. | | ||
| remainingMakingAmount | uint256 | The remaining amount of the asset left to be filled. | | ||
| orderHash | bytes32 | The hash of the order. | | ||
|
||
#### Return Values | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
[0] | uint256 | takingAmount The amount of the asset the taker takes. | | ||
|
||
### isValidExtension | ||
|
||
### preInteraction | ||
```solidity | ||
function preInteraction( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
function isValidExtension(struct IOrderMixin.Order order, bytes extension) internal pure returns (bool, bytes4) | ||
``` | ||
|
||
_Validates the extension associated with an order._ | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
| order | struct IOrderMixin.Order | The order to validate against. | | ||
| extension | bytes | The extension associated with the order. | | ||
|
||
#### Return Values | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
| Name | Type | Description | | ||
| ---- | ---- | ----------- | | ||
[0] | bool | valid True if the extension is valid, false otherwise. | | ||
[1] | bytes4 | errorSelector The error selector if the extension is invalid, 0x00000000 otherwise. | | ||
|
||
### Errors | ||
### MissingOrderExtension | ||
|
||
### postInteraction | ||
```solidity | ||
function postInteraction( | ||
struct OrderLib.Order order | ||
) internal returns (bytes) | ||
error MissingOrderExtension() | ||
``` | ||
|
||
_Error to be thrown when the extension data of an order is missing._ | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
### UnexpectedOrderExtension | ||
|
||
|
||
### hash | ||
```solidity | ||
function hash( | ||
struct OrderLib.Order order | ||
) internal returns (bytes32 result) | ||
error UnexpectedOrderExtension() | ||
``` | ||
|
||
_Error to be thrown when the order has an unexpected extension._ | ||
|
||
### InvalidExtensionHash | ||
|
||
#### Parameters: | ||
| Name | Type | Description | | ||
| :--- | :--- | :------------------------------------------------------------------- | | ||
|`order` | struct OrderLib.Order | | ||
```solidity | ||
error InvalidExtensionHash() | ||
``` | ||
|
||
_Error to be thrown when the order extension hash is invalid._ | ||
|
Oops, something went wrong.