-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added TWAMM Factory but getting errors in factory contract
- Loading branch information
1 parent
1dfa490
commit 93df672
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.15; | ||
|
||
import {TWAMM} from "./TWAMM.sol"; | ||
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; | ||
import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol"; | ||
|
||
contract TWAMMFactory { | ||
PoolManager public immutable poolManager; | ||
uint256 public immutable orderTimeInterval; | ||
|
||
event TWAMMDeployed(address twammAddress); | ||
|
||
constructor(PoolManager _poolManager, uint256 _orderTimeInterval) { | ||
poolManager = _poolManager; | ||
orderTimeInterval = _orderTimeInterval; | ||
} | ||
|
||
function deployTWAMM() public returns (address) { | ||
TWAMM newTWAMM = new TWAMM( | ||
address(poolManager), | ||
orderTimeInterval, | ||
address(uint160(Hooks.BEFORE_INITIALIZE_FLAG | Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_ADD_LIQUIDITY_FLAG)) | ||
); | ||
|
||
emit TWAMMDeployed(address(newTWAMM)); | ||
return address(newTWAMM); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
pragma solidity ^0.8.15; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol"; | ||
import {TWAMMFactory} from "../src/TWAMMFactory.sol"; | ||
import {TWAMM} from "../src/TWAMM.sol"; | ||
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol"; | ||
|
||
contract TWAMMFactoryTest is Test { | ||
PoolManager public poolManager; | ||
TWAMMFactory public factory; | ||
uint256 constant ORDER_TIME_INTERVAL = 10_000; | ||
|
||
event TWAMMDeployed(address twammAddress); | ||
|
||
function setUp() public { | ||
// Deploy a mock PoolManager | ||
poolManager = new PoolManager(500000); | ||
|
||
// Deploy the TWAMMFactory | ||
factory = new TWAMMFactory(poolManager, ORDER_TIME_INTERVAL); | ||
} | ||
|
||
function testFactoryDeployment() public { | ||
assertEq(address(factory.poolManager()), address(poolManager)); | ||
assertEq(factory.orderTimeInterval(), ORDER_TIME_INTERVAL); | ||
} | ||
|
||
function testDeployTWAMM() public { | ||
vm.expectEmit(true, true, true, true); | ||
emit TWAMMDeployed(address(0)); // We don't know the exact address, so we use a placeholder | ||
|
||
address twammAddress = factory.deployTWAMM(); | ||
|
||
assertTrue(twammAddress != address(0)); | ||
TWAMM twamm = TWAMM(twammAddress); | ||
|
||
// Verify that the TWAMM contract was deployed with the correct parameters | ||
assertEq(address(twamm.poolManager()), address(poolManager)); | ||
assertEq(twamm.ORDER_TIME_INTERVAL(), ORDER_TIME_INTERVAL); | ||
|
||
// Verify that the TWAMM contract has the correct hooks enabled | ||
uint160 expectedFlags = uint160(Hooks.BEFORE_INITIALIZE_FLAG | Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_ADD_LIQUIDITY_FLAG); | ||
assertEq(uint160(twammAddress), expectedFlags); | ||
} | ||
|
||
function testMultipleDeployments() public { | ||
address twamm1 = factory.deployTWAMM(); | ||
address twamm2 = factory.deployTWAMM(); | ||
|
||
assertTrue(twamm1 != twamm2); | ||
assertTrue(twamm1 != address(0)); | ||
assertTrue(twamm2 != address(0)); | ||
} | ||
} |