Created
February 9, 2018 20:28
-
-
Save PillarDevelopment/15c88286516b7ffbf1e47e0be4548c4d to your computer and use it in GitHub Desktop.
Сложные проценты в solidity
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
| function compoundInterest(uint256 depo, uint256 stage2, uint256 start, uint256 current) internal pure returns (uint256) { | |
| assert(current>=start); | |
| assert(start>=stage2); | |
| uint256 ret=depo; uint g; uint d; | |
| stage2=stage2/1 days; | |
| start=start/1 days; | |
| current=current/1 days; | |
| uint dpercent=100; | |
| uint i=start; | |
| if(i-stage2>365) dpercent=200; | |
| if(i-stage2>730) dpercent=1000; | |
| while(i<current) | |
| { | |
| g=i-stage2; | |
| if(g>265 && g<=365) | |
| { | |
| d=365-g; | |
| ret=fracExp(ret, dpercent, d, 8); | |
| i+=d; | |
| dpercent=200; | |
| } | |
| if(g>630 && g<=730) | |
| { | |
| d=730-g; | |
| ret=fracExp(ret, dpercent, d, 8); | |
| i+=d; | |
| dpercent=1000; | |
| } | |
| else if(g>730) dpercent=1000; | |
| else if(g>365) dpercent=200; | |
| if(i+100<current) ret=fracExp(ret, dpercent, 100, 8); | |
| else return fracExp(ret, dpercent, current-i, 8); | |
| i+=100; | |
| } | |
| return ret; | |
| } /// предоставлено MMMtokencoin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment