AccountCap integration
Supply assets from a Move contract using a NAVI AccountCap and incentive v3.
Create an account with lending_core::lending::create_account(ctx) and store the returned AccountCap inside an object your contract controls. Pass a reference to the same cap when depositing and withdrawing so NAVI attributes both operations to the same position.
Code Snippet: Account Cap Integration
The following helper belongs inside your Move module. Its visibility is private so your module can apply its own access checks before using the cap.
use lending_core::account::AccountCap;
use lending_core::incentive_v2::Incentive as IncentiveV2;
use lending_core::incentive_v3::{Self, Incentive};
use lending_core::pool::Pool;
use lending_core::storage::Storage;
use sui::clock::Clock;
use sui::coin::Coin;
fun supply<CoinType>(
clock: &Clock,
storage: &mut Storage,
pool: &mut Pool<CoinType>,
asset: u8,
deposit_coin: Coin<CoinType>,
incentive_v2: &mut IncentiveV2,
incentive_v3: &mut Incentive,
cap: &AccountCap,
) {
incentive_v3::deposit_with_account_cap<CoinType>(
clock, storage, pool, asset, deposit_coin, incentive_v2, incentive_v3, cap,
)
}Select the pool, asset index, storage and both incentive objects from the same market. The v3 function still takes the v2 incentive object. Calling the deposit function in the old incentive_v2 module aborts on mainnet.
For withdrawals, call incentive_v3::withdraw_with_account_cap_v2 and handle its returned balance.