FoldCaptiveStaking
Inherits: Owned
Author: CopyPaste
SPDX-License-Identifier: SSPL-1.0 Interfaces Libraries contracts
Staking contract for managing FOLD token liquidity on Uniswap V3
State Variables
initialized
bool public initialized;
TICK_UPPER
The max Tick of the position
int24 public constant TICK_UPPER = TickMath.MAX_TICK;
TICK_LOWER
The lower Tick of the position
int24 public constant TICK_LOWER = TickMath.MIN_TICK;
positionManager
The Canonical UniswapV3 Position Manager
INonfungiblePositionManager public immutable positionManager;
POOL
The FOLD <> {WETH, USDC} Liquidity Pool
IUniswapV3Pool public immutable POOL;
token0
token0 In terms of the Uniswap Pool
ERC20 public immutable token0;
token1
token1 in terms of the Uniswap Pool
ERC20 public immutable token1;
TOKEN_ID
The tokenId of the UniswapV3 position
uint256 public TOKEN_ID;
liquidityUnderManagement
Used for all rewards related tracking
uint256 public liquidityUnderManagement;
rewardsPerLiquidity
Used to keep track of rewards given per share
uint256 public rewardsPerLiquidity;
token0FeesPerLiquidity
For keeping track of position fees
uint256 public token0FeesPerLiquidity;
token1FeesPerLiquidity
For keeping track of positions fees
uint256 public token1FeesPerLiquidity;
depositCap
The cap on deposits in the pool in liquidity, set to 0 if no cap
uint256 public depositCap;
balances
mapping(address user => UserInfo info) public balances;
WETH9
The Canonical WETH address
WETH public immutable WETH9;
FOLD
ERC20 public immutable FOLD;
Functions
constructor
constructor(address _positionManager, address _pool, address _weth, address _fold);
Parameters
Name | Type | Description |
---|---|---|
_positionManager | address | The Canonical UniswapV3 PositionManager |
_pool | address | The FOLD Pool to Reward |
_weth | address | The address of WETH on the deployed chain |
_fold | address | The address of Fold on the deployed chain |
initialize
Initialize the contract by minting a small initial liquidity position
function initialize() public onlyOwner;
isInitialized
modifier isInitialized();
depositRewards
Allows anyone to add funds to the contract, split among all depositors
function depositRewards() public payable isInitialized;
receive
receive() external payable;
deposit
Allows a user to deposit liquidity into the pool
function deposit(uint256 amount0, uint256 amount1, uint256 slippage) external isInitialized;
Parameters
Name | Type | Description |
---|---|---|
amount0 | uint256 | The amount of token0 to deposit |
amount1 | uint256 | The amount of token1 to deposit |
slippage | uint256 | Slippage on deposit out of 1e18 |
compound
Compounds User Earned Fees back into their position
function compound() public isInitialized;
collectFees
User-specific function to collect fees on the singular position
function collectFees() public isInitialized;
collectRewards
User-specific Rewards for Protocol Rewards
function collectRewards() public isInitialized;
withdraw
Withdraws liquidity from the pool
function withdraw(uint128 liquidity) external isInitialized;
Parameters
Name | Type | Description |
---|---|---|
liquidity | uint128 | The amount of liquidity to withdraw |
collectPositionFees
Collects fees on the underling UniswapV3 Position
function collectPositionFees() internal;
setDepositCap
function setDepositCap(uint256 _newCap) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_newCap | uint256 | The new deposit cap, measured in liquidity |
claimInsurance
Allows the owner to claim insurance in case of relay outage
function claimInsurance(uint128 liquidity) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
liquidity | uint128 | The amount of liquidity to claim |
Events
Initialized
event Initialized();
Deposit
event Deposit(address indexed user, uint256 amount0, uint256 amount1);
Withdraw
event Withdraw(address indexed user, uint128 liquidity);
RewardsDeposited
event RewardsDeposited(uint256 amount);
FeesCollected
event FeesCollected(address indexed user, uint256 fee0Owed, uint256 fee1Owed);
RewardsCollected
event RewardsCollected(address indexed user, uint256 rewardsOwed);
Compounded
event Compounded(address indexed user, uint128 liquidity, uint256 fee0Owed, uint256 fee1Owed);
InsuranceClaimed
event InsuranceClaimed(address indexed owner, uint256 amount0, uint256 amount1);
Errors
ZeroAddress
Custom Errors
error ZeroAddress();
AlreadyInitialized
error AlreadyInitialized();
NotInitialized
error NotInitialized();
ZeroLiquidity
error ZeroLiquidity();
WithdrawFailed
error WithdrawFailed();
WithdrawProRata
error WithdrawProRata();
DepositCapReached
error DepositCapReached();
Structs
UserInfo
struct UserInfo {
uint128 amount;
uint128 rewardDebt;
uint128 token0FeeDebt;
uint128 token1FeeDebt;
}