Search code examples
blockchainethereumsoliditysmartcontractsuniswap

How permit function works


I'm trying to figure out what's purpose of permit function from the Uniswap core

I know that ecrecover function ensures, that messages was signed by some address, but that's not clear for me -- why we can use permit function?


Solution

  • The owner can sign a structured message which produces a signature (separated into variables v, r, and s).

    Meaning of the message could be described like "I, the owner, am approving the spender to operate value of my LP tokens of this specific Uniswap pair. This approval needs to be recorded onchain before deadline."

    The owner then passes the signature and the values offchain to anyone else (e.g. to the spender), who executes the permit() function. By executing the permit() function, the approval becomes valid since now it's recorded onchain.


    This is useful in cases when the owner has LP tokens - but doesn't have sufficient native balance to pay for gas fees for their transfer or approval.

    Or when the owner is a user of your app and you have some kind of an agreement that your app will pay gas fees for the user. E.g. because they compensate you for the gas fees using another way - stablecoins, monthly fee, etc.