I want to build an ERC20 token and I want to add staking functionality for liquidity providers. If someone decided to make a liquidity pool with my tokens and then stake it to my contract to earn profits, Is ther any way for me to determine these LP tokens created against which pair of tokens? I meen if somebody transfer some LP tokens to my contract how can I determine these LP tokens represents which pair of tokens in Solidity?
When you provide liquidity to a pool you will receive LP tokens for that specific pool (with a contract address unique to that pair). You can check the contract address for your tokens LP token and only provide rewards to users holding those LP tokens. However, here you need to know the platforms that allow liquidity pool creation for your token, take note of the LP tokens address, and make sure your staking contract is aware of them.
If you are looking for a way to derive the token pair simply for the LP token address then I don't believe this is possible as different platform have different logic for creating LP contracts. For example, with Uniswap it is possible to get the underlying token pair by calling token0 and token1 which will return the underlying token address, but you can't be sure other platforms will make that information available to you as a public variable.