Skip to content

Commit

Permalink
Forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Dec 13, 2024
1 parent 35fadcd commit d8a803a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 74 deletions.
1 change: 0 additions & 1 deletion script/Chamber.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {Script} from "lib/forge-std/src/Script.sol";
import {Chamber} from "src/Chamber.sol";

contract DeployChamber is Script {

address token = address(1);
address nft = address(2);

Expand Down
8 changes: 2 additions & 6 deletions src/Board.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.0;

abstract contract Board {

event SetSeats(uint256 numOfSeats);
event SetSeatsCall(address caller);

Expand Down Expand Up @@ -95,9 +94,7 @@ abstract contract Board {
}

// View functions for the leaderboard
function _getTop(
uint256 count
) internal view returns (uint256[] memory, uint256[] memory) {
function _getTop(uint256 count) internal view returns (uint256[] memory, uint256[] memory) {
uint256 resultCount = count > size ? size : count;
uint256[] memory tokenIds = new uint256[](resultCount);
uint256[] memory amounts = new uint256[](resultCount);
Expand All @@ -116,12 +113,11 @@ abstract contract Board {
return 1 + (seats * 51) / 100;
}

function _getSeats() internal view returns(uint256) {
function _getSeats() internal view returns (uint256) {
return seats;
}

function _setSeats(uint256 numOfSeats) internal {

if (seats == 0) {
seats = numOfSeats;
emit SetSeats(numOfSeats);
Expand Down
29 changes: 7 additions & 22 deletions src/Chamber.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,15 @@ contract Chamber is Board, Wallet {
}

// Transfer tokens from user
require(
token.transferFrom(msg.sender, address(this), amount),
"Transfer failed"
);
require(token.transferFrom(msg.sender, address(this), amount), "Transfer failed");

// Emit Delegate event
emit Delegate(msg.sender, tokenId, amount);
}

function undelegate(uint256 tokenId, uint256 amount) external {
require(amount > 0, "Amount must be greater than 0");
require(
_userDelegations[msg.sender][tokenId] >= amount,
"Insufficient delegated amount"
);
require(_userDelegations[msg.sender][tokenId] >= amount, "Insufficient delegated amount");

// Update user delegation amount
_userDelegations[msg.sender][tokenId] -= amount;
Expand Down Expand Up @@ -85,16 +79,11 @@ contract Chamber is Board, Wallet {
return _getNode(tokenId);
}

function getTop(
uint256 count
) public view returns (uint256[] memory, uint256[] memory) {
function getTop(uint256 count) public view returns (uint256[] memory, uint256[] memory) {
return _getTop(count);
}

function getDelegation(
address user,
uint256 tokenId
) public view returns (uint256) {
function getDelegation(address user, uint256 tokenId) public view returns (uint256) {
return _userDelegations[user][tokenId];
}

Expand All @@ -107,7 +96,7 @@ contract Chamber is Board, Wallet {
}

function getDirectors() public view returns (address[] memory) {
(uint256[] memory topTokenIds, ) = getTop(_getSeats());
(uint256[] memory topTokenIds,) = getTop(_getSeats());
address[] memory topOwners = new address[](topTokenIds.length);

for (uint256 i = 0; i < topTokenIds.length; i++) {
Expand All @@ -126,7 +115,7 @@ contract Chamber is Board, Wallet {
}

modifier onlyDirector() {
(uint256[] memory topTokenIds, ) = getTop(_getSeats());
(uint256[] memory topTokenIds,) = getTop(_getSeats());

for (uint256 i = 0; i < topTokenIds.length; i++) {
if (nft.ownerOf(topTokenIds[i]) == msg.sender) {
Expand All @@ -140,11 +129,7 @@ contract Chamber is Board, Wallet {

/// WALLET ///

function submitTransaction(
address to,
uint256 value,
bytes memory data
) public onlyDirector {
function submitTransaction(address to, uint256 value, bytes memory data) public onlyDirector {
_submitTransaction(to, value, data);
}

Expand Down
32 changes: 12 additions & 20 deletions src/Wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
pragma solidity ^0.8.24;

abstract contract Wallet {

event SubmitTransaction(address indexed leader, uint256 indexed txIndex, address indexed to, uint256 value, bytes data);
event SubmitTransaction(
address indexed leader, uint256 indexed txIndex, address indexed to, uint256 value, bytes data
);
event ConfirmTransaction(address indexed leader, uint256 indexed txIndex);
event RevokeConfirmation(address indexed leader, uint256 indexed txIndex);
event ExecuteTransaction(address indexed leader, uint256 indexed txIndex);
Expand Down Expand Up @@ -37,20 +38,17 @@ abstract contract Wallet {
function _submitTransaction(address _to, uint256 _value, bytes memory _data) internal {
uint256 txIndex = transactions.length;

transactions.push(
Transaction({
to: _to,
value: _value,
data: _data,
executed: false,
numConfirmations: 0
})
);
transactions.push(Transaction({to: _to, value: _value, data: _data, executed: false, numConfirmations: 0}));

emit SubmitTransaction(msg.sender, txIndex, _to, _value, _data);
}

function _confirmTransaction(uint256 _txIndex) internal txExists(_txIndex) notExecuted(_txIndex) notConfirmed(_txIndex) {
function _confirmTransaction(uint256 _txIndex)
internal
txExists(_txIndex)
notExecuted(_txIndex)
notConfirmed(_txIndex)
{
Transaction storage transaction = transactions[_txIndex];
transaction.numConfirmations += 1;
isConfirmed[_txIndex][msg.sender] = true;
Expand All @@ -73,7 +71,7 @@ abstract contract Wallet {

transaction.executed = true;

(bool success, ) = transaction.to.call{value: transaction.value}(transaction.data);
(bool success,) = transaction.to.call{value: transaction.value}(transaction.data);
require(success, "Tx failed");

emit ExecuteTransaction(msg.sender, _txIndex);
Expand All @@ -83,11 +81,7 @@ abstract contract Wallet {
return transactions.length;
}

function getTransaction(uint256 _txIndex)
public
view
returns (Transaction memory)
{
function getTransaction(uint256 _txIndex) public view returns (Transaction memory) {
Transaction storage transaction = transactions[_txIndex];

return Transaction({
Expand All @@ -99,5 +93,3 @@ abstract contract Wallet {
});
}
}


11 changes: 2 additions & 9 deletions test/Chamber.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ contract ChamberTest is Test {
}

function test_Chamber_getLeaderboard_success() public {

uint256 num = 5000;
uint256[] memory tokenIds = new uint256[](num);
uint256[] memory amounts = new uint256[](num);
Expand Down Expand Up @@ -122,7 +121,6 @@ contract ChamberTest is Test {
MockERC721(address(nft)).mint(user1, tokenId);
MockERC20(address(token)).mint(user1, amount);


vm.startPrank(user1);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId, 1);
Expand All @@ -149,7 +147,6 @@ contract ChamberTest is Test {
MockERC721(address(nft)).mint(user1, tokenId);
MockERC20(address(token)).mint(user1, amount);


vm.startPrank(user1);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId, 1);
Expand All @@ -171,7 +168,6 @@ contract ChamberTest is Test {
MockERC721(address(nft)).mint(user1, tokenId);
MockERC20(address(token)).mint(user1, amount);


vm.startPrank(user1);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId, 1);
Expand Down Expand Up @@ -203,7 +199,6 @@ contract ChamberTest is Test {
MockERC721(address(nft)).mint(user3, tokenId + 3);
MockERC20(address(token)).mint(user3, amount);


vm.startPrank(user1);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId, 1);
Expand Down Expand Up @@ -242,7 +237,6 @@ contract ChamberTest is Test {
MockERC721(address(nft)).mint(user1, tokenId);
MockERC20(address(token)).mint(user1, amount);


vm.startPrank(user1);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId, 1);
Expand Down Expand Up @@ -284,12 +278,12 @@ contract ChamberTest is Test {
chamber.delegate(tokenId1, amount);
vm.stopPrank();

vm.startPrank(user2);
vm.startPrank(user2);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId2, amount);
vm.stopPrank();

vm.startPrank(user3);
vm.startPrank(user3);
MockERC20(address(token)).approve(address(chamber), amount);
chamber.delegate(tokenId3, amount);
vm.stopPrank();
Expand All @@ -312,4 +306,3 @@ contract ChamberTest is Test {
chamber.updateNumSeats(6);
}
}

1 change: 0 additions & 1 deletion test/mock/MockERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ contract MockERC20 is IERC20 {
emit Transfer(address(0), to, amount);
}
}

23 changes: 13 additions & 10 deletions test/mock/MockERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,42 @@ contract MockERC721 is IERC721 {
_owners[tokenId] = to;
}

function balanceOf(address /*owner*/) external pure returns (uint256 /*balance*/) {
function balanceOf(address /*owner*/ ) external pure returns (uint256 /*balance*/ ) {
revert("Not implemented");
}

function approve(address /*to*/, uint256 /*tokenId*/) external pure {
function approve(address, /*to*/ uint256 /*tokenId*/ ) external pure {
revert("Not implemented");
}

function getApproved(uint256 /*tokenId*/) external pure returns (address /*operator*/) {
function getApproved(uint256 /*tokenId*/ ) external pure returns (address /*operator*/ ) {
revert("Not implemented");
}

function isApprovedForAll(address /*owner*/, address /*operator*/) external pure returns (bool) {
function isApprovedForAll(address, /*owner*/ address /*operator*/ ) external pure returns (bool) {
revert("Not implemented");
}

function safeTransferFrom(address /*from*/, address /*to*/, uint256 /*tokenId*/) external pure {
function safeTransferFrom(address, /*from*/ address, /*to*/ uint256 /*tokenId*/ ) external pure {
revert("Not implemented");
}

function safeTransferFrom(address /*from*/, address /*to*/, uint256 /*tokenId*/, bytes calldata /*data*/) external pure {
function safeTransferFrom(address, /*from*/ address, /*to*/ uint256, /*tokenId*/ bytes calldata /*data*/ )
external
pure
{
revert("Not implemented");
}

function setApprovalForAll(address /*operator*/, bool /*approved*/) external pure {
function setApprovalForAll(address, /*operator*/ bool /*approved*/ ) external pure {
revert("Not implemented");
}

function supportsInterface(bytes4 /*interfaceId*/) external pure returns (bool) {
function supportsInterface(bytes4 /*interfaceId*/ ) external pure returns (bool) {
revert("Not implemented");
}

function transferFrom(address /*from*/, address /*to*/, uint256 /*tokenId*/) external pure {
function transferFrom(address, /*from*/ address, /*to*/ uint256 /*tokenId*/ ) external pure {
revert("Not implemented");
}
}
}
6 changes: 1 addition & 5 deletions test/mock/MockWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ pragma solidity ^0.8.24;
import {Wallet} from "src/Wallet.sol";

contract MockWallet is Wallet {
function submitTransaction(
address to,
uint256 value,
bytes memory data
) public {
function submitTransaction(address to, uint256 value, bytes memory data) public {
_submitTransaction(to, value, data);
}

Expand Down

0 comments on commit d8a803a

Please sign in to comment.