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 Parameter for all contract settable variable #406

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion contracts/Airdropper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';

contract Airdropper is Initializable, OwnableUpgradeable {
import './interfaces/IParameter.sol';

contract Airdropper is Initializable, OwnableUpgradeable, IParameter {
using SafeERC20 for IERC20;
// -- Data --

Expand Down Expand Up @@ -53,6 +55,7 @@ contract Airdropper is Initializable, OwnableUpgradeable {

function setSettleDestination(address _settleDestination) external onlyOwner {
settleDestination = _settleDestination;
emit Parameter('settleDestination', abi.encodePacked(settleDestination));
}

function addController(address controller) external onlyOwner {
Expand Down
6 changes: 5 additions & 1 deletion contracts/ConsumerHost.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import './interfaces/IConsumer.sol';
import './interfaces/IEraManager.sol';
import './interfaces/ISettings.sol';
import './interfaces/IConsumerRegistry.sol';
import './interfaces/IParameter.sol';

/**
* @title Consumer Host Contract
Expand All @@ -25,7 +26,7 @@ import './interfaces/IConsumerRegistry.sol';
* Other contracts can verify the consumer and safeTransfer SQT.
*
*/
contract ConsumerHost is Initializable, OwnableUpgradeable, IConsumer, ERC165 {
contract ConsumerHost is Initializable, OwnableUpgradeable, IConsumer, ERC165, IParameter {
using SafeERC20 for IERC20;

// -- Structs --
Expand Down Expand Up @@ -109,6 +110,7 @@ contract ConsumerHost is Initializable, OwnableUpgradeable, IConsumer, ERC165 {
__Ownable_init();
settings = _settings;
feePerMill = _feePerMill;
emit Parameter('feePerMill', abi.encodePacked(feePerMill));

// Approve Token to State Channel.
IERC20 sqt = IERC20(_sqt);
Expand All @@ -130,6 +132,8 @@ contract ConsumerHost is Initializable, OwnableUpgradeable, IConsumer, ERC165 {
function setFeeRate(uint256 _feePerMill) external onlyOwner {
require(_feePerMill <= PER_MILL, 'C001');
feePerMill = _feePerMill;

emit Parameter('feePerMill', abi.encodePacked(feePerMill));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion contracts/DisputeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import './interfaces/ISettings.sol';
import './interfaces/IEraManager.sol';
import './interfaces/ISQToken.sol';
import './interfaces/IDisputeManager.sol';
import './interfaces/IParameter.sol';

contract DisputeManager is IDisputeManager, Initializable, OwnableUpgradeable {
contract DisputeManager is IDisputeManager, Initializable, OwnableUpgradeable, IParameter {
using SafeERC20 for IERC20;

enum DisputeType {
Expand Down Expand Up @@ -65,6 +66,7 @@ contract DisputeManager is IDisputeManager, Initializable, OwnableUpgradeable {
settings = _settings;
nextDisputeId = 1;
minimumDeposit = _minimumDeposit;
emit Parameter('minimumDeposit', abi.encodePacked(minimumDeposit));
}

/**
Expand All @@ -77,6 +79,7 @@ contract DisputeManager is IDisputeManager, Initializable, OwnableUpgradeable {

function setMinimumDeposit(uint256 _minimumDeposit) external onlyOwner {
minimumDeposit = _minimumDeposit;
emit Parameter('minimumDeposit', abi.encodePacked(minimumDeposit));
}

function createDispute(
Expand Down
7 changes: 6 additions & 1 deletion contracts/IndexerRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import './Constants.sol';
import './interfaces/IRewardsStaking.sol';
import './interfaces/IStakingManager.sol';
import './utils/MathUtil.sol';
import './interfaces/IParameter.sol';

/**
* @title Indexer Registry Contract
Expand Down Expand Up @@ -44,7 +45,7 @@ import './utils/MathUtil.sol';
* Indexer must set a appropriate commission rate and stake enough SQT Token when registering.
* Indexer need to make sure all the query projects with NOT INDEXING status before unregister.
*/
contract IndexerRegistry is Initializable, OwnableUpgradeable {
contract IndexerRegistry is Initializable, OwnableUpgradeable, IParameter {
using SafeERC20 for IERC20;
using MathUtil for uint256;

Expand Down Expand Up @@ -113,6 +114,8 @@ contract IndexerRegistry is Initializable, OwnableUpgradeable {

settings = _settings;
minimumStakingAmount = _minimumStakingAmount;
emit Parameter('minimumStakingAmount', abi.encodePacked(minimumStakingAmount));
emit Parameter('minimumCommissionRate', abi.encodePacked(uint256(0)));
}

/**
Expand All @@ -129,6 +132,7 @@ contract IndexerRegistry is Initializable, OwnableUpgradeable {
*/
function setminimumStakingAmount(uint256 amount) external onlyOwner {
minimumStakingAmount = amount;
emit Parameter('minimumStakingAmount', abi.encodePacked(minimumStakingAmount));
}

/**
Expand All @@ -139,6 +143,7 @@ contract IndexerRegistry is Initializable, OwnableUpgradeable {
require(rate <= PER_MILL, 'IR006');
minimumCommissionRate = rate;
emit MinimumCommissionRateUpdated(rate);
emit Parameter('minimumCommissionRate', abi.encodePacked(minimumCommissionRate));
}

/**
Expand Down
8 changes: 7 additions & 1 deletion contracts/PermissionedExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

import './interfaces/ISettings.sol';
import './interfaces/IEraManager.sol';
import './interfaces/IParameter.sol';

/**
* @title PermissionedExchange Contract
* @notice For now PermissionedExchange contract allows traders trade their SQTs on admin sent orders, later on we may allow others to send their orders. Controllers may set the trade quota for trader, and trader cannot trade over the their quota.
* It provides a way for indexers to swap their rewards(SQT) to stable token with a fixed exchange rate.
*/
contract PermissionedExchange is Initializable, OwnableUpgradeable {
contract PermissionedExchange is Initializable, OwnableUpgradeable, IParameter {
using SafeERC20 for IERC20;

struct ExchangeOrder {
Expand Down Expand Up @@ -93,6 +94,9 @@ contract PermissionedExchange is Initializable, OwnableUpgradeable {
for (uint256 i; i < _controllers.length; i++) {
exchangeController[_controllers[i]] = true;
}

emit Parameter('tradeLimitation', abi.encodePacked(uint256(0)));
emit Parameter('tradeLimitationPerAccount', abi.encodePacked(uint256(0)));
}

/**
Expand All @@ -118,6 +122,7 @@ contract PermissionedExchange is Initializable, OwnableUpgradeable {
*/
function setTradeLimitation(uint256 _limit) external onlyOwner {
tradeLimitation = _limit;
emit Parameter('tradeLimitation', abi.encodePacked(tradeLimitation));
}

/**
Expand All @@ -126,6 +131,7 @@ contract PermissionedExchange is Initializable, OwnableUpgradeable {
*/
function setTradeLimitationPerAccount(uint256 _limit) external onlyOwner {
tradeLimitationPerAccount = _limit;
emit Parameter('tradeLimitationPerAccount', abi.encodePacked(tradeLimitationPerAccount));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion contracts/PlanManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import './interfaces/ISettings.sol';
import './interfaces/IPlanManager.sol';
import './interfaces/IEraManager.sol';
import './interfaces/IPriceOracle.sol';
import './interfaces/IParameter.sol';

/**
* @title Plan Manager Contract
Expand All @@ -26,7 +27,7 @@ import './interfaces/IPriceOracle.sol';
* PlanTemplate: PlanTemplate is create and maintenance by owner, we provide a set of PlanTemplates
* for Indexer to create the Plan.
*/
contract PlanManager is Initializable, OwnableUpgradeable, IPlanManager {
contract PlanManager is Initializable, OwnableUpgradeable, IPlanManager, IParameter {
/// @dev ### STATES
/// @notice ISettings contract which stores SubQuery network contracts address
ISettings public settings;
Expand Down Expand Up @@ -81,6 +82,7 @@ contract PlanManager is Initializable, OwnableUpgradeable, IPlanManager {
settings = _settings;
limit = 5;
nextPlanId = 1;
emit Parameter('limit', abi.encodePacked(limit));
}

/**
Expand All @@ -97,6 +99,7 @@ contract PlanManager is Initializable, OwnableUpgradeable, IPlanManager {
*/
function setPlanLimit(uint256 _limit) external onlyOwner {
limit = _limit;
emit Parameter('limit', abi.encodePacked(limit));
}

/**
Expand Down
7 changes: 6 additions & 1 deletion contracts/PriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';

import './interfaces/IPriceOracle.sol';
import './interfaces/IParameter.sol';

contract PriceOracle is IPriceOracle, Initializable, OwnableUpgradeable {
contract PriceOracle is IPriceOracle, Initializable, OwnableUpgradeable, IParameter {
///@notice the price of assetTo in assetFrom
mapping(address => mapping(address => uint256)) public prices;

Expand All @@ -32,6 +33,8 @@ contract PriceOracle is IPriceOracle, Initializable, OwnableUpgradeable {
sizeLimit = _sizeLimit;
blockLimit = _blockLimit;
enlargementFactor = 1e6;
emit Parameter('sizeLimit', abi.encodePacked(sizeLimit));
emit Parameter('blockLimit', abi.encodePacked(blockLimit));
}

event PricePosted(address assetFrom, address assetTo, uint256 previousPrice, uint256 newPrice);
Expand All @@ -40,6 +43,8 @@ contract PriceOracle is IPriceOracle, Initializable, OwnableUpgradeable {
function setLimit(uint256 _sizeLimit, uint256 _blockLimit) public onlyOwner {
sizeLimit = _sizeLimit;
blockLimit = _blockLimit;
emit Parameter('sizeLimit', abi.encodePacked(sizeLimit));
emit Parameter('blockLimit', abi.encodePacked(blockLimit));
}

///@notice update the controller account
Expand Down
13 changes: 12 additions & 1 deletion contracts/PurchaseOfferMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import './interfaces/IEraManager.sol';
import './interfaces/IStakingManager.sol';
import './Constants.sol';
import './utils/MathUtil.sol';
import './interfaces/IParameter.sol';

/**
* @title Purchase Offer Market Contract
Expand All @@ -42,7 +43,12 @@ import './utils/MathUtil.sol';
* Consumers can cancel their purchase offer after expire date for free, but if cancel the unexpired Purchase Offer
* we will charge the penalty fee.
*/
contract PurchaseOfferMarket is Initializable, OwnableUpgradeable, IPurchaseOfferMarket {
contract PurchaseOfferMarket is
Initializable,
OwnableUpgradeable,
IPurchaseOfferMarket,
IParameter
{
using SafeERC20 for IERC20;

/**
Expand Down Expand Up @@ -139,6 +145,9 @@ contract PurchaseOfferMarket is Initializable, OwnableUpgradeable, IPurchaseOffe
settings = _settings;
penaltyRate = _penaltyRate;
penaltyDestination = _penaltyDestination;

emit Parameter('penaltyRate', abi.encodePacked(penaltyRate));
emit Parameter('penaltyDestination', abi.encodePacked(penaltyDestination));
}

/**
Expand All @@ -156,6 +165,7 @@ contract PurchaseOfferMarket is Initializable, OwnableUpgradeable, IPurchaseOffe
function setPenaltyRate(uint256 _penaltyRate) external onlyOwner {
require(_penaltyRate < PER_MILL, 'PO001');
penaltyRate = _penaltyRate;
emit Parameter('penaltyRate', abi.encodePacked(penaltyRate));
}

/**
Expand All @@ -164,6 +174,7 @@ contract PurchaseOfferMarket is Initializable, OwnableUpgradeable, IPurchaseOffe
*/
function setPenaltyDestination(address _penaltyDestination) external onlyOwner {
penaltyDestination = _penaltyDestination;
emit Parameter('penaltyDestination', abi.encodePacked(penaltyDestination));
}

/**
Expand Down
21 changes: 13 additions & 8 deletions contracts/RewardsBooster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import './interfaces/IProjectRegistry.sol';
import './utils/FixedMath.sol';
import './utils/MathUtil.sol';
import './utils/StakingUtil.sol';
import './interfaces/IParameter.sol';

/**
* @title Rewards for running
* @notice ### Overview
* The RewardsRunning using the Cobb-Douglas production function for staking & running
*/
contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster {
contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster, IParameter {
using ERC165CheckerUpgradeable for address;
using SafeERC20 for IERC20;
using MathUtil for uint256;
Expand Down Expand Up @@ -120,6 +121,8 @@ contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster {
settings = _settings;
issuancePerBlock = _issuancePerBlock;
minimumDeploymentBooster = _minimumDeploymentBooster;
emit Parameter('issuancePerBlock', abi.encodePacked(issuancePerBlock));
emit Parameter('minimumDeploymentBooster', abi.encodePacked(minimumDeploymentBooster));
}

/**
Expand All @@ -137,6 +140,7 @@ contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster {

function setMinimumDeploymentBooster(uint256 _minimumDeploymentBooster) external onlyOwner {
minimumDeploymentBooster = _minimumDeploymentBooster;
emit Parameter('minimumDeploymentBooster', abi.encodePacked(minimumDeploymentBooster));
}

/**
Expand All @@ -151,6 +155,7 @@ contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster {

issuancePerBlock = _issuancePerBlock;
emit ParameterUpdated('issuancePerBlock', issuancePerBlock);
emit Parameter('issuancePerBlock', abi.encodePacked(issuancePerBlock));
}

/**
Expand Down Expand Up @@ -197,10 +202,7 @@ contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster {
* @param deploymentId deploymentId
* @param amount the added amount
*/
function removeBoosterDeployment(
bytes32 deploymentId,
uint256 amount
) external {
function removeBoosterDeployment(bytes32 deploymentId, uint256 amount) external {
require(deploymentPools[deploymentId].accountBooster[msg.sender] >= amount, 'RB003');
_removeBoosterDeployment(deploymentId, msg.sender, amount);
IERC20(settings.getContractAddress(SQContracts.SQToken)).safeTransfer(msg.sender, amount);
Expand Down Expand Up @@ -278,21 +280,24 @@ contract RewardsBooster is Initializable, OwnableUpgradeable, IRewardsBooster {
);
}


/**
* @notice Add booster deployment staking
* @param _deploymentId the deployment id
* @param _account the booster account
* @param _amount the added amount
*/
function _addBoosterDeployment(bytes32 _deploymentId, address _account, uint256 _amount) internal {
function _addBoosterDeployment(
bytes32 _deploymentId,
address _account,
uint256 _amount
) internal {
DeploymentPool storage deploymentPool = deploymentPools[_deploymentId];
onDeploymentBoosterUpdate(_deploymentId, _account);
deploymentPool.boosterPoint += _amount;
deploymentPool.accountBooster[_account] += _amount;
deploymentPool.accRewardsPerBooster = accRewardsPerBooster;
totalBoosterPoint += _amount;

emit DeploymentBoosterAdded(_deploymentId, _account, _amount);
}

Expand Down
7 changes: 6 additions & 1 deletion contracts/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './interfaces/IStaking.sol';
import './interfaces/IStakingManager.sol';
import './Constants.sol';
import './utils/MathUtil.sol';
import './interfaces/IParameter.sol';

/**
* @title Rewards Distributer Contract
Expand Down Expand Up @@ -55,7 +56,7 @@ import './utils/MathUtil.sol';
*
* Runner's commission is treated as unbond request to Staking Contract, which applies a lock period on it.
*/
contract RewardsDistributor is IRewardsDistributor, Initializable, OwnableUpgradeable {
contract RewardsDistributor is IRewardsDistributor, Initializable, OwnableUpgradeable, IParameter {
using SafeERC20 for IERC20;
using MathUtil for uint256;

Expand Down Expand Up @@ -123,6 +124,8 @@ contract RewardsDistributor is IRewardsDistributor, Initializable, OwnableUpgrad

//Settings
settings = _settings;
emit Parameter('maxCommissionFactor', abi.encodePacked(uint256(0)));
emit Parameter('maxRewardFactor', abi.encodePacked(uint256(0)));
}

function setSettings(ISettings _settings) external onlyOwner {
Expand All @@ -131,10 +134,12 @@ contract RewardsDistributor is IRewardsDistributor, Initializable, OwnableUpgrad

function setMaxCommissionFactor(uint256 _maxCommissionFactor) external onlyOwner {
maxCommissionFactor = _maxCommissionFactor;
emit Parameter('maxCommissionFactor', abi.encodePacked(maxCommissionFactor));
}

function setMaxRewardFactor(uint256 _maxRewardFactor) external onlyOwner {
maxRewardFactor = _maxRewardFactor;
emit Parameter('maxRewardFactor', abi.encodePacked(maxRewardFactor));
}

/**
Expand Down
Loading
Loading