@towns-protocol/contracts 0.0.441 → 0.0.442
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/scripts/deployments/diamonds/DeploySpace.s.sol +0 -7
- package/scripts/interactions/InteractBaseAlpha.s.sol +3 -0
- package/src/apps/facets/registry/AppRegistryBase.sol +4 -2
- package/src/apps/facets/registry/IAppRegistry.sol +1 -1
- package/src/factory/facets/architect/IArchitect.sol +1 -0
- package/src/factory/facets/create/CreateSpaceBase.sol +2 -9
- package/src/spaces/facets/membership/IMembership.sol +0 -16
- package/src/spaces/facets/membership/join/MembershipJoin.sol +6 -15
- package/src/spaces/facets/xchain/SpaceEntitlementGated.sol +0 -2
- package/scripts/deployments/facets/DeployPrepayFacet.s.sol +0 -31
- package/scripts/interactions/InteractPrepay.s.sol +0 -30
- package/src/spaces/facets/prepay/IPrepay.sol +0 -44
- package/src/spaces/facets/prepay/PrepayBase.sol +0 -27
- package/src/spaces/facets/prepay/PrepayFacet.sol +0 -65
- package/src/spaces/facets/prepay/PrepayStorage.sol +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@towns-protocol/contracts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.442",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"clean": "forge clean",
|
|
6
6
|
"compile": "forge build",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@layerzerolabs/oapp-evm": "^0.3.2",
|
|
34
34
|
"@openzeppelin/merkle-tree": "^1.0.8",
|
|
35
35
|
"@prb/test": "^0.6.4",
|
|
36
|
-
"@towns-protocol/prettier-config": "^0.0.
|
|
36
|
+
"@towns-protocol/prettier-config": "^0.0.442",
|
|
37
37
|
"@wagmi/cli": "^2.2.0",
|
|
38
38
|
"forge-std": "github:foundry-rs/forge-std#v1.10.0",
|
|
39
39
|
"prettier": "^3.5.3",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "d2e07ef0deb899067d0d1a47e30c4edd5bb22547"
|
|
54
54
|
}
|
|
@@ -20,7 +20,6 @@ import {DeployEntitlementsManager} from "../facets/DeployEntitlementsManager.s.s
|
|
|
20
20
|
import {DeployMembership} from "../facets/DeployMembership.s.sol";
|
|
21
21
|
import {DeployMembershipMetadata} from "../facets/DeployMembershipMetadata.s.sol";
|
|
22
22
|
import {DeployMembershipToken} from "../facets/DeployMembershipToken.s.sol";
|
|
23
|
-
import {DeployPrepayFacet} from "../facets/DeployPrepayFacet.s.sol";
|
|
24
23
|
import {DeployReferrals} from "../facets/DeployReferrals.s.sol";
|
|
25
24
|
import {DeployReviewFacet} from "../facets/DeployReviewFacet.s.sol";
|
|
26
25
|
import {DeployRoles} from "../facets/DeployRoles.s.sol";
|
|
@@ -112,7 +111,6 @@ contract DeploySpace is IDiamondInitHelper, DiamondHelper, Deployer {
|
|
|
112
111
|
facetHelper.add("Roles");
|
|
113
112
|
facetHelper.add("Channels");
|
|
114
113
|
facetHelper.add("TokenPausableFacet");
|
|
115
|
-
facetHelper.add("PrepayFacet");
|
|
116
114
|
facetHelper.add("ReferralsFacet");
|
|
117
115
|
facetHelper.add("ReviewFacet");
|
|
118
116
|
|
|
@@ -164,9 +162,6 @@ contract DeploySpace is IDiamondInitHelper, DiamondHelper, Deployer {
|
|
|
164
162
|
facet = facetHelper.getDeployedAddress("TokenPausableFacet");
|
|
165
163
|
addCut(makeCut(facet, FacetCutAction.Add, DeployTokenPausable.selectors()));
|
|
166
164
|
|
|
167
|
-
facet = facetHelper.getDeployedAddress("PrepayFacet");
|
|
168
|
-
addCut(makeCut(facet, FacetCutAction.Add, DeployPrepayFacet.selectors()));
|
|
169
|
-
|
|
170
165
|
facet = facetHelper.getDeployedAddress("ReferralsFacet");
|
|
171
166
|
addCut(makeCut(facet, FacetCutAction.Add, DeployReferrals.selectors()));
|
|
172
167
|
|
|
@@ -247,8 +242,6 @@ contract DeploySpace is IDiamondInitHelper, DiamondHelper, Deployer {
|
|
|
247
242
|
addCut(makeCut(facet, FacetCutAction.Add, DeployChannels.selectors()));
|
|
248
243
|
} else if (facetName.eq("TokenPausableFacet")) {
|
|
249
244
|
addCut(makeCut(facet, FacetCutAction.Add, DeployTokenPausable.selectors()));
|
|
250
|
-
} else if (facetName.eq("PrepayFacet")) {
|
|
251
|
-
addCut(makeCut(facet, FacetCutAction.Add, DeployPrepayFacet.selectors()));
|
|
252
245
|
} else if (facetName.eq("ReferralsFacet")) {
|
|
253
246
|
addCut(makeCut(facet, FacetCutAction.Add, DeployReferrals.selectors()));
|
|
254
247
|
} else if (facetName.eq("ReviewFacet")) {
|
|
@@ -38,8 +38,11 @@ contract InteractBaseAlpha is AlphaHelper {
|
|
|
38
38
|
executeDiamondCutsWithLogging(deployer, space, "Space", deploySpace);
|
|
39
39
|
executeDiamondCutsWithLogging(deployer, spaceOwner, "SpaceOwner", deploySpaceOwner);
|
|
40
40
|
|
|
41
|
+
deploySpaceFactory.diamondInitParams(deployer);
|
|
41
42
|
address spaceFactoryInit = deploySpaceFactory.spaceFactoryInit();
|
|
42
43
|
bytes memory initData = deploySpaceFactory.spaceFactoryInitData();
|
|
44
|
+
deploySpaceFactory.clearCuts();
|
|
45
|
+
|
|
43
46
|
executeDiamondCutsWithLogging(
|
|
44
47
|
deployer,
|
|
45
48
|
spaceFactory,
|
|
@@ -9,7 +9,6 @@ import {ITownsApp} from "../../ITownsApp.sol";
|
|
|
9
9
|
import {IAppRegistryBase} from "./IAppRegistry.sol";
|
|
10
10
|
import {ISchemaResolver} from "@ethereum-attestation-service/eas-contracts/resolver/ISchemaResolver.sol";
|
|
11
11
|
import {IPlatformRequirements} from "../../../factory/facets/platform/requirements/IPlatformRequirements.sol";
|
|
12
|
-
import {IERC173} from "@towns-protocol/diamond/src/facets/ownable/IERC173.sol";
|
|
13
12
|
import {IAppAccount} from "../../../spaces/facets/account/IAppAccount.sol";
|
|
14
13
|
import {IEntitlementsManager} from "../../../spaces/facets/entitlements/IEntitlementsManager.sol";
|
|
15
14
|
|
|
@@ -320,7 +319,7 @@ abstract contract AppRegistryBase is IAppRegistryBase, SchemaBase, AttestationBa
|
|
|
320
319
|
uint256 installPrice
|
|
321
320
|
) internal view returns (uint256 totalRequired, uint256 protocolFee) {
|
|
322
321
|
protocolFee = _getProtocolFee(installPrice);
|
|
323
|
-
if (installPrice == 0) return (
|
|
322
|
+
if (installPrice == 0) return (0, protocolFee);
|
|
324
323
|
return (installPrice + protocolFee, protocolFee);
|
|
325
324
|
}
|
|
326
325
|
|
|
@@ -332,6 +331,9 @@ abstract contract AppRegistryBase is IAppRegistryBase, SchemaBase, AttestationBa
|
|
|
332
331
|
function _chargeForInstall(address payer, address recipient, uint256 installPrice) internal {
|
|
333
332
|
(uint256 totalRequired, uint256 protocolFee) = _getTotalRequiredPayment(installPrice);
|
|
334
333
|
|
|
334
|
+
if (totalRequired == 0 && msg.value != 0) UnexpectedETH.selector.revertWith();
|
|
335
|
+
if (totalRequired == 0) return;
|
|
336
|
+
|
|
335
337
|
if (msg.value < totalRequired) InsufficientPayment.selector.revertWith();
|
|
336
338
|
|
|
337
339
|
// Cache platform requirements to avoid multiple storage reads
|
|
@@ -3,7 +3,6 @@ pragma solidity ^0.8.23;
|
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {ISchemaResolver} from "@ethereum-attestation-service/eas-contracts/resolver/ISchemaResolver.sol";
|
|
6
|
-
import {IAppAccount} from "../../../spaces/facets/account/IAppAccount.sol";
|
|
7
6
|
import {ITownsApp} from "../../ITownsApp.sol";
|
|
8
7
|
|
|
9
8
|
// libraries
|
|
@@ -39,6 +38,7 @@ interface IAppRegistryBase {
|
|
|
39
38
|
error NotAllowed();
|
|
40
39
|
error ClientAlreadyRegistered();
|
|
41
40
|
error ClientNotRegistered();
|
|
41
|
+
error UnexpectedETH();
|
|
42
42
|
|
|
43
43
|
error AppRegistry__InvalidDuration();
|
|
44
44
|
error AppRegistry__InvalidPrice();
|
|
@@ -97,6 +97,7 @@ interface IArchitectBase {
|
|
|
97
97
|
error Architect__InvalidAddress();
|
|
98
98
|
error Architect__NotContract();
|
|
99
99
|
error Architect__InvalidPricingModule();
|
|
100
|
+
error Architect__UnexpectedETH();
|
|
100
101
|
|
|
101
102
|
event Architect__ProxyInitializerSet(address indexed proxyInitializer);
|
|
102
103
|
}
|
|
@@ -12,7 +12,6 @@ import {IUserEntitlement} from "../../../spaces/entitlements/user/IUserEntitleme
|
|
|
12
12
|
import {IChannel} from "../../../spaces/facets/channels/IChannel.sol";
|
|
13
13
|
import {IEntitlementsManager} from "../../../spaces/facets/entitlements/IEntitlementsManager.sol";
|
|
14
14
|
import {IMembershipBase} from "../../../spaces/facets/membership/IMembership.sol";
|
|
15
|
-
import {IPrepay} from "../../../spaces/facets/prepay/IPrepay.sol";
|
|
16
15
|
import {IRoles, IRolesBase} from "../../../spaces/facets/roles/IRoles.sol";
|
|
17
16
|
import {IArchitectBase} from "../architect/IArchitect.sol";
|
|
18
17
|
|
|
@@ -43,6 +42,7 @@ abstract contract CreateSpaceBase is IArchitectBase {
|
|
|
43
42
|
CreateSpace calldata space,
|
|
44
43
|
SpaceOptions memory spaceOptions
|
|
45
44
|
) internal returns (address spaceAddress) {
|
|
45
|
+
if (msg.value > 0) revert Architect__UnexpectedETH();
|
|
46
46
|
Validator.checkAddress(space.membership.settings.pricingModule);
|
|
47
47
|
Validator.checkAddress(spaceOptions.to);
|
|
48
48
|
|
|
@@ -54,10 +54,6 @@ abstract contract CreateSpaceBase is IArchitectBase {
|
|
|
54
54
|
space.channel,
|
|
55
55
|
spaceOptions
|
|
56
56
|
);
|
|
57
|
-
|
|
58
|
-
if (space.prepay.supply > 0) {
|
|
59
|
-
IPrepay(spaceAddress).prepayMembership{value: msg.value}(space.prepay.supply);
|
|
60
|
-
}
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
/// @dev Converts legacy CreateSpaceOld format and creates space
|
|
@@ -65,6 +61,7 @@ abstract contract CreateSpaceBase is IArchitectBase {
|
|
|
65
61
|
CreateSpaceOld calldata space,
|
|
66
62
|
SpaceOptions memory spaceOptions
|
|
67
63
|
) internal returns (address spaceAddress) {
|
|
64
|
+
if (msg.value > 0) revert Architect__UnexpectedETH();
|
|
68
65
|
Validator.checkAddress(space.membership.settings.pricingModule);
|
|
69
66
|
Validator.checkAddress(spaceOptions.to);
|
|
70
67
|
|
|
@@ -84,10 +81,6 @@ abstract contract CreateSpaceBase is IArchitectBase {
|
|
|
84
81
|
space.channel,
|
|
85
82
|
spaceOptions
|
|
86
83
|
);
|
|
87
|
-
|
|
88
|
-
if (space.prepay.supply > 0) {
|
|
89
|
-
IPrepay(spaceAddress).prepayMembership{value: msg.value}(space.prepay.supply);
|
|
90
|
-
}
|
|
91
84
|
}
|
|
92
85
|
|
|
93
86
|
function _createSpaceCore(
|
|
@@ -41,38 +41,22 @@ interface IMembershipBase {
|
|
|
41
41
|
string referralCode;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
struct PricingDetails {
|
|
45
|
-
uint256 basePrice;
|
|
46
|
-
uint256 amountDue;
|
|
47
|
-
bool shouldCharge;
|
|
48
|
-
bool isPrepaid;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
44
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
52
45
|
/* ERRORS */
|
|
53
46
|
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
|
|
54
47
|
|
|
55
48
|
error Membership__InvalidAddress();
|
|
56
|
-
error Membership__InvalidPrice();
|
|
57
|
-
error Membership__InvalidLimit();
|
|
58
|
-
error Membership__InvalidCurrency();
|
|
59
|
-
error Membership__InvalidFeeRecipient();
|
|
60
49
|
error Membership__InvalidDuration();
|
|
61
50
|
error Membership__InvalidMaxSupply();
|
|
62
51
|
error Membership__InvalidFreeAllocation();
|
|
63
52
|
error Membership__InvalidPricingModule();
|
|
64
|
-
error Membership__AlreadyMember();
|
|
65
53
|
error Membership__InsufficientPayment();
|
|
66
54
|
error Membership__MaxSupplyReached();
|
|
67
|
-
error Membership__InvalidTokenId();
|
|
68
|
-
error Membership__NotExpired();
|
|
69
|
-
error Membership__InsufficientAllowance();
|
|
70
55
|
error Membership__InvalidPayment();
|
|
71
56
|
error Membership__InvalidTransactionType();
|
|
72
57
|
error Membership__Banned();
|
|
73
58
|
error Membership__InvalidAction();
|
|
74
59
|
error Membership__CannotSetFreeAllocationOnPaidSpace();
|
|
75
|
-
error Membership__CannotSetPriceOnFreeSpace();
|
|
76
60
|
|
|
77
61
|
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
|
|
78
62
|
/* EVENTS */
|
|
@@ -22,7 +22,6 @@ import {DispatcherBase} from "../../dispatcher/DispatcherBase.sol";
|
|
|
22
22
|
import {Entitled} from "../../Entitled.sol";
|
|
23
23
|
import {EntitlementGatedBase} from "../../gated/EntitlementGatedBase.sol";
|
|
24
24
|
import {PointsBase} from "../../points/PointsBase.sol";
|
|
25
|
-
import {PrepayBase} from "../../prepay/PrepayBase.sol";
|
|
26
25
|
import {ReferralsBase} from "../../referrals/ReferralsBase.sol";
|
|
27
26
|
import {RolesBase} from "../../roles/RolesBase.sol";
|
|
28
27
|
import {MembershipBase} from "../MembershipBase.sol";
|
|
@@ -41,7 +40,6 @@ abstract contract MembershipJoin is
|
|
|
41
40
|
RolesBase,
|
|
42
41
|
EntitlementGatedBase,
|
|
43
42
|
Entitled,
|
|
44
|
-
PrepayBase,
|
|
45
43
|
PointsBase,
|
|
46
44
|
ERC721ABase
|
|
47
45
|
{
|
|
@@ -53,6 +51,12 @@ abstract contract MembershipJoin is
|
|
|
53
51
|
/// @notice Constant representing the joinSpace(address) function selector
|
|
54
52
|
bytes4 internal constant JOIN_SPACE_SELECTOR = bytes4(keccak256("joinSpace(address)"));
|
|
55
53
|
|
|
54
|
+
struct PricingDetails {
|
|
55
|
+
uint256 basePrice;
|
|
56
|
+
uint256 amountDue;
|
|
57
|
+
bool shouldCharge;
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
/// @notice Encodes data for joining a space
|
|
57
61
|
/// @param selector The type of transaction (join with or without referral)
|
|
58
62
|
/// @param sender The address of the sender
|
|
@@ -82,13 +86,6 @@ abstract contract MembershipJoin is
|
|
|
82
86
|
return joinDetails;
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
// Check if this is a free join due to prepaid supply
|
|
86
|
-
uint256 prepaidSupply = _getPrepaidSupply();
|
|
87
|
-
if (prepaidSupply > 0) {
|
|
88
|
-
joinDetails.isPrepaid = true;
|
|
89
|
-
return joinDetails;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
89
|
(uint256 totalRequired, ) = _getTotalMembershipPayment(membershipPrice);
|
|
93
90
|
(joinDetails.amountDue, joinDetails.shouldCharge) = (totalRequired, true);
|
|
94
91
|
}
|
|
@@ -105,9 +102,6 @@ abstract contract MembershipJoin is
|
|
|
105
102
|
Membership__InsufficientPayment.selector.revertWith();
|
|
106
103
|
}
|
|
107
104
|
|
|
108
|
-
// Consume prepaid membership if applicable
|
|
109
|
-
if (joinDetails.isPrepaid) _reducePrepay(1);
|
|
110
|
-
|
|
111
105
|
bytes32 transactionId = _registerTransaction(
|
|
112
106
|
receiver,
|
|
113
107
|
_encodeJoinSpaceData(JOIN_SPACE_SELECTOR, msg.sender, receiver, "")
|
|
@@ -144,9 +138,6 @@ abstract contract MembershipJoin is
|
|
|
144
138
|
Membership__InsufficientPayment.selector.revertWith();
|
|
145
139
|
}
|
|
146
140
|
|
|
147
|
-
// Consume prepaid membership if applicable
|
|
148
|
-
if (joinDetails.isPrepaid) _reducePrepay(1);
|
|
149
|
-
|
|
150
141
|
_validateUserReferral(receiver, referral);
|
|
151
142
|
|
|
152
143
|
bytes memory referralData = abi.encode(referral);
|
|
@@ -4,8 +4,6 @@ pragma solidity ^0.8.23;
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {IMembership} from "../membership/IMembership.sol";
|
|
6
6
|
|
|
7
|
-
// libraries
|
|
8
|
-
|
|
9
7
|
// contracts
|
|
10
8
|
import {EntitlementGated} from "../gated/EntitlementGated.sol";
|
|
11
9
|
import {MembershipJoin} from "../membership/join/MembershipJoin.sol";
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.23;
|
|
3
|
-
|
|
4
|
-
//interfaces
|
|
5
|
-
import {IDiamond} from "@towns-protocol/diamond/src/Diamond.sol";
|
|
6
|
-
import {IPrepay} from "src/spaces/facets/prepay/IPrepay.sol";
|
|
7
|
-
|
|
8
|
-
//libraries
|
|
9
|
-
import {LibDeploy} from "@towns-protocol/diamond/src/utils/LibDeploy.sol";
|
|
10
|
-
|
|
11
|
-
//contracts
|
|
12
|
-
|
|
13
|
-
library DeployPrepayFacet {
|
|
14
|
-
function selectors() internal pure returns (bytes4[] memory res) {
|
|
15
|
-
res = new bytes4[](3);
|
|
16
|
-
res[0] = IPrepay.prepayMembership.selector;
|
|
17
|
-
res[1] = IPrepay.prepaidMembershipSupply.selector;
|
|
18
|
-
res[2] = IPrepay.calculateMembershipPrepayFee.selector;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function makeCut(
|
|
22
|
-
address facetAddress,
|
|
23
|
-
IDiamond.FacetCutAction action
|
|
24
|
-
) internal pure returns (IDiamond.FacetCut memory) {
|
|
25
|
-
return IDiamond.FacetCut(facetAddress, action, selectors());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function deploy() internal returns (address) {
|
|
29
|
-
return LibDeploy.deployCode("PrepayFacet.sol", "");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.23;
|
|
3
|
-
|
|
4
|
-
// interfaces
|
|
5
|
-
|
|
6
|
-
// libraries
|
|
7
|
-
|
|
8
|
-
// contracts
|
|
9
|
-
import {Interaction} from "scripts/common/Interaction.s.sol";
|
|
10
|
-
import {IPrepay} from "src/spaces/facets/prepay/IPrepay.sol";
|
|
11
|
-
|
|
12
|
-
// debuggging
|
|
13
|
-
import {console} from "forge-std/console.sol";
|
|
14
|
-
|
|
15
|
-
contract InteractPrepay is Interaction {
|
|
16
|
-
IPrepay prepay = IPrepay(0x0000000000000000000000000000000000000000);
|
|
17
|
-
|
|
18
|
-
function __interact(address deployer) internal override {
|
|
19
|
-
uint256 expectedAmount = 1000;
|
|
20
|
-
uint256 totalAmount = prepay.calculateMembershipPrepayFee(expectedAmount);
|
|
21
|
-
|
|
22
|
-
console.log("paying:", totalAmount);
|
|
23
|
-
|
|
24
|
-
vm.startBroadcast(deployer);
|
|
25
|
-
IPrepay(prepay).prepayMembership{value: totalAmount}(expectedAmount);
|
|
26
|
-
vm.stopBroadcast();
|
|
27
|
-
|
|
28
|
-
console.log("prepaidSupply", prepay.prepaidMembershipSupply());
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.23;
|
|
3
|
-
|
|
4
|
-
// interfaces
|
|
5
|
-
|
|
6
|
-
// libraries
|
|
7
|
-
|
|
8
|
-
// contracts
|
|
9
|
-
interface IPrepayBase {
|
|
10
|
-
// =============================================================
|
|
11
|
-
// ERRORS
|
|
12
|
-
// =============================================================
|
|
13
|
-
error Prepay__InvalidSupplyAmount();
|
|
14
|
-
error Prepay__InvalidAmount();
|
|
15
|
-
error Prepay__InvalidAddress();
|
|
16
|
-
error Prepay__InvalidMembership();
|
|
17
|
-
error Prepay__NotAllowed();
|
|
18
|
-
|
|
19
|
-
// =============================================================
|
|
20
|
-
// EVENTS
|
|
21
|
-
// =============================================================
|
|
22
|
-
event Prepay__Prepaid(uint256 supply);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface IPrepay is IPrepayBase {
|
|
26
|
-
/**
|
|
27
|
-
* @notice Prepay a membership
|
|
28
|
-
* @param supply The amount of memberships to prepay
|
|
29
|
-
*/
|
|
30
|
-
function prepayMembership(uint256 supply) external payable;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @notice Get the prepaid supply
|
|
34
|
-
* @return The remaining prepaid supply
|
|
35
|
-
*/
|
|
36
|
-
function prepaidMembershipSupply() external view returns (uint256);
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @notice Calculate the prepay fee for a given supply
|
|
40
|
-
* @param supply The supply to calculate the fee for
|
|
41
|
-
* @return The fee
|
|
42
|
-
*/
|
|
43
|
-
function calculateMembershipPrepayFee(uint256 supply) external view returns (uint256);
|
|
44
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.23;
|
|
3
|
-
|
|
4
|
-
// interfaces
|
|
5
|
-
import {IPrepayBase} from "./IPrepay.sol";
|
|
6
|
-
|
|
7
|
-
// libraries
|
|
8
|
-
import {PrepayStorage} from "./PrepayStorage.sol";
|
|
9
|
-
|
|
10
|
-
// contracts
|
|
11
|
-
|
|
12
|
-
abstract contract PrepayBase is IPrepayBase {
|
|
13
|
-
function _addPrepay(uint256 supply) internal {
|
|
14
|
-
PrepayStorage.Layout storage ds = PrepayStorage.layout();
|
|
15
|
-
ds.supply += supply;
|
|
16
|
-
emit Prepay__Prepaid(supply);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _reducePrepay(uint256 supply) internal {
|
|
20
|
-
PrepayStorage.Layout storage ds = PrepayStorage.layout();
|
|
21
|
-
ds.supply -= supply;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function _getPrepaidSupply() internal view returns (uint256) {
|
|
25
|
-
return PrepayStorage.layout().supply;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.23;
|
|
3
|
-
|
|
4
|
-
// interfaces
|
|
5
|
-
|
|
6
|
-
import {IPlatformRequirements} from "src/factory/facets/platform/requirements/IPlatformRequirements.sol";
|
|
7
|
-
import {IPrepay} from "src/spaces/facets/prepay/IPrepay.sol";
|
|
8
|
-
|
|
9
|
-
// libraries
|
|
10
|
-
import {MembershipStorage} from "src/spaces/facets/membership/MembershipStorage.sol";
|
|
11
|
-
import {CurrencyTransfer} from "src/utils/libraries/CurrencyTransfer.sol";
|
|
12
|
-
|
|
13
|
-
// contracts
|
|
14
|
-
import {PrepayBase} from "./PrepayBase.sol";
|
|
15
|
-
|
|
16
|
-
import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
|
|
17
|
-
import {Entitled} from "src/spaces/facets/Entitled.sol";
|
|
18
|
-
import {ReentrancyGuard} from "solady/utils/ReentrancyGuard.sol";
|
|
19
|
-
|
|
20
|
-
contract PrepayFacet is IPrepay, PrepayBase, ReentrancyGuard, Entitled, Facet {
|
|
21
|
-
function __PrepayFacet_init() external onlyInitializing {
|
|
22
|
-
_addInterface(type(IPrepay).interfaceId);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function prepayMembership(uint256 supply) external payable nonReentrant {
|
|
26
|
-
_validatePrepayCaller();
|
|
27
|
-
if (supply == 0) revert Prepay__InvalidSupplyAmount();
|
|
28
|
-
|
|
29
|
-
MembershipStorage.Layout storage ds = MembershipStorage.layout();
|
|
30
|
-
IPlatformRequirements platform = IPlatformRequirements(ds.spaceFactory);
|
|
31
|
-
|
|
32
|
-
uint256 cost = supply * platform.getMembershipFee();
|
|
33
|
-
|
|
34
|
-
// validate payment covers membership fee
|
|
35
|
-
if (msg.value != cost) revert Prepay__InvalidAmount();
|
|
36
|
-
|
|
37
|
-
// add prepay
|
|
38
|
-
_addPrepay(supply);
|
|
39
|
-
|
|
40
|
-
// transfer fee to platform recipient
|
|
41
|
-
address currency = ds.membershipCurrency;
|
|
42
|
-
address platformRecipient = platform.getFeeRecipient();
|
|
43
|
-
CurrencyTransfer.transferCurrency(
|
|
44
|
-
currency,
|
|
45
|
-
msg.sender, // from
|
|
46
|
-
platformRecipient, // to
|
|
47
|
-
cost
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function prepaidMembershipSupply() external view returns (uint256) {
|
|
52
|
-
return _getPrepaidSupply();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function calculateMembershipPrepayFee(uint256 supply) external view returns (uint256) {
|
|
56
|
-
MembershipStorage.Layout storage ds = MembershipStorage.layout();
|
|
57
|
-
IPlatformRequirements platform = IPlatformRequirements(ds.spaceFactory);
|
|
58
|
-
return supply * platform.getMembershipFee();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function _validatePrepayCaller() internal view {
|
|
62
|
-
address spaceFactory = MembershipStorage.layout().spaceFactory;
|
|
63
|
-
if (msg.sender != spaceFactory && msg.sender != _owner()) revert Prepay__NotAllowed();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.23;
|
|
3
|
-
|
|
4
|
-
// interfaces
|
|
5
|
-
|
|
6
|
-
// libraries
|
|
7
|
-
|
|
8
|
-
// contracts
|
|
9
|
-
|
|
10
|
-
library PrepayStorage {
|
|
11
|
-
// keccak256(abi.encode(uint256(keccak256("spaces.facets.prepay.storage")) - 1)) &
|
|
12
|
-
// ~bytes32(uint256(0xff))
|
|
13
|
-
bytes32 constant STORAGE_SLOT =
|
|
14
|
-
0x097b4f25b64e012d0cf55f67e9b34fe5d57f15b11b95baa4ddd136b424967c00;
|
|
15
|
-
|
|
16
|
-
struct Layout {
|
|
17
|
-
uint256 supply;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function layout() internal pure returns (Layout storage l) {
|
|
21
|
-
bytes32 slot = STORAGE_SLOT;
|
|
22
|
-
assembly {
|
|
23
|
-
l.slot := slot
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|