Skip to content

Commit 23e327b

Browse files
committed
add natspec comments
1 parent 363cb9f commit 23e327b

31 files changed

Lines changed: 1131 additions & 28 deletions

contracts/accounts/AccountSubscriptionManager.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ contract AccountSubscriptionManager is
2727
);
2828
}
2929

30+
/// @inheritdoc IAccountSubscriptionManager
3031
function addSubscriptionCreators(address[] calldata subscriptionCreators_) external onlyOwner {
3132
for (uint256 i = 0; i < subscriptionCreators_.length; ++i) {
3233
_addSubscriptionCreator(subscriptionCreators_[i]);
3334
}
3435
}
3536

37+
/// @inheritdoc IAccountSubscriptionManager
3638
function removeSubscriptionCreators(
3739
address[] calldata subscriptionCreators_
3840
) external onlyOwner {

contracts/core/HelperDataRegistry.sol

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ pragma solidity ^0.8.28;
44
import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
55
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
66

7+
/**
8+
* @title HelperDataRegistry
9+
* @notice Registry for storing accounts helper data
10+
*/
711
contract HelperDataRegistry is EIP712Upgradeable {
12+
/**
13+
* @notice Data structure storing helper data for an account.
14+
* @param faceVersion Version of the facial data.
15+
* @param objectVersion Version of the object data.
16+
* @param helperDataVersion Version of the helper data.
17+
* @param helperData Encoded bytes representing the helper data.
18+
*/
819
struct HelperData {
920
uint64 faceVersion;
1021
uint96 objectVersion;
@@ -24,14 +35,28 @@ contract HelperDataRegistry is EIP712Upgradeable {
2435
"HelperData(uint256 faceVersion,uint256 objectVersion,uint256 helperDataVersion,bytes helperData)"
2536
);
2637

38+
/**
39+
* @notice Thrown when trying to set helper data for an account that already has it.
40+
* @param signer The account address that already has helper data set.
41+
*/
2742
error HelperDataAlreadySet(address signer);
2843

44+
/**
45+
* @notice Emitted when the helper data is set for an account.
46+
* @param account The account address for which helper data was set.
47+
*/
2948
event HelperDataSet(address indexed account);
3049

3150
function initialize() external initializer {
3251
__EIP712_init("HelperDataRegistry", "1");
3352
}
3453

54+
/**
55+
* @notice A function to set helper data for an account.
56+
* @dev Reverts if helper data is already set for the signer.
57+
* @param helperData_ The helper data struct to set.
58+
* @param signature_ The EIP-712 signature of the helper data signed by the account to set the data for.
59+
*/
3560
function setHelperData(HelperData calldata helperData_, bytes calldata signature_) external {
3661
bytes32 digest_ = hashHelperDataStruct(helperData_);
3762

@@ -44,10 +69,20 @@ contract HelperDataRegistry is EIP712Upgradeable {
4469
emit HelperDataSet(signer_);
4570
}
4671

72+
/**
73+
* @notice A function to retrieve the helper data for the provided account.
74+
* @param account_ The account address to query.
75+
* @return The `HelperData` struct associated with the account.
76+
*/
4777
function getHelperData(address account_) external view returns (HelperData memory) {
4878
return _getHelperDataRegistryStorage().accountsToHelperData[account_];
4979
}
5080

81+
/**
82+
* @notice A function to compute the EIP-712 hash for a given `HelperData` struct.
83+
* @param helperData_ The helper data to hash.
84+
* @return The EIP-712 typed hash of the helper data struct.
85+
*/
5186
function hashHelperDataStruct(HelperData calldata helperData_) public view returns (bytes32) {
5287
return
5388
_hashTypedDataV4(
@@ -63,6 +98,11 @@ contract HelperDataRegistry is EIP712Upgradeable {
6398
);
6499
}
65100

101+
/**
102+
* @notice A function to check whether helper data is already set for the provided account.
103+
* @param account_ The account address to check.
104+
* @return `true` if helper data exists for the account, `false` otherwise.
105+
*/
66106
function isHelperDataSet(address account_) public view returns (bool) {
67107
return
68108
_getHelperDataRegistryStorage().accountsToHelperData[account_].helperDataVersion != 0;

contracts/core/RecoveryManager.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
77
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
88

99
import {ADeployerGuard} from "@solarity/solidity-lib/utils/ADeployerGuard.sol";
10+
import {IRecoveryProvider} from "@solarity/solidity-lib/interfaces/account-abstraction/IRecoveryProvider.sol";
1011

1112
import {IRecoveryManager} from "../interfaces/core/IRecoveryManager.sol";
1213
import {ISubscriptionManager} from "../interfaces/core/ISubscriptionManager.sol";
@@ -54,39 +55,47 @@ contract RecoveryManager is IRecoveryManager, ADeployerGuard, OwnableUpgradeable
5455
_addStrategies(recoveryStrategies_);
5556
}
5657

58+
/// @inheritdoc IRecoveryManager
5759
function updateSubscriptionManagers(
5860
address[] calldata subscriptionManagersToUpdate_,
5961
bool isAdding_
6062
) external onlyOwner {
6163
_updateSubscriptionManagers(subscriptionManagersToUpdate_, isAdding_);
6264
}
6365

66+
/// @inheritdoc IRecoveryManager
6467
function addRecoveryStrategies(address[] calldata newStrategies_) external onlyOwner {
6568
_addStrategies(newStrategies_);
6669
}
6770

71+
/// @inheritdoc IRecoveryManager
6872
function disableStrategy(uint256 strategyId_) external onlyOwner {
6973
_disableStrategy(strategyId_);
7074
}
7175

76+
/// @inheritdoc IRecoveryManager
7277
function enableStrategy(uint256 strategyId_) external onlyOwner {
7378
_enableStrategy(strategyId_);
7479
}
7580

81+
/// @inheritdoc IRecoveryProvider
7682
function subscribe(bytes memory recoveryData_) external payable {
7783
_subscribe(recoveryData_);
7884
}
7985

86+
/// @inheritdoc IRecoveryProvider
8087
function unsubscribe() external payable {
8188
_unsubscribe();
8289
}
8390

91+
/// @inheritdoc IRecoveryManager
8492
function resubscribe(bytes memory recoveryData_) external payable {
8593
_unsubscribe();
8694

8795
_subscribe(recoveryData_);
8896
}
8997

98+
/// @inheritdoc IRecoveryProvider
9099
function recover(bytes memory object_, bytes memory proof_) external {
91100
RecoveryManagerStorage storage $ = _getRecoveryManagerStorage();
92101

@@ -116,10 +125,12 @@ contract RecoveryManager is IRecoveryManager, ADeployerGuard, OwnableUpgradeable
116125
);
117126
}
118127

128+
/// @inheritdoc IRecoveryProvider
119129
function getRecoveryData(address account_) external view returns (bytes memory) {
120130
return abi.encode(getRecoveryMethods(account_));
121131
}
122132

133+
/// @inheritdoc IRecoveryManager
123134
function getRecoveryMethods(
124135
address account_
125136
) public view returns (RecoveryMethod[] memory recoveryMethods_) {
@@ -137,18 +148,22 @@ contract RecoveryManager is IRecoveryManager, ADeployerGuard, OwnableUpgradeable
137148
}
138149
}
139150

151+
/// @inheritdoc IRecoveryManager
140152
function subscriptionManagerExists(address subscriptionManager_) public view returns (bool) {
141153
return _getRecoveryManagerStorage().subscriptionManagers.contains(subscriptionManager_);
142154
}
143155

156+
/// @inheritdoc IRecoveryManager
144157
function getStrategyStatus(uint256 strategyId_) public view returns (StrategyStatus) {
145158
return _getRecoveryManagerStorage().strategiesData[strategyId_].status;
146159
}
147160

161+
/// @inheritdoc IRecoveryManager
148162
function getStrategy(uint256 strategyId_) public view returns (address) {
149163
return _getRecoveryManagerStorage().strategiesData[strategyId_].strategy;
150164
}
151165

166+
/// @inheritdoc IRecoveryManager
152167
function isActiveStrategy(uint256 strategyId_) public view returns (bool) {
153168
return getStrategyStatus(strategyId_) == StrategyStatus.Active;
154169
}

contracts/core/strategies/ARecoveryStrategy.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ abstract contract ARecoveryStrategy is IRecoveryStrategy, NoncesUpgradeable {
1313
address recoveryManagerAddr;
1414
}
1515

16-
error NotARecoveryManager(address account);
17-
1816
modifier onlyRecoveryManager() {
1917
_onlyRecoveryManager();
2018
_;
@@ -36,6 +34,7 @@ abstract contract ARecoveryStrategy is IRecoveryStrategy, NoncesUpgradeable {
3634
_getARecoveryStrategyStorage().recoveryManagerAddr = recoveryManagerAddr_;
3735
}
3836

37+
/// @inheritdoc IRecoveryStrategy
3938
function recoverAccount(
4039
address account_,
4140
bytes memory object_,
@@ -44,10 +43,12 @@ abstract contract ARecoveryStrategy is IRecoveryStrategy, NoncesUpgradeable {
4443
_recoverAccount(account_, object_, recoveryData_);
4544
}
4645

46+
/// @inheritdoc IRecoveryStrategy
4747
function getRecoveryManager() public view virtual returns (address) {
4848
return _getARecoveryStrategyStorage().recoveryManagerAddr;
4949
}
5050

51+
/// @inheritdoc IRecoveryStrategy
5152
function validateRecoveryData(bytes memory recoveryData_) external view {
5253
_validateRecoveryData(recoveryData_);
5354
}

contracts/core/strategies/SignatureRecoveryStrategy.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ contract SignatureRecoveryStrategy is
2424
__ARecoveryStrategy_init(recoveryManagerAddr_);
2525
}
2626

27+
/// @inheritdoc ISignatureRecoveryStrategy
2728
function hashSignatureRecovery(
2829
address account_,
2930
bytes memory object_,

contracts/core/subscription/BaseSubscriptionManager.sol

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ abstract contract BaseSubscriptionManager is
3636
EnumerableSet.AddressSet subscriptionCreators;
3737
}
3838

39-
error SubscriptionCreatorAlreadyAdded(address subscriptionCreator);
40-
41-
event SubscriptionCreatorAdded(address indexed subscriptionCreator);
42-
event SubscriptionCreatorRemoved(address indexed subscriptionCreator);
43-
4439
modifier onlySubscriptionCreator() {
4540
_onlySubscriptionCreator(msg.sender);
4641
_;
@@ -76,14 +71,21 @@ abstract contract BaseSubscriptionManager is
7671
__SignatureSubscriptionModule_init(sigSubscriptionInitData_);
7772
}
7873

74+
/// @inheritdoc ISubscriptionManager
7975
function pause() public virtual onlyOwner {
8076
_pause();
8177
}
8278

79+
/// @inheritdoc ISubscriptionManager
8380
function unpause() public virtual onlyOwner {
8481
_unpause();
8582
}
8683

84+
/**
85+
* @notice A function to update payment token configurations.
86+
* @param paymentTokenEntries_ An array of payment token configurations
87+
containing token addresses and their base costs.
88+
*/
8789
function updatePaymentTokens(
8890
PaymentTokenUpdateEntry[] calldata paymentTokenEntries_
8991
) public virtual onlyOwner {
@@ -95,16 +97,31 @@ abstract contract BaseSubscriptionManager is
9597
}
9698
}
9799

100+
/**
101+
* @notice A function to remove supported payment tokens.
102+
* @param tokensToRemove_ An array of token addresses to remove.
103+
*/
98104
function removePaymentTokens(address[] calldata tokensToRemove_) public virtual onlyOwner {
99105
for (uint256 i = 0; i < tokensToRemove_.length; ++i) {
100106
_removePaymentToken(tokensToRemove_[i]);
101107
}
102108
}
103109

110+
/**
111+
* @notice A function to update the duration-based factor for adjusting subscription costs.
112+
* @param duration_ Subscription duration to update the factor for.
113+
* @param factor_ Updated multiplicative factor applied to the base cost.
114+
*/
104115
function updateDurationFactor(uint64 duration_, uint256 factor_) public virtual onlyOwner {
105116
_updateDurationFactor(duration_, factor_);
106117
}
107118

119+
/**
120+
* @notice A function to withdraw tokens from the subscription manager.
121+
* @param tokenAddr_ Payment token address to withdraw.
122+
* @param to_ Withdrawal recipient address.
123+
* @param amount_ Amount of tokens to withdraw.
124+
*/
108125
function withdrawTokens(
109126
address tokenAddr_,
110127
address to_,
@@ -113,26 +130,41 @@ abstract contract BaseSubscriptionManager is
113130
_withdrawTokens(tokenAddr_, to_, amount_);
114131
}
115132

133+
/**
134+
* @notice A function to update supported SBTs used for subscription purchases.
135+
* @param sbtEntries_ An array of SBT configurations containing
136+
token addresses and their subscription durations.
137+
*/
116138
function updateSBTs(SBTUpdateEntry[] calldata sbtEntries_) public virtual onlyOwner {
117139
for (uint256 i = 0; i < sbtEntries_.length; ++i) {
118140
_updateSBT(sbtEntries_[i].sbt, sbtEntries_[i].subscriptionDurationPerToken);
119141
}
120142
}
121143

144+
/**
145+
* @notice A function to remove supported SBTs.
146+
* @param sbtsToRemove_ An array of SBT addresses to remove.
147+
*/
122148
function removeSBTs(address[] calldata sbtsToRemove_) public virtual onlyOwner {
123149
for (uint256 i = 0; i < sbtsToRemove_.length; ++i) {
124150
_removeSBT(sbtsToRemove_[i]);
125151
}
126152
}
127153

154+
/**
155+
* @notice A function to set a new subscription signer used for signature-based subscriptions.
156+
* @param newSigner_ Address of the new subscription signer.
157+
*/
128158
function setSubscriptionSigner(address newSigner_) public virtual onlyOwner {
129159
_setSubscriptionSigner(newSigner_);
130160
}
131161

162+
/// @inheritdoc ISubscriptionManager
132163
function createSubscription(address account_) public virtual onlySubscriptionCreator {
133164
_createSubscription(account_);
134165
}
135166

167+
/// @inheritdoc ITokensPaymentModule
136168
function buySubscription(
137169
address account_,
138170
address token_,
@@ -148,6 +180,7 @@ abstract contract BaseSubscriptionManager is
148180
super.buySubscription(account_, token_, duration_);
149181
}
150182

183+
/// @inheritdoc ISBTPaymentModule
151184
function buySubscriptionWithSBT(
152185
address vault_,
153186
address sbt_,
@@ -156,6 +189,7 @@ abstract contract BaseSubscriptionManager is
156189
super.buySubscriptionWithSBT(vault_, sbt_, tokenId_);
157190
}
158191

192+
/// @inheritdoc ISignatureSubscriptionModule
159193
function buySubscriptionWithSignature(
160194
address vault_,
161195
uint64 duration_,
@@ -170,14 +204,17 @@ abstract contract BaseSubscriptionManager is
170204
super.buySubscriptionWithSignature(vault_, duration_, signature_);
171205
}
172206

207+
/// @inheritdoc ISubscriptionManager
173208
function implementation() external view returns (address) {
174209
return ERC1967Utils.getImplementation();
175210
}
176211

212+
/// @inheritdoc ISubscriptionManager
177213
function getSubscriptionCreators() public view virtual returns (address[] memory) {
178214
return _getBaseSubscriptionManagerStorage().subscriptionCreators.values();
179215
}
180216

217+
/// @inheritdoc ISubscriptionManager
181218
function isSubscriptionCreator(address account_) public view virtual returns (bool) {
182219
return _getBaseSubscriptionManagerStorage().subscriptionCreators.contains(account_);
183220
}

contracts/core/subscription/modules/BaseSubscriptionModule.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,27 @@ contract BaseSubscriptionModule is IBaseSubscriptionModule {
2323
}
2424
}
2525

26+
/// @inheritdoc IBaseSubscriptionModule
2627
function hasSubscription(address account_) public view virtual returns (bool) {
2728
return getSubscriptionStartTime(account_) > 0;
2829
}
2930

31+
/// @inheritdoc IBaseSubscriptionModule
3032
function hasActiveSubscription(address account_) public view virtual returns (bool) {
3133
return block.timestamp < getSubscriptionEndTime(account_);
3234
}
3335

36+
/// @inheritdoc IBaseSubscriptionModule
3437
function hasSubscriptionDebt(address account_) public view virtual returns (bool) {
3538
return !hasActiveSubscription(account_) && hasSubscription(account_);
3639
}
3740

41+
/// @inheritdoc IBaseSubscriptionModule
3842
function getSubscriptionStartTime(address account_) public view virtual returns (uint64) {
3943
return _getAccountSubscriptionData(account_).startTime;
4044
}
4145

46+
/// @inheritdoc IBaseSubscriptionModule
4247
function getSubscriptionEndTime(address account_) public view virtual returns (uint64) {
4348
if (!hasSubscription(account_)) {
4449
return uint64(block.timestamp);

0 commit comments

Comments
 (0)