Skip to content

Commit

Permalink
feat: getDistribution getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Picodes committed Jan 31, 2024
1 parent d116591 commit 8e91fff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions contracts/DistributionCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
/// on pools with whitelisted tokens
mapping(address => uint256) public isWhitelistedToken;

/// @deprecated, kept for storage compatibility
/// @notice deprecated, kept for storage compatibility
mapping(address => uint256) public _nonces;

/// @notice Maps an address to the last valid hash signed
Expand Down Expand Up @@ -294,6 +294,10 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
GETTERS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

function getDistribution(uint256 index) external view returns (CampaignParameters memory) {
return _convertDistribution(distributionList[index]);
}

/// @notice Returns the index of a campaign in the campaign list
function campaignLookup(bytes32 _campaignId) public view returns (uint256) {
uint256 index = _campaignLookup[_campaignId];
Expand All @@ -302,7 +306,7 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
}

/// @notice Returns the campaign parameters of a given campaignId
function campaign(bytes32 _campaignId) external view returns (CampaignParameters memory) {
function getCampaign(bytes32 _campaignId) external view returns (CampaignParameters memory) {
return campaignList[campaignLookup(_campaignId)];
}

Expand Down Expand Up @@ -499,8 +503,17 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
return campaign.campaignId;
}

/// @notice Converts the deprecated distribution type into a campaign
/// @notice Creates a distribution from a deprecated distribution type
function _createDistribution(DistributionParameters memory distribution) internal returns (uint256) {
_createCampaign(_convertDistribution(distribution));
// Not gas efficient but deprecated
return campaignList[campaignList.length - 1].amount;
}

/// @notice Converts the deprecated distribution type into a campaign
function _convertDistribution(
DistributionParameters memory distribution
) internal view returns (CampaignParameters memory) {
address[] memory whitelist = new address[](distribution.wrapperTypes.length);
address[] memory blacklist = new address[](distribution.wrapperTypes.length);
uint256 whitelistLength;
Expand All @@ -522,7 +535,7 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
mstore(blacklist, blacklistLength)
}

_createCampaign(
return
CampaignParameters({
campaignId: distribution.rewardId,
creator: msg.sender,
Expand All @@ -543,11 +556,7 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
blacklist, // blacklist
"0x"
)
})
);

// Not gas efficient but deprecated
return campaignList[campaignList.length - 1].amount;
});
}

/// @notice Computes the fees to be taken on a campaign and transfers them to the fee recipient
Expand Down
2 changes: 1 addition & 1 deletion test/foundry/unit/DistributionCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ contract Test_DistributionCreator_CreateDistribution is DistributionCreatorTest
)
)
);
CampaignParameters memory fetchedCampaign = creator.campaign(campaignId);
CampaignParameters memory fetchedCampaign = creator.getCampaign(campaignId);
assertEq(alice, fetchedCampaign.creator);
assertEq(address(angle), fetchedCampaign.rewardToken);
assertEq(2, fetchedCampaign.campaignType);
Expand Down

0 comments on commit 8e91fff

Please sign in to comment.