Skip to content

Commit

Permalink
chore(deps): update dependency ser-kit to v1 (#321)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency ser-kit to v1

* update to ser-kit v1

* more adjustments around parsePrefixedAddress

* use PROPOSE_TRANSACTION instead of PROPOSE_SAFE_TRANSACTION

* chore: replace MetaTransactionData type with MetaTransactionRequest

* update ser-kit to v1.0.2

* migrate some tests

* update another place to use metaTransactionRequest

* update ser-kit to v1.0.3

* handle transition from bigint to string

* fix type issue

* remove deprecated dependency

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Philipp Giese <giese.philipp+git@gmail.com>
  • Loading branch information
renovate[bot] and frontendphil authored Dec 11, 2024
1 parent d8b255e commit 2f1544e
Show file tree
Hide file tree
Showing 33 changed files with 221 additions and 334 deletions.
3 changes: 1 addition & 2 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@safe-global/api-kit": "^2.4.2",
"@safe-global/protocol-kit": "^5.0.1",
"@safe-global/safe-apps-sdk": "^9.1.0",
"@safe-global/safe-core-sdk-types": "^5.0.2",
"@safe-global/safe-gateway-typescript-sdk": "^3.21.10",
"@shazow/whatsabi": "^0.17.0",
"@testing-library/dom": "^10.4.0",
Expand Down Expand Up @@ -85,7 +84,7 @@
"react-dom": "^18.2.0",
"react-select": "5.8.3",
"rimraf": "6.0.1",
"ser-kit": "^0.3.17",
"ser-kit": "1.0.3",
"tailwindcss": "^3.4.14",
"typescript": "^5.5.4",
"typescript-eslint": "^7.16.0",
Expand Down
10 changes: 7 additions & 3 deletions extension/src/chains/getChainId.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { invariant } from '@epic-web/invariant'
import { parsePrefixedAddress, type PrefixedAddress } from 'ser-kit'
import {
splitPrefixedAddress,
type ChainId,
type PrefixedAddress,
} from 'ser-kit'

export const getChainId = (address: PrefixedAddress) => {
export const getChainId = (address: PrefixedAddress): ChainId => {
// atm, we don't yet support cross-chain routes, so can derive a general chainId from the avatar
const [chainId] = parsePrefixedAddress(address)
const [chainId] = splitPrefixedAddress(address)

invariant(chainId != null, 'chainId is empty')

Expand Down
2 changes: 1 addition & 1 deletion extension/src/panel/execution-routes/useRouteConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const useCanEstablishConnection = (route: ExecutionRoute) => {

const pilotAddress =
route.initiator && route.initiator !== `eoa:` + ZeroAddress
? parsePrefixedAddress(route.initiator)[1].toLowerCase()
? parsePrefixedAddress(route.initiator).toLowerCase()
: undefined

if (pilotAddress == null) {
Expand Down
17 changes: 10 additions & 7 deletions extension/src/panel/integrations/safe/signing.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { MetaTransactionData } from '@safe-global/safe-core-sdk-types'
import type { HexAddress } from '@/types'
import type { EIP712TypedData } from '@safe-global/safe-gateway-typescript-sdk'
import {
Contract,
hashMessage as ethersHashMessage,
toUtf8String,
TypedDataEncoder,
} from 'ethers'
import type { MetaTransactionRequest } from 'ser-kit'

const SIGN_MESSAGE_LIB_ADDRESS = '0xd53cd0aB83D845Ac265BE939c57F53AD838012c9'
const SIGN_MESSAGE_LIB_ABI = [
Expand All @@ -18,12 +19,12 @@ const signMessageLib = new Contract(
SIGN_MESSAGE_LIB_ABI,
)

export const signMessage = (message: string): MetaTransactionData => ({
export const signMessage = (message: string): MetaTransactionRequest => ({
to: SIGN_MESSAGE_LIB_ADDRESS,
data: signMessageLib.interface.encodeFunctionData('signMessage', [
hashMessage(message),
]),
value: '0',
]) as HexAddress,
value: 0n,
operation: 1,
})

Expand All @@ -34,13 +35,15 @@ export const typedDataHash = (data: EIP712TypedData): string => {
return TypedDataEncoder.hash(data.domain as any, types, data.message)
}

export const signTypedData = (data: EIP712TypedData) => {
export const signTypedData = (
data: EIP712TypedData,
): MetaTransactionRequest => {
return {
to: SIGN_MESSAGE_LIB_ADDRESS,
data: signMessageLib.interface.encodeFunctionData('signMessage', [
typedDataHash(data),
]),
value: '0',
]) as HexAddress,
value: 0n,
operation: 1,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useZodiacModules = (
const [error, setError] = useState(false)
const [modules, setModules] = useState<Module[]>([])
const chainId = getChainId(safeAddress)
const [, address] = parsePrefixedAddress(safeAddress)
const address = parsePrefixedAddress(safeAddress)

useEffect(() => {
setLoading(true)
Expand Down
9 changes: 5 additions & 4 deletions extension/src/panel/pages/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export const Root = () => {
// make sure the injected provider stays updated on every relevant route change
const route = useExecutionRoute()

const chainId = getChainId(route.avatar)
const provider = useProvider()
const [, avatarAddress] = parsePrefixedAddress(route.avatar)
const saveRoute = useSaveExecutionRoute()

useProviderBridge({ provider, chainId, account: avatarAddress })
useProviderBridge({
provider: useProvider(),
chainId: getChainId(route.avatar),
account: parsePrefixedAddress(route.avatar),
})
useConnectInjectedWalletIfNeeded(route)
useDisconnectWalletConnectIfNeeded(route, {
onDisconnect: () =>
Expand Down
45 changes: 23 additions & 22 deletions extension/src/panel/pages/legacyConnectionMigrations.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {
ProviderType,
type ExecutionRoute,
type LegacyConnection,
ProviderType,
} from '@/types'
import { MULTISEND, MULTISEND_CALL_ONLY } from '@/zodiac'
import { invariant } from '@epic-web/invariant'
import { KnownContracts } from '@gnosis.pm/zodiac'
import { ZeroAddress } from 'ethers'
import {
AccountType,
ConnectionType,
type Delay,
formatPrefixedAddress,
parsePrefixedAddress,
type Roles,
splitPrefixedAddress,
type PrefixedAddress,
type Waypoint,
} from 'ser-kit'

Expand Down Expand Up @@ -46,33 +47,33 @@ export function fromLegacyConnection(
const delayModuleWaypoint = moduleType === KnownContracts.DELAY && {
account: {
type: AccountType.DELAY,
prefixedAddress: modulePrefixedAddress,
prefixedAddress: modulePrefixedAddress?.toLowerCase(),
address: connection.moduleAddress,
chain: chainId,
} as Delay,
},

connection: {
type: ConnectionType.IS_ENABLED,
from: pilotPrefixedAddress,
from: pilotPrefixedAddress.toLowerCase(),
},
}

const rolesModuleWaypoint = (moduleType === KnownContracts.ROLES_V1 ||
moduleType === KnownContracts.ROLES_V2) && {
account: {
type: AccountType.ROLES,
prefixedAddress: modulePrefixedAddress,
prefixedAddress: modulePrefixedAddress?.toLowerCase(),
address: connection.moduleAddress,
chain: chainId,
version: moduleType === KnownContracts.ROLES_V1 ? 1 : 2,
multisend: [connection.multisend, connection.multisendCallOnly].filter(
Boolean,
) as `0x${string}`[],
} as Roles,
},
connection: pilotPrefixedAddress
? {
type: ConnectionType.IS_MEMBER,
from: pilotPrefixedAddress,
from: pilotPrefixedAddress.toLowerCase(),
roles: [connection.roleId].filter(Boolean) as string[],
}
: undefined,
Expand All @@ -85,12 +86,12 @@ export function fromLegacyConnection(
account: isEoa
? ({
type: AccountType.EOA,
prefixedAddress: pilotPrefixedAddress,
prefixedAddress: pilotPrefixedAddress.toLowerCase(),
address: pilotAddress,
} as const)
: ({
type: AccountType.SAFE,
prefixedAddress: pilotPrefixedAddress,
prefixedAddress: pilotPrefixedAddress.toLowerCase(),
address: pilotAddress,
chain: chainId,
threshold: NaN, // we don't know the threshold
Expand All @@ -102,19 +103,19 @@ export function fromLegacyConnection(
{
account: {
type: AccountType.SAFE,
prefixedAddress: avatarPrefixedAddress,
prefixedAddress: avatarPrefixedAddress.toLowerCase(),
address: avatarAddress,
chain: chainId,
threshold: NaN, // we don't know the threshold
},
connection: modulePrefixedAddress
? {
type: ConnectionType.IS_ENABLED,
from: modulePrefixedAddress,
from: modulePrefixedAddress.toLowerCase(),
}
: {
type: ConnectionType.OWNS,
from: pilotPrefixedAddress,
from: pilotPrefixedAddress.toLowerCase(),
},
} as Waypoint,
]
Expand All @@ -125,8 +126,10 @@ export function fromLegacyConnection(
lastUsed: connection.lastUsed,
providerType,
waypoints: waypoints as ExecutionRoute['waypoints'],
initiator: pilotAddress ? pilotPrefixedAddress : undefined,
avatar: avatarPrefixedAddress,
initiator: pilotAddress
? (pilotPrefixedAddress.toLowerCase() as PrefixedAddress)
: undefined,
avatar: avatarPrefixedAddress.toLowerCase() as PrefixedAddress,
}
}

Expand All @@ -135,15 +138,13 @@ export function asLegacyConnection(route: ExecutionRoute): LegacyConnection {
throw new Error('Not representable as legacy connection')
}

const [chainId, avatarAddressChecksummed] = parsePrefixedAddress(route.avatar)
const [chainId, avatarAddressChecksummed] = splitPrefixedAddress(route.avatar)
const avatarAddress = avatarAddressChecksummed.toLowerCase()
if (!chainId) {
throw new Error('chainId is empty')
}

invariant(chainId != null, 'chainId is empty')

const pilotAddress =
(route.initiator &&
parsePrefixedAddress(route.initiator)[1].toLowerCase()) ||
(route.initiator && parsePrefixedAddress(route.initiator).toLowerCase()) ||
''

const moduleWaypoint = route.waypoints?.find(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useExecutionRoute, useRouteConnect } from '@/execution-routes'
import { getReadOnlyProvider } from '@/providers'
import type { JsonRpcError, LegacyConnection } from '@/types'
import type { HexAddress, JsonRpcError, LegacyConnection } from '@/types'
import {
decodeGenericError,
decodeRoleKey,
Expand Down Expand Up @@ -136,7 +136,7 @@ async function dryRun(connection: LegacyConnection) {
{
to: '0x0000000000000000000000000000000000000000',
data: '0x00000000',
from: connection.avatarAddress,
from: connection.avatarAddress as HexAddress,
},
connection,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const getPilotAddress = (route: ExecutionRoute) => {
return null
}

const address = parsePrefixedAddress(route.initiator)[1].toLowerCase()
const address = parsePrefixedAddress(route.initiator).toLowerCase()

if (address === ZeroAddress) {
return null
Expand Down
15 changes: 8 additions & 7 deletions extension/src/panel/pages/routes/edit.$routeId/wrapRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LegacyConnection, TransactionData } from '@/types'
import type { HexAddress, LegacyConnection, TransactionData } from '@/types'
import { ContractFactories, KnownContracts } from '@gnosis.pm/zodiac'
import type { MetaTransactionData } from '@safe-global/safe-core-sdk-types'
import { toQuantity } from 'ethers'
import type { MetaTransactionRequest } from 'ser-kit'

const RolesV1Interface =
ContractFactories[KnownContracts.ROLES_V1].createInterface()
Expand All @@ -9,7 +10,7 @@ const RolesV2Interface =
const DelayInterface = ContractFactories[KnownContracts.DELAY].createInterface()

export function wrapRequest(
request: MetaTransactionData | TransactionData,
request: MetaTransactionRequest | TransactionData,
connection: LegacyConnection,
revertOnError = true,
): TransactionData {
Expand Down Expand Up @@ -53,9 +54,9 @@ export function wrapRequest(
}

return {
from: connection.pilotAddress,
to: connection.moduleAddress,
data: data,
value: '0x0',
from: connection.pilotAddress as HexAddress,
to: connection.moduleAddress as HexAddress,
data: data as HexAddress,
value: toQuantity(0n),
}
}
34 changes: 18 additions & 16 deletions extension/src/panel/pages/transactions/RolePermissionCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import {
decodeRolesV1Error,
decodeRolesV2Error,
} from '@/utils'
import type { MetaTransactionData } from '@safe-global/safe-core-sdk-types'
import { invariant } from '@epic-web/invariant'
import { toQuantity, ZeroAddress } from 'ethers'
import { Check, TriangleAlert, UsersRound } from 'lucide-react'
import { useEffect, useState } from 'react'
import {
ExecutionActionType,
parsePrefixedAddress,
planExecution,
type MetaTransactionRequest,
type Route as SerRoute,
} from 'ser-kit'
import { Translate } from './Translate'

const simulateRolesTransaction = async (
encodedTransaction: MetaTransactionData,
encodedTransaction: MetaTransactionRequest,
route: ExecutionRoute,
provider: Eip1193Provider,
) => {
Expand All @@ -32,19 +33,20 @@ const simulateRolesTransaction = async (
const plan = await planExecution([encodedTransaction], routeWithInitiator)

// TODO generalize permission checking logic (ser-kit)
if (plan.length > 1) {
throw new Error('Multi-step execution not yet supported')
}
invariant(plan.length <= 1, 'Multi-step execution not yet supported')

if (plan[0]?.type !== ExecutionActionType.EXECUTE_TRANSACTION) {
throw new Error('Only transaction execution is currently supported')
}
const [action] = plan

invariant(
action != null && action.type === ExecutionActionType.EXECUTE_TRANSACTION,
'Only transaction execution is currently supported',
)

const [, from] = parsePrefixedAddress(plan[0].from)
const from = parsePrefixedAddress(action.from)
const tx = {
...plan[0].transaction,
...action.transaction,
from,
value: toQuantity(BigInt(plan[0].transaction.value || 0)),
value: toQuantity(BigInt(action.transaction.value || 0)),
}

try {
Expand All @@ -66,11 +68,11 @@ const simulateRolesTransaction = async (
return RolesV2Status[decodedError.args.status]
}
return decodedError.name
} else {
const genericError = decodeGenericError(e as JsonRpcError)
if (genericError === 'Module not authorized') {
return 'Not a member of any role'
}
}

const genericError = decodeGenericError(e as JsonRpcError)
if (genericError === 'Module not authorized') {
return 'Not a member of any role'
}
}

Expand Down
2 changes: 1 addition & 1 deletion extension/src/panel/pages/transactions/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const Submit = () => {
console.debug(
`Transaction batch has been proposed with safeTxHash ${safeTxHash}`,
)
const [, avatarAddress] = parsePrefixedAddress(avatar)
const avatarAddress = parsePrefixedAddress(avatar)
successToast({
title: 'Transaction batch has been proposed for execution',
message: (
Expand Down
Loading

0 comments on commit 2f1544e

Please sign in to comment.