Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add closeCampaign() to CurvePoolBooster. #2360

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions contracts/abi/createx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[
{
"inputs": [
{
"internalType": "bytes32",
"name": "salt",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "initCode",
"type": "bytes"
}
],
"name": "deployCreate2",
"outputs": [
{
"internalType": "address",
"name": "newContract",
"type": "address"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "salt",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "initCode",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
},
{
"components": [
{
"internalType": "uint256",
"name": "constructorAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "initCallAmount",
"type": "uint256"
}
],
"internalType": "struct CreateX.Values",
"name": "values",
"type": "tuple"
},
{
"internalType": "address",
"name": "refundAddress",
"type": "address"
}
],
"name": "deployCreate2AndInit",
"outputs": [
{
"internalType": "address",
"name": "newContract",
"type": "address"
}
],
"stateMutability": "payable",
"type": "function"
}
]
17 changes: 15 additions & 2 deletions contracts/contracts/interfaces/ICampaignRemoteManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ interface ICampaignRemoteManager {
function createCampaign(
CampaignCreationParams memory params,
uint256 destinationChainId,
uint256 additionalGasLimit
uint256 additionalGasLimit,
address votemarket
) external payable;

function manageCampaign(
CampaignManagementParams memory params,
uint256 destinationChainId,
uint256 additionalGasLimit
uint256 additionalGasLimit,
address votemarket
) external payable;

function closeCampaign(
CampaignClosingParams memory params,
uint256 destinationChainId,
uint256 additionalGasLimit,
address votemarket
) external payable;

struct CampaignCreationParams {
Expand All @@ -34,4 +43,8 @@ interface ICampaignRemoteManager {
uint256 totalRewardAmount;
uint256 maxRewardPerVote;
}

struct CampaignClosingParams {
uint256 campaignId;
}
}
111 changes: 92 additions & 19 deletions contracts/contracts/strategies/CurvePoolBooster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
/// @notice Address of the reward token
address public immutable rewardToken;

/// @notice Address of the campaignRemoteManager linked to VotemarketV2
address public immutable campaignRemoteManager;

/// @notice Chain id of the target chain
uint256 public immutable targetChainId;

Expand All @@ -40,22 +37,31 @@
/// @notice Address of the fee collector
address public feeCollector;

/// @notice Address of the campaignRemoteManager linked to VotemarketV2
address public campaignRemoteManager;

/// @notice Address of votemarket in L2
address public votemarket;

/// @notice Id of the campaign created
uint256 public campaignId;

////////////////////////////////////////////////////
/// --- EVENTS
////////////////////////////////////////////////////
event FeeUpdated(uint16 _newFee);
event FeeCollected(address _feeCollector, uint256 _feeAmount);
event FeeCollectorUpdated(address _newFeeCollector);
event CampaignIdUpdated(uint256 _newId);
event BribeCreated(
event FeeUpdated(uint16 newFee);
event FeeCollected(address feeCollector, uint256 feeAmount);
event FeeCollectorUpdated(address newFeeCollector);
event VotemarketUpdated(address newVotemarket);
event CampaignRemoteManagerUpdated(address newCampaignRemoteManager);
event CampaignCreated(
address gauge,
address rewardToken,
uint256 maxRewardPerVote,
uint256 totalRewardAmount
);
event CampaignIdUpdated(uint256 newId);
event CampaignClosed(uint256 campaignId);
event TotalRewardAmountUpdated(uint256 extraTotalRewardAmount);
event NumberOfPeriodsUpdated(uint8 extraNumberOfPeriods);
event RewardPerVoteUpdated(uint256 newMaxRewardPerVote);
Expand All @@ -66,12 +72,10 @@
////////////////////////////////////////////////////
constructor(
uint256 _targetChainId,
address _campaignRemoteManager,
address _rewardToken,
address _gauge
) {
targetChainId = _targetChainId;
campaignRemoteManager = _campaignRemoteManager;
rewardToken = _rewardToken;
gauge = _gauge;

Expand All @@ -86,11 +90,15 @@
function initialize(
address _strategist,
uint16 _fee,
address _feeCollector
address _feeCollector,
address _campaignRemoteManager,
address _votemarket
) external onlyGovernor initializer {
_setStrategistAddr(_strategist);
_setFee(_fee);
_setFeeCollector(_feeCollector);
_setCampaignRemoteManager(_campaignRemoteManager);
_setVotemarket(_votemarket);
}

////////////////////////////////////////////////////
Expand Down Expand Up @@ -137,10 +145,16 @@
isWhitelist: false
}),
targetChainId,
additionalGasLimit
additionalGasLimit,
votemarket
);

emit BribeCreated(gauge, rewardToken, maxRewardPerVote, balanceSubFee);
emit CampaignCreated(

Check warning on line 152 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L152

Added line #L152 was not covered by tests
gauge,
rewardToken,
maxRewardPerVote,
balanceSubFee
);
}

/// @notice Manage the total reward amount of the campaign
Expand Down Expand Up @@ -173,7 +187,8 @@
maxRewardPerVote: 0
}),
targetChainId,
additionalGasLimit
additionalGasLimit,
votemarket
);

emit TotalRewardAmountUpdated(balanceSubFee);
Expand Down Expand Up @@ -205,7 +220,8 @@
maxRewardPerVote: 0
}),
targetChainId,
additionalGasLimit
additionalGasLimit,
votemarket
);

emit NumberOfPeriodsUpdated(extraNumberOfPeriods);
Expand Down Expand Up @@ -236,15 +252,37 @@
maxRewardPerVote: newMaxRewardPerVote
}),
targetChainId,
additionalGasLimit
additionalGasLimit,
votemarket
);

emit RewardPerVoteUpdated(newMaxRewardPerVote);
}

/// @notice Take the balance of rewards tokens owned by this contract and calculate the fee amount.
/// Transfer the fee to the feeCollector.
/// @return balance remaining balance of reward token
/// @notice Close the campaign.
/// @dev This function only work on the L2 chain. Not on mainnet.
/// @dev The _campaignId parameter is not related to the campaignId of this contract, allowing greater flexibility.
/// @param _campaignId Id of the campaign to close
function closeCampaign(

Check warning on line 266 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L266

Added line #L266 was not covered by tests
uint256 _campaignId,
uint256 bridgeFee,
uint256 additionalGasLimit
) external onlyGovernorOrStrategist {
ICampaignRemoteManager(campaignRemoteManager).closeCampaign{

Check warning on line 271 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L271

Added line #L271 was not covered by tests
value: bridgeFee
}(
ICampaignRemoteManager.CampaignClosingParams({
campaignId: campaignId
}),
targetChainId,
additionalGasLimit,
votemarket
);
emit CampaignClosed(_campaignId);

Check warning on line 281 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L281

Added line #L281 was not covered by tests
}

/// @notice calculate the fee amount and transfer it to the feeCollector
/// @return Balance after fee
function _handleFee() internal returns (uint256) {
// Cache current rewardToken balance
uint256 balance = IERC20(rewardToken).balanceOf(address(this));
Expand Down Expand Up @@ -334,5 +372,40 @@
emit FeeCollectorUpdated(_feeCollector);
}

/// @notice Set the campaignRemoteManager
/// @param _campaignRemoteManager New campaignRemoteManager address
function setCampaignRemoteManager(address _campaignRemoteManager)

Check warning on line 377 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L377

Added line #L377 was not covered by tests
external
onlyGovernor
{
_setCampaignRemoteManager(_campaignRemoteManager);

Check warning on line 381 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L381

Added line #L381 was not covered by tests
}

/// @notice Internal logic to set the campaignRemoteManager
/// @param _campaignRemoteManager New campaignRemoteManager address
function _setCampaignRemoteManager(address _campaignRemoteManager)
internal
{
require(
_campaignRemoteManager != address(0),
"Invalid campaignRemoteManager"
);
campaignRemoteManager = _campaignRemoteManager;
emit CampaignRemoteManagerUpdated(_campaignRemoteManager);
}

/// @notice Set the votemarket address
/// @param _votemarket New votemarket address
function setVotemarket(address _votemarket) external onlyGovernor {
_setVotemarket(_votemarket);

Check warning on line 400 in contracts/contracts/strategies/CurvePoolBooster.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/CurvePoolBooster.sol#L400

Added line #L400 was not covered by tests
}

/// @notice Internal logic to set the votemarket address
function _setVotemarket(address _votemarket) internal onlyGovernor {
require(_votemarket != address(0), "Invalid votemarket");
votemarket = _votemarket;
emit VotemarketUpdated(_votemarket);
}

receive() external payable {}
}
Loading
Loading