Skip to content

Commit

Permalink
first cut
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Jul 24, 2020
1 parent 2acb0d2 commit 99e9647
Show file tree
Hide file tree
Showing 8 changed files with 437 additions and 73 deletions.
144 changes: 87 additions & 57 deletions contracts/DTFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@ pragma solidity ^0.5.7;
import './utils/Deployer.sol';
import './utils/Converter.sol';
import './interfaces/IERC20Template.sol';
import './interfaces/IFPLP.sol';

/**
* @title DTFactory contract
* @author Ocean Protocol Team
*
* @dev Implementation of Ocean DataTokens Factory
*
* DTFactory deploys DataToken proxy contracts.
* New DataToken proxy contracts are links to the template contract's bytecode.
* Proxy contract functionality is based on Ocean Protocol custom implementation of ERC1167 standard.
*/
* @title DTFactory contract
* @author Ocean Protocol Team
*
* @dev Implementation of Ocean DataTokens Factory
*
* DTFactory deploys DataToken proxy contracts.
* New DataToken proxy contracts are links to the template contract's bytecode.
* Proxy contract functionality is based on Ocean Protocol custom implementation of ERC1167 standard.
*/
contract DTFactory is Deployer, Converter {

address private tokenTemplate;
address private fplpTemplate;

uint256 private currentTokenCount = 1;
// cap has max uint256 (2^256 -1)
uint256 constant private cap =
115792089237316195423570985008687907853269984665640564039457584007913129639935;
string constant private TOKEN_NAME_PREFIX = 'DT';
uint256
private constant cap = 115792089237316195423570985008687907853269984665640564039457584007913129639935;
string private constant TOKEN_NAME_PREFIX = 'DT';

event TokenCreated(
address indexed newTokenAddress,
address indexed newTokenAddress,
address indexed templateAddress,
string indexed tokenName
);

event TokenRegistered(
address indexed tokenAddress,
string tokenName,
Expand All @@ -40,68 +43,56 @@ contract DTFactory is Deployer, Converter {
uint256 registeredAt,
string indexed blob
);


event FPLPCreated(
address indexed FPLPAddress,
address indexed basetoken,
address indexed datatoken,
uint256 ratio
);

/**
* @dev constructor
* Called on contract deployment. Could not be called with zero address parameters.
* @param _template refers to the address of a deployed DataToken contract.
*/
constructor(
address _template
)
public
{
constructor(address _template, address _fplp) public {
require(
_template != address(0),
_template != address(0) && _fplp != address(0),
'DTFactory: Invalid token factory initialization'
);
tokenTemplate = _template;
fplpTemplate = _fplp;
}

/**
* @dev Deploys new DataToken proxy contract.
* Template contract address could not be a zero address.
* Template contract address could not be a zero address.
* @return address of a new proxy DataToken contract
*/
function createToken(
string memory blob
)
public
returns (address token)
{

function createToken(string memory blob) public returns (address token) {
token = deploy(tokenTemplate);

require(
token != address(0),
'DTFactory: Failed to perform minimal deploy of a new token'
);

string memory name = concatenateStrings(
TOKEN_NAME_PREFIX,
TOKEN_NAME_PREFIX,
uintToString(currentTokenCount)
);
string memory symbol = name;
string memory symbol = name;

IERC20Template tokenInstance = IERC20Template(token);
tokenInstance.initialize(
name,
symbol,
msg.sender,
cap,
blob
);
tokenInstance.initialize(name, symbol, msg.sender, cap, blob);

require(
tokenInstance.isInitialized(),
'DTFactory: Unable to initialize token instance'
);

emit TokenCreated(
token,
tokenTemplate,
name
);
emit TokenCreated(token, tokenTemplate, name);

emit TokenRegistered(
token,
Expand All @@ -117,26 +108,65 @@ contract DTFactory is Deployer, Converter {
}

/**
* @dev get the current token index.
* @dev get the current token index.
* @return the current token count
*/
function getCurrentTokenIndex()
external
view
returns (uint256)
{
function getCurrentTokenIndex() external view returns (uint256) {
return currentTokenCount;
}

/**
* @dev get the token template address
* @return the template address
*/
function getTokenTemplate()
external
view
returns (address)
{
function getTokenTemplate() external view returns (address) {
return tokenTemplate;
}

/**
* @dev Deploys new FPLP proxy contract.
* @param _lpAddress address that is providing liquidity (usually datatoken minter)
* @param _basetoken base token address
* @param _datatoken data token address
* @param _ratio exchange rate (IE: How many basetokens are required to get a DataToken)
* @return address of a new proxy DataToken contract
*/
function createFPLP(
address _lpAddress,
address _basetoken,
address _datatoken,
uint256 _ratio
) public returns (address FPLPAddress) {
require(_lpAddress != address(0), 'Factory: Invalid LP, zero address');
require(
_basetoken != address(0),
'Factory: Invalid basetoken, zero address'
);
require(
_datatoken != address(0),
'Factory: Invalid datatoken, zero address'
);
require(
_basetoken != _datatoken,
'Factory: Invalid datatoken, equals basetoken'
);
require(_ratio > 0, 'Factory: Invalid ratio value');

FPLPAddress = deploy(fplpTemplate);

require(
FPLPAddress != address(0),
'Factory: Failed to perform minimal deploy of a new FPLP'
);

IFPLP fplpInstance = IFPLP(FPLPAddress);
fplpInstance.initialize(_lpAddress, _basetoken, _datatoken, _ratio);

require(
fplpInstance.isInitialized(),
'Factory: Unable to initialize fplp instance'
);

emit FPLPCreated(FPLPAddress, _basetoken, _datatoken, _ratio);
}
}
45 changes: 35 additions & 10 deletions contracts/interfaces/IERC20Template.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,42 @@ interface IERC20Template {
address minter,
uint256 cap,
string calldata blob
) external returns(bool);
function mint(address account, uint256 value)
external payable;
) external returns (bool);

function mint(address account, uint256 value) external payable;

function pause() external;

function unpause() external;

function setMinter(address minter) external;
function name() external view returns(string memory);
function symbol() external view returns(string memory);
function decimals() external view returns(uint256);

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint256);

function cap() external view returns (uint256);
function isMinter(address account) external view returns(bool);
function isInitialized() external view returns(bool);
function isPaused() external view returns(bool);
}

function isMinter(address account) external view returns (bool);

function isInitialized() external view returns (bool);

function isPaused() external view returns (bool);

function allowance(address owner, address spender)
external
view
returns (uint256);

function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);

function balanceOf(address account) external view returns (uint256);

function transfer(address to, uint256 value) external returns (bool);
}
20 changes: 20 additions & 0 deletions contracts/interfaces/IFPLP.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity >=0.5.0;

interface IFPLP {
function initialize(
address lpAddress,
address basetoken,
address datatoken,
uint256 ratio
) external returns (bool);

function isInitialized() external returns (bool);

function buyDataTokens(uint256 dtAmount) external returns (bool);

function getRatio() external returns (uint256);

function getTokens() external returns (address[] memory);

function getDTReserve() external returns (uint256);
}

0 comments on commit 99e9647

Please sign in to comment.