Skip to content

Commit b86bdb5

Browse files
committed
cli: update to new package management
1 parent fe60b2c commit b86bdb5

File tree

1 file changed

+20
-86
lines changed

1 file changed

+20
-86
lines changed

cli/src/index.ts

Lines changed: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,16 +2882,19 @@ async function upgradeSui<N extends Network, C extends SuiChains>(
28822882

28832883
// Setup Sui environment and execute upgrade
28842884
await withSuiEnv(pwd, ctx, async () => {
2885+
// Determine build environment for Sui 1.63+ package system
2886+
const buildEnv = ctx.network === "Mainnet" ? "mainnet" : "testnet";
2887+
28852888
// Build the updated packages
2886-
console.log("Building updated packages...");
2889+
console.log(`Building updated packages for ${buildEnv} environment...`);
28872890
const packagesToBuild = ["ntt_common", "ntt", "wormhole_transceiver"];
28882891

28892892
for (const packageName of packagesToBuild) {
28902893
const packagePath = `${pwd}/sui/packages/${packageName}`;
28912894
console.log(`Building package: ${packageName}`);
28922895

28932896
try {
2894-
execSync(`sui move build`, {
2897+
execSync(`sui move build -e ${buildEnv}`, {
28952898
cwd: packagePath,
28962899
stdio: "inherit",
28972900
env: process.env,
@@ -2936,7 +2939,7 @@ async function upgradeSui<N extends Network, C extends SuiChains>(
29362939
const packagePath = `${pwd}/${pkg.path}`;
29372940
console.log(`Building package at: ${packagePath}`);
29382941

2939-
execSync(`sui move build`, {
2942+
execSync(`sui move build -e ${buildEnv}`, {
29402943
cwd: packagePath,
29412944
stdio: "pipe",
29422945
env: process.env,
@@ -2995,13 +2998,16 @@ async function performPackageUpgradeInPTB<
29952998
throw new Error(`Unknown package: ${packageName}`);
29962999
}
29973000

3001+
// Determine build environment for Sui 1.63+ package system
3002+
const buildEnv = ctx.network === "Mainnet" ? "mainnet" : "testnet";
3003+
29983004
// Get build output with dependencies using the correct sui command
29993005
console.log(
3000-
`Running sui move build --dump-bytecode-as-base64 for ${packagePath}...`
3006+
`Running sui move build --dump-bytecode-as-base64 -e ${buildEnv} for ${packagePath}...`
30013007
);
30023008

30033009
const buildOutput = execSync(
3004-
`sui move build --dump-bytecode-as-base64 --path ${packagePath}`,
3010+
`sui move build --dump-bytecode-as-base64 -e ${buildEnv} --path ${packagePath}`,
30053011
{
30063012
encoding: "utf-8",
30073013
env: process.env,
@@ -3797,73 +3803,6 @@ async function deploySvm<N extends Network, C extends SolanaChains>(
37973803
return { chain: ch.chain, address: toUniversal(ch.chain, providedProgramId) };
37983804
}
37993805

3800-
// Helper function to update Move.toml files for network-specific dependencies
3801-
function updateMoveTomlForNetwork(
3802-
packagesPath: string,
3803-
networkType: Network
3804-
): { restore: () => void } {
3805-
const packages = ["ntt_common", "ntt", "wormhole_transceiver"];
3806-
const backups: { [key: string]: string } = {};
3807-
3808-
// Determine the correct revisions based on network (with environment variable overrides)
3809-
const wormholeRev =
3810-
process.env.WORMHOLE_REV ||
3811-
(networkType === "Mainnet" ? "sui/mainnet" : "sui/testnet");
3812-
3813-
// localhost not supported for now, because the
3814-
if (networkType === "Devnet") {
3815-
throw new Error("devnet not supported yet");
3816-
}
3817-
3818-
console.log(`Updating Move.toml files for ${networkType} network...`);
3819-
console.log(` Wormhole revision: ${wormholeRev}`);
3820-
3821-
for (const packageName of packages) {
3822-
const moveTomlPath = `${packagesPath}/${packageName}/Move.toml`;
3823-
3824-
try {
3825-
// Backup original content
3826-
const originalContent = fs.readFileSync(moveTomlPath, "utf8");
3827-
backups[moveTomlPath] = originalContent;
3828-
3829-
let content = originalContent;
3830-
3831-
// Update Wormhole revision
3832-
content = content.replace(
3833-
/rev = "sui\/(testnet|mainnet)"/g,
3834-
`rev = "${wormholeRev}"`
3835-
);
3836-
3837-
// Only write if content actually changed
3838-
if (content !== originalContent) {
3839-
fs.writeFileSync(moveTomlPath, content, "utf8");
3840-
console.log(` Updated ${packageName}/Move.toml`);
3841-
} else {
3842-
console.log(` No changes needed for ${packageName}/Move.toml`);
3843-
}
3844-
} catch (error) {
3845-
console.warn(
3846-
` Warning: Could not update ${packageName}/Move.toml: ${error}`
3847-
);
3848-
// Don't throw error here to allow deployment to continue
3849-
}
3850-
}
3851-
3852-
// Return restore function
3853-
return {
3854-
restore: () => {
3855-
console.log("Restoring original Move.toml files...");
3856-
for (const [filePath, content] of Object.entries(backups)) {
3857-
try {
3858-
fs.writeFileSync(filePath, content, "utf8");
3859-
} catch (error) {
3860-
console.warn(` Warning: Could not restore ${filePath}: ${error}`);
3861-
}
3862-
}
3863-
},
3864-
};
3865-
}
3866-
38673806
async function deploySui<N extends Network, C extends Chain>(
38683807
pwd: string,
38693808
version: string | null,
@@ -3895,16 +3834,16 @@ async function deploySui<N extends Network, C extends Chain>(
38953834
console.log("Building Move packages...");
38963835
const packagesPath = `${pwd}/${finalPackagePath}/packages`;
38973836

3898-
// Detect network type and update Move.toml files accordingly
3837+
// Determine build environment for Sui 1.63+ package system
38993838
const networkType = ch.network;
3900-
const { restore } = updateMoveTomlForNetwork(packagesPath, networkType);
3839+
const buildEnv = networkType === "Mainnet" ? "mainnet" : "testnet";
3840+
console.log(`Building for ${buildEnv} environment...`);
39013841

3902-
// Ensure we restore files if deployment fails
39033842
try {
39043843
// Build ntt_common first (dependency)
39053844
try {
39063845
console.log("Building ntt_common package...");
3907-
execSync(`cd ${packagesPath}/ntt_common && sui move build`, {
3846+
execSync(`cd ${packagesPath}/ntt_common && sui move build -e ${buildEnv}`, {
39083847
stdio: "inherit",
39093848
env: process.env,
39103849
});
@@ -3916,7 +3855,7 @@ async function deploySui<N extends Network, C extends Chain>(
39163855
// Build ntt package
39173856
try {
39183857
console.log("Building ntt package...");
3919-
execSync(`cd ${packagesPath}/ntt && sui move build`, {
3858+
execSync(`cd ${packagesPath}/ntt && sui move build -e ${buildEnv}`, {
39203859
stdio: "inherit",
39213860
env: process.env,
39223861
});
@@ -3928,7 +3867,7 @@ async function deploySui<N extends Network, C extends Chain>(
39283867
// Build wormhole_transceiver package
39293868
try {
39303869
console.log("Building wormhole_transceiver package...");
3931-
execSync(`cd ${packagesPath}/wormhole_transceiver && sui move build`, {
3870+
execSync(`cd ${packagesPath}/wormhole_transceiver && sui move build -e ${buildEnv}`, {
39323871
stdio: "inherit",
39333872
env: process.env,
39343873
});
@@ -3950,7 +3889,7 @@ async function deploySui<N extends Network, C extends Chain>(
39503889
}
39513890
);
39523891

3953-
const nttCommonDeploy = JSON.parse(nttCommonResult);
3892+
const nttCommonDeploy = JSON.parse(nttCommonResult.substring(nttCommonResult.indexOf("{")));
39543893
if (!nttCommonDeploy.objectChanges) {
39553894
throw new Error("Failed to deploy ntt_common package");
39563895
}
@@ -3975,7 +3914,7 @@ async function deploySui<N extends Network, C extends Chain>(
39753914
}
39763915
);
39773916

3978-
const nttDeploy = JSON.parse(nttResult);
3917+
const nttDeploy = JSON.parse(nttResult.substring(nttResult.indexOf("{")));
39793918
if (!nttDeploy.objectChanges) {
39803919
throw new Error("Failed to deploy ntt package");
39813920
}
@@ -4000,7 +3939,7 @@ async function deploySui<N extends Network, C extends Chain>(
40003939
}
40013940
);
40023941

4003-
const whTransceiverDeploy = JSON.parse(whTransceiverResult);
3942+
const whTransceiverDeploy = JSON.parse(whTransceiverResult.substring(whTransceiverResult.indexOf("{")));
40043943
if (!whTransceiverDeploy.objectChanges) {
40053944
throw new Error("Failed to deploy wormhole_transceiver package");
40063945
}
@@ -4415,9 +4354,6 @@ async function deploySui<N extends Network, C extends Chain>(
44154354
}`
44164355
);
44174356

4418-
// Restore original Move.toml files after successful deployment
4419-
restore();
4420-
44214357
// Return the deployment information including AdminCaps and package IDs
44224358
return {
44234359
chain: ch.chain,
@@ -4435,8 +4371,6 @@ async function deploySui<N extends Network, C extends Chain>(
44354371
},
44364372
};
44374373
} catch (deploymentError) {
4438-
// Restore original Move.toml files if deployment fails
4439-
restore();
44404374
handleDeploymentError(
44414375
deploymentError,
44424376
ch.chain,

0 commit comments

Comments
 (0)