All Projects → zeriontech → Defi Sdk

zeriontech / Defi Sdk

Licence: lgpl-3.0
DeFi SDK Makes Money Lego Work

Programming Languages

solidity
1140 projects

Projects that are alternatives of or similar to Defi Sdk

Yieldfarming
🧑‍🌾 It ain't much, but it's an honest work
Stars: ✭ 235 (-46.59%)
Mutual labels:  ethereum, curve, balancer
React Ethereum Dapp Example
A starter boilerplate for an Ethereum dapp using web3.js v1.0, truffle, react, and parity
Stars: ✭ 384 (-12.73%)
Mutual labels:  ethereum, truffle
Sparkle Proof Of Loyalty
Sparkle Proof of Loyalty Contract
Stars: ✭ 216 (-50.91%)
Mutual labels:  ethereum, truffle
Truffle Flattener
Truffle Flattener concats solidity files from Truffle and Buidler projects with all of their dependencies
Stars: ✭ 254 (-42.27%)
Mutual labels:  ethereum, truffle
Angular Truffle Starter Dapp
Angular CLI + Truffle Starter Dapp; write, compile & deploy smart contracts on Ethereum blockchains
Stars: ✭ 174 (-60.45%)
Mutual labels:  ethereum, truffle
Armors Solidity
Armors-solidity is a framework to build secure smart contracts on Ethereum.
Stars: ✭ 184 (-58.18%)
Mutual labels:  ethereum, truffle
Ganache
A tool for creating a local blockchain for fast Ethereum development.
Stars: ✭ 1,028 (+133.64%)
Mutual labels:  ethereum, truffle
Eth Crypto
Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
Stars: ✭ 420 (-4.55%)
Mutual labels:  ethereum, truffle
Love Ethereum
区块链学习
Stars: ✭ 323 (-26.59%)
Mutual labels:  ethereum, truffle
0xdeca10b
Sharing Updatable Models (SUM) on Blockchain
Stars: ✭ 285 (-35.23%)
Mutual labels:  ethereum, truffle
React Auth Box
Truffle, Webpack, React, Redux boilerplate with routing and authentication via a smart contract.
Stars: ✭ 172 (-60.91%)
Mutual labels:  ethereum, truffle
Eth Gas Reporter
Gas usage per unit test. Average gas usage per method. A mocha reporter.
Stars: ✭ 330 (-25%)
Mutual labels:  ethereum, truffle
Eth Vue
Featured in Awesome Vue [https://github.com/vuejs/awesome-vue], a curated list maintained by vuejs of awesome things related to the Vue.js framework, and Awesome List [https://awesomelists.net/150-Vue.js/3863-Open+Source/18749-DOkwufulueze-eth-vue], this Truffle Box provides everything you need to quickly build Ethereum dApps that have authentication features with vue, including configuration for easy deployment to the Ropsten Network. It's also Gravatar-enabled. Connecting to a running Ganache blockchain network from Truffle is also possible -- for fast development and testing purposes. Built on Truffle 5 and Vue 3, eth-vue uses vuex for state management, vuex-persist for local storage of app state, and vue-router for routing. Authentication functionalities are handled by Smart Contracts running on the Ethereum blockchain.
Stars: ✭ 171 (-61.14%)
Mutual labels:  ethereum, truffle
Erc20 Generator
Create an ERC20 Token for FREE in less than a minute with the most used Smart Contract Generator for ERC20 Token. No login. No setup. No coding required.
Stars: ✭ 202 (-54.09%)
Mutual labels:  ethereum, truffle
Sablier
The protocol for real-time finance on the Ethereum blockchain
Stars: ✭ 147 (-66.59%)
Mutual labels:  ethereum, truffle
Truffle Plugin Verify
✅ Verify your smart contracts on Etherscan from the Truffle CLI
Stars: ✭ 144 (-67.27%)
Mutual labels:  ethereum, truffle
Truffle Assertions
🛠 Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
Stars: ✭ 109 (-75.23%)
Mutual labels:  ethereum, truffle
Truffle Next
🛰️ A boilerplate Truffle Box project with Next.js for rapid Ethereum Dapp development
Stars: ✭ 130 (-70.45%)
Mutual labels:  ethereum, truffle
Solidity Idiosyncrasies
Solidity gotchas, pitfalls, limitations, and idiosyncrasies.
Stars: ✭ 267 (-39.32%)
Mutual labels:  ethereum, truffle
Truffle eth class2
Stars: ✭ 330 (-25%)
Mutual labels:  ethereum, truffle

Build status Test status Coverage status Lint status License Discord Twitter Follow

DeFi SDK is an open-source system of smart contracts designed for precise DeFi portfolio accounting. To put it simply, DeFi SDK is the on-chain balanceOf for DeFi protocols.

If you have any questions about DeFi SDK, feel free to reach out to us on our Discord server.

Features

💥Query user assets and debt deposited in DeFi protocols like Maker, Aave, dYdX, etc.

How much debt does 0xdead..beef have on Compound?

📊Get the underlying components of complex derivative ERC20 tokens

How much cUSDC vs ETH does ETHMACOAPY have?

✨Interact with multiple DeFi protocols in a unified way (coming soon)

See What’s next for DeFi SDK

Table of Contents

Examples

Fetch Compound debt and collateral

As of now, to get all cTokens along with a user's debt on Compound you need to perform over 10 calls to the Ethereum node to different contracts or rely on a centralized API. With DeFi SDK, you can call

getProtocolBalances('0xdead...beef', ['Compound'])

on the api.zerion.eth smart contract and get all borrowed and supplied tokens

[{
  metadata: {
    name: 'Compound',
    description: 'Decentralized Lending & Borrowing Protocol',
    websiteURL: 'compound.finance',
    iconURL: 'protocol-icons.s3.amazonaws.com/compound.png',
    version: '0'
  },
  adapterBalances: [{
    metadata: {
      adapterAddress: '0x90F0Ed76cfCf75Ccab31A9b4E51782F230aA0747',
      adapterType: 'Asset'
    },
    balances: [{
      base: {
        metadata: {
          token: '0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E',
          name: 'Compound Basic Attention Token',
          symbol: 'cBAT',
          decimals: '8'
        },
        amount: '314159265'
      },
      underlying: [{
        metadata: {
          token: '0x0D8775F648430679A709E98d2b0Cb6250d2887EF',
          name: 'Basic Attention Token',
          symbol: 'BAT',
          decimals: '18'
        },
        amount: '6626070040000000000'
      }]
    }]
  },{
      metadata: {
        adapterAddress: '0xD0646777520Aff625F976a8D81b95B5B42cDa1B9',
        adapterType: 'Debt'
      },
      balances: [{
        base: {
          metadata: {
            token: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
            name: 'Dai Stablecoin',
            symbol: 'DAI',
            decimals: '18'
          },
          amount: '1971081500000000000'
        },
        underlying: []
      }]
    }
  ]
}]

Make sense of tokens like UNI-V1 ETH-cDAI

Sometimes, a DeFi token contains several other tokens, and to calculate their price, you need to know their underlying assets. For example, a Uniswap V1 cDAI pool consists of ETH and cDAI. cDAI, in turn, has DAI as an underlying token. With DeFi SDK you can call

// Uniswap V1 cDAI pool
getFinalFullTokenBalance('0x34E89740adF97C3A9D3f63Cc2cE4a914382c230b', "Uniswap V1 Pool Token")

and fetch the decomposition of UNI-token into ERC20 tokens, like ETH and DAI

0.98 ETH
215.6 DAI

Get account balances across all supported DeFi protocols

In case you want to get account balances across all supported DeFi protocols, you can call

// bankless.zerion.eth portfolio 
getBalances('0x0ef51b7dac3933b8109482e7d910c21848e45da0f') 

and obtain all balances for a given account. The response from the smart-contract will contain information about each of the protocols

100 DAI // collateral on Compound
0.1 ETH // debt on Compound
100 USDC // locked in PoolTogether
213 TUSD + 201 USDC + 82 USDT + 11 DAI // Curve Y Pool
...

DeFi SDK Architecture

  • ProtocolAdapter is a special contract for every protocol. Its main purpose is to wrap all the protocol interactions. There are different types of protocol adapters: "Asset" adapter returns the amount of the account's tokens held on the protocol and the "Debt" adapter returns the amount of the account's debt to the protocol. Some protocols do not use "simple" ERC20 tokens but instead have complex derivatives, for example the Compound protocol has CTokens. The ProtocolAdapter contract also provides information about the type of tokens used within it.
  • TokenAdapter is a contract for every derivative token type (e.g cTokens, aTokens, yTokens, etc.) Its main purpose is to provide ERC20-style token metadata as well as information about the underlying ERC20 tokens (like DAI for cDAI). Namely, it provides addresses, types and rates of underlying tokens.
  • AdapterRegistry is a contract that a) maintains a list of ProtocolAdapters and TokenAdapters and b) is called to fetch user balances.

More detailed documentation about contracts can be found in adapters and AdapterRegistry documentation.

Addresses

AdapterRegistry contract is deployed to the mainnet and its source code is verified on etherscan.

All the deployed contracts' addresses are available here.

Supported Protocols

Protocol Name Description Protocol Adapters Token Adapters
Aave Decentralized lending & borrowing protocol. Asset adapter
Debt adapter
"AToken"
Balancer Non-custodial portfolio manager, liquidity provider, and price sensor. Asset adapter supports all Balancer pools "Balancer Pool Token"
Bancor Automated liquidity protocol. Asset adapter supports Bancor pools starting from version 11 "SmartToken"
Compound Decentralized lending & borrowing protocol. Asset adapter
Debt adapter
"CToken"
Curve Exchange liquidity pool for stablecoin trading. Supports Compound, Y, and BUSD pools. Asset adapter "Curve Pool Token"
DeFi Money Market Crypto through revenue-producing real world assets. Asset adapter "MToken"
dYdX Decentralized trading platform. All 4 markets (WETH, SAI, USDC, DAI) are supported. Asset adapter
Debt adapter
Idle Yield aggregator for lending platforms. Asset adapter "IdleToken"
yearn.finance (v2/v3) Yield aggregator for lending platforms. Protocol adapter is duplicated for v2 and v3 versions of protocol. Asset adapter "YToken"
Chai A simple ERC20 wrapper over the Dai Savings Protocol. Asset adapter "Chai token"
Dai Savings Protocol Decentralized lending protocol. Asset adapter
Multi-Collateral Dai Collateralized loans on Maker. Asset adapter
Debt adapter
PoolTogether Decentralized no-loss lottery. Supports SAI, DAI, and USDC pools. Asset adapter "PoolTogether pool"
Synthetix Synthetic assets protocol. Asset adapter returns amount of SNX locked as collateral. Asset adapter
Debt adapter
TokenSets TokenSets. Automated asset management strategies. Asset adapter "SetToken"
Uniswap V1 Automated liquidity protocol. Asset adapter supports all Uniswap pools "Uniswap V1 Pool Token"
0x Staking Liquidity rewards for staking ZRX. Asset adapter

How to Add Your Adapter

The full instructions on how to add a custom adapter to the AdapterRegistry contract may be found in our wiki.

If you have questions and/or want to add your adapter to Zerion reach out to us on our Discord server.

What’s Next for DeFi SDK? 🚀

This first version of DeFi SDK is for read-only accounting purposes. Our next step is to introduce Interactive Adapters that allow users to make cross-protocol transactions from a single interface. We are incredibly excited to work with developers, users and the wider DeFi community to make these integrations as secure and accessible as possible. Watch this space, because the “De” in DeFi is about to get a whole lot more user-friendly!

Security Vulnerabilities 🛡

If you discover a security vulnerability within DeFi SDK, please send us an e-mail at [email protected]. All security vulnerabilities will be promptly addressed.

Dev Notes

This project uses Truffle and web3js for all Ethereum interactions and testing.

Set environment

Rename .env.sample file to .env, and fill in the env variables.

MNEMONIC and INFURA_API_KEY are required for core and adapters tests. PRIVATE_KEY is required for interactiveAdapters tests.

Compile contracts

npm run compile

Run tests

npm run test:core for core tests. npm run test:adapters for adapters tests. npm run test:interactiveAdapters for interactiveAdapters tests.

Run Solidity code coverage

npm run coverage

Currently, unsupported files are ignored.

Run Solidity and JS linters

npm run lint

Currently, unsupported files are ignored.

Run all the migrations scripts

npm run deploy:network, network is either development or mainnet.

License

All smart contracts are released under GNU LGPLv3.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].