kokio-sdk 0.0.5 → 0.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokio-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/config.js",
package/src/config.ts CHANGED
@@ -16,6 +16,7 @@ export class Kokio {
16
16
  credentialId: string;
17
17
  rpId: string;
18
18
  organizationId: string;
19
+ pimlicoAPIKey: string;
19
20
  gasPolicyId: string;
20
21
 
21
22
  constants: ConstantsSubPackage;
@@ -34,6 +35,7 @@ export class Kokio {
34
35
  credentialId: string,
35
36
  rpId: string,
36
37
  organizationId: string,
38
+ pimlicoAPIKey: string,
37
39
  gasPolicyId: string,
38
40
  smartAccountClient?: SmartAccountClient,
39
41
  deviceWalletAddress?: Address,
@@ -44,11 +46,12 @@ export class Kokio {
44
46
  this.credentialId = credentialId;
45
47
  this.rpId = rpId;
46
48
  this.organizationId = organizationId;
49
+ this.pimlicoAPIKey = pimlicoAPIKey;
47
50
  this.gasPolicyId = gasPolicyId;
48
51
 
49
- this.constants = new ConstantsSubPackage(this.viemWalletClient);
52
+ this.constants = new ConstantsSubPackage(this.viemWalletClient, this.pimlicoAPIKey);
50
53
 
51
- this.smartAccount = new SmartAccountSubPackage(this.viemWalletClient, this.turnkeyClient, this.credentialId, this.rpId, this.organizationId, this.gasPolicyId);
54
+ this.smartAccount = new SmartAccountSubPackage(this.viemWalletClient, this.turnkeyClient, this.credentialId, this.rpId, this.organizationId, this.pimlicoAPIKey, this.gasPolicyId);
52
55
  this.deviceWalletFactory = smartAccountClient? new DeviceWalletFactorySubPackage(viemWalletClient, smartAccountClient): undefined;
53
56
  this.eSIMWalletFactory = smartAccountClient? new ESIMWalletFactorySubPackage(viemWalletClient, smartAccountClient): undefined;
54
57
  this.lazyWalletRegistry = smartAccountClient? new LazyWalletRegistrySubPackage(smartAccountClient): undefined;
@@ -21,11 +21,11 @@ export class ConstantsSubPackage {
21
21
  typeof arbitrumSepoliaFactoryAddresses;
22
22
  customErrors!: typeof customErrors;
23
23
 
24
- constructor(client: WalletClient) {
24
+ constructor(client: WalletClient, pimlicoAPIKey: string) {
25
25
  (async () => {
26
26
  const chainID = await _extractChainID(client);
27
27
  const rpcURL = client.transport.url;
28
- const values = _getChainSpecificConstants(chainID, rpcURL);
28
+ const values = _getChainSpecificConstants(chainID, rpcURL, pimlicoAPIKey);
29
29
 
30
30
  this.factoryAddresses = values?.factoryAddresses;
31
31
  this.customErrors = values?.customErrors;
@@ -10,15 +10,17 @@ export class SmartAccountSubPackage {
10
10
  turnkeyClient;
11
11
  credentialId;
12
12
  rpId;
13
- organizationId;
13
+ organizationId;
14
+ pimlicoAPIKey;
14
15
  gasPolicyId;
15
16
 
16
- constructor(client: WalletClient, turnkeyClient: TurnkeyClient, credentialId: string, rpId: string, organiationId: string, gasPolicyId: string) {
17
+ constructor(client: WalletClient, turnkeyClient: TurnkeyClient, credentialId: string, rpId: string, organiationId: string, pimlicoAPIKey: string, gasPolicyId: string) {
17
18
  this.client = client;
18
19
  this.turnkeyClient = turnkeyClient;
19
20
  this.credentialId = credentialId;
20
21
  this.rpId = rpId;
21
22
  this.organizationId = organiationId;
23
+ this.pimlicoAPIKey = pimlicoAPIKey;
22
24
  this.gasPolicyId = gasPolicyId;
23
25
  }
24
26
 
@@ -27,6 +29,6 @@ export class SmartAccountSubPackage {
27
29
  }
28
30
 
29
31
  getSmartWalletClient (account: SmartContractAccount) {
30
- return _getSmartWalletClient(this.client, this.gasPolicyId, account);
32
+ return _getSmartWalletClient(this.client, this.pimlicoAPIKey, this.gasPolicyId, account);
31
33
  }
32
34
  }
@@ -266,17 +266,35 @@ export const _getSmartWallet = async (
266
266
  });
267
267
  }
268
268
 
269
- export const _getSmartWalletClient = async (client: WalletClient, gasPolicyId: string, account: SmartContractAccount) => {
269
+ export const _getSmartWalletClient = async (client: WalletClient, pimlicoAPIKey: string, gasPolicyId: string, account: SmartContractAccount) => {
270
270
 
271
271
  const chainID = await client.getChainId();
272
272
  const rpcURL = client.transport.url;
273
- const values = _getChainSpecificConstants(chainID, rpcURL);
273
+ const values = _getChainSpecificConstants(chainID, rpcURL, pimlicoAPIKey);
274
+
275
+ const bundlerMethods = [
276
+ "eth_sendUserOperation",
277
+ "eth_estimateUserOperationGas",
278
+ "eth_getUserOperationReceipt",
279
+ "eth_getUserOperationByHash",
280
+ "eth_supportedEntryPoints",
281
+ ];
274
282
 
283
+ // Uses Pimlico paymaster by default for above defined bundler methods and Alchemy as fallback
275
284
  return createSmartAccountClient({
276
285
  // created above
277
286
  account: account,
278
287
  chain: values.chain,
279
- transport: http(values.rpcURL),
288
+ transport: split({
289
+ overrides: [
290
+ {
291
+ methods: bundlerMethods,
292
+ transport: http(`${values.pimlicoRpcURL}`),
293
+ },
294
+ ],
295
+ fallback: http(values.rpcURL),
296
+ }),
297
+ // transport: http(values.rpcURL),
280
298
  ...alchemyGasManagerMiddleware(gasPolicyId)
281
299
  });
282
300
  }
@@ -36,7 +36,8 @@ export interface chainSpecifcConstants {
36
36
  typeof optimismSepolia |
37
37
  typeof arbitrum |
38
38
  typeof arbitrumSepolia
39
- rpcURL: string;
39
+ rpcURL: string;
40
+ pimlicoRpcURL: string;
40
41
  customErrors: typeof customErrors;
41
42
  }
42
43
 
@@ -122,7 +123,8 @@ export const _getChainSpecificConstants = (
122
123
  CHAIN_ID.OPTIMISM_SEPOLIA |
123
124
  CHAIN_ID.ARBITRUM_ONE |
124
125
  CHAIN_ID.ARBITRUM_SEPOLIA,
125
- rpcURL: string
126
+ rpcURL: string,
127
+ pimlicoAPIKey?: string
126
128
  ): chainSpecifcConstants => {
127
129
 
128
130
  if (chainID == CHAIN_ID.SEPOLIA) {
@@ -130,6 +132,7 @@ export const _getChainSpecificConstants = (
130
132
  factoryAddresses: sepoliaFactoryAddresses,
131
133
  chain: sepolia,
132
134
  rpcURL: rpcURL,
135
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
133
136
  customErrors: customErrors
134
137
  }
135
138
  }
@@ -138,6 +141,7 @@ export const _getChainSpecificConstants = (
138
141
  factoryAddresses: mainnetFactoryAddresses,
139
142
  chain: mainnet,
140
143
  rpcURL: rpcURL,
144
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
141
145
  customErrors: customErrors
142
146
  }
143
147
  }
@@ -146,6 +150,7 @@ export const _getChainSpecificConstants = (
146
150
  factoryAddresses: optimismMainnetFactoryAddresses,
147
151
  chain: optimism,
148
152
  rpcURL: rpcURL,
153
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
149
154
  customErrors: customErrors
150
155
  }
151
156
  }
@@ -154,6 +159,7 @@ export const _getChainSpecificConstants = (
154
159
  factoryAddresses: optimismSepoliaFactoryAddresses,
155
160
  chain: optimismSepolia,
156
161
  rpcURL: rpcURL,
162
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
157
163
  customErrors: customErrors
158
164
  }
159
165
  }
@@ -162,6 +168,7 @@ export const _getChainSpecificConstants = (
162
168
  factoryAddresses: arbitrumOneFactoryAddresses,
163
169
  chain: arbitrum,
164
170
  rpcURL: rpcURL,
171
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
165
172
  customErrors: customErrors
166
173
  }
167
174
  }
@@ -170,6 +177,7 @@ export const _getChainSpecificConstants = (
170
177
  factoryAddresses: arbitrumSepoliaFactoryAddresses,
171
178
  chain: arbitrumSepolia,
172
179
  rpcURL: rpcURL,
180
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
173
181
  customErrors: customErrors
174
182
  }
175
183
  }