title_body: How to validate transaction where number of tokens are generated based on the value locked in a contract? As far as my understanding token with some amount can be forged by using this constraints.
  Constraints.mustForgeValue SomeValue
  
  And ada can be locked into smart contract using mustPayToTheScript if i am not wrong.
  So how to validate this transaction where some ada can be deposited to the contract and contract forges the equivalent amount of tokens according to the amount of ada locked in smart contract.
upvoted_answer: Yes, Constraints.mustForgeValue and Constraints.mustPayToTheScript are used to define/create a transaction that forges tokens or locks tokens in your script respectively (https://youtu.be/6VbhY162GQA?t=1720).
  There are multiple script types that validate different aspects of a transaction.
  If you want to spend funds locked in a script(address) you need a validator script (Plutus.V1.Ledger.Scripts.Validator) that will validate any transaction consuming the UTXOs locked in that script. To lock funds in a script you need to transfer funds to that script, thus creating a new UTXO that is owned by the script.
  If you want to forge tokens in a transaction you need a minting policy script (Plutus.V1.Ledger.Scripts.MonetaryPolicy) which validates that the forged tokens adhere to the specified policy. Minting policy scripts don't have a Datum and Redeemer available, because the transaction is not consuming a UTXO locked in the minting policy. I don't think sending funds to a minting policy makes sense or is even possible.
  In your case you might want to have two scripts:
  
  MonetaryPolicy: validates the minting transaction
  Validator: A script that manages funds created from minting
  
  The minting policy then has to make sure that the adequate amount of ada is being transferred to the fund-managing-script when validating the minting transaction.
  When creating the minting transaction you can use Constraints.mustPayToOtherScript to send funds to the script.