Please check the application carefully, I am describing the application lifecycle.
Agent Will sell the product, not Admin, make some fresh users with the referral code.
During sales, select that users which registered using another referral code. Such as
User 1 has been registered
User 2 registered using User1 Ref Code
Agent1 sold some product to user 2
The Commission will be divided by below format
Agent1 will get his mentioned percent as commission
User1 will get the commission as percent for reference
User2 will get his commission for buying the product (You can disable it by the set commission to 0 at settings)
Admin Will get his commission as mentioned percent as platform owner
In the settings, you can set persons commission
If you need anything more or your requirement is the difference, then you need to be customized this product, it will reduce your cost instead of making the new one.