feat: uniswapx start time buffer (#7279)

* wip

* feat: use startTimeBufferSecs from API response
This commit is contained in:
eddie 2023-09-08 09:30:57 -07:00 committed by GitHub
parent 1ac1002c37
commit a3fbab9163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 3 deletions

@ -32,6 +32,7 @@
"quoteId": "f9f47cd7-a62c-4622-9ac7-51d0e662245a",
"requestId": "2d16f993-6429-4755-ba50-1383789459dc",
"auctionPeriodSecs": 60,
"startTimeBufferSecs": 30,
"deadlineBufferSecs": 12,
"slippageTolerance": "0.5",
"permitData": {
@ -252,6 +253,7 @@
"quoteId": "f9f47cd7-a62c-4622-9ac7-51d0e662245a",
"requestId": "2d16f993-6429-4755-ba50-1383789459dc",
"auctionPeriodSecs": 60,
"startTimeBufferSecs": 30,
"deadlineBufferSecs": 12,
"slippageTolerance": "0.5",
"permitData": {

@ -32,6 +32,7 @@
"quoteId": "09ce28b7-1ddf-4317-a28d-d21092be9f84",
"requestId": "f00535d4-461a-4363-afbe-7a5ab7061cd1",
"auctionPeriodSecs": 60,
"startTimeBufferSecs": 30,
"deadlineBufferSecs": 12,
"slippageTolerance": "0.5",
"permitData": {
@ -252,6 +253,7 @@
"quoteId": "09ce28b7-1ddf-4317-a28d-d21092be9f84",
"requestId": "f00535d4-461a-4363-afbe-7a5ab7061cd1",
"auctionPeriodSecs": 60,
"startTimeBufferSecs": 30,
"deadlineBufferSecs": 12,
"slippageTolerance": "0.5",
"permitData": {

@ -13,8 +13,6 @@ import { UserRejectedRequestError } from 'utils/errors'
import { signTypedData } from 'utils/signing'
import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage'
const DEFAULT_START_TIME_PADDING_SECONDS = 30
type DutchAuctionOrderError = { errorCode?: number; detail?: string }
type DutchAuctionOrderSuccess = { hash: string }
type DutchAuctionOrderResponse = DutchAuctionOrderError | DutchAuctionOrderSuccess
@ -69,7 +67,7 @@ export function useUniswapXSwapCallback({
try {
const updatedNonce = await getUpdatedNonce(account, trade.order.chainId)
const startTime = Math.floor(Date.now() / 1000) + DEFAULT_START_TIME_PADDING_SECONDS
const startTime = Math.floor(Date.now() / 1000) + trade.startTimeBufferSecs
setTraceData('startTime', startTime)
const endTime = startTime + trade.auctionPeriodSecs

@ -114,6 +114,7 @@ type URADutchOrderQuoteResponse = {
quote: {
auctionPeriodSecs: number
deadlineBufferSecs: number
startTimeBufferSecs: number
orderInfo: DutchOrderInfoJSON
quoteId?: string
requestId?: string
@ -236,6 +237,7 @@ export class DutchOrderTrade extends IDutchOrderTrade<Currency, Currency, TradeT
// The gas estimate of the reference classic trade, if there is one.
classicGasUseEstimateUSD?: number
auctionPeriodSecs: number
startTimeBufferSecs: number
deadlineBufferSecs: number
slippageTolerance: Percent
@ -250,6 +252,7 @@ export class DutchOrderTrade extends IDutchOrderTrade<Currency, Currency, TradeT
approveInfo,
classicGasUseEstimateUSD,
auctionPeriodSecs,
startTimeBufferSecs,
deadlineBufferSecs,
slippageTolerance,
}: {
@ -263,6 +266,7 @@ export class DutchOrderTrade extends IDutchOrderTrade<Currency, Currency, TradeT
wrapInfo: WrapInfo
classicGasUseEstimateUSD?: number
auctionPeriodSecs: number
startTimeBufferSecs: number
deadlineBufferSecs: number
slippageTolerance: Percent
}) {
@ -275,6 +279,7 @@ export class DutchOrderTrade extends IDutchOrderTrade<Currency, Currency, TradeT
this.auctionPeriodSecs = auctionPeriodSecs
this.deadlineBufferSecs = deadlineBufferSecs
this.slippageTolerance = slippageTolerance
this.startTimeBufferSecs = startTimeBufferSecs
}
public get totalGasUseEstimateUSD(): number {
@ -351,6 +356,7 @@ type UniswapXConfig = {
swapper?: string
exclusivityOverrideBps?: number
auctionPeriodSecs?: number
startTimeBufferSecs?: number
}
export type RoutingConfig = (UniswapXConfig | ClassicAPIConfig)[]

@ -277,6 +277,7 @@ export async function transformRoutesToTrade(
wrapInfo,
approveInfo,
auctionPeriodSecs: data.quote.auctionPeriodSecs,
startTimeBufferSecs: data.quote.startTimeBufferSecs,
deadlineBufferSecs: data.quote.deadlineBufferSecs,
slippageTolerance: toSlippagePercent(data.quote.slippageTolerance),
})

@ -121,6 +121,7 @@ export const TEST_DUTCH_TRADE_ETH_INPUT = new DutchOrderTrade({
classicGasUseEstimateUSD: 7.87,
auctionPeriodSecs: 120,
deadlineBufferSecs: 30,
startTimeBufferSecs: 30,
slippageTolerance: new Percent(5, 100),
})