From 57ddfac00e9231122965dc241552107dd715691f Mon Sep 17 00:00:00 2001 From: mejango Date: Wed, 30 Aug 2023 17:30:56 -0400 Subject: [PATCH] implemented in terminals --- .../JBSingleTokenPaymentTerminalStore3_2.sol | 29 ++++++++++++----- .../JBPayoutRedemptionPaymentTerminal3_2.sol | 32 ++++++++----------- .../IJBPayoutRedemptionPaymentTerminal3_2.sol | 4 +-- .../IJBSingleTokenPaymentTerminalStore3_2.sol | 4 +-- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/contracts/JBSingleTokenPaymentTerminalStore3_2.sol b/contracts/JBSingleTokenPaymentTerminalStore3_2.sol index e60a6cc86..3f4b8e73e 100644 --- a/contracts/JBSingleTokenPaymentTerminalStore3_2.sol +++ b/contracts/JBSingleTokenPaymentTerminalStore3_2.sol @@ -9,7 +9,7 @@ import {IJBDirectory} from './interfaces/IJBDirectory.sol'; import {IJBFundingCycleDataSource3_1_1} from './interfaces/IJBFundingCycleDataSource3_1_1.sol'; import {IJBFundingCycleStore} from './interfaces/IJBFundingCycleStore.sol'; import {IJBPaymentTerminal} from './interfaces/IJBPaymentTerminal.sol'; -import {IJBPrices} from './interfaces/IJBPrices.sol'; +import {IJBPrices3_2} from './interfaces/IJBPrices3_2.sol'; import {IJBSingleTokenPaymentTerminal} from './interfaces/IJBSingleTokenPaymentTerminal.sol'; import {IJBSingleTokenPaymentTerminalStore3_2} from './interfaces/IJBSingleTokenPaymentTerminalStore3_2.sol'; import {JBConstants} from './libraries/JBConstants.sol'; @@ -65,7 +65,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is IJBFundingCycleStore public immutable override fundingCycleStore; /// @notice The contract that exposes price feeds. - IJBPrices public immutable override prices; + IJBPrices3_2 public immutable override prices; //*********************************************************************// // --------------------- public stored properties -------------------- // @@ -212,7 +212,11 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is /// @param _directory A contract storing directories of terminals and controllers for each project. /// @param _fundingCycleStore A contract storing all funding cycle configurations. /// @param _prices A contract that exposes price feeds. - constructor(IJBDirectory _directory, IJBFundingCycleStore _fundingCycleStore, IJBPrices _prices) { + constructor( + IJBDirectory _directory, + IJBFundingCycleStore _fundingCycleStore, + IJBPrices3_2 _prices + ) { directory = _directory; fundingCycleStore = _fundingCycleStore; prices = _prices; @@ -336,7 +340,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is // The weight is always a fixed point mumber with 18 decimals. To ensure this, the ratio should use the same number of decimals as the `_amount`. uint256 _weightRatio = _amount.currency == fundingCycle.baseCurrency() ? 10 ** _decimals - : prices.priceFor(_amount.currency, fundingCycle.baseCurrency(), _decimals); + : prices.priceFor(_projectId, _amount.currency, fundingCycle.baseCurrency(), _decimals); // Find the number of tokens to mint, as a fixed point number with as many decimals as `weight` has. tokenCount = PRBMath.mulDiv(_amount.value, _weight, _weightRatio); @@ -545,7 +549,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is : PRBMath.mulDiv( _amount, 10 ** _MAX_FIXED_POINT_FIDELITY, // Use _MAX_FIXED_POINT_FIDELITY to keep as much of the `_amount.value`'s fidelity as possible when converting. - prices.priceFor(_currency, _balanceCurrency, _MAX_FIXED_POINT_FIDELITY) + prices.priceFor(_projectId, _currency, _balanceCurrency, _MAX_FIXED_POINT_FIDELITY) ); // The amount being distributed must be available. @@ -616,7 +620,7 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is : PRBMath.mulDiv( _amount, 10 ** _MAX_FIXED_POINT_FIDELITY, // Use _MAX_FIXED_POINT_FIDELITY to keep as much of the `_amount.value`'s fidelity as possible when converting. - prices.priceFor(_currency, _balanceCurrency, _MAX_FIXED_POINT_FIDELITY) + prices.priceFor(_projectId, _currency, _balanceCurrency, _MAX_FIXED_POINT_FIDELITY) ); // The amount being distributed must be available in the overflow. @@ -757,7 +761,12 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is _distributionLimitRemaining = PRBMath.mulDiv( _distributionLimitRemaining, 10 ** _MAX_FIXED_POINT_FIDELITY, // Use _MAX_FIXED_POINT_FIDELITY to keep as much of the `_amount.value`'s fidelity as possible when converting. - prices.priceFor(_distributionLimitCurrency, _balanceCurrency, _MAX_FIXED_POINT_FIDELITY) + prices.priceFor( + _projectId, + _distributionLimitCurrency, + _balanceCurrency, + _MAX_FIXED_POINT_FIDELITY + ) ); // Overflow is the balance of this project minus the amount that can still be distributed. @@ -795,7 +804,11 @@ contract JBSingleTokenPaymentTerminalStore3_1_1 is // Convert the ETH overflow to the specified currency if needed, maintaining a fixed point number with 18 decimals. uint256 _totalOverflow18Decimal = _currency == JBCurrencies.ETH ? _ethOverflow - : PRBMath.mulDiv(_ethOverflow, 10 ** 18, prices.priceFor(JBCurrencies.ETH, _currency, 18)); + : PRBMath.mulDiv( + _ethOverflow, + 10 ** 18, + prices.priceFor(_projectId, JBCurrencies.ETH, _currency, 18) + ); // Adjust the decimals of the fixed point number if needed to match the target decimals. return diff --git a/contracts/abstract/JBPayoutRedemptionPaymentTerminal3_2.sol b/contracts/abstract/JBPayoutRedemptionPaymentTerminal3_2.sol index d59bc6ef7..271dff2ba 100644 --- a/contracts/abstract/JBPayoutRedemptionPaymentTerminal3_2.sol +++ b/contracts/abstract/JBPayoutRedemptionPaymentTerminal3_2.sol @@ -16,10 +16,10 @@ import {IJBOperatable} from './../interfaces/IJBOperatable.sol'; import {IJBOperatorStore} from './../interfaces/IJBOperatorStore.sol'; import {IJBPaymentTerminal} from './../interfaces/IJBPaymentTerminal.sol'; import {IJBPayoutTerminal3_1} from './../interfaces/IJBPayoutTerminal3_1.sol'; -import {IJBPrices} from './../interfaces/IJBPrices.sol'; +import {IJBPrices3_2} from './../interfaces/IJBPrices3_2.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'; @@ -95,7 +95,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is IJBSplitsStore public immutable override splitsStore; /// @notice The contract that exposes price feeds. - IJBPrices public immutable override prices; + IJBPrices3_2 public immutable override prices; /// @notice The contract that stores and manages the terminal's data. address public immutable override store; @@ -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 ); @@ -148,7 +148,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is : PRBMath.mulDiv( _adjustedOverflow, 10 ** decimals, - prices.priceFor(currency, JBCurrencies.ETH, decimals) + prices.priceFor(_projectId, currency, JBCurrencies.ETH, decimals) ); } @@ -212,7 +212,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is IJBProjects _projects, IJBDirectory _directory, IJBSplitsStore _splitsStore, - IJBPrices _prices, + IJBPrices3_2 _prices, address _store, address _owner ) @@ -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) { @@ -646,7 +646,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is reclaimAmount, _delegateAllocations, _memo - ) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordRedemptionFor( + ) = IJBSingleTokenPaymentTerminalStore3_2(store).recordRedemptionFor( _holder, _projectId, _tokenCount, @@ -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); @@ -806,7 +805,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is ( JBFundingCycle memory _fundingCycle, uint256 _distributedAmount - ) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordDistributionFor( + ) = IJBSingleTokenPaymentTerminalStore3_2(store).recordDistributionFor( _projectId, _amount, _currency @@ -924,7 +923,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is ( JBFundingCycle memory _fundingCycle, uint256 _distributedAmount - ) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordUsedAllowanceOf( + ) = IJBSingleTokenPaymentTerminalStore3_2(store).recordUsedAllowanceOf( _projectId, _amount, _currency @@ -1308,10 +1307,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. @@ -1355,7 +1351,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is _tokenCount, _delegateAllocations, _memo - ) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordPaymentFrom( + ) = IJBSingleTokenPaymentTerminalStore3_2(store).recordPaymentFrom( _payer, _bundledAmount, _projectId, @@ -1463,7 +1459,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 ); diff --git a/contracts/interfaces/IJBPayoutRedemptionPaymentTerminal3_2.sol b/contracts/interfaces/IJBPayoutRedemptionPaymentTerminal3_2.sol index 248091340..1e8ff3f61 100644 --- a/contracts/interfaces/IJBPayoutRedemptionPaymentTerminal3_2.sol +++ b/contracts/interfaces/IJBPayoutRedemptionPaymentTerminal3_2.sol @@ -8,7 +8,7 @@ import {IJBFeeHoldingTerminal} from './IJBFeeHoldingTerminal.sol'; import {IJBPayDelegate3_1_1} from './IJBPayDelegate3_1_1.sol'; import {IJBPaymentTerminal} from './IJBPaymentTerminal.sol'; import {IJBPayoutTerminal3_1} from './IJBPayoutTerminal3_1.sol'; -import {IJBPrices} from './IJBPrices.sol'; +import {IJBPrices3_2} from './IJBPrices3_2.sol'; import {IJBProjects} from './IJBProjects.sol'; import {IJBRedemptionDelegate3_1_1} from './IJBRedemptionDelegate3_1_1.sol'; import {IJBRedemptionTerminal} from './IJBRedemptionTerminal.sol'; @@ -170,7 +170,7 @@ interface IJBPayoutRedemptionPaymentTerminal3_2 is function directory() external view returns (IJBDirectory); - function prices() external view returns (IJBPrices); + function prices() external view returns (IJBPrices3_2); function store() external view returns (address); diff --git a/contracts/interfaces/IJBSingleTokenPaymentTerminalStore3_2.sol b/contracts/interfaces/IJBSingleTokenPaymentTerminalStore3_2.sol index df2db4f6d..39d97925d 100644 --- a/contracts/interfaces/IJBSingleTokenPaymentTerminalStore3_2.sol +++ b/contracts/interfaces/IJBSingleTokenPaymentTerminalStore3_2.sol @@ -7,7 +7,7 @@ import {JBRedemptionDelegateAllocation3_1_1} from './../structs/JBRedemptionDele import {JBTokenAmount} from './../structs/JBTokenAmount.sol'; import {IJBDirectory} from './IJBDirectory.sol'; import {IJBFundingCycleStore} from './IJBFundingCycleStore.sol'; -import {IJBPrices} from './IJBPrices.sol'; +import {IJBPrices3_2} from './IJBPrices3_2.sol'; import {IJBSingleTokenPaymentTerminal} from './IJBSingleTokenPaymentTerminal.sol'; interface IJBSingleTokenPaymentTerminalStore3_2 { @@ -15,7 +15,7 @@ interface IJBSingleTokenPaymentTerminalStore3_2 { function directory() external view returns (IJBDirectory); - function prices() external view returns (IJBPrices); + function prices() external view returns (IJBPrices3_2); function balanceOf( IJBSingleTokenPaymentTerminal terminal,