Skip to content

Commit

Permalink
nft/token: handle revert on zetachain
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 18, 2024
1 parent 75438c3 commit aa55fa3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions examples/nft/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ contract Universal is
address(this),
true,
address(0),
message,
abi.encode(tokenId, uri, msg.sender),
gasLimit
);

Expand Down Expand Up @@ -165,16 +165,22 @@ contract Universal is
destination,
abi.encode(receiver, tokenId, uri, out - gasFee, sender),
CallOptions(gasLimit, false),
RevertOptions(address(0), false, address(0), "", 0)
RevertOptions(
address(this),
true,
address(0),
abi.encode(tokenId, uri, sender),
0
)
);
}
emit TokenTransferToDestination(receiver, destination, tokenId, uri);
}

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

_safeMint(sender, tokenId);
Expand Down
14 changes: 10 additions & 4 deletions examples/token/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events {
address(this),
true,
address(0),
message,
abi.encode(amount, msg.sender),
gasLimit
);

Expand Down Expand Up @@ -129,16 +129,22 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events {
destination,
abi.encode(receiver, tokenAmount, out - gasFee, sender),
CallOptions(gasLimit, false),
RevertOptions(address(0), false, address(0), "", 0)
RevertOptions(
address(this),
true,
address(0),
abi.encode(amount, sender),
0
)
);
}
emit TokenTransferToDestination(destination, receiver, amount);
}

function onRevert(RevertContext calldata context) external onlyGateway {
(address sender, uint256 amount) = abi.decode(
(uint256 amount, address sender) = abi.decode(
context.revertMessage,
(address, uint256)
(uint256, address)
);
_mint(sender, amount);
emit TokenTransferReverted(sender, amount);
Expand Down

0 comments on commit aa55fa3

Please sign in to comment.