# Dripper

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

**Inherits:** IDripper, Ownable

**Author:** Sperax Foundation

This contract releases tokens at a steady rate to the Vault contract, for rebasing the USDs stablecoin.

*The Dripper contract ensures that tokens are released gradually over time, allowing for consistent and controlled distribution.*

## **State Variables**

### **vault**

```solidity
address public vault;

```

### **dripRate**

```solidity
uint256 public dripRate;

```

### **dripDuration**

```solidity
uint256 public dripDuration;

```

### **lastCollectTS**

```solidity
uint256 public lastCollectTS;

```

## **Functions**

### **constructor**

Constructor to initialize the Dripper.

```solidity
constructor(address _vault, uint256 _dripDuration);

```

**Parameters**

| Name           | Type    | Description                                               |
| -------------- | ------- | --------------------------------------------------------- |
| \_vault        | address | Address of the contract that receives the dripped tokens. |
| \_dripDuration | uint256 | The duration over which tokens are dripped.               |

### **recoverTokens**

Emergency fund recovery function.

*Transfers the asset to the owner of the contract.*

```solidity
function recoverTokens(address _asset) external onlyOwner;

```

**Parameters**

| Name    | Type    | Description                      |
| ------- | ------- | -------------------------------- |
| \_asset | address | Address of the asset to recover. |

### **addUSDs**

Function to be used to send USDs to dripper and update `dripRate`.

```solidity
function addUSDs(uint256 _amount) external;

```

**Parameters**

| Name     | Type    | Description                                             |
| -------- | ------- | ------------------------------------------------------- |
| \_amount | uint256 | Amount of USDs to be sent form caller to this contract. |

### **collect**

Transfers the dripped tokens to the vault.

*This function also updates the dripRate based on the fund state.*

```solidity
function collect() public returns (uint256);

```

**Returns**

| Name | Type    | Description                                                  |
| ---- | ------- | ------------------------------------------------------------ |
|      | uint256 | The amount of tokens collected and transferred to the vault. |

### **updateVault**

Update the vault address.

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

```

**Parameters**

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

### **updateDripDuration**

Updates the dripDuration.

```solidity
function updateDripDuration(uint256 _dripDuration) public onlyOwner;

```

**Parameters**

| Name           | Type    | Description                          |
| -------------- | ------- | ------------------------------------ |
| \_dripDuration | uint256 | The desired drip duration to be set. |

### **getCollectableAmt**

Gets the collectible amount of tokens at the current time.

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

```

**Returns**

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
|      | uint256 | The amount of tokens that can be collected. |

## **Events**

### **Collected**

```solidity
event Collected(uint256 amount);

```

### **Recovered**

```solidity
event Recovered(address owner, uint256 amount);

```

### **VaultUpdated**

```solidity
event VaultUpdated(address vault);

```

### **DripDurationUpdated**

```solidity
event DripDurationUpdated(uint256 dripDuration);

```

### **USDsAdded**

```solidity
event USDsAdded(uint256 _amount);

```

## **Errors**

### **NothingToRecover**

```solidity
error NothingToRecover();
```
