aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-07 18:40:58 +0800
committerFabio Berger <me@fabioberger.com>2017-06-07 18:40:58 +0800
commit918315e89f3408124d2e78bbd1acb58ed42d1766 (patch)
tree40a6066c47e3643afd4f5fabde9fe7f260ea6f5a /src/utils
parent8ec3bec5b3de726fbf2cc828e179ac2ed1029d9f (diff)
downloaddexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.tar
dexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.tar.gz
dexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.tar.bz2
dexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.tar.lz
dexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.tar.xz
dexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.tar.zst
dexon-sol-tools-918315e89f3408124d2e78bbd1acb58ed42d1766.zip
Implement fillOrKill & tests
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/constants.ts1
-rw-r--r--src/utils/utils.ts24
2 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index 5a5ba0e0a..ebc8586f3 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -1,4 +1,5 @@
export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
TESTRPC_NETWORK_ID: 50,
+ INVALID_JUMP_IDENTIFIER: 'invalid JUMP at',
};
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index 114b46f6c..1d2e2f908 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -1,5 +1,8 @@
import * as _ from 'lodash';
import * as BN from 'bn.js';
+import * as ethUtil from 'ethereumjs-util';
+import * as ethABI from 'ethereumjs-abi';
+import {SolidityTypes, Order} from '../types';
export const utils = {
/**
@@ -22,6 +25,27 @@ export const utils = {
const isValid = /^0x[0-9A-F]{64}$/i.test(orderHashHex);
return isValid;
},
+ getOrderHashHex(order: Order, exchangeContractAddr: string) {
+ const orderParts = [
+ {value: exchangeContractAddr, type: SolidityTypes.address},
+ {value: order.maker, type: SolidityTypes.address},
+ {value: order.taker, type: SolidityTypes.address},
+ {value: order.makerTokenAddress, type: SolidityTypes.address},
+ {value: order.takerTokenAddress, type: SolidityTypes.address},
+ {value: order.feeRecipient, type: SolidityTypes.address},
+ {value: utils.bigNumberToBN(order.makerTokenAmount), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.takerTokenAmount), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.makerFee), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.takerFee), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.expirationUnixTimestampSec), type: SolidityTypes.uint256},
+ {value: utils.bigNumberToBN(order.salt), type: SolidityTypes.uint256},
+ ];
+ const types = _.map(orderParts, o => o.type);
+ const values = _.map(orderParts, o => o.value);
+ const hashBuff = ethABI.soliditySHA3(types, values);
+ const hashHex = ethUtil.bufferToHex(hashBuff);
+ return hashHex;
+ },
spawnSwitchErr(name: string, value: any) {
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
},