Skip to content

Commit

Permalink
inherit from hypnativecollateral
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Dec 13, 2024
1 parent 9fcc4d9 commit 41ff083
Showing 1 changed file with 23 additions and 90 deletions.
113 changes: 23 additions & 90 deletions solidity/contracts/token/HypNative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure

Code scanning / Olympix Integrated Security

Contracts that can receive ether but cannot send it may lock value permanently. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/locked-ether Critical

Contracts that can receive ether but cannot send it may lock value permanently. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/locked-ether
constructor(address _mailbox) HypNativeCollateral(_mailbox) {}

Check notice

Code scanning / Olympix Integrated Security

Test functions fail to thoroughly test all aspects of contract constructors, potentially missing critical initialization issues. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/incomplete-constructor-tests Low

Test functions fail to thoroughly test all aspects of contract constructors, potentially missing critical initialization issues. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/incomplete-constructor-tests

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor

// ============ 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

Check warning on line 40 in solidity/contracts/token/HypNative.sol

View check run for this annotation

Codecov / codecov/patch

solidity/contracts/token/HypNative.sol#L39-L40

Added lines #L39 - L40 were not covered by tests
}
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()
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 41ff083

Please sign in to comment.