do not demand multihop prices from non-fee soures

This commit is contained in:
Lawrence Forman
2022-03-08 15:41:54 -05:00
parent f46b878637
commit 27ae6aabd1
2 changed files with 27 additions and 10 deletions

View File

@@ -176,7 +176,8 @@ export class MarketOperationUtils {
takerToken,
makerToken,
side: MarketOperation.Sell,
sources: samplerSourceFilters.sources,
requiredSources: feeSourceFilters.sources,
optionalSources: samplerSourceFilters.exclude(feeSourceFilters.sources).sources,
inputAmount: takerAmount,
})
: [[], []];
@@ -240,7 +241,8 @@ export class MarketOperationUtils {
side: MarketOperation,
takerToken: Address,
makerToken: Address,
sources: ERC20BridgeSource[],
requiredSources: ERC20BridgeSource[],
optionalSources: ERC20BridgeSource[],
inputAmount: BigNumber,
hopAmountScaling?: number,
}): Promise<[Address[][], BigNumber[]]> {
@@ -248,7 +250,8 @@ export class MarketOperationUtils {
side,
takerToken,
makerToken,
sources,
requiredSources,
optionalSources,
inputAmount,
} = opts;
const hopAmountScaling = opts.hopAmountScaling === undefined ? 1.25 : opts.hopAmountScaling;
@@ -281,10 +284,22 @@ export class MarketOperationUtils {
if (!hopTokenPaths.length) {
return [[],[]];
}
const hopTokenPathPrices = await this._sampler.getPricesAsync(
hopTokenPaths,
sources,
);
let hopTokenPathPrices: BigNumber[];
{
const [requiredHopTokenPathPrices, optionalHopTokenPathPrices] = await Promise.all([
this._sampler.getPricesAsync(
hopTokenPaths,
requiredSources,
),
this._sampler.getPricesAsync(
hopTokenPaths,
optionalSources,
false,
),
]);
hopTokenPathPrices = hopTokenPaths
.map((_, i) => BigNumber.max(...[requiredHopTokenPathPrices[i], optionalHopTokenPathPrices[i]]));
}
// Find eligible two-hops and compute their total price.
let twoHopPathDetails = hopTokenPaths.map((firstHop, firstHopIndex) => {
const firstHopPrice = hopTokenPathPrices[firstHopIndex];
@@ -405,7 +420,8 @@ export class MarketOperationUtils {
takerToken,
makerToken,
side: MarketOperation.Buy,
sources: samplerSourceFilters.sources,
requiredSources: feeSourceFilters.sources,
optionalSources: samplerSourceFilters.exclude(feeSourceFilters.sources).sources,
inputAmount: makerAmount,
})
: [[], []];

View File

@@ -18,7 +18,7 @@ interface TokenInfo {
export interface Sampler {
chainId: ChainId;
getTokenInfosAsync(tokens: Address[]): Promise<TokenInfo[]>;
getPricesAsync(paths: Address[][], sources: ERC20BridgeSource[]): Promise<BigNumber[]>;
getPricesAsync(paths: Address[][], sources: ERC20BridgeSource[], demand?: boolean): Promise<BigNumber[]>;
getSellLiquidityAsync(path: Address[], takerAmount: BigNumber, sources: ERC20BridgeSource[], numSamples?: number): Promise<DexSample[][]>;
getBuyLiquidityAsync(path: Address[], makerAmount: BigNumber, sources: ERC20BridgeSource[], numSamples?: number): Promise<DexSample[][]>;
}
@@ -49,10 +49,11 @@ export class SamplerClient implements Sampler {
public async getPricesAsync(
paths: Address[][],
sources: ERC20BridgeSource[],
demand: boolean = true,
): Promise<BigNumber[]> {
return this._service.getPricesAsync(paths.map(p => ({
tokenPath: p,
demand: true,
demand,
sources,
})));
}