Skip to content

Commit

Permalink
Merge pull request #111 from The-Poolz/issue-109
Browse files Browse the repository at this point in the history
added prettier config, formatted files
  • Loading branch information
ashwinarora authored Sep 21, 2022
2 parents fdc39af + 82f0630 commit 1e73c66
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 294 deletions.
28 changes: 28 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "always"
}
},
{
"files": "*.js",
"options": {
"printWidth": 120,
"useTabs": false,
"tabWidth": 4,
"semi": false,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": true
}
}
]
}
2 changes: 1 addition & 1 deletion contracts/ERC20Token.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "poolz-helper-v2/contracts/token/ERC20Token.sol";
import "poolz-helper-v2/contracts/token/ERC20Token.sol";
53 changes: 41 additions & 12 deletions contracts/LockedCreation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ contract LockedCreation is LockedPoolz {
uint256 _FinishTime, //Until what time the pool will end
uint256 _StartAmount, //Total amount of the tokens to sell in the pool
address _Owner // Who the tokens belong to
) external payable notZeroAddress(_Owner) returns(uint256) {
) external payable notZeroAddress(_Owner) returns (uint256) {
TransferInToken(_Token, msg.sender, _StartAmount);
if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){
if (
WhiteList_Address != address(0) &&
!(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))
) {
PayFee(Fee);
}
CreatePool(_Token, _StartTime, _FinishTime, _StartAmount, _Owner);
Expand All @@ -25,20 +28,31 @@ contract LockedCreation is LockedPoolz {
uint256[] calldata _FinishTime,
uint256[] calldata _StartAmount,
address[] calldata _Owner
) external payable
)
external
payable
isGreaterThanZero(_Owner.length)
isBelowLimit(_Owner.length)
{
require(_Owner.length == _FinishTime.length, "Date Array Invalid");
require(_StartTime.length == _FinishTime.length, "Date Array Invalid");
require(_Owner.length == _StartAmount.length, "Amount Array Invalid");
TransferInToken(_Token, msg.sender, Array.getArraySum(_StartAmount));
if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){
if (
WhiteList_Address != address(0) &&
!(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))
) {
PayFee(Fee * _Owner.length);
}
uint256 firstPoolId = Index;
for(uint i=0 ; i < _Owner.length; i++){
CreatePool(_Token, _StartTime[i], _FinishTime[i], _StartAmount[i], _Owner[i]);
for (uint256 i = 0; i < _Owner.length; i++) {
CreatePool(
_Token,
_StartTime[i],
_FinishTime[i],
_StartAmount[i],
_Owner[i]
);
}
uint256 lastPoolId = Index - 1;
emit MassPoolsCreated(firstPoolId, lastPoolId);
Expand All @@ -51,20 +65,35 @@ contract LockedCreation is LockedPoolz {
uint256[] calldata _FinishTime,
uint256[] calldata _StartAmount,
address[] calldata _Owner
) external payable
)
external
payable
isGreaterThanZero(_StartTime.length)
isBelowLimit(_Owner.length * _FinishTime.length)
{
require(_Owner.length == _StartAmount.length, "Amount Array Invalid");
require(_FinishTime.length == _StartTime.length, "Date Array Invalid");
TransferInToken(_Token, msg.sender, Array.getArraySum(_StartAmount) * _FinishTime.length);
TransferInToken(
_Token,
msg.sender,
Array.getArraySum(_StartAmount) * _FinishTime.length
);
uint256 firstPoolId = Index;
if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){
if (
WhiteList_Address != address(0) &&
!(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))
) {
PayFee(Fee * _Owner.length * _FinishTime.length);
}
for(uint i=0 ; i < _FinishTime.length ; i++){
for(uint j=0 ; j < _Owner.length ; j++){
CreatePool(_Token, _StartTime[i], _FinishTime[i], _StartAmount[j], _Owner[j]);
for (uint256 i = 0; i < _FinishTime.length; i++) {
for (uint256 j = 0; j < _Owner.length; j++) {
CreatePool(
_Token,
_StartTime[i],
_FinishTime[i],
_StartAmount[j],
_Owner[j]
);
}
}
uint256 lastPoolId = Index - 1;
Expand Down
20 changes: 11 additions & 9 deletions contracts/LockedDealV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ pragma solidity ^0.8.0;
import "./LockedPoolzData.sol";

contract LockedDealV2 is LockedPoolzData {
function getWithdrawableAmount(uint256 _PoolId) public view isPoolValid(_PoolId) returns(uint256){
function getWithdrawableAmount(uint256 _PoolId)
public
view
isPoolValid(_PoolId)
returns (uint256)
{
Pool storage pool = AllPoolz[_PoolId];
if(block.timestamp < pool.StartTime) return 0;
if(pool.FinishTime < block.timestamp) return pool.StartAmount - pool.DebitedAmount;
if (block.timestamp < pool.StartTime) return 0;
if (pool.FinishTime < block.timestamp)
return pool.StartAmount - pool.DebitedAmount;
uint256 totalPoolDuration = pool.FinishTime - pool.StartTime;
uint256 timePassed = block.timestamp - pool.StartTime;
uint256 timePassedPermille = timePassed * 1000;
uint256 ratioPermille = timePassedPermille / totalPoolDuration;
uint256 debitableAmount = pool.StartAmount * ratioPermille/ 1000;
uint256 debitableAmount = (pool.StartAmount * ratioPermille) / 1000;
return debitableAmount - pool.DebitedAmount;
}

Expand All @@ -28,11 +34,7 @@ contract LockedDealV2 is LockedPoolzData {
uint256 tokenAmount = getWithdrawableAmount(_PoolId);
uint256 tempDebitAmount = tokenAmount + pool.DebitedAmount;
pool.DebitedAmount = tempDebitAmount;
TransferToken(
pool.Token,
pool.Owner,
tokenAmount
);
TransferToken(pool.Token, pool.Owner, tokenAmount);
emit TokenWithdrawn(_PoolId, pool.Owner, tokenAmount);
return true;
}
Expand Down
46 changes: 38 additions & 8 deletions contracts/LockedManageable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import "poolz-helper-v2/contracts/FeeBaseHelper.sol";
import "./LockedDealEvents.sol";
import "./LockedDealModifiers.sol";

contract LockedManageable is FeeBaseHelper, LockedDealEvents, LockedDealModifiers {
contract LockedManageable is
FeeBaseHelper,
LockedDealEvents,
LockedDealModifiers
{
constructor() {
maxTransactionLimit = 400;
isTokenFilterOn = false; // disable token filter whitelist
Expand All @@ -32,19 +36,45 @@ contract LockedManageable is FeeBaseHelper, LockedDealEvents, LockedDealModifier
isTokenFilterOn = !isTokenFilterOn;
}

function isTokenWithoutFee(address _tokenAddress) notZeroAddress(WhiteList_Address) public view returns(bool) {
return IWhiteList(WhiteList_Address).Check(_tokenAddress, TokenFeeWhiteListId) > 0;
function isTokenWithoutFee(address _tokenAddress)
public
view
notZeroAddress(WhiteList_Address)
returns (bool)
{
return
IWhiteList(WhiteList_Address).Check(
_tokenAddress,
TokenFeeWhiteListId
) > 0;
}

function isTokenWhiteListed(address _tokenAddress) public view returns(bool) {
return !isTokenFilterOn || IWhiteList(WhiteList_Address).Check(_tokenAddress, TokenFilterWhiteListId) > 0;
function isTokenWhiteListed(address _tokenAddress)
public
view
returns (bool)
{
return
!isTokenFilterOn ||
IWhiteList(WhiteList_Address).Check(
_tokenAddress,
TokenFilterWhiteListId
) >
0;
}

function isUserWithoutFee(address _UserAddress) notZeroAddress(WhiteList_Address) public view returns(bool) {
return IWhiteList(WhiteList_Address).Check(_UserAddress, UserWhiteListId) > 0;
function isUserWithoutFee(address _UserAddress)
public
view
notZeroAddress(WhiteList_Address)
returns (bool)
{
return
IWhiteList(WhiteList_Address).Check(_UserAddress, UserWhiteListId) >
0;
}

function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner{
function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner {
maxTransactionLimit = _newLimit;
}
}
9 changes: 8 additions & 1 deletion contracts/LockedPoolz.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ contract LockedPoolz is LockedManageable {
"StartTime is greater than FinishTime"
);
//register the pool
AllPoolz[Index] = Pool(_StartTime, _FinishTime, _StartAmount, 0, _Owner, _Token);
AllPoolz[Index] = Pool(
_StartTime,
_FinishTime,
_StartAmount,
0,
_Owner,
_Token
);
MyPoolz[_Owner].push(Index);
emit NewPoolCreated(
Index,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"prettier": "prettier --write contracts/*.sol && prettier --write test/"
},
"author": "Ashwin Arora",
"license": "MIT",
Expand All @@ -28,6 +28,8 @@
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^2.0.2",
"ganache-cli": "^6.12.2",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-dev.23",
"poolz-helper-v2": "^2.0.16",
"truffle-plugin-verify": "^0.5.26"
}
Expand Down
25 changes: 13 additions & 12 deletions test/1_TrustSwap.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
const LockedDealV2 = artifacts.require("LockedDealV2")
const TestToken = artifacts.require("ERC20Token")
const { assert } = require('chai')
const constants = require('@openzeppelin/test-helpers/src/constants.js');
const { assert } = require("chai")
const constants = require("@openzeppelin/test-helpers/src/constants.js")

contract('LockedDealV2', (accounts) => {
contract("LockedDealV2", (accounts) => {
let instance, Token
const allow = 1, owner = accounts[2]
const allow = 1,
owner = accounts[2]
const date = new Date()

before(async () => {
instance = await LockedDealV2.deployed()
Token = await TestToken.new('TestToken', 'TEST')
Token = await TestToken.new("TestToken", "TEST")
})

it('Lock 1 test token for account2 from acount 0', async () => {
it("Lock 1 test token for account2 from acount 0", async () => {
await Token.approve(instance.address, constants.MAX_UINT256)
date.setDate(date.getDate() + 1) // add a day
date.setDate(date.getDate() + 1) // add a day
const startTime = Math.floor(date.getTime() / 1000)
const finishTime = startTime + 60 * 60 * 24 * 30
await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner)
const mypoolz = await instance.GetAllMyPoolsId(owner, { from: owner })
assert.equal(mypoolz.length, 1)
})

it('fail on withdraw from account 2', async () => {
it("fail on withdraw from account 2", async () => {
let took = await instance.WithdrawToken.call(0)
assert.isFalse(took)
})

it('open new pool for account 1 ', async () => {
it("open new pool for account 1 ", async () => {
const date = new Date()
date.setDate(date.getDate() - 1) // sub a day
date.setDate(date.getDate() - 1) // sub a day
const startTime = Math.floor(date.getTime() / 1000)
const finishTime = startTime + 60 * 60 * 24 * 30
await instance.CreateNewPool(Token.address, startTime, finishTime, allow, accounts[1])
const mypoolz = await instance.GetAllMyPoolsId(owner, { from: accounts[1] })
assert.equal(mypoolz.length, 1)
})

it('withdraw from account 1', async () => {
it("withdraw from account 1", async () => {
let took = await instance.WithdrawToken.call(1)
assert.isTrue(took)
})
})
})
Loading

0 comments on commit 1e73c66

Please sign in to comment.