From 6a1d9727def407a6473c5246b039f8ff4a2f6357 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Mon, 27 Nov 2023 20:21:29 -0500 Subject: [PATCH] feat(`PartyNFTRenderer`): update renderer for add party cards (#320) * update renderer * fix test log * simply revert handling * add testnet distributors to deploy constants * add goerli v1 distributor * give distributor more info * chore: add line break custom description (#293) --------- Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> --- contracts/renderers/PartyNFTRenderer.sol | 44 ++++++++++++++++++------ deploy/Deploy.s.sol | 3 +- deploy/LibDeployConstants.sol | 15 +++++--- lib/party-addresses | 2 +- test/crowdfund/InitialETHCrowdfund.t.sol | 1 + test/party/PartyGovernanceNFT.t.sol | 1 + test/utils/PartyGovernanceHelpers.t.sol | 1 + 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/contracts/renderers/PartyNFTRenderer.sol b/contracts/renderers/PartyNFTRenderer.sol index 4d8e7f7e..585d2cc2 100644 --- a/contracts/renderers/PartyNFTRenderer.sol +++ b/contracts/renderers/PartyNFTRenderer.sol @@ -76,7 +76,8 @@ contract PartyNFTRenderer is RendererBase { IMetadataRegistry1_1 constant OLD_METADATA_REGISTRY = IMetadataRegistry1_1(0x175487875F0318EdbAB54BBA442fF53b36e96015); /// @notice The old token distributor contract address. - address immutable OLD_TOKEN_DISTRIBUTOR; + address immutable TOKEN_DISTRIBUTOR_V1; + address immutable TOKEN_DISTRIBUTOR_V2; /// @notice The base url for external URLs. External URL is BASE_EXTERNAL_URL + PARTY_ADDRESS /// @dev First byte is the size of the data, the rest is the data (starting from MSB) @@ -86,11 +87,13 @@ contract PartyNFTRenderer is RendererBase { IGlobals globals, RendererStorage rendererStorage, IFont font, - address oldTokenDistributor, + address tokenDistributionV1, + address tokenDistributionV2, string memory baseExternalURL ) RendererBase(globals, rendererStorage, font) { IMPL = address(this); - OLD_TOKEN_DISTRIBUTOR = oldTokenDistributor; + TOKEN_DISTRIBUTOR_V1 = tokenDistributionV1; + TOKEN_DISTRIBUTOR_V2 = tokenDistributionV2; bytes memory baseExternalURLBytes = bytes(baseExternalURL); if (baseExternalURLBytes.length > 31) { @@ -219,7 +222,7 @@ contract PartyNFTRenderer is RendererBase { ? generateDescription(PartyGovernanceNFT(address(this)).name(), tokenId) : string.concat( metadata.description, - " ", + "\\n\\n", // Append default description. generateDescription( PartyGovernanceNFT(address(this)).name(), @@ -659,14 +662,21 @@ contract PartyNFTRenderer is RendererBase { if (address(this) == IMPL) return false; // There will only be one distributor if old token distributor is not set - TokenDistributor[] memory distributors = new TokenDistributor[](1); - if (OLD_TOKEN_DISTRIBUTOR != address(0)) { - distributors = new TokenDistributor[](2); - distributors[1] = TokenDistributor(OLD_TOKEN_DISTRIBUTOR); - } + TokenDistributor[] memory distributors = new TokenDistributor[](3); distributors[0] = TokenDistributor( _GLOBALS.getAddress(LibGlobals.GLOBAL_TOKEN_DISTRIBUTOR) ); + uint256 l = 1; + if (TOKEN_DISTRIBUTOR_V2 != address(0)) { + distributors[l++] = TokenDistributor(TOKEN_DISTRIBUTOR_V2); + } + if (TOKEN_DISTRIBUTOR_V1 != address(0)) { + distributors[l++] = TokenDistributor(TOKEN_DISTRIBUTOR_V1); + } + assembly { + // Update length of `distributors` + mstore(distributors, l) + } Party party = Party(payable(address(this))); for (uint256 i; i < distributors.length; ++i) { @@ -679,7 +689,21 @@ contract PartyNFTRenderer is RendererBase { ++distributionId ) { if (!distributor.hasPartyTokenIdClaimed(party, tokenId, distributionId)) { - return true; + TokenDistributor.DistributionInfo memory info; + info.party = party; + info.distributionId = distributionId; + info.totalShares = 1; // low amount to avoid div by 0 + info.memberSupply = 1e18; // arbitrary amount + + // `TokenIdAboveMaxError` may prevent it from being claimed. + (bool success, bytes memory response) = address(distributor).staticcall( + abi.encodeCall(TokenDistributor.getClaimAmount, (info, tokenId)) + ); + + if (success) { + uint128 amount = abi.decode(response, (uint128)); + if (amount != 0) return true; + } } } } diff --git a/deploy/Deploy.s.sol b/deploy/Deploy.s.sol index 8ea59661..b7bfee29 100644 --- a/deploy/Deploy.s.sol +++ b/deploy/Deploy.s.sol @@ -333,7 +333,8 @@ abstract contract Deploy { globals, rendererStorage, IFont(address(pixeldroidConsoleFont)), - deployConstants.oldTokenDistributor, + deployConstants.tokenDistributorV1, + deployConstants.tokenDistributorV2, deployConstants.baseExternalURL ); _trackDeployerGasAfter(); diff --git a/deploy/LibDeployConstants.sol b/deploy/LibDeployConstants.sol index a9df3b67..6ace2a2f 100644 --- a/deploy/LibDeployConstants.sol +++ b/deploy/LibDeployConstants.sol @@ -27,7 +27,8 @@ library LibDeployConstants { string networkName; address deployedNounsMarketWrapper; uint96 contributionRouterInitialFee; - address oldTokenDistributor; + address tokenDistributorV1; + address tokenDistributorV2; string baseExternalURL; } @@ -58,7 +59,8 @@ library LibDeployConstants { networkName: "goerli", deployedNounsMarketWrapper: 0x0000000000000000000000000000000000000000, contributionRouterInitialFee: 0.00055 ether, - oldTokenDistributor: address(0), + tokenDistributorV1: 0xE6F58B31344404E3479d81fB8f9dD592feB37965, + tokenDistributorV2: 0x8714EA9C2BC5a8f2d26D7c3F86558331c16145B5, baseExternalURL: "https://party.app/party/" }); @@ -92,7 +94,8 @@ library LibDeployConstants { networkName: "base-goerli", deployedNounsMarketWrapper: 0x0000000000000000000000000000000000000000, contributionRouterInitialFee: 0.00055 ether, - oldTokenDistributor: address(0), + tokenDistributorV1: address(0), + tokenDistributorV2: 0x55D2463cf5b6743F279Fe9BcbF32415f575B953d, baseExternalURL: "https://base.party.app/party/" }); @@ -126,7 +129,8 @@ library LibDeployConstants { networkName: "mainnet", deployedNounsMarketWrapper: 0x9319DAd8736D752C5c72DB229f8e1b280DC80ab1, contributionRouterInitialFee: 0.00055 ether, - oldTokenDistributor: 0x1CA2007a81F8A7491BB6E11D8e357FD810896454, + tokenDistributorV1: 0x1CA2007a81F8A7491BB6E11D8e357FD810896454, + tokenDistributorV2: 0x49a3caab781f711aD74C9d2F34c3cbD835d6A608, baseExternalURL: "https://party.app/party/" }); @@ -160,7 +164,8 @@ library LibDeployConstants { networkName: "base", deployedNounsMarketWrapper: 0x0000000000000000000000000000000000000000, contributionRouterInitialFee: 0.00055 ether, - oldTokenDistributor: address(0), + tokenDistributorV1: address(0), + tokenDistributorV2: 0xf0560F963538017CAA5081D96f839FE5D265acCB, baseExternalURL: "https://base.party.app/party/" }); diff --git a/lib/party-addresses b/lib/party-addresses index 33018a98..c4d530f8 160000 --- a/lib/party-addresses +++ b/lib/party-addresses @@ -1 +1 @@ -Subproject commit 33018a986a762d5d0fb76f572af49b8f4092d11e +Subproject commit c4d530f8edf60329aea1fc245694d4022fc4c9d9 diff --git a/test/crowdfund/InitialETHCrowdfund.t.sol b/test/crowdfund/InitialETHCrowdfund.t.sol index 9ea89b1c..119c4b5d 100644 --- a/test/crowdfund/InitialETHCrowdfund.t.sol +++ b/test/crowdfund/InitialETHCrowdfund.t.sol @@ -54,6 +54,7 @@ contract InitialETHCrowdfundTest is LintJSON, TestUtils, ERC721Receiver { nftRendererStorage, font, address(0), + address(0), "https://party.app/party/" ); tokenDistributor = new TokenDistributor(globals, 0); diff --git a/test/party/PartyGovernanceNFT.t.sol b/test/party/PartyGovernanceNFT.t.sol index 2c371956..1e32e39c 100644 --- a/test/party/PartyGovernanceNFT.t.sol +++ b/test/party/PartyGovernanceNFT.t.sol @@ -70,6 +70,7 @@ contract PartyGovernanceNFTTest is LintJSON, TestUtils { nftRendererStorage, font, address(0), + address(0), "https://party.app/party/" ); globalsAdmin.setGovernanceNftRendererAddress(address(nftRenderer)); diff --git a/test/utils/PartyGovernanceHelpers.t.sol b/test/utils/PartyGovernanceHelpers.t.sol index 1f4c215a..70f7ab20 100644 --- a/test/utils/PartyGovernanceHelpers.t.sol +++ b/test/utils/PartyGovernanceHelpers.t.sol @@ -43,6 +43,7 @@ contract PartyGovernanceHelpersTest is Test, TestUtils { RendererStorage(address(0)), IFont(address(0)), address(0), + address(0), "https://party.app/party/" ); globalsAdmin.setGovernanceNftRendererAddress(address(nftRenderer));