2

Hi im new to smart contracts and trying to create a contract that stores and splits the funds between founders is this anywhere near close or can anyone help me please. Thank you

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.4;

import './Ownable.sol';

interface wallet {

    function getCut(address _from, address _to, uint _value) external returns(bool success);

    function splitFoundersCut(uint _amount, address Ceo, address Cfo, address Cto) external returns(bool success);
}

interface ERC20 {
    function totalSupply() external view returns(uint supply);

    function balanceOf(address _owner) external view returns(uint balance);

    function transfer(address _to, uint _value) external returns(bool success);

    function transferFrom(address _from, address _to, uint _value) external returns(bool success);

    function approve(address _spender, uint _value) external returns(bool success);

    function allowance(address _owner, address _spender) external view returns(uint remaining);

    function decimals() external view returns(uint digits);
    event Approval(address indexed _owner, address indexed _spender, uint _value);

    function deposit() external payable;

    function withdraw(uint256 wad) external;
}

contract FoundersWallet is Ownable {

    address payable Ceo = 0x471F9361ec8Fc947d371B95e5a5f5820C7A42A1B;
    address payable Cto = 0x471F9361ec8Fc947d371B95e5a5f5820C7A42A1B;
    address payable Cfo = 0x471F9361ec8Fc947d371B95e5a5f5820C7A42A1B;

    uint256 amount = address(this).balance;

    function withdraw() internal returns(bool) {

        if(amount > 0) {
            Ceo.transfer((amount / 40));
            Cto.transfer((amount / 40));
            Cfo.transfer((amount / 20));
        }

        else {
            return false;
        }
    }
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
Leeb
  • 21
  • 2

1 Answers1

0

Your code is assigning the value of uint256 amount only when the contract is created, and not updating it when the balance changes. Which would result in having the value of amount always 0.

Note: I'm not counting for edge cases like the contract address already having ETH value before the contract is deployed, or sending ETH to your contract using selfdestruct(). These are valid cases, but out of scope for this question.

The withdraw() function is expected to return boolean. But when you don't return any value, the caller may interpret it as false. So I'd advise to return true if the transfer was successful.

Also, you might want to be able to call the withdraw() function externally, so mark it as external instead of internal. But this depends on your use case and maybe you're already calling it internally from another function that is not shown in your question.

pragma solidity ^0.7.4;

contract FoundersWallet is Ownable {

    address payable Ceo = 0x471F9361ec8Fc947d371B95e5a5f5820C7A42A1B;
    address payable Cto = 0x471F9361ec8Fc947d371B95e5a5f5820C7A42A1B;
    address payable Cfo = 0x471F9361ec8Fc947d371B95e5a5f5820C7A42A1B;

    function withdraw() external returns(bool) { // visibility `external`
        // moved the `amount` here so that it's recalculated on each function call
        uint256 amount = address(this).balance;

        if(amount > 0) {
            Ceo.transfer((amount / 40));
            Cto.transfer((amount / 40));
            Cfo.transfer((amount / 20));
            
            return true; // added the return value
        }
        
        // don't need the `else` because of the early return
        return false;
    }
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100