Skip to content

Commit

Permalink
intial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyamSB committed Oct 10, 2018
1 parent 5d3e9a0 commit 4a8a473
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 148 deletions.
23 changes: 23 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.4.23;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
157 changes: 9 additions & 148 deletions ReferenceImplementation.sol → contracts/PartialFungibleToken.sol
Original file line number Diff line number Diff line change
@@ -1,150 +1,11 @@
// This is a work in progress currently based on an older version of the specification.

pragma solidity ^0.4.24;

interface IERCPFT {

/// @notice A descriptive name for tokens in this contract
function name() external view returns (string _name);

/// @notice An abbreviated name for tokens in this contract
function symbol() external view returns (string _symbol);

/// @notice Counts the sum of all tranche balances assigned to an owner
/// @param _owner An address for whom to query the balance
/// @return The number of tokens owned by `_owner`, possibly zero
function balanceOf(address _owner) external view returns (uint256);

/// @notice Counts the balance associated with a specific tranche assigned to an owner
/// @param _tranche The tranche for which to query the balance
/// @param _owner An address for whom to query the balance
/// @return The number of tokens owned by `_owner` with the metadata associated with `_tranche`, possibly zero
function balanceOfTranche(bytes32 _tranche, address _owner) external view returns (uint256);

/// @notice Count all tokens tracked by this contract
/// @return A count of all tokens tracked by this contract
function totalSupply() external view returns (uint256);

/// @notice Transfers the ownership of tokens from a specified tranche from one address to another address
/// @param _tranche The tranche from which to transfer tokens
/// @param _to The address to which to transfer tokens to
/// @param _amount The amount of tokens to transfer from `_tranche`
/// @param _data Additional data attached to the transfer of tokens
/// @return A reason code related to the success of the send operation
/// @return The tranche to which the transferred tokens were allocated for the _to address
function sendTranche(bytes32 _tranche, address _to, uint256 _amount, bytes _data) external returns (byte, bytes32);

/// @notice Transfers the ownership of tokens from a specified tranche from one address to another address
/// @param _tranche The tranche from which to transfer tokens
/// @param _from The address from which to transfer tokens from
/// @param _to The address to which to transfer tokens to
/// @param _amount The amount of tokens to transfer from `_tranche`
/// @param _data Additional data attached to the transfer of tokens
/// @param _operatorData Additional data attached to the transfer of tokens by the operator
/// @return A reason code related to the success of the send operation
/// @return The tranche to which the transferred tokens were allocated for the _to address
function operatorSendTranche(bytes32 _tranche, address _from, address _to, uint256 _amount, bytes _data, bytes _operatorData) external returns (byte, bytes32);

/// @notice Allows enumeration over an individual owners tranches
/// @param _owner An address over which to enumerate tranches
/// @param _index The index of the tranche
/// @return The tranche key corresponding to `_index`
function trancheByIndex(address _owner, uint256 _index) external view returns (bytes32);

/// @notice Enables caller to determine the count of tranches owned by an address
/// @param _owner An address over which to enumerate tranches
/// @return The number of tranches owned by an `_owner`
function tranchesOf(address _owner) external view returns (uint256);

/// @notice Defines a list of operators which can operate over all addresses and tranches
/// @return The list of default operators
function defaultOperators() public view returns (address[]);

/// @notice Defines a list of operators which can operate over all addresses for the specified tranche
/// @return The list of default operators for `_tranche`
function defaultOperatorsTranche(bytes32 _tranche) public view returns (address[]);

/// @notice Authorises an operator for all tranches of `msg.sender`
/// @param _operator An address which is being authorised
function authorizeOperator(address _operator) public;

/// @notice Authorises an operator for a given tranche of `msg.sender`
/// @param _tranche The tranche to which the operator is authorised
/// @param _operator An address which is being authorised
function authorizeOperatorTranche(bytes32 _tranche, address _operator) public;

/// @notice Revokes authorisation of an operator previously given for all tranches of `msg.sender`
/// @param _operator An address which is being de-authorised
function revokeOperator(address _operator) public;

/// @notice Revokes authorisation of an operator previously given for a specified tranche of `msg.sender`
/// @param _tranche The tranche to which the operator is de-authorised
/// @param _operator An address which is being de-authorised
function revokeOperatorTranche(bytes32 _tranche, address _operator) public;

/// @notice Determines whether `_operator` is an operator for all tranches of `_owner`
/// @param _operator The operator to check
/// @param _owner The owner to check
/// @return Whether the `_operator` is an operator for all tranches of `_owner`
function isOperatorFor(address _operator, address _owner) public view returns (bool);

/// @notice Determines whether `_operator` is an operator for a specified tranche of `_owner`
/// @param _tranche The tranche to check
/// @param _operator The operator to check
/// @param _owner The owner to check
/// @return Whether the `_operator` is an operator for a specified tranche of `_owner`
function isOperatorForTranche(bytes32 _tranche, address _operator, address _owner) public view returns (bool);

/// @notice Increases totalSupply and the corresponding amount of the specified owners tranche
/// @param _tranche The tranche to allocate the increase in balance
/// @param _owner The owner whose balance should be increased
/// @param _amount The amount by which to increase the balance
/// @param _data Additional data attached to the minting of tokens
/// @return A reason code related to the success of the mint operation
function mint(bytes32 _tranche, address _owner, uint256 _amount, bytes _data) public returns (byte reason);

/// @notice Decreases totalSupply and the corresponding amount of the specified owners tranche
/// @param _tranche The tranche to allocate the decrease in balance
/// @param _owner The owner whose balance should be decreased
/// @param _amount The amount by which to decrease the balance
/// @param _data Additional data attached to the burning of tokens
/// @return A reason code related to the success of the burn operation
function burn(bytes32 _tranche, address _owner, uint256 _amount, bytes _data) public returns (byte reason);

/// @notice This emits on any successful call to `mint`
event Minted(address indexed owner, bytes32 tranche, uint256 amount, bytes data);

/// @notice This emits on any successful call to `burn`
event Burnt(address indexed owner, bytes32 tranche, uint256 amount, bytes data);

/// @notice This emits on any successful transfer or minting of tokens
event SentTranche(
address indexed operator,
address indexed from,
address indexed to,
bytes32 fromTranche,
bytes32 toTranche,
uint256 amount,
bytes data,
bytes operatorData
);

/// @notice This emits on any successful operator approval for all tranches, excluding default operators
event AuthorizedOperator(address indexed operator, address indexed owner);

/// @notice This emits on any successful operator approval for a single tranche, excluding default tranche operators
event AuthorizedOperatorTranche(bytes32 indexed tranche, address indexed operator, address indexed owner);

/// @notice This emits on any successful revoke of an operators approval for all tranches
event RevokedOperator(address indexed operator, address indexed owner);

/// @notice This emits on any successful revoke of an operators approval for a single tranche
event RevokedOperatorTranche(bytes32 indexed tranche, address indexed operator, address indexed owner);

}
import "./interfaces/IERC1410.sol";

// Reference implementation of partially-fungible tokens
contract PFT is IERCPFT {
/**
* @title Reference implementation of partially-fungible tokens
*/
contract PartialFungibleToken is IERC1410 {

// Represents a fungible set of tokens.
struct Tranche {
Expand Down Expand Up @@ -174,7 +35,7 @@ contract PFT is IERCPFT {
mapping (address => mapping (address => bool)) approvals;

// Returns sum of amounts over all owned fungible token sets for investor
function balanceOf(address _owner) public view returns (uint256) {
function balanceOf(address _owner) external view returns (uint256) {
return balances[_owner];
}

Expand All @@ -185,7 +46,7 @@ contract PFT is IERCPFT {

// Transfers tokens from the sender to the _to address, keeping the _tranche the same
function sendTranche(bytes32 _tranche, address _to, uint256 _amount, bytes _data) external returns (byte, bytes32) {
(byte reason, bytes32 newTranche) = _sendTranche(msg.sender, _to, _tranche, _amount, _data, '');
(byte reason, bytes32 newTranche) = _sendTranche(msg.sender, _to, _amount, _tranche, _data, '');
emit SentTranche(
address(0),
msg.sender,
Expand All @@ -199,9 +60,9 @@ contract PFT is IERCPFT {
return (reason, newTranche);
}

function _sendTranche(bytes32 _tranche, address _from, address _to, uint256 _amount, bytes _data, bytes _operatorData) internal returns (byte, bytes32) {
function _sendTranche(address _from, address _to, uint256 _amount, bytes32 _tranche, bytes _data, bytes _operatorData) internal returns (byte, bytes32) {

if (balanceOfTranche(msg.sender, _tranche) < _amount) {
if (balanceOfTranche(_from, _tranche) < _amount) {
return (hex"00", bytes32(''));
}

Expand Down
38 changes: 38 additions & 0 deletions contracts/interfaces/ERC777Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pragma solidity ^0.4.24;

/**
* @title Interface of ERC777 standard
* @dev ref. https://eips.ethereum.org/EIPS/eip-777
*/

interface ERC777Token {
function name() external view returns (string);
function symbol() external view returns (string);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function granularity() external view returns (uint256);

function defaultOperators() external view returns (address[]);
function authorizeOperator(address operator) public;
function revokeOperator(address operator) public;
function isOperatorFor(address operator, address tokenHolder) public view returns (bool);

function send(address to, uint256 amount, bytes data) external;
function operatorSend(address from, address to, uint256 amount, bytes data, bytes operatorData) external;

function burn(uint256 amount, bytes data) public;
function operatorBurn(address from, uint256 amount, bytes data, bytes operatorData) external;

event Sent(
address indexed operator,
address indexed from,
address indexed to,
uint256 amount,
bytes data,
bytes operatorData
);
event Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData);
event Burned(address indexed operator, address indexed from, uint256 amount, bytes operatorData);
event AuthorizedOperator(address indexed operator, address indexed tokenHolder);
event RevokedOperator(address indexed operator, address indexed tokenHolder);
}
Loading

0 comments on commit 4a8a473

Please sign in to comment.