Skip to content
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

add zk-dex-service #42

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
af4d46d
vapp: sort local storage by resource
4000D Aug 26, 2019
62ee35d
contracts/ZkDex: add timestamp
4000D Aug 30, 2019
64a69a4
scripts/lib: update utils
4000D Aug 30, 2019
8494b61
vapp: update and install npm packages
4000D Aug 30, 2019
a5cd30b
vapp: refactor localStorage and express routes
4000D Aug 30, 2019
ebd7e69
vapp: add vapp api server test
4000D Aug 30, 2019
cf397bb
vapp: add zkdex-service to handle ZkDex events
4000D Aug 30, 2019
7025b12
vapp/src: rename getOrdersByAccount to getOrdersByUser
4000D Aug 30, 2019
c7ee2bf
update truffle-contract
4000D Aug 30, 2019
17ded6b
Merge remote-tracking branch 'origin/master' into zk-dex-service-server
4000D Sep 3, 2019
ee0ecd7
temp
4000D Sep 17, 2019
0391a30
vapp: init zkdex service
shingonu Aug 30, 2019
ea5c448
npm: update package-lock
shingonu Aug 30, 2019
c8f1743
vapp: modify account api
shingonu Aug 30, 2019
10037bb
vapp: renew vapp
shingonu Nov 11, 2019
8c5f873
fix misusing event remover
shingonu Dec 6, 2019
b4a01c8
vapp: give padding
shingonu Dec 10, 2019
ad8a947
vapp: make footer be fixed below
shingonu Dec 10, 2019
32de9f4
vapp: modify some codes to make settleOrder work
shingonu Dec 10, 2019
635b637
vapp: make transferNote work
shingonu Dec 11, 2019
00760d6
vapp: add checking tx status
shingonu Dec 11, 2019
4173a61
vapp: make liquidateNote work
shingonu Dec 11, 2019
272cf28
vapp: hide menus which is not yet worked
shingonu Dec 11, 2019
1ad6a2c
vapp: use font-awesome
shingonu Jan 29, 2020
0a41dd6
vapp: make standard button component and use it
shingonu Jan 29, 2020
895c2cd
vapp: lint
shingonu Jan 29, 2020
6e95ef1
vapp: fix some codes
shingonu Jan 29, 2020
c51b206
vapp: add filter functions
shingonu Jan 29, 2020
df89067
vapp: filter table datas
shingonu Jan 29, 2020
70eb068
vapp: use router of previous version
shingonu Jan 30, 2020
8e35cfb
vapp: npm install --save zk-dex-keystore
shingonu Jan 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions contracts/ZkDex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ contract ZkDex is ZkDai {
bytes32 takerNoteToMaker;
bytes32 parentNote;

uint64 createdAt;
uint64 takendAt;
uint64 settledAt;

OrderState state;
}

Order[] public orders;

event OrderCreated(uint256 orderId, uint256 sourceToken, uint256 targetToken);
event OrderTaken(uint256 orderId, bytes32 takerNoteToMaker, bytes32 parentNote);
event OrderSettled(uint256 orderId, bytes32 rewardNote, bytes32 paymentNote, bytes32 changeNote);
event OrderCreated(uint256 orderId, uint256 sourceToken, uint256 targetToken, uint256 createdAt);
event OrderTaken(uint256 orderId, bytes32 takerNoteToMaker, bytes32 parentNote, uint256 takenAt);
event OrderSettled(uint256 orderId, bytes32 rewardNote, bytes32 paymentNote, bytes32 changeNote, uint256 settledAt);

constructor(
bool _development,
Expand Down Expand Up @@ -131,13 +135,14 @@ contract ZkDex is ZkDai {
order.targetToken = targetToken;
order.price = price;
order.state = OrderState.Created;
order.createdAt = uint64(block.timestamp);

notes[makerNote] = State.Traiding;

emit NoteStateChange(makerNote, State.Traiding);

// NOTE: cannot compile below line due to stack too deep error..
// emit OrderCreated(orderId, input[2], targetToken);
// emit OrderCreated(orderId, input[2], targetToken, block.timestamp);
}


Expand Down Expand Up @@ -190,10 +195,11 @@ contract ZkDex is ZkDai {
order.parentNote = parentNote;
order.takerNoteToMaker = takerNoteToMaker;
order.state = OrderState.Taken;
order.takendAt = uint64(block.timestamp);

emit NoteStateChange(parentNote, State.Traiding);
emit NoteStateChange(takerNoteToMaker, State.Traiding);
emit OrderTaken(orderId, takerNoteToMaker, parentNote);
emit OrderTaken(orderId, takerNoteToMaker, parentNote, block.timestamp);
}

/**
Expand Down Expand Up @@ -271,6 +277,7 @@ contract ZkDex is ZkDai {
encryptedNotes[calcHash(input[16], input[17])] = encList[2].toBytes();

order.state = OrderState.Settled;
order.settledAt = uint64(block.timestamp);

emit NoteStateChange(calcHash(input[6], input[7]), State.Valid);
emit NoteStateChange(calcHash(input[11], input[12]), State.Valid);
Expand All @@ -280,7 +287,7 @@ contract ZkDex is ZkDai {
emit NoteStateChange(order.parentNote, State.Spent);
emit NoteStateChange(order.takerNoteToMaker, State.Spent);

emit OrderSettled(orderId, calcHash(input[6], input[7]), calcHash(input[11], input[12]), calcHash(input[16], input[17]));
emit OrderSettled(orderId, calcHash(input[6], input[7]), calcHash(input[11], input[12]), calcHash(input[16], input[17]), block.timestamp);
}

function hashOrder(Order memory order) internal view returns (bytes32) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/MockDai.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'openzeppelin-solidity/contracts/token/ERC20/ERC20.sol';

contract MockDai is ERC20 {
constructor() public {
_mint(msg.sender, 100 * 10**18);
_mint(msg.sender, 1000000 * 10**18);
}

function mint() public {
_mint(msg.sender, 100 * 10**18);
_mint(msg.sender, 1000000 * 10**18);
}
}
Loading