forked from Uniswap/continuous-clearing-auction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContinuousClearingAuctionFactory.sol
More file actions
61 lines (53 loc) · 2.99 KB
/
Copy pathContinuousClearingAuctionFactory.sol
File metadata and controls
61 lines (53 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {ContinuousClearingAuction} from './ContinuousClearingAuction.sol';
import {AuctionParameters} from './interfaces/IContinuousClearingAuction.sol';
import {IContinuousClearingAuctionFactory} from './interfaces/IContinuousClearingAuctionFactory.sol';
import {IDistributionContract} from './interfaces/external/IDistributionContract.sol';
import {IDistributionStrategy} from './interfaces/external/IDistributionStrategy.sol';
import {Create2} from '@openzeppelin/contracts/utils/Create2.sol';
import {ActionConstants} from 'v4-periphery/src/libraries/ActionConstants.sol';
/// @title ContinuousClearingAuctionFactory
/// @custom:security-contact security@uniswap.org
contract ContinuousClearingAuctionFactory is IContinuousClearingAuctionFactory {
/// @inheritdoc IDistributionStrategy
function initializeDistribution(address token, uint256 amount, bytes calldata configData, bytes32 salt)
external
returns (IDistributionContract distributionContract)
{
if (amount > type(uint128).max) revert InvalidTokenAmount(amount);
AuctionParameters memory parameters = abi.decode(configData, (AuctionParameters));
// If the tokensRecipient is address(1), set it to the msg.sender
if (parameters.tokensRecipient == ActionConstants.MSG_SENDER) parameters.tokensRecipient = msg.sender;
// If the fundsRecipient is address(1), set it to the msg.sender
if (parameters.fundsRecipient == ActionConstants.MSG_SENDER) parameters.fundsRecipient = msg.sender;
distributionContract = IDistributionContract(
address(
new ContinuousClearingAuction{salt: keccak256(abi.encode(msg.sender, salt))}(
token, uint128(amount), parameters
)
)
);
emit AuctionCreated(address(distributionContract), token, uint128(amount), abi.encode(parameters));
}
/// @inheritdoc IContinuousClearingAuctionFactory
function getAuctionAddress(address token, uint256 amount, bytes calldata configData, bytes32 salt, address sender)
external
view
returns (address)
{
if (amount > type(uint128).max) revert InvalidTokenAmount(amount);
AuctionParameters memory parameters = abi.decode(configData, (AuctionParameters));
// If the tokensRecipient is address(1), set it to the msg.sender
if (parameters.tokensRecipient == ActionConstants.MSG_SENDER) parameters.tokensRecipient = sender;
// If the fundsRecipient is address(1), set it to the msg.sender
if (parameters.fundsRecipient == ActionConstants.MSG_SENDER) parameters.fundsRecipient = sender;
bytes32 initCodeHash = keccak256(
abi.encodePacked(
type(ContinuousClearingAuction).creationCode, abi.encode(token, uint128(amount), parameters)
)
);
salt = keccak256(abi.encode(sender, salt));
return Create2.computeAddress(salt, initCodeHash, address(this));
}
}