@circle-fin/adapter-ethers-v6 1.8.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @circle-fin/adapter-ethers-v6
2
2
 
3
+ ## 1.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Enable Earn deposit, withdrawal, and claim rewards execution when paired with `@circle-fin/earn-kit`.
8
+
3
9
  ## 1.8.0
4
10
 
5
11
  ### Minor Changes
package/index.cjs CHANGED
@@ -408,6 +408,12 @@ const InputError = {
408
408
  name: 'INPUT_INVALID_AMOUNT',
409
409
  type: 'INPUT',
410
410
  },
411
+ /** Unsupported or invalid bridge route configuration */
412
+ UNSUPPORTED_ROUTE: {
413
+ code: 1003,
414
+ name: 'INPUT_UNSUPPORTED_ROUTE',
415
+ type: 'INPUT',
416
+ },
411
417
  /** Invalid or unsupported chain identifier */
412
418
  INVALID_CHAIN: {
413
419
  code: 1005,
@@ -564,6 +570,35 @@ const NetworkError = {
564
570
  type: 'NETWORK',
565
571
  }};
566
572
 
573
+ /**
574
+ * Creates error for unsupported earn route.
575
+ *
576
+ * This error is thrown when no available earn provider supports the requested
577
+ * operation on the specified chain.
578
+ *
579
+ * @param operation - Earn operation name
580
+ * @param chain - Chain name where the earn operation was attempted
581
+ * @returns KitError with specific earn route details
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * import { createUnsupportedEarnRouteError } from '@core/errors'
586
+ *
587
+ * throw createUnsupportedEarnRouteError('deposit', 'Ethereum')
588
+ * // Message: "Earn deposit on Ethereum is not supported by any available provider."
589
+ * ```
590
+ */
591
+ function createUnsupportedEarnRouteError(operation, chain) {
592
+ const errorDetails = {
593
+ ...InputError.UNSUPPORTED_ROUTE,
594
+ recoverability: 'FATAL',
595
+ message: `Earn ${operation} on ${chain} is not supported by any available provider.`,
596
+ cause: {
597
+ trace: { operation, chain },
598
+ },
599
+ };
600
+ return new KitError(errorDetails);
601
+ }
567
602
  /**
568
603
  * Creates error for unsupported token on chain.
569
604
  *
@@ -2052,23 +2087,21 @@ var UnifiedBalanceChain;
2052
2087
  * Enumeration of blockchains that support earn (vault deposit/withdraw)
2053
2088
  * operations through the Earn Kit.
2054
2089
  *
2055
- * Currently only Ethereum mainnet is supported. Additional chains
2056
- * will be added as vault protocol support expands.
2057
- *
2058
2090
  * @example
2059
2091
  * ```typescript
2060
2092
  * import { EarnChain } from '@core/chains'
2061
2093
  *
2062
2094
  * const result = await earnKit.deposit({
2063
- * from: { adapter, chain: EarnChain.Ethereum },
2095
+ * from: { adapter, chain: EarnChain.Arc_Testnet },
2064
2096
  * vaultAddress: '0x...',
2065
2097
  * amount: '100',
2066
2098
  * })
2067
2099
  * ```
2068
2100
  */
2101
+ // Values must match Blockchain enum members exactly.
2069
2102
  var EarnChain;
2070
2103
  (function (EarnChain) {
2071
- EarnChain["Ethereum"] = "Ethereum";
2104
+ EarnChain["Arc_Testnet"] = "Arc_Testnet";
2072
2105
  })(EarnChain || (EarnChain = {}));
2073
2106
 
2074
2107
  /**
@@ -5762,7 +5795,7 @@ zod.z.union([
5762
5795
  * Zod schema for validating earn-specific chain identifiers.
5763
5796
  *
5764
5797
  * Validate that the provided chain is supported for earn (vault
5765
- * deposit/withdraw) operations. Currently only Ethereum is
5798
+ * deposit/withdraw) operations. Currently only Arc Testnet is
5766
5799
  * supported.
5767
5800
  *
5768
5801
  * Accept an EarnChain enum value, a matching string literal, or
@@ -5771,12 +5804,12 @@ zod.z.union([
5771
5804
  * @example
5772
5805
  * ```typescript
5773
5806
  * import { earnChainIdentifierSchema } from '@core/chains'
5774
- * import { EarnChain, Ethereum } from '@core/chains'
5807
+ * import { ArcTestnet, EarnChain } from '@core/chains'
5775
5808
  *
5776
5809
  * // Valid
5777
- * earnChainIdentifierSchema.parse(EarnChain.Ethereum)
5778
- * earnChainIdentifierSchema.parse('Ethereum')
5779
- * earnChainIdentifierSchema.parse(Ethereum)
5810
+ * earnChainIdentifierSchema.parse(EarnChain.Arc_Testnet)
5811
+ * earnChainIdentifierSchema.parse('Arc_Testnet')
5812
+ * earnChainIdentifierSchema.parse(ArcTestnet)
5780
5813
  *
5781
5814
  * // Invalid (throws ZodError)
5782
5815
  * earnChainIdentifierSchema.parse('Solana')
@@ -7389,7 +7422,9 @@ const hexStringSchema = zod.z
7389
7422
  * console.log(result.success) // true
7390
7423
  * ```
7391
7424
  */
7392
- const evmAddressSchema = hexStringSchema.refine((value) => value.length === 42, 'EVM address must be exactly 42 characters long (0x + 40 hex characters)');
7425
+ const evmAddressSchema = hexStringSchema
7426
+ .refine((value) => value.length === 42, 'EVM address must be exactly 42 characters long (0x + 40 hex characters)')
7427
+ .transform((value) => value);
7393
7428
  /**
7394
7429
  * Schema for validating transaction hashes.
7395
7430
  *
@@ -7410,6 +7445,29 @@ const evmAddressSchema = hexStringSchema.refine((value) => value.length === 42,
7410
7445
  * ```
7411
7446
  */
7412
7447
  hexStringSchema.refine((value) => value.length === 66, 'Transaction hash must be exactly 66 characters long (0x + 64 hex characters)');
7448
+ /**
7449
+ * Schema for validating EVM signatures.
7450
+ *
7451
+ * This schema validates that a string is a properly formatted 65-byte EVM
7452
+ * signature:
7453
+ * - Must be a valid hex string with '0x' prefix
7454
+ * - Must be exactly 132 characters long (0x + 130 hex characters)
7455
+ *
7456
+ * @throws {KitError} If validation fails with INPUT_VALIDATION_FAILED code (1098), with details about which properties failed
7457
+ *
7458
+ * @example
7459
+ * ```typescript
7460
+ * import { evmSignatureSchema } from '@core/adapter'
7461
+ *
7462
+ * const validSignature = `0x${'ab'.repeat(65)}`
7463
+ *
7464
+ * const result = evmSignatureSchema.safeParse(validSignature)
7465
+ * console.log(result.success) // true
7466
+ * ```
7467
+ */
7468
+ const evmSignatureSchema = hexStringSchema
7469
+ .refine((value) => value.length === 132, 'EVM signature must be exactly 132 characters long (0x + 130 hex characters)')
7470
+ .transform((value) => value);
7413
7471
  /**
7414
7472
  * Schema for validating base58-encoded strings.
7415
7473
  *
@@ -7644,6 +7702,79 @@ function getSupportedChains(ecosystem) {
7644
7702
  }
7645
7703
  }
7646
7704
 
7705
+ /**
7706
+ * IAdapter contract ABI.
7707
+ *
7708
+ * Shared ABI for the on-chain Adapter contract used by multiple kits
7709
+ * (swap, earn) for executing signed instruction sets. The `execute()`
7710
+ * function accepts EIP-712 signed execution parameters, token inputs,
7711
+ * and a signature, then executes the corresponding on-chain
7712
+ * instructions.
7713
+ */
7714
+ const adapterContractAbi = [
7715
+ {
7716
+ type: 'function',
7717
+ name: 'execute',
7718
+ inputs: [
7719
+ {
7720
+ name: 'params',
7721
+ type: 'tuple',
7722
+ internalType: 'struct IAdapter.ExecutionParams',
7723
+ components: [
7724
+ {
7725
+ name: 'instructions',
7726
+ type: 'tuple[]',
7727
+ internalType: 'struct IAdapter.Instruction[]',
7728
+ components: [
7729
+ { name: 'target', type: 'address', internalType: 'address' },
7730
+ { name: 'data', type: 'bytes', internalType: 'bytes' },
7731
+ { name: 'value', type: 'uint256', internalType: 'uint256' },
7732
+ { name: 'tokenIn', type: 'address', internalType: 'address' },
7733
+ {
7734
+ name: 'amountToApprove',
7735
+ type: 'uint256',
7736
+ internalType: 'uint256',
7737
+ },
7738
+ { name: 'tokenOut', type: 'address', internalType: 'address' },
7739
+ { name: 'minTokenOut', type: 'uint256', internalType: 'uint256' },
7740
+ ],
7741
+ },
7742
+ {
7743
+ name: 'tokens',
7744
+ type: 'tuple[]',
7745
+ internalType: 'struct IAdapter.TokenRecipient[]',
7746
+ components: [
7747
+ { name: 'token', type: 'address', internalType: 'address' },
7748
+ { name: 'beneficiary', type: 'address', internalType: 'address' },
7749
+ ],
7750
+ },
7751
+ { name: 'execId', type: 'uint256', internalType: 'uint256' },
7752
+ { name: 'deadline', type: 'uint256', internalType: 'uint256' },
7753
+ { name: 'metadata', type: 'bytes', internalType: 'bytes' },
7754
+ ],
7755
+ },
7756
+ {
7757
+ name: 'tokenInputs',
7758
+ type: 'tuple[]',
7759
+ internalType: 'struct IAdapter.TokenInput[]',
7760
+ components: [
7761
+ {
7762
+ name: 'permitType',
7763
+ type: 'uint8',
7764
+ internalType: 'enum IAdapter.PermitType',
7765
+ },
7766
+ { name: 'token', type: 'address', internalType: 'address' },
7767
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
7768
+ { name: 'permitCalldata', type: 'bytes', internalType: 'bytes' },
7769
+ ],
7770
+ },
7771
+ { name: 'signature', type: 'bytes', internalType: 'bytes' },
7772
+ ],
7773
+ outputs: [],
7774
+ stateMutability: 'payable',
7775
+ },
7776
+ ];
7777
+
7647
7778
  /**
7648
7779
  * ERC20 ABI
7649
7780
  *
@@ -11009,78 +11140,6 @@ const bridgeContractAbi = [
11009
11140
  },
11010
11141
  ];
11011
11142
 
11012
- /**
11013
- * Adapter Contract ABI
11014
- *
11015
- * This ABI is used to interact with the Adapter smart contract that handles
11016
- * gasless token approvals via permits and atomic swap execution.
11017
- *
11018
- * The execute() function is the primary entry point for swap operations.
11019
- */
11020
- const adapterContractAbi = [
11021
- {
11022
- type: 'function',
11023
- name: 'execute',
11024
- inputs: [
11025
- {
11026
- name: 'params',
11027
- type: 'tuple',
11028
- internalType: 'struct IAdapter.ExecutionParams',
11029
- components: [
11030
- {
11031
- name: 'instructions',
11032
- type: 'tuple[]',
11033
- internalType: 'struct IAdapter.Instruction[]',
11034
- components: [
11035
- { name: 'target', type: 'address', internalType: 'address' },
11036
- { name: 'data', type: 'bytes', internalType: 'bytes' },
11037
- { name: 'value', type: 'uint256', internalType: 'uint256' },
11038
- { name: 'tokenIn', type: 'address', internalType: 'address' },
11039
- {
11040
- name: 'amountToApprove',
11041
- type: 'uint256',
11042
- internalType: 'uint256',
11043
- },
11044
- { name: 'tokenOut', type: 'address', internalType: 'address' },
11045
- { name: 'minTokenOut', type: 'uint256', internalType: 'uint256' },
11046
- ],
11047
- },
11048
- {
11049
- name: 'tokens',
11050
- type: 'tuple[]',
11051
- internalType: 'struct IAdapter.TokenRecipient[]',
11052
- components: [
11053
- { name: 'token', type: 'address', internalType: 'address' },
11054
- { name: 'beneficiary', type: 'address', internalType: 'address' },
11055
- ],
11056
- },
11057
- { name: 'execId', type: 'uint256', internalType: 'uint256' },
11058
- { name: 'deadline', type: 'uint256', internalType: 'uint256' },
11059
- { name: 'metadata', type: 'bytes', internalType: 'bytes' },
11060
- ],
11061
- },
11062
- {
11063
- name: 'tokenInputs',
11064
- type: 'tuple[]',
11065
- internalType: 'struct IAdapter.TokenInput[]',
11066
- components: [
11067
- {
11068
- name: 'permitType',
11069
- type: 'uint8',
11070
- internalType: 'enum IAdapter.PermitType',
11071
- },
11072
- { name: 'token', type: 'address', internalType: 'address' },
11073
- { name: 'amount', type: 'uint256', internalType: 'uint256' },
11074
- { name: 'permitCalldata', type: 'bytes', internalType: 'bytes' },
11075
- ],
11076
- },
11077
- { name: 'signature', type: 'bytes', internalType: 'bytes' },
11078
- ],
11079
- outputs: [],
11080
- stateMutability: 'payable',
11081
- },
11082
- ];
11083
-
11084
11143
  /**
11085
11144
  * ABI for the Circle Gateway Wallet contract.
11086
11145
  *
@@ -15502,6 +15561,107 @@ const balanceOf$2 = async (params, adapter, context) => {
15502
15561
  };
15503
15562
  };
15504
15563
 
15564
+ const hexBytesSchema = zod.z
15565
+ .string()
15566
+ .regex(/^0x([0-9a-fA-F]{2})*$/, {
15567
+ message: 'value must be a 0x-prefixed even-length hex string',
15568
+ })
15569
+ .transform((value) => value);
15570
+ const earnExecuteParamsSchema = zod.z
15571
+ .object({
15572
+ executeParams: zod.z.object({}).passthrough(),
15573
+ signature: evmSignatureSchema,
15574
+ tokenInputs: zod.z.array(zod.z.object({
15575
+ permitType: zod.z.nativeEnum(PermitType),
15576
+ token: evmAddressSchema,
15577
+ amount: zod.z.bigint().refine((value) => value >= 0n, {
15578
+ message: 'amount must be a non-negative bigint',
15579
+ }),
15580
+ permitCalldata: hexBytesSchema,
15581
+ })),
15582
+ })
15583
+ .passthrough();
15584
+ function validateAdapterContractAddress(chainName, value) {
15585
+ const result = evmAddressSchema.safeParse(value);
15586
+ if (!result.success) {
15587
+ throw createValidationFailedError('chain.kitContracts.adapter', value, `Adapter contract for chain ${chainName} must be a 0x-prefixed 20-byte hex address.`);
15588
+ }
15589
+ return result.data;
15590
+ }
15591
+ function validateEarnExecuteParams(params) {
15592
+ const result = earnExecuteParamsSchema.safeParse(params);
15593
+ if (!result.success) {
15594
+ throw createValidationErrorFromZod(result.error, 'earn execute params');
15595
+ }
15596
+ return {
15597
+ executeParams: result.data.executeParams,
15598
+ signature: result.data.signature,
15599
+ tokenInputs: result.data.tokenInputs,
15600
+ __isActionParams: true,
15601
+ };
15602
+ }
15603
+ /**
15604
+ * Prepare an earn operation against the adapter contract on EVM chains.
15605
+ *
15606
+ * Forward the service-signed `executeParams` and `signature` to the adapter
15607
+ * contract's `execute` function. Token approvals are handled upstream by the
15608
+ * provider (today via a separate `token.approve` transaction; future: permit
15609
+ * entries in `tokenInputs`). This function performs runtime validation for
15610
+ * plain-JS callers, prepares calldata only, performs no network I/O, and does
15611
+ * not submit the transaction.
15612
+ *
15613
+ * @param params - Service-signed earn payload.
15614
+ * @param adapter - EVM adapter used to prepare the transaction.
15615
+ * @param context - Resolved operation context (chain + address).
15616
+ * @returns Prepared chain request ready to `estimate()` or `execute()`.
15617
+ * @throws {@link KitError} If the chain is not EVM-compatible.
15618
+ * @throws {@link KitError} If the chain has no adapter contract configured.
15619
+ * @throws {@link KitError} If required fields are missing or invalid.
15620
+ *
15621
+ * @example
15622
+ * ```typescript
15623
+ * const prepared = await evmAdapter.prepareAction(
15624
+ * 'earn.deposit',
15625
+ * {
15626
+ * executeParams: {
15627
+ * instructions: [],
15628
+ * tokens: [],
15629
+ * execId: 1n,
15630
+ * deadline: 0n,
15631
+ * metadata: '0x',
15632
+ * },
15633
+ * tokenInputs: [],
15634
+ * signature: '0x...',
15635
+ * },
15636
+ * { chain, address },
15637
+ * )
15638
+ * const txHash = await prepared.execute()
15639
+ * ```
15640
+ */
15641
+ const prepareEarnExecute = async (params, adapter, context) => {
15642
+ const { chain } = context;
15643
+ if (chain.type !== 'evm') {
15644
+ throw createInvalidChainError(chain.name, `Expected EVM chain, but received chain type: ${String(chain.type)}`);
15645
+ }
15646
+ const adapterContractAddress = chain.kitContracts?.adapter;
15647
+ if (adapterContractAddress === undefined) {
15648
+ throw createUnsupportedEarnRouteError('execute', chain.name);
15649
+ }
15650
+ const validatedAdapterAddress = validateAdapterContractAddress(chain.name, adapterContractAddress);
15651
+ const validatedParams = validateEarnExecuteParams(params);
15652
+ return adapter.prepare({
15653
+ type: 'evm',
15654
+ abi: adapterContractAbi,
15655
+ address: validatedAdapterAddress,
15656
+ functionName: 'execute',
15657
+ args: [
15658
+ validatedParams.executeParams,
15659
+ validatedParams.tokenInputs,
15660
+ validatedParams.signature,
15661
+ ],
15662
+ }, context);
15663
+ };
15664
+
15505
15665
  /**
15506
15666
  * Type guard to check if params is ExecuteSwapEVMParams.
15507
15667
  *
@@ -16351,6 +16511,36 @@ const getHandlers = (adapter) => {
16351
16511
  'swap.execute': async (params, context) => {
16352
16512
  return executeSwap(params, adapter, context);
16353
16513
  },
16514
+ /**
16515
+ * Handler for earn deposit execution on EVM chains.
16516
+ *
16517
+ * Forwards the earn service's signed `executeParams` and `signature` to the
16518
+ * on-chain adapter contract's `execute` function. Token approvals are handled
16519
+ * by the earn provider via separate `token.approve` transactions.
16520
+ */
16521
+ 'earn.deposit': async (params, context) => {
16522
+ return prepareEarnExecute(params, adapter, context);
16523
+ },
16524
+ /**
16525
+ * Handler for earn withdraw execution on EVM chains.
16526
+ *
16527
+ * Forwards the earn service's signed `executeParams` and `signature` to the
16528
+ * on-chain adapter contract's `execute` function. Token approvals are handled
16529
+ * by the earn provider via separate `token.approve` transactions.
16530
+ */
16531
+ 'earn.withdraw': async (params, context) => {
16532
+ return prepareEarnExecute(params, adapter, context);
16533
+ },
16534
+ /**
16535
+ * Handler for earn claim rewards execution on EVM chains.
16536
+ *
16537
+ * Forwards the earn service's signed `executeParams` and `signature` to the
16538
+ * on-chain adapter contract's `execute` function. Claim rewards does not
16539
+ * require approvals because the adapter does not pull user tokens.
16540
+ */
16541
+ 'earn.claimRewards': async (params, context) => {
16542
+ return prepareEarnExecute(params, adapter, context);
16543
+ },
16354
16544
  /**
16355
16545
  * Handler for CCTP v2 custom burn with hook operations on EVM chains.
16356
16546
  *
package/index.d.ts CHANGED
@@ -1812,12 +1812,14 @@ declare enum PermitType {
1812
1812
  * The Adapter Contract uses this to pull tokens from the user's wallet
1813
1813
  * using permit signatures instead of requiring separate approval transactions.
1814
1814
  *
1815
+ * Shared by the `swap.*` and `earn.*` action namespaces because both forward
1816
+ * `tokenInputs` unchanged to the adapter contract's `execute` call.
1817
+ *
1815
1818
  * @example
1816
1819
  * ```typescript
1817
1820
  * const tokenInput: TokenInput = {
1818
1821
  * permitType: PermitType.EIP2612,
1819
1822
  * token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
1820
- * from: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
1821
1823
  * amount: 1000000n, // 1 USDC
1822
1824
  * permitCalldata: '0x...' // Encoded permit(value, deadline, v, r, s)
1823
1825
  * }
@@ -1840,12 +1842,91 @@ interface TokenInput {
1840
1842
  * ABI-encoded permit calldata.
1841
1843
  *
1842
1844
  * For EIP-2612: encode(value, deadline, v, r, s)
1843
- * For Permit2: encode(permit, signature)
1844
1845
  *
1845
1846
  * @example '0x0000000000000000000000000000000000000000000000000000000000989680...'
1846
1847
  */
1847
1848
  permitCalldata: `0x${string}`;
1848
1849
  }
1850
+
1851
+ /**
1852
+ * Parameters for executing a service-signed earn operation via the Adapter
1853
+ * smart contract on EVM chains.
1854
+ *
1855
+ * Shared across earn action keys: `earn.deposit`, `earn.withdraw`, and
1856
+ * `earn.claimRewards`. Each operation forwards the same `executeParams`,
1857
+ * `tokenInputs`, and `signature` triple to the adapter contract's `execute`
1858
+ * function. The service signs `executeParams` off-chain; the contract verifies
1859
+ * the signature on-chain.
1860
+ *
1861
+ * @example
1862
+ * ```typescript
1863
+ * import type { ActionPayload } from '@core/adapter'
1864
+ *
1865
+ * const params: ActionPayload<'earn.deposit'> = {
1866
+ * executeParams: { instructions: [], tokens: [], execId: 1n, deadline: 0n, metadata: '0x' },
1867
+ * tokenInputs: [],
1868
+ * signature: '0x...',
1869
+ * }
1870
+ *
1871
+ * const prepared = await adapter.prepareAction('earn.deposit', params, { chain, address })
1872
+ * const txHash = await prepared.execute()
1873
+ * ```
1874
+ */
1875
+ interface ExecuteEarnEVMParams extends ActionParameters {
1876
+ /**
1877
+ * Execution parameters returned by the earn service.
1878
+ *
1879
+ * Kept as an opaque record so the adapter forwards the service-signed struct
1880
+ * unchanged. The adapter contract ABI decodes it on-chain.
1881
+ */
1882
+ executeParams: Record<string, unknown>;
1883
+ /**
1884
+ * Token inputs with permit signatures for gasless approvals.
1885
+ *
1886
+ * Populated by the earn provider after it decides how token spending is
1887
+ * authorised. Today deposit uses a separate `token.approve` transaction and
1888
+ * passes `PermitType.NONE`; a future permit-enabled path can populate this
1889
+ * field without a breaking change.
1890
+ */
1891
+ tokenInputs: TokenInput[];
1892
+ /**
1893
+ * EIP-712 signature from the earn service proxy.
1894
+ *
1895
+ * The adapter contract verifies this signature on-chain. Passed through
1896
+ * unchanged.
1897
+ */
1898
+ signature: `0x${string}`;
1899
+ }
1900
+ /**
1901
+ * Parameters for earn execute actions across supported ecosystems.
1902
+ *
1903
+ * EVM-only today; becomes a union when a non-EVM adapter implementation
1904
+ * lands. Action handlers narrow via a property-based type guard, same
1905
+ * pattern as {@link ExecuteSwapParams}.
1906
+ */
1907
+ type ExecuteEarnParams = ExecuteEarnEVMParams;
1908
+ /**
1909
+ * Action map for earn operations.
1910
+ *
1911
+ * Each action key forwards the same `(executeParams, tokenInputs, signature)`
1912
+ * triple to the adapter contract. Provider-side orchestration performs any
1913
+ * required token approval; this action only prepares the adapter execute call.
1914
+ */
1915
+ interface EarnActionMap {
1916
+ /**
1917
+ * Execute a service-signed deposit against the adapter contract.
1918
+ */
1919
+ readonly deposit: ExecuteEarnParams;
1920
+ /**
1921
+ * Execute a service-signed withdraw against the adapter contract.
1922
+ */
1923
+ readonly withdraw: ExecuteEarnParams;
1924
+ /**
1925
+ * Execute a service-signed claim rewards against the adapter contract.
1926
+ */
1927
+ readonly claimRewards: ExecuteEarnParams;
1928
+ }
1929
+
1849
1930
  /**
1850
1931
  * Single instruction to execute within the Adapter Contract.
1851
1932
  *
@@ -2027,7 +2108,6 @@ interface ExecuteParams {
2027
2108
  * const tokenInputs: TokenInput[] = [{
2028
2109
  * permitType: PermitType.EIP2612,
2029
2110
  * token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
2030
- * from: userAddress,
2031
2111
  * amount: 1000000n,
2032
2112
  * permitCalldata: '0x...' // Encoded permit signature
2033
2113
  * }]
@@ -2070,7 +2150,6 @@ interface ExecuteSwapEVMParams extends ActionParameters {
2070
2150
  * [{
2071
2151
  * permitType: PermitType.EIP2612,
2072
2152
  * token: '0xUSDC',
2073
- * from: userAddress,
2074
2153
  * amount: 1000000n,
2075
2154
  * permitCalldata: '0x...'
2076
2155
  * }]
@@ -2806,6 +2885,8 @@ interface ActionMap {
2806
2885
  readonly usdt: USDTActionMap;
2807
2886
  /** Swap operations for DEX aggregator integrations. */
2808
2887
  readonly swap: SwapActionMap;
2888
+ /** Earn operations that execute service-signed payloads via the adapter contract. */
2889
+ readonly earn: EarnActionMap;
2809
2890
  }
2810
2891
  /**
2811
2892
  * Determine if a type represents an action parameter object (leaf node).
package/index.mjs CHANGED
@@ -403,6 +403,12 @@ const InputError = {
403
403
  name: 'INPUT_INVALID_AMOUNT',
404
404
  type: 'INPUT',
405
405
  },
406
+ /** Unsupported or invalid bridge route configuration */
407
+ UNSUPPORTED_ROUTE: {
408
+ code: 1003,
409
+ name: 'INPUT_UNSUPPORTED_ROUTE',
410
+ type: 'INPUT',
411
+ },
406
412
  /** Invalid or unsupported chain identifier */
407
413
  INVALID_CHAIN: {
408
414
  code: 1005,
@@ -559,6 +565,35 @@ const NetworkError = {
559
565
  type: 'NETWORK',
560
566
  }};
561
567
 
568
+ /**
569
+ * Creates error for unsupported earn route.
570
+ *
571
+ * This error is thrown when no available earn provider supports the requested
572
+ * operation on the specified chain.
573
+ *
574
+ * @param operation - Earn operation name
575
+ * @param chain - Chain name where the earn operation was attempted
576
+ * @returns KitError with specific earn route details
577
+ *
578
+ * @example
579
+ * ```typescript
580
+ * import { createUnsupportedEarnRouteError } from '@core/errors'
581
+ *
582
+ * throw createUnsupportedEarnRouteError('deposit', 'Ethereum')
583
+ * // Message: "Earn deposit on Ethereum is not supported by any available provider."
584
+ * ```
585
+ */
586
+ function createUnsupportedEarnRouteError(operation, chain) {
587
+ const errorDetails = {
588
+ ...InputError.UNSUPPORTED_ROUTE,
589
+ recoverability: 'FATAL',
590
+ message: `Earn ${operation} on ${chain} is not supported by any available provider.`,
591
+ cause: {
592
+ trace: { operation, chain },
593
+ },
594
+ };
595
+ return new KitError(errorDetails);
596
+ }
562
597
  /**
563
598
  * Creates error for unsupported token on chain.
564
599
  *
@@ -2047,23 +2082,21 @@ var UnifiedBalanceChain;
2047
2082
  * Enumeration of blockchains that support earn (vault deposit/withdraw)
2048
2083
  * operations through the Earn Kit.
2049
2084
  *
2050
- * Currently only Ethereum mainnet is supported. Additional chains
2051
- * will be added as vault protocol support expands.
2052
- *
2053
2085
  * @example
2054
2086
  * ```typescript
2055
2087
  * import { EarnChain } from '@core/chains'
2056
2088
  *
2057
2089
  * const result = await earnKit.deposit({
2058
- * from: { adapter, chain: EarnChain.Ethereum },
2090
+ * from: { adapter, chain: EarnChain.Arc_Testnet },
2059
2091
  * vaultAddress: '0x...',
2060
2092
  * amount: '100',
2061
2093
  * })
2062
2094
  * ```
2063
2095
  */
2096
+ // Values must match Blockchain enum members exactly.
2064
2097
  var EarnChain;
2065
2098
  (function (EarnChain) {
2066
- EarnChain["Ethereum"] = "Ethereum";
2099
+ EarnChain["Arc_Testnet"] = "Arc_Testnet";
2067
2100
  })(EarnChain || (EarnChain = {}));
2068
2101
 
2069
2102
  /**
@@ -5757,7 +5790,7 @@ z.union([
5757
5790
  * Zod schema for validating earn-specific chain identifiers.
5758
5791
  *
5759
5792
  * Validate that the provided chain is supported for earn (vault
5760
- * deposit/withdraw) operations. Currently only Ethereum is
5793
+ * deposit/withdraw) operations. Currently only Arc Testnet is
5761
5794
  * supported.
5762
5795
  *
5763
5796
  * Accept an EarnChain enum value, a matching string literal, or
@@ -5766,12 +5799,12 @@ z.union([
5766
5799
  * @example
5767
5800
  * ```typescript
5768
5801
  * import { earnChainIdentifierSchema } from '@core/chains'
5769
- * import { EarnChain, Ethereum } from '@core/chains'
5802
+ * import { ArcTestnet, EarnChain } from '@core/chains'
5770
5803
  *
5771
5804
  * // Valid
5772
- * earnChainIdentifierSchema.parse(EarnChain.Ethereum)
5773
- * earnChainIdentifierSchema.parse('Ethereum')
5774
- * earnChainIdentifierSchema.parse(Ethereum)
5805
+ * earnChainIdentifierSchema.parse(EarnChain.Arc_Testnet)
5806
+ * earnChainIdentifierSchema.parse('Arc_Testnet')
5807
+ * earnChainIdentifierSchema.parse(ArcTestnet)
5775
5808
  *
5776
5809
  * // Invalid (throws ZodError)
5777
5810
  * earnChainIdentifierSchema.parse('Solana')
@@ -7384,7 +7417,9 @@ const hexStringSchema = z
7384
7417
  * console.log(result.success) // true
7385
7418
  * ```
7386
7419
  */
7387
- const evmAddressSchema = hexStringSchema.refine((value) => value.length === 42, 'EVM address must be exactly 42 characters long (0x + 40 hex characters)');
7420
+ const evmAddressSchema = hexStringSchema
7421
+ .refine((value) => value.length === 42, 'EVM address must be exactly 42 characters long (0x + 40 hex characters)')
7422
+ .transform((value) => value);
7388
7423
  /**
7389
7424
  * Schema for validating transaction hashes.
7390
7425
  *
@@ -7405,6 +7440,29 @@ const evmAddressSchema = hexStringSchema.refine((value) => value.length === 42,
7405
7440
  * ```
7406
7441
  */
7407
7442
  hexStringSchema.refine((value) => value.length === 66, 'Transaction hash must be exactly 66 characters long (0x + 64 hex characters)');
7443
+ /**
7444
+ * Schema for validating EVM signatures.
7445
+ *
7446
+ * This schema validates that a string is a properly formatted 65-byte EVM
7447
+ * signature:
7448
+ * - Must be a valid hex string with '0x' prefix
7449
+ * - Must be exactly 132 characters long (0x + 130 hex characters)
7450
+ *
7451
+ * @throws {KitError} If validation fails with INPUT_VALIDATION_FAILED code (1098), with details about which properties failed
7452
+ *
7453
+ * @example
7454
+ * ```typescript
7455
+ * import { evmSignatureSchema } from '@core/adapter'
7456
+ *
7457
+ * const validSignature = `0x${'ab'.repeat(65)}`
7458
+ *
7459
+ * const result = evmSignatureSchema.safeParse(validSignature)
7460
+ * console.log(result.success) // true
7461
+ * ```
7462
+ */
7463
+ const evmSignatureSchema = hexStringSchema
7464
+ .refine((value) => value.length === 132, 'EVM signature must be exactly 132 characters long (0x + 130 hex characters)')
7465
+ .transform((value) => value);
7408
7466
  /**
7409
7467
  * Schema for validating base58-encoded strings.
7410
7468
  *
@@ -7639,6 +7697,79 @@ function getSupportedChains(ecosystem) {
7639
7697
  }
7640
7698
  }
7641
7699
 
7700
+ /**
7701
+ * IAdapter contract ABI.
7702
+ *
7703
+ * Shared ABI for the on-chain Adapter contract used by multiple kits
7704
+ * (swap, earn) for executing signed instruction sets. The `execute()`
7705
+ * function accepts EIP-712 signed execution parameters, token inputs,
7706
+ * and a signature, then executes the corresponding on-chain
7707
+ * instructions.
7708
+ */
7709
+ const adapterContractAbi = [
7710
+ {
7711
+ type: 'function',
7712
+ name: 'execute',
7713
+ inputs: [
7714
+ {
7715
+ name: 'params',
7716
+ type: 'tuple',
7717
+ internalType: 'struct IAdapter.ExecutionParams',
7718
+ components: [
7719
+ {
7720
+ name: 'instructions',
7721
+ type: 'tuple[]',
7722
+ internalType: 'struct IAdapter.Instruction[]',
7723
+ components: [
7724
+ { name: 'target', type: 'address', internalType: 'address' },
7725
+ { name: 'data', type: 'bytes', internalType: 'bytes' },
7726
+ { name: 'value', type: 'uint256', internalType: 'uint256' },
7727
+ { name: 'tokenIn', type: 'address', internalType: 'address' },
7728
+ {
7729
+ name: 'amountToApprove',
7730
+ type: 'uint256',
7731
+ internalType: 'uint256',
7732
+ },
7733
+ { name: 'tokenOut', type: 'address', internalType: 'address' },
7734
+ { name: 'minTokenOut', type: 'uint256', internalType: 'uint256' },
7735
+ ],
7736
+ },
7737
+ {
7738
+ name: 'tokens',
7739
+ type: 'tuple[]',
7740
+ internalType: 'struct IAdapter.TokenRecipient[]',
7741
+ components: [
7742
+ { name: 'token', type: 'address', internalType: 'address' },
7743
+ { name: 'beneficiary', type: 'address', internalType: 'address' },
7744
+ ],
7745
+ },
7746
+ { name: 'execId', type: 'uint256', internalType: 'uint256' },
7747
+ { name: 'deadline', type: 'uint256', internalType: 'uint256' },
7748
+ { name: 'metadata', type: 'bytes', internalType: 'bytes' },
7749
+ ],
7750
+ },
7751
+ {
7752
+ name: 'tokenInputs',
7753
+ type: 'tuple[]',
7754
+ internalType: 'struct IAdapter.TokenInput[]',
7755
+ components: [
7756
+ {
7757
+ name: 'permitType',
7758
+ type: 'uint8',
7759
+ internalType: 'enum IAdapter.PermitType',
7760
+ },
7761
+ { name: 'token', type: 'address', internalType: 'address' },
7762
+ { name: 'amount', type: 'uint256', internalType: 'uint256' },
7763
+ { name: 'permitCalldata', type: 'bytes', internalType: 'bytes' },
7764
+ ],
7765
+ },
7766
+ { name: 'signature', type: 'bytes', internalType: 'bytes' },
7767
+ ],
7768
+ outputs: [],
7769
+ stateMutability: 'payable',
7770
+ },
7771
+ ];
7772
+
7642
7773
  /**
7643
7774
  * ERC20 ABI
7644
7775
  *
@@ -11004,78 +11135,6 @@ const bridgeContractAbi = [
11004
11135
  },
11005
11136
  ];
11006
11137
 
11007
- /**
11008
- * Adapter Contract ABI
11009
- *
11010
- * This ABI is used to interact with the Adapter smart contract that handles
11011
- * gasless token approvals via permits and atomic swap execution.
11012
- *
11013
- * The execute() function is the primary entry point for swap operations.
11014
- */
11015
- const adapterContractAbi = [
11016
- {
11017
- type: 'function',
11018
- name: 'execute',
11019
- inputs: [
11020
- {
11021
- name: 'params',
11022
- type: 'tuple',
11023
- internalType: 'struct IAdapter.ExecutionParams',
11024
- components: [
11025
- {
11026
- name: 'instructions',
11027
- type: 'tuple[]',
11028
- internalType: 'struct IAdapter.Instruction[]',
11029
- components: [
11030
- { name: 'target', type: 'address', internalType: 'address' },
11031
- { name: 'data', type: 'bytes', internalType: 'bytes' },
11032
- { name: 'value', type: 'uint256', internalType: 'uint256' },
11033
- { name: 'tokenIn', type: 'address', internalType: 'address' },
11034
- {
11035
- name: 'amountToApprove',
11036
- type: 'uint256',
11037
- internalType: 'uint256',
11038
- },
11039
- { name: 'tokenOut', type: 'address', internalType: 'address' },
11040
- { name: 'minTokenOut', type: 'uint256', internalType: 'uint256' },
11041
- ],
11042
- },
11043
- {
11044
- name: 'tokens',
11045
- type: 'tuple[]',
11046
- internalType: 'struct IAdapter.TokenRecipient[]',
11047
- components: [
11048
- { name: 'token', type: 'address', internalType: 'address' },
11049
- { name: 'beneficiary', type: 'address', internalType: 'address' },
11050
- ],
11051
- },
11052
- { name: 'execId', type: 'uint256', internalType: 'uint256' },
11053
- { name: 'deadline', type: 'uint256', internalType: 'uint256' },
11054
- { name: 'metadata', type: 'bytes', internalType: 'bytes' },
11055
- ],
11056
- },
11057
- {
11058
- name: 'tokenInputs',
11059
- type: 'tuple[]',
11060
- internalType: 'struct IAdapter.TokenInput[]',
11061
- components: [
11062
- {
11063
- name: 'permitType',
11064
- type: 'uint8',
11065
- internalType: 'enum IAdapter.PermitType',
11066
- },
11067
- { name: 'token', type: 'address', internalType: 'address' },
11068
- { name: 'amount', type: 'uint256', internalType: 'uint256' },
11069
- { name: 'permitCalldata', type: 'bytes', internalType: 'bytes' },
11070
- ],
11071
- },
11072
- { name: 'signature', type: 'bytes', internalType: 'bytes' },
11073
- ],
11074
- outputs: [],
11075
- stateMutability: 'payable',
11076
- },
11077
- ];
11078
-
11079
11138
  /**
11080
11139
  * ABI for the Circle Gateway Wallet contract.
11081
11140
  *
@@ -15497,6 +15556,107 @@ const balanceOf$2 = async (params, adapter, context) => {
15497
15556
  };
15498
15557
  };
15499
15558
 
15559
+ const hexBytesSchema = z
15560
+ .string()
15561
+ .regex(/^0x([0-9a-fA-F]{2})*$/, {
15562
+ message: 'value must be a 0x-prefixed even-length hex string',
15563
+ })
15564
+ .transform((value) => value);
15565
+ const earnExecuteParamsSchema = z
15566
+ .object({
15567
+ executeParams: z.object({}).passthrough(),
15568
+ signature: evmSignatureSchema,
15569
+ tokenInputs: z.array(z.object({
15570
+ permitType: z.nativeEnum(PermitType),
15571
+ token: evmAddressSchema,
15572
+ amount: z.bigint().refine((value) => value >= 0n, {
15573
+ message: 'amount must be a non-negative bigint',
15574
+ }),
15575
+ permitCalldata: hexBytesSchema,
15576
+ })),
15577
+ })
15578
+ .passthrough();
15579
+ function validateAdapterContractAddress(chainName, value) {
15580
+ const result = evmAddressSchema.safeParse(value);
15581
+ if (!result.success) {
15582
+ throw createValidationFailedError('chain.kitContracts.adapter', value, `Adapter contract for chain ${chainName} must be a 0x-prefixed 20-byte hex address.`);
15583
+ }
15584
+ return result.data;
15585
+ }
15586
+ function validateEarnExecuteParams(params) {
15587
+ const result = earnExecuteParamsSchema.safeParse(params);
15588
+ if (!result.success) {
15589
+ throw createValidationErrorFromZod(result.error, 'earn execute params');
15590
+ }
15591
+ return {
15592
+ executeParams: result.data.executeParams,
15593
+ signature: result.data.signature,
15594
+ tokenInputs: result.data.tokenInputs,
15595
+ __isActionParams: true,
15596
+ };
15597
+ }
15598
+ /**
15599
+ * Prepare an earn operation against the adapter contract on EVM chains.
15600
+ *
15601
+ * Forward the service-signed `executeParams` and `signature` to the adapter
15602
+ * contract's `execute` function. Token approvals are handled upstream by the
15603
+ * provider (today via a separate `token.approve` transaction; future: permit
15604
+ * entries in `tokenInputs`). This function performs runtime validation for
15605
+ * plain-JS callers, prepares calldata only, performs no network I/O, and does
15606
+ * not submit the transaction.
15607
+ *
15608
+ * @param params - Service-signed earn payload.
15609
+ * @param adapter - EVM adapter used to prepare the transaction.
15610
+ * @param context - Resolved operation context (chain + address).
15611
+ * @returns Prepared chain request ready to `estimate()` or `execute()`.
15612
+ * @throws {@link KitError} If the chain is not EVM-compatible.
15613
+ * @throws {@link KitError} If the chain has no adapter contract configured.
15614
+ * @throws {@link KitError} If required fields are missing or invalid.
15615
+ *
15616
+ * @example
15617
+ * ```typescript
15618
+ * const prepared = await evmAdapter.prepareAction(
15619
+ * 'earn.deposit',
15620
+ * {
15621
+ * executeParams: {
15622
+ * instructions: [],
15623
+ * tokens: [],
15624
+ * execId: 1n,
15625
+ * deadline: 0n,
15626
+ * metadata: '0x',
15627
+ * },
15628
+ * tokenInputs: [],
15629
+ * signature: '0x...',
15630
+ * },
15631
+ * { chain, address },
15632
+ * )
15633
+ * const txHash = await prepared.execute()
15634
+ * ```
15635
+ */
15636
+ const prepareEarnExecute = async (params, adapter, context) => {
15637
+ const { chain } = context;
15638
+ if (chain.type !== 'evm') {
15639
+ throw createInvalidChainError(chain.name, `Expected EVM chain, but received chain type: ${String(chain.type)}`);
15640
+ }
15641
+ const adapterContractAddress = chain.kitContracts?.adapter;
15642
+ if (adapterContractAddress === undefined) {
15643
+ throw createUnsupportedEarnRouteError('execute', chain.name);
15644
+ }
15645
+ const validatedAdapterAddress = validateAdapterContractAddress(chain.name, adapterContractAddress);
15646
+ const validatedParams = validateEarnExecuteParams(params);
15647
+ return adapter.prepare({
15648
+ type: 'evm',
15649
+ abi: adapterContractAbi,
15650
+ address: validatedAdapterAddress,
15651
+ functionName: 'execute',
15652
+ args: [
15653
+ validatedParams.executeParams,
15654
+ validatedParams.tokenInputs,
15655
+ validatedParams.signature,
15656
+ ],
15657
+ }, context);
15658
+ };
15659
+
15500
15660
  /**
15501
15661
  * Type guard to check if params is ExecuteSwapEVMParams.
15502
15662
  *
@@ -16346,6 +16506,36 @@ const getHandlers = (adapter) => {
16346
16506
  'swap.execute': async (params, context) => {
16347
16507
  return executeSwap(params, adapter, context);
16348
16508
  },
16509
+ /**
16510
+ * Handler for earn deposit execution on EVM chains.
16511
+ *
16512
+ * Forwards the earn service's signed `executeParams` and `signature` to the
16513
+ * on-chain adapter contract's `execute` function. Token approvals are handled
16514
+ * by the earn provider via separate `token.approve` transactions.
16515
+ */
16516
+ 'earn.deposit': async (params, context) => {
16517
+ return prepareEarnExecute(params, adapter, context);
16518
+ },
16519
+ /**
16520
+ * Handler for earn withdraw execution on EVM chains.
16521
+ *
16522
+ * Forwards the earn service's signed `executeParams` and `signature` to the
16523
+ * on-chain adapter contract's `execute` function. Token approvals are handled
16524
+ * by the earn provider via separate `token.approve` transactions.
16525
+ */
16526
+ 'earn.withdraw': async (params, context) => {
16527
+ return prepareEarnExecute(params, adapter, context);
16528
+ },
16529
+ /**
16530
+ * Handler for earn claim rewards execution on EVM chains.
16531
+ *
16532
+ * Forwards the earn service's signed `executeParams` and `signature` to the
16533
+ * on-chain adapter contract's `execute` function. Claim rewards does not
16534
+ * require approvals because the adapter does not pull user tokens.
16535
+ */
16536
+ 'earn.claimRewards': async (params, context) => {
16537
+ return prepareEarnExecute(params, adapter, context);
16538
+ },
16349
16539
  /**
16350
16540
  * Handler for CCTP v2 custom burn with hook operations on EVM chains.
16351
16541
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@circle-fin/adapter-ethers-v6",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "EVM blockchain adapter powered by Ethers v6",
5
5
  "keywords": [
6
6
  "circle",