Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
feat: update limit orders docs
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Dec 16, 2021
1 parent 75f5fd0 commit 0f60af7
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 10 deletions.
18 changes: 12 additions & 6 deletions docs/limit-order-protocol/guide/create-limit-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ sidebar_position: 3
| `makerAssetAddress` | `String` | the address of the asset you want to sell (address of a token contract) |
| `takerAssetAddress` | `String` | the address of the asset you want to buy (address of a token contract) |
| `makerAddress` | `String` | an address of the maker (wallet address) |
| `takerAddress` | `String?` | the address of the taker for whom the limit order is being created. _This is an optional parameter_, if it is not specified, then the limit order will be available for execution for everyone |
| `takerAddress` | `String?` | by default contains a zero address, which means that a limit order is available for everyone to fill. If you set a value, then the limit order will be available for execution only for the specified address (private limit order) |
| `reciever` | `String?` | by default contains a zero address, which means that taker asset will be sent to the address of the creator of the limit order. If you set a value, then taker asset will be sent to the specified address |
| `makerAmount` | `String` | the number of maker asset tokens that you want to sell (in token units). For example: 5 DAI = 5000000000000000000 units |
| `takerAmount` | `String` | the number of taker asset tokens that you want to receive for selling the maker asset (in token units). For example: 5 DAI = 5000000000000000000 units |
| `predicate` | `String?` | a predicate call data. Default: `0x`. See [Predicate docs](./predicate.md) |
| `permit` | `String?` | a permit call data. Default: `0x` |
| `interaction` | `String?` | an interaction call data. Default: `0x` |
| `permit` | `String?` | a permit (`EIP-2612`) call data. Could be built using [utility library](https://github.com/1inch/permit-signed-approvals-utils). Default: `0x` |
| `interaction` | `String?` | a call data for InteractiveNotificationReceiver. See more [Interaction receiver docs](./interactive-receiver.md). Default: `0x` |

## Example:

Expand Down Expand Up @@ -74,11 +75,16 @@ As result you will receive a structure of [limit order](./limit-order-structure.
"salt": "1",
"makerAsset": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"takerAsset": "0x6b175474e89094c44da98b954eedeac495271d0f",
"maker": "0xfb3c7ebccccAA12B5A884d612393969Adddddddd",
"receiver": "0x0000000000000000000000000000000000000000",
"allowedSender": "0x0000000000000000000000000000000000000000",
"makingAmount": "100",
"takingAmount": "200",
"makerAssetData": "0x",
"takerAssetData": "0x",
"getMakerAmount": "0xf4a215c300000...0000",
"getTakerAmount": "0x296637bf00000...0000",
"makerAssetData": "0x23b872dd00000...0000",
"takerAssetData": "0x23b872dd00000...0000",
"predicate": "0x961d5b1e0000000000...0000",
"predicate": "0x",
"permit": "0x",
"interaction": "0x"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/limit-order-protocol/guide/domain-separator.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 11
sidebar_position: 12
---

# Domain separator
Expand Down
70 changes: 70 additions & 0 deletions docs/limit-order-protocol/guide/interactive-receiver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
sidebar_position: 11
---

# Interaction receiver

Limit order protocol has the ability to call an **intermediate contract** when an order is filled.

Intermediate contract should implement an interface: [InteractiveNotificationReceiver.sol](https://github.com/1inch/limit-order-protocol/blob/master/contracts/interfaces/InteractiveNotificationReceiver.sol)

## Use case
For example, we want to create a limit order `1INCH` - `WETH`, but so that when this order is filled, we will not receive WETH but ETH.

To do this, let's create a [smart contract](https://etherscan.io/address/0x1282d0c06368c40c8d4a4d818d78f258d982437b#code):
```solidity
contract WethUnwrapper is InteractiveNotificationReceiver {
// solhint-disable-next-line no-empty-blocks
receive() external payable {}
function notifyFillOrder(
address /* taker */,
address /* makerAsset */,
address takerAsset,
uint256 /* makingAmount */,
uint256 takingAmount,
bytes calldata interactiveData
) external override {
address payable makerAddress;
// solhint-disable-next-line no-inline-assembly
assembly {
makerAddress := shr(96, calldataload(interactiveData.offset))
}
IWithdrawable(takerAsset).withdraw(takingAmount);
makerAddress.transfer(takingAmount);
}
}
```

And create a limit order with `interaction` field:
```typescript
const interactiveReceiverAddress = '0x1282d0c06368c40c8d4a4d818d78f258d982437b';
const walletAddress = '0xfb3c7ebccccAA12B5A884d612393969Adddddddd';

const limitOrder = limitOrderBuilder.buildLimitOrder({
makerAssetAddress: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
takerAssetAddress: '0x111111111117dc0aa78b770fa6a738034120c302',
makerAddress: walletAddress,
reciever: interactiveReceiverAddress,
interaction: interactiveReceiverAddress + walletAddress.slice(2),
makerAmount: '100',
takerAmount: '200',
predicate: '0x0',
permit: '0x0',
});
```

> As you can see, the interaction field consists of two parts - the `contract address` and the `interactiveData` (which contains the wallet address).
> We also set the `interactiveReceiverAddress` as the `reciever`.
> This is necessary in order for this contract to receive a `WETH` when filling out an limit order and return `ETH` to the creator of the limit order.
Now the limit order will work according to the following scenario:
- someone (`taker`) will create a transaction to execute a limit order
- `taker` funds (`WETH`) will be transferred to the `interactiveReceiver` contract
- `interactiveReceiver` contract will send the same amount of `ETH` to the `maker`
- and finally, the `maker asset` (`1INCH`) will be transferred from the `maker's` address to the `taker's` address

[Example of transaction](https://etherscan.io/tx/0x1fe3929fcbe62d587ee98d3cfbcb6b8c392891565a56767f0e9ed39bf387c7a5)

> **However, this is one example of the use of interactivity. You can implement any other scenario**
11 changes: 8 additions & 3 deletions docs/limit-order-protocol/guide/limit-order-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ sidebar_position: 3
| `salt` | `String` | some unique value. It is necessary to be able to create limit orders with the same parameters (so that they have a different hash) |
| `makerAsset` | `String` | the address of the asset you want to sell (address of a token contract) |
| `takerAsset` | `String` | the address of the asset you want to buy (address of a token contract) |
| `maker` | `String` | the address of the limit order creator |
| `receiver` | `String` | by default contains a zero address, which means that taker asset will be sent to the address of the creator of the limit order. If you set a value, then taker asset will be sent to the specified address |
| `allowedSender` | `String` | by default contains a zero address, which means that a limit order is available for everyone to fill. If you set a value, then the limit order will be available for execution only for the specified address (private limit order) |
| `makingAmount` | `String` | amount of maker asset |
| `takingAmount` | `String` | amount of taker asset |
| `makerAssetData` | `String` | the technical info about a maker asset and its amount |
| `takerAssetData` | `String` | the technical info about a taker asset and its amount |
| `getMakerAmount` | `String` | technical information to get the amount of the maker asset |
| `getTakerAmount` | `String` | technical information to get the amount of the taker asset |
| `predicate` | `String` | a predicate call data. See [Predicate docs](./predicate.md) |
| `permit` | `String` | a permit call data |
| `interaction` | `String` | an interaction call data |
| `predicate` | `String` | a predicate call data. See more [Predicate docs](./predicate.md) |
| `permit` | `String` | a permit (`EIP-2612`) call data. Could be built using [utility library](https://github.com/1inch/permit-signed-approvals-utils) |
| `interaction` | `String` | a call data for InteractiveNotificationReceiver. See more [Interaction receiver docs](./interactive-receiver.md) |
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sidebar_position: 2
| Field | Type | Description |
| -------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | `Number` | is a pass-through, integer identifier starting at 1 |
| `wrapEth` | `Boolean?`| if this flag is enabled, then in the case of a limit order, the taker asset of which is WETH, the taker does not need to give permission to use WETH. Aggregation protocol router will use ETH instead of WETH as taker asset |
| `expiresInTimestamp` | `Number` | is the timestamp in seconds when the limit order will no longer be available for execution. For example: 1623166270029 |
| `makerAssetAddress` | `String` | the address of the asset you want to sell (address of a token contract) |
| `takerAssetAddress` | `String` | the address of the asset you want to buy (address of a token contract) |
Expand Down

0 comments on commit 0f60af7

Please sign in to comment.