Skip to content
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

Refund unused tokens to the sender on ZetaChain #40

Open
fadeev opened this issue Dec 27, 2024 · 2 comments · May be fixed by #41
Open

Refund unused tokens to the sender on ZetaChain #40

fadeev opened this issue Dec 27, 2024 · 2 comments · May be fixed by #41
Labels
bug Something isn't working

Comments

@fadeev
Copy link
Member

fadeev commented Dec 27, 2024

When a transfer (EVM to EVM or ZetaChain to EVM) fails, the unused tokens must be returned to the sender on ZetaChain inside onRevert:

function onRevert(RevertContext calldata context) external onlyGateway {
(uint256 tokenId, string memory uri, address sender) = abi.decode(
context.revertMessage,
(uint256, string, address)
);
_safeMint(sender, tokenId);
_setTokenURI(tokenId, uri);
emit TokenTransferReverted(sender, tokenId, uri);
}

For ZetaChain to EVM transfers this is not that important, because the contract charges only the required amount and refunds unused tokens back before executing transferCrossChain.

But for EVM to EVM transfers this is important, because a sender may supply more tokens than required. In a successful transfer the tokens are refunded on the destination chain, but in case of revert the excess tokens (RevertContext.amount) are lost.

@fadeev fadeev added the bug Something isn't working label Dec 27, 2024
@fadeev fadeev changed the title Refund unused tokens to the sender Refund unused tokens to the sender on ZetaChain Dec 27, 2024
@fadeev
Copy link
Member Author

fadeev commented Dec 27, 2024

The question is, should the tokens be swapped to ZETA or refunded as ZRC-20? In case of a revert, the sender might want to transfer the token to a different chain, and for that they'd need ZETA.

@fadeev fadeev linked a pull request Jan 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@fadeev and others