Skip to content

Commit

Permalink
chore: lint horizon package
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed May 20, 2024
1 parent 6165dc9 commit fe747d1
Show file tree
Hide file tree
Showing 22 changed files with 953 additions and 943 deletions.
20 changes: 10 additions & 10 deletions packages/horizon/contracts/GraphDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ contract GraphDirectory {
address public immutable GRAPH_PAYMENTS;
address public immutable GRAPH_ESCROW;

constructor(address _controller) {
CONTROLLER = _controller;
STAKING = IController(_controller).getContractProxy(keccak256("Staking"));
EPOCH_MANAGER = IController(_controller).getContractProxy(keccak256("EpochManager"));
GRAPH_TOKEN = IController(_controller).getContractProxy(keccak256("GraphToken"));
GRAPH_TOKEN_GATEWAY = IController(_controller).getContractProxy(keccak256("GraphTokenGateway"));
REWARDS_MANAGER = IController(_controller).getContractProxy(keccak256("RewardsManager"));
CURATION = IController(_controller).getContractProxy(keccak256("Curation"));
GRAPH_PAYMENTS = IController(_controller).getContractProxy(keccak256("GraphPayments"));
GRAPH_ESCROW = IController(_controller).getContractProxy(keccak256("GraphEscrow"));
constructor(address controller) {
CONTROLLER = controller;
STAKING = IController(controller).getContractProxy(keccak256("Staking"));
EPOCH_MANAGER = IController(controller).getContractProxy(keccak256("EpochManager"));
GRAPH_TOKEN = IController(controller).getContractProxy(keccak256("GraphToken"));
GRAPH_TOKEN_GATEWAY = IController(controller).getContractProxy(keccak256("GraphTokenGateway"));
REWARDS_MANAGER = IController(controller).getContractProxy(keccak256("RewardsManager"));
CURATION = IController(controller).getContractProxy(keccak256("Curation"));
GRAPH_PAYMENTS = IController(controller).getContractProxy(keccak256("GraphPayments"));
GRAPH_ESCROW = IController(controller).getContractProxy(keccak256("GraphEscrow"));
}
}
50 changes: 26 additions & 24 deletions packages/horizon/contracts/escrow/GraphEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ import { GraphEscrowStorageV1Storage } from "./GraphEscrowStorage.sol";
import { TokenUtils } from "../libraries/TokenUtils.sol";

contract GraphEscrow is IGraphEscrow, GraphEscrowStorageV1Storage, GraphDirectory {
// -- Errors --

error GraphEscrowNotGraphPayments();
error GraphEscrowInputsLengthMismatch();
error GraphEscrowInsufficientThawAmount();
error GraphEscrowInsufficientAmount(uint256 available, uint256 required);
error GraphEscrowNotThawing();
error GraphEscrowStillThawing(uint256 currentTimestamp, uint256 thawEndTimestamp);
error GraphEscrowThawingPeriodTooLong(uint256 thawingPeriod, uint256 maxThawingPeriod);
error GraphEscrowCollectorNotAuthorized(address sender, address dataService);
error GraphEscrowCollectorInsufficientAmount(uint256 available, uint256 required);

// -- Events --

event AuthorizedCollector(address indexed sender, address indexed dataService);
Expand All @@ -39,23 +27,35 @@ contract GraphEscrow is IGraphEscrow, GraphEscrowStorageV1Storage, GraphDirector
event Withdraw(address indexed sender, address indexed receiver, uint256 amount);
event Collect(address indexed sender, address indexed receiver, uint256 amount);

// -- Errors --

error GraphEscrowNotGraphPayments();
error GraphEscrowInputsLengthMismatch();
error GraphEscrowInsufficientThawAmount();
error GraphEscrowInsufficientAmount(uint256 available, uint256 required);
error GraphEscrowNotThawing();
error GraphEscrowStillThawing(uint256 currentTimestamp, uint256 thawEndTimestamp);
error GraphEscrowThawingPeriodTooLong(uint256 thawingPeriod, uint256 maxThawingPeriod);
error GraphEscrowCollectorNotAuthorized(address sender, address dataService);
error GraphEscrowCollectorInsufficientAmount(uint256 available, uint256 required);

// -- Constructor --

constructor(
address _controller,
uint256 _revokeCollectorThawingPeriod,
uint256 _withdrawEscrowThawingPeriod
) GraphDirectory(_controller) {
if (_revokeCollectorThawingPeriod > MAX_THAWING_PERIOD) {
revert GraphEscrowThawingPeriodTooLong(_revokeCollectorThawingPeriod, MAX_THAWING_PERIOD);
address controller,
uint256 revokeCollectorThawingPeriod,
uint256 withdrawEscrowThawingPeriod
) GraphDirectory(controller) {
if (revokeCollectorThawingPeriod > MAX_THAWING_PERIOD) {
revert GraphEscrowThawingPeriodTooLong(revokeCollectorThawingPeriod, MAX_THAWING_PERIOD);
}

if (_withdrawEscrowThawingPeriod > MAX_THAWING_PERIOD) {
revert GraphEscrowThawingPeriodTooLong(_withdrawEscrowThawingPeriod, MAX_THAWING_PERIOD);
if (withdrawEscrowThawingPeriod > MAX_THAWING_PERIOD) {
revert GraphEscrowThawingPeriodTooLong(withdrawEscrowThawingPeriod, MAX_THAWING_PERIOD);
}

revokeCollectorThawingPeriod = _revokeCollectorThawingPeriod;
withdrawEscrowThawingPeriod = _withdrawEscrowThawingPeriod;
revokeCollectorThawingPeriod = revokeCollectorThawingPeriod;
withdrawEscrowThawingPeriod = withdrawEscrowThawingPeriod;
}

// approve a data service to collect funds
Expand All @@ -67,7 +67,9 @@ contract GraphEscrow is IGraphEscrow, GraphEscrowStorageV1Storage, GraphDirector

// thaw a data service's collector authorization
function thawCollector(address dataService) external {
authorizedCollectors[msg.sender][dataService].thawEndTimestamp = block.timestamp + revokeCollectorThawingPeriod;
authorizedCollectors[msg.sender][dataService].thawEndTimestamp =
block.timestamp +
REVOKE_COLLECTOR_THAWING_PERIOD;
emit ThawCollector(msg.sender, dataService);
}

Expand Down Expand Up @@ -147,7 +149,7 @@ contract GraphEscrow is IGraphEscrow, GraphEscrowStorageV1Storage, GraphDirector
// Set amount to thaw
account.amountThawing = amount;
// Set when the thaw is complete (thawing period number of seconds after current timestamp)
account.thawEndTimestamp = block.timestamp + withdrawEscrowThawingPeriod;
account.thawEndTimestamp = block.timestamp + WITHDRAW_ESCROW_THAWING_PERIOD;

emit Thaw(msg.sender, receiver, amount, account.amountThawing, account.thawEndTimestamp);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/contracts/escrow/GraphEscrowStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ contract GraphEscrowStorageV1Storage {
uint256 public constant MAX_THAWING_PERIOD = 90 days;

// Thawing period for authorized collectors
uint256 public immutable revokeCollectorThawingPeriod;
uint256 public immutable REVOKE_COLLECTOR_THAWING_PERIOD;

// The duration (in seconds) in which escrow funds are thawing before they can be withdrawn
uint256 public immutable withdrawEscrowThawingPeriod;
uint256 public immutable WITHDRAW_ESCROW_THAWING_PERIOD;
}
26 changes: 13 additions & 13 deletions packages/horizon/contracts/interfaces/IGraphToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ interface IGraphToken is IERC20 {

function burn(uint256 amount) external;

function burnFrom(address _from, uint256 amount) external;
function burnFrom(address from, uint256 amount) external;

function mint(address _to, uint256 _amount) external;
function mint(address to, uint256 amount) external;

// -- Mint Admin --

function addMinter(address _account) external;
function addMinter(address account) external;

function removeMinter(address _account) external;
function removeMinter(address account) external;

function renounceMinter() external;

function isMinter(address _account) external view returns (bool);

// -- Permit --

function permit(
address _owner,
address _spender,
uint256 _value,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;

// -- Allowance --

function increaseAllowance(address spender, uint256 addedValue) external returns (bool);

function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);

function isMinter(address account) external view returns (bool);
}
122 changes: 59 additions & 63 deletions packages/horizon/contracts/interfaces/IHorizonStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ interface IHorizonStakingBase is IHorizonStakingTypes {
);

// deposit stake
function stake(uint256 _tokens) external;
function stake(uint256 tokens) external;

function stakeTo(address _serviceProvider, uint256 _tokens) external;
function stakeTo(address serviceProvider, uint256 tokens) external;

// can be called by anyone if the indexer has provisioned stake to this verifier
function stakeToProvision(address _serviceProvider, address _verifier, uint256 _tokens) external;
function stakeToProvision(address serviceProvider, address verifier, uint256 tokens) external;

// create a provision
function provision(
address _serviceProvider,
address _verifier,
uint256 _tokens,
uint32 _maxVerifierCut,
uint64 _thawingPeriod
address serviceProvider,
address verifier,
uint256 tokens,
uint32 maxVerifierCut,
uint64 thawingPeriod
) external;

/**
Expand All @@ -135,102 +135,98 @@ interface IHorizonStakingBase is IHorizonStakingTypes {
* service, where the data service is the verifier. Only authorized verifiers can be used.
* This function can be called by the service provider or by an operator authorized by the provider
* for this specific verifier.
* @param _serviceProvider The service provider address
* @param _verifier The verifier address for which the tokens are provisioned (who will be able to slash the tokens)
* @param _tokens The amount of tokens that will be locked and slashable
* @param _maxVerifierCut The maximum cut, expressed in PPM, that a verifier can transfer instead of burning when slashing
* @param _thawingPeriod The period in seconds that the tokens will be thawing before they can be removed from the provision
* @param serviceProvider The service provider address
* @param verifier The verifier address for which the tokens are provisioned (who will be able to slash the tokens)
* @param tokens The amount of tokens that will be locked and slashable
* @param maxVerifierCut The maximum cut, expressed in PPM, that a verifier can transfer instead of burning when slashing
* @param thawingPeriod The period in seconds that the tokens will be thawing before they can be removed from the provision
*/
function provisionLocked(
address _serviceProvider,
address _verifier,
uint256 _tokens,
uint32 _maxVerifierCut,
uint64 _thawingPeriod
address serviceProvider,
address verifier,
uint256 tokens,
uint32 maxVerifierCut,
uint64 thawingPeriod
) external;

// initiate a thawing to remove tokens from a provision
function thaw(address _serviceProvider, address _verifier, uint256 _tokens) external returns (bytes32);
function thaw(address serviceProvider, address verifier, uint256 tokens) external returns (bytes32);

// add more tokens from idle stake to an existing provision
function addToProvision(address _serviceProvider, address _verifier, uint256 _tokens) external;
function addToProvision(address serviceProvider, address verifier, uint256 tokens) external;

// moves thawed stake from a provision back into the provider's available stake
function deprovision(address _serviceProvider, address _verifier, uint256 _tokens) external;
function deprovision(address serviceProvider, address verifier, uint256 tokens) external;

// moves thawed stake from one provision into another provision
function reprovision(
address _serviceProvider,
address _oldVerifier,
address _newVerifier,
uint256 _tokens
) external;
function reprovision(address serviceProvider, address oldVerifier, address newVerifier, uint256 tokens) external;

// moves thawed stake back to the owner's account - stake is removed from the protocol
function unstake(uint256 _tokens) external;
function unstake(uint256 tokens) external;

// delegate tokens to a provider on a data service
function delegate(address _serviceProvider, address _verifier, uint256 _tokens, uint256 _minSharesOut) external;
function delegate(address serviceProvider, address verifier, uint256 tokens, uint256 minSharesOut) external;

// undelegate (thaw) delegated tokens from a provision
function undelegate(address _serviceProvider, address _verifier, uint256 _shares) external;
function undelegate(address serviceProvider, address verifier, uint256 shares) external;

// withdraw delegated tokens after thawing
function withdrawDelegated(
address _serviceProvider,
address _verifier,
address _newServiceProvider,
uint256 _minSharesForNewProvider
address serviceProvider,
address verifier,
address newServiceProvider,
uint256 minSharesForNewProvider
) external;

function slash(
address _serviceProvider,
uint256 _tokens,
uint256 _verifierCutAmount,
address _verifierCutDestination
address serviceProvider,
uint256 tokens,
uint256 verifierCutAmount,
address verifierCutDestination
) external;

// staked tokens that are currently not provisioned, aka idle stake
// `getStake(serviceProvider) - ServiceProvider.tokensProvisioned`
function getIdleStake(address _serviceProvider) external view returns (uint256 tokens);

/**
* @notice Withdraw indexer tokens once the thawing period has passed.
* @dev This is only needed during the transition period while we still have
* a global lock. After that, unstake() will also withdraw.
*/
function withdraw() external;

function setDelegationSlashingEnabled(bool _enabled) external;
function setDelegationSlashingEnabled(bool enabled) external;

/**
* @notice Check if an operator is authorized for the caller on a specific verifier / data service.
* @param _operator The address to check for auth
* @param _serviceProvider The service provider on behalf of whom they're claiming to act
* @param _verifier The verifier / data service on which they're claiming to act
*/
function isAuthorized(address _operator, address _serviceProvider, address _verifier) external view returns (bool);

function getProviderTokensAvailable(address _serviceProvider, address _verifier) external view returns (uint256);
function setMaxThawingPeriod(uint64 _maxThawingPeriod) external;
function setMaxThawingPeriod(uint64 maxThawingPeriod) external;

function setAllowedLockedVerifier(address _verifier, bool _allowed) external;
function setAllowedLockedVerifier(address verifier, bool allowed) external;

/**
* @notice Add tokens to a delegation pool (without getting shares).
* Used by data services to pay delegation fees/rewards.
* @param _serviceProvider The service provider address
* @param _verifier The verifier address for which the tokens are provisioned
* @param _tokens The amount of tokens to add to the delegation pool
* @param serviceProvider The service provider address
* @param verifier The verifier address for which the tokens are provisioned
* @param tokens The amount of tokens to add to the delegation pool
*/
function addToDelegationPool(address _serviceProvider, address _verifier, uint256 _tokens) external;
function addToDelegationPool(address serviceProvider, address verifier, uint256 tokens) external;

function setProvisionParameters(
address _serviceProvider,
address _verifier,
uint32 _maxVerifierCut,
uint64 _thawingPeriod
address serviceProvider,
address verifier,
uint32 maxVerifierCut,
uint64 thawingPeriod
) external;

function acceptProvisionParameters(address _serviceProvider) external;
function acceptProvisionParameters(address serviceProvider) external;

// staked tokens that are currently not provisioned, aka idle stake
// `getStake(serviceProvider) - ServiceProvider.tokensProvisioned`
function getIdleStake(address serviceProvider) external view returns (uint256 tokens);

/**
* @notice Check if an operator is authorized for the caller on a specific verifier / data service.
* @param operator The address to check for auth
* @param serviceProvider The service provider on behalf of whom they're claiming to act
* @param verifier The verifier / data service on which they're claiming to act
*/
function isAuthorized(address operator, address serviceProvider, address verifier) external view returns (bool);

function getProviderTokensAvailable(address serviceProvider, address verifier) external view returns (uint256);
}
Loading

0 comments on commit fe747d1

Please sign in to comment.