This repo is dedicated to making minimal repos of existing defi primatives.

Overview

Defi Minimal

This repo is dedicated to making minimal repos of existing defi primatives.

WARNING WARNING: None of the contracts are audited! WARNING

Completed (but unreviewed) minimal contracts:

  • Lending.sol: Based off Aave
  • Staking.sol: Based off Synthetix
  • RewardToken.sol: Based off Synthetix
  • Exchange.sol , Factory.sol , Token.sol : Based off Uniswap v1. The used pricing formula is documented here

Uncompleted:

  • Options.sol: Based off nothing

Not a minimal contract:

Table Of Contents

Getting Started

It's recommended that you've gone through the hardhat getting started documentation before proceeding here.

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • Nodejs
    • You'll know you've installed nodejs right if you can run:
      • node --versionand get an ouput like: vx.x.x
  • Yarn instead of npm
    • You'll know you've installed yarn right if you can run:
      • yarn --version And get an output like: x.x.x
      • You might need to install it with npm

If you're familiar with npx and npm instead of yarn, you can use npx for execution and npm for installing dependencies.

Quickstart

  1. Clone and install dependencies

After installing all the requirements, run the following:

git clone https://github.com/smartcontractkit/defi-minimal/
cd defi-minimal

Then:

yarn

or

npm i
  1. You can now do stuff!
yarn hardhat test

or

npx hardhat test

Usage

If you run yarn hardhat --help you'll get an output of all the tasks you can run.

Deploying Contracts

yarn hardhat deploy

This 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.

Run a Local Network

One 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:

yarn hardhat node

You'll get a local blockchain, private keys, contracts deployed (from the deploy folder scripts), and an endpoint to potentially add to an EVM wallet.

Using a Testnet or Live Network (like Mainnet or Polygon)

In your hardhat.config.js you'll see section like:

module.exports = {
  defaultNetwork: "hardhat",
  networks: {

This 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.

To interact with a live or test network, you'll need:

  1. An rpc URL
  2. A Private Key
  3. ETH & LINK token (either testnet or real)

Let's look at an example of setting these up using the Rinkeby testnet.

Rinkeby Ethereum Testnet Setup

First, 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 from the linked twilio blog. You'll find a sample of what this file will look like in .env.example

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.

  1. Set your RINKEBY_RPC_URL environment variable.

You can get one for free from Alchmey, Infura, or Moralis. This is your connection to the blockchain.

  1. Set your PRIVATE_KEY environment variable.

This is your private key from your wallet, ie MetaMask. 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.

WARNING WARNING WARNING

When 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.

Don'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!

.env example:

RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'
PRIVATE_KEY='abcdef'

bash example

export RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'
export PRIVATE_KEY='abcdef'

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.

For 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.

  1. Get some Rinkeby Testnet ETH and LINK

Head over to the Chainlink faucets and get some ETH and LINK. Please follow the chainlink documentation if unfamiliar.

Code Formating

This will format both your javascript and solidity to look nicer.

yarn format

Slither Static Analysis

You have to do a few steps for slither since right now multiple imports are not supported. First, you'll have to copy paste any non opennzepplin imports into the contracts, and then you should be able to run this:

slither ./contracts/ --solc-remaps @openzeppelin/contracts=./node_modules/@openzeppelin/contracts --exclude naming-convention

Contributing

Contributions are always welcome! Open a PR or an issue!

Thank You!

Resources

Comments
  • use dai for staking token

    use dai for staking token

    It is confusing that the staking.test.js has the DAI ERC20 variable, but DAI is actually not used in Staking. Currently staking and reward tokens are the same.

    This pull request uses DAI as the staked token.

    I used

    const rewardToken = await ethers.getContract("RewardToken") instead of const rewardToken = await deployments.get("RewardToken")

    because otherwise the deployemnt failed with unknown function rewardToken.approve

    opened by tonisives 6
  • Options.sol

    Options.sol

    What are your plans for Options.sol? Do plan to include reference to an underlying like ETH/USD? How do you plan to offer different trading types (long call, short put, etc.)?

    If you give a little direction on what you envisioned, I wouldn't mind working on this :)

    opened by TobiasBK 4
  • Basic options contract and test file

    Basic options contract and test file

    Basic options contract that allows for covered calls and puts. The underlying is ETH and the payment is in DAI. This is a work in progress. I wanted to share what I had so far. I haven't written any test yet, will do in the next few days. Let me know what you think.

    opened by TobiasBK 3
  • Replaced msg.sender with _msgSender() in burn() function in CentralizedStableCoin.sol

    Replaced msg.sender with _msgSender() in burn() function in CentralizedStableCoin.sol

    In the original ERC20Burnable Openzeppelin Standard, _msgSender() is passed to _burn() function instead of msg.sender for meta transactions cases. Did the changes

    opened by proxima424 2
  • Uniswap v1

    Uniswap v1

    Hello,

    I can take care of implementing a minimal version of uniswap v1. Found several nice and detailed examples online so I can give it a try. We can have:

    • Factory to create several exchanges
    • Exchange contract (ETH vs ERC20 Token):
      • Add liquidity
      • Get Reserve of token
      • Get current price of token ( constant product formula)
      • Buy / sell token (swap functions - including fees)
      • Manage liquidity tokens
    in progress 
    opened by aelmanaa 2
  • Bancor v1 - bonding curve

    Bancor v1 - bonding curve

    some references

    http://coders-errand.com/token_bonding_curves/

    https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5

    https://billyrennekamp.medium.com/converting-between-bancor-and-bonding-curve-price-formulas-9c11309062f5

    legacy project communauty example formula

    in progress 
    opened by aelmanaa 0
Releases(0.0.1)
  • 0.0.1(Aug 14, 2022)

    What's Changed

    • Basic options contract and test file by @TobiasBK in https://github.com/smartcontractkit/defi-minimal/pull/3
    • Add Uniswap v1 with LP implementation by @aelmanaa in https://github.com/smartcontractkit/defi-minimal/pull/4
    • remove unused dai variable by @tonisives in https://github.com/smartcontractkit/defi-minimal/pull/7
    • Stablecoins by @PatrickAlphaC in https://github.com/smartcontractkit/defi-minimal/pull/8

    New Contributors

    • @TobiasBK made their first contribution in https://github.com/smartcontractkit/defi-minimal/pull/3
    • @aelmanaa made their first contribution in https://github.com/smartcontractkit/defi-minimal/pull/4
    • @tonisives made their first contribution in https://github.com/smartcontractkit/defi-minimal/pull/7
    • @PatrickAlphaC made their first contribution in https://github.com/smartcontractkit/defi-minimal/pull/8

    Full Changelog: https://github.com/smartcontractkit/defi-minimal/commits/0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
SmartContract
SmartContract
Save your favorite GitHub Repos/Profiles Live

Save your favorite GitHub Repos/Profiles Live Getting Started by Fork and clone this repository or simply git clone https://github.com/ttran293/useful

Thanh Nam Tran 3 May 2, 2022
🦀 A browser extension to explore rust cargo dependencies on GitHub repos

cratehub On every GitHub repository or folder with a Cargo.toml file, scroll to the bottom of the page to see a list of its npm dependencies and their

一块木头 23 Aug 10, 2022
A web scraping / data mining script for extracting beginner-friendly github repos from Y Combinator's company database

A web scraping / data mining script for extracting beginner-friendly github repos from Y Combinator's company database

Oscar Mier 27 Nov 24, 2022
The repos includes script for uploading bulk files in a directory to ipfs using nft.storage

Uploading Foloder to IPFS using nft.storage This repository includes script for uploading bulk files in a directory to ipfs using nft.storage Acknowle

Dapp Composer 22 Dec 17, 2022
Sell access to your GitHub repos using Gumroad.

GitCash Sell access to your GitHub repos using Gumroad. Documentation Visit the GitCash documentation for detailed documentation on how to set up your

Ronald Blüthl 7 Nov 1, 2022
A utility for cloning all your repos, including issues, discussions, stargazers and more!

github-takeout A utility for cloning all your repos, including issues, discussions, stargazers and more! The tool gives you the ability to download a

Lukas Bach 5 Oct 26, 2022
Components and tools for building DeFi dapps on Solana + Anchor. Public domain license.

Solana DeFi Framework Components and tools for building DeFi dapps on Solana + Anchor. Public domain license. Status Pre-pre-pre-alpha. Contributing A

null 4 Mar 28, 2022
Squeeth is a new financial primitive in DeFi that gives traders exposure to ETH²

Squeeth Monorepo The Squeethiest ?? ?? What is Squeeth The squeeth contract is designed for users to long or short a special index: Eth², as an implem

Opyn 156 Jan 4, 2023
Transaction tracker for Defi Kingdoms and more!

DFK Balances DFK Balances is a super customizable and extensible Financial tracker for the DeFi Kingdoms ecosystem. It allows users to easily add thei

Gabriel Guimaraes 9 Feb 22, 2022
A comprehensive collection of useful tools developed with the help of Ethers.js to interact with the Ethereum Blockchain to develop great DeFi apps as quickly and easily as possible.

hudi-packages-ethersfactory How to install Installing with npm For more information on using npm check out the docs here. npm i @humandataincome/ether

HUDI 6 Mar 30, 2022
🏦 Defi Bank is a dapp created for ethereum 101 course of cadena.dev

Welcome to DefiBank ?? Defi Bank is a dapp created for ethereum 101 course of cadena.dev ✨ Demo Install npm install Usage npm run dev Tech NextJS Reac

Alberto Cruz Luis 7 Nov 21, 2022
In this repository, I try to perform a mainnet fork and then simulate popular smart contract exploits on various DEFI Protocols using Hardhat Framework.

defiHacks_via_Hardhat 1. Alchemix Access Control Bug Any user could have called setWhitelist() to give an attacker the ability to call the harvest fun

null 34 Dec 27, 2022
Multi-chain defi crypto sniper written in typescript/javascript. Fastest method of sniping with auto-sell and rug prevention features.

CryptoSniper Community Edition Multi-chain defi crypto sniper written in typescript/javascript. Fastest method of sniping with auto-sell and rug preve

null 18 Nov 3, 2022
A Stacks DeFi app that automates covered call writing to generate sustainable, risk-adjusted yield.

?? Options Vault ?? A Stacks DeFi app that automates covered call writing to generate sustainable, risk-adjusted yield. Options vaults allow you to al

null 15 Nov 16, 2022
4Web is a collection&creation of codebase, frameworks, libraries dedicated to web development 📦

?? You can also contribute to add / create your own collection in this repository Collection name Description ?? blinke

Raja Rakotonirina 5 Nov 14, 2022
This website is dedicated to be able to store books, add new books and delete books.

awesome-books This is a book shelve website dedicated to store collection of books, add new books and delete books. In this project, you will be using

Okoroji Victor Ebube 11 Jul 4, 2022
A dedicated desktop app that enables you to move items in and out of storage units in CSGO.

CASEMOVE Casemove is an open-source desktop application that helps you easily move items out of and into Storage Units in Counter-Strike: Global Offen

null 161 Dec 24, 2022
Jugglr is a tool for managing test data and running tests with a dedicated database running in a Docker container.

Jugglr Jugglr is a tool for managing test data and running tests with a lightweight, dedicated database. Jugglr enables developers, testers, and CI/CD

OSLabs Beta 74 Aug 20, 2022