diff --git a/src/providers/abstract-provider.ts b/src/providers/abstract-provider.ts index 679c2099..9d8cf031 100644 --- a/src/providers/abstract-provider.ts +++ b/src/providers/abstract-provider.ts @@ -861,9 +861,44 @@ export class AbstractProvider implements Provider { * @returns {Promise} A promise that resolves to the protocol expansion number. */ async getProtocolExpansionNumber(): Promise { - return await this.#perform({ - method: 'getProtocolExpansionNumber', - }); + return getNumber(await this.#perform({ method: 'getProtocolExpansionNumber' })); + } + + /** + * Get the active region shards based on the protocol expansion number. + * + * @returns {Promise} A promise that resolves to the active shards. + */ + async getActiveRegions(): Promise { + const protocolExpansionNumber = await this.getProtocolExpansionNumber(); + const shards = [Shard.Cyprus]; + if (protocolExpansionNumber >= 1) { + shards.push(Shard.Paxos); + } + if (protocolExpansionNumber >= 3) { + shards.push(Shard.Hydra); + } + return shards.sort((a: Shard, b: Shard) => a.localeCompare(b)); + } + + /** + * Get the active zones for a shard based on the protocol expansion number. + * + * @returns {Promise} A promise that resolves to the active zones. + */ + async getActiveZones(): Promise { + const protocolExpansionNumber = await this.getProtocolExpansionNumber(); + const zones = [Zone.Cyprus1]; + if (protocolExpansionNumber >= 1) { + zones.push(Zone.Cyprus2); + } + if (protocolExpansionNumber >= 2) { + zones.push(Zone.Paxos1, Zone.Paxos2); + } + if (protocolExpansionNumber >= 3) { + zones.push(Zone.Cyprus3, Zone.Paxos3, Zone.Hydra1, Zone.Hydra2, Zone.Hydra3); + } + return zones.sort((a: Zone, b: Zone) => a.localeCompare(b)); } /**