Skip to content

Commit 0f5a9bf

Browse files
authored
Merge branch 'master' into add-idle-finance
2 parents d0d5290 + d670a52 commit 0f5a9bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+148
-80
lines changed

README.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
# DeFi SDK
44

5-
![](https://github.com/zeriontech/protocol-wrappers/workflows/lint/badge.svg)
6-
![](https://github.com/zeriontech/protocol-wrappers/workflows/build/badge.svg)
7-
![](https://github.com/zeriontech/protocol-wrappers/workflows/test/badge.svg)
8-
![](https://github.com/zeriontech/protocol-wrappers/workflows/coverage/badge.svg)
5+
[![Build status](https://github.com/zeriontech/protocol-wrappers/workflows/build/badge.svg)](https://github.com/zeriontech/defi-sdk/actions?query=workflow:build)
6+
[![Test status](https://github.com/zeriontech/protocol-wrappers/workflows/test/badge.svg)](https://github.com/zeriontech/defi-sdk/actions?query=workflow:test)
7+
[![Coverage status](https://github.com/zeriontech/protocol-wrappers/workflows/coverage/badge.svg)](https://github.com/zeriontech/defi-sdk/actions?query=workflow:coverage)
8+
[![Lint status](https://github.com/zeriontech/protocol-wrappers/workflows/lint/badge.svg)](https://github.com/zeriontech/defi-sdk/actions?query=workflow:lint)
9+
[![License](https://img.shields.io/github/license/zeriontech/defi-sdk)](https://www.gnu.org/licenses/lgpl-3.0.en.html)
10+
[![Discord](https://img.shields.io/discord/544761450724458498?label=discord)](https://go.zerion.io/discord)
11+
[![Twitter Follow](https://img.shields.io/twitter/follow/zerion_io.svg)](https://twitter.com/intent/follow?screen_name=zerion_io)
912

1013
**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.
1114

1215
If you have any questions about DeFi SDK, feel free to reach out to us on our [Discord server](https://go.zerion.io/discord).
1316

1417
## Features
1518

16-
#### 💥Query user assets and debt deposited in DeFi protocols like *Maker, Aave, Curve*, etc.
17-
> How much debt does `0xdead..beef` have on Curve Y pool?
18-
#### 📊Get the underlying components of complex derivative ERC20 tokens
19+
20+
#### 💥Query user assets and debt deposited in DeFi protocols like *Maker, Aave, dYdX*, etc.
21+
> How much debt does `0xdead..beef` have on Compound?
22+
#### 📊Get the underlying components of complex derivative ERC20 tokens
1923
> How much `cUSDC` vs `ETH` does `ETHMACOAPY` have?
2024
#### ✨Interact with multiple DeFi protocols in a unified way (coming soon)
2125
> See [What’s next for DeFi SDK](#whats-next-for-defi-sdk-)
@@ -33,11 +37,14 @@ If you have any questions about DeFi SDK, feel free to reach out to us on our [D
3337

3438
### Fetch Compound debt and collateral
3539

36-
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 one function `getProtocolBalances(account, ["Compound"])` on the `api.zerion.eth` smart contract to get all borrowed and supplied tokens.
40+
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
3741

3842
```solidity
39-
getBalances('0xdead...beef', ['Compound'])
43+
getProtocolBalances('0xdead...beef', ['Compound'])
4044
```
45+
46+
on the `api.zerion.eth` smart contract and get all borrowed and supplied tokens
47+
4148
```javascript
4249
[{
4350
metadata: {
@@ -60,7 +67,7 @@ getBalances('0xdead...beef', ['Compound'])
6067
symbol: 'cBAT',
6168
decimals: '8'
6269
},
63-
amount: '0'
70+
amount: '314159265'
6471
},
6572
underlying: [{
6673
metadata: {
@@ -69,7 +76,7 @@ getBalances('0xdead...beef', ['Compound'])
6976
symbol: 'BAT',
7077
decimals: '18'
7178
},
72-
amount: '0'
79+
amount: '6626070040000000000'
7380
}]
7481
}]
7582
},{
@@ -85,7 +92,7 @@ getBalances('0xdead...beef', ['Compound'])
8592
symbol: 'DAI',
8693
decimals: '18'
8794
},
88-
amount: '0'
95+
amount: '1971081500000000000'
8996
},
9097
underlying: []
9198
}]
@@ -101,31 +108,37 @@ getBalances('0xdead...beef', ['Compound'])
101108
</p>
102109

103110
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
104-
```solidity
111+
112+
```solidity
105113
// Uniswap V1 cDAI pool
106114
getFinalFullTokenBalance('0x34E89740adF97C3A9D3f63Cc2cE4a914382c230b', "Uniswap V1 pool token")
107115
```
116+
117+
and fetch the decomposition of UNI-token into ERC20 tokens, like `ETH` and `DAI`
118+
108119
```javascript
109-
100 ETH
110-
0.1 DAI
120+
0.98 ETH
121+
215.6 DAI
111122
```
112-
and fetch the decomposition of UNI-token into ERC20 tokens, like `ETH` and `DAI`.
113123

114124
### Get account balances across all supported DeFi protocols
115125

116126
In case you want to get account balances across all supported DeFi protocols, you can call
117-
```solidity
118-
// bankless.zerion.eth portfolio
119-
getBalances('0x0ef51b7dac3933b8109482e7d910c21848e45da0f')
127+
128+
```solidity
129+
// bankless.zerion.eth portfolio
130+
getBalances('0x0ef51b7dac3933b8109482e7d910c21848e45da0f')
120131
```
132+
133+
and obtain all balances for a given account. The response from the smart-contract will contain information about each of the protocols
134+
121135
```javascript
122136
100 DAI // collateral on Compound
123-
0.1 ETH // debt on Compound
137+
0.1 ETH // debt on Compound
124138
100 USDC // locked in PoolTogether
125139
213 TUSD + 201 USDC + 82 USDT + 11 DAI // Curve Y pool
126140
...
127141
```
128-
and obtain all balances for a given account. The response from the smart-contract will contain information about each of the protocols.
129142

130143
## DeFi SDK architecture
131144

@@ -145,8 +158,8 @@ More detailed documentation about contracts can be found in [adapters](../../wik
145158
| [Compound](./contracts/adapters/compound) | Decentralized lending & borrowing protocol. | [Asset adapter](./contracts/adapters/compound/CompoundAssetAdapter.sol) <br> [Debt adapter](./contracts/adapters/compound/CompoundDebtAdapter.sol) | ["CToken"](./contracts/adapters/compound/CompoundTokenAdapter.sol) |
146159
| [Curve](./contracts/adapters/curve) | Exchange liquidity pool for stablecoin trading. Supports Compound, Y, and BUSD pools. | [Asset adapter](./contracts/adapters/curve/CurveAdapter.sol) | ["Curve pool token"](contracts/adapters/curve/CurveTokenAdapter.sol) |
147160
| [dYdX](./contracts/adapters/dydx) | Decentralized trading platform. All 4 markets (WETH, SAI, USDC, DAI) are supported. | [Asset adapter](./contracts/adapters/dydx/DyDxAssetAdapter.sol) <br> [Debt adapter](./contracts/adapters/dydx/DyDxDebtAdapter.sol) ||
161+
| [Idle](./contracts/adapters/idle) | Yield aggregator for lending platforms. | [Asset adapter](./contracts/adapters/idle/IdleAdapter.sol) | ["IdleToken"](./contracts/adapters/idle/IdleTokenAdapter.sol) |
148162
| [iearn.finance (v2/v3)](./contracts/adapters/iearn) | Yield aggregator for lending platforms. Protocol adapter is duplicated for v2 and v3 versions of protocol. | [Asset adapter](./contracts/adapters/iearn/IearnAdapter.sol) | ["YToken"](./contracts/adapters/iearn/IearnTokenAdapter.sol) |
149-
| [idle.finance](./contracts/adapters/idle) | Yield aggregator for lending platforms. | [Asset adapter](./contracts/adapters/idle/IdleAdapter.sol) | ["IdleToken"](./contracts/adapters/idle/IdleTokenAdapter.sol) |
150163
| [Chai](./contracts/adapters/maker) | A simple ERC20 wrapper over the Dai Savings Rate. | [Asset adapter](./contracts/adapters/maker/ChaiAdapter.sol) | ["Chai token"](./contracts/adapters/maker/ChaiTokenAdapter.sol) |
151164
| [DSR](./contracts/adapters/maker) | Decentralized lending protocol by MakerDAO. | [Asset adapter](./contracts/adapters/maker/DSRAdapter.sol) ||
152165
| [MCD](./contracts/adapters/maker) | Collateralized loans on Maker. | [Asset adapter](./contracts/adapters/maker/MCDAssetAdapter.sol) <br> [Debt adapter](./contracts/adapters/maker/MCDDebtAdapter.sol) ||

contracts/AdapterRegistry.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -35,9 +35,10 @@ import {
3535

3636

3737
/**
38-
* @title Registry for protocols, protocol adapters, and token adapters.
39-
* @notice getBalances() function implements the main functionality.
40-
*/
38+
* @title Registry for protocols, adapters, and token adapters.
39+
* @notice getBalances() function implements the main functionality.
40+
* @author Igor Sobolev <[email protected]>
41+
*/
4142
contract AdapterRegistry is Ownable, ProtocolManager, TokenAdapterManager {
4243

4344
using Strings for string;

contracts/ERC20.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by

contracts/Ownable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by

contracts/ProtocolManager.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -22,7 +22,9 @@ import { Strings } from "./Strings.sol";
2222

2323

2424
/**
25-
* @title Base contract for AdapterRegistry.
25+
* @title AdapterRegistry part responsible for protocols and adapters management.
26+
* @dev Base contract for AdapterRegistry.
27+
* @author Igor Sobolev <[email protected]>
2628
*/
2729
abstract contract ProtocolManager is Ownable {
2830

contracts/Strings.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -16,7 +16,10 @@
1616
pragma solidity 0.6.4;
1717
pragma experimental ABIEncoderV2;
1818

19-
19+
/**
20+
* @notice Library for strings.
21+
* @author Igor Sobolev <[email protected]>
22+
*/
2023
library Strings {
2124

2225
function isEmpty(string memory s) internal pure returns (bool) {

contracts/Structs.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by

contracts/TokenAdapterManager.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -21,7 +21,9 @@ import { Strings } from "./Strings.sol";
2121

2222

2323
/**
24-
* @title Base contract for AdapterRegistry.
24+
* @title AdapterRegistry part responsible for token adapters management.
25+
* @dev Base contract for AdapterRegistry.
26+
* @author Igor Sobolev <[email protected]>
2527
*/
2628
abstract contract TokenAdapterManager is Ownable {
2729

contracts/adapters/ERC20TokenAdapter.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@ import { TokenMetadata, Component } from "../Structs.sol";
2424
/**
2525
* @title Adapter for ERC20 tokens.
2626
* @dev Implementation of TokenAdapter interface function.
27+
* @author Igor Sobolev <[email protected]>
2728
*/
2829
contract ERC20TokenAdapter is TokenAdapter {
2930

contracts/adapters/ProtocolAdapter.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Igor Sobolev <sobolev@zerion.io>
1+
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -18,8 +18,9 @@ pragma experimental ABIEncoderV2;
1818

1919

2020
/**
21-
* @title Base contract for protocol adapters.
21+
* @title Protocol adapter interface.
2222
* @dev adapterType(), tokenType(), and getBalance() functions MUST be implemented.
23+
* @author Igor Sobolev <[email protected]>
2324
*/
2425
interface ProtocolAdapter {
2526

0 commit comments

Comments
 (0)