Skip to content

Commit

Permalink
chore(contracts): lint sol files with graph config
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Mar 7, 2024
1 parent 48361b5 commit 41a4c97
Show file tree
Hide file tree
Showing 61 changed files with 560 additions and 1,409 deletions.
7 changes: 1 addition & 6 deletions packages/contracts/contracts/arbitrum/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ interface IBridge {
bytes32 messageDataHash
);

event BridgeCallTriggered(
address indexed outbox,
address indexed destAddr,
uint256 amount,
bytes data
);
event BridgeCallTriggered(address indexed outbox, address indexed destAddr, uint256 amount, bytes data);

event InboxToggle(address indexed inbox, bool enabled);

Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/contracts/arbitrum/IOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ interface IOutbox {

function l2ToL1OutputId() external view returns (bytes32);

function processOutgoingMessages(bytes calldata sendsData, uint256[] calldata sendLengths)
external;
function processOutgoingMessages(bytes calldata sendsData, uint256[] calldata sendLengths) external;

function outboxEntryExists(uint256 batchNum) external view returns (bool);
}
54 changes: 12 additions & 42 deletions packages/contracts/contracts/bancor/BancorFormula.sol
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ contract BancorFormula {
uint256 _amount
) public view returns (uint256) {
// validate input
require(
_supply > 0 && _reserveBalance > 0 && _totalRatio > 1 && _totalRatio <= MAX_RATIO * 2
);
require(_supply > 0 && _reserveBalance > 0 && _totalRatio > 1 && _totalRatio <= MAX_RATIO * 2);

// special case for 0 amount
if (_amount == 0) return 0;
Expand Down Expand Up @@ -364,11 +362,7 @@ contract BancorFormula {
) public view returns (uint256) {
// validate input
require(
_supply > 0 &&
_reserveBalance > 0 &&
_totalRatio > 1 &&
_totalRatio <= MAX_RATIO * 2 &&
_amount <= _supply
_supply > 0 && _reserveBalance > 0 && _totalRatio > 1 && _totalRatio <= MAX_RATIO * 2 && _amount <= _supply
);

// special case for 0 amount
Expand Down Expand Up @@ -407,12 +401,7 @@ contract BancorFormula {
* This functions assumes that "_expN < 2 ^ 256 / log(MAX_NUM - 1)", otherwise the multiplication should be replaced with a "safeMul".
* Since we rely on unsigned-integer arithmetic and "base < 1" ==> "log(base) < 0", this function does not support "_baseN < _baseD".
*/
function power(
uint256 _baseN,
uint256 _baseD,
uint32 _expN,
uint32 _expD
) internal view returns (uint256, uint8) {
function power(uint256 _baseN, uint256 _baseD, uint32 _expN, uint32 _expD) internal view returns (uint256, uint8) {
require(_baseN < MAX_NUM);

uint256 baseLog;
Expand All @@ -428,10 +417,7 @@ contract BancorFormula {
return (optimalExp(baseLogTimesExp), MAX_PRECISION);
} else {
uint8 precision = findPositionInMaxExpArray(baseLogTimesExp);
return (
generalExp(baseLogTimesExp >> (MAX_PRECISION - precision), precision),
precision
);
return (generalExp(baseLogTimesExp >> (MAX_PRECISION - precision), precision), precision);
}
}

Expand Down Expand Up @@ -642,37 +628,21 @@ contract BancorFormula {

z = y = x - FIXED_1;
w = (y * y) / FIXED_1;
res +=
(z * (0x100000000000000000000000000000000 - y)) /
0x100000000000000000000000000000000;
res += (z * (0x100000000000000000000000000000000 - y)) / 0x100000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^01 / 01 - y^02 / 02
res +=
(z * (0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - y)) /
0x200000000000000000000000000000000;
res += (z * (0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - y)) / 0x200000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^03 / 03 - y^04 / 04
res +=
(z * (0x099999999999999999999999999999999 - y)) /
0x300000000000000000000000000000000;
res += (z * (0x099999999999999999999999999999999 - y)) / 0x300000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^05 / 05 - y^06 / 06
res +=
(z * (0x092492492492492492492492492492492 - y)) /
0x400000000000000000000000000000000;
res += (z * (0x092492492492492492492492492492492 - y)) / 0x400000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^07 / 07 - y^08 / 08
res +=
(z * (0x08e38e38e38e38e38e38e38e38e38e38e - y)) /
0x500000000000000000000000000000000;
res += (z * (0x08e38e38e38e38e38e38e38e38e38e38e - y)) / 0x500000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^09 / 09 - y^10 / 10
res +=
(z * (0x08ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b - y)) /
0x600000000000000000000000000000000;
res += (z * (0x08ba2e8ba2e8ba2e8ba2e8ba2e8ba2e8b - y)) / 0x600000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^11 / 11 - y^12 / 12
res +=
(z * (0x089d89d89d89d89d89d89d89d89d89d89 - y)) /
0x700000000000000000000000000000000;
res += (z * (0x089d89d89d89d89d89d89d89d89d89d89 - y)) / 0x700000000000000000000000000000000;
z = (z * w) / FIXED_1; // add y^13 / 13 - y^14 / 14
res +=
(z * (0x088888888888888888888888888888888 - y)) /
0x800000000000000000000000000000000; // add y^15 / 15 - y^16 / 16
res += (z * (0x088888888888888888888888888888888 - y)) / 0x800000000000000000000000000000000; // add y^15 / 15 - y^16 / 16

return res;
}
Expand Down
101 changes: 20 additions & 81 deletions packages/contracts/contracts/curation/Curation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @dev Emitted when `curator` burned `signal` for a `subgraphDeploymentID`.
* The curator will receive `tokens` according to the value of the bonding curve.
*/
event Burned(
address indexed curator,
bytes32 indexed subgraphDeploymentID,
uint256 tokens,
uint256 signal
);
event Burned(address indexed curator, bytes32 indexed subgraphDeploymentID, uint256 tokens, uint256 signal);

/**
* @dev Emitted when `tokens` amount were collected for `subgraphDeploymentID` as part of fees
Expand Down Expand Up @@ -113,11 +108,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @notice Update the minimum deposit amount to `_minimumCurationDeposit`
* @param _minimumCurationDeposit Minimum amount of tokens required deposit
*/
function setMinimumCurationDeposit(uint256 _minimumCurationDeposit)
external
override
onlyGovernor
{
function setMinimumCurationDeposit(uint256 _minimumCurationDeposit) external override onlyGovernor {
_setMinimumCurationDeposit(_minimumCurationDeposit);
}

Expand Down Expand Up @@ -149,10 +140,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
require(msg.sender == address(staking()), "Caller must be the staking contract");

// Must be curated to accept tokens
require(
isCurated(_subgraphDeploymentID),
"Subgraph deployment must be curated to collect fees"
);
require(isCurated(_subgraphDeploymentID), "Subgraph deployment must be curated to collect fees");

// Collect new funds into reserve
CurationPool storage curationPool = pools[_subgraphDeploymentID];
Expand Down Expand Up @@ -193,9 +181,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
// If no signal token for the pool - create one
if (address(curationPool.gcs) == address(0)) {
// Use a minimal proxy to reduce gas cost
IGraphCurationToken gcs = IGraphCurationToken(
ClonesUpgradeable.clone(curationTokenMaster)
);
IGraphCurationToken gcs = IGraphCurationToken(ClonesUpgradeable.clone(curationTokenMaster));
gcs.initialize(address(this));
curationPool.gcs = gcs;
}
Expand Down Expand Up @@ -238,10 +224,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {

// Validations
require(_signalIn != 0, "Cannot burn zero signal");
require(
getCuratorSignal(curator, _subgraphDeploymentID) >= _signalIn,
"Cannot burn more signal than you own"
);
require(getCuratorSignal(curator, _subgraphDeploymentID) >= _signalIn, "Cannot burn more signal than you own");

// Get the amount of tokens to refund based on returned signal
uint256 tokensOut = signalToTokens(_subgraphDeploymentID, _signalIn);
Expand Down Expand Up @@ -277,12 +260,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @return Amount of token reserves in the curation pool
*/
function getCurationPoolTokens(bytes32 _subgraphDeploymentID)
external
view
override
returns (uint256)
{
function getCurationPoolTokens(bytes32 _subgraphDeploymentID) external view override returns (uint256) {
return pools[_subgraphDeploymentID].tokens;
}

Expand All @@ -301,12 +279,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of signal owned by a curator for the subgraph deployment
*/
function getCuratorSignal(address _curator, bytes32 _subgraphDeploymentID)
public
view
override
returns (uint256)
{
function getCuratorSignal(address _curator, bytes32 _subgraphDeploymentID) public view override returns (uint256) {
IGraphCurationToken gcs = pools[_subgraphDeploymentID].gcs;
return (address(gcs) == address(0)) ? 0 : gcs.balanceOf(_curator);
}
Expand All @@ -316,12 +289,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @return Amount of signal minted for the subgraph deployment
*/
function getCurationPoolSignal(bytes32 _subgraphDeploymentID)
public
view
override
returns (uint256)
{
function getCurationPoolSignal(bytes32 _subgraphDeploymentID) public view override returns (uint256) {
IGraphCurationToken gcs = pools[_subgraphDeploymentID].gcs;
return (address(gcs) == address(0)) ? 0 : gcs.totalSupply();
}
Expand All @@ -334,12 +302,10 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @return Amount of signal that can be bought
* @return Amount of tokens that will be burned as curation tax
*/
function tokensToSignal(bytes32 _subgraphDeploymentID, uint256 _tokensIn)
public
view
override
returns (uint256, uint256)
{
function tokensToSignal(
bytes32 _subgraphDeploymentID,
uint256 _tokensIn
) public view override returns (uint256, uint256) {
// NOTE: We're aware that this function rounds down and tax can be 0 for small amounts
// of tokens but since minimumCurationDeposit is 1 GRT tax will always be greater than 0.
uint256 curationTax = _tokensIn.mul(uint256(curationTaxPercentage)).div(MAX_PPM);
Expand All @@ -353,20 +319,13 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @param _tokensIn Amount of tokens used to mint signal
* @return Amount of signal that can be bought with tokens
*/
function _tokensToSignal(bytes32 _subgraphDeploymentID, uint256 _tokensIn)
private
view
returns (uint256)
{
function _tokensToSignal(bytes32 _subgraphDeploymentID, uint256 _tokensIn) private view returns (uint256) {
// Get curation pool tokens and signal
CurationPool memory curationPool = pools[_subgraphDeploymentID];

// Init curation pool
if (curationPool.tokens == 0) {
require(
_tokensIn >= minimumCurationDeposit,
"Curation deposit is below minimum required"
);
require(_tokensIn >= minimumCurationDeposit, "Curation deposit is below minimum required");
return
BancorFormula(bondingCurve)
.calculatePurchaseReturn(
Expand All @@ -393,22 +352,11 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @param _signalIn Amount of signal to burn
* @return Amount of tokens to get for the specified amount of signal
*/
function signalToTokens(bytes32 _subgraphDeploymentID, uint256 _signalIn)
public
view
override
returns (uint256)
{
function signalToTokens(bytes32 _subgraphDeploymentID, uint256 _signalIn) public view override returns (uint256) {
CurationPool memory curationPool = pools[_subgraphDeploymentID];
uint256 curationPoolSignal = getCurationPoolSignal(_subgraphDeploymentID);
require(
curationPool.tokens != 0,
"Subgraph deployment must be curated to perform calculations"
);
require(
curationPoolSignal >= _signalIn,
"Signal must be above or equal to signal issued in the curation pool"
);
require(curationPool.tokens != 0, "Subgraph deployment must be curated to perform calculations");
require(curationPoolSignal >= _signalIn, "Signal must be above or equal to signal issued in the curation pool");

return
BancorFormula(bondingCurve).calculateSaleReturn(
Expand All @@ -427,10 +375,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
function _setDefaultReserveRatio(uint32 _defaultReserveRatio) private {
// Reserve Ratio must be within 0% to 100% (inclusive, in PPM)
require(_defaultReserveRatio != 0, "Default reserve ratio must be > 0");
require(
_defaultReserveRatio <= MAX_PPM,
"Default reserve ratio cannot be higher than MAX_PPM"
);
require(_defaultReserveRatio <= MAX_PPM, "Default reserve ratio cannot be higher than MAX_PPM");

defaultReserveRatio = _defaultReserveRatio;
emit ParameterUpdated("defaultReserveRatio");
Expand All @@ -453,10 +398,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
* @param _percentage Curation tax charged when depositing GRT tokens in PPM
*/
function _setCurationTaxPercentage(uint32 _percentage) private {
require(
_percentage <= MAX_PPM,
"Curation tax percentage must be below or equal to MAX_PPM"
);
require(_percentage <= MAX_PPM, "Curation tax percentage must be below or equal to MAX_PPM");

curationTaxPercentage = _percentage;
emit ParameterUpdated("curationTaxPercentage");
Expand All @@ -468,10 +410,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {
*/
function _setCurationTokenMaster(address _curationTokenMaster) private {
require(_curationTokenMaster != address(0), "Token master must be non-empty");
require(
AddressUpgradeable.isContract(_curationTokenMaster),
"Token master must be a contract"
);
require(AddressUpgradeable.isContract(_curationTokenMaster), "Token master must be a contract");

curationTokenMaster = _curationTokenMaster;
emit ParameterUpdated("curationTokenMaster");
Expand Down
21 changes: 4 additions & 17 deletions packages/contracts/contracts/curation/ICuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ interface ICuration {
* @param _tokensOutMin Expected minimum amount of tokens to receive
* @return Tokens returned
*/
function burn(
bytes32 _subgraphDeploymentID,
uint256 _signalIn,
uint256 _tokensOutMin
) external returns (uint256);
function burn(bytes32 _subgraphDeploymentID, uint256 _signalIn, uint256 _tokensOutMin) external returns (uint256);

/**
* @notice Assign Graph Tokens collected as curation fees to the curation pool reserve.
Expand All @@ -84,10 +80,7 @@ interface ICuration {
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of signal owned by a curator for the subgraph deployment
*/
function getCuratorSignal(address _curator, bytes32 _subgraphDeploymentID)
external
view
returns (uint256);
function getCuratorSignal(address _curator, bytes32 _subgraphDeploymentID) external view returns (uint256);

/**
* @notice Get the amount of signal in a curation pool.
Expand All @@ -111,21 +104,15 @@ interface ICuration {
* @return Amount of signal that can be bought
* @return Amount of tokens that will be burned as curation tax
*/
function tokensToSignal(bytes32 _subgraphDeploymentID, uint256 _tokensIn)
external
view
returns (uint256, uint256);
function tokensToSignal(bytes32 _subgraphDeploymentID, uint256 _tokensIn) external view returns (uint256, uint256);

/**
* @notice Calculate number of tokens to get when burning signal from a curation pool.
* @param _subgraphDeploymentID Subgraph deployment to burn signal
* @param _signalIn Amount of signal to burn
* @return Amount of tokens to get for the specified amount of signal
*/
function signalToTokens(bytes32 _subgraphDeploymentID, uint256 _signalIn)
external
view
returns (uint256);
function signalToTokens(bytes32 _subgraphDeploymentID, uint256 _signalIn) external view returns (uint256);

/**
* @notice Tax charged when curators deposit funds.
Expand Down
Loading

0 comments on commit 41a4c97

Please sign in to comment.