Contract c908c656a4ae77390dc05d43419f8624ebe1eef3d1d14d122370017ec5231fe9

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.8#f46e9e0610213bbb72285566f9dd960ff96d03d8
rsver 1.90.0

Instances

  • CDV45ELSBUXVLEBHFVVYRCMYZPRS5YUWCCDTPVZBTQKIJ6W22VZC5BPD

Interface

Initialize the incentives contract

Arguments

  • emission_manager: Address authorized to configure rewards
  • lending_pool: Address authorized to call handle_action
fn initialize(
    env: soroban_sdk::Env,
    emission_manager: soroban_sdk::Address,
    lending_pool: soroban_sdk::Address,
) -> Result<(), IncentivesError>

Handle action called by token contracts (aToken/debtToken) when balances change

This is the core function that updates reward indices and calculates user rewards. Called after balance updates (mint/burn) to update rewards.

Following Aave's pattern: the asset is determined by the token_address parameter (which should be the token contract calling this). This makes it safe for anyone to call with arbitrary parameters - if the token_address is not a registered reward-bearing asset, the function simply returns without doing anything.

Arguments

  • token_address: The aToken or debtToken address (the asset identifier)
  • user: The user address whose balance changed
  • total_supply: Total scaled supply/borrow for the asset
  • user_balance: User's scaled balance
  • reward_type: 0 for supply, 1 for borrow

Security

  • Asset is determined by token_address parameter (following Aave's msg.sender pattern)
  • If token_address is not a registered asset, function returns early (no-op)
  • Parameters cannot affect re
fn handle_action(
    env: soroban_sdk::Env,
    token_address: soroban_sdk::Address,
    user: soroban_sdk::Address,
    total_supply: u128,
    user_balance: u128,
    reward_type: u32,
) -> Result<(), IncentivesError>

Claim rewards for specific assets and reward token

Arguments

  • caller: Address calling the function (must be authorized)
  • assets: List of assets to claim rewards for
  • reward_token: The reward token to claim
  • amount: Amount to claim (0 = claim all available)
  • to: Address to receive the rewards

Returns

The amount of rewards actually claimed

Errors

Returns InsufficientRewards if amount > 0 and the requested amount exceeds the total claimable rewards across all assets and reward types.

fn claim_rewards(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    assets: soroban_sdk::Vec,
    reward_token: soroban_sdk::Address,
    amount: u128,
    to: soroban_sdk::Address,
) -> Result

Claim all rewards for all configured reward tokens

This function batches transfers by reward token to reduce gas costs. Instead of one transfer per (asset, reward_token, reward_type) combination, it accumulates all rewards per reward token and does a single transfer per token.

Gas Optimization

  • Before: N transfers for N reward positions (e.g., 3 assets × 2 tokens × 2 types = 12 transfers)
  • After: M transfers for M unique reward tokens (e.g., 2 transfers for 2 unique tokens)
  • Savings: Reduces transfers from O(assets × tokens × types) to O(unique_tokens)

Arguments

  • caller: Address calling the function (must be authorized)
  • assets: List of assets to claim rewards for
  • to: Address to receive the rewards
fn claim_all_rewards(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    assets: soroban_sdk::Vec,
    to: soroban_sdk::Address,
) -> Result<(), IncentivesError>

Configure asset rewards (admin function)

Following Aave's pattern: rewards are configured per token contract (aToken/debtToken), not per underlying asset. The asset parameter is the token address that will call handle_action.

Arguments

  • caller: Must be emission_manager
  • asset: The token address (aToken or debtToken) - this is the asset identifier
  • reward_token: The reward token to distribute
  • reward_type: 0 for supply, 1 for borrow
  • emission_per_second: Emission rate in reward tokens per second
  • distribution_end: Distribution end timestamp (0 = no end)
fn configure_asset_rewards(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    reward_type: u32,
    emission_per_second: u128,
    distribution_end: u64,
) -> Result<(), IncentivesError>

Set emission per second for an asset reward (admin function)

Arguments

  • caller: Must be emission_manager
  • asset: The underlying asset address
  • reward_token: The reward token address
  • reward_type: 0 for supply, 1 for borrow
  • new_emission_per_second: New emission rate
fn set_emission_per_second(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    reward_type: u32,
    new_emission_per_second: u128,
) -> Result<(), IncentivesError>

Set distribution end timestamp (admin function)

Arguments

  • caller: Must be emission_manager
  • asset: The underlying asset address
  • reward_token: The reward token address
  • reward_type: 0 for supply, 1 for borrow
  • new_distribution_end: New distribution end timestamp (0 = no end)
fn set_distribution_end(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    reward_type: u32,
    new_distribution_end: u64,
) -> Result<(), IncentivesError>

Remove/deactivate asset reward (admin function)

Arguments

  • caller: Must be emission_manager
  • asset: The underlying asset address
  • reward_token: The reward token address
  • reward_type: 0 for supply, 1 for borrow
fn remove_asset_reward(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    reward_type: u32,
) -> Result<(), IncentivesError>

Pause the incentives contract (emergency admin function)

When paused, users cannot claim rewards. Admin functions remain available. Rewards continue to accrue via handle_action, but claims are blocked.

Arguments

  • caller: Must be emission_manager
fn pause(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
) -> Result<(), IncentivesError>

Unpause the incentives contract (emergency admin function)

Arguments

  • caller: Must be emission_manager
fn unpause(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
) -> Result<(), IncentivesError>

Check if the contract is paused

Returns

true if paused, false otherwise

fn is_paused(env: soroban_sdk::Env) -> bool

Fund the contract with reward tokens (admin function)

Transfers reward tokens from the emission manager to the contract. The contract must be funded before users can claim rewards.

Arguments

  • caller: Must be emission_manager
  • reward_token: The reward token address to fund
  • amount: Amount of reward tokens to transfer to the contract
fn fund_rewards(
    env: soroban_sdk::Env,
    caller: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    amount: u128,
) -> Result<(), IncentivesError>

Get asset reward configuration

fn get_asset_reward_config(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    reward_type: u32,
) -> Option

Get asset reward index

fn get_asset_reward_index(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    reward_type: u32,
) -> AssetRewardIndex

Get user reward data

fn get_user_reward_data(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    user: soroban_sdk::Address,
    reward_type: u32,
) -> UserRewardData

Get user's accrued rewards

fn get_user_accrued_rewards(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
    reward_token: soroban_sdk::Address,
    user: soroban_sdk::Address,
    reward_type: u32,
) -> u128

Get all configured assets

fn get_assets(env: soroban_sdk::Env) -> soroban_sdk::Vec

Get reward tokens for an asset

fn get_reward_tokens(
    env: soroban_sdk::Env,
    asset: soroban_sdk::Address,
) -> soroban_sdk::Vec

Get the contract's balance for a reward token

Returns the amount of reward tokens held by the contract. This can be used to check if the contract has sufficient funds to cover pending reward claims.

Arguments

  • reward_token: The reward token address to check

Returns

The contract's balance of the reward token

fn get_reward_token_balance(
    env: soroban_sdk::Env,
    reward_token: soroban_sdk::Address,
) -> u128

Imports

WebAssembly Text (WAT) ▶