-
Notifications
You must be signed in to change notification settings - Fork 90
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
Implement 0x liquidity #2218
Merged
Merged
Implement 0x liquidity #2218
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
37facc8
Implement 0x liquidity
squadgazzz 7d982bd
Minor
squadgazzz f3e38c1
Refactoring
squadgazzz cb88286
Remaining todos
squadgazzz 4f23650
Clean-up
squadgazzz 3bba068
Refactoring
squadgazzz 1647ad8
Naming
squadgazzz 5184697
Review fixes
squadgazzz a9d7fd5
Merge branch 'main' into fix/1666-2
squadgazzz 1fbeba6
Merge branch 'main' into fix/1666-2
squadgazzz a459359
IZeroEx via Arc
squadgazzz 38de5f9
Signature field
squadgazzz aaf7c29
Safe executed amount conversion
squadgazzz 17dd562
Merge branch 'main' into fix/1666-2
squadgazzz 5dc0d86
Merge branch 'main' into fix/1666-2
squadgazzz cdef6b6
Merge branch 'main' into fix/1666-2
squadgazzz 8354312
Merge branch 'main' into fix/1666-2
squadgazzz b67d0ee
Review fixes
squadgazzz 5301a49
Merge branch 'main' into fix/1666-2
squadgazzz 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
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
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,5 +1,80 @@ | ||
/// A signed 0x Protocol Limit Order [^1]. | ||
/// | ||
/// [^1]: <https://docs.0x.org/limit-orders-advanced-traders/docs/introduction> | ||
use { | ||
crate::domain::{eth, liquidity}, | ||
anyhow::{anyhow, Context}, | ||
contracts::IZeroEx, | ||
ethcontract::Bytes, | ||
primitive_types::{H160, H256, U256}, | ||
std::sync::Arc, | ||
}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct LimitOrder {} | ||
pub struct LimitOrder { | ||
pub order: Order, | ||
pub zeroex: Arc<IZeroEx>, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Order { | ||
pub maker: H160, | ||
pub taker: H160, | ||
pub sender: H160, | ||
pub maker_token: H160, | ||
pub taker_token: H160, | ||
pub maker_amount: u128, | ||
pub taker_amount: u128, | ||
pub taker_token_fee_amount: u128, | ||
pub fee_recipient: H160, | ||
pub pool: H256, | ||
pub expiry: u64, | ||
pub salt: U256, | ||
pub signature: ZeroExSignature, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ZeroExSignature { | ||
pub r: H256, | ||
pub s: H256, | ||
pub v: u8, | ||
pub signature_type: u8, | ||
} | ||
|
||
impl LimitOrder { | ||
pub fn to_interaction(&self, input: &liquidity::MaxInput) -> anyhow::Result<eth::Interaction> { | ||
let method = self.zeroex.clone().fill_or_kill_limit_order( | ||
( | ||
squadgazzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.order.maker_token, | ||
self.order.taker_token, | ||
self.order.maker_amount, | ||
self.order.taker_amount, | ||
self.order.taker_token_fee_amount, | ||
self.order.maker, | ||
self.order.taker, | ||
self.order.sender, | ||
self.order.fee_recipient, | ||
Bytes(self.order.pool.0), | ||
self.order.expiry, | ||
self.order.salt, | ||
), | ||
( | ||
self.order.signature.signature_type, | ||
self.order.signature.v, | ||
Bytes(self.order.signature.r.0), | ||
Bytes(self.order.signature.s.0), | ||
), | ||
input | ||
.0 | ||
.amount | ||
.0 | ||
.try_into() | ||
.map_err(|err: &str| anyhow!(err)) | ||
.context("executed amount does not fit into u128")?, | ||
squadgazzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
let calldata = method.tx.data.ok_or(anyhow!("no calldata"))?; | ||
|
||
Ok(eth::Interaction { | ||
target: self.zeroex.clone().address().into(), | ||
value: 0.into(), | ||
squadgazzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
call_data: calldata.0.into(), | ||
}) | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -153,12 +153,6 @@ components: | |
type: string | ||
example: "13.37" | ||
|
||
Digest: | ||
description: | | ||
A hex-encoded 32 byte digest. | ||
type: string | ||
example: "0x1e66721bb1bd77d2641c77ea1d61e8abb92bf69c64fcc90c2c6ad518d1b50db1" | ||
|
||
NativePrice: | ||
description: | | ||
The price in wei of the native token (Ether on Mainnet for example) to | ||
|
@@ -526,7 +520,6 @@ components: | |
type: object | ||
required: | ||
- kind | ||
- hash | ||
- makerToken | ||
- takerToken | ||
- makerAmount | ||
|
@@ -536,8 +529,6 @@ components: | |
kind: | ||
type: string | ||
enum: [limitOrder] | ||
hash: | ||
$ref: "#/components/schemas/Digest" | ||
Comment on lines
-539
to
-540
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. Turned out that is not currently used at all. And also not sure how to populate it. |
||
makerToken: | ||
$ref: "#/components/schemas/Token" | ||
takerToken: | ||
|
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.
😬 hack alert. Can we add a comment in the code on why we are chosing this workaround and how a proper solution would look like?
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.
Done