Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Pull auction params from client #423

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/config/ChainConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type IntentOverrides = {
};

export type DutchOverrides = IntentOverrides & {
skipRFQ?: boolean;
forceOpenOrders?: boolean;
codyborn marked this conversation as resolved.
Show resolved Hide resolved
priceImprovementBps?: number;
};

Expand Down Expand Up @@ -76,6 +76,9 @@ export abstract class ChainConfigManager {
[ChainId.ARBITRUM_ONE]: {
routingTypes: {
[RoutingType.CLASSIC]: {},
[RoutingType.DUTCH_V2]: {
deadlineBufferSecs: 60
},
},
alarmEnabled: true,
},
Expand Down
11 changes: 8 additions & 3 deletions lib/entities/context/DutchQuoteContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class DutchQuoteContext implements QuoteContext {
}

const quoteConfig = ChainConfigManager.getQuoteConfig(quote.chainId, this.request.routingType);
if (quoteConfig.skipRFQ) {
if (quoteConfig.forceOpenOrders || this.request.config.forceOpenOrders) {
this.log.info('RFQ Orders are disabled in config');
return null;
}
Expand Down Expand Up @@ -202,8 +202,13 @@ export class DutchQuoteContext implements QuoteContext {
const chainId = classicQuote.request.info.tokenInChainId;
const quoteConfig = ChainConfigManager.getQuoteConfig(chainId, this.request.routingType);
// if the useSyntheticQuotes override is not set by client or server and we're not skipping RFQ, return null
// if we are skipping RFQ, we need a synthetic quote
if (!this.request.config.useSyntheticQuotes && !syntheticStatus.syntheticEnabled && !quoteConfig.skipRFQ) {
// if we are forcing Open Orders, we need a synthetic quote
if (
codyborn marked this conversation as resolved.
Show resolved Hide resolved
!this.request.config.useSyntheticQuotes &&
!this.request.config.forceOpenOrders &&
!syntheticStatus.syntheticEnabled &&
!quoteConfig.forceOpenOrders
) {
this.log.info('Synthetic not enabled, skipping synthetic');
return null;
}
Expand Down
7 changes: 2 additions & 5 deletions lib/entities/quote/DutchQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export abstract class DutchQuote<T extends DutchQuoteRequest> implements IQuote
public readonly createdAt: string;
public derived: DutchQuoteDerived;
public routingType: RoutingType.DUTCH_LIMIT | RoutingType.DUTCH_V2;
public abstract readonly defaultDeadlienBufferInSecs: number;
public abstract readonly defaultDeadlineBufferInSecs: number;
Copy link
Member

@ConjunctiveNormalForm ConjunctiveNormalForm May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't quoteConfig cover all chains and routingTypes, so that this is no longer needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quoteConfig doesn't have a default value; it currently acts as an override.

// Add 1bps price improvmement to favor Dutch
public static defaultPriceImprovementBps = 1;

Expand Down Expand Up @@ -166,11 +166,8 @@ export abstract class DutchQuote<T extends DutchQuoteRequest> implements IQuote

// The number of seconds from endTime that the order should expire
public get deadlineBufferSecs(): number {
if (this.request.config.deadlineBufferSecs !== undefined) {
return this.request.config.deadlineBufferSecs;
}
const quoteConfig = ChainConfigManager.getQuoteConfig(this.chainId, this.request.routingType);
return quoteConfig.deadlineBufferSecs ?? this.defaultDeadlienBufferInSecs;
return this.request.config.deadlineBufferSecs ?? quoteConfig.deadlineBufferSecs ?? this.defaultDeadlineBufferInSecs;
}

public get portionAmountOutStart(): BigNumber {
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/quote/DutchQuoteFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class DutchQuoteFactory {
const priceImprovedStartAmounts = DutchQuote.applyPriceImprovement(
{ amountIn: quote.amountInGasAdjusted, amountOut: quote.amountOutGasAdjusted },
request.info.type,
quoteConfig.priceImprovementBps
request.config.priceImprovementBps ?? quoteConfig.priceImprovementBps
);
const startAmounts = DutchQuote.applyPreSwapGasAdjustment(priceImprovedStartAmounts, quote);

Expand Down
2 changes: 1 addition & 1 deletion lib/entities/quote/DutchV1Quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { generateRandomNonce } from '../../util/nonce';

export class DutchV1Quote extends DutchQuote<DutchV1Request> implements IQuote {
public routingType: RoutingType.DUTCH_LIMIT = RoutingType.DUTCH_LIMIT;
public readonly defaultDeadlienBufferInSecs: number = DEFAULT_DEADLINE_BUFFER_SECS;
public readonly defaultDeadlineBufferInSecs: number = DEFAULT_DEADLINE_BUFFER_SECS;

public toJSON(): DutchQuoteDataJSON {
return {
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/quote/DutchV2Quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type DutchV2QuoteDataJSON = SharedOrderQuoteDataJSON & {

export class DutchV2Quote extends DutchQuote<DutchV2Request> implements IQuote {
public readonly routingType: RoutingType.DUTCH_V2 = RoutingType.DUTCH_V2;
public readonly defaultDeadlienBufferInSecs: number = DEFAULT_V2_DEADLINE_BUFFER_SECS;
public readonly defaultDeadlineBufferInSecs: number = DEFAULT_V2_DEADLINE_BUFFER_SECS;

public toJSON(): DutchV2QuoteDataJSON {
return {
Expand Down
8 changes: 8 additions & 0 deletions lib/entities/request/DutchV1Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export interface DutchConfig {
startTimeBufferSecs?: number;
auctionPeriodSecs?: number;
deadlineBufferSecs?: number;
// Setting true will include an Open Order in the quote comparison
useSyntheticQuotes: boolean;
gasAdjustmentBps?: number;
// Setting true will force an Open Order and skip RFQ
forceOpenOrders?: boolean;
priceImprovementBps?: number;
}

export interface DutchQuoteRequestInfo extends QuoteRequestInfo {
Expand All @@ -32,6 +36,8 @@ export interface DutchConfigJSON {
deadlineBufferSecs?: number;
useSyntheticQuotes?: boolean;
gasAdjustmentBps?: number;
forceOpenOrders?: boolean;
priceImprovementBps?: number;
}

export class DutchV1Request implements QuoteRequest {
Expand All @@ -52,6 +58,8 @@ export class DutchV1Request implements QuoteRequest {
deadlineBufferSecs: body.deadlineBufferSecs,
useSyntheticQuotes: body.useSyntheticQuotes ?? false,
gasAdjustmentBps: body.gasAdjustmentBps,
forceOpenOrders: body.forceOpenOrders,
priceImprovementBps: body.priceImprovementBps,
}
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/entities/request/DutchV2Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { DutchQuoteRequestInfo } from './DutchV1Request';
export interface DutchV2Config {
swapper: string;
deadlineBufferSecs?: number;
// Setting true will include an Open Order in the quote comparison
useSyntheticQuotes: boolean;
gasAdjustmentBps?: number;
// Setting true will force an Open Order and skip RFQ
forceOpenOrders?: boolean;
priceImprovementBps?: number;
}

export interface DutchV2ConfigJSON extends Omit<DutchV2Config, 'useSyntheticQuotes'> {
Expand All @@ -30,6 +34,8 @@ export class DutchV2Request implements QuoteRequest {
deadlineBufferSecs: body.deadlineBufferSecs,
useSyntheticQuotes: body.useSyntheticQuotes ?? false,
gasAdjustmentBps: body.gasAdjustmentBps,
forceOpenOrders: body.forceOpenOrders,
priceImprovementBps: body.priceImprovementBps,
}
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/providers/quoters/RfqQuoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ID_TO_CHAIN_ID, WRAPPED_NATIVE_CURRENCY } from '@uniswap/smart-order-ro
import { BigNumber } from 'ethers';
import axios from './helpers';

import { ChainConfigManager } from '../../config/ChainConfigManager';
import { BPS, frontendAndUraEnablePortion, NATIVE_ADDRESS, RoutingType } from '../../constants';
import { DutchQuoteRequest, Quote } from '../../entities';
import { DutchQuoteFactory } from '../../entities/quote/DutchQuoteFactory';
Expand All @@ -19,6 +20,11 @@ export class RfqQuoter implements Quoter {
constructor(private rfqUrl: string, private serviceUrl: string, private paramApiKey: string) {}

async quote(request: DutchQuoteRequest): Promise<Quote | null> {
// Skip RFQ for forced Open Orders
const quoteConfig = ChainConfigManager.getQuoteConfig(request.info.tokenInChainId, request.routingType);
if (quoteConfig.forceOpenOrders || request.config.forceOpenOrders) {
return null;
}
const swapper = request.config.swapper;
const now = Date.now();
const portionEnabled = frontendAndUraEnablePortion(request.info.sendPortionEnabled);
Expand Down
4 changes: 4 additions & 0 deletions lib/util/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export class FieldValidator {
deadlineBufferSecs: FieldValidator.positiveNumber.optional(),
useSyntheticQuotes: Joi.boolean().optional(),
gasAdjustmentBps: FieldValidator.bps.optional(),
forceOpenOrders: Joi.boolean().optional(),
priceImprovementBps: FieldValidator.bps.optional(),
});

// extends a classic request config, but requires a gasToken and has optional parameters for the fee auction
Expand All @@ -131,5 +133,7 @@ export class FieldValidator {
deadlineBufferSecs: FieldValidator.positiveNumber.optional(),
useSyntheticQuotes: Joi.boolean().optional(),
gasAdjustmentBps: FieldValidator.bps.optional(),
forceOpenOrders: Joi.boolean().optional(),
priceImprovementBps: FieldValidator.bps.optional(),
});
}
9 changes: 1 addition & 8 deletions test/integ/base.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { ZERO } from '@uniswap/router-sdk';
import { Currency, CurrencyAmount, Fraction, Percent } from '@uniswap/sdk-core';
import {
DAI_MAINNET,
parseAmount,
USDC_MAINNET,
USDT_MAINNET,
WBTC_MAINNET,
WETH9,
} from '@uniswap/smart-order-router';
import { DAI_MAINNET, parseAmount, USDC_MAINNET, USDT_MAINNET, WBTC_MAINNET, WETH9 } from '@uniswap/smart-order-router';
import { fail } from 'assert';
import axiosStatic, { AxiosRequestConfig, AxiosResponse } from 'axios';
import axiosRetry from 'axios-retry';
Expand Down
4 changes: 2 additions & 2 deletions test/integ/quote-relay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe.skip('relayQuote', function () {
expect(order.info.universalRouterCalldata).to.not.be.undefined;
});

it('missing gasToken in request config' , async () => {
it('missing gasToken in request config', async () => {
const quoteReq: QuoteRequestBodyJSON = {
requestId: 'id',
tokenIn: USDC_MAINNET.address,
Expand All @@ -140,7 +140,7 @@ describe.skip('relayQuote', function () {
errorCode: 'VALIDATION_ERROR',
},
});
})
});
});
});
}
Expand Down
Loading
Loading