Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Have securityTokenRegistrar check namespaceRegistrar before allowing a ticker name to be registered #198

Open
wants to merge 5 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
14 changes: 12 additions & 2 deletions contracts/SecurityTokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ pragma solidity ^0.4.18;
import './interfaces/ISecurityTokenRegistrar.sol';
import './interfaces/IERC20.sol';
import './SecurityToken.sol';
import './interfaces/INameSpaceRegistrar.sol';

/**
* @title SecurityTokenRegistrar
* @dev Contract use to register the security token on Polymath platform
*/

contract SecurityTokenRegistrar is ISecurityTokenRegistrar {

string public VERSION = "2";
IERC20 public PolyToken; // Address of POLY token
address public polyCustomersAddress; // Address of the polymath-core Customers contract address
address public polyComplianceAddress; // Address of the polymath-core Compliance contract address
INameSpaceRegistrar public polyNameSpaceRegistrar; // NameSpaceRegistrar contract pointer


struct NameSpaceData {
address owner;
Expand Down Expand Up @@ -49,15 +51,18 @@ contract SecurityTokenRegistrar is ISecurityTokenRegistrar {
function SecurityTokenRegistrar(
address _polyTokenAddress,
address _polyCustomersAddress,
address _polyComplianceAddress
address _polyComplianceAddress,
address _polyNameSpaceRegistrarAddress
) public
{
require(_polyTokenAddress != address(0));
require(_polyCustomersAddress != address(0));
require(_polyComplianceAddress != address(0));
require(_polyNameSpaceRegistrarAddress != address(0));
PolyToken = IERC20(_polyTokenAddress);
polyCustomersAddress = _polyCustomersAddress;
polyComplianceAddress = _polyComplianceAddress;
polyNameSpaceRegistrar = INameSpaceRegistrar(_polyNameSpaceRegistrarAddress);
}

/**
Expand Down Expand Up @@ -128,7 +133,12 @@ contract SecurityTokenRegistrar is ISecurityTokenRegistrar {
require(nameSpace.owner != address(0));
require(_owner != address(0));
require(bytes(_name).length > 0 && bytes(_ticker).length > 0);

var(, _tickerTimeStamp) = polyNameSpaceRegistrar.getDetails(_nameSpaceName, _ticker);
require(_tickerTimeStamp + 90 days <= now);

require(PolyToken.transferFrom(msg.sender, nameSpace.owner, nameSpace.fee));

address newSecurityTokenAddress = new SecurityToken(
_name,
_ticker,
Expand Down
12 changes: 12 additions & 0 deletions contracts/interfaces/INameSpaceRegistrar.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pragma solidity ^0.4.18;


interface INameSpaceRegistrar {

function changeAdmin(address _admin, bool _valid) public;
function changeTokenOwner(string _nameSpace, string _symbol, address _newOwner) public;
function registerToken(string _nameSpace, string _symbol, string _description, string _contact, address _owner) public;
function getDetails(string _nameSpace, string _symbol) view public returns (address, uint256);
function getDescription(string _nameSpace, string _symbol) view public returns (string, string);

}
2 changes: 1 addition & 1 deletion migrations/1_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module.exports = async (deployer, network) => {
try{
await deployer.deploy(Customers, PolyToken);
await deployer.deploy(Compliance, Customers.address);
await deployer.deploy(SecurityTokenRegistrar, PolyToken, Customers.address, Compliance.address);
await deployer.deploy(NameSpaceRegistrar);
await deployer.deploy(SecurityTokenRegistrar, PolyToken, Customers.address, Compliance.address, NameSpaceRegistrar.address);
let compliance = await Compliance.deployed()
await compliance.setRegistrarAddress(SecurityTokenRegistrar.address);
console.log(`\nPolymath Network Smart Contracts Deployed:\n
Expand Down
8 changes: 6 additions & 2 deletions test/SecurityToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Compliance = artifacts.require('Compliance.sol');
const Registrar = artifacts.require('SecurityTokenRegistrar.sol');
const SimpleCappedOfferingFactory = artifacts.require('SimpleCappedOfferingFactory.sol');
const SimpleCappedOffering = artifacts.require('SimpleCappedOffering.sol');
const NameSpaceRegistrar = artifacts.require('./NameSpaceRegistrar.sol');
const BigNumber = web3.BigNumber;

const ethers = require('ethers');
Expand Down Expand Up @@ -111,16 +112,19 @@ contract('SecurityToken', accounts => {
let polyTokenRate = 100;
let investedAmount;
let POLY, customers, compliance, STRegistrar, securityToken;
let STAddress, templateAddress, offeringFactory, offeringFactory_2, offeringContract;
let STAddress, templateAddress, offeringFactory, offeringFactory_2, offeringContract, polyNameSpaceRegistrar;

before(async()=>{
POLY = await PolyToken.new();
customers = await Customers.new(POLY.address);
compliance = await Compliance.new(customers.address);
polyNameSpaceRegistrar = await NameSpaceRegistrar.new();
console.log("polyNameSpaceRegistrar " + polyNameSpaceRegistrar.address);
STRegistrar = await Registrar.new(
POLY.address,
customers.address,
compliance.address
compliance.address,
polyNameSpaceRegistrar.address
);
await compliance.setRegistrarAddress(STRegistrar.address);
// Adding the new KYC provider in to the Polymath Platform chain data
Expand Down
9 changes: 7 additions & 2 deletions test/SecurityTokenRegistrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const SecurityToken = artifacts.require('./SecurityToken.sol');
const POLY = artifacts.require('./helpers/mockContracts/PolyTokenMock.sol');
const Compliance = artifacts.require('./Compliance.sol');
const Customers = artifacts.require('./Customers.sol');
const NameSpaceRegistrar = artifacts.require('./NameSpaceRegistrar.sol');


contract('SecurityTokenRegistrar', accounts => {
Expand All @@ -32,18 +33,22 @@ contract('SecurityTokenRegistrar', accounts => {
let acct2 = accounts[2];
let issuer2 = accounts[3];
let issuer1 = accounts[4];
let polyToken, polyCustomers, polyCompliance, STRegistrar;
let polyToken, polyCustomers, polyCompliance, STRegistrar, polyNameSpaceRegistrar;

beforeEach(async () => {
polyToken = await POLY.new();
polyCustomers = await Customers.new(polyToken.address);
polyCompliance = await Compliance.new(polyCustomers.address);
polyNameSpaceRegistrar = await NameSpaceRegistrar.new();
console.log("polyNameSpaceRegistrar " + polyNameSpaceRegistrar.address);
// Creation of the new SecurityTokenRegistrar contract
STRegistrar = await SecurityTokenRegistrar.new(
polyToken.address,
polyCustomers.address,
polyCompliance.address
polyCompliance.address,
polyNameSpaceRegistrar.address
);

})

describe('Constructor', async () => {
Expand Down