From 53c941dcb2ec55b6b1442fb38f988fe26f70562b Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 16 Jan 2025 20:29:36 +0300 Subject: [PATCH 1/4] update subgraphs for BalV2, UniV3 and MaverickV1 on base chain + fixed integration tests for BalV2 --- src/dex/balancer-v2/balancer-v2-e2e.test.ts | 267 +++++++++------ .../balancer-v2-integration.test.ts | 318 +++++++++++++----- src/dex/balancer-v2/balancer-v2.ts | 18 +- src/dex/balancer-v2/config.ts | 3 +- src/dex/maverick-v1/config.ts | 3 +- src/dex/uniswap-v3/config.ts | 3 +- 6 files changed, 418 insertions(+), 194 deletions(-) diff --git a/src/dex/balancer-v2/balancer-v2-e2e.test.ts b/src/dex/balancer-v2/balancer-v2-e2e.test.ts index 491b06c0e..76f88ccec 100644 --- a/src/dex/balancer-v2/balancer-v2-e2e.test.ts +++ b/src/dex/balancer-v2/balancer-v2-e2e.test.ts @@ -23,35 +23,36 @@ function testForNetwork( tokenAAmount: string, tokenBAmount: string, nativeTokenAmount: string, - slippage?: number | undefined, + excludeNativeTokenTests: boolean = false, ) { + const config = generateConfig(network); const provider = new StaticJsonRpcProvider( - generateConfig(network).privateHttpProvider, + config.privateHttpProvider, network, ); const tokens = Tokens[network]; const holders = Holders[network]; const nativeTokenSymbol = NativeTokenSymbols[network]; + const sleepMs = 10000; const sideToContractMethods = new Map([ [ SwapSide.SELL, [ - // ContractMethod.simpleSwap, - // ContractMethod.multiSwap, - // ContractMethod.megaSwap, ContractMethod.swapExactAmountIn, ContractMethod.swapExactAmountInOnBalancerV2, + // ContractMethod.simpleSwap, + // ContractMethod.megaSwap, + // ContractMethod.multiSwap, ], ], [ SwapSide.BUY, [ - // ContractMethod.simpleBuy, - // ContractMethod.buy, - // DirectMethodsV6.directBuy, ContractMethod.swapExactAmountOut, ContractMethod.swapExactAmountOutOnBalancerV2, + // ContractMethod.simpleBuy, + // ContractMethod.buy, ], ], ]); @@ -59,59 +60,119 @@ function testForNetwork( describe(`${network}`, () => { sideToContractMethods.forEach((contractMethods, side) => describe(`${side}`, () => { - contractMethods.forEach((contractMethod: string) => { + contractMethods.forEach((contractMethod: ContractMethod) => { describe(`${contractMethod}`, () => { - it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { - await testE2E( - tokens[nativeTokenSymbol], - tokens[tokenASymbol], - holders[nativeTokenSymbol], - side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, - side, - dexKey, - contractMethod as any, - network, - provider, - undefined, - undefined, - undefined, - slippage, - ); - }); - it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { - await testE2E( - tokens[tokenASymbol], - tokens[nativeTokenSymbol], - holders[tokenASymbol], - side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, - side, - dexKey, - contractMethod as any, - network, - provider, - undefined, - undefined, - undefined, - slippage, - ); - }); - it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { - await testE2E( - tokens[tokenASymbol], - tokens[tokenBSymbol], - holders[tokenASymbol], - side === SwapSide.SELL ? tokenAAmount : tokenBAmount, - side, - dexKey, - contractMethod as any, - network, - provider, - undefined, - undefined, - undefined, - slippage, - ); - }); + if (excludeNativeTokenTests) { + it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[tokenBSymbol], + holders[tokenASymbol], + side === SwapSide.SELL ? tokenAAmount : tokenBAmount, + side, + dexKey, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + undefined, + sleepMs, + ); + }); + it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => { + await testE2E( + tokens[tokenBSymbol], + tokens[tokenASymbol], + holders[tokenBSymbol], + side === SwapSide.SELL ? tokenBAmount : tokenAAmount, + side, + dexKey, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + undefined, + sleepMs, + ); + }); + } else { + it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { + await testE2E( + tokens[nativeTokenSymbol], + tokens[tokenASymbol], + holders[nativeTokenSymbol], + side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, + side, + dexKey, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + undefined, + sleepMs, + ); + }); + it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[nativeTokenSymbol], + holders[tokenASymbol], + side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, + side, + dexKey, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + undefined, + sleepMs, + ); + }); + it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[tokenBSymbol], + holders[tokenASymbol], + side === SwapSide.SELL ? tokenAAmount : tokenBAmount, + side, + dexKey, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + undefined, + sleepMs, + ); + }); + it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => { + await testE2E( + tokens[tokenBSymbol], + tokens[tokenASymbol], + holders[tokenBSymbol], + side === SwapSide.SELL ? tokenBAmount : tokenAAmount, + side, + dexKey, + contractMethod, + network, + provider, + undefined, + undefined, + undefined, + undefined, + sleepMs, + ); + }); + } }); }); }), @@ -120,7 +181,7 @@ function testForNetwork( } describe('BalancerV2 E2E', () => { - describe('BalancerV2 MAINNET', () => { + describe('Mainnet', () => { const dexKey = 'BalancerV2'; const network = Network.MAINNET; const tokens = Tokens[Network.MAINNET]; @@ -130,7 +191,7 @@ describe('BalancerV2 E2E', () => { network, ); - describe.only('GHO -> USDT', () => { + describe('GHO -> USDT', () => { const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [ [ @@ -796,7 +857,7 @@ describe('BalancerV2 E2E', () => { */ }); - describe('BalancerV2 Polygon_V6', () => { + describe('Polygon_v6', () => { const dexKey = 'BalancerV2'; const network = Network.POLYGON; const tokens = Tokens[Network.POLYGON]; @@ -909,7 +970,7 @@ describe('BalancerV2 E2E', () => { }); }); - describe('BalancerV2 ARBITRUM', () => { + describe('Arbitrum', () => { const dexKey = 'BalancerV2'; const network = Network.ARBITRUM; const tokens = Tokens[Network.ARBITRUM]; @@ -1087,7 +1148,7 @@ describe('BalancerV2 E2E', () => { }); }); - describe('BeetsFi FANTOM', () => { + describe('Fantom', () => { const dexKey = 'BeetsFi'; const network = Network.FANTOM; const tokens = Tokens[network]; @@ -1208,7 +1269,7 @@ describe('BalancerV2 E2E', () => { }); }); - describe('BalancerV2 Polygon', () => { + describe('Polygon', () => { const dexKey = 'BalancerV2'; const network = Network.POLYGON; const tokens = Tokens[Network.POLYGON]; @@ -1302,7 +1363,7 @@ describe('BalancerV2 E2E', () => { }); }); - describe('BalancerV2 Avalanche', () => { + describe('Avalanche', () => { const dexKey = 'BalancerV2'; const network = Network.AVALANCHE; const tokens = Tokens[Network.AVALANCHE]; @@ -1478,51 +1539,53 @@ describe('BalancerV2 E2E', () => { }); }); - describe('BalancerV2 Base', () => { + describe('Base', () => { const dexKey = 'BalancerV2'; const network = Network.BASE; - const tokenASymbol: string = 'USDC'; - const tokenBSymbol: string = 'GOLD'; + describe('USDC -> GOLD', () => { + const tokenASymbol: string = 'USDC'; + const tokenBSymbol: string = 'GOLD'; - const tokenAAmount: string = '11110010'; - const tokenBAmount: string = '210000000000000000000'; - const nativeTokenAmount = '1000000000000000000'; + const tokenAAmount: string = '11110010'; + const tokenBAmount: string = '210000000000000000000'; + const nativeTokenAmount = '1000000000000000000'; - testForNetwork( - network, - dexKey, - tokenASymbol, - tokenBSymbol, - tokenAAmount, - tokenBAmount, - nativeTokenAmount, - ); - }); - - describe('BalancerV2_MAINNET', () => { - const dexKey = 'BalancerV2'; - const network = Network.MAINNET; + testForNetwork( + network, + dexKey, + tokenASymbol, + tokenBSymbol, + tokenAAmount, + tokenBAmount, + nativeTokenAmount, + ); + }); - const tokenASymbol: string = 'USDC'; - const tokenBSymbol: string = 'USDT'; + describe('WETH -> USDC', () => { + const tokenASymbol: string = 'WETH'; + const tokenBSymbol: string = 'USDC'; - const tokenAAmount: string = '11110010'; - const tokenBAmount: string = '21000000'; - const nativeTokenAmount = '1000000000000000000'; + // const tokenAAmount: string = '375699066125449'; + const tokenAAmount: string = '300000000000000'; + // const tokenBAmount: string = '1196427'; + const tokenBAmount: string = '1000000'; + const nativeTokenAmount = '1000000000000000000'; - testForNetwork( - network, - dexKey, - tokenASymbol, - tokenBSymbol, - tokenAAmount, - tokenBAmount, - nativeTokenAmount, - ); + testForNetwork( + network, + dexKey, + tokenASymbol, + tokenBSymbol, + tokenAAmount, + tokenBAmount, + nativeTokenAmount, + true, + ); + }); }); - describe('BalancerV2_GNOSIS', () => { + describe('Gnosis', () => { const dexKey = 'BalancerV2'; const network = Network.GNOSIS; diff --git a/src/dex/balancer-v2/balancer-v2-integration.test.ts b/src/dex/balancer-v2/balancer-v2-integration.test.ts index 81e6f39b4..8395e5879 100644 --- a/src/dex/balancer-v2/balancer-v2-integration.test.ts +++ b/src/dex/balancer-v2/balancer-v2-integration.test.ts @@ -30,11 +30,9 @@ async function getOnChainPricingForWeightedPool( return 0n; } - const params = balancerV2.getBalancerParam( + const params = balancerV2.getBalancerV2BatchSwapParam( srcTokenAddress, destTokenAddress, - '0', - '0', { swaps: [ { @@ -44,6 +42,8 @@ async function getOnChainPricingForWeightedPool( ], }, side, + balancerV2.dexHelper.config.data.augustusV6Address!, + balancerV2.dexHelper.config.data.augustusV6Address!, ); const calldata = [ @@ -611,85 +611,243 @@ describe('BalancerV2', function () { }); describe('GyroE', () => { - // sDAI<>GYD - more likely to have continued liqudity - const gyroEAddr = '0x1cce5169bde03f3d5ad0206f6bd057953539dae6'; - - it('getPoolIdentifiers and getPricesVolume', async function () { - const network = Network.MAINNET; - const dexHelper = new DummyDexHelper(network); - // const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber(); - const blocknumber = 19425305; - const balancerV2 = new BalancerV2(network, dexKey, dexHelper); - const tokens = Tokens[network]; - - await balancerV2.initializePricing(blocknumber); - - const pools = await balancerV2.getPoolIdentifiers( - tokens.GYD, - tokens.sDAI, - SwapSide.SELL, - blocknumber, - ); - console.log('GYD <> sDAI Pool Identifiers (Mainnet): ', pools); - - const isPool = pools.find(poolIdentifier => - poolIdentifier.includes(gyroEAddr), - ); - - expect(isPool).toBeDefined(); - - const poolPrices = await balancerV2.getPricesVolume( - tokens.GYD, - tokens.sDAI, - amounts, - SwapSide.SELL, - blocknumber, - pools, - ); - console.log('GYD <> sDAI Pool Prices (Mainnet): ', poolPrices); - - expect(poolPrices).not.toBeNull(); - checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey); - const isPoolPrice = poolPrices!.find(price => - price.data.poolId.includes(gyroEAddr), - ); - expect(isPoolPrice).toBeDefined(); - - const onChainPrices = await getOnChainPricingForWeightedPool( - balancerV2, - blocknumber, - isPoolPrice!, - amounts, - tokens.GYD.address, - tokens.sDAI.address, - SwapSide.SELL, - ); - - console.log('GYD <> sDAI on-chain prices: ', onChainPrices); - - expect(onChainPrices).toEqual(isPoolPrice!.prices); - - await balancerV2.releaseResources(); + describe('sDAI > GYD', () => { + // sDAI<>GYD - more likely to have continued liqudity + const gyroEAddr = '0x1cce5169bde03f3d5ad0206f6bd057953539dae6'; + + it('getPoolIdentifiers and getPricesVolume', async function () { + const network = Network.MAINNET; + const dexHelper = new DummyDexHelper(network); + // const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber(); + const blocknumber = 19425305; + const balancerV2 = new BalancerV2(network, dexKey, dexHelper); + const tokens = Tokens[network]; + + await balancerV2.initializePricing(blocknumber); + + const pools = await balancerV2.getPoolIdentifiers( + tokens.GYD, + tokens.sDAI, + SwapSide.SELL, + blocknumber, + ); + console.log('GYD <> sDAI Pool Identifiers (Mainnet): ', pools); + + const isPool = pools.find(poolIdentifier => + poolIdentifier.includes(gyroEAddr), + ); + + expect(isPool).toBeDefined(); + + const poolPrices = await balancerV2.getPricesVolume( + tokens.GYD, + tokens.sDAI, + amounts, + SwapSide.SELL, + blocknumber, + pools, + ); + console.log('GYD <> sDAI Pool Prices (Mainnet): ', poolPrices); + + expect(poolPrices).not.toBeNull(); + checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey); + const isPoolPrice = poolPrices!.find(price => + price.data.poolId.includes(gyroEAddr), + ); + expect(isPoolPrice).toBeDefined(); + + const onChainPrices = await getOnChainPricingForWeightedPool( + balancerV2, + blocknumber, + isPoolPrice!, + amounts, + tokens.GYD.address, + tokens.sDAI.address, + SwapSide.SELL, + ); + + console.log('GYD <> sDAI on-chain prices: ', onChainPrices); + + expect(onChainPrices).toEqual(isPoolPrice!.prices); + + await balancerV2.releaseResources(); + }); + + it('getTopPoolsForToken', async function () { + const network = Network.MAINNET; + const dexHelper = new DummyDexHelper(network); + const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber(); + const balancerV2 = new BalancerV2(network, dexKey, dexHelper); + await balancerV2.initializePricing(blocknumber); + const tokens = Tokens[network]; + + const poolLiquidity = await balancerV2.getTopPoolsForToken( + tokens.sDAI.address.toLowerCase(), + 10, + ); + console.log('sDAI Top Pools (Mainnet):', poolLiquidity); + + checkPoolsLiquidity(poolLiquidity, tokens.sDAI.address, dexKey); + const isTopPool = poolLiquidity.find( + pool => pool.address === gyroEAddr, + ); + expect(isTopPool).toBeDefined(); + await balancerV2.releaseResources(); + }); }); - it('getTopPoolsForToken', async function () { - const network = Network.MAINNET; - const dexHelper = new DummyDexHelper(network); - const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber(); - const balancerV2 = new BalancerV2(network, dexKey, dexHelper); - await balancerV2.initializePricing(blocknumber); - const tokens = Tokens[network]; - - const poolLiquidity = await balancerV2.getTopPoolsForToken( - tokens.sDAI.address.toLowerCase(), - 10, - ); - console.log('sDAI Top Pools (Mainnet):', poolLiquidity); - - checkPoolsLiquidity(poolLiquidity, tokens.sDAI.address, dexKey); - const isTopPool = poolLiquidity.find(pool => pool.address === gyroEAddr); - expect(isTopPool).toBeDefined(); - await balancerV2.releaseResources(); + describe('WETH / USDC', () => { + const gyroEAddr = '0x4c42b5057a8663e2b1ac21685d1502c937a03817'; + + it('SELL WETH -> USDC getPoolIdentifiers and getPricesVolume', async function () { + const network = Network.BASE; + + const dexHelper = new DummyDexHelper(network); + const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber(); + // const blocknumber = 19425305; + const balancerV2 = new BalancerV2(network, dexKey, dexHelper); + const tokens = Tokens[network]; + + const amounts = [ + 0n, + BI_POWS[18], + 2n * BI_POWS[18], + 3n * BI_POWS[18], + 4n * BI_POWS[18], + 5n * BI_POWS[18], + 6n * BI_POWS[18], + 7n * BI_POWS[18], + 8n * BI_POWS[18], + 9n * BI_POWS[18], + 10n * BI_POWS[18], + ]; + + await balancerV2.initializePricing(blocknumber); + + const pools = await balancerV2.getPoolIdentifiers( + tokens.WETH, + tokens.USDC, + SwapSide.SELL, + blocknumber, + ); + console.log('WETH <> USDC Pool Identifiers (Mainnet): ', pools); + + const isPool = pools.find(poolIdentifier => + poolIdentifier.includes(gyroEAddr), + ); + + expect(isPool).toBeDefined(); + + const poolPrices = await balancerV2.getPricesVolume( + tokens.WETH, + tokens.USDC, + amounts, + SwapSide.SELL, + blocknumber, + pools, + ); + console.log('WETH <> USDC Pool Prices (Base): ', poolPrices); + + expect(poolPrices).not.toBeNull(); + + // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey); + const isPoolPrice = poolPrices!.find(price => + price.data.poolId.includes(gyroEAddr), + ); + expect(isPoolPrice).toBeDefined(); + + const onChainPrices = await getOnChainPricingForWeightedPool( + balancerV2, + blocknumber, + isPoolPrice!, + amounts, + tokens.WETH.address, + tokens.USDC.address, + SwapSide.SELL, + ); + + console.log('WETH <> USDC on-chain prices: ', onChainPrices); + + expect(onChainPrices).toEqual(isPoolPrice!.prices); + + await balancerV2.releaseResources(); + }); + + it('SELL USDC -> WETH getPoolIdentifiers and getPricesVolume', async function () { + const network = Network.BASE; + const dexHelper = new DummyDexHelper(network); + // const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber(); + const blocknumber = 24931862; + const balancerV2 = new BalancerV2(network, dexKey, dexHelper); + const tokens = Tokens[network]; + + const amounts = [ + 0n, + 1000000n, + // BI_POWS[6], + // 2n * BI_POWS[6], + // 3n * BI_POWS[6], + // 4n * BI_POWS[6], + // 5n * BI_POWS[6], + // 6n * BI_POWS[6], + // 7n * BI_POWS[6], + // 8n * BI_POWS[6], + // 9n * BI_POWS[6], + // 10n * BI_POWS[6], + ]; + + await balancerV2.initializePricing(blocknumber); + + const pools = await balancerV2.getPoolIdentifiers( + tokens.USDC, + tokens.WETH, + SwapSide.SELL, + blocknumber, + ); + console.log('USDC -> WETH Pool Identifiers (Base): ', pools); + + const isPool = pools.find(poolIdentifier => + poolIdentifier.includes(gyroEAddr), + ); + + expect(isPool).toBeDefined(); + + const poolPrices = await balancerV2.getPricesVolume( + tokens.USDC, + tokens.WETH, + amounts, + SwapSide.SELL, + blocknumber, + pools, + ); + console.log('USDC -> WETH Pool Prices (Base): ', poolPrices); + + expect(poolPrices).not.toBeNull(); + + // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey); + const isPoolPrice = poolPrices!.find(price => + price.data.poolId.includes(gyroEAddr), + ); + expect(isPoolPrice).toBeDefined(); + + console.log('isPoolPrice: ', isPoolPrice); + + const onChainPrices = await getOnChainPricingForWeightedPool( + balancerV2, + blocknumber, + isPoolPrice!, + amounts, + tokens.USDC.address, + tokens.WETH.address, + SwapSide.SELL, + ); + + console.log('USDC -> WETH on-chain prices: ', onChainPrices); + + expect(onChainPrices).toEqual(isPoolPrice!.prices); + + await balancerV2.releaseResources(); + }); }); }); }); diff --git a/src/dex/balancer-v2/balancer-v2.ts b/src/dex/balancer-v2/balancer-v2.ts index f82937960..dbc2308a3 100644 --- a/src/dex/balancer-v2/balancer-v2.ts +++ b/src/dex/balancer-v2/balancer-v2.ts @@ -32,6 +32,7 @@ import { LinearPool } from './pools/linear/LinearPool'; import { Gyro3Pool } from './pools/gyro/Gyro3Pool'; import { GyroEPool } from './pools/gyro/GyroEPool'; import VaultABI from '../../abi/balancer-v2/vault.json'; +import BalancerVaultABI from '../../abi/balancer-v2/vault.json'; import DirectSwapABI from '../../abi/DirectSwap.json'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { @@ -42,11 +43,15 @@ import { import { Context, IDex } from '../../dex/idex'; import { IDexHelper } from '../../dex-helper'; import { - BalancerV2BatchSwapParam, BalancerPoolTypes, BalancerSwap, + BalancerV2BatchSwapParam, BalancerV2Data, BalancerV2DirectParam, + BalancerV2DirectParamV6, + BalancerV2DirectParamV6Swap, + BalancerV2SingleSwap, + BalancerV2SwapParam, OptimizedBalancerV2Data, PoolState, PoolStateCache, @@ -54,10 +59,6 @@ import { SubgraphPoolAddressDictionary, SubgraphPoolBase, SwapTypes, - BalancerV2DirectParamV6, - BalancerV2DirectParamV6Swap, - BalancerV2SwapParam, - BalancerV2SingleSwap, } from './types'; import { getLocalDeadlineAsFriendlyPlaceholder, @@ -79,10 +80,11 @@ import { } from './constants'; import { NumberAsString, OptimalSwapExchange } from '@paraswap/core'; import { hexConcat, hexlify, hexZeroPad, solidityPack } from 'ethers/lib/utils'; -import BalancerVaultABI from '../../abi/balancer-v2/vault.json'; import { BigNumber } from 'ethers'; import { SpecialDex } from '../../executor/types'; import { extractReturnAmountPosition } from '../../executor/utils'; +import { util } from 'protobufjs'; +import pool = util.pool; // If you disable some pool, don't forget to clear the cache, otherwise changes won't be applied immediately const enabledPoolTypes = [ @@ -504,6 +506,7 @@ export class BalancerV2EventPool extends StatefulEventSubscriber { amounts: bigint[], unitVolume: bigint, side: SwapSide, + poolAddress: string, ): { unit: bigint; prices: bigint[] } | null { if (!this.isSupportedPool(subgraphPool.poolType)) { this.logger.error(`Unsupported Pool Type: ${subgraphPool.poolType}`); @@ -728,6 +731,7 @@ export class BalancerV2 (wu: { poolId: { address: Address } }) => wu.poolId.address, ), ); + const poolAddressList = JSON.stringify(this.eventDisabledPools); this.logger.info( `Pools blocked from event based on ${this.dexKey}_${this.network}: ${poolAddressList}`, @@ -899,6 +903,7 @@ export class BalancerV2 missingPools, blockNumber, ); + // Update non-event pool state cache with newly retrieved data so it can be reused in future nonEventPoolStates = this.updateNonEventPoolStateCache( missingPoolsStateMap, @@ -946,6 +951,7 @@ export class BalancerV2 pathAmounts, unitVolume, side, + poolAddress, ); if (!res) { diff --git a/src/dex/balancer-v2/config.ts b/src/dex/balancer-v2/config.ts index 8be7e7eef..ee3b698c7 100644 --- a/src/dex/balancer-v2/config.ts +++ b/src/dex/balancer-v2/config.ts @@ -21,8 +21,7 @@ export const BalancerConfig: DexConfigMap = { vaultAddress: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', }, [Network.BASE]: { - subgraphURL: - 'https://api.studio.thegraph.com/query/24660/balancer-base-v2/version/latest', + subgraphURL: 'E7XyutxXVLrp8njmjF16Hh38PCJuHm12RRyMt5ma4ctX', vaultAddress: '0xBA12222222228d8Ba445958a75a0704d566BF2C8', }, [Network.GNOSIS]: { diff --git a/src/dex/maverick-v1/config.ts b/src/dex/maverick-v1/config.ts index c235cbab2..150744ec2 100644 --- a/src/dex/maverick-v1/config.ts +++ b/src/dex/maverick-v1/config.ts @@ -14,8 +14,7 @@ export const MaverickV1Config: DexConfigMap = { poolInspectorAddress: '0xaA5BF61a664109e959D69C38734d4EA7dF74e456', }, [Network.BASE]: { - subgraphURL: - 'https://api.studio.thegraph.com/query/42519/maverick-base/version/latest', + subgraphURL: 'CSxkHjxpG1TxTBQMn55uG1DWpdD4Lsix4RNX4RTLvK4T', routerAddress: '0x32AED3Bce901DA12ca8489788F3A99fCe1056e14', poolInspectorAddress: '0x65A3AD03Be97619284bA7AA1E3Ca05638B9d6364', }, diff --git a/src/dex/uniswap-v3/config.ts b/src/dex/uniswap-v3/config.ts index d27ca7679..aa248b525 100644 --- a/src/dex/uniswap-v3/config.ts +++ b/src/dex/uniswap-v3/config.ts @@ -117,8 +117,7 @@ export const UniswapV3Config: DexConfigMap = { chunksCount: 10, initRetryFrequency: 10, initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`, - subgraphURL: - 'https://api.studio.thegraph.com/query/48211/uniswap-v3-base/version/latest', + subgraphURL: 'GqzP4Xaehti8KSfQmv3ZctFSjnSUYZ4En5NRsiTbvZpz', }, }, SushiSwapV3: { From 3386ea4205df07e6ce7d1eb688937adb9dfad00b Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Thu, 16 Jan 2025 20:54:33 +0300 Subject: [PATCH 2/4] rollback bal v2 changes --- src/dex/balancer-v2/balancer-v2.ts | 18 ++++++------------ src/dex/curve-v1/curve-v1-e2e.test.ts | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/dex/balancer-v2/balancer-v2.ts b/src/dex/balancer-v2/balancer-v2.ts index dbc2308a3..f82937960 100644 --- a/src/dex/balancer-v2/balancer-v2.ts +++ b/src/dex/balancer-v2/balancer-v2.ts @@ -32,7 +32,6 @@ import { LinearPool } from './pools/linear/LinearPool'; import { Gyro3Pool } from './pools/gyro/Gyro3Pool'; import { GyroEPool } from './pools/gyro/GyroEPool'; import VaultABI from '../../abi/balancer-v2/vault.json'; -import BalancerVaultABI from '../../abi/balancer-v2/vault.json'; import DirectSwapABI from '../../abi/DirectSwap.json'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { @@ -43,15 +42,11 @@ import { import { Context, IDex } from '../../dex/idex'; import { IDexHelper } from '../../dex-helper'; import { + BalancerV2BatchSwapParam, BalancerPoolTypes, BalancerSwap, - BalancerV2BatchSwapParam, BalancerV2Data, BalancerV2DirectParam, - BalancerV2DirectParamV6, - BalancerV2DirectParamV6Swap, - BalancerV2SingleSwap, - BalancerV2SwapParam, OptimizedBalancerV2Data, PoolState, PoolStateCache, @@ -59,6 +54,10 @@ import { SubgraphPoolAddressDictionary, SubgraphPoolBase, SwapTypes, + BalancerV2DirectParamV6, + BalancerV2DirectParamV6Swap, + BalancerV2SwapParam, + BalancerV2SingleSwap, } from './types'; import { getLocalDeadlineAsFriendlyPlaceholder, @@ -80,11 +79,10 @@ import { } from './constants'; import { NumberAsString, OptimalSwapExchange } from '@paraswap/core'; import { hexConcat, hexlify, hexZeroPad, solidityPack } from 'ethers/lib/utils'; +import BalancerVaultABI from '../../abi/balancer-v2/vault.json'; import { BigNumber } from 'ethers'; import { SpecialDex } from '../../executor/types'; import { extractReturnAmountPosition } from '../../executor/utils'; -import { util } from 'protobufjs'; -import pool = util.pool; // If you disable some pool, don't forget to clear the cache, otherwise changes won't be applied immediately const enabledPoolTypes = [ @@ -506,7 +504,6 @@ export class BalancerV2EventPool extends StatefulEventSubscriber { amounts: bigint[], unitVolume: bigint, side: SwapSide, - poolAddress: string, ): { unit: bigint; prices: bigint[] } | null { if (!this.isSupportedPool(subgraphPool.poolType)) { this.logger.error(`Unsupported Pool Type: ${subgraphPool.poolType}`); @@ -731,7 +728,6 @@ export class BalancerV2 (wu: { poolId: { address: Address } }) => wu.poolId.address, ), ); - const poolAddressList = JSON.stringify(this.eventDisabledPools); this.logger.info( `Pools blocked from event based on ${this.dexKey}_${this.network}: ${poolAddressList}`, @@ -903,7 +899,6 @@ export class BalancerV2 missingPools, blockNumber, ); - // Update non-event pool state cache with newly retrieved data so it can be reused in future nonEventPoolStates = this.updateNonEventPoolStateCache( missingPoolsStateMap, @@ -951,7 +946,6 @@ export class BalancerV2 pathAmounts, unitVolume, side, - poolAddress, ); if (!res) { diff --git a/src/dex/curve-v1/curve-v1-e2e.test.ts b/src/dex/curve-v1/curve-v1-e2e.test.ts index b5a0b4f29..1acf7df32 100644 --- a/src/dex/curve-v1/curve-v1-e2e.test.ts +++ b/src/dex/curve-v1/curve-v1-e2e.test.ts @@ -15,7 +15,7 @@ import { DIRECT_METHOD_NAME_V6 } from './constants'; describe('CurveV1 E2E', () => { const dexKey = 'CurveV1'; - describe('CurveV1 MAINNET', () => { + describe('CurveV1_MAINNET', () => { const network = Network.MAINNET; const tokens = Tokens[network]; const holders = Holders[network]; From c01eeb2f46a146d1fb693d32d82390fc241b7caf Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Mon, 20 Jan 2025 14:32:26 +0300 Subject: [PATCH 3/4] 4.0.22-bal-v2-base-subgraph.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e50177fb..136bba568 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "4.0.21", + "version": "4.0.22-bal-v2-base-subgraph.0", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 80d226795f4c68885d85bafed20ffd8063734595 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 22 Jan 2025 18:25:03 +0300 Subject: [PATCH 4/4] 4.0.23 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 136bba568..f786835ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "4.0.22-bal-v2-base-subgraph.0", + "version": "4.0.23", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib",