This project demonstrates interaction with yearn contract on mainnet.
Currently the following is demonstrated:
- Forking off Mainnet with Ganache
- Forking off of a fork of Mainnet to run tests in parallel (thanks to Jest)
- Checking token prices in DAI with Uniswap's on-chain contracts
- Swapping ETH for DAI from Uniswap
- Invest DAI in yearn contract by approving tokens and calling the custom
enter (uint256 amount)
function. User would receive the equivalent yDAI tokens in their wallet - Exit position by depositing back yDai calling the
exit (uint256 amount)
function, Now, user would receive DAI back in their wallet
-
Clone the repo or
npx truffle unbox defi
-
Run
npm install
-
Create a
.env
file with the following contents:MAINNET_NODE_URL=https://mainnet.infura.io/v3/<API_KEY_HERE> PRIV_KEY_TEST=<some private key> PRIV_KEY_DEPLOY=<some other private key>
- Get an API key from: https://infura.io/
- Both of the private keys can be any private key you choose:
PRIV_KEY_DEPLOY
refers to an account specifically for deployingPRIV_KEY_TEST
refers to an account specifically for testing
-
Run
npm start
to start a local Ganache chain with forked Mainnet state -
Run
npm run migrate
in order to compile and migrate the project's contracts to this local Ganache chain -
Run
npm test
in order to run the tests.- Each test suite will fork off the local Ganache instance (yes, it's a fork of a fork) and create its own Ganache instance in-memory. This is to prevent out-of-order nonce issues since our tests are run in parallel by Jest.
Some information about the test chains:
-
./tests/utils/test-chain.js
starts a test chain exposed athttp://127.0.0.1:8545
and our contracts need to be migrated to it withtruffle migrate
(or thenpm run migrate
script). -
./tests/utils/test-environment.js
is instantiated for each and every test suite (i.e. test file in our case). It makes another Ganache instance in-memory that is forked off the local test-chain athttp://127.0.0.1:8545
UniswapLiteBase.sol
utilizes the interface contracts: IUniswapExchange.sol
and IUniswapFactory.sol
in order to provide more convenient internal functions.
MyDapp.sol
then inherits from UniswapLiteBase.sol
to expose convenient outward facing contract functions.