An Agent-based Theory of Social Economy