This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add liquidity unbalanced permit2 (#1117)
* feat: add permit2 signature step * chore: rename includesNativeAsset * feat: avoid buildcall when permit2 is not signed * fix: add nonces query * chore: add token symbols to permit2 transfer label * refactor: extract base abstract class * refactor: extract signature helpers * fix: sign permit2 loading condition * chore: extract token helpers * feat: add 24h permit2 expiration * fix: unit tests after rename * chore: refactor hasValidPermit2 --------- Co-authored-by: uiuxxx <[email protected]>
- Loading branch information
Showing
49 changed files
with
953 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
'use client' | ||
|
||
import { getGqlChain, getNetworkConfig } from '@/lib/config/app.config' | ||
import { BPT_DECIMALS } from '@/lib/modules/pool/pool.constants' | ||
import { useUserAccount } from '@/lib/modules/web3/UserAccountProvider' | ||
import { permit2Abi } from '@balancer/sdk' | ||
import { Center, Input, Text, VStack } from '@chakra-ui/react' | ||
import { useState } from 'react' | ||
import { Address, formatUnits } from 'viem' | ||
import { sepolia } from 'viem/chains' | ||
import { useReadContract } from 'wagmi' | ||
|
||
export default function Page() { | ||
const [tokenAddress, setTokenAddress] = useState<Address>('' as Address) | ||
|
||
const { chain, userAddress } = useUserAccount() | ||
|
||
const chainId = chain?.id || sepolia.id | ||
|
||
const { data } = usePermit2Allowance({ chainId, tokenAddress, owner: userAddress }) | ||
|
||
return ( | ||
<Center> | ||
<VStack w="50%"> | ||
<Text> | ||
Enter address of token to check permit2 allowance in the current chain:{' '} | ||
{chain ? chain.name : 'None'} | ||
</Text> | ||
<Input type="text" onChange={e => setTokenAddress(e.target.value as Address)} /> | ||
|
||
{data && ( | ||
<div> | ||
<div>Amount: {formatUnits(data[0], BPT_DECIMALS).toString()}</div> | ||
<div>Expires: {data[1]}</div> | ||
<div>Nonce: {data[2]}</div> | ||
</div> | ||
)} | ||
</VStack> | ||
</Center> | ||
) | ||
} | ||
|
||
type Params = { | ||
chainId: number | ||
tokenAddress: Address | ||
owner: Address | ||
} | ||
function usePermit2Allowance({ chainId, tokenAddress, owner }: Params) { | ||
const permit2Address = '0x000000000022D473030F116dDEE9F6B43aC78BA3' | ||
const balancerRouter = getNetworkConfig(getGqlChain(chainId)).contracts.balancer.router! | ||
const spender = balancerRouter | ||
|
||
return useReadContract({ | ||
chainId, | ||
address: permit2Address, | ||
abi: permit2Abi, | ||
functionName: 'allowance', | ||
args: [owner, tokenAddress, spender], | ||
query: { | ||
enabled: !!tokenAddress && !!owner, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/modules/pool/actions/add-liquidity/handlers/AddLiquidity.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.