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.
- package/README.md +21 -7
- package/dist/esm/abis/DeviceWallet.js +60 -59
- package/dist/esm/abis/ESIMWallet.js +263 -58
- package/dist/esm/abis/ESIMWalletFactory.js +2 -2
- package/dist/esm/abis/LazyWalletRegistry.js +68 -24
- package/dist/esm/abis/PaymentAdapter.js +861 -0
- package/dist/esm/abis/Registry.js +294 -18
- package/dist/esm/abis/RegistryHelper.js +101 -9
- package/dist/esm/abis/index.js +2 -1
- package/dist/esm/admin/config-admin.js +4 -0
- package/dist/esm/admin/interface/deviceWalletClass.js +3 -3
- package/dist/esm/admin/interface/eSIMWalletClass.js +6 -6
- package/dist/esm/admin/interface/lazyWalletRegistryClass.js +4 -1
- package/dist/esm/admin/interface/paymentAdapterClass.js +54 -0
- package/dist/esm/admin/interface/protocolAdminClass.js +6 -3
- package/dist/esm/admin/interface/registryClass.js +15 -6
- package/dist/esm/config.js +3 -0
- package/dist/esm/interface/deviceWalletClass.js +5 -5
- package/dist/esm/interface/eSIMWalletClass.js +10 -7
- package/dist/esm/interface/paymentAdapterClass.js +28 -0
- package/dist/esm/interface/registryClass.js +12 -3
- package/dist/esm/logic/admin/eSIMWallet.eoa.js +12 -10
- package/dist/esm/logic/admin/paymentAdapter.eoa.js +123 -0
- package/dist/esm/logic/admin/protocolAdmin.eoa.js +21 -3
- package/dist/esm/logic/admin/reads/deviceWallet.reads.js +2 -2
- package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +8 -7
- package/dist/esm/logic/admin/reads/lazyWalletRegistry.reads.js +19 -2
- package/dist/esm/logic/admin/reads/paymentAdapter.reads.js +106 -0
- package/dist/esm/logic/admin/reads/registry.reads.js +34 -6
- package/dist/esm/logic/admin/registry.eoa.js +32 -8
- package/dist/esm/logic/constants.js +17 -87
- package/dist/esm/logic/deviceWallet.js +11 -11
- package/dist/esm/logic/eSIMWallet.js +51 -22
- package/dist/esm/logic/paymentAdapter.js +116 -0
- package/dist/esm/logic/registry.js +50 -5
- package/dist/esm/types-export.js +1 -1
- package/dist/esm/types.js +11 -1
- package/dist/types/abis/DeviceWallet.d.ts +50 -49
- package/dist/types/abis/ESIMWallet.d.ts +215 -55
- package/dist/types/abis/ESIMWalletFactory.d.ts +2 -2
- package/dist/types/abis/LazyWalletRegistry.d.ts +58 -24
- package/dist/types/abis/PaymentAdapter.d.ts +661 -0
- package/dist/types/abis/Registry.d.ts +233 -18
- package/dist/types/abis/RegistryHelper.d.ts +83 -9
- package/dist/types/abis/index.d.ts +2 -1
- package/dist/types/admin/config-admin.d.ts +2 -0
- package/dist/types/admin/interface/deviceWalletClass.d.ts +1 -1
- package/dist/types/admin/interface/eSIMWalletClass.d.ts +3 -3
- package/dist/types/admin/interface/lazyWalletRegistryClass.d.ts +1 -0
- package/dist/types/admin/interface/paymentAdapterClass.d.ts +20 -0
- package/dist/types/admin/interface/protocolAdminClass.d.ts +2 -1
- package/dist/types/admin/interface/registryClass.d.ts +6 -2
- package/dist/types/config.d.ts +2 -0
- package/dist/types/interface/constantsClass.d.ts +2 -2
- package/dist/types/interface/deviceWalletClass.d.ts +2 -2
- package/dist/types/interface/eSIMWalletClass.d.ts +5 -4
- package/dist/types/interface/paymentAdapterClass.d.ts +13 -0
- package/dist/types/interface/registryClass.d.ts +5 -2
- package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +9 -6
- package/dist/types/logic/admin/paymentAdapter.eoa.d.ts +28 -0
- package/dist/types/logic/admin/protocolAdmin.eoa.d.ts +12 -2
- package/dist/types/logic/admin/reads/deviceWallet.reads.d.ts +1 -1
- package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +5 -4
- package/dist/types/logic/admin/reads/lazyWalletRegistry.reads.d.ts +7 -0
- package/dist/types/logic/admin/reads/paymentAdapter.reads.d.ts +30 -0
- package/dist/types/logic/admin/reads/registry.reads.d.ts +13 -5
- package/dist/types/logic/admin/registry.eoa.d.ts +18 -8
- package/dist/types/logic/constants.d.ts +5 -17
- package/dist/types/logic/deviceWallet.d.ts +7 -7
- package/dist/types/logic/eSIMWallet.d.ts +29 -15
- package/dist/types/logic/paymentAdapter.d.ts +40 -0
- package/dist/types/logic/registry.d.ts +20 -5
- package/dist/types/types-export.d.ts +2 -1
- package/dist/types/types.d.ts +20 -2
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
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";
|
|
3
|
+
export class AdminPaymentAdapterSubPackage {
|
|
4
|
+
walletClient;
|
|
5
|
+
constructor(walletClient) {
|
|
6
|
+
this.walletClient = walletClient;
|
|
7
|
+
}
|
|
8
|
+
registry() {
|
|
9
|
+
return _registry(this.walletClient);
|
|
10
|
+
}
|
|
11
|
+
settlementToken() {
|
|
12
|
+
return _settlementToken(this.walletClient);
|
|
13
|
+
}
|
|
14
|
+
assets(symbol) {
|
|
15
|
+
return _assets(this.walletClient, symbol);
|
|
16
|
+
}
|
|
17
|
+
resolveAsset(symbol) {
|
|
18
|
+
return _resolveAsset(this.walletClient, symbol);
|
|
19
|
+
}
|
|
20
|
+
quote(symbol, priceUSDCents) {
|
|
21
|
+
return _quote(this.walletClient, symbol, priceUSDCents);
|
|
22
|
+
}
|
|
23
|
+
usedReferences(paymentReference) {
|
|
24
|
+
return _usedReferences(this.walletClient, paymentReference);
|
|
25
|
+
}
|
|
26
|
+
upgradeManager() {
|
|
27
|
+
return _upgradeManager(this.walletClient);
|
|
28
|
+
}
|
|
29
|
+
// Direct writes - only succeed if this wallet client is the owner. On the
|
|
30
|
+
// live deployment the owner is the ProtocolAdmin timelock, so these revert
|
|
31
|
+
// there; use the *Call builders below with `protocolAdmin.schedule` instead.
|
|
32
|
+
registerAsset(symbol, asset) {
|
|
33
|
+
return _registerAsset(this.walletClient, symbol, asset);
|
|
34
|
+
}
|
|
35
|
+
updateAsset(symbol, asset) {
|
|
36
|
+
return _updateAsset(this.walletClient, symbol, asset);
|
|
37
|
+
}
|
|
38
|
+
acceptOwnership() {
|
|
39
|
+
return _acceptOwnership(this.walletClient);
|
|
40
|
+
}
|
|
41
|
+
// Owner payloads - build an OwnerCall to hand to protocolAdmin.schedule.
|
|
42
|
+
registerAssetCall(symbol, asset) {
|
|
43
|
+
return _registerAssetCall(this.walletClient, symbol, asset);
|
|
44
|
+
}
|
|
45
|
+
updateAssetCall(symbol, asset) {
|
|
46
|
+
return _updateAssetCall(this.walletClient, symbol, asset);
|
|
47
|
+
}
|
|
48
|
+
transferOwnershipCall(newOwner) {
|
|
49
|
+
return _transferOwnershipCall(this.walletClient, newOwner);
|
|
50
|
+
}
|
|
51
|
+
upgradeCall(newImplementation, data) {
|
|
52
|
+
return _upgradeCall(this.walletClient, newImplementation, data);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -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,
|
|
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";
|
|
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 {
|
|
@@ -129,8 +129,11 @@ export class AdminProtocolAdminSubPackage {
|
|
|
129
129
|
unpauseCall(target) {
|
|
130
130
|
return _unpauseCall(this.walletClient, target);
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
return
|
|
132
|
+
setDefaultPriceCapUSDCentsCall(cap, target) {
|
|
133
|
+
return _setDefaultPriceCapUSDCentsCall(this.walletClient, cap, target);
|
|
134
|
+
}
|
|
135
|
+
setPaymentAdapterCall(paymentAdapter, target) {
|
|
136
|
+
return _setPaymentAdapterCall(this.walletClient, paymentAdapter, target);
|
|
134
137
|
}
|
|
135
138
|
// Operation ids
|
|
136
139
|
operationId(call, opts) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _addOrUpdateLazyWalletRegistryAddress, _updateVaultAddress, _requestAdminUpdate, _disableAdmin, _enableAdmin, _acceptAdminUpdate, _assignESIMIdentifier, _pause, _unpause,
|
|
2
|
-
import { _owner, _eSIMWalletAdmin, _adminOfRecord, _adminDisabled, _newRequestedAdmin, _vault, _upgradeManager, _lazyWalletRegistry, _uniqueIdentifierToDeviceWallet, _deviceWalletToOwner, _registeredP256Keys, _isDeviceWalletValid, _isESIMWalletValid, _isESIMWalletOnStandby, _paused,
|
|
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";
|
|
3
3
|
/** Thin EOA (owner) wrapper around `Registry`. */
|
|
4
4
|
export class AdminRegistrySubPackage {
|
|
5
5
|
walletClient;
|
|
@@ -24,6 +24,9 @@ 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);
|
|
29
|
+
}
|
|
27
30
|
assignESIMIdentifier(eSIMWalletAddress, eSIMUniqueIdentifier) {
|
|
28
31
|
return _assignESIMIdentifier(this.walletClient, eSIMWalletAddress, eSIMUniqueIdentifier);
|
|
29
32
|
}
|
|
@@ -33,8 +36,8 @@ export class AdminRegistrySubPackage {
|
|
|
33
36
|
unpause() {
|
|
34
37
|
return _unpause(this.walletClient);
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
return
|
|
39
|
+
setDefaultPriceCapUSDCents(cap) {
|
|
40
|
+
return _setDefaultPriceCapUSDCents(this.walletClient, cap);
|
|
38
41
|
}
|
|
39
42
|
acceptOwnership() {
|
|
40
43
|
return _acceptOwnership(this.walletClient);
|
|
@@ -92,8 +95,14 @@ export class AdminRegistrySubPackage {
|
|
|
92
95
|
paused() {
|
|
93
96
|
return _paused(this.walletClient);
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
return
|
|
98
|
+
defaultPriceCapUSDCents() {
|
|
99
|
+
return _defaultPriceCapUSDCents(this.walletClient);
|
|
100
|
+
}
|
|
101
|
+
paymentAdapter() {
|
|
102
|
+
return _paymentAdapter(this.walletClient);
|
|
103
|
+
}
|
|
104
|
+
usedPaymentReferences(scopedReference) {
|
|
105
|
+
return _usedPaymentReferences(this.walletClient, scopedReference);
|
|
97
106
|
}
|
|
98
107
|
isDeviceIdentifierAlreadyUsed(deviceUniqueIdentifier) {
|
|
99
108
|
return _isDeviceIdentifierAlreadyUsed(this.walletClient, deviceUniqueIdentifier);
|
package/dist/esm/config.js
CHANGED
|
@@ -6,6 +6,7 @@ import { RegistrySubPackage } from "./interface/registryClass.js";
|
|
|
6
6
|
import { DeviceWalletSubPackage } from "./interface/deviceWalletClass.js";
|
|
7
7
|
import { ESIMWalletSubPackage } from "./interface/eSIMWalletClass.js";
|
|
8
8
|
import { ESIMWalletFactorySubPackage } from "./interface/eSIMWalletFactoryClass.js";
|
|
9
|
+
import { PaymentAdapterSubPackage } from "./interface/paymentAdapterClass.js";
|
|
9
10
|
// Re-export the typed error surface so consumers can `instanceof KokioError`
|
|
10
11
|
// (or a specific subclass) and decode on-chain reverts without reaching into
|
|
11
12
|
// internal module paths.
|
|
@@ -27,6 +28,7 @@ export class Kokio {
|
|
|
27
28
|
deviceWallet;
|
|
28
29
|
eSIMWallet;
|
|
29
30
|
P256Verifier;
|
|
31
|
+
paymentAdapter;
|
|
30
32
|
constructor(viemWalletClient, credentialId, rpId, pimlicoAPIKey, gasPolicyId, smartAccountClient, deviceWalletAddress, eSIMWalletAddress) {
|
|
31
33
|
this.viemWalletClient = viemWalletClient;
|
|
32
34
|
this.credentialId = credentialId;
|
|
@@ -42,6 +44,7 @@ export class Kokio {
|
|
|
42
44
|
this.eSIMWalletFactory = smartAccountClient ? new ESIMWalletFactorySubPackage(viemWalletClient, smartAccountClient) : undefined;
|
|
43
45
|
this.registry = smartAccountClient ? new RegistrySubPackage(smartAccountClient) : undefined;
|
|
44
46
|
this.P256Verifier = smartAccountClient ? new P256VerifierSubPackage(smartAccountClient) : undefined;
|
|
47
|
+
this.paymentAdapter = smartAccountClient ? new PaymentAdapterSubPackage(smartAccountClient) : undefined;
|
|
45
48
|
this.deviceWallet = deviceWalletAddress && smartAccountClient ? new DeviceWalletSubPackage(viemWalletClient, smartAccountClient, deviceWalletAddress) : undefined;
|
|
46
49
|
this.eSIMWallet = eSIMWalletAddress && smartAccountClient ? new ESIMWalletSubPackage(smartAccountClient, eSIMWalletAddress) : undefined;
|
|
47
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _addDeposit, _addESIMWallet,
|
|
1
|
+
import { _addDeposit, _addESIMWallet, _canPullFunds, _deviceUniqueIdentifier, _entryPoint, _eSIMWalletFactory, _getDeposit, _getOwner, _getVaultAddress, _isValidESIMWallet, _isValidSignature, _registry, _removeESIMWallet, _sendUserOperation, _toggleAccessToFunds, _transferOwnership, _verifier, _withdrawDepositTo } from "../logic/deviceWallet.js";
|
|
2
2
|
export class DeviceWalletSubPackage {
|
|
3
3
|
smartAccountClient;
|
|
4
4
|
walletClient;
|
|
@@ -23,8 +23,8 @@ export class DeviceWalletSubPackage {
|
|
|
23
23
|
removeESIMWallet(eSIMWalletAddress, callBackETH) {
|
|
24
24
|
return _removeESIMWallet(this.smartAccountClient, this.address, eSIMWalletAddress, callBackETH);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
return
|
|
26
|
+
toggleAccessToFunds(eSIMWalletAddress, hasAccessToFunds) {
|
|
27
|
+
return _toggleAccessToFunds(this.smartAccountClient, this.address, eSIMWalletAddress, hasAccessToFunds);
|
|
28
28
|
}
|
|
29
29
|
transferOwnership(newOwner) {
|
|
30
30
|
return _transferOwnership(this.smartAccountClient, this.address, newOwner);
|
|
@@ -33,8 +33,8 @@ export class DeviceWalletSubPackage {
|
|
|
33
33
|
return _withdrawDepositTo(this.smartAccountClient, this.address, withdrawAddress, amount);
|
|
34
34
|
}
|
|
35
35
|
// Reads
|
|
36
|
-
|
|
37
|
-
return
|
|
36
|
+
canPullFunds(eSIMWalletAddress) {
|
|
37
|
+
return _canPullFunds(this.smartAccountClient, this.address, eSIMWalletAddress);
|
|
38
38
|
}
|
|
39
39
|
deviceUniqueIdentifier() {
|
|
40
40
|
return _deviceUniqueIdentifier(this.smartAccountClient, this.address);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _acceptOwnershipTransfer,
|
|
1
|
+
import { _acceptOwnershipTransfer, _buyDataBundleWithToken, _priceCapUSDCents, _deviceWallet, _owner, _requestTransferOwnership, _sendETHToDeviceWallet, _sendTokenToDeviceWallet, _setPriceCapUSDCents, _transactionHistory } from "../logic/eSIMWallet.js";
|
|
2
2
|
export class ESIMWalletSubPackage {
|
|
3
3
|
client;
|
|
4
4
|
address;
|
|
@@ -9,11 +9,11 @@ export class ESIMWalletSubPackage {
|
|
|
9
9
|
acceptOwnershipTransfer() {
|
|
10
10
|
return _acceptOwnershipTransfer(this.client, this.address);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
buyDataBundleWithToken(dataBundleDetails, asset, maxAmountIn, paymentReference) {
|
|
13
|
+
return _buyDataBundleWithToken(this.client, this.address, dataBundleDetails, asset, maxAmountIn, paymentReference);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return
|
|
15
|
+
priceCapUSDCents() {
|
|
16
|
+
return _priceCapUSDCents(this.client, this.address);
|
|
17
17
|
}
|
|
18
18
|
deviceWallet() {
|
|
19
19
|
return _deviceWallet(this.client, this.address);
|
|
@@ -27,8 +27,11 @@ export class ESIMWalletSubPackage {
|
|
|
27
27
|
sendETHToDeviceWallet(amount) {
|
|
28
28
|
return _sendETHToDeviceWallet(this.client, this.address, amount);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
return
|
|
30
|
+
sendTokenToDeviceWallet(token, amount) {
|
|
31
|
+
return _sendTokenToDeviceWallet(this.client, this.address, token, amount);
|
|
32
|
+
}
|
|
33
|
+
setPriceCapUSDCents(cap) {
|
|
34
|
+
return _setPriceCapUSDCents(this.client, this.address, cap);
|
|
32
35
|
}
|
|
33
36
|
transactionHistory(index) {
|
|
34
37
|
return _transactionHistory(this.client, this.address, index);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { _registry, _settlementToken, _assets, _resolveAsset, _quote, _usedReferences, _upgradeManager } from "../logic/paymentAdapter.js";
|
|
2
|
+
export class PaymentAdapterSubPackage {
|
|
3
|
+
client;
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this.client = client;
|
|
6
|
+
}
|
|
7
|
+
registry() {
|
|
8
|
+
return _registry(this.client);
|
|
9
|
+
}
|
|
10
|
+
settlementToken() {
|
|
11
|
+
return _settlementToken(this.client);
|
|
12
|
+
}
|
|
13
|
+
assets(symbol) {
|
|
14
|
+
return _assets(this.client, symbol);
|
|
15
|
+
}
|
|
16
|
+
resolveAsset(symbol) {
|
|
17
|
+
return _resolveAsset(this.client, symbol);
|
|
18
|
+
}
|
|
19
|
+
quote(symbol, priceUSDCents) {
|
|
20
|
+
return _quote(this.client, symbol, priceUSDCents);
|
|
21
|
+
}
|
|
22
|
+
usedReferences(paymentReference) {
|
|
23
|
+
return _usedReferences(this.client, paymentReference);
|
|
24
|
+
}
|
|
25
|
+
upgradeManager() {
|
|
26
|
+
return _upgradeManager(this.client);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _bindESIMWallet, _toggleESIMWalletStandbyStatus, _isDeviceIdentifierAlreadyUsed, _paused, _requireNotPaused, _isESIMWalletValid, _isESIMWalletOnStandby, _isDeviceWalletValid, _uniqueIdentifierToDeviceWallet, _isESIMIdentifierClaimed, _eSIMWalletForIdentifier,
|
|
1
|
+
import { _bindESIMWallet, _toggleESIMWalletStandbyStatus, _isDeviceIdentifierAlreadyUsed, _paused, _requireNotPaused, _isESIMWalletValid, _isESIMWalletOnStandby, _isDeviceWalletValid, _uniqueIdentifierToDeviceWallet, _isESIMIdentifierClaimed, _eSIMWalletForIdentifier, _defaultPriceCapUSDCents, _paymentAdapter, _usedPaymentReferences, _requireLazyHistoryCopied, _requireDeviceIdentifierNotReserved } from "../logic/registry.js";
|
|
2
2
|
export class RegistrySubPackage {
|
|
3
3
|
client;
|
|
4
4
|
constructor(client) {
|
|
@@ -38,8 +38,17 @@ export class RegistrySubPackage {
|
|
|
38
38
|
eSIMWalletForIdentifier(eSIMUniqueIdentifier) {
|
|
39
39
|
return _eSIMWalletForIdentifier(this.client, eSIMUniqueIdentifier);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
41
|
+
defaultPriceCapUSDCents() {
|
|
42
|
+
return _defaultPriceCapUSDCents(this.client);
|
|
43
|
+
}
|
|
44
|
+
paymentAdapter() {
|
|
45
|
+
return _paymentAdapter(this.client);
|
|
46
|
+
}
|
|
47
|
+
usedPaymentReferences(scopedReference) {
|
|
48
|
+
return _usedPaymentReferences(this.client, scopedReference);
|
|
49
|
+
}
|
|
50
|
+
requireLazyHistoryCopied(eSIMWallet) {
|
|
51
|
+
return _requireLazyHistoryCopied(this.client, eSIMWallet);
|
|
43
52
|
}
|
|
44
53
|
requireDeviceIdentifierNotReserved(deviceUniqueIdentifier) {
|
|
45
54
|
return _requireDeviceIdentifierNotReserved(this.client, deviceUniqueIdentifier);
|
|
@@ -2,15 +2,18 @@ import { _getChainSpecificConstants } from "../constants.js";
|
|
|
2
2
|
import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
|
|
3
3
|
import { ESIMWallet } from "../../abis/index.js";
|
|
4
4
|
// Admin-EOA logic targeting a specific `ESIMWallet` instance (address passed in).
|
|
5
|
-
// `
|
|
6
|
-
// call it directly.
|
|
5
|
+
// `buyDataBundleWithToken` is `onlyDeviceWalletOrESIMWalletAdmin`, so the admin
|
|
6
|
+
// EOA can call it directly.
|
|
7
7
|
/**
|
|
8
|
-
* Buy a data bundle
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Buy a data bundle in `asset`, an ERC-20 the payment adapter accepts.
|
|
9
|
+
* `onlyDeviceWalletOrESIMWalletAdmin`.
|
|
10
|
+
*
|
|
11
|
+
* `maxAmountIn` is the most of `asset` the buyer will spend, in its smallest
|
|
12
|
+
* unit - read it from `paymentAdapter.quote(asset, dataBundleDetails.priceUSDCents)`
|
|
13
|
+
* first. `paymentReference` ties this purchase to its offchain order and is
|
|
14
|
+
* spendable once per eSIM wallet.
|
|
12
15
|
*/
|
|
13
|
-
export const
|
|
16
|
+
export const _buyDataBundleWithToken = async (client, eSIMWalletAddress, dataBundleDetails, asset, maxAmountIn, paymentReference) => {
|
|
14
17
|
const chainID = await client.getChainId();
|
|
15
18
|
const rpcURL = client.transport.url;
|
|
16
19
|
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
@@ -21,8 +24,7 @@ export const _buyDataBundle = async (client, eSIMWalletAddress, dataBundleDetail
|
|
|
21
24
|
chain: values.chain,
|
|
22
25
|
account: client.account.address,
|
|
23
26
|
abi: ESIMWallet,
|
|
24
|
-
functionName: '
|
|
25
|
-
args: [dataBundleDetails]
|
|
26
|
-
value
|
|
27
|
+
functionName: 'buyDataBundleWithToken',
|
|
28
|
+
args: [dataBundleDetails, asset, maxAmountIn, paymentReference]
|
|
27
29
|
});
|
|
28
30
|
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { _getChainSpecificConstants } from "../constants.js";
|
|
2
|
+
import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
|
|
3
|
+
import { PaymentAdapter } from "../../abis/index.js";
|
|
4
|
+
// Admin-EOA logic for `PaymentAdapter`. `registerAsset`/`updateAsset` are
|
|
5
|
+
// `onlyOwner`, so the `client` must carry the `upgradeManager` EOA.
|
|
6
|
+
//
|
|
7
|
+
// On the live deployment the owner is the `ProtocolAdmin` timelock, not an EOA,
|
|
8
|
+
// so either call sent directly reverts. Route them through
|
|
9
|
+
// `protocolAdmin.proposer.schedule` instead, via the payload builders below.
|
|
10
|
+
/** Add a currency the adapter has never seen. Reverts if `_symbol` is already registered. Owner only. */
|
|
11
|
+
export const _registerAsset = async (client, symbol, asset) => {
|
|
12
|
+
const chainID = await client.getChainId();
|
|
13
|
+
const rpcURL = client.transport.url;
|
|
14
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
15
|
+
if (!client.account)
|
|
16
|
+
throw new MissingEOAWalletError();
|
|
17
|
+
return writeContractOrThrow(client, {
|
|
18
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
19
|
+
chain: values.chain,
|
|
20
|
+
account: client.account.address,
|
|
21
|
+
abi: PaymentAdapter,
|
|
22
|
+
functionName: 'registerAsset',
|
|
23
|
+
args: [symbol, asset]
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
/** Change a currency already in the table (its decimals, token, or allowed flag). Owner only. */
|
|
27
|
+
export const _updateAsset = async (client, symbol, asset) => {
|
|
28
|
+
const chainID = await client.getChainId();
|
|
29
|
+
const rpcURL = client.transport.url;
|
|
30
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
31
|
+
if (!client.account)
|
|
32
|
+
throw new MissingEOAWalletError();
|
|
33
|
+
return writeContractOrThrow(client, {
|
|
34
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
35
|
+
chain: values.chain,
|
|
36
|
+
account: client.account.address,
|
|
37
|
+
abi: PaymentAdapter,
|
|
38
|
+
functionName: 'updateAsset',
|
|
39
|
+
args: [symbol, asset]
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Owner payloads - only reachable through schedule
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// All `onlyOwner`, and on the live deployment the owner is the timelock, so they
|
|
46
|
+
// exist as something to schedule rather than to send. Each returns the
|
|
47
|
+
// `OwnerCall` to hand to `protocolAdmin.schedule`.
|
|
48
|
+
/** Add or change a currency, scheduled through the timelock. Pass the result to `schedule`. */
|
|
49
|
+
export const _registerAssetCall = async (client, symbol, asset) => {
|
|
50
|
+
const chainID = await client.getChainId();
|
|
51
|
+
const rpcURL = client.transport.url;
|
|
52
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
53
|
+
return {
|
|
54
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
55
|
+
abi: PaymentAdapter,
|
|
56
|
+
functionName: 'registerAsset',
|
|
57
|
+
args: [symbol, asset],
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/** Change a currency already in the table, scheduled through the timelock. Pass the result to `schedule`. */
|
|
61
|
+
export const _updateAssetCall = async (client, symbol, asset) => {
|
|
62
|
+
const chainID = await client.getChainId();
|
|
63
|
+
const rpcURL = client.transport.url;
|
|
64
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
65
|
+
return {
|
|
66
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
67
|
+
abi: PaymentAdapter,
|
|
68
|
+
functionName: 'updateAsset',
|
|
69
|
+
args: [symbol, asset],
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Offer ownership to a new address. Pass the result to `schedule`.
|
|
74
|
+
*
|
|
75
|
+
* Ownable2Step, so the offer changes nothing until the named address calls
|
|
76
|
+
* `acceptOwnership`.
|
|
77
|
+
*/
|
|
78
|
+
export const _transferOwnershipCall = async (client, newOwner) => {
|
|
79
|
+
const chainID = await client.getChainId();
|
|
80
|
+
const rpcURL = client.transport.url;
|
|
81
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
82
|
+
return {
|
|
83
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
84
|
+
abi: PaymentAdapter,
|
|
85
|
+
functionName: 'transferOwnership',
|
|
86
|
+
args: [newOwner],
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/** Point the adapter's proxy at a new implementation. Builds `upgradeToAndCall`. Pass the result to `schedule`. */
|
|
90
|
+
export const _upgradeCall = async (client, newImplementation, data = '0x') => {
|
|
91
|
+
const chainID = await client.getChainId();
|
|
92
|
+
const rpcURL = client.transport.url;
|
|
93
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
94
|
+
return {
|
|
95
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
96
|
+
abi: PaymentAdapter,
|
|
97
|
+
functionName: 'upgradeToAndCall',
|
|
98
|
+
args: [newImplementation, data],
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Take ownership after a `transferOwnership` named this client. `msg.sender`
|
|
103
|
+
* must equal `pendingOwner`, so the `client` is the incoming owner.
|
|
104
|
+
*
|
|
105
|
+
* Where the incoming owner is the timelock, use
|
|
106
|
+
* `protocolAdmin.acceptOwnershipBatch` instead, which accepts for every
|
|
107
|
+
* contract at once.
|
|
108
|
+
*/
|
|
109
|
+
export const _acceptOwnership = async (client) => {
|
|
110
|
+
const chainID = await client.getChainId();
|
|
111
|
+
const rpcURL = client.transport.url;
|
|
112
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
113
|
+
if (!client.account)
|
|
114
|
+
throw new MissingEOAWalletError();
|
|
115
|
+
return writeContractOrThrow(client, {
|
|
116
|
+
address: values.factoryAddresses.PAYMENT_ADAPTER,
|
|
117
|
+
chain: values.chain,
|
|
118
|
+
account: client.account.address,
|
|
119
|
+
abi: PaymentAdapter,
|
|
120
|
+
functionName: 'acceptOwnership',
|
|
121
|
+
args: []
|
|
122
|
+
});
|
|
123
|
+
};
|
|
@@ -456,22 +456,40 @@ export const _unpauseCall = async (client, target) => {
|
|
|
456
456
|
};
|
|
457
457
|
};
|
|
458
458
|
/**
|
|
459
|
-
* Set the fallback
|
|
459
|
+
* Set the fallback price ceiling, in USD cents. Pass the result to `schedule`.
|
|
460
460
|
*
|
|
461
461
|
* Zero reverts on execution, not on scheduling, so a zero here costs the whole
|
|
462
462
|
* delay before it fails.
|
|
463
463
|
*
|
|
464
464
|
* `target` defaults to the registry.
|
|
465
465
|
*/
|
|
466
|
-
export const
|
|
466
|
+
export const _setDefaultPriceCapUSDCentsCall = async (client, cap, target) => {
|
|
467
467
|
const values = await _resolve(client);
|
|
468
468
|
return {
|
|
469
469
|
address: target ?? values.factoryAddresses.REGISTRY,
|
|
470
470
|
abi: Registry,
|
|
471
|
-
functionName: '
|
|
471
|
+
functionName: 'setDefaultPriceCapUSDCents',
|
|
472
472
|
args: [cap],
|
|
473
473
|
};
|
|
474
474
|
};
|
|
475
|
+
/**
|
|
476
|
+
* Point the registry at a new payment adapter. Pass the result to `schedule`.
|
|
477
|
+
*
|
|
478
|
+
* Owner only, deliberately not the admin: the adapter holds the spent payment
|
|
479
|
+
* references, so an admin that could swap it would get an empty set back and
|
|
480
|
+
* could record every purchase a second time.
|
|
481
|
+
*
|
|
482
|
+
* `target` defaults to the registry.
|
|
483
|
+
*/
|
|
484
|
+
export const _setPaymentAdapterCall = async (client, paymentAdapter, target) => {
|
|
485
|
+
const values = await _resolve(client);
|
|
486
|
+
return {
|
|
487
|
+
address: target ?? values.factoryAddresses.REGISTRY,
|
|
488
|
+
abi: Registry,
|
|
489
|
+
functionName: 'setPaymentAdapter',
|
|
490
|
+
args: [paymentAdapter],
|
|
491
|
+
};
|
|
492
|
+
};
|
|
475
493
|
// ---------------------------------------------------------------------------
|
|
476
494
|
// Admin suspension payloads - the owner's route, aimed at the target contract
|
|
477
495
|
// ---------------------------------------------------------------------------
|
|
@@ -24,11 +24,11 @@ export const _isValidESIMWallet = async (client, deviceWalletAddress, eSIMWallet
|
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
26
|
/** Whether an eSIM wallet is allowed to pull ETH from this device wallet. */
|
|
27
|
-
export const
|
|
27
|
+
export const _canPullFunds = async (client, deviceWalletAddress, eSIMWallet) => {
|
|
28
28
|
return client.extend(publicActions).readContract({
|
|
29
29
|
address: deviceWalletAddress,
|
|
30
30
|
abi: DeviceWallet,
|
|
31
|
-
functionName: "
|
|
31
|
+
functionName: "canPullFunds",
|
|
32
32
|
args: [eSIMWallet]
|
|
33
33
|
});
|
|
34
34
|
};
|
|
@@ -26,13 +26,13 @@ export const _eSIMUniqueIdentifier = async (client, eSIMWalletAddress) => {
|
|
|
26
26
|
* This wallet's own price ceiling in wei. Zero means it follows the registry's
|
|
27
27
|
* `defaultDataBundlePriceCap` instead, which is the state a fresh wallet and a
|
|
28
28
|
* newly handed-over wallet both start in. Worth reading before naming a price on
|
|
29
|
-
* `
|
|
29
|
+
* `buyDataBundleWithToken`, since a price over the ceiling reverts.
|
|
30
30
|
*/
|
|
31
|
-
export const
|
|
31
|
+
export const _priceCapUSDCents = async (client, eSIMWalletAddress) => {
|
|
32
32
|
return client.extend(publicActions).readContract({
|
|
33
33
|
address: eSIMWalletAddress,
|
|
34
34
|
abi: ESIMWallet,
|
|
35
|
-
functionName: "
|
|
35
|
+
functionName: "priceCapUSDCents",
|
|
36
36
|
args: []
|
|
37
37
|
});
|
|
38
38
|
};
|
|
@@ -74,15 +74,16 @@ export const _deviceWallet = async (client, eSIMWalletAddress) => {
|
|
|
74
74
|
*
|
|
75
75
|
* The contract publishes no length getter, so there is no way to ask how many
|
|
76
76
|
* entries exist. Read upwards from zero until a call reverts, or track the count
|
|
77
|
-
* from the `
|
|
78
|
-
* `_totalEntries` is the length
|
|
77
|
+
* from the `DataBundleBoughtWithToken`, `DataBundleSettlementRecorded` and
|
|
78
|
+
* `TransactionHistoryPopulated` events, whose `_totalEntries` is the length
|
|
79
|
+
* after the batch landed.
|
|
79
80
|
*/
|
|
80
81
|
export const _transactionHistory = async (client, eSIMWalletAddress, index) => {
|
|
81
|
-
const [
|
|
82
|
+
const [id, priceUSDCents, settlement] = await client.extend(publicActions).readContract({
|
|
82
83
|
address: eSIMWalletAddress,
|
|
83
84
|
abi: ESIMWallet,
|
|
84
85
|
functionName: "transactionHistory",
|
|
85
86
|
args: [index]
|
|
86
87
|
});
|
|
87
|
-
return {
|
|
88
|
+
return { id, priceUSDCents, settlement };
|
|
88
89
|
};
|
|
@@ -38,13 +38,13 @@ export const _deviceIdentifierToESIMDetails = async (client, deviceIdentifier, e
|
|
|
38
38
|
const chainID = await client.getChainId();
|
|
39
39
|
const rpcURL = client.transport.url;
|
|
40
40
|
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
41
|
-
const [
|
|
41
|
+
const [id, priceUSDCents, settlement] = await client.extend(publicActions).readContract({
|
|
42
42
|
address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
43
43
|
abi: LazyWalletRegistry,
|
|
44
44
|
functionName: "deviceIdentifierToESIMDetails",
|
|
45
45
|
args: [deviceIdentifier, eSIMIdentifier, index]
|
|
46
46
|
});
|
|
47
|
-
return {
|
|
47
|
+
return { id, priceUSDCents, settlement };
|
|
48
48
|
};
|
|
49
49
|
/** Most eSIM wallets one `deployLazyWalletAndSetESIMIdentifier` call will deploy. */
|
|
50
50
|
export const _maxESIMWalletsPerCall = async (client) => {
|
|
@@ -125,6 +125,23 @@ export const _historyEntriesCopied = async (client, eSIMIdentifier) => {
|
|
|
125
125
|
args: [eSIMIdentifier]
|
|
126
126
|
});
|
|
127
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* History entries still waiting to be copied in for this eSIM. A wallet's own
|
|
130
|
+
* purchase paths (`buyDataBundleWithToken`, `recordSettledPurchase`) refuse a
|
|
131
|
+
* new entry while this is non-zero, since it would land ahead of history that
|
|
132
|
+
* has not arrived yet.
|
|
133
|
+
*/
|
|
134
|
+
export const _outstandingHistoryEntries = async (client, eSIMIdentifier) => {
|
|
135
|
+
const chainID = await client.getChainId();
|
|
136
|
+
const rpcURL = client.transport.url;
|
|
137
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
138
|
+
return client.extend(publicActions).readContract({
|
|
139
|
+
address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
|
|
140
|
+
abi: LazyWalletRegistry,
|
|
141
|
+
functionName: "outstandingHistoryEntries",
|
|
142
|
+
args: [eSIMIdentifier]
|
|
143
|
+
});
|
|
144
|
+
};
|
|
128
145
|
/** Whether a device identifier has purchases recorded against it here. */
|
|
129
146
|
export const _isDeviceIdentifierReserved = async (client, deviceIdentifier) => {
|
|
130
147
|
const chainID = await client.getChainId();
|