@towns-protocol/contracts 0.0.439 → 0.0.441

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towns-protocol/contracts",
3
- "version": "0.0.439",
3
+ "version": "0.0.441",
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.439",
36
+ "@towns-protocol/prettier-config": "^0.0.441",
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": "8e9e84d7be1d6fb6eadbd24b67db8bc7d495cc4c"
53
+ "gitHead": "7b6cdd45d3c3c2e94efdb26a68f4c8ff11e3699f"
54
54
  }
@@ -0,0 +1,188 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // interfaces
5
+ import {IDiamondInitHelper} from "./IDiamondInitHelper.sol";
6
+
7
+ // libraries
8
+ import {DeployDiamondCut} from "@towns-protocol/diamond/scripts/deployments/facets/DeployDiamondCut.sol";
9
+ import {DeployDiamondLoupe} from "@towns-protocol/diamond/scripts/deployments/facets/DeployDiamondLoupe.sol";
10
+ import {DeployIntrospection} from "@towns-protocol/diamond/scripts/deployments/facets/DeployIntrospection.sol";
11
+ import {DeployOwnable} from "@towns-protocol/diamond/scripts/deployments/facets/DeployOwnable.sol";
12
+ import {DeployMetadata} from "../facets/DeployMetadata.s.sol";
13
+ import {DeployAccountHubFacet} from "../facets/DeployAccountHubFacet.s.sol";
14
+ import {DeployAppManagerFacet} from "../facets/DeployAppManagerFacet.s.sol";
15
+ import {DeployAccountTippingFacet} from "../facets/DeployAccountTippingFacet.s.sol";
16
+ import {DeploySpaceFactory} from "./DeploySpaceFactory.s.sol";
17
+ import {DeployAppRegistry} from "./DeployAppRegistry.s.sol";
18
+ import {LibString} from "solady/utils/LibString.sol";
19
+
20
+ // contracts
21
+ import {Diamond} from "@towns-protocol/diamond/src/Diamond.sol";
22
+ import {MultiInit} from "@towns-protocol/diamond/src/initializers/MultiInit.sol";
23
+ import {DiamondHelper} from "@towns-protocol/diamond/scripts/common/helpers/DiamondHelper.s.sol";
24
+
25
+ // deployers
26
+ import {DeployFacet} from "../../common/DeployFacet.s.sol";
27
+ import {Deployer} from "../../common/Deployer.s.sol";
28
+
29
+ contract DeployAccountModules is IDiamondInitHelper, DiamondHelper, Deployer {
30
+ using LibString for string;
31
+
32
+ DeployFacet private facetHelper = new DeployFacet();
33
+ DeploySpaceFactory private deploySpaceFactory = new DeploySpaceFactory();
34
+ DeployAppRegistry private deployAppRegistry = new DeployAppRegistry();
35
+
36
+ address public spaceFactory;
37
+ address public appRegistry;
38
+
39
+ bytes32 internal constant METADATA_NAME = bytes32("AccountModules");
40
+
41
+ function versionName() public pure override returns (string memory) {
42
+ return "accountModules";
43
+ }
44
+
45
+ function setDependencies(address spaceFactory_, address appRegistry_) external {
46
+ spaceFactory = spaceFactory_;
47
+ appRegistry = appRegistry_;
48
+ }
49
+
50
+ function diamondInitHelper(
51
+ address deployer,
52
+ string[] memory facetNames
53
+ ) external override returns (FacetCut[] memory) {
54
+ for (uint256 i; i < facetNames.length; ++i) {
55
+ facetHelper.add(facetNames[i]);
56
+ }
57
+
58
+ facetHelper.deployBatch(deployer);
59
+
60
+ for (uint256 i; i < facetNames.length; ++i) {
61
+ string memory facetName = facetNames[i];
62
+ address facet = facetHelper.getDeployedAddress(facetName);
63
+
64
+ if (facetName.eq("AccountHubFacet")) {
65
+ addCut(makeCut(facet, FacetCutAction.Add, DeployAccountHubFacet.selectors()));
66
+ }
67
+ if (facetName.eq("AppManagerFacet")) {
68
+ addCut(makeCut(facet, FacetCutAction.Add, DeployAppManagerFacet.selectors()));
69
+ }
70
+ if (facetName.eq("AccountTippingFacet")) {
71
+ addCut(makeCut(facet, FacetCutAction.Add, DeployAccountTippingFacet.selectors()));
72
+ }
73
+ }
74
+
75
+ return baseFacets();
76
+ }
77
+
78
+ function diamondInitParams(address deployer) public returns (Diamond.InitParams memory) {
79
+ // Queue up feature facets for batch deployment
80
+ facetHelper.add("MultiInit");
81
+ facetHelper.add("MetadataFacet");
82
+ facetHelper.add("AccountHubFacet");
83
+ facetHelper.add("AppManagerFacet");
84
+ facetHelper.add("AccountTippingFacet");
85
+
86
+ facetHelper.deployBatch(deployer);
87
+
88
+ // Add feature facets
89
+ address facet = facetHelper.getDeployedAddress("MetadataFacet");
90
+ addFacet(
91
+ makeCut(facet, FacetCutAction.Add, DeployMetadata.selectors()),
92
+ facet,
93
+ DeployMetadata.makeInitData(METADATA_NAME, "")
94
+ );
95
+
96
+ facet = facetHelper.getDeployedAddress("AccountHubFacet");
97
+ addFacet(
98
+ makeCut(facet, FacetCutAction.Add, DeployAccountHubFacet.selectors()),
99
+ facet,
100
+ DeployAccountHubFacet.makeInitData(spaceFactory, appRegistry)
101
+ );
102
+
103
+ facet = facetHelper.getDeployedAddress("AppManagerFacet");
104
+ addFacet(
105
+ makeCut(facet, FacetCutAction.Add, DeployAppManagerFacet.selectors()),
106
+ facet,
107
+ DeployAppManagerFacet.makeInitData()
108
+ );
109
+
110
+ facet = facetHelper.getDeployedAddress("AccountTippingFacet");
111
+ addFacet(
112
+ makeCut(facet, FacetCutAction.Add, DeployAccountTippingFacet.selectors()),
113
+ facet,
114
+ DeployAccountTippingFacet.makeInitData()
115
+ );
116
+
117
+ address multiInit = facetHelper.getDeployedAddress("MultiInit");
118
+
119
+ return
120
+ Diamond.InitParams({
121
+ baseFacets: baseFacets(),
122
+ init: multiInit,
123
+ initData: abi.encodeCall(MultiInit.multiInit, (_initAddresses, _initDatas))
124
+ });
125
+ }
126
+
127
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
128
+ /* Internal */
129
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
130
+
131
+ function _resolveDependencies(address deployer) internal {
132
+ spaceFactory = spaceFactory == address(0)
133
+ ? deploySpaceFactory.deploy(deployer)
134
+ : spaceFactory;
135
+ appRegistry = appRegistry == address(0) ? deployAppRegistry.deploy(deployer) : appRegistry;
136
+ }
137
+
138
+ function _coreFacets(address deployer) internal {
139
+ // Deploy dependencies
140
+ _resolveDependencies(deployer);
141
+
142
+ // Queue up all core facets for batch deployment
143
+ facetHelper.add("DiamondCutFacet");
144
+ facetHelper.add("DiamondLoupeFacet");
145
+ facetHelper.add("IntrospectionFacet");
146
+ facetHelper.add("OwnableFacet");
147
+
148
+ // Get predicted addresses
149
+ address facet = facetHelper.predictAddress("DiamondCutFacet");
150
+ addFacet(
151
+ makeCut(facet, FacetCutAction.Add, DeployDiamondCut.selectors()),
152
+ facet,
153
+ DeployDiamondCut.makeInitData()
154
+ );
155
+
156
+ facet = facetHelper.predictAddress("DiamondLoupeFacet");
157
+ addFacet(
158
+ makeCut(facet, FacetCutAction.Add, DeployDiamondLoupe.selectors()),
159
+ facet,
160
+ DeployDiamondLoupe.makeInitData()
161
+ );
162
+
163
+ facet = facetHelper.predictAddress("IntrospectionFacet");
164
+ addFacet(
165
+ makeCut(facet, FacetCutAction.Add, DeployIntrospection.selectors()),
166
+ facet,
167
+ DeployIntrospection.makeInitData()
168
+ );
169
+
170
+ facet = facetHelper.predictAddress("OwnableFacet");
171
+ addFacet(
172
+ makeCut(facet, FacetCutAction.Add, DeployOwnable.selectors()),
173
+ facet,
174
+ DeployOwnable.makeInitData(deployer)
175
+ );
176
+ }
177
+
178
+ function __deploy(address deployer) internal override returns (address) {
179
+ _coreFacets(deployer);
180
+
181
+ Diamond.InitParams memory initDiamondCut = diamondInitParams(deployer);
182
+
183
+ vm.broadcast(deployer);
184
+ Diamond diamond = new Diamond(initDiamondCut);
185
+
186
+ return address(diamond);
187
+ }
188
+ }
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.29;
3
+
4
+ // interfaces
5
+
6
+ // contracts
7
+ import {LibDeploy} from "@towns-protocol/diamond/src/utils/LibDeploy.sol";
8
+ import {AccountHubFacet} from "src/account/facets/hub/AccountHubFacet.sol";
9
+ import {DynamicArrayLib} from "solady/utils/DynamicArrayLib.sol";
10
+
11
+ library DeployAccountHubFacet {
12
+ using DynamicArrayLib for DynamicArrayLib.DynamicArray;
13
+
14
+ function selectors() internal pure returns (bytes4[] memory res) {
15
+ DynamicArrayLib.DynamicArray memory arr = DynamicArrayLib.p().reserve(11);
16
+
17
+ // ERC-6900 functions
18
+ arr.p(AccountHubFacet.moduleId.selector);
19
+ arr.p(AccountHubFacet.onInstall.selector);
20
+ arr.p(AccountHubFacet.onUninstall.selector);
21
+ arr.p(AccountHubFacet.preExecutionHook.selector);
22
+ arr.p(AccountHubFacet.postExecutionHook.selector);
23
+ arr.p(AccountHubFacet.executionManifest.selector);
24
+
25
+ // External functions
26
+ arr.p(AccountHubFacet.setSpaceFactory.selector);
27
+ arr.p(AccountHubFacet.setAppRegistry.selector);
28
+ arr.p(AccountHubFacet.getSpaceFactory.selector);
29
+ arr.p(AccountHubFacet.getAppRegistry.selector);
30
+ arr.p(AccountHubFacet.isInstalled.selector);
31
+ bytes32[] memory selectors_ = arr.asBytes32Array();
32
+ assembly ("memory-safe") {
33
+ res := selectors_
34
+ }
35
+ }
36
+
37
+ function makeInitData(
38
+ address spaceFactory,
39
+ address appRegistry
40
+ ) internal pure returns (bytes memory) {
41
+ return abi.encodeCall(AccountHubFacet.__AccountHubFacet_init, (spaceFactory, appRegistry));
42
+ }
43
+
44
+ function deploy() internal returns (address) {
45
+ return LibDeploy.deployCode("AccountHubFacet.sol", "");
46
+ }
47
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.29;
3
+
4
+ // contracts
5
+ import {LibDeploy} from "@towns-protocol/diamond/src/utils/LibDeploy.sol";
6
+ import {AccountTippingFacet} from "src/account/facets/tipping/AccountTippingFacet.sol";
7
+ import {DynamicArrayLib} from "solady/utils/DynamicArrayLib.sol";
8
+
9
+ library DeployAccountTippingFacet {
10
+ using DynamicArrayLib for DynamicArrayLib.DynamicArray;
11
+
12
+ function selectors() internal pure returns (bytes4[] memory res) {
13
+ DynamicArrayLib.DynamicArray memory arr = DynamicArrayLib.p().reserve(8);
14
+
15
+ arr.p(AccountTippingFacet.sendTip.selector);
16
+ arr.p(AccountTippingFacet.tip.selector);
17
+ arr.p(AccountTippingFacet.tipsByWalletAndCurrency.selector);
18
+ arr.p(AccountTippingFacet.tipCountByWalletAndCurrency.selector);
19
+ arr.p(AccountTippingFacet.tipsByCurrencyAndTokenId.selector);
20
+ arr.p(AccountTippingFacet.tippingCurrencies.selector);
21
+ arr.p(AccountTippingFacet.totalTipsByCurrency.selector);
22
+ arr.p(AccountTippingFacet.tipAmountByCurrency.selector);
23
+
24
+ bytes32[] memory selectors_ = arr.asBytes32Array();
25
+ assembly ("memory-safe") {
26
+ res := selectors_
27
+ }
28
+ }
29
+
30
+ function makeInitData() internal pure returns (bytes memory) {
31
+ return abi.encodeCall(AccountTippingFacet.__AccountTippingFacet_init, ());
32
+ }
33
+
34
+ function deploy() internal returns (address) {
35
+ return LibDeploy.deployCode("AccountTippingFacet.sol", "");
36
+ }
37
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.23;
3
+
4
+ // contracts
5
+ import {LibDeploy} from "@towns-protocol/diamond/src/utils/LibDeploy.sol";
6
+ import {AppManagerFacet} from "src/account/facets/app/AppManagerFacet.sol";
7
+ import {DynamicArrayLib} from "solady/utils/DynamicArrayLib.sol";
8
+
9
+ library DeployAppManagerFacet {
10
+ using DynamicArrayLib for DynamicArrayLib.DynamicArray;
11
+
12
+ function selectors() internal pure returns (bytes4[] memory res) {
13
+ DynamicArrayLib.DynamicArray memory arr = DynamicArrayLib.p().reserve(11);
14
+
15
+ arr.p(AppManagerFacet.onInstallApp.selector);
16
+ arr.p(AppManagerFacet.onUninstallApp.selector);
17
+ arr.p(AppManagerFacet.onRenewApp.selector);
18
+ arr.p(AppManagerFacet.onUpdateApp.selector);
19
+ arr.p(AppManagerFacet.enableApp.selector);
20
+ arr.p(AppManagerFacet.disableApp.selector);
21
+ arr.p(AppManagerFacet.isAppInstalled.selector);
22
+ arr.p(AppManagerFacet.getAppId.selector);
23
+ arr.p(AppManagerFacet.getAppExpiration.selector);
24
+ arr.p(AppManagerFacet.getInstalledApps.selector);
25
+ arr.p(AppManagerFacet.isAppEntitled.selector);
26
+
27
+ bytes32[] memory selectors_ = arr.asBytes32Array();
28
+ assembly ("memory-safe") {
29
+ res := selectors_
30
+ }
31
+ }
32
+
33
+ function makeInitData() internal pure returns (bytes memory) {
34
+ return abi.encodeCall(AppManagerFacet.__AppManagerFacet_init, ());
35
+ }
36
+
37
+ function deploy() internal returns (address) {
38
+ return LibDeploy.deployCode("AppManagerFacet.sol", "");
39
+ }
40
+ }
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.29;
3
+
4
+ // interfaces
5
+ import {IAppAccount} from "src/spaces/facets/account/IAppAccount.sol";
6
+
7
+ // libraries
8
+ import "./AppManagerMod.sol" as AppManager;
9
+
10
+ // contracts
11
+ import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
12
+ import {ReentrancyGuardTransient} from "solady/utils/ReentrancyGuardTransient.sol";
13
+
14
+ contract AppManagerFacet is IAppAccount, ReentrancyGuardTransient, Facet {
15
+ function __AppManagerFacet_init() external onlyInitializing {
16
+ _addInterface(type(IAppAccount).interfaceId);
17
+ }
18
+
19
+ function __AppManagerFacet_init_unchained() internal {}
20
+
21
+ function onInstallApp(bytes32 appId, bytes calldata data) external nonReentrant {
22
+ AppManager.installApp(msg.sender, appId, data);
23
+ }
24
+
25
+ function onUninstallApp(bytes32 appId, bytes calldata data) external nonReentrant {
26
+ AppManager.uninstallApp(msg.sender, appId, data);
27
+ }
28
+
29
+ function onRenewApp(bytes32 appId, bytes calldata data) external nonReentrant {
30
+ AppManager.renewApp(msg.sender, appId, data);
31
+ }
32
+
33
+ function onUpdateApp(bytes32 appId, bytes calldata data) external nonReentrant {
34
+ AppManager.updateApp(msg.sender, appId, data);
35
+ }
36
+
37
+ function enableApp(address app) external nonReentrant {
38
+ AppManager.enableApp(msg.sender, app);
39
+ }
40
+
41
+ function disableApp(address app) external nonReentrant {
42
+ AppManager.disableApp(msg.sender, app);
43
+ }
44
+
45
+ function isAppInstalled(address app) external view returns (bool) {
46
+ return AppManager.isAppInstalled(msg.sender, app);
47
+ }
48
+
49
+ function getAppId(address app) external view returns (bytes32) {
50
+ return AppManager.getAppId(msg.sender, app);
51
+ }
52
+
53
+ function getAppExpiration(address app) external view returns (uint48) {
54
+ return AppManager.getAppExpiration(msg.sender, app);
55
+ }
56
+
57
+ function getInstalledApps() external view returns (address[] memory) {
58
+ return AppManager.getInstalledApps(msg.sender);
59
+ }
60
+
61
+ function isAppEntitled(
62
+ address app,
63
+ address publicKey,
64
+ bytes32 permission
65
+ ) external view returns (bool) {
66
+ return AppManager.isAppEntitled(msg.sender, app, publicKey, permission);
67
+ }
68
+ }