Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kyu-c committed May 10, 2022
2 parents ca880fb + 09413c0 commit b34a961
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 95 deletions.
29 changes: 29 additions & 0 deletions packages/asset-swapper/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
[
{
"version": "16.57.4",
"changes": [
{
"note": "Remove SnowSwap on mainnet",
"pr": 468
}
]
},
{
"version": "16.57.3",
"changes": [
{
"note": "Fix a runtime error related to BalancerV2SwapInfoCache",
"pr": 472
}
],
"timestamp": 1652146864
},
{
"version": "16.57.2",
"changes": [
{
"note": "Fix missing AMM quotes on indicative Quote Reports",
"pr": 466
}
],
"timestamp": 1651526551
},
{
"version": "16.57.1",
"changes": [
Expand Down
13 changes: 13 additions & 0 deletions packages/asset-swapper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ Edit the package's CHANGELOG.json file only.

CHANGELOG

## v16.57.3 - _May 10, 2022_

* Fix a runtime error related to BalancerV2SwapInfoCache (#472)

## v16.57.2 - _May 2, 2022_

* Fix missing AMM quotes on indicative Quote Reports (#466)

## v16.57.1 - _Invalid date_

* Added QUICK/ANY pair on Polygon (#464)
* Added cvxFXS/FXS curve pool on mainnet (#465)

## v16.57.0 - _April 22, 2022_

* Add BalancerV2 batch swap support (#462)
Expand Down
2 changes: 1 addition & 1 deletion packages/asset-swapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0x/asset-swapper",
"version": "16.57.0",
"version": "16.57.3",
"engines": {
"node": ">=6.12"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
SHIBASWAP_ROUTER_BY_CHAIN_ID,
SMOOTHY_BSC_INFOS,
SMOOTHY_MAINNET_INFOS,
SNOWSWAP_MAINNET_INFOS,
SPIRITSWAP_ROUTER_BY_CHAIN_ID,
SPOOKYSWAP_ROUTER_BY_CHAIN_ID,
SUSHISWAP_ROUTER_BY_CHAIN_ID,
Expand Down Expand Up @@ -224,19 +223,6 @@ export function getCurveV2InfosForPair(chainId: ChainId, takerToken: string, mak
}
}

export function getSnowSwapInfosForPair(chainId: ChainId, takerToken: string, makerToken: string): CurveInfo[] {
if (chainId !== ChainId.Mainnet) {
return [];
}
return Object.values(SNOWSWAP_MAINNET_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) && [makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
}

export function getNerveInfosForPair(chainId: ChainId, takerToken: string, makerToken: string): CurveInfo[] {
if (chainId !== ChainId.BSC) {
return [];
Expand Down Expand Up @@ -479,7 +465,6 @@ export function getCurveLikeInfosForPair(
source:
| ERC20BridgeSource.Curve
| ERC20BridgeSource.CurveV2
| ERC20BridgeSource.SnowSwap
| ERC20BridgeSource.Nerve
| ERC20BridgeSource.Synapse
| ERC20BridgeSource.Belt
Expand All @@ -500,9 +485,6 @@ export function getCurveLikeInfosForPair(
case ERC20BridgeSource.CurveV2:
pools = getCurveV2InfosForPair(chainId, takerToken, makerToken);
break;
case ERC20BridgeSource.SnowSwap:
pools = getSnowSwapInfosForPair(chainId, takerToken, makerToken);
break;
case ERC20BridgeSource.Nerve:
pools = getNerveInfosForPair(chainId, takerToken, makerToken);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.Bancor,
ERC20BridgeSource.MStable,
ERC20BridgeSource.Mooniswap,
ERC20BridgeSource.SnowSwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.Shell,
ERC20BridgeSource.MultiHop,
Expand Down Expand Up @@ -232,7 +231,6 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
ERC20BridgeSource.MStable,
ERC20BridgeSource.Mooniswap,
ERC20BridgeSource.Shell,
ERC20BridgeSource.SnowSwap,
ERC20BridgeSource.SushiSwap,
ERC20BridgeSource.MultiHop,
ERC20BridgeSource.Dodo,
Expand Down Expand Up @@ -737,17 +735,6 @@ export const CURVE_OPTIMISM_POOLS = {
tri: '0x1337bedc9d22ecbe766df105c9623922a27963ec',
};

export const SNOWSWAP_POOLS = {
yUSD: '0xbf7ccd6c446acfcc5df023043f2167b62e81899b',
yVault: '0x4571753311e37ddb44faa8fb78a6df9a6e3c6c0b',
// POOL Disabled as it uses WETH over ETH
// There is a conflict with Curve and SnowSwap
// where Curve uses ETH and SnowSwap uses WETH
// To re-enable this we need to flag an WETH
// unwrap or not
// eth: '0x16bea2e63adade5984298d53a4d4d9c09e278192',
};

export const SMOOTHY_POOLS = {
syUSD: '0xe5859f4efc09027a9b718781dcb2c6910cac6e91',
};
Expand Down Expand Up @@ -1506,30 +1493,6 @@ export const CURVE_OPTIMISM_INFOS: { [name: string]: CurveInfo } = {
}),
};

export const SNOWSWAP_MAINNET_INFOS: { [name: string]: CurveInfo } = {
[SNOWSWAP_POOLS.yUSD]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.yUSD, MAINNET_TOKENS.ybCRV],
pool: SNOWSWAP_POOLS.yUSD,
gasSchedule: 990e3,
}),
[SNOWSWAP_POOLS.yUSD]: createCurveExchangeUnderlyingPool({
tokens: [MAINNET_TOKENS.yCRV, MAINNET_TOKENS.bCRV],
pool: SNOWSWAP_POOLS.yUSD,
gasSchedule: 990e3,
}),
[SNOWSWAP_POOLS.yVault]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.yDAI, MAINNET_TOKENS.yUSDC, MAINNET_TOKENS.yUSDT, MAINNET_TOKENS.yTUSD],
pool: SNOWSWAP_POOLS.yVault,
gasSchedule: 1490e3,
}),
// Unsupported due to collision with WETH and ETH with execution using MixinCurve
// [SNOWSWAP_POOLS.eth]: createCurveExchangePool({
// tokens: [MAINNET_TOKENS.WETH, MAINNET_TOKENS.vETH, MAINNET_TOKENS.ankrETH, MAINNET_TOKENS.crETH],
// pool: SNOWSWAP_POOLS.eth,
// gasSchedule: 990e3,
// }),
};

export const BELT_BSC_INFOS: { [name: string]: CurveInfo } = {
[BELT_POOLS.vPool]: createCurveExchangeUnderlyingPool({
tokens: [BSC_TOKENS.DAI, BSC_TOKENS.USDC, BSC_TOKENS.USDT, BSC_TOKENS.BUSD],
Expand Down Expand Up @@ -2413,7 +2376,6 @@ export const DEFAULT_GAS_SCHEDULE: Required<FeeSchedule> = {
[ERC20BridgeSource.Kyber]: () => 450e3,
[ERC20BridgeSource.Curve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.CurveV2]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.SnowSwap]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Nerve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Synapse]: fillData => (fillData as CurveFillData).pool.gasSchedule,
[ERC20BridgeSource.Belt]: fillData => (fillData as CurveFillData).pool.gasSchedule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ export class MarketOperationUtils {
private async _refreshPoolCacheIfRequiredAsync(takerToken: string, makerToken: string): Promise<void> {
void Promise.all(
Object.values(this._sampler.poolsCaches).map(async cache => {
if (cache.isFresh(takerToken, makerToken)) {
if (!cache || cache.isFresh(takerToken, makerToken)) {
return Promise.resolve([]);
}
return cache.getFreshPoolsForPairAsync(takerToken, makerToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s
return encodeBridgeSourceId(BridgeProtocol.Oasis, 'Eth2Dai');
case ERC20BridgeSource.Shell:
return encodeBridgeSourceId(BridgeProtocol.Shell, 'Shell');
case ERC20BridgeSource.SnowSwap:
return encodeBridgeSourceId(BridgeProtocol.Curve, 'SnowSwap');
case ERC20BridgeSource.SushiSwap:
return encodeBridgeSourceId(BridgeProtocol.UniswapV2, 'SushiSwap');
case ERC20BridgeSource.Uniswap:
Expand Down Expand Up @@ -228,7 +226,6 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
switch (order.source) {
case ERC20BridgeSource.Curve:
case ERC20BridgeSource.CurveV2:
case ERC20BridgeSource.SnowSwap:
case ERC20BridgeSource.Nerve:
case ERC20BridgeSource.Synapse:
case ERC20BridgeSource.Belt:
Expand Down Expand Up @@ -484,7 +481,6 @@ export const BRIDGE_ENCODERS: {
// Curve like
[ERC20BridgeSource.Curve]: curveEncoder,
[ERC20BridgeSource.CurveV2]: curveEncoder,
[ERC20BridgeSource.SnowSwap]: curveEncoder,
[ERC20BridgeSource.Nerve]: curveEncoder,
[ERC20BridgeSource.Synapse]: curveEncoder,
[ERC20BridgeSource.Belt]: curveEncoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const TWO_HOP_SOURCE_FILTERS = SourceFilters.all().exclude([
export const BATCH_SOURCE_FILTERS = SourceFilters.all().exclude([ERC20BridgeSource.MultiHop, ERC20BridgeSource.Native]);

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
Expand Down Expand Up @@ -149,7 +149,10 @@ export class SamplerOperations {
),
[ERC20BridgeSource.Balancer]: new BalancerPoolsCache(),
[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];
Expand Down Expand Up @@ -569,7 +572,7 @@ export class SamplerOperations {
});
}

public getBalancerV2MulthopSellQuotes(
public getBalancerV2MultihopSellQuotes(
vault: string,
quoteSwaps: BalancerSwapInfo, // Should always be sell swap steps.
fillSwaps: BalancerSwapInfo, // Should always be sell swap steps.
Expand All @@ -590,7 +593,7 @@ export class SamplerOperations {
});
}

public getBalancerV2MulthopBuyQuotes(
public getBalancerV2MultihopBuyQuotes(
vault: string,
quoteSwaps: BalancerSwapInfo, // Should always be buy swap steps.
fillSwaps: BalancerSwapInfo, // Should always be a sell quote.
Expand Down Expand Up @@ -1420,7 +1423,6 @@ export class SamplerOperations {
);
case ERC20BridgeSource.Curve:
case ERC20BridgeSource.CurveV2:
case ERC20BridgeSource.SnowSwap:
case ERC20BridgeSource.Nerve:
case ERC20BridgeSource.Synapse:
case ERC20BridgeSource.Belt:
Expand Down Expand Up @@ -1496,15 +1498,19 @@ export class SamplerOperations {
),
);
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];
if (!swaps || vault === NULL_ADDRESS) {
return [];
}
// Changed to retrieve queryBatchSwap for swap steps > 1 of length
return swaps.swapInfoExactIn.map(swapInfo =>
this.getBalancerV2MulthopSellQuotes(vault, swapInfo, swapInfo, takerFillAmounts, source),
this.getBalancerV2MultihopSellQuotes(vault, swapInfo, swapInfo, takerFillAmounts, source),
);
}
case ERC20BridgeSource.Beethovenx: {
Expand Down Expand Up @@ -1725,7 +1731,6 @@ export class SamplerOperations {
);
case ERC20BridgeSource.Curve:
case ERC20BridgeSource.CurveV2:
case ERC20BridgeSource.SnowSwap:
case ERC20BridgeSource.Nerve:
case ERC20BridgeSource.Synapse:
case ERC20BridgeSource.Belt:
Expand Down Expand Up @@ -1801,15 +1806,19 @@ export class SamplerOperations {
),
);
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];
if (!swaps || vault === NULL_ADDRESS) {
return [];
}
// Changed to retrieve queryBatchSwap for swap steps > 1 of length
return swaps.swapInfoExactOut.map((quoteSwapInfo, i) =>
this.getBalancerV2MulthopBuyQuotes(
this.getBalancerV2MultihopBuyQuotes(
vault,
quoteSwapInfo,
swaps.swapInfoExactIn[i],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export enum ERC20BridgeSource {
Mooniswap = 'Mooniswap',
MultiHop = 'MultiHop',
Shell = 'Shell',
SnowSwap = 'SnowSwap',
SushiSwap = 'SushiSwap',
Dodo = 'DODO',
DodoV2 = 'DODO_V2',
Expand Down
14 changes: 3 additions & 11 deletions packages/asset-swapper/src/utils/quote_report_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export function generateExtendedQuoteReportSources(
..._.flatten(
quotes.dexQuotes.map(dex =>
dex
.filter(quote => isDexSampleForTotalAmount(quote, marketOperation, amount))
.filter(quote => isDexSampleForTotalAmount(quote, amount))
.map(quote => dexSampleToReportSource(quote, marketOperation)),
),
),
Expand Down Expand Up @@ -306,16 +306,8 @@ export function dexSampleToReportSource(ds: DexSample, marketOperation: MarketOp
* Checks if a DEX sample is the one that represents the whole amount requested by taker
* NOTE: this is used for the QuoteReport to filter samples
*/
function isDexSampleForTotalAmount(ds: DexSample, marketOperation: MarketOperation, amount: BigNumber): boolean {
// input and output map to different values
// based on the market operation
if (marketOperation === MarketOperation.Buy) {
return ds.input === amount;
} else if (marketOperation === MarketOperation.Sell) {
return ds.output === amount;
} else {
throw new Error(`Unexpected marketOperation ${marketOperation}`);
}
function isDexSampleForTotalAmount(ds: DexSample, amount: BigNumber): boolean {
return ds.input.eq(amount);
}

/**
Expand Down
11 changes: 0 additions & 11 deletions packages/asset-swapper/test/market_operation_utils_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,6 @@ describe('MarketOperationUtils tests', () => {
fromTokenIdx: 0,
toTokenIdx: 1,
},
[ERC20BridgeSource.SnowSwap]: {
pool: {
poolAddress: randomAddress(),
tokens: [TAKER_TOKEN, MAKER_TOKEN],
exchangeFunctionSelector: hexUtils.random(4),
sellQuoteFunctionSelector: hexUtils.random(4),
buyQuoteFunctionSelector: hexUtils.random(4),
},
fromTokenIdx: 0,
toTokenIdx: 1,
},
[ERC20BridgeSource.Smoothy]: {
pool: {
poolAddress: randomAddress(),
Expand Down

0 comments on commit b34a961

Please sign in to comment.