Skip to content

Commit

Permalink
bitcoin chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Dec 6, 2024
1 parent bf4d40d commit 09213be
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions examples/swap/contracts/Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ contract Swap is
{
address public uniswapRouter;
GatewayZEVM public gateway;
uint256 constant BITCOIN = 18332;
uint256 constant BITCOIN = 8332;
uint256 constant BITCOIN_TESTNET = 18332;
uint256 public gasLimit;

error InvalidAddress();
error Unauthorized();
error ApprovalFailed();
error TransferFailed();

event TokenSwap(
address sender,
bytes indexed recipient,
address indexed inputToken,
address indexed targetToken,
uint256 inputAmount,
uint256 outputAmount
);

modifier onlyGateway() {
if (msg.sender != address(gateway)) revert Unauthorized();
_;
Expand Down Expand Up @@ -75,7 +85,7 @@ contract Swap is
withdraw: true
});

if (context.chainID == BITCOIN) {
if (context.chainID == BITCOIN_TESTNET || context.chainID == BITCOIN) {
params.target = BytesHelperLib.bytesToAddress(message, 0);
params.to = abi.encodePacked(
BytesHelperLib.bytesToAddress(message, 20)
Expand All @@ -99,6 +109,14 @@ contract Swap is
amount,
params.target
);
emit TokenSwap(
context.sender,
params.to,
zrc20,
params.target,
amount,
out
);
withdraw(params, context.sender, gasFee, gasZRC20, out, zrc20);
}

Expand All @@ -123,7 +141,14 @@ contract Swap is
amount,
targetToken
);

emit TokenSwap(
msg.sender,
recipient,
inputToken,
targetToken,
amount,
out
);
withdraw(
Params({
target: targetToken,
Expand Down

0 comments on commit 09213be

Please sign in to comment.