Skip to content

Commit 6da30a7

Browse files
authored
feat: increase sampler granularity [LIT-843] (0xProject#1283)
* increasing sampler granularity to 40 * updating native orders to use 40 sample granularity * replacing magic numbers with constant
1 parent 2f0ab5a commit 6da30a7

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/asset-swapper/utils/market_operation_utils/constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,17 +2197,18 @@ const DEFAULT_FEE_SCHEDULE: FeeSchedule = Object.keys(DEFAULT_GAS_SCHEDULE).redu
21972197
return acc;
21982198
}, {} as FeeSchedule);
21992199

2200+
const numSamples = 40;
22002201
export const DEFAULT_GET_MARKET_ORDERS_OPTS: Omit<GetMarketOrdersOpts, 'gasPrice'> = {
22012202
excludedSources: [],
22022203
includedSources: [],
22032204
bridgeSlippage: 0.005,
2204-
numSamples: 13,
2205+
numSamples: numSamples,
22052206
sampleDistributionBase: 1,
22062207
feeSchedule: DEFAULT_FEE_SCHEDULE,
22072208
exchangeProxyOverhead: () => ZERO_AMOUNT,
22082209
shouldGenerateQuoteReport: true,
22092210
tokenAdjacencyGraph: TokenAdjacencyGraph.getEmptyGraph(),
2210-
neonRouterNumSamples: 14,
2211+
neonRouterNumSamples: numSamples + 1,
22112212
fillAdjustor: new IdentityFillAdjustor(),
22122213
endpoint: 'price',
22132214
};

src/asset-swapper/utils/market_operation_utils/path_optimizer.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,22 @@ export class PathOptimizer {
262262
}
263263
const fee = this.calculateOutputFee(nativeOrder).integerValue().toNumber();
264264

265-
// HACK: due to an issue with the Rust router interpolation we need to create exactly 13 samples from the native order
265+
// HACK: due to an issue with the Rust router interpolation we need to create exactly 40 samples from the native order
266266
const ids = [];
267267
const inputs = [];
268268
const outputs = [];
269269
const outputFees = [];
270270

271271
// NOTE: Limit orders can be both larger or smaller than the input amount
272272
// If the order is larger than the input we can scale the order to the size of
273-
// the quote input (order pricing is constant) and then create 13 "samples" up to
273+
// the quote input (order pricing is constant) and then create 40 "samples" up to
274274
// and including the full quote input amount.
275275
// If the order is smaller we don't need to scale anything, we will just end up
276276
// with trailing duplicate samples for the order input as we cannot go higher
277277
const scaleToInput = BigNumber.min(this.inputAmount.dividedBy(normalizedOrderInput), 1);
278278

279-
// TODO: replace constant with a proper sample size.
280-
for (let i = 1; i <= 13; i++) {
281-
const fraction = i / 13;
279+
for (let i = 1; i < this.neonRouterNumSamples; i++) {
280+
const fraction = i / (this.neonRouterNumSamples - 1);
282281
const currentInput = BigNumber.min(
283282
normalizedOrderInput.times(scaleToInput).times(fraction),
284283
normalizedOrderInput,

src/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ const EXCHANGE_PROXY_OVERHEAD_FULLY_FEATURED = (sourceFlags: bigint) => {
7777
}
7878
};
7979

80-
const NEON_ROUTER_NUM_SAMPLES = 14;
80+
const NUM_SAMPLES = 40;
8181
// TODO(kimpers): Due to an issue with the Rust router we want to use equidistant samples when using the Rust router
8282

8383
export const ASSET_SWAPPER_MARKET_ORDERS_OPTS: Partial<SwapQuoteRequestOpts> = {
8484
bridgeSlippage: DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE,
85-
numSamples: 13,
85+
numSamples: NUM_SAMPLES,
8686
sampleDistributionBase: SAMPLE_DISTRIBUTION_BASE,
87-
neonRouterNumSamples: NEON_ROUTER_NUM_SAMPLES,
87+
neonRouterNumSamples: NUM_SAMPLES + 1,
8888
exchangeProxyOverhead: EXCHANGE_PROXY_OVERHEAD_FULLY_FEATURED,
8989
shouldGenerateQuoteReport: true,
9090
};

0 commit comments

Comments
 (0)