Skip to content

Commit

Permalink
ico complete code
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrakumarreddy committed Jun 12, 2022
0 parents commit 8efee97
Show file tree
Hide file tree
Showing 24 changed files with 12,008 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hardhat-tutorial/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.env
coverage
coverage.json
typechain

#Hardhat files
cache
artifacts
15 changes: 15 additions & 0 deletions hardhat-tutorial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Basic Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.

Try running some of the following tasks:

```shell
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
node scripts/sample-script.js
npx hardhat help
```
4 changes: 4 additions & 0 deletions hardhat-tutorial/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
CRYPTO_DEVS_NFT_CONTRACT_ADDRESS:
"0x37303618c6258EBCDE2fea24c5fE3968bD25E79c",
};
56 changes: 56 additions & 0 deletions hardhat-tutorial/contracts/CryptoDevToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./ICryptoDevs.sol";

contract CryptoDevToken is ERC20, Ownable {
uint256 public constant tokenPrice = 0.001 ether;
uint256 public constant tokensPerNFT = 10 * 10**18;
uint256 public constant maxTotalSupply = 10000 * 10**18;
ICryptoDevs CryptoDevsNFT;
mapping(uint256 => bool) public tokenIdsClaimed;

constructor(address _cryptoDevsContract) ERC20("Crypto Dev Token", "CD") {
CryptoDevsNFT = ICryptoDevs(_cryptoDevsContract);
}

function mint(uint256 amount) public payable {
uint256 _requiredAmount = amount * tokenPrice;
require(msg.value >= _requiredAmount, "Ether sent is incorrect");
uint256 amountWithDecimals = amount * 10**18;
require(
totalSupply() + amountWithDecimals <= maxTotalSupply,
"Exceeds the max total supply available."
);
_mint(msg.sender, amountWithDecimals);
}

function claim() public {
address sender = msg.sender;
uint256 balance = CryptoDevsNFT.balanceOf(sender);
require(balance > 0, "You dont own any Crypto Dev NFT's");
uint256 amount = 0;
for (uint256 i = 0; i < balance; i++) {
uint256 tokenId = CryptoDevsNFT.tokenOfOwnerByIndex(sender, i);
if (!tokenIdsClaimed[tokenId]) {
amount += 1;
tokenIdsClaimed[tokenId] = true;
}
}
require(amount > 0, "You have already claimed all the tokens");
_mint(sender, amount * tokensPerNFT);
}

function withdraw() public onlyOwner {
address _owner = owner();
uint256 amount = address(this).balance;
(bool sent, ) = _owner.call{value: amount}("");
require(sent, "Failed to send Ether");
}

receive() external payable {}

fallback() external payable {}
}
14 changes: 14 additions & 0 deletions hardhat-tutorial/contracts/ICryptoDevs.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

interface ICryptoDevs {
function tokenOfOwnerByIndex(address _address, uint256 index)
external
view
returns (uint256 tokenId);

function balanceOf(address _address)
external
view
returns (uint256 balance);
}
16 changes: 16 additions & 0 deletions hardhat-tutorial/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require("@nomiclabs/hardhat-waffle");
require("dotenv").config({ path: ".env" });

const ALCHEMY_API_KEY_URL = process.env.ALCHEMY_API_KEY_URL;

const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY;

module.exports = {
solidity: "0.8.4",
networks: {
rinkeby: {
url: ALCHEMY_API_KEY_URL,
accounts: [RINKEBY_PRIVATE_KEY],
},
},
};
24 changes: 24 additions & 0 deletions hardhat-tutorial/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "hardhat-tutorial",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"chai": "^4.3.6",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.6.8",
"hardhat": "^2.9.9"
},
"dependencies": {
"@openzeppelin/contracts": "^4.6.0",
"dotenv": "^16.0.1"
}
}
26 changes: 26 additions & 0 deletions hardhat-tutorial/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { ethers } = require("hardhat");
const { CRYPTO_DEVS_NFT_CONTRACT_ADDRESS } = require("../constants");

async function main() {
const cryptoDevsNFTContract = CRYPTO_DEVS_NFT_CONTRACT_ADDRESS;
const cryptoDevsTokenContract = await ethers.getContractFactory(
"CryptoDevToken"
);
const deployedCryptoDevsTokenContract = await cryptoDevsTokenContract.deploy(
cryptoDevsNFTContract
);

await deployedCryptoDevsTokenContract.deployed();

console.log(
"Crypto Devs Token Contract Address:",
deployedCryptoDevsTokenContract.address
);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
19 changes: 19 additions & 0 deletions hardhat-tutorial/test/sample-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Greeter", function () {
it("Should return the new greeting once it's changed", async function () {
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, world!");
await greeter.deployed();

expect(await greeter.greet()).to.equal("Hello, world!");

const setGreetingTx = await greeter.setGreeting("Hola, mundo!");

// wait until the transaction is mined
await setGreetingTx.wait();

expect(await greeter.greet()).to.equal("Hola, mundo!");
});
});
Loading

0 comments on commit 8efee97

Please sign in to comment.