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

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

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

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

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

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