Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions packages/delegation-toolkit/src/delegatorEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ import { deployContract } from './write';
type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
export const PREFERRED_VERSION: SupportedVersion = '1.3.0';

type DeployedEnvironments = Record<
SupportedVersion,
Record<number, DeleGatorEnvironment>
>;
const contractOverrideMap: Map<string, DeleGatorEnvironment> = new Map();

const contractOverrides: DeployedEnvironments = {
'1.0.0': {},
'1.1.0': {},
'1.2.0': {},
'1.3.0': {},
};
const getContractOverrideKey = (chainId: number, version: SupportedVersion) =>
`${version}:${chainId}`;

/**
* Overrides the deployed environment for a specific chain and version.
Expand All @@ -70,7 +63,10 @@ export function overrideDeployedEnvironment(
version: SupportedVersion,
environment: DeleGatorEnvironment,
) {
contractOverrides[version][chainId] = environment;
contractOverrideMap.set(
getContractOverrideKey(chainId, version),
environment,
);
}

/**
Expand All @@ -82,10 +78,12 @@ export function overrideDeployedEnvironment(
export function getDeleGatorEnvironment(
chainId: number,
version: SupportedVersion = PREFERRED_VERSION,
) {
const override = contractOverrides[version][chainId];
if (override) {
return override;
): DeleGatorEnvironment {
const overrideKey = getContractOverrideKey(chainId, version);

const overriddenContracts = contractOverrideMap.get(overrideKey);
if (overriddenContracts) {
return overriddenContracts;
}

const contracts = DELEGATOR_CONTRACTS[version]?.[chainId];
Expand Down
Loading