# LootCreator

Contract handling the Budget for gauges & Quests and the Loot creation. The budget allocated to each Quest for each period is based on the weight of a gauge received through votes on the LootVoteController, and the number of Quest on each gauge. All unallocated budget is pushed back to the pending budget for the next period. The rewards allocated to Quest voters are allocated by this contract (which creates the Loot), based on the Quest allocation, the user voting rewards and the user boosting power. All rewards not allocated to an user for its Loot (by lack of boosting power) are pushed back to the pending budget for the next period. Each period budget is pulled from the LootBudget or the LootGauge.

#### BASE\_MULTIPLIER

```solidity
uint256 BASE_MULTIPLIER
```

Base Multiplier for Loot rewards

#### MAX\_MULTIPLIER

```solidity
uint256 MAX_MULTIPLIER
```

Max Multiplier for Loot rewards

#### Budget

Budget struct

```solidity
struct Budget {
  uint128 palAmount;
  uint128 extraAmount;
}
```

#### Allocation

Allocation strcut

```solidity
struct Allocation {
  uint128 palPerVote;
  uint128 extraPerVote;
}
```

#### CreateVars

Struct use in memory for Loot creation method

```solidity
struct CreateVars {
  address gauge;
  uint256 userPower;
  uint256 totalPower;
  uint256 totalRewards;
  uint256 lockedRatio;
  uint256 rewardRatio;
  uint256 totalRatio;
  uint256 userPeriodRewards;
  uint256 userMultiplier;
  uint256 userPalAmount;
  uint256 userExtraAmount;
}
```

#### loot

```solidity
address loot
```

Address of the Loot contract

#### lootVoteController

```solidity
address lootVoteController
```

Address of the Loot Vote Controller contract

#### holyPower

```solidity
address holyPower
```

Address of the HolyPalPower contract

#### lootGauge

```solidity
address lootGauge
```

Address of the Loot Gauge or Budget contract

#### allowedDistributors

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

Quest Distributors allowed to intract with this contract

#### distributorsBoards

```solidity
mapping(address => address) distributorsBoards
```

QuestBoard for each Distributor

#### distributors

```solidity
address[] distributors
```

List of listed Quest Distributors

#### nextBudgetUpdatePeriod

```solidity
uint256 nextBudgetUpdatePeriod
```

Timestamp of the next Budget update

#### pendingBudget

```solidity
struct LootCreator.Budget pendingBudget
```

Current pending budget to be used during next period

#### periodBudget

```solidity
mapping(uint256 => struct LootCreator.Budget) periodBudget
```

Budgets for each period

#### allocatedBudgetHistory

```solidity
mapping(uint256 => struct LootCreator.Budget) allocatedBudgetHistory
```

History of allocated amounts from the Budget of each period

#### gaugeBudgetPerPeriod

```solidity
mapping(address => mapping(uint256 => struct LootCreator.Budget)) gaugeBudgetPerPeriod
```

Budget allocated to a Gauge for each period

#### isGaugeAllocatedForPeriod

```solidity
mapping(address => mapping(uint256 => bool)) isGaugeAllocatedForPeriod
```

Was the gauge allocated a Budget for each period

#### totalQuestPeriodRewards

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

Total Rewards distributed for a period for a Quest

#### totalQuestPeriodSet

```solidity
mapping(address => mapping(uint256 => mapping(uint256 => bool))) totalQuestPeriodSet
```

Was the total reward set for a Quest period

#### userQuestPeriodRewards

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

User claimed amount for a Quest period

#### userQuestPeriodCreated

```solidity
mapping(address => mapping(uint256 => mapping(uint256 => mapping(address => bool)))) userQuestPeriodCreated
```

User created Loot for a Quest period

#### Init

```solidity
event Init(address lootGauge)
```

Event emitted when the contract is initialized

#### NewDistributorListed

```solidity
event NewDistributorListed(address distributor)
```

Event emitted when a new Distributor is listed

#### DistributorUnlisted

```solidity
event DistributorUnlisted(address distributor)
```

Event emitted when Distributor is unlisted

#### GaugeUpdated

```solidity
event GaugeUpdated(address oldGauge, address newGauge)
```

Event emitted when the budget Gauge is updated

#### LootCreated

```solidity
event LootCreated(address user, uint256 questId, uint256 period, uint256 lootId)
```

Event emitted when a Loot is created

#### getBudgetForPeriod

```solidity
function getBudgetForPeriod(uint256 period) external view returns (uint256 palAmount, uint256 extraAmount)
```

Returns the global budget for a period

**Parameters**

| Name   | Type    | Description             |
| ------ | ------- | ----------------------- |
| period | uint256 | Timestamp of the period |

**Return Values**

| Name        | Type    | Description                                                 |
| ----------- | ------- | ----------------------------------------------------------- |
| palAmount   | uint256 | (uint256) : Amount of PAL tokens allocated for the period   |
| extraAmount | uint256 | (uint256) : Amount of extra tokens allocated for the period |

#### getGaugeBudgetForPeriod

```solidity
function getGaugeBudgetForPeriod(address gauge, uint256 period) external view returns (uint256 palAmount, uint256 extraAmount)
```

Returns the gauge budget for a period

**Parameters**

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

**Return Values**

| Name        | Type    | Description                                                 |
| ----------- | ------- | ----------------------------------------------------------- |
| palAmount   | uint256 | (uint256) : Amount of PAL tokens allocated for the period   |
| extraAmount | uint256 | (uint256) : Amount of extra tokens allocated for the period |

#### getQuestAllocationForPeriod

```solidity
function getQuestAllocationForPeriod(uint256 questId, address distributor, uint256 period) external view returns (uint256 palPerVote, uint256 extraPerVote)
```

Returns the allocation for a Quest for a period

**Parameters**

| Name        | Type    | Description                                           |
| ----------- | ------- | ----------------------------------------------------- |
| questId     | uint256 | ID of the Quest                                       |
| distributor | address | Address of the Distributor handling the Quest rewards |
| period      | uint256 | Timestamp of the period                               |

**Return Values**

| Name         | Type    | Description                                                 |
| ------------ | ------- | ----------------------------------------------------------- |
| palPerVote   | uint256 | (uint256) : Amount of PAL tokens allocated for the period   |
| extraPerVote | uint256 | (uint256) : Amount of extra tokens allocated for the period |

#### getListedDistributors

```solidity
function getListedDistributors() external view returns (address[])
```

Returns all listed Distributors

**Return Values**

| Name | Type       | Description                    |
| ---- | ---------- | ------------------------------ |
| \[0] | address\[] | uint256 : List of Distributors |

#### createLoot

```solidity
function createLoot(address user, address distributor, uint256 questId, uint256 period) external
```

Creates a Loot for a user

**Parameters**

| Name        | Type    | Description                                           |
| ----------- | ------- | ----------------------------------------------------- |
| user        | address | Address of the user                                   |
| distributor | address | Address of the Distributor handling the Quest rewards |
| questId     | uint256 | ID of the Quest                                       |
| period      | uint256 | Timestamp of the period                               |

#### createMultipleLoot

```solidity
function createMultipleLoot(address user, struct ILootCreator.MultiCreate[] params) external
```

Creates multiple Loots for a user

**Parameters**

| Name   | Type                               | Description                                           |
| ------ | ---------------------------------- | ----------------------------------------------------- |
| user   | address                            | Address of the user                                   |
| params | struct ILootCreator.MultiCreate\[] | Quest claim parameters (distributor, questId, period) |

#### notifyQuestClaim

```solidity
function notifyQuestClaim(address user, uint256 questId, uint256 period, uint256 claimedAmount) external
```

Notifies of a Quest claim

**Parameters**

| Name          | Type    | Description                           |
| ------------- | ------- | ------------------------------------- |
| user          | address | Address of the user                   |
| questId       | uint256 | ID of the Quest                       |
| period        | uint256 | Timestamp of the period               |
| claimedAmount | uint256 | Amount of rewards claimed by the user |

#### notifyDistributedQuestPeriod

```solidity
function notifyDistributedQuestPeriod(uint256 questId, uint256 period, uint256 totalRewards) external
```

Notifies of a Quest period distribution

**Parameters**

| Name         | Type    | Description                                                      |
| ------------ | ------- | ---------------------------------------------------------------- |
| questId      | uint256 | ID of the Quest                                                  |
| period       | uint256 | Timestamp of the period                                          |
| totalRewards | uint256 | Total amount of rewards distributed for the period for the Quest |

#### notifyAddedRewardsQuestPeriod

```solidity
function notifyAddedRewardsQuestPeriod(uint256 questId, uint256 period, uint256 addedRewards) external
```

Notifies of the amount added to a Quest period via emergency update in Distributors

**Parameters**

| Name         | Type    | Description               |
| ------------ | ------- | ------------------------- |
| questId      | uint256 | ID of the Quest           |
| period       | uint256 | Timestamp of the period   |
| addedRewards | uint256 | Amount added to the total |

#### notifyUndistributedRewards

```solidity
function notifyUndistributedRewards(uint256 palAmount) external
```

Notifies of undistributed rewards

**Parameters**

| Name      | Type    | Description                  |
| --------- | ------- | ---------------------------- |
| palAmount | uint256 | Amount of PAL tokens slashed |

#### notifyNewBudget

```solidity
function notifyNewBudget(uint256 palAmount, uint256 extraAmount) external
```

Notifies of new budget

**Parameters**

| Name        | Type    | Description                                |
| ----------- | ------- | ------------------------------------------ |
| palAmount   | uint256 | Amount of PAL tokens added to the budget   |
| extraAmount | uint256 | Amount of extra tokens added to the budget |

#### updatePeriod

```solidity
function updatePeriod() external
```

Updates the period
