Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Assignments/Assignment-1.md/assignment1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Assignment 1

Here's a link to [Assignment 1](../../contracts/counter.frankhood.sol)

73 changes: 73 additions & 0 deletions Assignments/Assignment-1.md/counter..FRANKHOOD.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

/// @title Counter Contract Implementation
/// @author FRANKHOOD
/// @notice this contract defines the count and maximum value of the count
/// @dev All function calls are currently implemented without side effects
contract Counter{
uint public count = 0;
uint maxValue = getMaxUint256 ();

/// @notice this event is emitted when the count is increased
/// @param amount the value of the count after increasing
/// @param timestamp the time the count increased
event CountIncreased(uint amount, uint timestamp);

/// @notice this event is emitted when the count is decreased
/// @param amount the value of the count after decreasing
/// @param timestamp the time the count decreased
event CountDecreased(uint amount, uint timestamp);

/// @notice this function increases the count by 0ne
/// @notice this function is reverted if it exceeds the maxValue
function increaseByOne() public {
require(count < maxValue, "cannot increase beyond max uint");
count ++;
emit CountIncreased(count, block.timestamp);
}

/// @notice this function increases the count by a value that must be greater than 0
/// @notice this function is reverted if it exceeds the maxValue
function increaseByValue(uint _value) public {
require (_value > 0);
require(count < maxValue, "cannot increase beyond max uint");
count += _value;
emit CountIncreased(count, block.timestamp);
}

/// @notice this function decreases the count by 0ne
/// @notice this function is reverted if the value of count is less than 1
function decreaseByOne() public {
require(count >= 1,"cannot decrease below 0");
count --;
emit CountDecreased(count, block.timestamp);
}

/// @notice this function decreases the count by a value greater than or equal to one
/// @notice this function is reverted if the result is greater than maxValue
function decreaseByValue(uint _value) public {
require(count >= 1,"cannot decrease below 0");
require(count + _value <= maxValue);
count += _value;
emit CountDecreased(count, block.timestamp);
}

/// @notice this function resets the count to original value - 0
function resetCount() public {
count = 0;
emit CountDecreased(count, block.timestamp);
}

/// @notice this function returns the current value of count
function getCount() public view returns (uint){
return count;
}

/// @notice this function returns the maximum value of count
function getMaxUint256() public pure returns (uint){
unchecked {
return uint256 (0)-1;
}
}
}
73 changes: 73 additions & 0 deletions contracts/counter.frankhood.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

/// @title Counter Contract Implementation
/// @author FRANKHOOD
/// @notice this contract defines the count and maximum value of the count
/// @dev All function calls are currently implemented without side effects
contract Counter{
uint public count = 0;
uint maxValue = getMaxUint256 ();

/// @notice this event is emitted when the count is increased
/// @param amount the value of the count after increasing
/// @param timestamp the time the count increased
event CountIncreased(uint amount, uint timestamp);

/// @notice this event is emitted when the count is decreased
/// @param amount the value of the count after decreasing
/// @param timestamp the time the count decreased
event CountDecreased(uint amount, uint timestamp);

/// @notice this function increases the count by 0ne
/// @notice this function is reverted if it exceeds the maxValue
function increaseByOne() public {
require(count < maxValue, "cannot increase beyond max uint");
count ++;
emit CountIncreased(count, block.timestamp);
}

/// @notice this function increases the count by a value that must be greater than 0
/// @notice this function is reverted if it exceeds the maxValue
function increaseByValue(uint _value) public {
require (_value > 0);
require(count < maxValue, "cannot increase beyond max uint");
count += _value;
emit CountIncreased(count, block.timestamp);
}

/// @notice this function decreases the count by 0ne
/// @notice this function is reverted if the value of count is less than 1
function decreaseByOne() public {
require(count >= 1,"cannot decrease below 0");
count --;
emit CountDecreased(count, block.timestamp);
}

/// @notice this function decreases the count by a value greater than or equal to one
/// @notice this function is reverted if the result is greater than maxValue
function decreaseByValue(uint _value) public {
require(count >= 1,"cannot decrease below 0");
require(count + _value <= maxValue);
count += _value;
emit CountDecreased(count, block.timestamp);
}

/// @notice this function resets the count to original value - 0
function resetCount() public {
count = 0;
emit CountDecreased(count, block.timestamp);
}

/// @notice this function returns the current value of count
function getCount() public view returns (uint){
return count;
}

/// @notice this function returns the maximum value of count
function getMaxUint256() public pure returns (uint){
unchecked {
return uint256 (0)-1;
}
}
}
64 changes: 64 additions & 0 deletions submissions/Assignment3/KingFRANKHOOD/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

contract ERC20 {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;

mapping (address => uint256) public balanceOf;
mapping (address => mapping(address => uint256)) public allowance;

event Transfer (address indexed from, address indexed to, uint256 value);
event Approval (address indexed owner, address indexed spender, uint value);

constructor(string memory _name, string memory _symbol, uint8 _decimals) {
name = _name;
symbol = _symbol;
decimals = _decimals;
}


function transfer(address recipient, uint256 amount) external returns (bool) {
require(balanceOf[msg.sender] >= amount);
balanceOf[msg.sender] -= amount;
balanceOf[recipient] += amount;

emit Transfer(msg.sender, recipient, amount);
return true;
}

function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
allowance[sender][msg.sender] -= amount;
balanceOf[sender] -= amount;
balanceOf[recipient] += amount;
emit Transfer(sender, recipient, amount);
return true;
}

function _mint (address _to, uint256 _amount) virtual public {
require(msg.sender != address(0), "zero address");
balanceOf[_to] += _amount;
totalSupply += _amount;

emit Transfer(address(0), _to, _amount);
}

function _burn (address, uint256 _amount) public {
require(balanceOf[msg.sender] >= _amount, "insufficient funds");
totalSupply -= _amount;
balanceOf[msg.sender] -= _amount;
balanceOf[address(0)] -= _amount;

emit Transfer(msg.sender, address(0), _amount);
}

function mint(address to, uint256 amount) external {
_mint(to, amount);
}

function burn(address from, uint256 amount) external {
_burn(from, amount);
}
}
77 changes: 77 additions & 0 deletions submissions/Assignment3/KingFRANKHOOD/ERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.24;

import "./IERC721.sol";

contract ERC721 is IERC721 {
// Mapping fron tokenId to owner address
mapping (uint256=> address) internal _ownerOf;

//Mapping from owner address to token count
mapping (address => uint256) internal _balanceOf;

//Mapping from tokenId to approved address
mapping (uint256 => address) internal _approvals;

//Mapping from owner to operator approvals
mapping (address => mapping (address => bool)) public isApprovedForAll;

event NFTTransfer(address indexed from, address indexed to, uint256 indexed id);
event NFTApproval(address indexed owner, address indexed spender, uint256 indexed id);
event ApprovalForAll(address indexed owner, address operator, bool approved);

function nftBalanceOf(address owner) external view returns (uint256) {
require(owner != address(0), "owner = zero address");
return _balanceOf[owner];
}

function ownerOf(uint256 tokenId) external view returns (address ownerOfToken) {
ownerOfToken = _ownerOf[tokenId];
require(ownerOfToken != address(0), "token doesn't exist");
}

function setApprovalForAll(address operator, bool approved) external {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender,operator,approved);
}

function approve(address to, uint256 tokenId) external {
address owner = _ownerOf[tokenId];
require(msg.sender == owner || isApprovedForAll[owner][msg.sender], 'not authorised');

_approvals[tokenId] = to;

emit NFTApproval(owner, to, tokenId);
}

function getApproved(uint256 tokenId) external view returns (address) {
require (_ownerOf[tokenId] !=address(0), "token does not exist");
return _approvals[tokenId];
}

function isApprovedOrOwner(address owner, address spender, uint256 id) private view returns (bool) {
return (spender == owner || isApprovedForAll[owner][spender] || spender == _approvals[id]);
}

function nftTransferFrom(address from, address to, uint256 tokenId) external {
require(from == _ownerOf[tokenId], "from != owner");
require(to != address(0), "transfer to zero address");
require(isApprovedOrOwner(from, msg.sender, tokenId), "not authorised");

_balanceOf[from]--;
_balanceOf[to]++;
_ownerOf[tokenId] = to;

delete _approvals[tokenId];
}

function _mintNFT(address to, uint256 tokenId) internal virtual {
require(to != address(0), "mint to zero address");
require(_ownerOf[tokenId] == address(0), "already minted");

_balanceOf[to]++;
_ownerOf[tokenId] = to;

emit NFTTransfer(address(0), to, tokenId);
}
}
13 changes: 13 additions & 0 deletions submissions/Assignment3/KingFRANKHOOD/IERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.24;

interface IERC721 {
function nftBalanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint tokenId) external view returns (address owner);
//function safeTransferFrom(address from, address to, uint tokenId, bytes memory data) external;
//function safeTransferFrom(address from, address to, uint tokenId) external;
function nftTransferFrom(address from, address to, uint tokenId) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
Loading