@towns-protocol/contracts 0.0.452 → 0.0.455

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.
Files changed (63) hide show
  1. package/docs/membership_architecture.md +23 -6
  2. package/package.json +6 -6
  3. package/scripts/common/Interaction.s.sol +3 -3
  4. package/scripts/deployments/diamonds/DeployBaseRegistry.s.sol +1 -4
  5. package/scripts/deployments/diamonds/DeploySpace.s.sol +1 -9
  6. package/scripts/deployments/diamonds/DeploySpaceFactory.s.sol +1 -5
  7. package/scripts/deployments/facets/DeployAppFactoryFacet.s.sol +3 -3
  8. package/scripts/deployments/facets/DeployAppInstallerFacet.s.sol +3 -3
  9. package/scripts/deployments/facets/DeployAppRegistryFacet.s.sol +3 -3
  10. package/scripts/deployments/facets/DeployArchitect.s.sol +3 -3
  11. package/scripts/deployments/facets/DeployAttestationRegistry.s.sol +3 -3
  12. package/scripts/deployments/facets/DeployERC721ANonTransferable.s.sol +3 -3
  13. package/scripts/deployments/facets/DeployFeatureManager.s.sol +3 -3
  14. package/scripts/deployments/facets/DeployMainnetDelegation.s.sol +3 -3
  15. package/scripts/deployments/facets/DeployMembershipMetadata.s.sol +3 -3
  16. package/scripts/deployments/facets/DeployMerkleAirdrop.s.sol +3 -3
  17. package/scripts/deployments/facets/DeployMetadata.s.sol +3 -3
  18. package/scripts/deployments/facets/DeployMockLegacyArchitect.s.sol +3 -3
  19. package/scripts/deployments/facets/DeployNodeOperator.s.sol +3 -3
  20. package/scripts/deployments/facets/DeployPartnerRegistry.s.sol +3 -3
  21. package/scripts/deployments/facets/DeployPricingModules.s.sol +3 -3
  22. package/scripts/deployments/facets/DeploySchemaRegistry.s.sol +3 -3
  23. package/scripts/deployments/facets/DeploySpaceFactoryInit.s.sol +3 -3
  24. package/scripts/deployments/facets/DeploySpaceOwnerFacet.s.sol +3 -3
  25. package/scripts/deployments/facets/DeployTokenMigration.s.sol +3 -3
  26. package/scripts/deployments/facets/DeployXChain.s.sol +3 -3
  27. package/scripts/deployments/utils/DeployAccountFactory.s.sol +3 -3
  28. package/scripts/deployments/utils/DeployEntitlementGatedExample.s.sol +3 -3
  29. package/scripts/deployments/utils/DeployEntrypoint.s.sol +3 -3
  30. package/scripts/deployments/utils/DeployMember.s.sol +3 -3
  31. package/scripts/deployments/utils/DeployMockLegacyMembership.s.sol +3 -3
  32. package/scripts/deployments/utils/DeployMockMessenger.s.sol +3 -3
  33. package/scripts/deployments/utils/DeploySpaceProxyInitializer.s.sol +3 -3
  34. package/scripts/deployments/utils/DeployTieredLogPricingV2.s.sol +3 -3
  35. package/scripts/deployments/utils/DeployTieredLogPricingV3.s.sol +3 -3
  36. package/scripts/deployments/utils/DeployTownsBase.s.sol +3 -3
  37. package/scripts/deployments/utils/DeployTownsMainnet.s.sol +3 -3
  38. package/scripts/deployments/utils/pricing/TieredLogPricing.s.sol +3 -3
  39. package/scripts/interactions/InteractAirdrop.s.sol +3 -3
  40. package/scripts/interactions/InteractBaseBridge.s.sol +3 -3
  41. package/scripts/interactions/InteractRegisterApp.s.sol +2 -2
  42. package/scripts/interactions/InteractRiverRegistrySetTrimByStreamId.s.sol +44 -0
  43. package/scripts/interactions/helpers/RiverConfigValues.sol +1 -2
  44. package/src/account/facets/app/AppManagerFacet.sol +43 -14
  45. package/src/account/facets/app/AppManagerMod.sol +311 -278
  46. package/src/account/facets/hub/AccountHubFacet.sol +12 -11
  47. package/src/account/facets/hub/AccountHubMod.sol +117 -116
  48. package/src/account/facets/tipping/AccountTippingFacet.sol +10 -9
  49. package/src/account/facets/tipping/AccountTippingMod.sol +133 -124
  50. package/src/apps/modules/subscription/ISubscriptionModule.sol +40 -43
  51. package/src/apps/modules/subscription/SubscriptionModuleBase.sol +41 -16
  52. package/src/apps/modules/subscription/SubscriptionModuleFacet.sol +113 -105
  53. package/src/apps/modules/subscription/SubscriptionModuleStorage.sol +2 -1
  54. package/src/base/registry/facets/checker/EntitlementChecker.sol +43 -17
  55. package/src/river/registry/facets/stream/StreamRegistry.sol +4 -1
  56. package/src/spaces/facets/ProtocolFeeLib.sol +43 -0
  57. package/src/spaces/facets/membership/IMembership.sol +6 -1
  58. package/src/spaces/facets/membership/MembershipFacet.sol +16 -7
  59. package/src/spaces/facets/membership/join/MembershipJoin.sol +34 -23
  60. package/src/spaces/facets/tipping/TippingBase.sol +10 -26
  61. package/src/tokens/Member.sol +3 -4
  62. package/src/utils/libraries/CurrencyTransfer.sol +6 -2
  63. package/scripts/interactions/InteractRiverRegistrySetFreq.s.sol +0 -27
@@ -13,8 +13,7 @@ import {CurrencyTransfer} from "../../../utils/libraries/CurrencyTransfer.sol";
13
13
  import {CustomRevert} from "../../../utils/libraries/CustomRevert.sol";
14
14
  import {MembershipStorage} from "../membership/MembershipStorage.sol";
15
15
  import {TippingStorage} from "./TippingStorage.sol";
16
- import {BasisPoints} from "../../../utils/libraries/BasisPoints.sol";
17
- import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
16
+ import {ProtocolFeeLib} from "../ProtocolFeeLib.sol";
18
17
 
19
18
  // contracts
20
19
  import {PointsBase} from "../points/PointsBase.sol";
@@ -23,8 +22,6 @@ abstract contract TippingBase is ITippingBase, PointsBase {
23
22
  using EnumerableSet for EnumerableSet.AddressSet;
24
23
  using CustomRevert for bytes4;
25
24
 
26
- uint256 internal constant MAX_FEE_TOLERANCE = 100; // 1% tolerance
27
-
28
25
  /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
29
26
  /* Internal Functions */
30
27
  /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
@@ -205,41 +202,28 @@ abstract contract TippingBase is ITippingBase, PointsBase {
205
202
  address currency,
206
203
  uint256 amount
207
204
  ) internal returns (uint256 protocolFee) {
208
- MembershipStorage.Layout storage ds = MembershipStorage.layout();
209
- address spaceFactory = ds.spaceFactory;
205
+ address spaceFactory = MembershipStorage.layout().spaceFactory;
210
206
 
211
- // Calculate expected fee
212
- uint256 expectedFee = IFeeManager(spaceFactory).calculateFee(
207
+ // Calculate fee first
208
+ protocolFee = IFeeManager(spaceFactory).calculateFee(
213
209
  FeeTypesLib.TIP_MEMBER,
214
210
  msg.sender,
215
211
  amount,
216
212
  ""
217
213
  );
218
214
 
219
- if (expectedFee == 0) return 0;
220
-
221
- // Add slippage tolerance (1%)
222
- uint256 maxFee = expectedFee + BasisPoints.calculate(expectedFee, MAX_FEE_TOLERANCE);
223
-
224
- // Approve ERC20 if needed (native token sends value with call)
225
- bool isNative = currency == CurrencyTransfer.NATIVE_TOKEN;
226
- if (!isNative) SafeTransferLib.safeApproveWithRetry(currency, spaceFactory, maxFee);
227
-
228
- // Charge fee (excess native token will be refunded)
229
- protocolFee = IFeeManager(spaceFactory).chargeFee{value: isNative ? maxFee : 0}(
215
+ // Charge with pre-calculated fee
216
+ protocolFee = ProtocolFeeLib.charge(
217
+ spaceFactory,
230
218
  FeeTypesLib.TIP_MEMBER,
231
219
  msg.sender,
232
- amount,
233
220
  currency,
234
- maxFee,
235
- ""
221
+ amount,
222
+ protocolFee
236
223
  );
237
224
 
238
- // Reset ERC20 approval
239
- if (!isNative) SafeTransferLib.safeApprove(currency, spaceFactory, 0);
240
-
241
225
  // Mint points for fee payment (only for ETH tips)
242
- if (isNative) {
226
+ if (protocolFee > 0 && currency == CurrencyTransfer.NATIVE_TOKEN) {
243
227
  address airdropDiamond = _getAirdropDiamond();
244
228
  uint256 points = _getPoints(
245
229
  airdropDiamond,
@@ -1,13 +1,12 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.24;
3
3
 
4
- //interfaces
4
+ // interfaces
5
5
 
6
- //libraries
6
+ // libraries
7
7
  import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
8
8
 
9
- //contracts
10
-
9
+ // contracts
11
10
  import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
12
11
  import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
13
12
 
@@ -8,8 +8,6 @@ import {IWETH} from "../interfaces/IWETH.sol";
8
8
  import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
9
9
  import {CustomRevert} from "./CustomRevert.sol";
10
10
 
11
- // contracts
12
-
13
11
  library CurrencyTransfer {
14
12
  using SafeTransferLib for address;
15
13
  using CustomRevert for bytes4;
@@ -124,4 +122,10 @@ library CurrencyTransfer {
124
122
  if (actualFee > 0) safeTransferERC20(currency, payer, recipient, actualFee);
125
123
  }
126
124
  }
125
+
126
+ /// @dev Returns the balance of `account` in `currency`.
127
+ function balanceOf(address currency, address account) internal view returns (uint256) {
128
+ if (currency == NATIVE_TOKEN) return account.balance;
129
+ return currency.balanceOf(account);
130
+ }
127
131
  }
@@ -1,27 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.24;
3
-
4
- // interfaces
5
- import {IRiverConfig} from "src/river/registry/facets/config/IRiverConfig.sol";
6
-
7
- // libraries
8
- import {RiverConfigValues} from "scripts/interactions/helpers/RiverConfigValues.sol";
9
-
10
- // contracts
11
- import {Interaction} from "scripts/common/Interaction.s.sol";
12
-
13
- contract InteractRiverRegistrySetFreq is Interaction {
14
- function __interact(address deployer) internal override {
15
- address riverRegistry = getDeployment("riverRegistry");
16
-
17
- uint64 value = 10;
18
-
19
- vm.startBroadcast(deployer);
20
- IRiverConfig(riverRegistry).setConfiguration(
21
- RiverConfigValues.STREAM_MINIBLOCK_REGISTRATION_FREQUENCY,
22
- 0,
23
- abi.encode(value)
24
- );
25
- vm.stopBroadcast();
26
- }
27
- }