-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add details about CoWUidGenerator contract #444
Open
bram-vdberg
wants to merge
3
commits into
main
Choose a base branch
from
Add-UID-Generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
72 changes: 72 additions & 0 deletions
72
docs/cow-protocol/reference/contracts/periphery/cow_uid_generator.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
id: cow-uid-generator | ||
sidebar_position: 4 | ||
--- | ||
|
||
# CoWUidGenerator | ||
|
||
A helper contract for calculating the same EIP-712 signature hash for a given user order that the GPv2SettlementContract expects. | ||
|
||
## Architecture | ||
This contract is a simple helper contract that: | ||
|
||
- References the CoW Protocol settlement contract’s `domainSeparator`. | ||
- Constructs a Gnosis Protocol v2 (CoW) order data struct on-chain. | ||
- Determines whether the order is a sell or buy order based on `isSell`. | ||
- Computes the EIP-712 hash that matches what the CoW Protocol uses to verify user signatures off-chain. | ||
|
||
## Data Types and Storage | ||
|
||
### `GPv2SettlementContract` | ||
An interface for the [CoW Protocol settlement contract](../core/settlement.md). | ||
|
||
```solidity | ||
interface GPv2SettlementContract { | ||
function domainSeparator() external view returns (bytes32); | ||
} | ||
``` | ||
|
||
## Functions | ||
|
||
### `getUid` | ||
Constructs an order, determines if it is a sell or buy order, then computes the same EIP-712 hash used by CoW Protocol for verifying signatures. Returns both the EIP-712 digest and the ABI-encoded order. | ||
bram-vdberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
:::tip | ||
|
||
Note: The digest being returned is only the order digest, not the actual order uid. In order to get the order uid this must be concatenated with the address of the order owner and the timestamp until which the order is valid ([reference](../core/settlement.md#orderuid)). | ||
|
||
::: | ||
|
||
```solidity | ||
getUid( | ||
address sellToken, | ||
address buyToken, | ||
address receiver, | ||
uint256 sellAmount, | ||
uint256 buyAmount, | ||
uint32 validTo, | ||
bytes32 appData, | ||
uint256 feeAmount, | ||
bool isSell, | ||
bool partiallyFillable) | ||
public view returns (bytes32 hash, bytes memory encoded) | ||
``` | ||
|
||
| **Parameter** | **Description** | | ||
| --- | --- | | ||
| `sellToken` | The token address being sold if the order is a sell order, or the token that the user owes if the order is a buy order | | ||
| `buyToken` | The token the user will receive if the order is a sell order, or the token the user wants to buy if if the order is a buy order | | ||
| `receiver` | The address to receive the bought tokens | | ||
| `sellAmount` | The amount of `sellToken` being transferred (cannot be 0) | | ||
| `buyAmount` | The amount of `buyToken` being transferred (cannot be 0) | | ||
| `validTo` | Timestamp after which the order expires | | ||
| `appData` | Optional field used by users/dapps/wallets to attach meta-information to orders | | ||
| `feeAmount` | Amount of fee to be charged (currently hardcoded to 0) | | ||
| `isSell` | Indicates whether the order is a buy or sell | | ||
| `partiallyFillable` | Indicates whether the order is partially fillable or fill-or-kill | | ||
|
||
## Indexing | ||
Nil | ||
|
||
## Off-chain | ||
Nil |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a github link? Seems to be provided in all other contracts