|
1 | 1 | const Contracts = require('../lib/ethereum/contracts/Contracts').default;
|
2 | 2 | const fm = require('../lib/common/formatter');
|
| 3 | +const Order = require('../lib/relay/rpc/order'); |
| 4 | +const Ring = require('../lib/relay/rpc/ring'); |
| 5 | +const ethUtil = require('ethereumjs-util'); |
3 | 6 |
|
4 | 7 | const order1 = {
|
5 |
| - 'delegateAddress': '0x17233e07c67d086464fD408148c3ABB56245FA64', |
6 |
| - 'protocol': '0x8d8812b72d1e4ffCeC158D25f56748b7d67c1e78', |
7 |
| - 'owner': '0x56447C02767BA621f103C0f3DbF564dbcacF284b', |
8 |
| - 'tokenB': '0xef68e7c694f40c8202821edf525de3782458639f', |
9 |
| - 'tokenS': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
10 |
| - 'amountB': '0x97e81a3e7c517c000', |
11 |
| - 'amountS': '0x9184e72a000', |
12 |
| - 'lrcFee': '0x0', |
13 |
| - 'validSince': '0x5bd34a12', |
14 |
| - 'validUntil': '0x5bd49b92', |
15 |
| - 'marginSplitPercentage': 0, |
16 |
| - 'buyNoMoreThanAmountB': true, |
17 |
| - 'walletAddress': '0x56447c02767ba621f103c0f3dbf564dbcacf284b', |
18 |
| - 'authAddr': '0x688ed736c2d388264fb08f81b466d2e46ec0bf35', |
19 |
| - 'authPrivateKey': '9508518b4b6d6ca20ef967ab5b26ff44865899888c23ec6cb19453a7dee589a6', |
20 |
| - 'orderType': 'p2p_order', |
21 |
| - 'r': '0x680bf9e74c9986bc31b1c1aece669199b695a79826034236e243e342d4dd35ac', |
22 |
| - 's': '0x34a8dc840e5f25bfb3bb6e39aa7ce61ea0fd4bad2c33945cae70693a120982be', |
23 |
| - 'v': 28, |
24 |
| - 'powNonce': 100 |
| 8 | + 'amountS': fm.toHex(fm.toBig('3700000000000000')), |
| 9 | + 'amountB': fm.toHex(fm.toBig('10000000000000000000')) |
25 | 10 | };
|
| 11 | + |
26 | 12 | const order2 = {
|
27 |
| - 'protocol': '0x8d8812b72d1e4ffCeC158D25f56748b7d67c1e78', |
28 |
| - 'delegateAddress': '0x17233e07c67d086464fD408148c3ABB56245FA64', |
29 |
| - 'address': '0xb94065482Ad64d4c2b9252358D746B39e820A582', |
30 |
| - 'hash': '0x390809f080bfd439f66f762efa15276fee9d7377c8f8e4001c7ffb443040866d', |
31 |
| - 'tokenS': '0xef68e7c694f40c8202821edf525de3782458639f', |
32 |
| - 'tokenB': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
33 |
| - 'amountS': '0x97e81a3e7c517c000', |
34 |
| - 'amountB': '0x9184e72a000', |
35 |
| - 'validSince': '0x5bd34823', |
36 |
| - 'validUntil': '0x5bfc26a3', |
37 |
| - 'lrcFee': '0x0', |
38 |
| - 'buyNoMoreThanAmountB': true, |
39 |
| - 'marginSplitPercentage': 0, |
40 |
| - 'v': '0x1c', |
41 |
| - 'r': '0x5db84ed535187149c8801436fc0e89759d2a0e960d0bb37eca79ae2a6722e353', |
42 |
| - 's': '0x38cb8578005fea7edd257e7a6a9ea5987ccd63a8c0e558a931828e4eb0624544', |
43 |
| - 'walletAddress': '0x56447C02767BA621f103C0f3DbF564dbcacF284b', |
44 |
| - 'authAddr': '0xbBE040a613154e8d58DA52B975Cd324A8430e788', |
45 |
| - 'authPrivateKey': '45447993b644a00d7d6aaa4351482d29c4c4a0909704169df0262681281ec443', |
46 |
| - 'owner': '0xb94065482Ad64d4c2b9252358D746B39e820A582' |
| 13 | + 'amountB': fm.toHex(fm.toBig('3700000000000000')), |
| 14 | + 'amountS': fm.toHex(fm.toBig('10000000000000000000')) |
47 | 15 | };
|
48 |
| -console.log(Contracts.LoopringProtocol.encodeSubmitRing([order1, order2], '0x5552dcfba48c94544beaaf26470df9898e050ac2')); |
| 16 | + |
| 17 | +const orders = [order1, order2]; |
| 18 | + |
| 19 | +const amounts = orders.map(order => fm.toBig(order.amountS).div(fm.toBig(order.amountB))); |
| 20 | +const tem = amounts.reduce((total, amount) => |
| 21 | +{ |
| 22 | + return total.times(amount); |
| 23 | +}); |
| 24 | +const rate = tem.pow(fm.toBig(1 / orders.length)); |
| 25 | + |
| 26 | +orders.forEach(order => console.log(fm.toNumber(fm.toHex(fm.toBig(fm.toFixed(fm.toBig(order.amountS).times(rate))))))); |
0 commit comments