I need some kind of "Referral and Reward points modules mix".

When the new customer 1 create an account, he has to enter his referrer's (who is already registered custumer 2) unique ID as a required information.
Customer 1 get reward points as a persent of his order's cost, but also the customer 2 get some points, as he is referrer of customer 1. If customer 1 brought up someone else, let it be Customer 3 and 4, he and Customer 2 get reward points as a persent of Customer 3 and 4 orders and so on. This points can be used at the shop but also can be taken as cash.

Maybe that has been already done by someone in the community or have some issues on how it could be done.

I would be appreciate for any help.
Thanks