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 nonReentrant

Initializes 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 initialized

  • Farm: Array lengths do not match - When input arrays have different lengths

  • Token already added - When duplicate reward tokens provided

Events: None


stakeLocked

Stakes tokens with a time lock.

Parameters:

  • liquidity: Amount of tokens to stake

  • secs: Duration of the lock in seconds

Emits: StakeLocked

Errors:

  • Staking paused - When staking is paused

  • Must stake more than zero - When liquidity is 0

  • Farm cap exceeded - When total staked would exceed cap

  • Address has been greylisted - When user is greylisted

  • Minimum stake time not met - When secs < lock_time_min

  • Trying to lock for too long - When secs > lock_time_for_max_multiplier


withdrawLocked

Withdraws a specific locked stake.

Parameters:

  • kek_id: Unique identifier of the stake to withdraw

Emits: WithdrawLocked

Errors:

  • Withdrawals paused - When withdrawals are paused

  • Stake not found - When kek_id doesn't exist

  • Stake is still locked! - When lock duration hasn't expired


getReward

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

Adds 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:

  • RewardTokenAdded

  • RewardRateUpdated

Errors:

  • Zero address detected - When _rewardToken is zero address

  • Token already added - When token already exists in farm


setRewardRate

Updates the reward rate for a specific token.

Parameters:

  • _rewardToken: Address of the reward token

  • _rewardRate: New reward rate

  • sync_too: Whether to sync rewards after rate change

Emits: RewardRateUpdated

Errors:

  • Farm: Not owner, factory owner, or tkn mgr - When caller lacks permission


emergencyWithdraw

Emergency withdraws a stake without claiming rewards.

Parameters:

  • kek_id: Unique identifier of the stake to withdraw

Emits: WithdrawLocked

Errors:

  • Withdrawals paused - When withdrawals are paused

  • Stake not found - When kek_id doesn't exist


recoverERC20

Recovers mistakenly sent tokens from the contract.

Parameters:

  • tokenAddress: Address of token to recover

  • tokenAmount: Amount to recover

Emits:

  • Recovered

  • RewardRateUpdated (if reward token)

Errors:

  • Cannot rug staking / LP tokens - When attempting to withdraw stake token

  • No valid tokens to recover - When caller lacks permission for token

Stakes tokens for a specified duration.

  • liquidity: Amount of tokens to stake

  • secs: Lock duration in seconds

  • Requirements:

    • Staking not paused

    • Duration within min/max bounds

    • Address not greylisted

    • Within staking cap

Withdraws a specific stake after lock period.

  • kek_id: Unique identifier of the stake

  • Requirements:

    • Lock period expired

    • Withdrawals not paused

Reward Management

Claims all available rewards.

  • Requirements:

    • Rewards collection not paused

  • Returns array of claimed reward amounts

Updates reward rate for a specific token.

  • Requires manager privileges

  • Auto-funds if rate increases

  • Optionally syncs rewards

Administrative Functions

Updates the maximum lock multiplier.

  • Must be >= 1e18 (1x)

Adds a new reward token to the farm.

  • Cannot add duplicate tokens

  • Auto-funds rewards if farm active

Events

Modifiers

Role-Based Access Control

  1. Owner

    • Set multipliers and durations

    • Add new reward tokens

    • Configure staking caps

    • Manage greylist

  2. Factory Owner

    • Emergency controls

    • Pause withdrawals/rewards

    • Override lock restrictions

  3. Token Managers

    • Manage specific reward tokens

    • Set reward rates

    • Recover mistaken tokens

Error Handling

Common error scenarios and their meanings:

State Variables

Key state tracking:

Security Features

  1. Emergency Controls

    • Pause staking/withdrawals/rewards

    • Emergency withdrawal option

    • Factory owner override

  2. Access Controls

    • Multi-role system

    • Greylist functionality

    • Manager-specific permissions

  3. Economic Safety

    • Dynamic reward adjustment

    • Staking caps

    • Lock time restrictions

Last updated