From 41ff0833840d7f4634dad10d9853924b457e0e18 Mon Sep 17 00:00:00 2001 From: -f Date: Fri, 13 Dec 2024 16:40:12 +0530 Subject: [PATCH] inherit from hypnativecollateral --- solidity/contracts/token/HypNative.sol | 113 +++++-------------------- 1 file changed, 23 insertions(+), 90 deletions(-) diff --git a/solidity/contracts/token/HypNative.sol b/solidity/contracts/token/HypNative.sol index 1c72daf0c7..8a7ae06d72 100644 --- a/solidity/contracts/token/HypNative.sol +++ b/solidity/contracts/token/HypNative.sol @@ -15,51 +15,40 @@ pragma solidity >=0.8.0; // ============ Internal Imports ============ import {TokenRouter} from "./libs/TokenRouter.sol"; +import {HypNativeCollateral} from "./HypNativeCollateral.sol"; import {StandardHookMetadata} from "../hooks/libs/StandardHookMetadata.sol"; -// ============ External Imports ============ -import {Address} from "@openzeppelin/contracts/utils/Address.sol"; - /** * @title HypNative * @author Abacus Works * @notice This contract facilitates the transfer of value between chains using value transfer hooks */ -contract HypNative is TokenRouter { - /** - * @dev Emitted when native tokens are donated to the contract. - * @param sender The address of the sender. - * @param amount The amount of native tokens donated. - */ - event Donation(address indexed sender, uint256 amount); - // ============ Errors ============ - - error InsufficientValue(uint256 requiredValue, uint256 providedValue); - - constructor(address _mailbox) TokenRouter(_mailbox) {} +contract HypNative is HypNativeCollateral { + constructor(address _mailbox) HypNativeCollateral(_mailbox) {} - // ============ Initialization ============ + // ============ External Functions ============ - /** - * @notice Initializes the contract - * @param _valuehook The address of the value transfer hook - * @param _interchainSecurityModule The address of the interchain security module - * @param _owner The owner of the contract - */ - function initialize( - address _valuehook, - address _interchainSecurityModule, - address _owner - ) public initializer { - _MailboxClient_initialize( - _valuehook, - _interchainSecurityModule, - _owner - ); + /// @inheritdoc TokenRouter + function transferRemote( + uint32 _destination, + bytes32 _recipient, + uint256 _amount + ) external payable virtual override returns (bytes32 messageId) { + bytes calldata emptyBytes; + assembly { + emptyBytes.length := 0 + emptyBytes.offset := 0 + } + return + transferRemote( + _destination, + _recipient, + _amount, + emptyBytes, + address(hook) + ); } - // ============ External Functions ============ - /** * @inheritdoc TokenRouter * @dev use _hook with caution, make sure that this hook can handle msg.value transfer using the metadata.msgValue() @@ -92,60 +81,4 @@ contract HypNative is TokenRouter { _hook ); } - - /// @inheritdoc TokenRouter - function transferRemote( - uint32 _destination, - bytes32 _recipient, - uint256 _amount - ) external payable virtual override returns (bytes32 messageId) { - bytes calldata emptyBytes; - assembly { - emptyBytes.length := 0 - emptyBytes.offset := 0 - } - return - transferRemote( - _destination, - _recipient, - _amount, - emptyBytes, - address(hook) - ); - } - - // ============ Internal Functions ============ - - /** - * @inheritdoc TokenRouter - * @dev No token metadata is needed for value transfers - */ - function _transferFromSender( - uint256 - ) internal pure override returns (bytes memory) { - return bytes(""); // no token metadata - } - - /** - * @inheritdoc TokenRouter - * @dev Sends the value to the recipient - */ - function _transferTo( - address _recipient, - uint256 _amount, - bytes calldata // no token metadata - ) internal virtual override { - Address.sendValue(payable(_recipient), _amount); - } - - /// @inheritdoc TokenRouter - function balanceOf( - address _account - ) external view override returns (uint256) { - return _account.balance; - } - - receive() external payable { - emit Donation(msg.sender, msg.value); - } }