Skip to content

Commit be2b226

Browse files
committed
Merge branch 'dev' into release/0.0.1
2 parents 16a6ca0 + 1ce84e6 commit be2b226

19 files changed

+3096
-20
lines changed

contracts/Association.sol

Lines changed: 454 additions & 0 deletions
Large diffs are not rendered by default.

contracts/ComplexBank.sol

Lines changed: 470 additions & 0 deletions
Large diffs are not rendered by default.

contracts/Deposit.sol

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "./zeppelin/math/SafeMath.sol";
4+
import "./zeppelin/lifecycle/Pausable.sol";
5+
import "./zeppelin/ownership/Ownable.sol";
6+
import "./interfaces/I_Bank.sol";
7+
import "./token/LibreCash.sol";
8+
import "./ComplexExchanger.sol";
9+
10+
11+
contract Deposit is Ownable {
12+
using SafeMath for uint256;
13+
address public Libre;
14+
LibreCash libre;
15+
16+
uint256 public needAmount = 20000 ether;
17+
uint256 constant REVERSE_PERCENT = 10000;
18+
uint256 constant YEAR_SECONDS = 365.25 * 24 * 60 * 60;
19+
uint256 public lockedTokens = 0;
20+
21+
DepositPlan[] public plans;
22+
23+
event NewDeposit(address beneficiar, uint256 timestamp, uint256 deadline, uint256 amount, uint256 margin);
24+
event ClaimDeposit(address beneficiar, uint256 amount, uint256 margin);
25+
26+
struct OwnDeposit {
27+
uint256 timestamp;
28+
uint256 deadline;
29+
uint256 amount;
30+
uint256 margin;
31+
string plan;
32+
}
33+
34+
struct DepositPlan {
35+
uint256 period;
36+
uint256 percent;
37+
uint256 minAmount;
38+
string description;
39+
}
40+
41+
mapping (address => OwnDeposit[]) public deposits;
42+
43+
/**
44+
* @dev Constructor.
45+
* @param _libre Address of LibreCash contract.
46+
*/
47+
function Deposit(address _libre) public {
48+
Libre = _libre;
49+
libre = LibreCash(Libre);
50+
}
51+
52+
/**
53+
* @dev Set amount the contract needs.
54+
* @param _amount New amount.
55+
*/
56+
function setAmount(uint256 _amount) public onlyOwner {
57+
needAmount = _amount;
58+
}
59+
60+
/**
61+
* @dev Return count deposits.
62+
*/
63+
function myDepositCount() public view returns(uint256) {
64+
return deposits[msg.sender].length;
65+
}
66+
67+
/**
68+
* @dev Lets user to get back his deposit with margin after deadline.
69+
* @param _id Deposit ID.
70+
*/
71+
function claimDeposit(uint256 _id) public {
72+
OwnDeposit storage dep = deposits[msg.sender][_id];
73+
require(dep.deadline <= now);
74+
uint256 refundAmount = dep.amount.add(dep.margin);
75+
lockedTokens = lockedTokens.sub(refundAmount);
76+
needAmount = needAmount.add(dep.amount);
77+
libre.transfer(msg.sender, refundAmount);
78+
ClaimDeposit(msg.sender, dep.amount, dep.margin);
79+
delete deposits[msg.sender][_id];
80+
}
81+
82+
/**
83+
* @dev Creates deposit plan.
84+
* @param _period Deposit period (lifetime in seconds).
85+
* @param _percent Deposit percentage (annual).
86+
* @param _minAmount Minimum deposit amount.
87+
* @param _description Plan description.
88+
*/
89+
function createPlan(uint256 _period, uint256 _percent, uint256 _minAmount, string _description) public onlyOwner {
90+
require(_period > 0);
91+
plans.push(DepositPlan(_period, _percent, _minAmount, _description));
92+
}
93+
94+
/**
95+
* @dev Delete deposit plan.
96+
* @param _id Deposit plan ID.
97+
*/
98+
function deletePlan(uint256 _id) public onlyOwner {
99+
delete plans[_id];
100+
}
101+
102+
/**
103+
* @dev Change deposit plan.
104+
* @param _id Deposit plan ID.
105+
* @param _period Deposit period (lifetime in seconds).
106+
* @param _percent Deposit percentage (annual).
107+
* @param _minAmount Minimum deposit amount.
108+
* @param _description Plan description.
109+
*/
110+
function changePlan(uint256 _id, uint256 _period, uint256 _percent, uint256 _minAmount, string _description) public onlyOwner {
111+
require(_period > 0);
112+
plans[_id] = DepositPlan(_period, _percent, _minAmount, _description);
113+
}
114+
115+
/**
116+
* @dev Create deposit.
117+
* @param _amount Libre amount.
118+
* @param _planId Deposit plan ID.
119+
*/
120+
function createDeposit(uint256 _amount, uint256 _planId) public {
121+
_amount = (_amount <= needAmount) ? _amount : needAmount;
122+
DepositPlan memory plan = plans[_planId];
123+
uint256 margin = calcProfit(_amount, _planId);
124+
125+
require(_amount >= plan.minAmount && _amount.add(margin) <= availableTokens());
126+
lockedTokens = lockedTokens.add(margin).add(_amount);
127+
128+
libre.transferFrom(msg.sender, this, _amount);
129+
deposits[msg.sender].push(OwnDeposit(
130+
now,
131+
now.add(plan.period),
132+
_amount,
133+
margin,
134+
plan.description
135+
));
136+
137+
needAmount = needAmount.sub(_amount);
138+
NewDeposit(msg.sender, now, now.add(plan.period), _amount, margin);
139+
}
140+
141+
/**
142+
* @dev Get available tokens on the deposit contract.
143+
*/
144+
function availableTokens() public view returns(uint256) {
145+
return libre.balanceOf(this).sub(lockedTokens);
146+
}
147+
148+
/**
149+
* @dev Calculate potential profit.
150+
* @param _amount Libre amount.
151+
* @param _planId Deposit plan ID.
152+
*/
153+
function calcProfit(uint256 _amount, uint256 _planId) public view returns(uint256) {
154+
DepositPlan storage plan = plans[_planId];
155+
// yearlyProfitX100 = _amount * percent * 100
156+
uint256 yearlyProfitX100 = _amount.mul(plan.percent);
157+
// periodicProfit = yearlyProfitX100 * period / 365.25 days / 100
158+
uint256 periodicProfit = yearlyProfitX100.mul(plan.period).div(YEAR_SECONDS).div(REVERSE_PERCENT);
159+
return periodicProfit;
160+
}
161+
162+
/**
163+
* @dev Gets deposit plans count.
164+
*/
165+
function plansCount() public view returns(uint256) {
166+
return plans.length;
167+
}
168+
}

contracts/Exchanger.sol

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "./zeppelin/math/SafeMath.sol";
4+
import "./zeppelin/ownership/Ownable.sol";
5+
import "./zeppelin/token/StandardToken.sol";
6+
import "./zeppelin/token/BurnableToken.sol";
7+
8+
9+
contract BurnableERC20 is BurnableToken, StandardToken {}
10+
11+
/**
12+
* @title Token exchanger contract.
13+
*
14+
* @dev ERC20 token exchanger contract for an ICO.
15+
*/
16+
contract Exchanger is Ownable {
17+
using SafeMath for uint;
18+
19+
address public supplyTokenAddress = 0x0;
20+
address public collectingTokenAddress = 0x0;
21+
StandardToken private supplyToken;
22+
BurnableERC20 private collectingToken;
23+
uint constant RATE_MULTIPLIER = 10**9;
24+
uint public rate = 10**9; // 10**9 / RATE_MULTIPLIER = 1
25+
26+
event NewCollectingToken(address oldTokenContract, address newTokenContract);
27+
event NewRate(uint oldRate, uint newRate);
28+
event Deposit(address tokenSender, uint tokenAmount, address tokenContract);
29+
event ExchangeRequest(address tokenSender, uint tokenAmount, address tokenContract);
30+
event SupplySent(address tokenBeneficiar, uint tokenAmount, address tokenContract);
31+
32+
modifier tokens {
33+
require((msg.sender == supplyTokenAddress) || (msg.sender == collectingTokenAddress));
34+
_;
35+
}
36+
37+
/**
38+
* @dev Allows the owner to set new exchange rate.
39+
* @param _rate The new rate.
40+
*/
41+
function setRate(uint _rate) public onlyOwner {
42+
require(_rate != 0);
43+
NewRate(rate, _rate);
44+
rate = _rate;
45+
}
46+
47+
/**
48+
* @dev Allows the owner to set the supply token address (can be set only once).
49+
* @param _address The contract address.
50+
*/
51+
function setSupplyTokenOnce(address _address) public onlyOwner {
52+
require(supplyTokenAddress == 0x0);
53+
require(_address != collectingTokenAddress);
54+
require(_address != 0x0);
55+
supplyTokenAddress = _address;
56+
supplyToken = StandardToken(_address);
57+
}
58+
59+
/**
60+
* @dev Allows the owner to set the collecting token address.
61+
* @param _address The contract address.
62+
*/
63+
function setCollectingToken(address _address) public onlyOwner {
64+
require(_address != 0x0);
65+
require(_address != supplyTokenAddress);
66+
NewCollectingToken(collectingTokenAddress, _address);
67+
collectingTokenAddress = _address;
68+
collectingToken = BurnableERC20(_address);
69+
}
70+
71+
/**
72+
* @dev Returns supply token balance.
73+
*/
74+
function totalSupply() public view returns (uint) {
75+
return supplyToken.balanceOf(this);
76+
}
77+
78+
/**
79+
* @dev buySupplyToken; the place where exchanges are done.
80+
* @param _value The number of tokens.
81+
*/
82+
function buySupplyToken(uint _value) public {
83+
require(_value <= collectingToken.allowance(msg.sender,this));
84+
ExchangeRequest(msg.sender, _value, supplyTokenAddress);
85+
uint256 supplyToSend = _value.mul(RATE_MULTIPLIER) / rate;
86+
87+
if (supplyToSend > supplyToken.balanceOf(this)) {
88+
uint256 restSupplyToken = supplyToken.balanceOf(this);
89+
_value = restSupplyToken.mul(rate) / RATE_MULTIPLIER;
90+
}
91+
collectingToken.transferFrom(msg.sender, this, _value);
92+
collectingToken.burn(_value);
93+
supplyToken.transfer(msg.sender, supplyToSend);
94+
SupplySent(msg.sender, supplyToSend, supplyTokenAddress);
95+
}
96+
}

contracts/LBRSFaucet.sol

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "./token/LibertyToken.sol";
4+
import "./zeppelin/ownership/Ownable.sol";
5+
import "./zeppelin/lifecycle/Pausable.sol";
6+
7+
contract LBRSFaucet is Ownable, Pausable {
8+
address public lbrsToken;
9+
LibertyToken token;
10+
uint256 public tokensToSend = 0;
11+
mapping(address => bool) public tokensSent;
12+
13+
/**
14+
* @dev Constructor
15+
* @param LBRS - LBRS token address
16+
*/
17+
function LBRSFaucet(address LBRS) public {
18+
lbrsToken = LBRS;
19+
token = LibertyToken(lbrsToken);
20+
tokensToSend = 2000 * 10**(token.decimals());
21+
}
22+
23+
/**
24+
* @dev Returns LBRS token balance of contract.
25+
*/
26+
function tokenBalance() public view returns(uint256) {
27+
return token.balanceOf(this);
28+
}
29+
30+
/**
31+
* @dev Implements method for getting testing LBRS tokens to DAO testing.
32+
*/
33+
function get() public whenNotPaused {
34+
require(!tokensSent[msg.sender]);
35+
tokensSent[msg.sender] = true;
36+
token.transfer(msg.sender, tokensToSend);
37+
}
38+
39+
/**
40+
* @dev Sets tokens amount to send
41+
*/
42+
function setTokenAmount(uint256 tokensAmount) public onlyOwner {
43+
tokensToSend = tokensAmount;
44+
}
45+
46+
}

contracts/LBRSMultitransfer.sol

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
pragma solidity ^0.4.18;
2+
3+
import "./token/LibertyToken.sol";
4+
import "./zeppelin/ownership/Ownable.sol";
5+
6+
contract LBRSMultitransfer is Ownable {
7+
address public lbrsToken;
8+
LibertyToken token;
9+
10+
/**
11+
* @dev Implements transfer method for multiple recipient. Needed in LBRS token distribution process after ICO
12+
* @param recipient - recipient addresses array
13+
* @param balance - refill amounts array
14+
*/
15+
function multiTransfer(address[] recipient,uint256[] balance) public onlyOwner {
16+
require(recipient.length == balance.length);
17+
18+
for(uint256 i = 0; i < recipient.length; i++) {
19+
token.transfer(recipient[i],balance[i]);
20+
}
21+
}
22+
23+
/**
24+
* @dev Constructor
25+
* @param LBRS - LBRS token address
26+
*/
27+
function LBRSMultitransfer(address LBRS) public {
28+
lbrsToken = LBRS;
29+
token = LibertyToken(lbrsToken);
30+
}
31+
32+
/**
33+
* @dev Returns LBRS token balance of contract.
34+
*/
35+
function tokenBalance() public view returns(uint256) {
36+
return token.balanceOf(this);
37+
}
38+
}

0 commit comments

Comments
 (0)