Skip to content

Commit

Permalink
Add basic deposit/withdraw events
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Jan 14, 2021
1 parent 9e443d2 commit cc39fd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 3 additions & 6 deletions contracts/contracts/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ interface Events {
event BlockVerification(uint32 indexed blockNumber);

/// @notice Event emitted when user funds are withdrawn from the zkSync contract
event OnchainWithdrawal(address indexed owner, uint16 indexed tokenId, uint128 amount, bool success);
event Withdrawal(uint16 indexed tokenId, uint128 amount);

/// @notice Event emitted when user funds are withdrawn from the rollup
event RollupWithdrawal(address indexed owner, uint16 indexed tokenId, uint128 amount);

/// @notice Event emitted when user send a transaction to deposit her funds
event OnchainDeposit(address indexed sender, uint16 indexed tokenId, uint128 amount, address indexed owner);
/// @notice Event emitted when user funds are deposited to the zkSync contract
event Deposit(uint16 indexed tokenId, uint128 amount);

/// @notice Event emitted when user sends a authentication fact (e.g. pub-key hash)
event FactAuth(address indexed sender, uint32 nonce, bytes fact);
Expand Down
6 changes: 5 additions & 1 deletion contracts/contracts/ZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
sent = false;
}
}
if (!sent) {
if (sent) {
emit Withdrawal(_tokenId, _amount);
} else {
increaseBalanceToWithdraw(packedBalanceKey, _amount);
}
}
Expand Down Expand Up @@ -594,6 +596,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
});
bytes memory pubData = Operations.writeDepositPubdataForPriorityQueue(op);
addPriorityRequest(Operations.OpType.Deposit, pubData);
emit Deposit(_tokenId, _amount);
}

/// @notice Register withdrawal - update user balance and emit OnchainWithdrawal event
Expand All @@ -608,6 +611,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
bytes22 packedBalanceKey = packAddressAndTokenId(_to, _token);
uint128 balance = pendingBalances[packedBalanceKey].balanceToWithdraw;
pendingBalances[packedBalanceKey].balanceToWithdraw = balance.sub(_amount);
emit Withdrawal(_token, _amount);
}

/// @dev Gets operations packed in bytes array. Unpacks it and stores onchain operations.
Expand Down

0 comments on commit cc39fd4

Please sign in to comment.