Overview
Credits accrued via the farming-pool (get_credits, calculate_credits) have no on-chain redemption mechanism. They exist as an accounting value in storage but cannot currently be converted to any reward token. A CreditRedeemer contract is needed to close this loop.
Design
CreditRedeemer
├── initialize(admin, reward_token, pool: Address, credits_per_token: u128)
├── redeem(user) — burns user credits, transfers reward tokens
├── set_credits_per_token(admin, new_rate)
└── redemption_info() -> RedemptionInfo
Redemption Flow
- User calls
redeem
- Redeemer reads user's total credits from the farming-pool contract via cross-contract call
- Computes
reward_amount = total_credits / credits_per_token
- Marks credits as redeemed (stores
redeemed_credits for the user)
- Transfers
reward_amount of reward_token to user
- Emits
redeemed event
Credit Snapshot Problem
Credits accrue continuously — the redeemer cannot "burn" them from the pool contract. Instead, use a snapshot model:
CreditRedeemer stores credits_at_last_redemption per user
- On redeem:
redeemable_credits = current_credits - credits_at_last_redemption
- Updates the snapshot after redemption
pub struct RedeemKey {
pub user: Address,
pub last_redeemed_credits: i128,
}
Token Supply Consideration
The admin must fund the CreditRedeemer contract address with enough reward_token balance before redemptions can proceed. Add a reward_balance() getter.
Acceptance Criteria
Overview
Credits accrued via the farming-pool (
get_credits,calculate_credits) have no on-chain redemption mechanism. They exist as an accounting value in storage but cannot currently be converted to any reward token. ACreditRedeemercontract is needed to close this loop.Design
Redemption Flow
redeemreward_amount = total_credits / credits_per_tokenredeemed_creditsfor the user)reward_amountofreward_tokento userredeemedeventCredit Snapshot Problem
Credits accrue continuously — the redeemer cannot "burn" them from the pool contract. Instead, use a snapshot model:
CreditRedeemerstorescredits_at_last_redemptionper userredeemable_credits = current_credits - credits_at_last_redemptionToken Supply Consideration
The admin must fund the
CreditRedeemercontract address with enoughreward_tokenbalance before redemptions can proceed. Add areward_balance()getter.Acceptance Criteria
contracts/credit-redeemer/createdFarmingPoolClient::get_credits(orcalculate_credits)set_credits_per_tokenadmin function for rate adjustmentreward_balancegetter returns contract's current token balance