Skip to content

Commit

Permalink
mixed route eth -> uni test that repro smarter pool filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 committed Aug 22, 2023
1 parent e604570 commit d5272f3
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/integ/routers/alpha-router/alpha-router.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,76 @@ describe('alpha router integration', () => {
10000
);
});

it.only('ETH -> UNI', async () => {
/// Fails for v3 for some reason, ProviderGasError
const tokenIn = Ether.onChain(1) as Currency;
const tokenOut = UNI_MAINNET;
const amount =
tradeType == TradeType.EXACT_INPUT
? parseAmount('10', tokenIn)
: parseAmount('10000', tokenOut);

const swap = await alphaRouter.route(
amount,
getQuoteToken(tokenIn, tokenOut, tradeType),
tradeType,
{
type: SwapType.UNIVERSAL_ROUTER,
recipient: alice._address,
slippageTolerance: SLIPPAGE,
deadlineOrPreviousBlockhash: parseDeadline(360),
},
{
...ROUTING_CONFIG,
protocols: [Protocol.MIXED],
}
);
expect(swap).toBeDefined();
expect(swap).not.toBeNull();

const { quote, methodParameters } = swap!;

expect(methodParameters).not.toBeUndefined();

const { tokenInBefore, tokenInAfter, tokenOutBefore, tokenOutAfter } =
await executeSwap(
SwapType.UNIVERSAL_ROUTER,
methodParameters!,
tokenIn,
tokenOut
);

if (tradeType == TradeType.EXACT_INPUT) {
// We've swapped 10 ETH + gas costs
expect(
tokenInBefore
.subtract(tokenInAfter)
.greaterThan(parseAmount('10', tokenIn))
).toBe(true);
checkQuoteToken(
tokenOutBefore,
tokenOutAfter,
CurrencyAmount.fromRawAmount(tokenOut, quote.quotient)
);
} else {
/**
* @dev it is possible for an exactOut to generate more tokens on V2 due to precision errors
*/
expect(
!tokenOutAfter
.subtract(tokenOutBefore)
// == .greaterThanOrEqualTo
.lessThan(
CurrencyAmount.fromRawAmount(
tokenOut,
expandDecimals(tokenOut, 10000)
)
)
).toBe(true);
// Can't easily check slippage for ETH due to gas costs effecting ETH balance.
}
});
});
});
});
Expand Down

0 comments on commit d5272f3

Please sign in to comment.