# OAppAuthSender

[Git Source](https://github.com/Ion-Protocol/nucleus-boring-vault/blob/cc0b494b83e17b9b169a73b96050d2810b690477/src/base/Roles/CrossChain/OAppAuth/OAppAuthSender.sol)

**Inherits:** OAppAuthCore

*Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.*

*This Auth version of OAppCore uses solmate's Auth instead of OZ's Ownable for compatibility purposes*

## State Variables

### SENDER\_VERSION

```solidity
uint64 internal constant SENDER_VERSION = 1;
```

## Functions

### oAppVersion

Retrieves the OApp version information.

*Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented. ie. this is a SEND only OApp.*

*If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions*

```solidity
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion);
```

**Returns**

| Name              | Type     | Description                                   |
| ----------------- | -------- | --------------------------------------------- |
| `senderVersion`   | `uint64` | The version of the OAppSender.sol contract.   |
| `receiverVersion` | `uint64` | The version of the OAppReceiver.sol contract. |

### \_quote

*Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.*

```solidity
function _quote(
    uint32 _dstEid,
    bytes memory _message,
    bytes memory _options,
    bool _payInLzToken
)
    internal
    view
    virtual
    returns (MessagingFee memory fee);
```

**Parameters**

| Name            | Type     | Description                                          |
| --------------- | -------- | ---------------------------------------------------- |
| `_dstEid`       | `uint32` | The destination endpoint ID.                         |
| `_message`      | `bytes`  | The message payload.                                 |
| `_options`      | `bytes`  | Additional options for the message.                  |
| `_payInLzToken` | `bool`   | Flag indicating whether to pay the fee in LZ tokens. |

**Returns**

| Name  | Type           | Description                                                                                                                               |
| ----- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `fee` | `MessagingFee` | The calculated MessagingFee for the message. - nativeFee: The native fee for the message. - lzTokenFee: The LZ token fee for the message. |

### \_lzSend

*Internal function to interact with the LayerZero EndpointV2.send() for sending a message.*

```solidity
function _lzSend(
    uint32 _dstEid,
    bytes memory _message,
    bytes memory _options,
    MessagingFee memory _fee,
    address _refundAddress
)
    internal
    virtual
    returns (MessagingReceipt memory receipt);
```

**Parameters**

| Name             | Type           | Description                                                                                               |
| ---------------- | -------------- | --------------------------------------------------------------------------------------------------------- |
| `_dstEid`        | `uint32`       | The destination endpoint ID.                                                                              |
| `_message`       | `bytes`        | The message payload.                                                                                      |
| `_options`       | `bytes`        | Additional options for the message.                                                                       |
| `_fee`           | `MessagingFee` | The calculated LayerZero fee for the message. - nativeFee: The native fee. - lzTokenFee: The lzToken fee. |
| `_refundAddress` | `address`      | The address to receive any excess fee values sent to the endpoint.                                        |

**Returns**

| Name      | Type               | Description                                                                                                                                                                      |
| --------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `receipt` | `MessagingReceipt` | The receipt for the sent message. - guid: The unique identifier for the sent message. - nonce: The nonce of the sent message. - fee: The LayerZero fee incurred for the message. |

### \_payNative

*Internal function to pay the native fee associated with the message.*

*If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction, this will need to be overridden because msg.value would contain multiple lzFees.*

*Should be overridden in the event the LayerZero endpoint requires a different native currency.*

*Some EVMs use an ERC20 as a method for paying transactions/gasFees.*

*The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.*

```solidity
function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee);
```

**Parameters**

| Name         | Type      | Description                |
| ------------ | --------- | -------------------------- |
| `_nativeFee` | `uint256` | The native fee to be paid. |

**Returns**

| Name        | Type      | Description                         |
| ----------- | --------- | ----------------------------------- |
| `nativeFee` | `uint256` | The amount of native currency paid. |

### \_payLzToken

*Internal function to pay the LZ token fee associated with the message.*

*If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.*

*Any excess sent, is passed back to the specified \_refundAddress in the \_lzSend().*

```solidity
function _payLzToken(uint256 _lzTokenFee) internal virtual;
```

**Parameters**

| Name          | Type      | Description                  |
| ------------- | --------- | ---------------------------- |
| `_lzTokenFee` | `uint256` | The LZ token fee to be paid. |

## Errors

### NotEnoughNative

```solidity
error NotEnoughNative(uint256 msgValue);
```

### LzTokenUnavailable

```solidity
error LzTokenUnavailable();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nucleusearn.io/nucleus-architecture/smart-contracts/contracts/base/roles/cross-chain/oappauth/oappauthsender.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
