Smart Contract Reference
Smart Contract Reference
Core Functions
initialize
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 initializedFarm: Array lengths do not match
- When input arrays have different lengthsToken already added
- When duplicate reward tokens provided
Events: None
stakeLocked
Stakes 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
Withdraws 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
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 addressToken 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 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
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 pausedStake not found
- When kek_id doesn't exist
recoverERC20
Recovers mistakenly sent tokens from the contract.
Parameters:
tokenAddress
: Address of token to recovertokenAmount
: Amount to recover
Emits:
Recovered
RewardRateUpdated
(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
Stakes 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
Withdraws a specific stake after lock period.
kek_id
: Unique identifier of the stakeRequirements:
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
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:
State Variables
Key state tracking:
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