Skip to content

Commit ded1b66

Browse files
committed
replaces external trust source with actively managed locking trust
Signed-off-by: Stefan Adolf <[email protected]>
1 parent a6b7a19 commit ded1b66

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/crowdsale/LockingCrowdSale.sol

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.18;
33

4+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
45
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
56
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
67
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
@@ -12,27 +13,20 @@ import { CrowdSale, Sale } from "./CrowdSale.sol";
1213
error UnsupportedInitializer();
1314
error InvalidDuration();
1415

15-
interface ITrustedLockingContracts {
16-
function lockingContracts(address) external view returns (TimelockedToken);
17-
}
1816

1917
/**
2018
* @title LockingCrowdSale
2119
* @author molecule.to
2220
* @notice a fixed price sales base contract that locks the sold tokens for a configurable duration
2321
*/
24-
contract LockingCrowdSale is CrowdSale, ITrustedLockingContracts {
22+
contract LockingCrowdSale is CrowdSale {
2523
using SafeERC20 for IERC20Metadata;
2624

2725
mapping(uint256 => uint256) public salesLockingDuration;
2826

2927
/// @notice map from token address to reusable TimelockedToken contracts
3028
mapping(address => TimelockedToken) public lockingContracts;
3129

32-
///@notice this can be another contract registry that takes care of locking contracts
33-
/// to reuse implementations
34-
ITrustedLockingContracts public lockingContractTrustee;
35-
3630
address immutable public TIMELOCKED_TOKEN_IMPLEMENTATION;
3731

3832
event Started(uint256 indexed saleId, address indexed issuer, Sale sale, TimelockedToken lockingToken, uint256 lockingDuration, uint16 feeBp);
@@ -47,8 +41,14 @@ contract LockingCrowdSale is CrowdSale, ITrustedLockingContracts {
4741
revert UnsupportedInitializer();
4842
}
4943

50-
function trustLockingContractSource(ITrustedLockingContracts _lockingContractTrustee) public onlyOwner {
51-
lockingContractTrustee = _lockingContractTrustee;
44+
/**
45+
* @notice allows the owner to trust a timelocked token contract for a specific underlying token so it's not registered again.
46+
*
47+
* @param token the underlying token
48+
* @param _lockingContract the timelocked token contract to trust
49+
*/
50+
function trustLockingContract(IERC20 token, TimelockedToken _lockingContract) public onlyOwner {
51+
lockingContracts[address(token)] = _lockingContract;
5252
}
5353

5454
/**
@@ -62,12 +62,7 @@ contract LockingCrowdSale is CrowdSale, ITrustedLockingContracts {
6262
lockedTokenContract = lockingContracts[address(underlyingToken)];
6363

6464
if (address(lockedTokenContract) == address(0)) {
65-
if (address(lockingContractTrustee) != address(0)) {
66-
lockedTokenContract = lockingContractTrustee.lockingContracts(address(underlyingToken));
67-
}
68-
if (address(lockedTokenContract) == address(0)) {
69-
lockedTokenContract = _makeNewLockedTokenContract(underlyingToken);
70-
}
65+
lockedTokenContract = _makeNewLockedTokenContract(underlyingToken);
7166
lockingContracts[address(underlyingToken)] = lockedTokenContract;
7267
}
7368
}

0 commit comments

Comments
 (0)