# LosslessControllerV2

This contract is the gateway contract that connects LERC20 token contracts with all the lossless hack mitigation system.&#x20;

Contract can be found here:

{% embed url="<https://github.com/Lossless-Cash/lossless-v2/blob/master/contracts/LosslessControllerV2.sol>" %}

### Variables

* `pauseAdmin`
* `admin`
* `recoveryAdmin`
* `guardian`
* `tokenProtections`

#### pauseAdmin

This address has the access to pause and unpause controller contract.

#### admin

This address has access to configure lossless protocol. Can be changed by `recoveryAdmin`.

#### recoveryAdmin

This is a super admin's address. This wallet is able to change the regular admin and pause admin. This address is the most powerful admin in the whole lossless protocol and we are using a secure and time tested multi-sig ([Gnosis Safe](https://gnosis-safe.io/)) for it. This variable can be changed using `transferRecoveryAdminOwnership`  function.

#### guardian

The address of the [guardian](https://docs.lossless.io/protocol/technical-reference/vault-and-treasury-protection/losslessguardian) smart contract. Guardian contract has access to control protection strategies on controller contract.

#### tokenProtections

This mapping saves info about every address that is protected. It has a flag that shows if the address is protected or not and also has strategy address so that if the address is protected the controller knows which of the protections strategies should be applied.

### Events

* `AdminChanged(address indexed previousAdmin, address indexed newAdmin)`
* `RecoveryAdminChanged(address indexed previousAdmin, address indexed newAdmin)`
* `PauseAdminChanged(address indexed previousAdmin, address indexed newAdmin)`
* `GuardianSet(address indexed oldGuardian, address indexed newGuardian)`
* `ProtectedAddressSet(address indexed token, address indexed protectedAddress, address indexed strategy)`
* `RemovedProtectedAddress(address indexed token, address indexed protectedAddress)`

### Modifiers

* `onlyLosslessRecoveryAdmin`
* `onlyLosslessAdmin`
* `onlyPauseAdmin`
* `onlyGuardian`

#### onlyLosslessRecoveryAdmin

Checks if msg.sender is `recoveryAdmin`.

#### onlyLosslessAdmin

Checks if `msg.sender` is `admin`.

#### onlyPauseAdmin

Checks if `msg.sender` is `pauseAdmin`.

#### onlyGuardian

Checks if `msg.sender` is `guardian` smart contract.

### Functions

* `getVersion`
* `isAddressProtected`
* `getProtectedAddressStrategy`
* `pause`
* `unpause`
* `setAdmin`
* `setRecoveryAdmin`
* `setPauseAdmin`
* `setGuardian`
* `setProtectedAddress`
* `removeProtectedAddress`
* `beforeTransfer`
* `beforeTransferFrom`
* `beforeApprove`
* `beforeIncreaseAllowance`
* `beforeDecreaseAllowance`
* `afterApprove`
* `afterTransfer`
* `afterTransferFrom`
* `afterIncreaseAllowance`
* `afterDecreaseAllowance`

#### getVersion

```solidity
function getVersion() external pure returns (uint256)
```

Returns current version of the controller.

#### isAddressProtected

```solidity
function isAddressProtected(address token, address protectedAddress) external view returns (bool)
```

Returns either true or false depending if the address has any protections set up on it.

Parameters:

#### getProtectedAddressStrategy

```solidity
function getProtectedAddressStrategy(address token, address protectedAddress) external view returns (address)
```

Returns address of the strategy that the protected address is using. If address is not protected returns zero address.

Parameters:

| Name               | Type    | Description                                   |
| ------------------ | ------- | --------------------------------------------- |
| `token`            | address | Token for which the protection is set.        |
| `protectedAddress` | address | Address to check the protection strategy for. |

#### pause

```solidity
function pause() external onlyPauseAdmin
```

Sets the pause flag to true which in turn pauses some of the contracts functionality. Can be called only by the `pauseAdmin`.

#### unpause

```solidity
function unpause() external onlyPauseAdmin
```

Sets the pause flag to false which in turn unpauses some of the contracts functionality. Can be called only by the `pauseAdmin`.

#### setAdmin

```solidity
function setAdmin(address newAdmin) external onlyLosslessRecoveryAdmin
```

Sets `admin` address. Can be called only by `recoveryAdmin`.

Parameters:

| Name       | Type    | Description        |
| ---------- | ------- | ------------------ |
| `newAdmin` | address | New admin address. |

#### setRecoveryAdmin

```solidity
function setRecoveryAdmin(address newRecoveryAdmin) external onlyLosslessRecoveryAdmin
```

Sets `recoveryAdmin` address. Can be called only by `recoveryAdmin`.

Parameters:

| Name               | Type    | Description                 |
| ------------------ | ------- | --------------------------- |
| `newRecoveryAdmin` | address | New recovery admin address. |

#### setPauseAdmin

```solidity
function setPauseAdmin(address newPauseAdmin) external onlyLosslessRecoveryAdmin
```

Sets `pauseAdmin` address. Can be called only by `recoveryAdmin`.

Parameters:

| Name            | Type    | Description              |
| --------------- | ------- | ------------------------ |
| `newPauseAdmin` | address | New pause admin address. |

#### setGuardian

```solidity
function setGuardian(address newGuardian) external onlyLosslessAdmin whenNotPaused
```

Sets `guardian` contract's address. Can be called only by `admin` when contract is not paused.

Parameters:

| Name          | Type    | Description                      |
| ------------- | ------- | -------------------------------- |
| `newGuardian` | address | New guardian contract's address. |

#### setProtectedAddress

```solidity
function setProtectedAddress(address token, address protectedAddresss, ProtectionStrategy strategy) external onlyGuardian whenNotPaused
```

Sets token scoped protection on an address. Can be called only by the `guardian` when contract is not paused.

Parameters:

| Name               | Type               | Description                                                       |
| ------------------ | ------------------ | ----------------------------------------------------------------- |
| `token`            | address            | Token for which the protection rules should be applied.           |
| `protectedAddress` | address            | Address to protect.                                               |
| `strategy`         | ProtectionStrategy | Strategy address that should be used when protecting the address. |

#### removeProtectedAddress

```solidity
function removeProtectedAddress(address token, address protectedAddresss) external onlyGuardian whenNotPaused
```

Removes token scoped protection. Can be called only by `guardian` contract when contract is not paused.

Parameters:

| Name               | Type    | Description                                             |
| ------------------ | ------- | ------------------------------------------------------- |
| `token`            | address | Token for which the protection rules should be removed. |
| `protectedAddress` | address | Address to remove the protection from.                  |

#### beforeTransfer

```solidity
function beforeTransfer(address sender, address recipient, uint256 amount) external 
```

Hook function that is called before every [LERC20](https://docs.lossless.io/protocol/technical-reference/lerc20) token `transfer` function. Also does a call to protection strategy in case sender's address is protected.

Parameters:

| Name        | Type    | Description                         |
| ----------- | ------- | ----------------------------------- |
| `sender`    | address | Sender's address.                   |
| `recipient` | address | Recipient's address.                |
| `amount`    | uint256 | Amount of tokens being transferred. |

#### beforeTransferFrom

```solidity
function beforeTransferFrom(address msgSender, address sender, address recipient, uint256 amount) external
```

Hook function that is called before every [LERC20](https://docs.lossless.io/protocol/technical-reference/lerc20) token `transferFrom` function. Also does a call to protection strategy in case sender's address is protected.

Parameters:

| Name        | Type    | Description                                            |
| ----------- | ------- | ------------------------------------------------------ |
| `msgSender` | address | Address that triggered transfer from sender's address. |
| `sender`    | address | Sender's address.                                      |
| `recipient` | address | Recipient's address.                                   |
| `amount`    | uint256 | Amount of tokens being transferred.                    |

#### beforeApprove

```solidity
function beforeApprove(address sender, address spender, uint256 amount) external
```

Hook function that is called before every [LERC20](https://docs.lossless.io/protocol/technical-reference/lerc20) token `approve` function. Does not implement any logic yet.&#x20;

Parameters:

| Name        | Type    | Description                      |
| ----------- | ------- | -------------------------------- |
| `sender`    | address | Sender's address.                |
| `recipient` | address | Recipient's address.             |
| `amount`    | uint256 | Amount of tokens being approved. |

#### beforeIncreaseAllowance

```solidity
function beforeIncreaseAllowance(address msgSender, address spender, uint256 addedValue) external
```

Hook function that is called before every [LERC20](https://docs.lossless.io/protocol/technical-reference/lerc20) token `increaseAllowance` function. Does not implement any logic yet.&#x20;

Parameters:

| Name         | Type    | Description                                                                 |
| ------------ | ------- | --------------------------------------------------------------------------- |
| `msgSender`  | address | Address that triggered `increaseAllowance` function from spender's address. |
| `spender`    | address | Spender's address.                                                          |
| `addedValue` | uint256 | How many tokens to add to the already approved amount.                      |

#### beforeDecreaseAllowance

```solidity
function beforeDecreaseAllowance(address msgSender, address spender, uint256 subtractedValue) external
```

Hook function that is called before every [LERC20](https://docs.lossless.io/protocol/technical-reference/lerc20) token `decreaseAllowance` function. Does not implement any logic yet.

Parameters:

| Name            | Type    | Description                                                                 |
| --------------- | ------- | --------------------------------------------------------------------------- |
| `msgSender`     | address | Address that triggered `decreaseAllowance` function from spender's address. |
| `spender`       | address | Spender's address.                                                          |
| `subtractValue` | uint256 | How many tokens to subtract from the already approved amount.               |

#### after hooks

* `afterApprove`
* `afterTransfer`
* `afterTransferFrom`
* `afterIncreaseAllowance`
* `afterDecreaseAllowance`

These functions are deprecated and do not contain any logic. These functions are kept in the controller because tokens that use older version of LERC20 do calls to these functions. They must be kept on the controller in order not to brick those tokens.
