-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
953 additions
and
10,035 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.env | ||
docs | ||
build | ||
*.out | ||
*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
updated
29 files
+1 −0 | .gitattributes | |
+0 −3 | .gitmodules | |
+1 −1 | README.md | |
+0 −1 | lib/ds-test | |
+1 −1 | package.json | |
+635 −0 | scripts/vm.py | |
+518 −225 | src/StdAssertions.sol | |
+7 −1 | src/StdChains.sol | |
+7 −11 | src/StdJson.sol | |
+201 −106 | src/StdStorage.sol | |
+179 −0 | src/StdToml.sol | |
+2 −5 | src/Test.sol | |
+1,273 −483 | src/Vm.sol | |
+51 −33 | src/mocks/MockERC20.sol | |
+46 −32 | src/mocks/MockERC721.sol | |
+39 −909 | test/StdAssertions.t.sol | |
+27 −22 | test/StdChains.t.sol | |
+18 −10 | test/StdCheats.t.sol | |
+3 −1 | test/StdError.t.sol | |
+49 −0 | test/StdJson.t.sol | |
+8 −8 | test/StdMath.t.sol | |
+159 −11 | test/StdStorage.t.sol | |
+49 −0 | test/StdToml.t.sol | |
+20 −20 | test/StdUtils.t.sol | |
+3 −3 | test/Vm.t.sol | |
+8 −0 | test/fixtures/test.json | |
+6 −0 | test/fixtures/test.toml | |
+1 −1 | test/mocks/MockERC20.t.sol | |
+1 −1 | test/mocks/MockERC721.t.sol |
Submodule openzeppelin-contracts
added at
dbb610
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
|
||
/** | ||
* @title UserRegistry | ||
* @author ronfflex | ||
* @notice This contract manages user registration, authentication, and administration for a decentralized exchange (DEX) platform. | ||
*/ | ||
contract UserRegistry is Ownable { | ||
using EnumerableSet for EnumerableSet.UintSet; | ||
|
||
mapping(address => User) public users; | ||
|
||
// Set to store registered user IDs | ||
EnumerableSet.UintSet private registeredUserIds; | ||
|
||
struct User { | ||
uint256 id; | ||
string name; | ||
bool isBanned; | ||
} | ||
|
||
constructor() Ownable(msg.sender) {} | ||
|
||
// Events to log | ||
event UserRegistered(address indexed userAddress, uint256 userId); | ||
event UserBanned(address indexed userAddress, uint256 userId); | ||
event UserUnbanned(address indexed userAddress, uint256 userId); | ||
|
||
/** | ||
* @notice Gets the user IDs of all registered users. | ||
* @return uint256[] An array of user IDs. | ||
*/ | ||
function getRegisteredUserIds() public view returns (uint256[] memory) { | ||
return registeredUserIds.values(); | ||
} | ||
|
||
/** | ||
* @notice Registers a new user with the provided name. | ||
* @param _name The name of the user. | ||
*/ | ||
function registerUser(string memory _name) public { | ||
require(users[msg.sender].id == 0, "User already registered"); | ||
|
||
uint256 userId = registeredUserIds.length() + 1; | ||
users[msg.sender] = User(userId, _name, false); | ||
registeredUserIds.add(userId); | ||
|
||
emit UserRegistered(msg.sender, userId); | ||
} | ||
|
||
/** | ||
* @notice Checks if the given address is a registered user. | ||
* @param _address The address to check. | ||
* @return bool True if the address is a registered user, false otherwise. | ||
*/ | ||
function isRegisteredUser(address _address) public view returns (bool) { | ||
return users[_address].id != 0; | ||
} | ||
|
||
/** | ||
* @notice Gets the user ID associated with the given address. | ||
* @param _address The address of the user. | ||
* @return uint256 The user ID. | ||
*/ | ||
function getUserId(address _address) public view returns (uint256) { | ||
return users[_address].id; | ||
} | ||
|
||
/** | ||
* @notice Bans the user with the given address. | ||
* @param _userAddress The address of the user to ban. | ||
*/ | ||
function banUser(address _userAddress) public onlyOwner { | ||
require(isRegisteredUser(_userAddress), "User not registered"); | ||
|
||
users[_userAddress].isBanned = true; | ||
|
||
emit UserBanned(_userAddress, users[_userAddress].id); | ||
} | ||
|
||
/** | ||
* @notice Unbans the user with the given address. | ||
* @param _userAddress The address of the user to unban. | ||
*/ | ||
function unbanUser(address _userAddress) public onlyOwner { | ||
require(isRegisteredUser(_userAddress), "User not registered"); | ||
require(users[_userAddress].isBanned, "User not banned"); | ||
|
||
users[_userAddress].isBanned = false; | ||
|
||
emit UserUnbanned(_userAddress, users[_userAddress].id); | ||
} | ||
|
||
/** | ||
* @notice Checks if the given user is banned. | ||
* @param _userAddress The address of the user. | ||
* @return bool True if the user is banned, false otherwise. | ||
*/ | ||
function isUserBanned(address _userAddress) public view returns (bool) { | ||
return isRegisteredUser(_userAddress) && users[_userAddress].isBanned; | ||
} | ||
|
||
/** | ||
* @notice Transfers the user ID from the old address to the new address. | ||
* @param _oldAddress The old address of the user. | ||
* @param _newAddress The new address of the user. | ||
*/ | ||
function transferUserId(address _oldAddress, address _newAddress) public onlyOwner { | ||
require(isRegisteredUser(_oldAddress), "Old address not registered"); | ||
require(!isRegisteredUser(_newAddress), "New address already registered"); | ||
|
||
uint256 userId = users[_oldAddress].id; | ||
string memory name = users[_oldAddress].name; | ||
|
||
delete users[_oldAddress]; | ||
users[_newAddress] = User(userId, name, false); | ||
|
||
emit UserRegistered(_newAddress, userId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.