Smart Contract Reference
Smart Contract Reference
Core Functions
initialize
function initialize(
    address _owner,
    address _stakingToken,
    address[] memory _rewardTokens,
    address[] memory _rewardManagers,
    uint256[] memory _rewardRates,
    bytes calldata _data
) external nonReentrantInitializes a new KodiakFarm instance.
Parameters:
_owner: Address that will own the farm_stakingToken: Address of the token that can be staked_rewardTokens: Array of reward token addresses_rewardManagers: Array of managers for each reward token_rewardRates: Array of reward rates for each token_data: Additional initialization data (unused)
Errors:
Farm: Already initialized- When farm already initializedFarm: Array lengths do not match- When input arrays have different lengthsToken already added- When duplicate reward tokens provided
Events: None
stakeLocked
function stakeLocked(
    uint256 liquidity,
    uint256 secs
) public nonReentrantStakes tokens with a time lock.
Parameters:
liquidity: Amount of tokens to stakesecs: Duration of the lock in seconds
Emits: StakeLocked
Errors:
Staking paused- When staking is pausedMust stake more than zero- When liquidity is 0Farm cap exceeded- When total staked would exceed capAddress has been greylisted- When user is greylistedMinimum stake time not met- When secs < lock_time_minTrying to lock for too long- When secs > lock_time_for_max_multiplier
withdrawLocked
function withdrawLocked(
    bytes32 kek_id
) public nonReentrant withdrawalsNotPausedWithdraws a specific locked stake.
Parameters:
kek_id: Unique identifier of the stake to withdraw
Emits: WithdrawLocked
Errors:
Withdrawals paused- When withdrawals are pausedStake not found- When kek_id doesn't existStake is still locked!- When lock duration hasn't expired
getReward
function getReward() 
external nonReentrant 
returns (uint256[] memory)Claims all available reward tokens.
Returns:
Array of claimed reward amounts for each reward token
Emits: RewardPaid
Errors:
Rewards collection paused- When rewards collection is paused
addNewRewardToken
function addNewRewardToken(
    address _rewardToken,
    address _rewardManager,
    uint256 _rewardRate
) external onlyOwnerOrFactoryOwnerAdds a new reward token to the farm.
Parameters:
_rewardToken: Address of the new reward token_rewardManager: Address of the token's reward manager_rewardRate: Initial reward rate for the token
Emits:
RewardTokenAddedRewardRateUpdated
Errors:
Zero address detected- When _rewardToken is zero addressToken already added- When token already exists in farm
setRewardRate
function setRewardRate(
    address _rewardToken,
    uint256 _rewardRate,
    bool sync_too
) external onlyTknMgrs(_rewardToken)Updates the reward rate for a specific token.
Parameters:
_rewardToken: Address of the reward token_rewardRate: New reward ratesync_too: Whether to sync rewards after rate change
Emits: RewardRateUpdated
Errors:
Farm: Not owner, factory owner, or tkn mgr- When caller lacks permission
emergencyWithdraw
function emergencyWithdraw(
    bytes32 kek_id
) public nonReentrant withdrawalsNotPausedEmergency withdraws a stake without claiming rewards.
Parameters:
kek_id: Unique identifier of the stake to withdraw
Emits: WithdrawLocked
Errors:
Withdrawals paused- When withdrawals are pausedStake not found- When kek_id doesn't exist
recoverERC20
function recoverERC20(
    address tokenAddress,
    uint256 tokenAmount
) external onlyTknMgrs(tokenAddress)Recovers mistakenly sent tokens from the contract.
Parameters:
tokenAddress: Address of token to recovertokenAmount: Amount to recover
Emits:
RecoveredRewardRateUpdated(if reward token)
Errors:
Cannot rug staking / LP tokens- When attempting to withdraw stake tokenNo valid tokens to recover- When caller lacks permission for token
function stakeLocked(uint256 liquidity, uint256 secs) public nonReentrantStakes tokens for a specified duration.
liquidity: Amount of tokens to stakesecs: Lock duration in secondsRequirements:
Staking not paused
Duration within min/max bounds
Address not greylisted
Within staking cap
function withdrawLocked(bytes32 kek_id) public nonReentrant withdrawalsNotPausedWithdraws a specific stake after lock period.
kek_id: Unique identifier of the stakeRequirements:
Lock period expired
Withdrawals not paused
Reward Management
function getReward() external nonReentrant returns (uint256[] memory)Claims all available rewards.
Requirements:
Rewards collection not paused
Returns array of claimed reward amounts
function setRewardRate(
    address _rewardToken,
    uint256 _rewardRate,
    bool sync_too
) external onlyTknMgrs(_rewardToken)Updates reward rate for a specific token.
Requires manager privileges
Auto-funds if rate increases
Optionally syncs rewards
Administrative Functions
function setMultipliers(uint256 _lock_max_multiplier) external onlyOwnerOrFactoryOwnerUpdates the maximum lock multiplier.
Must be >= 1e18 (1x)
function addNewRewardToken(
    address _rewardToken,
    address _rewardManager,
    uint256 _rewardRate
) external onlyOwnerOrFactoryOwnerAdds a new reward token to the farm.
Cannot add duplicate tokens
Auto-funds rewards if farm active
Events
event StakeLocked(address indexed user, uint256 amount, uint256 secs, bytes32 kek_id)
event WithdrawLocked(address indexed user, uint256 amount, bytes32 kek_id)
event RewardPaid(address indexed user, uint256 reward, address token_address)Modifiers
modifier onlyOwnerOrFactoryOwner()
modifier onlyTknMgrs(address reward_token_address)
modifier onlyFactoryOwner()
modifier notStakingPaused()
modifier withdrawalsNotPaused()Role-Based Access Control
Owner
Set multipliers and durations
Add new reward tokens
Configure staking caps
Manage greylist
Factory Owner
Emergency controls
Pause withdrawals/rewards
Override lock restrictions
Token Managers
Manage specific reward tokens
Set reward rates
Recover mistaken tokens
Error Handling
Common error scenarios and their meanings:
"Farm: not started yet" // Farm needs initialization
"Staking paused" // Administrative pause active
"Farm cap exceeded" // Total stake limit reached
"Stake is still locked!" // Lock duration not met
"Rewards collection paused" // Emergency pause on rewardsState Variables
Key state tracking:
uint256 public stakingTokenCap;
uint256 public lock_max_multiplier;
uint256 public lock_time_for_max_multiplier;
uint256 private _total_liquidity_locked;
mapping(address => LockedStake[]) private lockedStakes;Security Features
Emergency Controls
Pause staking/withdrawals/rewards
Emergency withdrawal option
Factory owner override
Access Controls
Multi-role system
Greylist functionality
Manager-specific permissions
Economic Safety
Dynamic reward adjustment
Staking caps
Lock time restrictions
Last updated