Skip to content

Commit

Permalink
chore: use delegation ratio in getTokensAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranzav committed May 17, 2024
1 parent 83b73ae commit 83540af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 13 additions & 5 deletions packages/horizon/contracts/HorizonStakingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StakingBackwardsCompatibility } from "./StakingBackwardsCompatibility.s
import { IL2StakingBase } from "@graphprotocol/contracts/contracts/l2/staking/IL2StakingBase.sol";
import { IL2StakingTypes } from "@graphprotocol/contracts/contracts/l2/staking/IL2StakingTypes.sol";
import { IHorizonStakingExtension } from "./IHorizonStakingExtension.sol";
import { MathUtils } from "./utils/MathUtils.sol";

/**
* @title L2Staking contract
Expand Down Expand Up @@ -62,11 +63,18 @@ contract HorizonStakingExtension is StakingBackwardsCompatibility, IHorizonStaki
}

// provisioned tokens that are not being thawed (including provider tokens and delegation)
function getTokensAvailable(address _serviceProvider, address _verifier) external view override returns (uint256) {
return
provisions[_serviceProvider][_verifier].tokens -
provisions[_serviceProvider][_verifier].tokensThawing +
getDelegatedTokensAvailable(_serviceProvider, _verifier);
function getTokensAvailable(
address _serviceProvider,
address _verifier,
uint32 _delegationRatio
) external view override returns (uint256) {
uint256 providerTokens = provisions[_serviceProvider][_verifier].tokens;
uint256 tokensDelegatedMax = providerTokens * (uint256(_delegationRatio));
uint256 tokensDelegatedCapacity = MathUtils.min(
getDelegatedTokensAvailable(_serviceProvider, _verifier),
tokensDelegatedMax
);
return providerTokens - provisions[_serviceProvider][_verifier].tokensThawing + tokensDelegatedCapacity;
}

function getServiceProvider(address serviceProvider) external view override returns (ServiceProvider memory) {
Expand Down
6 changes: 5 additions & 1 deletion packages/horizon/contracts/IHorizonStakingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ interface IHorizonStakingExtension {
function getStake(address serviceProvider) external view returns (uint256);

function getDelegatedTokensAvailable(address _serviceProvider, address _verifier) external view returns (uint256);
function getTokensAvailable(address _serviceProvider, address _verifier) external view returns (uint256);
function getTokensAvailable(
address _serviceProvider,
address _verifier,
uint32 _delegationRatio
) external view returns (uint256);

function getServiceProvider(
address serviceProvider
Expand Down

0 comments on commit 83540af

Please sign in to comment.