Skip to content

Commit f7265f9

Browse files
fix(deployer): check token version before V2 upgrade
Fixes #3812 Add version check at the start of upgrade_esp_token_v2() and upgrade_esp_token_v2_multisig_owner() to fail early with a clear error message if the token is already on V2. Previously, attempting to upgrade an already-V2 token would result in a cryptic 'InvalidInitialization' revert (0xf92ee8a9). Now users get a clear message: 'EspToken is already on V2, no upgrade needed'
1 parent 7c10665 commit f7265f9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

contracts/rust/deployer/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,16 @@ pub async fn upgrade_esp_token_v2(
857857
};
858858

859859
let proxy = EspToken::new(proxy_addr, &provider);
860+
861+
// Check if already on V2
862+
let current_version = proxy.getVersion().call().await?;
863+
if current_version.majorVersion >= 2 {
864+
anyhow::bail!(
865+
"EspToken is already on V{}, no upgrade needed",
866+
current_version.majorVersion
867+
)
868+
}
869+
860870
// Deploy the new implementation
861871
let v2_addr = contracts
862872
.deploy(Contract::EspTokenV2, EspTokenV2::deploy_builder(&provider))

contracts/rust/deployer/src/proposals/multisig.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,16 @@ pub async fn upgrade_esp_token_v2_multisig_owner(
526526
.ok_or_else(|| anyhow!("EspTokenProxy (multisig owner) not found, can't upgrade"))?;
527527
tracing::info!("EspTokenProxy found at {proxy_addr:#x}");
528528
let proxy = EspToken::new(proxy_addr, &provider);
529+
530+
// Check if already on V2
531+
let current_version = proxy.getVersion().call().await?;
532+
if current_version.majorVersion >= 2 {
533+
anyhow::bail!(
534+
"EspToken is already on V{}, no upgrade needed",
535+
current_version.majorVersion
536+
)
537+
}
538+
529539
let owner_addr = proxy.owner().call().await?;
530540

531541
if !dry_run {

0 commit comments

Comments
 (0)