-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the multioutput example to support Bitcoin #113
Conversation
One final change request is to remove So it would look something like this: function onCrossChainCall(
zContext calldata context,
address zrc20,
uint256 amount,
bytes calldata message
) external virtual override onlySystem {
address btcToken = systemContract.gasCoinZRC20ByChainId(BITCOIN);
if (btcToken == address(0)) revert FetchingBTCZRC20Failed();
(
address evmRecipient,
bytes memory btcRecipient,
address[] memory destinationTokens
) = parseMessage(context.chainID, message);
uint256 totalTransfers = destinationTokens.length;
if (totalTransfers == 0) revert NoAvailableTransfers();
uint256 amountToTransfer = amount / totalTransfers;
uint256 leftOver = amount - amountToTransfer * totalTransfers;
uint256 lastTransferIndex = destinationTokens[
destinationTokens.length - 1
] == zrc20
? destinationTokens.length - 2
: destinationTokens.length - 1;
for (uint256 i; i < destinationTokens.length; i++) {
address targetZRC20 = destinationTokens[i];
if (targetZRC20 == zrc20) continue;
if (lastTransferIndex == i) {
amountToTransfer += leftOver;
}
bytes memory recipient = abi.encodePacked(
BytesHelperLib.addressToBytes(evmRecipient)
);
if (targetZRC20 == btcToken) {
if (btcRecipient.length == 0) revert InvalidRecipient();
recipient = abi.encodePacked(btcRecipient);
}
(address gasZRC20, uint256 gasFee) = IZRC20(targetZRC20)
.withdrawGasFee();
uint256 outputAmount = SwapHelperLib._doSwap(
systemContract.wZetaContractAddress(),
systemContract.uniswapv2FactoryAddress(),
systemContract.uniswapv2Router02Address(),
zrc20,
amountToTransfer,
targetZRC20,
0
);
if (gasZRC20 != targetZRC20) revert WrongGasContract();
if (gasFee >= amount) revert NotEnoughToPayGasFee();
IZRC20(targetZRC20).approve(targetZRC20, gasFee);
IZRC20(targetZRC20).withdraw(
abi.encodePacked(recipient),
amount - gasFee
);
emit Withdrawal(targetZRC20, outputAmount, recipient);
}
} |
Great work, @lukema95! 🎉 |
Hi @fadeev , I've extracted the _doSwapAndWithdraw and _doWithdrawal functions because the above will cause a deep stack error at compile time, looks like below:
The error is the following function:
|
@andresaiello please, review. |
@lukema95 ok, cool. Can you please resolve the yarn conflict, and we should be good to go 👍 |
btw this PR doesn't add support for ERC-20s, so we might want to change the title. |
Change to “Update the multioutput example to support Bitcoin ?” |
Removed the |
Removed |
@lukema95 I'm having issues with the contract, can't get it to work.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npx hardhat interact --contract 0xa573Df1F0729FE6F1BD69b0a5dbFE393e6e09f47 --network mumbai_testnet --target-token 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891,0x65a45c57636f9BcCeD4fe193A602008578BcA90b --amount 50 --recipient 0x4955a3F38ff86ae92A914445099caa8eA2B9bA32 --btc-recipient tb1q8shzf7afc3rhw8n6w6ec32s8h6e2mrw077d0gg
npx hardhat cctx 0x642446f8b3d20d12f58cbbf2de33377e3c92d016f043deb81c5b854e7a440cd0
✓ CCTXs on ZetaChain found.
✓ 0x7b54665297fb6779da417ca431dd764b15f2237e3d7efbc0881e3801cced4fce: 80001 → 7001: OutboundMined (Remote omnicha
in contract call completed)
✓ 0xbd97de12a390e767491d5d6cbeed30a08b9c69adac7becee0be8cbb46ced93d2: 7001 → 97: OutboundMined
⠋ 0x468e11ea759a3683ec89467ee2c47dde3f8245c984c41886c7a3712e5956e349: 7001 → 18332: PendingOutbound
Relevant PR: #101