Skip to main content

JBTerminalStore

Git Source

Inherits: IJBTerminalStore

Manages all bookkeeping for inflows and outflows of funds from any terminal address.

This contract expects a project's controller to be an IJBController.

State Variables

_MAX_FIXED_POINT_FIDELITY

Constrains mulDiv operations on fixed point numbers to a maximum number of decimal points of persisted fidelity.

uint256 internal constant _MAX_FIXED_POINT_FIDELITY = 18;

DIRECTORY

The directory of terminals and controllers for projects.

IJBDirectory public immutable override DIRECTORY;

PRICES

The contract that exposes price feeds.

IJBPrices public immutable override PRICES;

RULESETS

The contract storing and managing project rulesets.

IJBRulesets public immutable override RULESETS;

balanceOf

A project's balance of a specific token within a terminal.

The balance is represented as a fixed point number with the same amount of decimals as its relative terminal.

mapping(address terminal => mapping(uint256 projectId => mapping(address token => uint256))) public override balanceOf;

usedPayoutLimitOf

The currency-denominated amount of funds that a project has already paid out from its payout limit during the current ruleset for each terminal, in terms of the payout limit's currency.

Increases as projects pay out funds.

The used payout limit is represented as a fixed point number with the same amount of decimals as the terminal it applies to.

mapping(
address terminal
=> mapping(
uint256 projectId
=> mapping(address token => mapping(uint256 rulesetCycleNumber => mapping(uint256 currency => uint256)))
)
) public override usedPayoutLimitOf;

usedSurplusAllowanceOf

The currency-denominated amounts of funds that a project has used from its surplus allowance during the current ruleset for each terminal, in terms of the surplus allowance's currency.

Increases as projects use their allowance.

The used surplus allowance is represented as a fixed point number with the same amount of decimals as the terminal it applies to.

mapping(
address terminal
=> mapping(
uint256 projectId
=> mapping(address token => mapping(uint256 rulesetId => mapping(uint256 currency => uint256)))
)
) public override usedSurplusAllowanceOf;

Functions

constructor

constructor(IJBDirectory directory, IJBPrices prices, IJBRulesets rulesets);

Parameters

NameTypeDescription
directoryIJBDirectoryA contract storing directories of terminals and controllers for each project.
pricesIJBPricesA contract that exposes price feeds.
rulesetsIJBRulesetsA contract storing and managing project rulesets.

currentReclaimableSurplusOf

Returns the number of surplus terminal tokens that would be reclaimed by cashing out a given project's tokens based on its current ruleset and the given total project token supply and total terminal token surplus.

function currentReclaimableSurplusOf(
uint256 projectId,
uint256 cashOutCount,
uint256 totalSupply,
uint256 surplus
)
external
view
override
returns (uint256);

Parameters

NameTypeDescription
projectIduint256The ID of the project whose project tokens would be cashed out.
cashOutCountuint256The number of project tokens that would be cashed out, as a fixed point number with 18 decimals.
totalSupplyuint256The total project token supply, as a fixed point number with 18 decimals.
surplusuint256The total terminal token surplus amount, as a fixed point number.

Returns

NameTypeDescription
<none>uint256The number of surplus terminal tokens that would be reclaimed, as a fixed point number with the same number of decimals as the provided surplus.

currentReclaimableSurplusOf

Returns the number of surplus terminal tokens that would be reclaimed from a terminal by cashing out a given number of tokens, based on the total token supply and total surplus.

The returned amount in terms of the specified terminal's base currency.

The returned amount is represented as a fixed point number with the same amount of decimals as the specified terminal.

function currentReclaimableSurplusOf(
uint256 projectId,
uint256 cashOutCount,
IJBTerminal[] calldata terminals,
JBAccountingContext[] calldata accountingContexts,
uint256 decimals,
uint256 currency
)
external
view
override
returns (uint256);

Parameters

NameTypeDescription
projectIduint256The ID of the project whose tokens would be cashed out.
cashOutCountuint256The number of tokens that would be cashed out, as a fixed point number with 18 decimals.
terminalsIJBTerminal[]The terminals that would be cashed out from. If this is the zero address, surplus within all the project's terminals are considered.
accountingContextsJBAccountingContext[]The accounting contexts of the surplus terminal tokens that would be reclaimed. Pass an empty array to use all of the project's accounting contexts.
decimalsuint256The number of decimals to include in the resulting fixed point number.
currencyuint256The currency that the resulting number will be in terms of.

Returns

NameTypeDescription
<none>uint256The amount of surplus terminal tokens that would be reclaimed by cashing out cashOutCount tokens.

currentSurplusOf

Gets the current surplus amount in a terminal for a specified project.

The surplus is the amount of funds a project has in a terminal in excess of its payout limit.

The surplus is represented as a fixed point number with the same amount of decimals as the specified terminal.

function currentSurplusOf(
address terminal,
uint256 projectId,
JBAccountingContext[] calldata accountingContexts,
uint256 decimals,
uint256 currency
)
external
view
override
returns (uint256);

Parameters

NameTypeDescription
terminaladdressThe terminal the surplus is being calculated for.
projectIduint256The ID of the project to get surplus for.
accountingContextsJBAccountingContext[]The accounting contexts of tokens whose balances should contribute to the surplus being calculated.
decimalsuint256The number of decimals to expect in the resulting fixed point number.
currencyuint256The currency the resulting amount should be in terms of.

Returns

NameTypeDescription
<none>uint256The current surplus amount the project has in the specified terminal.

currentTotalSurplusOf

Gets the current surplus amount for a specified project across all terminals.

function currentTotalSurplusOf(
uint256 projectId,
uint256 decimals,
uint256 currency
)
external
view
override
returns (uint256);

Parameters

NameTypeDescription
projectIduint256The ID of the project to get the total surplus for.
decimalsuint256The number of decimals that the fixed point surplus should include.
currencyuint256The currency that the total surplus should be in terms of.

Returns

NameTypeDescription
<none>uint256The current total surplus amount that the project has across all terminals.

_surplusFrom

Gets a project's surplus amount in a terminal as measured by a given ruleset, across multiple accounting contexts.

This amount changes as the value of the balance changes in relation to the currency being used to measure various payout limits.

function _surplusFrom(
address terminal,
uint256 projectId,
JBAccountingContext[] memory accountingContexts,
JBRuleset memory ruleset,
uint256 targetDecimals,
uint256 targetCurrency
)
internal
view
returns (uint256 surplus);

Parameters

NameTypeDescription
terminaladdressThe terminal the surplus is being calculated for.
projectIduint256The ID of the project to get the surplus for.
accountingContextsJBAccountingContext[]The accounting contexts of tokens whose balances should contribute to the surplus being calculated.
rulesetJBRulesetThe ID of the ruleset to base the surplus on.
targetDecimalsuint256The number of decimals to include in the resulting fixed point number.
targetCurrencyuint256The currency that the reported surplus is expected to be in terms of.

Returns

NameTypeDescription
surplusuint256The surplus of funds in terms of targetCurrency, as a fixed point number with targetDecimals decimals.

_tokenSurplusFrom

Get a project's surplus amount of a specific token in a given terminal as measured by a given ruleset (one specific accounting context).

This amount changes as the value of the balance changes in relation to the currency being used to measure the payout limits.

function _tokenSurplusFrom(
address terminal,
uint256 projectId,
JBAccountingContext memory accountingContext,
JBRuleset memory ruleset,
uint256 targetDecimals,
uint256 targetCurrency
)
internal
view
returns (uint256 surplus);

Parameters

NameTypeDescription
terminaladdressThe terminal the surplus is being calculated for.
projectIduint256The ID of the project to get the surplus of.
accountingContextJBAccountingContextThe accounting context of the token whose balance should contribute to the surplus being measured.
rulesetJBRulesetThe ID of the ruleset to base the surplus calculation on.
targetDecimalsuint256The number of decimals to include in the resulting fixed point number.
targetCurrencyuint256The currency that the reported surplus is expected to be in terms of.

Returns

NameTypeDescription
surplusuint256The surplus of funds in terms of targetCurrency, as a fixed point number with targetDecimals decimals.

recordAddedBalanceFor

Records funds being added to a project's balance.

function recordAddedBalanceFor(uint256 projectId, address token, uint256 amount) external override;

Parameters

NameTypeDescription
projectIduint256The ID of the project which funds are being added to the balance of.
tokenaddressThe token being added to the balance.
amountuint256The amount of terminal tokens added, as a fixed point number with the same amount of decimals as its relative terminal.

recordCashOutFor

Records a cash out from a project.

Cashs out the project's tokens according to values provided by the ruleset's data hook. If the ruleset has no data hook, cashs out tokens along a cash out bonding curve that is a function of the number of tokens being burned.

function recordCashOutFor(
address holder,
uint256 projectId,
uint256 cashOutCount,
JBAccountingContext calldata accountingContext,
JBAccountingContext[] calldata balanceAccountingContexts,
bytes memory metadata
)
external
override
returns (
JBRuleset memory ruleset,
uint256 reclaimAmount,
uint256 cashOutTaxRate,
JBCashOutHookSpecification[] memory hookSpecifications
);

Parameters

NameTypeDescription
holderaddressThe account that is cashing out tokens.
projectIduint256The ID of the project being cashing out from.
cashOutCountuint256The number of project tokens to cash out, as a fixed point number with 18 decimals.
accountingContextJBAccountingContextThe accounting context of the token being reclaimed by the cash out.
balanceAccountingContextsJBAccountingContext[]The accounting contexts of the tokens whose balances should contribute to the surplus being reclaimed from.
metadatabytesBytes to send to the data hook, if the project's current ruleset specifies one.

Returns

NameTypeDescription
rulesetJBRulesetThe ruleset during the cash out was made during, as a JBRuleset struct. This ruleset will have a cash out tax rate provided by the cash out hook if applicable.
reclaimAmountuint256The amount of tokens reclaimed from the terminal, as a fixed point number with 18 decimals.
cashOutTaxRateuint256The cash out tax rate influencing the reclaim amount.
hookSpecificationsJBCashOutHookSpecification[]A list of cash out hooks, including data and amounts to send to them. The terminal should fulfill these specifications.

recordPaymentFrom

Records a payment to a project.

Mints the project's tokens according to values provided by the ruleset's data hook. If the ruleset has no data hook, mints tokens in proportion with the amount paid.

function recordPaymentFrom(
address payer,
JBTokenAmount calldata amount,
uint256 projectId,
address beneficiary,
bytes calldata metadata
)
external
override
returns (JBRuleset memory ruleset, uint256 tokenCount, JBPayHookSpecification[] memory hookSpecifications);

Parameters

NameTypeDescription
payeraddressThe address that made the payment to the terminal.
amountJBTokenAmountThe amount of tokens being paid. Includes the token being paid, their value, the number of decimals included, and the currency of the amount.
projectIduint256The ID of the project being paid.
beneficiaryaddressThe address that should be the beneficiary of anything the payment yields (including project tokens minted by the payment).
metadatabytesBytes to send to the data hook, if the project's current ruleset specifies one.

Returns

NameTypeDescription
rulesetJBRulesetThe ruleset the payment was made during, as a JBRuleset struct.
tokenCountuint256The number of project tokens that were minted, as a fixed point number with 18 decimals.
hookSpecificationsJBPayHookSpecification[]A list of pay hooks, including data and amounts to send to them. The terminal should fulfill these specifications.

recordPayoutFor

Records a payout from a project.

function recordPayoutFor(
uint256 projectId,
JBAccountingContext calldata accountingContext,
uint256 amount,
uint256 currency
)
external
override
returns (JBRuleset memory ruleset, uint256 amountPaidOut);

Parameters

NameTypeDescription
projectIduint256The ID of the project that is paying out funds.
accountingContextJBAccountingContextThe context of the token being paid out.
amountuint256The amount to pay out (use from the payout limit), as a fixed point number.
currencyuint256The currency of the amount. This must match the project's current ruleset's currency.

Returns

NameTypeDescription
rulesetJBRulesetThe ruleset the payout was made during, as a JBRuleset struct.
amountPaidOutuint256The amount of terminal tokens paid out, as a fixed point number with the same amount of decimals as its relative terminal.

recordTerminalMigration

Records the migration of funds from this store.

function recordTerminalMigration(uint256 projectId, address token) external override returns (uint256 balance);

Parameters

NameTypeDescription
projectIduint256The ID of the project being migrated.
tokenaddressThe token being migrated.

Returns

NameTypeDescription
balanceuint256The project's current balance (which is being migrated), as a fixed point number with the same amount of decimals as its relative terminal.

recordUsedAllowanceOf

Records a use of a project's surplus allowance.

When surplus allowance is "used", it is taken out of the project's surplus within a terminal.

function recordUsedAllowanceOf(
uint256 projectId,
JBAccountingContext calldata accountingContext,
uint256 amount,
uint256 currency
)
external
override
returns (JBRuleset memory ruleset, uint256 usedAmount);

Parameters

NameTypeDescription
projectIduint256The ID of the project to use the surplus allowance of.
accountingContextJBAccountingContextThe accounting context of the token whose balances should contribute to the surplus allowance being reclaimed from.
amountuint256The amount to use from the surplus allowance, as a fixed point number.
currencyuint256The currency of the amount. Must match the currency of the surplus allowance.

Returns

NameTypeDescription
rulesetJBRulesetThe ruleset during the surplus allowance is being used during, as a JBRuleset struct.
usedAmountuint256The amount of terminal tokens used, as a fixed point number with the same amount of decimals as its relative terminal.

Errors

JBTerminalStore_InadequateControllerAllowance

error JBTerminalStore_InadequateControllerAllowance(uint256 amount, uint256 allowance);

JBTerminalStore_InadequateControllerPayoutLimit

error JBTerminalStore_InadequateControllerPayoutLimit(uint256 amount, uint256 limit);

JBTerminalStore_InadequateTerminalStoreBalance

error JBTerminalStore_InadequateTerminalStoreBalance(uint256 amount, uint256 balance);

JBTerminalStore_InsufficientTokens

error JBTerminalStore_InsufficientTokens(uint256 count, uint256 totalSupply);

JBTerminalStore_InvalidAmountToForwardHook

error JBTerminalStore_InvalidAmountToForwardHook(uint256 amount, uint256 paidAmount);

JBTerminalStore_RulesetNotFound

error JBTerminalStore_RulesetNotFound();

JBTerminalStore_RulesetPaymentPaused

error JBTerminalStore_RulesetPaymentPaused();

JBTerminalStore_TerminalMigrationNotAllowed

error JBTerminalStore_TerminalMigrationNotAllowed();