Skip to content

Commit

Permalink
feat: replace fleek with subgraph for BalancerV1
Browse files Browse the repository at this point in the history
  • Loading branch information
KanievskyiDanylo committed Nov 1, 2023
1 parent bd5a8c9 commit f79c2b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
38 changes: 34 additions & 4 deletions src/dex/balancer-v1/balancer-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,36 @@ import {
} from './types';
import { SimpleExchange } from '../simple-exchange';
import {
MIN_USD_LIQUIDITY_TO_FETCH,
BalancerV1Config,
Adapters,
POOLS_FETCH_TIMEOUT,
MAX_POOLS_FOR_PRICING,
BALANCER_SWAP_GAS_COST,
MAX_POOL_CNT,
} from './config';
import { BalancerV1EventPool } from './balancer-v1-pool';
import { generatePoolStates } from './utils';
import BalancerV1ExchangeProxyABI from '../../abi/BalancerV1ExchangeProxy.json';
import BalancerCustomMulticallABI from '../../abi/BalancerCustomMulticall.json';

const fetchAllPoolsQuery = `query {
pools(first: ${MAX_POOL_CNT.toString()}
orderBy: liquidity
orderDirection: desc
where: {liquidity_gt: ${MIN_USD_LIQUIDITY_TO_FETCH.toString()}}) {
id
swapFee
totalWeight
tokensList
tokens {
address
balance
decimals
denormWeight
}
}
}`;

export class BalancerV1
extends SimpleExchange
implements IDex<BalancerV1Data | OptimizedBalancerV1Data>
Expand Down Expand Up @@ -82,10 +101,21 @@ export class BalancerV1
// for pricing requests. It is optional for a DEX to
// implement this function
async initializePricing(_blockNumber: number) {
this.poolsInfo = await this.dexHelper.httpRequest.get<PoolsInfo>(
this.config.poolsURL,
POOLS_FETCH_TIMEOUT,
const { data } = await this.dexHelper.httpRequest.post<{
data: { pools: PoolInfo[] };
}>(
this.config.subgraphURL,
{ query: fetchAllPoolsQuery },
SUBGRAPH_TIMEOUT,
);

if (!(data && data.pools))
throw new Error(
`Error ${this.dexKey} Subgraph: couldn't fetch the pools from the subgraph`,
);

this.poolsInfo = data;

this.poolInfosByToken = {};
for (const poolInfo of this.poolsInfo.pools) {
for (const tokenAddress of poolInfo.tokensList) {
Expand Down
3 changes: 2 additions & 1 deletion src/dex/balancer-v1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { DexParams } from './types';
import { DexConfigMap, AdapterMappings } from '../../types';
import { Network, SwapSide } from '../../constants';

export const POOLS_FETCH_TIMEOUT = 10000;
export const MAX_POOL_CNT = 1000;
export const MIN_USD_LIQUIDITY_TO_FETCH = 100;
export const BALANCES_MULTICALL_POOLS_LIMIT = 200;
export const MAX_POOLS_FOR_PRICING = 5;
export const BALANCER_SWAP_GAS_COST = 120 * 1000;
Expand Down
7 changes: 6 additions & 1 deletion tests/constants-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const Tokens: {
address: '0x8f8221aFbB33998d8584A2B05749bA73c37a938a',
decimals: 18,
},
AMPL: {
address: '0xd46ba6d942050d489dbd938a2c909a5d5039a161',
decimals: 9,
},
USDC: {
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
decimals: 6,
Expand Down Expand Up @@ -957,7 +961,8 @@ export const Holders: {
} = {
[Network.MAINNET]: {
ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
USDC: '0x79E2Ba942B0e8fDB6ff3d406e930289d10B49ADe',
USDC: '0x7713974908be4bed47172370115e8b1219f4a5f0',
AMPL: '0x223592a191ECfC7FDC38a9256c3BD96E771539A9',
WBTC: '0x1cb17a66dc606a52785f69f08f4256526abd4943',
sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195',
BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a',
Expand Down

0 comments on commit f79c2b5

Please sign in to comment.