Fund

It is a utility struct to easily know how many shares to issue/burn based on an underlying amount.

Structs

Account

struct Fund has store, copy, drop {
    shares: u128,
    underlying: u128
 }
  • shares - The amount of shares issued based on the underlying amount.

  • underlying - The amount of assets in the fund.

Interface

empty

Creates an empty Fund.

public fun empty(): Fund
  • @return Fund.

underlying

Returns the amount of underlying in the self.

public fun underlying(self: &Fund): u64
  • @param self: A Fund.

  • @return u64. The amount of underlying.

shares

Returns the amount of shares in the self.

public fun shares(self: &Fund): u64
  • @param self: A Fund.

  • @return u64. The amount of shares.

to_shares

Returns the number of shares the self would issue if more underlying was deposited in it.

public fun to_shares(self: &Fund, underlying: u64, round_up: bool): u64
  • @param self: A Fund.

  • @param underlying: The amount of underlying that the caller intends to add to the self.

  • @param round_up: If true we would round up the returned value.

  • @return u64. The amount of shares the fund would issue.

to_underlying

Returns the number of shares the self would issue if more underlying was deposited in it.

public fun to_underlying(rebase: &Fund, shares: u64, round_up: bool): u64
  • @param self: A Fund.

  • @param shares: The amount of shares that the caller intends to burn.

  • @param round_up: If true we would round up the returned value.

  • @return u64. The amount underlying the fund would release.

sub_shares

This function reduces the amount of underlying and shares in the fund.

public fun sub_shares(self: &mut Fund, shares: u64, round_up: bool): u64
  • @param self: A Fund.

  • @param shares: The amount of shares that the caller intends to burn.

  • @param round_up: If true we would round up the returned value.

  • @return u64. The amount underlying the shares were worth.

add_underlying

Adds underlying to the self and returns the additional shares issued. This function increases the amount of underlying and shares in the fund.

public fun add_underlying(rebase: &mut Fund, underlying: u64, round_up: bool): u64
  • @param self: A Fund.

  • @param underlying: The amount of underlying to deposit in the self.

  • @param round_up: If true we would round up the returned value.

  • @return u64. The amount of shares the fund issued.

sub_underlying

Removes underlying from the self and returns the burned shares. This function reduces the amount of underlying and shares in the fund.

public fun sub_underlying(rebase: &mut Fund, underlying: u64, round_up: bool): u64
  • @param self: A Fund.

  • @param underlying: The amount of underlying to remove from the self.

  • @param round_up: If true we would round up the returned value.

  • @return u64. The amount of shares the fund burned.

add_profit

Adds profits to the underlying. This is to add profits to the fund.

public fun add_profit(rebase: &mut Fund, profit: u64)
  • @param self: A Fund.

  • @param profit: The amount of underlying to add as profit to self.underlying.

Last updated