Margin Account

Collateral Types

Hubble is built to support multiple collaterals. Here we list the collateral types that are currently supported.

1. Hubble USD (hUSD)

hUSD is hubble’s unit of accounting. Trading fee, liquidation fee and pnl are denominated in hUSD. It’s not mandatory to have hUSD to trade. It’s possible to post margin in any of the supported collaterals. However, since trading fee/PnL are still charged in hUSD, it’s possible to have a negative hUSD balance.

It is possible to mint hUSD with USDC at any time.

Mint

// contract: VUSDfunction mintWithReserve(address to, uint amount) external;

After the user has attained hUSD, it can be posted as margin, deposited in insurance fund and used to perform margin account liquidations.

Note that hUSD is backed by a combination of all the supported collaterals. Consider the following scenario:

  • Say there are 2 traders, Alice and Bob
  • Alice has a profitable position and realizes their PnL in form of hUSD margin.
  • It’s possible that Bob still has open positions and has not yet realized their -ve PnL.
  • In that case we'll take a credit from hUSD contract (i.e. mint hUSD), which will eventually be returned when Bob pays their debt back.

Withdraw

For the reasons outlined above, hUSD → USDC withdraws are queued on first come first serve basis. a call to withdraw will push your withdrawal request to the end of the Q. To prevent a DDOS, a min withdraw amount of 5 vUSD has been imposed.

// contract: VUSDfunction withdraw(uint amount) external whenNotPaused {      require(amount >= 5 * (10 ** PRECISION), "min withdraw is 5 vusd");      burn(amount);      withdrawals.push(Withdrawal(msg.sender, amount));}

Process Withdrawals

Any one is free to call processWithdrawals which processes all the withdrawals that are possible to be executed with the amount of USDC on the hUSD contract. Up to a max of 100 withdrawals can be executed at once.

// contract: VUSDfunction processWithdrawals() external;

2. Avalanche (AVAX)

  • Needless to say the very first (non usd) collateral leveraging Hubble’s multi-collateral design is Avax. Avax posted as margin acts as a collateral that can be utilized for both trading and making (LP). The collateral weight for Avax is 0.8 which means that you have a margin of $80 on $100 worth of Avax deposited. This acts as a cushion so that users don’t get liquidated in events of price volatility.
  • Since Hubble allows for a max of 5x leverage, so the free margin on $100 worth of collateral is calculated $100 * 0.8 * 5 = $400.
  • Note that max leverage and collateral weight are configurable parameters which can be changed in the future.

3. Wrapper ETH (Weth.e)

On Sep 13, 2022, ETH was added as supported collateral to Hubble. Also has a weight of 0.8


Margin Account

Add Margin

// contract: MarginAccount/*** @notice Post margin* @param idx Index of the supported collateral* @param amount Amount to deposit (scaled same as the asset)*/function addMargin(uint idx, uint amount) external;

Variant

// contract: MarginAccount/*** @notice Post margin for another account* @param idx Index of the supported collateral* @param amount Amount to deposit (scaled same as the asset)* @param to Account to post margin for*/function addMarginFor(uint idx, uint amount, address to) public {    require(amount > 0, "Add non-zero margin");    // will revert for idx >= supportedCollateral.length    supportedCollateral[idx].token.safeTransferFrom(_msgSender(), address(this), amount);    margin[idx][to] += amount.toInt256();    emit MarginAdded(to, idx, amount);}

Remove Margin

// contract: MarginAccount/*** @notice Withdraw margin.*   Collateral can not be withdrawn if vUSD balance is < 0.* @dev If the contract has insufficient vUSD balance, a loan is taken from the vUSD contract.* @param idx Index of the supported collateral* @param amount Amount to withdraw (scaled same as the asset)*/function removeMargin(uint idx, uint256 amount) external;

Query Margin Balances

// contract: HubbleViewer/*** @notice get user margin for all collaterals* Takes the pending funding amount into account but not the unrealized PnL* @return Array of deposited margin where [0] is hUSD, [1] is avax, [2] is weth.e with precision 6, 18, 18 respectively*/function userInfo(address trader) external view returns(int256[] memory);