Skip to content

Commit e340864

Browse files
JOYclaude
andcommitted
fix: patch protocol-kit to support Safe v1.5.0
protocol-kit ^5.2.25 doesn't have case '1.5.0' in contractInstances switch statements. When Safe is upgraded to v1.5.0, SDK throws "Invalid Safe version" and refuses to initialize. Patch adds case '1.5.0' before each '1.4.1' case, using the same v1.4.1 contract classes (ABI compatible). Also updates safeCoreSDK.ts to provide v1.5.0 contract addresses explicitly for chain 7979. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b664763 commit e340864

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

apps/web/src/hooks/coreSDK/safeCoreSDK.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,38 @@ export const initSafeSDK = async ({
100100
contractNetworks,
101101
})
102102

103-
// For self-hosted chains not in safe-deployments, provide contract addresses explicitly
104-
// This bypasses the safe-deployments lookup that fails for custom chains
105-
if (!contractNetworks?.[chainId]) {
103+
// For DOS Chain (7979): always provide contract addresses explicitly
104+
// Covers both v1.4.1 and v1.5.0 contracts deployed on DOS Chain
105+
// This bypasses the safe-deployments lookup that fails for custom chains in webpack bundles
106+
if (chainId === '7979') {
107+
contractNetworks = {
108+
...contractNetworks,
109+
[chainId]: {
110+
...contractNetworks?.[chainId],
111+
// v1.4.1 contracts
112+
multiSendAddress: '0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526',
113+
multiSendCallOnlyAddress: '0x9641d764fc13c8B624c04430C7356C1C7C8102e2',
114+
safeSingletonAddress: '0x41675C099F32341bf84BFc5382aF534df5C7461a',
115+
safeSingletonL2Address: '0x29fcB43b46531BcA003ddC8FCB67FFE91900C762',
116+
safeProxyFactoryAddress: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67',
117+
fallbackHandlerAddress: '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99',
118+
signMessageLibAddress: '0xd53cd0aB83D845Ac265BE939c57F53AD838012c9',
119+
createCallAddress: '0x9b35Af71d77eaf8d7e40252370304687390A1A52',
120+
simulateTxAccessorAddress: '0x3d4BA2E0884aa488718476ca2FB8Efc291A46199',
121+
// v1.5.0 contracts (canonical addresses)
122+
safeSingletonAddress: '0xFf51A5898e281Db6DfC7855790607438dF2ca44b',
123+
safeSingletonL2Address: '0xEdd160fEBBD92E350D4D398fb636302fccd67C7e',
124+
safeProxyFactoryAddress: '0x14F2982D601c9458F93bd70B218933A6f8165e7b',
125+
fallbackHandlerAddress: '0x3EfCBb83A4A7AfcB4F68D501E2c2203a38be77f4',
126+
multiSendAddress: '0x218543288004CD07832472D464648173c77D7eB7',
127+
multiSendCallOnlyAddress: '0xA83c336B20401Af773B6219BA5027174338D1836',
128+
signMessageLibAddress: '0x4FfeF8222648872B3dE295Ba1e49110E61f5b5aa',
129+
createCallAddress: '0x2Ef5ECfbea521449E4De05EDB1ce63B75eDA90B4',
130+
simulateTxAccessorAddress: '0x07EfA797c55B5DdE3698d876b277aBb6B893654C',
131+
},
132+
}
133+
} else if (!contractNetworks?.[chainId]) {
134+
// For other unknown chains, provide v1.4.1 defaults
106135
contractNetworks = {
107136
...contractNetworks,
108137
[chainId]: {

scripts/patch-safe-deployments.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,41 @@ function patchTypesKit() {
180180
}
181181

182182
patchTypesKit()
183+
184+
// Patch protocol-kit to support Safe v1.5.0
185+
// protocol-kit ^5.2.25 only has case '1.4.1' in switch statements
186+
// Adding case '1.5.0' before each '1.4.1' case makes it use the same contract class
187+
function patchProtocolKit() {
188+
const candidates = [
189+
join(__dirname, '..', 'node_modules', '@safe-global', 'protocol-kit'),
190+
join(__dirname, '..', 'apps', 'web', 'node_modules', '@safe-global', 'protocol-kit'),
191+
]
192+
193+
let pkDir = null
194+
for (const dir of candidates) {
195+
try { readdirSync(dir); pkDir = dir; break } catch {}
196+
}
197+
if (!pkDir) {
198+
console.log('protocol-kit not found, skipping v1.5.0 patch')
199+
return
200+
}
201+
202+
const contractInstancesFile = join(pkDir, 'dist', 'src', 'contracts', 'contractInstances.js')
203+
try {
204+
let content = readFileSync(contractInstancesFile, 'utf-8')
205+
if (content.includes("case '1.5.0':")) {
206+
console.log('[skip] protocol-kit already has 1.5.0 support')
207+
return
208+
}
209+
210+
// Add case '1.5.0': before every case '1.4.1':
211+
const count = (content.match(/case '1\.4\.1':/g) || []).length
212+
content = content.replace(/case '1\.4\.1':/g, "case '1.5.0':\n case '1.4.1':")
213+
writeFileSync(contractInstancesFile, content)
214+
console.log(`[ok] protocol-kit: added case '1.5.0' to ${count} switch statements`)
215+
} catch (e) {
216+
console.log(`[err] protocol-kit patch: ${e.message}`)
217+
}
218+
}
219+
220+
patchProtocolKit()

0 commit comments

Comments
 (0)