Skip to content

Commit

Permalink
chore: Better format solidity files
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnfy-view committed Mar 23, 2024
1 parent c345e52 commit a5a1ca2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 62 deletions.
7 changes: 3 additions & 4 deletions script/DeployThunderSwapPoolFactory.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {Script} from "forge-std/Script.sol";
import {ThunderSwapPoolFactory} from "@src/ThunderSwapPoolFactory.sol";
import { ThunderSwapPoolFactory } from "@src/ThunderSwapPoolFactory.sol";
import { Script } from "forge-std/Script.sol";

contract DeployThunderSwapPoolFactory is Script {
function run() external {
vm.startBroadcast();
ThunderSwapPoolFactory thunderSwapPoolFactory = new ThunderSwapPoolFactory();
vm.stopBroadcast();
}

}
}
18 changes: 12 additions & 6 deletions test/unit/deployPool/DeployPool.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {PoolFactoryHelper} from "../../utils/helpers/PoolFactoryHelper.sol";
import {UniversalHelper} from "../../utils/helpers/UniversalHelper.sol";
import {Token} from "../../utils/mocks/Token.sol";
import { PoolFactoryHelper } from "../../utils/helpers/PoolFactoryHelper.sol";
import { UniversalHelper } from "../../utils/helpers/UniversalHelper.sol";
import { Token } from "../../utils/mocks/Token.sol";

contract DeployPool is UniversalHelper, PoolFactoryHelper {
function testDeployingThunderSwapPoolRevertsIfTokenNotSupported() public {
Expand All @@ -22,8 +22,14 @@ contract DeployPool is UniversalHelper, PoolFactoryHelper {
thunderSwapPoolFactory.deployThunderSwapPool(tokenAddress, tokenAddress);
}

function testDeployingThunderSwapPoolRevertsIfPoolAlreadyExists() public distributeTokensToUsers(1e18, 2e18) addInitialLiquidity(1e18, 2e18) {
vm.expectRevert(abi.encodeWithSelector(PoolAlreadyExists.selector, address(thunderSwapPool)));
function testDeployingThunderSwapPoolRevertsIfPoolAlreadyExists()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
vm.expectRevert(
abi.encodeWithSelector(PoolAlreadyExists.selector, address(thunderSwapPool))
);
thunderSwapPoolFactory.deployThunderSwapPool(address(tokenB), address(tokenA));
}

Expand All @@ -40,4 +46,4 @@ contract DeployPool is UniversalHelper, PoolFactoryHelper {
thunderSwapPoolFactory.deployThunderSwapPool(address(tokenC), address(tokenD));
vm.stopPrank();
}
}
}
102 changes: 51 additions & 51 deletions test/unit/flashSwapTests/FlashSwap.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {FlashSwapHelper} from "../../utils/helpers/FlashSwapHelper.sol";
import { ThunderSwapper } from "../../utils/ThunderSwapper.sol";
import { FlashSwapHelper } from "../../utils/helpers/FlashSwapHelper.sol";
import { UniversalHelper } from "../../utils/helpers/UniversalHelper.sol";

contract FlashSwap is UniversalHelper, FlashSwapHelper {
Expand Down Expand Up @@ -84,7 +84,17 @@ contract FlashSwap is UniversalHelper, FlashSwapHelper {
vm.startPrank(user1);
tokenA.transfer(address(thunderSwapper), tokenA.balanceOf(user1));
vm.expectEmit(true, true, true, false);
emit FlashSwapped(user1, tokenA, tokenB,inputAmount, thunderSwapPool.getOutputBasedOnInput(inputAmount, tokenA.balanceOf(address(thunderSwapPool)), tokenB.balanceOf(address(thunderSwapPool))));
emit FlashSwapped(
user1,
tokenA,
tokenB,
inputAmount,
thunderSwapPool.getOutputBasedOnInput(
inputAmount,
tokenA.balanceOf(address(thunderSwapPool)),
tokenB.balanceOf(address(thunderSwapPool))
)
);
thunderSwapPool.flashSwapExactInput(
tokenA,
inputAmount,
Expand All @@ -96,58 +106,32 @@ contract FlashSwap is UniversalHelper, FlashSwapHelper {
vm.stopPrank();
}

function flashSwappingRevertsIfInputOrOutputAmountsAreZero()
public
deployThunderSwapper
{
function flashSwappingRevertsIfInputOrOutputAmountsAreZero() public deployThunderSwapper {
vm.expectRevert(InputValueZeroNotAllowed.selector);
thunderSwapPool.flashSwapExactInput(
tokenA,
0,
0,
address(thunderSwapper),
true,
uint256(block.timestamp)
tokenA, 0, 0, address(thunderSwapper), true, uint256(block.timestamp)
);

vm.expectRevert(InputValueZeroNotAllowed.selector);
thunderSwapPool.flashSwapExactOutput(
tokenA,
0,
0,
address(thunderSwapper),
true,
uint256(block.timestamp)
tokenA, 0, 0, address(thunderSwapper), true, uint256(block.timestamp)
);
}

function flashSwappingRevertsIfDeadlinePassed()
public
deployThunderSwapper
{
function flashSwappingRevertsIfDeadlinePassed() public deployThunderSwapper {
uint256 dummyValue1 = 1e18;
uint256 dummyValue2 = 2e18;

vm.warp(1 days);
uint256 deadline = uint256(block.timestamp - 1);
vm.expectRevert(abi.encodeWithSelector(DeadlinePassed.selector, deadline));
thunderSwapPool.flashSwapExactInput(
tokenA,
dummyValue1,
dummyValue2,
address(thunderSwapper),
true,
deadline
tokenA, dummyValue1, dummyValue2, address(thunderSwapper), true, deadline
);

vm.expectRevert(abi.encodeWithSelector(DeadlinePassed.selector, deadline));
thunderSwapPool.flashSwapExactOutput(
tokenA,
dummyValue1,
dummyValue2,
address(thunderSwapper),
true,
deadline
tokenA, dummyValue1, dummyValue2, address(thunderSwapper), true, deadline
);
}

Expand All @@ -157,33 +141,38 @@ contract FlashSwap is UniversalHelper, FlashSwapHelper {

vm.expectRevert(ReceiverZeroAddress.selector);
thunderSwapPool.flashSwapExactInput(
tokenA,
dummyValue1,
dummyValue2,
address(0),
true,
uint256(block.timestamp)
tokenA, dummyValue1, dummyValue2, address(0), true, uint256(block.timestamp)
);

vm.expectRevert(ReceiverZeroAddress.selector);
thunderSwapPool.flashSwapExactOutput(
tokenA,
dummyValue1,
dummyValue2,
address(0),
true,
uint256(block.timestamp)
tokenA, dummyValue1, dummyValue2, address(0), true, uint256(block.timestamp)
);
}

function flashSwappingExactInputRevertsIfOutputAmountisLessThanMinimumOutputAmountToReceive() public distributeTokensToUsers(1e18, 2e18) addInitialLiquidity(1e18, 2e18) {
function flashSwappingExactInputRevertsIfOutputAmountisLessThanMinimumOutputAmountToReceive()
public
distributeTokensToUsers(1e18, 2e18)
addInitialLiquidity(1e18, 2e18)
{
uint256 inputAmount = 1e18;
uint256 minimumOutputTokensToReceive = 5e18;
uint256 calculatedOutputAmount = thunderSwapPool.getOutputBasedOnInput(inputAmount, tokenA.balanceOf(address(thunderSwapPool)), tokenB.balanceOf(address(thunderSwapPool)));
uint256 calculatedOutputAmount = thunderSwapPool.getOutputBasedOnInput(
inputAmount,
tokenA.balanceOf(address(thunderSwapPool)),
tokenB.balanceOf(address(thunderSwapPool))
);

vm.startPrank(user1);
tokenA.transfer(address(thunderSwapper), tokenA.balanceOf(user1));
vm.expectRevert(abi.encodeWithSelector(PoolTokenToReceiveLessThanMinimumPoolTokenToReceive.selector, tokenB, calculatedOutputAmount, minimumOutputTokensToReceive));
vm.expectRevert(
abi.encodeWithSelector(
PoolTokenToReceiveLessThanMinimumPoolTokenToReceive.selector,
tokenB,
calculatedOutputAmount,
minimumOutputTokensToReceive
)
);
thunderSwapPool.flashSwapExactInput(
tokenA,
inputAmount,
Expand All @@ -203,11 +192,22 @@ contract FlashSwap is UniversalHelper, FlashSwapHelper {
{
uint256 outputAmount = 5e17;
uint256 maximumInputTokensToSend = 1e18;
uint256 calculatedInputAmount = thunderSwapPool.getInputBasedOnOuput(outputAmount, tokenB.balanceOf(address(thunderSwapPool)), tokenA.balanceOf(address(thunderSwapPool)));
uint256 calculatedInputAmount = thunderSwapPool.getInputBasedOnOuput(
outputAmount,
tokenB.balanceOf(address(thunderSwapPool)),
tokenA.balanceOf(address(thunderSwapPool))
);

vm.startPrank(user1);
tokenB.transfer(address(thunderSwapper), tokenB.balanceOf(user1));
vm.expectRevert(abi.encodeWithSelector(PoolTokenToSendMoreThanMaximumPoolTokenToSend.selector, tokenB, calculatedInputAmount, maximumInputTokensToSend));
vm.expectRevert(
abi.encodeWithSelector(
PoolTokenToSendMoreThanMaximumPoolTokenToSend.selector,
tokenB,
calculatedInputAmount,
maximumInputTokensToSend
)
);
thunderSwapPool.flashSwapExactOutput(
tokenA,
outputAmount,
Expand Down
2 changes: 1 addition & 1 deletion test/utils/helpers/PoolFactoryHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ contract PoolFactoryHelper {
error PoolAlreadyExists(address pool);
error PoolCannotHaveTwoTokensOfTheSameType();
error TokenNotSupported(address tokenAddress);
}
}

0 comments on commit a5a1ca2

Please sign in to comment.