Account Cap

Our AccountCap allows you to operate NAVI with a smart contract. It could be used when engaging in positions or strategies through contracts on the NAVI platform.

Firstly, you need to create a custodian account from the lending module in our lending_core package.

public fun create_account(ctx: &mut TxContext): AccountCap

After generating a custodian account by invoking create_account and obtaining an AccountCap object, which authorizes access to the custodian account, you can interact with the NAVI protocol through the incentive_v2 module using the provided interfaces. You can obtain the necessary parameters from here.

  public fun deposit_with_account_cap<CoinType>(
        clock: &Clock,
        storage: &mut Storage,
        pool: &mut Pool<CoinType>,
        asset: u8,
        deposit_coin: Coin<CoinType>,
        incentive_v1: &mut IncentiveV1,
        incentive_v2: &mut Incentive,
        account_cap: &AccountCap
    )
    
    public fun borrow_with_account_cap<CoinType>(
        clock: &Clock,
        oracle: &PriceOracle,
        storage: &mut Storage,
        pool: &mut Pool<CoinType>,
        asset: u8,
        amount: u64,
        incentive: &mut Incentive,
        account_cap: &AccountCap
    ): Balance<CoinType> 
    
    public fun repay_with_account_cap<CoinType>(
        clock: &Clock,
        oracle: &PriceOracle,
        storage: &mut Storage,
        pool: &mut Pool<CoinType>,
        asset: u8,
        repay_coin: Coin<CoinType>,
        incentive: &mut Incentive,
        account_cap: &AccountCap
    ): Balance<CoinType> 
    
    public fun withdraw_with_account_cap<CoinType>(
        clock: &Clock,
        oracle: &PriceOracle,
        storage: &mut Storage,
        pool: &mut Pool<CoinType>,
        asset: u8,
        amount: u64,
        incentive_v1: &mut IncentiveV1,
        incentive_v2: &mut Incentive,
        account_cap: &AccountCap
    ): Balance<CoinType>
    
    public fun claim_reward_with_account_cap<T>(
        clock: &Clock,
        incentive: &mut Incentive,
        funds_pool: &mut IncentiveFundsPool<T>,
        storage: &mut Storage,
        asset_id: u8,
        option: u8,
        account_cap: &AccountCap): Balance<T> 

Here is an example contract to interact with NAVI

module example::account_example {
    use sui::object::{Self, UID};
    use sui::clock::{Clock};
    use sui::transfer::{Self};
    use sui::tx_context::{TxContext};
    use lending_core::account::{AccountCap};
    use lending_core::lending::{Self};

    use lending_core::pool::{Pool};
    use sui::coin::{Coin};
    use lending_core::incentive::{Incentive as IncentiveV1};
    use lending_core::incentive_v2::{Self as incentive_v2, Incentive as IncentiveV2};
    use lending_core::storage::{Storage};

    struct MyStruct has key, store {
        id: UID,
        navi_account: AccountCap
    }

    fun init(ctx: &mut TxContext) {
        let cap = lending::create_account(ctx);
        transfer::share_object(MyStruct{id: object::new(ctx), navi_account: cap})
    }

    public fun deposit<CoinType>(me: &MyStruct, clock: &Clock, storage: &mut Storage, pool: &mut Pool<CoinType>, asset: u8, deposit_coin: Coin<CoinType>, incentive_v1: &mut IncentiveV1, incentive_v2: &mut IncentiveV2) {
        incentive_v2::deposit_with_account_cap(clock, storage, pool, asset, deposit_coin, incentive_v1, incentive_v2, &me.navi_account)
    }
}

Refer GitHub example for more details

Refer Contract Address for a complete list of addresses

Last updated