{"id":13631035,"url":"https://github.com/smartcontractkit/defi-minimal","last_synced_at":"2025-04-05T03:11:33.219Z","repository":{"id":39580967,"uuid":"471534015","full_name":"smartcontractkit/defi-minimal","owner":"smartcontractkit","description":"This repo is dedicated to making minimal repos of existing defi primatives.","archived":false,"fork":false,"pushed_at":"2022-10-18T22:32:58.000Z","size":714,"stargazers_count":481,"open_issues_count":4,"forks_count":111,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-03-29T02:08:24.607Z","etag":null,"topics":["blockchain","defi","web3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartcontractkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-18T22:29:43.000Z","updated_at":"2025-03-28T17:14:11.000Z","dependencies_parsed_at":"2023-01-19T17:16:46.091Z","dependency_job_id":null,"html_url":"https://github.com/smartcontractkit/defi-minimal","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fdefi-minimal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fdefi-minimal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fdefi-minimal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartcontractkit%2Fdefi-minimal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartcontractkit","download_url":"https://codeload.github.com/smartcontractkit/defi-minimal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","defi","web3"],"created_at":"2024-08-01T22:02:07.980Z","updated_at":"2025-04-05T03:11:33.199Z","avatar_url":"https://github.com/smartcontractkit.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Defi Minimal\n\nThis repo is dedicated to making minimal repos of existing defi primatives. \n\n\n| :exclamation:  ** WARNING None of the contracts are audited!  |\n|-----------------------------------------|\n\n### Completed (but unreviewed) minimal contracts:\n- `Lending.sol`: Based off [Aave](https://aave.com/)\n- `Staking.sol`: Based off [Synthetix](https://synthetix.io/)\n- `RewardToken.sol`: Based off [Synthetix](https://synthetix.io/)\n- `Exchange.sol` , `Factory.sol` , `Token.sol` : Based off [Uniswap v1](https://docs.uniswap.org/protocol/V1/introduction). The used pricing formula is documented [here](./docs/uniswap-v1/)\n- `DecentralizedStableCoin`: Based off DAI\n- `CentralizedStableCoin`: Based off USDC\n\n### Uncompleted:\n- `Options.sol`: Based off nothing\n\n### Not a minimal contract:\n- `Swap.sol`: Based off [Uniswap](https://uniswap.org/) - shows how a smart contract can integrate with a Uniswap-like dex. \n\n# Table Of Contents\n- [Defi Minimal](#defi-minimal)\n    - [Completed (but unreviewed) minimal contracts:](#completed-but-unreviewed-minimal-contracts)\n    - [Uncompleted:](#uncompleted)\n    - [Not a minimal contract:](#not-a-minimal-contract)\n- [Table Of Contents](#table-of-contents)\n- [Getting Started](#getting-started)\n  - [Requirements](#requirements)\n  - [Quickstart](#quickstart)\n- [Usage](#usage)\n  - [Deploying Contracts](#deploying-contracts)\n  - [Run a Local Network](#run-a-local-network)\n  - [Using a Testnet or Live Network (like Mainnet or Polygon)](#using-a-testnet-or-live-network-like-mainnet-or-polygon)\n    - [Rinkeby Ethereum Testnet Setup](#rinkeby-ethereum-testnet-setup)\n- [Code Formating](#code-formating)\n- [Slither Static Analysis](#slither-static-analysis)\n- [Contributing](#contributing)\n- [Thank You!](#thank-you)\n- [Resources](#resources)\n\n\n# Getting Started \n\nIt's recommended that you've gone through the [hardhat getting started documentation](https://hardhat.org/getting-started/) before proceeding here. \n\n## Requirements\n\n- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)\n  - You'll know you did it right if you can run `git --version` and you see a response like `git version x.x.x`\n- [Nodejs](https://nodejs.org/en/)\n  - You'll know you've installed nodejs right if you can run:\n    - `node --version`and get an ouput like: `vx.x.x`\n- [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/) instead of `npm`\n  - You'll know you've installed yarn right if you can run:\n    - `yarn --version` And get an output like: `x.x.x`\n    - You might need to install it with npm\n\n\u003e If you're familiar with `npx` and `npm` instead of `yarn`, you can use `npx` for execution and `npm` for installing dependencies. \n\n## Quickstart\n\n1. Clone and install dependencies\n\nAfter installing all the requirements, run the following:\n\n```bash\ngit clone https://github.com/smartcontractkit/defi-minimal/\ncd defi-minimal\n```\nThen:\n```\nyarn\n```\n\nor\n```\nnpm i\n```\n\n2. You can now do stuff!\n\n```\nyarn hardhat test\n```\n\nor\n\n```\nnpx hardhat test\n```\n\n\n# Usage\n\nIf you run `yarn hardhat --help` you'll get an output of all the tasks you can run. \n\n## Deploying Contracts\n\n```\nyarn hardhat deploy\n```\n\nThis will deploy your contracts to a local network. Additionally, if on a local network, it will deploy mock Chainlink contracts for you to interact with. If you'd like to interact with your deployed contracts, skip down to [Interacting with Deployed Contracts](#interacting-with-deployed-contracts).\n\n## Run a Local Network\n\nOne of the best ways to test and interact with smart contracts is with a local network. To run a local network with all your contracts in it, run the following:\n\n```\nyarn hardhat node\n```\n\nYou'll get a local blockchain, private keys, contracts deployed (from the `deploy` folder scripts), and an endpoint to potentially add to an EVM wallet. \n\n\n## Using a Testnet or Live Network (like Mainnet or Polygon)\n\nIn your `hardhat.config.js` you'll see section like:\n\n```\nmodule.exports = {\n  defaultNetwork: \"hardhat\",\n  networks: {\n```\n\nThis section of the file is where you define which networks you want to interact with. You can read more about that whole file in the [hardhat documentation.](https://hardhat.org/config/)\n\nTo interact with a live or test network, you'll need:\n\n1. An rpc URL \n2. A Private Key\n3. ETH \u0026 LINK token (either testnet or real)\n\nLet's look at an example of setting these up using the Rinkeby testnet. \n\n### Rinkeby Ethereum Testnet Setup\n\nFirst, we will need to set environment variables. We can do so by setting them in our `.env` file (create it if it's not there). You can also read more about [environment variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html) from the linked twilio blog. You'll find a sample of what this file will look like in `.env.example`\n\n\u003e IMPORTANT: MAKE SURE YOU'D DONT EXPOSE THE KEYS YOU PUT IN THIS `.env` FILE. By that, I mean don't push them to a public repo, and please try to keep them keys you use in development not associated with any real funds. \n\n1. Set your `RINKEBY_RPC_URL` [environment variable.](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html)\n\nYou can get one for free from [Alchmey](https://www.alchemy.com/), [Infura](https://infura.io/), or [Moralis](https://moralis.io/speedy-nodes/). This is your connection to the blockchain. \n\n2. Set your `PRIVATE_KEY` environment variable. \n\nThis is your private key from your wallet, ie [MetaMask](https://metamask.io/). This is needed for deploying contracts to public networks. You can optionally set your `MNEMONIC` environment variable instead with some changes to the `hardhat.config.js`.\n\n![WARNING](https://via.placeholder.com/15/f03c15/000000?text=+) **WARNING** ![WARNING](https://via.placeholder.com/15/f03c15/000000?text=+)\n\nWhen developing, it's best practice to use a Metamask that isn't associated with any real money. A good way to do this is to make a new browser profile (on Chrome, Brave, Firefox, etc) and install Metamask on that brower, and never send this wallet money.  \n\nDon't commit and push any changes to .env files that may contain sensitive information, such as a private key! If this information reaches a public GitHub repository, someone can use it to check if you have any Mainnet funds in that wallet address, and steal them!\n\n`.env` example:\n```\nRINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'\nPRIVATE_KEY='abcdef'\n```\n`bash` example\n```\nexport RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'\nexport PRIVATE_KEY='abcdef'\n```\n\n\u003e You can also use a `MNEMONIC` instead of a `PRIVATE_KEY` environment variable by uncommenting the section in the `hardhat.config.js`, and commenting out the `PRIVATE_KEY` line. However this is not recommended. \n\nFor other networks like mainnet and polygon, you can use different environment variables for your RPC URL and your private key. See the `hardhat.config.js` to learn more. \n\n3. Get some Rinkeby Testnet ETH and LINK \n\nHead over to the [Chainlink faucets](https://faucets.chain.link/) and get some ETH and LINK. Please follow [the chainlink documentation](https://docs.chain.link/docs/acquire-link/) if unfamiliar. \n\n# Code Formating\n\nThis will format both your javascript and solidity to look nicer. \n\n```\nyarn format\n```\n\n# Slither Static Analysis\n\nYou'll need [python](https://www.python.org/downloads/) and [slither](https://github.com/crytic/slither) installed. \n\n```\nyarn slither\n```\n\n# Contributing\n\nContributions are always welcome! Open a PR or an issue!\n\n# Thank You!\n\n# Resources\n\n- [Chainlink Documentation](https://docs.chain.link/)\n- [Hardhat Documentation](https://hardhat.org/getting-started/)\n- [Solidity by Example](https://solidity-by-example.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartcontractkit%2Fdefi-minimal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartcontractkit%2Fdefi-minimal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartcontractkit%2Fdefi-minimal/lists"}