permissionless 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js +16 -13
- package/_cjs/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js +16 -13
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_cjs/accounts/signerToSafeSmartAccount.js +20 -17
- package/_cjs/accounts/signerToSafeSmartAccount.js.map +1 -1
- package/_cjs/accounts/signerToSimpleSmartAccount.js +15 -12
- package/_cjs/accounts/signerToSimpleSmartAccount.js.map +1 -1
- package/_cjs/utils/index.js +3 -1
- package/_cjs/utils/index.js.map +1 -1
- package/_cjs/utils/isSmartAccountDeployed.js +15 -0
- package/_cjs/utils/isSmartAccountDeployed.js.map +1 -0
- package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js +17 -14
- package/_esm/accounts/biconomy/signerToBiconomySmartAccount.js.map +1 -1
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +17 -14
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_esm/accounts/signerToSafeSmartAccount.js +21 -18
- package/_esm/accounts/signerToSafeSmartAccount.js.map +1 -1
- package/_esm/accounts/signerToSimpleSmartAccount.js +16 -13
- package/_esm/accounts/signerToSimpleSmartAccount.js.map +1 -1
- package/_esm/utils/index.js +2 -1
- package/_esm/utils/index.js.map +1 -1
- package/_esm/utils/isSmartAccountDeployed.js +11 -0
- package/_esm/utils/isSmartAccountDeployed.js.map +1 -0
- package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts +2 -1
- package/_types/accounts/biconomy/signerToBiconomySmartAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts +2 -1
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
- package/_types/accounts/signerToSafeSmartAccount.d.ts +3 -2
- package/_types/accounts/signerToSafeSmartAccount.d.ts.map +1 -1
- package/_types/accounts/signerToSimpleSmartAccount.d.ts +2 -1
- package/_types/accounts/signerToSimpleSmartAccount.d.ts.map +1 -1
- package/_types/utils/index.d.ts +2 -1
- package/_types/utils/index.d.ts.map +1 -1
- package/_types/utils/isSmartAccountDeployed.d.ts +3 -0
- package/_types/utils/isSmartAccountDeployed.d.ts.map +1 -0
- package/accounts/biconomy/signerToBiconomySmartAccount.ts +25 -18
- package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +24 -13
- package/accounts/signerToSafeSmartAccount.ts +24 -18
- package/accounts/signerToSimpleSmartAccount.ts +25 -18
- package/package.json +1 -1
- package/utils/index.ts +3 -1
- package/utils/isSmartAccountDeployed.ts +16 -0
|
@@ -22,13 +22,13 @@ import {
|
|
|
22
22
|
} from "viem"
|
|
23
23
|
import { toAccount } from "viem/accounts"
|
|
24
24
|
import {
|
|
25
|
-
getBytecode,
|
|
26
25
|
getChainId,
|
|
27
26
|
readContract,
|
|
28
27
|
signMessage,
|
|
29
28
|
signTypedData
|
|
30
29
|
} from "viem/actions"
|
|
31
30
|
import { getAccountNonce } from "../actions/public/getAccountNonce.js"
|
|
31
|
+
import { isSmartAccountDeployed } from "../utils/isSmartAccountDeployed.js"
|
|
32
32
|
import {
|
|
33
33
|
SignTransactionNotSupportedBySmartAccount,
|
|
34
34
|
type SmartAccount,
|
|
@@ -502,6 +502,7 @@ export async function signerToSafeSmartAccount<
|
|
|
502
502
|
client: Client<TTransport, TChain>,
|
|
503
503
|
{
|
|
504
504
|
signer,
|
|
505
|
+
address,
|
|
505
506
|
safeVersion,
|
|
506
507
|
entryPoint,
|
|
507
508
|
addModuleLibAddress: _addModuleLibAddress,
|
|
@@ -516,9 +517,10 @@ export async function signerToSafeSmartAccount<
|
|
|
516
517
|
safeModules = [],
|
|
517
518
|
setupTransactions = []
|
|
518
519
|
}: {
|
|
519
|
-
safeVersion: SafeVersion
|
|
520
520
|
signer: SmartAccountSigner<TSource, TAddress>
|
|
521
|
+
safeVersion: SafeVersion
|
|
521
522
|
entryPoint: Address
|
|
523
|
+
address?: Address
|
|
522
524
|
addModuleLibAddress?: Address
|
|
523
525
|
safe4337ModuleAddress?: Address
|
|
524
526
|
safeProxyFactoryAddress?: Address
|
|
@@ -561,21 +563,25 @@ export async function signerToSafeSmartAccount<
|
|
|
561
563
|
multiSendCallOnlyAddress: _multiSendCallOnlyAddress
|
|
562
564
|
})
|
|
563
565
|
|
|
564
|
-
const accountAddress =
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
566
|
+
const accountAddress =
|
|
567
|
+
address ??
|
|
568
|
+
(await getAccountAddress<TTransport, TChain>({
|
|
569
|
+
client,
|
|
570
|
+
owner: viemSigner.address,
|
|
571
|
+
addModuleLibAddress,
|
|
572
|
+
safe4337ModuleAddress,
|
|
573
|
+
safeProxyFactoryAddress,
|
|
574
|
+
safeSingletonAddress,
|
|
575
|
+
multiSendAddress,
|
|
576
|
+
saltNonce,
|
|
577
|
+
setupTransactions,
|
|
578
|
+
safeModules
|
|
579
|
+
}))
|
|
576
580
|
|
|
577
581
|
if (!accountAddress) throw new Error("Account address not found")
|
|
578
582
|
|
|
583
|
+
let safeDeployed = await isSmartAccountDeployed(client, accountAddress)
|
|
584
|
+
|
|
579
585
|
const account = toAccount({
|
|
580
586
|
address: accountAddress,
|
|
581
587
|
async signMessage({ message }) {
|
|
@@ -695,11 +701,11 @@ export async function signerToSafeSmartAccount<
|
|
|
695
701
|
)
|
|
696
702
|
},
|
|
697
703
|
async getInitCode() {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
704
|
+
if (safeDeployed) return "0x"
|
|
705
|
+
|
|
706
|
+
safeDeployed = await isSmartAccountDeployed(client, accountAddress)
|
|
701
707
|
|
|
702
|
-
if (
|
|
708
|
+
if (safeDeployed) return "0x"
|
|
703
709
|
|
|
704
710
|
return getAccountInitCode({
|
|
705
711
|
owner: viemSigner.address,
|
|
@@ -11,15 +11,11 @@ import {
|
|
|
11
11
|
encodeFunctionData
|
|
12
12
|
} from "viem"
|
|
13
13
|
import { toAccount } from "viem/accounts"
|
|
14
|
-
import {
|
|
15
|
-
getBytecode,
|
|
16
|
-
getChainId,
|
|
17
|
-
signMessage,
|
|
18
|
-
signTypedData
|
|
19
|
-
} from "viem/actions"
|
|
14
|
+
import { getChainId, signMessage, signTypedData } from "viem/actions"
|
|
20
15
|
import { getAccountNonce } from "../actions/public/getAccountNonce.js"
|
|
21
16
|
import { getSenderAddress } from "../actions/public/getSenderAddress.js"
|
|
22
17
|
import { getUserOperationHash } from "../utils/getUserOperationHash.js"
|
|
18
|
+
import { isSmartAccountDeployed } from "../utils/isSmartAccountDeployed.js"
|
|
23
19
|
import {
|
|
24
20
|
SignTransactionNotSupportedBySmartAccount,
|
|
25
21
|
type SmartAccount,
|
|
@@ -113,12 +109,14 @@ export async function signerToSimpleSmartAccount<
|
|
|
113
109
|
signer,
|
|
114
110
|
factoryAddress,
|
|
115
111
|
entryPoint,
|
|
116
|
-
index = 0n
|
|
112
|
+
index = 0n,
|
|
113
|
+
address
|
|
117
114
|
}: {
|
|
118
115
|
signer: SmartAccountSigner<TSource, TAddress>
|
|
119
116
|
factoryAddress: Address
|
|
120
117
|
entryPoint: Address
|
|
121
118
|
index?: bigint
|
|
119
|
+
address?: Address
|
|
122
120
|
}
|
|
123
121
|
): Promise<SimpleSmartAccount<TTransport, TChain>> {
|
|
124
122
|
const viemSigner: LocalAccount = {
|
|
@@ -129,18 +127,24 @@ export async function signerToSimpleSmartAccount<
|
|
|
129
127
|
} as LocalAccount
|
|
130
128
|
|
|
131
129
|
const [accountAddress, chainId] = await Promise.all([
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
address ??
|
|
131
|
+
getAccountAddress<TTransport, TChain>({
|
|
132
|
+
client,
|
|
133
|
+
factoryAddress,
|
|
134
|
+
entryPoint,
|
|
135
|
+
owner: viemSigner.address,
|
|
136
|
+
index
|
|
137
|
+
}),
|
|
139
138
|
getChainId(client)
|
|
140
139
|
])
|
|
141
140
|
|
|
142
141
|
if (!accountAddress) throw new Error("Account address not found")
|
|
143
142
|
|
|
143
|
+
let smartAccountDeployed = await isSmartAccountDeployed(
|
|
144
|
+
client,
|
|
145
|
+
accountAddress
|
|
146
|
+
)
|
|
147
|
+
|
|
144
148
|
const account = toAccount({
|
|
145
149
|
address: accountAddress,
|
|
146
150
|
async signMessage({ message }) {
|
|
@@ -189,11 +193,14 @@ export async function signerToSimpleSmartAccount<
|
|
|
189
193
|
})
|
|
190
194
|
},
|
|
191
195
|
async getInitCode() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
196
|
+
if (smartAccountDeployed) return "0x"
|
|
197
|
+
|
|
198
|
+
smartAccountDeployed = await isSmartAccountDeployed(
|
|
199
|
+
client,
|
|
200
|
+
accountAddress
|
|
201
|
+
)
|
|
195
202
|
|
|
196
|
-
if (
|
|
203
|
+
if (smartAccountDeployed) return "0x"
|
|
197
204
|
|
|
198
205
|
return getAccountInitCode(factoryAddress, viemSigner.address, index)
|
|
199
206
|
},
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type GetUserOperationHashParams,
|
|
10
10
|
getUserOperationHash
|
|
11
11
|
} from "./getUserOperationHash.js"
|
|
12
|
+
import { isSmartAccountDeployed } from "./isSmartAccountDeployed"
|
|
12
13
|
import {
|
|
13
14
|
AccountOrClientNotFoundError,
|
|
14
15
|
type SignUserOperationHashWithECDSAParams,
|
|
@@ -33,5 +34,6 @@ export {
|
|
|
33
34
|
type GetUserOperationHashParams,
|
|
34
35
|
signUserOperationHashWithECDSA,
|
|
35
36
|
type SignUserOperationHashWithECDSAParams,
|
|
36
|
-
AccountOrClientNotFoundError
|
|
37
|
+
AccountOrClientNotFoundError,
|
|
38
|
+
isSmartAccountDeployed
|
|
37
39
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Address, Client } from "viem"
|
|
2
|
+
import { getBytecode } from "viem/actions"
|
|
3
|
+
|
|
4
|
+
export const isSmartAccountDeployed = async (
|
|
5
|
+
client: Client,
|
|
6
|
+
address: Address
|
|
7
|
+
): Promise<boolean> => {
|
|
8
|
+
const contractCode = await getBytecode(client, {
|
|
9
|
+
address: address
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
if ((contractCode?.length ?? 0) > 2) {
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
return false
|
|
16
|
+
}
|