Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP-FIX: Safe as Initiator #22

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading