fix: [asset-swapper] excludedFeeSources. DODO Trade Allowed (#2731)

* fix: Fee sources and Ganache existence

* Added excludedFeeSources

* Comments and CHANGELOG

* fix: DODO Trade Allowed (#2732)
This commit is contained in:
Jacob Evans 2020-10-16 10:01:12 +10:00 committed by GitHub
parent fb21ca5404
commit c4ead689a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 5 deletions

View File

@ -157,6 +157,14 @@
{
"note": "Fix for some edge cases with `includedSources` and `MultiHop`",
"pr": 2730
},
{
"note": "Introduced `excludedFeeSources` to disable sources when determining the price of an asset in ETH",
"pr": 2731
},
{
"note": "Support DODO Trade Allowed parameter to automatically disable the pool",
"pr": 2732
}
]
},

View File

@ -34,6 +34,7 @@ interface IDODOHelper {
interface IDODO {
function querySellBaseToken(uint256 amount) external view returns (uint256);
function _TRADE_ALLOWED_() external view returns (bool);
}
contract DODOSampler is
@ -80,6 +81,11 @@ contract DODOSampler is
sellBase = false;
}
// DODO Pool has been disabled
if (!IDODO(pool)._TRADE_ALLOWED_()) {
return (sellBase, pool, makerTokenAmounts);
}
for (uint256 i = 0; i < numSamples; i++) {
uint256 buyAmount = _sampleSellForApproximateBuyFromDODO(
abi.encode(takerToken, pool, baseToken), // taker token data
@ -132,6 +138,11 @@ contract DODOSampler is
sellBase = false;
}
// DODO Pool has been disabled
if (!IDODO(pool)._TRADE_ALLOWED_()) {
return (sellBase, pool, takerTokenAmounts);
}
takerTokenAmounts = _sampleApproximateBuys(
ApproximateBuyQuoteOpts({
makerTokenData: abi.encode(makerToken, pool, baseToken),

View File

@ -55,6 +55,7 @@ export const DEFAULT_GET_MARKET_ORDERS_OPTS: GetMarketOrdersOpts = {
// tslint:disable-next-line: custom-no-magic-numbers
runLimit: 2 ** 15,
excludedSources: [],
excludedFeeSources: [],
includedSources: [],
bridgeSlippage: 0.005,
maxFallbackSlippage: 0.05,

View File

@ -137,12 +137,12 @@ export class MarketOperationUtils {
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]);
const sampleAmounts = getSampleAmounts(takerAmount, _opts.numSamples, _opts.sampleDistributionBase);
const requestFilters = new SourceFilters().exclude(_opts.excludedSources).include(_opts.includedSources);
// We don't exclude from the fee sources as we always want to be able to get a price
// of taker to Eth or maker to Eth, especially for MultiHop
const feeSourceFilters = this._feeSources;
const quoteSourceFilters = this._sellSources.merge(requestFilters);
const feeSourceFilters = this._feeSources.exclude(_opts.excludedFeeSources);
const {
onChain: sampleBalancerOnChain,
offChain: sampleBalancerOffChain,
@ -255,10 +255,12 @@ export class MarketOperationUtils {
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]);
const sampleAmounts = getSampleAmounts(makerAmount, _opts.numSamples, _opts.sampleDistributionBase);
const requestFilters = new SourceFilters().exclude(_opts.excludedSources).include(_opts.includedSources);
const feeSourceFilters = this._feeSources.merge(requestFilters);
const quoteSourceFilters = this._buySources.merge(requestFilters);
const feeSourceFilters = this._feeSources.exclude(_opts.excludedFeeSources);
const {
onChain: sampleBalancerOnChain,
offChain: sampleBalancerOffChain,
@ -444,9 +446,10 @@ export class MarketOperationUtils {
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const requestFilters = new SourceFilters().exclude(_opts.excludedSources).include(_opts.includedSources);
const feeSourceFilters = this._feeSources.merge(requestFilters);
const quoteSourceFilters = this._buySources.merge(requestFilters);
const feeSourceFilters = this._feeSources.exclude(_opts.excludedFeeSources);
const ops = [
...batchNativeOrders.map(orders =>
this._sampler.getOrderFillableMakerAmounts(orders, this.contractAddresses.exchange),

View File

@ -241,6 +241,11 @@ export interface GetMarketOrdersOpts {
* Liquidity sources to exclude. Default is none.
*/
excludedSources: ERC20BridgeSource[];
/**
* Liquidity sources to exclude when used to calculate the cost of the route.
* Default is none.
*/
excludedFeeSources: ERC20BridgeSource[];
/**
* Liquidity sources to include. Default is none, which allows all supported
* sources that aren't excluded by `excludedSources`.