Skip to content

Commit

Permalink
added a few relevant context
Browse files Browse the repository at this point in the history
  • Loading branch information
mejango committed Sep 1, 2023
1 parent 52deb26 commit 3eaeaae
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 45 deletions.
17 changes: 8 additions & 9 deletions contracts/JBSingleTokenPaymentTerminalStore3_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {PRBMath} from '@paulrberg/contracts/math/PRBMath.sol';
import {JBBallotState} from './enums/JBBallotState.sol';
import {IJBController3_1} from './interfaces/IJBController3_1.sol';
import {IJBDirectory} from './interfaces/IJBDirectory.sol';
import {IJBFundingCycleDataSource3_1_1} from './interfaces/IJBFundingCycleDataSource3_1_1.sol';
import {IJBFundingCycleDataSource3_2} from './interfaces/IJBFundingCycleDataSource3_2.sol';
import {IJBFundingCycleStore} from './interfaces/IJBFundingCycleStore.sol';
import {IJBPaymentTerminal} from './interfaces/IJBPaymentTerminal.sol';
import {IJBPrices} from './interfaces/IJBPrices.sol';
Expand All @@ -17,10 +17,10 @@ import {JBCurrencies} from './libraries/JBCurrencies.sol';
import {JBFixedPointNumber} from './libraries/JBFixedPointNumber.sol';
import {JBFundingCycleMetadataResolver3_2} from './libraries/JBFundingCycleMetadataResolver3_2.sol';
import {JBFundingCycle} from './structs/JBFundingCycle.sol';
import {JBPayDelegateAllocation3_1_1} from './structs/JBPayDelegateAllocation3_1_1.sol';
import {JBPayDelegateAllocation3_2} from './structs/JBPayDelegateAllocation3_2.sol';
import {JBPayParamsData} from './structs/JBPayParamsData.sol';
import {JBRedeemParamsData} from './structs/JBRedeemParamsData.sol';
import {JBRedemptionDelegateAllocation3_1_1} from './structs/JBRedemptionDelegateAllocation3_1_1.sol';
import {JBRedemptionDelegateAllocation3_2} from './structs/JBRedemptionDelegateAllocation3_2.sol';
import {JBTokenAmount} from './structs/JBTokenAmount.sol';

/// @notice Manages all bookkeeping for inflows and outflows of funds from any ISingleTokenPaymentTerminal.
Expand Down Expand Up @@ -249,7 +249,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is
returns (
JBFundingCycle memory fundingCycle,
uint256 tokenCount,
JBPayDelegateAllocation3_1_1[] memory delegateAllocations,
JBPayDelegateAllocation3_2[] memory delegateAllocations,
string memory memo
)
{
Expand Down Expand Up @@ -280,9 +280,8 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is
_memo,
_metadata
);
(_weight, memo, delegateAllocations) = IJBFundingCycleDataSource3_1_1(
fundingCycle.dataSource()
).payParams(_data);
(_weight, memo, delegateAllocations) = IJBFundingCycleDataSource3_2(fundingCycle.dataSource())
.payParams(_data);
}
// Otherwise use the funding cycle's weight
else {
Expand Down Expand Up @@ -367,7 +366,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is
returns (
JBFundingCycle memory fundingCycle,
uint256 reclaimAmount,
JBRedemptionDelegateAllocation3_1_1[] memory delegateAllocations,
JBRedemptionDelegateAllocation3_2[] memory delegateAllocations,
string memory memo
)
{
Expand Down Expand Up @@ -448,7 +447,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is
_memo,
_metadata
);
(reclaimAmount, memo, delegateAllocations) = IJBFundingCycleDataSource3_1_1(
(reclaimAmount, memo, delegateAllocations) = IJBFundingCycleDataSource3_2(
fundingCycle.dataSource()
).redeemParams(_data);
}
Expand Down
46 changes: 22 additions & 24 deletions contracts/abstract/JBPayoutRedemptionPaymentTerminal3_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {IJBPayoutTerminal3_1} from './../interfaces/IJBPayoutTerminal3_1.sol';
import {IJBPrices} from './../interfaces/IJBPrices.sol';
import {IJBProjects} from './../interfaces/IJBProjects.sol';
import {IJBRedemptionTerminal} from './../interfaces/IJBRedemptionTerminal.sol';
import {IJBSingleTokenPaymentTerminalStore3_1_1} from './../interfaces/IJBSingleTokenPaymentTerminalStore3_1_1.sol';
import {IJBSingleTokenPaymentTerminalStore3_2} from './../interfaces/IJBSingleTokenPaymentTerminalStore3_2.sol';
import {IJBSplitAllocator} from './../interfaces/IJBSplitAllocator.sol';
import {JBConstants} from './../libraries/JBConstants.sol';
import {JBCurrencies} from './../libraries/JBCurrencies.sol';
Expand All @@ -28,12 +28,12 @@ import {JBFixedPointNumber} from './../libraries/JBFixedPointNumber.sol';
import {JBFundingCycleMetadataResolver3_2} from './../libraries/JBFundingCycleMetadataResolver3_2.sol';
import {JBOperations} from './../libraries/JBOperations.sol';
import {JBTokens} from './../libraries/JBTokens.sol';
import {JBDidRedeemData3_1_1} from './../structs/JBDidRedeemData3_1_1.sol';
import {JBDidPayData3_1_1} from './../structs/JBDidPayData3_1_1.sol';
import {JBDidRedeemData3_2} from './../structs/JBDidRedeemData3_2.sol';
import {JBDidPayData3_2} from './../structs/JBDidPayData3_2.sol';
import {JBFee} from './../structs/JBFee.sol';
import {JBFundingCycle} from './../structs/JBFundingCycle.sol';
import {JBPayDelegateAllocation3_1_1} from './../structs/JBPayDelegateAllocation3_1_1.sol';
import {JBRedemptionDelegateAllocation3_1_1} from './../structs/JBRedemptionDelegateAllocation3_1_1.sol';
import {JBPayDelegateAllocation3_2} from './../structs/JBPayDelegateAllocation3_2.sol';
import {JBRedemptionDelegateAllocation3_2} from './../structs/JBRedemptionDelegateAllocation3_2.sol';
import {JBSplit} from './../structs/JBSplit.sol';
import {JBSplitAllocationData} from './../structs/JBSplitAllocationData.sol';
import {JBTokenAmount} from './../structs/JBTokenAmount.sol';
Expand Down Expand Up @@ -131,7 +131,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
uint256 _projectId
) external view virtual override returns (uint256) {
// Get this terminal's current overflow.
uint256 _overflow = IJBSingleTokenPaymentTerminalStore3_1_1(store).currentOverflowOf(
uint256 _overflow = IJBSingleTokenPaymentTerminalStore3_2(store).currentOverflowOf(
this,
_projectId
);
Expand Down Expand Up @@ -411,7 +411,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
if (!_to.acceptsToken(token, _projectId)) revert TERMINAL_TOKENS_INCOMPATIBLE();

// Record the migration in the store.
balance = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordMigration(_projectId);
balance = IJBSingleTokenPaymentTerminalStore3_2(store).recordMigration(_projectId);

// Transfer the balance if needed.
if (balance != 0) {
Expand Down Expand Up @@ -638,15 +638,15 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is

// Scoped section prevents stack too deep. `_delegateAllocations` only used within scope.
{
JBRedemptionDelegateAllocation3_1_1[] memory _delegateAllocations;
JBRedemptionDelegateAllocation3_2[] memory _delegateAllocations;

// Record the redemption.
(
_fundingCycle,
reclaimAmount,
_delegateAllocations,
_memo
) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordRedemptionFor(
) = IJBSingleTokenPaymentTerminalStore3_2(store).recordRedemptionFor(
_holder,
_projectId,
_tokenCount,
Expand All @@ -656,8 +656,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is

// Set the reference to the fee discount to apply. No fee if the beneficiary is feeless or if the redemption rate is at its max.
_feeDiscount = isFeelessAddress[_beneficiary] ||
(_fundingCycle.redemptionRate() == JBConstants.MAX_REDEMPTION_RATE &&
_fundingCycle.ballotRedemptionRate() == JBConstants.MAX_REDEMPTION_RATE) ||
_fundingCycle.redemptionRate() == JBConstants.MAX_REDEMPTION_RATE ||
_feePercent == 0
? JBConstants.MAX_FEE_DISCOUNT
: _currentFeeDiscount(_projectId, JBFeeType.REDEMPTION);
Expand All @@ -677,21 +676,22 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is

// If delegate allocations were specified by the data source, fulfill them.
if (_delegateAllocations.length != 0) {
JBDidRedeemData3_1_1 memory _data = JBDidRedeemData3_1_1(
JBDidRedeemData3_2 memory _data = JBDidRedeemData3_2(
_holder,
_projectId,
_fundingCycle.configuration,
_tokenCount,
JBTokenAmount(token, reclaimAmount, decimals, currency),
JBTokenAmount(token, 0, decimals, currency),
_fundingCycle.redemptionRate(),
_beneficiary,
_memo,
bytes(''),
_metadata
);

// Keep a reference to the allocation.
JBRedemptionDelegateAllocation3_1_1 memory _delegateAllocation;
JBRedemptionDelegateAllocation3_2 memory _delegateAllocation;

// Keep a reference to the fee.
uint256 _delegatedAmountFee;
Expand Down Expand Up @@ -806,7 +806,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
(
JBFundingCycle memory _fundingCycle,
uint256 _distributedAmount
) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordDistributionFor(
) = IJBSingleTokenPaymentTerminalStore3_2(store).recordDistributionFor(
_projectId,
_amount,
_currency
Expand Down Expand Up @@ -924,7 +924,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
(
JBFundingCycle memory _fundingCycle,
uint256 _distributedAmount
) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordUsedAllowanceOf(
) = IJBSingleTokenPaymentTerminalStore3_2(store).recordUsedAllowanceOf(
_projectId,
_amount,
_currency
Expand Down Expand Up @@ -1308,10 +1308,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
if (_allowanceAmount != 0) _cancelTransferTo(_expectedDestination, _allowanceAmount);

// Add undistributed amount back to project's balance.
IJBSingleTokenPaymentTerminalStore3_1_1(store).recordAddedBalanceFor(
_projectId,
_depositAmount
);
IJBSingleTokenPaymentTerminalStore3_2(store).recordAddedBalanceFor(_projectId, _depositAmount);
}

/// @notice Contribute tokens to a project.
Expand Down Expand Up @@ -1343,7 +1340,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is

// Scoped section prevents stack too deep. `_delegateAllocations` and `_tokenCount` only used within scope.
{
JBPayDelegateAllocation3_1_1[] memory _delegateAllocations;
JBPayDelegateAllocation3_2[] memory _delegateAllocations;
uint256 _tokenCount;

// Bundle the amount info into a JBTokenAmount struct.
Expand All @@ -1355,7 +1352,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
_tokenCount,
_delegateAllocations,
_memo
) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordPaymentFrom(
) = IJBSingleTokenPaymentTerminalStore3_2(store).recordPaymentFrom(
_payer,
_bundledAmount,
_projectId,
Expand All @@ -1381,12 +1378,13 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is

// If delegate allocations were specified by the data source, fulfill them.
if (_delegateAllocations.length != 0) {
JBDidPayData3_1_1 memory _data = JBDidPayData3_1_1(
JBDidPayData3_2 memory _data = JBDidPayData3_2(
_payer,
_projectId,
_fundingCycle.configuration,
_bundledAmount,
JBTokenAmount(token, 0, decimals, currency),
_fundingCycle.weight,
beneficiaryTokenCount,
_beneficiary,
_preferClaimedTokens,
Expand All @@ -1399,7 +1397,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
uint256 _numDelegates = _delegateAllocations.length;

// Keep a reference to the allocation.
JBPayDelegateAllocation3_1_1 memory _delegateAllocation;
JBPayDelegateAllocation3_2 memory _delegateAllocation;

for (uint256 _i; _i < _numDelegates; ) {
// Get a reference to the delegate being iterated on.
Expand Down Expand Up @@ -1463,7 +1461,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
uint256 _refundedFees = _shouldRefundHeldFees ? _refundHeldFees(_projectId, _amount) : 0;

// Record the added funds with any refunded fees.
IJBSingleTokenPaymentTerminalStore3_1_1(store).recordAddedBalanceFor(
IJBSingleTokenPaymentTerminalStore3_2(store).recordAddedBalanceFor(
_projectId,
_amount + _refundedFees
);
Expand Down
44 changes: 44 additions & 0 deletions contracts/interfaces/IJBFundingCycleDataSource3_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
import {JBPayDelegateAllocation3_2} from './../structs/JBPayDelegateAllocation3_2.sol';
import {JBPayParamsData} from './../structs/JBPayParamsData.sol';
import {JBRedeemParamsData} from './../structs/JBRedeemParamsData.sol';
import {JBRedemptionDelegateAllocation3_2} from './../structs/JBRedemptionDelegateAllocation3_2.sol';

/// @title Datasource
/// @notice The datasource is called by JBPayoutRedemptionPaymentTerminals on pay and redemption, and provide an extra layer of logic to use a custom weight, a custom memo and/or a pay/redeem delegate
interface IJBFundingCycleDataSource3_2 is IERC165 {
/// @notice The datasource implementation for JBPaymentTerminal.pay(..)
/// @param data the data passed to the data source in terminal.pay(..), as a JBPayParamsData struct:
/// @return weight the weight to use to override the funding cycle weight
/// @return memo the memo to override the pay(..) memo
/// @return delegateAllocations The amount to send to delegates instead of adding to the local balance.
function payParams(
JBPayParamsData calldata data
)
external
view
returns (
uint256 weight,
string memory memo,
JBPayDelegateAllocation3_2[] memory delegateAllocations
);

/// @notice The datasource implementation for JBPaymentTerminal.redeemTokensOf(..)
/// @param data the data passed to the data source in terminal.redeemTokensOf(..), as a JBRedeemParamsData struct:
/// @return reclaimAmount The amount to claim, overriding the terminal logic.
/// @return memo The memo to override the redeemTokensOf(..) memo.
/// @return delegateAllocations The amount to send to delegates instead of adding to the beneficiary.
function redeemParams(
JBRedeemParamsData calldata data
)
external
view
returns (
uint256 reclaimAmount,
string memory memo,
JBRedemptionDelegateAllocation3_2[] memory delegateAllocations
);
}
14 changes: 14 additions & 0 deletions contracts/interfaces/IJBPayDelegate3_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
import {JBDidPayData3_2} from './../structs/JBDidPayData3_2.sol';

/// @title Pay delegate
/// @notice Delegate called after JBTerminal.pay(..) logic completion (if passed by the funding cycle datasource)
interface IJBPayDelegate3_2 is IERC165 {
/// @notice This function is called by JBPaymentTerminal.pay(..), after the execution of its logic
/// @dev Critical business logic should be protected by an appropriate access control
/// @param data the data passed by the terminal, as a JBDidPayData3_2 struct:
function didPay(JBDidPayData3_2 calldata data) external payable;
}
16 changes: 8 additions & 8 deletions contracts/interfaces/IJBPayoutRedemptionPaymentTerminal3_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {JBFee} from './../structs/JBFee.sol';
import {IJBAllowanceTerminal3_1} from './IJBAllowanceTerminal3_1.sol';
import {IJBDirectory} from './IJBDirectory.sol';
import {IJBFeeHoldingTerminal} from './IJBFeeHoldingTerminal.sol';
import {IJBPayDelegate3_1_1} from './IJBPayDelegate3_1_1.sol';
import {IJBPayDelegate3_2} from './IJBPayDelegate3_2.sol';
import {IJBPaymentTerminal} from './IJBPaymentTerminal.sol';
import {IJBPayoutTerminal3_1} from './IJBPayoutTerminal3_1.sol';
import {IJBPrices} from './IJBPrices.sol';
import {IJBProjects} from './IJBProjects.sol';
import {IJBRedemptionDelegate3_1_1} from './IJBRedemptionDelegate3_1_1.sol';
import {IJBRedemptionDelegate3_2} from './IJBRedemptionDelegate3_2.sol';
import {IJBRedemptionTerminal} from './IJBRedemptionTerminal.sol';
import {IJBSplitsStore} from './IJBSplitsStore.sol';
import {JBDidPayData3_1_1} from './../structs/JBDidPayData3_1_1.sol';
import {JBDidRedeemData3_1_1} from './../structs/JBDidRedeemData3_1_1.sol';
import {JBDidPayData3_2} from './../structs/JBDidPayData3_2.sol';
import {JBDidRedeemData3_2} from './../structs/JBDidRedeemData3_2.sol';
import {JBSplit} from './../structs/JBSplit.sol';

interface IJBPayoutRedemptionPaymentTerminal3_2 is
Expand Down Expand Up @@ -150,16 +150,16 @@ interface IJBPayoutRedemptionPaymentTerminal3_2 is
);

event DelegateDidRedeem(
IJBRedemptionDelegate3_1_1 indexed delegate,
JBDidRedeemData3_1_1 data,
IJBRedemptionDelegate3_2 indexed delegate,
JBDidRedeemData3_2 data,
uint256 delegatedAmount,
uint256 fee,
address caller
);

event DelegateDidPay(
IJBPayDelegate3_1_1 indexed delegate,
JBDidPayData3_1_1 data,
IJBPayDelegate3_2 indexed delegate,
JBDidPayData3_2 data,
uint256 delegatedAmount,
address caller
);
Expand Down
14 changes: 14 additions & 0 deletions contracts/interfaces/IJBRedemptionDelegate3_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC165} from '@openzeppelin/contracts/utils/introspection/IERC165.sol';
import {JBDidRedeemData3_2} from './../structs/JBDidRedeemData3_2.sol';

/// @title Redemption delegate
/// @notice Delegate called after JBTerminal.redeemTokensOf(..) logic completion (if passed by the funding cycle datasource)
interface IJBRedemptionDelegate3_2 is IERC165 {
/// @notice This function is called by JBPaymentTerminal.redeemTokensOf(..), after the execution of its logic
/// @dev Critical business logic should be protected by an appropriate access control
/// @param data the data passed by the terminal, as a JBDidRedeemData struct:
function didRedeem(JBDidRedeemData3_2 calldata data) external payable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.0;

import {JBFundingCycle} from './../structs/JBFundingCycle.sol';
import {JBPayDelegateAllocation3_1_1} from './../structs/JBPayDelegateAllocation3_1_1.sol';
import {JBRedemptionDelegateAllocation3_1_1} from './../structs/JBRedemptionDelegateAllocation3_1_1.sol';
import {JBPayDelegateAllocation3_2} from './../structs/JBPayDelegateAllocation3_2.sol';
import {JBRedemptionDelegateAllocation3_2} from './../structs/JBRedemptionDelegateAllocation3_2.sol';
import {JBTokenAmount} from './../structs/JBTokenAmount.sol';
import {IJBDirectory} from './IJBDirectory.sol';
import {IJBFundingCycleStore} from './IJBFundingCycleStore.sol';
Expand Down Expand Up @@ -71,7 +71,7 @@ interface IJBSingleTokenPaymentTerminalStore3_2 {
returns (
JBFundingCycle memory fundingCycle,
uint256 tokenCount,
JBPayDelegateAllocation3_1_1[] memory delegateAllocations,
JBPayDelegateAllocation3_2[] memory delegateAllocations,
string memory outputMemo
);

Expand All @@ -86,7 +86,7 @@ interface IJBSingleTokenPaymentTerminalStore3_2 {
returns (
JBFundingCycle memory fundingCycle,
uint256 reclaimAmount,
JBRedemptionDelegateAllocation3_1_1[] memory delegateAllocations,
JBRedemptionDelegateAllocation3_2[] memory delegateAllocations,
string memory outputMemo
);

Expand Down
Loading

0 comments on commit 3eaeaae

Please sign in to comment.