recordUsedAllowanceOf
Contract: JBSingleTokenPaymentTerminalStore
Interface: IJBSingleTokenPaymentTerminalStore
- Step by step
- Code
- Errors
- Bug bounty
Records newly used allowance funds of a project.
The msg.sender must be an IJBSingleTokenPaymentTerminal
.
Definition
function recordUsedAllowanceOf(
uint256 _projectId,
uint256 _amount,
uint256 _currency
)
external
override
nonReentrant
returns (JBFundingCycle memory fundingCycle, uint256 usedAmount) { ... }
- Arguments:
_projectId
is the ID of the project to use the allowance of._amount
is the amount to use from the allowance, as a fixed point number._currency
is the currency of the_amount
. Must match the currency of the overflow allowance.
- The resulting function overrides a function definition from the
JBSingleTokenPaymentTerminalStore
interface. - The function returns:
fundingCycle
is the funding cycle during which the withdrawal was made.usedAmount
is the amount of terminal tokens used, as a fixed point number with the same amount of decimals as its relative terminal.
Body
-
Get a reference to the project's first funding cycle.
// Get a reference to the project's current funding cycle.
fundingCycle = fundingCycleStore.currentOf(_projectId);External references:
-
Get a reference to the new used overflow allowance for this funding cycle configuration.
// Get a reference to the new used overflow allowance for this funding cycle configuration.
uint256 _newUsedOverflowAllowanceOf = usedOverflowAllowanceOf[
IJBSingleTokenPaymentTerminal(msg.sender)
][_projectId][fundingCycle.configuration] + _amount;Internal references:
-
Get a reference to the overflow allowance of the project during the current funding cycle configuration, and the currency the overflow allowance is in terms of.
// There must be sufficient allowance available.
(uint256 _overflowAllowanceOf, uint256 _overflowAllowanceCurrency) = IJBController(
directory.controllerOf(_projectId)
).overflowAllowanceOf(
_projectId,
fundingCycle.configuration,
IJBSingleTokenPaymentTerminal(msg.sender),
IJBSingleTokenPaymentTerminal(msg.sender).token()
);External references:
-
Make sure there's enough allowance left to accomodate the new used amount.
// Make sure the new used amount is within the allowance.
if (_newUsedOverflowAllowanceOf > _overflowAllowanceOf || _overflowAllowanceOf == 0)
revert INADEQUATE_CONTROLLER_ALLOWANCE(); -
Make the sure the provided currency matches the expected currency for the overflow allowance.
// Make sure the currencies match.
if (_currency != _overflowAllowanceCurrency) revert CURRENCY_MISMATCH(); -
Get a reference to the terminal's currency.
// Get a reference to the terminal's currency.
uint256 _balanceCurrency = IJBSingleTokenPaymentTerminal(msg.sender).currency(); -
Get a reference to the current distribution limit of the project during the current funding cycle configuration.
// Get the current funding target
uint256 distributionLimit =
directory.controllerOf(_projectId).distributionLimitOf(
_projectId,
fundingCycle.configuration,
terminal
);