I was looking at Rocket Pool's docs on interacting with other contracts and they included a simple example function that another protocol could use to accept deposits of ETH, forward it to RP, and get back rETH. See below.
My question is about balance1 and balance2 for measuring how much someone who called this function deposited...specifically what if two people both called deposit at the same time...wouldn't address(this) contain both their funds and therefore balance2 would credit them with too much rETH?
deposit() external payable {
// Check deposit amount
require(msg.value > 0, "Invalid deposit amount");
// Load contracts
address rocketDepositPoolAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketDepositPool")));
RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(rocketDepositPoolAddress);
address rocketTokenRETHAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketTokenRETH")));
RocketTokenRETHInterface rocketTokenRETH = RocketTokenRETHInterface(rocketTokenRETHAddress);
// Forward deposit to RP & get amount of rETH minted
uint256 rethBalance1 = rocketTokenRETH.balanceOf(address(this));
rocketDepositPool.deposit{value: msg.value}();
uint256 rethBalance2 = rocketTokenRETH.balanceOf(address(this));
require(rethBalance2 > rethBalance1, "No rETH was minted");
uint256 rethMinted = rethBalance2 - rethBalance1;
// Update user's balance
balances[msg.sender] += rethMinted;
}