@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.
package/estimateSwap.mjs CHANGED
@@ -8755,6 +8755,7 @@ const swapTokenEnumSchema = z.enum([
8755
8755
  [Blockchain.Arbitrum_Sepolia]: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
8756
8756
  [Blockchain.Avalanche_Fuji]: '0x5425890298aed601595a70AB815c96711a31Bc65',
8757
8757
  [Blockchain.Base_Sepolia]: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
8758
+ [Blockchain.Celo_Alfajores_Testnet]: '0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B',
8758
8759
  [Blockchain.Codex_Testnet]: '0x6d7f141b6819C2c9CC2f818e6ad549E7Ca090F8f',
8759
8760
  [Blockchain.Cronos_Testnet]: '0xEb33dc5fac03833e132593659e1dE7256aB59794',
8760
8761
  [Blockchain.Edge_Testnet]: '0x2d9F7CAD728051AA35Ecdc472a14cf8cDF5CFD6B',
@@ -10122,6 +10123,44 @@ var pkg$2 = {
10122
10123
  }
10123
10124
  });
10124
10125
 
10126
+ /**
10127
+ * Canonical list of actions that do not prepare or submit transactions.
10128
+ *
10129
+ * @internal
10130
+ */ const READ_ACTION_KEYS = [
10131
+ 'token.allowance',
10132
+ 'token.balanceOf',
10133
+ 'token.name',
10134
+ 'native.balanceOf',
10135
+ 'usdc.allowance',
10136
+ 'usdc.balanceOf',
10137
+ 'usdc.name',
10138
+ 'gateway.v1.isDelegate',
10139
+ 'gateway.v1.withdrawingBalance',
10140
+ 'gateway.v1.withdrawalBlock',
10141
+ 'gateway.v1.signBurnIntents'
10142
+ ];
10143
+ const READ_ACTION_KEY_SET = new Set(READ_ACTION_KEYS);
10144
+ /**
10145
+ * Check whether a runtime value identifies a read action.
10146
+ *
10147
+ * @param action - The value to classify.
10148
+ * @returns Whether the value is a registered read-action key.
10149
+ *
10150
+ * @example
10151
+ * ```typescript
10152
+ * import { isReadActionKey } from '@core/adapter'
10153
+ *
10154
+ * if (isReadActionKey(value)) {
10155
+ * await adapter.readAction(value, params, context)
10156
+ * }
10157
+ * ```
10158
+ *
10159
+ * @internal
10160
+ */ function isReadActionKey(action) {
10161
+ return typeof action === 'string' && READ_ACTION_KEY_SET.has(action);
10162
+ }
10163
+
10125
10164
  /**
10126
10165
  * Resolves an operation context into concrete chain and address values.
10127
10166
  *
@@ -10201,6 +10240,141 @@ var pkg$2 = {
10201
10240
  };
10202
10241
  }
10203
10242
 
10243
+ /**
10244
+ * Create the standard error for a missing or non-read action.
10245
+ *
10246
+ * @param action - The unsupported action value.
10247
+ * @returns A fatal unsupported-action error.
10248
+ *
10249
+ * @internal
10250
+ */ function createUnsupportedReadActionError(action) {
10251
+ return new KitError({
10252
+ ...InputError.UNSUPPORTED_ACTION,
10253
+ recoverability: 'FATAL',
10254
+ message: `Read action "${String(action)}" is not registered in this adapter.`
10255
+ });
10256
+ }
10257
+ /**
10258
+ * Execute a read through the adapter's dedicated read seam when available.
10259
+ *
10260
+ * @remarks
10261
+ * Fall back to the legacy `prepareAction().execute()` contract so providers
10262
+ * remain runtime-compatible with adapter versions released before `readAction`.
10263
+ * Consumers must upgrade their adapter package for reads to bypass custom
10264
+ * `prepareAction` wrappers.
10265
+ *
10266
+ * @typeParam TAdapterCapabilities - The adapter capabilities type.
10267
+ * @typeParam TActionKey - The read action key.
10268
+ * @param adapter - The adapter that owns the read action.
10269
+ * @param action - The read action to execute.
10270
+ * @param params - The parameters for the read action.
10271
+ * @param ctx - The operation context.
10272
+ * @returns The raw read-action result.
10273
+ * @throws {KitError} When `action` is not a supported read-action key.
10274
+ *
10275
+ * @example
10276
+ * ```typescript
10277
+ * import { executeAdapterReadAction } from '@core/adapter'
10278
+ * import { Ethereum } from '@core/chains'
10279
+ *
10280
+ * const allowance = await executeAdapterReadAction(
10281
+ * adapter,
10282
+ * 'token.allowance',
10283
+ * { tokenAddress, delegate },
10284
+ * { chain: Ethereum },
10285
+ * )
10286
+ * ```
10287
+ *
10288
+ * @internal
10289
+ */ async function executeAdapterReadAction(adapter, action, params, ctx) {
10290
+ if (!isReadActionKey(action)) {
10291
+ throw createUnsupportedReadActionError(action);
10292
+ }
10293
+ const runtimeAdapter = adapter;
10294
+ if (typeof runtimeAdapter.readAction === 'function') {
10295
+ return runtimeAdapter.readAction(action, params, ctx);
10296
+ }
10297
+ let request;
10298
+ try {
10299
+ request = await adapter.prepareAction(action, params, ctx);
10300
+ } catch (error) {
10301
+ if (error instanceof Error && error.message === `Action ${action} is not supported`) {
10302
+ throw createUnsupportedReadActionError(action);
10303
+ }
10304
+ throw error;
10305
+ }
10306
+ return request.execute();
10307
+ }
10308
+ /**
10309
+ * Read and parse a token allowance while supporting older adapter versions.
10310
+ *
10311
+ * @remarks
10312
+ * Prefer the adapter's dedicated read seam and fall back to the legacy
10313
+ * `prepareAction().execute()` contract when the runtime adapter predates it.
10314
+ *
10315
+ * @typeParam TAdapterCapabilities - The adapter capabilities type.
10316
+ * @param adapter - The adapter that owns the allowance action.
10317
+ * @param params - The token and delegate whose allowance is being read.
10318
+ * @param ctx - The operation context.
10319
+ * @returns The non-negative allowance in token base units.
10320
+ * @throws {KitError} When the action is unsupported or its response is malformed.
10321
+ *
10322
+ * @example
10323
+ * ```typescript
10324
+ * import { readTokenAllowance } from '@core/adapter'
10325
+ * import { Ethereum } from '@core/chains'
10326
+ *
10327
+ * const allowance = await readTokenAllowance(
10328
+ * adapter,
10329
+ * { tokenAddress, delegate },
10330
+ * { chain: Ethereum },
10331
+ * )
10332
+ * ```
10333
+ *
10334
+ * @internal
10335
+ */ async function readTokenAllowance(adapter, params, ctx) {
10336
+ return parseAllowanceResponse(await executeAdapterReadAction(adapter, 'token.allowance', params, ctx));
10337
+ }
10338
+ /**
10339
+ * Parse a raw token allowance response into base units.
10340
+ *
10341
+ * @param allowanceRaw - The adapter response, optionally wrapped as an Amount output.
10342
+ * @returns The non-negative allowance as a bigint, or zero for a missing value.
10343
+ * @throws {KitError} When the response cannot represent a non-negative bigint.
10344
+ *
10345
+ * @example
10346
+ * ```typescript
10347
+ * import { parseAllowanceResponse } from '@core/adapter'
10348
+ *
10349
+ * const allowance = parseAllowanceResponse({ amount: { raw: 1000000n } })
10350
+ * ```
10351
+ */ function parseAllowanceResponse(allowanceRaw) {
10352
+ let value = allowanceRaw;
10353
+ if (typeof value === 'object' && value !== null && 'amount' in value) {
10354
+ const amount = value.amount;
10355
+ if (typeof amount === 'object' && amount !== null && 'raw' in amount) {
10356
+ value = amount.raw;
10357
+ }
10358
+ }
10359
+ if (value === undefined || value === null) {
10360
+ return 0n;
10361
+ }
10362
+ let allowance;
10363
+ if (typeof value === 'bigint') {
10364
+ allowance = value;
10365
+ } else if (typeof value === 'string') {
10366
+ try {
10367
+ allowance = BigInt(value);
10368
+ } catch {
10369
+ allowance = undefined;
10370
+ }
10371
+ }
10372
+ if (allowance === undefined || allowance < 0n) {
10373
+ throw createValidationFailedError$1('token.allowance', value, 'token.allowance response must be a non-negative bigint-compatible string or bigint');
10374
+ }
10375
+ return allowance;
10376
+ }
10377
+
10204
10378
  /**
10205
10379
  * Schema for validating hexadecimal strings with '0x' prefix.
10206
10380
  *
@@ -10978,7 +11152,7 @@ var TransferSpeed;
10978
11152
  registerKit(`${pkg$2.name}/${pkg$2.version}`);
10979
11153
 
10980
11154
  var name$1 = "@circle-fin/swap-kit";
10981
- var version$1 = "1.5.1";
11155
+ var version$1 = "1.5.2";
10982
11156
  var pkg$1 = {
10983
11157
  name: name$1,
10984
11158
  version: version$1};
@@ -15298,14 +15472,13 @@ const TOKEN_REGISTRY$2 = createTokenRegistry();
15298
15472
  return;
15299
15473
  }
15300
15474
  // For non-native tokens (SPL tokens, ERC-20 tokens), check the token balance
15301
- const balancePrepared = await adapter.prepareAction('token.balanceOf', {
15475
+ const balance = await executeAdapterReadAction(adapter, 'token.balanceOf', {
15302
15476
  tokenAddress: tokenInAddress,
15303
15477
  walletAddress
15304
15478
  }, context);
15305
- const balance = await balancePrepared.execute();
15306
15479
  // Compare balances
15307
15480
  const requiredAmount = BigInt(amount);
15308
- const currentBalance = BigInt(balance);
15481
+ const currentBalance = BigInt(String(balance));
15309
15482
  if (currentBalance < requiredAmount) {
15310
15483
  throw new KitError({
15311
15484
  ...BalanceError.INSUFFICIENT_TOKEN,
@@ -16466,11 +16639,10 @@ async function fetchSameChainStatusSnapshot({ isCrossChainSwap, txHash, chain, a
16466
16639
  * @throws Error if the adapter fails to prepare or execute approval transactions
16467
16640
  * @throws Error if transaction confirmation fails or times out
16468
16641
  */ async handleUsdtApproval(adapter, chain, executionCtx, adapterContractAddress, resolvedContext, executedTransactions) {
16469
- const allowanceRequest = await adapter.prepareAction('token.allowance', {
16642
+ const current = await readTokenAllowance(adapter, {
16470
16643
  tokenAddress: executionCtx.tokenInAddress,
16471
16644
  delegate: adapterContractAddress
16472
16645
  }, resolvedContext);
16473
- const current = BigInt(await allowanceRequest.execute());
16474
16646
  const required = BigInt(executionCtx.amount);
16475
16647
  if (current >= required) {
16476
16648
  // Sufficient allowance - proceed to swap
@@ -21244,7 +21416,7 @@ registerKit(`${pkg$1.name}/${pkg$1.version}`);
21244
21416
  };
21245
21417
 
21246
21418
  var name = "@circle-fin/earn-kit";
21247
- var version = "1.5.0";
21419
+ var version = "1.5.1";
21248
21420
  var pkg = {
21249
21421
  name: name,
21250
21422
  version: version};