Help transfering a percentage of an amount to addresses in an array by their amounts

Basically, I need to take an amount and send it to addresses that are in an array. The amount would be distributed by the percentage of the tokens they have from the total amount of coins.

User1 has 25
User2 has 25
User2 has 50
Total of 100

Amount sent 10
User1 gets 2.5
User2 gets 2.5
User2 gets 5

I cant figure out how to get the addresses in the array with their amounts and their percentage of tokens.

I posted about this yesterday with the code I've been working on:

Iterating over an array is not a good idea, unless the array will have a known fixed length.

You can take a look at PaymentSplitter for a pull-based model that implements basically the same thing you’re trying to do.

You’re right. That’s perfect for my problem. How do I use it alongside my contract? Import it and call the events? I’ve never used contracts together like this.

It’s a standalone contract. You deploy it and then you send ETH to it, or the native token in whatever chain you’re on. It does not work with ERC20, you would have to write a similar one for that.