Skip to content

Commit ba873f0

Browse files
james-toussaintarr00
authored andcommitted
Move excess transfer to the end when wrapper receives callback (#125)
1 parent 2100c93 commit ba873f0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

contracts/token/extensions/ConfidentialFungibleTokenERC20Wrapper.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ abstract contract ConfidentialFungibleTokenERC20Wrapper is ConfidentialFungibleT
7070
// check caller is the token contract
7171
require(address(underlying()) == msg.sender, ConfidentialFungibleTokenUnauthorizedCaller(msg.sender));
7272

73-
// transfer excess back to the sender
74-
uint256 excess = amount % rate();
75-
if (excess > 0) SafeERC20.safeTransfer(underlying(), from, excess);
76-
7773
// mint confidential token
7874
address to = data.length < 20 ? from : address(bytes20(data));
7975
_mint(to, FHE.asEuint64(SafeCast.toUint64(amount / rate())));
8076

77+
// transfer excess back to the sender
78+
uint256 excess = amount % rate();
79+
if (excess > 0) SafeERC20.safeTransfer(underlying(), from, excess);
80+
8181
// return magic value
8282
return IERC1363Receiver.onTransferReceived.selector;
8383
}

0 commit comments

Comments
 (0)