Advertisement
Guest User

Payday Source Code (ATS Compliant Token)

a guest
Feb 22nd, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity 0.4.15;
  2.  
  3. library SafeMath {
  4.     function mul(uint128 _a, uint128 _b) internal constant returns (uint128 c) {
  5.         if (_a == 0) {
  6.             return 0;
  7.         }
  8.         c = _a * _b;
  9.         require(c / _a == _b);
  10.         return c;
  11.     }
  12.  
  13.     function div(uint128 _a, uint128 _b) internal constant returns (uint128) {
  14.         require(_b > 0);
  15.         return _a / _b;
  16.     }
  17.  
  18.     function sub(uint128 _a, uint128 _b) internal constant returns (uint128) {
  19.         require(_b <= _a);
  20.         return _a - _b;
  21.     }
  22.  
  23.     function add(uint128 _a, uint128 _b) internal constant returns (uint128 c) {
  24.         c = _a + _b;
  25.         require(c >= _a);
  26.         return c;
  27.     }
  28. }
  29.  
  30. interface ATS {
  31.     function name() public constant returns (string);
  32.     function symbol() public constant returns (string);
  33.     function totalSupply() public constant returns (uint128);
  34.     function liquidSupply() public constant returns (uint128);
  35.     function balanceOf(address owner) public constant returns (uint128);
  36.     function granularity() public constant returns (uint128);
  37.     function isOperatorFor(address operator, address tokenHolder) public constant returns (bool);
  38.     function authorizeOperator(address operator) public;
  39.     function revokeOperator(address operator) public;
  40.  
  41.     function send(address to, uint128 amount, bytes holderData) public;
  42.     function operatorSend(address from, address to, uint128 amount, bytes holderData, bytes operatorData) public;
  43.     function burn(uint128 amount, bytes holderData) public;
  44.     function operatorBurn(address from, uint128 amount, bytes holderData, bytes operatorData) public;
  45.     function thaw(address localRecipient, uint128 amount, bytes32 bridgeId, bytes bridgeData,
  46.                    bytes32 remoteSender, bytes32 remoteBridgeId, bytes remoteData) public;    
  47.     function freeze(bytes32 remoteRecipient, uint128 amount, bytes32 bridgeId, bytes localData) public;
  48.     function operatorFreeze(address localSender, bytes32 remoteRecipient, uint128 amount, bytes32 bridgeId,
  49.                              bytes localData) public;
  50.  
  51.     event Created(
  52.         uint128 indexed     _totalSupply,
  53.         address indexed     _creator);
  54.  
  55.     event Sent(
  56.         address indexed     _operator,
  57.         address indexed     _from,
  58.         address indexed     _to,
  59.         uint128             _amount,
  60.         bytes               _holderData,
  61.         bytes               _operatorData);
  62.  
  63.     event Thawed(
  64.         address indexed localRecipient,
  65.         uint128 amount,
  66.         bytes32 indexed bridgeId,
  67.         bytes bridgeData,
  68.         bytes32 indexed remoteSender,
  69.         bytes32 remoteBridgeId,
  70.         bytes remoteData);
  71.  
  72.     event Froze(
  73.         address indexed localSender,
  74.         bytes32 indexed remoteRecipient,
  75.         uint128 amount,
  76.         bytes32 indexed bridgeId,
  77.         bytes localData);
  78.  
  79.     event Minted(
  80.         address indexed     _operator,
  81.         address indexed     _to,
  82.         uint128             _amount,
  83.         bytes               _operatorData);
  84.  
  85.     event Burned(
  86.         address indexed     _operator,
  87.         address indexed     _from,
  88.         uint128             _amount,
  89.         bytes               _holderData,
  90.         bytes               _operatorData);
  91.  
  92.     event AuthorizedOperator(
  93.         address indexed     _Eoperator,
  94.         address indexed     _tokenHolder);
  95.  
  96.     event RevokedOperator(
  97.         address indexed     _operator,
  98.         address indexed     _tokenHolder);
  99. }
  100.  
  101. contract ERC20 {
  102.     function totalSupply() public constant returns (uint128);
  103.     function balanceOf(address _who) public constant returns (uint128);
  104.     function allowance(address _owner, address _spender) public constant returns (uint128);
  105.     function transfer(address _to, uint128 _value) public returns (bool);
  106.     function approve(address _spender, uint128 _value) public returns (bool);
  107.     function transferFrom(address _from, address _to, uint128 _value) public returns (bool);
  108.  
  109.     event Transfer(
  110.         address indexed from,
  111.         address indexed to,
  112.         uint128 value
  113.     );
  114.  
  115.     event Approval(
  116.         address indexed owner,
  117.         address indexed spender,
  118.         uint128 value
  119.     );
  120. }
  121.  
  122. contract AionInterfaceRegistry {
  123.     function getManager(address target) public constant returns(address);
  124.     function setManager(address target, address manager) public;
  125.     function getInterfaceDelegate(address target, bytes32 interfaceHash) public constant returns (address);
  126.     function setInterfaceDelegate(address target, bytes32 interfaceHash, address delegate) public;
  127. }
  128.  
  129. contract AionInterfaceImplementer {
  130.     AionInterfaceRegistry air=AionInterfaceRegistry(0xa0d270e7759e8fc020df5f1352bf4d329342c1bcdfe9297ef594fa352c7cab26);
  131.  
  132.     function setInterfaceDelegate(string _interfaceLabel, address impl) internal {
  133.         bytes32 interfaceHash = sha3(_interfaceLabel);
  134.         air.setInterfaceDelegate(this, interfaceHash, impl);
  135.     }
  136.  
  137.     function getInterfaceDelegate(address addr, string _interfaceLabel) internal constant returns(address) {
  138.         bytes32 interfaceHash = sha3(_interfaceLabel);
  139.         return air.getInterfaceDelegate(addr, interfaceHash);
  140.     }
  141.  
  142.     function setDelegateManager(address _newManager) internal {
  143.         air.setManager(this, _newManager);
  144.     }
  145. }
  146.  
  147. interface ATSTokenRecipient {
  148.     function tokensReceived(
  149.         address operator,
  150.         address from,
  151.         address to,
  152.         uint128 amount,
  153.         bytes userData,
  154.         bytes operatorData
  155.     ) public;
  156. }
  157.  
  158. interface ATSTokenSender {
  159.     function tokensToSend(
  160.         address operator,
  161.         address from,
  162.         address to,
  163.         uint128 amount,
  164.         bytes userData,
  165.         bytes operatorData
  166.     ) public;
  167. }
  168.  
  169.  
  170.  
  171.   ///////////////////////////////////////////////////
  172.  ////////////// Contract Begins Here ///////////////
  173. ///////////////////////////////////////////////////
  174.  
  175. contract ATSImpl is ATS, ERC20, AionInterfaceImplementer {
  176.     using SafeMath for uint128;
  177.     address constant internal addressTypeMask = 0xFF00000000000000000000000000000000000000000000000000000000000000;
  178.     address constant internal zeroAddress = 0x0000000000000000000000000000000000000000000000000000000000000000;
  179.  
  180.     string internal mName;
  181.     string internal mSymbol;
  182.     uint128 internal mGranularity;
  183.     uint128 internal mTotalSupply;
  184.     uint128 internal transaction;
  185.     uint128 internal pool=0;
  186.     uint128 internal burnRate = 1;
  187.     uint128 internal prizeRate = 24;
  188.  
  189.     mapping(address => uint128) internal mBalances;
  190.     mapping(address => mapping(address => bool)) internal mAuthorized;
  191.     mapping(address => mapping(address => uint128)) internal mAllowed;
  192.  
  193.  
  194.     //ATS Constructor Function    
  195.     function ATSImpl() {
  196.        
  197.         mName = "Payday";
  198.         mSymbol = "PAY";
  199.         mTotalSupply = 500000*10**18; //500k initial supply
  200.         mGranularity = 1;
  201.         require(mGranularity >= 1);
  202.         initialize(mTotalSupply);
  203.  
  204.         // register onto CIR
  205.         setInterfaceDelegate("AIP004Token", this);
  206.     }
  207.  
  208.  
  209.     function initialize(uint128 _totalSupply) internal {
  210.         mBalances[msg.sender] = _totalSupply;
  211.         Created(_totalSupply, msg.sender);
  212.         transaction = 0;
  213.         pool = 0;
  214.     }
  215.  
  216.  
  217.       ///////////////////////////////////////////////////
  218.      /////////////// ERC-777 Compliance ////////////////
  219.     ///////////////////////////////////////////////////
  220.     function name() public constant returns (string) { return mName; }
  221.     function symbol() public constant returns (string) { return mSymbol; }
  222.     function granularity() public constant returns (uint128) { return mGranularity; }
  223.     function totalSupply() public constant returns (uint128) { return mTotalSupply; }
  224.     function balanceOf(address _tokenHolder) public constant returns (uint128) { return mBalances[_tokenHolder]; }
  225.  
  226.     function send(address _to, uint128 _amount, bytes _userData) public {
  227.         doSend(msg.sender, msg.sender, _to, _amount, _userData, "", true);
  228.     }
  229.  
  230.     function authorizeOperator(address _operator) public {
  231.         require(_operator != msg.sender);
  232.         mAuthorized[_operator][msg.sender] = true;
  233.         AuthorizedOperator(_operator, msg.sender);
  234.     }
  235.  
  236.     function revokeOperator(address _operator) public {
  237.         require(_operator != msg.sender);
  238.         mAuthorized[_operator][msg.sender] = false;
  239.         RevokedOperator(_operator, msg.sender);
  240.     }
  241.  
  242.     function isOperatorFor(address _operator, address _tokenHolder) public constant returns (bool) {
  243.         return (_operator == _tokenHolder || mAuthorized[_operator][_tokenHolder]);
  244.     }
  245.  
  246.     function operatorSend(address _from, address _to, uint128 _amount, bytes _userData, bytes _operatorData) public {
  247.         require(isOperatorFor(msg.sender, _from));
  248.         doSend(msg.sender, _from, _to, _amount, _userData, _operatorData, true);
  249.     }
  250.  
  251.     function burn(uint128 _amount, bytes _holderData) public {
  252.         doBurn(msg.sender, msg.sender, _amount, _holderData, "");
  253.     }
  254.  
  255.     function operatorBurn(address _tokenHolder, uint128 _amount, bytes _holderData, bytes _operatorData) public {
  256.         require(isOperatorFor(msg.sender, _tokenHolder));
  257.         doBurn(msg.sender, _tokenHolder, _amount, _holderData, _operatorData);
  258.     }
  259.  
  260.       ///////////////////////////////////////////////////
  261.      //////////////// Helper Functions /////////////////
  262.     ///////////////////////////////////////////////////
  263.     function requireMultiple(uint128 _amount) internal constant {
  264.         require(_amount.div(mGranularity).mul(mGranularity) == _amount);
  265.     }
  266.  
  267.     function isRegularAddress(address _addr) internal constant returns (bool) {
  268.         return true;
  269.     }
  270.  
  271.     function doSend(
  272.         address _operator,
  273.         address _from,
  274.         address _to,
  275.         uint128 _amount,
  276.         bytes _userData,
  277.         bytes _operatorData,
  278.         bool _preventLocking
  279.     )
  280.    
  281.     internal    {
  282.         requireMultiple(_amount);
  283.  
  284.         callSender(_operator, _from, _to, _amount, _userData, _operatorData);
  285.  
  286.         require(_to != address(0));             // forbid sending to 0x0 (=burning)
  287.         require(_to != address(this));          // forbid sending to the contract itself
  288.         require(mBalances[_from] >= _amount);   // ensure enough funds
  289.         pool = pool.add(_amount*24/100);
  290.  
  291.         // Increments tx counter
  292.         transaction = transaction+1;
  293.         // Removes tx from sender's address
  294.         mBalances[_from] = mBalances[_from].sub(_amount);
  295.         // Shrinks Supply by 1% of tx
  296.         mTotalSupply = mTotalSupply.sub(_amount/100);
  297.         // Sends 99% of the tx to recipient
  298.         mBalances[_to] = mBalances[_to].add(_amount*75/100);
  299.        
  300.         // Checks to see if sender is the lucky 10th sender
  301.         if (transaction==10) {
  302.             //Rewards prize pool to lucky winner and resets tx counter.
  303.             mBalances[_from] = mBalances[_from].add(pool);
  304.             transaction=0;
  305.         }
  306.  
  307.         callRecipient(_operator, _from, _to, _amount, _userData, _operatorData, _preventLocking);
  308.  
  309.         Sent(_operator, _from, _to, _amount, _userData, _operatorData);
  310.     }
  311.  
  312.  
  313.     function doBurn(address _operator, address _tokenHolder, uint128 _amount, bytes _holderData, bytes _operatorData)
  314.        
  315.     internal {
  316.         requireMultiple(_amount);
  317.         require(balanceOf(_tokenHolder) >= _amount);
  318.  
  319.         mBalances[_tokenHolder] = mBalances[_tokenHolder].sub(_amount);
  320.         mTotalSupply = mTotalSupply.sub(_amount);
  321.  
  322.         callSender(_operator, _tokenHolder, 0x0, _amount, _holderData, _operatorData);
  323.         Burned(_operator, _tokenHolder, _amount, _holderData, _operatorData);
  324.     }
  325.  
  326.  
  327.     function callRecipient(
  328.         address _operator,
  329.         address _from,
  330.         address _to,
  331.         uint128 _amount,
  332.         bytes _userData,
  333.         bytes _operatorData,
  334.         bool _preventLocking
  335.     )
  336.        
  337.     internal {
  338.         address recipientImplementation = getInterfaceDelegate(_to, "AIP004TokenRecipient");
  339.         if (recipientImplementation != 0) {
  340.             ATSTokenRecipient(recipientImplementation).tokensReceived(
  341.                 _operator, _from, _to, _amount, _userData, _operatorData);
  342.         } else if (_preventLocking) {
  343.             require(isRegularAddress(_to));
  344.         }
  345.     }
  346.  
  347.  
  348.     function callSender(
  349.         address _operator,
  350.         address _from,
  351.         address _to,
  352.         uint128 _amount,
  353.         bytes _userData,
  354.         bytes _operatorData
  355.     )
  356.        
  357.     internal {
  358.         address senderImplementation = getInterfaceDelegate(_from, "AIP004TokenSender");
  359.         if (senderImplementation == 0) { return; }
  360.         ATSTokenSender(senderImplementation).tokensToSend(_operator, _from, _to, _amount, _userData, _operatorData);
  361.     }
  362.  
  363.  
  364.     function liquidSupply() public constant returns (uint128) {
  365.         return mTotalSupply.sub(balanceOf(this));
  366.     }
  367.  
  368.  
  369.       ///////////////////////////////////////////////////
  370.      ///////////// Cross-Chain Compliance //////////////
  371.     ///////////////////////////////////////////////////
  372.     function thaw(
  373.         address localRecipient,
  374.         uint128 amount,
  375.         bytes32 bridgeId,
  376.         bytes bridgeData,
  377.         bytes32 remoteSender,
  378.         bytes32 remoteBridgeId,
  379.         bytes remoteData)
  380.     public {
  381.  
  382.     }
  383.  
  384.     function freeze(
  385.         bytes32 remoteRecipient,
  386.         uint128 amount,
  387.         bytes32 bridgeId,
  388.         bytes localData)
  389.     public {
  390.  
  391.     }
  392.  
  393.     function operatorFreeze(address localSender,
  394.         bytes32 remoteRecipient,
  395.         uint128 amount,
  396.         bytes32 bridgeId,
  397.         bytes localData)
  398.     public {
  399.  
  400.     }
  401.  
  402.       ///////////////////////////////////////////////////
  403.      /////////////// ERC-20 Compliance /////////////////
  404.     ///////////////////////////////////////////////////
  405.     function decimals() public constant returns (uint8) {
  406.         return uint8(18);
  407.     }
  408.  
  409.     function transfer(address _to, uint128 _amount) public returns (bool success) {
  410.         doSend(msg.sender, msg.sender, _to, _amount, "", "", false);
  411.         return true;
  412.     }
  413.  
  414.     function transferFrom(address _from, address _to, uint128 _amount) public returns (bool success) {
  415.         require(_amount <= mAllowed[_from][msg.sender]);
  416.  
  417.         mAllowed[_from][msg.sender] = mAllowed[_from][msg.sender].sub(_amount);
  418.         doSend(msg.sender, _from, _to, _amount, "", "", false);
  419.         return true;
  420.     }
  421.  
  422.     function approve(address _spender, uint128 _amount) public returns (bool success) {
  423.         mAllowed[msg.sender][_spender] = _amount;
  424.         Approval(msg.sender, _spender, _amount);
  425.         return true;
  426.     }
  427.  
  428.     function allowance(address _owner, address _spender) public constant returns (uint128 remaining) {
  429.         return mAllowed[_owner][_spender];
  430.     }
  431. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement