-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ChainXBridge by precompile contracts
- Loading branch information
Showing
7 changed files
with
381 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
library SystemWithdraw { | ||
address constant private precompile = address(0x403); | ||
uint256 constant MIN_BTC_TRANSFER_VALUE = 10_000_000_000; | ||
|
||
event WithdrawBTC(address from, uint256 amount, string to); | ||
event WithdrawPCX(address from, uint256 amount, bytes32 to); | ||
|
||
function withdrawBTC( | ||
uint256 value, | ||
string calldata btcAddr | ||
) public returns (bool) { | ||
(bool success, bytes memory returnData) = precompile.delegatecall(abi.encodePacked(false, value, btcAddr)); | ||
|
||
require(success, string(returnData)); | ||
|
||
emit WithdrawBTC(msg.sender, value / MIN_BTC_TRANSFER_VALUE, btcAddr); | ||
|
||
return success; | ||
} | ||
|
||
function withdrawPCX( | ||
uint256 value, | ||
bytes32 chainxPubkey | ||
) public returns (bool) { | ||
(bool success, bytes memory returnData) = precompile.delegatecall(abi.encodePacked(true, value, chainxPubkey)); | ||
|
||
require(success, string(returnData)); | ||
|
||
emit WithdrawPCX(msg.sender, value, chainxPubkey); | ||
|
||
return success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.