Skip to content

Commit

Permalink
Fix paco0x#4
Browse files Browse the repository at this point in the history
Typo in math calculation

Signed-off-by: Penghui Liao <[email protected]>
  • Loading branch information
paco0x committed May 3, 2021
1 parent e68295f commit 3fbcd3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/FlashBot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ contract FlashBot is Ownable {
(int256 a1, int256 a2, int256 b1, int256 b2) =
(int256(reserves.a1 / d), int256(reserves.a2 / d), int256(reserves.b1 / d), int256(reserves.b2 / d));

int256 a = a1 * b1 - a2 * b1;
int256 a = a1 * b1 - a2 * b2;
int256 b = 2 * b1 * b2 * (a1 + a2);
int256 c = b1 * b2 * (a1 * b2 - a2 * b1);

Expand Down
6 changes: 3 additions & 3 deletions test/MathTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('MathTest', () => {
const input = lodash.mapValues(reserves, (v) => ethers.utils.parseEther(v));
const res = await flashBot._calcBorrowAmount(input);
// @ts-ignore
expect(res).to.be.closeTo(ethers.utils.parseEther('0.45'), ethers.utils.parseEther('0.1'));
expect(res).to.be.closeTo(ethers.utils.parseEther('0.45'), ethers.utils.parseEther('0.01'));
});

it('returns right amount with large liquidity pairs', async () => {
Expand All @@ -64,12 +64,12 @@ describe('MathTest', () => {
expect(res).to.be.closeTo(ethers.utils.parseEther('53052.8604'), ethers.utils.parseEther('1500'));
});

it('returns right amount with high difference liquidity pairs', async () => {
it('returns right amount with big difference between liquidity pairs', async () => {
const reserves = { a1: '1200000000', b1: '600000', a2: '100000', b2: '30' };
const input = lodash.mapValues(reserves, (v) => ethers.utils.parseEther(v));
const res = await flashBot._calcBorrowAmount(input);
// @ts-ignore
expect(res).to.be.closeTo(ethers.utils.parseEther('8.729'), ethers.utils.parseEther('0.5'));
expect(res).to.be.closeTo(ethers.utils.parseEther('8.729'), ethers.utils.parseEther('0.01'));
});

it('revert with wrong order input', async () => {
Expand Down

0 comments on commit 3fbcd3d

Please sign in to comment.