@@ -1154,6 +1154,14 @@ export function updateDelegationExchangeRateForProvision(provision: Provision):
11541154// TODO - this is broken if we change the delegatio ratio
11551155// Need to remove, or find a fix
11561156export function calculateCapacities ( indexer : Indexer ) : Indexer {
1157+ if ( indexer . provisionedTokens . gt ( BigInt . fromI32 ( 0 ) ) ) {
1158+ return calculateCapacitiesHorizon ( indexer )
1159+ } else {
1160+ return calculateCapacitiesLegacy ( indexer )
1161+ }
1162+ }
1163+
1164+ export function calculateCapacitiesHorizon ( indexer : Indexer ) : Indexer {
11571165 let graphNetwork = GraphNetwork . load ( '1' ) !
11581166 let tokensDelegatedMax = indexer . provisionedTokens . times ( BigInt . fromI32 ( graphNetwork . delegationRatio ) )
11591167
@@ -1170,6 +1178,21 @@ export function calculateCapacities(indexer: Indexer): Indexer {
11701178 return indexer
11711179}
11721180
1181+ export function calculateCapacitiesLegacy ( indexer : Indexer ) : Indexer {
1182+ let graphNetwork = GraphNetwork . load ( '1' ) !
1183+ let tokensDelegatedMax = indexer . stakedTokens . times ( BigInt . fromI32 ( graphNetwork . delegationRatio ) )
1184+
1185+ // Eligible to add to the capacity
1186+ indexer . delegatedCapacity =
1187+ indexer . delegatedTokens < tokensDelegatedMax ? indexer . delegatedTokens : tokensDelegatedMax
1188+
1189+ indexer . tokenCapacity = indexer . stakedTokens . plus ( indexer . delegatedCapacity )
1190+ indexer . availableStake = indexer . tokenCapacity
1191+ . minus ( indexer . allocatedTokens )
1192+ . minus ( indexer . lockedTokens )
1193+ return indexer
1194+ }
1195+
11731196export function calculatePricePerShare ( deployment : SubgraphDeployment ) : BigDecimal {
11741197 // TODO check why there's a deviation from the values of the bancor formula
11751198 // Ideally this would be a 1 to 1 recreation of the share sell formula, but due to
0 commit comments