kokio-sdk 0.0.5 → 0.0.7

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 ADDED
@@ -0,0 +1,3 @@
1
+ # Kokio SDK
2
+
3
+ This is an internal SDK that allows Koki'o mobile app to interact with the Smart contracts.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokio-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
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
  }
@@ -5,7 +5,9 @@ import {
5
5
  optimism,
6
6
  optimismSepolia,
7
7
  arbitrum,
8
- arbitrumSepolia
8
+ arbitrumSepolia,
9
+ base,
10
+ baseSepolia
9
11
  } from "viem/chains";
10
12
 
11
13
  export const ZERO = BigInt('0');
@@ -17,6 +19,8 @@ export enum CHAIN_ID {
17
19
  SEPOLIA = 11155111,
18
20
  OPTIMISM_MAINNET = 10,
19
21
  OPTIMISM_SEPOLIA = 11155420,
22
+ BASE_MAINNET = 8453,
23
+ BASE_SEPOLIA = 84532,
20
24
  ARBITRUM_ONE = 42161,
21
25
  ARBITRUM_SEPOLIA = 421614,
22
26
  }
@@ -27,6 +31,8 @@ export interface chainSpecifcConstants {
27
31
  typeof mainnetFactoryAddresses |
28
32
  typeof optimismMainnetFactoryAddresses |
29
33
  typeof optimismSepoliaFactoryAddresses |
34
+ typeof baseMainnetFactoryAddresses |
35
+ typeof baseSepoliaFactoryAddresses |
30
36
  typeof arbitrumOneFactoryAddresses |
31
37
  typeof arbitrumSepoliaFactoryAddresses;
32
38
  chain:
@@ -34,9 +40,12 @@ export interface chainSpecifcConstants {
34
40
  typeof sepolia |
35
41
  typeof optimism |
36
42
  typeof optimismSepolia |
43
+ typeof base |
44
+ typeof baseSepolia |
37
45
  typeof arbitrum |
38
46
  typeof arbitrumSepolia
39
- rpcURL: string;
47
+ rpcURL: string;
48
+ pimlicoRpcURL: string;
40
49
  customErrors: typeof customErrors;
41
50
  }
42
51
 
@@ -80,6 +89,26 @@ export const optimismSepoliaFactoryAddresses: Record<string, Address> = {
80
89
  P256VERIFIER: '0x3c15a78046838481788613A9F111F972B562623C'
81
90
  }
82
91
 
92
+ export const baseMainnetFactoryAddresses: Record<string, Address> = {
93
+ DEVICE_WALLET_FACTORY: '0x',
94
+ ESIM_WALLET_FACTORY: '0x',
95
+ LAZY_WALLET_REGISTRY: '0x',
96
+ REGISTRY: '0x',
97
+ ENTRY_POINT: '0x',
98
+ SENDER_CREATOR: '0x',
99
+ P256VERIFIER: '0x'
100
+ }
101
+
102
+ export const baseSepoliaFactoryAddresses: Record<string, Address> = {
103
+ DEVICE_WALLET_FACTORY: '0xB4473979ff8cE4e09161B08f74EEb66BD7718076',
104
+ ESIM_WALLET_FACTORY: '0x63005d8214533fC7209678Aa39F7b9b0b51a7bcB',
105
+ LAZY_WALLET_REGISTRY: '0x8a1E53b903efcc6b252CE4bD3b255202318505Ef',
106
+ REGISTRY: '0xCa447f5C75C57f6C59027304A5Fb5A09F0E005c9',
107
+ ENTRY_POINT: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
108
+ SENDER_CREATOR: '0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c',
109
+ P256VERIFIER: '0xF04f3b3935aD461D17d4a8a78E7ea21d4a61AEb1'
110
+ }
111
+
83
112
  export const arbitrumOneFactoryAddresses: Record<string, Address> = {
84
113
  DEVICE_WALLET_FACTORY: '0x',
85
114
  ESIM_WALLET_FACTORY: '0x',
@@ -120,9 +149,12 @@ export const _getChainSpecificConstants = (
120
149
  CHAIN_ID.MAINNET |
121
150
  CHAIN_ID.OPTIMISM_MAINNET |
122
151
  CHAIN_ID.OPTIMISM_SEPOLIA |
152
+ CHAIN_ID.BASE_MAINNET |
153
+ CHAIN_ID.BASE_SEPOLIA |
123
154
  CHAIN_ID.ARBITRUM_ONE |
124
155
  CHAIN_ID.ARBITRUM_SEPOLIA,
125
- rpcURL: string
156
+ rpcURL: string,
157
+ pimlicoAPIKey?: string
126
158
  ): chainSpecifcConstants => {
127
159
 
128
160
  if (chainID == CHAIN_ID.SEPOLIA) {
@@ -130,6 +162,7 @@ export const _getChainSpecificConstants = (
130
162
  factoryAddresses: sepoliaFactoryAddresses,
131
163
  chain: sepolia,
132
164
  rpcURL: rpcURL,
165
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
133
166
  customErrors: customErrors
134
167
  }
135
168
  }
@@ -138,6 +171,7 @@ export const _getChainSpecificConstants = (
138
171
  factoryAddresses: mainnetFactoryAddresses,
139
172
  chain: mainnet,
140
173
  rpcURL: rpcURL,
174
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
141
175
  customErrors: customErrors
142
176
  }
143
177
  }
@@ -146,6 +180,7 @@ export const _getChainSpecificConstants = (
146
180
  factoryAddresses: optimismMainnetFactoryAddresses,
147
181
  chain: optimism,
148
182
  rpcURL: rpcURL,
183
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
149
184
  customErrors: customErrors
150
185
  }
151
186
  }
@@ -154,6 +189,25 @@ export const _getChainSpecificConstants = (
154
189
  factoryAddresses: optimismSepoliaFactoryAddresses,
155
190
  chain: optimismSepolia,
156
191
  rpcURL: rpcURL,
192
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
193
+ customErrors: customErrors
194
+ }
195
+ }
196
+ else if (chainID == CHAIN_ID.BASE_MAINNET) {
197
+ return {
198
+ factoryAddresses: optimismMainnetFactoryAddresses,
199
+ chain: optimism,
200
+ rpcURL: rpcURL,
201
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
202
+ customErrors: customErrors
203
+ }
204
+ }
205
+ else if (chainID == CHAIN_ID.BASE_SEPOLIA) {
206
+ return {
207
+ factoryAddresses: optimismSepoliaFactoryAddresses,
208
+ chain: optimismSepolia,
209
+ rpcURL: rpcURL,
210
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
157
211
  customErrors: customErrors
158
212
  }
159
213
  }
@@ -162,6 +216,7 @@ export const _getChainSpecificConstants = (
162
216
  factoryAddresses: arbitrumOneFactoryAddresses,
163
217
  chain: arbitrum,
164
218
  rpcURL: rpcURL,
219
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
165
220
  customErrors: customErrors
166
221
  }
167
222
  }
@@ -170,6 +225,7 @@ export const _getChainSpecificConstants = (
170
225
  factoryAddresses: arbitrumSepoliaFactoryAddresses,
171
226
  chain: arbitrumSepolia,
172
227
  rpcURL: rpcURL,
228
+ pimlicoRpcURL: pimlicoAPIKey ? `https://api.pimlico.io/v2/${chainID}/rpc?apikey=${pimlicoAPIKey}` : "",
173
229
  customErrors: customErrors
174
230
  }
175
231
  }