Skip to content

Commit

Permalink
Merge pull request #16 from oceanprotocol/develop
Browse files Browse the repository at this point in the history
Merge everything before switching to truffle
  • Loading branch information
arseneeth authored Apr 22, 2020
2 parents bc62913 + 5382270 commit 6994058
Show file tree
Hide file tree
Showing 10 changed files with 22,912 additions and 6,234 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sol linguist-language=Solidity
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
/node_modules
.openzeppelin/.session
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# ocean-contracts


```
npm install @openzeppelin/cli
npm install --save-dev mocha chai
npm install --save-dev @openzeppelin/test-helpers
npm install --save-dev @openzeppelin/test-environment
npm install @openzeppelin/contracts-ethereum-package
```


```
oz compile
npm test
```
53 changes: 41 additions & 12 deletions contracts/DataToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.3;
pragma solidity ^0.5.0;

import './Fees.sol';
import './TokenFactory.sol';
Expand All @@ -21,29 +21,40 @@ contract DataToken is Initializable, ERC20, Fees, Ownable {
string public metadata;
TokenFactory public factory;

event Initialized(address indexed thisAddress);
bool public initialized = false;

event Initialized(
address indexed thisAddress
);

event TokenMinted(
address indexed to,
uint256 amount,
uint256 fee,
uint256 cashBack
);

/**
* @notice initializer
* @param _metadata Data token metadata
* @param _publisher publisher(contract owner) address
*/
function initialize(
string memory _metadata,
string memory _metadata,
address _publisher
)
public
initializer
{

Ownable.initialize(_publisher);

factory = TokenFactory(msg.sender);
metadata = _metadata;

uint256 tokenNumber = factory.getTokenCount();
uint256 tokenNumber = factory.tokenCount();

symbol = string(abi.encodePacked('ODT-', tokenNumber.add(1)));
name = string(abi.encodePacked('OceanDataToken-', tokenNumber.add(1)));
symbol = string(abi.encodePacked('ODT-', tokenNumber.add(1)));
name = string(abi.encodePacked('OceanDataToken-', tokenNumber.add(1)));
initialized = true;

emit Initialized(address(this));
}
Expand All @@ -61,14 +72,32 @@ contract DataToken is Initializable, ERC20, Fees, Ownable {
payable
onlyOwner
{
uint256 startGas = gasleft();
//additional check so it does not revert with SafeMath: subtraction overflow
require(msg.value > 0,
"fee amount is not enough");

uint256 startGas = gasleft();
address payable beneficiary = factory.beneficiary();
address payable sender = msg.sender;

//mint tokens
_mint(address(this), _amount);

uint256 fee = _getFee(startGas);
uint256 cashback = _getCashback(fee, msg.value);

// discuss: change to "=="
require(msg.value >= fee,
"fee amount is not enough");

require(_isPayed(startGas, msg.value),
"fee is not payed");
//TODO: add transfer fee to beneficiary
//transfer fee to beneficiary
beneficiary.transfer(fee);
// return cashback
sender.transfer(cashback);

_transfer(address(this), _to, _amount);

emit TokenMinted(_to, _amount, fee, cashback);
}

}
19 changes: 14 additions & 5 deletions contracts/Fees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ contract Fees {

using SafeMath for uint256;

function _isPayed(
uint256 _startGas,
uint256 _msgValue
function _getFee(
uint256 _startGas
)
public
view
returns(bool)
returns(uint256)
{
uint256 usedGas = _startGas.sub(gasleft());
return usedGas.mul(tx.gasprice) >= _msgValue; //TODO: should be changed to '=='
return usedGas.mul(tx.gasprice);
}

function _getCashback(
uint256 _fee,
uint256 _payed
)
public
pure
returns(uint256)
{
return _payed.sub(_fee);
}
}
62 changes: 31 additions & 31 deletions contracts/TokenFactory.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity ^0.5.3;
pragma solidity ^0.5.0;

import './Fees.sol';
import './DataToken.sol';
import '@openzeppelin/upgrades/contracts/upgradeability/ProxyFactory.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol';
import '@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol';
import '@openzeppelin/upgrades/contracts/upgradeability/ProxyFactory.sol';

/**
* @title TokenFactory
Expand All @@ -14,9 +14,9 @@ contract TokenFactory is ProxyFactory, Ownable, Fees {

using SafeMath for uint256;

address payable beneficiary;
address public template;
uint256 public tokenCount;
address payable public beneficiary;
address public template;
uint256 public tokenCount;

mapping (uint256 => address) idToToken;
mapping (address => uint256) tokenToId;
Expand Down Expand Up @@ -48,21 +48,33 @@ contract TokenFactory is ProxyFactory, Ownable, Fees {
)
public
payable
returns(address)
{
uint256 startGas = gasleft();

bytes memory _payload = abi.encodeWithSignature("initialize(string, address)", _metadata, msg.sender);
address token = deployMinimal(template, _payload);

tokenCount = tokenCount.add(1);
idToToken[tokenCount] = token;
tokenToId[token] = tokenCount;

require(_isPayed(startGas, msg.value),
"fee is not payed");
//TODO: add transfer fee to beneficiary
uint256 startGas = gasleft();

bytes memory _payload = abi.encodeWithSignature("initialize(string,address)", _metadata, msg.sender);
address token = deployMinimal(template, _payload);
address payable sender = msg.sender;

tokenCount = tokenCount.add(1);
idToToken[tokenCount] = token;
tokenToId[token] = tokenCount;

uint256 fee = _getFee(startGas);

// discuss: change to "=="
require(msg.value >= fee,
"fee amount is not enough");

//transfer fee to beneficiary
beneficiary.transfer(fee);
// return cashback
sender.transfer(_getCashback(fee, msg.value));

return token;
}


/**
* @notice Get Data Token contract address
* @param tokenId token id
Expand Down Expand Up @@ -94,20 +106,8 @@ contract TokenFactory is ProxyFactory, Ownable, Fees {
}

/**
* @notice Get total number of tokens deployed
* @return number of tokens deployed
*/
function getTokenCount()
public
view
returns(uint256)
{
return tokenCount;
}

/**
* @notice Change beneficiarry address(only contract owner can do that)
* @param newBeneficiary new beneficiarry address
* @notice Change beneficiary address(only contract owner can do that)
* @param newBeneficiary new beneficiary address
*/
function changeBeneficiary(
address payable newBeneficiary
Expand Down
Loading

0 comments on commit 6994058

Please sign in to comment.