Do not initialize BalancerV2SwapInfoCache on unsupported chains [TKR-365] (#472)

* Do not initialize BalancerV2SwapInfoCache on unsupported chains
* Update CHANGELOG.json
This commit is contained in:
Kyu 2022-05-09 18:21:04 -07:00 committed by GitHub
parent 423ef57344
commit aa1016ee5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View File

@ -1,4 +1,13 @@
[ [
{
"version": "16.57.3",
"changes": [
{
"note": "Fix a runtime error related to BalancerV2SwapInfoCache",
"pr": 472
}
]
},
{ {
"version": "16.57.2", "version": "16.57.2",
"changes": [ "changes": [

View File

@ -777,7 +777,7 @@ export class MarketOperationUtils {
private async _refreshPoolCacheIfRequiredAsync(takerToken: string, makerToken: string): Promise<void> { private async _refreshPoolCacheIfRequiredAsync(takerToken: string, makerToken: string): Promise<void> {
void Promise.all( void Promise.all(
Object.values(this._sampler.poolsCaches).map(async cache => { Object.values(this._sampler.poolsCaches).map(async cache => {
if (cache.isFresh(takerToken, makerToken)) { if (!cache || cache.isFresh(takerToken, makerToken)) {
return Promise.resolve([]); return Promise.resolve([]);
} }
return cache.getFreshPoolsForPairAsync(takerToken, makerToken); return cache.getFreshPoolsForPairAsync(takerToken, makerToken);

View File

@ -107,7 +107,7 @@ export const TWO_HOP_SOURCE_FILTERS = SourceFilters.all().exclude([
export const BATCH_SOURCE_FILTERS = SourceFilters.all().exclude([ERC20BridgeSource.MultiHop, ERC20BridgeSource.Native]); export const BATCH_SOURCE_FILTERS = SourceFilters.all().exclude([ERC20BridgeSource.MultiHop, ERC20BridgeSource.Native]);
export type PoolsCacheMap = { [key in Exclude<SourcesWithPoolsCache, ERC20BridgeSource.BalancerV2>]: PoolsCache } & { export type PoolsCacheMap = { [key in Exclude<SourcesWithPoolsCache, ERC20BridgeSource.BalancerV2>]: PoolsCache } & {
[ERC20BridgeSource.BalancerV2]: BalancerV2SwapInfoCache; [ERC20BridgeSource.BalancerV2]: BalancerV2SwapInfoCache | undefined;
}; };
// tslint:disable:no-inferred-empty-object-type no-unbound-method // tslint:disable:no-inferred-empty-object-type no-unbound-method
@ -151,7 +151,10 @@ export class SamplerOperations {
), ),
[ERC20BridgeSource.Balancer]: new BalancerPoolsCache(), [ERC20BridgeSource.Balancer]: new BalancerPoolsCache(),
[ERC20BridgeSource.Cream]: new CreamPoolsCache(), [ERC20BridgeSource.Cream]: new CreamPoolsCache(),
[ERC20BridgeSource.BalancerV2]: new BalancerV2SwapInfoCache(chainId), [ERC20BridgeSource.BalancerV2]:
BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[chainId] === NULL_ADDRESS
? undefined
: new BalancerV2SwapInfoCache(chainId),
}; };
const aaveSubgraphUrl = AAVE_V2_SUBGRAPH_URL_BY_CHAIN_ID[chainId]; const aaveSubgraphUrl = AAVE_V2_SUBGRAPH_URL_BY_CHAIN_ID[chainId];
@ -571,7 +574,7 @@ export class SamplerOperations {
}); });
} }
public getBalancerV2MulthopSellQuotes( public getBalancerV2MultihopSellQuotes(
vault: string, vault: string,
quoteSwaps: BalancerSwapInfo, // Should always be sell swap steps. quoteSwaps: BalancerSwapInfo, // Should always be sell swap steps.
fillSwaps: BalancerSwapInfo, // Should always be sell swap steps. fillSwaps: BalancerSwapInfo, // Should always be sell swap steps.
@ -592,7 +595,7 @@ export class SamplerOperations {
}); });
} }
public getBalancerV2MulthopBuyQuotes( public getBalancerV2MultihopBuyQuotes(
vault: string, vault: string,
quoteSwaps: BalancerSwapInfo, // Should always be buy swap steps. quoteSwaps: BalancerSwapInfo, // Should always be buy swap steps.
fillSwaps: BalancerSwapInfo, // Should always be a sell quote. fillSwaps: BalancerSwapInfo, // Should always be a sell quote.
@ -1499,15 +1502,19 @@ export class SamplerOperations {
), ),
); );
case ERC20BridgeSource.BalancerV2: { case ERC20BridgeSource.BalancerV2: {
const swaps = this.poolsCaches[source].getCachedSwapInfoForPair(takerToken, makerToken); const cache = this.poolsCaches[source];
if (!cache) {
return [];
}
const swaps = cache.getCachedSwapInfoForPair(takerToken, makerToken);
const vault = BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId]; const vault = BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId];
if (!swaps || vault === NULL_ADDRESS) { if (!swaps || vault === NULL_ADDRESS) {
return []; return [];
} }
// Changed to retrieve queryBatchSwap for swap steps > 1 of length // Changed to retrieve queryBatchSwap for swap steps > 1 of length
return swaps.swapInfoExactIn.map(swapInfo => return swaps.swapInfoExactIn.map(swapInfo =>
this.getBalancerV2MulthopSellQuotes(vault, swapInfo, swapInfo, takerFillAmounts, source), this.getBalancerV2MultihopSellQuotes(vault, swapInfo, swapInfo, takerFillAmounts, source),
); );
} }
case ERC20BridgeSource.Beethovenx: { case ERC20BridgeSource.Beethovenx: {
@ -1822,15 +1829,19 @@ export class SamplerOperations {
), ),
); );
case ERC20BridgeSource.BalancerV2: { case ERC20BridgeSource.BalancerV2: {
const swaps = this.poolsCaches[source].getCachedSwapInfoForPair(takerToken, makerToken); const cache = this.poolsCaches[source];
if (!cache) {
return [];
}
const swaps = cache.getCachedSwapInfoForPair(takerToken, makerToken);
const vault = BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId]; const vault = BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[this.chainId];
if (!swaps || vault === NULL_ADDRESS) { if (!swaps || vault === NULL_ADDRESS) {
return []; return [];
} }
// Changed to retrieve queryBatchSwap for swap steps > 1 of length // Changed to retrieve queryBatchSwap for swap steps > 1 of length
return swaps.swapInfoExactOut.map((quoteSwapInfo, i) => return swaps.swapInfoExactOut.map((quoteSwapInfo, i) =>
this.getBalancerV2MulthopBuyQuotes( this.getBalancerV2MultihopBuyQuotes(
vault, vault,
quoteSwapInfo, quoteSwapInfo,
swaps.swapInfoExactIn[i], swaps.swapInfoExactIn[i],