Kujira.Usk.Position (kujira v0.1.47)

An item representing the collateral deposit vs debt position of a particular address for a particular market

Fields

  • :market - The market where the position is held

  • :holder - The address that owns the position

  • :collateral_amount - The amount of collateral_token that has been deposited

  • :mint_amount - The amount of USK minted and owed by this position

  • :interest_amount - The amount of USK owed in interest. This is ultimately deducted from the collateral during a collateral deposit, withdrawal, or liquidation

  • :debt_amount - The total amount of USK owed - mint_amount + interest_amount

Summary

Types

The direction of the adjustment to the Position: collateral deposit, collateral withdrawal, debt borrow (mint), debt repay (burn)

t()

Functions

Returns all adjustments to positions found in the tx response

Calculates a liquidation price for a given position. Quoted in terms of the underlying token decimals

Types

Link to this type

adjustment()

@type adjustment() :: :deposit | :withdrawal | :borrow | :repay

The direction of the adjustment to the Position: collateral deposit, collateral withdrawal, debt borrow (mint), debt repay (burn)

TODO: Add :liquidation

@type t() :: %Kujira.Usk.Position{
  collateral_amount: integer(),
  debt_amount: integer(),
  holder: String.t(),
  interest_amount: integer(),
  market: {Kujira.Usk.Market, String.t()},
  mint_amount: integer()
}

Functions

Link to this function

from_query(market, arg2)

@spec from_query(Kujira.Usk.Market.t(), map()) :: :error | {:ok, t()}
Link to this function

from_tx_response(response)

@spec from_tx_response(Cosmos.Base.Abci.V1beta1.TxResponse.t()) ::
  [{{Kujira.Usk.Market, String.t()}, String.t(), adjustment()}] | nil

Returns all adjustments to positions found in the tx response

Link to this function

liquidation_price(position, arg2)

@spec liquidation_price(Position.t(), Kujira.Usk.Market.t()) :: Decimal.t()

Calculates a liquidation price for a given position. Quoted in terms of the underlying token decimals

TODO: Load current and historic interest rates. Calculate accrued interest

Token where decimals are similar - eg a loan of 1 USDC against 1 KUJI where max ltv is 0.6

iex> Kujira.Usk.Position.liquidation_price( ...> %Kujira.Usk.Position{debt_amount: 1_000_000, collateral_amount: 1_000_000}, ...> %Kujira.Usk.Market{max_ltv: Decimal.from_float(0.6)} ...>) Decimal.new("1.666666666666666666666666667")

And eg 1 wETH with 1000 USDC debt. Liq price should be 1666, which with a 12 dp decimal delta is 0.000000001666

iex> Kujira.Usk.Position.liquidation_price( ...> %Kujira.Usk.Position{debt_amount: 1_000_000_000, collateral_amount: 1_000_000_000_000_000_000}, ...> %Kujira.Usk.Market{max_ltv: Decimal.from_float(0.6)} ...>) Decimal.new("1.666666666666666666666666667E-9")