Skip to content

Commit

Permalink
use explicit variable check
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Sep 12, 2024
1 parent 6408a83 commit 4ff8bd7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,17 @@ export async function toBiconomySmartAccount(
]
})
}
if (calls.length === 0) {

const call = calls.length === 0 ? undefined : calls[0]

if (!call) {
throw new Error("No calls to encode")
}
const { to, value, data } = calls[0]
// Encode a simple call
return encodeFunctionData({
abi: BiconomyAbi,
functionName: "execute_ncC",
args: [to, value ?? 0n, data ?? "0x"]
args: [call.to, call.value ?? 0n, call.data ?? "0x"]
})
},
// Get simple dummy signature for ECDSA module authorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ export const encodeCallData = ({
})
}

if (calls.length === 0) {
const call = calls.length === 0 ? undefined : calls[0]

if (!call) {
throw new Error("No calls to encode")
}

// Encode a simple call
return encodeFunctionData({
abi: KernelExecuteAbi,
functionName: "execute",
args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? "0x", 0]
args: [call.to, call.value ?? 0n, call.data ?? "0x", 0]
})
}

Expand Down
6 changes: 4 additions & 2 deletions packages/permissionless/accounts/light/toLightSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ export async function toLightSmartAccount<
})
}

if (calls.length === 0) {
const call = calls.length === 0 ? undefined : calls[0]

if (!call) {
throw new Error("No calls to encode")
}

Expand Down Expand Up @@ -306,7 +308,7 @@ export async function toLightSmartAccount<
}
],
functionName: "execute",
args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? "0x"]
args: [call.to, call.value ?? 0n, call.data ?? "0x"]
})
},
async getNonce(args) {
Expand Down
10 changes: 6 additions & 4 deletions packages/permissionless/accounts/safe/toSafeSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,13 +1348,15 @@ export async function toSafeSmartAccount<
)
operationType = 1
} else {
if (calls.length === 0) {
const call = calls.length === 0 ? undefined : calls[0]

if (!call) {
throw new Error("No calls to encode")
}

to = calls[0].to
data = calls[0].data ?? "0x"
value = calls[0].value ?? 0n
to = call.to
data = call.data ?? "0x"
value = call.value ?? 0n
}

return encodeFunctionData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export async function toSimpleSmartAccount<
})
}

if (calls.length === 0) {
const call = calls.length === 0 ? undefined : calls[0]

if (!call) {
throw new Error("No calls to encode")
}

Expand Down Expand Up @@ -287,7 +289,7 @@ export async function toSimpleSmartAccount<
}
],
functionName: "execute",
args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? "0x"]
args: [call.to, call.value ?? 0n, call.data ?? "0x"]
})
},
async getNonce(args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const encodeCallData = async (
})
}

if (calls.length === 0) {
const call = calls.length === 0 ? undefined : calls[0]

if (!call) {
throw new Error("No calls to encode")
}

Expand Down Expand Up @@ -74,6 +76,6 @@ export const encodeCallData = async (
}
],
functionName: "execute",
args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? "0x"]
args: [call.to, call.value ?? 0n, call.data ?? "0x"]
})
}
10 changes: 6 additions & 4 deletions packages/permissionless/utils/encode7579Calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export function encode7579Calls<callType extends CallType>({
})
}

if (callData.length === 0) {
const call = callData.length === 0 ? undefined : callData[0]

if (!call) {
throw new Error("No calls to encode")
}

Expand All @@ -103,9 +105,9 @@ export function encode7579Calls<callType extends CallType>({
args: [
encodeExecutionMode(mode),
concatHex([
callData[0].to,
toHex(callData[0].value ?? 0n, { size: 32 }),
callData[0].data ?? "0x"
call.to,
toHex(call.value ?? 0n, { size: 32 }),
call.data ?? "0x"
])
]
})
Expand Down

0 comments on commit 4ff8bd7

Please sign in to comment.