Skip to content

Commit cb8ca1e

Browse files
committed
added iearn adapter
1 parent bde61ed commit cb8ca1e

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
pragma solidity 0.6.2;
2+
pragma experimental ABIEncoderV2;
3+
4+
import { Adapter } from "./Adapter.sol";
5+
import { Component } from "../Structs.sol";
6+
import { ERC20 } from "../ERC20.sol";
7+
8+
9+
/**
10+
* @dev YToken contract interface.
11+
* Only the functions required for IearnAdapter contract are added.
12+
* The YToken contracts is available here
13+
* https://github.com/iearn-finance/itoken/tree/master/contracts.
14+
*/
15+
interface YToken {
16+
function token() external view returns (address);
17+
function getPricePerFullShare() external view returns (uint256);
18+
}
19+
20+
21+
/**
22+
* @title Adapter for iearn.finance protocol.
23+
* @dev Implementation of Adapter interface.
24+
*/
25+
contract IearnAdapter is Adapter {
26+
27+
/**
28+
* @return Name of the protocol.
29+
* @dev Implementation of Adapter function.
30+
*/
31+
function getProtocolName() external pure override returns (string memory) {
32+
return("iearn.finance");
33+
}
34+
35+
/**
36+
* @return Amount of yToken held by the given user.
37+
* @dev Implementation of Adapter function.
38+
*/
39+
function getAssetAmount(address asset, address user) external view override returns (int256) {
40+
return int256(ERC20(asset).balanceOf(user));
41+
}
42+
43+
/**
44+
* @return Struct with underlying assets rates for the given asset.
45+
* @dev Implementation of Adapter function.
46+
* Repeats calculations made in stableswap contract.
47+
*/
48+
function getUnderlyingRates(address asset) external view override returns (Component[] memory) {
49+
Component[] memory components = new Component[](1);
50+
51+
components[0] = Component({
52+
underlying: YToken(asset).token(),
53+
rate: YToken(asset).getPricePerFullShare()
54+
});
55+
56+
return components;
57+
}
58+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const IearnAdapter = artifacts.require('IearnAdapter');
2+
3+
module.exports = (deployer, network, accounts) => {
4+
const yDAIAddress = '0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01';
5+
const yUSDCAddress = '0xd6aD7a6750A7593E092a9B218d66C0A814a3436e';
6+
const yUSDTAddress = '0x83f798e925BcD4017Eb265844FDDAbb448f1707D';
7+
const ySUSDAddress = '0xF61718057901F84C4eEC4339EF8f0D86D2B45600';
8+
const yTUSDAddress = '0x73a052500105205d34Daf004eAb301916DA8190f';
9+
const yWBTCAddress = '0x04Aa51bbcB46541455cCF1B8bef2ebc5d3787EC9';
10+
11+
const iearnAdapterAssets = [
12+
yDAIAddress,
13+
yUSDCAddress,
14+
yUSDTAddress,
15+
ySUSDAddress,
16+
yTUSDAddress,
17+
yWBTCAddress,
18+
];
19+
20+
let adapterRegistry;
21+
22+
deployer.deploy(IearnAdapter, { from: accounts[0] })
23+
.then(() => AdapterRegistry.at('0xaF51e57D3c78CE8495219Ceb6d559B85E62F680E')
24+
.then((registry) => {
25+
adapterRegistry = registry;
26+
return adapterRegistry.methods['addAdapter(address,address[])'](IearnAdapter.address, iearnAdapterAssets, { from: accounts[0] });
27+
}));
28+
};

test/IearnAdapter.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const { BN } = web3.utils;
2+
const AdapterRegistry = artifacts.require('./AdapterRegistry');
3+
const IearnAdapter = artifacts.require('./IearnAdapter');
4+
5+
contract('IearnAdapter', () => {
6+
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
7+
const yDAIAddress = '0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01';
8+
const yUSDCAddress = '0xd6aD7a6750A7593E092a9B218d66C0A814a3436e';
9+
const yUSDTAddress = '0x83f798e925BcD4017Eb265844FDDAbb448f1707D';
10+
const ySUSDAddress = '0xF61718057901F84C4eEC4339EF8f0D86D2B45600';
11+
const yTUSDAddress = '0x73a052500105205d34Daf004eAb301916DA8190f';
12+
const yWBTCAddress = '0x04Aa51bbcB46541455cCF1B8bef2ebc5d3787EC9';
13+
const testAddress = '0x42b9dF65B219B3dD36FF330A4dD8f327A6Ada990';
14+
15+
let accounts;
16+
let adapterRegistry;
17+
let iearnAdapter;
18+
19+
beforeEach(async () => {
20+
accounts = await web3.eth.getAccounts();
21+
await IearnAdapter.new({ from: accounts[0] })
22+
.then((result) => {
23+
iearnAdapter = result.contract;
24+
});
25+
await AdapterRegistry.new(
26+
[iearnAdapter.options.address],
27+
[[yDAIAddress,
28+
yUSDCAddress,
29+
yUSDTAddress,
30+
ySUSDAddress,
31+
yTUSDAddress,
32+
yWBTCAddress,
33+
]],
34+
{ from: accounts[0] },
35+
)
36+
.then((result) => {
37+
adapterRegistry = result.contract;
38+
});
39+
});
40+
41+
it('should be correct balances and rates', async () => {
42+
await adapterRegistry.methods['getBalancesAndRates(address)'](testAddress)
43+
.call()
44+
.then((result) => {
45+
const base = new BN(10).pow(new BN(34));
46+
const yDAIAmount = new BN(result[0].balances[0].amount);
47+
const yDAIRate = new BN(result[0].rates[0].components[0].rate);
48+
const daiAmount = yDAIRate.mul(yDAIAmount).div(base).toNumber() / 100;
49+
// eslint-disable-next-line no-console
50+
console.log(`Deposited yDAI amount: ${yDAIAmount.toString()}`);
51+
// eslint-disable-next-line no-console
52+
console.log(`yDAI rate: ${yDAIRate.toString()}`);
53+
// eslint-disable-next-line no-console
54+
console.log(`Means its: ${daiAmount} DAI locked`);
55+
// eslint-disable-next-line no-console
56+
console.log(`Deposited yUSDC amount: ${result[0].balances[1].amount.toString()}`);
57+
// eslint-disable-next-line no-console
58+
console.log(`Deposited yUSDT amount: ${result[0].balances[2].amount.toString()}`);
59+
60+
assert.equal(result[0].balances[0].decimals, 18);
61+
assert.equal(result[0].balances[0].asset, yDAIAddress);
62+
assert.equal(result[0].rates[0].asset, yDAIAddress);
63+
assert.equal(result[0].rates[0].components[0].underlying, daiAddress);
64+
assert.equal(result[0].name, 'iearn.finance');
65+
});
66+
});
67+
});

0 commit comments

Comments
 (0)