Protocol Interaction Practical

Mint

mint(market_id : Principal, underlying_amount : 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

mint(market_id : Principal, amount : Nat) : 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/remove as collateral

enter_market(market_id : Principal) : async ()

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

And to remove an asset:

exit_market(market_id : Principal) : async ()

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(_token : Principal, _amount : Nat) : 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

repay(_token : Principal, _underlying_token_amount : Nat) : 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)

Last updated