feat: contracts and deploy script

This commit is contained in:
leggio 2022-11-09 10:19:59 -05:00
parent 7446847f2e
commit bd4012f0fd
9 changed files with 4915 additions and 2 deletions

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types
#Hardhat files
cache
artifacts
node_modules
.env
coverage
coverage.json
typechain
typechain-types
#Hardhat files
cache
artifacts

View File

@ -1,2 +1,13 @@
# take-home
Magna engineering take-home assessment
# Sample Hardhat Project
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.
Try running some of the following tasks:
```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.ts
```

26
contracts/Airdrop.sol Normal file
View File

@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.17;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Airdrop is Ownable {
address public token;
constructor(address _token) {
token = _token;
}
function airdropTokens(
address[] memory _recipients,
uint256[] memory amount
) external onlyOwner {
require(
_recipients.length == amount.length,
"Airdrop: Recipients and amount length mismatch"
);
for (uint256 i = 0; i < _recipients.length; i++) {
IERC20(token).transfer(_recipients[i], amount[i]);
}
}
}

12
contracts/MagnaToken.sol Normal file
View File

@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MagnaToken is ERC20 {
uint256 constant _initial_supply = (10**9) * (10**18);
constructor() ERC20("MagnaToken", "MAGNA") {
_mint(msg.sender, _initial_supply);
}
}

8
hardhat.config.ts Normal file
View File

@ -0,0 +1,8 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
const config: HardhatUserConfig = {
solidity: "0.8.17",
};
export default config;

33
package.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "take-home",
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/magna-eng/take-home.git",
"author": "pop-punk <harrison@magna.so>",
"license": "MIT",
"devDependencies": {
"@ethersproject/abi": "^5.4.7",
"@ethersproject/providers": "^5.4.7",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.2.0",
"@types/mocha": "^9.1.0",
"@types/node": ">=12.0.0",
"chai": "^4.2.0",
"ethers": "^5.4.7",
"hardhat": "^2.12.2",
"hardhat-gas-reporter": "^1.0.8",
"solidity-coverage": "^0.8.0",
"ts-node": ">=8.0.0",
"typechain": "^8.1.0",
"typescript": ">=4.5.0"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.0"
}
}

21
scripts/deploy.ts Normal file
View File

@ -0,0 +1,21 @@
import { ethers } from "hardhat";
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
const Token = await ethers.getContractFactory("MagnaToken");
const token = await Token.deploy();
console.log("Token address:", token.address);
const Airdrop = await ethers.getContractFactory("Airdrop");
const airdrop = await Airdrop.deploy(token.address);
console.log("Airdrop address:", airdrop.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}

4769
yarn.lock Normal file

File diff suppressed because it is too large Load Diff