Fraction ProtocolgenericFacetspriceFacetsstablePriceFacet

OraclePriceFacetStorage

This library manages the storage and logic for the configuration of fraction pricing in terms of funding packets (a.k.a input packets) within fractionalization campaigns.

_This implementation is designed for use in campaigns where the price of fractions are set by an Oracle and may vary throughout the campaign lifecycle. Each campaign is configured separately.

IMPORTANT:

  • Extra care should be taken when setting the price of a fraction in a campaign (see setAndCheckPriceFacet()) as it is closely tied to the configuration of the campaign's funding packet (see FundingPackets facets)._

InvalidPriceZero

error InvalidPriceZero()

Thrown when attempting to set price as zero.

InvalidZeroAddress

error InvalidZeroAddress()

Thrown when the zero address is provided as input.

OnlyOracleCaller

error OnlyOracleCaller(address invalidCaller)

Thrown when the caller is not the oracle address.

STORAGE_SLOT

bytes32 STORAGE_SLOT

Unique identifier for the storage slot where the Layout struct is stored. Derived from the ERC7201 formula. STORAGE_SLOT: TO_DO

Layout

struct Layout {
  mapping(uint256 => uint256) campaignsPrice;
  address oracleAddress;
}

layout

function layout() internal pure returns (struct OraclePriceFacetStorage.Layout l)

Retrieves a reference to the Layout struct stored at a specified storage slot

setAndCheckPriceFacet

function setAndCheckPriceFacet(struct OraclePriceFacetStorage.Layout l, bytes postFractionPriceData) internal returns (address)

Sets the oracle address cappable to set the price of a fraction, in terms of funding packets, for a campaign.

_Defines the oracle address as the address that is allowed to set the price of a fraction in an associated campaign.

Emits a {OracleAddressConfigured} event._

Parameters

NameTypeDescription
lstruct OraclePriceFacetStorage.LayoutA reference to the Layout struct in storage.
postFractionPriceDatabytesThe ABI-encoded data containing the following: - oracleAddress: The address of the oracle that will set the price of a fraction in an associated campaign.

Return Values

NameTypeDescription
[0]addressaddress The oracle address.

setPrice

function setPrice(struct OraclePriceFacetStorage.Layout l, uint256 campaignId, uint256 price) internal

Sets the price of a fraction, in terms of funding packets, for a campaign.

_Defines the price as the number of funding packets required to purchase a single fraction in an associated campaign.

This function is callable only by the oracle address set in setAndCheckPriceFacet().

Emits a {CampaignPriceConfigured} event.

IMPORTANT:

There are two ways to configure price and funding packets at the API level, depending on the decimal precision of tokens in the campaign's funding packet:

  1. Uniform Decimal Precision (All funding tokens have the same decimal precision—no mixed ERCs allowed):

    • Either:
      • Set the funding packet's tokenAmount values (see FundingPackets Facets) in whole units (e.g., 2 wei).
      • Set price scaled by the token’s decimal precision (e.g., for 6 decimals, price = 10 * 10^6).
    • Or:
      • Set tokenAmount values already scaled by the decimal precision (e.g., 2 * 10^6).
      • Set price in whole units (e.g., price = 10).
  2. Mixed Decimal Precision (Funding tokens have different decimal precision-mixed ERCs allowed):

    • The tokenAmount values in the funding packet must always be scaled to the respective decimal precision.
    • The price must be set in whole units.

Discount & Interest Mechanisms:

  • If discount & interest mechanisms are configured, the tokenAmount(s) of funding packet must be defined in whole units (e.g., 2 wei), and price must always be scaled according to the funding token decimal precision (e.g., for 6 decimals, price = 10 * 10^6). This requirement should be enforced at the API level and within front-end applications.

  • To prevent truncation, price should be scaled by at least 1e6, considering that percentages are 1e6 scaled.

  • This ensures that percentage-based discount & interest mechanisms (e.g., BurnFungibleForDiscount) can correctly compute discounted and interest-adjusted prices without truncation. Percentages are based on 10^6, meaning 10^6 == 100%.


Example:

  • If the campaign's funding packet has been configured (see FundingPackets Facets) as 2 wei of $TOKEN (suppose $TOKEN has 18 decimals), and price == 1 * 10^18, then to purchase a single fraction, investors will need to provide 10^18 funding packets which corresponds to 2 $TOKEN per fraction (2 wei * 10^18 == 2 * 10^18)._

Parameters

NameTypeDescription
lstruct OraclePriceFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted campaign.
priceuint256The price (in terms of funding packets) required to purchase a single fraction.

getCurrentPrice

function getCurrentPrice(struct OraclePriceFacetStorage.Layout l, uint256 campaignId) internal view returns (uint256)

Retrieves the price of a single fraction within a specified campaign.

Parameters

NameTypeDescription
lstruct OraclePriceFacetStorage.LayoutA reference to the Layout struct in storage.
campaignIduint256The unique identifier of the targeted campaign.

Return Values

NameTypeDescription
[0]uint256uint256 The amount of funding packets required to purchase a single fraction in campaignId.

On this page