Skip to content

Commit bde61ed

Browse files
authored
Merge pull request #4 from zeriontech/additional-adapters
Adapters for Compound, PoolTogether, and others
2 parents 3f0bdd7 + b802609 commit bde61ed

34 files changed

+1810
-2004
lines changed

.solcover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
'ERC20.sol',
88
'Logic.sol',
99
'adapters/Adapter.sol',
10+
'adapters/MKRAdapter.sol',
1011
'interactiveAdapters',
1112
'mock',
1213
],

.solhint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"compiler-version": [
1212
"error",
13-
"0.6.1"
13+
"0.6.2"
1414
]
1515
}
1616
}

README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ This is a project with Zerion Smart Contracts interacting with different DeFi pr
1111
- [AdapterRegistry](#adapterregistry-is-AdapterAssetsManager)
1212
- [AdapterAssetsManager](#AdapterAssetsManager-is-ownable)
1313
- [Ownable](#ownable)
14+
- [adapters/AaveAdapter](#aaveadapter-is-Adapter)
15+
- [adapters/CompoundAdapter](#compoundadapter-is-Adapter)
16+
- [adapters/CurveAdapter](#curveadapter-is-Adapter)
1417
- [adapters/DSRAdapter](#dsradapter-is-Adapter)
18+
- [adapters/MCDAdapter](#mcdadapter-is-Adapter)
19+
- [adapters/MKRAdapter (abstract contract)](#mkradapter-abstract-contract)
20+
- [adapters/PoolTogetherAdapter](#pooltogetheradapter-is-Adapter)
1521
- [adapters/SynthetixAdapter](#synthetixadapter-is-Adapter)
16-
- [adapters/CurveAdapter](#curveadapter-is-Adapter)
22+
- [adapters/ZrxAdapter](#zrxadapter-is-Adapter)
1723
- [adapters/Adapter (abstract contract)](#Adapter-abstract-contract)
1824
- [Logic](#logic)
1925
- [TokenSpender](#tokenspender)
@@ -96,11 +102,35 @@ Base contract for `AdapterAssetsManager` and `Logic` contracts.
96102
Implements `Ownable` logic.
97103
Includes `onlyOwner` modifier, `transferOwnership()` function, and public state variable `owner`.
98104

105+
## AaveAdapter is [Adapter](#Adapter-abstract-contract)
106+
107+
Adapter for Aave protocol.
108+
109+
## CompoundAdapter is [Adapter](#Adapter-abstract-contract)
110+
111+
Adapter for Compound protocol.
112+
113+
## CurveAdapter is [Adapter](#Adapter-abstract-contract)
114+
115+
Adapter for [curve.fi](https://compound.curve.fi/) protocol.
116+
Currently, there is the only pool with cDAI/cUSDC locked on it.
117+
99118
## DSRAdapter is [Adapter](#Adapter-abstract-contract)
100119

101120
Adapter for DSR protocol.
102121

103-
Interactive adapter will not be implemented.
122+
## MCDAdapter is [Adapter](#Adapter-abstract-contract)
123+
124+
Adapter for MCD vaults.
125+
126+
## MKRAdapter (abstract contract)
127+
128+
Base contract for Maker adapters.
129+
It includes all the required constants and `pure` functions with calculations.
130+
131+
## PoolTogetherAdapter is [Adapter](#Adapter-abstract-contract)
132+
133+
Adapter for PoolTogether protocol.
104134

105135
## SynthetixAdapter is [Adapter](#Adapter-abstract-contract)
106136

@@ -110,12 +140,9 @@ Adapter for Synthetix protocol.
110140
- amount of SNX tokens locked by minting sUSD tokens (positive);
111141
- amount of sUSD that should be burned to unlock SNX tokens (negative).
112142

113-
Interactive adapter will not be implemented.
114-
115-
## CurveAdapter is [Adapter](#Adapter-abstract-contract)
143+
## ZrxAdapter is [Adapter](#Adapter-abstract-contract)
116144

117-
Adapter for [curve.fi](https://compound.curve.fi/) protocol.
118-
Currently, there is the only pool with cDAI/cUSDC locked on it.
145+
Adapter for Zrx protocol.
119146

120147
## Adapter (abstract contract)
121148

contracts/AdapterAssetsManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.6.1;
1+
pragma solidity 0.6.2;
22
pragma experimental ABIEncoderV2;
33

44
import { Ownable } from "./Ownable.sol";

contracts/AdapterRegistry.sol

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.6.1;
1+
pragma solidity 0.6.2;
22
pragma experimental ABIEncoderV2;
33

44
import { Adapter } from "./adapters/Adapter.sol";
@@ -15,11 +15,13 @@ import {
1515

1616
/**
1717
* @title Registry for protocol adapters.
18-
* @notice balance() and exchangeRates() functions
18+
* @notice getBalances() and getRates() functions
1919
* with different arguments implement the main functionality.
2020
*/
2121
contract AdapterRegistry is AdapterAssetsManager {
2222

23+
address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
24+
2325
constructor(
2426
address[] memory _adapters,
2527
address[][] memory _assets
@@ -42,7 +44,7 @@ contract AdapterRegistry is AdapterAssetsManager {
4244
address[] memory adapters = getAdapters();
4345
ProtocolDetail[] memory protocolDetails = new ProtocolDetail[](adapters.length);
4446

45-
for (uint i = 0; i < adapters.length; i++) {
47+
for (uint256 i = 0; i < adapters.length; i++) {
4648
protocolDetails[i] = ProtocolDetail({
4749
name: Adapter(adapters[i]).getProtocolName(),
4850
balances: getBalances(user, adapters[i]),
@@ -67,7 +69,7 @@ contract AdapterRegistry is AdapterAssetsManager {
6769
address[] memory adapters = getAdapters();
6870
ProtocolBalance[] memory protocolBalances = new ProtocolBalance[](adapters.length);
6971

70-
for (uint i = 0; i < adapters.length; i++) {
72+
for (uint256 i = 0; i < adapters.length; i++) {
7173
protocolBalances[i] = ProtocolBalance({
7274
name: Adapter(adapters[i]).getProtocolName(),
7375
balances: getBalances(user, adapters[i])
@@ -89,7 +91,7 @@ contract AdapterRegistry is AdapterAssetsManager {
8991
address[] memory adapters = getAdapters();
9092
ProtocolRate[] memory protocolRates = new ProtocolRate[](adapters.length);
9193

92-
for (uint i = 0; i < adapters.length; i++) {
94+
for (uint256 i = 0; i < adapters.length; i++) {
9395
protocolRates[i] = ProtocolRate({
9496
name: Adapter(adapters[i]).getProtocolName(),
9597
rates: getRates(adapters[i])
@@ -137,7 +139,7 @@ contract AdapterRegistry is AdapterAssetsManager {
137139
assetBalances[i] = AssetBalance({
138140
asset: asset,
139141
amount: Adapter(adapter).getAssetAmount(asset, user),
140-
decimals: ERC20(asset).decimals()
142+
decimals: getAssetDecimals(asset)
141143
});
142144
}
143145

@@ -185,4 +187,15 @@ contract AdapterRegistry is AdapterAssetsManager {
185187

186188
return rates;
187189
}
190+
191+
function getAssetDecimals(
192+
address asset
193+
)
194+
internal
195+
view
196+
returns (uint8)
197+
{
198+
return asset == ETH ? uint8(18) : ERC20(asset).decimals();
199+
}
200+
188201
}

contracts/ERC20.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.6.1;
1+
pragma solidity 0.6.2;
22
pragma experimental ABIEncoderV2;
33

44

contracts/Ownable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.6.1;
1+
pragma solidity 0.6.2;
22
pragma experimental ABIEncoderV2;
33

44

contracts/Structs.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.6.1;
1+
pragma solidity 0.6.2;
22
pragma experimental ABIEncoderV2;
33

44

@@ -23,7 +23,7 @@ struct ProtocolRate {
2323

2424
struct AssetBalance {
2525
address asset;
26-
int128 amount;
26+
int256 amount;
2727
uint8 decimals;
2828
}
2929

contracts/adapters/AaveAdapter.sol

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
pragma solidity 0.6.2;
2+
pragma experimental ABIEncoderV2;
3+
4+
import { Adapter } from "./Adapter.sol";
5+
import { Component } from "../Structs.sol";
6+
7+
8+
/**
9+
* @dev LendingPoolAddressesProvider contract interface.
10+
* Only the functions required for AaveAdapter contract are added.
11+
* The LendingPoolAddressesProvider contract is available here
12+
* https://github.com/aave/aave-protocol/blob/master/contracts/configuration/LendingPoolAddressesProvider.sol.
13+
*/
14+
interface LendingPoolAddressesProvider {
15+
function getLendingPool() external view returns (LendingPool);
16+
}
17+
18+
19+
/**
20+
* @dev LendingPool contract interface.
21+
* Only the functions required for AaveAdapter contract are added.
22+
* The LendingPool contract is available here
23+
* https://github.com/aave/aave-protocol/blob/master/contracts/lendingpool/LendingPool.sol.
24+
*/
25+
interface LendingPool {
26+
function getUserReserveData(address, address)
27+
external
28+
view
29+
returns (
30+
uint256,
31+
uint256,
32+
uint256,
33+
uint256,
34+
uint256,
35+
uint256,
36+
uint256,
37+
uint256,
38+
uint256,
39+
bool
40+
);
41+
}
42+
43+
44+
/**
45+
* @title Adapter for Aave protocol.
46+
* @dev Implementation of Adapter interface.
47+
*/
48+
contract AaveAdapter is Adapter {
49+
50+
address internal constant PROVIDER = 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8;
51+
52+
/**
53+
* @return Name of the protocol.
54+
* @dev Implementation of Adapter function.
55+
*/
56+
function getProtocolName() external pure override returns (string memory) {
57+
return("Aave");
58+
}
59+
60+
/**
61+
* @return Amount of asset locked on the protocol by the given user.
62+
* @dev Implementation of Adapter function.
63+
*/
64+
function getAssetAmount(address asset, address user) external view override returns (int256) {
65+
LendingPool pool = LendingPoolAddressesProvider(PROVIDER).getLendingPool();
66+
67+
(uint256 depositAmount, uint256 debtAmount, , , , , , , , ) =
68+
pool.getUserReserveData(asset, user);
69+
70+
return depositAmount > 0 ? int256(depositAmount) : -int256(debtAmount);
71+
}
72+
73+
/**
74+
* @return Struct with underlying assets rates for the given asset.
75+
* @dev Implementation of Adapter function.
76+
*/
77+
function getUnderlyingRates(address asset) external view override returns (Component[] memory) {
78+
Component[] memory components = new Component[](1);
79+
80+
components[0] = Component({
81+
underlying: asset,
82+
rate: uint256(1e18)
83+
});
84+
85+
return components;
86+
}
87+
}

contracts/adapters/Adapter.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity 0.6.1;
1+
pragma solidity 0.6.2;
22
pragma experimental ABIEncoderV2;
33

44
import { Component } from "../Structs.sol";
@@ -8,20 +8,20 @@ import { Component } from "../Structs.sol";
88
* @title Base contract for protocol adapters.
99
* @dev getProtocolName(), getAssetAmount(), and getUnderlyingRates() functions MUST be implemented.
1010
*/
11-
abstract contract Adapter {
11+
interface Adapter {
1212

1313
/**
1414
* @dev MUST return name of the protocol.
1515
*/
16-
function getProtocolName() external pure virtual returns (string memory);
16+
function getProtocolName() external pure returns (string memory);
1717

1818
/**
1919
* @dev MUST return amount of the given asset locked on the protocol by the given user.
2020
*/
21-
function getAssetAmount(address asset, address user) external view virtual returns (int128);
21+
function getAssetAmount(address asset, address user) external view returns (int256);
2222

2323
/**
2424
* @dev MUST return struct with underlying assets rates for the given asset.
2525
*/
26-
function getUnderlyingRates(address asset) external view virtual returns (Component[] memory);
26+
function getUnderlyingRates(address asset) external view returns (Component[] memory);
2727
}

0 commit comments

Comments
 (0)