From 68314458f7e050702dd69064f91c111b0161612d Mon Sep 17 00:00:00 2001 From: adibas03 Date: Wed, 18 Dec 2019 17:12:58 +0100 Subject: [PATCH 1/3] concept --- .circleci/config.yml | 2 +- contracts/crowdloan/CrowdloanToken.sol | 34 ++++++++++++++++++++++++++ contracts/crowdloan/ICrowdloan.sol | 32 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 contracts/crowdloan/CrowdloanToken.sol create mode 100644 contracts/crowdloan/ICrowdloan.sol diff --git a/.circleci/config.yml b/.circleci/config.yml index 62be63a..138df06 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: - save_cache: paths: - node_modules - key: v1-dependencies-{{ checksum "package.json" }} + key: v1-{{ .Branch }}-dependencies-{{ checksum "package.json" }} - run: npx truffle compile --all - run: npx zos push --network development - run: npx zos publish --network development diff --git a/contracts/crowdloan/CrowdloanToken.sol b/contracts/crowdloan/CrowdloanToken.sol new file mode 100644 index 0000000..0e36e23 --- /dev/null +++ b/contracts/crowdloan/CrowdloanToken.sol @@ -0,0 +1,34 @@ +pragma solidity 0.5.11; + +import "openzeppelin-eth/contracts/math/SafeMath.sol"; +import "openzeppelin-eth/contracts/token/ERC20/IERC20.sol"; +import "openzeppelin-eth/contracts/token/ERC20/StandaloneERC20.sol"; +import "./ICrowdloan.sol"; + +contract CrowdloanToken is StandaloneERC20 { + using SafeMath for uint256; + + ICrowdloan crowdloan; + mapping(address => uint256) claimedTokens; + + function initialize( + string memory name, + string memory symbol, + uint256 decimals, + address loanAddress, + + ) public { + address[] memory emptyAdressArray = new address[](0); + crowdloan = ICrowdloan(loanAddress); + + StandaloneERC20.initialize( name, symbol, uint8(decimals), crowdloan.principalRequested(), address(this), + emptyAdressArray, emptyAdressArray ); + } + + function claimTokens (address claimant) public { + uint256 addressClaimed = claimedTokens[claimant]; + uint256 tokensDue = crowdloan.amountContributed(claimant).sub(addressClaimed); + require(tokensDue > 0, 'No tokens to Claim'); + IERC20(address(this)).transfer(claimant, tokensDue); + } +} diff --git a/contracts/crowdloan/ICrowdloan.sol b/contracts/crowdloan/ICrowdloan.sol new file mode 100644 index 0000000..8967181 --- /dev/null +++ b/contracts/crowdloan/ICrowdloan.sol @@ -0,0 +1,32 @@ +pragma solidity 0.5.11; + +contract ICrowdloan { + function amountRepaid () external returns (uint256); + function borrower () external returns (uint256); + function crowdfundStart () external returns (uint256); + function crowdfundEnd () external returns (uint256); + function crowdfundDuration () external returns (uint256); + function principalRequested () external returns (uint256); + function repaymentCap () external returns (uint256); + function totalRepaymentWithdrawn () external returns (uint256); + function loanMetadataUrl () external returns (string); + + function amountContributed (address) external returns (uint256); + function repaymentWithdrawn (address) external returns (uint256); + + function fund (uint256) external; + function repay (uint256) external; + function withdrawPrincipal (uint256) external; + function withdrawRepayment () external; + function startCrowdfund () external; + + // Events + event Fund(address sender, uint256 amount); + event WithdrawPrincipal(address borrower, uint256 amount); + event WithdrawRepayment(address lender, uint256 amount); + event Repay(uint256 amount); + event StartCrowdfund(uint256 crowdfundStart); + + + +} From 500538af62bc198d378f83bbd0790a083014892d Mon Sep 17 00:00:00 2001 From: adibas03 Date: Thu, 26 Dec 2019 03:08:57 +0100 Subject: [PATCH 2/3] manual token --- contracts/crowdloan/CrowdloanToken.sol | 37 ++++++++++++-------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/contracts/crowdloan/CrowdloanToken.sol b/contracts/crowdloan/CrowdloanToken.sol index 0e36e23..2e038bc 100644 --- a/contracts/crowdloan/CrowdloanToken.sol +++ b/contracts/crowdloan/CrowdloanToken.sol @@ -1,34 +1,31 @@ pragma solidity 0.5.11; import "openzeppelin-eth/contracts/math/SafeMath.sol"; -import "openzeppelin-eth/contracts/token/ERC20/IERC20.sol"; import "openzeppelin-eth/contracts/token/ERC20/StandaloneERC20.sol"; -import "./ICrowdloan.sol"; contract CrowdloanToken is StandaloneERC20 { using SafeMath for uint256; - ICrowdloan crowdloan; - mapping(address => uint256) claimedTokens; - function initialize( - string memory name, - string memory symbol, - uint256 decimals, - address loanAddress, - + string memory name, + string memory symbol, + uint256 decimals, + uint256 initialSupply, + address initialHolder ) public { address[] memory emptyAdressArray = new address[](0); - crowdloan = ICrowdloan(loanAddress); - - StandaloneERC20.initialize( name, symbol, uint8(decimals), crowdloan.principalRequested(), address(this), - emptyAdressArray, emptyAdressArray ); - } + if (initialHolder == address(0)) { + initialHolder = msg.sender; + } - function claimTokens (address claimant) public { - uint256 addressClaimed = claimedTokens[claimant]; - uint256 tokensDue = crowdloan.amountContributed(claimant).sub(addressClaimed); - require(tokensDue > 0, 'No tokens to Claim'); - IERC20(address(this)).transfer(claimant, tokensDue); + StandaloneERC20.initialize( + name, + symbol, + uint8(decimals), + initialSupply, + initialHolder, + emptyAdressArray, //Minters + emptyAdressArray //Pausers + ); } } From 637d88fed161cbf741483f9248f8076f57620fae Mon Sep 17 00:00:00 2001 From: adibas03 Date: Tue, 31 Dec 2019 16:40:32 +0100 Subject: [PATCH 3/3] fix test --- contracts/crowdloan/ICrowdloan.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/crowdloan/ICrowdloan.sol b/contracts/crowdloan/ICrowdloan.sol index 8967181..0a4682a 100644 --- a/contracts/crowdloan/ICrowdloan.sol +++ b/contracts/crowdloan/ICrowdloan.sol @@ -9,7 +9,7 @@ contract ICrowdloan { function principalRequested () external returns (uint256); function repaymentCap () external returns (uint256); function totalRepaymentWithdrawn () external returns (uint256); - function loanMetadataUrl () external returns (string); + function loanMetadataUrl () external returns (string memory); function amountContributed (address) external returns (uint256); function repaymentWithdrawn (address) external returns (uint256);