File size: 70,002 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  "language": "Solidity",
  "sources": {
    "contracts/facets/PartyFacet.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport {IPartyFacet} from \"../interfaces/IPartyFacet.sol\";\nimport {IERC20} from \"../interfaces/IERC20.sol\";\n\nimport {LibParty} from \"../libraries/LibParty.sol\";\nimport {LibSignatures} from \"../libraries/LibSignatures.sol\";\nimport {Modifiers, PartyInfo} from \"../libraries/LibAppStorage.sol\";\n\n/// \"Party manager is not kickable\"\nerror OwnerNotKickable();\n/// \"Non-member user is not kickable\"\nerror UserNotKickable();\n/// \"Manager user is not kickable. Need to remove role first\"\nerror ManagerNotKickable();\n/// \"User needs invitation to join private party\"\nerror NeedsInvitation();\n\n/**\n * @title PartyFacet\n * @author PartyFinance\n * @notice Facet that contains the main actions to interact with a Party\n */\ncontract PartyFacet is Modifiers, IPartyFacet, IERC20 {\n    /***************\n    PARTY STATE GETTER\n    ***************/\n    // @inheritdoc IERC20\n    function name() external view override returns (string memory) {\n        return s.name;\n    }\n\n    // @inheritdoc IERC20\n    function symbol() external view override returns (string memory) {\n        return s.symbol;\n    }\n\n    // @inheritdoc IERC20\n    function decimals() external pure override returns (uint8) {\n        return 18;\n    }\n\n    // @inheritdoc IERC20\n    function totalSupply() external view override returns (uint256) {\n        return s.totalSupply;\n    }\n\n    // @inheritdoc IERC20\n    function balanceOf(\n        address account\n    ) external view override returns (uint256) {\n        return s.balances[account];\n    }\n\n    // @inheritdoc IPartyState\n    function denominationAsset() external view override returns (address) {\n        return s.denominationAsset;\n    }\n\n    // @inheritdoc IPartyState\n    function creator() external view override returns (address) {\n        return s.creator;\n    }\n\n    // @inheritdoc IPartyState\n    function members(address account) external view override returns (bool) {\n        return s.members[account];\n    }\n\n    // @inheritdoc IPartyState\n    function managers(address account) external view override returns (bool) {\n        return s.managers[account];\n    }\n\n    // @inheritdoc IPartyState\n    function getTokens() external view override returns (address[] memory) {\n        return s.tokens;\n    }\n\n    // @inheritdoc IPartyState\n    function partyInfo() external view override returns (PartyInfo memory) {\n        return s.partyInfo;\n    }\n\n    // @inheritdoc IPartyState\n    function closed() external view override returns (bool) {\n        return s.closed;\n    }\n\n    /***************\n    ACCESS ACTIONS\n    ***************/\n    // @inheritdoc IPartyCreatorActions\n    function handleManager(address manager, bool setManager) external override {\n        if (s.creator == address(0)) {\n            // Patch for Facet upgrade\n            require(s.managers[msg.sender], \"Only Party Managers allowed\");\n            /// @dev Previously, parties didn't have the `creator` state, so for those parties the state will be zero address.\n            s.creator = msg.sender;\n        }\n        require(s.creator == msg.sender, \"Only Party Creator allowed\");\n        s.managers[manager] = setManager;\n        // Emit Party managers change event\n        emit PartyManagersChange(manager, setManager);\n    }\n\n    /***************\n    PARTY ACTIONS\n    ***************/\n    // @inheritdoc IPartyActions\n    function joinParty(\n        address user,\n        uint256 amount,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) external override notMember isAlive {\n        // Handle request for private parties\n        if (!s.partyInfo.isPublic) {\n            if (!s.acceptedRequests[user]) {\n                revert NeedsInvitation();\n            }\n            delete s.acceptedRequests[user];\n        }\n\n        // Add user as member\n        s.members[user] = true;\n\n        // Deposit, collect fees and mint party tokens\n        (uint256 fee, uint256 mintedPT) = LibParty.mintPartyTokens(\n            user,\n            amount,\n            allocation,\n            approval\n        );\n\n        // Emit Join event\n        emit Join(user, s.denominationAsset, amount, fee, mintedPT);\n    }\n\n    // @inheritdoc IPartyMemberActions\n    function deposit(\n        address user,\n        uint256 amount,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) external override isAlive {\n        require(s.members[user], \"Only Party Members allowed\");\n        // Deposit, collect fees and mint party tokens\n        (uint256 fee, uint256 mintedPT) = LibParty.mintPartyTokens(\n            user,\n            amount,\n            allocation,\n            approval\n        );\n        // Emit Deposit event\n        emit Deposit(user, s.denominationAsset, amount, fee, mintedPT);\n    }\n\n    // @inheritdoc IPartyMemberActions\n    function withdraw(\n        uint256 amountPT,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) external override onlyMember {\n        // Withdraw, collect fees and burn party tokens\n        LibParty.redeemPartyTokens(\n            amountPT,\n            msg.sender,\n            allocation,\n            approval,\n            liquidate\n        );\n        // Emit Withdraw event\n        emit Withdraw(msg.sender, amountPT);\n    }\n\n    // @inheritdoc IPartyManagerActions\n    function swapToken(\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) external override onlyManager {\n        // Swap token\n        (uint256 soldAmount, uint256 boughtAmount, uint256 fee) = LibParty\n            .swapToken(allocation, approval);\n\n        // Emit SwapToken event\n        emit SwapToken(\n            msg.sender,\n            address(allocation.sellTokens[0]),\n            address(allocation.buyTokens[0]),\n            soldAmount,\n            boughtAmount,\n            fee\n        );\n    }\n\n    // @inheritdoc IPartyManagerActions\n    function kickMember(\n        address kickingMember,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) external override onlyManager {\n        if (kickingMember == msg.sender) revert OwnerNotKickable();\n        if (!s.members[kickingMember]) revert UserNotKickable();\n        if (s.managers[kickingMember]) revert ManagerNotKickable();\n        // Get total PT from kicking member\n        uint256 kickingMemberPT = s.balances[kickingMember];\n        LibParty.redeemPartyTokens(\n            kickingMemberPT,\n            kickingMember,\n            allocation,\n            approval,\n            liquidate\n        );\n        // Remove user as a member\n        delete s.members[kickingMember];\n        // Emit Kick event\n        emit Kick(msg.sender, kickingMember, kickingMemberPT);\n    }\n\n    // @inheritdoc IPartyMemberActions\n    function leaveParty(\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) external override onlyMember {\n        // Get total PT from member\n        uint256 leavingMemberPT = s.balances[msg.sender];\n        LibParty.redeemPartyTokens(\n            leavingMemberPT,\n            msg.sender,\n            allocation,\n            approval,\n            liquidate\n        );\n        // Remove user as a member\n        delete s.members[msg.sender];\n        // Emit Leave event\n        emit Leave(msg.sender, leavingMemberPT);\n    }\n\n    // @inheritdoc IPartyCreatorActions\n    function closeParty() external override onlyCreator isAlive {\n        s.closed = true;\n        // Emit Close event\n        emit Close(msg.sender, s.totalSupply);\n    }\n\n    // @inheritdoc IPartyCreatorActions\n    function editPartyInfo(\n        PartyInfo memory _partyInfo\n    ) external override onlyCreator {\n        s.partyInfo = _partyInfo;\n        emit PartyInfoEdit(\n            _partyInfo.name,\n            _partyInfo.bio,\n            _partyInfo.img,\n            _partyInfo.model,\n            _partyInfo.purpose,\n            _partyInfo.isPublic,\n            _partyInfo.minDeposit,\n            _partyInfo.maxDeposit\n        );\n    }\n}\n"
    },
    "contracts/libraries/LibParty.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport {IERC20Metadata} from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\nimport {LibAppStorage, AppStorage} from \"./LibAppStorage.sol\";\nimport {LibERC20} from \"./LibERC20.sol\";\nimport {LibSignatures} from \"./LibSignatures.sol\";\nimport {LibSharedStructs} from \"./LibSharedStructs.sol\";\nimport {LibAddressArray} from \"./LibAddressArray.sol\";\n\n/// \"Deposit is not enough\"\nerror DepositNotEnough();\n/// \"Deposit exceeds maximum required\"\nerror DepositExceeded();\n/// \"User balance is not enough\"\nerror UserBalanceNotEnough();\n/// \"Failed approve reset\"\nerror FailedAproveReset();\n/// \"Failed approving sellToken\"\nerror FailedAprove();\n/// \"0x Protocol: SWAP_CALL_FAILED\"\nerror ZeroXFail();\n/// \"Invalid approval signature\"\nerror InvalidSignature();\n/// \"Only one swap at a time\"\nerror InvalidSwap();\n\nlibrary LibParty {\n    /**\n     * @notice Emitted when quotes are filled by 0x for allocation of funds\n     * @dev SwapToken is not included on this event, since its have the same information\n     * @param member Address of the user\n     * @param sellTokens Array of sell tokens\n     * @param buyTokens Array of buy tokens\n     * @param soldAmounts Array of sold amount of tokens\n     * @param boughtAmounts Array of bought amount of tokens\n     * @param partyValueDA The party value in denomination asset prior to the allocation\n     */\n    event AllocationFilled(\n        address member,\n        address[] sellTokens,\n        address[] buyTokens,\n        uint256[] soldAmounts,\n        uint256[] boughtAmounts,\n        uint256 partyValueDA\n    );\n\n    /**\n     * @notice Emitted when a member redeems shares from a party\n     * @param member Address of the user\n     * @param burnedPT Burned party tokens for redemption\n     * @param liquidate Redemption by liquitating shares into denomination asset\n     * @param redeemedAssets Array of asset addresses\n     * @param redeemedAmounts Array of asset amounts\n     * @param redeemedFees Array of asset fees\n     * @param redeemedNetAmounts Array of net asset amounts\n     */\n    event RedeemedShares(\n        address member,\n        uint256 burnedPT,\n        bool liquidate,\n        address[] redeemedAssets,\n        uint256[] redeemedAmounts,\n        uint256[] redeemedFees,\n        uint256[] redeemedNetAmounts\n    );\n\n    /***************\n    PLATFORM COLLECTOR\n    ***************/\n    /**\n     * @notice Retrieves the Platform fee to be taken from an amount\n     * @param amount Base amount to calculate fees\n     */\n    function getPlatformFee(uint256 amount, uint256 feeBps)\n        internal\n        pure\n        returns (uint256 fee)\n    {\n        fee = (amount * feeBps) / 10000;\n    }\n\n    /**\n     * @notice Transfers a fee amount of an ERC20 token to the platform collector address\n     * @param amount Base amount to calculate fees\n     * @param token ERC-20 token address\n     */\n    function collectPlatformFee(uint256 amount, address token)\n        internal\n        returns (uint256 fee)\n    {\n        AppStorage storage s = LibAppStorage.diamondStorage();\n        fee = getPlatformFee(amount, s.platformFee);\n        IERC20Metadata(token).transfer(s.platformFeeCollector, fee);\n    }\n\n    /***************\n    PARTY TOKEN FUNCTIONS\n    ***************/\n    /**\n     * @notice Swap a token using 0x Protocol\n     * @param allocation The swap allocation\n     * @param approval The platform signature approval for the allocation\n     */\n    function swapToken(\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    )\n        internal\n        returns (\n            uint256 soldAmount,\n            uint256 boughtAmount,\n            uint256 fee\n        )\n    {\n        AppStorage storage s = LibAppStorage.diamondStorage();\n        if (allocation.sellTokens.length != 1) revert InvalidSwap();\n        // -> Validate authenticity of assets allocation\n        if (\n            !LibSignatures.isValidAllocation(\n                msg.sender,\n                s.platformSentinel,\n                allocation,\n                approval\n            )\n        ) {\n            revert InvalidSignature();\n        }\n        // Fill 0x Quote\n        LibSharedStructs.FilledQuote memory filledQuote = fillQuote(\n            allocation.sellTokens[0],\n            allocation.sellAmounts[0],\n            allocation.buyTokens[0],\n            allocation.spenders[0],\n            allocation.swapsTargets[0],\n            allocation.swapsCallData[0]\n        );\n        soldAmount = filledQuote.soldAmount;\n        boughtAmount = filledQuote.boughtAmount;\n        // Collect fees\n        fee = collectPlatformFee(\n            filledQuote.boughtAmount,\n            allocation.buyTokens[0]\n        );\n        // Check if bought asset is new\n        if (!LibAddressArray.contains(s.tokens, allocation.buyTokens[0])) {\n            // Adding new asset to list\n            s.tokens.push(allocation.buyTokens[0]);\n        }\n    }\n\n    /**\n     * @notice Mints PartyTokens in exchange for a deposit\n     * @param user User address\n     * @param amountDA The deposit amount in DA\n     * @param allocation The deposit allocation\n     * @param approval The platform signature approval for the allocation\n     */\n    function mintPartyTokens(\n        address user,\n        uint256 amountDA,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) internal returns (uint256 fee, uint256 mintedPT) {\n        AppStorage storage s = LibAppStorage.diamondStorage();\n        // 1) Handle deposit amount is between min-max range\n        if (amountDA < s.partyInfo.minDeposit) revert DepositNotEnough();\n        if (s.partyInfo.maxDeposit > 0 && amountDA > s.partyInfo.maxDeposit)\n            revert DepositExceeded();\n\n        // 2) Calculate Platform Fee\n        fee = getPlatformFee(amountDA, s.platformFee);\n\n        // 3) Transfer DA from user (deposit + fees)\n        IERC20Metadata(s.denominationAsset).transferFrom(\n            user,\n            address(this),\n            amountDA + fee\n        );\n\n        // 4) Collect protocol fees\n        collectPlatformFee(amountDA, s.denominationAsset);\n\n        // 5) Allocate deposit assets\n        allocateAssets(user, allocation, approval, s.platformSentinel);\n\n        // 6) Mint PartyTokens to user\n        if (s.totalSupply == 0 || allocation.partyTotalSupply == 0) {\n            mintedPT =\n                amountDA *\n                10**(18 - IERC20Metadata(s.denominationAsset).decimals());\n        } else {\n            uint256 adjPartyValueDA = allocation.partyValueDA;\n            /// Handle any totalSupply changes\n            /// @dev Which will indicate the the allocated partyValueDA was updated in the same block by another tx\n            if (allocation.partyTotalSupply != s.totalSupply) {\n                // Since there has been a change in the totalSupply, we need to get the adjusted party value in DA\n                /// @dev Example case:\n                //          - allocation.totalSupply: 500\n                //          - allocation.partyValueDA is 1000\n                //          - totalSupply is 750\n                //       This means that the current partyValueDA is no longer 1000, since there was a change in the totalSupply.\n                //       The totalSupply delta is 50%. So the current partyValueDA should be 1500.\n                adjPartyValueDA =\n                    (adjPartyValueDA * s.totalSupply) /\n                    allocation.partyTotalSupply;\n            }\n            mintedPT = (s.totalSupply * amountDA) / adjPartyValueDA;\n        }\n        LibERC20._mint(user, mintedPT);\n    }\n\n    /**\n     * @notice Redeems funds in exchange for PartyTokens\n     * @param amountPT The PartyTokens amount\n     * @param _memberAddress The member's address to redeem PartyTokens in\n     * @param allocation The withdraw allocation\n     * @param approval The platform signature approval for the allocation\n     * @param liquidate Whether to withdraw by swapping funds into DA or not\n     */\n    function redeemPartyTokens(\n        uint256 amountPT,\n        address _memberAddress,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) internal {\n        AppStorage storage s = LibAppStorage.diamondStorage();\n\n        // 1) Check if user has PartyTokens balance to redeem\n        if (amountPT > s.balances[_memberAddress])\n            revert UserBalanceNotEnough();\n\n        // 2) Get the total supply of PartyTokens\n        uint256 totalSupply = s.totalSupply;\n\n        // 3) Burn PartyTokens\n        LibERC20._burn(_memberAddress, amountPT);\n\n        if (amountPT > 0) {\n            // 4) Handle holdings redemption: liquidate holdings or redeem as it is\n            if (liquidate) {\n                liquidateHoldings(\n                    amountPT,\n                    totalSupply,\n                    _memberAddress,\n                    allocation,\n                    approval,\n                    s.denominationAsset,\n                    s.platformSentinel\n                );\n            } else {\n                redeemHoldings(amountPT, totalSupply, _memberAddress, s.tokens);\n            }\n        }\n    }\n\n    /***************\n    HELPER FUNCTIONS\n    ***************/\n    /**\n     * @notice Redeems assets without liquidating them\n     * @param amountPT The PartyTokens amount\n     * @param totalSupply The current totalSupply of the PartyTokens\n     * @param _memberAddress The member's address to redeem PartyTokens in\n     * @param tokens Current tokens in the party\n     */\n    function redeemHoldings(\n        uint256 amountPT,\n        uint256 totalSupply,\n        address _memberAddress,\n        address[] storage tokens\n    ) private {\n        uint256[] memory redeemedAmounts = new uint256[](tokens.length);\n        uint256[] memory redeemedFees = new uint256[](tokens.length);\n        uint256[] memory redeemedNetAmounts = new uint256[](tokens.length);\n\n        // 1) Handle token holdings\n        for (uint256 i = 0; i < tokens.length; i++) {\n            // 2) Get token amount to redeem\n            uint256 tBalance = IERC20Metadata(tokens[i]).balanceOf(\n                address(this)\n            );\n            redeemedAmounts[i] = ((tBalance * amountPT) / totalSupply);\n\n            if (redeemedAmounts[i] > 0) {\n                // 3) Collect fees\n                redeemedFees[i] = collectPlatformFee(\n                    redeemedAmounts[i],\n                    tokens[i]\n                );\n                redeemedNetAmounts[i] = (redeemedAmounts[i] - redeemedFees[i]);\n\n                // 4) Transfer relative asset funds to user\n                IERC20Metadata(tokens[i]).transfer(\n                    _memberAddress,\n                    redeemedNetAmounts[i]\n                );\n            }\n        }\n        emit RedeemedShares(\n            _memberAddress,\n            amountPT,\n            false,\n            tokens,\n            redeemedAmounts,\n            redeemedFees,\n            redeemedNetAmounts\n        );\n    }\n\n    /**\n     * @notice Redeems assets by liquidating them into DA\n     * @param amountPT The PartyTokens amount\n     * @param totalSupply The current totalSupply of the PartyTokens\n     * @param _memberAddress The member's address to redeem PartyTokens in\n     * @param allocation The liquidation allocation\n     * @param approval The platform signature approval for the allocation\n     * @param denominationAsset The party's denomination asset address\n     * @param sentinel The platform sentinel address\n     */\n    function liquidateHoldings(\n        uint256 amountPT,\n        uint256 totalSupply,\n        address _memberAddress,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        address denominationAsset,\n        address sentinel\n    ) private {\n        uint256[] memory redeemedAmounts = new uint256[](1);\n        uint256[] memory redeemedFees = new uint256[](1);\n        uint256[] memory redeemedNetAmounts = new uint256[](1);\n\n        // 1) Get the portion of denomination asset to withdraw (before allocation)\n        uint256 daBalance = IERC20Metadata(denominationAsset).balanceOf(\n            address(this)\n        );\n        redeemedAmounts[0] = ((daBalance * amountPT) / totalSupply);\n\n        // 2) Swap member's share of other assets into the denomination asset\n        LibSharedStructs.Allocated memory allocated = allocateAssets(\n            _memberAddress,\n            allocation,\n            approval,\n            sentinel\n        );\n\n        // 3) Iterate through allocation and accumulate pending withdrawal for the user\n        for (uint256 i = 0; i < allocated.boughtAmounts.length; i++) {\n            // Double check that bought tokens are same as DA\n            if (allocated.buyTokens[i] == denominationAsset) {\n                redeemedAmounts[0] += allocated.boughtAmounts[i];\n            }\n        }\n\n        // 4) Collect fees\n        redeemedFees[0] = collectPlatformFee(\n            redeemedAmounts[0],\n            denominationAsset\n        );\n\n        // 5) Transfer relative DA funds to user\n        redeemedNetAmounts[0] = redeemedAmounts[0] - redeemedFees[0];\n        IERC20Metadata(denominationAsset).transfer(\n            _memberAddress,\n            redeemedNetAmounts[0]\n        );\n\n        emit RedeemedShares(\n            _memberAddress,\n            amountPT,\n            true,\n            allocated.sellTokens,\n            redeemedAmounts,\n            redeemedFees,\n            redeemedNetAmounts\n        );\n    }\n\n    /**\n     * @notice Allocates multiple 0x quotes\n     * @param sender The user's address\n     * @param allocation The allocation\n     * @param approval The platform signature approval for the allocation\n     * @param sentinel The platform sentinel address\n     */\n    function allocateAssets(\n        address sender,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        address sentinel\n    ) private returns (LibSharedStructs.Allocated memory allocated) {\n        if (\n            !LibSignatures.isValidAllocation(\n                sender,\n                sentinel,\n                allocation,\n                approval\n            )\n        ) {\n            revert InvalidSignature();\n        }\n\n        // Declaring array with a known length\n        allocated.sellTokens = new address[](allocation.sellTokens.length);\n        allocated.buyTokens = new address[](allocation.sellTokens.length);\n        allocated.soldAmounts = new uint256[](allocation.sellTokens.length);\n        allocated.boughtAmounts = new uint256[](allocation.sellTokens.length);\n        for (uint256 i = 0; i < allocation.sellTokens.length; i++) {\n            LibSharedStructs.FilledQuote memory filledQuote = fillQuote(\n                allocation.sellTokens[i],\n                allocation.sellAmounts[i],\n                allocation.buyTokens[i],\n                allocation.spenders[i],\n                allocation.swapsTargets[i],\n                allocation.swapsCallData[i]\n            );\n            allocated.sellTokens[i] = address(allocation.sellTokens[i]);\n            allocated.buyTokens[i] = address(allocation.buyTokens[i]);\n            allocated.soldAmounts[i] = filledQuote.soldAmount;\n            allocated.boughtAmounts[i] = filledQuote.boughtAmount;\n        }\n\n        // Emit AllocationFilled\n        emit AllocationFilled(\n            sender,\n            allocated.sellTokens,\n            allocated.buyTokens,\n            allocated.soldAmounts,\n            allocated.boughtAmounts,\n            allocation.partyValueDA\n        );\n    }\n\n    /**\n     * @notice Swap a token held by this contract using a 0x-API quote.\n     * @param sellToken The token address to sell\n     * @param sellAmount The token amount to sell\n     * @param buyToken The token address to buy\n     * @param spender The spender address\n     * @param swapTarget The swap target to interact (0x Exchange Proxy)\n     * @param swapCallData The swap calldata to pass\n     */\n    function fillQuote(\n        address sellToken,\n        uint256 sellAmount,\n        address buyToken,\n        address spender,\n        address payable swapTarget,\n        bytes memory swapCallData\n    ) private returns (LibSharedStructs.FilledQuote memory filledQuote) {\n        if (!IERC20Metadata(sellToken).approve(spender, 0))\n            revert FailedAproveReset();\n        if (!IERC20Metadata(sellToken).approve(spender, sellAmount))\n            revert FailedAprove();\n\n        // Track initial balance of the sellToken to determine how much we've sold.\n        filledQuote.initialSellBalance = IERC20Metadata(sellToken).balanceOf(\n            address(this)\n        );\n\n        // Track initial balance of the buyToken to determine how much we've bought.\n        filledQuote.initialBuyBalance = IERC20Metadata(buyToken).balanceOf(\n            address(this)\n        );\n        // Execute 0xSwap\n        (bool success, ) = swapTarget.call{value: msg.value}(swapCallData);\n        if (!success) revert ZeroXFail();\n\n        // Get how much we've sold.\n        filledQuote.soldAmount =\n            filledQuote.initialSellBalance -\n            IERC20Metadata(sellToken).balanceOf(address(this));\n\n        // Get how much we've bought.\n        filledQuote.boughtAmount =\n            IERC20Metadata(buyToken).balanceOf(address(this)) -\n            filledQuote.initialBuyBalance;\n    }\n}\n"
    },
    "contracts/interfaces/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\ninterface IERC20 {\n    /**\n     * @notice Queries the Party ERC-20 token name\n     * @return Token name metadata\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @notice Queries the Party ERC-20 token symbol\n     * @return Token symbol metadata\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @notice Queries the Party ERC-20 token decimals\n     * @return Token decimals metadata\n     */\n    function decimals() external pure returns (uint8);\n\n    /**\n     * @notice Queries the Party ERC-20 total minted supply\n     * @return Token total supply\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @notice Queries the Party ERC-20 balance of a given account\n     * @param account Address\n     * @return Token balance of a given ccount\n     */\n    function balanceOf(address account) external view returns (uint256);\n}\n"
    },
    "contracts/interfaces/IPartyFacet.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport {IPartyActions} from \"./party/IPartyActions.sol\";\nimport {IPartyEvents} from \"./party/IPartyEvents.sol\";\nimport {IPartyMemberActions} from \"./party/IPartyMemberActions.sol\";\nimport {IPartyManagerActions} from \"./party/IPartyManagerActions.sol\";\nimport {IPartyCreatorActions} from \"./party/IPartyCreatorActions.sol\";\nimport {IPartyState} from \"./party/IPartyState.sol\";\n\n/**\n * @title Interface for PartyFacet\n * @dev The party interface is broken up into smaller chunks\n */\ninterface IPartyFacet is\n    IPartyActions,\n    IPartyEvents,\n    IPartyCreatorActions,\n    IPartyManagerActions,\n    IPartyMemberActions,\n    IPartyState\n{\n\n}\n"
    },
    "contracts/libraries/LibSignatures.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport \"@openzeppelin/contracts/utils/cryptography/ECDSA.sol\";\n\nlibrary LibSignatures {\n    /**\n     * @notice A struct containing the recovered Signature\n     */\n    struct Sig {\n        bytes32 r;\n        bytes32 s;\n        uint8 v;\n    }\n    /**\n     * @notice A struct containing the Allocation info\n     * @dev For the array members, need to have the same length.\n     * @param sellTokens Array of ERC-20 token addresses to sell\n     * @param sellAmounts Array of ERC-20 token amounts to sell\n     * @param buyTokens Array of ERC-20 token addresses to buy\n     * @param spenders Array of the spenders addresses\n     * @param swapTargets Array of the targets to interact with (0x Exchange Proxy)\n     * @param swapsCallDAta Array of bytes containing the calldata\n     * @param partyValueDA Current value of the Party in denomination asset\n     * @param partyTotalSupply Current total supply of the Party\n     * @param expiresAt Block timestamp expiration date\n     */\n    struct Allocation {\n        address[] sellTokens;\n        uint256[] sellAmounts;\n        address[] buyTokens;\n        address[] spenders;\n        address payable[] swapsTargets;\n        bytes[] swapsCallData;\n        uint256 partyValueDA;\n        uint256 partyTotalSupply;\n        uint256 expiresAt;\n    }\n\n    /**\n     * @notice Returns the address that signed a hashed message with a signature\n     */\n    function recover(bytes32 _hash, bytes calldata _signature)\n        internal\n        pure\n        returns (address)\n    {\n        return ECDSA.recover(_hash, _signature);\n    }\n\n    /**\n     * @notice Returns an Ethereum Signed Message.\n     * @dev Produces a hash corresponding to the one signed with the\n     * [eth_sign JSON-RPC method](https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]) as part of EIP-191.\n     */\n    function getMessageHash(bytes memory _abiEncoded)\n        internal\n        pure\n        returns (bytes32)\n    {\n        return\n            keccak256(\n                abi.encodePacked(\n                    \"\\x19Ethereum Signed Message:\\n32\",\n                    keccak256(_abiEncoded)\n                )\n            );\n    }\n\n    /**\n     * @notice Verifies the tx signature against the PartyFi Sentinel address\n     * @dev Used by the deposit, join, kick, leave and swap actions\n     * @param user The user involved in the allocation\n     * @param signer The PartyFi Sentinel singer address\n     * @param allocation The allocation struct to verify\n     * @param rsv The values for the transaction's signature\n     */\n    function isValidAllocation(\n        address user,\n        address signer,\n        Allocation memory allocation,\n        Sig memory rsv\n    ) internal view returns (bool) {\n        // 1. Checks if the allocation hasn't expire\n        if (allocation.expiresAt < block.timestamp) return false;\n\n        // 2. Hashes the allocation struct to get the allocation hash\n        bytes32 allocationHash = getMessageHash(\n            abi.encodePacked(\n                address(this),\n                user,\n                allocation.sellTokens,\n                allocation.sellAmounts,\n                allocation.buyTokens,\n                allocation.spenders,\n                allocation.swapsTargets,\n                allocation.partyValueDA,\n                allocation.partyTotalSupply,\n                allocation.expiresAt\n            )\n        );\n\n        // 3. Validates if the recovered signer is the PartyFi Sentinel\n        return ECDSA.recover(allocationHash, rsv.v, rsv.r, rsv.s) == signer;\n    }\n}\n"
    },
    "contracts/libraries/LibAppStorage.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport {LibMeta} from \"./LibMeta.sol\";\n\n/**\n * @notice A struct containing the Party info tracked in storage.\n * @param name Name of the Party\n * @param bio Description of the Party\n * @param img Image URL of the Party (path to storage without protocol/domain)\n * @param model Model of the Party: \"Democracy\", \"Monarchy\", \"WeightedDemocracy\", \"Republic\"\n * @param purpose Purpose of the Party: \"Trading\", \"YieldFarming\", \"LiquidityProviding\", \"NFT\"\n * @param isPublic Visibility of the Party. (Private parties requires an accepted join request)\n * @param minDeposit Minimum deposit allowed in denomination asset\n * @param maxDeposit Maximum deposit allowed in denomination asset\n */\nstruct PartyInfo {\n    string name;\n    string bio;\n    string img;\n    string model;\n    string purpose;\n    bool isPublic;\n    uint256 minDeposit;\n    uint256 maxDeposit;\n}\n\n/**\n * @notice A struct containing the Announcement info tracked in storage.\n * @param title Title of the Announcement\n * @param bio Content of the Announcement\n * @param img Any external URL to include in the Announcement\n * @param model Model of the Party: \"Democracy\", \"Monarchy\", \"WeightedDemocracy\", \"Republic\"\n * @param created Block timestamp date of the Announcement creation\n * @param updated Block timestamp date of any Announcement edition\n */\nstruct Announcement {\n    string title;\n    string content;\n    string url;\n    string img;\n    uint256 created;\n    uint256 updated;\n}\n\nstruct AppStorage {\n    //\n    // Party vault token\n    //\n    string name;\n    string symbol;\n    uint256 totalSupply;\n    mapping(address => uint256) balances;\n    mapping(address => mapping(address => uint256)) allowances;\n    //\n    // Denomination token asset for deposit/withdraws\n    //\n    address denominationAsset;\n    //\n    // Party info\n    //\n    PartyInfo partyInfo;\n    bool closed; // Party life status\n    //\n    // Party access\n    //\n    mapping(address => bool) managers; // Maping to get if address is a manager\n    mapping(address => bool) members; // Maping to get if address is a member\n    //\n    // Party ERC-20 holdings\n    //\n    address[] tokens; // Array of current party tokens holdings\n    //\n    // Party Announcements\n    //\n    Announcement[] announcements;\n    //\n    // Party Join Requests\n    //\n    address[] joinRequests; // Array of users that requested to join the party\n    mapping(address => bool) acceptedRequests; // Mapping of requests accepted by a manager\n    //\n    // PLATFORM\n    //\n    uint256 platformFee; // Platform fee (in bps, 50 bps -> 0.5%)\n    address platformFeeCollector; // Platform fee collector\n    address platformSentinel; // Platform sentinel\n    address platformFactory; // Platform factory\n    //\n    // Extended Party access\n    //\n    address creator; // Creator of the Party\n}\n\nlibrary LibAppStorage {\n    function diamondStorage() internal pure returns (AppStorage storage ds) {\n        assembly {\n            ds.slot := 0\n        }\n    }\n}\n\ncontract Modifiers {\n    AppStorage internal s;\n\n    modifier onlyCreator() {\n        require(s.creator == LibMeta.msgSender(), \"Only Party Creator allowed\");\n        _;\n    }\n\n    modifier onlyManager() {\n        require(s.managers[LibMeta.msgSender()], \"Only Party Managers allowed\");\n        _;\n    }\n\n    modifier onlyMember() {\n        require(s.members[LibMeta.msgSender()], \"Only Party Members allowed\");\n        _;\n    }\n\n    modifier notMember() {\n        require(\n            !s.members[LibMeta.msgSender()],\n            \"Only non Party Members allowed\"\n        );\n        _;\n    }\n\n    modifier onlyFactory() {\n        require(\n            LibMeta.msgSender() == s.platformFactory,\n            \"Only Factory allowed\"\n        );\n        _;\n    }\n\n    modifier isAlive() {\n        require(!s.closed, \"Party is closed\");\n        _;\n    }\n}\n"
    },
    "contracts/libraries/LibAddressArray.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nlibrary LibAddressArray {\n    function contains(address[] memory self, address _address)\n        internal\n        pure\n        returns (bool contained)\n    {\n        for (uint256 i; i < self.length; i++) {\n            if (_address == self[i]) {\n                return true;\n            }\n        }\n        return false;\n    }\n}\n"
    },
    "contracts/libraries/LibERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport {LibAppStorage, AppStorage} from \"./LibAppStorage.sol\";\n\nlibrary LibERC20 {\n    event Transfer(address indexed from, address indexed to, uint256 amount);\n\n    /**\n     * @notice Mint tokens for a given account\n     * @param account Address recipient\n     * @param amount Amount of tokens to be minted\n     */\n    function _mint(address account, uint256 amount) internal {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        AppStorage storage s = LibAppStorage.diamondStorage();\n        s.totalSupply += amount;\n        s.balances[account] += amount;\n\n        emit Transfer(address(0), account, amount);\n    }\n\n    /**\n     * @notice Burn tokens held by given account\n     * @param account Address of burned tokens\n     * @param amount Amount of tokens to be burnt\n     */\n    function _burn(address account, uint256 amount) internal {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        AppStorage storage s = LibAppStorage.diamondStorage();\n        uint256 balance = s.balances[account];\n        require(balance >= amount, \"ERC20: burn amount exceeds balance\");\n        unchecked {\n            s.balances[account] = balance - amount;\n        }\n        s.totalSupply -= amount;\n\n        emit Transfer(account, address(0), amount);\n    }\n}\n"
    },
    "contracts/libraries/LibSharedStructs.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nlibrary LibSharedStructs {\n    struct Allocation {\n        address[] sellTokens;\n        uint256[] sellAmounts;\n        address[] buyTokens;\n        address[] spenders;\n        address payable[] swapsTargets;\n        bytes[] swapsCallData;\n        uint256 partyValueDA;\n        uint256 partyTotalSupply;\n        uint256 expiresAt;\n    }\n\n    struct FilledQuote {\n        address sellToken;\n        address buyToken;\n        uint256 soldAmount;\n        uint256 boughtAmount;\n        uint256 initialSellBalance;\n        uint256 initialBuyBalance;\n    }\n\n    struct Allocated {\n        address[] sellTokens;\n        address[] buyTokens;\n        uint256[] soldAmounts;\n        uint256[] boughtAmounts;\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
    },
    "contracts/libraries/LibMeta.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nlibrary LibMeta {\n    function getChainID() internal view returns (uint256 id) {\n        assembly {\n            id := chainid()\n        }\n    }\n\n    function msgSender() internal view returns (address sender_) {\n        if (msg.sender == address(this)) {\n            bytes memory array = msg.data;\n            uint256 index = msg.data.length;\n            assembly {\n                // Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.\n                sender_ := and(\n                    mload(add(array, index)),\n                    0xffffffffffffffffffffffffffffffffffffffff\n                )\n            }\n        } else {\n            sender_ = msg.sender;\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n    enum RecoverError {\n        NoError,\n        InvalidSignature,\n        InvalidSignatureLength,\n        InvalidSignatureS,\n        InvalidSignatureV\n    }\n\n    function _throwError(RecoverError error) private pure {\n        if (error == RecoverError.NoError) {\n            return; // no error: do nothing\n        } else if (error == RecoverError.InvalidSignature) {\n            revert(\"ECDSA: invalid signature\");\n        } else if (error == RecoverError.InvalidSignatureLength) {\n            revert(\"ECDSA: invalid signature length\");\n        } else if (error == RecoverError.InvalidSignatureS) {\n            revert(\"ECDSA: invalid signature 's' value\");\n        } else if (error == RecoverError.InvalidSignatureV) {\n            revert(\"ECDSA: invalid signature 'v' value\");\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature` or error string. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     *\n     * Documentation for signature generation:\n     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n        if (signature.length == 65) {\n            bytes32 r;\n            bytes32 s;\n            uint8 v;\n            // ecrecover takes the signature parameters, and the only way to get them\n            // currently is to use assembly.\n            /// @solidity memory-safe-assembly\n            assembly {\n                r := mload(add(signature, 0x20))\n                s := mload(add(signature, 0x40))\n                v := byte(0, mload(add(signature, 0x60)))\n            }\n            return tryRecover(hash, v, r, s);\n        } else {\n            return (address(0), RecoverError.InvalidSignatureLength);\n        }\n    }\n\n    /**\n     * @dev Returns the address that signed a hashed message (`hash`) with\n     * `signature`. This address can then be used for verification purposes.\n     *\n     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n     * this function rejects them by requiring the `s` value to be in the lower\n     * half order, and the `v` value to be either 27 or 28.\n     *\n     * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n     * verification to be secure: it is possible to craft signatures that\n     * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n     * this is by receiving a hash of the original message (which may otherwise\n     * be too long), and then calling {toEthSignedMessageHash} on it.\n     */\n    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, signature);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n     *\n     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address, RecoverError) {\n        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n        uint8 v = uint8((uint256(vs) >> 255) + 27);\n        return tryRecover(hash, v, r, s);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n     *\n     * _Available since v4.2._\n     */\n    function recover(\n        bytes32 hash,\n        bytes32 r,\n        bytes32 vs\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     *\n     * _Available since v4.3._\n     */\n    function tryRecover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address, RecoverError) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n            return (address(0), RecoverError.InvalidSignatureS);\n        }\n        if (v != 27 && v != 28) {\n            return (address(0), RecoverError.InvalidSignatureV);\n        }\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        if (signer == address(0)) {\n            return (address(0), RecoverError.InvalidSignature);\n        }\n\n        return (signer, RecoverError.NoError);\n    }\n\n    /**\n     * @dev Overload of {ECDSA-recover} that receives the `v`,\n     * `r` and `s` signature fields separately.\n     */\n    function recover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address) {\n        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n        _throwError(error);\n        return recovered;\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n        // 32 is the length in bytes of hash,\n        // enforced by the type signature above\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Message, created from `s`. This\n     * produces hash corresponding to the one signed with the\n     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n     * JSON-RPC method as part of EIP-191.\n     *\n     * See {recover}.\n     */\n    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n    }\n\n    /**\n     * @dev Returns an Ethereum Signed Typed Data, created from a\n     * `domainSeparator` and a `structHash`. This produces hash corresponding\n     * to the one signed with the\n     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n     * JSON-RPC method as part of EIP-712.\n     *\n     * See {recover}.\n     */\n    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Strings.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n    uint8 private constant _ADDRESS_LENGTH = 20;\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        // Inspired by OraclizeAPI's implementation - MIT licence\n        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n        if (value == 0) {\n            return \"0\";\n        }\n        uint256 temp = value;\n        uint256 digits;\n        while (temp != 0) {\n            digits++;\n            temp /= 10;\n        }\n        bytes memory buffer = new bytes(digits);\n        while (value != 0) {\n            digits -= 1;\n            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n            value /= 10;\n        }\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        if (value == 0) {\n            return \"0x00\";\n        }\n        uint256 temp = value;\n        uint256 length = 0;\n        while (temp != 0) {\n            length++;\n            temp >>= 8;\n        }\n        return toHexString(value, length);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _HEX_SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n     */\n    function toHexString(address addr) internal pure returns (string memory) {\n        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "contracts/interfaces/party/IPartyActions.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\n// Libraries\nimport {LibSignatures} from \"../../libraries/LibSignatures.sol\";\n\n/**\n * @notice Contains party methods that can be called by anyone\n * @dev Permissionless Party actions\n */\ninterface IPartyActions {\n    /**\n     * @notice Joins and deposits into the party\n     * @dev For private parties, the joiner must have an accepted join request by a manager.\n     *      The user must not be a member and the party must be opened\n     * @param user User address that will be joining the party\n     * @param amount Deposit amount in denomination asset\n     * @param allocation Desired allocation of the deposit\n     * @param approval Verified sentinel signature of the desired deposit\n     */\n    function joinParty(\n        address user,\n        uint256 amount,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) external;\n}\n"
    },
    "contracts/interfaces/party/IPartyManagerActions.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\n// Libraries\nimport {LibSignatures} from \"../../libraries/LibSignatures.sol\";\nimport {PartyInfo} from \"../../libraries/LibAppStorage.sol\";\n\n/**\n * @notice Contains party methods that can be called by any manager of the Party\n * @dev Permissioned Party actions\n */\ninterface IPartyManagerActions {\n    /**\n     * @notice Swap a token with the party's fund\n     * @dev The user must be a manager. Only swaps a single asset.\n     * @param allocation Desired allocation of the swap\n     * @param approval Verified sentinel signature of the desired swap\n     */\n    function swapToken(\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) external;\n\n    /**\n     * @notice Kick a member from the party\n     * @dev The user must be a manager\n     * @param kickingMember address of the member to be kicked\n     * @param allocation desired allocation of the withdraw\n     * @param approval verified sentinel signature of the desired kick\n     * @param liquidate whether to liquidate assets (convert all owned assets into denomination asset) or to transfer assets as it is\n     */\n    function kickMember(\n        address kickingMember,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) external;\n}\n"
    },
    "contracts/interfaces/party/IPartyState.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport {PartyInfo} from \"../../libraries/LibAppStorage.sol\";\n\n/**\n * @notice Methods that compose the party and that are mutable\n */\ninterface IPartyState {\n    /**\n     * @notice Queries the Party denomination asset (ERC-20)\n     * @dev The denomination asset is used for depositing into the party, which is an ERC-20 stablecoin\n     * @return Denomination asset address\n     */\n    function denominationAsset() external view returns (address);\n\n    /**\n     * @notice Queries the Party's creator address\n     * @return The address of the user who created the Party\n     */\n    function creator() external view returns (address);\n\n    /**\n     * @notice Queries the Party's member access of given address\n     * @param account Address\n     * @return Whether if the given address is a member\n     */\n    function members(address account) external view returns (bool);\n\n    /**\n     * @notice Queries the Party's manager access of given address\n     * @param account Address\n     * @return Whether if the given address is a manager\n     */\n    function managers(address account) external view returns (bool);\n\n    /**\n     * @notice Queries the ERC-20 tokens held in the Party\n     * @dev Will display the tokens that were acquired through a Swap/LimitOrder method\n     * @return Array of ERC-20 addresses\n     */\n    function getTokens() external view returns (address[] memory);\n\n    /**\n     * @notice Queries the party information\n     * @return PartyInfo struct\n     */\n    function partyInfo() external view returns (PartyInfo memory);\n\n    /**\n     * @notice Queries if the Party is closed\n     * @return Whether if the Party is already closed or not\n     */\n    function closed() external view returns (bool);\n}\n"
    },
    "contracts/interfaces/party/IPartyEvents.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\n/**\n * @notice Contains all events emitted by the party\n * @dev Events emitted by a party\n */\ninterface IPartyEvents {\n    /**\n     * @notice Emitted exactly once by a party when #initialize is first called\n     * @param partyCreator Address of the user that created the party\n     * @param partyName Name of the party\n     * @param isPublic Visibility of the party\n     * @param dAsset Address of the denomination asset for the party\n     * @param minDeposit Minimum deposit of the party\n     * @param maxDeposit Maximum deposit of the party\n     * @param mintedPT Minted party tokens for creating the party\n     * @param bio Bio of the party\n     * @param img Img url of the party\n     * @param model Model of party created\n     * @param purpose Purpose of party created\n     */\n    event PartyCreated(\n        address partyCreator,\n        string partyName,\n        bool isPublic,\n        address dAsset,\n        uint256 minDeposit,\n        uint256 maxDeposit,\n        uint256 mintedPT,\n        string bio,\n        string img,\n        string model,\n        string purpose\n    );\n\n    /**\n     * @notice Emitted when a user joins a party\n     * @param member Address of the user\n     * @param asset Address of the denomination asset\n     * @param amount Amount of the deposit\n     * @param fee Collected fee\n     * @param mintedPT Minted party tokens for joining\n     */\n    event Join(\n        address member,\n        address asset,\n        uint256 amount,\n        uint256 fee,\n        uint256 mintedPT\n    );\n\n    /**\n     * @notice Emitted when a member deposits denomination assets into a party\n     * @param member Address of the user\n     * @param asset Address of the denomination asset\n     * @param amount Amount of the deposit\n     * @param fee Collected fee\n     * @param mintedPT Minted party tokens for depositing\n     */\n    event Deposit(\n        address member,\n        address asset,\n        uint256 amount,\n        uint256 fee,\n        uint256 mintedPT\n    );\n\n    /**\n     * @notice Emitted when quotes are filled by 0x for allocation of funds\n     * @dev SwapToken is not included on this event, since its have the same information\n     * @param member Address of the user\n     * @param sellTokens Array of sell tokens\n     * @param buyTokens Array of buy tokens\n     * @param soldAmounts Array of sold amount of tokens\n     * @param boughtAmounts Array of bought amount of tokens\n     * @param partyValueDA The party value in denomination asset prior to the allocation\n     */\n    event AllocationFilled(\n        address member,\n        address[] sellTokens,\n        address[] buyTokens,\n        uint256[] soldAmounts,\n        uint256[] boughtAmounts,\n        uint256 partyValueDA\n    );\n\n    /**\n     * @notice Emitted when a member redeems shares from a party\n     * @param member Address of the user\n     * @param burnedPT Burned party tokens for redemption\n     * @param liquidate Redemption by liquitating shares into denomination asset\n     * @param redeemedAssets Array of asset addresses\n     * @param redeemedAmounts Array of asset amounts\n     * @param redeemedFees Array of asset fees\n     * @param redeemedNetAmounts Array of net asset amounts\n     */\n    event RedeemedShares(\n        address member,\n        uint256 burnedPT,\n        bool liquidate,\n        address[] redeemedAssets,\n        uint256[] redeemedAmounts,\n        uint256[] redeemedFees,\n        uint256[] redeemedNetAmounts\n    );\n\n    /**\n     * @notice Emitted when a member withdraws from a party\n     * @param member Address of the user\n     * @param burnedPT Burned party tokens of member\n     */\n    event Withdraw(address member, uint256 burnedPT);\n\n    /**\n     * @notice Emitted when quotes are filled by 0x in the same tx\n     * @param member Address of the user\n     * @param sellToken Sell token address\n     * @param buyToken Buy token address\n     * @param soldAmount Sold amount of token\n     * @param boughtAmount Bought amount of token\n     * @param fee fee collected\n     */\n    event SwapToken(\n        address member,\n        address sellToken,\n        address buyToken,\n        uint256 soldAmount,\n        uint256 boughtAmount,\n        uint256 fee\n    );\n\n    /**\n     * @notice Emitted when a member gets kicked from a party\n     * @param kicker Address of the kicker (owner)\n     * @param kicked Address of the kicked member\n     * @param burnedPT Burned party tokens of member\n     */\n    event Kick(address kicker, address kicked, uint256 burnedPT);\n\n    /**\n     * @notice Emitted when a member leaves a party\n     * @param member Address of the user\n     * @param burnedPT Burned party tokens for withdrawing\n     */\n    event Leave(address member, uint256 burnedPT);\n\n    /**\n     * @notice Emitted when the owner closes a party\n     * @param member Address of the user (should be party owner)\n     * @param supply Total supply of party tokens when the party closed\n     */\n    event Close(address member, uint256 supply);\n\n    /**\n     * @notice Emitted when the party information changes after creation\n     * @param name Name of the party\n     * @param bio Bio of the party\n     * @param img Img url of the party\n     * @param model Model of party created\n     * @param purpose Purpose of party created\n     * @param isPublic Visibility of the party\n     * @param minDeposit Minimum deposit of the party\n     * @param maxDeposit Maximum deposit of the party\n     */\n    event PartyInfoEdit(\n        string name,\n        string bio,\n        string img,\n        string model,\n        string purpose,\n        bool isPublic,\n        uint256 minDeposit,\n        uint256 maxDeposit\n    );\n\n    /**\n     * @notice Emitted when the party creator adds or remove a party manager\n     * @param manager Address of the user\n     * @param isManager Whether to set the user was set as manager or removed from it\n     */\n    event PartyManagersChange(address manager, bool isManager);\n}\n"
    },
    "contracts/interfaces/party/IPartyMemberActions.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\n// Libraries\nimport {LibSignatures} from \"../../libraries/LibSignatures.sol\";\n\n/**\n * @notice Contains party methods that can be called by any member of the party\n * @dev Permissioned Party actions\n */\ninterface IPartyMemberActions {\n    /**\n     * @notice Deposits into the party\n     * @dev The user must be a member and the party must be opened\n     * @param user User address that will be making the deposit\n     * @param amount Deposit amount in denomination asset\n     * @param allocation Desired allocation of the deposit\n     * @param approval Verified sentinel signature of the desired deposit\n     */\n    function deposit(\n        address user,\n        uint256 amount,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval\n    ) external;\n\n    /**\n     * @notice Withdraw funds from the party\n     * @dev The user must be a member\n     * @param amountPT Amount of PartyTokens of the requester to withdraw\n     * @param allocation Desired allocation of the withdraw\n     * @param approval Verified sentinel signature of the desired withdraw\n     * @param liquidate Whether to liquidate assets (convert all owned assets into denomination asset) or to withdraw assets as it is\n     */\n    function withdraw(\n        uint256 amountPT,\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) external;\n\n    /**\n     * @notice Leave the party (withdraw all funds and remove membership)\n     * @dev The user must be a member\n     * @param allocation Desired allocation of the withdraw\n     * @param approval Verified sentinel signature of the desired withdraw\n     * @param liquidate Whether to liquidate assets (convert all owned assets into denomination asset) or to withdraw assets as it is\n     */\n    function leaveParty(\n        LibSignatures.Allocation memory allocation,\n        LibSignatures.Sig memory approval,\n        bool liquidate\n    ) external;\n}\n"
    },
    "contracts/interfaces/party/IPartyCreatorActions.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\n// Libraries\nimport {LibSignatures} from \"../../libraries/LibSignatures.sol\";\nimport {PartyInfo} from \"../../libraries/LibAppStorage.sol\";\n\n/**\n * @notice Contains party methods that can be called by the creator of the Party\n * @dev Permissioned Party actions\n */\ninterface IPartyCreatorActions {\n    /**\n     * @notice Close the party\n     * @dev The user must be a creator and the party must be opened\n     */\n    function closeParty() external;\n\n    /**\n     * @notice Edits the party information\n     * @dev The user must be a creator\n     * @param _partyInfo PartyInfo struct\n     */\n    function editPartyInfo(PartyInfo memory _partyInfo) external;\n\n    /**\n     * @notice Handles the managers for the party\n     * @dev The user must be the creator of the party\n     * @param manager Address of the user\n     * @param setManager Whether to set the user as manager or remove it\n     */\n    function handleManager(address manager, bool setManager) external;\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 2000
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "metadata": {
      "useLiteralContent": true
    },
    "libraries": {}
  }
}