Skip to content

Instantly share code, notes, and snippets.

@johngriffin
Created July 12, 2018 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngriffin/64d9091b59f8173402f2eae6cef3d48d to your computer and use it in GitHub Desktop.
Save johngriffin/64d9091b59f8173402f2eae6cef3d48d to your computer and use it in GitHub Desktop.
function createNewUserPortfolio(
uint[] _percent,
uint[] _investmentAmounts,
address[] _funds,
Period _period,
uint256 _amountToPay,
uint256 _durationInYears,
uint256 _aktStake
) payable public {
address _userAddress = msg.sender;
require(_funds.length == _percent.length && _funds.length == _investmentAmounts.length);
require(_funds.length > 0);
uint256 allowance = token.allowance(_userAddress, this);
require(allowance >= _aktStake, "Stake not approved for transfer");
uint sumOfPercent = 0;
uint256 amount = 0;
for (uint i = 0; i < _percent.length; i++) {
sumOfPercent += _percent[i];
amount += _investmentAmounts[i];
}
require(sumOfPercent == 100);
require(amount == msg.value);
require(_amountToPay == msg.value);
require(token.transferFrom(_userAddress, this, _aktStake));
for (i = 0; i < _funds.length; i++) {
FundFunctional fund = FundFunctional(_funds[i]);
fund.invest(_userAddress, _investmentAmounts[i]);
}
portfolioData.createNewUserAllocation(_userAddress, _percent, _investmentAmounts, _funds);
portfolioData.createNewUserCommitment(_userAddress, _period, _amountToPay, _durationInYears, _aktStake, block.timestamp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment