# Router

## Contents

## Modifiers

### onlySystemCaller

No description

**Declaration:**

```solidity
  modifier onlySystemCaller
```

## Functions

### constructor

No description

**Declaration:**

```solidity
  function constructor(
  ) public Only
```

**Modifiers:**

| Modifier |
| -------- |
| Only     |

### estimateTotalFee

Estimate daily fee and free fee left.

**Declaration:**

```solidity
  function estimateTotalFee(
    address from,
    address to,
    uint256 timestamp
  ) external returns (uint256 fee, uint256 freeFee, uint256 contractFee)
```

**Modifiers:** No modifiers

**Args:**

| Arg         | Type    | Description                                            |
| ----------- | ------- | ------------------------------------------------------ |
| `from`      | address | Transaction sender                                     |
| `to`        | address | Transaction receiver(if contract creation, address(0)) |
| `timestamp` | uint256 | Timestamp                                              |

### assignTransactionReward

Assign transaction reward to miner, and emit the `UsageInfo` event, if the consumed fee is `dailyFee` or `dailyFreeFee`, it will only increase miner's share of the fee pool, otherwise, if the consumed fee is user's balance, it will add the fee to the fee pool and increase miner's share of the fee pool.

**Declaration:**

```solidity
  function assignTransactionReward(
    address validator,
    address from,
    address to,
    uint256 feeUsage,
    uint256 freeFeeUsage,
    uint256 contractFeeUsage
  ) external nonReentrant onlySystemCaller
```

**Modifiers:**

| Modifier         |
| ---------------- |
| nonReentrant     |
| onlySystemCaller |

**Args:**

| Arg                | Type    | Description                                            |
| ------------------ | ------- | ------------------------------------------------------ |
| `validator`        | address | Block miner                                            |
| `from`             | address | Transaction sender                                     |
| `to`               | address | Transaction receiver(if contract creation, address(0)) |
| `feeUsage`         | uint256 | `dailyFee` usage                                       |
| `freeFeeUsage`     | uint256 | `dailyFreeFee` usage                                   |
| `contractFeeUsage` | uint256 | Contract fee usage                                     |

### assignBlockReward

Assign block reward, and call `onAssignBlockReward` callback, it will split the block reward into two parts according to the `minerRewardFactor`, one part will be directly distributed to miners as a reward, and the other part will be added to the transaction fee pool.

**Declaration:**

```solidity
  function assignBlockReward(
    address validator
  ) external nonReentrant onlySystemCaller
```

**Modifiers:**

| Modifier         |
| ---------------- |
| nonReentrant     |
| onlySystemCaller |

**Args:**

| Arg         | Type    | Description |
| ----------- | ------- | ----------- |
| `validator` | address | Block miner |

### slash

Slash validator by reason

**Declaration:**

```solidity
  function slash(
    address validator,
    uint8 reason
  ) external nonReentrant onlySystemCaller
```

**Modifiers:**

| Modifier         |
| ---------------- |
| nonReentrant     |
| onlySystemCaller |

**Args:**

| Arg         | Type    | Description       |
| ----------- | ------- | ----------------- |
| `validator` | address | Validator address |
| `reason`    | uint8   | Slash reason      |

### onAfterBlock

After block callback, it only can be called by system caller

**Declaration:**

```solidity
  function onAfterBlock(
    address _proposer,
    address[] acValidators,
    int256[] priorities
  ) external nonReentrant onlySystemCaller
```

**Modifiers:**

| Modifier         |
| ---------------- |
| nonReentrant     |
| onlySystemCaller |

**Args:**

| Arg            | Type       | Description                            |
| -------------- | ---------- | -------------------------------------- |
| `_proposer`    | address    | Proposer address                       |
| `acValidators` | address\[] | Parameter of StakeManager.onAfterBlock |
| `priorities`   | int256\[]  | Parameter of StakeManager.onAfterBlock |

## Events

### UsageInfo

`UsageInfo` event contains the usage information of tx, it will be automatically appended to the end of the transaction log.

#### Params:

| Param              | Type    | Indexed | Description                        |
| ------------------ | ------- | :-----: | ---------------------------------- |
| `feeUsage`         | uint256 |         | `dailyFee` usage                   |
| `freeFeeUsage`     | uint256 |         | `dailyFreeFee` usage               |
| `contractFeeUsage` | uint256 |         | Contract fee usage                 |
| `balanceUsage`     | uint256 |         | Transaction sender's balance usage |
