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

fix: refund unused tokens on revert #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contracts/nft/contracts/zetachain/UniversalNFTCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ abstract contract UniversalNFTCore is
_safeMint(sender, tokenId);
_setTokenURI(tokenId, uri);
emit TokenTransferReverted(sender, tokenId, uri);

if (context.amount > 0 && context.asset != address(0)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we maybe add some comment explaining that this is optional? because usually if some address is address(0) i guess first thought is that it is wrong argument

also, do we have tests for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't have tests yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skosito what do you mean about this being optional? We're just checking that both amount and asset is not a zero and transferring the assets.

if (!IZRC20(context.asset).transfer(sender, context.amount)) {
revert TransferFailed();
}
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions contracts/token/contracts/zetachain/UniversalTokenCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,11 @@ abstract contract UniversalTokenCore is
);
_mint(sender, amount);
emit TokenTransferReverted(sender, amount);

if (context.amount > 0 && context.asset != address(0)) {
if (!IZRC20(context.asset).transfer(sender, context.amount)) {
revert TransferFailed();
}
}
}
}