Skip to content

Commit

Permalink
fix for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 30, 2024
1 parent e7cb486 commit ccb3d7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
49 changes: 27 additions & 22 deletions src/dex/fluid-dex/fluid-dex-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ import ResolverABI from '../../abi/fluid-dex/resolver.abi.json';
function getReaderCalldata(
exchangeAddress: string,
readerIface: Interface,
poolAddress: string,
amounts: bigint[],
funcName: string,
) {
return amounts.map(amount => ({
target: exchangeAddress,
callData: readerIface.encodeFunctionData(funcName, [
'0x0b1a513ee24972daef112bc777a5610d4325c9e7',
poolAddress,
funcName == 'estimateSwapIn' ? true : false,
amount,
funcName == 'estimateSwapIn' ? 0 : 2n * amount,
Expand All @@ -60,6 +61,7 @@ function decodeReaderResult(
async function checkOnChainPricing(
fluidDex: FluidDex,
funcName: string,
poolAddress: string,
blockNumber: number,
prices: bigint[],
amounts: bigint[],
Expand All @@ -71,9 +73,11 @@ async function checkOnChainPricing(
const readerCallData = getReaderCalldata(
resolverAddress,
readerIface,
poolAddress,
amounts.slice(1),
funcName,
);

const readerResult = (
await fluidDex.dexHelper.multiContract.methods
.aggregate(readerCallData)
Expand All @@ -83,6 +87,8 @@ async function checkOnChainPricing(
const expectedPrices = [0n].concat(
decodeReaderResult(readerResult, readerIface, funcName),
);

expect(prices).toEqual(expectedPrices);
}

async function testPricingOnNetwork(
Expand Down Expand Up @@ -138,6 +144,7 @@ async function testPricingOnNetwork(
await checkOnChainPricing(
fluidDex,
funcNameToCheck,
poolPrices![0].poolAddresses![0],
blockNumber,
poolPrices![0].prices,
amounts,
Expand All @@ -153,8 +160,6 @@ describe('FluidDex', function () {
const network = Network.MAINNET;
const dexHelper = new DummyDexHelper(network);

const tokens = Tokens[network];

beforeAll(async () => {
blockNumber = await dexHelper.provider.getBlockNumber();
fluidDex = new FluidDex(network, dexKey, dexHelper);
Expand All @@ -169,16 +174,16 @@ describe('FluidDex', function () {

const amountsForSell = [
0n,
1n * BI_POWS[8],
2n * BI_POWS[8],
3n * BI_POWS[8],
4n * BI_POWS[8],
5n * BI_POWS[8],
6n * BI_POWS[8],
7n * BI_POWS[8],
8n * BI_POWS[8],
9n * BI_POWS[8],
10n * BI_POWS[8],
1n * BI_POWS[18],
2n * BI_POWS[18],
3n * BI_POWS[18],
4n * BI_POWS[18],
5n * BI_POWS[18],
6n * BI_POWS[18],
7n * BI_POWS[18],
8n * BI_POWS[18],
9n * BI_POWS[18],
10n * BI_POWS[18],
];

it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume SELL', async function () {
Expand Down Expand Up @@ -216,16 +221,16 @@ describe('FluidDex', function () {

const amountsForSell = [
0n,
1n * BI_POWS[6],
2n * BI_POWS[6],
3n * BI_POWS[6],
4n * BI_POWS[6],
5n * BI_POWS[6],
6n * BI_POWS[6],
7n * BI_POWS[6],
8n * BI_POWS[6],
9n * BI_POWS[6],
10n * BI_POWS[6],
20n * BI_POWS[6],
30n * BI_POWS[6],
40n * BI_POWS[6],
50n * BI_POWS[6],
60n * BI_POWS[6],
70n * BI_POWS[6],
80n * BI_POWS[6],
90n * BI_POWS[6],
100n * BI_POWS[6],
];

it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () {
Expand Down
4 changes: 3 additions & 1 deletion src/dex/fluid-dex/fluid-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
side: SwapSide,
blockNumber: number,
): Promise<string[]> {
if (side === SwapSide.BUY) return [];

const pool = await this.getPoolByTokenPair(
srcToken.address,
destToken.address,
Expand Down Expand Up @@ -183,7 +185,7 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
if (srcToken.address.toLowerCase() === destToken.address.toLowerCase())
return null;

if (side === SwapSide.BUY) throw new Error(`Buy not supported`);
if (side === SwapSide.BUY) return null;
// Get the pool to use.
const pool = await this.getPoolByTokenPair(
srcToken.address,
Expand Down

0 comments on commit ccb3d7c

Please sign in to comment.