From be2c1ce988fd635e05df15674dbc747d918823d8 Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Wed, 21 Apr 2021 15:26:43 +0200 Subject: [PATCH 1/8] update truffle config, use env --- truffle-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/truffle-config.js b/truffle-config.js index 3795c5e..885a2fd 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -47,7 +47,7 @@ module.exports = { // Useful for deploying to a public network. // NB: It's important to wrap the provider as a function. // ropsten: { - // provider: () => new HDWalletProvider("73630578a4cf7b0c4d65929733f714ddb9119cd7798fec7bca8e19d0bea806bc", `https://ropsten.infura.io/v3/847eb8e2713c43d59dea835ceb49b39f`), + // provider: () => new HDWalletProvider(privateKey, providerUrl), // network_id: 3, // Ropsten's id // gas: 5500000, // Ropsten has a lower block limit than mainnet // confirmations: 2, // # of confs to wait between deployments. (default: 0) From 023fd49cc777d7cd84bd21ad415e4de0e93856d2 Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Wed, 21 Apr 2021 15:47:00 +0200 Subject: [PATCH 2/8] add IPoolFactory interface of PoolFactory contract --- contracts/IPoolFactory.sol | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 contracts/IPoolFactory.sol diff --git a/contracts/IPoolFactory.sol b/contracts/IPoolFactory.sol new file mode 100644 index 0000000..2272889 --- /dev/null +++ b/contracts/IPoolFactory.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +interface PoolFactory{ + function enroll(address participant) external returns (uint256); + function deposit() external payable returns (uint256); + function deposit_and_invest_compound(address payable _cEtherContract) external payable returns (uint256); + function withdraw(uint256 withdrawAmount) external payable returns (uint256 remainingBal); + function withdraw_and_redeem(uint256 withdrawAmount, bool redeemType,address _cEtherContract) external returns (uint256 remainingBal); + function balance() external returns (uint256); + function depositsBalance() external returns (uint256); + function is_owner() external returns (bool); + function get_owner() external returns (address); + function is_public() external returns(bool); + function balanceParticipant(address participant) external returns (uint256); + function is_allowed(address participant) external returns (bool); + function getParticipantList() external returns (address[] memory); +} From 401e998163c0c947aade7248747ef2b638ff4153 Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Sat, 24 Apr 2021 01:29:36 +0200 Subject: [PATCH 3/8] update contracts --- contracts/IPoolFactory.sol | 3 +- contracts/PoolFactory.sol | 17 ++++++----- contracts/PoolRecorder.sol | 58 +++++--------------------------------- 3 files changed, 19 insertions(+), 59 deletions(-) diff --git a/contracts/IPoolFactory.sol b/contracts/IPoolFactory.sol index 2272889..c4b6f5f 100644 --- a/contracts/IPoolFactory.sol +++ b/contracts/IPoolFactory.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; -interface PoolFactory{ +interface IPoolFactory{ function enroll(address participant) external returns (uint256); function deposit() external payable returns (uint256); function deposit_and_invest_compound(address payable _cEtherContract) external payable returns (uint256); @@ -15,4 +15,5 @@ interface PoolFactory{ function balanceParticipant(address participant) external returns (uint256); function is_allowed(address participant) external returns (bool); function getParticipantList() external returns (address[] memory); + function getPoolInfo() external returns(bytes32, bytes32, address, uint); } diff --git a/contracts/PoolFactory.sol b/contracts/PoolFactory.sol index 2670aa5..54acd12 100644 --- a/contracts/PoolFactory.sol +++ b/contracts/PoolFactory.sol @@ -4,9 +4,10 @@ pragma solidity >=0.8.0; import "./compound/Compound.sol"; contract PoolFactory is Compound { - bool private isPublic; + bool public isPublic; address public owner; - uint8 private participantCount; + bytes32 public title; + bytes32 public description; address[] public participantsList; mapping(address => uint256) public balances; mapping(address => bool) public exists; @@ -14,13 +15,14 @@ contract PoolFactory is Compound { // Log the event about a deposit being made by an address and its amount event LogDepositMade(address indexed accountAddress, uint256 amount); - constructor(bool _isPublic, address _owner) { + constructor(bool _isPublic, address _owner, bytes32 _title,bytes32 _description) { /* Set the owner to the creator of this contract */ isPublic = _isPublic; owner = _owner; + title = _title; + description = _description; balances[owner] = 0; exists[owner] = true; - participantCount = 0; participantsList.push(owner); } @@ -30,7 +32,6 @@ contract PoolFactory is Compound { function enroll(address participant) public returns (uint256) { require(msg.sender == owner, "Not authorized"); require(exists[participant] == false, "Already enrolled"); - participantCount++; participantsList.push(participant); balances[participant] = 0; exists[participant] = true; @@ -42,7 +43,6 @@ contract PoolFactory is Compound { function deposit() public payable returns (uint256) { require(exists[msg.sender] == true || isPublic == true, "Not allowed"); if (is_allowed(msg.sender) == false) { - participantCount++; participantsList.push(msg.sender); balances[msg.sender] = 0; exists[msg.sender] = true; @@ -59,7 +59,6 @@ contract PoolFactory is Compound { { require(exists[msg.sender] == true || isPublic == true, "Not allowed"); if (is_allowed(msg.sender) == false) { - participantCount++; participantsList.push(msg.sender); balances[msg.sender] = 0; exists[msg.sender] = true; @@ -148,4 +147,8 @@ contract PoolFactory is Compound { function getParticipantList() public view returns (address[] memory) { return participantsList; } + + function getPoolInfo() public view returns(bytes32, bytes32, address, uint) { + return (title, description, owner, participantsList.length); + } } diff --git a/contracts/PoolRecorder.sol b/contracts/PoolRecorder.sol index fe9da21..bf9a74f 100644 --- a/contracts/PoolRecorder.sol +++ b/contracts/PoolRecorder.sol @@ -2,75 +2,31 @@ pragma solidity >=0.8.0; import "./PoolFactory.sol"; +import "./IPoolFactory.sol"; contract PoolRecorder { - struct Pool { - string name; - string description; - address owner; - address PoolAddress; - bool visible; - } - address[] poolList; - mapping(address => Pool) public poolRecorded; - event PoolAdded(address poolAddress); function createPool( - string memory _name, - string memory _description, + bytes32 _name, + bytes32 _description, bool _visible, address _owner ) public returns (address) { - PoolFactory newPoolBank = new PoolFactory(_visible, _owner); - addPool( - address(newPoolBank), - _owner, - _name, - _description, - _visible - ); + PoolFactory newPoolBank = new PoolFactory(_visible, _owner, _name, _description); return address(newPoolBank); } - function addPool( - address poolAddress, - address _owner, - string memory _name, - string memory _description, - bool _visible - ) private { - poolList.push(poolAddress); - poolRecorded[poolAddress] = Pool( - _name, - _description, - _owner, - poolAddress, - _visible - ); - emit PoolAdded(poolAddress); - } - - function removePool(address poolAddress) public { - for (uint256 index = 0; index < poolList.length; index++) { - if (poolList[index] == poolAddress) { - poolList[index] = poolList[poolList.length - 1]; - delete poolList[poolList.length - 1]; - break; - } - } - } - function getListPools() public view returns (address[] memory) { return poolList; } function getPoolInfo(address poolAddress) public - view - returns (Pool memory) + returns (bytes32, bytes32, address, uint) { - return poolRecorded[poolAddress]; + IPoolFactory pool = IPoolFactory(poolAddress); + return pool.getPoolInfo(); } } From 7c45af054bee2aa5cc5fae4a7d976a34cb15a1a0 Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Sat, 24 Apr 2021 02:24:52 +0200 Subject: [PATCH 4/8] update smartcontractd --- contracts/IPoolFactory.sol | 18 +++++++++--------- contracts/PoolFactory.sol | 10 +++++----- contracts/PoolRecorder.sol | 8 +++++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/contracts/IPoolFactory.sol b/contracts/IPoolFactory.sol index c4b6f5f..6e57ccf 100644 --- a/contracts/IPoolFactory.sol +++ b/contracts/IPoolFactory.sol @@ -7,13 +7,13 @@ interface IPoolFactory{ function deposit_and_invest_compound(address payable _cEtherContract) external payable returns (uint256); function withdraw(uint256 withdrawAmount) external payable returns (uint256 remainingBal); function withdraw_and_redeem(uint256 withdrawAmount, bool redeemType,address _cEtherContract) external returns (uint256 remainingBal); - function balance() external returns (uint256); - function depositsBalance() external returns (uint256); - function is_owner() external returns (bool); - function get_owner() external returns (address); - function is_public() external returns(bool); - function balanceParticipant(address participant) external returns (uint256); - function is_allowed(address participant) external returns (bool); - function getParticipantList() external returns (address[] memory); - function getPoolInfo() external returns(bytes32, bytes32, address, uint); + function balance() external view returns (uint256); + function depositsBalance() external view returns (uint256); + function is_owner() external view returns (bool); + function get_owner() external view returns (address); + function is_public() external view returns(bool); + function balanceParticipant(address participant) external view returns (uint256); + function is_allowed(address participant) external view returns (bool); + function getParticipantList() external view returns (address[] memory); + function getPoolInfo() external view returns(string memory, string memory, address, bool, uint); } diff --git a/contracts/PoolFactory.sol b/contracts/PoolFactory.sol index 54acd12..247a13b 100644 --- a/contracts/PoolFactory.sol +++ b/contracts/PoolFactory.sol @@ -6,8 +6,8 @@ import "./compound/Compound.sol"; contract PoolFactory is Compound { bool public isPublic; address public owner; - bytes32 public title; - bytes32 public description; + string public title; + string public description; address[] public participantsList; mapping(address => uint256) public balances; mapping(address => bool) public exists; @@ -15,7 +15,7 @@ contract PoolFactory is Compound { // Log the event about a deposit being made by an address and its amount event LogDepositMade(address indexed accountAddress, uint256 amount); - constructor(bool _isPublic, address _owner, bytes32 _title,bytes32 _description) { + constructor(bool _isPublic, address _owner, string memory _title,string memory _description) { /* Set the owner to the creator of this contract */ isPublic = _isPublic; owner = _owner; @@ -148,7 +148,7 @@ contract PoolFactory is Compound { return participantsList; } - function getPoolInfo() public view returns(bytes32, bytes32, address, uint) { - return (title, description, owner, participantsList.length); + function getPoolInfo() public view returns(string memory, string memory, address, bool, uint) { + return (title, description, owner, isPublic, participantsList.length); } } diff --git a/contracts/PoolRecorder.sol b/contracts/PoolRecorder.sol index bf9a74f..661ab3a 100644 --- a/contracts/PoolRecorder.sol +++ b/contracts/PoolRecorder.sol @@ -9,12 +9,13 @@ contract PoolRecorder { event PoolAdded(address poolAddress); function createPool( - bytes32 _name, - bytes32 _description, + string memory _name, + string memory _description, bool _visible, address _owner ) public returns (address) { PoolFactory newPoolBank = new PoolFactory(_visible, _owner, _name, _description); + poolList.push(address(newPoolBank)); return address(newPoolBank); } @@ -24,7 +25,8 @@ contract PoolRecorder { function getPoolInfo(address poolAddress) public - returns (bytes32, bytes32, address, uint) + view + returns (string memory, string memory, address,bool, uint) { IPoolFactory pool = IPoolFactory(poolAddress); return pool.getPoolInfo(); From 2fe73a6b707d18af8c68bcf4ddd5e4f14961e414 Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Sat, 24 Apr 2021 02:25:05 +0200 Subject: [PATCH 5/8] update tests --- test/PoolRecorder.test.js | 22 +++++++++++----------- test/poolFactory.test.js | 17 ++++++++++------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/test/PoolRecorder.test.js b/test/PoolRecorder.test.js index 52f8db0..8aa4efe 100644 --- a/test/PoolRecorder.test.js +++ b/test/PoolRecorder.test.js @@ -15,14 +15,14 @@ describe('PoolRecorder', function () { it('should create new pools from PoolRecorder smarcontract', async () => { addressAlicePool = await this.poolRecorder.createPool("alice's pool", "pool for alice and friends", true, alice, { from: alice }) - addressMyDefiPool = await this.poolRecorder.createPool("MyDefi's pool", "MyDefi is a new defi project that have a great impact", true, charlie, { from: charlie }) + addressMyDefiPool = await this.poolRecorder.createPool("MyDefi pool", "MyDefi is a new defi project that have a great impact", true, charlie, { from: charlie }) const listPool = await this.poolRecorder.getListPools() assert.equal(listPool.length, 2) - getPoolInfoAlice = await this.poolRecorder.getPoolInfo(listPool[0]) - assert.equal(getPoolInfoAlice.name, "alice\'s pool") - assert.equal(getPoolInfoAlice.description, "pool for alice and friends") - assert.equal(getPoolInfoAlice.visible, true) - assert.equal(getPoolInfoAlice.owner, alice) + getPoolInfoAlice = await this.poolRecorder.getPoolInfo(listPool[0], {from: owner}) + assert.equal(getPoolInfoAlice[0], "alice's pool") + assert.equal(getPoolInfoAlice[1], "pool for alice and friends") + assert.equal(getPoolInfoAlice[3], true) + assert.equal(getPoolInfoAlice[2], alice) }); it('should remove a pool from PoolRecorder smarcontract', async () => { @@ -30,11 +30,11 @@ describe('PoolRecorder', function () { // addressMyDefiPool = await this.poolRecorder.createPool("MyDefi's pool", "MyDefi is a new defi project that have a great impact", true, { from: charlie }) const listPool = await this.poolRecorder.getListPools() assert.equal(listPool.length, 1) - getPoolInfoAlice = await this.poolRecorder.getPoolInfo(listPool[0]) - assert.equal(getPoolInfoAlice.name, "alice\'s pool") - assert.equal(getPoolInfoAlice.description, "pool for alice and friends") - assert.equal(getPoolInfoAlice.visible, true) - assert.equal(getPoolInfoAlice.owner, alice) + getPoolInfoAlice = await this.poolRecorder.getPoolInfo(listPool[0], {from: owner}) + assert.equal(getPoolInfoAlice[0], "alice\'s pool") + assert.equal(getPoolInfoAlice[1], "pool for alice and friends") + assert.equal(getPoolInfoAlice[3], true) + assert.equal(getPoolInfoAlice[2], alice) }); it('should remove a pool from PoolRecorder smarcontract', async () => { diff --git a/test/poolFactory.test.js b/test/poolFactory.test.js index 7de8af8..29ddc5b 100644 --- a/test/poolFactory.test.js +++ b/test/poolFactory.test.js @@ -11,7 +11,7 @@ const [chairperson, alice, bob, charlie, danny] = accounts; describe("PoolFactory", () => { it("enroll everyone", async () => { - pool = await PoolFactory.new(false, chairperson, { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "0x"+"title", "0x"+"description", { from: chairperson }); assert.isTrue(await pool.is_owner({ from: chairperson })) await pool.enroll(alice, { from: chairperson }); @@ -29,10 +29,13 @@ describe("PoolFactory", () => { await pool.enroll(danny, { from: chairperson }); const dannyBalance = await pool.balance({ from: danny }); assert.equal(dannyBalance, 0, "initial balance is incorrect"); + + const poolInfo = await pool.getInfo({from: chairperson}); + console.log(poolInfo) }); it("should deposit correct amount", async () => { - pool = await PoolFactory.new(false, chairperson, { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "0x"+"title", "description", { from: chairperson }); const deposit = 1.5 * ether; await pool.enroll(alice, { from: chairperson }); const receipt = await pool.deposit({ from: alice, value: Web3.utils.toBN(deposit) }); @@ -52,7 +55,7 @@ describe("PoolFactory", () => { }); it("should not deposit if not enrolled", async () => { - pool = await PoolFactory.new(false, chairperson, { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "0x"+"title", "description", { from: chairperson }); const deposit = 1.5 * ether; await expectRevert( @@ -62,7 +65,7 @@ describe("PoolFactory", () => { }); it("should withdraw correct amount", async () => { - pool = await PoolFactory.new(false, chairperson, { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "0x"+"title", "description", { from: chairperson }); const deposit = 5 * ether; await pool.enroll(alice, { from: chairperson }); @@ -78,7 +81,7 @@ describe("PoolFactory", () => { }); it("should keep balance unchanged if withdraw greater than balance", async () => { - pool = await PoolFactory.new(false, chairperson, { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "0x"+"title", "description", { from: chairperson }); const deposit = 3 * ether; await pool.enroll(alice, { from: chairperson }); @@ -93,7 +96,7 @@ describe("PoolFactory", () => { }); it("should revert ether sent to this contract through fallback", async () => { - pool = await PoolFactory.new(false, chairperson, { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "0x"+"title", "description", { from: chairperson }); const deposit = 3 * ether; const first_balance = await balance.current(alice); @@ -109,7 +112,7 @@ describe("PoolFactory", () => { }); it("should allow depost if pool is public", async () => { - pool = await PoolFactory.new(true, chairperson, { from: chairperson }); + pool = await PoolFactory.new(true, chairperson, "title", "description", { from: chairperson }); const deposit = 3 * ether; await pool.deposit({ from: alice, value: Web3.utils.toBN(deposit) }); await pool.deposit({ from: bob, value: Web3.utils.toBN(deposit) }); From 014209f9ccdc0aa759fbd09bd0007c13366fee83 Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Sat, 24 Apr 2021 02:27:41 +0200 Subject: [PATCH 6/8] restore removePool method --- contracts/PoolRecorder.sol | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/contracts/PoolRecorder.sol b/contracts/PoolRecorder.sol index 661ab3a..2275825 100644 --- a/contracts/PoolRecorder.sol +++ b/contracts/PoolRecorder.sol @@ -19,6 +19,16 @@ contract PoolRecorder { return address(newPoolBank); } + function removePool(address poolAddress) public { + for (uint256 index = 0; index < poolList.length; index++) { + if (poolList[index] == poolAddress) { + poolList[index] = poolList[poolList.length - 1]; + delete poolList[poolList.length - 1]; + break; + } + } + } + function getListPools() public view returns (address[] memory) { return poolList; } From e91bbc5ec5526d9863b82c73eb71687658f8511b Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Sat, 24 Apr 2021 02:35:20 +0200 Subject: [PATCH 7/8] update PoolFactory.test.js --- test/poolFactory.test.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/poolFactory.test.js b/test/poolFactory.test.js index 29ddc5b..a3d9d4d 100644 --- a/test/poolFactory.test.js +++ b/test/poolFactory.test.js @@ -11,7 +11,7 @@ const [chairperson, alice, bob, charlie, danny] = accounts; describe("PoolFactory", () => { it("enroll everyone", async () => { - pool = await PoolFactory.new(false, chairperson, "0x"+"title", "0x"+"description", { from: chairperson }); + pool = await PoolFactory.new(false, chairperson, "title", "description", { from: chairperson }); assert.isTrue(await pool.is_owner({ from: chairperson })) await pool.enroll(alice, { from: chairperson }); @@ -30,8 +30,13 @@ describe("PoolFactory", () => { const dannyBalance = await pool.balance({ from: danny }); assert.equal(dannyBalance, 0, "initial balance is incorrect"); - const poolInfo = await pool.getInfo({from: chairperson}); - console.log(poolInfo) + const poolInfo = await pool.getPoolInfo({from: chairperson}); + assert.equal(poolInfo[0], "title") + assert.equal(poolInfo[1], "description") + assert.equal(poolInfo[2], chairperson) + assert.equal(poolInfo[3], false) + assert.equal(poolInfo[4].toNumber(), 5) + }); it("should deposit correct amount", async () => { From 6e683dc5cb9537cd4bc77023f65ec409aedb8dcc Mon Sep 17 00:00:00 2001 From: Eddine Omar Date: Mon, 26 Apr 2021 21:59:37 +0200 Subject: [PATCH 8/8] use modifier in order to factor code --- contracts/PoolFactory.sol | 106 ++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 33 deletions(-) diff --git a/contracts/PoolFactory.sol b/contracts/PoolFactory.sol index 247a13b..04ed384 100644 --- a/contracts/PoolFactory.sol +++ b/contracts/PoolFactory.sol @@ -15,7 +15,12 @@ contract PoolFactory is Compound { // Log the event about a deposit being made by an address and its amount event LogDepositMade(address indexed accountAddress, uint256 amount); - constructor(bool _isPublic, address _owner, string memory _title,string memory _description) { + constructor( + bool _isPublic, + address _owner, + string memory _title, + string memory _description + ) { /* Set the owner to the creator of this contract */ isPublic = _isPublic; owner = _owner; @@ -26,11 +31,42 @@ contract PoolFactory is Compound { participantsList.push(owner); } + modifier onlyOwnerOrPublic() { + require(msg.sender == owner, "Only owner can call this function."); + _; + } + + modifier onlyOwner() { + require(msg.sender == owner, "Not authorized"); + _; + } + + modifier autoEnroll() { + if (is_allowed(msg.sender) == false) { + participantsList.push(msg.sender); + balances[msg.sender] = 0; + exists[msg.sender] = true; + } + _; + } + + modifier onlyEnrolled() { + require(exists[msg.sender] == true, "Not allowed"); + _; + } + + modifier sufficentBalanceCheck(uint256 withdrawAmount) { + require( + withdrawAmount <= balances[msg.sender], + "Error amount, can't withdraw more than deposit" + ); + _; + } + /// @notice Enroll a customer with the bank, /// Only the owner can enroll a participant /// @return The balance of the user after enrolling - function enroll(address participant) public returns (uint256) { - require(msg.sender == owner, "Not authorized"); + function enroll(address participant) public onlyOwner returns (uint256) { require(exists[participant] == false, "Already enrolled"); participantsList.push(participant); balances[participant] = 0; @@ -40,13 +76,13 @@ contract PoolFactory is Compound { /// @notice Deposit ether into bank, requires method is "payable" /// @return The balance of the user after the deposit is made - function deposit() public payable returns (uint256) { - require(exists[msg.sender] == true || isPublic == true, "Not allowed"); - if (is_allowed(msg.sender) == false) { - participantsList.push(msg.sender); - balances[msg.sender] = 0; - exists[msg.sender] = true; - } + function deposit() + public + payable + onlyOwnerOrPublic + autoEnroll + returns (uint256) + { balances[msg.sender] += msg.value; emit LogDepositMade(msg.sender, msg.value); return balances[msg.sender]; @@ -55,14 +91,10 @@ contract PoolFactory is Compound { function deposit_and_invest_compound(address payable _cEtherContract) public payable + onlyOwnerOrPublic + autoEnroll returns (uint256) { - require(exists[msg.sender] == true || isPublic == true, "Not allowed"); - if (is_allowed(msg.sender) == false) { - participantsList.push(msg.sender); - balances[msg.sender] = 0; - exists[msg.sender] = true; - } balances[msg.sender] += msg.value; supplyEthToCompound(_cEtherContract); emit LogDepositMade(msg.sender, msg.value); @@ -73,31 +105,29 @@ contract PoolFactory is Compound { /// @return remainingBal : the balance remaining for the user function withdraw(uint256 withdrawAmount) public + onlyEnrolled + sufficentBalanceCheck(withdrawAmount) returns (uint256 remainingBal) { - require(exists[msg.sender] == true, "Not allowed"); - require(withdrawAmount <= balances[msg.sender], "Error amount, can't withdraw more than deposit"); - // Check enough balance available, otherwise just return balance - if (withdrawAmount <= balances[msg.sender]) { - balances[msg.sender] -= withdrawAmount; - payable(msg.sender).transfer(withdrawAmount); - } + balances[msg.sender] -= withdrawAmount; + payable(msg.sender).transfer(withdrawAmount); return balances[msg.sender]; } - function withdraw_and_redeem(uint256 withdrawAmount, bool redeemType, - address _cEtherContract) + function withdraw_and_redeem( + uint256 withdrawAmount, + bool redeemType, + address _cEtherContract + ) public + onlyEnrolled + sufficentBalanceCheck(withdrawAmount) returns (uint256 remainingBal) { - require(exists[msg.sender] == true, "Not allowed"); - require(withdrawAmount <= balances[msg.sender], "Error amount, can't withdraw more than deposit"); // Check enough balance available, otherwise just return balance redeemCEth(withdrawAmount, redeemType, _cEtherContract); - if (withdrawAmount <= balances[msg.sender]) { - balances[msg.sender] -= withdrawAmount; - payable(msg.sender).transfer(withdrawAmount); - } + balances[msg.sender] -= withdrawAmount; + payable(msg.sender).transfer(withdrawAmount); return balances[msg.sender]; } @@ -127,7 +157,7 @@ contract PoolFactory is Compound { return owner; } - function is_public() public view returns(bool) { + function is_public() public view returns (bool) { return isPublic; } @@ -148,7 +178,17 @@ contract PoolFactory is Compound { return participantsList; } - function getPoolInfo() public view returns(string memory, string memory, address, bool, uint) { + function getPoolInfo() + public + view + returns ( + string memory, + string memory, + address, + bool, + uint256 + ) + { return (title, description, owner, isPublic, participantsList.length); } }