Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

feat: add liquidity unbalanced permit2 #1117

Merged
merged 44 commits into from
Oct 7, 2024
Merged

Conversation

agualis
Copy link
Contributor

@agualis agualis commented Sep 23, 2024

Adds v3 permit2 flow only for unbalanced add handler.
Contains many TODOs but let's merge it before moving to the monorepo.
Note: It only works pointing to test api in .env.local as sepolia v3 pools are not yet in production api

Unbalanced add
https://github.com/user-attachments/assets/dd105d30-3df6-40a7-a05d-d18689fca49a

Reuse signature in the next 24h after permit2 signature
https://github.com/user-attachments/assets/b824a3bf-b210-4956-b970-7d7aa1192574

@garethfuller we can avoid signing the permit2 for those tokens that have 0 amount but I got some errors when I tried that so I will do that in a different PR 👇
MAX amount during 24H:
permi2Dai

@agualis agualis self-assigned this Sep 23, 2024
Copy link

vercel bot commented Sep 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
frontend-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 7, 2024 1:45pm
test-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 7, 2024 1:45pm

@@ -106,4 +134,22 @@ export class UnbalancedAddLiquidityHandler implements AddLiquidityHandler {
kind: AddLiquidityKind.Unbalanced,
}
}

public constructBaseBuildCallInput({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will probably try to extract this method to be shared by all the handlers but for now I will keep it here until I implement the rest of the v3 handlers

slippage: Slippage.fromPercentage(`${Number(slippagePercent)}`),
wethIsEth: this.helpers.includesNativeAsset(sdkQueryOutput.amountsIn),
}
// baseBuildCallParams.amountsIn = baseBuildCallParams.amountsIn.filter(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will delete this later. It is a reminder to try something...

@@ -0,0 +1,55 @@
//TODO: move all this file logic to a better place
Copy link
Contributor

Choose a reason for hiding this comment

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

Just call it add-liquidity.utils.ts for now.

Comment on lines 45 to 67
}
}

async function signPermit2({
sdkClient,
pool,
humanAmountsIn,
permit2Input,
nonces,
}: SignPermit2Params): Promise<Permit2> {
if (!sdkClient) throw new Error('Missing sdkClient')
const baseInput = constructBaseBuildCallInput({
humanAmountsIn,
slippagePercent: permit2Input.slippagePercent,
// TODO: generalize for all v3 pool types
sdkQueryOutput: permit2Input.sdkQueryOutput as AddLiquidityBaseQueryOutput,
pool,
})

const signature = await Permit2Helper.signAddLiquidityApproval({
...baseInput,
client: sdkClient,
owner: permit2Input.account,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be generalized or does it need to be two functions, one for add liquidity and one for swaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably both, I would wait until we implement V3 swaps.

}, [setSignPermit2State, sdkClient])

//TODO: Generalize for Swaps and other potential signatures
const minimumBpt = queryOutput?.sdkQueryOutput.bptOut.amount
Copy link
Contributor

Choose a reason for hiding this comment

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

The naming here is a bit misleading? It's not minimum, you're just checking that
we have a bptOut value right? If so, I'd change to:

Suggested change
const minimumBpt = queryOutput?.sdkQueryOutput.bptOut.amount
const hasBptOut = !!queryOutput?.sdkQueryOutput.bptOut.amount

Comment on lines +78 to +82
labels: {
title: `Permit on balancer`,
init: `Sign permit`,
tooltip: 'Sign permit',
},
Copy link
Contributor

@garethfuller garethfuller Oct 7, 2024

Choose a reason for hiding this comment

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

I don't think we should change user facing terminology for users from Approvals.
Because in the end it's the same thing, just the underlying tech is a bit
different. If they need more information about what type of a approval they are
doing then we can provide more information, but that should be nested. Please
confirm this with Pon.

Copy link
Contributor Author

@agualis agualis Oct 7, 2024

Choose a reason for hiding this comment

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

I suggest to wait until we have everything together (v3 adds/removes for different kinds of pools) and then review the labels and UX hints (tooltips, links etc) after some user testing.

@agualis agualis merged commit c2b5bba into main Oct 7, 2024
5 of 6 checks passed
@agualis agualis deleted the feat/addLiquidityPermit2 branch October 7, 2024 13:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unbalanced v3 Adds/Permit2 support
3 participants