Skip to content

Commit

Permalink
process held fees on migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
mejango committed Dec 8, 2023
1 parent ac1f6c1 commit a0235bd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
85 changes: 48 additions & 37 deletions src/JBMultiTerminal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ contract JBMultiTerminal is JBPermissioned, Ownable, ERC2771Context, IJBMultiTer
revert TERMINAL_TOKENS_INCOMPATIBLE();
}

// Process any held fees.
_processHeldFeesOf(projectId, token);

// Record the migration in the store.
balance = STORE.recordTerminalMigration(projectId, token);

Expand Down Expand Up @@ -505,7 +508,8 @@ contract JBMultiTerminal is JBPermissioned, Ownable, ERC2771Context, IJBMultiTer
/// @dev Only a project's owner, an operator with the `PROCESS_FEES` permission from that owner, or this terminal's
/// owner can process held fees.
/// @param projectId The ID of the project to process held fees for.
function processHeldFees(uint256 projectId, address token) external virtual override {
/// @param token The token to process held fees for.
function processHeldFeesOf(uint256 projectId, address token) external virtual override {
// Enforce permissions.
_requirePermissionAllowingOverride({
account: PROJECTS.ownerOf(projectId),
Expand All @@ -514,42 +518,7 @@ contract JBMultiTerminal is JBPermissioned, Ownable, ERC2771Context, IJBMultiTer
alsoGrantAccessIf: _msgSender() == owner()
});

// Get a reference to the project's held fees.
JBFee[] memory heldFees = _heldFeesOf[projectId][token];

// Delete the held fees.
delete _heldFeesOf[projectId][token];

// Keep a reference to the amount.
uint256 amount;

// Keep a reference to the number of held fees.
uint256 numberOfHeldFees = heldFees.length;

// Keep a reference to the fee being iterated on.
JBFee memory heldFee;

// Keep a reference to the terminal that'll receive the fees.
IJBTerminal feeTerminal = DIRECTORY.primaryTerminalOf(_FEE_BENEFICIARY_PROJECT_ID, token);

// Process each fee.
for (uint256 i; i < numberOfHeldFees; ++i) {
// Keep a reference to the held fee being iterated on.
heldFee = heldFees[i];

// Get the fee amount.
amount = JBFees.feeAmountIn(heldFee.amount, FEE);

// Process the fee.
_processFee({
projectId: projectId,
token: token,
amount: heldFee.amount,
beneficiary: heldFee.beneficiary,
feeTerminal: feeTerminal,
wasHeld: true
});
}
_processHeldFeesOf(projectId, token);
}

/// @notice Sets an address as feeless or not feeless for this terminal.
Expand Down Expand Up @@ -1611,6 +1580,48 @@ contract JBMultiTerminal is JBPermissioned, Ownable, ERC2771Context, IJBMultiTer
}
}

/// @notice Process any fees that are being held for the project.
/// @param projectId The ID of the project to process held fees for.
/// @param token The token to process held fees for.
function _processHeldFeesOf(uint256 projectId, address token) private {
// Get a reference to the project's held fees.
JBFee[] memory heldFees = _heldFeesOf[projectId][token];

// Delete the held fees.
delete _heldFeesOf[projectId][token];

// Keep a reference to the amount.
uint256 amount;

// Keep a reference to the number of held fees.
uint256 numberOfHeldFees = heldFees.length;

// Keep a reference to the fee being iterated on.
JBFee memory heldFee;

// Keep a reference to the terminal that'll receive the fees.
IJBTerminal feeTerminal = DIRECTORY.primaryTerminalOf(_FEE_BENEFICIARY_PROJECT_ID, token);

// Process each fee.
for (uint256 i; i < numberOfHeldFees; ++i) {
// Keep a reference to the held fee being iterated on.
heldFee = heldFees[i];

// Get the fee amount.
amount = JBFees.feeAmountIn(heldFee.amount, FEE);

// Process the fee.
_processFee({
projectId: projectId,
token: token,
amount: heldFee.amount,
beneficiary: heldFee.beneficiary,
feeTerminal: feeTerminal,
wasHeld: true
});
}
}

/// @notice Process a fee of the specified amount from a project.
/// @param projectId The ID of the project paying the fee.
/// @param token The token the fee is being paid in.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/terminal/IJBFeeTerminal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface IJBFeeTerminal is IJBTerminal {

function isFeelessAddress(address account) external view returns (bool);

function processHeldFees(uint256 projectId, address token) external;
function processHeldFeesOf(uint256 projectId, address token) external;

function setFeelessAddress(address account, bool flag) external;
}

0 comments on commit a0235bd

Please sign in to comment.