Skip to content

Commit

Permalink
fix: Safe as Initiator (#22)
Browse files Browse the repository at this point in the history
Allow safes as initiators in Route
  • Loading branch information
cristovaoth authored and jfschwarz committed Dec 20, 2024
1 parent 7ff2d16 commit f37793b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
8 changes: 1 addition & 7 deletions src/execute/plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ import { OperationType } from '@safe-global/types-kit'

import { formatPrefixedAddress } from '../addresses'

import {
AccountType,
ConnectionType,
MetaTransactionRequest,
PrefixedAddress,
Route,
} from '../types'
import { MetaTransactionRequest } from '../types'
import {
ExecutionActionType,
ExecuteTransactionAction,
Expand Down
38 changes: 28 additions & 10 deletions src/execute/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,16 @@ const planAsSafe = async (
index: number,
options: Options
): Promise<ExecutionAction[]> => {
const { waypoint, left, right } = pointers(waypoints, index)
const { waypoint, connection, left, right } = pointers(waypoints, index)

assert(waypoint.account.type == AccountType.SAFE)

assert(
'connection' in waypoint &&
(waypoint.connection.type == ConnectionType.IS_ENABLED ||
waypoint.connection.type == ConnectionType.OWNS)
)
if (left !== null) {
assert(
connection?.type == ConnectionType.IS_ENABLED ||
connection?.type == ConnectionType.OWNS
)
}

assert(
request.type == ExecutionActionType.SAFE_TRANSACTION ||
Expand Down Expand Up @@ -219,7 +221,11 @@ const planAsSafe = async (
}

// OUT
if (waypoint.connection.type == ConnectionType.OWNS) {
const isInitiator = left == null
const isUpstreamOwner = connection?.type == ConnectionType.OWNS
const isUpstreamModule = connection?.type == ConnectionType.IS_ENABLED

if (isUpstreamOwner) {
return [
{
type: shouldPropose(waypoint, options)
Expand All @@ -241,8 +247,7 @@ const planAsSafe = async (
},
...result,
]
} else {
assert(waypoint.connection.type == ConnectionType.IS_ENABLED)
} else if (isUpstreamModule) {
return [
{
type: ExecutionActionType.EXECUTE_TRANSACTION,
Expand All @@ -256,6 +261,17 @@ const planAsSafe = async (
},
...result,
]
} else {
assert(isInitiator)
return [
{
type: ExecutionActionType.EXECUTE_TRANSACTION,
chain: waypoint.account.chain,
from: waypoint.account.address,
transaction,
},
...result,
]
}
}

Expand Down Expand Up @@ -397,7 +413,7 @@ function pointers(waypoints: Route['waypoints'], index: number) {
if (left) {
assert(
'connection' in waypoint &&
waypoint.connection.from == left?.account.prefixedAddress
waypoint.connection.from == left.account.prefixedAddress
)
}

Expand All @@ -414,9 +430,11 @@ function pointers(waypoints: Route['waypoints'], index: number) {
waypoint,
left,
right,
connection: left ? (waypoint as Waypoint).connection! : null,
} as {
waypoint: StartingPoint | Waypoint
left: StartingPoint | Waypoint | null
right: Waypoint | null
connection: Connection | null
}
}

0 comments on commit f37793b

Please sign in to comment.