Skip to content

Commit

Permalink
implemented in terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
mejango committed Aug 30, 2023
1 parent e44d351 commit 57ddfac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
29 changes: 21 additions & 8 deletions contracts/JBSingleTokenPaymentTerminalStore3_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 -------------------- //
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
32 changes: 14 additions & 18 deletions contracts/abstract/JBPayoutRedemptionPaymentTerminal3_2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
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 All @@ -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)
);
}

Expand Down Expand Up @@ -212,7 +212,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
IJBProjects _projects,
IJBDirectory _directory,
IJBSplitsStore _splitsStore,
IJBPrices _prices,
IJBPrices3_2 _prices,
address _store,
address _owner
)
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 @@ -646,7 +646,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
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 Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1355,7 +1351,7 @@ abstract contract JBPayoutRedemptionPaymentTerminal3_2 is
_tokenCount,
_delegateAllocations,
_memo
) = IJBSingleTokenPaymentTerminalStore3_1_1(store).recordPaymentFrom(
) = IJBSingleTokenPaymentTerminalStore3_2(store).recordPaymentFrom(
_payer,
_bundledAmount,
_projectId,
Expand Down Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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 {
function fundingCycleStore() external view returns (IJBFundingCycleStore);

function directory() external view returns (IJBDirectory);

function prices() external view returns (IJBPrices);
function prices() external view returns (IJBPrices3_2);

function balanceOf(
IJBSingleTokenPaymentTerminal terminal,
Expand Down

0 comments on commit 57ddfac

Please sign in to comment.