From 824b669ac0bea2ac053b55e0a2353d2785c23c3f Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Mon, 9 Sep 2024 18:14:52 +0200 Subject: [PATCH 1/3] fix: use rpc url from transports in handlers --- .../handlers/NestedAddLiquidity.handler.ts | 5 ++--- .../handlers/ProportionalAddLiquidity.handler.ts | 5 ++--- .../handlers/UnbalancedAddLiquidity.handler.ts | 8 ++++---- .../NestedProportionalRemoveLiquidity.handler.ts | 4 ++-- .../NestedSingleTokenRemoveLiquidity.handler.ts | 4 ++-- .../handlers/ProportionalRemoveLiquidity.handler.ts | 4 ++-- .../handlers/RecoveryRemoveLiquidity.handler.ts | 4 ++-- .../handlers/SingleTokenRemoveLiquidity.handler.ts | 4 ++-- lib/modules/swap/handlers/AuraBalSwap.handler.ts | 6 +++--- lib/modules/swap/handlers/DefaultSwap.handler.ts | 4 ++-- lib/modules/web3/transports.ts | 7 ++++++- test/vitest/setup-integration.ts | 13 ++++++------- 12 files changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts b/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts index 32b21a49c..1bf7d3899 100644 --- a/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts +++ b/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { AddLiquidityNested, @@ -13,6 +11,7 @@ import { LiquidityActionHelpers, areEmptyAmounts } from '../../LiquidityActionHe import { NestedBuildAddLiquidityInput, NestedQueryAddLiquidityOutput } from '../add-liquidity.types' import { AddLiquidityHandler } from './AddLiquidity.handler' import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' /** * NestedAddLiquidityHandler is a handler that implements the @@ -88,7 +87,7 @@ export class NestedAddLiquidityHandler implements AddLiquidityHandler { return { chainId: this.helpers.chainId as ChainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), amountsIn: nonEmptyAmountsIn, } } diff --git a/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts b/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts index d62422319..08de3658f 100644 --- a/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts +++ b/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { AddLiquidity, @@ -14,6 +12,7 @@ import { LiquidityActionHelpers } from '../../LiquidityActionHelpers' import { SdkBuildAddLiquidityInput, SdkQueryAddLiquidityOutput } from '../add-liquidity.types' import { AddLiquidityHandler } from './AddLiquidity.handler' import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' /** * ProportionalAddLiquidityHandler is a handler that implements the @@ -80,7 +79,7 @@ export class ProportionalAddLiquidityHandler implements AddLiquidityHandler { private constructSdkInput(referenceAmount: InputAmount): AddLiquidityProportionalInput { return { chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), referenceAmount, kind: AddLiquidityKind.Proportional, } diff --git a/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts b/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts index aa9d443ad..bbbcc0235 100644 --- a/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts +++ b/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' +import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' import { AddLiquidity, AddLiquidityKind, @@ -11,9 +12,8 @@ import { } from '@balancer/sdk' import { Pool } from '../../../PoolProvider' import { LiquidityActionHelpers, areEmptyAmounts } from '../../LiquidityActionHelpers' -import { AddLiquidityHandler } from './AddLiquidity.handler' import { SdkBuildAddLiquidityInput, SdkQueryAddLiquidityOutput } from '../add-liquidity.types' -import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' +import { AddLiquidityHandler } from './AddLiquidity.handler' /** * UnbalancedAddLiquidityHandler is a handler that implements the @@ -91,7 +91,7 @@ export class UnbalancedAddLiquidityHandler implements AddLiquidityHandler { return { chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), amountsIn, kind: AddLiquidityKind.Unbalanced, } diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts index 91aa1c75e..38f9cf680 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts @@ -1,4 +1,3 @@ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { HumanAmount, @@ -16,6 +15,7 @@ import { QueryRemoveLiquidityOutput, } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' export interface NestedProportionalQueryRemoveLiquidityOutput extends QueryRemoveLiquidityOutput { sdkQueryOutput: RemoveLiquidityNestedQueryOutput @@ -88,7 +88,7 @@ export class NestedProportionalRemoveLiquidityHandler implements RemoveLiquidity // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), } return result diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts index 9c78d7c81..aa4426c85 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts @@ -1,4 +1,3 @@ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { HumanAmount, @@ -18,6 +17,7 @@ import { QueryRemoveLiquidityOutput, } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' export interface NestedSingleTokenQueryRemoveLiquidityOutput extends QueryRemoveLiquidityOutput { sdkQueryOutput: RemoveLiquidityNestedQueryOutput @@ -104,7 +104,7 @@ export class NestedSingleTokenRemoveLiquidityHandler implements RemoveLiquidityH // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), } return result diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts index 2bcf32be7..5cf8f1821 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts @@ -1,4 +1,3 @@ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { HumanAmount, @@ -18,6 +17,7 @@ import { SdkQueryRemoveLiquidityOutput, } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' export class ProportionalRemoveLiquidityHandler implements RemoveLiquidityHandler { helpers: LiquidityActionHelpers @@ -79,7 +79,7 @@ export class ProportionalRemoveLiquidityHandler implements RemoveLiquidityHandle return { chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), bptIn, kind: RemoveLiquidityKind.Proportional, } diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts index 0139deaf2..b6c0b1367 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts @@ -13,11 +13,11 @@ import { SdkBuildRemoveLiquidityInput, SdkQueryRemoveLiquidityOutput, } from '../remove-liquidity.types' -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { parseEther } from 'viem' import { BPT_DECIMALS } from '../../../pool.constants' import { LiquidityActionHelpers } from '../../LiquidityActionHelpers' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' /* A recovery exit is just a Proportional one but with Recovery kind @@ -85,7 +85,7 @@ export class RecoveryRemoveLiquidityHandler { return { chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), bptIn, kind: RemoveLiquidityKind.Recovery, } diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts index 2cb2df183..ad6d53774 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts @@ -1,4 +1,3 @@ -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { HumanAmount, @@ -21,6 +20,7 @@ import { } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' import { SentryError } from '@/lib/shared/utils/errors' +import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' export class SingleTokenRemoveLiquidityHandler implements RemoveLiquidityHandler { helpers: LiquidityActionHelpers @@ -104,7 +104,7 @@ export class SingleTokenRemoveLiquidityHandler implements RemoveLiquidityHandler return { chainId: this.helpers.chainId, - rpcUrl: getDefaultRpcUrl(this.helpers.chainId), + rpcUrl: getHandlerRpcUrl(this.helpers.chainId), bptIn: bptInInputAmount, kind: RemoveLiquidityKind.SingleTokenExactIn, tokenOut, diff --git a/lib/modules/swap/handlers/AuraBalSwap.handler.ts b/lib/modules/swap/handlers/AuraBalSwap.handler.ts index e6109683e..08cc49d85 100644 --- a/lib/modules/swap/handlers/AuraBalSwap.handler.ts +++ b/lib/modules/swap/handlers/AuraBalSwap.handler.ts @@ -9,7 +9,7 @@ import { AuraBalSimulateSwapResponse, SimulateSwapInputs, } from '../swap.types' -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' +import { getHandlerRpcUrl } from '../../web3/transports' import { isNativeAsset, isSameAddress } from '@/lib/shared/utils/addresses' import { bn } from '@/lib/shared/utils/numbers' @@ -20,7 +20,7 @@ export class AuraBalSwapHandler implements SwapHandler { async simulate({ ...variables }: SimulateSwapInputs): Promise { const { chain, swapType } = variables - const rpcUrl = getDefaultRpcUrl(getChainId(chain)) + const rpcUrl = getHandlerRpcUrl(getChainId(chain)) const tokenInAddress = isNativeAsset(chain, variables.tokenIn) ? getWrappedNativeAssetAddress(chain) @@ -87,7 +87,7 @@ export class AuraBalSwapHandler implements SwapHandler { relayerApprovalSignature, wethIsEth, }: AuraBalBuildSwapInputs): TransactionConfig { - const rpcUrl = getDefaultRpcUrl(getChainId(selectedChain)) + const rpcUrl = getHandlerRpcUrl(getChainId(selectedChain)) const auraBalSwap = new AuraBalSwap(rpcUrl) diff --git a/lib/modules/swap/handlers/DefaultSwap.handler.ts b/lib/modules/swap/handlers/DefaultSwap.handler.ts index 63141cf86..886ba6adc 100644 --- a/lib/modules/swap/handlers/DefaultSwap.handler.ts +++ b/lib/modules/swap/handlers/DefaultSwap.handler.ts @@ -6,7 +6,7 @@ import { Path, Slippage, Swap, SwapKind, TokenAmount } from '@balancer/sdk' import { formatUnits } from 'viem' import { TransactionConfig } from '../../web3/contracts/contract.types' import { SdkBuildSwapInputs, SdkSimulateSwapResponse, SimulateSwapInputs } from '../swap.types' -import { getDefaultRpcUrl } from '@/lib/modules/web3/ChainConfig' +import { getHandlerRpcUrl } from '../../web3/transports' export class DefaultSwapHandler implements SwapHandler { name = 'DefaultSwapHandler' @@ -15,7 +15,7 @@ export class DefaultSwapHandler implements SwapHandler { async simulate({ ...variables }: SimulateSwapInputs): Promise { const { chain, swapType } = variables - const rpcUrl = getDefaultRpcUrl(getChainId(chain)) + const rpcUrl = getHandlerRpcUrl(getChainId(chain)) const { data } = await this.apolloClient.query({ query: GetSorSwapsDocument, diff --git a/lib/modules/web3/transports.ts b/lib/modules/web3/transports.ts index 38213587e..14ae6b2c5 100644 --- a/lib/modules/web3/transports.ts +++ b/lib/modules/web3/transports.ts @@ -5,7 +5,7 @@ import { fallback, http } from 'wagmi' import { getGqlChain } from '@/lib/config/app.config' import { SupportedChainId } from '@/lib/config/config.types' -import { chains, rpcFallbacks, rpcOverrides } from './ChainConfig' +import { chains, getDefaultRpcUrl, rpcFallbacks, rpcOverrides } from './ChainConfig' export function getTransports(chain: Chain) { const gqlChain = getGqlChain(chain.id as SupportedChainId) const overrideRpcUrl = rpcOverrides[gqlChain] @@ -17,3 +17,8 @@ export function getTransports(chain: Chain) { export const transports = Object.fromEntries( chains.map(chain => [chain.id, getTransports(chain)]) ) as Record> + +export function getHandlerRpcUrl(chainId: number): string { + const gqlChain = getGqlChain(chainId) + return rpcOverrides[gqlChain] || rpcFallbacks[gqlChain] || getDefaultRpcUrl(chainId) +} diff --git a/test/vitest/setup-integration.ts b/test/vitest/setup-integration.ts index bdd25ca5a..3ee932d04 100644 --- a/test/vitest/setup-integration.ts +++ b/test/vitest/setup-integration.ts @@ -1,9 +1,10 @@ import { connectWithDefaultUser, disconnectDefaultUser } from '../utils/wagmi/wagmi-connections' -import * as chainConfigModule from '../../lib/modules/web3/ChainConfig' +import * as transportsModule from '../../lib/modules/web3/transports' import { NetworksWithFork, getTestRpcSetup } from '../anvil/anvil-setup' import { GqlChain } from '@/lib/shared/services/api/generated/graphql' import { createPublicClient, http } from 'viem' import { mainnetTest, polygonTest } from '../anvil/testWagmiConfig' +import { chainsByKey } from '@/lib/modules/web3/ChainConfig' /* Specific setup for integration tests (that it is not needed in unit tests) @@ -22,14 +23,12 @@ afterAll(async () => { Mocks getDefaultRpcUrl to return the test rpcUrl ('http://127.0.0.1:port/poolId') Keeps the rest of the module unmocked */ -vi.mock('../../lib/modules/web3/ChainConfig', async importOriginal => { - const originalModule = await importOriginal() +vi.mock('../../lib/modules/web3/transports', async importOriginal => { + const originalModule = await importOriginal() return { ...originalModule, - getDefaultRpcUrl: (chainId: number) => { - const { rpcUrl } = getTestRpcSetup( - chainConfigModule.chainsByKey[chainId].name as NetworksWithFork - ) + getHandlerRpcUrl: (chainId: number) => { + const { rpcUrl } = getTestRpcSetup(chainsByKey[chainId].name as NetworksWithFork) return rpcUrl }, } From 5c98287015a8737e6b4d2470375758838216109e Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Mon, 9 Sep 2024 18:40:10 +0200 Subject: [PATCH 2/3] fix: use private infura urls in all integration tests --- test/anvil/anvil-setup.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/anvil/anvil-setup.ts b/test/anvil/anvil-setup.ts index d2ff02a68..6d13fa29a 100644 --- a/test/anvil/anvil-setup.ts +++ b/test/anvil/anvil-setup.ts @@ -85,16 +85,23 @@ export function getTestRpcSetup(networkName: NetworksWithFork) { } export function getForkUrl(network: NetworkSetup, verbose = false): string { - if (network.networkName === 'Ethereum' && process.env['NEXT_PRIVATE_INFURA_KEY']) { - return `https://mainnet.infura.io/v3/${process.env['NEXT_PRIVATE_INFURA_KEY']}` - } else { - if (!network.fallBackRpc) { - throw Error(`Please add a fallback RPC for ${network.networkName} network.`) + const privateInfuraKey = process.env['NEXT_PRIVATE_INFURA_KEY'] + if (privateInfuraKey) { + if (network.networkName === 'Ethereum') { + return `https://mainnet.infura.io/v3/${privateInfuraKey}` } - - if (verbose) { - console.warn(`Falling back to \`${network.fallBackRpc}\`.`) + if (network.networkName === 'Polygon') { + return `https://polygon-mainnet.infura.io/v3/${privateInfuraKey}` } - return network.fallBackRpc + if (network.networkName === 'Sepolia') return `https://sepolia.infura.io/v3/${privateInfuraKey}` + } + + if (!network.fallBackRpc) { + throw Error(`Please add a fallback RPC for ${network.networkName} network.`) + } + + if (verbose) { + console.warn(`Falling back to \`${network.fallBackRpc}\`.`) } + return network.fallBackRpc } From 6a98bd78741a059b870fe3facf10e96cd5aaf861 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Tue, 10 Sep 2024 12:15:07 +0200 Subject: [PATCH 3/3] chore: rename getRcpUrl --- .../add-liquidity/handlers/NestedAddLiquidity.handler.ts | 4 ++-- .../handlers/ProportionalAddLiquidity.handler.ts | 4 ++-- .../handlers/UnbalancedAddLiquidity.handler.ts | 4 ++-- .../handlers/NestedProportionalRemoveLiquidity.handler.ts | 4 ++-- .../handlers/NestedSingleTokenRemoveLiquidity.handler.ts | 4 ++-- .../handlers/ProportionalRemoveLiquidity.handler.ts | 4 ++-- .../handlers/RecoveryRemoveLiquidity.handler.ts | 4 ++-- .../handlers/SingleTokenRemoveLiquidity.handler.ts | 4 ++-- lib/modules/swap/handlers/AuraBalSwap.handler.ts | 6 +++--- lib/modules/swap/handlers/DefaultSwap.handler.ts | 4 ++-- lib/modules/web3/transports.ts | 2 +- test/vitest/setup-integration.ts | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts b/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts index 1bf7d3899..189927d3d 100644 --- a/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts +++ b/lib/modules/pool/actions/add-liquidity/handlers/NestedAddLiquidity.handler.ts @@ -11,7 +11,7 @@ import { LiquidityActionHelpers, areEmptyAmounts } from '../../LiquidityActionHe import { NestedBuildAddLiquidityInput, NestedQueryAddLiquidityOutput } from '../add-liquidity.types' import { AddLiquidityHandler } from './AddLiquidity.handler' import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' /** * NestedAddLiquidityHandler is a handler that implements the @@ -87,7 +87,7 @@ export class NestedAddLiquidityHandler implements AddLiquidityHandler { return { chainId: this.helpers.chainId as ChainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), amountsIn: nonEmptyAmountsIn, } } diff --git a/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts b/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts index 08de3658f..f9cad592b 100644 --- a/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts +++ b/lib/modules/pool/actions/add-liquidity/handlers/ProportionalAddLiquidity.handler.ts @@ -12,7 +12,7 @@ import { LiquidityActionHelpers } from '../../LiquidityActionHelpers' import { SdkBuildAddLiquidityInput, SdkQueryAddLiquidityOutput } from '../add-liquidity.types' import { AddLiquidityHandler } from './AddLiquidity.handler' import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' /** * ProportionalAddLiquidityHandler is a handler that implements the @@ -79,7 +79,7 @@ export class ProportionalAddLiquidityHandler implements AddLiquidityHandler { private constructSdkInput(referenceAmount: InputAmount): AddLiquidityProportionalInput { return { chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), referenceAmount, kind: AddLiquidityKind.Proportional, } diff --git a/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts b/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts index bbbcc0235..f71f483a1 100644 --- a/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts +++ b/lib/modules/pool/actions/add-liquidity/handlers/UnbalancedAddLiquidity.handler.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { HumanTokenAmountWithAddress } from '@/lib/modules/tokens/token.types' import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' import { AddLiquidity, AddLiquidityKind, @@ -91,7 +91,7 @@ export class UnbalancedAddLiquidityHandler implements AddLiquidityHandler { return { chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), amountsIn, kind: AddLiquidityKind.Unbalanced, } diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts index 38f9cf680..1e90231a6 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/NestedProportionalRemoveLiquidity.handler.ts @@ -15,7 +15,7 @@ import { QueryRemoveLiquidityOutput, } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' export interface NestedProportionalQueryRemoveLiquidityOutput extends QueryRemoveLiquidityOutput { sdkQueryOutput: RemoveLiquidityNestedQueryOutput @@ -88,7 +88,7 @@ export class NestedProportionalRemoveLiquidityHandler implements RemoveLiquidity // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), } return result diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts index aa4426c85..0c8732173 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/NestedSingleTokenRemoveLiquidity.handler.ts @@ -17,7 +17,7 @@ import { QueryRemoveLiquidityOutput, } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' export interface NestedSingleTokenQueryRemoveLiquidityOutput extends QueryRemoveLiquidityOutput { sdkQueryOutput: RemoveLiquidityNestedQueryOutput @@ -104,7 +104,7 @@ export class NestedSingleTokenRemoveLiquidityHandler implements RemoveLiquidityH // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), } return result diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts index 5cf8f1821..a0370fd47 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/ProportionalRemoveLiquidity.handler.ts @@ -17,7 +17,7 @@ import { SdkQueryRemoveLiquidityOutput, } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' export class ProportionalRemoveLiquidityHandler implements RemoveLiquidityHandler { helpers: LiquidityActionHelpers @@ -79,7 +79,7 @@ export class ProportionalRemoveLiquidityHandler implements RemoveLiquidityHandle return { chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), bptIn, kind: RemoveLiquidityKind.Proportional, } diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts index b6c0b1367..a7cd09b0d 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/RecoveryRemoveLiquidity.handler.ts @@ -17,7 +17,7 @@ import { TransactionConfig } from '@/lib/modules/web3/contracts/contract.types' import { parseEther } from 'viem' import { BPT_DECIMALS } from '../../../pool.constants' import { LiquidityActionHelpers } from '../../LiquidityActionHelpers' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' /* A recovery exit is just a Proportional one but with Recovery kind @@ -85,7 +85,7 @@ export class RecoveryRemoveLiquidityHandler { return { chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), bptIn, kind: RemoveLiquidityKind.Recovery, } diff --git a/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts b/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts index ad6d53774..3ee78fee1 100644 --- a/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts +++ b/lib/modules/pool/actions/remove-liquidity/handlers/SingleTokenRemoveLiquidity.handler.ts @@ -20,7 +20,7 @@ import { } from '../remove-liquidity.types' import { RemoveLiquidityHandler } from './RemoveLiquidity.handler' import { SentryError } from '@/lib/shared/utils/errors' -import { getHandlerRpcUrl } from '@/lib/modules/web3/transports' +import { getRpcUrl } from '@/lib/modules/web3/transports' export class SingleTokenRemoveLiquidityHandler implements RemoveLiquidityHandler { helpers: LiquidityActionHelpers @@ -104,7 +104,7 @@ export class SingleTokenRemoveLiquidityHandler implements RemoveLiquidityHandler return { chainId: this.helpers.chainId, - rpcUrl: getHandlerRpcUrl(this.helpers.chainId), + rpcUrl: getRpcUrl(this.helpers.chainId), bptIn: bptInInputAmount, kind: RemoveLiquidityKind.SingleTokenExactIn, tokenOut, diff --git a/lib/modules/swap/handlers/AuraBalSwap.handler.ts b/lib/modules/swap/handlers/AuraBalSwap.handler.ts index 08cc49d85..a9bb56d1b 100644 --- a/lib/modules/swap/handlers/AuraBalSwap.handler.ts +++ b/lib/modules/swap/handlers/AuraBalSwap.handler.ts @@ -9,7 +9,7 @@ import { AuraBalSimulateSwapResponse, SimulateSwapInputs, } from '../swap.types' -import { getHandlerRpcUrl } from '../../web3/transports' +import { getRpcUrl } from '../../web3/transports' import { isNativeAsset, isSameAddress } from '@/lib/shared/utils/addresses' import { bn } from '@/lib/shared/utils/numbers' @@ -20,7 +20,7 @@ export class AuraBalSwapHandler implements SwapHandler { async simulate({ ...variables }: SimulateSwapInputs): Promise { const { chain, swapType } = variables - const rpcUrl = getHandlerRpcUrl(getChainId(chain)) + const rpcUrl = getRpcUrl(getChainId(chain)) const tokenInAddress = isNativeAsset(chain, variables.tokenIn) ? getWrappedNativeAssetAddress(chain) @@ -87,7 +87,7 @@ export class AuraBalSwapHandler implements SwapHandler { relayerApprovalSignature, wethIsEth, }: AuraBalBuildSwapInputs): TransactionConfig { - const rpcUrl = getHandlerRpcUrl(getChainId(selectedChain)) + const rpcUrl = getRpcUrl(getChainId(selectedChain)) const auraBalSwap = new AuraBalSwap(rpcUrl) diff --git a/lib/modules/swap/handlers/DefaultSwap.handler.ts b/lib/modules/swap/handlers/DefaultSwap.handler.ts index 886ba6adc..28ba5f9d3 100644 --- a/lib/modules/swap/handlers/DefaultSwap.handler.ts +++ b/lib/modules/swap/handlers/DefaultSwap.handler.ts @@ -6,7 +6,7 @@ import { Path, Slippage, Swap, SwapKind, TokenAmount } from '@balancer/sdk' import { formatUnits } from 'viem' import { TransactionConfig } from '../../web3/contracts/contract.types' import { SdkBuildSwapInputs, SdkSimulateSwapResponse, SimulateSwapInputs } from '../swap.types' -import { getHandlerRpcUrl } from '../../web3/transports' +import { getRpcUrl } from '../../web3/transports' export class DefaultSwapHandler implements SwapHandler { name = 'DefaultSwapHandler' @@ -15,7 +15,7 @@ export class DefaultSwapHandler implements SwapHandler { async simulate({ ...variables }: SimulateSwapInputs): Promise { const { chain, swapType } = variables - const rpcUrl = getHandlerRpcUrl(getChainId(chain)) + const rpcUrl = getRpcUrl(getChainId(chain)) const { data } = await this.apolloClient.query({ query: GetSorSwapsDocument, diff --git a/lib/modules/web3/transports.ts b/lib/modules/web3/transports.ts index 14ae6b2c5..a99a310d6 100644 --- a/lib/modules/web3/transports.ts +++ b/lib/modules/web3/transports.ts @@ -18,7 +18,7 @@ export const transports = Object.fromEntries( chains.map(chain => [chain.id, getTransports(chain)]) ) as Record> -export function getHandlerRpcUrl(chainId: number): string { +export function getRpcUrl(chainId: number): string { const gqlChain = getGqlChain(chainId) return rpcOverrides[gqlChain] || rpcFallbacks[gqlChain] || getDefaultRpcUrl(chainId) } diff --git a/test/vitest/setup-integration.ts b/test/vitest/setup-integration.ts index 3ee932d04..020c41e34 100644 --- a/test/vitest/setup-integration.ts +++ b/test/vitest/setup-integration.ts @@ -27,7 +27,7 @@ vi.mock('../../lib/modules/web3/transports', async importOriginal => { const originalModule = await importOriginal() return { ...originalModule, - getHandlerRpcUrl: (chainId: number) => { + getRpcUrl: (chainId: number) => { const { rpcUrl } = getTestRpcSetup(chainsByKey[chainId].name as NetworksWithFork) return rpcUrl },