Skip to content

Commit

Permalink
fix swap compatibility with bitcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 10, 2023
1 parent 5cc4224 commit d5de088
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
15 changes: 9 additions & 6 deletions omnichain/swap/contracts/Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ contract Swap is zContract {
bytes calldata message
) external virtual override onlySystem {
uint32 targetChainID;
bytes memory recipient;
address recipient;
uint256 minAmountOut;

if (context.chainID == BITCOIN) {
targetChainID = BytesHelperLib.bytesToUint32(message, 0);
recipient = BytesHelperLib.bytesToBech32Bytes(message, 4);
recipient = BytesHelperLib.bytesToAddress(message, 4);
} else {
(
uint32 targetChainID_,
bytes32 recipient_,
address recipient_,
uint256 minAmountOut_
) = abi.decode(message, (uint32, bytes32, uint256));
) = abi.decode(message, (uint32, address, uint256));
targetChainID = targetChainID_;
recipient = abi.encodePacked(recipient_);
recipient = recipient_;
minAmountOut = minAmountOut_;
}

Expand All @@ -69,6 +69,9 @@ contract Swap is zContract {
if (gasFee >= outputAmount) revert NotEnoughToPayGasFee();

IZRC20(targetZRC20).approve(targetZRC20, gasFee);
IZRC20(targetZRC20).withdraw(recipient, outputAmount - gasFee);
IZRC20(targetZRC20).withdraw(
abi.encodePacked(recipient),
outputAmount - gasFee
);
}
}
5 changes: 1 addition & 4 deletions omnichain/swap/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
}
};

task("deploy", "Deploy the contract", main).addFlag(
"json",
"Output in JSON"
);
task("deploy", "Deploy the contract", main).addFlag("json", "Output in JSON");
2 changes: 1 addition & 1 deletion omnichain/swap/tasks/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {

const data = prepareData(
args.contract,
["uint32", "bytes32", "uint256"],
["uint32", "address", "uint256"],
[targetChainID, args.recipient, minAmountOut]
);
const to = getAddress("tss", hre.network.name);
Expand Down

0 comments on commit d5de088

Please sign in to comment.