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

new: DefiDollar readonly adapters #1

Open
wants to merge 2 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
40 changes: 40 additions & 0 deletions contracts/adapters/defidollar/DefiDollarProtocolAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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";

/**
* @title Adapter for DefiDollar protocol.
* @dev Implementation of ProtocolAdapter interface.
* @author Manthankumar Satani <[email protected]>
*/
contract DefiDollarProtocolAdapter is ProtocolAdapter {
string public constant override adapterType = "Asset";

string public constant override tokenType = "ERC20";

/**
* @return Amount of DefiDollar tokens held by the given account.
* @param token Address of the DefiDollar Protocol tokens.
* @dev Implementation of ProtocolAdapter interface function.
*/
function getBalance(address token, address account) external view override returns (uint256) {
return ERC20(token).balanceOf(account);
}
}
54 changes: 54 additions & 0 deletions contracts/adapters/defidollar/DefiDollarTokenAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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";

/**
* @title Token adapter for DefiDollar protocol.
* @dev Implementation of TokenAdapter interface.
* @author Manthankumar Satani <[email protected]>
*/
contract DefiDollarTokenAdapter 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 interface function.
*/
function getComponents(address token) external view override returns (Component[] memory) {
Component[] memory underlyingTokens = new Component[](1);

underlyingTokens[0] = Component({ token: token, tokenType: "ERC20", rate: uint256(1e18) });

return underlyingTokens;
}
}
33 changes: 33 additions & 0 deletions test/DefiDollarTokenAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const TokenAdapter = artifacts.require('DefiDollarTokenAdapter');

contract('DefiDollarTokenAdapter', () => {
const tokenAddress = '0x5bc25f649fc4e26069ddf4cf4010f9f706c23831';

let accounts;
let tokenAdapter;
const DUSD = [tokenAddress, 'DefiDollar', 'DUSD', '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)'](tokenAddress)
.call()
.then((result) => {
console.dir(result, { depth: null });
});
});

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