Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/unagii v2 adapters #165

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ All the deployed contracts' addresses are available [here](../../wiki/Addresses)
| [Synthetix](./contracts/adapters/synthetix) | Synthetic assets protocol. Asset adapter returns amount of SNX locked as collateral. | [Asset adapter](./contracts/adapters/synthetix/SynthetixAssetAdapter.sol) <br> [Debt adapter](./contracts/adapters/synthetix/SynthetixDebtAdapter.sol) | — |
| [TokenSets](./contracts/adapters/tokenSets) | Automated asset management strategies. | [Asset adapter](./contracts/adapters/tokenSets/TokenSetsAdapter.sol) <br> [Asset adapter V2](./contracts/adapters/tokenSets/TokenSetsV2Adapter.sol) | ["SetToken"](./contracts/adapters/tokenSets/TokenSetsTokenAdapter.sol) <br> ["SetToken V2"](./contracts/adapters/tokenSets/TokenSetsV2TokenAdapter.sol) |
| [Unagii](./contracts/adapters/unagii) | DeFi yields on auto-pilot. | [Asset adapter](./contracts/adapters/unagii/UnagiiVaultAdapter.sol) | — |
| [Unagii V2](./contracts/adapters/unagii) | DeFi yields on auto-pilot. | [Asset adapter](./contracts/adapters/unagii/UnagiiVaultV2Adapter.sol) | — |
| [Uniswap V1](./contracts/adapters/uniswap) | Automated liquidity protocol. | [Asset adapter](./contracts/adapters/uniswap/UniswapV1Adapter.sol) supports all Uniswap V1 pools | ["Uniswap V1 pool token"](./contracts/adapters/uniswap/UniswapV1TokenAdapter.sol) |
| [Uniswap V2](./contracts/adapters/uniswap) | Automated liquidity protocol. | [Asset adapter](./contracts/adapters/uniswap/UniswapV2Adapter.sol) supports all Uniswap V2 pools | ["Uniswap V2 pool token"](./contracts/adapters/uniswap/UniswapV2TokenAdapter.sol) |
| [0x Staking](./contracts/adapters/zrx) | Liquidity rewards for staking ZRX. | [Asset adapter](./contracts/adapters/zrx/ZrxAdapter.sol) | — |
Expand Down
46 changes: 46 additions & 0 deletions contracts/adapters/unagii/UnagiiVaultV2Adapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;

import { ERC20 } from "../../ERC20.sol";
import { ProtocolAdapter } from "../ProtocolAdapter.sol";

interface UnagiiVaultV2 {
function uToken() external view returns (address);
}

/**
* @title Adapter for Unagii V2 protocol.
* @dev Implementation of ProtocolAdapter interface.
* @author Igor Sobolev <[email protected]>
*/
contract UnagiiVaultV2Adapter is ProtocolAdapter {

string public constant override adapterType = "Asset";

string public constant override tokenType = "UnagiiV2 token";

/**
* @return Amount of Unagii Vault V2 Tokens owned by the given account.
* @param token Address of the vault token.
* @dev Implementation of ProtocolAdapter interface function.
*/
function getBalance(address token, address account) external view override returns (uint256) {
address uToken = UnagiiVaultV2(token).uToken();
return ERC20(uToken).balanceOf(account);
}
}
67 changes: 67 additions & 0 deletions contracts/adapters/unagii/UnagiiVaultV2TokenAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;

import { ERC20 } from "../../ERC20.sol";
import { TokenMetadata, Component } from "../../Structs.sol";
import { TokenAdapter } from "../TokenAdapter.sol";

interface UnagiiVaultV2 {
function token() external view returns (address);

function calcWithdraw(uint256) external view returns (uint256);
}

/**
* @title Token adapter for Unagii Vaults V2.
* @dev Implementation of TokenAdapter interface.
* @author Igor Sobolev <[email protected]>
*/
contract UnagiiVaultV2TokenAdapter is TokenAdapter {

/**
* @return TokenMetadata struct with ERC20-style token info.
* @dev Implementation of TokenAdapter interface function.
*/
function getMetadata(address token) external view override returns (TokenMetadata memory) {
return TokenMetadata({
token: token,
name: ERC20(token).name(),
symbol: ERC20(token).symbol(),
decimals: ERC20(token).decimals()
});
}

/**
* @return Array of Component structs with underlying tokens rates for the given token.
* @dev Implementation of TokenAdapter abstract contract function.
*/
function getComponents(address token) external view override returns (Component[] memory) {
address underlying = UnagiiVaultV2(token).token();
uint256 pricing = UnagiiVaultV2(token).calcWithdraw(1e18);

Component[] memory underlyingTokens = new Component[](1);

underlyingTokens[0] = Component({
token: underlying,
tokenType: "ERC20",
rate: pricing
});

return underlyingTokens;
}
}
34 changes: 34 additions & 0 deletions migrations_scripts/1_deploy_registry_and_add_adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const UniswapV1TokenAdapter = artifacts.require('UniswapV1TokenAdapter');
const UniswapV2TokenAdapter = artifacts.require('UniswapV2TokenAdapter');
const UnagiiVaultAdapter = artifacs.require('UnagiiVaultAdapter');
const UnagiiVaultTokenAdapter = artifacs.require('UnagiiVaultTokenAdapter');
const UnagiiVaultV2Adapter = artifacs.require('UnagiiVaultV2Adapter');
const UnagiiVaultV2TokenAdapter = artifacs.require('UnagiiVaultV2TokenAdapter');
const AdapterRegistry = artifacts.require('AdapterRegistry');

const antAddress = '0x960b236A07cf122663c4303350609A66A7B288C0';
Expand Down Expand Up @@ -454,6 +456,12 @@ const unagiiVaultUSDTAddress = '0x178Bf8fD04b47D2De3eF3f6b3D112106375ad584';
const unagiiVaultWBTCAddress = '0x3aF5Ba94C29a8407785f5f6d90eF5d69a8EB2436';
const unagiiVaultETHAddress = '0x77607588222e01bf892a29Abab45796A2047fc7b';

const unagiiVaultV2USDCAddress = '0x7f75d72886D6A8677321E5602d18948aBCb4281A';
const unagiiVaultV2DAIAddress = '0x9ce3018375d305CE3C3303A26eF62D3d2EB8561A';
const unagiiVaultV2USDTAddress = '0x1Eb06EaE3263a35619dC87812a8e7Ec811B59E63';
const unagiiVaultV2WBTCAddress = '0xB088D7C71ea9eBAed981c103Fc3019B59950d2C9';
const unagiiVaultV2ETHAddress = '0x8eF11c51a666C53Aeeec504f120cd1435E451342';

const aaveAssetAdapterTokens = [
aDaiAddress,
aTusdAddress,
Expand Down Expand Up @@ -979,6 +987,14 @@ const unagiiVaultAdapterTokens = [
unagiiVaultETHAddress,
];

const unagiiVaultV2AdapterTokens = [
unagiiVaultV2USDCAddress,
unagiiVaultV2DAIAddress,
unagiiVaultV2USDTAddress,
unagiiVaultV2WBTCAddress,
unagiiVaultV2ETHAddress,
];

let protocolNames = [];
let metadata = [];
let adapters = [];
Expand Down Expand Up @@ -1635,6 +1651,18 @@ module.exports = async (deployer, network, accounts) => {
'0',
]);

await deployer.deploy(UnagiiVaultV2Adapter, { from: accounts[0] });
adapters.push([UnagiiVaultV2Adapter.address]);
tokens.push([unagiiVaultV2AdapterTokens]);
protocolNames.push('Unagii V2');
metadata.push([
'Unagii V2',
'DeFi yields on auto-pilot.',
'unagii.com',
'protocol-icons.s3.amazonaws.com/unagii.png',
'0',
]);

await deployer.deploy(ERC20TokenAdapter, { from: accounts[0] })
.then(() => {
tokenAdapters.push(
Expand Down Expand Up @@ -1785,6 +1813,12 @@ module.exports = async (deployer, network, accounts) => {
UnagiiVaultTokenAdapter.address,
);
});
await deployer.deploy(UnagiiVaultV2TokenAdapter, { from: accounts[0] })
.then(() => {
tokenAdapters.push(
UnagiiVaultV2TokenAdapter.address,
);
});
await deployer.deploy(LinkswapTokenAdapter, { from: accounts[0] })
.then(() => {
tokenAdapters.push(
Expand Down
41 changes: 41 additions & 0 deletions test/UnagiiV2Adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const TokenAdapter = artifacts.require('UnagiiVaultTokenAdapter');

contract('UnagiiVaultTokenAdapter', () => {
const uDAIV2Address = '0x9ce3018375d305CE3C3303A26eF62D3d2EB8561A';
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F';

let accounts;
let tokenAdapter;
const uDAIV2 = [
uDAIV2Address,
'unagii_Dai Stablecoin_v2',
'uDAIv2',
'18',
];

beforeEach(async () => {
accounts = await web3.eth.getAccounts();

await TokenAdapter.new({ from: accounts[0] })
.then((result) => {
tokenAdapter = result.contract;
});
});

it('should return correct components', async () => {
await tokenAdapter.methods['getComponents(address)'](uDAIV2Address)
.call()
.then((result) => {
assert.equal(result[0][0], daiAddress);
assert.equal(result[0][1], 'ERC20');
});
});

it('should return correct metadata', async () => {
await tokenAdapter.methods['getMetadata(address)'](uDAIV2Address)
.call()
.then((result) => {
assert.deepEqual(result, uDAIV2);
});
});
});