From 6ef222a572bd67d92903648c2c772790b9c33a22 Mon Sep 17 00:00:00 2001 From: Defi Dev Date: Wed, 13 Dec 2023 18:19:49 +0000 Subject: [PATCH] improve agent version check --- app/App.ts | 4 ++-- app/agents/AbstractAgent.ts | 5 ++--- app/agents/Agent.2.2.0.light.ts | 6 ++---- app/agents/Agent.2.3.0.randao.ts | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/App.ts b/app/App.ts index a311fb9..b7c84e2 100644 --- a/app/App.ts +++ b/app/App.ts @@ -108,9 +108,9 @@ export class App { } let agent; - if (version === '2.3.0' && strategy === 'randao') { + if (version.startsWith('2.') && strategy === 'randao') { agent = new AgentRandao_2_3_0(checksummedAddress, agentConfig, networkName); - } else if (version === '2.2.0' && strategy === 'light') { + } else if (version.startsWith('2.') && strategy === 'light') { agent = new AgentLight_2_2_0(checksummedAddress, agentConfig, networkName); } else { throw new Error( diff --git a/app/agents/AbstractAgent.ts b/app/agents/AbstractAgent.ts index 26b21d3..cc22b87 100644 --- a/app/agents/AbstractAgent.ts +++ b/app/agents/AbstractAgent.ts @@ -69,7 +69,7 @@ export abstract class AbstractAgent implements IAgent { // blacklisting by a job key protected blacklistedJobs: Set; - abstract _getSupportedAgentVersions(): string[]; + abstract _isVersionSupported(version): boolean; protected toString(): string { return `(network: ${this.networkName}, address: ${this.address}, keeperId: ${this.keeperId || 'Fetching...'})`; @@ -184,7 +184,7 @@ export abstract class AbstractAgent implements IAgent { // Ensure version matches // TODO: extract check const version = await this.queryContractVersion(); - if (!this._getSupportedAgentVersions().includes(version)) { + if (!this._isVersionSupported(version)) { throw this.err(`Invalid version: ${version}`); } @@ -401,7 +401,6 @@ export abstract class AbstractAgent implements IAgent { workerAddress: this.keyAddress, keeperId: this.keeperId, keeperConfigNumeric: this.keeperConfig, - supportedAgentVersions: this._getSupportedAgentVersions(), fullSyncFrom: this.fullSyncFrom, minKeeperCvpWei: this.minKeeperCvp?.toString(), minKeeperCvp: weiValueToEth(this.minKeeperCvp), diff --git a/app/agents/Agent.2.2.0.light.ts b/app/agents/Agent.2.2.0.light.ts index 4b80043..0bac131 100644 --- a/app/agents/Agent.2.2.0.light.ts +++ b/app/agents/Agent.2.2.0.light.ts @@ -6,10 +6,8 @@ export class AgentLight_2_2_0 extends AbstractAgent { // jobKey => keeper private assignedKeepers: Map; - // jobKeys - - _getSupportedAgentVersions(): string[] { - return ['2.2.0']; + _isVersionSupported(version): boolean { + return version.startsWith('2.'); } async _beforeInit() { diff --git a/app/agents/Agent.2.3.0.randao.ts b/app/agents/Agent.2.3.0.randao.ts index 85a5a06..915532e 100644 --- a/app/agents/Agent.2.3.0.randao.ts +++ b/app/agents/Agent.2.3.0.randao.ts @@ -14,8 +14,8 @@ export class AgentRandao_2_3_0 extends AbstractAgent implements IRandaoAgent { private jobMinCreditsFinney: bigint; - _getSupportedAgentVersions(): string[] { - return ['2.3.0']; + _isVersionSupported(version): boolean { + return version.startsWith('2.'); } async _beforeInit() {