Skip to content

Commit

Permalink
feat: set decayStartBlock to current block number + buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Nov 25, 2024
1 parent 3d4cdb5 commit c364984
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export const POST_ORDER_ERROR_REASON = {

export const WEBHOOK_TIMEOUT_MS = 500;
export const NOTIFICATION_TIMEOUT_MS = 10;
export const V3_BLOCK_BUFFER = 4;
20 changes: 13 additions & 7 deletions lib/handlers/hard-quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { BigNumber, ethers } from 'ethers';
import Joi from 'joi';

import { POST_ORDER_ERROR_REASON } from '../../constants';
import { POST_ORDER_ERROR_REASON, V3_BLOCK_BUFFER } from '../../constants';
import { HardQuoteRequest, Metric, QuoteResponse } from '../../entities';
import { V2HardQuoteResponse } from '../../entities/V2HardQuoteResponse';
import { V3HardQuoteResponse } from '../../entities/V3HardQuoteResponse';
Expand Down Expand Up @@ -48,7 +48,7 @@ export class QuoteHandler extends APIGLambdaHandler<
): Promise<ErrorResponse | Response<HardQuoteResponseData>> {
const {
requestInjected: { log, metric },
containerInjected: { quoters, orderServiceProvider },
containerInjected: { quoters, orderServiceProvider, provider },
requestBody,
} = params;
const start = Date.now();
Expand Down Expand Up @@ -109,7 +109,7 @@ export class QuoteHandler extends APIGLambdaHandler<
cosignerData = getCosignerData(request, bestQuote, orderType);
log.info({ bestQuote: bestQuote }, 'bestQuote');
} else {
cosignerData = getDefaultCosignerData(request, orderType);
cosignerData = await getDefaultCosignerData(request, orderType, provider);
log.info({ cosignerData: cosignerData }, 'open order with default cosignerData');
}

Expand Down Expand Up @@ -221,12 +221,16 @@ export function getCosignerData(
throw new Error('Unsupported order type');
}
}
export function getDefaultCosignerData(request: HardQuoteRequest, orderType: OrderType): CosignerData | V3CosignerData {
export async function getDefaultCosignerData(
request: HardQuoteRequest,
orderType: OrderType,
provider: ethers.providers.Provider
): Promise<CosignerData | V3CosignerData> {
switch (orderType) {
case OrderType.Dutch_V2:
return getDefaultV2CosignerData(request);
case OrderType.Dutch_V3:
return getDefaultV3CosignerData(request);
return await getDefaultV3CosignerData(request, provider);
default:
throw new Error('Unsupported order type');
}
Expand Down Expand Up @@ -306,9 +310,11 @@ function getDefaultV2CosignerData(request: HardQuoteRequest): CosignerData {
};
}

function getDefaultV3CosignerData(request: HardQuoteRequest): V3CosignerData {
async function getDefaultV3CosignerData(request: HardQuoteRequest, provider: ethers.providers.Provider): Promise<V3CosignerData> {
const currentBlock = await provider.getBlockNumber();

return {
decayStartBlock: 1,
decayStartBlock: currentBlock + V3_BLOCK_BUFFER,
exclusiveFiller: ethers.constants.AddressZero,
exclusivityOverrideBps: BigNumber.from(0),
inputOverride: BigNumber.from(0),
Expand Down
8 changes: 8 additions & 0 deletions lib/handlers/hard-quote/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import { DynamoFillerAddressRepository } from '../../repositories/filler-address
import { STAGE } from '../../util/stage';
import { ApiInjector, ApiRInj } from '../base/api-handler';
import { HardQuoteRequestBody } from './schema';
import { ethers } from 'ethers';

export interface ContainerInjected {
quoters: Quoter[];
firehose: FirehoseLogger;
orderServiceProvider: OrderServiceProvider;
provider: ethers.providers.Provider;
}

export interface RequestInjected extends ApiRInj {
Expand Down Expand Up @@ -74,10 +76,16 @@ export class QuoteInjector extends ApiInjector<ContainerInjected, RequestInjecte
const quoters: Quoter[] = [
new WebhookQuoter(log, firehose, webhookProvider, circuitBreakerProvider, fillerComplianceProvider, repository),
];

const provider = new ethers.providers.JsonRpcProvider(
process.env.ARBITRUM_RPC_URL
);

return {
quoters: quoters,
firehose: firehose,
orderServiceProvider,
provider,
};
}

Expand Down

0 comments on commit c364984

Please sign in to comment.