Skip to content

Commit

Permalink
First 5 Questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arda Usman authored and Arda Usman committed May 25, 2022
1 parent 858dfc9 commit 7d53bd6
Show file tree
Hide file tree
Showing 47 changed files with 11,250 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
40 changes: 40 additions & 0 deletions contracts/DamnValuableNFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

/**
* @title DamnValuableNFT
* @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz)
* @notice Implementation of a mintable and burnable NFT with role-based access controls
*/
contract DamnValuableNFT is ERC721, ERC721Burnable, AccessControl {
using Counters for Counters.Counter;

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
Counters.Counter private _tokenIdCounter;

constructor() ERC721("DamnValuableNFT", "DVNFT") {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(MINTER_ROLE, msg.sender);
}

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

function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
17 changes: 17 additions & 0 deletions contracts/DamnValuableToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/**
* @title DamnValuableToken
* @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz)
*/
contract DamnValuableToken is ERC20 {

// Decimals are set to 18 by default in `ERC20`
constructor() ERC20("DamnValuableToken", "DVT") {
_mint(msg.sender, type(uint256).max);
}
}
31 changes: 31 additions & 0 deletions contracts/DamnValuableTokenSnapshot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol";

/**
* @title DamnValuableTokenSnapshot
* @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz)
*/
contract DamnValuableTokenSnapshot is ERC20Snapshot {

uint256 private lastSnapshotId;

constructor(uint256 initialSupply) ERC20("DamnValuableToken", "DVT") {
_mint(msg.sender, initialSupply);
}

function snapshot() public returns (uint256) {
lastSnapshotId = _snapshot();
return lastSnapshotId;
}

function getBalanceAtLastSnapshot(address account) external view returns (uint256) {
return balanceOfAt(account, lastSnapshotId);
}

function getTotalSupplyAtLastSnapshot() external view returns (uint256) {
return totalSupplyAt(lastSnapshotId);
}
}
Loading

0 comments on commit 7d53bd6

Please sign in to comment.