Git Product home page Git Product logo

token-fund's Introduction

Token Fund.

This project implements an Governable TokenFund smart contract, with the implementation of Uniswap and Sushiswap DEXes where:

  • Users can deposit USDT or USDC.
  • Contract will swap these assets 50% to LINK and 50% to WETH with the best price available between Uniswap and Sushiswap.
  • Contract will mint fund tokens to the user who deposited, which will represent the share in the LINK and WETH asset pool.
  • Contract will use these LINK and WETH tokens to gain a profit.
  • On the user withdrawal, the tokens allocated for the user will be calculated by the shares, swapped to USDT or USDC and transferred back to user.
  • If the contract made some profit on the user's deposit, contract will take 10% of the profit.

The development tool used is the Foundry where everything is written including the tests and the scripts.

Table of Contents

Features

  • depositUSDC - Users can deposit USDC by calling this function. Contract will then find the best price to swap it 50%-50% and WETH and LINK, swap it and mint the shares token to the user to represent his shares in the LINK and WETH asset pool.

  • depositUSDT - Users can deposit USDT by calling this function. Contract will then find the best price to swap it 50%-50% and WETH and LINK, swap it and mint the shares token to the user to represent his shares in the LINK and WETH asset pool.

The 2 functions above are separated. It could have been done in one function but then the extra check would have been needed. So by this implementation, yes I increase the gas cost of the contract deployment, but from the user perspective gas costs will be cheaper.

  • withdrawUSDC - Users can withdraw all their funds from the contract by calling this function. The LINK and WETH allocation for them will be calculate by their number of shares (formula is the same as in calculation of shares when providing/removing liquidity in AMM). LINK and WETH will be swapped to USDC for the best price and transferred to user. If the contract made some profits on users funds, it will take 10% profit fee.

  • withdrawUSDT - Users can withdraw all their funds from the contract by calling this function. The LINK and WETH allocation for them will be calculate by their number of shares (formula is the same as in calculation of shares when providing/removing liquidity in AMM). LINK and WETH will be swapped to USDT for the best price and transferred to user. If the contract made some profits on users funds, it will take 10% profit fee.

The same goes for the 2 functions above. By this implementation, yes I increase the gas cost of the contract deployment, but from the user perspective gas costs will be cheaper.

  • withdrawProfits - This is the admins (deployer's) function to withdraw all the profits from the contracts.

  • mintShares - This internal function calculates amount of shares that should be given to user based on their provided assets and the existing assets. The formula used here is the same as in calculation of shares when providing/removing liquidity in AMM

  • timeLockFunction - DEMONSTRATIONAL PURPOSES FUNCTION. This function can be called by the TimeLock to demonstrate the governance functionality.

  • swapForBestPrice - This internal function takes the list of tokens for the swap and checks the swap prices for the Uniswap and the Sushiswap. Add then swaps the tokens for the best prices.

Testing

Tests are written to cover as many scenarios as possible, but still, it's not enough for production. This should never happen in production-ready code!

To run the tests, you will have to do the following

IMPORTANT1: You will have to test it on Mainnet fork as the token/contract addresses used in tests are mainnet addresses. IMPORTANT2: Please make sure you specify the block number 18032971 as a fork block number. This will make sure the Governance tests are passing correctly.

  1. Clone this repository to your local machine.
  2. Run forge install.
  3. Run forge build.
  4. Run forge test --fork-block-number 18032971 --fork-url {MAINNET_RPC_URL}.

OR, you can just run forge test --fork-block-number 18032971 --fork-url {MAINNET_RPC_URL}, which will automatically install dependencies and compile the contracts.

Deploying

To deploy the smart contract do the following:

  1. Update the variables in files of the script/ folder to your needs.
  2. Deploy the smart contract with forge script script/TokenFund.s.sol --fork-url {RPC_URL} --broadcast

To deploy the smart contract locally you can run:

  1. anvil to run a local node.

And then follow the 2 steps above and replace {RPC_URL} in step2 with http://localhost:8545

Read More About the Deployment from the Foundry Book

token-fund's People

Contributors

nikakhachi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.