JBMultiTerminal
Inherits: JBPermissioned, ERC2771Context, IJBMultiTerminal
JBMultiTerminal
manages native/ERC-20 payments, cash outs, and surplus allowance usage for any number of
projects. Terminals are the entry point for operations involving inflows and outflows of funds.
State Variables
FEE
This terminal's fee (as a fraction out of JBConstants.MAX_FEE
).
Fees are charged on payouts to addresses and surplus allowance usage, as well as cash outs while the cash out tax rate is less than 100%.
uint256 public constant override FEE = 25;
_FEE_BENEFICIARY_PROJECT_ID
Project ID #1 receives fees. It should be the first project launched during the deployment process.
uint256 internal constant _FEE_BENEFICIARY_PROJECT_ID = 1;
_FEE_HOLDING_SECONDS
The number of seconds fees can be held for.
uint256 internal constant _FEE_HOLDING_SECONDS = 2_419_200;
DIRECTORY
The directory of terminals and controllers for PROJECTS.
IJBDirectory public immutable override DIRECTORY;
FEELESS_ADDRESSES
The contract that stores addresses that shouldn't incur fees when being paid towards or from.
IJBFeelessAddresses public immutable override FEELESS_ADDRESSES;
PERMIT2
The permit2 utility.
IPermit2 public immutable override PERMIT2;
PROJECTS
Mints ERC-721s that represent project ownership and transfers.
IJBProjects public immutable override PROJECTS;
RULESETS
The contract storing and managing project rulesets.
IJBRulesets public immutable override RULESETS;
SPLITS
The contract that stores splits for each project.
IJBSplits public immutable override SPLITS;
STORE
The contract that stores and manages the terminal's data.
IJBTerminalStore public immutable override STORE;
TOKENS
The contract storing and managing project rulesets.
IJBTokens public immutable override TOKENS;
_accountingContextForTokenOf
Context describing how a token is accounted for by a project.
mapping(uint256 projectId => mapping(address token => JBAccountingContext)) internal _accountingContextForTokenOf;
_accountingContextsOf
A list of tokens accepted by each project.
mapping(uint256 projectId => JBAccountingContext[]) internal _accountingContextsOf;
_heldFeesOf
Fees that are being held for each project.
Projects can temporarily hold fees and unlock them later by adding funds to the project's balance.
Held fees can be processed at any time by this terminal's owner.
mapping(uint256 projectId => mapping(address token => JBFee[])) internal _heldFeesOf;
_nextHeldFeeIndexOf
The next index to use when processing a next held fee.
mapping(uint256 projectId => mapping(address token => uint256)) internal _nextHeldFeeIndexOf;
Functions
constructor
constructor(
IJBFeelessAddresses feelessAddresses,
IJBPermissions permissions,
IJBProjects projects,
IJBSplits splits,
IJBTerminalStore store,
IJBTokens tokens,
IPermit2 permit2,
address trustedForwarder
)
JBPermissioned(permissions)
ERC2771Context(trustedForwarder);
Parameters
Name | Type | Description |
---|---|---|
feelessAddresses | IJBFeelessAddresses | A contract that stores addresses that shouldn't incur fees when being paid towards or from. |
permissions | IJBPermissions | A contract storing permissions. |
projects | IJBProjects | A contract which mints ERC-721s that represent project ownership and transfers. |
splits | IJBSplits | A contract that stores splits for each project. |
store | IJBTerminalStore | A contract that stores the terminal's data. |
tokens | IJBTokens | |
permit2 | IPermit2 | A permit2 utility. |
trustedForwarder | address | A trusted forwarder of transactions to this contract. |
accountingContextForTokenOf
A project's accounting context for a token.
See the JBAccountingContext
struct for more information.
function accountingContextForTokenOf(
uint256 projectId,
address token
)
external
view
override
returns (JBAccountingContext memory);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get token accounting context of. |
token | address | The token to check the accounting context of. |
Returns
Name | Type | Description |
---|---|---|
<none> | JBAccountingContext | The token's accounting context for the token. |
accountingContextsOf
The tokens accepted by a project.
function accountingContextsOf(uint256 projectId) external view override returns (JBAccountingContext[] memory);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the accepted tokens of. |
Returns
Name | Type | Description |
---|---|---|
<none> | JBAccountingContext[] | tokenContexts The accounting contexts of the accepted tokens. |
currentSurplusOf
Gets the total current surplus amount in this terminal for a project, in terms of a given currency.
This total surplus only includes tokens that the project accepts (as returned by
accountingContextsOf(...)
).
function currentSurplusOf(
uint256 projectId,
JBAccountingContext[] memory accountingContexts,
uint256 decimals,
uint256 currency
)
external
view
override
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the current total surplus of. |
accountingContexts | JBAccountingContext[] | The accounting contexts to use to calculate the surplus. Pass an empty array to use all of the project's accounting contexts. |
decimals | uint256 | The number of decimals to include in the fixed point returned value. |
currency | uint256 | The currency to express the returned value in terms of. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The current surplus amount the project has in this terminal, in terms of currency and with the specified number of decimals. |
heldFeesOf
Fees that are being held for a project.
Projects can temporarily hold fees and unlock them later by adding funds to the project's balance.
Held fees can be processed at any time by this terminal's owner.
function heldFeesOf(
uint256 projectId,
address token,
uint256 count
)
external
view
override
returns (JBFee[] memory heldFees);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project that is holding fees. |
token | address | The token that the fees are held in. |
count | uint256 |
supportsInterface
Indicates whether this contract adheres to the specified interface.
See IERC165-supportsInterface.
function supportsInterface(bytes4 interfaceId) public pure override returns (bool);
Parameters
Name | Type | Description |
---|---|---|
interfaceId | bytes4 | The ID of the interface to check for adherence to. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A flag indicating if the provided interface ID is supported. |
_balanceOf
Checks this terminal's balance of a specific token.
function _balanceOf(address token) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token to get this terminal's balance of. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | This terminal's balance. |
_contextSuffixLength
ERC-2771
specifies the context as being a single address (20 bytes).
function _contextSuffixLength() internal view override(ERC2771Context, Context) returns (uint256);
_controllerOf
Returns the current controller of a project.
function _controllerOf(uint256 projectId) internal view returns (IJBController);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the controller of. |
Returns
Name | Type | Description |
---|---|---|
<none> | IJBController | controller The project's controller. |
_isFeeless
Returns a flag indicating if interacting with an address should not incur fees.
function _isFeeless(address addr) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
addr | address | The address to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A flag indicating if the address should not incur fees. |
_msgData
The calldata. Preferred to use over msg.data
.
function _msgData() internal view override(ERC2771Context, Context) returns (bytes calldata);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | calldata The msg.data of this call. |
_msgSender
The message's sender. Preferred to use over msg.sender
.
function _msgSender() internal view override(ERC2771Context, Context) returns (address sender);
Returns
Name | Type | Description |
---|---|---|
sender | address | The address which sent this call. |
_ownerOf
The owner of a project.
function _ownerOf(uint256 projectId) internal view returns (address);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the owner of. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The owner of the project. |
_primaryTerminalOf
The primary terminal of a project for a token.
function _primaryTerminalOf(uint256 projectId, address token) internal view returns (IJBTerminal);
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to get the primary terminal of. |
token | address | The token to get the primary terminal of. |
Returns
Name | Type | Description |
---|---|---|
<none> | IJBTerminal | The primary terminal of the project for the token. |
addAccountingContextsFor
Adds accounting contexts for a project to this terminal so the project can begin accepting the tokens in those contexts.
Only a project's owner, an operator with the ADD_ACCOUNTING_CONTEXTS
permission from that owner, or a
project's controller can add accounting contexts for the project.
function addAccountingContextsFor(
uint256 projectId,
JBAccountingContext[] calldata accountingContexts
)
external
override;
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project having to add accounting contexts for. |
accountingContexts | JBAccountingContext[] | The accounting contexts to add. |
addToBalanceOf
Adds funds to a project's balance without minting tokens.
Adding to balance can unlock held fees if shouldUnlockHeldFees
is true.
function addToBalanceOf(
uint256 projectId,
address token,
uint256 amount,
bool shouldReturnHeldFees,
string calldata memo,
bytes calldata metadata
)
external
payable
override;
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project to add funds to the balance of. |
token | address | The token being added to the balance. |
amount | uint256 | The amount of tokens to add to the balance, as a fixed point number with the same number of decimals as this terminal. If this is a native token terminal, this is ignored and msg.value is used instead. |
shouldReturnHeldFees | bool | A flag indicating if held fees should be returned based on the amount being added. |
memo | string | A memo to pass along to the emitted event. |
metadata | bytes | Extra data to pass along to the emitted event. |
cashOutTokensOf
Holders can cash out a project's tokens to reclaim some of that project's surplus tokens, or to trigger rules determined by the current ruleset's data hook and cash out hook.
Only a token's holder or an operator with the CASH_OUT_TOKENS
permission from that holder can cash out
those tokens.
function cashOutTokensOf(
address holder,
uint256 projectId,
uint256 cashOutCount,
address tokenToReclaim,
uint256 minTokensReclaimed,
address payable beneficiary,
bytes calldata metadata
)
external
override
returns (uint256 reclaimAmount);
Parameters
Name | Type | Description |
---|---|---|
holder | address | The account whose tokens are being cashed out. |
projectId | uint256 | The ID of the project the project tokens belong to. |
cashOutCount | uint256 | The number of project tokens to cash out, as a fixed point number with 18 decimals. |
tokenToReclaim | address | The token being reclaimed. |
minTokensReclaimed | uint256 | The minimum number of terminal tokens expected in return, as a fixed point number with the same number of decimals as this terminal. If the amount of tokens minted for the beneficiary would be less than this amount, the cash out is reverted. |
beneficiary | address payable | The address to send the cashed out terminal tokens to, and to pass along to the ruleset's data hook and cash out hook if applicable. |
metadata | bytes | Bytes to send along to the emitted event, as well as the data hook and cash out hook if applicable. |
Returns
Name | Type | Description |
---|---|---|
reclaimAmount | uint256 | The amount of terminal tokens that the project tokens were cashed out for, as a fixed point number with 18 decimals. |
executePayout
Executes a payout to a split.
Only accepts calls from this terminal itself.
function executePayout(
JBSplit calldata split,
uint256 projectId,
address token,
uint256 amount,
address originalMessageSender
)
external
returns (uint256 netPayoutAmount);
Parameters
Name | Type | Description |
---|---|---|
split | JBSplit | The split to pay. |
projectId | uint256 | The ID of the project the split belongs to. |
token | address | The address of the token being paid to the split. |
amount | uint256 | The total amount being paid to the split, as a fixed point number with the same number of decimals as this terminal. |
originalMessageSender | address |
Returns
Name | Type | Description |
---|---|---|
netPayoutAmount | uint256 | The amount sent to the split after subtracting fees. |
executeProcessFee
Process a specified amount of fees for a project.
Only accepts calls from this terminal itself.
function executeProcessFee(
uint256 projectId,
address token,
uint256 amount,
address beneficiary,
IJBTerminal feeTerminal
)
external;
Parameters
Name | Type | Description |
---|---|---|
projectId | uint256 | The ID of the project paying the fee. |
token | address | The token the fee is being paid in. |
amount | uint256 | The fee amount, as a fixed point number with 18 decimals. |
beneficiary | address | The address to mint tokens to (from the project which receives fees), and pass along to the ruleset's data hook and pay hook if applicable. |
feeTerminal | IJBTerminal | The terminal that'll receive the fees. |