# LootVoteController

Contract handling the vote logic for repartition of the global Loot budget between all the listed gauges for the Quest system. User voting power is based on their hPAL locks, transformed into a bias via the HolyPalPower contract. Votes are sticky, meaning users do not need to cast them every period, but can set their vote and update it periods later. Before an user can change its votes, a vote cooldown need to be respected.

#### QuestBoard

Quest Board & distributor struct

```solidity
struct QuestBoard {
  address board;
  address distributor;
}
```

#### Point

Point struct

```solidity
struct Point {
  uint256 bias;
  uint256 slope;
}
```

#### VotedSlope

Voted Slope struct

```solidity
struct VotedSlope {
  uint256 slope;
  uint256 power;
  uint256 end;
  address caller;
}
```

#### VoteVars

Struct used for the vote method

```solidity
struct VoteVars {
  uint256 currentPeriod;
  uint256 nextPeriod;
  int128 userSlope;
  uint256 userLockEnd;
  uint256 oldBias;
  uint256 newBias;
  uint256 totalPowerUsed;
  uint256 oldUsedPower;
  uint256 oldWeightBias;
  uint256 oldWeightSlope;
  uint256 oldTotalBias;
  uint256 oldTotalSlope;
}
```

#### ProxyVoter

Proxy Voter struct

```solidity
struct ProxyVoter {
  uint256 maxPower;
  uint256 usedPower;
  uint256 endTimestamp;
}
```

#### hPalPower

```solidity
address hPalPower
```

Address of the hPalPower contract

#### nextBoardId

```solidity
uint256 nextBoardId
```

Next ID to list Boards

#### questBoards

```solidity
mapping(uint256 => struct LootVoteController.QuestBoard) questBoards
```

Listed Quest Boards

#### boardToId

```solidity
mapping(address => uint256) boardToId
```

Match Board address to ID

#### distributorToId

```solidity
mapping(address => uint256) distributorToId
```

Match Distributor address to ID

#### gaugeToBoardId

```solidity
mapping(address => uint256) gaugeToBoardId
```

Match a Gauge to a Board ID

#### defaultCap

```solidity
uint256 defaultCap
```

Default weight cap for gauges

#### gaugeCaps

```solidity
mapping(address => uint256) gaugeCaps
```

Custom caps for gauges

#### isGaugeKilled

```solidity
mapping(address => bool) isGaugeKilled
```

Flag for killed gauges

#### voteUserSlopes

```solidity
mapping(address => mapping(address => struct LootVoteController.VotedSlope)) voteUserSlopes
```

User VotedSlopes for each gauge

#### voteUserPower

```solidity
mapping(address => uint256) voteUserPower
```

Total vote power used by user

#### lastUserVote

```solidity
mapping(address => mapping(address => uint256)) lastUserVote
```

Last user vote's timestamp for each gauge address

#### pointsWeight

```solidity
mapping(address => mapping(uint256 => struct LootVoteController.Point)) pointsWeight
```

Point weight for each gauge

#### changesWeight

```solidity
mapping(address => mapping(uint256 => uint256)) changesWeight
```

Slope changes for each gauge

#### timeWeight

```solidity
mapping(address => uint256) timeWeight
```

Last scheduled time for gauge weight update

#### pointsWeightTotal

```solidity
mapping(uint256 => struct LootVoteController.Point) pointsWeightTotal
```

Total Point weights

#### changesWeightTotal

```solidity
mapping(uint256 => uint256) changesWeightTotal
```

Total weight slope changes

#### timeTotal

```solidity
uint256 timeTotal
```

Last scheduled time for weight update

#### isProxyManager

```solidity
mapping(address => mapping(address => bool)) isProxyManager
```

Proxy Managers set for each user

#### maxProxyDuration

```solidity
mapping(address => mapping(address => uint256)) maxProxyDuration
```

Max Proxy duration allowed for Manager

#### proxyVoterState

```solidity
mapping(address => mapping(address => struct LootVoteController.ProxyVoter)) proxyVoterState
```

State of Proxy Managers for each user

#### currentUserProxyVoters

```solidity
mapping(address => address[]) currentUserProxyVoters
```

List of current proxy for each user

#### blockedProxyPower

```solidity
mapping(address => uint256) blockedProxyPower
```

Blocked (for Proxies) voting power for each user

#### usedFreePower

```solidity
mapping(address => uint256) usedFreePower
```

Used free voting power for each user

#### VoteForGauge

```solidity
event VoteForGauge(uint256 time, address user, address gauge_addr, uint256 weight)
```

Event emitted when a vote is casted for a gauge

#### NewBoardListed

```solidity
event NewBoardListed(uint256 id, address board, address distributor)
```

Event emitted when a new Board is listed

#### BoardUpdated

```solidity
event BoardUpdated(uint256 id, address newDistributor)
```

Event emitted when a Board is udpated

#### NewGaugeAdded

```solidity
event NewGaugeAdded(address gauge, uint256 boardId, uint256 cap)
```

Event emitted when a new Gauge is listed

#### GaugeCapUpdated

```solidity
event GaugeCapUpdated(address gauge, uint256 boardId, uint256 newCap)
```

Event emitted when a Gauge is updated

#### GaugeBoardUpdated

```solidity
event GaugeBoardUpdated(address gauge, uint256 newBoardId)
```

Event emitted when a Gauge is updated

#### GaugeKilled

```solidity
event GaugeKilled(address gauge, uint256 boardId)
```

Event emitted when a Gauge is killed

#### GaugeUnkilled

```solidity
event GaugeUnkilled(address gauge, uint256 boardId)
```

Event emitted when a Gauge is unkilled

#### SetProxyManager

```solidity
event SetProxyManager(address user, address manager)
```

Event emitted when a Proxy Manager is set

#### RemoveProxyManager

```solidity
event RemoveProxyManager(address user, address manager)
```

Event emitted when a Proxy Manager is removed

#### SetNewProxyVoter

```solidity
event SetNewProxyVoter(address user, address proxyVoter, uint256 maxPower, uint256 endTimestamp)
```

Event emitted when a Proxy Voter is set

#### DefaultCapUpdated

```solidity
event DefaultCapUpdated(uint256 newCap)
```

Event emitted when the default gauge cap is updated

#### isListedGauge

```solidity
function isListedGauge(address gauge) external view returns (bool)
```

Is the gauge listed

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type | Description                |
| ---- | ---- | -------------------------- |
| \[0] | bool | bool : Is the gauge listed |

#### getBoardForGauge

```solidity
function getBoardForGauge(address gauge) external view returns (address)
```

Returns the Quest Board assocatied to a gauge

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type    | Description                          |
| ---- | ------- | ------------------------------------ |
| \[0] | address | address : Address of the Quest Board |

#### getDistributorForGauge

```solidity
function getDistributorForGauge(address gauge) external view returns (address)
```

Returns the Distributor assocatied to a gauge

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type    | Description                          |
| ---- | ------- | ------------------------------------ |
| \[0] | address | address : Address of the Distributor |

#### getGaugeWeight

```solidity
function getGaugeWeight(address gauge) external view returns (uint256)
```

Returns the current gauge weight

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type    | Description                    |
| ---- | ------- | ------------------------------ |
| \[0] | uint256 | uint256 : Current gauge weight |

#### getGaugeWeightAt

```solidity
function getGaugeWeightAt(address gauge, uint256 ts) external view returns (uint256)
```

Returns the gauge weight at a specific timestamp

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |
| ts    | uint256 | Timestamp            |

**Return Values**

| Name | Type    | Description                             |
| ---- | ------- | --------------------------------------- |
| \[0] | uint256 | uint256 : Gauge weight at the timestamp |

#### getTotalWeight

```solidity
function getTotalWeight() external view returns (uint256)
```

Returns the current total weight

**Return Values**

| Name | Type    | Description            |
| ---- | ------- | ---------------------- |
| \[0] | uint256 | uint256 : Total weight |

#### getGaugeRelativeWeight

```solidity
function getGaugeRelativeWeight(address gauge) external view returns (uint256)
```

Returns a gauge relative weight

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type    | Description                     |
| ---- | ------- | ------------------------------- |
| \[0] | uint256 | uint256 : Gauge relative weight |

#### getGaugeRelativeWeight

```solidity
function getGaugeRelativeWeight(address gauge, uint256 ts) external view returns (uint256)
```

Returns a gauge relative weight at a specific timestamp

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |
| ts    | uint256 | Timestamp            |

**Return Values**

| Name | Type    | Description                                      |
| ---- | ------- | ------------------------------------------------ |
| \[0] | uint256 | uint256 : Gauge relative weight at the timestamp |

#### getGaugeCap

```solidity
function getGaugeCap(address gauge) external view returns (uint256)
```

Returns the cap relative weight for a gauge

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type    | Description         |
| ---- | ------- | ------------------- |
| \[0] | uint256 | uint256 : Gauge cap |

#### getUserProxyVoters

```solidity
function getUserProxyVoters(address user) external view returns (address[])
```

Returns the list of current proxies for a user

**Parameters**

| Name | Type    | Description         |
| ---- | ------- | ------------------- |
| user | address | Address of the user |

**Return Values**

| Name | Type       | Description                          |
| ---- | ---------- | ------------------------------------ |
| \[0] | address\[] | address\[] : List of proxy addresses |

#### voteForGaugeWeights

```solidity
function voteForGaugeWeights(address gauge, uint256 userPower) external
```

Votes for a gauge weight

*Votes for a gauge weight based on the given user power*

**Parameters**

| Name      | Type    | Description               |
| --------- | ------- | ------------------------- |
| gauge     | address | Address of the gauge      |
| userPower | uint256 | Power used for this gauge |

#### voteForManyGaugeWeights

```solidity
function voteForManyGaugeWeights(address[] gauge, uint256[] userPower) external
```

Votes for multiple gauge weights

**Parameters**

| Name      | Type       | Description               |
| --------- | ---------- | ------------------------- |
| gauge     | address\[] | Address of the gauges     |
| userPower | uint256\[] | Power used for each gauge |

#### voteForGaugeWeightsFor

```solidity
function voteForGaugeWeightsFor(address user, address gauge, uint256 userPower) external
```

Votes for a gauge weight as another user

**Parameters**

| Name      | Type    | Description               |
| --------- | ------- | ------------------------- |
| user      | address | Address of the user       |
| gauge     | address | Address of the gauge      |
| userPower | uint256 | Power used for this gauge |

#### voteForManyGaugeWeightsFor

```solidity
function voteForManyGaugeWeightsFor(address user, address[] gauge, uint256[] userPower) external
```

Votes for multiple gauge weights as another user

**Parameters**

| Name      | Type       | Description               |
| --------- | ---------- | ------------------------- |
| user      | address    | Address of the user       |
| gauge     | address\[] | Address of the gauges     |
| userPower | uint256\[] | Power used for each gauge |

#### getGaugeRelativeWeightWrite

```solidity
function getGaugeRelativeWeightWrite(address gauge) external returns (uint256)
```

Returns the updated gauge relative weight

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

**Return Values**

| Name | Type    | Description                             |
| ---- | ------- | --------------------------------------- |
| \[0] | uint256 | uint256 : Updated gauge relative weight |

#### getGaugeRelativeWeightWrite

```solidity
function getGaugeRelativeWeightWrite(address gauge, uint256 ts) external returns (uint256)
```

Returns the updated gauge relative weight at a given timestamp

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |
| ts    | uint256 | Timestamp            |

**Return Values**

| Name | Type    | Description                                              |
| ---- | ------- | -------------------------------------------------------- |
| \[0] | uint256 | uint256 : Updated gauge relative weight at the timestamp |

#### updateGaugeWeight

```solidity
function updateGaugeWeight(address gauge) external
```

Updates the gauge weight

**Parameters**

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| gauge | address | Address of the gauge |

#### updateTotalWeight

```solidity
function updateTotalWeight() external
```

Updates the total weight

#### approveProxyManager

```solidity
function approveProxyManager(address manager, uint256 maxDuration) external
```

Approves a Proxy Manager for the caller

**Parameters**

| Name        | Type    | Description                                                                                |
| ----------- | ------- | ------------------------------------------------------------------------------------------ |
| manager     | address | Address of the Proxy Manager                                                               |
| maxDuration | uint256 | Maximum Proxy duration allowed to be created by the Manager (can be set to 0 for no limit) |

#### updateProxyManagerDuration

```solidity
function updateProxyManagerDuration(address manager, uint256 newMaxDuration) external
```

Updates the max duration allowed for a Proxy Manager

**Parameters**

| Name           | Type    | Description                                                                                |
| -------------- | ------- | ------------------------------------------------------------------------------------------ |
| manager        | address | Address of the Proxy Manager                                                               |
| newMaxDuration | uint256 | Maximum Proxy duration allowed to be created by the Manager (can be set to 0 for no limit) |

#### removeProxyManager

```solidity
function removeProxyManager(address manager) external
```

Approves a Proxy Manager for the caller

**Parameters**

| Name    | Type    | Description                  |
| ------- | ------- | ---------------------------- |
| manager | address | Address of the Proxy Manager |

#### setVoterProxy

```solidity
function setVoterProxy(address user, address proxy, uint256 maxPower, uint256 endTimestamp) external
```

Sets a Proxy Voter for the user

**Parameters**

| Name         | Type    | Description                            |
| ------------ | ------- | -------------------------------------- |
| user         | address | Address of the user                    |
| proxy        | address | Address of the Proxy Voter             |
| maxPower     | uint256 | Max voting power allowed for the Proxy |
| endTimestamp | uint256 | Timestamp of the Proxy expiry          |

#### clearUserExpiredProxies

```solidity
function clearUserExpiredProxies(address user) external
```

Clears expired Proxies for a user

**Parameters**

| Name | Type    | Description         |
| ---- | ------- | ------------------- |
| user | address | Address of the user |
