kokio-sdk 2.0.0 → 2.1.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.
@@ -1,5 +1,5 @@
1
1
  import { _getChainSpecificConstants } from "../constants.js";
2
- import { MissingEOAWalletError } from "../errors.js";
2
+ import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
3
3
  import { DeviceWallet } from "../../abis/index.js";
4
4
  // Admin-EOA logic targeting a specific `DeviceWallet` instance (its address is
5
5
  // passed in - there is no single factory address). `deployESIMWallet` is
@@ -19,7 +19,7 @@ export const _deployESIMWallet = async (client, deviceWalletAddress, salt) => {
19
19
  const values = _getChainSpecificConstants(chainID, rpcURL);
20
20
  if (!client.account)
21
21
  throw new MissingEOAWalletError();
22
- return client.writeContract({
22
+ return writeContractOrThrow(client, {
23
23
  address: deviceWalletAddress,
24
24
  chain: values.chain,
25
25
  account: client.account.address,
@@ -41,7 +41,7 @@ export const _addDeposit = async (client, deviceWalletAddress, amount) => {
41
41
  const values = _getChainSpecificConstants(chainID, rpcURL);
42
42
  if (!client.account)
43
43
  throw new MissingEOAWalletError();
44
- return client.writeContract({
44
+ return writeContractOrThrow(client, {
45
45
  address: deviceWalletAddress,
46
46
  chain: values.chain,
47
47
  account: client.account.address,
@@ -1,5 +1,5 @@
1
1
  import { _getChainSpecificConstants } from "../constants.js";
2
- import { MissingEOAWalletError } from "../errors.js";
2
+ import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
3
3
  import { DeviceWalletFactory } from "../../abis/index.js";
4
4
  // Admin-EOA logic for `DeviceWalletFactory`.
5
5
  //
@@ -24,7 +24,7 @@ export const _deployDeviceWalletForUsers = async (client, deviceUniqueIdentifier
24
24
  const values = _getChainSpecificConstants(chainID, rpcURL);
25
25
  if (!client.account)
26
26
  throw new MissingEOAWalletError();
27
- return client.writeContract({
27
+ return writeContractOrThrow(client, {
28
28
  address: values.factoryAddresses.DEVICE_WALLET_FACTORY,
29
29
  chain: values.chain,
30
30
  account: client.account.address,
@@ -45,7 +45,7 @@ export const _postCreateAccount = async (client, deviceWallet, deviceUniqueIdent
45
45
  const values = _getChainSpecificConstants(chainID, rpcURL);
46
46
  if (!client.account)
47
47
  throw new MissingEOAWalletError();
48
- return client.writeContract({
48
+ return writeContractOrThrow(client, {
49
49
  address: values.factoryAddresses.DEVICE_WALLET_FACTORY,
50
50
  chain: values.chain,
51
51
  account: client.account.address,
@@ -61,7 +61,7 @@ export const _addRegistryAddress = async (client, registryContractAddress) => {
61
61
  const values = _getChainSpecificConstants(chainID, rpcURL);
62
62
  if (!client.account)
63
63
  throw new MissingEOAWalletError();
64
- return client.writeContract({
64
+ return writeContractOrThrow(client, {
65
65
  address: values.factoryAddresses.DEVICE_WALLET_FACTORY,
66
66
  chain: values.chain,
67
67
  account: client.account.address,
@@ -77,7 +77,7 @@ export const _updateDeviceWalletImplementation = async (client, newDeviceImpl) =
77
77
  const values = _getChainSpecificConstants(chainID, rpcURL);
78
78
  if (!client.account)
79
79
  throw new MissingEOAWalletError();
80
- return client.writeContract({
80
+ return writeContractOrThrow(client, {
81
81
  address: values.factoryAddresses.DEVICE_WALLET_FACTORY,
82
82
  chain: values.chain,
83
83
  account: client.account.address,
@@ -143,7 +143,7 @@ export const _acceptOwnership = async (client) => {
143
143
  const values = _getChainSpecificConstants(chainID, rpcURL);
144
144
  if (!client.account)
145
145
  throw new MissingEOAWalletError();
146
- return client.writeContract({
146
+ return writeContractOrThrow(client, {
147
147
  address: values.factoryAddresses.DEVICE_WALLET_FACTORY,
148
148
  chain: values.chain,
149
149
  account: client.account.address,
@@ -1,5 +1,5 @@
1
1
  import { _getChainSpecificConstants } from "../constants.js";
2
- import { MissingEOAWalletError } from "../errors.js";
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
5
  // `buyDataBundle` is `onlyDeviceWalletOrESIMWalletAdmin`, so the admin EOA can
@@ -16,7 +16,7 @@ export const _buyDataBundle = async (client, eSIMWalletAddress, dataBundleDetail
16
16
  const values = _getChainSpecificConstants(chainID, rpcURL);
17
17
  if (!client.account)
18
18
  throw new MissingEOAWalletError();
19
- return client.writeContract({
19
+ return writeContractOrThrow(client, {
20
20
  address: eSIMWalletAddress,
21
21
  chain: values.chain,
22
22
  account: client.account.address,
@@ -1,5 +1,5 @@
1
1
  import { _getChainSpecificConstants } from "../constants.js";
2
- import { MissingEOAWalletError } from "../errors.js";
2
+ import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
3
3
  import { ESIMWalletFactory } from "../../abis/index.js";
4
4
  // Admin-EOA logic for `ESIMWalletFactory`. Both functions are owner-gated
5
5
  // (`addRegistryAddress` requires `msg.sender == owner()`, `updateESIMWalletImplementation`
@@ -19,7 +19,7 @@ export const _addRegistryAddress = async (client, registryContractAddress) => {
19
19
  const values = _getChainSpecificConstants(chainID, rpcURL);
20
20
  if (!client.account)
21
21
  throw new MissingEOAWalletError();
22
- return client.writeContract({
22
+ return writeContractOrThrow(client, {
23
23
  address: values.factoryAddresses.ESIM_WALLET_FACTORY,
24
24
  chain: values.chain,
25
25
  account: client.account.address,
@@ -35,7 +35,7 @@ export const _updateESIMWalletImplementation = async (client, eSIMWalletImpl) =>
35
35
  const values = _getChainSpecificConstants(chainID, rpcURL);
36
36
  if (!client.account)
37
37
  throw new MissingEOAWalletError();
38
- return client.writeContract({
38
+ return writeContractOrThrow(client, {
39
39
  address: values.factoryAddresses.ESIM_WALLET_FACTORY,
40
40
  chain: values.chain,
41
41
  account: client.account.address,
@@ -100,7 +100,7 @@ export const _acceptOwnership = async (client) => {
100
100
  const values = _getChainSpecificConstants(chainID, rpcURL);
101
101
  if (!client.account)
102
102
  throw new MissingEOAWalletError();
103
- return client.writeContract({
103
+ return writeContractOrThrow(client, {
104
104
  address: values.factoryAddresses.ESIM_WALLET_FACTORY,
105
105
  chain: values.chain,
106
106
  account: client.account.address,
@@ -1,6 +1,6 @@
1
1
  import { BaseError, ContractFunctionRevertedError, isAddressEqual, parseEventLogs, publicActions, } from "viem";
2
2
  import { _getChainSpecificConstants } from "../constants.js";
3
- import { BatchSizeOutOfRangeError, DepositOnResumeError, ESIMWalletNotLazyDeployedError, MissingBatchEventError, MissingEOAWalletError, StalledBatchError, } from "../errors.js";
3
+ import { BatchSizeOutOfRangeError, DepositOnResumeError, ESIMWalletNotLazyDeployedError, MissingBatchEventError, MissingEOAWalletError, StalledBatchError, writeContractOrThrow, } from "../errors.js";
4
4
  import { LazyWalletRegistry, Registry } from "../../abis/index.js";
5
5
  import { _eSIMWalletsDeployed, _lazyDeployedESIMWallet } from "./reads/lazyWalletRegistry.reads.js";
6
6
  // Admin-EOA logic for `LazyWalletRegistry`. Every function here is
@@ -45,7 +45,7 @@ export const _batchPopulateHistory = async (client, deviceUniqueIdentifiers, eSI
45
45
  const values = await _resolve(client);
46
46
  if (!client.account)
47
47
  throw new MissingEOAWalletError();
48
- return client.writeContract({
48
+ return writeContractOrThrow(client, {
49
49
  address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
50
50
  chain: values.chain,
51
51
  account: client.account.address,
@@ -67,7 +67,7 @@ export const _deployLazyWalletAndSetESIMIdentifier = async (client, deviceOwnerP
67
67
  const values = await _resolve(client);
68
68
  if (!client.account)
69
69
  throw new MissingEOAWalletError();
70
- return client.writeContract({
70
+ return writeContractOrThrow(client, {
71
71
  address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
72
72
  chain: values.chain,
73
73
  account: client.account.address,
@@ -90,7 +90,7 @@ export const _deployMoreESIMWalletsForLazyDevice = async (client, deviceUniqueId
90
90
  const values = await _resolve(client);
91
91
  if (!client.account)
92
92
  throw new MissingEOAWalletError();
93
- return client.writeContract({
93
+ return writeContractOrThrow(client, {
94
94
  address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
95
95
  chain: values.chain,
96
96
  account: client.account.address,
@@ -110,7 +110,7 @@ export const _setHistoryForLazyWallet = async (client, eSIMIdentifier, maxEntrie
110
110
  const values = await _resolve(client);
111
111
  if (!client.account)
112
112
  throw new MissingEOAWalletError();
113
- return client.writeContract({
113
+ return writeContractOrThrow(client, {
114
114
  address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
115
115
  chain: values.chain,
116
116
  account: client.account.address,
@@ -124,7 +124,7 @@ export const _switchESIMIdentifierToNewDeviceIdentifier = async (client, eSIMIde
124
124
  const values = await _resolve(client);
125
125
  if (!client.account)
126
126
  throw new MissingEOAWalletError();
127
- return client.writeContract({
127
+ return writeContractOrThrow(client, {
128
128
  address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
129
129
  chain: values.chain,
130
130
  account: client.account.address,
@@ -362,7 +362,7 @@ export const _acceptOwnership = async (client) => {
362
362
  const values = _getChainSpecificConstants(chainID, rpcURL);
363
363
  if (!client.account)
364
364
  throw new MissingEOAWalletError();
365
- return client.writeContract({
365
+ return writeContractOrThrow(client, {
366
366
  address: values.factoryAddresses.LAZY_WALLET_REGISTRY,
367
367
  chain: values.chain,
368
368
  account: client.account.address,
@@ -1,6 +1,6 @@
1
1
  import { encodeFunctionData, publicActions } from "viem";
2
2
  import { _getChainSpecificConstants } from "../constants.js";
3
- import { MissingEOAWalletError } from "../errors.js";
3
+ import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
4
4
  import { ProtocolAdmin, Registry } from "../../abis/index.js";
5
5
  // Admin-EOA logic for `ProtocolAdmin`, the timelock that owns `Registry`,
6
6
  // `LazyWalletRegistry`, `DeviceWalletFactory` and `ESIMWalletFactory`.
@@ -116,7 +116,7 @@ export const _schedule = async (client, call, opts = {}, delay) => {
116
116
  functionName: "hashOperation",
117
117
  args: [target, value, payload, predecessor, salt]
118
118
  });
119
- const hash = await client.writeContract({
119
+ const hash = await writeContractOrThrow(client, {
120
120
  address: values.factoryAddresses.PROTOCOL_ADMIN,
121
121
  chain: values.chain,
122
122
  account: client.account.address,
@@ -156,7 +156,7 @@ export const _scheduleBatch = async (client, calls, opts = {}, delay) => {
156
156
  functionName: "hashOperationBatch",
157
157
  args: [targets, callValues, payloads, predecessor, salt]
158
158
  });
159
- const hash = await client.writeContract({
159
+ const hash = await writeContractOrThrow(client, {
160
160
  address: values.factoryAddresses.PROTOCOL_ADMIN,
161
161
  chain: values.chain,
162
162
  account: client.account.address,
@@ -183,7 +183,7 @@ export const _scheduleRaw = async (client, target, value, payload, predecessor,
183
183
  functionName: "hashOperation",
184
184
  args: [target, value, payload, predecessor, salt]
185
185
  });
186
- const hash = await client.writeContract({
186
+ const hash = await writeContractOrThrow(client, {
187
187
  address: values.factoryAddresses.PROTOCOL_ADMIN,
188
188
  chain: values.chain,
189
189
  account: client.account.address,
@@ -208,7 +208,7 @@ export const _execute = async (client, operation) => {
208
208
  const values = await _resolve(client);
209
209
  if (!client.account)
210
210
  throw new MissingEOAWalletError();
211
- return client.writeContract({
211
+ return writeContractOrThrow(client, {
212
212
  address: values.factoryAddresses.PROTOCOL_ADMIN,
213
213
  chain: values.chain,
214
214
  account: client.account.address,
@@ -223,7 +223,7 @@ export const _executeBatch = async (client, operation) => {
223
223
  const values = await _resolve(client);
224
224
  if (!client.account)
225
225
  throw new MissingEOAWalletError();
226
- return client.writeContract({
226
+ return writeContractOrThrow(client, {
227
227
  address: values.factoryAddresses.PROTOCOL_ADMIN,
228
228
  chain: values.chain,
229
229
  account: client.account.address,
@@ -238,7 +238,7 @@ export const _executeRaw = async (client, target, value, payload, predecessor, s
238
238
  const values = await _resolve(client);
239
239
  if (!client.account)
240
240
  throw new MissingEOAWalletError();
241
- return client.writeContract({
241
+ return writeContractOrThrow(client, {
242
242
  address: values.factoryAddresses.PROTOCOL_ADMIN,
243
243
  chain: values.chain,
244
244
  account: client.account.address,
@@ -259,7 +259,7 @@ export const _cancel = async (client, id) => {
259
259
  const values = await _resolve(client);
260
260
  if (!client.account)
261
261
  throw new MissingEOAWalletError();
262
- return client.writeContract({
262
+ return writeContractOrThrow(client, {
263
263
  address: values.factoryAddresses.PROTOCOL_ADMIN,
264
264
  chain: values.chain,
265
265
  account: client.account.address,
@@ -281,7 +281,7 @@ export const _unpauseInstantly = async (client, target) => {
281
281
  const values = await _resolve(client);
282
282
  if (!client.account)
283
283
  throw new MissingEOAWalletError();
284
- return client.writeContract({
284
+ return writeContractOrThrow(client, {
285
285
  address: values.factoryAddresses.PROTOCOL_ADMIN,
286
286
  chain: values.chain,
287
287
  account: client.account.address,
@@ -301,7 +301,7 @@ export const _revokeCancellersInstantly = async (client, accounts) => {
301
301
  const values = await _resolve(client);
302
302
  if (!client.account)
303
303
  throw new MissingEOAWalletError();
304
- return client.writeContract({
304
+ return writeContractOrThrow(client, {
305
305
  address: values.factoryAddresses.PROTOCOL_ADMIN,
306
306
  chain: values.chain,
307
307
  account: client.account.address,
@@ -324,7 +324,7 @@ export const _disableAdminInstantly = async (client, target) => {
324
324
  const values = await _resolve(client);
325
325
  if (!client.account)
326
326
  throw new MissingEOAWalletError();
327
- return client.writeContract({
327
+ return writeContractOrThrow(client, {
328
328
  address: values.factoryAddresses.PROTOCOL_ADMIN,
329
329
  chain: values.chain,
330
330
  account: client.account.address,
@@ -345,7 +345,7 @@ export const _acceptOwnershipBatch = async (client, targets) => {
345
345
  const values = await _resolve(client);
346
346
  if (!client.account)
347
347
  throw new MissingEOAWalletError();
348
- return client.writeContract({
348
+ return writeContractOrThrow(client, {
349
349
  address: values.factoryAddresses.PROTOCOL_ADMIN,
350
350
  chain: values.chain,
351
351
  account: client.account.address,
@@ -362,7 +362,7 @@ export const _renounceRole = async (client, role, account) => {
362
362
  const values = await _resolve(client);
363
363
  if (!client.account)
364
364
  throw new MissingEOAWalletError();
365
- return client.writeContract({
365
+ return writeContractOrThrow(client, {
366
366
  address: values.factoryAddresses.PROTOCOL_ADMIN,
367
367
  chain: values.chain,
368
368
  account: client.account.address,
@@ -1,5 +1,5 @@
1
1
  import { _getChainSpecificConstants } from "../constants.js";
2
- import { MissingEOAWalletError } from "../errors.js";
2
+ import { MissingEOAWalletError, writeContractOrThrow } from "../errors.js";
3
3
  import { Registry } from "../../abis/index.js";
4
4
  // Admin-EOA logic for `Registry`. Most of this is `onlyOwner`, so the `client`
5
5
  // must carry the owner EOA. `_acceptAdminUpdate` is the nominee's own call and
@@ -16,7 +16,7 @@ export const _addOrUpdateLazyWalletRegistryAddress = async (client, lazyWalletRe
16
16
  const values = _getChainSpecificConstants(chainID, rpcURL);
17
17
  if (!client.account)
18
18
  throw new MissingEOAWalletError();
19
- return client.writeContract({
19
+ return writeContractOrThrow(client, {
20
20
  address: values.factoryAddresses.REGISTRY,
21
21
  chain: values.chain,
22
22
  account: client.account.address,
@@ -32,7 +32,7 @@ export const _updateVaultAddress = async (client, newVaultAddress) => {
32
32
  const values = _getChainSpecificConstants(chainID, rpcURL);
33
33
  if (!client.account)
34
34
  throw new MissingEOAWalletError();
35
- return client.writeContract({
35
+ return writeContractOrThrow(client, {
36
36
  address: values.factoryAddresses.REGISTRY,
37
37
  chain: values.chain,
38
38
  account: client.account.address,
@@ -56,7 +56,7 @@ export const _requestAdminUpdate = async (client, newAdmin) => {
56
56
  const values = _getChainSpecificConstants(chainID, rpcURL);
57
57
  if (!client.account)
58
58
  throw new MissingEOAWalletError();
59
- return client.writeContract({
59
+ return writeContractOrThrow(client, {
60
60
  address: values.factoryAddresses.REGISTRY,
61
61
  chain: values.chain,
62
62
  account: client.account.address,
@@ -78,7 +78,7 @@ export const _disableAdmin = async (client) => {
78
78
  const values = _getChainSpecificConstants(chainID, rpcURL);
79
79
  if (!client.account)
80
80
  throw new MissingEOAWalletError();
81
- return client.writeContract({
81
+ return writeContractOrThrow(client, {
82
82
  address: values.factoryAddresses.REGISTRY,
83
83
  chain: values.chain,
84
84
  account: client.account.address,
@@ -100,7 +100,7 @@ export const _enableAdmin = async (client) => {
100
100
  const values = _getChainSpecificConstants(chainID, rpcURL);
101
101
  if (!client.account)
102
102
  throw new MissingEOAWalletError();
103
- return client.writeContract({
103
+ return writeContractOrThrow(client, {
104
104
  address: values.factoryAddresses.REGISTRY,
105
105
  chain: values.chain,
106
106
  account: client.account.address,
@@ -124,7 +124,7 @@ export const _pause = async (client) => {
124
124
  const values = _getChainSpecificConstants(chainID, rpcURL);
125
125
  if (!client.account)
126
126
  throw new MissingEOAWalletError();
127
- return client.writeContract({
127
+ return writeContractOrThrow(client, {
128
128
  address: values.factoryAddresses.REGISTRY,
129
129
  chain: values.chain,
130
130
  account: client.account.address,
@@ -146,7 +146,7 @@ export const _unpause = async (client) => {
146
146
  const values = _getChainSpecificConstants(chainID, rpcURL);
147
147
  if (!client.account)
148
148
  throw new MissingEOAWalletError();
149
- return client.writeContract({
149
+ return writeContractOrThrow(client, {
150
150
  address: values.factoryAddresses.REGISTRY,
151
151
  chain: values.chain,
152
152
  account: client.account.address,
@@ -169,7 +169,7 @@ export const _setDefaultDataBundlePriceCap = async (client, cap) => {
169
169
  const values = _getChainSpecificConstants(chainID, rpcURL);
170
170
  if (!client.account)
171
171
  throw new MissingEOAWalletError();
172
- return client.writeContract({
172
+ return writeContractOrThrow(client, {
173
173
  address: values.factoryAddresses.REGISTRY,
174
174
  chain: values.chain,
175
175
  account: client.account.address,
@@ -190,7 +190,7 @@ export const _assignESIMIdentifier = async (client, eSIMWalletAddress, eSIMUniqu
190
190
  const values = _getChainSpecificConstants(chainID, rpcURL);
191
191
  if (!client.account)
192
192
  throw new MissingEOAWalletError();
193
- return client.writeContract({
193
+ return writeContractOrThrow(client, {
194
194
  address: values.factoryAddresses.REGISTRY,
195
195
  chain: values.chain,
196
196
  account: client.account.address,
@@ -210,7 +210,7 @@ export const _acceptAdminUpdate = async (client) => {
210
210
  const values = _getChainSpecificConstants(chainID, rpcURL);
211
211
  if (!client.account)
212
212
  throw new MissingEOAWalletError();
213
- return client.writeContract({
213
+ return writeContractOrThrow(client, {
214
214
  address: values.factoryAddresses.REGISTRY,
215
215
  chain: values.chain,
216
216
  account: client.account.address,
@@ -234,7 +234,7 @@ export const _acceptOwnership = async (client) => {
234
234
  const values = _getChainSpecificConstants(chainID, rpcURL);
235
235
  if (!client.account)
236
236
  throw new MissingEOAWalletError();
237
- return client.writeContract({
237
+ return writeContractOrThrow(client, {
238
238
  address: values.factoryAddresses.REGISTRY,
239
239
  chain: values.chain,
240
240
  account: client.account.address,
@@ -1,4 +1,4 @@
1
- import { decodeErrorResult, isHex } from "viem";
1
+ import { BaseError, ContractFunctionRevertedError, decodeErrorResult, isHex, } from "viem";
2
2
  import { DeviceWallet, DeviceWalletFactory, ESIMWallet, ESIMWalletFactory, LazyWalletRegistry, P256Verifier, Registry, RegistryHelper, } from "../abis/index.js";
3
3
  /**
4
4
  * Base class for every error the Kokio SDK throws deliberately. Consumers can
@@ -180,3 +180,32 @@ export class ContractRevertError extends KokioError {
180
180
  this.decoded = decoded;
181
181
  }
182
182
  }
183
+ /**
184
+ * Pulls a ContractRevertError out of an error thrown by viem, or `null` if it
185
+ * isn't a revert viem could decode a selector for.
186
+ */
187
+ export const toContractRevertError = (err) => {
188
+ if (!(err instanceof BaseError))
189
+ return null;
190
+ const revert = err.walk((e) => e instanceof ContractFunctionRevertedError);
191
+ if (!(revert instanceof ContractFunctionRevertedError) || !revert.raw)
192
+ return null;
193
+ return new ContractRevertError(revert.raw);
194
+ };
195
+ /**
196
+ * `client.writeContract`, but a recognised on-chain revert comes back as a
197
+ * ContractRevertError instead of viem's raw error chain. Anything else -
198
+ * network failures, an unrecognised revert selector - is rethrown as-is.
199
+ *
200
+ * Mirrors `WalletClient["writeContract"]`'s own generics rather than reading
201
+ * them off `Parameters<...>`, since that would collapse the per-call overload
202
+ * (e.g. a payable function's `value` field) to a single, wrong shape.
203
+ */
204
+ export const writeContractOrThrow = async (client, request) => {
205
+ try {
206
+ return await client.writeContract(request);
207
+ }
208
+ catch (err) {
209
+ throw toContractRevertError(err) ?? err;
210
+ }
211
+ };
@@ -1,4 +1,4 @@
1
- import { Hex } from "viem";
1
+ import { Abi, Account, Chain, ContractFunctionArgs, ContractFunctionName, Hex, WalletClient, WriteContractParameters, WriteContractReturnType } from "viem";
2
2
  /**
3
3
  * Base class for every error the Kokio SDK throws deliberately. Consumers can
4
4
  * `instanceof KokioError` to distinguish SDK-originated failures from viem /
@@ -106,3 +106,18 @@ export declare class ContractRevertError extends KokioError {
106
106
  readonly decoded: DecodedRevert | null;
107
107
  constructor(data: Hex);
108
108
  }
109
+ /**
110
+ * Pulls a ContractRevertError out of an error thrown by viem, or `null` if it
111
+ * isn't a revert viem could decode a selector for.
112
+ */
113
+ export declare const toContractRevertError: (err: unknown) => ContractRevertError | null;
114
+ /**
115
+ * `client.writeContract`, but a recognised on-chain revert comes back as a
116
+ * ContractRevertError instead of viem's raw error chain. Anything else -
117
+ * network failures, an unrecognised revert selector - is rethrown as-is.
118
+ *
119
+ * Mirrors `WalletClient["writeContract"]`'s own generics rather than reading
120
+ * them off `Parameters<...>`, since that would collapse the per-call overload
121
+ * (e.g. a payable function's `value` field) to a single, wrong shape.
122
+ */
123
+ export declare const writeContractOrThrow: <const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "payable" | "nonpayable">, args extends ContractFunctionArgs<abi, "payable" | "nonpayable", functionName>, chainOverride extends Chain | undefined = undefined>(client: WalletClient, request: WriteContractParameters<abi, functionName, args, Chain | undefined, Account | undefined, chainOverride>) => Promise<WriteContractReturnType>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokio-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/config.js",