├── .gitignore ├── .env.example ├── tsconfig.json ├── test ├── unit │ ├── Lending │ │ └── LendingShouldDeposit.spec.ts │ └── index.ts └── shared │ ├── types.ts │ ├── mocks.ts │ └── fixtures.ts ├── package.json ├── LICENSE ├── hardhat.config.ts ├── scripts └── deploy.ts ├── contracts └── Lending.sol ├── README.md └── abis └── erc20.abi.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | coverage 4 | coverage.json 5 | typechain 6 | typechain-types 7 | 8 | #Hardhat files 9 | cache 10 | artifacts 11 | 12 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | MAINNET_RPC_URL=https://eth-mainnet.alchemyapi.io/v2/ 2 | GOERLI_RPC_URL=https://eth-goerli.alchemyapi.io/v2/ 3 | PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 4 | ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1 -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "outDir": "dist", 8 | "declaration": true, 9 | "resolveJsonModule": true 10 | }, 11 | "include": ["./scripts", "./test", "./typechain"], 12 | "files": ["./hardhat.config.ts"] 13 | } 14 | -------------------------------------------------------------------------------- /test/unit/Lending/LendingShouldDeposit.spec.ts: -------------------------------------------------------------------------------- 1 | export const shouldDeposit = (): void => { 2 | // // to silent warning for duplicate definition of Transfer event 3 | // ethers.utils.Logger.setLogLevel(ethers.utils.Logger.levels.OFF); 4 | 5 | describe(`#deposit`, async function () { 6 | it(`should start here...`, async function () { }); 7 | }); 8 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hardhat-project", 3 | "devDependencies": { 4 | "@chainlink/contracts": "^0.5.1", 5 | "@ethereum-waffle/mock-contract": "^3.4.4", 6 | "@nomicfoundation/hardhat-toolbox": "^2.0.0", 7 | "@openzeppelin/contracts": "^4.7.3", 8 | "hardhat": "^2.12.0" 9 | }, 10 | "dependencies": { 11 | "dotenv": "^16.0.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/shared/types.ts: -------------------------------------------------------------------------------- 1 | import { MockContract } from '@ethereum-waffle/mock-contract'; 2 | import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; 3 | import { Lending } from "../../typechain-types"; 4 | 5 | declare module "mocha" { 6 | export interface Context { 7 | signers: Signers; 8 | mocks: Mocks; 9 | lending: Lending; 10 | } 11 | } 12 | 13 | export interface Signers { 14 | deployer: SignerWithAddress; 15 | alice: SignerWithAddress; 16 | bob: SignerWithAddress; 17 | } 18 | 19 | export interface Mocks { 20 | mockUsdc: MockContract; 21 | } -------------------------------------------------------------------------------- /test/shared/mocks.ts: -------------------------------------------------------------------------------- 1 | import { MockContract, deployMockContract } from '@ethereum-waffle/mock-contract'; 2 | import { Signer } from "ethers"; 3 | import { artifacts } from "hardhat"; 4 | import { Artifact } from "hardhat/types"; 5 | import ERC_20_ABI from "../../abis/erc20.abi.json"; 6 | 7 | export async function deployMockUsdc(deployer: Signer): Promise { 8 | // const erc20Artifact: Artifact = await artifacts.readArtifact("ERC20"); 9 | const erc20: MockContract = await deployMockContract( 10 | deployer, 11 | ERC_20_ABI 12 | ); 13 | 14 | await erc20.mock.decimals.returns(6); 15 | await erc20.mock.name.returns(`USD Coin`); 16 | await erc20.mock.symbol.returns(`USDC`); 17 | await erc20.mock.transferFrom.returns(true); 18 | 19 | return erc20; 20 | } -------------------------------------------------------------------------------- /test/unit/index.ts: -------------------------------------------------------------------------------- 1 | import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; 2 | import { getSigners, unitLendingFixture } from "../shared/fixtures"; 3 | import { Mocks, Signers } from "../shared/types"; 4 | import { shouldDeposit } from "./Lending/LendingShouldDeposit.spec"; 5 | 6 | describe(`Unit tests`, async () => { 7 | before(async function () { 8 | const { deployer, alice, bob } = await loadFixture(getSigners); 9 | 10 | this.signers = {} as Signers; 11 | this.signers.deployer = deployer; 12 | this.signers.alice = alice; 13 | this.signers.bob = bob; 14 | }); 15 | 16 | describe(`Lending`, async () => { 17 | beforeEach(async function () { 18 | const { lending, mockUsdc } = await loadFixture(unitLendingFixture); 19 | 20 | this.lending = lending; 21 | 22 | this.mocks = {} as Mocks; 23 | this.mocks.mockUsdc = mockUsdc; 24 | }); 25 | 26 | shouldDeposit(); 27 | }); 28 | }); -------------------------------------------------------------------------------- /test/shared/fixtures.ts: -------------------------------------------------------------------------------- 1 | import { MockContract } from '@ethereum-waffle/mock-contract'; 2 | import { ContractFactory, Wallet } from "ethers"; 3 | import { ethers } from "hardhat"; 4 | import { Lending } from "../../typechain-types"; 5 | import { deployMockUsdc } from "./mocks"; 6 | import { Signers } from './types'; 7 | 8 | type UnitLendingFixtureType = { 9 | lending: Lending; 10 | mockUsdc: MockContract; 11 | }; 12 | 13 | export async function getSigners(): Promise { 14 | const [deployer, alice, bob] = await ethers.getSigners(); 15 | 16 | return { deployer, alice, bob }; 17 | } 18 | 19 | export async function unitLendingFixture(): Promise { 20 | const { deployer } = await getSigners(); 21 | 22 | const lendingFactory: ContractFactory = await ethers.getContractFactory( 23 | `Lending` 24 | ); 25 | 26 | const lending: Lending = (await lendingFactory 27 | .connect(deployer) 28 | .deploy()) as Lending; 29 | 30 | await lending.deployed(); 31 | 32 | const mockUsdc = await deployMockUsdc(deployer); 33 | 34 | return { lending, mockUsdc }; 35 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Andrej 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import * as dotenv from "dotenv"; 2 | 3 | import { HardhatUserConfig } from "hardhat/config"; 4 | import "@nomicfoundation/hardhat-toolbox"; 5 | 6 | dotenv.config(); 7 | 8 | const config: HardhatUserConfig = { 9 | solidity: "0.8.17", 10 | networks: { 11 | hardhat: { 12 | hardfork: "merge", 13 | // If you want to do some forking set `enabled` to true. 14 | // It is higly recommended to set forking block number, otherwise the latest one will be used each time 15 | // which can lead into inconsistency of tests 16 | forking: { 17 | url: process.env.MAINNET_RPC_URL || "", 18 | // blockNumber: 19 | enabled: false, 20 | }, 21 | chainId: 31337, 22 | }, 23 | goerli: { 24 | url: process.env.GOERLI_RPC_URL || "", 25 | accounts: 26 | process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], 27 | }, 28 | }, 29 | etherscan: { 30 | // npx hardhat verify --network 31 | apiKey: { 32 | goerli: process.env.ETHERSCAN_API_KEY || "", 33 | }, 34 | }, 35 | }; 36 | 37 | export default config; 38 | -------------------------------------------------------------------------------- /scripts/deploy.ts: -------------------------------------------------------------------------------- 1 | // We require the Hardhat Runtime Environment explicitly here. This is optional 2 | // but useful for running the script in a standalone fashion through `node