Skip to content

Commit

Permalink
chore: add salt to createPair
Browse files Browse the repository at this point in the history
  • Loading branch information
happenwah committed Sep 6, 2024
1 parent 45543a6 commit be5761c
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/ValidlyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ contract ValidlyFactory is IValidlyFactory {
* @custom:error ValidlyFactory__createPair_failedDeployment Thrown if the Validly contract deployment fails.
* @custom:error ValidlyFactory__createPair_invalidFeeBips Thrown if the feeBips is not between 0 and 10000.
*/
function createPair(address _token0, address _token1, bool _isStable) external returns (address) {
(_token0, _token1) = _token0 < _token1 ? (_token0, _token1) : (_token1, _token0);
function createPair(
address _token0,
address _token1,
bool _isStable
) external returns (address) {
(_token0, _token1) = _token0 < _token1
? (_token0, _token1)
: (_token1, _token0);

bytes32 poolKey = _poolKey(_token0, _token1, _isStable);

Expand All @@ -113,7 +119,7 @@ contract ValidlyFactory is IValidlyFactory {

address pool = protocolFactory.deploySovereignPool(args);

Validly validly = new Validly(pool, _isStable);
Validly validly = new Validly{salt: poolKey}(pool, _isStable);

ISovereignPool(pool).setALM(address(validly));

Expand All @@ -131,7 +137,10 @@ contract ValidlyFactory is IValidlyFactory {
* @param _isStable Boolean indicating if the pool should be stable or volatile.
* @custom:error ValidlyFactory__createPool_failedDeployment Thrown if the Validly contract deployment fails.
*/
function createPool(SovereignPoolConstructorArgs memory _args, bool _isStable) external returns (address validly) {
function createPool(
SovereignPoolConstructorArgs memory _args,
bool _isStable
) external returns (address validly) {
_args.poolManager = address(this);

address pool = protocolFactory.deploySovereignPool(_args);
Expand All @@ -150,7 +159,10 @@ contract ValidlyFactory is IValidlyFactory {
* @param _feeBips The fee percentage for the pool manager.
* @custom:error ValidlyFactory__setPoolManagerFees_unauthorized Thrown if the caller is not the protocol manager.
*/
function setPoolManagerFeeBips(address _pool, uint256 _feeBips) external onlyProtocolManager {
function setPoolManagerFeeBips(
address _pool,
uint256 _feeBips
) external onlyProtocolManager {
ISovereignPool(_pool).setPoolManagerFeeBips(_feeBips);

emit PoolManagerFeeBipsSet(_pool, _feeBips);
Expand All @@ -163,7 +175,10 @@ contract ValidlyFactory is IValidlyFactory {
* @param _token The address of the token to claim.
* @param _recipient The address of the recipient.
*/
function claimTokens(address _token, address _recipient) external onlyProtocolManager {
function claimTokens(
address _token,
address _recipient
) external onlyProtocolManager {
if (_token == address(0)) {
revert ValidlyFactory__claimTokens_invalidToken();
}
Expand Down Expand Up @@ -196,7 +211,11 @@ contract ValidlyFactory is IValidlyFactory {
/**
* PRIVATE FUNCTIONS
*/
function _poolKey(address token0, address token1, bool isStable) private pure returns (bytes32 key) {
function _poolKey(
address token0,
address token1,
bool isStable
) private pure returns (bytes32 key) {
key = keccak256(abi.encode(token0, token1, isStable));
}
}

0 comments on commit be5761c

Please sign in to comment.