performed a rename

This commit is contained in:
Daniel Pyrathon 2020-02-28 16:54:05 -08:00
parent 08619e2c06
commit 7495ac8111
9 changed files with 91 additions and 91 deletions

View File

@ -41,7 +41,7 @@ contract DummyLiquidityProviderRegistry
poolAddress = _gAddressBook[takerToken][makerToken]; poolAddress = _gAddressBook[takerToken][makerToken];
require( require(
poolAddress != NULL_ADDRESS, poolAddress != NULL_ADDRESS,
"PLPRegistry/MARKET_PAIR_NOT_SET" "Registry/MARKET_PAIR_NOT_SET"
); );
} }
} }

View File

@ -144,7 +144,7 @@ export class SwapQuoter {
* @return An instance of SwapQuoter * @return An instance of SwapQuoter
*/ */
constructor(supportedProvider: SupportedProvider, orderbook: Orderbook, options: Partial<SwapQuoterOpts> = {}) { constructor(supportedProvider: SupportedProvider, orderbook: Orderbook, options: Partial<SwapQuoterOpts> = {}) {
const { chainId, expiryBufferMs, permittedOrderFeeTypes, samplerGasLimit, plpRegistryAddress } = _.merge( const { chainId, expiryBufferMs, permittedOrderFeeTypes, samplerGasLimit, liquidityProviderRegistryAddress } = _.merge(
{}, {},
constants.DEFAULT_SWAP_QUOTER_OPTS, constants.DEFAULT_SWAP_QUOTER_OPTS,
options, options,
@ -174,7 +174,7 @@ export class SwapQuoter {
chainId, chainId,
exchangeAddress: this._contractAddresses.exchange, exchangeAddress: this._contractAddresses.exchange,
}, },
plpRegistryAddress, liquidityProviderRegistryAddress,
); );
this._swapQuoteCalculator = new SwapQuoteCalculator(this._protocolFeeUtils, this._marketOperationUtils); this._swapQuoteCalculator = new SwapQuoteCalculator(this._protocolFeeUtils, this._marketOperationUtils);
} }

View File

@ -212,7 +212,7 @@ export interface SwapQuoterOpts extends OrderPrunerOpts {
expiryBufferMs: number; expiryBufferMs: number;
contractAddresses?: ContractAddresses; contractAddresses?: ContractAddresses;
samplerGasLimit?: number; samplerGasLimit?: number;
plpRegistryAddress?: string; liquidityProviderRegistryAddress?: string;
} }
/** /**

View File

@ -32,7 +32,7 @@ export class CreateOrderUtils {
outputToken: string, outputToken: string,
path: CollapsedFill[], path: CollapsedFill[],
bridgeSlippage: number, bridgeSlippage: number,
plpPoolAddress?: string, liquidityPoolAddress?: string,
): OptimizedMarketOrder[] { ): OptimizedMarketOrder[] {
const orders: OptimizedMarketOrder[] = []; const orders: OptimizedMarketOrder[] = [];
for (const fill of path) { for (const fill of path) {
@ -43,7 +43,7 @@ export class CreateOrderUtils {
createBridgeOrder( createBridgeOrder(
orderDomain, orderDomain,
fill, fill,
this._getBridgeAddressFromSource(fill.source, plpPoolAddress), this._getBridgeAddressFromSource(fill.source, liquidityPoolAddress),
outputToken, outputToken,
inputToken, inputToken,
bridgeSlippage, bridgeSlippage,
@ -61,7 +61,7 @@ export class CreateOrderUtils {
outputToken: string, outputToken: string,
path: CollapsedFill[], path: CollapsedFill[],
bridgeSlippage: number, bridgeSlippage: number,
plpPoolAddress?: string, liquidityPoolAddress?: string,
): OptimizedMarketOrder[] { ): OptimizedMarketOrder[] {
const orders: OptimizedMarketOrder[] = []; const orders: OptimizedMarketOrder[] = [];
for (const fill of path) { for (const fill of path) {
@ -72,7 +72,7 @@ export class CreateOrderUtils {
createBridgeOrder( createBridgeOrder(
orderDomain, orderDomain,
fill, fill,
this._getBridgeAddressFromSource(fill.source, plpPoolAddress), this._getBridgeAddressFromSource(fill.source, liquidityPoolAddress),
inputToken, inputToken,
outputToken, outputToken,
bridgeSlippage, bridgeSlippage,
@ -84,7 +84,7 @@ export class CreateOrderUtils {
return orders; return orders;
} }
private _getBridgeAddressFromSource(source: ERC20BridgeSource, plpPoolAddress?: string): string { private _getBridgeAddressFromSource(source: ERC20BridgeSource, liquidityPoolAddress?: string): string {
switch (source) { switch (source) {
case ERC20BridgeSource.Eth2Dai: case ERC20BridgeSource.Eth2Dai:
return this._contractAddress.eth2DaiBridge; return this._contractAddress.eth2DaiBridge;
@ -96,12 +96,12 @@ export class CreateOrderUtils {
case ERC20BridgeSource.CurveUsdcDaiUsdt: case ERC20BridgeSource.CurveUsdcDaiUsdt:
case ERC20BridgeSource.CurveUsdcDaiUsdtTusd: case ERC20BridgeSource.CurveUsdcDaiUsdtTusd:
return this._contractAddress.curveBridge; return this._contractAddress.curveBridge;
case ERC20BridgeSource.Plp: case ERC20BridgeSource.LiquidityProvider:
if (plpPoolAddress === undefined) { if (liquidityPoolAddress === undefined) {
throw new Error('Cannot create a PLP order without a PLP pool address.'); throw new Error('Cannot create a LiquidityProvider order without a LiquidityProvider pool address.');
} }
assert.isETHAddressHex('plpPoolAddress', plpPoolAddress); assert.isETHAddressHex('liquidityPoolAddress', liquidityPoolAddress);
return plpPoolAddress; return liquidityPoolAddress;
default: default:
break; break;
} }

View File

@ -46,7 +46,7 @@ export class MarketOperationUtils {
private readonly _sampler: DexOrderSampler, private readonly _sampler: DexOrderSampler,
contractAddresses: ContractAddresses, contractAddresses: ContractAddresses,
private readonly _orderDomain: OrderDomain, private readonly _orderDomain: OrderDomain,
private readonly _plpRegistryAddress: string = NULL_ADDRESS, private readonly _liquidityProviderRegistry: string = NULL_ADDRESS,
) { ) {
this._createOrderUtils = new CreateOrderUtils(contractAddresses); this._createOrderUtils = new CreateOrderUtils(contractAddresses);
this._wethAddress = contractAddresses.etherToken; this._wethAddress = contractAddresses.etherToken;
@ -73,24 +73,24 @@ export class MarketOperationUtils {
...opts, ...opts,
}; };
const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]); const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]);
const [fillableAmounts, plpPoolAddress, ethToMakerAssetRate, dexQuotes] = await this._sampler.executeAsync( const [fillableAmounts, liquidityPoolAddress, ethToMakerAssetRate, dexQuotes] = await this._sampler.executeAsync(
DexOrderSampler.ops.getOrderFillableTakerAmounts(nativeOrders), DexOrderSampler.ops.getOrderFillableTakerAmounts(nativeOrders),
DexOrderSampler.ops.getLiquidityProviderFromRegistry(this._plpRegistryAddress, takerToken, makerToken), DexOrderSampler.ops.getLiquidityProviderFromRegistry(this._liquidityProviderRegistry, takerToken, makerToken),
makerToken.toLowerCase() === this._wethAddress.toLowerCase() makerToken.toLowerCase() === this._wethAddress.toLowerCase()
? DexOrderSampler.ops.constant(new BigNumber(1)) ? DexOrderSampler.ops.constant(new BigNumber(1))
: DexOrderSampler.ops.getMedianSellRate( : DexOrderSampler.ops.getMedianSellRate(
difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(this._plpSourceIfAvailable()), difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(this._liquidityPoolSourceIfAvailable()),
makerToken, makerToken,
this._wethAddress, this._wethAddress,
ONE_ETHER, ONE_ETHER,
this._plpRegistryAddress, this._liquidityProviderRegistry,
), ),
DexOrderSampler.ops.getSellQuotes( DexOrderSampler.ops.getSellQuotes(
difference(SELL_SOURCES, _opts.excludedSources).concat(this._plpSourceIfAvailable()), difference(SELL_SOURCES, _opts.excludedSources).concat(this._liquidityPoolSourceIfAvailable()),
makerToken, makerToken,
takerToken, takerToken,
getSampleAmounts(takerAmount, _opts.numSamples, _opts.sampleDistributionBase), getSampleAmounts(takerAmount, _opts.numSamples, _opts.sampleDistributionBase),
this._plpRegistryAddress, this._liquidityProviderRegistry,
), ),
); );
@ -135,7 +135,7 @@ export class MarketOperationUtils {
makerToken, makerToken,
collapsePath(optimalPath, false), collapsePath(optimalPath, false),
_opts.bridgeSlippage, _opts.bridgeSlippage,
plpPoolAddress, liquidityPoolAddress,
); );
} }
@ -160,24 +160,24 @@ export class MarketOperationUtils {
...opts, ...opts,
}; };
const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]); const [makerToken, takerToken] = getOrderTokens(nativeOrders[0]);
const [fillableAmounts, plpPoolAddress, ethToTakerAssetRate, dexQuotes] = await this._sampler.executeAsync( const [fillableAmounts, liquidityPoolAddress, ethToTakerAssetRate, dexQuotes] = await this._sampler.executeAsync(
DexOrderSampler.ops.getOrderFillableMakerAmounts(nativeOrders), DexOrderSampler.ops.getOrderFillableMakerAmounts(nativeOrders),
DexOrderSampler.ops.getLiquidityProviderFromRegistry(this._plpRegistryAddress, takerToken, makerToken), DexOrderSampler.ops.getLiquidityProviderFromRegistry(this._liquidityProviderRegistry, takerToken, makerToken),
takerToken.toLowerCase() === this._wethAddress.toLowerCase() takerToken.toLowerCase() === this._wethAddress.toLowerCase()
? DexOrderSampler.ops.constant(new BigNumber(1)) ? DexOrderSampler.ops.constant(new BigNumber(1))
: DexOrderSampler.ops.getMedianSellRate( : DexOrderSampler.ops.getMedianSellRate(
difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(this._plpSourceIfAvailable()), difference(FEE_QUOTE_SOURCES, _opts.excludedSources).concat(this._liquidityPoolSourceIfAvailable()),
takerToken, takerToken,
this._wethAddress, this._wethAddress,
ONE_ETHER, ONE_ETHER,
this._plpRegistryAddress, this._liquidityProviderRegistry,
), ),
DexOrderSampler.ops.getBuyQuotes( DexOrderSampler.ops.getBuyQuotes(
difference(BUY_SOURCES, _opts.excludedSources).concat(this._plpSourceIfAvailable()), difference(BUY_SOURCES, _opts.excludedSources).concat(this._liquidityPoolSourceIfAvailable()),
makerToken, makerToken,
takerToken, takerToken,
getSampleAmounts(makerAmount, _opts.numSamples, _opts.sampleDistributionBase), getSampleAmounts(makerAmount, _opts.numSamples, _opts.sampleDistributionBase),
this._plpRegistryAddress, this._liquidityProviderRegistry,
), ),
); );
const signedOrderWithFillableAmounts = this._createBuyOrdersPathFromSamplerResultIfExists( const signedOrderWithFillableAmounts = this._createBuyOrdersPathFromSamplerResultIfExists(
@ -187,7 +187,7 @@ export class MarketOperationUtils {
dexQuotes, dexQuotes,
ethToTakerAssetRate, ethToTakerAssetRate,
_opts, _opts,
plpPoolAddress, liquidityPoolAddress,
); );
if (!signedOrderWithFillableAmounts) { if (!signedOrderWithFillableAmounts) {
throw new Error(AggregationError.NoOptimalPath); throw new Error(AggregationError.NoOptimalPath);
@ -253,8 +253,8 @@ export class MarketOperationUtils {
); );
} }
private _plpSourceIfAvailable(): ERC20BridgeSource[] { private _liquidityPoolSourceIfAvailable(): ERC20BridgeSource[] {
return this._plpRegistryAddress !== NULL_ADDRESS ? [ERC20BridgeSource.Plp] : []; return this._liquidityProviderRegistry !== NULL_ADDRESS ? [ERC20BridgeSource.LiquidityProvider] : [];
} }
private _createBuyOrdersPathFromSamplerResultIfExists( private _createBuyOrdersPathFromSamplerResultIfExists(
@ -264,7 +264,7 @@ export class MarketOperationUtils {
dexQuotes: DexSample[][], dexQuotes: DexSample[][],
ethToTakerAssetRate: BigNumber, ethToTakerAssetRate: BigNumber,
opts: GetMarketOrdersOpts, opts: GetMarketOrdersOpts,
plpPoolAddress?: string | undefined, liquidityPoolAddress?: string | undefined,
): OptimizedMarketOrder[] | undefined { ): OptimizedMarketOrder[] | undefined {
const nativeOrdersWithFillableAmounts = createSignedOrdersWithFillableAmounts( const nativeOrdersWithFillableAmounts = createSignedOrdersWithFillableAmounts(
nativeOrders, nativeOrders,
@ -307,7 +307,7 @@ export class MarketOperationUtils {
outputToken, outputToken,
collapsePath(optimalPath, true), collapsePath(optimalPath, true),
opts.bridgeSlippage, opts.bridgeSlippage,
plpPoolAddress, liquidityPoolAddress,
); );
} }
} }
@ -489,8 +489,8 @@ function sourceToFillFlags(source: ERC20BridgeSource): number {
if (source === ERC20BridgeSource.Uniswap) { if (source === ERC20BridgeSource.Uniswap) {
return FillFlags.SourceUniswap; return FillFlags.SourceUniswap;
} }
if (source === ERC20BridgeSource.Plp) { if (source === ERC20BridgeSource.LiquidityProvider) {
return FillFlags.SourcePlp; return FillFlags.SourceLiquidityPool;
} }
return FillFlags.SourceNative; return FillFlags.SourceNative;
} }

View File

@ -75,8 +75,8 @@ const samplerOperations = {
}, },
}; };
}, },
getPLPSellQuotes( getLiquidityProviderSellQuotes(
plpRegistryAddress: string, liquidityProviderRegistryAddress: string,
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
takerFillAmounts: BigNumber[], takerFillAmounts: BigNumber[],
@ -85,7 +85,7 @@ const samplerOperations = {
encodeCall: contract => { encodeCall: contract => {
return contract return contract
.sampleSellsFromLiquidityProviderRegistry( .sampleSellsFromLiquidityProviderRegistry(
plpRegistryAddress, liquidityProviderRegistryAddress,
takerToken, takerToken,
makerToken, makerToken,
takerFillAmounts, takerFillAmounts,
@ -100,8 +100,8 @@ const samplerOperations = {
}, },
}; };
}, },
getPLPBuyQuotes( getLiquidityProviderBuyQuotes(
plpRegistryAddress: string, liquidityProviderRegistryAddress: string,
takerToken: string, takerToken: string,
makerToken: string, makerToken: string,
makerFillAmounts: BigNumber[], makerFillAmounts: BigNumber[],
@ -110,7 +110,7 @@ const samplerOperations = {
encodeCall: contract => { encodeCall: contract => {
return contract return contract
.sampleBuysFromLiquidityProviderRegistry( .sampleBuysFromLiquidityProviderRegistry(
plpRegistryAddress, liquidityProviderRegistryAddress,
takerToken, takerToken,
makerToken, makerToken,
makerFillAmounts, makerFillAmounts,
@ -200,14 +200,14 @@ const samplerOperations = {
makerToken: string, makerToken: string,
takerToken: string, takerToken: string,
takerFillAmount: BigNumber, takerFillAmount: BigNumber,
plpRegistryAddress?: string | undefined, liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<BigNumber> { ): BatchedOperation<BigNumber> {
const getSellQuotes = samplerOperations.getSellQuotes( const getSellQuotes = samplerOperations.getSellQuotes(
sources, sources,
makerToken, makerToken,
takerToken, takerToken,
[takerFillAmount], [takerFillAmount],
plpRegistryAddress, liquidityProviderRegistryAddress,
); );
return { return {
encodeCall: contract => { encodeCall: contract => {
@ -262,7 +262,7 @@ const samplerOperations = {
makerToken: string, makerToken: string,
takerToken: string, takerToken: string,
takerFillAmounts: BigNumber[], takerFillAmounts: BigNumber[],
plpRegistryAddress?: string | undefined, liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<DexSample[][]> { ): BatchedOperation<DexSample[][]> {
const subOps = sources const subOps = sources
.map(source => { .map(source => {
@ -289,14 +289,14 @@ const samplerOperations = {
takerFillAmounts, takerFillAmounts,
); );
} }
} else if (source === ERC20BridgeSource.Plp) { } else if (source === ERC20BridgeSource.LiquidityProvider) {
if (plpRegistryAddress === undefined) { if (liquidityProviderRegistryAddress === undefined) {
throw new Error( throw new Error(
'Cannot sample liquidity from a PLP liquidity pool, if a registry is not provided.', 'Cannot sample liquidity from a LiquidityProvider liquidity pool, if a registry is not provided.',
); );
} }
batchedOperation = samplerOperations.getPLPSellQuotes( batchedOperation = samplerOperations.getLiquidityProviderSellQuotes(
plpRegistryAddress, liquidityProviderRegistryAddress,
takerToken, takerToken,
makerToken, makerToken,
takerFillAmounts, takerFillAmounts,
@ -337,20 +337,20 @@ const samplerOperations = {
makerToken: string, makerToken: string,
takerToken: string, takerToken: string,
makerFillAmounts: BigNumber[], makerFillAmounts: BigNumber[],
plpRegistryAddress?: string | undefined, liquidityProviderRegistryAddress?: string | undefined,
): BatchedOperation<DexSample[][]> { ): BatchedOperation<DexSample[][]> {
const subOps = sources.map(source => { const subOps = sources.map(source => {
if (source === ERC20BridgeSource.Eth2Dai) { if (source === ERC20BridgeSource.Eth2Dai) {
return samplerOperations.getEth2DaiBuyQuotes(makerToken, takerToken, makerFillAmounts); return samplerOperations.getEth2DaiBuyQuotes(makerToken, takerToken, makerFillAmounts);
} else if (source === ERC20BridgeSource.Uniswap) { } else if (source === ERC20BridgeSource.Uniswap) {
return samplerOperations.getUniswapBuyQuotes(makerToken, takerToken, makerFillAmounts); return samplerOperations.getUniswapBuyQuotes(makerToken, takerToken, makerFillAmounts);
} else if (source === ERC20BridgeSource.Plp) { } else if (source === ERC20BridgeSource.LiquidityProvider) {
if (plpRegistryAddress === undefined) { if (liquidityProviderRegistryAddress === undefined) {
throw new Error( throw new Error(
'Cannot sample liquidity from a PLP liquidity pool, if a registry is not provided.', 'Cannot sample liquidity from a LiquidityProvider liquidity pool, if a registry is not provided.',
); );
} }
return samplerOperations.getPLPBuyQuotes(plpRegistryAddress, takerToken, makerToken, makerFillAmounts); return samplerOperations.getLiquidityProviderBuyQuotes(liquidityProviderRegistryAddress, takerToken, makerToken, makerFillAmounts);
} else { } else {
throw new Error(`Unsupported buy sample source: ${source}`); throw new Error(`Unsupported buy sample source: ${source}`);
} }

View File

@ -31,7 +31,7 @@ export enum ERC20BridgeSource {
CurveUsdcDai = 'Curve_USDC_DAI', CurveUsdcDai = 'Curve_USDC_DAI',
CurveUsdcDaiUsdt = 'Curve_USDC_DAI_USDT', CurveUsdcDaiUsdt = 'Curve_USDC_DAI_USDT',
CurveUsdcDaiUsdtTusd = 'Curve_USDC_DAI_USDT_TUSD', CurveUsdcDaiUsdtTusd = 'Curve_USDC_DAI_USDT_TUSD',
Plp = 'PLP', LiquidityProvider = 'LiquidityProvider',
} }
// Internal `fillData` field for `Fill` objects. // Internal `fillData` field for `Fill` objects.
@ -61,7 +61,7 @@ export enum FillFlags {
SourceUniswap = 0x2, SourceUniswap = 0x2,
SourceEth2Dai = 0x4, SourceEth2Dai = 0x4,
SourceKyber = 0x8, SourceKyber = 0x8,
SourcePlp = 0x10, SourceLiquidityPool = 0x10,
} }
/** /**

View File

@ -342,7 +342,7 @@ describe('DexSampler tests', () => {
expect(quotes).to.deep.eq(expectedQuotes); expect(quotes).to.deep.eq(expectedQuotes);
}); });
describe('PLP Operations', () => { describe('LiquidityProvider Operations', () => {
const xAsset = randomAddress(); const xAsset = randomAddress();
const yAsset = randomAddress(); const yAsset = randomAddress();
const zAsset = randomAddress(); const zAsset = randomAddress();
@ -392,7 +392,7 @@ describe('DexSampler tests', () => {
expect(yzPool).to.eql(NULL_ADDRESS); expect(yzPool).to.eql(NULL_ADDRESS);
expect(nullPool).to.eql(NULL_ADDRESS); expect(nullPool).to.eql(NULL_ADDRESS);
}); });
it('is able to sample DEX liquidity from PLP', async () => { it('is able to sample DEX liquidity from LiquidityProvider', async () => {
const fakeLiquidityPool = await DummyLiquidityProviderContract.deployFrom0xArtifactAsync( const fakeLiquidityPool = await DummyLiquidityProviderContract.deployFrom0xArtifactAsync(
erc20BridgeSamplerArtifacts.DummyLiquidityProvider, erc20BridgeSamplerArtifacts.DummyLiquidityProvider,
provider, provider,
@ -408,14 +408,14 @@ describe('DexSampler tests', () => {
); );
const [buyQuotes, sellQuotes] = await dexOrderSampler.executeBatchAsync([ const [buyQuotes, sellQuotes] = await dexOrderSampler.executeBatchAsync([
DexOrderSampler.ops.getBuyQuotes( DexOrderSampler.ops.getBuyQuotes(
[ERC20BridgeSource.Plp], [ERC20BridgeSource.LiquidityProvider],
xAsset, xAsset,
yAsset, yAsset,
[new BigNumber(10), new BigNumber(100)], [new BigNumber(10), new BigNumber(100)],
registryContract.address, registryContract.address,
), ),
DexOrderSampler.ops.getSellQuotes( DexOrderSampler.ops.getSellQuotes(
[ERC20BridgeSource.Plp], [ERC20BridgeSource.LiquidityProvider],
xAsset, xAsset,
yAsset, yAsset,
[new BigNumber(10), new BigNumber(100), new BigNumber(500)], [new BigNumber(10), new BigNumber(100), new BigNumber(500)],
@ -423,18 +423,18 @@ describe('DexSampler tests', () => {
), ),
]); ]);
expect(buyQuotes.length).to.eql(1); expect(buyQuotes.length).to.eql(1);
const plpBuyQuotes: DexSample[] = buyQuotes[0]; const liquidityPoolBuyQuotes: DexSample[] = buyQuotes[0];
expect(plpBuyQuotes.length).to.eql(2); expect(liquidityPoolBuyQuotes.length).to.eql(2);
for (const quote of plpBuyQuotes) { for (const quote of liquidityPoolBuyQuotes) {
expect(quote.source).to.bignumber.eql(ERC20BridgeSource.Plp); expect(quote.source).to.bignumber.eql(ERC20BridgeSource.LiquidityProvider);
expect(quote.input.plus(1)).to.bignumber.eql(quote.output); expect(quote.input.plus(1)).to.bignumber.eql(quote.output);
} }
expect(sellQuotes.length).to.eql(1); expect(sellQuotes.length).to.eql(1);
const plpSellQuotes: DexSample[] = sellQuotes[0]; const iquidityPoolSellQuotes: DexSample[] = sellQuotes[0];
expect(plpSellQuotes.length).to.eql(3); expect(iquidityPoolSellQuotes.length).to.eql(3);
for (const quote of plpSellQuotes) { for (const quote of iquidityPoolSellQuotes) {
expect(quote.source).to.bignumber.eql(ERC20BridgeSource.Plp); expect(quote.source).to.bignumber.eql(ERC20BridgeSource.LiquidityProvider);
expect(quote.input.minus(1)).to.bignumber.eql(quote.output); expect(quote.input.minus(1)).to.bignumber.eql(quote.output);
} }
}); });

View File

@ -141,7 +141,7 @@ describe('MarketOperationUtils tests', () => {
makerToken: string, makerToken: string,
takerToken: string, takerToken: string,
fillAmounts: BigNumber[], fillAmounts: BigNumber[],
plpRegistryAddress?: string | undefined, liquidityProviderAddress?: string | undefined,
) => DexSample[][]; ) => DexSample[][];
function createGetMultipleSellQuotesOperationFromRates(rates: RatesBySource): GetMultipleQuotesOperation { function createGetMultipleSellQuotesOperationFromRates(rates: RatesBySource): GetMultipleQuotesOperation {
@ -156,26 +156,26 @@ describe('MarketOperationUtils tests', () => {
}; };
} }
function callTradeOperationAndRetainPLPParams( function callTradeOperationAndRetainLiquidityProviderParams(
tradeOperation: (rates: RatesBySource) => GetMultipleQuotesOperation, tradeOperation: (rates: RatesBySource) => GetMultipleQuotesOperation,
rates: RatesBySource, rates: RatesBySource,
): [{ sources: ERC20BridgeSource[]; plpRegistryAddress?: string }, GetMultipleQuotesOperation] { ): [{ sources: ERC20BridgeSource[]; liquidityProviderAddress?: string }, GetMultipleQuotesOperation] {
const plpParams: { sources: ERC20BridgeSource[]; plpRegistryAddress?: string } = { const liquidityPoolParams: { sources: ERC20BridgeSource[]; liquidityProviderAddress?: string } = {
sources: [], sources: [],
plpRegistryAddress: undefined, liquidityProviderAddress: undefined,
}; };
const fn = ( const fn = (
sources: ERC20BridgeSource[], sources: ERC20BridgeSource[],
makerToken: string, makerToken: string,
takerToken: string, takerToken: string,
fillAmounts: BigNumber[], fillAmounts: BigNumber[],
plpRegistryAddress: string | undefined, liquidityProviderAddress: string | undefined,
) => { ) => {
plpParams.plpRegistryAddress = plpRegistryAddress; liquidityPoolParams.liquidityProviderAddress = liquidityProviderAddress;
plpParams.sources = sources; liquidityPoolParams.sources = sources;
return tradeOperation(rates)(sources, makerToken, takerToken, fillAmounts, plpRegistryAddress); return tradeOperation(rates)(sources, makerToken, takerToken, fillAmounts, liquidityProviderAddress);
}; };
return [plpParams, fn]; return [liquidityPoolParams, fn];
} }
function createGetMultipleBuyQuotesOperationFromRates(rates: RatesBySource): GetMultipleQuotesOperation { function createGetMultipleBuyQuotesOperationFromRates(rates: RatesBySource): GetMultipleQuotesOperation {
@ -195,7 +195,7 @@ describe('MarketOperationUtils tests', () => {
makerToken: string, makerToken: string,
takerToken: string, takerToken: string,
fillAmounts: BigNumber[], fillAmounts: BigNumber[],
plpRegistryAddress?: string | undefined, liquidityProviderAddress?: string | undefined,
) => BigNumber; ) => BigNumber;
type GetLiquidityProviderFromRegistryOperation = ( type GetLiquidityProviderFromRegistryOperation = (
@ -260,7 +260,7 @@ describe('MarketOperationUtils tests', () => {
[ERC20BridgeSource.CurveUsdcDai]: _.times(NUM_SAMPLES, () => 0), [ERC20BridgeSource.CurveUsdcDai]: _.times(NUM_SAMPLES, () => 0),
[ERC20BridgeSource.CurveUsdcDaiUsdt]: _.times(NUM_SAMPLES, () => 0), [ERC20BridgeSource.CurveUsdcDaiUsdt]: _.times(NUM_SAMPLES, () => 0),
[ERC20BridgeSource.CurveUsdcDaiUsdtTusd]: _.times(NUM_SAMPLES, () => 0), [ERC20BridgeSource.CurveUsdcDaiUsdtTusd]: _.times(NUM_SAMPLES, () => 0),
[ERC20BridgeSource.Plp]: _.times(NUM_SAMPLES, () => 0), [ERC20BridgeSource.LiquidityProvider]: _.times(NUM_SAMPLES, () => 0),
}; };
function findSourceWithMaxOutput(rates: RatesBySource): ERC20BridgeSource { function findSourceWithMaxOutput(rates: RatesBySource): ERC20BridgeSource {
@ -375,7 +375,7 @@ describe('MarketOperationUtils tests', () => {
}); });
it('polls the liquidity provider when the registry is provided in the arguments', async () => { it('polls the liquidity provider when the registry is provided in the arguments', async () => {
const [args, fn] = callTradeOperationAndRetainPLPParams( const [args, fn] = callTradeOperationAndRetainLiquidityProviderParams(
createGetMultipleSellQuotesOperationFromRates, createGetMultipleSellQuotesOperationFromRates,
DEFAULT_RATES, DEFAULT_RATES,
); );
@ -393,8 +393,8 @@ describe('MarketOperationUtils tests', () => {
...DEFAULT_OPTS, ...DEFAULT_OPTS,
excludedSources: [], excludedSources: [],
}); });
expect(args.sources.sort()).to.deep.eq(SELL_SOURCES.concat([ERC20BridgeSource.Plp]).sort()); expect(args.sources.sort()).to.deep.eq(SELL_SOURCES.concat([ERC20BridgeSource.LiquidityProvider]).sort());
expect(args.plpRegistryAddress).to.eql(registryAddress); expect(args.liquidityProviderAddress).to.eql(registryAddress);
}); });
it('does not poll DEXes in `excludedSources`', async () => { it('does not poll DEXes in `excludedSources`', async () => {
@ -669,7 +669,7 @@ describe('MarketOperationUtils tests', () => {
}); });
it('polls the liquidity provider when the registry is provided in the arguments', async () => { it('polls the liquidity provider when the registry is provided in the arguments', async () => {
const [args, fn] = callTradeOperationAndRetainPLPParams( const [args, fn] = callTradeOperationAndRetainLiquidityProviderParams(
createGetMultipleBuyQuotesOperationFromRates, createGetMultipleBuyQuotesOperationFromRates,
DEFAULT_RATES, DEFAULT_RATES,
); );
@ -687,8 +687,8 @@ describe('MarketOperationUtils tests', () => {
...DEFAULT_OPTS, ...DEFAULT_OPTS,
excludedSources: [], excludedSources: [],
}); });
expect(args.sources.sort()).to.deep.eq(BUY_SOURCES.concat([ERC20BridgeSource.Plp]).sort()); expect(args.sources.sort()).to.deep.eq(BUY_SOURCES.concat([ERC20BridgeSource.LiquidityProvider]).sort());
expect(args.plpRegistryAddress).to.eql(registryAddress); expect(args.liquidityProviderAddress).to.eql(registryAddress);
}); });
it('does not poll DEXes in `excludedSources`', async () => { it('does not poll DEXes in `excludedSources`', async () => {
@ -871,17 +871,17 @@ describe('MarketOperationUtils tests', () => {
expect(orderSources).to.deep.eq(expectedSources); expect(orderSources).to.deep.eq(expectedSources);
}); });
it('is able to create a order from PLP', async () => { it('is able to create a order from LiquidityProvider', async () => {
const registryAddress = randomAddress(); const registryAddress = randomAddress();
const liquidityPoolAddress = randomAddress(); const liquidityPoolAddress = randomAddress();
const xAsset = randomAddress(); const xAsset = randomAddress();
const yAsset = randomAddress(); const yAsset = randomAddress();
const toSell = Web3Wrapper.toBaseUnitAmount(10, 18); const toSell = Web3Wrapper.toBaseUnitAmount(10, 18);
const [getSellQuiotesParams, getSellQuotesFn] = callTradeOperationAndRetainPLPParams( const [getSellQuiotesParams, getSellQuotesFn] = callTradeOperationAndRetainLiquidityProviderParams(
createGetMultipleSellQuotesOperationFromRates, createGetMultipleSellQuotesOperationFromRates,
{ {
[ERC20BridgeSource.Plp]: createDecreasingRates(5), [ERC20BridgeSource.LiquidityProvider]: createDecreasingRates(5),
}, },
); );
const [ const [
@ -920,8 +920,8 @@ describe('MarketOperationUtils tests', () => {
expect(decodedAssetData.assetProxyId).to.eql(AssetProxyId.ERC20Bridge); expect(decodedAssetData.assetProxyId).to.eql(AssetProxyId.ERC20Bridge);
expect(decodedAssetData.bridgeAddress).to.eql(liquidityPoolAddress); expect(decodedAssetData.bridgeAddress).to.eql(liquidityPoolAddress);
expect(result[0].takerAssetAmount).to.bignumber.eql(toSell); expect(result[0].takerAssetAmount).to.bignumber.eql(toSell);
expect(getSellQuiotesParams.sources).contains(ERC20BridgeSource.Plp); expect(getSellQuiotesParams.sources).contains(ERC20BridgeSource.LiquidityProvider);
expect(getSellQuiotesParams.plpRegistryAddress).is.eql(registryAddress); expect(getSellQuiotesParams.liquidityProviderAddress).is.eql(registryAddress);
expect(getLiquidityProviderParams.registryAddress).is.eql(registryAddress); expect(getLiquidityProviderParams.registryAddress).is.eql(registryAddress);
expect(getLiquidityProviderParams.makerToken).is.eql(xAsset); expect(getLiquidityProviderParams.makerToken).is.eql(xAsset);
expect(getLiquidityProviderParams.takerToken).is.eql(yAsset); expect(getLiquidityProviderParams.takerToken).is.eql(yAsset);