Skip to content

Commit

Permalink
add pool and receiver deployers
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcivita committed Aug 13, 2024
1 parent d1fda94 commit 597a8cd
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
41 changes: 41 additions & 0 deletions contracts/MarginalV1LBPoolDeployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.17;

import {IMarginalV1LBPoolDeployer} from "./interfaces/IMarginalV1LBPoolDeployer.sol";
import {MarginalV1LBPool} from "./MarginalV1LBPool.sol";

contract MarginalV1LBPoolDeployer is IMarginalV1LBPoolDeployer {
/// @inheritdoc IMarginalV1LBPoolDeployer
function deploy(
address token0,
address token1,
int24 tickLower,
int24 tickUpper,
address supplier,
uint256 blockTimestampInitialize
) external returns (address pool) {
pool = address(
new MarginalV1LBPool{
salt: keccak256(
abi.encode(
msg.sender,
token0,
token1,
tickLower,
tickUpper,
supplier,
blockTimestampInitialize
)
)
}(
msg.sender,
token0,
token1,
tickLower,
tickUpper,
supplier,
blockTimestampInitialize
)
);
}
}
4 changes: 4 additions & 0 deletions contracts/base/PeripheryImmutableState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import "../interfaces/IPeripheryImmutableState.sol";
/// @title Immutable state
/// @notice Immutable state used by liquidity bootstrapping periphery contracts
abstract contract PeripheryImmutableState is IPeripheryImmutableState {
/// @inheritdoc IPeripheryImmutableState
address public immutable factory;
/// @inheritdoc IPeripheryImmutableState
address public immutable marginalV1Factory;
/// @inheritdoc IPeripheryImmutableState
address public immutable uniswapV3Factory;
/// @inheritdoc IPeripheryImmutableState
address public immutable WETH9;

constructor(address _factory, address _marginalV1Factory, address _WETH9) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ interface IMarginalV1LBLiquidityReceiverDeployer is
/// @notice Returns the address of the Marginal v1 periphery router
/// @return The address of the Marginal v1 router
function marginalV1Router() external view returns (address);

/// @notice Returns the address of WETH9
/// @return The address of WETH9
function WETH9() external view returns (address);
}
64 changes: 64 additions & 0 deletions contracts/receiver/MarginalV1LBLiquidityReceiverDeployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity =0.8.15;

import {MarginalV1LBLiquidityReceiver} from "./MarginalV1LBLiquidityReceiver.sol";

import {IMarginalV1LBPool} from "../interfaces/IMarginalV1LBPool.sol";
import {IMarginalV1LBReceiverDeployer} from "../interfaces/receiver/IMarginalV1LBReceiverDeployer.sol";
import {IMarginalV1LBLiquidityReceiverDeployer} from "../interfaces/receiver/liquidity/IMarginalV1LBLiquidityReceiverDeployer.sol";

contract MarginalV1LBLiquidityReceiverDeployer is
IMarginalV1LBLiquidityReceiverDeployer
{
/// @inheritdoc IMarginalV1LBLiquidityReceiverDeployer
address public immutable uniswapV3NonfungiblePositionManager;
/// @inheritdoc IMarginalV1LBLiquidityReceiverDeployer
address public immutable marginalV1Factory;
/// @inheritdoc IMarginalV1LBLiquidityReceiverDeployer
address public immutable marginalV1PoolInitializer;
/// @inheritdoc IMarginalV1LBLiquidityReceiverDeployer
address public immutable marginalV1Router;
/// @inheritdoc IMarginalV1LBLiquidityReceiverDeployer
address public immutable WETH9;

modifier onlyPoolSupplier(address pool) {
if (msg.sender != IMarginalV1LBPool(pool).supplier())
revert Unauthorized();
_;
}

error Unauthorized();

constructor(
address _uniswapV3NonfungiblePositionManager,
address _marginalV1Factory,
address _marginalV1PoolInitializer,
address _marginalV1Router,
address _WETH9
) {
uniswapV3NonfungiblePositionManager = _uniswapV3NonfungiblePositionManager;
marginalV1Factory = _marginalV1Factory;
marginalV1PoolInitializer = _marginalV1PoolInitializer;
marginalV1Router = _marginalV1Router;
WETH9 = _WETH9;
}

/// @inheritdoc IMarginalV1LBReceiverDeployer
function deploy(
address pool,
bytes calldata data
)
external
virtual
override(IMarginalV1LBReceiverDeployer)
onlyPoolSupplier(pool)
returns (address receiver)
{
address factory = IMarginalV1LBPool(pool).factory();
receiver = address(
new MarginalV1LBLiquidityReceiver{
salt: keccak256(abi.encode(msg.sender, pool))
}(factory, marginalV1Factory, WETH9, pool, data)
);
}
}

0 comments on commit 597a8cd

Please sign in to comment.