Created
February 8, 2018 04:52
-
-
Save dominiek/f01b1b8a284fb39d6a0cd8909b788c48 to your computer and use it in GitHub Desktop.
EtherDelta Trade Logic
This file contains hidden or 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
mapping (address => mapping (bytes32 => bool)) public orders; | |
mapping (address => mapping (bytes32 => uint)) public orderFills; | |
function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount) { | |
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); | |
if (!( | |
(orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && | |
block.number <= expires && | |
safeAdd(orderFills[user][hash], amount) <= amountGet | |
)) throw; | |
tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount); | |
orderFills[user][hash] = safeAdd(orderFills[user][hash], amount); | |
Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment