diff --git a/contracts/adapters/defidollar/DefiDollarProtocolAdapter.sol b/contracts/adapters/defidollar/DefiDollarProtocolAdapter.sol new file mode 100644 index 00000000..14fbc16c --- /dev/null +++ b/contracts/adapters/defidollar/DefiDollarProtocolAdapter.sol @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Zerion Inc. +// +// 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 . + +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 + */ +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); + } +} diff --git a/contracts/adapters/defidollar/DefiDollarTokenAdapter.sol b/contracts/adapters/defidollar/DefiDollarTokenAdapter.sol new file mode 100644 index 00000000..eee10354 --- /dev/null +++ b/contracts/adapters/defidollar/DefiDollarTokenAdapter.sol @@ -0,0 +1,54 @@ +// Copyright (C) 2020 Zerion Inc. +// +// 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 . + +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 + */ +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; + } +} diff --git a/test/DefiDollarTokenAdapter.js b/test/DefiDollarTokenAdapter.js new file mode 100644 index 00000000..28cff368 --- /dev/null +++ b/test/DefiDollarTokenAdapter.js @@ -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); + }); + }); +});