USX Controller

The mintUSX function mints and transfers USX from the protocol to the user, and adds a borrow balance. The amount minted must be less than the user's Account Liquidity and the mint USX limit.

function mintUSX(uint mintUSXAmount) returns (uint)
  • msg.sender: The account to which minted USX shall be transferred.
  • mintUSXAmount: The amount of the USX to be minted.
  • RETURN: 0 on success, otherwise an Error code

USXController usxController = USXController(0x0040...);
require(sToken.borrow(100) == 0, "got collateral and has usx mint rate?");

const usxController = USXController.at(0x0040...);
await usxController.methods.mintUSX(50).send({from: 0xMyAccount});

The repay function transfers USX into the protocol and burn, reducing the user's borrow balance.

function repayUSX(uint repayUSXAmount) returns (uint)
  • msg.sender: The account which minted the USX, and shall repay the USX.
  • borrowAmount: The amount of the USX to be repaid.
  • RETURN: 0 on success, otherwise an Error code
Before repaying an asset, users must first approve the USX to access their USX balance.

USXController usxController = USXController(0x0040...);
require(usxController.repayUSX.value(100)() == 0, "transfer approved?");

const usxController = USXController.at(0x0040...);
usxController.methods.repayUSX(10000).send({from: ...});

A user who has negative account liquidity is subject to liquidation by other users of the protocol to return his/her account liquidity back to positive (i.e. above the collateral requirement). When a liquidation occurs, a liquidator may repay some or all of an outstanding borrow on behalf of a borrower and in return receive a discounted amount of collateral held by the borrower; this discount is defined as the liquidation incentive.
A liquidator may close up to a certain fixed percentage (i.e. close factor) of any individual outstanding borrow of the underwater account. Liquidators must interact with USXUnitroller contract in which they wish to repay USX and seize another asset as collateral. When collateral is seized, the liquidator is transferred sTokens, which they may redeem the same as if they had supplied the asset themselves. Users must approve USX contract before calling liquidateUSX, as they are transferring funds into the contract.

function liquidateUSX(address borrower, uint amount, address collateral) returns (uint)
  • msg.sender: The account which shall liquidate the borrower by repaying their USX and seizing their collateral.
  • borrower: The account with negative account liquidity that shall be liquidated.
  • repayAmount: The amount of the minted USX to be repaid and converted into collateral.
  • sTokenCollateral: The address of the sToken currently held as collateral by a borrower, that the liquidator shall seize.
  • RETURN: 0 on success, otherwise an Error code
Before supplying USX, users must first approve the USXController to access their USX balance.

USXController usxController = USXController(0x0040...);
SBep20 sTokenCollateral = SBep20(0xfD58...);
require(sToken.liquidateUSX(0xBorrower, 100, sTokenCollateral) == 0, "borrower underwater??");

const usxController = USXController.at(0x0040...);
const xTokenCollateral = SBep20.at(0xfD58...);
await usxController.methods.liquidateUSX(0xBorrower, 33, sTokenCollateral).send({from: 0xLiquidator})

Event
Description
MintUSX(address minter, uint mintUSXAmount)
Emitted upon a successful MintUSX.
RepayMAI(address payer, address borrower, uint repayAmount)
Emitted upon a successful RepayUSX.
LiquidateUSX(address liquidator, address borrower, uint repayAmount, address sTokenCollateral, uint seizeTokens)
Emitted upon a successful LiquidateUSX.

Code
Name
Description
0
NO_ERROR
Not a failure.
1
UNAUTHORIZED
The sender is not authorized to perform this action.
2
REJECTION
The action would violate the comptroller, usxcontroller policy.
3
SNAPSHOT_ERROR
The comptroller could not get the account borrows and exchange rate from the market.
4
PRICE_ERROR
The comptroller could not obtain a required price of an asset.
5
MATH_ERROR
A math calculation error occurred.
6
MARKET_NOT_FRESH
Interest has not been properly accrued.
7
INSUFFICIENT_BALANCE_FOR_USX
Caller does not have sufficient balance to mint USX.

Text
Name
0
SET_PENDING_ADMIN_OWNER_CHECK
1
SET_PENDING_IMPLEMENTATION_OWNER_CHECK
2
SET_COMPTROLLER_OWNER_CHECK
3
ACCEPT_ADMIN_PENDING_ADMIN_CHECK
4
ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK
5
USX_MINT_REJECTION
6
USX_BURN_REJECTION
7
USX_LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED
8
USX_LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED
9
USX_LIQUIDATE_COLLATERAL_FRESHNESS_CHECK
10
USX_LIQUIDATE_COMPTROLLER_REJECTION
11
USX_LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED
12
USX_LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX
13
USX_LIQUIDATE_CLOSE_AMOUNT_IS_ZERO
14
USX_LIQUIDATE_FRESHNESS_CHECK
15
USX_LIQUIDATE_LIQUIDATOR_IS_BORROWER
16
USX_LIQUIDATE_REPAY_BORROW_FRESH_FAILED
17
USX_LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED
18
USX_LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED
19
USX_LIQUIDATE_SEIZE_COMPTROLLER_REJECTION
20
USX_LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER
21
USX_LIQUIDATE_SEIZE_TOO_MUCH
22
MINT_FEE_CALCULATION_FAILED
23
SET_TREASURY_OWNER_CHECK
Copy link
On this page
MintUSX
RepayUSX
LiquidateUSX
Key Events
Error Codes
Failure Info