-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from clober-dex/feat/priceBook-deployer
Feat/price book deployer
- Loading branch information
Showing
17 changed files
with
294 additions
and
73 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
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,14 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
interface CloberOrderTokenDeployer { | ||
// TODO: add docstring | ||
function deploy(bytes32 salt) external returns (address); | ||
|
||
/** | ||
* @notice Computes the OrderNFT contract address. | ||
* @param salt The salt to compute the OrderNFT contract address via CREATE2. | ||
*/ | ||
function computeTokenAddress(bytes32 salt) external view returns (address); | ||
} |
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,11 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
interface CloberPriceBookDeployer { | ||
// TODO: add docstring | ||
function deployArithmeticPriceBook(uint128 a, uint128 d) external returns (address); | ||
|
||
// TODO: add docstring | ||
function deployGeometricPriceBook(uint128 a, uint128 r) external returns (address); | ||
} |
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,34 @@ | ||
// SPDX-License-Identifier: - | ||
// License: https://license.clober.io/LICENSE.pdf | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/utils/Create2.sol"; | ||
|
||
import "../interfaces/CloberOrderTokenDeployer.sol"; | ||
import "../OrderNFT.sol"; | ||
|
||
contract OrderTokenDeployer is CloberOrderTokenDeployer { | ||
address private immutable _factory; | ||
address private immutable _canceler; | ||
bytes32 private immutable _orderTokenBytecodeHash; | ||
|
||
constructor(address factory_, address canceler_) { | ||
_factory = factory_; | ||
_canceler = canceler_; | ||
_orderTokenBytecodeHash = keccak256( | ||
abi.encodePacked(type(OrderNFT).creationCode, abi.encode(factory_, canceler_)) | ||
); | ||
} | ||
|
||
function deploy(bytes32 salt) external returns (address) { | ||
if (msg.sender != _factory) { | ||
revert Errors.CloberError(Errors.ACCESS); | ||
} | ||
return address(new OrderNFT{salt: salt}(_factory, _canceler)); | ||
} | ||
|
||
function computeTokenAddress(bytes32 salt) external view returns (address) { | ||
return Create2.computeAddress(salt, _orderTokenBytecodeHash); | ||
} | ||
} |
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,52 @@ | ||
// SPDX-License-Identifier: - | ||
// License: https://license.clober.io/LICENSE.pdf | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./ArithmeticPriceBook.sol"; | ||
import "./GeometricPriceBook.sol"; | ||
import "../interfaces/CloberPriceBookDeployer.sol"; | ||
|
||
import "@openzeppelin/contracts/utils/Create2.sol"; | ||
|
||
contract PriceBookDeployer is CloberPriceBookDeployer { | ||
address private immutable _factory; | ||
|
||
constructor(address factory_) { | ||
_factory = factory_; | ||
} | ||
|
||
function deployArithmeticPriceBook(uint128 a, uint128 d) external returns (address priceBook) { | ||
if (msg.sender != _factory) { | ||
revert Errors.CloberError(Errors.ACCESS); | ||
} | ||
bytes32 salt = keccak256(abi.encodePacked(a, d)); | ||
priceBook = address(new ArithmeticPriceBook{salt: salt}(a, d)); | ||
} | ||
|
||
function deployGeometricPriceBook(uint128 a, uint128 r) external returns (address priceBook) { | ||
if (msg.sender != _factory) { | ||
revert Errors.CloberError(Errors.ACCESS); | ||
} | ||
bytes32 salt = keccak256(abi.encodePacked(a, r)); | ||
priceBook = address(new GeometricPriceBook{salt: salt}(a, r)); | ||
} | ||
|
||
function computeArithmeticPriceBookAddress(uint128 a, uint128 d) external view returns (address) { | ||
bytes32 salt = keccak256(abi.encodePacked(a, d)); | ||
return | ||
Create2.computeAddress( | ||
salt, | ||
keccak256(abi.encodePacked(type(ArithmeticPriceBook).creationCode, abi.encode(a, d))) | ||
); | ||
} | ||
|
||
function computeGeometricPriceBookAddress(uint128 a, uint128 r) external view returns (address) { | ||
bytes32 salt = keccak256(abi.encodePacked(a, r)); | ||
return | ||
Create2.computeAddress( | ||
salt, | ||
keccak256(abi.encodePacked(type(GeometricPriceBook).creationCode, abi.encode(a, r))) | ||
); | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"OrderCanceler": "0x03A2D3e0e4b073CDE7E227098B4257844910F094", | ||
"MarketDeployer": "0x6baa80Fff765eB9994b65AfFA121517910316074", | ||
"PriceBookDeployer": "0x30A075a4244a5A02e64a95eD3289234926baf02f", | ||
"MarketFactory": "0x7CE81Be8B48311D2E9e89fE4731B58D2CC8Aa1E4", | ||
"MarketRouter": "0x0ccc1fd632a5beE5bD9eda3aad490119eE50648F" | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.