Skip to content

Commit 85a2905

Browse files
authored
feat: add events for contracts (#9)
* feat: events for filesystem * feat: add events for social connections * feat: add events for user verification * refactor: update create2 salt, redeploy contracts
1 parent 5ed212e commit 85a2905

File tree

10 files changed

+239
-249
lines changed

10 files changed

+239
-249
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ The following contracts are available in the repository:
1919
### Superchain (CREATE2) Addresses
2020
| Contract | Superchain Address |
2121
|----------------------------------|------------------------------------------------------------------------------------------------------------------------|
22-
| SocialConnections.sol | [0xB7C1C10A71d3C90f42351bec7E4BCd647C992743](https://blockscan.com/address/0xB7C1C10A71d3C90f42351bec7E4BCd647C992743) |
23-
| FilesystemChanges.sol | [0x55043C8f3e8Ec55D2d60Acef83024F3b6da5AAf0](https://blockscan.com/address/0x55043C8f3e8Ec55D2d60Acef83024F3b6da5AAf0) |
22+
| SocialConnections.sol | [0x99583220489a0e4217911ECf50680918F6a8B958](https://blockscan.com/address/0x99583220489a0e4217911ECf50680918F6a8B958) |
23+
| FilesystemChanges.sol | [0x30C974bE6581e3a00595d0b7C1ba7A8A91413e1f](https://blockscan.com/address/0x30C974bE6581e3a00595d0b7C1ba7A8A91413e1f) |
2424

2525
### Addresses
2626
| Contract | Address |
@@ -31,12 +31,23 @@ The following contracts are available in the repository:
3131

3232
[Old contracts](/docs/OLD_CONTRACTS.md).
3333

34+
## Testing smart contracts
35+
36+
```shell
37+
# install dependencies
38+
npm ci
39+
40+
# test the contracts
41+
npx hardhat test
42+
```
43+
3444
## Deploy contracts
3545

3646
### With Create2 (preferable)
3747

3848
```shell
3949
# localhost
50+
npx hardhat node # start a local node
4051
npm run deploy-all-localhost
4152

4253
# OP Sepolia
@@ -88,16 +99,6 @@ npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESS
8899
# the deployed addresses will be saved in `./deployed-contracts.json`
89100
```
90101

91-
## Testing smart contracts
92-
93-
```shell
94-
# install dependencies
95-
npm ci
96-
97-
# test the contracts
98-
npx hardhat test
99-
```
100-
101102
## Other
102103

103104
[Superchain Chains](https://www.superchain.eco/chains)

contracts/FilesystemChanges.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ pragma solidity ^0.8.20;
66
* @dev Store and manage filesystem changes (in form of Multihash) for users and services.
77
*/
88
contract FilesystemChanges {
9+
// Event for setting a service connection
10+
event ServiceConnectionSet(address indexed serviceAddress, bytes32 hash, uint8 hashFunction, uint8 size);
11+
12+
// Event for setting a user connection
13+
event UserConnectionSet(address indexed userAddress, bytes32 hash, uint8 hashFunction, uint8 size);
14+
15+
// Event for removing a connection
16+
event ConnectionRemoved(address indexed accountAddress, bool isService);
17+
918
struct Multihash {
1019
bytes32 hash;
1120
uint8 hashFunction;
@@ -24,6 +33,7 @@ contract FilesystemChanges {
2433
*/
2534
function setServiceChange(Multihash memory multihash) public {
2635
serviceChanges[msg.sender] = multihash;
36+
emit ServiceConnectionSet(msg.sender, multihash.hash, multihash.hashFunction, multihash.size);
2737
}
2838

2939
/**
@@ -32,6 +42,7 @@ contract FilesystemChanges {
3242
*/
3343
function setUserChange(Multihash memory multihash) public {
3444
userChanges[msg.sender] = multihash;
45+
emit UserConnectionSet(msg.sender, multihash.hash, multihash.hashFunction, multihash.size);
3546
}
3647

3748
/**
@@ -44,5 +55,7 @@ contract FilesystemChanges {
4455
} else {
4556
delete userChanges[msg.sender];
4657
}
58+
59+
emit ConnectionRemoved(msg.sender, isService);
4760
}
4861
}

contracts/SocialConnections.sol

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ pragma solidity ^0.8.20;
66
* @dev Store and manage social connections (in form of Multihash) for users and services.
77
*/
88
contract SocialConnections {
9+
// Event for setting a service connection
10+
event ServiceConnectionSet(address indexed serviceAddress, bytes32 hash, uint8 hashFunction, uint8 size);
11+
12+
// Event for setting a user connection
13+
event UserConnectionSet(address indexed userAddress, bytes32 hash, uint8 hashFunction, uint8 size);
14+
15+
// Event for removing a connection
16+
event ConnectionRemoved(address indexed accountAddress, bool isService);
17+
918
struct Multihash {
1019
bytes32 hash;
1120
uint8 hashFunction;
@@ -24,6 +33,7 @@ contract SocialConnections {
2433
*/
2534
function setServiceConnection(Multihash memory multihash) public {
2635
serviceConnections[msg.sender] = multihash;
36+
emit ServiceConnectionSet(msg.sender, multihash.hash, multihash.hashFunction, multihash.size);
2737
}
2838

2939
/**
@@ -32,17 +42,20 @@ contract SocialConnections {
3242
*/
3343
function setUserConnection(Multihash memory multihash) public {
3444
userConnections[msg.sender] = multihash;
45+
emit UserConnectionSet(msg.sender, multihash.hash, multihash.hashFunction, multihash.size);
3546
}
3647

3748
/**
38-
* @dev Delete the Multihash associated with the sender's smart account.
49+
* @dev Remove the Multihash associated with the sender's smart account.
3950
* @param isService Indicates whether the sender's account is a service account.
4051
*/
41-
function deleteConnection(bool isService) public {
52+
function removeConnection(bool isService) public {
4253
if (isService) {
4354
delete serviceConnections[msg.sender];
4455
} else {
4556
delete userConnections[msg.sender];
4657
}
58+
59+
emit ConnectionRemoved(msg.sender, isService);
4760
}
4861
}

contracts/UserVerification.sol

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
1414
* revocation, and reissuance of tokens, as well as checking their validity and expiration status.
1515
*/
1616
contract UserVerification is Initializable, ERC721Upgradeable, ERC721BurnableUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
17+
/// @notice Emitted when a manager is set or unset
18+
event ManagerSet(address manager, bool flag);
19+
20+
/// @notice Emitted when the default expiry duration is changed
21+
event DefaultExpiryDurationChanged(uint256 newDuration);
22+
23+
/// @notice Emitted when a token is issued
24+
event TokenIssued(address user, uint256 tokenId);
25+
26+
/// @notice Emitted when a token is revoked
27+
event TokenRevoked(address user, uint256 tokenId);
28+
29+
/// @notice Emitted when a token's expiry is extended
30+
event TokenExpiryExtended(address user, uint256 tokenId);
31+
1732
/// @notice Indicates if an address is a manager
1833
mapping(address => bool) public isManager;
1934

@@ -33,12 +48,6 @@ contract UserVerification is Initializable, ERC721Upgradeable, ERC721BurnableUpg
3348
_;
3449
}
3550

36-
/// @notice Emitted when a manager is set or unset
37-
event ManagerSet(address manager, bool flag);
38-
39-
/// @notice Emitted when the default expiry duration is changed
40-
event DefaultExpiryDurationChanged(uint256 newDuration);
41-
4251
/**
4352
* @dev Initializes the contract with the given name, symbol, and default expiry duration.
4453
* @param initialOwner The address of the initial owner.
@@ -115,6 +124,7 @@ contract UserVerification is Initializable, ERC721Upgradeable, ERC721BurnableUpg
115124
_safeMint(user, tokenId);
116125
_userTokens[user] = tokenId;
117126
_setTokenExpiry(tokenId, block.timestamp + defaultExpiryDuration);
127+
emit TokenIssued(user, tokenId);
118128
}
119129

120130
/**
@@ -128,6 +138,7 @@ contract UserVerification is Initializable, ERC721Upgradeable, ERC721BurnableUpg
128138
_burn(tokenId);
129139
delete _userTokens[tokenOwner];
130140
delete _tokenExpiryTimes[tokenId];
141+
emit TokenRevoked(tokenOwner, tokenId);
131142
}
132143

133144
/**
@@ -138,6 +149,7 @@ contract UserVerification is Initializable, ERC721Upgradeable, ERC721BurnableUpg
138149
function extendTokenExpiry(uint256 tokenId) external onlyManagers {
139150
require(_ownerOf(tokenId) != address(0), "Token does not exist");
140151
_setTokenExpiry(tokenId, block.timestamp + defaultExpiryDuration);
152+
emit TokenExpiryExtended(_ownerOf(tokenId), tokenId);
141153
}
142154

143155
/**

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const config: HardhatUserConfig = {
6363
ignition: {
6464
strategyConfig: {
6565
create2: {
66-
salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
66+
salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
6767
},
6868
},
6969
},

0 commit comments

Comments
 (0)