Protocol Interaction Practical

mint

deposit_mint(_token:Principal,_amount_underlying:Nat) : async [T.TxReceipt]

Mints fTokens in the market of ID market_id to the caller. The amount depends on the current exchange rate and the underlying_amount specified. Returns:

#Ok: the total balance in underlying (fToken converted to underlying amount) the user has in the market. #Err: Insufficient Balance, if the user does not have enough underlying in the protocol.

redeem

redeem_withdraw(_token:Principal,_amount:Nat,_change_principal:Principal,_change_subaccount:?Blob):async [T.TxReceipt]

Converts fTokens in the market of ID market_id to the underlying asset, and stores it in the book. The amount depends on the current exchange rate and the amount specified. Returns:

#Ok: The current amount owned by the user, still in the market, as the underlying asset. #Err: Unauthorized, if a user tries to redeem while using the fTokens as collateral for a borrow.

declare token as collateral

enter_market(_token : Principal) : async T.TxReceipt

Locks the value the user has in the market of ID market_id as collateral for a borrow. This allows us to offer users the ability to borrow against certain assets instead of risking their entire portfolio. Returns: NULL type

remove token as collateral

exit_market(market_id : Principal) : async T.TxReceipt

Removes the user balance of market_id to be used as collateral. Will fail if user has a borrow open. Returns: NULL type

borrow

Note: If you have any amount of lent balance open for this borrow, you will not be able to borrow any additional amount.

borrow_withdraw(_token:Principal,_amount:Nat,_change_principal:Principal,_change_subaccount:?Blob):async [T.TxReceipt]

Opens a borrow position in market_id of the size amount. Returns:

#Ok: The total borrow balance the user has in market of ID '_token'

repay

borrow_withdraw(_token:Principal,_amount:Nat,_change_principal:Principal,_change_subaccount:?Blob):async [T.TxReceipt]

Repays a borrow of the size underlying_token_amount in the market _token. Can partially repay an open borrow. Returns:

#Ok: Remaining borrow balance. #Err: Insufficient Balance, if a user tries to repay with not enough book balance/borrow balance.

liquidate

liquidate(_collateral_token:T.Token,_borrowed_token:T.Token,_borrower:Principal,_underlying_token_amount:Nat):async T.TxReceipt

Liquidates _borrower and gives the collateral to the caller.

#Ok: Remaining fToke balance. #Err: Insufficient Balance - Token Not Found - Principal Not Found (wrong borrower ID)

redeem_liquidator

redeem_liquidator(_token:T.Token, _amount:Nat):async T.TxReceipt

Last updated