Skip to content

Commit

Permalink
Add withdraw event bttcprotocol#7
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatoishealthy committed Mar 2, 2022
1 parent 674dd0d commit 2d6bf60
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
11 changes: 10 additions & 1 deletion contracts/root/TokenPredicates/ERC20Predicate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ contract ERC20Predicate is ITokenPredicate, AccessControlMixin, Initializable {
uint256 amount
);

event Withdraw(
address indexed withdrawer,
address indexed rootToken,
uint256 amount
);

constructor() public {}

function initialize(address _owner) external initializer {
Expand Down Expand Up @@ -85,9 +91,12 @@ contract ERC20Predicate is ITokenPredicate, AccessControlMixin, Initializable {
"ERC20Predicate: INVALID_RECEIVER"
);

uint256 amount = logRLPList[2].toUint();

IERC20(rootToken).safeTransfer(
withdrawer,
logRLPList[2].toUint() // log data field
amount // log data field
);
emit Withdraw(withdrawer, rootToken, amount);
}
}
16 changes: 15 additions & 1 deletion contracts/root/TokenPredicates/ERC721Predicate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ contract ERC721Predicate is ITokenPredicate, AccessControlMixin, Initializable,
address indexed rootToken,
uint256[] tokenIds
);
event Withdraw(
address indexed receiver,
address indexed rootToken,
uint256 tokenId
);
event WithdrawBatch(
address indexed receiver,
address indexed rootToken,
uint256[] tokenIds
);

constructor() public {}

Expand Down Expand Up @@ -122,11 +132,13 @@ contract ERC721Predicate is ITokenPredicate, AccessControlMixin, Initializable,
address(logTopicRLPList[2].toUint()) == address(0), // topic2 is to address
"ERC721Predicate: INVALID_RECEIVER"
);
uint256 tokenId = logRLPList[2].toUint();
IRootERC721(rootToken).safeTransferFrom(
address(this),
withdrawer,
logRLPList[2].toUint() // tokenId field
tokenId // tokenId field
);
emit Withdraw(withdrawer, rootToken, tokenId);

} else if (bytes32(logTopicRLPList[0].toUint()) == WITHDRAW_BATCH_EVENT_SIG) { // topic0 is event sig
bytes memory logData = logRLPList[2].toBytes();
Expand All @@ -135,6 +147,7 @@ contract ERC721Predicate is ITokenPredicate, AccessControlMixin, Initializable,
for (uint256 i; i < length; i++) {
IRootERC721(rootToken).safeTransferFrom(address(this), withdrawer, tokenIds[i]);
}
emit WithdrawBatch(withdrawer, rootToken, tokenIds);

} else if (bytes32(logTopicRLPList[0].toUint()) == TRANSFER_WITH_METADATA_EVENT_SIG) {
// If this is when NFT exit is done with arbitrary metadata on L2
Expand All @@ -148,6 +161,7 @@ contract ERC721Predicate is ITokenPredicate, AccessControlMixin, Initializable,
uint256 tokenId = logTopicRLPList[3].toUint(); // topic3 is tokenId field

token.safeTransferFrom(address(this), withdrawer, tokenId);
emit Withdraw(withdrawer, rootToken, tokenId);
// This function will be invoked for passing arbitrary
// metadata, obtained from event emitted in L2, to
// L1 ERC721, so that it can decode & do further processing
Expand Down
6 changes: 6 additions & 0 deletions contracts/root/TokenPredicates/MintableERC20Predicate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ contract MintableERC20Predicate is
address indexed rootToken,
uint256 amount
);
event Withdraw(
address indexed withdrawer,
address indexed rootToken,
uint256 amount
);

constructor() public {}

Expand Down Expand Up @@ -101,5 +106,6 @@ contract MintableERC20Predicate is
}

token.transfer(withdrawer, amount);
emit Withdraw(withdrawer, rootToken, amount);
}
}
13 changes: 13 additions & 0 deletions contracts/root/TokenPredicates/MintableERC721Predicate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial
address indexed rootToken,
uint256[] tokenIds
);
event Withdraw(
address indexed receiver,
address indexed rootToken,
uint256 tokenId
);
event WithdrawBatch(
address indexed receiver,
address indexed rootToken,
uint256[] tokenIds
);

constructor() public {}

Expand Down Expand Up @@ -164,6 +174,7 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial
} else {
token.mint(withdrawer, tokenId);
}
emit Withdraw(withdrawer, rootToken, tokenId);

} else if (bytes32(logTopicRLPList[0].toUint()) == WITHDRAW_BATCH_EVENT_SIG) { // topic0 is event sig
// If it's a simple batch exit, where a set of
Expand Down Expand Up @@ -204,6 +215,7 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial
}

}
emit WithdrawBatch(withdrawer, rootToken, tokenIds);

} else if (bytes32(logTopicRLPList[0].toUint()) == TRANSFER_WITH_METADATA_EVENT_SIG) {
// If this is NFT exit with metadata i.e. URI 👆
Expand Down Expand Up @@ -242,6 +254,7 @@ contract MintableERC721Predicate is ITokenPredicate, AccessControlMixin, Initial

token.mint(withdrawer, tokenId, metaData);
}
emit Withdraw(withdrawer, rootToken, tokenId);

} else {
// Attempting to exit with some event signature from L2, which is
Expand Down

0 comments on commit 2d6bf60

Please sign in to comment.