kokio-sdk 3.3.0 → 3.5.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 (55) hide show
  1. package/README.md +8 -4
  2. package/dist/esm/abis/DeviceWallet.js +29 -0
  3. package/dist/esm/abis/ESIMWallet.js +55 -0
  4. package/dist/esm/abis/PaymentAdapter.js +53 -0
  5. package/dist/esm/abis/ProtocolAdmin.js +48 -0
  6. package/dist/esm/abis/Registry.js +55 -0
  7. package/dist/esm/abis/RegistryHelper.js +13 -0
  8. package/dist/esm/admin/config-admin.js +3 -1
  9. package/dist/esm/admin/interface/eSIMWalletClass.js +4 -1
  10. package/dist/esm/admin/interface/paymentAdapterClass.js +4 -1
  11. package/dist/esm/admin/interface/protocolAdminClass.js +7 -1
  12. package/dist/esm/admin/interface/registryClass.js +6 -3
  13. package/dist/esm/admin/interface/utilsClass.js +19 -3
  14. package/dist/esm/interface/deviceWalletClass.js +6 -3
  15. package/dist/esm/interface/eSIMWalletClass.js +7 -1
  16. package/dist/esm/interface/registryClass.js +4 -1
  17. package/dist/esm/logic/admin/eSIMWallet.eoa.js +9 -1
  18. package/dist/esm/logic/admin/paymentAdapter.eoa.js +16 -0
  19. package/dist/esm/logic/admin/protocolAdmin.eoa.js +34 -0
  20. package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +12 -0
  21. package/dist/esm/logic/admin/reads/registry.reads.js +12 -0
  22. package/dist/esm/logic/admin/registry.eoa.js +79 -5
  23. package/dist/esm/logic/admin/utils/paymentReference.js +58 -0
  24. package/dist/esm/logic/constants.js +11 -14
  25. package/dist/esm/logic/deviceWallet.js +19 -6
  26. package/dist/esm/logic/eSIMWallet.js +36 -0
  27. package/dist/esm/logic/errors.js +38 -0
  28. package/dist/esm/logic/registry.js +12 -0
  29. package/dist/types/abis/DeviceWallet.d.ts +22 -0
  30. package/dist/types/abis/ESIMWallet.d.ts +42 -0
  31. package/dist/types/abis/PaymentAdapter.d.ts +42 -0
  32. package/dist/types/abis/ProtocolAdmin.d.ts +37 -0
  33. package/dist/types/abis/Registry.d.ts +42 -0
  34. package/dist/types/abis/RegistryHelper.d.ts +10 -0
  35. package/dist/types/admin/config-admin.d.ts +2 -1
  36. package/dist/types/admin/interface/eSIMWalletClass.d.ts +1 -0
  37. package/dist/types/admin/interface/paymentAdapterClass.d.ts +1 -0
  38. package/dist/types/admin/interface/protocolAdminClass.d.ts +2 -0
  39. package/dist/types/admin/interface/registryClass.d.ts +14 -1
  40. package/dist/types/admin/interface/utilsClass.d.ts +19 -4
  41. package/dist/types/interface/deviceWalletClass.d.ts +2 -1
  42. package/dist/types/interface/eSIMWalletClass.d.ts +2 -0
  43. package/dist/types/interface/registryClass.d.ts +1 -0
  44. package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +3 -0
  45. package/dist/types/logic/admin/paymentAdapter.eoa.d.ts +6 -0
  46. package/dist/types/logic/admin/protocolAdmin.eoa.d.ts +14 -0
  47. package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +5 -0
  48. package/dist/types/logic/admin/reads/registry.reads.d.ts +2 -0
  49. package/dist/types/logic/admin/registry.eoa.d.ts +23 -2
  50. package/dist/types/logic/admin/utils/paymentReference.d.ts +26 -0
  51. package/dist/types/logic/deviceWallet.d.ts +11 -5
  52. package/dist/types/logic/eSIMWallet.d.ts +14 -0
  53. package/dist/types/logic/errors.d.ts +27 -0
  54. package/dist/types/logic/registry.d.ts +2 -0
  55. package/package.json +1 -1
package/README.md CHANGED
@@ -249,10 +249,14 @@ const { factoryAddresses, chain, rpcURL } = await kokio.constants;
249
249
  ```
250
250
 
251
251
  The SDK resolves these from the wallet client's connected chain id, so you do not
252
- pass addresses yourself. Base Sepolia (chain id `84532`) is the only chain with a
253
- live deployment today. Ethereum, Optimism, and Arbitrum (mainnet and their
254
- testnets) are wired into the chain-resolution logic but not yet deployed;
255
- connecting to one of them throws `UnconfiguredChainError` until it is.
252
+ pass addresses yourself.
253
+
254
+ | Chain | Chain id | EntryPoint |
255
+ |---|---|---|
256
+ | Base mainnet | `8453` | v0.8, `0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108` |
257
+ | Base Sepolia | `84532` | v0.8, `0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108` |
258
+
259
+ Any other chain id throws `UnsupportedChainError`. The contract addresses for each chain are in `src/logic/constants.ts`, taken from the deployment records in `smart-contract-suite/deployments/`.
256
260
 
257
261
  ## Testing
258
262
 
@@ -453,6 +453,25 @@ const DeviceWallet = [
453
453
  "outputs": [],
454
454
  "stateMutability": "nonpayable"
455
455
  },
456
+ {
457
+ "type": "function",
458
+ "name": "rotationChallenge",
459
+ "inputs": [
460
+ {
461
+ "name": "newOwner",
462
+ "type": "bytes32[2]",
463
+ "internalType": "bytes32[2]"
464
+ }
465
+ ],
466
+ "outputs": [
467
+ {
468
+ "name": "",
469
+ "type": "bytes",
470
+ "internalType": "bytes"
471
+ }
472
+ ],
473
+ "stateMutability": "view"
474
+ },
456
475
  {
457
476
  "type": "function",
458
477
  "name": "supportsInterface",
@@ -498,6 +517,11 @@ const DeviceWallet = [
498
517
  "name": "newOwner",
499
518
  "type": "bytes32[2]",
500
519
  "internalType": "bytes32[2]"
520
+ },
521
+ {
522
+ "name": "newOwnerSignature",
523
+ "type": "bytes",
524
+ "internalType": "bytes"
501
525
  }
502
526
  ],
503
527
  "outputs": [
@@ -838,6 +862,11 @@ const DeviceWallet = [
838
862
  "name": "InvalidInitialization",
839
863
  "inputs": []
840
864
  },
865
+ {
866
+ "type": "error",
867
+ "name": "NewOwnerKeyCannotSign",
868
+ "inputs": []
869
+ },
841
870
  {
842
871
  "type": "error",
843
872
  "name": "NotInitializing",
@@ -10,6 +10,19 @@ const ESIMWallet = [
10
10
  "outputs": [],
11
11
  "stateMutability": "nonpayable"
12
12
  },
13
+ {
14
+ "type": "function",
15
+ "name": "adminAllowanceUSDCents",
16
+ "inputs": [],
17
+ "outputs": [
18
+ {
19
+ "name": "",
20
+ "type": "uint64",
21
+ "internalType": "uint64"
22
+ }
23
+ ],
24
+ "stateMutability": "view"
25
+ },
13
26
  {
14
27
  "type": "function",
15
28
  "name": "buyDataBundleWithToken",
@@ -286,6 +299,19 @@ const ESIMWallet = [
286
299
  ],
287
300
  "stateMutability": "nonpayable"
288
301
  },
302
+ {
303
+ "type": "function",
304
+ "name": "setAdminAllowanceUSDCents",
305
+ "inputs": [
306
+ {
307
+ "name": "_allowance",
308
+ "type": "uint64",
309
+ "internalType": "uint64"
310
+ }
311
+ ],
312
+ "outputs": [],
313
+ "stateMutability": "nonpayable"
314
+ },
289
315
  {
290
316
  "type": "function",
291
317
  "name": "setESIMUniqueIdentifier",
@@ -354,6 +380,19 @@ const ESIMWallet = [
354
380
  "outputs": [],
355
381
  "stateMutability": "pure"
356
382
  },
383
+ {
384
+ "type": "event",
385
+ "name": "AdminAllowanceUSDCentsUpdated",
386
+ "inputs": [
387
+ {
388
+ "name": "_allowance",
389
+ "type": "uint64",
390
+ "indexed": false,
391
+ "internalType": "uint64"
392
+ }
393
+ ],
394
+ "anonymous": false
395
+ },
357
396
  {
358
397
  "type": "event",
359
398
  "name": "DataBundleBoughtWithToken",
@@ -623,6 +662,22 @@ const ESIMWallet = [
623
662
  ],
624
663
  "anonymous": false
625
664
  },
665
+ {
666
+ "type": "error",
667
+ "name": "AdminAllowanceExceeded",
668
+ "inputs": [
669
+ {
670
+ "name": "priceUSDCents",
671
+ "type": "uint64",
672
+ "internalType": "uint64"
673
+ },
674
+ {
675
+ "name": "remaining",
676
+ "type": "uint64",
677
+ "internalType": "uint64"
678
+ }
679
+ ]
680
+ },
626
681
  {
627
682
  "type": "error",
628
683
  "name": "AssetNotTransferable",
@@ -152,6 +152,29 @@ const PaymentAdapter = [
152
152
  ],
153
153
  "stateMutability": "view"
154
154
  },
155
+ {
156
+ "type": "function",
157
+ "name": "recoverTokens",
158
+ "inputs": [
159
+ {
160
+ "name": "_token",
161
+ "type": "address",
162
+ "internalType": "address"
163
+ },
164
+ {
165
+ "name": "_to",
166
+ "type": "address",
167
+ "internalType": "address"
168
+ },
169
+ {
170
+ "name": "_amount",
171
+ "type": "uint256",
172
+ "internalType": "uint256"
173
+ }
174
+ ],
175
+ "outputs": [],
176
+ "stateMutability": "nonpayable"
177
+ },
155
178
  {
156
179
  "type": "function",
157
180
  "name": "registerAsset",
@@ -571,6 +594,31 @@ const PaymentAdapter = [
571
594
  ],
572
595
  "anonymous": false
573
596
  },
597
+ {
598
+ "type": "event",
599
+ "name": "TokensRecovered",
600
+ "inputs": [
601
+ {
602
+ "name": "_token",
603
+ "type": "address",
604
+ "indexed": true,
605
+ "internalType": "address"
606
+ },
607
+ {
608
+ "name": "_to",
609
+ "type": "address",
610
+ "indexed": true,
611
+ "internalType": "address"
612
+ },
613
+ {
614
+ "name": "_amount",
615
+ "type": "uint256",
616
+ "indexed": false,
617
+ "internalType": "uint256"
618
+ }
619
+ ],
620
+ "anonymous": false
621
+ },
574
622
  {
575
623
  "type": "event",
576
624
  "name": "Upgraded",
@@ -852,6 +900,11 @@ const PaymentAdapter = [
852
900
  }
853
901
  ]
854
902
  },
903
+ {
904
+ "type": "error",
905
+ "name": "ZeroAmount",
906
+ "inputs": []
907
+ },
855
908
  {
856
909
  "type": "error",
857
910
  "name": "ZeroDataBundlePrice",
@@ -582,6 +582,19 @@ const ProtocolAdmin = [
582
582
  ],
583
583
  "stateMutability": "nonpayable"
584
584
  },
585
+ {
586
+ "type": "function",
587
+ "name": "pauseInstantly",
588
+ "inputs": [
589
+ {
590
+ "name": "target",
591
+ "type": "address",
592
+ "internalType": "address"
593
+ }
594
+ ],
595
+ "outputs": [],
596
+ "stateMutability": "nonpayable"
597
+ },
585
598
  {
586
599
  "type": "function",
587
600
  "name": "renounceRole",
@@ -959,6 +972,25 @@ const ProtocolAdmin = [
959
972
  ],
960
973
  "anonymous": false
961
974
  },
975
+ {
976
+ "type": "event",
977
+ "name": "PauseRaised",
978
+ "inputs": [
979
+ {
980
+ "name": "target",
981
+ "type": "address",
982
+ "indexed": true,
983
+ "internalType": "address"
984
+ },
985
+ {
986
+ "name": "guardian",
987
+ "type": "address",
988
+ "indexed": true,
989
+ "internalType": "address"
990
+ }
991
+ ],
992
+ "anonymous": false
993
+ },
962
994
  {
963
995
  "type": "event",
964
996
  "name": "PauseReleased",
@@ -1105,6 +1137,22 @@ const ProtocolAdmin = [
1105
1137
  "name": "NoProposers",
1106
1138
  "inputs": []
1107
1139
  },
1140
+ {
1141
+ "type": "error",
1142
+ "name": "NomineeIsTheIncumbent",
1143
+ "inputs": [
1144
+ {
1145
+ "name": "target",
1146
+ "type": "address",
1147
+ "internalType": "address"
1148
+ },
1149
+ {
1150
+ "name": "admin",
1151
+ "type": "address",
1152
+ "internalType": "address"
1153
+ }
1154
+ ]
1155
+ },
1108
1156
  {
1109
1157
  "type": "error",
1110
1158
  "name": "NotACanceller",
@@ -151,6 +151,19 @@ const Registry = [
151
151
  "outputs": [],
152
152
  "stateMutability": "nonpayable"
153
153
  },
154
+ {
155
+ "type": "function",
156
+ "name": "defaultAdminAllowanceUSDCents",
157
+ "inputs": [],
158
+ "outputs": [
159
+ {
160
+ "name": "",
161
+ "type": "uint64",
162
+ "internalType": "uint64"
163
+ }
164
+ ],
165
+ "stateMutability": "view"
166
+ },
154
167
  {
155
168
  "type": "function",
156
169
  "name": "defaultPriceCapUSDCents",
@@ -394,6 +407,11 @@ const Registry = [
394
407
  "name": "_defaultPriceCapUSDCents",
395
408
  "type": "uint64",
396
409
  "internalType": "uint64"
410
+ },
411
+ {
412
+ "name": "_defaultAdminAllowanceUSDCents",
413
+ "type": "uint64",
414
+ "internalType": "uint64"
397
415
  }
398
416
  ],
399
417
  "outputs": [],
@@ -749,6 +767,19 @@ const Registry = [
749
767
  "outputs": [],
750
768
  "stateMutability": "view"
751
769
  },
770
+ {
771
+ "type": "function",
772
+ "name": "setDefaultAdminAllowanceUSDCents",
773
+ "inputs": [
774
+ {
775
+ "name": "_allowance",
776
+ "type": "uint64",
777
+ "internalType": "uint64"
778
+ }
779
+ ],
780
+ "outputs": [],
781
+ "stateMutability": "nonpayable"
782
+ },
752
783
  {
753
784
  "type": "function",
754
785
  "name": "setDefaultPriceCapUSDCents",
@@ -1094,6 +1125,19 @@ const Registry = [
1094
1125
  ],
1095
1126
  "anonymous": false
1096
1127
  },
1128
+ {
1129
+ "type": "event",
1130
+ "name": "DefaultAdminAllowanceUSDCentsUpdated",
1131
+ "inputs": [
1132
+ {
1133
+ "name": "_allowance",
1134
+ "type": "uint64",
1135
+ "indexed": false,
1136
+ "internalType": "uint64"
1137
+ }
1138
+ ],
1139
+ "anonymous": false
1140
+ },
1097
1141
  {
1098
1142
  "type": "event",
1099
1143
  "name": "DefaultPriceCapUSDCentsUpdated",
@@ -1719,6 +1763,17 @@ const Registry = [
1719
1763
  }
1720
1764
  ]
1721
1765
  },
1766
+ {
1767
+ "type": "error",
1768
+ "name": "OwnerKeyNotHeldByWallet",
1769
+ "inputs": [
1770
+ {
1771
+ "name": "deviceWallet",
1772
+ "type": "address",
1773
+ "internalType": "address"
1774
+ }
1775
+ ]
1776
+ },
1722
1777
  {
1723
1778
  "type": "error",
1724
1779
  "name": "OwnershipCannotBeRenounced",
@@ -495,6 +495,19 @@ const RegistryHelper = [
495
495
  ],
496
496
  "anonymous": false
497
497
  },
498
+ {
499
+ "type": "event",
500
+ "name": "DefaultAdminAllowanceUSDCentsUpdated",
501
+ "inputs": [
502
+ {
503
+ "name": "_allowance",
504
+ "type": "uint64",
505
+ "indexed": false,
506
+ "internalType": "uint64"
507
+ }
508
+ ],
509
+ "anonymous": false
510
+ },
498
511
  {
499
512
  "type": "event",
500
513
  "name": "DefaultPriceCapUSDCentsUpdated",
@@ -12,10 +12,12 @@ import { AdminUtilsSubPackage } from "./interface/utilsClass.js";
12
12
  // Re-export the typed error surface so backend consumers can `instanceof
13
13
  // KokioError` (or a subclass) and decode reverts without reaching into internal
14
14
  // module paths - mirroring `config.ts`.
15
- export { KokioError, NullOrUndefinedValueError, MissingSmartWalletError, MissingEOAWalletError, InvalidClientError, UnsupportedChainError, UnconfiguredChainError, CounterfactualMismatchError, BatchSizeOutOfRangeError, DepositOnResumeError, ESIMWalletNotLazyDeployedError, MissingBatchEventError, StalledBatchError, InvalidAddressError, InvalidSymbolError, TokenNotAcceptedError, NotAProtocolESIMWalletError, UnknownTransactionError, TransactionRevertedError, ReceiptNotCanonicalError, NotAnERC20TokenError, UnmatchedPaymentEventsError, PriceOutOfRangeError, ContractRevertError, decodeContractRevert, } from "../logic/errors.js";
15
+ export { KokioError, NullOrUndefinedValueError, MissingSmartWalletError, MissingEOAWalletError, InvalidClientError, UnsupportedChainError, UnconfiguredChainError, CounterfactualMismatchError, BatchSizeOutOfRangeError, DepositOnResumeError, ESIMWalletNotLazyDeployedError, MissingBatchEventError, StalledBatchError, InvalidAddressError, InvalidSymbolError, TokenNotAcceptedError, NotAProtocolESIMWalletError, UnknownTransactionError, TransactionRevertedError, ReceiptNotCanonicalError, NotAnERC20TokenError, UnmatchedPaymentEventsError, PriceOutOfRangeError, AdminAllowanceExceededError, InvalidPaymentReferenceError, CouponSplitOutOfRangeError, ContractRevertError, decodeContractRevert, } from "../logic/errors.js";
16
16
  // `getOperationState` answers with this, and comparing against it needs the enum
17
17
  // at runtime rather than only in the types.
18
18
  export { OperationState } from "../logic/admin/reads/protocolAdmin.reads.js";
19
+ // Passed to `utils.tagPaymentReference` and returned by `utils.parsePaymentReference`.
20
+ export { PaymentReferenceKind } from "../logic/admin/utils/paymentReference.js";
19
21
  /**
20
22
  * EOA-only entry point for the NodeJS backend.
21
23
  *
@@ -1,5 +1,5 @@
1
1
  import { _buyDataBundleWithToken } from "../../logic/admin/eSIMWallet.eoa.js";
2
- import { _eSIMWalletFactory, _eSIMUniqueIdentifier, _newRequestedOwner, _owner, _priceCapUSDCents, _deviceWallet, _transactionHistory, } from "../../logic/admin/reads/eSIMWallet.reads.js";
2
+ import { _adminAllowanceUSDCents, _eSIMWalletFactory, _eSIMUniqueIdentifier, _newRequestedOwner, _owner, _priceCapUSDCents, _deviceWallet, _transactionHistory, } from "../../logic/admin/reads/eSIMWallet.reads.js";
3
3
  /**
4
4
  * Thin EOA wrapper around a specific `ESIMWallet` instance. The instance address
5
5
  * is bound at construction; `KokioAdmin.setESIMWalletAddress` swaps it by
@@ -31,6 +31,9 @@ export class AdminESIMWalletSubPackage {
31
31
  priceCapUSDCents() {
32
32
  return _priceCapUSDCents(this.walletClient, this.eSIMWalletAddress);
33
33
  }
34
+ adminAllowanceUSDCents() {
35
+ return _adminAllowanceUSDCents(this.walletClient, this.eSIMWalletAddress);
36
+ }
34
37
  deviceWallet() {
35
38
  return _deviceWallet(this.walletClient, this.eSIMWalletAddress);
36
39
  }
@@ -1,5 +1,5 @@
1
1
  import { _registry, _settlementToken, _assets, _resolveAsset, _quote, _usedReferences, _upgradeManager } from "../../logic/admin/reads/paymentAdapter.reads.js";
2
- import { _registerAsset, _updateAsset, _registerAssetCall, _updateAssetCall, _transferOwnershipCall, _upgradeCall, _acceptOwnership } from "../../logic/admin/paymentAdapter.eoa.js";
2
+ import { _registerAsset, _updateAsset, _registerAssetCall, _updateAssetCall, _recoverTokensCall, _transferOwnershipCall, _upgradeCall, _acceptOwnership } from "../../logic/admin/paymentAdapter.eoa.js";
3
3
  export class AdminPaymentAdapterSubPackage {
4
4
  walletClient;
5
5
  constructor(walletClient) {
@@ -42,6 +42,9 @@ export class AdminPaymentAdapterSubPackage {
42
42
  registerAssetCall(symbol, asset) {
43
43
  return _registerAssetCall(this.walletClient, symbol, asset);
44
44
  }
45
+ recoverTokensCall(token, to, amount) {
46
+ return _recoverTokensCall(this.walletClient, token, to, amount);
47
+ }
45
48
  updateAssetCall(symbol, asset) {
46
49
  return _updateAssetCall(this.walletClient, symbol, asset);
47
50
  }
@@ -1,4 +1,4 @@
1
- import { _operationId, _operationIdBatch, _operationIdRaw, _operationIdBatchRaw, _schedule, _scheduleBatch, _scheduleRaw, _execute, _executeBatch, _executeRaw, _cancel, _unpauseInstantly, _revokeCancellersInstantly, _disableAdminInstantly, _acceptOwnershipBatch, _renounceRole, _grantRoleCall, _revokeRoleCall, _updateDelayCall, _disableAndNominateCall, _disableAdminCall, _enableAdminCall, _unpauseCall, _setDefaultPriceCapUSDCentsCall, _setPaymentAdapterCall, } from "../../logic/admin/protocolAdmin.eoa.js";
1
+ import { _operationId, _operationIdBatch, _operationIdRaw, _operationIdBatchRaw, _schedule, _scheduleBatch, _scheduleRaw, _execute, _executeBatch, _executeRaw, _cancel, _pauseInstantly, _unpauseInstantly, _revokeCancellersInstantly, _disableAdminInstantly, _acceptOwnershipBatch, _renounceRole, _grantRoleCall, _revokeRoleCall, _updateDelayCall, _disableAndNominateCall, _disableAdminCall, _enableAdminCall, _unpauseCall, _setDefaultPriceCapUSDCentsCall, _setDefaultAdminAllowanceUSDCentsCall, _setPaymentAdapterCall, } from "../../logic/admin/protocolAdmin.eoa.js";
2
2
  import { _getMinDelay, _minDelayFloor, _getOperationState, _getTimestamp, _isOperation, _isOperationPending, _isOperationReady, _isOperationDone, _hasRole, _getRoleAdmin, _defaultAdminRole, _proposerRole, _cancellerRole, _executorRole, _guardianRole, } from "../../logic/admin/reads/protocolAdmin.reads.js";
3
3
  /** Schedules operations. Needs an EOA holding `PROPOSER_ROLE`. */
4
4
  export class ProtocolAdminProposerSubPackage {
@@ -55,6 +55,9 @@ export class ProtocolAdminGuardianSubPackage {
55
55
  constructor(walletClient) {
56
56
  this.walletClient = walletClient;
57
57
  }
58
+ pauseInstantly(target) {
59
+ return _pauseInstantly(this.walletClient, target);
60
+ }
58
61
  unpauseInstantly(target) {
59
62
  return _unpauseInstantly(this.walletClient, target);
60
63
  }
@@ -132,6 +135,9 @@ export class AdminProtocolAdminSubPackage {
132
135
  setDefaultPriceCapUSDCentsCall(cap, target) {
133
136
  return _setDefaultPriceCapUSDCentsCall(this.walletClient, cap, target);
134
137
  }
138
+ setDefaultAdminAllowanceUSDCentsCall(allowance, target) {
139
+ return _setDefaultAdminAllowanceUSDCentsCall(this.walletClient, allowance, target);
140
+ }
135
141
  setPaymentAdapterCall(paymentAdapter, target) {
136
142
  return _setPaymentAdapterCall(this.walletClient, paymentAdapter, target);
137
143
  }
@@ -1,5 +1,5 @@
1
1
  import { _addOrUpdateLazyWalletRegistryAddress, _updateVaultAddress, _requestAdminUpdate, _disableAdmin, _enableAdmin, _acceptAdminUpdate, _assignESIMIdentifier, _recordSettledPurchase, _pause, _unpause, _setDefaultPriceCapUSDCents, _acceptOwnership, _transferOwnershipCall, _upgradeCall, } from "../../logic/admin/registry.eoa.js";
2
- import { _owner, _eSIMWalletAdmin, _adminOfRecord, _adminDisabled, _newRequestedAdmin, _vault, _upgradeManager, _lazyWalletRegistry, _uniqueIdentifierToDeviceWallet, _deviceWalletToOwner, _registeredP256Keys, _isDeviceWalletValid, _isESIMWalletValid, _isESIMWalletOnStandby, _paused, _defaultPriceCapUSDCents, _paymentAdapter, _usedPaymentReferences, _isDeviceIdentifierAlreadyUsed, _isESIMIdentifierClaimed, _eSIMWalletForIdentifier, _claimedESIMIdentifiers, _requireDeviceIdentifierNotReserved, _pendingOwner, _deviceWalletFactory, _eSIMWalletFactory, _entryPoint, _requireNotPaused, _proxiableUUID, _upgradeInterfaceVersion, } from "../../logic/admin/reads/registry.reads.js";
2
+ import { _owner, _eSIMWalletAdmin, _adminOfRecord, _adminDisabled, _newRequestedAdmin, _vault, _upgradeManager, _lazyWalletRegistry, _uniqueIdentifierToDeviceWallet, _deviceWalletToOwner, _registeredP256Keys, _isDeviceWalletValid, _isESIMWalletValid, _isESIMWalletOnStandby, _paused, _defaultPriceCapUSDCents, _defaultAdminAllowanceUSDCents, _paymentAdapter, _usedPaymentReferences, _isDeviceIdentifierAlreadyUsed, _isESIMIdentifierClaimed, _eSIMWalletForIdentifier, _claimedESIMIdentifiers, _requireDeviceIdentifierNotReserved, _pendingOwner, _deviceWalletFactory, _eSIMWalletFactory, _entryPoint, _requireNotPaused, _proxiableUUID, _upgradeInterfaceVersion, } from "../../logic/admin/reads/registry.reads.js";
3
3
  /** Thin EOA (owner) wrapper around `Registry`. */
4
4
  export class AdminRegistrySubPackage {
5
5
  walletClient;
@@ -24,8 +24,8 @@ export class AdminRegistrySubPackage {
24
24
  acceptAdminUpdate() {
25
25
  return _acceptAdminUpdate(this.walletClient);
26
26
  }
27
- recordSettledPurchase(eSIMWalletAddress, dataBundleDetail, asset, tokenAmount, paymentReference) {
28
- return _recordSettledPurchase(this.walletClient, eSIMWalletAddress, dataBundleDetail, asset, tokenAmount, paymentReference);
27
+ recordSettledPurchase(eSIMWalletAddress, dataBundleDetail, asset, tokenAmount, paymentReference, couponUSDCents) {
28
+ return _recordSettledPurchase(this.walletClient, eSIMWalletAddress, dataBundleDetail, asset, tokenAmount, paymentReference, couponUSDCents);
29
29
  }
30
30
  assignESIMIdentifier(eSIMWalletAddress, eSIMUniqueIdentifier) {
31
31
  return _assignESIMIdentifier(this.walletClient, eSIMWalletAddress, eSIMUniqueIdentifier);
@@ -98,6 +98,9 @@ export class AdminRegistrySubPackage {
98
98
  defaultPriceCapUSDCents() {
99
99
  return _defaultPriceCapUSDCents(this.walletClient);
100
100
  }
101
+ defaultAdminAllowanceUSDCents() {
102
+ return _defaultAdminAllowanceUSDCents(this.walletClient);
103
+ }
101
104
  paymentAdapter() {
102
105
  return _paymentAdapter(this.walletClient);
103
106
  }
@@ -1,8 +1,9 @@
1
1
  import { _verifyERC20Transfer, _verifyProtocolPayment } from "../../logic/admin/utils/tokenTransfer.js";
2
+ import { _parsePaymentReference, _tagPaymentReference, } from "../../logic/admin/utils/paymentReference.js";
2
3
  /**
3
- * Checks what a mined transaction actually paid. Nothing is sent. Pass a hash
4
- * when it came from a user: a receipt is used as given, so it must come from
5
- * your own node.
4
+ * Checks what a mined transaction actually paid, and builds and reads payment
5
+ * references. Nothing is sent. Pass a hash when it came from a user: a receipt
6
+ * is used as given, so it must come from your own node.
6
7
  */
7
8
  export class AdminUtilsSubPackage {
8
9
  walletClient;
@@ -24,4 +25,19 @@ export class AdminUtilsSubPackage {
24
25
  verifyERC20Transfer(transaction, token, sender, destination) {
25
26
  return _verifyERC20Transfer(this.walletClient, transaction, token, sender, destination);
26
27
  }
28
+ /**
29
+ * Marks `reference` with how the purchase was paid for. Its high 20 bytes
30
+ * must be zero. For a split purchase, tag the same reference once as
31
+ * `CouponPart` and once as `Remainder`.
32
+ */
33
+ tagPaymentReference(reference, kind) {
34
+ return _tagPaymentReference(reference, kind);
35
+ }
36
+ /**
37
+ * How a purchase was paid for, and the untagged reference it was built
38
+ * from. Throws on a tag this SDK did not write.
39
+ */
40
+ parsePaymentReference(reference) {
41
+ return _parsePaymentReference(reference);
42
+ }
27
43
  }
@@ -1,4 +1,4 @@
1
- import { _addDeposit, _addESIMWallet, _canPullFunds, _deployAndBindESIMWallet, _deviceUniqueIdentifier, _entryPoint, _eSIMWalletFactory, _getDeposit, _getOwner, _getVaultAddress, _isValidESIMWallet, _isValidSignature, _registry, _removeESIMWallet, _sendUserOperation, _toggleAccessToFunds, _transferOwnership, _verifier, _withdrawDepositTo } from "../logic/deviceWallet.js";
1
+ import { _addDeposit, _addESIMWallet, _canPullFunds, _deployAndBindESIMWallet, _deviceUniqueIdentifier, _entryPoint, _eSIMWalletFactory, _getDeposit, _getOwner, _getVaultAddress, _isValidESIMWallet, _isValidSignature, _registry, _removeESIMWallet, _rotationChallenge, _sendUserOperation, _toggleAccessToFunds, _transferOwnership, _verifier, _withdrawDepositTo } from "../logic/deviceWallet.js";
2
2
  export class DeviceWalletSubPackage {
3
3
  smartAccountClient;
4
4
  walletClient;
@@ -35,8 +35,8 @@ export class DeviceWalletSubPackage {
35
35
  toggleAccessToFunds(eSIMWalletAddress, hasAccessToFunds) {
36
36
  return _toggleAccessToFunds(this.smartAccountClient, this.address, eSIMWalletAddress, hasAccessToFunds);
37
37
  }
38
- transferOwnership(newOwner) {
39
- return _transferOwnership(this.smartAccountClient, this.address, newOwner);
38
+ transferOwnership(newOwner, newOwnerSignature) {
39
+ return _transferOwnership(this.smartAccountClient, this.address, newOwner, newOwnerSignature);
40
40
  }
41
41
  withdrawDepositTo(withdrawAddress, amount) {
42
42
  return _withdrawDepositTo(this.smartAccountClient, this.address, withdrawAddress, amount);
@@ -69,6 +69,9 @@ export class DeviceWalletSubPackage {
69
69
  registry() {
70
70
  return _registry(this.smartAccountClient, this.address);
71
71
  }
72
+ rotationChallenge(newOwner) {
73
+ return _rotationChallenge(this.smartAccountClient, this.address, newOwner);
74
+ }
72
75
  verifier() {
73
76
  return _verifier(this.smartAccountClient, this.address);
74
77
  }
@@ -1,4 +1,4 @@
1
- import { _acceptAndBindESIMWallet, _acceptOwnershipTransfer, _buyDataBundleWithToken, _buyDataBundleWithTransfer, _priceCapUSDCents, _deviceWallet, _owner, _requestTransferOwnership, _sendETHToDeviceWallet, _sendTokenToDeviceWallet, _setPriceCapUSDCents, _transactionHistory } from "../logic/eSIMWallet.js";
1
+ import { _acceptAndBindESIMWallet, _acceptOwnershipTransfer, _adminAllowanceUSDCents, _buyDataBundleWithToken, _buyDataBundleWithTransfer, _priceCapUSDCents, _deviceWallet, _owner, _requestTransferOwnership, _sendETHToDeviceWallet, _sendTokenToDeviceWallet, _setAdminAllowanceUSDCents, _setPriceCapUSDCents, _transactionHistory } from "../logic/eSIMWallet.js";
2
2
  export class ESIMWalletSubPackage {
3
3
  client;
4
4
  address;
@@ -31,6 +31,12 @@ export class ESIMWalletSubPackage {
31
31
  priceCapUSDCents() {
32
32
  return _priceCapUSDCents(this.client, this.address);
33
33
  }
34
+ adminAllowanceUSDCents() {
35
+ return _adminAllowanceUSDCents(this.client, this.address);
36
+ }
37
+ setAdminAllowanceUSDCents(allowance) {
38
+ return _setAdminAllowanceUSDCents(this.client, this.address, allowance);
39
+ }
34
40
  deviceWallet() {
35
41
  return _deviceWallet(this.client, this.address);
36
42
  }
@@ -1,4 +1,4 @@
1
- import { _bindESIMWallet, _toggleESIMWalletStandbyStatus, _isDeviceIdentifierAlreadyUsed, _paused, _requireNotPaused, _isESIMWalletValid, _isESIMWalletOnStandby, _isDeviceWalletValid, _uniqueIdentifierToDeviceWallet, _isESIMIdentifierClaimed, _eSIMWalletForIdentifier, _defaultPriceCapUSDCents, _paymentAdapter, _usedPaymentReferences, _requireLazyHistoryCopied, _requireDeviceIdentifierNotReserved } from "../logic/registry.js";
1
+ import { _bindESIMWallet, _toggleESIMWalletStandbyStatus, _isDeviceIdentifierAlreadyUsed, _paused, _requireNotPaused, _isESIMWalletValid, _isESIMWalletOnStandby, _isDeviceWalletValid, _uniqueIdentifierToDeviceWallet, _isESIMIdentifierClaimed, _eSIMWalletForIdentifier, _defaultPriceCapUSDCents, _defaultAdminAllowanceUSDCents, _paymentAdapter, _usedPaymentReferences, _requireLazyHistoryCopied, _requireDeviceIdentifierNotReserved } from "../logic/registry.js";
2
2
  export class RegistrySubPackage {
3
3
  client;
4
4
  constructor(client) {
@@ -49,6 +49,9 @@ export class RegistrySubPackage {
49
49
  defaultPriceCapUSDCents() {
50
50
  return _defaultPriceCapUSDCents(this.client);
51
51
  }
52
+ defaultAdminAllowanceUSDCents() {
53
+ return _defaultAdminAllowanceUSDCents(this.client);
54
+ }
52
55
  paymentAdapter() {
53
56
  return _paymentAdapter(this.client);
54
57
  }
@@ -1,6 +1,7 @@
1
1
  import { _chainId, _getChainSpecificConstants } from "../constants.js";
2
- import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
2
+ import { AdminAllowanceExceededError, MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
3
3
  import { ESIMWallet } from "../../abis/index.js";
4
+ import { _adminAllowanceUSDCents } from "./reads/eSIMWallet.reads.js";
4
5
  // Admin-EOA logic targeting a specific `ESIMWallet` instance (address passed in).
5
6
  // `buyDataBundleWithToken` is `onlyDeviceWalletOrESIMWalletAdmin`, so the admin
6
7
  // EOA can call it directly.
@@ -12,6 +13,9 @@ import { ESIMWallet } from "../../abis/index.js";
12
13
  * unit - read it from `paymentAdapter.quote(asset, dataBundleDetails.priceUSDCents)`
13
14
  * first. `paymentReference` ties this purchase to its offchain order and is
14
15
  * spendable once per eSIM wallet.
16
+ *
17
+ * Throws `AdminAllowanceExceededError` without sending when the price is above
18
+ * what the wallet's owner still allows the admin to charge.
15
19
  */
16
20
  export const _buyDataBundleWithToken = async (client, eSIMWalletAddress, dataBundleDetails, asset, maxAmountIn, paymentReference) => {
17
21
  const chainID = await _chainId(client);
@@ -19,6 +23,10 @@ export const _buyDataBundleWithToken = async (client, eSIMWalletAddress, dataBun
19
23
  const values = _getChainSpecificConstants(chainID, rpcURL);
20
24
  if (!client.account)
21
25
  throw new MissingEOAWalletError();
26
+ const remaining = await _adminAllowanceUSDCents(client, eSIMWalletAddress);
27
+ if (dataBundleDetails.priceUSDCents > remaining) {
28
+ throw new AdminAllowanceExceededError(dataBundleDetails.priceUSDCents, remaining);
29
+ }
22
30
  return writeContractOrThrow(client, {
23
31
  address: eSIMWalletAddress,
24
32
  chain: values.chain,
@@ -57,6 +57,22 @@ export const _registerAssetCall = async (client, symbol, asset) => {
57
57
  args: [symbol, asset],
58
58
  };
59
59
  };
60
+ /**
61
+ * Send back `amount` of `token` someone sent to the adapter by mistake. Pass the
62
+ * result to `schedule`. Purchases never leave tokens in the adapter, so anything
63
+ * it holds arrived by mistake.
64
+ */
65
+ export const _recoverTokensCall = async (client, token, to, amount) => {
66
+ const chainID = await _chainId(client);
67
+ const rpcURL = client.transport.url;
68
+ const values = _getChainSpecificConstants(chainID, rpcURL);
69
+ return {
70
+ address: values.factoryAddresses.PAYMENT_ADAPTER,
71
+ abi: PaymentAdapter,
72
+ functionName: 'recoverTokens',
73
+ args: [token, to, amount],
74
+ };
75
+ };
60
76
  /** Change a currency already in the table, scheduled through the timelock. Pass the result to `schedule`. */
61
77
  export const _updateAssetCall = async (client, symbol, asset) => {
62
78
  const chainID = await _chainId(client);