@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.
@@ -0,0 +1,25 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.29;
3
+
4
+ interface IAccountHub {
5
+ /// @notice Sets the space factory
6
+ /// @param spaceFactory The address of the space factory
7
+ function setSpaceFactory(address spaceFactory) external;
8
+
9
+ /// @notice Sets the app registry
10
+ /// @param appRegistry The address of the app registry
11
+ function setAppRegistry(address appRegistry) external;
12
+
13
+ /// @notice Gets the space factory
14
+ /// @return The address of the space factory
15
+ function getSpaceFactory() external view returns (address);
16
+
17
+ /// @notice Gets the app registry
18
+ /// @return The address of the app registry
19
+ function getAppRegistry() external view returns (address);
20
+
21
+ /// @notice Checks if an account is installed
22
+ /// @param account The address of the account
23
+ /// @return True if the account is installed, false otherwise
24
+ function isInstalled(address account) external view returns (bool);
25
+ }
@@ -0,0 +1,72 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.29;
3
+
4
+ // interfaces
5
+ import {ITipping} from "src/spaces/facets/tipping/ITipping.sol";
6
+
7
+ // libraries
8
+ import "./AccountTippingMod.sol" as AccountTipping;
9
+ import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol";
10
+ import {CustomRevert} from "../../../utils/libraries/CustomRevert.sol";
11
+
12
+ // contracts
13
+ import {Facet} from "@towns-protocol/diamond/src/facets/Facet.sol";
14
+ import {ReentrancyGuardTransient} from "solady/utils/ReentrancyGuardTransient.sol";
15
+
16
+ contract AccountTippingFacet is ITipping, ReentrancyGuardTransient, Facet {
17
+ using EnumerableSetLib for EnumerableSetLib.AddressSet;
18
+ using CustomRevert for bytes4;
19
+
20
+ function __AccountTippingFacet_init() external onlyInitializing {
21
+ _addInterface(type(ITipping).interfaceId);
22
+ }
23
+
24
+ /// @inheritdoc ITipping
25
+ function sendTip(
26
+ TipRecipientType recipientType,
27
+ bytes calldata data
28
+ ) external payable nonReentrant {
29
+ AccountTipping.tipAny(address(this), uint8(recipientType), data);
30
+ }
31
+
32
+ /// @inheritdoc ITipping
33
+ function tip(TipRequest calldata) external payable {
34
+ CustomRevert.revertWith(Deprecated.selector);
35
+ }
36
+
37
+ /// @inheritdoc ITipping
38
+ function tipsByWalletAndCurrency(
39
+ address wallet,
40
+ address currency
41
+ ) external view returns (uint256) {
42
+ return AccountTipping.getStorage().accountStatsByCurrency[wallet][currency].amount;
43
+ }
44
+
45
+ /// @inheritdoc ITipping
46
+ function tipCountByWalletAndCurrency(
47
+ address wallet,
48
+ address currency
49
+ ) external view returns (uint256) {
50
+ return AccountTipping.getStorage().accountStatsByCurrency[wallet][currency].total;
51
+ }
52
+
53
+ /// @inheritdoc ITipping
54
+ function tipsByCurrencyAndTokenId(uint256, address) external pure returns (uint256) {
55
+ CustomRevert.revertWith(Deprecated.selector);
56
+ }
57
+
58
+ /// @inheritdoc ITipping
59
+ function tippingCurrencies() external view returns (address[] memory) {
60
+ return AccountTipping.getStorage().currencies.values();
61
+ }
62
+
63
+ /// @inheritdoc ITipping
64
+ function totalTipsByCurrency(address currency) external view returns (uint256) {
65
+ return AccountTipping.getStorage().currencyStats[currency].total;
66
+ }
67
+
68
+ /// @inheritdoc ITipping
69
+ function tipAmountByCurrency(address currency) external view returns (uint256) {
70
+ return AccountTipping.getStorage().currencyStats[currency].amount;
71
+ }
72
+ }
@@ -0,0 +1,144 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.29;
3
+
4
+ // interfaces
5
+ import {ITippingBase} from "../../../spaces/facets/tipping/ITipping.sol";
6
+
7
+ // libraries
8
+ import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol";
9
+ import {CustomRevert} from "../../../utils/libraries/CustomRevert.sol";
10
+ import {CurrencyTransfer} from "../../../utils/libraries/CurrencyTransfer.sol";
11
+
12
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
13
+ /* TYPES */
14
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
15
+ using CustomRevert for bytes4;
16
+ using EnumerableSetLib for EnumerableSetLib.AddressSet;
17
+
18
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
19
+ /* STORAGE */
20
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
21
+
22
+ // keccak256(abi.encode(uint256(keccak256("towns.account.tipping.mod.storage")) - 1)) & ~bytes32(uint256(0xff))
23
+ bytes32 constant STORAGE_SLOT = 0x2a95e0ca73c50924d5ddd84672da871cae538509d7dabaedae2f730a19f18300;
24
+
25
+ /// @notice Stats for a currency
26
+ /// @param total The total number of tips
27
+ /// @param amount The total amount of tips
28
+ struct Stats {
29
+ uint256 total;
30
+ uint256 amount;
31
+ }
32
+
33
+ /// @notice Storage layout for the AccountTippingMod
34
+ /// @custom:storage-location erc7201:towns.account.tipping.mod.storage
35
+ struct Layout {
36
+ // Global mappings
37
+ EnumerableSetLib.AddressSet currencies;
38
+ mapping(address currency => Stats stats) currencyStats;
39
+ mapping(address account => Stats stats) accountStats;
40
+ mapping(address account => mapping(address currency => Stats stats)) accountStatsByCurrency;
41
+ }
42
+
43
+ /// @notice Returns the storage layout for the AccountTippingMod
44
+ function getStorage() pure returns (Layout storage $) {
45
+ assembly {
46
+ $.slot := STORAGE_SLOT
47
+ }
48
+ }
49
+
50
+ /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
51
+ /* FUNCTIONS */
52
+ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
53
+
54
+ /// @notice Sends a tip
55
+ /// @param recipientType The type of recipient
56
+ /// @param data The data for the tip
57
+ /// @return tipAmount The amount of the tip
58
+ /// @return protocolFee The protocol fee
59
+ function tipAny(
60
+ address self,
61
+ uint8 recipientType,
62
+ bytes calldata data
63
+ ) returns (uint256 tipAmount, uint256 protocolFee) {
64
+ if (recipientType != uint8(ITippingBase.TipRecipientType.Any))
65
+ ITippingBase.InvalidRecipientType.selector.revertWith();
66
+
67
+ ITippingBase.AnyTipParams memory request = abi.decode(data, (ITippingBase.AnyTipParams));
68
+
69
+ protocolFee;
70
+ tipAmount = request.amount;
71
+
72
+ validateTip(request.sender, request.receiver, request.currency, request.amount);
73
+ depositTip(self, request.currency, request.amount);
74
+ processTip(getStorage(), self, request.receiver, request.currency, request.amount);
75
+
76
+ emit ITippingBase.TipSent(
77
+ msg.sender,
78
+ request.receiver,
79
+ ITippingBase.TipRecipientType.Any,
80
+ request.currency,
81
+ request.amount,
82
+ request.data
83
+ );
84
+ }
85
+
86
+ /// @notice Processes a tip
87
+ /// @param $ The storage layout
88
+ /// @param self The address of the facet
89
+ /// @param receiver The address of the recipient
90
+ /// @param currency The currency of the tip
91
+ /// @param amount The amount of the tip
92
+ function processTip(
93
+ Layout storage $,
94
+ address self,
95
+ address receiver,
96
+ address currency,
97
+ uint256 amount
98
+ ) {
99
+ // Add currency to set
100
+ $.currencies.add(currency);
101
+
102
+ // Update global currency stats
103
+ Stats storage stats = $.currencyStats[currency];
104
+ stats.amount += amount;
105
+ stats.total += 1;
106
+
107
+ // Update account-specific stats
108
+ Stats storage accountStats = $.accountStats[receiver];
109
+ accountStats.amount += amount;
110
+ accountStats.total += 1;
111
+
112
+ Stats storage accountStatsByCurrency = $.accountStatsByCurrency[receiver][currency];
113
+ accountStatsByCurrency.amount += amount;
114
+ accountStatsByCurrency.total += 1;
115
+
116
+ // Transfer currency
117
+ CurrencyTransfer.transferCurrency(currency, self, receiver, amount);
118
+ }
119
+
120
+ /// @notice Validates a tip
121
+ /// @param sender The address of the sender
122
+ /// @param receiver The address of the recipient
123
+ /// @param currency The currency of the tip
124
+ /// @param amount The amount of the tip
125
+ function validateTip(address sender, address receiver, address currency, uint256 amount) view {
126
+ if (currency == address(0)) ITippingBase.CurrencyIsZero.selector.revertWith();
127
+ if (receiver == address(0)) ITippingBase.InvalidAddressInput.selector.revertWith();
128
+ if (amount == 0) ITippingBase.AmountIsZero.selector.revertWith();
129
+ if (sender != msg.sender) ITippingBase.NotSenderOfTip.selector.revertWith();
130
+ if (sender == receiver) ITippingBase.CannotTipSelf.selector.revertWith();
131
+ }
132
+
133
+ /// @notice Deposits a tip
134
+ /// @param self The address of the facet
135
+ /// @param currency The currency of the tip
136
+ /// @param amount The amount of the tip
137
+ function depositTip(address self, address currency, uint256 amount) {
138
+ if (currency == CurrencyTransfer.NATIVE_TOKEN) {
139
+ if (msg.value != amount) ITippingBase.MsgValueMismatch.selector.revertWith();
140
+ } else {
141
+ if (msg.value != 0) ITippingBase.UnexpectedETH.selector.revertWith();
142
+ CurrencyTransfer.transferCurrency(currency, msg.sender, self, amount);
143
+ }
144
+ }
@@ -11,6 +11,7 @@ import {ISchemaResolver} from "@ethereum-attestation-service/eas-contracts/resol
11
11
  import {IPlatformRequirements} from "../../../factory/facets/platform/requirements/IPlatformRequirements.sol";
12
12
  import {IERC173} from "@towns-protocol/diamond/src/facets/ownable/IERC173.sol";
13
13
  import {IAppAccount} from "../../../spaces/facets/account/IAppAccount.sol";
14
+ import {IEntitlementsManager} from "../../../spaces/facets/entitlements/IEntitlementsManager.sol";
14
15
 
15
16
  // libraries
16
17
  import {CustomRevert} from "../../../utils/libraries/CustomRevert.sol";
@@ -24,6 +25,7 @@ import {LibAppRegistry} from "./LibAppRegistry.sol";
24
25
  import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol";
25
26
  import {Attestation, EMPTY_UID} from "@ethereum-attestation-service/eas-contracts/Common.sol";
26
27
  import {AttestationRequest, RevocationRequestData} from "@ethereum-attestation-service/eas-contracts/IEAS.sol";
28
+ import {Permissions} from "../../../spaces/facets/Permissions.sol";
27
29
 
28
30
  // contracts
29
31
  import {SchemaBase} from "../schema/SchemaBase.sol";
@@ -32,8 +34,16 @@ import {AttestationBase} from "../attest/AttestationBase.sol";
32
34
  abstract contract AppRegistryBase is IAppRegistryBase, SchemaBase, AttestationBase {
33
35
  using CustomRevert for bytes4;
34
36
 
37
+ /// @notice Modifier to check if the caller is allowed to interact with the app registry
38
+ /// @dev Only the owner of the space or modular account can interact
35
39
  modifier onlyAllowed(IAppAccount account) {
36
- if (address(account) != msg.sender && IERC173(address(account)).owner() != msg.sender) {
40
+ if (
41
+ address(account) != msg.sender &&
42
+ !IEntitlementsManager(address(account)).isEntitledToSpace(
43
+ msg.sender,
44
+ Permissions.ModifyAppSettings
45
+ )
46
+ ) {
37
47
  NotAllowed.selector.revertWith();
38
48
  }
39
49
  _;
@@ -8,14 +8,15 @@ pragma solidity ^0.8.23;
8
8
  // contracts
9
9
 
10
10
  library Permissions {
11
- string public constant ModifyChannel = "ModifyChannel";
12
- string public constant AddRemoveChannels = "AddRemoveChannels";
13
- string public constant ModifySpaceSettings = "ModifySpaceSettings";
14
- string public constant ModifyRoles = "ModifyRoles";
15
- string public constant JoinSpace = "JoinSpace";
16
- string public constant ModifyBanning = "ModifyBanning";
17
- string public constant Read = "Read";
18
- string public constant Write = "Write";
19
- string public constant React = "React";
20
- string public constant Ping = "Ping";
11
+ string internal constant ModifyChannel = "ModifyChannel";
12
+ string internal constant AddRemoveChannels = "AddRemoveChannels";
13
+ string internal constant ModifySpaceSettings = "ModifySpaceSettings";
14
+ string internal constant ModifyRoles = "ModifyRoles";
15
+ string internal constant JoinSpace = "JoinSpace";
16
+ string internal constant ModifyBanning = "ModifyBanning";
17
+ string internal constant Read = "Read";
18
+ string internal constant Write = "Write";
19
+ string internal constant React = "React";
20
+ string internal constant Ping = "Ping";
21
+ string internal constant ModifyAppSettings = "ModifyAppSettings";
21
22
  }
@@ -6,7 +6,6 @@ import {IAppRegistry} from "src/apps/facets/registry/IAppRegistry.sol";
6
6
 
7
7
  // libraries
8
8
  import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol";
9
- import {ExecutorStorage} from "src/spaces/facets/executor/ExecutorStorage.sol";
10
9
  import {DependencyLib} from "src/spaces/facets/DependencyLib.sol";
11
10
  import {EMPTY_UID} from "@ethereum-attestation-service/eas-contracts/Common.sol";
12
11
 
@@ -2,26 +2,27 @@
2
2
  pragma solidity ^0.8.23;
3
3
 
4
4
  interface ITippingBase {
5
- // =============================================================
6
- // Enums
7
- // =============================================================
8
-
9
5
  enum TipRecipientType {
10
6
  Member, // Tips to token holders
11
7
  Bot, // Tips to bot wallets
12
- Pool // Tips to pool wallets
8
+ Any // Tips to any address
13
9
  }
14
10
 
15
- // =============================================================
16
- // Structs
17
- // =============================================================
18
-
19
11
  struct TipMetadata {
20
12
  bytes32 messageId;
21
13
  bytes32 channelId;
22
14
  bytes data; // Extensible metadata
23
15
  }
24
16
 
17
+ /// @notice Params for any tip
18
+ struct AnyTipParams {
19
+ address currency;
20
+ address sender;
21
+ address receiver;
22
+ uint256 amount;
23
+ bytes data;
24
+ }
25
+
25
26
  /// @notice Params for Member tips (includes tokenId)
26
27
  struct MembershipTipParams {
27
28
  address receiver;
@@ -50,10 +51,6 @@ interface ITippingBase {
50
51
  bytes32 channelId;
51
52
  }
52
53
 
53
- // =============================================================
54
- // Events
55
- // =============================================================
56
-
57
54
  event TipSent(
58
55
  address indexed sender,
59
56
  address indexed receiver,
@@ -74,10 +71,6 @@ interface ITippingBase {
74
71
  bytes32 channelId
75
72
  );
76
73
 
77
- // =============================================================
78
- // Errors
79
- // =============================================================
80
-
81
74
  error InvalidRecipientType();
82
75
  error InvalidTipData();
83
76
  error TokenDoesNotExist();
@@ -87,6 +80,9 @@ interface ITippingBase {
87
80
  error CurrencyIsZero();
88
81
  error MsgValueMismatch();
89
82
  error UnexpectedETH();
83
+ error NotSenderOfTip();
84
+ error Deprecated();
85
+ error InvalidAddressInput();
90
86
  }
91
87
 
92
88
  interface ITipping is ITippingBase {
@@ -94,9 +90,8 @@ interface ITipping is ITippingBase {
94
90
  /// @param recipientType The type of recipient (Member, Wallet, Bot, Pool)
95
91
  /// @param data ABI-encoded tip params based on recipientType:
96
92
  /// - Member: abi.encode(MembershipTipParams)
97
- /// - Wallet: abi.encode(WalletTipParams)
98
93
  /// - Bot: abi.encode(BotTipParams)
99
- /// - Pool: Reserved for future implementation
94
+ /// - Any: abi.encode(AnyTipParams)
100
95
  function sendTip(TipRecipientType recipientType, bytes calldata data) external payable;
101
96
 
102
97
  /// @notice Sends a tip to a space member (legacy)
@@ -6,7 +6,6 @@ import {ITippingBase} from "./ITipping.sol";
6
6
  import {ITownsPointsBase} from "../../../airdrop/points/ITownsPoints.sol";
7
7
  import {IFeeManager} from "../../../factory/facets/fee/IFeeManager.sol";
8
8
  import {FeeTypesLib} from "../../../factory/facets/fee/FeeTypesLib.sol";
9
- import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
10
9
 
11
10
  // libraries
12
11
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";