Skip to content

Commit

Permalink
add expanded authority abilities
Browse files Browse the repository at this point in the history
  • Loading branch information
0xble authored and arr00 committed Oct 16, 2023
1 parent 2502828 commit d9539b2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 44 deletions.
101 changes: 58 additions & 43 deletions contracts/party/PartyGovernanceNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,46 +208,58 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
/// authority.
/// @param tokenId The ID of the NFT to add voting power to.
/// @param votingPower The amount of voting power to add.
function addVotingPower(uint256 tokenId, uint256 votingPower) external onlyAuthority {
function addVotingPower(uint256 tokenId, uint96 votingPower) external onlyAuthority {
uint96 mintedVotingPower_ = mintedVotingPower;
uint96 totalVotingPower = _getSharedProposalStorage().governanceValues.totalVotingPower;
// Cap voting power to remaining unminted voting power supply.
uint96 votingPower_ = votingPower.safeCastUint256ToUint96();
// Allow minting past total voting power if minting party cards for
// initial crowdfund when there is no total voting power.
if (totalVotingPower != 0 && totalVotingPower - mintedVotingPower_ < votingPower_) {

// Cap voting power to remaining unminted voting power supply. Allow
// minting past total voting power if minting party cards for initial
// crowdfund when there is no total voting power.
if (totalVotingPower != 0 && totalVotingPower - mintedVotingPower_ < votingPower) {
unchecked {
votingPower_ = totalVotingPower - mintedVotingPower_;
votingPower = totalVotingPower - mintedVotingPower_;
}
}

// Update state.
mintedVotingPower += votingPower_;
uint256 newIntrinsicVotingPower = votingPowerByTokenId[tokenId] + votingPower_;
mintedVotingPower += votingPower;
uint256 newIntrinsicVotingPower = votingPowerByTokenId[tokenId] + votingPower;
votingPowerByTokenId[tokenId] = newIntrinsicVotingPower;

emit PartyCardIntrinsicVotingPowerSet(tokenId, newIntrinsicVotingPower);

_adjustVotingPower(ownerOf(tokenId), votingPower_.safeCastUint96ToInt192(), address(0));
_adjustVotingPower(ownerOf(tokenId), votingPower.safeCastUint96ToInt192(), address(0));
}

/// @notice Remove voting power from an existing NFT. Only callable by an
/// authority.
/// @param tokenId The ID of the NFT to remove voting power from.
/// @param votingPower The amount of voting power to remove.
function removeVotingPower(uint256 tokenId, uint96 votingPower) external onlyAuthority {
mintedVotingPower -= votingPower;
votingPowerByTokenId[tokenId] -= votingPower;

_adjustVotingPower(ownerOf(tokenId), -votingPower.safeCastUint96ToInt192(), address(0));
}

/// @notice Increase the total voting power of the party. Only callable by
/// an authority.
/// @param votingPower The new total voting power to add.
function increaseTotalVotingPower(uint96 votingPower) external onlyAuthority {
_getSharedProposalStorage().governanceValues.totalVotingPower += votingPower;
}

/// @notice Update the total voting power of the party. Only callable by
/// @notice Decrease the total voting power of the party. Only callable by
/// an authority.
/// @param newVotingPower The new total voting power to add.
function increaseTotalVotingPower(uint96 newVotingPower) external onlyAuthority {
_getSharedProposalStorage().governanceValues.totalVotingPower += newVotingPower;
/// @param votingPower The new total voting power to add.
function decreaseTotalVotingPower(uint96 votingPower) external onlyAuthority {
_getSharedProposalStorage().governanceValues.totalVotingPower -= votingPower;
}

/// @notice Burn governance NFTs and remove their voting power. Can only
/// be called by an authority before the party has started.
/// @param tokenIds The IDs of the governance NFTs to burn.
function burn(uint256[] memory tokenIds) public onlyAuthority {
// Authority needs to be able to burn cards during the initial
// crowdfund to process refunds but not after the party has started.
if (_getSharedProposalStorage().governanceValues.totalVotingPower != 0)
revert UnauthorizedToBurnError();

// Used to update voting power state of party at the end.
_burnAndUpdateVotingPower(tokenIds, false);
}

Expand All @@ -257,9 +269,9 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
) private returns (uint96 totalVotingPowerBurned) {
for (uint256 i; i < tokenIds.length; ++i) {
uint256 tokenId = tokenIds[i];
address owner = ownerOf(tokenId);

// Check if caller is authorized to burn the token.
address owner = ownerOf(tokenId);
if (checkIfAuthorizedToBurn) {
if (
msg.sender != owner &&
Expand Down Expand Up @@ -334,19 +346,24 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
) external {
if (tokenIds.length == 0) revert NothingToBurnError();

// Check if called by an authority.
bool isAuthority_ = isAuthority[msg.sender];

// Check if ragequit is allowed.
uint40 currentRageQuitTimestamp = rageQuitTimestamp;
if (currentRageQuitTimestamp != ENABLE_RAGEQUIT_PERMANENTLY) {
if (
currentRageQuitTimestamp == DISABLE_RAGEQUIT_PERMANENTLY ||
currentRageQuitTimestamp < block.timestamp
) {
revert CannotRageQuitError(currentRageQuitTimestamp);
if (!isAuthority_) {
if (currentRageQuitTimestamp != ENABLE_RAGEQUIT_PERMANENTLY) {
if (
currentRageQuitTimestamp == DISABLE_RAGEQUIT_PERMANENTLY ||
currentRageQuitTimestamp < block.timestamp
) {
revert CannotRageQuitError(currentRageQuitTimestamp);
}
}
}

// Used as a reentrancy guard. Will be updated back after ragequit.
rageQuitTimestamp = DISABLE_RAGEQUIT_PERMANENTLY;
// Used as a reentrancy guard. Will be updated back after ragequit.
rageQuitTimestamp = DISABLE_RAGEQUIT_PERMANENTLY;
}

// Update last rage quit timestamp.
lastRageQuitTimestamp = uint40(block.timestamp);
Expand All @@ -356,33 +373,29 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
{
IERC20 prevToken;
for (uint256 i; i < withdrawTokens.length; ++i) {
IERC20 token = withdrawTokens[i];

// Check if order of tokens to transfer is valid.
// Prevent null and duplicate transfers.
if (prevToken >= token) revert InvalidTokenOrderError();
if (prevToken >= withdrawTokens[i]) revert InvalidTokenOrderError();

prevToken = token;
prevToken = withdrawTokens[i];

// Check token's balance.
uint256 balance = address(token) == ETH_ADDRESS
uint256 balance = address(withdrawTokens[i]) == ETH_ADDRESS
? address(this).balance
: token.balanceOf(address(this));
: withdrawTokens[i].balanceOf(address(this));

// Add fair share of tokens from the party to total.
for (uint256 j; j < tokenIds.length; ++j) {
// Must be retrieved before burning the token.
uint256 shareOfVotingPower = getVotingPowerShareOf(tokenIds[j]);

withdrawAmounts[i] += (balance * shareOfVotingPower) / 1e18;
withdrawAmounts[i] += (balance * getVotingPowerShareOf(tokenIds[j])) / 1e18;
}
}
}
{
// Burn caller's party cards. This will revert if caller is not the
// the owner or approved for any of the card they are attempting to
// burn or if there are duplicate token IDs.
uint96 totalVotingPowerBurned = _burnAndUpdateVotingPower(tokenIds, true);
// burn, not an authority, or if there are duplicate token IDs.
uint96 totalVotingPowerBurned = _burnAndUpdateVotingPower(tokenIds, !isAuthority_);

// Update total voting power of party.
_getSharedProposalStorage().governanceValues.totalVotingPower -= totalVotingPowerBurned;
Expand Down Expand Up @@ -425,8 +438,10 @@ contract PartyGovernanceNFT is PartyGovernance, ERC721, IERC2981 {
}
}

// Update ragequit timestamp back to before.
rageQuitTimestamp = currentRageQuitTimestamp;
if (!isAuthority_) {
// Update ragequit timestamp back to before.
rageQuitTimestamp = currentRageQuitTimestamp;
}

emit RageQuit(msg.sender, tokenIds, withdrawTokens, receiver);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/party-addresses
Submodule party-addresses updated 79 files
+2,690 −0 abis/11d80eae.json
+454 −0 abis/2196d57e.json
+1,957 −0 abis/284b3877.json
+1,740 −0 abis/44eec358.json
+1,989 −0 abis/5717682f.json
+454 −0 abis/5d2ee735.json
+1,772 −0 abis/656e47cd.json
+1,385 −0 abis/66a777ff.json
+416 −0 abis/66e87b84.json
+2,157 −0 abis/7ba9aaf4.json
+182 −0 abis/822359f1.json
+110 −0 abis/86dac43d.json
+2,361 −0 abis/8fb26606.json
+1,552 −0 abis/92347fae.json
+1,117 −0 abis/9f8a060f.json
+122 −0 abis/b476a1fa.json
+1,085 −0 abis/b6e83a9b.json
+1,812 −0 abis/cd6c76a1.json
+175 −0 abis/d1542df0.json
+1,844 −0 abis/d19ad914.json
+2,125 −0 abis/d293d6be.json
+93 −0 abis/d66cf901.json
+1,741 −0 abis/d87e8fd3.json
+1,285 −0 abis/e0d5b2e2.json
+1,520 −0 abis/ed468e7c.json
+1,709 −0 abis/f6037b99.json
+4 −0 contracts/base-goerli/contribution_fee_router/AllowListGateKeeper.json
+4 −0 contracts/base-goerli/contribution_fee_router/ContributionRouter.json
+4 −0 contracts/base-goerli/contribution_fee_router/InitialETHCrowdfund.json
+4 −0 contracts/base-goerli/contribution_fee_router/TokenGateKeeper.json
+4 −0 contracts/base-goerli/custom_token_renderer/AllowListGateKeeper.json
+4 −0 contracts/base-goerli/custom_token_renderer/AuctionCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/BuyCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/CollectionBatchBuyCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/CollectionBatchBuyOperator.json
+4 −0 contracts/base-goerli/custom_token_renderer/CollectionBuyCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/CrowdfundFactory.json
+4 −0 contracts/base-goerli/custom_token_renderer/CrowdfundNFTRenderer.json
+4 −0 contracts/base-goerli/custom_token_renderer/ERC20SwapOperator.json
+4 −0 contracts/base-goerli/custom_token_renderer/Globals.json
+4 −0 contracts/base-goerli/custom_token_renderer/InitialETHCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/MetadataProvider.json
+4 −0 contracts/base-goerli/custom_token_renderer/MetadataRegistry.json
+4 −0 contracts/base-goerli/custom_token_renderer/Party.json
+4 −0 contracts/base-goerli/custom_token_renderer/PartyFactory.json
+4 −0 contracts/base-goerli/custom_token_renderer/PartyHelpers.json
+4 −0 contracts/base-goerli/custom_token_renderer/PartyNFTRenderer.json
+4 −0 contracts/base-goerli/custom_token_renderer/PixeldroidConsoleFont.json
+4 −0 contracts/base-goerli/custom_token_renderer/ProposalExecutionEngine.json
+4 −0 contracts/base-goerli/custom_token_renderer/RendererStorage.json
+4 −0 contracts/base-goerli/custom_token_renderer/ReraiseETHCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/RollingAuctionCrowdfund.json
+4 −0 contracts/base-goerli/custom_token_renderer/TokenDistributor.json
+4 −0 contracts/base-goerli/custom_token_renderer/TokenGateKeeper.json
+26 −24 contracts/base-goerli/head.json
+4 −0 contracts/base-goerli/manual_party/AtomicManualParty.json
+0 −4 contracts/goerli/atomic_manual_party/AtomicManualParty.json
+4 −0 contracts/goerli/contribution_fee_router/AllowListGateKeeper.json
+4 −0 contracts/goerli/contribution_fee_router/ContributionRouter.json
+4 −0 contracts/goerli/contribution_fee_router/InitialETHCrowdfund.json
+4 −0 contracts/goerli/contribution_fee_router/TokenGateKeeper.json
+1 −1 contracts/goerli/custom_token_renderer/PartyNFTRenderer.json
+5 −4 contracts/goerli/head.json
+4 −0 contracts/goerli/manual_party/AtomicManualParty.json
+4 −0 contracts/mainnet/contribution_fee_router/AllowListGateKeeper.json
+4 −0 contracts/mainnet/contribution_fee_router/ContributionRouter.json
+4 −0 contracts/mainnet/contribution_fee_router/InitialETHCrowdfund.json
+4 −0 contracts/mainnet/contribution_fee_router/TokenGateKeeper.json
+4 −1 contracts/mainnet/custom_token_renderer/CrowdfundFactory.json
+4 −1 contracts/mainnet/custom_token_renderer/CrowdfundNFTRenderer.json
+4 −1 contracts/mainnet/custom_token_renderer/InitialETHCrowdfund.json
+4 −1 contracts/mainnet/custom_token_renderer/MetadataProvider.json
+4 −1 contracts/mainnet/custom_token_renderer/MetadataRegistry.json
+4 −1 contracts/mainnet/custom_token_renderer/PartyFactory.json
+4 −1 contracts/mainnet/custom_token_renderer/PartyNFTRenderer.json
+6 −4 contracts/mainnet/head.json
+4 −0 contracts/mainnet/manual_party/AtomicManualParty.json
+244 −0 deploy/contribution_fee_router.sol
+2 −3 deploy/manual_party.sol

0 comments on commit d9539b2

Please sign in to comment.