Documentation

Token Staking

Stake tokens for a lock period and earn rewards over time. The operator funds a reward pool, and stakers earn proportional rewards based on their stake amount and duration.

Use Cases

  • Protocol staking with reward distribution
  • Liquidity mining incentives
  • Token lock-up programs with yield

Init Parameters

ParameterTypeDescription
token_idTokenIdToken to stake
reward_rateu128Reward per second per 1e12 tokens staked
min_lock_periodu64Minimum lock duration (seconds) before unstaking

Execute Methods

MethodParametersDescription
initializetoken_id, reward_rate, min_lock_periodSet up the staking vault. Only callable once.
stakeamount: u128Deposit tokens. Auto-claims pending rewards if existing stake.
unstakeamount: u128Withdraw tokens. Auto-claims rewards. Requires lock period elapsed.
claim_rewards--Claim pending rewards without changing stake.
fund_rewardsamount: u128Operator adds tokens to the reward pool.

Query Methods

MethodParametersReturnsDescription
get_config--StakingConfigVault configuration
get_stakeaddress: AddressStakeInfoStake details for an address
get_pending_rewardsaddress: Addressu128Claimable rewards for an address
get_total_staked--u128Total tokens staked across all users
get_reward_pool--u128Remaining tokens in the reward pool

Key Types

StakingConfig

pub struct StakingConfig {
    pub operator: Address,
    pub token_id: TokenId,
    pub reward_rate: u128,
    pub min_lock_period: u64,
    pub created_at: u64,
}

StakeInfo

pub struct StakeInfo {
    pub amount: u128,
    pub start_time: u64,
    pub last_claim_time: u64,
}

Reward Calculation

elapsed = now - last_claim_time
rewards = (stake_amount * elapsed * reward_rate) / 1e12
actual = min(rewards, available_pool)

CLI Usage

# Deploy
norn wallet deploy-loom --name my-staking
 
# Upload bytecode
norn wallet upload-bytecode --loom-id <LOOM_ID> \
  --bytecode staking.wasm
 
# Execute (borsh-encoded input)
norn wallet execute-loom --loom-id <LOOM_ID> --input <HEX>
 
# Query config
norn wallet query-loom --loom-id <LOOM_ID>