Uniswap / permit2

🔑🔑🔑 next generation token approvals mechanism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Who has integrated permit2?

michaelr524 opened this issue · comments

Permit2 seems like a great solution with many wins for security and efficiency.
We are considering integrating it in the next version of our smart contracts.

It could be great to understand who has already integrated permit2 in production.
And if there is any good practices to adhere to already from your experience.

commented

We have integrated with Permit2, though I cannot say if we followed best practices, couldn't find many other protocols to compare our code with. Here is our contract for deposits/withdrawals that uses permit2:

https://github.com/CygnusDAO/core/blob/main/contracts/cygnus-core/CygnusTerminal.sol#L269

For the frontend/how to interact with it you can check our scripts and tests, for example:

https://github.com/CygnusDAO/core/blob/main/test/core/Permit2.js#L118

Hope it helps.

We've almost finished integrating as well, both Allowance and Signature methods.
I wonder why you and Uniswap chose to implement just the allowance method?
Also, did you stumble on any issues with wallets signing the JSON?

commented

We've almost finished integrating as well, both Allowance and Signature methods. I wonder why you and Uniswap chose to implement just the allowance method? Also, did you stumble on any issues with wallets signing the JSON?

The reason we implemented the Allowance methods on our core contracts is because other contracts may use the deposit/withdraw function. Other contracts can simply approve our contract in permit2, and then pass an empty signature to the deposit function bypassing the signature approval. I think this wouldn't be possible with the Signature methods. I would say that Uniswap did it for the same reason, but that's just a guess.

In our case the deposit/withdrawals happen on the core and everything else is done via our router, which is integrated with both:

Repay with Signature: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L703

Repay with Allowance: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L665

Liquidate with Signature: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L800

Liquidate with Allowance: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L761

I haven't stumbled upon any issues with wallets signing, on the contrary, it's very smooth. Here is one of our core contracts live on Polygon where u can see the deposits:

https://polygonscan.com/address/0x520F4Cd05a3F727459E0d6B2Dbc78593d6DfE281

And here a repay tx with the allowance method mentioned above - could have been done with the signature method just as well:

https://polygonscan.com/tx/0x6e3c5b9ea642d62a69b350a4ce03f82336308c000624d20d5c8f09965d04faf9

@0xHyoga Thank you for sharing.

commented

@0xHyoga Thank you for sharing.

You're welcome!

Casi hemos terminado de integrar también los métodos de asignación y firma. Me pregunto por qué usted y Uniswap eligieron implementar solo el método de asignación. Además, ¿tuvo algún problema con las billeteras que firman el JSON?

La razón por la que implementamos los métodos de asignación en nuestros contratos principales es porque otros contratos pueden usar la función de depósito/retiro. Otros contratos pueden simplemente aprobar nuestro contrato en permit2 y luego pasar una firma vacía a la función de depósito sin pasar por la aprobación de la firma. Creo que esto no sería posible con los métodos de Firma. Yo diría que Uniswap lo hizo por la misma razón, pero eso es sólo una suposición.

En nuestro caso, los depósitos/retiros se realizan en el núcleo y todo lo demás se hace a través de nuestro enrutador, que está integrado con ambos:

Repay with Signature: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L703

Repay with Allowance: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L665

Liquidate with Signature: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L800

Liquidate with Allowance: https://github.com/CygnusDAO/periphery/blob/main/contracts/cygnus-periphery/CygnusAltair.sol#L761

I haven't stumbled upon any issues with wallets signing, on the contrary, it's very smooth. Here is one of our core contracts live on Polygon where u can see the deposits:

https://polygonscan.com/address/0x520F4Cd05a3F727459E0d6B2Dbc78593d6DfE281

Y aquí, un reembolso de transmisión con el método de asignación mencionado anteriormente, también podría haberse realizado con el método de firma:

https://polygonscan.com/tx/0x6e3c5b9ea642d62a69b350a4ce03f82336308c000624d20d5c8f09965d04faf9