Skip to content

Commit

Permalink
fix: assume no v3 rfq, uncomment v3 functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Nov 22, 2024
1 parent 4cd9531 commit 3d4cdb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
19 changes: 9 additions & 10 deletions lib/entities/HardQuoteRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TradeType } from '@uniswap/sdk-core';
import { OrderType, UnsignedV2DutchOrder, UnsignedV3DutchOrder } from '@uniswap/uniswapx-sdk';
import { OrderType, UnsignedV2DutchOrder, UnsignedV3DutchOrder, V3DutchOrderBuilder } from '@uniswap/uniswapx-sdk';
import { BigNumber, ethers, utils } from 'ethers';
import { v4 as uuidv4 } from 'uuid';

Expand All @@ -22,9 +22,8 @@ export class HardQuoteRequest {
};
if (orderType === OrderType.Dutch_V2) {
this.order = UnsignedV2DutchOrder.parse(_data.encodedInnerOrder, _data.tokenInChainId);
// } else if (orderType === OrderType.Dutch_V3) {
// this.order = UnsignedV3DutchOrder.parse(_data.encodedInnerOrder, _data.tokenInChainId);
// }
} else if (orderType === OrderType.Dutch_V3) {
this.order = UnsignedV3DutchOrder.parse(_data.encodedInnerOrder, _data.tokenInChainId);
} else {
throw new Error('Unsupported order type');
}
Expand Down Expand Up @@ -122,12 +121,12 @@ export class HardQuoteRequest {
? TradeType.EXACT_INPUT
: TradeType.EXACT_OUTPUT
}
// else if (this.order instanceof UnsignedV3DutchOrder) {
// const startAmount = this.order.info.input.startAmount;
// return startAmount.eq(V3DutchOrderBuilder.getMinAmountOut(startAmount, this.order.info.input.curve.relativeAmounts))
// ? TradeType.EXACT_INPUT
// : TradeType.EXACT_OUTPUT
// }
else if (this.order instanceof UnsignedV3DutchOrder) {
const startAmount = this.order.info.input.startAmount;
return startAmount.eq(V3DutchOrderBuilder.getMinAmountOut(startAmount, this.order.info.input.curve.relativeAmounts))
? TradeType.EXACT_INPUT
: TradeType.EXACT_OUTPUT
}
else {
throw new Error('Unsupported order type');
}
Expand Down
14 changes: 3 additions & 11 deletions lib/handlers/hard-quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ export function getCosignerData(
let inputOverride = BigNumber.from(0);
const outputOverrides = request.order.info.outputs.map(() => BigNumber.from(0));

// if the quote is better, then increase amounts by the difference
if (request.type === TradeType.EXACT_INPUT) {
if (quote.amountOut.gt(request.totalOutputAmountStart)) {
const increase = quote.amountOut.sub(request.totalOutputAmountStart);
// give all the increase to the first (swapper) output
outputOverrides[0] = request.order.info.outputs[0].startAmount.add(increase);
if (quote.filler) {
filler = quote.filler;
Expand All @@ -214,17 +216,7 @@ export function getCosignerData(
return v2Data;
}

case OrderType.Dutch_V3: {
const v3Data: V3CosignerData = {
decayStartBlock: 1,
exclusiveFiller: ethers.constants.AddressZero,
exclusivityOverrideBps: BigNumber.from(0),
inputOverride: BigNumber.from(0),
outputOverrides: request.order.info.outputs.map(() => BigNumber.from(0)),
};
return v3Data;
}

case OrderType.Dutch_V3: // fallthrough; currently not expecting users to use V3 for RFQ
default:
throw new Error('Unsupported order type');
}
Expand Down

0 comments on commit 3d4cdb5

Please sign in to comment.