@graphprotocol/grc-20 0.9.0-next.0 → 0.9.0
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/README.md +30 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/smart-wallet.d.ts +39 -0
- package/dist/src/smart-wallet.d.ts.map +1 -0
- package/dist/src/smart-wallet.js +85 -0
- package/dist/src/smart-wallet.js.map +1 -0
- package/dist/src/smart-wallet.test.d.ts +2 -0
- package/dist/src/smart-wallet.test.d.ts.map +1 -0
- package/dist/src/smart-wallet.test.js +66 -0
- package/dist/src/smart-wallet.test.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -242,7 +242,7 @@ const cid = await Ipfs.publishEdit({
|
|
|
242
242
|
})
|
|
243
243
|
```
|
|
244
244
|
|
|
245
|
-
### Publishing an edit onchain
|
|
245
|
+
### Publishing an edit onchain using your wallet
|
|
246
246
|
|
|
247
247
|
Once you've uploaded the binary encoded Edit to IPFS and have correctly formed `ipfs://hash`, you can write this to a space.
|
|
248
248
|
|
|
@@ -274,6 +274,35 @@ const txResult = await walletClient.sendTransaction({
|
|
|
274
274
|
});
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
+
### Publishing an edit onchain using your Geo Account
|
|
278
|
+
|
|
279
|
+
The Geo Genesis browser uses a smart account associated with your account to publish edits. There may be situations where you want to use the same account in your code as you do on Geo Genesis. In order to get the smart account wallet client you can use the `getSmartAccountWalletClient` function.
|
|
280
|
+
|
|
281
|
+
To use `getSmartAccountWalletClient` you'll need the private key associated with your Geo account. You can get your private key using https://www.geobrowser.io/export-wallet.
|
|
282
|
+
|
|
283
|
+
Transaction costs from your smart account will be sponsored by the Geo team for the duration of the early access period. Eventually you will need to provide your own API key or provide funds to your smart account.
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
import { getSmartAccountWalletClient } from '@graphprotocol/grc-20';
|
|
287
|
+
|
|
288
|
+
// IMPORTANT: Be careful with your private key. Don't commit it to version control.
|
|
289
|
+
// You can get your private key using https://www.geobrowser.io/export-wallet
|
|
290
|
+
const privateKey = `0x${privateKeyFromGeoWallet}`;
|
|
291
|
+
const smartAccountWalletClient = await getSmartAccountWalletClient({
|
|
292
|
+
privateKey,
|
|
293
|
+
// rpcUrl, // optional
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// publish an edit to IPFS
|
|
297
|
+
// get the calldata for the edit
|
|
298
|
+
|
|
299
|
+
const txResult = await smartAccountWalletClient.sendTransaction({
|
|
300
|
+
to: to,
|
|
301
|
+
value: 0n,
|
|
302
|
+
data: data,
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
277
306
|
### Deploying a space
|
|
278
307
|
|
|
279
308
|
You can deploy spaces programmatically using the API. Currently there are two types of governance modes for spaces: one with voting and one without. They're called PUBLIC or PERSONAL spaces respectively. The API only supports deploying the PERSONAL governance mode currently.
|
package/dist/index.d.ts
CHANGED
|
@@ -59,4 +59,5 @@ export { getChecksumAddress } from './src/core/get-checksum-address.js';
|
|
|
59
59
|
*/
|
|
60
60
|
export * as Ipfs from './src/ipfs.js';
|
|
61
61
|
export * as Graph from './src/graph/index.js';
|
|
62
|
+
export { getSmartAccountWalletClient } from './src/smart-wallet.js';
|
|
62
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAE/B;;;;;GAKG;AACH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAElC;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,iCAAiC,EACjC,8BAA8B,EAC9B,wBAA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AAM,iBAAiB,CAAC;AAEnE;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE;;;;;GAKG;AACH,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -59,4 +59,5 @@ export { getChecksumAddress } from './src/core/get-checksum-address.js';
|
|
|
59
59
|
*/
|
|
60
60
|
export * as Ipfs from './src/ipfs.js';
|
|
61
61
|
export * as Graph from './src/graph/index.js';
|
|
62
|
+
export { getSmartAccountWalletClient } from './src/smart-wallet.js';
|
|
62
63
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAE/B;;;;;GAKG;AACH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAElC;;;GAGG;AACH,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,iCAAiC,EACjC,8BAA8B,EAC9B,wBAAw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iBAAiB,CAAC;AAEnE;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE;;;;;GAKG;AACH,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAEtC,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type SmartAccountClient } from 'permissionless';
|
|
2
|
+
import { type SafeSmartAccountImplementation } from 'permissionless/accounts';
|
|
3
|
+
import type { Address, Chain, Hex, HttpTransport } from 'viem';
|
|
4
|
+
import { type SmartAccountImplementation } from 'viem/account-abstraction';
|
|
5
|
+
type GetSmartAccountWalletClientParams = {
|
|
6
|
+
privateKey: Hex;
|
|
7
|
+
rpcUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
type SafeSmartAccount = SafeSmartAccountImplementation<'0.7'> & {
|
|
10
|
+
address: Address;
|
|
11
|
+
getNonce: NonNullable<SmartAccountImplementation['getNonce']>;
|
|
12
|
+
isDeployed: () => Promise<boolean>;
|
|
13
|
+
type: 'smart';
|
|
14
|
+
};
|
|
15
|
+
type GeoSmartAccount = SmartAccountClient<HttpTransport<undefined, false>, Chain, object & SafeSmartAccount & {
|
|
16
|
+
address: Address;
|
|
17
|
+
getNonce: NonNullable<SmartAccountImplementation['getNonce']>;
|
|
18
|
+
isDeployed: () => Promise<boolean>;
|
|
19
|
+
type: 'smart';
|
|
20
|
+
}, undefined, undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Get a smart account wallet client for your Geo account.
|
|
23
|
+
*
|
|
24
|
+
* IMPORTANT: Be careful with your private key. Don't commit it to version control.
|
|
25
|
+
* You can get your private key using https://www.geobrowser.io/export-wallet
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const smartAccountWalletClient = await getSmartAccountWalletClient({
|
|
30
|
+
* privateKey: '0x...',
|
|
31
|
+
* rpcUrl: '...', // optional
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
* @param params – {@link GetSmartAccountWalletClientParams}
|
|
35
|
+
* @returns – {@link SmartAccountClient}
|
|
36
|
+
*/
|
|
37
|
+
export declare const getSmartAccountWalletClient: ({ privateKey, rpcUrl, }: GetSmartAccountWalletClientParams) => Promise<GeoSmartAccount>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=smart-wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet.d.ts","sourceRoot":"","sources":["../../src/smart-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAA4B,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,KAAK,8BAA8B,EAAsB,MAAM,yBAAyB,CAAC;AAElG,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE/D,OAAO,EAAE,KAAK,0BAA0B,EAAuB,MAAM,0BAA0B,CAAC;AAWhG,KAAK,iCAAiC,GAAG;IACvC,UAAU,EAAE,GAAG,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,gBAAgB,GAAG,8BAA8B,CAAC,KAAK,CAAC,GAAG;IAC9D,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,WAAW,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9D,UAAU,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,KAAK,eAAe,GAAG,kBAAkB,CACvC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,EAC/B,KAAK,EACL,MAAM,GACJ,gBAAgB,GAAG;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,WAAW,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9D,UAAU,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,EAAE,OAAO,CAAC;CACf,EACH,SAAS,EACT,SAAS,CACV,CAAC;AAIF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,2BAA2B,GAAU,yBAG/C,iCAAiC,KAAG,OAAO,CAAC,eAAe,CA4D7D,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createSmartAccountClient } from 'permissionless';
|
|
2
|
+
import { toSafeSmartAccount } from 'permissionless/accounts';
|
|
3
|
+
import { createPimlicoClient } from 'permissionless/clients/pimlico';
|
|
4
|
+
import { http, createPublicClient } from 'viem';
|
|
5
|
+
import { entryPoint07Address } from 'viem/account-abstraction';
|
|
6
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
7
|
+
const DEFAULT_RPC_URL = 'https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz';
|
|
8
|
+
/**
|
|
9
|
+
* We provide a fallback API key for gas sponsorship for the duration of the
|
|
10
|
+
* Geo Genesis early access period. This API key is gas-limited.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_API_KEY = 'pim_KqHm63txxhbCYjdDaWaHqH';
|
|
13
|
+
// type GeoSmartAccountWalletClient = Promise<ReturnType<typeof createSmartAccountClient>>;
|
|
14
|
+
/**
|
|
15
|
+
* Get a smart account wallet client for your Geo account.
|
|
16
|
+
*
|
|
17
|
+
* IMPORTANT: Be careful with your private key. Don't commit it to version control.
|
|
18
|
+
* You can get your private key using https://www.geobrowser.io/export-wallet
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const smartAccountWalletClient = await getSmartAccountWalletClient({
|
|
23
|
+
* privateKey: '0x...',
|
|
24
|
+
* rpcUrl: '...', // optional
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
* @param params – {@link GetSmartAccountWalletClientParams}
|
|
28
|
+
* @returns – {@link SmartAccountClient}
|
|
29
|
+
*/
|
|
30
|
+
export const getSmartAccountWalletClient = async ({ privateKey, rpcUrl = DEFAULT_RPC_URL, }) => {
|
|
31
|
+
const GEOGENESIS = {
|
|
32
|
+
id: Number('80451'),
|
|
33
|
+
name: 'Geo Genesis',
|
|
34
|
+
nativeCurrency: {
|
|
35
|
+
name: 'Ethereum',
|
|
36
|
+
symbol: 'ETH',
|
|
37
|
+
decimals: 18,
|
|
38
|
+
},
|
|
39
|
+
rpcUrls: {
|
|
40
|
+
default: {
|
|
41
|
+
http: [rpcUrl],
|
|
42
|
+
},
|
|
43
|
+
public: {
|
|
44
|
+
http: [rpcUrl],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const transport = http(rpcUrl);
|
|
49
|
+
const publicClient = createPublicClient({
|
|
50
|
+
transport,
|
|
51
|
+
chain: GEOGENESIS,
|
|
52
|
+
});
|
|
53
|
+
const safeAccount = await toSafeSmartAccount({
|
|
54
|
+
client: publicClient,
|
|
55
|
+
owners: [privateKeyToAccount(privateKey)],
|
|
56
|
+
entryPoint: {
|
|
57
|
+
// optional, defaults to 0.7
|
|
58
|
+
address: entryPoint07Address,
|
|
59
|
+
version: '0.7',
|
|
60
|
+
},
|
|
61
|
+
version: '1.4.1',
|
|
62
|
+
});
|
|
63
|
+
const bundlerTransport = http(`https://api.pimlico.io/v2/80451/rpc?apikey=${DEFAULT_API_KEY}`);
|
|
64
|
+
const paymasterClient = createPimlicoClient({
|
|
65
|
+
transport: bundlerTransport,
|
|
66
|
+
chain: GEOGENESIS,
|
|
67
|
+
entryPoint: {
|
|
68
|
+
address: entryPoint07Address,
|
|
69
|
+
version: '0.7',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const smartAccount = createSmartAccountClient({
|
|
73
|
+
chain: GEOGENESIS,
|
|
74
|
+
account: safeAccount,
|
|
75
|
+
paymaster: paymasterClient,
|
|
76
|
+
bundlerTransport,
|
|
77
|
+
userOperation: {
|
|
78
|
+
estimateFeesPerGas: async () => {
|
|
79
|
+
return (await paymasterClient.getUserOperationGasPrice()).fast;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return smartAccount;
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=smart-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet.js","sourceRoot":"","sources":["../../src/smart-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAuC,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAmC,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,eAAe,GAAG,kDAAkD,CAAC;AAE3E;;;GAGG;AACH,MAAM,eAAe,GAAG,4BAA4B,CAAC;AA4BrD,2FAA2F;AAE3F;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,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,KAAK,IAAI,EAAE;gBAC7B,OAAO,CAAC,MAAM,eAAe,CAAC,wBAAwB,EAAE,CAAC,CAAC,IAAI,CAAC;YACjE,CAAC;SACF;KACF,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet.test.d.ts","sourceRoot":"","sources":["../../src/smart-wallet.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { toSafeSmartAccount } from 'permissionless/accounts';
|
|
2
|
+
import { http, createPublicClient } from 'viem';
|
|
3
|
+
import { entryPoint07Address } from 'viem/account-abstraction';
|
|
4
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
5
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { getSmartAccountWalletClient } from './smart-wallet.js';
|
|
7
|
+
// mock all external dependencies
|
|
8
|
+
vi.mock('permissionless', () => ({
|
|
9
|
+
createSmartAccountClient: vi.fn().mockReturnValue({ mockSmartAccountClient: true }),
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('permissionless/accounts', () => ({
|
|
12
|
+
toSafeSmartAccount: vi.fn().mockResolvedValue({ mockSafeAccount: true }),
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('permissionless/clients/pimlico', () => ({
|
|
15
|
+
createPimlicoClient: vi.fn().mockReturnValue({
|
|
16
|
+
mockPimlicoClient: true,
|
|
17
|
+
getUserOperationGasPrice: vi.fn().mockResolvedValue({
|
|
18
|
+
fast: { maxFeePerGas: 1000000000n, maxPriorityFeePerGas: 100000000n },
|
|
19
|
+
}),
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('viem', () => ({
|
|
23
|
+
createPublicClient: vi.fn().mockReturnValue({ mockPublicClient: true }),
|
|
24
|
+
http: vi.fn().mockImplementation(url => ({ mockTransport: true, url })),
|
|
25
|
+
}));
|
|
26
|
+
vi.mock('viem/accounts', () => ({
|
|
27
|
+
privateKeyToAccount: vi.fn().mockReturnValue({ mockAccount: true }),
|
|
28
|
+
}));
|
|
29
|
+
describe('getSmartAccountWalletClient', () => {
|
|
30
|
+
const mockPrivateKey = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef';
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
vi.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
it('should create a client with the default RPC URL when no RPC URL is provided', async () => {
|
|
35
|
+
await getSmartAccountWalletClient({ privateKey: mockPrivateKey, });
|
|
36
|
+
expect(http).toHaveBeenCalledWith('https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz');
|
|
37
|
+
expect(createPublicClient).toHaveBeenCalledWith(expect.objectContaining({
|
|
38
|
+
transport: { mockTransport: true, url: 'https://rpc-geo-genesis-h0q2s21xx8.t.conduit.xyz' },
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
it('should create a client with a custom RPC URL when provided', async () => {
|
|
42
|
+
const customRpcUrl = 'https://custom-rpc.example.com';
|
|
43
|
+
await getSmartAccountWalletClient({
|
|
44
|
+
privateKey: mockPrivateKey,
|
|
45
|
+
rpcUrl: customRpcUrl,
|
|
46
|
+
});
|
|
47
|
+
expect(http).toHaveBeenCalledWith(customRpcUrl);
|
|
48
|
+
expect(createPublicClient).toHaveBeenCalledWith(expect.objectContaining({
|
|
49
|
+
transport: { mockTransport: true, url: customRpcUrl },
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
it('should initialize safe account with correct parameters', async () => {
|
|
53
|
+
await getSmartAccountWalletClient({ privateKey: mockPrivateKey, });
|
|
54
|
+
expect(privateKeyToAccount).toHaveBeenCalledWith(mockPrivateKey);
|
|
55
|
+
expect(toSafeSmartAccount).toHaveBeenCalledWith(expect.objectContaining({
|
|
56
|
+
client: { mockPublicClient: true },
|
|
57
|
+
owners: [{ mockAccount: true }],
|
|
58
|
+
entryPoint: {
|
|
59
|
+
address: entryPoint07Address,
|
|
60
|
+
version: '0.7',
|
|
61
|
+
},
|
|
62
|
+
version: '1.4.1',
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=smart-wallet.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet.test.js","sourceRoot":"","sources":["../../src/smart-wallet.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAEhE,iCAAiC;AACjC,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/B,wBAAwB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC;CACpF,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,kBAAkB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;CACzE,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,gCAAgC,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/C,mBAAmB,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC;QAC3C,iBAAiB,EAAE,IAAI;QACvB,wBAAwB,EAA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",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"fflate": "^0.8.2",
|
|
27
27
|
"effect": "^3.13.6",
|
|
28
28
|
"image-size": "^2.0.0",
|
|
29
|
+
"permissionless": "^0.2.35",
|
|
29
30
|
"position-strings": "^2.0.1",
|
|
30
31
|
"uuid": "^11.1.0",
|
|
31
32
|
"viem": "^2.23.6"
|