library Rebalance {

    struct TokenFlow {
        address[] addresses;
        uint256[] inflow;
        uint256[] outflow;
    }

    function composeTokenFlow(
        address[] memory _addresses,
        uint256[] memory _inflow,
        uint256[] memory _outflow
    )
        internal
        pure
        returns(TokenFlow memory)
    {
        return TokenFlow({addresses: _addresses, inflow: _inflow, outflow: _outflow });
    }

    function decomposeTokenFlow(TokenFlow memory _tokenFlow)
        internal
        pure
        returns (address[] memory, uint256[] memory, uint256[] memory)
    {
        return (_tokenFlow.addresses, _tokenFlow.inflow, _tokenFlow.outflow);
    }

    function decomposeTokenFlowToBidPrice(TokenFlow memory _tokenFlow)
        internal
        pure
        returns (uint256[] memory, uint256[] memory)
    {
        return (_tokenFlow.inflow, _tokenFlow.outflow);
    }

    /**
     * Get token flows array of addresses, inflows and outflows
     *
     * @param    _rebalancingSetToken   The rebalancing Set Token instance
     * @param    _quantity              The amount of currentSet to be rebalanced
     * @return   combinedTokenArray     Array of token addresses
     * @return   inflowArray            Array of amount of tokens inserted into system in bid
     * @return   outflowArray           Array of amount of tokens returned from system in bid
     */
    function getTokenFlows(
        IRebalancingSetToken _rebalancingSetToken,
        uint256 _quantity
    )
        internal
        view
        returns (address[] memory, uint256[] memory, uint256[] memory)
    {
        // Get token addresses
        address[] memory combinedTokenArray = _rebalancingSetToken.getCombinedTokenArray();

        // Get inflow and outflow arrays for the given bid quantity
        (
            uint256[] memory inflowArray,
            uint256[] memory outflowArray
        ) = _rebalancingSetToken.getBidPrice(_quantity);

        return (combinedTokenArray, inflowArray, outflowArray);
    }
}
/**
 * @title Rebalance
 * @author Set Protocol
 *
 * Types and functions for Rebalance-related data.
 */
function getTokenFlows(
    IRebalancingSetToken _rebalancingSetToken,
    uint256 _quantity
)
    internal
    view
    returns (address[] memory, uint256[] memory, uint256[] memory)
{
    // Get token addresses
    address[] memory combinedTokenArray = _rebalancingSetToken.getCombinedTokenArray();

    // Get inflow and outflow arrays for the given bid quantity
    (
        uint256[] memory inflowArray,
        uint256[] memory outflowArray
    ) = _rebalancingSetToken.getBidPrice(_quantity);

    return (combinedTokenArray, inflowArray, outflowArray);
}

/**
 * Get token flows array of addresses, inflows and outflows
 *
 * @param    _rebalancingSetToken   The rebalancing Set Token instance
 * @param    _quantity              The amount of currentSet to be rebalanced
 * @return   combinedTokenArray     Array of token addresses
 * @return   inflowArray            Array of amount of tokens inserted into system in bid
 * @return   outflowArray           Array of amount of tokens returned from system in bid
 */