# RebaseManager

[Git Source](https://github.com/Sperax/USDs-v2/blob/ff71faf9d7e40d2b2764e5e8f2acc631f31489aa/contracts/rebase/RebaseManager.sol)

**Inherits:** IRebaseManager, Ownable

**Author:** Sperax Foundation

This contract handles the configuration and execution of the rebasing mechanism for the USDs stablecoin. It ensures that rebases occur only when certain prerequisites are fulfilled, such as the time gap between rebases and acceptable APR (Annual Percentage Rate) ranges.

*The Rebase Manager coordinates with the Vault and Dripper contracts to manage the rebase process.*

## **State Variables**

### **ONE\_YEAR**

```solidity
uint256 private constant ONE_YEAR = 365 days;

```

### **vault**

```solidity
address public vault;

```

### **dripper**

```solidity
address public dripper;

```

### **gap**

```solidity
uint256 public gap;

```

### **aprCap**

```solidity
uint256 public aprCap;

```

### **aprBottom**

```solidity
uint256 public aprBottom;

```

### **lastRebaseTS**

```solidity
uint256 public lastRebaseTS;

```

## **Functions**

### **onlyVault**

```solidity
modifier onlyVault();

```

### **constructor**

Constructor to initialize the Rebase Manager

```solidity
constructor(address _vault, address _dripper, uint256 _gap, uint256 _aprCap, uint256 _aprBottom);

```

**Parameters**

| Name        | Type    | Description                                               |
| ----------- | ------- | --------------------------------------------------------- |
| \_vault     | address | Address of the vault contract                             |
| \_dripper   | address | Address of the dripper contract for collecting USDs       |
| \_gap       | uint256 | Minimum time gap required between two consecutive rebases |
| \_aprCap    | uint256 | Maximum allowed APR for a rebase                          |
| \_aprBottom | uint256 | Minimum allowed APR for a rebase                          |

### **fetchRebaseAmt**

Get the current amount valid for rebase

*Function is called by the vault while rebasing*

```solidity
function fetchRebaseAmt() external onlyVault returns (uint256);

```

**Returns**

| Name | Type    | Description                            |
| ---- | ------- | -------------------------------------- |
|      | uint256 | The available amount for rebasing USDs |

### **updateVault**

Updates the vault address

```solidity
function updateVault(address _newVault) public onlyOwner;

```

**Parameters**

| Name       | Type    | Description                       |
| ---------- | ------- | --------------------------------- |
| \_newVault | address | Address of the new vault contract |

### **updateDripper**

Updates the dripper contract for USDs vault

```solidity
function updateDripper(address _dripper) public onlyOwner;

```

**Parameters**

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| \_dripper | address | Address of the new dripper contract |

### **updateGap**

Update the minimum time gap required between two rebases

```solidity
function updateGap(uint256 _gap) public onlyOwner;

```

**Parameters**

| Name  | Type    | Description      |
| ----- | ------- | ---------------- |
| \_gap | uint256 | Updated gap time |

### **updateAPR**

Update the APR requirements for each rebase

```solidity
function updateAPR(uint256 _aprBottom, uint256 _aprCap) public onlyOwner;

```

**Parameters**

| Name        | Type    | Description                  |
| ----------- | ------- | ---------------------------- |
| \_aprBottom | uint256 | New minimum APR for a rebase |
| \_aprCap    | uint256 | New maximum APR for a rebase |

### **getAvailableRebaseAmt**

Gets the current available rebase fund

```solidity
function getAvailableRebaseAmt() public view returns (uint256);

```

**Returns**

| Name | Type    | Description                                                       |
| ---- | ------- | ----------------------------------------------------------------- |
|      | uint256 | Current balance in the vault plus collectable dripped USDs amount |

### **getMinAndMaxRebaseAmt**

Gets the minimum and maximum rebase USDs amount based on the APR config

```solidity
function getMinAndMaxRebaseAmt() public view returns (uint256, uint256);

```

**Returns**

| Name | Type    | Description                        |
| ---- | ------- | ---------------------------------- |
|      | uint256 | Minimum and maximum rebase amounts |
|      | uint256 |                                    |

## **Events**

### **VaultUpdated**

```solidity
event VaultUpdated(address vault);

```

### **DripperUpdated**

```solidity
event DripperUpdated(address dripper);

```

### **GapUpdated**

```solidity
event GapUpdated(uint256 gap);

```

### **APRUpdated**

```solidity
event APRUpdated(uint256 aprBottom, uint256 aprCap);

```

## **Errors**

### **CallerNotVault**

```solidity
error CallerNotVault(address caller);

```

### **InvalidAPRConfig**

```solidity
error InvalidAPRConfig(uint256 aprBottom, uint256 aprCap);
```
