> For the complete documentation index, see [llms.txt](https://docs.ariaprotocol.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ariaprotocol.xyz/technical-docs/contract-docs/iprwa/staking/iprwastaking.md).

# IPRWAStaking

**Inherits:** UUPSUpgradeable, AccessControlUpgradeable, Pausable

**Author:** Aria Protocol

Staking contract for IPRWA token

## State Variables

### STAKE\_LOCK\_SLOT

STATE VARIABLES ///

Slot for the stake lock

```solidity
bytes32 private constant STAKE_LOCK_SLOT = 0xe750219e856dc1045ee53321d6403a2f5fd45d5721d9656823eb6ce52a38051a;
```

### iprwaToken

Address of the IPRWA token

```solidity
IERC20 public iprwaToken;
```

### stakedIPRWAToken

Address of the staked IPRWA token.

```solidity
IStakedERC20 public stakedIPRWAToken;
```

### legal

Address of the legal contract that checks blacklist and license.

```solidity
address public legal;
```

### UD60x18\_SCALE\_PRECISION

Scale precision for the stIPRWA:IPRWA ratio - scaled by 10^27

```solidity
UD60x18 public UD60x18_SCALE_PRECISION;
```

### usersNetIPRWADeposited

Amount of IPRWA solely deposited by users into the contract (not accounting for deposited rewards)

```solidity
uint256 public usersNetIPRWADeposited;
```

## Functions

### stakelock

CONSTRUCTOR

Modifier to prevent staking/unstaking during the same transaction

```solidity
modifier stakelock();
```

### constructor

CONSTRUCTOR

to avoid parity hack

**Note:** oz-upgrades-unsafe-allow: constructor

```solidity
constructor();
```

### initialize

INITIALIZER

Initializer function needed to set values when called behind a proxy

```solidity
function initialize(address _iprwaToken, address _stakedIPRWAToken, address _legal, address _owner)
    external
    initializer;
```

**Parameters**

| Name                | Type      | Description                                                      |
| ------------------- | --------- | ---------------------------------------------------------------- |
| `_iprwaToken`       | `address` | Address of the IPRWA token                                       |
| `_stakedIPRWAToken` | `address` | Address of the Staked IPRWA token                                |
| `_legal`            | `address` | Address of the legal contract that checks blacklist and license. |
| `_owner`            | `address` | Address of the initial owner of the contract                     |

### stake

STAKING FUNCTIONS

Stake IPRWA tokens

*Assumes this contract has approval to move IPRWA tokens*

```solidity
function stake(uint256 _amount) external stakelock whenNotPaused;
```

**Parameters**

| Name      | Type      | Description                       |
| --------- | --------- | --------------------------------- |
| `_amount` | `uint256` | Number of IPRWA tokens to staking |

### unstake

Unstake stIPRWA token in exchange for IPRWA tokens

*Assumes this contract has approval to move stIPRWA tokens*

```solidity
function unstake(uint256 _amount) external stakelock whenNotPaused;
```

**Parameters**

| Name      | Type      | Description                                                              |
| --------- | --------- | ------------------------------------------------------------------------ |
| `_amount` | `uint256` | Number of stIPRWA tokens to unstake, a.k.a. net user deposit w/o rewards |

### stIPRWAperIPRWA

EXTERNAL FUNCTIONS ///

Returns the stIPRWA:IPRWA ratio - scaled by 10^27

```solidity
function stIPRWAperIPRWA() external view returns (uint256);
```

### iprwaPerStIPRWA

Returns the IPRWA:stIPRWA ratio - scaled by 10^27

```solidity
function iprwaPerStIPRWA() external view returns (uint256);
```

### \_stIPRWAPerIPRWA

INTERNAL FUNCTIONS

*stIPRWA:IPRWA ratio = (total stIPRWA supply - stIPRWA contract balance) / (IPRWA in contract)*

```solidity
function _stIPRWAPerIPRWA() internal view returns (UD60x18);
```

### \_iprwaPerStIPRWA

*IPRWA:stIPRWA = (IPRWA in contract) / (total stIPRWA supply - stIPRWA contract balance)*

```solidity
function _iprwaPerStIPRWA() internal view returns (UD60x18);
```

### \_getIPRWAValue

```solidity
function _getIPRWAValue(uint256 _stIPRWAAmount) internal view returns (uint256);
```

### \_getStiprwaValue

```solidity
function _getStiprwaValue(uint256 _iprwaAmount) internal view returns (uint256);
```

### withdraw

ADMIN FUNCTIONS

Withdraw tokens from the contract.

*A \_tokenAddress of address(0) denotes ETH*

*Only callable by the contract owner*

```solidity
function withdraw(address _tokenAddress, uint256 _amount) external onlyRole(DEFAULT_ADMIN_ROLE);
```

**Parameters**

| Name            | Type      | Description                             |
| --------------- | --------- | --------------------------------------- |
| `_tokenAddress` | `address` | Address of token to withdraw tokens for |
| `_amount`       | `uint256` | Number of tokens to withdraw            |

### setIPRWAToken

Sets the address for the IPRWA token

*Only callable by the contract owner*

```solidity
function setIPRWAToken(address _iprwaToken) external onlyRole(DEFAULT_ADMIN_ROLE);
```

**Parameters**

| Name          | Type      | Description                 |
| ------------- | --------- | --------------------------- |
| `_iprwaToken` | `address` | Address for the IPRWA token |

### setStakedIPRWAToken

Sets the address for the stIPRWA token

*Only callable by the contract owner*

```solidity
function setStakedIPRWAToken(address _stakedIPRWAToken) external onlyRole(DEFAULT_ADMIN_ROLE);
```

**Parameters**

| Name                | Type      | Description                   |
| ------------------- | --------- | ----------------------------- |
| `_stakedIPRWAToken` | `address` | Address for the stIPRWA token |

### setPauseState

```solidity
function setPauseState(bool paused_) external;
```

### \_authorizeUpgrade

```solidity
function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(DEFAULT_ADMIN_ROLE);
```

## Events

### IPRWAStaked

EVENTS

Event emitted when IPRWA tokens are staked

```solidity
event IPRWAStaked(address indexed _user, uint256 _iprwaIn, uint256 _stIPRWAOut);
```

### IPRWAUnstaked

Event emitted when IPRWA tokens are unstaked

```solidity
event IPRWAUnstaked(address indexed _user, uint256 _stIPRWAIn, uint256 _iprwaOut);
```

### FundsWithdrawn

Event emitted when funds are withdrawn

```solidity
event FundsWithdrawn(address indexed _tokenAddress, uint256 indexed _amount);
```

## Errors

### EmptyAmount

CUSTOM ERRORS

Error thrown when trying to stake/unstake 0 tokens.

```solidity
error EmptyAmount();
```

### Unauthorized

Error thrown when msg sender is unauthorized

```solidity
error Unauthorized();
```

### BalanceTooLow

Error thrown when user does not have enough balance

```solidity
error BalanceTooLow(uint256 _balance, uint256 _requiredAmount);
```

### IncorrectSignatureLength

Error thrown when Signature length is incorrect

```solidity
error IncorrectSignatureLength();
```
