diff --git a/solidity/contracts/token/extensions/HypNativeScaled.sol b/solidity/contracts/token/extensions/HypNativeScaled.sol index ad129fce80..3edc64e830 100644 --- a/solidity/contracts/token/extensions/HypNativeScaled.sol +++ b/solidity/contracts/token/extensions/HypNativeScaled.sol @@ -17,62 +17,15 @@ contract HypNativeScaled is HypNative { scale = _scale; } - /** - * @inheritdoc HypNative - * @dev Sends scaled `msg.value` (divided by `scale`) to `_recipient`. - */ - function transferRemote( - uint32 _destination, - bytes32 _recipient, + function _outbound( uint256 _amount - ) external payable override returns (bytes32 messageId) { - require(msg.value >= _amount, "Native: amount exceeds msg.value"); - uint256 _hookPayment = msg.value - _amount; - uint256 _scaledAmount = _amount / scale; - return - _transferRemote( - _destination, - _recipient, - _scaledAmount, - _hookPayment - ); + ) internal view override returns (uint256) { + return _amount / scale; } - /** - * @inheritdoc TokenRouter - * @dev uses (`msg.value` - `_amount`) as hook payment. - */ - function transferRemote( - uint32 _destination, - bytes32 _recipient, - uint256 _amount, - bytes calldata _hookMetadata, - address _hook - ) external payable override returns (bytes32 messageId) { - require(msg.value >= _amount, "Native: amount exceeds msg.value"); - uint256 _hookPayment = msg.value - _amount; - uint256 _scaledAmount = _amount / scale; - return - _transferRemote( - _destination, - _recipient, - _scaledAmount, - _hookPayment, - _hookMetadata, - _hook - ); - } - - /** - * @dev Sends scaled `_amount` (multiplied by `scale`) to `_recipient`. - * @inheritdoc TokenRouter - */ - function _transferTo( - address _recipient, - uint256 _amount, - bytes calldata metadata // no metadata - ) internal override { - uint256 scaledAmount = _amount * scale; - HypNative._transferTo(_recipient, scaledAmount, metadata); + function _inbound( + uint256 _amount + ) internal view override returns (uint256) { + return _amount * scale; } } diff --git a/solidity/contracts/token/libs/TokenRouter.sol b/solidity/contracts/token/libs/TokenRouter.sol index 96ffcf8385..9663a9a8e3 100644 --- a/solidity/contracts/token/libs/TokenRouter.sol +++ b/solidity/contracts/token/libs/TokenRouter.sol @@ -116,9 +116,11 @@ abstract contract TokenRouter is GasRouter { address _hook ) internal virtual returns (bytes32 messageId) { bytes memory _tokenMetadata = _transferFromSender(_amountOrId); + + uint256 outboundAmount = _outbound(_amountOrId); bytes memory _tokenMessage = TokenMessage.format( _recipient, - _amountOrId, + outboundAmount, _tokenMetadata ); @@ -130,7 +132,19 @@ abstract contract TokenRouter is GasRouter { _hook ); - emit SentTransferRemote(_destination, _recipient, _amountOrId); + emit SentTransferRemote(_destination, _recipient, outboundAmount); + } + + function _outbound( + uint256 _amountOrId + ) internal view virtual returns (uint256) { + return _amountOrId; + } + + function _inbound( + uint256 _amountOrId + ) internal view virtual returns (uint256) { + return _amountOrId; } /** @@ -163,7 +177,7 @@ abstract contract TokenRouter is GasRouter { bytes32 recipient = _message.recipient(); uint256 amount = _message.amount(); bytes calldata metadata = _message.metadata(); - _transferTo(recipient.bytes32ToAddress(), amount, metadata); + _transferTo(recipient.bytes32ToAddress(), _inbound(amount), metadata); emit ReceivedTransferRemote(_origin, recipient, amount); } diff --git a/solidity/test/token/HypNativeScaled.t.sol b/solidity/test/token/HypNativeScaled.t.sol index ffded65655..47899ae89e 100644 --- a/solidity/test/token/HypNativeScaled.t.sol +++ b/solidity/test/token/HypNativeScaled.t.sol @@ -144,7 +144,7 @@ contract HypNativeScaledTest is Test { environment.processNextPendingMessage(); } - function test_tranferRemote(uint256 amount) public { + function test_transferRemote(uint256 amount) public { vm.assume(amount <= mintAmount); uint256 nativeValue = amount * (10 ** nativeDecimals);