Skip to content

Commit

Permalink
Rearrange code to reduce diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Jul 9, 2024
1 parent dcab26c commit 2027f7b
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions typescript/cli/src/deploy/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,44 +364,7 @@ export async function runWarpRouteApply(params: ApplyParams) {
// get diff of both configs
const warpDeployChains = Object.keys(warpDeployConfig);
const warpCoreChains = Object.keys(warpCoreByChain);
if (warpDeployChains.length > warpCoreChains.length) {
logGray('Extending deployed Warp configs');
// Deploy with the additional config
const additionalConfig = objFilter(
warpDeployConfig,
(chain, _config): _config is any => !warpCoreChains.includes(chain),
);

// @TODO handle synthetic addition because it needs to derive from one of the collateral

const newDeployedContracts = await executeDeploy({
context,
warpDeployConfig: additionalConfig,
});

// @TODO Enroll with existing chains

// Get existing contracts from config to merge with newly deployed ones
const deployedConfig = objFilter(
warpDeployConfig,
(chain, _config): _config is any => warpCoreChains.includes(chain),
);
const existingDeployedAddresses = objMap(
deployedConfig,
(chain, config) => {
return {
[config.type]: warpCoreByChain[chain].addressOrDenom!,
};
},
);

const updatedWarpCoreConfig = await getWarpCoreConfig(params, {
...attachContractsMap(existingDeployedAddresses, hypERC20factories),
...newDeployedContracts,
});
WarpCoreConfigSchema.parse(updatedWarpCoreConfig);
await writeDeploymentArtifacts(updatedWarpCoreConfig, context);
} else if (warpDeployChains.length === warpCoreChains.length) {
if (warpDeployChains.length === warpCoreChains.length) {
// Attempt to update Warp Routes
// Can update existing or deploy new contracts
logGray(`Comparing target and onchain Warp configs`);
Expand Down Expand Up @@ -441,6 +404,43 @@ export async function runWarpRouteApply(params: ApplyParams) {
}
}),
);
} else if (warpDeployChains.length > warpCoreChains.length) {
logGray('Extending deployed Warp configs');
// Deploy with the additional config
const additionalConfig = objFilter(
warpDeployConfig,
(chain, _config): _config is any => !warpCoreChains.includes(chain),
);

// @TODO handle synthetic addition because it needs to derive from one of the collateral

const newDeployedContracts = await executeDeploy({
context,
warpDeployConfig: additionalConfig,
});

// @TODO Enroll with existing chains

// Get existing contracts from config to merge with newly deployed ones
const deployedConfig = objFilter(
warpDeployConfig,
(chain, _config): _config is any => warpCoreChains.includes(chain),
);
const existingDeployedAddresses = objMap(
deployedConfig,
(chain, config) => {
return {
[config.type]: warpCoreByChain[chain].addressOrDenom!,
};
},
);

const updatedWarpCoreConfig = await getWarpCoreConfig(params, {
...attachContractsMap(existingDeployedAddresses, hypERC20factories),
...newDeployedContracts,
});
WarpCoreConfigSchema.parse(updatedWarpCoreConfig);
await writeDeploymentArtifacts(updatedWarpCoreConfig, context);
} else {
throw new Error('Unenrolling warp routes is currently not supported');
}
Expand Down

0 comments on commit 2027f7b

Please sign in to comment.