Kujira.Bow (kujira v0.1.80)

Kujira's on-chain Market Maker for FIN.

Summary

Functions

Fetches the Leverage contract and its current config from the chain

Fetches the Pool contract and its current config from the chain

Loads all positions via query_state_all, inheriting the same memoization

Fetches all Leverage markets

Loads the Leverage Market into a format that Orca can consume for health reporting. Default Memoization to 10 mins.

Loads the current pool status onto the pool

Functions

Link to this function

get_leverage(channel, address)

@spec get_leverage(Channel.t(), String.t()) ::
  {:ok, Kujira.Bow.Leverage.t()} | {:error, :not_found}

Fetches the Leverage contract and its current config from the chain

Link to this function

get_pool(channel, address)

@spec get_pool(Channel.t(), String.t()) ::
  {:ok, Kujira.Bow.Pool.t()} | {:error, :not_found}

Fetches the Pool contract and its current config from the chain

Link to this function

list_all_positions(channel, leverage)

@spec list_all_positions(GRPC.Channel.t(), Kujira.Bow.Leverage.t()) :: [
  Kujira.Bow.Leverage.Position.t()
]

Loads all positions via query_state_all, inheriting the same memoization

Link to this function

list_leverage(channel, code_ids \\ [337])

@spec list_leverage(GRPC.Channel.t(), [integer()]) ::
  {:ok, [Kujira.Bow.Leverage.t()]} | {:error, GRPC.RPCError.t()}

Fetches all Leverage markets

Link to this function

list_pools(channel, code_ids \\ [54, 126, 294, 158, 167, 161, 166])

@spec list_pools(GRPC.Channel.t(), [integer()]) ::
  {:ok, [Kujira.Bow.Pool.t()]} | {:error, GRPC.RPCError.t()}

Fetches all Pools

Link to this function

list_positions(channel, leverage, address)

Loads all user positions

Link to this function

load_orca_markets(channel, market, precision \\ 3)

@spec load_orca_markets(Channel.t(), Kujira.Bow.Leverage.t(), integer() | nil) ::
  {:ok, {Kujira.Orca.Market.t(), Kujira.Orca.Market.t()}}
  | {:error, GRPC.RPCError.t()}

Loads the Leverage Market into a format that Orca can consume for health reporting. Default Memoization to 10 mins.

This returns a {base, quote} tuple that represents the risk on both sides of liquidation

The liquidation price of a position is dependent on the algorithm of the BOW pool.

The liquidation price of a leveraged position on an XYK pool is defined as (loan_b - (max_ltv size_b)) / ((max_ltv size_a) - loan_a)

This will demonstrate that the closer loan_b / loan_a is to size_b / size_a (and therefore the current price of the asset), the more extreme the price deviation required to reach max LTV. In some cases, eg when loan_b / loan_a == size_b / size_a, the value of the debt tracks the value of the collateral exactly, and as such the loan cannot be liquidated through price movement

Finally, the at-risk collateral amount is determined as the net collateral amount required to be sold at the liquidation price E.g. a position with 1000 KUJI and 500 USDC collateral, 100 KUJI and 500 USDC debt, has a liquidation price of 0.1923 At this price, we have ~ 1612 KUJI and 310 USDC as collateral. The USDC debt has a defecit of 190, which must be covered from the KUJI side of the collateral, so the at-risk collateral is 190 / 0.1923 ~= 988

Link to this function

load_pool(channel, pool)

@spec load_pool(Channel.t(), Kujira.Bow.Pool.Xyk.t()) ::
  {:ok, Kujira.Bow.Pool.Xyk.t()} | {:error, :not_found}
@spec load_pool(Channel.t(), Kujira.Bow.Pool.Stable.t()) ::
  {:ok, Kujira.Bow.Pool.Stable.t()} | {:error, :not_found}
@spec load_pool(Channel.t(), Kujira.Bow.Pool.Lsd.t()) ::
  {:ok, Kujira.Bow.Pool.Lsd.t()} | {:error, :not_found}

Loads the current pool status onto the pool