# v9.1 Update

## Summary

* New features: GNS staking fees are all used to buy GNS, sends an adjustable % to treasury, burn, and GNS staking rewards and uses an adjustable price premium; new compound function in GNS staking
* Other changes: There is a 100 seconds cooldown to wait before one can unstake after staking GNS to prevent flashloans (vests must be 100 seconds long at least too now)

## Full Changelog

### core/GNSStaking.sol (update)

* New `UNSTAKING_COOLDOWN_SECONDS` constant (= 100 seconds)
* New `stakerInfos` mapping to store each user's lastDepositTs
* New `notInCooldown` modifier, used by `unstakeGns`, reverts if user deposited less than `UNSTAKING_COOLDOWN_SECONDS` ago
* `_harvestToken`, `_harvestFromUnlock`, `_harvestTokenFromUnlock`, `harvestToken`, `harvestTokenFromUnlock`, `harvestTokenAll` now all return the pending token rewards (needed for compound function)
* New `compoundGnsRewards` function: harvests pending regular rewards and vest rewards (accepts vests `_ids` as input) and stakes them in the same transaction
* `stakeGns`: now public (called by `compoundGnsRewards`) and stores current timestamp in `stakerInfos` mapping for caller
* `unstakeGns`: now uses `notInCooldown` modifier
* `createUnlockSchedule`: now checks vest duration >= `UNSTAKING_COOLDOWN_SECONDS` instead of accepting any non-zero value

### core/abstract/GNSDiamondStorage.sol (update)

* Added `otcStorage` private state var for new `GNSOtc` facet

### core/facets/GNSOtc.sol (new)

* New facet which handles the collateral -> GNS OTC buying process and transfer to treasury, burn, and GNS staking rewards (adjustable percentages)
* `initializeOtc`: infinite approval of GNS staking contract for GNS token and config initialization
* `updateOtcConfig`: update treasury address and percentages
* `addOtcCollateralBalance`: increases available collateral balance for OTC buying (used by `GNSTradingCallbacks` when distributing GNS staking fee)
* `sellGnsForCollateral`: executes OTC transaction; diamond receives GNS and sender receives collateral tokens, available collateral balance for OTC decreases accordingly
* `getOtcConfig`, `getOtcBalance`, `getOtcRate` getters

### interfaces/IGNSMultiCollatDiamond.sol (update)

* Now inherits `IOtcUtils`

### interfaces/IGNSStaking.sol (update)

* New `StakerInfo` struct (`lastDepositTs` and placeholder)

### interfaces/IGeneralErrors.sol (update)

* New `InsufficientBalance()` error

### interfaces/libraries/IOtcUtils.sol (new)

* Interface for new `GNSOtc` facet: contains all types, functions, events, and custom errors

### interfaces/types/IOtc.sol (new)

* Interface for new `GNSOtc` facet: contains all types
* `OtcStorage` struct: `collateralBalances` mapping, `otcConfig` struct
* `OtcConfig` struct: treasury address, percentages (treasury, GNS staking, burn), price premium

### interfaces/types/IPriceAggregator.sol (update)

* Fixed `__gap` array length, reduced from 41 to 39

### interfaces/types/ITypes.sol (update)

* Now inherits new facet types `IOtc`

### libraries/OtcUtils.sol (new)

* Internal library for new `GNSOtc` facet

### libraries/StorageUtils.sol (update)

* Added `GLOBAL_OTC_SLOT` constant for new `GNSOtc` facet

### libraries/TradingCommonUtils.sol (update)

* `convertCollateralToGns`, `transferCollateralTo`, and `_getMultiCollatDiamond` are now internal: allows not linking TradingCommonUtils to `GNSOtc` as internal functions are imported directly into the bytecode, should only make functions external when it becomes an issue for size
* New `transferGnsTo` and `transferGnsFrom` helpers to handle simple GNS transfers between users and the diamond
* `distributeGnsStakingFeeCollateral` now calls `_getMultiCollatDiamond().addOtcCollateralBalance` instead of `gnsStaking.distributeReward`
