Skip to content

Commit

Permalink
Simplify code and reuse types
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Dec 13, 2023
1 parent 5950339 commit 6deda1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
8 changes: 2 additions & 6 deletions packages/core/src/v1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers'
import { walletContracts } from '@0xsequence/abi'
import { commons } from '..'
import { encodeSigners } from './signature'
import { SimpleConfig } from '../commons/config'

export type AddressMember = {
weight: ethers.BigNumberish
Expand Down Expand Up @@ -49,12 +50,7 @@ export const ConfigCoder: commons.config.ConfigCoder<WalletConfig> = {
return config.signers.map(s => ({ address: s.address, weight: ethers.BigNumber.from(s.weight).toNumber() }))
},

fromSimple: (config: {
threshold: ethers.BigNumberish
checkpoint: ethers.BigNumberish
signers: { address: string; weight: ethers.BigNumberish }[]
subdigests?: string[]
}): WalletConfig => {
fromSimple: (config: SimpleConfig): WalletConfig => {
if (!ethers.constants.Zero.eq(config.checkpoint)) {
throw new Error('v1 wallet config does not support checkpoint')
}
Expand Down
30 changes: 4 additions & 26 deletions packages/core/src/v2/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ethers } from 'ethers'
import { walletContracts } from '@0xsequence/abi'
import { commons } from '..'
import { encodeSigners } from './signature'
import { SimpleConfig } from '../commons/config'

//
// Tree typings - leaves
Expand Down Expand Up @@ -434,33 +435,10 @@ export const ConfigCoder: commons.config.ConfigCoder<WalletConfig> = {
return signersOf(config.tree)
},

fromSimple: (config: {
threshold: ethers.BigNumberish
checkpoint: ethers.BigNumberish
signers: { address: string; weight: ethers.BigNumberish }[]
subdigests?: string[]
}): WalletConfig => {
let members: SimpleConfigMember[] = config.signers.map(signer => {
return {
address: signer.address,
weight: signer.weight
}
})

if (config.subdigests) {
members = members.concat(
config.subdigests.map(subdigest => {
return {
subdigest
}
})
)
}

fromSimple: (config: SimpleConfig): WalletConfig => {
return toWalletConfig({
threshold: config.threshold,
checkpoint: config.checkpoint,
members
...config,
members: [...config.signers, ...(config.subdigests ?? []).map(subdigest => ({ subdigest }))]
})
},

Expand Down

0 comments on commit 6deda1b

Please sign in to comment.