@circle-fin/app-kit 1.12.0 → 1.12.1

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.
@@ -2604,6 +2604,18 @@ interface TokenActionMap {
2604
2604
  */
2605
2605
  walletAddress?: string | undefined;
2606
2606
  };
2607
+ /**
2608
+ * Get the on-chain name of the token contract.
2609
+ *
2610
+ * This is a read-only operation. For USDC the value is also the EIP-712
2611
+ * domain name, which permit and authorize signing flows need.
2612
+ */
2613
+ name: ActionParameters & {
2614
+ /**
2615
+ * The contract address of the token.
2616
+ */
2617
+ tokenAddress: string;
2618
+ };
2607
2619
  }
2608
2620
 
2609
2621
  /**
@@ -3433,6 +3445,30 @@ declare class ActionRegistry {
3433
3445
  executeAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, context: ResolvedOperationContext): Promise<PreparedChainRequest>;
3434
3446
  }
3435
3447
 
3448
+ /**
3449
+ * Canonical list of actions that do not prepare or submit transactions.
3450
+ *
3451
+ * @internal
3452
+ */
3453
+ declare const READ_ACTION_KEYS: readonly ["token.allowance", "token.balanceOf", "token.name", "native.balanceOf", "usdc.allowance", "usdc.balanceOf", "usdc.name", "gateway.v1.isDelegate", "gateway.v1.withdrawingBalance", "gateway.v1.withdrawalBlock", "gateway.v1.signBurnIntents"];
3454
+ /**
3455
+ * Action keys that execute without preparing or submitting a transaction.
3456
+ *
3457
+ * @remarks
3458
+ * Derive this type from the canonical runtime list so compile-time and runtime
3459
+ * classification cannot drift. `gateway.v1.signBurnIntents` is included
3460
+ * because the action system models off-chain signing as a read action: it does
3461
+ * not prepare a chain request.
3462
+ *
3463
+ * @example
3464
+ * ```typescript
3465
+ * import type { ReadActionKey } from '@core/adapter'
3466
+ *
3467
+ * const action: ReadActionKey = 'token.allowance'
3468
+ * ```
3469
+ */
3470
+ type ReadActionKey = (typeof READ_ACTION_KEYS)[number];
3471
+
3436
3472
  /**
3437
3473
  * Defines the capabilities of an adapter, including address handling patterns and supported chains.
3438
3474
  *
@@ -3601,6 +3637,69 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
3601
3637
  * ```
3602
3638
  */
3603
3639
  prepareAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<PreparedChainRequest>;
3640
+ /**
3641
+ * Execute a non-transaction action without routing through transaction preparation.
3642
+ *
3643
+ * @remarks
3644
+ * Use this seam for balance, allowance, contract-state, and other actions
3645
+ * classified as reads. It never calls {@link Adapter.prepareAction}, so
3646
+ * transaction authorization wrappers only observe actions that can produce a
3647
+ * signable chain request.
3648
+ *
3649
+ * @typeParam TActionKey - The read action key.
3650
+ * @param action - The read action to execute.
3651
+ * @param params - The parameters for the read action.
3652
+ * @param ctx - The operation context.
3653
+ * @returns The raw action response.
3654
+ * @throws {KitError} When the key is not a read action or no handler is registered.
3655
+ * @throws Error When the operation context or action handler fails.
3656
+ *
3657
+ * @example
3658
+ * ```typescript
3659
+ * import { Ethereum } from '@core/chains'
3660
+ *
3661
+ * const balance = await adapter.readAction(
3662
+ * 'token.balanceOf',
3663
+ * { tokenAddress, walletAddress },
3664
+ * { chain: Ethereum },
3665
+ * )
3666
+ * ```
3667
+ *
3668
+ * @internal
3669
+ */
3670
+ readAction<TActionKey extends ReadActionKey>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<unknown>;
3671
+ /**
3672
+ * Read the current token allowance a delegate holds over an owner's tokens.
3673
+ *
3674
+ * @remarks
3675
+ * Perform a network read through {@link Adapter.readAction}. This method
3676
+ * never routes through {@link Adapter.prepareAction}. On chains without an
3677
+ * allowance model, such as Solana, return the maximum uint256 value.
3678
+ *
3679
+ * @param params - The token to query and the delegate whose allowance is being read.
3680
+ * @param ctx - Operation context with compile-time validated address requirements.
3681
+ * @returns A promise resolving to the current allowance in the token's base units.
3682
+ * @throws {KitError} When the adapter does not register a `token.allowance` handler.
3683
+ * @throws Error When the operation context or action handler fails.
3684
+ *
3685
+ * @example
3686
+ * ```typescript
3687
+ * import type { Adapter } from '@core/adapter'
3688
+ * import { Ethereum } from '@core/chains'
3689
+ *
3690
+ * declare const adapter: Adapter
3691
+ *
3692
+ * const allowance = await adapter.getTokenAllowance(
3693
+ * {
3694
+ * tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
3695
+ * delegate: '0x1111111111111111111111111111111111111111',
3696
+ * },
3697
+ * { chain: Ethereum },
3698
+ * )
3699
+ * console.log(allowance) // 1000000n
3700
+ * ```
3701
+ */
3702
+ getTokenAllowance(params: ActionPayload<'token.allowance'>, ctx: OperationContext<TAdapterCapabilities>): Promise<bigint>;
3604
3703
  /**
3605
3704
  * Prepares a transaction for future gas estimation and execution.
3606
3705
  *
@@ -3787,6 +3886,37 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
3787
3886
  abstract getTokenDecimals(tokenAddress: string, chain: ChainDefinition): Promise<number>;
3788
3887
  }
3789
3888
 
3889
+ /**
3890
+ * Simplified error information structure for logging and events.
3891
+ *
3892
+ * @remarks
3893
+ * This lightweight type is used for error reporting in events, logs, and
3894
+ * observability systems. It provides essential error context without the
3895
+ * full ErrorDetails structure. Used across retry mechanisms, adapters,
3896
+ * and other subsystems that need to record error information.
3897
+ *
3898
+ * @example
3899
+ * ```typescript
3900
+ * import { ErrorInfo } from '@core/errors'
3901
+ *
3902
+ * const info: ErrorInfo = {
3903
+ * name: 'NETWORK_TIMEOUT',
3904
+ * message: 'Request timed out after 5000ms',
3905
+ * code: 3002
3906
+ * }
3907
+ * ```
3908
+ */
3909
+ interface ErrorInfo {
3910
+ /** Error name (e.g., 'TypeError', 'KitError', 'NETWORK_TIMEOUT'). */
3911
+ name: string;
3912
+ /** Error message describing what went wrong. */
3913
+ message: string;
3914
+ /** Optional error code if the error has one (e.g., KitError codes). */
3915
+ code?: number;
3916
+ /** Error category (e.g., INPUT, RPC, ONCHAIN, BALANCE, NETWORK, UNKNOWN). Only set for KitError instances. */
3917
+ type?: string;
3918
+ }
3919
+
3790
3920
  /**
3791
3921
  * A type-safe event emitter for managing action-based event subscriptions.
3792
3922
  *
@@ -4027,37 +4157,6 @@ declare module './types' {
4027
4157
  }
4028
4158
  }
4029
4159
 
4030
- /**
4031
- * Simplified error information structure for logging and events.
4032
- *
4033
- * @remarks
4034
- * This lightweight type is used for error reporting in events, logs, and
4035
- * observability systems. It provides essential error context without the
4036
- * full ErrorDetails structure. Used across retry mechanisms, adapters,
4037
- * and other subsystems that need to record error information.
4038
- *
4039
- * @example
4040
- * ```typescript
4041
- * import { ErrorInfo } from '@core/errors'
4042
- *
4043
- * const info: ErrorInfo = {
4044
- * name: 'NETWORK_TIMEOUT',
4045
- * message: 'Request timed out after 5000ms',
4046
- * code: 3002
4047
- * }
4048
- * ```
4049
- */
4050
- interface ErrorInfo {
4051
- /** Error name (e.g., 'TypeError', 'KitError', 'NETWORK_TIMEOUT'). */
4052
- name: string;
4053
- /** Error message describing what went wrong. */
4054
- message: string;
4055
- /** Optional error code if the error has one (e.g., KitError codes). */
4056
- code?: number;
4057
- /** Error category (e.g., INPUT, RPC, ONCHAIN, BALANCE, NETWORK, UNKNOWN). Only set for KitError instances. */
4058
- type?: string;
4059
- }
4060
-
4061
4160
  /**
4062
4161
  * Runtime array of token identifiers supported by the Gateway v1 provider.
4063
4162
  *
@@ -2604,6 +2604,18 @@ interface TokenActionMap {
2604
2604
  */
2605
2605
  walletAddress?: string | undefined;
2606
2606
  };
2607
+ /**
2608
+ * Get the on-chain name of the token contract.
2609
+ *
2610
+ * This is a read-only operation. For USDC the value is also the EIP-712
2611
+ * domain name, which permit and authorize signing flows need.
2612
+ */
2613
+ name: ActionParameters & {
2614
+ /**
2615
+ * The contract address of the token.
2616
+ */
2617
+ tokenAddress: string;
2618
+ };
2607
2619
  }
2608
2620
 
2609
2621
  /**
@@ -3433,6 +3445,30 @@ declare class ActionRegistry {
3433
3445
  executeAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, context: ResolvedOperationContext): Promise<PreparedChainRequest>;
3434
3446
  }
3435
3447
 
3448
+ /**
3449
+ * Canonical list of actions that do not prepare or submit transactions.
3450
+ *
3451
+ * @internal
3452
+ */
3453
+ declare const READ_ACTION_KEYS: readonly ["token.allowance", "token.balanceOf", "token.name", "native.balanceOf", "usdc.allowance", "usdc.balanceOf", "usdc.name", "gateway.v1.isDelegate", "gateway.v1.withdrawingBalance", "gateway.v1.withdrawalBlock", "gateway.v1.signBurnIntents"];
3454
+ /**
3455
+ * Action keys that execute without preparing or submitting a transaction.
3456
+ *
3457
+ * @remarks
3458
+ * Derive this type from the canonical runtime list so compile-time and runtime
3459
+ * classification cannot drift. `gateway.v1.signBurnIntents` is included
3460
+ * because the action system models off-chain signing as a read action: it does
3461
+ * not prepare a chain request.
3462
+ *
3463
+ * @example
3464
+ * ```typescript
3465
+ * import type { ReadActionKey } from '@core/adapter'
3466
+ *
3467
+ * const action: ReadActionKey = 'token.allowance'
3468
+ * ```
3469
+ */
3470
+ type ReadActionKey = (typeof READ_ACTION_KEYS)[number];
3471
+
3436
3472
  /**
3437
3473
  * Defines the capabilities of an adapter, including address handling patterns and supported chains.
3438
3474
  *
@@ -3601,6 +3637,69 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
3601
3637
  * ```
3602
3638
  */
3603
3639
  prepareAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<PreparedChainRequest>;
3640
+ /**
3641
+ * Execute a non-transaction action without routing through transaction preparation.
3642
+ *
3643
+ * @remarks
3644
+ * Use this seam for balance, allowance, contract-state, and other actions
3645
+ * classified as reads. It never calls {@link Adapter.prepareAction}, so
3646
+ * transaction authorization wrappers only observe actions that can produce a
3647
+ * signable chain request.
3648
+ *
3649
+ * @typeParam TActionKey - The read action key.
3650
+ * @param action - The read action to execute.
3651
+ * @param params - The parameters for the read action.
3652
+ * @param ctx - The operation context.
3653
+ * @returns The raw action response.
3654
+ * @throws {KitError} When the key is not a read action or no handler is registered.
3655
+ * @throws Error When the operation context or action handler fails.
3656
+ *
3657
+ * @example
3658
+ * ```typescript
3659
+ * import { Ethereum } from '@core/chains'
3660
+ *
3661
+ * const balance = await adapter.readAction(
3662
+ * 'token.balanceOf',
3663
+ * { tokenAddress, walletAddress },
3664
+ * { chain: Ethereum },
3665
+ * )
3666
+ * ```
3667
+ *
3668
+ * @internal
3669
+ */
3670
+ readAction<TActionKey extends ReadActionKey>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<unknown>;
3671
+ /**
3672
+ * Read the current token allowance a delegate holds over an owner's tokens.
3673
+ *
3674
+ * @remarks
3675
+ * Perform a network read through {@link Adapter.readAction}. This method
3676
+ * never routes through {@link Adapter.prepareAction}. On chains without an
3677
+ * allowance model, such as Solana, return the maximum uint256 value.
3678
+ *
3679
+ * @param params - The token to query and the delegate whose allowance is being read.
3680
+ * @param ctx - Operation context with compile-time validated address requirements.
3681
+ * @returns A promise resolving to the current allowance in the token's base units.
3682
+ * @throws {KitError} When the adapter does not register a `token.allowance` handler.
3683
+ * @throws Error When the operation context or action handler fails.
3684
+ *
3685
+ * @example
3686
+ * ```typescript
3687
+ * import type { Adapter } from '@core/adapter'
3688
+ * import { Ethereum } from '@core/chains'
3689
+ *
3690
+ * declare const adapter: Adapter
3691
+ *
3692
+ * const allowance = await adapter.getTokenAllowance(
3693
+ * {
3694
+ * tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
3695
+ * delegate: '0x1111111111111111111111111111111111111111',
3696
+ * },
3697
+ * { chain: Ethereum },
3698
+ * )
3699
+ * console.log(allowance) // 1000000n
3700
+ * ```
3701
+ */
3702
+ getTokenAllowance(params: ActionPayload<'token.allowance'>, ctx: OperationContext<TAdapterCapabilities>): Promise<bigint>;
3604
3703
  /**
3605
3704
  * Prepares a transaction for future gas estimation and execution.
3606
3705
  *
@@ -3787,6 +3886,37 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
3787
3886
  abstract getTokenDecimals(tokenAddress: string, chain: ChainDefinition): Promise<number>;
3788
3887
  }
3789
3888
 
3889
+ /**
3890
+ * Simplified error information structure for logging and events.
3891
+ *
3892
+ * @remarks
3893
+ * This lightweight type is used for error reporting in events, logs, and
3894
+ * observability systems. It provides essential error context without the
3895
+ * full ErrorDetails structure. Used across retry mechanisms, adapters,
3896
+ * and other subsystems that need to record error information.
3897
+ *
3898
+ * @example
3899
+ * ```typescript
3900
+ * import { ErrorInfo } from '@core/errors'
3901
+ *
3902
+ * const info: ErrorInfo = {
3903
+ * name: 'NETWORK_TIMEOUT',
3904
+ * message: 'Request timed out after 5000ms',
3905
+ * code: 3002
3906
+ * }
3907
+ * ```
3908
+ */
3909
+ interface ErrorInfo {
3910
+ /** Error name (e.g., 'TypeError', 'KitError', 'NETWORK_TIMEOUT'). */
3911
+ name: string;
3912
+ /** Error message describing what went wrong. */
3913
+ message: string;
3914
+ /** Optional error code if the error has one (e.g., KitError codes). */
3915
+ code?: number;
3916
+ /** Error category (e.g., INPUT, RPC, ONCHAIN, BALANCE, NETWORK, UNKNOWN). Only set for KitError instances. */
3917
+ type?: string;
3918
+ }
3919
+
3790
3920
  /**
3791
3921
  * A type-safe event emitter for managing action-based event subscriptions.
3792
3922
  *
@@ -4027,37 +4157,6 @@ declare module './types' {
4027
4157
  }
4028
4158
  }
4029
4159
 
4030
- /**
4031
- * Simplified error information structure for logging and events.
4032
- *
4033
- * @remarks
4034
- * This lightweight type is used for error reporting in events, logs, and
4035
- * observability systems. It provides essential error context without the
4036
- * full ErrorDetails structure. Used across retry mechanisms, adapters,
4037
- * and other subsystems that need to record error information.
4038
- *
4039
- * @example
4040
- * ```typescript
4041
- * import { ErrorInfo } from '@core/errors'
4042
- *
4043
- * const info: ErrorInfo = {
4044
- * name: 'NETWORK_TIMEOUT',
4045
- * message: 'Request timed out after 5000ms',
4046
- * code: 3002
4047
- * }
4048
- * ```
4049
- */
4050
- interface ErrorInfo {
4051
- /** Error name (e.g., 'TypeError', 'KitError', 'NETWORK_TIMEOUT'). */
4052
- name: string;
4053
- /** Error message describing what went wrong. */
4054
- message: string;
4055
- /** Optional error code if the error has one (e.g., KitError codes). */
4056
- code?: number;
4057
- /** Error category (e.g., INPUT, RPC, ONCHAIN, BALANCE, NETWORK, UNKNOWN). Only set for KitError instances. */
4058
- type?: string;
4059
- }
4060
-
4061
4160
  /**
4062
4161
  * Runtime array of token identifiers supported by the Gateway v1 provider.
4063
4162
  *
@@ -658,6 +658,11 @@ class KitError extends Error {
658
658
  name: 'INPUT_UNSUPPORTED_TOKEN',
659
659
  type: 'INPUT'
660
660
  },
661
+ /** Action not supported by this adapter / ecosystem */ UNSUPPORTED_ACTION: {
662
+ code: 1008,
663
+ name: 'INPUT_UNSUPPORTED_ACTION',
664
+ type: 'INPUT'
665
+ },
661
666
  /** No route satisfies the slippage or minimum-output constraint */ SLIPPAGE_CONSTRAINT_NOT_MET: {
662
667
  code: 1009,
663
668
  name: 'INPUT_SLIPPAGE_CONSTRAINT_NOT_MET',
@@ -7989,6 +7994,7 @@ function parseOrThrow(value, schema, context) {
7989
7994
  [Blockchain.Arbitrum_Sepolia]: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
7990
7995
  [Blockchain.Avalanche_Fuji]: '0x5425890298aed601595a70AB815c96711a31Bc65',
7991
7996
  [Blockchain.Base_Sepolia]: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
7997
+ [Blockchain.Celo_Alfajores_Testnet]: '0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B',
7992
7998
  [Blockchain.Codex_Testnet]: '0x6d7f141b6819C2c9CC2f818e6ad549E7Ca090F8f',
7993
7999
  [Blockchain.Cronos_Testnet]: '0xEb33dc5fac03833e132593659e1dE7256aB59794',
7994
8000
  [Blockchain.Edge_Testnet]: '0x2d9F7CAD728051AA35Ecdc472a14cf8cDF5CFD6B',
@@ -8881,7 +8887,7 @@ function parseOrThrow(value, schema, context) {
8881
8887
  }
8882
8888
 
8883
8889
  var name = "@circle-fin/unified-balance-kit";
8884
- var version = "1.4.0";
8890
+ var version = "1.4.1";
8885
8891
  var pkg = {
8886
8892
  name: name,
8887
8893
  version: version};
@@ -9164,6 +9170,110 @@ var pkg = {
9164
9170
  * ```
9165
9171
  */ const USDC_DECIMALS$1 = 6;
9166
9172
 
9173
+ /**
9174
+ * Canonical list of actions that do not prepare or submit transactions.
9175
+ *
9176
+ * @internal
9177
+ */ const READ_ACTION_KEYS = [
9178
+ 'token.allowance',
9179
+ 'token.balanceOf',
9180
+ 'token.name',
9181
+ 'native.balanceOf',
9182
+ 'usdc.allowance',
9183
+ 'usdc.balanceOf',
9184
+ 'usdc.name',
9185
+ 'gateway.v1.isDelegate',
9186
+ 'gateway.v1.withdrawingBalance',
9187
+ 'gateway.v1.withdrawalBlock',
9188
+ 'gateway.v1.signBurnIntents'
9189
+ ];
9190
+ const READ_ACTION_KEY_SET = new Set(READ_ACTION_KEYS);
9191
+ /**
9192
+ * Check whether a runtime value identifies a read action.
9193
+ *
9194
+ * @param action - The value to classify.
9195
+ * @returns Whether the value is a registered read-action key.
9196
+ *
9197
+ * @example
9198
+ * ```typescript
9199
+ * import { isReadActionKey } from '@core/adapter'
9200
+ *
9201
+ * if (isReadActionKey(value)) {
9202
+ * await adapter.readAction(value, params, context)
9203
+ * }
9204
+ * ```
9205
+ *
9206
+ * @internal
9207
+ */ function isReadActionKey(action) {
9208
+ return typeof action === 'string' && READ_ACTION_KEY_SET.has(action);
9209
+ }
9210
+
9211
+ /**
9212
+ * Create the standard error for a missing or non-read action.
9213
+ *
9214
+ * @param action - The unsupported action value.
9215
+ * @returns A fatal unsupported-action error.
9216
+ *
9217
+ * @internal
9218
+ */ function createUnsupportedReadActionError(action) {
9219
+ return new KitError({
9220
+ ...InputError.UNSUPPORTED_ACTION,
9221
+ recoverability: 'FATAL',
9222
+ message: `Read action "${String(action)}" is not registered in this adapter.`
9223
+ });
9224
+ }
9225
+ /**
9226
+ * Execute a read through the adapter's dedicated read seam when available.
9227
+ *
9228
+ * @remarks
9229
+ * Fall back to the legacy `prepareAction().execute()` contract so providers
9230
+ * remain runtime-compatible with adapter versions released before `readAction`.
9231
+ * Consumers must upgrade their adapter package for reads to bypass custom
9232
+ * `prepareAction` wrappers.
9233
+ *
9234
+ * @typeParam TAdapterCapabilities - The adapter capabilities type.
9235
+ * @typeParam TActionKey - The read action key.
9236
+ * @param adapter - The adapter that owns the read action.
9237
+ * @param action - The read action to execute.
9238
+ * @param params - The parameters for the read action.
9239
+ * @param ctx - The operation context.
9240
+ * @returns The raw read-action result.
9241
+ * @throws {KitError} When `action` is not a supported read-action key.
9242
+ *
9243
+ * @example
9244
+ * ```typescript
9245
+ * import { executeAdapterReadAction } from '@core/adapter'
9246
+ * import { Ethereum } from '@core/chains'
9247
+ *
9248
+ * const allowance = await executeAdapterReadAction(
9249
+ * adapter,
9250
+ * 'token.allowance',
9251
+ * { tokenAddress, delegate },
9252
+ * { chain: Ethereum },
9253
+ * )
9254
+ * ```
9255
+ *
9256
+ * @internal
9257
+ */ async function executeAdapterReadAction(adapter, action, params, ctx) {
9258
+ if (!isReadActionKey(action)) {
9259
+ throw createUnsupportedReadActionError(action);
9260
+ }
9261
+ const runtimeAdapter = adapter;
9262
+ if (typeof runtimeAdapter.readAction === 'function') {
9263
+ return runtimeAdapter.readAction(action, params, ctx);
9264
+ }
9265
+ let request;
9266
+ try {
9267
+ request = await adapter.prepareAction(action, params, ctx);
9268
+ } catch (error) {
9269
+ if (error instanceof Error && error.message === `Action ${action} is not supported`) {
9270
+ throw createUnsupportedReadActionError(action);
9271
+ }
9272
+ throw error;
9273
+ }
9274
+ return request.execute();
9275
+ }
9276
+
9167
9277
  /**
9168
9278
  * Schema for validating hexadecimal strings with '0x' prefix.
9169
9279
  *
@@ -9373,16 +9483,15 @@ var pkg = {
9373
9483
  * ```
9374
9484
  */ const validateBalanceForTransaction = async (params)=>{
9375
9485
  const { amount, adapter, token, tokenAddress, operationContext } = params;
9376
- const balancePrepared = await adapter.prepareAction('usdc.balanceOf', {
9486
+ const balance = await executeAdapterReadAction(adapter, 'usdc.balanceOf', {
9377
9487
  walletAddress: operationContext.address
9378
9488
  }, operationContext);
9379
- const balance = await balancePrepared.execute();
9380
- if (BigInt(balance) < BigInt(amount)) {
9489
+ if (BigInt(String(balance)) < BigInt(amount)) {
9381
9490
  // Extract chain name from operationContext
9382
9491
  const chainName = extractChainInfo(operationContext.chain).name;
9383
9492
  // Create KitError with rich context in trace
9384
9493
  throw createInsufficientTokenBalanceError(chainName, token, {
9385
- balance: balance.toString(),
9494
+ balance: String(balance),
9386
9495
  amount,
9387
9496
  tokenAddress,
9388
9497
  walletAddress: operationContext.address
@@ -18376,8 +18485,7 @@ function assertNotSelfDelegation(chain, signerAddress, delegateAddress, action)
18376
18485
  chain
18377
18486
  };
18378
18487
  // Step 1: Quick check at latest block (no HTTP call)
18379
- const latestRequest = await adapter.prepareAction('gateway.v1.isDelegate', baseActionParams, operationContext);
18380
- const latestResult = await latestRequest.execute();
18488
+ const latestResult = await executeAdapterReadAction(adapter, 'gateway.v1.isDelegate', baseActionParams, operationContext);
18381
18489
  if (String(latestResult).toLowerCase() !== 'true') {
18382
18490
  return 'none';
18383
18491
  }
@@ -18386,13 +18494,12 @@ function assertNotSelfDelegation(chain, signerAddress, delegateAddress, action)
18386
18494
  // Solana uses confirmed vs finalized commitment as a proxy for
18387
18495
  // Gateway finality. This is conservative — can only over-report
18388
18496
  // 'pending', never falsely report 'ready'.
18389
- const finalizedRequest = await adapter.prepareAction('gateway.v1.isDelegate', {
18390
- ...baseActionParams,
18391
- commitment: 'finalized'
18392
- }, operationContext);
18393
18497
  let finalizedResult;
18394
18498
  try {
18395
- finalizedResult = await finalizedRequest.execute();
18499
+ finalizedResult = await executeAdapterReadAction(adapter, 'gateway.v1.isDelegate', {
18500
+ ...baseActionParams,
18501
+ commitment: 'finalized'
18502
+ }, operationContext);
18396
18503
  } catch (error) {
18397
18504
  if (isBlockRangeError(error)) {
18398
18505
  return 'pending';
@@ -18403,10 +18510,6 @@ function assertNotSelfDelegation(chain, signerAddress, delegateAddress, action)
18403
18510
  }
18404
18511
  // EVM: use processedHeight from /v1/info
18405
18512
  const processedHeight = await getProcessedHeight(chain.isTestnet, chain.gateway.domain);
18406
- const finalizedRequest = await adapter.prepareAction('gateway.v1.isDelegate', {
18407
- ...baseActionParams,
18408
- blockNumber: processedHeight
18409
- }, operationContext);
18410
18513
  // If the RPC node lags Gateway's indexer view, the historical read at
18411
18514
  // processedHeight may throw a block-range error. This is safe to treat
18412
18515
  // as 'pending' because processedHeight comes from Gateway's /v1/info
@@ -18415,7 +18518,10 @@ function assertNotSelfDelegation(chain, signerAddress, delegateAddress, action)
18415
18518
  // Re-throw structural errors to avoid masking real bugs.
18416
18519
  let finalizedResult;
18417
18520
  try {
18418
- finalizedResult = await finalizedRequest.execute();
18521
+ finalizedResult = await executeAdapterReadAction(adapter, 'gateway.v1.isDelegate', {
18522
+ ...baseActionParams,
18523
+ blockNumber: processedHeight
18524
+ }, operationContext);
18419
18525
  } catch (error) {
18420
18526
  if (isBlockRangeError(error)) {
18421
18527
  return 'pending';
@@ -18476,8 +18582,8 @@ function parseAmountSafe(amount) {
18476
18582
  chain
18477
18583
  };
18478
18584
  const [withdrawingRaw, withdrawalBlockRaw] = await Promise.all([
18479
- adapter.prepareAction('gateway.v1.withdrawingBalance', readParams, operationContext).then(async (req)=>req.execute()),
18480
- adapter.prepareAction('gateway.v1.withdrawalBlock', readParams, operationContext).then(async (req)=>req.execute())
18585
+ executeAdapterReadAction(adapter, 'gateway.v1.withdrawingBalance', readParams, operationContext),
18586
+ executeAdapterReadAction(adapter, 'gateway.v1.withdrawalBlock', readParams, operationContext)
18481
18587
  ]);
18482
18588
  const withdrawingValue = safeBigInt(String(withdrawingRaw), 'withdrawingBalance');
18483
18589
  const withdrawalBlockValue = safeBigInt(String(withdrawalBlockRaw), 'withdrawalBlock');
@@ -18517,12 +18623,11 @@ function parseAmountSafe(amount) {
18517
18623
  const tokenAddress = getTokenAddress(chain, params.token);
18518
18624
  // Read the pending balance before withdrawing — the contract resets it to 0
18519
18625
  // after withdraw() executes, so this is the only way to capture the amount.
18520
- const withdrawingBalanceReq = await adapter.prepareAction('gateway.v1.withdrawingBalance', {
18626
+ const withdrawingRaw = await executeAdapterReadAction(adapter, 'gateway.v1.withdrawingBalance', {
18521
18627
  token: tokenAddress,
18522
18628
  depositor: signerAddress,
18523
18629
  chain
18524
18630
  }, operationContext);
18525
- const withdrawingRaw = await withdrawingBalanceReq.execute();
18526
18631
  const withdrawingValue = safeBigInt(String(withdrawingRaw), 'withdrawingBalance');
18527
18632
  if (withdrawingValue === 0n) {
18528
18633
  throw new KitError({