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

Add Permit and Permit2 signature docs #498

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

brunoguerios
Copy link
Member

Closes #369

@brunoguerios brunoguerios added the documentation Improvements or additions to documentation label Nov 22, 2024
@brunoguerios brunoguerios self-assigned this Nov 22, 2024
README.md Outdated
Comment on lines 733 to 774
### Permit2 Helper

Balancer v3 handles token approval through Pemit2 and this helper facilitates Permit2 signature generation.

Each operation (e.g. addLiquidity, swap, ...) has its own method that leverages the same input type of the operation itself in order to simplify signature generation.

**Example**

See [addLiquidityWithPermit2Signature example](/examples/addLiquidity/addLiquidityWithPermit2Signature.ts).

**Function**

Helper function to create a Permit2 signature for an addLiquidity operation:

```typescript
static async signAddLiquidityApproval(
input: AddLiquidityBaseBuildCallInput & {
client: PublicWalletClient;
owner: Address;
nonces?: number[];
expirations?: number[];
},
): Promise<Permit2>
```

**Parameters**

| Name | Type | Description |
| ------------- | ------------- | ------------ |
| input | [AddLiquidityBaseBuildCallInput](./src/entities/addLiquidity/types.ts#L62) | Add Liquidity Input |
| client | [PublicWalletClient](./src/utils/types.ts#L3) | Viem's wallet client with public actions |
| owner | Address | User address |
| nonces (optional) | number[] | Nonces for each token |
| expirations (optional) | number[] | Expirations for each token |

**Returns**

```typescript
Promise<Permit2>;
```

[Permit2](./src/entities/permit2Helper/index.ts#L35) - Permit2 object with metadata and encoded signature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! Good balance between brevity and detail

If the plan is to detail each of the Permit2Helper methods, this is a great blueprint 💪

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since different operations are quite similar, maybe this is enough to guide how to use them all?
Still trying to figure out of how much info is too much info 😅
What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm on the fence as well. might not be a bad idea to hope for the best and only add more explicit docs for each method if we get complaints

Comment on lines +76 to +96
// Skip Permit2 approval during fork setup so we can test approvals through signatures
const approveOnPermit2 = false;

// Make the tx against the local fork and print the result
await makeForkTx(
call,
{
rpcUrl,
chainId,
impersonateAccount: userAccount,
forkTokens: amountsIn.map((a) => ({
address: a.address,
slot: getSlot(chainId, a.address),
rawBalance: a.rawAmount,
})),
client,
},
[...amountsIn.map((a) => a.address), pool.address],
call.protocolVersion,
approveOnPermit2,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice move adding the flag that prevents the default cascade of approvals by makeForkTx so that we can know the example is working properly!

I do have a larger suggestion for team to consider that I will bring up during standup:

makeForkTx may confuse less experienced devs who might be distracted by token slots or not fully grasp how the call object the SDK creates is used to send the tx.

This may be a stretch that requires a fair bit of refactor, but perhaps rolling a simplified fork setup for examples could be an option where we use the default anvil account #0 to

  1. wrap ETH into wETH
  2. swap wETH into BAL
  3. add liquidity to wETH/BAL pool
  4. any necessary setup for boosted or nested joins / removes

From there, we should be able to focus examples on just the code needed for each operation and it would be easier to explain a simplified fork setup in some detail

Not suggesting this as part of this PR and not too attached to this idea, just a suggestion that could enable examples to be a little more straightforward

P.S. John had this idea for examples a while back. Not sure if it applies to add / remove, but wanted to raise awareness

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep as is for now, since we're evaluating different approach for examples on a separate PR.

@brunoguerios brunoguerios marked this pull request as ready for review November 27, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permit Signatures - Document relevant info
2 participants