Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permit2: write a permit2 router #420

Closed
wants to merge 20 commits into from

Conversation

Louis-Amas
Copy link
Contributor

@Louis-Amas Louis-Amas commented Jul 27, 2023

In this pull request (PR), I integrated the Permit2 contract from Uniswap into our MangroveOrder contract. To achieve this, I created a new contract called Permit2Router, which inherits from the SimpleRouter implementation. The primary change is in the pull function. Within the pull function, I utilized Permit2 to facilitate fund transfers using the Permit2 contract. To enable this functionality, users' EOAs must call the approve function on the Permit2 contract to grant permission to the Permit2Router to withdraw funds on their behalf. Additionally, users have the option to generate an off-chain Transfer signature that authorizes the contract specified in the signature to perform a one-time fund withdrawal from their EOA instead of calling approve.

The new use cases of MangroveOrder are as follows:

  1. MarketOrder: This type of order utilizes the marketOrderWithTransferApproval function. In this scenario, the MangroveOrder contract pulls the specified amount of inbound_tkn from the msg.sender using just-in-time one-time approval. Subsequently, it executes a market order and returns any unused funds back to the user.

  2. LimitOrder with takeWithPermit: When using this function, a user initiates an off-chain permit signature, which is sent to the Permit2 contract to authorize the MangroveOrder router to withdraw funds from the Permit2 contract. After this, the function call take and initiate a limit order.

  3. LimitOrder with take: Similar to the previous case, the user calls permit or approve to the Permit2 contract beforehand. After this, they can do a LimitOrder by calling take.

These modifications expand the functionalities of MangroveOrder to permit the users to approve once by token by chain the permit2 contract, instead of approving once by token by contract that needs to pull the funds.

src/strategies/routers/AbstractRouter.sol Outdated Show resolved Hide resolved
src/strategies/routers/SimpleRouter.sol Outdated Show resolved Hide resolved
src/strategies/routers/integrations/AavePooledRouter.sol Outdated Show resolved Hide resolved
test/strategies/unit/AavePooledRouter.t.sol Outdated Show resolved Hide resolved
@Louis-Amas Louis-Amas marked this pull request as ready for review August 1, 2023 16:15
@espendk
Copy link
Collaborator

espendk commented Sep 6, 2023

Closing this at is has been migrated to the new mangrove-strats repo: mangrovedao/mangrove-strats#13

@espendk espendk closed this Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants