Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week5 samples #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/artifacts/**
**/artifacts/**
**/.deps/**
18 changes: 18 additions & 0 deletions week-5/2_OpenZeppelin/2_1_MyPestoGems_ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

// Another interesting way to import solidity files form GitHub
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

// MyPestoGems is an ERC20 token
// Basic implementation of ERC20 token standard is already provided by openzeppelin
contract MyPestoGems is ERC20 {

constructor(uint256 _initalSupply) ERC20("MyPestoGems", "MPG") {

//mint initial supply tokens to the deployer
// '**' means to the power, here 10 power 18
_mint(msg.sender, _initalSupply*10**18);

}
}
42 changes: 42 additions & 0 deletions week-5/2_OpenZeppelin/2_2_MyPestoGems_ERC20_extended.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/Pausable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

// This solution has a purposeful logical error. try to fix the problem.
// Deploy the contract and try to play around with the tokens.
contract MyPestoGems is ERC20, ERC20Burnable, ERC20Capped, Pausable, Ownable {

// Note the call of conttructors from ERC20 and ERC20Capped
constructor(uint256 _cap) ERC20("MyPestoGems", "MPG") ERC20Capped(_cap) {

}

function pause() public onlyOwner {
_pause();
}

function unpause() public onlyOwner {
_unpause();
}

function _beforeTokenTransfer(address from, address to, uint256 amount)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(from, to, amount);
}

/**
* @dev See {ERC20-_mint}.
*/
function _mint(address account, uint256 amount) internal virtual override(ERC20,ERC20Capped) {
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
super._mint(account, amount);
}
}
45 changes: 45 additions & 0 deletions week-5/2_OpenZeppelin/2_3_MyPestoGems_ERC20_solution.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/Pausable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

// The solution is to have a mint function to be able to mint tokens before they can be transferred.
contract MyPestoGems is ERC20, ERC20Burnable, ERC20Capped, Pausable, Ownable {

// Note the call of constructors from ERC20 and ERC20Capped
constructor(uint256 _cap) ERC20("MyPestoGems", "MPG") ERC20Capped(_cap) {

}

function pause() public onlyOwner {
_pause();
}

function unpause() public onlyOwner {
_unpause();
}

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

function _beforeTokenTransfer(address from, address to, uint256 amount)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(from, to, amount);
}

/**
* @dev See {ERC20-_mint}.
*/
function _mint(address account, uint256 amount) internal virtual override(ERC20,ERC20Capped) {
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
super._mint(account, amount);
}
}
11 changes: 11 additions & 0 deletions week-5/2_OpenZeppelin/2_4_PestoDevs_ERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master//contracts/token/ERC721/ERC721.sol";

contract PestoDevsNFT is ERC721 {
constructor() ERC721("PestoDevs", "PD") {
// mint an NFT to yourself
_mint(msg.sender, 1);
}
}
21 changes: 21 additions & 0 deletions week-5/2_OpenZeppelin/2_5_PestoDevs_ERC721_Mintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol";

contract PestoDevsNFT is ERC721 {

using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;

constructor() ERC721("PestoDevs", "PD") {
}

// Anyone can mint
function safeMint(address to) public {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
}
40 changes: 40 additions & 0 deletions week-5/2_OpenZeppelin/2_6_PestoDevs_ERC721_Enumerable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol";

// Easy to enumerate through the collection
contract PestoDevsNFT is ERC721, ERC721Enumerable {

using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;

constructor() ERC721("PestoDevs", "PD") {
}

function safeMint(address to) public {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}

// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
internal
override(ERC721, ERC721Enumerable)
{
super._beforeTokenTransfer(from, to, tokenId, batchSize);
}

function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}

44 changes: 44 additions & 0 deletions week-5/2_OpenZeppelin/2_7_PestoDevs_ERC721_URI.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol";

// Easy to enumerate through the collection
contract PestoDevsNFT is ERC721, ERC721Enumerable, ERC721URIStorage {

using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;

constructor() ERC721("PestoDevs", "PD") {
}

// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId, batchSize);
}

function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}

function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}

// URI for easy integration with NFT marketplace
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
return super.tokenURI(tokenId);
}

function safeMint(address to, string memory uri) public {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}
}


57 changes: 57 additions & 0 deletions week-5/2_OpenZeppelin/2_8_PestoGamingTokens_ERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol";

contract PestoGamingTokens is ERC1155, AccessControl {

// Roles for token processing
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

constructor() ERC1155("") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(URI_SETTER_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);

// To demo multiple tokens ERC20 and ERC721
// Pesto Coins - Given as a form of rewards redeemable in the marketplace
_mint(msg.sender, 1, 100*10**18, bytes("PestoCoins") );

// Pesto Team - Represents a Team NFT
_mint(msg.sender, 2, 1, bytes("Ayush Jaiswal-CEO") );

// Pesto Team - Represents a Team NFT
_mint(msg.sender, 3, 1, bytes("Rahul Jaimini-Co-founder") );
}

// URI to get metadata about the tokens on a off-chain location
function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {
_setURI(newuri);
}

function mint(address account, uint256 id, uint256 amount, bytes memory data)
public
onlyRole(MINTER_ROLE)
{
_mint(account, id, amount, data);
}

function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
public
onlyRole(MINTER_ROLE)
{
_mintBatch(to, ids, amounts, data);
}

// The following functions are overrides required by Solidity.
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
18 changes: 18 additions & 0 deletions week-5/3_ABI/3_1_MyPestoGems_ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

// Another interesting way to import solidity files form GitHub
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

// MyPestoGems is an ERC20 token
// Basic implementation of ERC20 token standard is already provided by openzeppelin
contract MyPestoGems is ERC20 {

constructor(uint256 _initalSupply) ERC20("MyPestoGems", "MPG") {

//mint initial supply tokens to the deployer
// '**' means to the power, here 10 power 18
_mint(msg.sender, _initalSupply*10**18);

}
}
45 changes: 45 additions & 0 deletions week-5/4_EthersJS/4_1/contracts/MyPestoGems_ERC20_extended.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/Pausable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

// The solution is to have a mint function to be able to mint tokens before they can be transferred.
contract MyPestoGems is ERC20, ERC20Burnable, ERC20Capped, Pausable, Ownable {

// Note the call of constructors from ERC20 and ERC20Capped
constructor(uint256 _cap) ERC20("MyPestoGems", "MPG") ERC20Capped(_cap) {

}

function pause() public onlyOwner {
_pause();
}

function unpause() public onlyOwner {
_unpause();
}

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

function _beforeTokenTransfer(address from, address to, uint256 amount)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(from, to, amount);
}

/**
* @dev See {ERC20-_mint}.
*/
function _mint(address account, uint256 amount) internal virtual override(ERC20,ERC20Capped) {
require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded");
super._mint(account, amount);
}
}
Loading