@circle-fin/app-kit 1.11.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/CHANGELOG.md +53 -0
- package/README.md +56 -25
- package/bridge.cjs +1696 -1348
- package/bridge.d.cts +979 -2
- package/bridge.d.mts +979 -2
- package/bridge.d.ts +979 -2
- package/bridge.mjs +1696 -1348
- package/chains.cjs +106 -1
- package/chains.d.cts +96 -2
- package/chains.d.mts +96 -2
- package/chains.d.ts +96 -2
- package/chains.mjs +105 -2
- package/context.d.cts +978 -1
- package/context.d.mts +978 -1
- package/context.d.ts +978 -1
- package/earn.cjs +1728 -65
- package/earn.d.cts +978 -1
- package/earn.d.mts +978 -1
- package/earn.d.ts +978 -1
- package/earn.mjs +1728 -65
- package/estimateBridge.cjs +1695 -1347
- package/estimateBridge.d.cts +978 -1
- package/estimateBridge.d.mts +978 -1
- package/estimateBridge.d.ts +978 -1
- package/estimateBridge.mjs +1695 -1347
- package/estimateSwap.cjs +312 -17
- package/estimateSwap.d.cts +977 -1
- package/estimateSwap.d.mts +977 -1
- package/estimateSwap.d.ts +977 -1
- package/estimateSwap.mjs +312 -17
- package/index.cjs +3608 -1603
- package/index.d.cts +4181 -3426
- package/index.d.mts +4181 -3426
- package/index.d.ts +4181 -3426
- package/index.mjs +3607 -1604
- package/package.json +6 -6
- package/swap.cjs +312 -17
- package/swap.d.cts +977 -1
- package/swap.d.mts +977 -1
- package/swap.d.ts +977 -1
- package/swap.mjs +312 -17
- package/unifiedBalance.cjs +436 -122
- package/unifiedBalance.d.cts +132 -31
- package/unifiedBalance.d.mts +132 -31
- package/unifiedBalance.d.ts +132 -31
- package/unifiedBalance.mjs +436 -122
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@circle-fin/app-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "A one-stop Circle SDK solution for building stablecoin (e.g. USDC) applications, with bridging, swapping, and more on-chain operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"circle",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"module": "./index.mjs",
|
|
37
37
|
"types": "./index.d.cts",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@circle-fin/unified-balance-kit": "1.
|
|
40
|
-
"@circle-fin/provider-gateway-v1": "1.1
|
|
41
|
-
"@circle-fin/earn-kit": "1.
|
|
42
|
-
"@circle-fin/bridge-kit": "1.
|
|
43
|
-
"@circle-fin/swap-kit": "1.5.
|
|
39
|
+
"@circle-fin/unified-balance-kit": "1.4.1",
|
|
40
|
+
"@circle-fin/provider-gateway-v1": "1.2.1",
|
|
41
|
+
"@circle-fin/earn-kit": "1.5.1",
|
|
42
|
+
"@circle-fin/bridge-kit": "1.13.0",
|
|
43
|
+
"@circle-fin/swap-kit": "1.5.2",
|
|
44
44
|
"@coral-xyz/anchor": "^0.31.1",
|
|
45
45
|
"@noble/curves": "1.4.2",
|
|
46
46
|
"bn.js": "^5.2.3",
|
package/swap.cjs
CHANGED
|
@@ -40,6 +40,7 @@ require('@coral-xyz/anchor');
|
|
|
40
40
|
var bs58 = require('bs58');
|
|
41
41
|
require('@noble/curves/ed25519');
|
|
42
42
|
var units = require('@ethersproject/units');
|
|
43
|
+
require('viem');
|
|
43
44
|
var keccak256 = require('@ethersproject/keccak256');
|
|
44
45
|
|
|
45
46
|
function _interopDefault (e) { return e && e.__esModule ? e.default : e; }
|
|
@@ -3008,6 +3009,8 @@ class KitError extends Error {
|
|
|
3008
3009
|
Blockchain["World_Chain_Sepolia"] = "World_Chain_Sepolia";
|
|
3009
3010
|
Blockchain["XDC"] = "XDC";
|
|
3010
3011
|
Blockchain["XDC_Apothem"] = "XDC_Apothem";
|
|
3012
|
+
Blockchain["X_Layer"] = "X_Layer";
|
|
3013
|
+
Blockchain["X_Layer_Testnet"] = "X_Layer_Testnet";
|
|
3011
3014
|
Blockchain["ZKSync_Era"] = "ZKSync_Era";
|
|
3012
3015
|
Blockchain["ZKSync_Sepolia"] = "ZKSync_Sepolia";
|
|
3013
3016
|
})(Blockchain || (Blockchain = {}));
|
|
@@ -3061,6 +3064,7 @@ var BridgeChain;
|
|
|
3061
3064
|
BridgeChain["Unichain"] = "Unichain";
|
|
3062
3065
|
BridgeChain["World_Chain"] = "World_Chain";
|
|
3063
3066
|
BridgeChain["XDC"] = "XDC";
|
|
3067
|
+
BridgeChain["X_Layer"] = "X_Layer";
|
|
3064
3068
|
// Testnet chains with CCTPv2 support
|
|
3065
3069
|
BridgeChain["Arc_Testnet"] = "Arc_Testnet";
|
|
3066
3070
|
BridgeChain["Arbitrum_Sepolia"] = "Arbitrum_Sepolia";
|
|
@@ -3086,6 +3090,7 @@ var BridgeChain;
|
|
|
3086
3090
|
BridgeChain["Unichain_Sepolia"] = "Unichain_Sepolia";
|
|
3087
3091
|
BridgeChain["World_Chain_Sepolia"] = "World_Chain_Sepolia";
|
|
3088
3092
|
BridgeChain["XDC_Apothem"] = "XDC_Apothem";
|
|
3093
|
+
BridgeChain["X_Layer_Testnet"] = "X_Layer_Testnet";
|
|
3089
3094
|
})(BridgeChain || (BridgeChain = {}));
|
|
3090
3095
|
var UnifiedBalanceChain;
|
|
3091
3096
|
(function(UnifiedBalanceChain) {
|
|
@@ -5634,7 +5639,8 @@ var EarnChain;
|
|
|
5634
5639
|
isTestnet: true,
|
|
5635
5640
|
explorerUrl: 'https://amoy.polygonscan.com/tx/{hash}',
|
|
5636
5641
|
rpcEndpoints: [
|
|
5637
|
-
'https://
|
|
5642
|
+
'https://polygon-amoy-bor-rpc.publicnode.com',
|
|
5643
|
+
'https://polygon-amoy.drpc.org'
|
|
5638
5644
|
],
|
|
5639
5645
|
eurcAddress: null,
|
|
5640
5646
|
usdcAddress: '0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582',
|
|
@@ -6499,6 +6505,104 @@ var EarnChain;
|
|
|
6499
6505
|
}
|
|
6500
6506
|
});
|
|
6501
6507
|
|
|
6508
|
+
/**
|
|
6509
|
+
* X Layer Mainnet chain definition
|
|
6510
|
+
* @remarks
|
|
6511
|
+
* This represents the official production network for the X Layer blockchain.
|
|
6512
|
+
* X Layer is an EVM-compatible OP Stack Layer-2 blockchain built by OKX,
|
|
6513
|
+
* using OKB as its native gas token. (Migrated from Polygon zkEVM/CDK to the
|
|
6514
|
+
* OP Stack on 2025-10-27; older docs describing it as zkEVM are obsolete.)
|
|
6515
|
+
*/ const XLayer = defineChain({
|
|
6516
|
+
type: 'evm',
|
|
6517
|
+
chain: Blockchain.X_Layer,
|
|
6518
|
+
name: 'X Layer',
|
|
6519
|
+
title: 'X Layer Mainnet',
|
|
6520
|
+
nativeCurrency: {
|
|
6521
|
+
name: 'OKB',
|
|
6522
|
+
symbol: 'OKB',
|
|
6523
|
+
decimals: 18
|
|
6524
|
+
},
|
|
6525
|
+
chainId: 196,
|
|
6526
|
+
isTestnet: false,
|
|
6527
|
+
explorerUrl: 'https://www.oklink.com/xlayer/tx/{hash}',
|
|
6528
|
+
rpcEndpoints: [
|
|
6529
|
+
'https://xlayerrpc.okx.com'
|
|
6530
|
+
],
|
|
6531
|
+
eurcAddress: null,
|
|
6532
|
+
usdcAddress: '0xB6CEceAB302E2E4948951eE7843FC24E92933061',
|
|
6533
|
+
usdtAddress: null,
|
|
6534
|
+
cctp: {
|
|
6535
|
+
domain: 37,
|
|
6536
|
+
contracts: {
|
|
6537
|
+
v2: {
|
|
6538
|
+
type: 'split',
|
|
6539
|
+
tokenMessenger: '0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d',
|
|
6540
|
+
messageTransmitter: '0x81D40F21F12A8F0E3252Bccb954D722d4c464B64',
|
|
6541
|
+
confirmations: 65,
|
|
6542
|
+
fastConfirmations: 1
|
|
6543
|
+
}
|
|
6544
|
+
},
|
|
6545
|
+
forwarderSupported: {
|
|
6546
|
+
source: false,
|
|
6547
|
+
destination: false
|
|
6548
|
+
}
|
|
6549
|
+
},
|
|
6550
|
+
kitContracts: {
|
|
6551
|
+
bridge: BRIDGE_CONTRACT_EVM_MAINNET
|
|
6552
|
+
}
|
|
6553
|
+
});
|
|
6554
|
+
|
|
6555
|
+
/**
|
|
6556
|
+
* X Layer Testnet chain definition
|
|
6557
|
+
* @remarks
|
|
6558
|
+
* This represents the official test network for the X Layer blockchain.
|
|
6559
|
+
* X Layer is an EVM-compatible OP Stack Layer-2 blockchain built by OKX,
|
|
6560
|
+
* using OKB as its native gas token. (Migrated from Polygon zkEVM/CDK to the
|
|
6561
|
+
* OP Stack on 2025-10-27; older docs describing it as zkEVM are obsolete.)
|
|
6562
|
+
*/ const XLayerTestnet = defineChain({
|
|
6563
|
+
type: 'evm',
|
|
6564
|
+
chain: Blockchain.X_Layer_Testnet,
|
|
6565
|
+
name: 'X Layer Testnet',
|
|
6566
|
+
title: 'X Layer Testnet',
|
|
6567
|
+
nativeCurrency: {
|
|
6568
|
+
name: 'OKB',
|
|
6569
|
+
symbol: 'OKB',
|
|
6570
|
+
decimals: 18
|
|
6571
|
+
},
|
|
6572
|
+
chainId: 1952,
|
|
6573
|
+
isTestnet: true,
|
|
6574
|
+
// Deliberately not oklink.com (used for mainnet): viem's bundled OKLink
|
|
6575
|
+
// testnet URL targets the deprecated pre-rebrand chain ID 195, not this
|
|
6576
|
+
// chain's ID (1952). Verified against the internal chain-expansion-scripts
|
|
6577
|
+
// config (`v2config.sandbox.yml`) — do not "normalize" this to match mainnet.
|
|
6578
|
+
explorerUrl: 'https://web3.okx.com/explorer/x-layer-testnet/tx/{hash}',
|
|
6579
|
+
rpcEndpoints: [
|
|
6580
|
+
'https://testrpc.xlayer.tech'
|
|
6581
|
+
],
|
|
6582
|
+
eurcAddress: null,
|
|
6583
|
+
usdcAddress: '0xDec90b78111Ba2fc6FC6d84d8B9ec159A2d4b9B3',
|
|
6584
|
+
usdtAddress: null,
|
|
6585
|
+
cctp: {
|
|
6586
|
+
domain: 37,
|
|
6587
|
+
contracts: {
|
|
6588
|
+
v2: {
|
|
6589
|
+
type: 'split',
|
|
6590
|
+
tokenMessenger: '0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA',
|
|
6591
|
+
messageTransmitter: '0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275',
|
|
6592
|
+
confirmations: 65,
|
|
6593
|
+
fastConfirmations: 1
|
|
6594
|
+
}
|
|
6595
|
+
},
|
|
6596
|
+
forwarderSupported: {
|
|
6597
|
+
source: false,
|
|
6598
|
+
destination: false
|
|
6599
|
+
}
|
|
6600
|
+
},
|
|
6601
|
+
kitContracts: {
|
|
6602
|
+
bridge: BRIDGE_CONTRACT_EVM_TESTNET
|
|
6603
|
+
}
|
|
6604
|
+
});
|
|
6605
|
+
|
|
6502
6606
|
/**
|
|
6503
6607
|
* ZKSync Era Mainnet chain definition
|
|
6504
6608
|
* @remarks
|
|
@@ -6618,6 +6722,8 @@ var Chains = {
|
|
|
6618
6722
|
WorldChainSepolia: WorldChainSepolia,
|
|
6619
6723
|
XDC: XDC,
|
|
6620
6724
|
XDCApothem: XDCApothem,
|
|
6725
|
+
XLayer: XLayer,
|
|
6726
|
+
XLayerTestnet: XLayerTestnet,
|
|
6621
6727
|
ZKSyncEra: ZKSyncEra,
|
|
6622
6728
|
ZKSyncEraSepolia: ZKSyncEraSepolia
|
|
6623
6729
|
};
|
|
@@ -8646,6 +8752,7 @@ const swapTokenEnumSchema = zod.z.enum([
|
|
|
8646
8752
|
[Blockchain.Unichain]: '0x078D782b760474a361dDA0AF3839290b0EF57AD6',
|
|
8647
8753
|
[Blockchain.World_Chain]: '0x79A02482A880bCE3F13e09Da970dC34db4CD24d1',
|
|
8648
8754
|
[Blockchain.XDC]: '0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1',
|
|
8755
|
+
[Blockchain.X_Layer]: '0xB6CEceAB302E2E4948951eE7843FC24E92933061',
|
|
8649
8756
|
[Blockchain.ZKSync_Era]: '0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4',
|
|
8650
8757
|
// =========================================================================
|
|
8651
8758
|
// Testnets (alphabetically sorted)
|
|
@@ -8654,6 +8761,7 @@ const swapTokenEnumSchema = zod.z.enum([
|
|
|
8654
8761
|
[Blockchain.Arbitrum_Sepolia]: '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d',
|
|
8655
8762
|
[Blockchain.Avalanche_Fuji]: '0x5425890298aed601595a70AB815c96711a31Bc65',
|
|
8656
8763
|
[Blockchain.Base_Sepolia]: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
|
|
8764
|
+
[Blockchain.Celo_Alfajores_Testnet]: '0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B',
|
|
8657
8765
|
[Blockchain.Codex_Testnet]: '0x6d7f141b6819C2c9CC2f818e6ad549E7Ca090F8f',
|
|
8658
8766
|
[Blockchain.Cronos_Testnet]: '0xEb33dc5fac03833e132593659e1dE7256aB59794',
|
|
8659
8767
|
[Blockchain.Edge_Testnet]: '0x2d9F7CAD728051AA35Ecdc472a14cf8cDF5CFD6B',
|
|
@@ -8680,6 +8788,7 @@ const swapTokenEnumSchema = zod.z.enum([
|
|
|
8680
8788
|
[Blockchain.Unichain_Sepolia]: '0x31d0220469e10c4E71834a79b1f276d740d3768F',
|
|
8681
8789
|
[Blockchain.World_Chain_Sepolia]: '0x66145f38cBAC35Ca6F1Dfb4914dF98F1614aeA88',
|
|
8682
8790
|
[Blockchain.XDC_Apothem]: '0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4',
|
|
8791
|
+
[Blockchain.X_Layer_Testnet]: '0xDec90b78111Ba2fc6FC6d84d8B9ec159A2d4b9B3',
|
|
8683
8792
|
[Blockchain.ZKSync_Sepolia]: '0xAe045DE5638162fa134807Cb558E15A3F5A7F853'
|
|
8684
8793
|
}
|
|
8685
8794
|
};
|
|
@@ -9967,7 +10076,7 @@ const swapTokenEnumSchema = zod.z.enum([
|
|
|
9967
10076
|
}
|
|
9968
10077
|
|
|
9969
10078
|
var name$2 = "@circle-fin/bridge-kit";
|
|
9970
|
-
var version$2 = "1.
|
|
10079
|
+
var version$2 = "1.13.0";
|
|
9971
10080
|
var pkg$2 = {
|
|
9972
10081
|
name: name$2,
|
|
9973
10082
|
version: version$2};
|
|
@@ -10003,15 +10112,61 @@ var pkg$2 = {
|
|
|
10003
10112
|
computeFee: zod.z.function().returns(zod.z.string().or(zod.z.promise(zod.z.string()))).optional(),
|
|
10004
10113
|
calculateFee: zod.z.function().returns(zod.z.string().or(zod.z.promise(zod.z.string()))).optional(),
|
|
10005
10114
|
resolveFeeRecipientAddress: zod.z.function().returns(zod.z.string().or(zod.z.promise(zod.z.string())))
|
|
10006
|
-
}).strict().
|
|
10115
|
+
}).strict().superRefine((data, ctx)=>{
|
|
10007
10116
|
const hasComputeFee = data.computeFee !== undefined;
|
|
10008
10117
|
const hasCalculateFee = data.calculateFee !== undefined;
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10118
|
+
if (hasComputeFee && hasCalculateFee) {
|
|
10119
|
+
ctx.addIssue({
|
|
10120
|
+
code: zod.z.ZodIssueCode.custom,
|
|
10121
|
+
message: 'Provide either computeFee or calculateFee, not both. Use computeFee (recommended) for human-readable amounts.'
|
|
10122
|
+
});
|
|
10123
|
+
}
|
|
10124
|
+
if (!hasComputeFee && !hasCalculateFee) {
|
|
10125
|
+
ctx.addIssue({
|
|
10126
|
+
code: zod.z.ZodIssueCode.custom,
|
|
10127
|
+
message: 'Provide either computeFee or calculateFee. Use computeFee (recommended) for human-readable amounts.'
|
|
10128
|
+
});
|
|
10129
|
+
}
|
|
10013
10130
|
});
|
|
10014
10131
|
|
|
10132
|
+
/**
|
|
10133
|
+
* Canonical list of actions that do not prepare or submit transactions.
|
|
10134
|
+
*
|
|
10135
|
+
* @internal
|
|
10136
|
+
*/ const READ_ACTION_KEYS = [
|
|
10137
|
+
'token.allowance',
|
|
10138
|
+
'token.balanceOf',
|
|
10139
|
+
'token.name',
|
|
10140
|
+
'native.balanceOf',
|
|
10141
|
+
'usdc.allowance',
|
|
10142
|
+
'usdc.balanceOf',
|
|
10143
|
+
'usdc.name',
|
|
10144
|
+
'gateway.v1.isDelegate',
|
|
10145
|
+
'gateway.v1.withdrawingBalance',
|
|
10146
|
+
'gateway.v1.withdrawalBlock',
|
|
10147
|
+
'gateway.v1.signBurnIntents'
|
|
10148
|
+
];
|
|
10149
|
+
const READ_ACTION_KEY_SET = new Set(READ_ACTION_KEYS);
|
|
10150
|
+
/**
|
|
10151
|
+
* Check whether a runtime value identifies a read action.
|
|
10152
|
+
*
|
|
10153
|
+
* @param action - The value to classify.
|
|
10154
|
+
* @returns Whether the value is a registered read-action key.
|
|
10155
|
+
*
|
|
10156
|
+
* @example
|
|
10157
|
+
* ```typescript
|
|
10158
|
+
* import { isReadActionKey } from '@core/adapter'
|
|
10159
|
+
*
|
|
10160
|
+
* if (isReadActionKey(value)) {
|
|
10161
|
+
* await adapter.readAction(value, params, context)
|
|
10162
|
+
* }
|
|
10163
|
+
* ```
|
|
10164
|
+
*
|
|
10165
|
+
* @internal
|
|
10166
|
+
*/ function isReadActionKey(action) {
|
|
10167
|
+
return typeof action === 'string' && READ_ACTION_KEY_SET.has(action);
|
|
10168
|
+
}
|
|
10169
|
+
|
|
10015
10170
|
/**
|
|
10016
10171
|
* Resolves an operation context into concrete chain and address values.
|
|
10017
10172
|
*
|
|
@@ -10091,6 +10246,141 @@ var pkg$2 = {
|
|
|
10091
10246
|
};
|
|
10092
10247
|
}
|
|
10093
10248
|
|
|
10249
|
+
/**
|
|
10250
|
+
* Create the standard error for a missing or non-read action.
|
|
10251
|
+
*
|
|
10252
|
+
* @param action - The unsupported action value.
|
|
10253
|
+
* @returns A fatal unsupported-action error.
|
|
10254
|
+
*
|
|
10255
|
+
* @internal
|
|
10256
|
+
*/ function createUnsupportedReadActionError(action) {
|
|
10257
|
+
return new KitError({
|
|
10258
|
+
...InputError.UNSUPPORTED_ACTION,
|
|
10259
|
+
recoverability: 'FATAL',
|
|
10260
|
+
message: `Read action "${String(action)}" is not registered in this adapter.`
|
|
10261
|
+
});
|
|
10262
|
+
}
|
|
10263
|
+
/**
|
|
10264
|
+
* Execute a read through the adapter's dedicated read seam when available.
|
|
10265
|
+
*
|
|
10266
|
+
* @remarks
|
|
10267
|
+
* Fall back to the legacy `prepareAction().execute()` contract so providers
|
|
10268
|
+
* remain runtime-compatible with adapter versions released before `readAction`.
|
|
10269
|
+
* Consumers must upgrade their adapter package for reads to bypass custom
|
|
10270
|
+
* `prepareAction` wrappers.
|
|
10271
|
+
*
|
|
10272
|
+
* @typeParam TAdapterCapabilities - The adapter capabilities type.
|
|
10273
|
+
* @typeParam TActionKey - The read action key.
|
|
10274
|
+
* @param adapter - The adapter that owns the read action.
|
|
10275
|
+
* @param action - The read action to execute.
|
|
10276
|
+
* @param params - The parameters for the read action.
|
|
10277
|
+
* @param ctx - The operation context.
|
|
10278
|
+
* @returns The raw read-action result.
|
|
10279
|
+
* @throws {KitError} When `action` is not a supported read-action key.
|
|
10280
|
+
*
|
|
10281
|
+
* @example
|
|
10282
|
+
* ```typescript
|
|
10283
|
+
* import { executeAdapterReadAction } from '@core/adapter'
|
|
10284
|
+
* import { Ethereum } from '@core/chains'
|
|
10285
|
+
*
|
|
10286
|
+
* const allowance = await executeAdapterReadAction(
|
|
10287
|
+
* adapter,
|
|
10288
|
+
* 'token.allowance',
|
|
10289
|
+
* { tokenAddress, delegate },
|
|
10290
|
+
* { chain: Ethereum },
|
|
10291
|
+
* )
|
|
10292
|
+
* ```
|
|
10293
|
+
*
|
|
10294
|
+
* @internal
|
|
10295
|
+
*/ async function executeAdapterReadAction(adapter, action, params, ctx) {
|
|
10296
|
+
if (!isReadActionKey(action)) {
|
|
10297
|
+
throw createUnsupportedReadActionError(action);
|
|
10298
|
+
}
|
|
10299
|
+
const runtimeAdapter = adapter;
|
|
10300
|
+
if (typeof runtimeAdapter.readAction === 'function') {
|
|
10301
|
+
return runtimeAdapter.readAction(action, params, ctx);
|
|
10302
|
+
}
|
|
10303
|
+
let request;
|
|
10304
|
+
try {
|
|
10305
|
+
request = await adapter.prepareAction(action, params, ctx);
|
|
10306
|
+
} catch (error) {
|
|
10307
|
+
if (error instanceof Error && error.message === `Action ${action} is not supported`) {
|
|
10308
|
+
throw createUnsupportedReadActionError(action);
|
|
10309
|
+
}
|
|
10310
|
+
throw error;
|
|
10311
|
+
}
|
|
10312
|
+
return request.execute();
|
|
10313
|
+
}
|
|
10314
|
+
/**
|
|
10315
|
+
* Read and parse a token allowance while supporting older adapter versions.
|
|
10316
|
+
*
|
|
10317
|
+
* @remarks
|
|
10318
|
+
* Prefer the adapter's dedicated read seam and fall back to the legacy
|
|
10319
|
+
* `prepareAction().execute()` contract when the runtime adapter predates it.
|
|
10320
|
+
*
|
|
10321
|
+
* @typeParam TAdapterCapabilities - The adapter capabilities type.
|
|
10322
|
+
* @param adapter - The adapter that owns the allowance action.
|
|
10323
|
+
* @param params - The token and delegate whose allowance is being read.
|
|
10324
|
+
* @param ctx - The operation context.
|
|
10325
|
+
* @returns The non-negative allowance in token base units.
|
|
10326
|
+
* @throws {KitError} When the action is unsupported or its response is malformed.
|
|
10327
|
+
*
|
|
10328
|
+
* @example
|
|
10329
|
+
* ```typescript
|
|
10330
|
+
* import { readTokenAllowance } from '@core/adapter'
|
|
10331
|
+
* import { Ethereum } from '@core/chains'
|
|
10332
|
+
*
|
|
10333
|
+
* const allowance = await readTokenAllowance(
|
|
10334
|
+
* adapter,
|
|
10335
|
+
* { tokenAddress, delegate },
|
|
10336
|
+
* { chain: Ethereum },
|
|
10337
|
+
* )
|
|
10338
|
+
* ```
|
|
10339
|
+
*
|
|
10340
|
+
* @internal
|
|
10341
|
+
*/ async function readTokenAllowance(adapter, params, ctx) {
|
|
10342
|
+
return parseAllowanceResponse(await executeAdapterReadAction(adapter, 'token.allowance', params, ctx));
|
|
10343
|
+
}
|
|
10344
|
+
/**
|
|
10345
|
+
* Parse a raw token allowance response into base units.
|
|
10346
|
+
*
|
|
10347
|
+
* @param allowanceRaw - The adapter response, optionally wrapped as an Amount output.
|
|
10348
|
+
* @returns The non-negative allowance as a bigint, or zero for a missing value.
|
|
10349
|
+
* @throws {KitError} When the response cannot represent a non-negative bigint.
|
|
10350
|
+
*
|
|
10351
|
+
* @example
|
|
10352
|
+
* ```typescript
|
|
10353
|
+
* import { parseAllowanceResponse } from '@core/adapter'
|
|
10354
|
+
*
|
|
10355
|
+
* const allowance = parseAllowanceResponse({ amount: { raw: 1000000n } })
|
|
10356
|
+
* ```
|
|
10357
|
+
*/ function parseAllowanceResponse(allowanceRaw) {
|
|
10358
|
+
let value = allowanceRaw;
|
|
10359
|
+
if (typeof value === 'object' && value !== null && 'amount' in value) {
|
|
10360
|
+
const amount = value.amount;
|
|
10361
|
+
if (typeof amount === 'object' && amount !== null && 'raw' in amount) {
|
|
10362
|
+
value = amount.raw;
|
|
10363
|
+
}
|
|
10364
|
+
}
|
|
10365
|
+
if (value === undefined || value === null) {
|
|
10366
|
+
return 0n;
|
|
10367
|
+
}
|
|
10368
|
+
let allowance;
|
|
10369
|
+
if (typeof value === 'bigint') {
|
|
10370
|
+
allowance = value;
|
|
10371
|
+
} else if (typeof value === 'string') {
|
|
10372
|
+
try {
|
|
10373
|
+
allowance = BigInt(value);
|
|
10374
|
+
} catch {
|
|
10375
|
+
allowance = undefined;
|
|
10376
|
+
}
|
|
10377
|
+
}
|
|
10378
|
+
if (allowance === undefined || allowance < 0n) {
|
|
10379
|
+
throw createValidationFailedError$1('token.allowance', value, 'token.allowance response must be a non-negative bigint-compatible string or bigint');
|
|
10380
|
+
}
|
|
10381
|
+
return allowance;
|
|
10382
|
+
}
|
|
10383
|
+
|
|
10094
10384
|
/**
|
|
10095
10385
|
* Schema for validating hexadecimal strings with '0x' prefix.
|
|
10096
10386
|
*
|
|
@@ -10868,7 +11158,7 @@ var TransferSpeed;
|
|
|
10868
11158
|
registerKit(`${pkg$2.name}/${pkg$2.version}`);
|
|
10869
11159
|
|
|
10870
11160
|
var name$1 = "@circle-fin/swap-kit";
|
|
10871
|
-
var version$1 = "1.5.
|
|
11161
|
+
var version$1 = "1.5.2";
|
|
10872
11162
|
var pkg$1 = {
|
|
10873
11163
|
name: name$1,
|
|
10874
11164
|
version: version$1};
|
|
@@ -15188,14 +15478,13 @@ const TOKEN_REGISTRY$2 = createTokenRegistry();
|
|
|
15188
15478
|
return;
|
|
15189
15479
|
}
|
|
15190
15480
|
// For non-native tokens (SPL tokens, ERC-20 tokens), check the token balance
|
|
15191
|
-
const
|
|
15481
|
+
const balance = await executeAdapterReadAction(adapter, 'token.balanceOf', {
|
|
15192
15482
|
tokenAddress: tokenInAddress,
|
|
15193
15483
|
walletAddress
|
|
15194
15484
|
}, context);
|
|
15195
|
-
const balance = await balancePrepared.execute();
|
|
15196
15485
|
// Compare balances
|
|
15197
15486
|
const requiredAmount = BigInt(amount);
|
|
15198
|
-
const currentBalance = BigInt(balance);
|
|
15487
|
+
const currentBalance = BigInt(String(balance));
|
|
15199
15488
|
if (currentBalance < requiredAmount) {
|
|
15200
15489
|
throw new KitError({
|
|
15201
15490
|
...BalanceError.INSUFFICIENT_TOKEN,
|
|
@@ -16356,11 +16645,10 @@ async function fetchSameChainStatusSnapshot({ isCrossChainSwap, txHash, chain, a
|
|
|
16356
16645
|
* @throws Error if the adapter fails to prepare or execute approval transactions
|
|
16357
16646
|
* @throws Error if transaction confirmation fails or times out
|
|
16358
16647
|
*/ async handleUsdtApproval(adapter, chain, executionCtx, adapterContractAddress, resolvedContext, executedTransactions) {
|
|
16359
|
-
const
|
|
16648
|
+
const current = await readTokenAllowance(adapter, {
|
|
16360
16649
|
tokenAddress: executionCtx.tokenInAddress,
|
|
16361
16650
|
delegate: adapterContractAddress
|
|
16362
16651
|
}, resolvedContext);
|
|
16363
|
-
const current = BigInt(await allowanceRequest.execute());
|
|
16364
16652
|
const required = BigInt(executionCtx.amount);
|
|
16365
16653
|
if (current >= required) {
|
|
16366
16654
|
// Sufficient allowance - proceed to swap
|
|
@@ -21073,7 +21361,9 @@ registerKit(`${pkg$1.name}/${pkg$1.version}`);
|
|
|
21073
21361
|
disableAnalytics: context.disableAnalytics
|
|
21074
21362
|
}
|
|
21075
21363
|
});
|
|
21076
|
-
if (
|
|
21364
|
+
if (context.customFeePolicy?.swap != null) {
|
|
21365
|
+
kit.setCustomFeePolicy(context.customFeePolicy.swap);
|
|
21366
|
+
} else if (hasBoth) {
|
|
21077
21367
|
kit.setCustomFeePolicy({
|
|
21078
21368
|
computeFee: async (params)=>{
|
|
21079
21369
|
// Adapt provider-level params (with tokenIn/tokenOut)
|
|
@@ -21132,7 +21422,7 @@ registerKit(`${pkg$1.name}/${pkg$1.version}`);
|
|
|
21132
21422
|
};
|
|
21133
21423
|
|
|
21134
21424
|
var name = "@circle-fin/earn-kit";
|
|
21135
|
-
var version = "1.
|
|
21425
|
+
var version = "1.5.1";
|
|
21136
21426
|
var pkg = {
|
|
21137
21427
|
name: name,
|
|
21138
21428
|
version: version};
|
|
@@ -22143,11 +22433,16 @@ const sourceAdapterContextSchema = zod.z.object({
|
|
|
22143
22433
|
*
|
|
22144
22434
|
* Validate the optional Kit Key field using the standard `apiKeySchema`
|
|
22145
22435
|
* format (`KIT_KEY:<keyId>:<keySecret>`). When omitted, the SDK
|
|
22146
|
-
* operates in permissionless mode.
|
|
22436
|
+
* operates in permissionless mode. `baseUrl` overrides the Earn Service
|
|
22437
|
+
* endpoint (e.g. staging); `batchTransactions: false` opts out of atomic
|
|
22438
|
+
* batched execution. Both are forwarded to the provider, so this `.strict()`
|
|
22439
|
+
* schema must accept them or a valid config object is rejected.
|
|
22147
22440
|
*
|
|
22148
22441
|
* @internal
|
|
22149
22442
|
*/ const earnConfigSchema = zod.z.object({
|
|
22150
|
-
kitKey: apiKeySchema.optional()
|
|
22443
|
+
kitKey: apiKeySchema.optional(),
|
|
22444
|
+
baseUrl: zod.z.string().optional(),
|
|
22445
|
+
batchTransactions: zod.z.boolean().optional()
|
|
22151
22446
|
}).strict();
|
|
22152
22447
|
/**
|
|
22153
22448
|
* Canonical decimal form: a leading digit with no leading zeros (a single
|