recordPaymentFrom
Contract: JBSingleTokenPaymentTerminalStore
Interface: IJBSingleTokenPaymentTerminalStore
- Step by step
- Code
- Errors
- Bug bounty
Records newly contributed tokens to a project.
Mints the project's tokens according to values provided by a configured data source. If no data source is configured, mints tokens proportional to the amount of the contribution.
The msg.sender must be an IJBSingleTokenPaymentTerminal
. The amount specified in the params is in terms of the msg.sender's tokens.
Definition
function recordPaymentFrom(
address _payer,
JBTokenAmount calldata _amount,
uint256 _projectId,
uint256 _baseWeightCurrency,
address _beneficiary,
string calldata _memo,
bytes memory _metadata
)
external
override
nonReentrant
returns (
JBFundingCycle memory fundingCycle,
uint256 tokenCount,
JBPayDelegateAllocation[] memory delegateAllocations,,
string memory memo
) { ... }
- Arguments:
_payer
is the original address that sent the payment to the terminal._amount
is aJBTokenAmount
data structure specifying the amount of tokens being paid. Includes the token being paid, the value, the number of decimals included, and the currency of the amount._projectId
is the ID of the project being paid._baseWeightCurrency
is the currency to base token issuance on._beneficiary
is the specified address that should be the beneficiary of anything that results from the payment._memo
is a memo to pass along to the emitted event, and passed along to the funding cycle's data source._metadata
are bytes to send along to the data source, if one is provided.
- The resulting function overrides a function definition from the
JBSingleTokenPaymentTerminalStore
interface. - The function returns:
fundingCycle
is the project's funding cycle during which payment was made.tokenCount
is the number of project tokens that were minted, as a fixed point number with 18 decimals.delegateAllocations
is the amount to send to delegates instead of adding to the local balance.memo
is a memo that should be passed along to the emitted event.
Body
-
Get a reference to the project's current funding cycle that should have its properties used in the subsequent calculations and returned.
// Get a reference to the current funding cycle for the project.
fundingCycle = fundingCycleStore.currentOf(_projectId);External references:
-
Make sure the project has a funding cycle configured. This is done by checking if the project's current funding cycle number is non-zero.
// The project must have a funding cycle configured.
if (fundingCycle.number == 0) revert INVALID_FUNDING_CYCLE(); -
Make sure the project's funding cycle isn't configured to pause payments.
// Must not be paused.
if (fundingCycle.payPaused()) revert FUNDING_CYCLE_PAYMENT_PAUSED();Library references:
JBFundingCycleMetadataResolver
.payPaused(...)
-
Create a variable where the weight to use in subsquent calculations will be saved.
// The weight according to which new token supply is to be minted, as a fixed point number with 18 decimals.
uint256 _weight; -
If the project's current funding cycle is configured to use a data source when receiving payments, ask the data source for the parameters that should be used throughout the rest of the function given provided contextual values in a
JBPayParamsData
structure. Otherwise default parameters are used.// If the funding cycle has configured a data source, use it to derive a weight and memo.
if (fundingCycle.useDataSourceForPay() && fundingCycle.dataSource() != address(0)) {
// Create the params that'll be sent to the data source.
JBPayParamsData memory _data = JBPayParamsData(
IJBSingleTokenPaymentTerminal(msg.sender),
_payer,
_amount,
_projectId,
_beneficiary,
fundingCycle.configuration,
fundingCycle.weight,
fundingCycle.reservedRate(),
_memo,
_metadata
);
(_weight, memo, delegateAllocations) = IJBFundingCycleDataSource(fundingCycle.dataSource())
.payParams(_data);
}
// Otherwise use the funding cycle's weight
else {
_weight = fundingCycle.weight;
memo = _memo;
}