Skip to content

Commit 26ff599

Browse files
committed
Update dev multisig code
1 parent e13f46d commit 26ff599

File tree

1 file changed

+115
-22
lines changed

1 file changed

+115
-22
lines changed

scripts/wallets/DeveloperMultisig.ts

Lines changed: 115 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ const V2_SIGNERS = [
2626
'0xEB5EeE1F1650b821E0d3a87C1341d85b3a16EA72' // tpin@horizon.io
2727
]
2828

29-
const makeWalletConfig = (signers: string[], checkpoint: number) => ({
30-
threshold: 2,
29+
const V3_SIGNERS = [
30+
...[...V2_SIGNERS].reverse(),
31+
'0x060b5A65ff25366e40b624DBc304fD76CF06BBa7' // wh@horizongames.net
32+
]
33+
34+
const makeWalletConfig = (signers: string[], threshold: number, checkpoint: number) => ({
35+
threshold,
3136
checkpoint,
3237
signers: signers.map(address => ({
3338
address,
3439
weight: 1
3540
}))
3641
})
3742

38-
const WALLET_CONFIG_V1 = makeWalletConfig(V1_SIGNERS, 0)
39-
const WALLET_CONFIG_V2 = makeWalletConfig(V2_SIGNERS, 1)
43+
const WALLET_CONFIG_V1 = makeWalletConfig(V1_SIGNERS, 2, 0)
44+
const WALLET_CONFIG_V2 = makeWalletConfig(V2_SIGNERS, 2, 1)
45+
const WALLET_CONFIG_V3 = makeWalletConfig(V3_SIGNERS, 3, 2)
4046

41-
const UPDATE_NONCE = BigNumber.from('0x019562960be2000000000000000000000000')
47+
const UPDATE_TO_V2_NONCE = BigNumber.from('0x019562960be2000000000000000000000000')
4248
const WALLET_CONFIG_V2_SIGNATURE_PARTS = new Map([
4349
[
4450
'0x0C885789f0642CA123008F961d19C9813DA11b24',
@@ -57,6 +63,25 @@ const WALLET_CONFIG_V2_SIGNATURE_PARTS = new Map([
5763
}
5864
]
5965
])
66+
const UPDATE_TO_V3_NONCE = BigNumber.from('0x019562960be2000000000000000000000001')
67+
const WALLET_CONFIG_V3_SIGNATURE_PARTS = new Map([
68+
[
69+
'0x0C885789f0642CA123008F961d19C9813DA11b24',
70+
{
71+
signature:
72+
'0xa2834a915327f935930a0c8db6dc6a991c1fe7f6cf5586070d3b751cd6eeaeb852d4a980c6310c207ab8332eec9f7d22b853186a5e8a9db2af02303b7a0b38111c02',
73+
isDynamic: false
74+
}
75+
],
76+
[
77+
'0x857CDfb0922bd51ca873340a9325F43F1233BEB8',
78+
{
79+
signature:
80+
'0x1e21820232c87e5398d3fabecae5d5462c68c33b6737b365a9367c5c5316e0aa3cada93a14326268c5fc66808b6cb5a9fe9bcceb7ba32990c4c593eb7fc7e6471c02',
81+
isDynamic: false
82+
}
83+
]
84+
])
6085

6186
const EXPECTED_ADDRESS = '0x007a47e6BF40C1e0ed5c01aE42fDC75879140bc4'
6287

@@ -91,12 +116,12 @@ export const deployDeveloperMultisig = async (
91116

92117
const chainId = (await provider.getNetwork()).chainId
93118

94-
const wallet = new Wallet({
119+
let wallet = new Wallet({
95120
coders: {
96121
signature: v2.signature.SignatureCoder,
97122
config: v2.config.ConfigCoder
98123
},
99-
context: context,
124+
context,
100125
config: walletConfig,
101126
chainId,
102127
address,
@@ -127,25 +152,48 @@ export const deployDeveloperMultisig = async (
127152
o.info(`Deployed developer multisig wallet at ${wallet.address}`)
128153
}
129154

130-
await updateDeveloperMultisig(wallet, o)
155+
wallet = await updateDeveloperMultisigToV2(wallet, o)
156+
wallet = await updateDeveloperMultisigToV3(wallet, o)
131157

132158
o.succeed(`Deployed and updated developer multisig wallet at ${wallet.address}`)
133159

134160
return wallet
135161
}
136162

137-
const updateDeveloperMultisig = async (wallet: WalletType, o: ora.Ora): Promise<WalletType> => {
138-
const configV2 = v2.coders.config.fromSimple(WALLET_CONFIG_V2)
139-
const imageHash = v2.coders.config.imageHashOf(configV2)
163+
/**
164+
* Updates the developer multisig wallet to a new configuration, if not already updated.
165+
*/
166+
const updateDeveloperMultisig = async (
167+
wallet: WalletType,
168+
o: ora.Ora,
169+
newConfig: commons.config.SimpleConfig,
170+
updateNonce: BigNumber,
171+
signatureParts: Map<string, { signature: string; isDynamic: boolean }>
172+
): Promise<WalletType> => {
173+
const updatedconfig = v2.coders.config.fromSimple(newConfig)
174+
const imageHash = v2.coders.config.imageHashOf(updatedconfig)
140175

141-
// Check current image hash on chain
142-
const currentImageHash = await wallet.reader().imageHash(wallet.address)
143-
if (currentImageHash === imageHash) {
176+
// Check if nonce was used before
177+
const [nonceSpace, nonce] = commons.transaction.decodeNonce(updateNonce)
178+
const currentNonce = await wallet.reader().nonce(wallet.address, nonceSpace)
179+
if (currentNonce > nonce) {
144180
o.info('Developer multisig already updated')
145-
wallet.setConfig(configV2)
146-
return wallet
181+
return new Wallet({
182+
coders: {
183+
signature: v2.signature.SignatureCoder,
184+
config: v2.config.ConfigCoder
185+
},
186+
context: wallet.context,
187+
config: updatedconfig,
188+
chainId: wallet.chainId,
189+
address: wallet.address,
190+
orchestrator: new Orchestrator([]),
191+
provider: wallet.provider,
192+
relayer: wallet.relayer
193+
})
147194
}
148195

196+
// Construct transaction
149197
const transactions = [
150198
{
151199
to: wallet.address,
@@ -156,10 +204,15 @@ const updateDeveloperMultisig = async (wallet: WalletType, o: ora.Ora): Promise<
156204
value: 0
157205
}
158206
]
159-
const digest = commons.transaction.digestOfTransactions(UPDATE_NONCE, transactions)
207+
208+
// Calculate digest and subdigest
209+
const digest = commons.transaction.digestOfTransactions(updateNonce, transactions)
160210
const subdigest = subDigestOf(wallet.address, 0, digest)
211+
console.log('subdigest:', subdigest)
161212

162-
const signature = v2.coders.signature.encodeSigners(wallet.config, WALLET_CONFIG_V2_SIGNATURE_PARTS, [subdigest], 0).encoded
213+
// Encode signature
214+
const signature = v2.coders.signature.encodeSigners(wallet.config, signatureParts, [subdigest], 0).encoded
215+
console.log('signature:', signature, '\n\n\n\n')
163216

164217
const bundle: commons.transaction.SignedTransactionBundle = {
165218
intent: {
@@ -169,16 +222,56 @@ const updateDeveloperMultisig = async (wallet: WalletType, o: ora.Ora): Promise<
169222
chainId: wallet.chainId,
170223
transactions,
171224
entrypoint: wallet.address,
172-
nonce: UPDATE_NONCE,
225+
nonce: updateNonce,
173226
signature
174227
}
175228

229+
// Send signed transaction
176230
const tx = await wallet.sendSignedTransaction(bundle)
177231
if (!tx) {
178-
throw new Error(`Unable to build update configuration transaction for developer multisig wallet at ${wallet.address}`)
232+
throw new Error(`Unable to build update configuration to ${imageHash} for developer multisig wallet at ${wallet.address}`)
179233
}
180234
await tx.wait()
235+
o.info(`Updated developer multisig wallet to ${imageHash} at ${wallet.address}`)
181236

182-
wallet.setConfig(configV2)
183-
return wallet
237+
return new Wallet({
238+
coders: {
239+
signature: v2.signature.SignatureCoder,
240+
config: v2.config.ConfigCoder
241+
},
242+
context: wallet.context,
243+
config: updatedconfig,
244+
chainId: wallet.chainId,
245+
address: wallet.address,
246+
orchestrator: new Orchestrator([]),
247+
provider: wallet.provider,
248+
relayer: wallet.relayer
249+
})
184250
}
251+
252+
const updateDeveloperMultisigToV2 = async (wallet: WalletType, o: ora.Ora): Promise<WalletType> => {
253+
return updateDeveloperMultisig(wallet, o, WALLET_CONFIG_V2, UPDATE_TO_V2_NONCE, WALLET_CONFIG_V2_SIGNATURE_PARTS)
254+
}
255+
const updateDeveloperMultisigToV3 = async (wallet: WalletType, o: ora.Ora): Promise<WalletType> => {
256+
return updateDeveloperMultisig(wallet, o, WALLET_CONFIG_V3, UPDATE_TO_V3_NONCE, WALLET_CONFIG_V3_SIGNATURE_PARTS)
257+
}
258+
259+
/**
260+
* Quick function to check the image hash of WALLET_CONFIG_V3
261+
*/
262+
export const checkAllConfigImageHashes = (): void => {
263+
const configV1 = v2.coders.config.fromSimple(WALLET_CONFIG_V1)
264+
const imageHashV1 = v2.coders.config.imageHashOf(configV1)
265+
console.log('WALLET_CONFIG_V1 image hash:', imageHashV1)
266+
267+
const configV2 = v2.coders.config.fromSimple(WALLET_CONFIG_V2)
268+
const imageHashV2 = v2.coders.config.imageHashOf(configV2)
269+
console.log('WALLET_CONFIG_V2 image hash:', imageHashV2)
270+
271+
const configV3 = v2.coders.config.fromSimple(WALLET_CONFIG_V3)
272+
const imageHashV3 = v2.coders.config.imageHashOf(configV3)
273+
console.log('WALLET_CONFIG_V3 image hash:', imageHashV3)
274+
}
275+
276+
// Call it to check the image hash
277+
checkAllConfigImageHashes()

0 commit comments

Comments
 (0)