Skip to content

Commit

Permalink
chore: add first draft IHorizonStaking
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranzav committed Feb 20, 2024
1 parent b3b59db commit de1cb2d
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 25 deletions.
157 changes: 157 additions & 0 deletions packages/contracts/contracts/staking/IHorizonStaking.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity 0.7.6;
pragma abicoder v2;

interface IHorizonStaking {
struct Provision {
// Service provider that created the provision
address serviceProvider;
// tokens in the provision
uint256 tokens;
// tokens that are being thawed (and will stop being slashable soon)
uint256 tokensThawing;
// timestamp of provision creation
uint64 createdAt;
// authority to slash the provision
address verifier;
// max amount that can be taken by the verifier when slashing, expressed in parts-per-million of the amount slashed
uint32 maxVerifierCut;
// time, in seconds, tokens must thaw before being withdrawn
uint64 thawingPeriod;
}

// the new "Indexer" struct
struct ServiceProviderInternal {
// Tokens on the Service Provider stake (staked by the provider)
uint256 tokensStaked;
// Tokens used in allocations
uint256 __DEPRECATED_tokensAllocated;
// Tokens locked for withdrawal subject to thawing period
uint256 __DEPRECATED_tokensLocked;
// Block when locked tokens can be withdrawn
uint256 __DEPRECATED_tokensLockedUntil;
// tokens used in a provision
uint256 tokensProvisioned;
// tokens that initiated a thawing in any one of the provider's provisions
uint256 tokensRequestedThaw;
// tokens that have been removed from any one of the provider's provisions after thawing
uint256 tokensFulfilledThaw;
// provisions that take priority for undelegation force thawing
bytes32[] forceThawProvisions;
}

struct ServiceProvider {
// Tokens on the provider stake (staked by the provider)
uint256 tokensStaked;
// tokens used in a provision
uint256 tokensProvisioned;
// tokens that initiated a thawing in any one of the provider's provisions
uint256 tokensRequestedThaw;
// tokens that have been removed from any one of the provider's provisions after thawing
uint256 tokensFulfilledThaw;
// provisions that take priority for undelegation force thawing
bytes32[] forceThawProvisions;
}

struct DelegationPool {
uint32 __DEPRECATED_cooldownBlocks; // solhint-disable-line var-name-mixedcase
uint32 __DEPRECATED_indexingRewardCut; // in PPM
uint32 __DEPRECATED_queryFeeCut; // in PPM
uint256 __DEPRECATED_updatedAtBlock; // Block when the pool was last updated
uint256 tokens; // Total tokens as pool reserves
uint256 shares; // Total shares minted in the pool
mapping(address => Delegation) delegators; // Mapping of delegator => Delegation
}

struct Delegation {
// shares owned by the delegator in the pool
uint256 shares;
// tokens delegated to the pool
uint256 tokens;
// Timestamp when locked tokens can be undelegated (after the timelock)
uint256 tokensLockedUntil;
}

struct ThawRequest {
// tokens that are being thawed by this request
uint256 tokens;
// the provision id to which this request corresponds to
bytes32 provisionId;
// the address that initiated the thaw request, allowed to remove the funds once thawed
address owner;
// the timestamp when the thawed funds can be removed from the provision
uint64 thawingUntil;
// the value of `ServiceProvider.tokensRequestedThaw` the moment the thaw request is created
uint256 tokensRequestedThawSnapshot;
}

// whitelist/deny a verifier
function allowVerifier(address verifier, bool allow) external;

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

// create a provision
function provision(
uint256 tokens,
address verifier,
uint256 maxVerifierCut,
uint256 thawingPeriod
) external;

// initiate a thawing to remove tokens from a provision
function thaw(bytes32 provisionId, uint256 tokens) external returns (bytes32);

// moves thawed stake from a provision back into the provider's available stake
function deprovision(bytes32 thawRequestId) external;

// moves thawed stake from one provision into another provision
function reprovision(bytes32 thawRequestId, bytes32 provisionId) external;

// moves thawed stake back to the owner's account - stake is removed from the protocol
function withdraw(bytes32 thawRequestId) external;

// delegate tokens to a provider
function delegate(address serviceProvider, uint256 tokens) external;

// undelegate tokens
function undelegate(
address serviceProvider,
uint256 tokens,
bytes32[] provisions
) external returns (bytes32[]);

// slash a service provider
function slash(
bytes32 provisionId,
uint256 tokens,
uint256 verifierAmount
) external;

// set the Service Provider's preferred provisions to be force thawed
function setForceThawProvisions(bytes32[] provisions);

// total staked tokens to the provider
// `ServiceProvider.tokensStaked + DelegationPool.serviceProvider.tokens`
function getStake(address serviceProvider) public view returns (uint256 tokens);

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

// staked tokens the provider can provision before hitting the delegation cap
// `ServiceProvider.tokensStaked * Staking.delegationRatio - Provision.tokensProvisioned`
function getCapacity(address serviceProvider) public view returns (uint256);

// provisioned tokens that are not being used
// `Provision.tokens - Provision.tokensThawing`
function getTokensAvailable(bytes32 provision) public view returns (uint256 tokens);

function getServiceProvider(address serviceProvider)
public
view
returns (ServiceProvider memory);

function getProvision(bytes32 provision) public view returns (Provision memory);
}
50 changes: 25 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11343,31 +11343,6 @@ __metadata:
languageName: node
linkType: hard

"horizon@workspace:packages/horizon":
version: 0.0.0-use.local
resolution: "horizon@workspace:packages/horizon"
dependencies:
"@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.0"
"@nomicfoundation/hardhat-ethers": "npm:^3.0.0"
"@nomicfoundation/hardhat-network-helpers": "npm:^1.0.0"
"@nomicfoundation/hardhat-toolbox": "npm:^4.0.0"
"@nomicfoundation/hardhat-verify": "npm:^2.0.0"
"@typechain/ethers-v6": "npm:^0.5.0"
"@typechain/hardhat": "npm:^9.0.0"
"@types/chai": "npm:^4.2.0"
"@types/mocha": "npm:>=9.1.0"
"@types/node": "npm:>=16.0.0"
chai: "npm:^4.2.0"
ethers: "npm:^6.4.0"
hardhat: "npm:^2.20.1"
hardhat-gas-reporter: "npm:^1.0.8"
solidity-coverage: "npm:^0.8.0"
ts-node: "npm:>=8.0.0"
typechain: "npm:^8.3.0"
typescript: "npm:>=4.5.0"
languageName: unknown
linkType: soft

"hosted-git-info@npm:^2.1.4, hosted-git-info@npm:^2.6.0":
version: 2.8.9
resolution: "hosted-git-info@npm:2.8.9"
Expand Down Expand Up @@ -18366,6 +18341,31 @@ __metadata:
languageName: node
linkType: hard

"subgraph-service@workspace:packages/subgraph-service":
version: 0.0.0-use.local
resolution: "subgraph-service@workspace:packages/subgraph-service"
dependencies:
"@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.0"
"@nomicfoundation/hardhat-ethers": "npm:^3.0.0"
"@nomicfoundation/hardhat-network-helpers": "npm:^1.0.0"
"@nomicfoundation/hardhat-toolbox": "npm:^4.0.0"
"@nomicfoundation/hardhat-verify": "npm:^2.0.0"
"@typechain/ethers-v6": "npm:^0.5.0"
"@typechain/hardhat": "npm:^9.0.0"
"@types/chai": "npm:^4.2.0"
"@types/mocha": "npm:>=9.1.0"
"@types/node": "npm:>=16.0.0"
chai: "npm:^4.2.0"
ethers: "npm:^6.4.0"
hardhat: "npm:^2.20.1"
hardhat-gas-reporter: "npm:^1.0.8"
solidity-coverage: "npm:^0.8.0"
ts-node: "npm:>=8.0.0"
typechain: "npm:^8.3.0"
typescript: "npm:>=4.5.0"
languageName: unknown
linkType: soft

"supports-color@npm:8.1.1":
version: 8.1.1
resolution: "supports-color@npm:8.1.1"
Expand Down

0 comments on commit de1cb2d

Please sign in to comment.