kokio-sdk 2.1.0 → 3.0.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.
Files changed (75) hide show
  1. package/README.md +21 -7
  2. package/dist/esm/abis/DeviceWallet.js +60 -59
  3. package/dist/esm/abis/ESIMWallet.js +263 -58
  4. package/dist/esm/abis/ESIMWalletFactory.js +2 -2
  5. package/dist/esm/abis/LazyWalletRegistry.js +68 -24
  6. package/dist/esm/abis/PaymentAdapter.js +861 -0
  7. package/dist/esm/abis/Registry.js +294 -18
  8. package/dist/esm/abis/RegistryHelper.js +101 -9
  9. package/dist/esm/abis/index.js +2 -1
  10. package/dist/esm/admin/config-admin.js +4 -0
  11. package/dist/esm/admin/interface/deviceWalletClass.js +3 -3
  12. package/dist/esm/admin/interface/eSIMWalletClass.js +6 -6
  13. package/dist/esm/admin/interface/lazyWalletRegistryClass.js +4 -1
  14. package/dist/esm/admin/interface/paymentAdapterClass.js +54 -0
  15. package/dist/esm/admin/interface/protocolAdminClass.js +6 -3
  16. package/dist/esm/admin/interface/registryClass.js +15 -6
  17. package/dist/esm/config.js +3 -0
  18. package/dist/esm/interface/deviceWalletClass.js +5 -5
  19. package/dist/esm/interface/eSIMWalletClass.js +10 -7
  20. package/dist/esm/interface/paymentAdapterClass.js +28 -0
  21. package/dist/esm/interface/registryClass.js +12 -3
  22. package/dist/esm/logic/admin/eSIMWallet.eoa.js +12 -10
  23. package/dist/esm/logic/admin/paymentAdapter.eoa.js +123 -0
  24. package/dist/esm/logic/admin/protocolAdmin.eoa.js +21 -3
  25. package/dist/esm/logic/admin/reads/deviceWallet.reads.js +2 -2
  26. package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +8 -7
  27. package/dist/esm/logic/admin/reads/lazyWalletRegistry.reads.js +19 -2
  28. package/dist/esm/logic/admin/reads/paymentAdapter.reads.js +106 -0
  29. package/dist/esm/logic/admin/reads/registry.reads.js +34 -6
  30. package/dist/esm/logic/admin/registry.eoa.js +32 -8
  31. package/dist/esm/logic/constants.js +17 -87
  32. package/dist/esm/logic/deviceWallet.js +11 -11
  33. package/dist/esm/logic/eSIMWallet.js +51 -22
  34. package/dist/esm/logic/paymentAdapter.js +116 -0
  35. package/dist/esm/logic/registry.js +50 -5
  36. package/dist/esm/types-export.js +1 -1
  37. package/dist/esm/types.js +11 -1
  38. package/dist/types/abis/DeviceWallet.d.ts +50 -49
  39. package/dist/types/abis/ESIMWallet.d.ts +215 -55
  40. package/dist/types/abis/ESIMWalletFactory.d.ts +2 -2
  41. package/dist/types/abis/LazyWalletRegistry.d.ts +58 -24
  42. package/dist/types/abis/PaymentAdapter.d.ts +661 -0
  43. package/dist/types/abis/Registry.d.ts +233 -18
  44. package/dist/types/abis/RegistryHelper.d.ts +83 -9
  45. package/dist/types/abis/index.d.ts +2 -1
  46. package/dist/types/admin/config-admin.d.ts +2 -0
  47. package/dist/types/admin/interface/deviceWalletClass.d.ts +1 -1
  48. package/dist/types/admin/interface/eSIMWalletClass.d.ts +3 -3
  49. package/dist/types/admin/interface/lazyWalletRegistryClass.d.ts +1 -0
  50. package/dist/types/admin/interface/paymentAdapterClass.d.ts +20 -0
  51. package/dist/types/admin/interface/protocolAdminClass.d.ts +2 -1
  52. package/dist/types/admin/interface/registryClass.d.ts +6 -2
  53. package/dist/types/config.d.ts +2 -0
  54. package/dist/types/interface/constantsClass.d.ts +2 -2
  55. package/dist/types/interface/deviceWalletClass.d.ts +2 -2
  56. package/dist/types/interface/eSIMWalletClass.d.ts +5 -4
  57. package/dist/types/interface/paymentAdapterClass.d.ts +13 -0
  58. package/dist/types/interface/registryClass.d.ts +5 -2
  59. package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +9 -6
  60. package/dist/types/logic/admin/paymentAdapter.eoa.d.ts +28 -0
  61. package/dist/types/logic/admin/protocolAdmin.eoa.d.ts +12 -2
  62. package/dist/types/logic/admin/reads/deviceWallet.reads.d.ts +1 -1
  63. package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +5 -4
  64. package/dist/types/logic/admin/reads/lazyWalletRegistry.reads.d.ts +7 -0
  65. package/dist/types/logic/admin/reads/paymentAdapter.reads.d.ts +30 -0
  66. package/dist/types/logic/admin/reads/registry.reads.d.ts +13 -5
  67. package/dist/types/logic/admin/registry.eoa.d.ts +18 -8
  68. package/dist/types/logic/constants.d.ts +5 -17
  69. package/dist/types/logic/deviceWallet.d.ts +7 -7
  70. package/dist/types/logic/eSIMWallet.d.ts +29 -15
  71. package/dist/types/logic/paymentAdapter.d.ts +40 -0
  72. package/dist/types/logic/registry.d.ts +20 -5
  73. package/dist/types/types-export.d.ts +2 -1
  74. package/dist/types/types.d.ts +20 -2
  75. package/package.json +1 -1
@@ -0,0 +1,116 @@
1
+ import { _getChainSpecificConstants } from "./constants.js";
2
+ import { PaymentAdapter } from "../abis/index.js";
3
+ // Every function here is a view. The adapter's only writes reachable from a
4
+ // userOp are `settle` (`onlyESIMWallet`, called from inside
5
+ // `eSIMWallet.buyDataBundleWithToken`, never directly) and
6
+ // `consumePaymentReference` (`onlyRegistry`), so neither is exposed on this
7
+ // surface. `registerAsset`/`updateAsset` are `onlyOwner`, reachable only through
8
+ // `KokioAdmin.protocolAdmin`'s timelock payloads.
9
+ /**
10
+ * The registry this adapter reads `vault()` and `isESIMWalletValid()` from.
11
+ */
12
+ export const _registry = async (client) => {
13
+ const chainID = await client.getChainId();
14
+ const rpcURL = client.transport.url;
15
+ const values = _getChainSpecificConstants(chainID, rpcURL);
16
+ return client.readContract({
17
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
18
+ abi: PaymentAdapter,
19
+ functionName: "registry",
20
+ args: []
21
+ });
22
+ };
23
+ /** The ERC-20 registered under the `USDC` symbol at configure time. */
24
+ export const _settlementToken = async (client) => {
25
+ const chainID = await client.getChainId();
26
+ const rpcURL = client.transport.url;
27
+ const values = _getChainSpecificConstants(chainID, rpcURL);
28
+ return client.readContract({
29
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
30
+ abi: PaymentAdapter,
31
+ functionName: "settlementToken",
32
+ args: []
33
+ });
34
+ };
35
+ /**
36
+ * The raw currency table entry for a symbol. `decimals` reads zero for a symbol
37
+ * never registered, which is how `resolveAsset` tells "not registered" apart
38
+ * from "registered but withdrawn" (`allowed: false`).
39
+ */
40
+ export const _assets = async (client, symbol) => {
41
+ const chainID = await client.getChainId();
42
+ const rpcURL = client.transport.url;
43
+ const values = _getChainSpecificConstants(chainID, rpcURL);
44
+ const [allowed, isDollarUnit, decimals, token] = await client.readContract({
45
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
46
+ abi: PaymentAdapter,
47
+ functionName: "assets",
48
+ args: [symbol]
49
+ });
50
+ return { allowed, isDollarUnit, decimals, token };
51
+ };
52
+ /**
53
+ * A currency's full entry, reverting if the symbol was never registered.
54
+ * `_asset` is not required for `buyDataBundleWithToken`, but is worth reading
55
+ * first: `token` being the zero address means the currency is fiat-only and the
56
+ * purchase will revert with `AssetNotTransferable`.
57
+ */
58
+ export const _resolveAsset = async (client, symbol) => {
59
+ const chainID = await client.getChainId();
60
+ const rpcURL = client.transport.url;
61
+ const values = _getChainSpecificConstants(chainID, rpcURL);
62
+ return client.readContract({
63
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
64
+ abi: PaymentAdapter,
65
+ functionName: "resolveAsset",
66
+ args: [symbol]
67
+ });
68
+ };
69
+ /**
70
+ * The amount of `symbol`, in its smallest unit, that a `priceUSDCents` charge
71
+ * currently costs. Read this before calling `buyDataBundleWithToken`, and pass
72
+ * the result (or a value at least this large) as `_maxAmountIn`: nothing today
73
+ * moves the price between the quote and the purchase, so the two always agree,
74
+ * but the contract will not assume that on the caller's behalf.
75
+ */
76
+ export const _quote = async (client, symbol, priceUSDCents) => {
77
+ const chainID = await client.getChainId();
78
+ const rpcURL = client.transport.url;
79
+ const values = _getChainSpecificConstants(chainID, rpcURL);
80
+ return client.readContract({
81
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
82
+ abi: PaymentAdapter,
83
+ functionName: "quote",
84
+ args: [symbol, priceUSDCents]
85
+ });
86
+ };
87
+ /**
88
+ * Whether a payment reference has already been spent here. Retired from the
89
+ * registry's live purchase paths (`PaymentAdapter.consumePaymentReference` is
90
+ * `onlyRegistry` but nothing calls it any more): replay protection now lives on
91
+ * `Registry.usedPaymentReferences`, scoped per eSIM wallet. Kept for whatever
92
+ * still reads the adapter's own record from before that move.
93
+ */
94
+ export const _usedReferences = async (client, paymentReference) => {
95
+ const chainID = await client.getChainId();
96
+ const rpcURL = client.transport.url;
97
+ const values = _getChainSpecificConstants(chainID, rpcURL);
98
+ return client.readContract({
99
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
100
+ abi: PaymentAdapter,
101
+ functionName: "usedReferences",
102
+ args: [paymentReference]
103
+ });
104
+ };
105
+ /** The address holding upgrade authority over this adapter (its owner). */
106
+ export const _upgradeManager = async (client) => {
107
+ const chainID = await client.getChainId();
108
+ const rpcURL = client.transport.url;
109
+ const values = _getChainSpecificConstants(chainID, rpcURL);
110
+ return client.readContract({
111
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
112
+ abi: PaymentAdapter,
113
+ functionName: "upgradeManager",
114
+ args: []
115
+ });
116
+ };
@@ -87,8 +87,9 @@ export const _isDeviceIdentifierAlreadyUsed = async (client, deviceUniqueIdentif
87
87
  });
88
88
  };
89
89
  /**
90
- * Whether the protocol is paused. While true, every ETH-moving path on the device
91
- * wallets and eSIM wallets reverts, so check this before offering a purchase.
90
+ * Whether the protocol is paused. While true, the purchase and token-pull paths
91
+ * on the device wallets and eSIM wallets revert, so check this before offering a
92
+ * purchase.
92
93
  */
93
94
  export const _paused = async (client) => {
94
95
  const chainID = await client.getChainId();
@@ -205,18 +206,62 @@ export const _eSIMWalletForIdentifier = async (client, eSIMUniqueIdentifier) =>
205
206
  args: [eSIMUniqueIdentifier]
206
207
  });
207
208
  };
208
- /** The fallback price ceiling in wei for a wallet holding no cap of its own. */
209
- export const _defaultDataBundlePriceCap = async (client) => {
209
+ /** The fallback price ceiling in USD cents for a wallet holding no cap of its own. */
210
+ export const _defaultPriceCapUSDCents = async (client) => {
210
211
  const chainID = await client.getChainId();
211
212
  const rpcURL = client.transport.url;
212
213
  const values = _getChainSpecificConstants(chainID, rpcURL);
213
214
  return client.readContract({
214
215
  address: values.factoryAddresses.REGISTRY,
215
216
  abi: Registry,
216
- functionName: "defaultDataBundlePriceCap",
217
+ functionName: "defaultPriceCapUSDCents",
217
218
  args: []
218
219
  });
219
220
  };
221
+ /** The payment adapter this registry currently points at. */
222
+ export const _paymentAdapter = async (client) => {
223
+ const chainID = await client.getChainId();
224
+ const rpcURL = client.transport.url;
225
+ const values = _getChainSpecificConstants(chainID, rpcURL);
226
+ return client.readContract({
227
+ address: values.factoryAddresses.REGISTRY,
228
+ abi: Registry,
229
+ functionName: "paymentAdapter",
230
+ args: []
231
+ });
232
+ };
233
+ /**
234
+ * Whether a payment reference has already been spent for an eSIM wallet.
235
+ * Scoped per wallet: pass the same `keccak256(abi.encode(eSIMWallet, paymentReference))`
236
+ * the contract keys `usedPaymentReferences` by, not the bare reference.
237
+ */
238
+ export const _usedPaymentReferences = async (client, scopedReference) => {
239
+ const chainID = await client.getChainId();
240
+ const rpcURL = client.transport.url;
241
+ const values = _getChainSpecificConstants(chainID, rpcURL);
242
+ return client.readContract({
243
+ address: values.factoryAddresses.REGISTRY,
244
+ abi: Registry,
245
+ functionName: "usedPaymentReferences",
246
+ args: [scopedReference]
247
+ });
248
+ };
249
+ /**
250
+ * Throws if `eSIMWallet` still has lazy-deployment history waiting to be copied
251
+ * in. `buyDataBundleWithToken` checks this itself before writing a new entry, so
252
+ * calling it first only turns that revert into a typed error ahead of a userOp.
253
+ */
254
+ export const _requireLazyHistoryCopied = async (client, eSIMWallet) => {
255
+ const chainID = await client.getChainId();
256
+ const rpcURL = client.transport.url;
257
+ const values = _getChainSpecificConstants(chainID, rpcURL);
258
+ await client.readContract({
259
+ address: values.factoryAddresses.REGISTRY,
260
+ abi: Registry,
261
+ functionName: "requireLazyHistoryCopied",
262
+ args: [eSIMWallet]
263
+ });
264
+ };
220
265
  /**
221
266
  * Throws if a fiat user's eSIMs are already waiting on this device identifier.
222
267
  * Worth calling before a deployment: taking a reserved identifier strands the
@@ -1 +1 @@
1
- export {};
1
+ export { Settlement } from './types';
package/dist/esm/types.js CHANGED
@@ -1 +1,11 @@
1
- export {};
1
+ /**
2
+ * Which contract, if any, saw the money for a data bundle move. Mirrors the
3
+ * on-chain `Settlement` enum (CustomStructs.sol) - viem decodes a Solidity enum
4
+ * as its `uint8` position, so the member order here must match exactly.
5
+ */
6
+ export var Settlement;
7
+ (function (Settlement) {
8
+ Settlement[Settlement["DeviceWallet"] = 0] = "DeviceWallet";
9
+ Settlement[Settlement["ExternalWallet"] = 1] = "ExternalWallet";
10
+ Settlement[Settlement["Fiat"] = 2] = "Fiat";
11
+ })(Settlement || (Settlement = {}));
@@ -15,7 +15,7 @@ declare const DeviceWallet: readonly [{
15
15
  readonly type: "address";
16
16
  readonly internalType: "address";
17
17
  }, {
18
- readonly name: "_hasAccessToETH";
18
+ readonly name: "_hasAccessToFunds";
19
19
  readonly type: "bool";
20
20
  readonly internalType: "bool";
21
21
  }];
@@ -23,14 +23,14 @@ declare const DeviceWallet: readonly [{
23
23
  readonly stateMutability: "nonpayable";
24
24
  }, {
25
25
  readonly type: "function";
26
- readonly name: "canPullETH";
26
+ readonly name: "canPullFunds";
27
27
  readonly inputs: readonly [{
28
28
  readonly name: "eSIMWalletAddress";
29
29
  readonly type: "address";
30
30
  readonly internalType: "address";
31
31
  }];
32
32
  readonly outputs: readonly [{
33
- readonly name: "isAllowedToPullETH";
33
+ readonly name: "isAllowedToPullFunds";
34
34
  readonly type: "bool";
35
35
  readonly internalType: "bool";
36
36
  }];
@@ -39,7 +39,7 @@ declare const DeviceWallet: readonly [{
39
39
  readonly type: "function";
40
40
  readonly name: "deployESIMWallet";
41
41
  readonly inputs: readonly [{
42
- readonly name: "_hasAccessToETH";
42
+ readonly name: "_hasAccessToFunds";
43
43
  readonly type: "bool";
44
44
  readonly internalType: "bool";
45
45
  }, {
@@ -305,8 +305,12 @@ declare const DeviceWallet: readonly [{
305
305
  readonly stateMutability: "view";
306
306
  }, {
307
307
  readonly type: "function";
308
- readonly name: "pullETH";
308
+ readonly name: "pullToken";
309
309
  readonly inputs: readonly [{
310
+ readonly name: "_token";
311
+ readonly type: "address";
312
+ readonly internalType: "address";
313
+ }, {
310
314
  readonly name: "_amount";
311
315
  readonly type: "uint256";
312
316
  readonly internalType: "uint256";
@@ -357,13 +361,13 @@ declare const DeviceWallet: readonly [{
357
361
  readonly stateMutability: "view";
358
362
  }, {
359
363
  readonly type: "function";
360
- readonly name: "toggleAccessToETH";
364
+ readonly name: "toggleAccessToFunds";
361
365
  readonly inputs: readonly [{
362
366
  readonly name: "_eSIMWalletAddress";
363
367
  readonly type: "address";
364
368
  readonly internalType: "address";
365
369
  }, {
366
- readonly name: "_hasAccessToETH";
370
+ readonly name: "_hasAccessToFunds";
367
371
  readonly type: "bool";
368
372
  readonly internalType: "bool";
369
373
  }];
@@ -500,7 +504,7 @@ declare const DeviceWallet: readonly [{
500
504
  readonly indexed: true;
501
505
  readonly internalType: "address";
502
506
  }, {
503
- readonly name: "_hasAccessToETH";
507
+ readonly name: "_hasAccessToFunds";
504
508
  readonly type: "bool";
505
509
  readonly indexed: false;
506
510
  readonly internalType: "bool";
@@ -531,21 +535,6 @@ declare const DeviceWallet: readonly [{
531
535
  readonly internalType: "address";
532
536
  }];
533
537
  readonly anonymous: false;
534
- }, {
535
- readonly type: "event";
536
- readonly name: "ETHAccessUpdated";
537
- readonly inputs: readonly [{
538
- readonly name: "_eSIMWalletAddress";
539
- readonly type: "address";
540
- readonly indexed: true;
541
- readonly internalType: "address";
542
- }, {
543
- readonly name: "_hasAccessToETH";
544
- readonly type: "bool";
545
- readonly indexed: false;
546
- readonly internalType: "bool";
547
- }];
548
- readonly anonymous: false;
549
538
  }, {
550
539
  readonly type: "event";
551
540
  readonly name: "ETHCalledBack";
@@ -558,17 +547,17 @@ declare const DeviceWallet: readonly [{
558
547
  readonly anonymous: false;
559
548
  }, {
560
549
  readonly type: "event";
561
- readonly name: "ETHSent";
550
+ readonly name: "FundsAccessUpdated";
562
551
  readonly inputs: readonly [{
563
552
  readonly name: "_eSIMWalletAddress";
564
553
  readonly type: "address";
565
554
  readonly indexed: true;
566
555
  readonly internalType: "address";
567
556
  }, {
568
- readonly name: "_amount";
569
- readonly type: "uint256";
557
+ readonly name: "_hasAccessToFunds";
558
+ readonly type: "bool";
570
559
  readonly indexed: false;
571
- readonly internalType: "uint256";
560
+ readonly internalType: "bool";
572
561
  }];
573
562
  readonly anonymous: false;
574
563
  }, {
@@ -586,6 +575,26 @@ declare const DeviceWallet: readonly [{
586
575
  readonly name: "NoETHToCallback";
587
576
  readonly inputs: readonly [];
588
577
  readonly anonymous: false;
578
+ }, {
579
+ readonly type: "event";
580
+ readonly name: "TokenSent";
581
+ readonly inputs: readonly [{
582
+ readonly name: "_token";
583
+ readonly type: "address";
584
+ readonly indexed: true;
585
+ readonly internalType: "address";
586
+ }, {
587
+ readonly name: "_eSIMWalletAddress";
588
+ readonly type: "address";
589
+ readonly indexed: true;
590
+ readonly internalType: "address";
591
+ }, {
592
+ readonly name: "_amount";
593
+ readonly type: "uint256";
594
+ readonly indexed: false;
595
+ readonly internalType: "uint256";
596
+ }];
597
+ readonly anonymous: false;
589
598
  }, {
590
599
  readonly type: "error";
591
600
  readonly name: "ESIMWalletAlreadyAdded";
@@ -608,7 +617,11 @@ declare const DeviceWallet: readonly [{
608
617
  }];
609
618
  }, {
610
619
  readonly type: "error";
611
- readonly name: "ETHAccessNotGrantableAtBind";
620
+ readonly name: "EmptyDeviceIdentifier";
621
+ readonly inputs: readonly [];
622
+ }, {
623
+ readonly type: "error";
624
+ readonly name: "FundsAccessNotGrantableAtBind";
612
625
  readonly inputs: readonly [{
613
626
  readonly name: "eSIMWallet";
614
627
  readonly type: "address";
@@ -616,32 +629,12 @@ declare const DeviceWallet: readonly [{
616
629
  }];
617
630
  }, {
618
631
  readonly type: "error";
619
- readonly name: "ETHAccessRevoked";
632
+ readonly name: "FundsAccessRevoked";
620
633
  readonly inputs: readonly [{
621
634
  readonly name: "eSIMWallet";
622
635
  readonly type: "address";
623
636
  readonly internalType: "address";
624
637
  }];
625
- }, {
626
- readonly type: "error";
627
- readonly name: "EmptyDeviceIdentifier";
628
- readonly inputs: readonly [];
629
- }, {
630
- readonly type: "error";
631
- readonly name: "FailedToTransfer";
632
- readonly inputs: readonly [];
633
- }, {
634
- readonly type: "error";
635
- readonly name: "InsufficientBalance";
636
- readonly inputs: readonly [{
637
- readonly name: "balance";
638
- readonly type: "uint256";
639
- readonly internalType: "uint256";
640
- }, {
641
- readonly name: "amount";
642
- readonly type: "uint256";
643
- readonly internalType: "uint256";
644
- }];
645
638
  }, {
646
639
  readonly type: "error";
647
640
  readonly name: "InvalidDeviceWalletOwnerKey";
@@ -686,6 +679,14 @@ declare const DeviceWallet: readonly [{
686
679
  readonly type: "error";
687
680
  readonly name: "ReentrancyGuardReentrantCall";
688
681
  readonly inputs: readonly [];
682
+ }, {
683
+ readonly type: "error";
684
+ readonly name: "SafeERC20FailedOperation";
685
+ readonly inputs: readonly [{
686
+ readonly name: "token";
687
+ readonly type: "address";
688
+ readonly internalType: "address";
689
+ }];
689
690
  }, {
690
691
  readonly type: "error";
691
692
  readonly name: "UnknownESIMWallet";