mirror of
https://github.com/Instadapp/dsa-resolvers-deprecated.git
synced 2024-07-29 22:38:16 +00:00
test: 💍 aggregate resolvers such as comp, aave and maker
This commit is contained in:
parent
0b048fbcc1
commit
31673ca186
|
|
@ -1,39 +1,43 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import {DSMath} from "./common/math.sol";
|
||||
|
||||
interface AaveProtocolDataProvider {
|
||||
function getUserAccountData(address user) external view returns (
|
||||
uint256 totalCollateralETH,
|
||||
uint256 totalDebtETH,
|
||||
uint256 availableBorrowsETH,
|
||||
uint256 currentLiquidationThreshold,
|
||||
uint256 ltv,
|
||||
uint256 healthFactor
|
||||
);
|
||||
function getUserAccountData(address user)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
uint256 totalCollateralETH,
|
||||
uint256 totalDebtETH,
|
||||
uint256 availableBorrowsETH,
|
||||
uint256 currentLiquidationThreshold,
|
||||
uint256 ltv,
|
||||
uint256 healthFactor
|
||||
);
|
||||
}
|
||||
|
||||
interface ChainLinkInterface {
|
||||
function latestAnswer() external view returns (int256);
|
||||
}
|
||||
|
||||
contract Variables {
|
||||
ChainLinkInterface public constant ethPriceFeed = ChainLinkInterface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
|
||||
AaveProtocolDataProvider public constant aaveDataProvider = AaveProtocolDataProvider(0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9);
|
||||
ChainLinkInterface public constant ethPriceFeed =
|
||||
ChainLinkInterface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
|
||||
AaveProtocolDataProvider public constant aaveDataProvider =
|
||||
AaveProtocolDataProvider(0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9);
|
||||
}
|
||||
|
||||
contract Resolver is Variables, DSMath {
|
||||
function getPosition(address account) external view returns (uint256 networthInUsd) {
|
||||
(
|
||||
uint256 totalCollateralETH,
|
||||
uint256 totalDebtETH,
|
||||
,
|
||||
,
|
||||
,
|
||||
|
||||
) = aaveDataProvider.getUserAccountData(account);
|
||||
|
||||
uint256 ethPrice = mul(uint256(ethPriceFeed.latestAnswer()), 10 ** 10);
|
||||
function getPosition(address account)
|
||||
external
|
||||
view
|
||||
returns (uint256 networthInUsd)
|
||||
{
|
||||
(uint256 totalCollateralETH, uint256 totalDebtETH, , , , ) =
|
||||
aaveDataProvider.getUserAccountData(account);
|
||||
|
||||
uint256 ethPrice = mul(uint256(ethPriceFeed.latestAnswer()), 10**10);
|
||||
|
||||
networthInUsd = sub(totalCollateralETH, totalDebtETH);
|
||||
networthInUsd = wmul(networthInUsd, ethPrice);
|
||||
|
|
@ -43,4 +47,3 @@ contract Resolver is Variables, DSMath {
|
|||
contract InstaAaveV2AggregateResolver is Resolver {
|
||||
string public constant name = "AaveV2-Aggregate-Resolver-v1.0";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,51 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import {DSMath} from "./common/math.sol";
|
||||
|
||||
interface CTokenInterface {
|
||||
function exchangeRateCurrent() external returns (uint);
|
||||
function borrowBalanceCurrent(address account) external returns (uint);
|
||||
function balanceOfUnderlying(address account) external returns (uint);
|
||||
function exchangeRateCurrent() external returns (uint256);
|
||||
|
||||
function borrowBalanceCurrent(address account) external returns (uint256);
|
||||
|
||||
function balanceOfUnderlying(address account) external returns (uint256);
|
||||
|
||||
function underlying() external view returns (address);
|
||||
function balanceOf(address) external view returns (uint);
|
||||
|
||||
function balanceOf(address) external view returns (uint256);
|
||||
}
|
||||
|
||||
interface OracleCompInterface {
|
||||
function getUnderlyingPrice(address) external view returns (uint);
|
||||
function getUnderlyingPrice(address) external view returns (uint256);
|
||||
}
|
||||
|
||||
interface ComptrollerLensInterface {
|
||||
function markets(address) external view returns (bool, uint, bool);
|
||||
function markets(address)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
bool,
|
||||
uint256,
|
||||
bool
|
||||
);
|
||||
|
||||
function oracle() external view returns (address);
|
||||
}
|
||||
|
||||
contract Variables {
|
||||
ComptrollerLensInterface public constant comptroller = ComptrollerLensInterface(0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B);
|
||||
ComptrollerLensInterface public constant comptroller =
|
||||
ComptrollerLensInterface(0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B);
|
||||
|
||||
address public constant cethAddr = 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5;
|
||||
address public constant cethAddr =
|
||||
0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5;
|
||||
|
||||
uint256 public constant markets = 12;
|
||||
function getAllMarkets() public pure returns (bytes20[markets] memory _markets) {
|
||||
|
||||
function getAllMarkets()
|
||||
public
|
||||
pure
|
||||
returns (bytes20[markets] memory _markets)
|
||||
{
|
||||
_markets = [
|
||||
bytes20(0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E), // cBAT
|
||||
bytes20(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643), // cDAI
|
||||
|
|
@ -48,13 +66,16 @@ contract Variables {
|
|||
}
|
||||
|
||||
contract Resolver is Variables, DSMath {
|
||||
function getCompoundNetworth(address account) internal returns (uint256 networth) {
|
||||
function getCompoundNetworth(address account)
|
||||
internal
|
||||
returns (uint256 networth)
|
||||
{
|
||||
bytes20[markets] memory allMarkets = getAllMarkets();
|
||||
OracleCompInterface oracle = OracleCompInterface(comptroller.oracle());
|
||||
uint256 totalBorrowInUsd = 0;
|
||||
uint256 totalSupplyInUsd = 0;
|
||||
|
||||
for (uint i = 0; i < markets; i++) {
|
||||
for (uint256 i = 0; i < markets; i++) {
|
||||
CTokenInterface cToken = CTokenInterface(address(allMarkets[i]));
|
||||
uint256 priceInUSD = oracle.getUnderlyingPrice(address(cToken));
|
||||
uint256 supply = cToken.balanceOfUnderlying(account);
|
||||
|
|
@ -69,10 +90,12 @@ contract Resolver is Variables, DSMath {
|
|||
networth = sub(totalSupplyInUsd, totalBorrowInUsd);
|
||||
}
|
||||
|
||||
function getPosition(address account) external returns (uint256 networthInUsd) {
|
||||
function getPosition(address account)
|
||||
external
|
||||
returns (uint256 networthInUsd)
|
||||
{
|
||||
return getCompoundNetworth(account);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract InstaCompoundAggregateResolver is Resolver {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,34 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
import "hardhat/console.sol";
|
||||
|
||||
import {DSMath} from "./common/math.sol";
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
interface ManagerLike {
|
||||
function ilks(uint) external view returns (bytes32);
|
||||
function owns(uint) external view returns (address);
|
||||
function urns(uint) external view returns (address);
|
||||
function ilks(uint256) external view returns (bytes32);
|
||||
|
||||
function owns(uint256) external view returns (address);
|
||||
|
||||
function urns(uint256) external view returns (address);
|
||||
}
|
||||
|
||||
interface VatLike {
|
||||
function ilks(bytes32) external view returns (uint, uint, uint, uint, uint);
|
||||
function dai(address) external view returns (uint);
|
||||
function urns(bytes32, address) external view returns (uint, uint);
|
||||
function gem(bytes32, address) external view returns (uint);
|
||||
function ilks(bytes32)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256,
|
||||
uint256
|
||||
);
|
||||
|
||||
function dai(address) external view returns (uint256);
|
||||
|
||||
function urns(bytes32, address) external view returns (uint256, uint256);
|
||||
|
||||
function gem(bytes32, address) external view returns (uint256);
|
||||
}
|
||||
|
||||
interface PipLike {
|
||||
|
|
@ -20,17 +36,19 @@ interface PipLike {
|
|||
}
|
||||
|
||||
interface SpotLike {
|
||||
function ilks(bytes32) external view returns (PipLike, uint);
|
||||
function ilks(bytes32) external view returns (PipLike, uint256);
|
||||
}
|
||||
|
||||
contract Variables {
|
||||
ManagerLike public constant managerContract = ManagerLike(0x5ef30b9986345249bc32d8928B7ee64DE9435E39);
|
||||
SpotLike public constant spotContract = SpotLike(0x65C79fcB50Ca1594B025960e539eD7A9a6D434A3);
|
||||
VatLike public constant vatContract = VatLike(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
|
||||
ManagerLike public constant managerContract =
|
||||
ManagerLike(0x5ef30b9986345249bc32d8928B7ee64DE9435E39);
|
||||
SpotLike public constant spotContract =
|
||||
SpotLike(0x65C79fcB50Ca1594B025960e539eD7A9a6D434A3);
|
||||
VatLike public constant vatContract =
|
||||
VatLike(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
|
||||
}
|
||||
|
||||
contract VaultResolver is Variables, DSMath {
|
||||
|
||||
function getOwner(uint256 id) external view returns (address owner) {
|
||||
owner = managerContract.owns(id);
|
||||
}
|
||||
|
|
@ -40,22 +58,20 @@ contract VaultResolver is Variables, DSMath {
|
|||
bytes32 ilk = managerContract.ilks(id);
|
||||
|
||||
(uint256 ink, uint256 art) = vatContract.urns(ilk, urn);
|
||||
(,uint256 rate, uint256 priceMargin,,) = vatContract.ilks(ilk);
|
||||
(, uint256 rate, uint256 priceMargin, , ) = vatContract.ilks(ilk);
|
||||
|
||||
(, uint256 mat) = spotContract.ilks(ilk);
|
||||
uint256 price = rmul(priceMargin, mat);
|
||||
price = price / 1e18;
|
||||
price = price / 1e9;
|
||||
|
||||
uint256 supply = wmul(ink, price);
|
||||
uint256 borrow = rmul(art, rate);
|
||||
borrow = borrow / 1e9;
|
||||
|
||||
networth = sub(supply, borrow);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract InstaMakerDAOAggregateResolver is VaultResolver {
|
||||
string public constant name = "MakerDAO-Aggregate-Resolver-v1.0";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,14 +23,17 @@ task("accounts", "Prints the list of accounts", async () => {
|
|||
* @type import('hardhat/config').HardhatUserConfig
|
||||
*/
|
||||
module.exports = {
|
||||
paths: {
|
||||
sources: "./contracts/aggregate",
|
||||
},
|
||||
solidity: {
|
||||
compilers: [
|
||||
{
|
||||
version: "0.6.10"
|
||||
version: "0.6.10",
|
||||
},
|
||||
{
|
||||
version: "0.7.3"
|
||||
}
|
||||
version: "0.7.3",
|
||||
},
|
||||
],
|
||||
optimizer: {
|
||||
enabled: true,
|
||||
|
|
@ -41,12 +44,11 @@ module.exports = {
|
|||
hardhat: {
|
||||
forking: {
|
||||
url: "https://eth-mainnet.alchemyapi.io/v2/" + ALCHEMY_API_KEY,
|
||||
blockNumber: 12386345
|
||||
}
|
||||
}
|
||||
blockNumber: 12510580,
|
||||
},
|
||||
},
|
||||
},
|
||||
mocha: {
|
||||
timeout: 100000,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
11
package-lock.json
generated
11
package-lock.json
generated
|
|
@ -8,6 +8,7 @@
|
|||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^3.4.1-solc-0.7-2",
|
||||
"solc": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -1378,6 +1379,11 @@
|
|||
"hardhat": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@openzeppelin/contracts": {
|
||||
"version": "3.4.1-solc-0.7-2",
|
||||
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-3.4.1-solc-0.7-2.tgz",
|
||||
"integrity": "sha512-tAG9LWg8+M2CMu7hIsqHPaTyG4uDzjr6mhvH96LvOpLZZj6tgzTluBt+LsCf1/QaYrlis6pITvpIaIhE+iZB+Q=="
|
||||
},
|
||||
"node_modules/@resolver-engine/core": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@resolver-engine/core/-/core-0.3.3.tgz",
|
||||
|
|
@ -18687,6 +18693,11 @@
|
|||
"@types/web3": "1.0.19"
|
||||
}
|
||||
},
|
||||
"@openzeppelin/contracts": {
|
||||
"version": "3.4.1-solc-0.7-2",
|
||||
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-3.4.1-solc-0.7-2.tgz",
|
||||
"integrity": "sha512-tAG9LWg8+M2CMu7hIsqHPaTyG4uDzjr6mhvH96LvOpLZZj6tgzTluBt+LsCf1/QaYrlis6pITvpIaIhE+iZB+Q=="
|
||||
},
|
||||
"@resolver-engine/core": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@resolver-engine/core/-/core-0.3.3.tgz",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
},
|
||||
"homepage": "https://github.com/InstaDApp/dsa-resolvers#readme",
|
||||
"dependencies": {
|
||||
"@openzeppelin/contracts": "^3.4.1-solc-0.7-2",
|
||||
"solc": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
36
test/aggregate-resolvers.js
Normal file
36
test/aggregate-resolvers.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const { expect } = require("chai");
|
||||
const { ethers } = require("hardhat");
|
||||
|
||||
describe("Resolver getPosition", function () {
|
||||
let maker, compound, aaveV2;
|
||||
before("Deploy Aggregate Resolvers", async function () {
|
||||
maker = await (
|
||||
await ethers.getContractFactory("InstaMakerDAOAggregateResolver")
|
||||
).deploy();
|
||||
compound = await (
|
||||
await ethers.getContractFactory("InstaCompoundAggregateResolver")
|
||||
).deploy();
|
||||
aaveV2 = await (
|
||||
await ethers.getContractFactory("InstaAaveV2AggregateResolver")
|
||||
).deploy();
|
||||
});
|
||||
|
||||
it("should get position for maker", async function () {
|
||||
const id = 2571;
|
||||
const position = await maker.getPosition(id);
|
||||
expect(position).gt(0);
|
||||
});
|
||||
|
||||
it("should get position for compound", async function () {
|
||||
const account = "0x005280119e7070fd1999703ec606c5e97b146e84";
|
||||
const tx = compound.getPosition(account);
|
||||
expect(tx).to.satisfy;
|
||||
});
|
||||
|
||||
it("should get position for aaveV2", async function () {
|
||||
const account = "0x005280119e7070fd1999703ec606c5e97b146e84";
|
||||
const position = await aaveV2.getPosition(account);
|
||||
console.log(position.toString());
|
||||
expect(position).gt(0);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user