Skip to content

Commit

Permalink
Merge pull request #839 from 0xprinc/aburkut/back-1766-fluid-dex-changes
Browse files Browse the repository at this point in the history
Updated tests
  • Loading branch information
aburkut authored Nov 21, 2024
2 parents aea6687 + 9a19b2d commit 58e7b28
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
7 changes: 0 additions & 7 deletions .env.example

This file was deleted.

4 changes: 2 additions & 2 deletions src/dex/fluid-dex/fluid-dex-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ describe('FluidDex E2E', () => {
const tokenASymbol: string = 'USDC';
const tokenBSymbol: string = 'USDT';

const tokenAAmount: string = '1000000';
const tokenBAmount: string = '100000000';
const tokenAAmount: string = '10000';
const tokenBAmount: string = '1000000';

testForNetwork(
network,
Expand Down
2 changes: 1 addition & 1 deletion src/dex/fluid-dex/fluid-dex-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('FluidDex EventPool Mainnet', function () {

const eventsToTest: Record<Address, EventMappings> = {
'0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085': {
LogDexDeployed: [21105298, 21105363, 21105367, 21105371],
LogDexDeployed: [21199929],
},
};

Expand Down
1 change: 0 additions & 1 deletion src/dex/fluid-dex/fluid-dex-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ async function checkOnChainPricing(
return price === 0n;
}
const percentDiff = ((price - expectedPrice) * 100n) / expectedPrice;
console.log('this is percent diff : ', percentDiff);
return percentDiff <= 0.01 && percentDiff >= -0.01;
}),
).toBe(true);
Expand Down
28 changes: 16 additions & 12 deletions src/dex/fluid-dex/fluid-dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,15 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
currentLimits,
syncTime,
);
return (
((amountIn * BigInt(this.FEE_100_PERCENT)) /
(BigInt(this.FEE_100_PERCENT) - fee)) *
BigInt(10) ** BigInt(inDecimals - 12)
);

if (amountIn == 2n ** 256n - 1n) {
return amountIn;
}
const ans =
(amountIn * this.FEE_100_PERCENT * BigInt(10 ** inDecimals)) /
BigInt(10 ** 12) /
(this.FEE_100_PERCENT - fee);
return ans;
}

/**
Expand Down Expand Up @@ -892,10 +896,10 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
debtIReserveOut,
);
if (amountOut > debtReserveOut) {
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}
if (amountOut > borrowable) {
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}
} else if (a >= amountOut) {
// Entire trade routes through collateral pool
Expand All @@ -906,10 +910,10 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
colIReserveOut,
);
if (amountOut > colReserveOut) {
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}
if (amountOut > withdrawable) {
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}
} else {
// Trade routes through both pools
Expand All @@ -922,10 +926,10 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
debtIReserveOut,
);
if (amountOutDebt > debtReserveOut || a > colReserveOut) {
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}
if (amountOutDebt > borrowable || a > withdrawable) {
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}
}

Expand Down Expand Up @@ -962,7 +966,7 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
(oldPrice / BigInt(100)) * MAX_PRICE_DIFF
) {
// if price diff is > 5% then swap would revert.
return BigInt(Number.MAX_SAFE_INTEGER);
return 2n ** 256n - 1n;
}

const totalAmountIn = amountInCollateral + amountInDebt;
Expand Down

0 comments on commit 58e7b28

Please sign in to comment.