This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
feature/multi-trade #95
Open
mattdf
wants to merge
9
commits into
version/3.0.0
Choose a base branch
from
feature/multi-trade
base: version/3.0.0
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.
+70
−3
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8508b2a
multi-trade poc
mattdf 0b012b1
enhancement/logic-libraries (#96)
68e1314
update to use lib, remove redundant vars/init
mattdf fa690bc
Merge remote-tracking branch 'origin/version/3.0.0' into feature/mult…
mattdf 5ae887b
add maxamount per trade
mattdf 3ba1508
add multifillupto for single token trades, make trade func return fil…
mattdf afa39be
made maxfill calc in fillupto work
mattdf a62b32a
fix sig byte storage offset
mattdf e238f2c
Merge branch 'version/3.0.0' into feature/multi-trade
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,13 +50,63 @@ contract Exchange is Ownable, ExchangeInterface { | |
emit Unsubscribed(msg.sender); | ||
} | ||
|
||
|
||
function multifillUpTo(address makerToken, address takerToken, address[] makers, uint[] values, bytes32[] sigmain, uint16[] sigaux, uint maxFillAmount) external { | ||
require(makers.length == sigaux.length); | ||
require(makers.length*2 == sigmain.length); | ||
require(makers.length*4 == values.length); | ||
|
||
address[3] memory addrs; | ||
uint[4] memory vals; | ||
bytes memory s; | ||
uint filledSoFar = 0; | ||
|
||
for (uint i = 0; i < makers.length; i++){ | ||
for (uint j = 0; j < 4; j++){ | ||
vals[j] = values[i*4 + j]; | ||
} | ||
addrs[0] = makers[i]; | ||
addrs[1] = makerToken; | ||
addrs[2] = takerToken; | ||
s = sigArrayToBytes(sigmain, sigaux, i); | ||
uint filled = exchange.trade(OrderLibrary.createOrder(addrs, vals), msg.sender, s, maxFillAmount-filledSoFar); | ||
filledSoFar = filledSoFar + filled; | ||
if (filledSoFar >= maxFillAmount){ | ||
return; | ||
} | ||
} | ||
} | ||
|
||
|
||
function multitrade(address[] addresses, uint[] values, bytes32[] sigmain, uint16[] sigaux, uint[] maxFillAmount) external { | ||
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. Even if we do not fully use it, we should consider |
||
require(addresses.length == 3*sigaux.length); | ||
require(values.length == 4*sigaux.length); | ||
require(sigmain.length == 2*sigaux.length); | ||
require(maxFillAmount.length == sigaux.length); | ||
|
||
address[3] memory addrs; | ||
uint[4] memory vals; | ||
bytes memory s; | ||
|
||
for (uint i = 0; i < sigaux.length; i++){ | ||
for (uint j = 0; j < 3; j++){ | ||
addrs[j] = addresses[(i*3)+j]; | ||
} | ||
for (j = 0; j < 4; j++){ | ||
vals[j] = values[(i*4)+j]; | ||
} | ||
s = sigArrayToBytes(sigmain, sigaux, i); | ||
exchange.trade(OrderLibrary.createOrder(addrs, vals), msg.sender, s, maxFillAmount[i]); | ||
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. no need for s, do it right here. |
||
} | ||
} | ||
|
||
/// @dev Takes an order. | ||
/// @param addresses Array of trade's maker, makerToken and takerToken. | ||
/// @param values Array of trade's makerTokenAmount, takerTokenAmount, expires and nonce. | ||
/// @param signature Signed order along with signature mode. | ||
/// @param maxFillAmount Maximum amount of the order to be filled. | ||
function trade(address[3] addresses, uint[4] values, bytes signature, uint maxFillAmount) external { | ||
exchange.trade(OrderLibrary.createOrder(addresses, values), msg.sender, signature, maxFillAmount); | ||
function trade(address[3] addresses, uint[4] values, bytes signature, uint maxFillAmount) external returns (uint) { | ||
return exchange.trade(OrderLibrary.createOrder(addresses, values), msg.sender, signature, maxFillAmount); | ||
} | ||
|
||
/// @dev Cancels an order. | ||
|
@@ -169,4 +219,19 @@ contract Exchange is Ownable, ExchangeInterface { | |
function isOrdered(address user, bytes32 hash) public view returns (bool) { | ||
return exchange.orders[user][hash]; | ||
} | ||
|
||
function sigArrayToBytes(bytes32[] sm, uint16[] sa, uint i) internal pure returns (bytes) { | ||
bytes32 s1 = sm[i*2]; | ||
bytes32 s2 = sm[i*2 + 1]; | ||
uint16 s3 = sa[i]; | ||
uint8 s4 = uint8(s3 % 256); | ||
s3 = (s3 - uint16(s4)) / 256; | ||
bytes memory s = new bytes(66); | ||
assembly { | ||
mstore(add(s, 32), s1) | ||
mstore(add(s, 64), s2) | ||
mstore8(add(s, 96), s3) | ||
mstore8(add(s, 97), s4) | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -47,7 +47,7 @@ library ExchangeLibrary { | |
bytes signature, | ||
uint maxFillAmount | ||
) | ||
internal | ||
internal returns (uint) | ||
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. returns on new line |
||
{ | ||
require(taker != order.maker); | ||
bytes32 hash = order.hash(); | ||
|
@@ -90,6 +90,8 @@ library ExchangeLibrary { | |
order.maker, | ||
taker | ||
); | ||
|
||
return fillAmount; | ||
} | ||
|
||
/// @dev Indicates whether or not an certain amount of an order can be traded. | ||
|
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.
no point in
addrs