Skip to content

ERC20 Transfer #3

Description

@ssolson

Old code previously used to send erc20s

/**
* @dev Owner may add ERC20 token addresses.
* @param _token token to add.
*/
function addERC20ToTrust(address _token) external {
    require(_token != address(0), 'address can not be zero address');
    // require(allowance>balance) //Need to add inputs for this check
    GrantorAssets[msg.sender].push(_token);
    uniqueAssets.add(_token);
    emit AddedERC20(msg.sender, _token);
}

/**
 * @notice Checks the balance of a passed token for a provided wallet.
 * @param _token The target token.
 * @param _wallet The target token.
 */
function erc20Balance(
    address _token,
    address _wallet)
    view
    public
    returns (uint256 total)
{
    total = IERC20(_token).balanceOf(_wallet);
    return total;
}

/**
 * @notice transfers the passed token from the grantor to the specified address.
 * @param _token The target token.
 * @param _from The grantor's wallet.
 * @param _to The trustee or beneficiary's wallet
 * @param _amount The _amount to send.
 */
function erc20TransferFrom(
    address _token,
    address _from,
    address _to,
    uint256 _amount
    ) public
{
    IERC20(_token).transferFrom( _from, _to, _amount);
}

/**
 * @notice transfers fungibles to the beneficiaries
 */
function executeERC20Trust() public onlyRole(TRUSTEE_ROLE) {
    // require(block.timestamp > checkInPeriodEnd, "Check-In Period is still live.") ;
    require(address(beneficiaryContract) != address(0));

    // Iterate over Grantor wallets
    for (
        uint256 grantor_wallet_idx = 0;
        grantor_wallet_idx < grantor.length();
        grantor_wallet_idx++
    ) {
        // Iterate over tokens in Grantor wallet
        address grantorAddress = grantor.at(grantor_wallet_idx);
        address[] memory grantorAddress_tokens = GrantorAssets[grantorAddress];
        for (
            uint256 asset_idx = 0;
            asset_idx < grantorAddress_tokens.length;
            asset_idx++
        ) {
            address asset_addr = grantorAddress_tokens[asset_idx];
            uint256 total_assets = erc20Balance(asset_addr, grantorAddress);
            // require(sent, "Failed to get balance.");
            // if (total_assets==0) {pass}
            erc20TransferFrom( asset_addr,
                grantorAddress,
                address(beneficiaryContract),
                total_assets
            );
            // (bool sent) =
            // require(sent, "Failed to withdraw tokens");
        }
    }
}

    /**
 * @notice transfers fungibles to the beneficiaries
 */
function claimERC20() public {
    // Send ether
    beneficiaryContract.release(msg.sender);

    // Iterate over tokens in Grantor wallet
    address grantorAddress = grantor[grantor_wallet_idx];
    address[] memory grantorAddress_tokens = GrantorAssets[grantorAddress];
    for (
        uint256 asset_idx = 0;
        asset_idx < grantorAddress_tokens.length;
        asset_idx++
    ) {
        address asset_addr = grantorAddress_tokens[asset_idx];
        uint256 total_assets = erc20Balance(asset_addr, grantorAddress);
        // require(sent, "Failed to get balance.");
        // if (total_assets==0) {pass}
         beneficiaryContract.release(asset_addr, msg.sender);
        // (bool sent) =
        // require(sent, "Failed to withdraw tokens");
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions