Skip to content

Commit 595af0e

Browse files
committed
Use Map to maintain delegator environment overrides
1 parent 28eb39e commit 595af0e

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

packages/delegation-toolkit/src/delegatorEnvironment.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,10 @@ import { deployContract } from './write';
4747
type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
4848
export const PREFERRED_VERSION: SupportedVersion = '1.3.0';
4949

50-
type DeployedEnvironments = Record<
51-
SupportedVersion,
52-
Record<number, DeleGatorEnvironment>
53-
>;
50+
const contractOverrideMap: Map<string, DeleGatorEnvironment> = new Map();
5451

55-
const contractOverrides: DeployedEnvironments = {
56-
'1.0.0': {},
57-
'1.1.0': {},
58-
'1.2.0': {},
59-
'1.3.0': {},
60-
};
52+
const getContractOverrideKey = (chainId: number, version: SupportedVersion) =>
53+
`${version}:${chainId}`;
6154

6255
/**
6356
* Overrides the deployed environment for a specific chain and version.
@@ -70,7 +63,10 @@ export function overrideDeployedEnvironment(
7063
version: SupportedVersion,
7164
environment: DeleGatorEnvironment,
7265
) {
73-
contractOverrides[version][chainId] = environment;
66+
contractOverrideMap.set(
67+
getContractOverrideKey(chainId, version),
68+
environment,
69+
);
7470
}
7571

7672
/**
@@ -83,9 +79,10 @@ export function getDeleGatorEnvironment(
8379
chainId: number,
8480
version: SupportedVersion = PREFERRED_VERSION,
8581
) {
86-
const override = contractOverrides[version][chainId];
87-
if (override) {
88-
return override;
82+
const overrideKey = getContractOverrideKey(chainId, version);
83+
84+
if (contractOverrideMap.has(overrideKey)) {
85+
return contractOverrideMap.get(overrideKey);
8986
}
9087

9188
const contracts = DELEGATOR_CONTRACTS[version]?.[chainId];

0 commit comments

Comments
 (0)