Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Prep for NFL playoff 2023 edition #24

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions contracts/DefifaDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,72 @@ contract DefifaDelegate is IDefifaDelegate, JB721TieredGovernance {
return (
PRBMath.mulDiv(
_data.overflow + _amountRedeemed,
_redemptionWeightOf(_decodedTokenIds, _data),
_totalRedemptionWeight(_data)
redemptionWeightOf(_decodedTokenIds, _data),
totalRedemptionWeight(_data)
),
_data.memo,
delegateAllocations
);
}

/**
@notice
The cumulative weight the given token IDs have in redemptions compared to the `_totalRedemptionWeight`.

@param _tokenIds The IDs of the tokens to get the cumulative redemption weight of.

@return cumulativeWeight The weight.
*/
function redemptionWeightOf(uint256[] memory _tokenIds, JBRedeemParamsData calldata)
public
view
virtual
override
returns (uint256 cumulativeWeight)
{
// If the game is over, set the weight based on the scorecard results.
// Keep a reference to the number of tokens being redeemed.
uint256 _tokenCount = _tokenIds.length;

for (uint256 _i; _i < _tokenCount; ) {
// Keep a reference to the token's tier ID.
uint256 _tierId = store.tierIdOfToken(_tokenIds[_i]);

// Keep a reference to the tier.
JB721Tier memory _tier = store.tier(address(this), _tierId);

// Calculate what percentage of the tier redemption amount a single token counts for.
cumulativeWeight +=
// Tier's are 1 indexed and are stored 0 indexed.
_tierRedemptionWeights[_tierId - 1] /
(_tier.initialQuantity - _tier.remainingQuantity + _redeemedFromTier[_tierId]);

unchecked {
++_i;
}
}

// If there's nothing to claim, revert to prevent burning for nothing.
if (cumulativeWeight == 0) revert NOTHING_TO_CLAIM();
}

/**
@notice
The cumulative weight that all token IDs have in redemptions.

@return The total weight.
*/
function totalRedemptionWeight(JBRedeemParamsData calldata)
public
view
virtual
override
returns (uint256)
{
// Set the total weight as the total scorecard weight.
return TOTAL_REDEMPTION_WEIGHT;
}

//*********************************************************************//
// ---------------------- external transactions ---------------------- //
//*********************************************************************//
Expand Down Expand Up @@ -316,62 +374,4 @@ contract DefifaDelegate is IDefifaDelegate, JB721TieredGovernance {
_transferTierVotingUnits(_from, _to, _tier.id, _tier.votingUnits);
}
}

/**
@notice
The cumulative weight the given token IDs have in redemptions compared to the `_totalRedemptionWeight`.

@param _tokenIds The IDs of the tokens to get the cumulative redemption weight of.

@return cumulativeWeight The weight.
*/
function _redemptionWeightOf(uint256[] memory _tokenIds, JBRedeemParamsData calldata)
internal
view
virtual
override
returns (uint256 cumulativeWeight)
{
// If the game is over, set the weight based on the scorecard results.
// Keep a reference to the number of tokens being redeemed.
uint256 _tokenCount = _tokenIds.length;

for (uint256 _i; _i < _tokenCount; ) {
// Keep a reference to the token's tier ID.
uint256 _tierId = store.tierIdOfToken(_tokenIds[_i]);

// Keep a reference to the tier.
JB721Tier memory _tier = store.tier(address(this), _tierId);

// Calculate what percentage of the tier redemption amount a single token counts for.
cumulativeWeight +=
// Tier's are 1 indexed and are stored 0 indexed.
_tierRedemptionWeights[_tierId - 1] /
(_tier.initialQuantity - _tier.remainingQuantity + _redeemedFromTier[_tierId]);

unchecked {
++_i;
}
}

// If there's nothing to claim, revert to prevent burning for nothing.
if (cumulativeWeight == 0) revert NOTHING_TO_CLAIM();
}

/**
@notice
The cumulative weight that all token IDs have in redemptions.

@return The total weight.
*/
function _totalRedemptionWeight(JBRedeemParamsData calldata)
internal
view
virtual
override
returns (uint256)
{
// Set the total weight as the total scorecard weight.
return TOTAL_REDEMPTION_WEIGHT;
}
}
117 changes: 61 additions & 56 deletions contracts/DefifaDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
return _timesFor[_gameId].mintDuration;
}

function startOf(uint256 _gameId) external view override returns (uint256) {
return _timesFor[_gameId].start;
function refundPeriodDurationOf(uint256 _gameId) external view override returns (uint256) {
return _timesFor[_gameId].refundPeriodDuration;
}

function tradeDeadlineOf(uint256 _gameId) external view override returns (uint256) {
return _timesFor[_gameId].tradeDeadline;
function startOf(uint256 _gameId) external view override returns (uint256) {
return _timesFor[_gameId].start;
}

function endOf(uint256 _gameId) external view override returns (uint256) {
Expand Down Expand Up @@ -227,10 +227,8 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
) external override returns (uint256 gameId) {
// Make sure the provided gameplay timestamps are sequential.
if (
_launchProjectData.start - _launchProjectData.mintDuration < block.timestamp ||
_launchProjectData.tradeDeadline < _launchProjectData.start ||
_launchProjectData.end < _launchProjectData.start ||
_launchProjectData.end < _launchProjectData.tradeDeadline
_launchProjectData.start - _launchProjectData.refundPeriodDuration - _launchProjectData.mintDuration < block.timestamp ||
_launchProjectData.end < _launchProjectData.start
) revert INVALID_GAME_CONFIGURATION();

// Get the game ID, optimistically knowing it will be one greater than the current count.
Expand All @@ -243,8 +241,8 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
// Store the timestamps that'll define the game phases.
_timesFor[gameId] = DefifaTimeData({
mintDuration: _launchProjectData.mintDuration,
refundPeriodDuration: _launchProjectData.refundPeriodDuration,
start: _launchProjectData.start,
tradeDeadline: _launchProjectData.tradeDeadline,
end: _launchProjectData.end
});

Expand Down Expand Up @@ -285,6 +283,7 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
_pricingParams,
_delegateData.store,
JBTiered721Flags({
preventOverspending: true,
lockReservedTokenChanges: false,
lockVotingUnitChanges: false,
lockManualMintingChanges: false
Expand Down Expand Up @@ -413,11 +412,12 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
metadata: JBTiered721FundingCycleMetadataResolver.packFundingCycleGlobalMetadata(
JBTiered721FundingCycleMetadata({
pauseTransfers: false,
// Reserved tokens can't be minted during this funding cycle.
pauseMintingReserves: true
})
)
}),
_launchProjectData.start - _launchProjectData.mintDuration,
_launchProjectData.start - _launchProjectData.mintDuration - _launchProjectData.refundPeriodDuration,
new JBGroupedSplits[](0),
new JBFundAccessConstraints[](0),
_terminals,
Expand All @@ -430,7 +430,7 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
Gets reconfiguration data for phase 2 of the game.

@dev
Phase 2 freezes the treasury and activates the pre-programmed distribution limit to the specified splits.
Phase 2 freezes mints, but continues to allow refund redemptions.

@param _gameId The ID of the project that's being reconfigured.
@param _dataSource The data source to use.
Expand All @@ -441,33 +441,6 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
internal
returns (uint256 configuration)
{
// Get a reference to the terminal being used by the project.
DefifaStoredOpsData memory _ops = _opsFor[_gameId];

// Set fund access constraints.
JBFundAccessConstraints[] memory fundAccessConstraints = new JBFundAccessConstraints[](1);
fundAccessConstraints[0] = JBFundAccessConstraints({
terminal: _ops.terminal,
token: token,
distributionLimit: _ops.distributionLimit,
distributionLimitCurrency: _ops.terminal.currencyForToken(token),
overflowAllowance: 0,
overflowAllowanceCurrency: 0
});

// Fetch splits.
JBSplit[] memory _splits = controller.splitsStore().splitsOf(SPLIT_PROJECT_ID, SPLIT_DOMAIN, _gameId);

// Make a group split for ETH payouts.
JBGroupedSplits[] memory _groupedSplits;

if (_splits.length != 0) {
_groupedSplits = new JBGroupedSplits[](1);
_groupedSplits[0] = JBGroupedSplits({group: JBSplitsGroups.ETH_PAYOUT, splits: _splits});
}
else {
_groupedSplits = new JBGroupedSplits[](0);
}

// Get a reference to the time data.
DefifaTimeData memory _times = _timesFor[_gameId];
Expand All @@ -476,7 +449,7 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
controller.reconfigureFundingCyclesOf(
_gameId,
JBFundingCycleData ({
duration: _times.tradeDeadline - _times.start,
duration: _times.refundPeriodDuration,
// Don't mint project tokens.
weight: 0,
discountRate: 0,
Expand All @@ -489,33 +462,36 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
pauseTransfers: false
}),
reservedRate: 0,
redemptionRate: 0,
ballotRedemptionRate: 0,
// Full refunds.
redemptionRate: JBConstants.MAX_REDEMPTION_RATE,
ballotRedemptionRate: JBConstants.MAX_REDEMPTION_RATE,
// No more payments.
pausePay: true,
pauseDistributions: false,
// No redemptions.
pauseRedeem: true,
// Allow redemptions.
pauseRedeem: false,
pauseBurn: false,
allowMinting: false,
allowTerminalMigration: false,
allowControllerMigration: false,
holdFees: _ops.holdFees,
holdFees: false,
preferClaimedTokenOverride: false,
useTotalOverflowForRedemptions: false,
useDataSourceForPay: true,
useDataSourceForRedeem: true,
dataSource: _dataSource,
// Set a metadata of 1 to impose token non-transferability.
metadata: JBTiered721FundingCycleMetadataResolver.packFundingCycleGlobalMetadata(
JBTiered721FundingCycleMetadata({
pauseTransfers: false,
pauseMintingReserves: false
// Reserved tokens can't be minted during this funding cycle.
pauseMintingReserves: true
})
)
}),
0, // mustStartAtOrAfter should be ASAP
_groupedSplits,
fundAccessConstraints,
new JBGroupedSplits[](0),
new JBFundAccessConstraints[](0),
'Defifa game phase 2.'
);
}
Expand All @@ -525,14 +501,44 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
Gets reconfiguration data for phase 3 of the game.

@dev
Phase 3 imposes a trade deadline.
Phase 3 freezes the treasury and activates the pre-programmed distribution limit to the specified splits.

@param _gameId The ID of the project that's being reconfigured.
@param _dataSource The data source to use.

@return configuration The configuration of the funding cycle that was successfully reconfigured.
*/
function _queuePhase3(uint256 _gameId, address _dataSource) internal returns (uint256 configuration) {
function _queuePhase3(uint256 _gameId, address _dataSource)
internal
returns (uint256 configuration)
{
// Get a reference to the terminal being used by the project.
DefifaStoredOpsData memory _ops = _opsFor[_gameId];

// Set fund access constraints.
JBFundAccessConstraints[] memory fundAccessConstraints = new JBFundAccessConstraints[](1);
fundAccessConstraints[0] = JBFundAccessConstraints({
terminal: _ops.terminal,
token: token,
distributionLimit: _ops.distributionLimit,
distributionLimitCurrency: _ops.terminal.currencyForToken(token),
overflowAllowance: 0,
overflowAllowanceCurrency: 0
});

// Fetch splits.
JBSplit[] memory _splits = controller.splitsStore().splitsOf(SPLIT_PROJECT_ID, SPLIT_DOMAIN, _gameId);

// Make a group split for ETH payouts.
JBGroupedSplits[] memory _groupedSplits;

if (_splits.length != 0) {
_groupedSplits = new JBGroupedSplits[](1);
_groupedSplits[0] = JBGroupedSplits({group: JBSplitsGroups.ETH_PAYOUT, splits: _splits});
}
else {
_groupedSplits = new JBGroupedSplits[](0);
}

// Get a reference to the time data.
DefifaTimeData memory _times = _timesFor[_gameId];
Expand All @@ -541,7 +547,7 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
controller.reconfigureFundingCyclesOf(
_gameId,
JBFundingCycleData ({
duration: _times.end - _times.tradeDeadline,
duration: _times.end - _times.start,
// Don't mint project tokens.
weight: 0,
discountRate: 0,
Expand All @@ -565,23 +571,22 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
allowMinting: false,
allowTerminalMigration: false,
allowControllerMigration: false,
holdFees: false,
holdFees: _ops.holdFees,
preferClaimedTokenOverride: false,
useTotalOverflowForRedemptions: false,
useDataSourceForPay: true,
useDataSourceForRedeem: true,
dataSource: _dataSource,
// Set a metadata of 1 to impose token non-transferability.
metadata: JBTiered721FundingCycleMetadataResolver.packFundingCycleGlobalMetadata(
JBTiered721FundingCycleMetadata({
pauseTransfers: true,
pauseTransfers: false,
pauseMintingReserves: false
})
)
}),
0, // mustStartAtOrAfter should be ASAP
new JBGroupedSplits[](0),
new JBFundAccessConstraints[](0),
_groupedSplits,
fundAccessConstraints,
'Defifa game phase 3.'
);
}
Expand All @@ -591,7 +596,7 @@ contract DefifaDeployer is IDefifaDeployer, IERC721Receiver {
Gets reconfiguration data for phase 4 of the game.

@dev
Phase 4 removes the trade deadline and open up redemptions.
Phase 4 removes the trade deadline and opens up redemptions.

@param _gameId The ID of the project that's being reconfigured.
@param _dataSource The data source to use.
Expand Down
Loading