Giter Site home page Giter Site logo

studydefi / money-legos Goto Github PK

View Code? Open in Web Editor NEW
1.0K 36.0 213.0 1.29 MB

πŸ’°One stop shop for Ethereum ABIs, addresses, and Solidity interfaces!

Home Page: https://money-legos.studydefi.com/

License: MIT License

TypeScript 36.42% JavaScript 3.39% Shell 0.30% Solidity 59.89%
ethereum money-legos defi blockchain

money-legos's Introduction

money-legos

circleci npm types minzip

legos autocomplete

Get ABIs, Addresses, and Solidity Interfaces to popular DeFi protocols

Now with Typescript-powered autocomplete!

money-legos is an NPM package that provides you with the mainnet addresses, ABIs, and Solidity interfaces for popular DeFi protocols.

Click here for docs and visit our Discord here!

Protocols supported:

  • AAVE
  • Compound
  • Curve Finance
  • DappSys
  • DyDx
  • ERC20
  • Idle V3
  • Kyber.Network
  • MakerDAO
  • OneSplit
  • UMA Protocol
  • Uniswap v1
  • Synthetix
  • Balancer
  • mStable
  • Uniswap v2

Importing specific protocols is also supported:

size

Install

npm install @studydefi/money-legos

Usage

JavaScript

import { legos } from "@studydefi/money-legos";

// access ABIs and addresses
legos.erc20.abi;
legos.erc20.dai.address;

// of many popular DeFi protocols
legos.uniswap.factory.abi;
legos.uniswap.factory.address;

// import only the protocol you are interested in
import uniswap from "@studydefi/money-legos/uniswap";

uniswap.factory.abi;
uniswap.factory.address;

Solidity

pragma solidity ^0.5.0;

import "@studydefi/money-legos/onesplit/contracts/IOneSplit.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";


contract OneSplitSwapper {
    // Uniswap Mainnet factory address
    address constant OneSplitAddress = 0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E;

    function _swap(address from, address to, uint256 amountWei) internal {
        IERC20 fromIERC20 = IERC20(from);
        IERC20 toIERC20 = IERC20(to);

        (uint256 returnAmount, uint256[] memory distribution) = IOneSplit(
            OneSplitAddress
        ).getExpectedReturn(
            fromIERC20,
            toIERC20,
            amountWei,
            10,
            0
        );

        IOneSplit(OneSplitAddress).swap(
            fromIERC20,
            toIERC20,
            amountWei,
            returnAmount,
            distribution,
            0
        );
    }
}

money-legos's People

Contributors

achiko avatar adrianmcli avatar cruzdanilo avatar dependabot[bot] avatar kendricktan avatar lieljack avatar marcelomorgado avatar nevillegrech avatar rori4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

money-legos's Issues

Make CI build docs

We need to run yarn build:docs on Zeit's build so that we can preview what happens when docs are generated.

Tests for .sol files

Hi there, I've just pushed the Kyber interface fix. I've just noticed that was wrong because I've tried to use if for a project of mine.
I think that it would be better if contract errors could be caught by a test script. Do you think that make sense to have some truffle test cases for solidity files to have they covered?

Best,

Can't access the documentation page

When visiting https://money-legos.studydefi.com/ I would get

`Secure Connection Failed

An error occurred during a connection to money-legos.studydefi.com. Peer reports it experienced an internal error.

Error code: SSL_ERROR_INTERNAL_ERROR_ALERT`

The error is on all web browsers that I tried (Chrome, Firefox).

Is there any other web page with docs?

Discussion: Better integration with MoonNet

Hi!
I'm interested to keep contributing with this project because I'm studying DeFi protocols and it's a great way to get they better, but one thing is bothering me, the time needed to run the tests, it's making my code/learning slowly since running a forked Ganache node isn't the fastest thing out there... because of that I've also get interested in the MoonNet project because it's trying to solve this issue, but actually, the performance of fork from Infura and fork from MoonNet are almost the same for me (sometimes Infura is performing better).
So, before back my contribution/studies with new protocols, I've spent some time trying to improve the time needed to run the tests and I think that I've found something (that can could also help MoonNet with their users' support):

I've started making some test rounds using the compound.test.ts test suite:

Forked from Infura: 83.418s
Forked from MoonNet: 81.527s
MoonNet (without forking): 29.596s πŸ₯‡

Based on these results, I was want to run all test suites using MoonNet without forking it. For make it possible some changes were needed because since the test suites run in parallel, all of them would run against the same node/state making some unexpected behaviors happen (e.g. mint dai in test suite A can make a dai balance assert to fail int test suite B).

The changes that I've made were:

  • Run jest without parallelism (--runInBand param);
  • Since MoonNet node is a ganache mode, we can call evm_revert and evm_snapshot methods. I've changed setup and tearDown functions to do so.

Here are the time results of running all test suites:

Forked from Infura: 462.934s
Forked from MoonNet: 499.884s
MoonNet (without forking): 89.819s πŸ₯‡

 PASS  tests/compound.test.ts (27.946s)
  compound
    βœ“ enter markets (4305ms)
    βœ“ supply 10 ETH (i.e. mint cETH) (3369ms)
    βœ“ borrow 20 DAI (4073ms)
    βœ“ supply 5 DAI (6321ms)
    βœ“ get supply/borrow balances for DAI (1313ms)
    βœ“ withdraw 1 ETH from collateral (2777ms)
    βœ“ repay 1 DAI of debt (4573ms)

 PASS  tests/aave.test.ts (25.069s)
  aave
    βœ“ lend 10 ETH (i.e. mint aETH) (3740ms)
    βœ“ borrow 20 DAI (5788ms)
    βœ“ lend 5 DAI (5001ms)
    βœ“ get supply/borrow balances for DAI (829ms)
    βœ“ withdraw 1 ETH from collateral (3035ms)
    βœ“ repay 1 DAI of debt (4147ms)
    βœ“ retrieve current health factor (1611ms)

 PASS  tests/kyber.test.ts (10.473s)
  kyber
    βœ“ buy DAI from Kyber.Network (9542ms)

 PASS  tests/maker.test.ts (9.424s)
  maker
    βœ“ create a proxy on Maker (2883ms)
    βœ“ open Vault on Maker (5783ms)

 PASS  tests/uniswap.test.ts (7.456s)
  uniswap
    βœ“ buy DAI from Uniswap (6689ms)

 PASS  tests/index.test.ts
  initial conditions
    βœ“ initial DAI balance of 0 (1255ms)
    βœ“ initial ETH balance of 1000 ETH (551ms)

 PASS  tests/medianizer.test.ts
  maker medianizer
    βœ“ read ETH price from medianizer (1181ms)

Test Suites: 7 passed, 7 total
Tests:       21 passed, 21 total
Snapshots:   0 total
Time:        89.819s

Some notes:

  • It's less "safe" than fork since the MoonNet node can remain with the changed state after the jest process;
  • Keep the parallelism would be ideal but I think that the most important thing is to get the tests running much faster as possible right?
  • If the coming buidler fork feature is more performatic than the ganache no change would be needed (Do you have some info about it?).
  • For now, it's a discovery/PoC, this way of running tests should be more battle-tested.

WDTY @adrianmcli @kendricktan?

Add AAVE lending and borrowing

We have docs for flash loans but nothing for lending and borrowing. And currently we have no AAVE-related tests at all.

This also means it would be a good idea to add the ERC20 tokens that AAVE supports as well: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances

Asks

  • Write test for flash loans on AAVE
  • Write test for lending on AAVE
  • Write test for borrowing on AAVE
  • Update doc with test snippets from above
  • Add extra ERC20 token addresses (and decimals and ABI where necessary)

Fix Synthetix Test

@marcelomorgado I prematurely merged your PR into master by accident. I haven't done a release yet because there's still an issue.

One of the Synthetix tests are failing:

Screen Shot 2020-06-23 at 11 46 26 PM

@marcelomorgado Can you fix this and make a new PR?

Integration with etherscan and web3.js?

Hi All,

Love the idea of this repo, has the potential to be super convenient for a lot of web3 developers.

Have you thought about retrieving all the defined contracts from etherscan and feeding them into your library?

This would also make sense as an add on to web3.js because you could fiddle with the known contracts while also having the capacity to call upon them as web3 contract objects.

Add the ability to sign ABI's/contract addresses with the contract deployer key or SSL certificate

The included contracts in this repo rely on trust, namely that the ABI and contract address actually match the correct contracts and not a scam contract.

While you are able to self-curate some contracts in this library by hand, this approach cannot scale for when there are many different contracts from many different authors.

Do you think it would be wise to add a feature which allows you to add your own contract to legos, with the underlying contract object (ABI + contract address) being canonicalised and signed by a valid authority such as the contract deployer or the SSL certificate of the contract issuer e.g. makerdao.cdp.com?

aave LendingPoolAddressProvider

in javascript i tried to instantiate LendingPoolAddressProvider SC. There is a small mistake, the 'r', is missing in the abi file name, so to ge the abi you need to type LendingPoolAddessProvider, instead, but even after corection i it says undefined, i have the same issue xith AToken but no pb with the others abi LendingPoolcore, LendingPool , why?? here is my code

const aave = require ('@studydefi/money-legos/aave');
const lpAddressProviderContract = new web3.eth.Contract(aave.LendingPoolAddessProvider.abi,, aave.LendingPoolAddessProvider.address);

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.