@spicenet-io/spiceflow-core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @spicenet-io/spiceflow-core
2
+
3
+ Single source of truth for chain configs, token lists, logos, ABIs, and shared utilities across spiceflow repos.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ npm install @spicenet-io/spiceflow-core
9
+ ```
10
+
11
+ ## What's in here
12
+
13
+ ### Chains
14
+
15
+ `CHAINS` is a record of all supported chains keyed by chain ID. Each entry has id, name, display name, network (mainnet/testnet), native currency, delegate contract address, block explorer, rpc url, and logo.
16
+
17
+ Helper functions: `getChainMeta(chainId)`, `getChainsByNetwork(network)`, `getChainIdsByNetwork(network)`, `getMainnetChains()`, `getTestnetChains()`, `getDelegateContract(chainId)`.
18
+
19
+ ### Tokens
20
+
21
+ `TOKENS` is the official token list. Each token has symbol, name, equivalence group, logo, and deployments across chains (address, decimals, network per chain).
22
+
23
+ Helper functions: `getTokensForChain(chainId)`, `getTokenByAddress(address, chainId)`, `getEquivalentAddresses(tokenAddress)`, `areEquivalent(a, b)`, `isUsdDenominated(address)`, `isBtcDenominated(address)`.
24
+
25
+ ### Logos
26
+
27
+ All chain and token logos are bundled as base64 data URIs in the package. They work directly in img src attributes with no network requests. To add a new logo, drop the PNG in `logos/` and reference it in the chain or token list. `npm run build` auto generates the base64 file.
28
+
29
+ ### Utilities
30
+
31
+ `isNativeToken(address)` checks if an address is a native token (zero address, 0x0, or 0xeee...eee).
32
+
33
+ `normalizeNativeTokenAddress(address)` normalizes any native token address to the zero address.
34
+
35
+ `convertAmountBetweenDecimals(amount, fromDecimals, toDecimals)` converts token amounts between different decimal precisions.
36
+
37
+ `formatTokenAmount(amount, decimals)` formats a bigint token amount into a human readable string.
38
+
39
+ `truncateAddress(address)` shortens an address for display.
40
+
41
+ `withRetry(fn, maxRetries, delayMs)` retries an async function with exponential backoff.
42
+
43
+ Constants: `NATIVE_TOKEN_ADDRESS`, `ZERO_ADDRESS`, `ESCROW_ADDRESS`.
44
+
45
+ ### ABIs
46
+
47
+ `DELEGATE_ABI`, `ERC20_ABI`, `WCBTC_ABI`.
48
+
49
+ ### Authorization
50
+
51
+ `hashChainBatches(chainCalls)` hashes chain call batches for intent signing.
52
+
53
+ `getIntentHash(signatureType, nbf, exp, chainBatches)` computes the intent hash.
54
+
55
+ `getAccountNonce(address, publicClient)` gets the account nonce from chain.
56
+
57
+ ### Core SDK
58
+
59
+ `SpiceFlowCore` class for building and submitting intents. Handles delegation signing, chain batch construction, intent signing, and transaction submission.
60
+
61
+ ### HTTP
62
+
63
+ `fetchWithRetry(url, init, opts)` is a fetch wrapper with retry and exponential backoff.
64
+
65
+ `submitTransaction(baseUrl, request)` submits a transaction to the relayer API.
66
+
67
+ `getIntentStepStatus(txApiUrl, intentId, stepId)` checks intent execution status.
68
+
69
+ `prepareRFQT(txApiUrl, request)` prepares an RFQT quote.
70
+
71
+ ## Adding a token
72
+
73
+ 1. Drop the logo PNG in `logos/`
74
+ 2. Add the token entry in `src/tokens/list.ts` with symbol, name, equivalence group, logo reference, and deployments
75
+ 3. `npm run build` and publish
76
+
77
+ ## Adding a chain
78
+
79
+ 1. Drop the logo PNG in `logos/` if it's a new chain logo
80
+ 2. Add the chain entry in `src/chains/list.ts`
81
+ 3. Add token deployments on that chain in `src/tokens/list.ts`
82
+ 4. `npm run build` and publish
@@ -1,4 +1,5 @@
1
1
  export { DELEGATE_ABI } from "./delegate.js";
2
2
  export { ERC20_ABI } from "./erc20.js";
3
3
  export { WCBTC_ABI } from "./wcbtc.js";
4
+ export { uniV3QuoterV2Abi, uniV3SwapRouterAbi } from "./uniV3.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,93 @@
1
+ export declare const uniV3QuoterV2Abi: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly components: readonly [{
4
+ readonly internalType: "address";
5
+ readonly name: "tokenIn";
6
+ readonly type: "address";
7
+ }, {
8
+ readonly internalType: "address";
9
+ readonly name: "tokenOut";
10
+ readonly type: "address";
11
+ }, {
12
+ readonly internalType: "uint256";
13
+ readonly name: "amountIn";
14
+ readonly type: "uint256";
15
+ }, {
16
+ readonly internalType: "uint24";
17
+ readonly name: "fee";
18
+ readonly type: "uint24";
19
+ }, {
20
+ readonly internalType: "uint160";
21
+ readonly name: "sqrtPriceLimitX96";
22
+ readonly type: "uint160";
23
+ }];
24
+ readonly internalType: "struct IQuoterV2.QuoteExactInputSingleParams";
25
+ readonly name: "params";
26
+ readonly type: "tuple";
27
+ }];
28
+ readonly name: "quoteExactInputSingle";
29
+ readonly outputs: readonly [{
30
+ readonly internalType: "uint256";
31
+ readonly name: "amountOut";
32
+ readonly type: "uint256";
33
+ }, {
34
+ readonly internalType: "uint160";
35
+ readonly name: "sqrtPriceX96After";
36
+ readonly type: "uint160";
37
+ }, {
38
+ readonly internalType: "uint32";
39
+ readonly name: "initializedTicksCrossed";
40
+ readonly type: "uint32";
41
+ }, {
42
+ readonly internalType: "uint256";
43
+ readonly name: "gasEstimate";
44
+ readonly type: "uint256";
45
+ }];
46
+ readonly stateMutability: "nonpayable";
47
+ readonly type: "function";
48
+ }];
49
+ export declare const uniV3SwapRouterAbi: readonly [{
50
+ readonly inputs: readonly [{
51
+ readonly components: readonly [{
52
+ readonly internalType: "address";
53
+ readonly name: "tokenIn";
54
+ readonly type: "address";
55
+ }, {
56
+ readonly internalType: "address";
57
+ readonly name: "tokenOut";
58
+ readonly type: "address";
59
+ }, {
60
+ readonly internalType: "uint24";
61
+ readonly name: "fee";
62
+ readonly type: "uint24";
63
+ }, {
64
+ readonly internalType: "address";
65
+ readonly name: "recipient";
66
+ readonly type: "address";
67
+ }, {
68
+ readonly internalType: "uint256";
69
+ readonly name: "amountIn";
70
+ readonly type: "uint256";
71
+ }, {
72
+ readonly internalType: "uint256";
73
+ readonly name: "amountOutMinimum";
74
+ readonly type: "uint256";
75
+ }, {
76
+ readonly internalType: "uint160";
77
+ readonly name: "sqrtPriceLimitX96";
78
+ readonly type: "uint160";
79
+ }];
80
+ readonly internalType: "struct IV3SwapRouter.ExactInputSingleParams";
81
+ readonly name: "params";
82
+ readonly type: "tuple";
83
+ }];
84
+ readonly name: "exactInputSingle";
85
+ readonly outputs: readonly [{
86
+ readonly internalType: "uint256";
87
+ readonly name: "amountOut";
88
+ readonly type: "uint256";
89
+ }];
90
+ readonly stateMutability: "payable";
91
+ readonly type: "function";
92
+ }];
93
+ //# sourceMappingURL=uniV3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniV3.d.ts","sourceRoot":"","sources":["../../src/abis/uniV3.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCnB,CAAC;AAIX,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCrB,CAAC"}
package/dist/index.cjs CHANGED
@@ -31,7 +31,9 @@ __export(index_exports, {
31
31
  TOKENS: () => TOKENS,
32
32
  WCBTC_ABI: () => WCBTC_ABI,
33
33
  ZERO_ADDRESS: () => ZERO_ADDRESS,
34
+ applySlippage: () => applySlippage,
34
35
  areEquivalent: () => areEquivalent,
36
+ buildUniV3SwapCalls: () => buildUniV3SwapCalls,
35
37
  convertAmountBetweenDecimals: () => convertAmountBetweenDecimals,
36
38
  fetchWithRetry: () => fetchWithRetry,
37
39
  formatTokenAmount: () => formatTokenAmount,
@@ -57,8 +59,11 @@ __export(index_exports, {
57
59
  isUsdDenominated: () => isUsdDenominated,
58
60
  normalizeNativeTokenAddress: () => normalizeNativeTokenAddress,
59
61
  prepareRFQT: () => prepareRFQT,
62
+ resolveTokenRef: () => resolveTokenRef,
60
63
  submitTransaction: () => submitTransaction,
61
64
  truncateAddress: () => truncateAddress,
65
+ uniV3QuoterV2Abi: () => uniV3QuoterV2Abi,
66
+ uniV3SwapRouterAbi: () => uniV3SwapRouterAbi,
62
67
  withRetry: () => withRetry
63
68
  });
64
69
  module.exports = __toCommonJS(index_exports);
@@ -444,6 +449,24 @@ function isBtcDenominated(address) {
444
449
  const group = getEquivalenceGroup(address);
445
450
  return group !== void 0 && BTC_GROUPS.has(group);
446
451
  }
452
+ function resolveTokenRef(ref) {
453
+ const [symbol, chainId] = ref;
454
+ const tokens = getTokensForChain(chainId);
455
+ const match = tokens.find(
456
+ (t) => t.symbol.toUpperCase() === symbol.toUpperCase()
457
+ );
458
+ if (!match) {
459
+ throw new Error(
460
+ `Token "${symbol}" not found on chain ${chainId} in the token registry.`
461
+ );
462
+ }
463
+ return {
464
+ address: match.address,
465
+ symbol: match.symbol,
466
+ decimals: match.decimals,
467
+ chainId
468
+ };
469
+ }
447
470
 
448
471
  // src/chains/list.ts
449
472
  var CHAINS = {
@@ -990,6 +1013,129 @@ var WCBTC_ABI = [
990
1013
  { stateMutability: "payable", type: "receive" },
991
1014
  { stateMutability: "payable", type: "fallback" }
992
1015
  ];
1016
+
1017
+ // src/abis/uniV3.ts
1018
+ var uniV3QuoterV2Abi = [
1019
+ {
1020
+ inputs: [
1021
+ {
1022
+ components: [
1023
+ { internalType: "address", name: "tokenIn", type: "address" },
1024
+ { internalType: "address", name: "tokenOut", type: "address" },
1025
+ { internalType: "uint256", name: "amountIn", type: "uint256" },
1026
+ { internalType: "uint24", name: "fee", type: "uint24" },
1027
+ {
1028
+ internalType: "uint160",
1029
+ name: "sqrtPriceLimitX96",
1030
+ type: "uint160"
1031
+ }
1032
+ ],
1033
+ internalType: "struct IQuoterV2.QuoteExactInputSingleParams",
1034
+ name: "params",
1035
+ type: "tuple"
1036
+ }
1037
+ ],
1038
+ name: "quoteExactInputSingle",
1039
+ outputs: [
1040
+ { internalType: "uint256", name: "amountOut", type: "uint256" },
1041
+ {
1042
+ internalType: "uint160",
1043
+ name: "sqrtPriceX96After",
1044
+ type: "uint160"
1045
+ },
1046
+ {
1047
+ internalType: "uint32",
1048
+ name: "initializedTicksCrossed",
1049
+ type: "uint32"
1050
+ },
1051
+ { internalType: "uint256", name: "gasEstimate", type: "uint256" }
1052
+ ],
1053
+ stateMutability: "nonpayable",
1054
+ type: "function"
1055
+ }
1056
+ ];
1057
+ var uniV3SwapRouterAbi = [
1058
+ {
1059
+ inputs: [
1060
+ {
1061
+ components: [
1062
+ { internalType: "address", name: "tokenIn", type: "address" },
1063
+ { internalType: "address", name: "tokenOut", type: "address" },
1064
+ { internalType: "uint24", name: "fee", type: "uint24" },
1065
+ { internalType: "address", name: "recipient", type: "address" },
1066
+ { internalType: "uint256", name: "amountIn", type: "uint256" },
1067
+ {
1068
+ internalType: "uint256",
1069
+ name: "amountOutMinimum",
1070
+ type: "uint256"
1071
+ },
1072
+ {
1073
+ internalType: "uint160",
1074
+ name: "sqrtPriceLimitX96",
1075
+ type: "uint160"
1076
+ }
1077
+ ],
1078
+ internalType: "struct IV3SwapRouter.ExactInputSingleParams",
1079
+ name: "params",
1080
+ type: "tuple"
1081
+ }
1082
+ ],
1083
+ name: "exactInputSingle",
1084
+ outputs: [
1085
+ { internalType: "uint256", name: "amountOut", type: "uint256" }
1086
+ ],
1087
+ stateMutability: "payable",
1088
+ type: "function"
1089
+ }
1090
+ ];
1091
+
1092
+ // src/swap.ts
1093
+ var import_viem2 = require("viem");
1094
+ function applySlippage(amount, slippage = 0.03) {
1095
+ const slippageBps = BigInt(Math.floor((1 - slippage) * 1e4));
1096
+ return amount * slippageBps / 10000n;
1097
+ }
1098
+ function buildUniV3SwapCalls(params) {
1099
+ const {
1100
+ tokenIn,
1101
+ tokenOut,
1102
+ amountIn,
1103
+ amountOutMinimum,
1104
+ fee,
1105
+ recipient,
1106
+ config
1107
+ } = params;
1108
+ return [
1109
+ {
1110
+ to: tokenIn,
1111
+ value: 0n,
1112
+ data: (0, import_viem2.encodeFunctionData)({
1113
+ abi: import_viem2.erc20Abi,
1114
+ functionName: "approve",
1115
+ args: [config.swapRouter, amountIn]
1116
+ })
1117
+ },
1118
+ {
1119
+ to: config.swapRouter,
1120
+ value: 0n,
1121
+ data: (0, import_viem2.encodeFunctionData)({
1122
+ abi: uniV3SwapRouterAbi,
1123
+ functionName: "exactInputSingle",
1124
+ args: [
1125
+ {
1126
+ tokenIn,
1127
+ tokenOut,
1128
+ fee,
1129
+ recipient,
1130
+ amountIn,
1131
+ amountOutMinimum,
1132
+ sqrtPriceLimitX96: 0n
1133
+ }
1134
+ ]
1135
+ })
1136
+ }
1137
+ ];
1138
+ }
993
1139
  // Annotate the CommonJS export names for ESM import in node:
994
1140
  0 && (module.exports = {
995
1141
  CHAINS,
@@ -1004,7 +1150,9 @@ var WCBTC_ABI = [
1004
1150
  TOKENS,
1005
1151
  WCBTC_ABI,
1006
1152
  ZERO_ADDRESS,
1153
+ applySlippage,
1007
1154
  areEquivalent,
1155
+ buildUniV3SwapCalls,
1008
1156
  convertAmountBetweenDecimals,
1009
1157
  fetchWithRetry,
1010
1158
  formatTokenAmount,
@@ -1030,7 +1178,10 @@ var WCBTC_ABI = [
1030
1178
  isUsdDenominated,
1031
1179
  normalizeNativeTokenAddress,
1032
1180
  prepareRFQT,
1181
+ resolveTokenRef,
1033
1182
  submitTransaction,
1034
1183
  truncateAddress,
1184
+ uniV3QuoterV2Abi,
1185
+ uniV3SwapRouterAbi,
1035
1186
  withRetry
1036
1187
  });
package/dist/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export * from "./tokens/index.js";
10
10
  export * from "./chains/index.js";
11
11
  export * from "./utils.js";
12
12
  export * from "./abis/index.js";
13
+ export * from "./swap.js";
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -379,6 +379,24 @@ function isBtcDenominated(address) {
379
379
  const group = getEquivalenceGroup(address);
380
380
  return group !== void 0 && BTC_GROUPS.has(group);
381
381
  }
382
+ function resolveTokenRef(ref) {
383
+ const [symbol, chainId] = ref;
384
+ const tokens = getTokensForChain(chainId);
385
+ const match = tokens.find(
386
+ (t) => t.symbol.toUpperCase() === symbol.toUpperCase()
387
+ );
388
+ if (!match) {
389
+ throw new Error(
390
+ `Token "${symbol}" not found on chain ${chainId} in the token registry.`
391
+ );
392
+ }
393
+ return {
394
+ address: match.address,
395
+ symbol: match.symbol,
396
+ decimals: match.decimals,
397
+ chainId
398
+ };
399
+ }
382
400
 
383
401
  // src/chains/list.ts
384
402
  var CHAINS = {
@@ -925,6 +943,129 @@ var WCBTC_ABI = [
925
943
  { stateMutability: "payable", type: "receive" },
926
944
  { stateMutability: "payable", type: "fallback" }
927
945
  ];
946
+
947
+ // src/abis/uniV3.ts
948
+ var uniV3QuoterV2Abi = [
949
+ {
950
+ inputs: [
951
+ {
952
+ components: [
953
+ { internalType: "address", name: "tokenIn", type: "address" },
954
+ { internalType: "address", name: "tokenOut", type: "address" },
955
+ { internalType: "uint256", name: "amountIn", type: "uint256" },
956
+ { internalType: "uint24", name: "fee", type: "uint24" },
957
+ {
958
+ internalType: "uint160",
959
+ name: "sqrtPriceLimitX96",
960
+ type: "uint160"
961
+ }
962
+ ],
963
+ internalType: "struct IQuoterV2.QuoteExactInputSingleParams",
964
+ name: "params",
965
+ type: "tuple"
966
+ }
967
+ ],
968
+ name: "quoteExactInputSingle",
969
+ outputs: [
970
+ { internalType: "uint256", name: "amountOut", type: "uint256" },
971
+ {
972
+ internalType: "uint160",
973
+ name: "sqrtPriceX96After",
974
+ type: "uint160"
975
+ },
976
+ {
977
+ internalType: "uint32",
978
+ name: "initializedTicksCrossed",
979
+ type: "uint32"
980
+ },
981
+ { internalType: "uint256", name: "gasEstimate", type: "uint256" }
982
+ ],
983
+ stateMutability: "nonpayable",
984
+ type: "function"
985
+ }
986
+ ];
987
+ var uniV3SwapRouterAbi = [
988
+ {
989
+ inputs: [
990
+ {
991
+ components: [
992
+ { internalType: "address", name: "tokenIn", type: "address" },
993
+ { internalType: "address", name: "tokenOut", type: "address" },
994
+ { internalType: "uint24", name: "fee", type: "uint24" },
995
+ { internalType: "address", name: "recipient", type: "address" },
996
+ { internalType: "uint256", name: "amountIn", type: "uint256" },
997
+ {
998
+ internalType: "uint256",
999
+ name: "amountOutMinimum",
1000
+ type: "uint256"
1001
+ },
1002
+ {
1003
+ internalType: "uint160",
1004
+ name: "sqrtPriceLimitX96",
1005
+ type: "uint160"
1006
+ }
1007
+ ],
1008
+ internalType: "struct IV3SwapRouter.ExactInputSingleParams",
1009
+ name: "params",
1010
+ type: "tuple"
1011
+ }
1012
+ ],
1013
+ name: "exactInputSingle",
1014
+ outputs: [
1015
+ { internalType: "uint256", name: "amountOut", type: "uint256" }
1016
+ ],
1017
+ stateMutability: "payable",
1018
+ type: "function"
1019
+ }
1020
+ ];
1021
+
1022
+ // src/swap.ts
1023
+ import { encodeFunctionData, erc20Abi } from "viem";
1024
+ function applySlippage(amount, slippage = 0.03) {
1025
+ const slippageBps = BigInt(Math.floor((1 - slippage) * 1e4));
1026
+ return amount * slippageBps / 10000n;
1027
+ }
1028
+ function buildUniV3SwapCalls(params) {
1029
+ const {
1030
+ tokenIn,
1031
+ tokenOut,
1032
+ amountIn,
1033
+ amountOutMinimum,
1034
+ fee,
1035
+ recipient,
1036
+ config
1037
+ } = params;
1038
+ return [
1039
+ {
1040
+ to: tokenIn,
1041
+ value: 0n,
1042
+ data: encodeFunctionData({
1043
+ abi: erc20Abi,
1044
+ functionName: "approve",
1045
+ args: [config.swapRouter, amountIn]
1046
+ })
1047
+ },
1048
+ {
1049
+ to: config.swapRouter,
1050
+ value: 0n,
1051
+ data: encodeFunctionData({
1052
+ abi: uniV3SwapRouterAbi,
1053
+ functionName: "exactInputSingle",
1054
+ args: [
1055
+ {
1056
+ tokenIn,
1057
+ tokenOut,
1058
+ fee,
1059
+ recipient,
1060
+ amountIn,
1061
+ amountOutMinimum,
1062
+ sqrtPriceLimitX96: 0n
1063
+ }
1064
+ ]
1065
+ })
1066
+ }
1067
+ ];
1068
+ }
928
1069
  export {
929
1070
  CHAINS,
930
1071
  ChainBatchHashAbi,
@@ -938,7 +1079,9 @@ export {
938
1079
  TOKENS,
939
1080
  WCBTC_ABI,
940
1081
  ZERO_ADDRESS,
1082
+ applySlippage,
941
1083
  areEquivalent,
1084
+ buildUniV3SwapCalls,
942
1085
  convertAmountBetweenDecimals,
943
1086
  fetchWithRetry,
944
1087
  formatTokenAmount,
@@ -964,7 +1107,10 @@ export {
964
1107
  isUsdDenominated,
965
1108
  normalizeNativeTokenAddress,
966
1109
  prepareRFQT,
1110
+ resolveTokenRef,
967
1111
  submitTransaction,
968
1112
  truncateAddress,
1113
+ uniV3QuoterV2Abi,
1114
+ uniV3SwapRouterAbi,
969
1115
  withRetry
970
1116
  };
package/dist/swap.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { type Address } from "viem";
2
+ import type { Call } from "./types.js";
3
+ export interface UniV3SwapConfig {
4
+ swapRouter: Address;
5
+ quoterV2: Address;
6
+ }
7
+ export interface UniV3QuoteParams {
8
+ tokenIn: Address;
9
+ tokenOut: Address;
10
+ amountIn: bigint;
11
+ fee: number;
12
+ chainId: number;
13
+ config: UniV3SwapConfig;
14
+ }
15
+ export interface UniV3QuoteResult {
16
+ amountOut: bigint;
17
+ sqrtPriceX96After: bigint;
18
+ gasEstimate: bigint;
19
+ }
20
+ export interface UniV3BuildSwapParams {
21
+ tokenIn: Address;
22
+ tokenOut: Address;
23
+ amountIn: bigint;
24
+ amountOutMinimum: bigint;
25
+ fee: number;
26
+ recipient: Address;
27
+ config: UniV3SwapConfig;
28
+ }
29
+ export declare function applySlippage(amount: bigint, slippage?: number): bigint;
30
+ export declare function buildUniV3SwapCalls(params: UniV3BuildSwapParams): Call[];
31
+ //# sourceMappingURL=swap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../src/swap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAElE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAO,GAAG,MAAM,CAGrE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,EAAE,CAyCxE"}
@@ -1,13 +1,15 @@
1
- export type { SwapContract, TokenDeployment, Token, ResolvedToken } from "./types.js";
1
+ export type { SwapContract, TokenDeployment, TokenDefinition, Token } from "./types.js";
2
2
  export { TOKENS } from "./list.js";
3
- import type { Token, TokenDeployment, ResolvedToken } from "./types.js";
4
- export declare function getTokensForChain(chainId: number): ResolvedToken[];
5
- export declare function getTokenByAddress(address: string, chainId: number): ResolvedToken | undefined;
6
- export declare function getTokenDefinition(address: string): Token | undefined;
3
+ import type { TokenDefinition, TokenDeployment, Token } from "./types.js";
4
+ import type { ChainToken, TokenRef } from "../types.js";
5
+ export declare function getTokensForChain(chainId: number): Token[];
6
+ export declare function getTokenByAddress(address: string, chainId: number): Token | undefined;
7
+ export declare function getTokenDefinition(address: string): TokenDefinition | undefined;
7
8
  export declare function getDeployment(address: string, chainId: number): TokenDeployment | undefined;
8
9
  export declare function getEquivalentAddresses(tokenAddress: string): string[];
9
10
  export declare function getEquivalenceGroup(tokenAddress: string): string | undefined;
10
11
  export declare function areEquivalent(a: string, b: string): boolean;
11
12
  export declare function isUsdDenominated(address: string): boolean;
12
13
  export declare function isBtcDenominated(address: string): boolean;
14
+ export declare function resolveTokenRef(ref: TokenRef): ChainToken;
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA6CxE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CAIlE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAI7F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAErE;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAE3F;AAED,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAIrE;AAED,wBAAgB,mBAAmB,CAAC,YAA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OAAO,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,UAAU,CAmBzD"}
@@ -1,3 +1,3 @@
1
- import type { Token } from "./types.js";
2
- export declare const TOKENS: Token[];
1
+ import type { TokenDefinition } from "./types.js";
2
+ export declare const TOKENS: TokenDefinition[];
3
3
  //# sourceMappingURL=list.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/tokens/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,eAAO,MAAM,MAAM,EAAE,KAAK,EAuHzB,CAAC"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/tokens/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,eAAO,MAAM,MAAM,EAAE,eAAe,EAuHnC,CAAC"}
@@ -12,14 +12,14 @@ export interface TokenDeployment {
12
12
  network: Network;
13
13
  swapContracts: SwapContract[];
14
14
  }
15
- export interface Token {
15
+ export interface TokenDefinition {
16
16
  symbol: string;
17
17
  name: string;
18
18
  equivalenceGroup: string;
19
19
  logo: string;
20
20
  deployments: TokenDeployment[];
21
21
  }
22
- export interface ResolvedToken {
22
+ export interface Token {
23
23
  symbol: string;
24
24
  name: string;
25
25
  equivalenceGroup: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,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;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC;AAGD,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B"}
package/dist/types.d.ts CHANGED
@@ -4,6 +4,46 @@ export type Call = {
4
4
  value: bigint;
5
5
  data: Hex;
6
6
  };
7
+ /** A declarative swap that the SDK resolves into concrete approve + swap Call[] before signing. */
8
+ export interface SwapIntent {
9
+ type: "swap";
10
+ tokenIn: Address;
11
+ tokenOut: Address;
12
+ amountIn: bigint;
13
+ maxSlippage?: number;
14
+ }
15
+ /** A batch entry is either a concrete Call or a declarative SwapIntent. */
16
+ export type BatchEntry = Call | SwapIntent;
17
+ /** Token transfer config for solver-managed transfers within a batch. */
18
+ export interface TokenTransferConfig {
19
+ from: Address | "solver";
20
+ to: Address;
21
+ token: Address;
22
+ amount: bigint;
23
+ }
24
+ export interface ChainToken {
25
+ address: Address;
26
+ symbol: string;
27
+ decimals: number;
28
+ chainId: number;
29
+ }
30
+ export type TokenRef = [symbol: string, chainId: number];
31
+ export type RouteStrategy = "direct" | "source-swap" | "intermediary";
32
+ export interface RoutePlan {
33
+ strategy: RouteStrategy;
34
+ sourceAsset: ChainToken;
35
+ outputAsset: ChainToken;
36
+ intermediaryAsset?: ChainToken;
37
+ sourceChainId: number;
38
+ destinationChainId: number;
39
+ summary: string;
40
+ }
41
+ export interface ResolvedSwap {
42
+ venue: string;
43
+ amountOut: bigint;
44
+ amountOutMinimum: bigint;
45
+ calls: Call[];
46
+ }
7
47
  export type Authorization = {
8
48
  address: string;
9
49
  chainId: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE1D,MAAM,MAAM,IAAI,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC,CAAC;CACrE"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE1D,MAAM,MAAM,IAAI,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAAC;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AC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,MAAM;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC,CAAC;CACrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spicenet-io/spiceflow-core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",