Skip to content

Commit b234f52

Browse files
committed
update
1 parent 37c51e9 commit b234f52

File tree

11 files changed

+47
-24
lines changed

11 files changed

+47
-24
lines changed

src/constants/exchange.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
metisTokens,
1414
baseTokens,
1515
iotaTokens,
16-
sonicTokens
16+
sonicTokens,
1717
} from '@real-wagmi/sdk';
1818
import { ChainMap, ChainTokenList } from '../types';
1919

@@ -30,7 +30,7 @@ export const SMART_ROUTER_ADDRESSES: ChainMap<string> = {
3030
[ChainId.METIS]: '0x8B741B0D79BE80E135C880F7583d427B4D41F015',
3131
[ChainId.BASE]: '0xB5fa77E3929fe198a86Aa40fd6c77886785bCd0e',
3232
[ChainId.IOTA]: '0xaE7b92C8B14E7bdB523408aE0A6fFbf3f589adD9',
33-
[ChainId.SONIC]: '0x1Ac569879EF7EacB17CC373EF801cDcE4acCdeD5'
33+
[ChainId.SONIC]: '0x1Ac569879EF7EacB17CC373EF801cDcE4acCdeD5',
3434
};
3535

3636
// used to construct intermediary pairs for trading
@@ -47,7 +47,7 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
4747
[ChainId.METIS]: [metisTokens.wmetis, metisTokens.usdc, metisTokens.usdt, metisTokens.weth, metisTokens.wbtc],
4848
[ChainId.BASE]: [baseTokens.weth, baseTokens.usdc, baseTokens.usdbc],
4949
[ChainId.IOTA]: [iotaTokens.weth, iotaTokens.usdt, iotaTokens.usdc, iotaTokens.wiota],
50-
[ChainId.SONIC]: [sonicTokens.ws, sonicTokens.weth, sonicTokens.usdce, sonicTokens.wagmi]
50+
[ChainId.SONIC]: [sonicTokens.ws, sonicTokens.weth, sonicTokens.usdce, sonicTokens.wagmi],
5151
};
5252

5353
/**

src/constants/multicall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ export const BATCH_MULTICALL_CONFIGS: ChainMap<BatchMulticallConfigs> = {
5555
},
5656
},
5757
[ChainId.IOTA]: DEFAULT,
58-
[ChainId.SONIC]: DEFAULT
58+
[ChainId.SONIC]: DEFAULT,
5959
};

src/constants/v3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export const V3_QUOTER_ADDRESSES: ChainMap<Address> = {
1818
[ChainId.METIS]: '0xB9a14EE1cd3417f3AcC988F61650895151abde24',
1919
[ChainId.BASE]: '0x8B741B0D79BE80E135C880F7583d427B4D41F015',
2020
[ChainId.IOTA]: '0x5C08A6762CAF9ec8a42F249eBC23aAE66097218D',
21-
[ChainId.SONIC]: '0xDb51CffFf3B989d0cB6b58AbF173371b6F2d0D24'
21+
[ChainId.SONIC]: '0xDb51CffFf3B989d0cB6b58AbF173371b6F2d0D24',
2222
};

src/multicall/constants/blockConflictTolerance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export const BLOCK_CONFLICT_TOLERANCE: { [key in ChainId]?: number } = {
1212
[ChainId.KAVA]: 3,
1313
[ChainId.METIS]: 5,
1414
[ChainId.IOTA]: 3,
15-
[ChainId.SONIC]: 5
15+
[ChainId.SONIC]: 30,
1616
};

src/multicall/constants/contracts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const MULTICALL_ADDRESS: { [key in ChainId]: Address } = {
1414
[ChainId.IOTA]: '0x212Aa024E25A9C9bAF5b5397B558B7ccea81740B',
1515
[ChainId.POLYGON]: '0x9ab6E62123464d6F7a21457840Daf34754C9C6d7',
1616
[ChainId.AVALANCHE]: '0x721655cCcd531DD6a2d87F72A31E2e927B965C3c',
17-
[ChainId.SONIC]: '0x6dF85fD781ddDAbD7f12835f1ff847Db6F14Ca2c'
17+
[ChainId.SONIC]: '0x6dF85fD781ddDAbD7f12835f1ff847Db6F14Ca2c',
1818
};
1919

2020
export const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
@@ -33,5 +33,5 @@ export const MULTICALL3_ADDRESSES: {
3333
[ChainId.BASE]: '0x7301350CC76D669ea384e77aF38a70C61661CA48',
3434
[ChainId.POLYGON]: '0xFE9409E7d74D4512a8BB5576937d990fcD8aBc52',
3535
[ChainId.AVALANCHE]: '0x8bb1Be7acD806BF6C9766486dC4c21284a472BaC',
36-
[ChainId.SONIC]: '0x2dA5DdBeC63dfd93112AedFa44F880927AA5Ae41'
36+
[ChainId.SONIC]: '0x2dA5DdBeC63dfd93112AedFa44F880927AA5Ae41',
3737
};

src/multicall/constants/gasLimit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const DEFAULT_GAS_LIMIT_BY_CHAIN: { [key in ChainId]?: bigint } = {
66
[ChainId.BSC]: 100_000_000n,
77
[ChainId.ZKSYNC]: 500_000_000n,
88
[ChainId.POLYGON]: 1_500_000n,
9-
[ChainId.SONIC]: 5_000_000_000n
9+
[ChainId.SONIC]: 5_000_000_000n,
1010
};
1111

1212
export const DEFAULT_GAS_BUFFER = 3_000_000n;

src/utils/pMap.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export async function pMap<T, R>(items: T[], mapper: (item: T) => Promise<R>, options: { concurrency: number }): Promise<R[]> {
2+
const results: R[] = [];
3+
const inProgress = new Set<Promise<void>>();
4+
5+
for (const item of items) {
6+
if (inProgress.size >= options.concurrency) {
7+
await Promise.race(inProgress);
8+
}
9+
10+
const processPromise = async () => {
11+
const result = await mapper(item);
12+
results.push(result);
13+
};
14+
15+
const promise = processPromise();
16+
inProgress.add(promise);
17+
promise.finally(() => inProgress.delete(promise));
18+
}
19+
20+
await Promise.all(inProgress);
21+
return results;
22+
}

src/v3-router/functions/getBestRouteCombinationByQuotes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function getBestRouteCombinationByQuotes(
4747
const swapRoute = getBestSwapRouteBy(
4848
tradeType,
4949
percentToQuotes,
50-
percents.sort((a, b) => a - b),
50+
percents.toSorted((a, b) => a - b),
5151
chainId,
5252
(rq: RouteWithQuote) => rq.quoteAdjustedForGas,
5353
config,
@@ -134,7 +134,7 @@ export function getBestSwapRouteBy(
134134
} | null {
135135
// Build a map of percentage to sorted list of quotes, with the biggest quote being first in the list.
136136
const percentToSortedQuotes = mapValues(percentToQuotes, (routeQuotes: RouteWithQuote[]) => {
137-
return routeQuotes.sort((routeQuoteA, routeQuoteB) => {
137+
return routeQuotes.toSorted((routeQuoteA, routeQuoteB) => {
138138
if (tradeType === TradeType.EXACT_INPUT) {
139139
return by(routeQuoteA).greaterThan(by(routeQuoteB)) ? -1 : 1;
140140
}
@@ -439,7 +439,7 @@ export function getBestSwapRouteBy(
439439
// flatL1GasCostUSD: gasCostL1USD.toExact(),
440440
// },
441441
// 'USD gas estimates of best route',
442-
// )
442+
// );
443443

444444
const estimatedGasUsedQuoteToken = sumFn(bestSwap.map(routeWithValidQuote => routeWithValidQuote.gasCostInToken)).add(gasCostL1QuoteToken);
445445

@@ -454,7 +454,7 @@ export function getBestSwapRouteBy(
454454
quoteGasAdjusted = quoteGasAdjustedForL1;
455455
}
456456

457-
const routeWithQuotes = bestSwap.sort((routeAmountA, routeAmountB) => (routeAmountB.amount.greaterThan(routeAmountA.amount) ? 1 : -1));
457+
const routeWithQuotes = bestSwap.toSorted((routeAmountA, routeAmountB) => (routeAmountB.amount.greaterThan(routeAmountA.amount) ? 1 : -1));
458458

459459
// metric.putMetric(
460460
// 'PostSplitDone',

src/v3-router/getRoutesWithValidQuote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { BaseRoute, GasModel, QuoteProvider, RouteWithoutQuote, RouteWithQuote }
66
import { getAmountDistribution } from './functions';
77
import { metric } from './utils/metric';
88
import { AbortControl } from '../utils/abortControl';
9+
import { pMap } from '../utils/pMap';
910

1011
type Params = {
1112
blockNumber?: BigintIsh;
@@ -62,7 +63,7 @@ export async function getRoutesWithValidQuote({
6263
});
6364
});
6465
const chunks = chunk(routesWithoutQuote, 10);
65-
const result = await Promise.all(chunks.map(getQuotes));
66+
const result = await pMap(chunks, async chunk => getQuotes(chunk), { concurrency: 5 });
6667
const quotes = result.reduce<RouteWithQuote[]>((acc, cur) => [...acc, ...cur], []);
6768
metric('Get quotes', 'success, got', quotes.length, 'quoted routes', quotes);
6869
return quotes;

src/v3-router/providers/poolProviders/poolTvlSelectors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function poolSelectorFactory<P extends WithTvl>({ getPoolSelectorConfig, getToke
2020
if (!currencyA || !currencyB || !unorderedPoolsWithTvl.length) {
2121
return [];
2222
}
23-
const poolsFromSubgraph = unorderedPoolsWithTvl.sort(sortByTvl);
23+
const poolsFromSubgraph = unorderedPoolsWithTvl.toSorted(sortByTvl);
2424
const { chainId } = getToken0(poolsFromSubgraph[0]);
2525
const baseTokens: Token[] = BASES_TO_CHECK_TRADES_AGAINST[chainId as ChainId] ?? [];
2626

@@ -40,11 +40,11 @@ function poolSelectorFactory<P extends WithTvl>({ getPoolSelectorConfig, getToke
4040
(getToken1(subgraphPool).wrapped.equals(token) && getToken0(subgraphPool).wrapped.equals(currencyA.wrapped))
4141
);
4242
})
43-
.sort(sortByTvl)
43+
.toSorted(sortByTvl)
4444
.slice(0, POOL_SELECTION_CONFIG.topNWithEachBaseToken);
4545
})
4646
.reduce<P[]>((acc, cur) => [...acc, ...cur], [])
47-
.sort(sortByTvl)
47+
.toSorted(sortByTvl)
4848
.slice(0, POOL_SELECTION_CONFIG.topNWithBaseToken);
4949

5050
addToPoolSet(topByBaseWithTokenIn);
@@ -61,11 +61,11 @@ function poolSelectorFactory<P extends WithTvl>({ getPoolSelectorConfig, getToke
6161
(getToken1(subgraphPool).wrapped.equals(token) && getToken0(subgraphPool).wrapped.equals(currencyB.wrapped))
6262
);
6363
})
64-
.sort(sortByTvl)
64+
.toSorted(sortByTvl)
6565
.slice(0, POOL_SELECTION_CONFIG.topNWithEachBaseToken);
6666
})
6767
.reduce<P[]>((acc, cur) => [...acc, ...cur], [])
68-
.sort(sortByTvl)
68+
.toSorted(sortByTvl)
6969
.slice(0, POOL_SELECTION_CONFIG.topNWithBaseToken);
7070

7171
addToPoolSet(topByBaseWithTokenOut);
@@ -154,7 +154,7 @@ function poolSelectorFactory<P extends WithTvl>({ getPoolSelectorConfig, getToke
154154
.reduce<P[]>((acc, cur) => [...acc, ...cur], [])
155155
// Uniq
156156
.reduce<P[]>((acc, cur) => (acc.some(p => p === cur) ? acc : [...acc, cur]), [])
157-
.sort(sortByTvl)
157+
.toSorted(sortByTvl)
158158
.slice(0, POOL_SELECTION_CONFIG.topNSecondHop);
159159

160160
const topByTVLUsingTokenInSecondHops = getTopByTVLUsingTokenSecondHops([...topByTVLUsingTokenBase, ...topByBaseWithTokenIn], currencyA);

0 commit comments

Comments
 (0)