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

Commit 97c06f4

Browse files
committed
Merge branch 'main' into feat/subSteps
2 parents 1df2fa5 + c2b5bba commit 97c06f4

File tree

8 files changed

+99
-87
lines changed

8 files changed

+99
-87
lines changed

.github/workflows/checks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
env:
77
NEXT_PUBLIC_BALANCER_API_URL: https://api-v3.balancer.fi/graphql
88
NEXT_PUBLIC_WALLET_CONNECT_ID: ${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_ID }}
9+
NEXT_PRIVATE_ALCHEMY_KEY: ${{ secrets.PRIVATE_ALCHEMY_KEY }}
910
NEXT_PRIVATE_DRPC_KEY: ${{ secrets.PRIVATE_DRPC_KEY }}
1011

1112
jobs:

lib/modules/pool/__mocks__/getPoolMock.ts

+6
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,11 @@ export async function getPoolMock(
3939
.then(response => response.json())
4040
.then(result => result.data)) as GetPoolQuery
4141

42+
if (!getPoolQuery.pool) {
43+
throw new Error(
44+
`Pool not found in api ${process.env.NEXT_PUBLIC_BALANCER_API_URL} network ${chain} poolId ${poolId}`
45+
)
46+
}
47+
4248
return getPoolQuery.pool as GqlPoolElement
4349
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import { SdkQueryAddLiquidityOutput } from '@/lib/modules/pool/actions/add-liquidity/add-liquidity.types'
22
import { getNowTimestampInSecs } from '@/lib/shared/utils/time'
33
import { AllowedAmountsByTokenAddress, ExpirationByTokenAddress } from './usePermit2Allowance'
4+
import { Address } from 'viem'
5+
import { TokenAmount } from '@balancer/sdk'
46

57
export function hasValidPermit2(
68
queryOutput?: SdkQueryAddLiquidityOutput,
79
expirations?: ExpirationByTokenAddress,
810
allowedAmounts?: AllowedAmountsByTokenAddress
911
): boolean {
1012
if (!expirations || !allowedAmounts) return false
11-
const isValid = !!queryOutput?.sdkQueryOutput.amountsIn.every(
12-
t =>
13-
t.amount === 0n ||
14-
(expirations[t.token.address] >= getNowTimestampInSecs() &&
15-
allowedAmounts[t.token.address] >= t.amount)
16-
)
13+
14+
const approvalExpired = (tokenAddress: Address) =>
15+
expirations[tokenAddress] >= getNowTimestampInSecs()
16+
const alreadyAllowed = (amountIn: TokenAmount) =>
17+
!approvalExpired(amountIn.token.address) &&
18+
allowedAmounts[amountIn.token.address] >= amountIn.amount
19+
const amountInValid = (amountIn: TokenAmount) =>
20+
amountIn.amount === 0n || alreadyAllowed(amountIn)
21+
const isValid = !!queryOutput?.sdkQueryOutput.amountsIn.every(amountInValid)
1722
return isValid
1823
}

lib/modules/tokens/approvals/useTokenApprovalSteps.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,28 @@ export function useTokenApprovalSteps({
6464
})
6565

6666
const steps = useMemo(() => {
67-
return tokenAmountsToApprove.map(tokenAmountToApprove => {
67+
return tokenAmountsToApprove.map((tokenAmountToApprove, index) => {
6868
const { tokenAddress, requiredRawAmount, requestedRawAmount } = tokenAmountToApprove
69+
// USDT edge-case: requires setting approval to 0n before adjusting the value up again
70+
const isApprovingZeroForDoubleApproval =
71+
requiresDoubleApproval(chain, tokenAddress) && requiredRawAmount === 0n
72+
const id = isApprovingZeroForDoubleApproval ? `${tokenAddress}-0` : tokenAddress
6973
const token = getToken(tokenAddress, chain)
7074
const symbol = bptSymbol ?? (token && token?.symbol) ?? 'Unknown'
7175
const labels = buildTokenApprovalLabels({ actionType, symbol, isPermit2 })
72-
const id = tokenAddress
7376

7477
const isComplete = () => {
7578
const isAllowed = tokenAllowances.allowanceFor(tokenAddress) >= requiredRawAmount
76-
// USDT edge-case: requires setting approval to 0n before adjusting the value up again
77-
if (requiresDoubleApproval(chain, tokenAddress)) return isAllowed
79+
if (isApprovingZeroForDoubleApproval) {
80+
// Edge case USDT case is completed if:
81+
// - The allowance is 0n
82+
// - The allowance is greater than the required amount (of the next step)
83+
return (
84+
tokenAllowances.allowanceFor(tokenAddress) === 0n ||
85+
tokenAllowances.allowanceFor(tokenAddress) >=
86+
tokenAmountsToApprove[index + 1].requiredRawAmount
87+
)
88+
}
7889
return requiredRawAmount > 0n && isAllowed
7990
}
8091

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@emotion/react": "^11.11.1",
4747
"@emotion/styled": "^11.11.0",
4848
"@nikolovlazar/chakra-ui-prose": "^1.2.1",
49-
"@rainbow-me/rainbowkit": "^2.1.6",
49+
"@rainbow-me/rainbowkit": "^2.1.7",
5050
"@sentry/nextjs": "^8.13.0",
5151
"@studio-freight/react-lenis": "^0.0.47",
5252
"@tanstack/react-query": "^5.56.2",
@@ -85,8 +85,8 @@
8585
"use-debounce": "^10.0.0",
8686
"use-sound": "^4.0.1",
8787
"usehooks-ts": "^3.1.0",
88-
"viem": "^2.21.6",
89-
"wagmi": "^2.12.11"
88+
"viem": "^2.21.18",
89+
"wagmi": "^2.12.16"
9090
},
9191
"devDependencies": {
9292
"@apollo/experimental-nextjs-app-support": "^0.11.3",

pnpm-lock.yaml

+53-71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/anvil/anvil-global-setup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function setup() {
88
for (const chain of Object.values(testChains)) {
99
console.log('Starting proxy ', {
1010
port: chain.port,
11-
forkUrl: getForkUrl(ANVIL_NETWORKS[chain.name], false),
11+
forkUrl: getForkUrl(chain.name, false),
1212
forkBlockNumber: ANVIL_NETWORKS[chain.name].forkBlockNumber,
1313
})
1414
promises.push(
@@ -17,7 +17,7 @@ export async function setup() {
1717
host: '::',
1818
options: {
1919
chainId: chain.id,
20-
forkUrl: getForkUrl(ANVIL_NETWORKS[chain.name], false),
20+
forkUrl: getForkUrl(chain.name, false),
2121
forkBlockNumber: ANVIL_NETWORKS[chain.name].forkBlockNumber,
2222
noMining: false,
2323
},

test/anvil/anvil-setup.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ export function getTestRpcSetup(networkName: NetworksWithFork) {
8383
return { port, rpcUrl }
8484
}
8585

86-
export function getForkUrl(network: NetworkSetup, verbose = false): string {
86+
/*
87+
* We currently use Drpc for all integration tests (Ethereum, Polygon and Sepolia networks)
88+
* In case you want to use a different RPC, you can set something like this (i.e. ALCHEMY)
89+
* const privateAlchemyKey = process.env['NEXT_PRIVATE_ALCHEMY_KEY']
90+
* return `https://polygon-mainnet.g.alchemy.com/v2/${privateAlchemyKey}`
91+
*/
92+
export function getForkUrl(networkName: NetworksWithFork, verbose = false): string {
93+
const network = ANVIL_NETWORKS[networkName]
8794
const privateKey = process.env['NEXT_PRIVATE_DRPC_KEY']
8895
const dRpcUrl = (chainName: string) =>
8996
`https://lb.drpc.org/ogrpc?network=${chainName}&dkey=${privateKey}`

0 commit comments

Comments
 (0)