Skip to content

Commit

Permalink
feat: update account contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Feb 4, 2025
1 parent 401d2dc commit 001e2cd
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-ants-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"porto": patch
---

**Breaking:** Updated Account contracts.
2 changes: 1 addition & 1 deletion playground/anvil.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions src/core/internal/__snapshots__/provider.test.ts.snap

This file was deleted.

22 changes: 10 additions & 12 deletions src/core/internal/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function execute<

let data: Hex.Hex | undefined
if (cause instanceof BaseError) {
const [, match] = cause.details.match(/"(0x[0-9a-f]{8})"/) || []
const [, match] = cause.details.match(/(0x[0-9a-f]{8})/) || []
if (match) data = match as Hex.Hex
}

Expand All @@ -134,6 +134,7 @@ export async function execute<
}

try {
if (data === '0xd0d5039b') return AbiError.from('error Unauthorized()')
return AbiError.fromAbi(delegationAbi, data)
} catch {
return undefined
Expand Down Expand Up @@ -273,6 +274,8 @@ export async function getExecuteSignPayload<
getEip712Domain(client, { account }),
])

const multichain = nonce & 1n

if (!client.chain) throw new Error('chain is required.')
return TypedData.getSignPayload({
domain: {
Expand All @@ -288,12 +291,14 @@ export async function getExecuteSignPayload<
{ name: 'data', type: 'bytes' },
],
Execute: [
{ name: 'multichain', type: 'bool' },
{ name: 'calls', type: 'Call[]' },
{ name: 'nonce', type: 'uint256' },
{ name: 'nonceSalt', type: 'uint256' },
],
},
message: {
multichain: Boolean(multichain),
calls,
nonce,
nonceSalt,
Expand Down Expand Up @@ -381,20 +386,17 @@ export async function prepareExecute<
client: Client<Transport, chain>,
parameters: prepareExecute.Parameters<calls, chain, account>,
): Promise<prepareExecute.ReturnType<calls, chain>> {
const {
account,
delegation,
executor,
nonce = Hex.toBigInt(Hex.random(32)),
...rest
} = parameters
const { account, delegation, executor, ...rest } = parameters

const calls = parameters.calls.map((call: any) => ({
data: call.data ?? '0x',
to: call.to === Call.self ? account.address : call.to,
value: call.value ?? 0n,
}))

let nonce = Hex.toBigInt(Hex.random(32))
if (nonce & 1n) nonce += 1n // even nonce (no chain replay) // TODO: enable replay for `authorize` calls

// Compute the signing payloads for execution and EIP-7702 authorization (optional).
const [executePayload, [authorization, authorizationPayload]] =
await Promise.all([
Expand Down Expand Up @@ -464,10 +466,6 @@ export declare namespace prepareExecute {
* - `undefined`: the transaction will be filled by the JSON-RPC server.
*/
executor?: Account | undefined
/**
* Nonce to use for execution that will be invalidated by the delegated account.
*/
nonce?: bigint | undefined
}

export type ReturnType<
Expand Down
Loading

0 comments on commit 001e2cd

Please sign in to comment.