Skip to content

Commit

Permalink
fix(uniswapx-sdk): rename vars to expectedAmountIn/Out for PriorityOr…
Browse files Browse the repository at this point in the history
…derTrade (#186)
  • Loading branch information
zhongeric authored Oct 28, 2024
1 parent 6a0d553 commit 7907e8c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
36 changes: 19 additions & 17 deletions sdks/uniswapx-sdk/src/trade/PriorityOrderTrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,27 @@ describe("PriorityOrderTrade", () => {
expect(ethOutputTrade.outputAmount.currency).toEqual(Ether.onChain(1));
});

it("returns the correct amountIn and amountOut with classic quote data", () => {
const classicAmounts = {
classicAmountInGasAndPortionAdjusted: "1",
classicAmountOutGasAndPortionAdjusted: "1",
it("returns the correct amountIn and amountOut with expected quote data", () => {
const expectedAmounts = {
expectedAmountIn: "1",
expectedAmountOut: "1",
};
const classicAmountTrade = new PriorityOrderTrade<Currency, Currency, TradeType>(
{
currencyIn: USDC,
currenciesOut: [DAI],
orderInfo,
tradeType: TradeType.EXACT_INPUT,
classicAmounts,
}
);
expect(classicAmountTrade.inputAmount.quotient.toString()).toEqual(
classicAmounts.classicAmountInGasAndPortionAdjusted
const expectedAmountTrade = new PriorityOrderTrade<
Currency,
Currency,
TradeType
>({
currencyIn: USDC,
currenciesOut: [DAI],
orderInfo,
tradeType: TradeType.EXACT_INPUT,
expectedAmounts,
});
expect(expectedAmountTrade.inputAmount.quotient.toString()).toEqual(
expectedAmounts.expectedAmountIn
);
expect(classicAmountTrade.outputAmount.quotient.toString()).toEqual(
classicAmounts.classicAmountOutGasAndPortionAdjusted
expect(expectedAmountTrade.outputAmount.quotient.toString()).toEqual(
expectedAmounts.expectedAmountOut
);
});
});
44 changes: 23 additions & 21 deletions sdks/uniswapx-sdk/src/trade/PriorityOrderTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export class PriorityOrderTrade<
> {
public readonly tradeType: TTradeType;
public readonly order: UnsignedPriorityOrder;
public readonly classicAmounts: {
classicAmountInGasAndPortionAdjusted: string;
classicAmountOutGasAndPortionAdjusted: string;
public readonly expectedAmounts: {
expectedAmountIn: string;
expectedAmountOut: string;
} | undefined;

private _inputAmount: CurrencyAmount<TInput> | undefined;
Expand All @@ -27,21 +27,21 @@ export class PriorityOrderTrade<
currenciesOut,
orderInfo,
tradeType,
classicAmounts,
expectedAmounts,
}: {
currencyIn: TInput;
currenciesOut: TOutput[];
orderInfo: UnsignedPriorityOrderInfo;
tradeType: TTradeType;
classicAmounts?: {
classicAmountInGasAndPortionAdjusted: string;
classicAmountOutGasAndPortionAdjusted: string;
expectedAmounts?: {
expectedAmountIn: string;
expectedAmountOut: string;
};
}) {
this._currencyIn = currencyIn;
this._currenciesOut = currenciesOut;
this.tradeType = tradeType;
this.classicAmounts = classicAmounts;
this.expectedAmounts = expectedAmounts;

// assume single-chain for now
this.order = new UnsignedPriorityOrder(orderInfo, currencyIn.chainId);
Expand All @@ -50,9 +50,9 @@ export class PriorityOrderTrade<
public get inputAmount(): CurrencyAmount<TInput> {
if (this._inputAmount) return this._inputAmount;

// If we have classic quote data use that, otherwise use the order input amount
const amount = this.classicAmounts?.classicAmountInGasAndPortionAdjusted
? this.getClassicAmountIn()
// If we have expected quote data use that, otherwise use the order input amount
const amount = this.expectedAmounts?.expectedAmountIn
? this.getExpectedAmountIn()
: CurrencyAmount.fromRawAmount(
this._currencyIn,
this.order.info.input.amount.toString()
Expand Down Expand Up @@ -120,8 +120,10 @@ export class PriorityOrderTrade<

// TODO: revise when there are actually multiple output amounts. for now, assume only one non-fee output at a time
public get outputAmount(): CurrencyAmount<TOutput> {
// If we have classic quote data use that, otherwise use the first non-fee output
return this.classicAmounts?.classicAmountOutGasAndPortionAdjusted ? this.getClassicAmountOut() : this.getFirstNonFeeOutputAmount();
// If we have expected quote data use that, otherwise use the first non-fee output
return this.expectedAmounts?.expectedAmountOut
? this.getExpectedAmountOut()
: this.getFirstNonFeeOutputAmount();
}

public minimumAmountOut(): CurrencyAmount<TOutput> {
Expand Down Expand Up @@ -165,25 +167,25 @@ export class PriorityOrderTrade<
);
}

private getClassicAmountIn(): CurrencyAmount<TInput> {
if (!this.classicAmounts?.classicAmountInGasAndPortionAdjusted) {
throw new Error("classicAmountInGasAndPortionAdjusted not set");
private getExpectedAmountIn(): CurrencyAmount<TInput> {
if (!this.expectedAmounts?.expectedAmountIn) {
throw new Error("expectedAmountIn not set");
}

return CurrencyAmount.fromRawAmount(
this._currencyIn,
this.classicAmounts.classicAmountInGasAndPortionAdjusted
this.expectedAmounts.expectedAmountIn
);
}

private getClassicAmountOut(): CurrencyAmount<TOutput> {
if (!this.classicAmounts?.classicAmountOutGasAndPortionAdjusted) {
throw new Error("classicAmountOutGasAndPortionAdjusted not set");
private getExpectedAmountOut(): CurrencyAmount<TOutput> {
if (!this.expectedAmounts?.expectedAmountOut) {
throw new Error("expectedAmountOut not set");
}

return CurrencyAmount.fromRawAmount(
this._currenciesOut[0],
this.classicAmounts.classicAmountOutGasAndPortionAdjusted
this.expectedAmounts.expectedAmountOut
);
}
}

0 comments on commit 7907e8c

Please sign in to comment.