@armory-sh/base 0.2.27-alpha.23.77 → 0.2.27-alpha.23.78

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.
@@ -0,0 +1,8 @@
1
+ import type { ClientHook, PaymentPayloadContext, PaymentRequiredContext } from "./types/hooks";
2
+ import type { PaymentRequirementsV2 } from "./types/v2";
3
+ export declare const runOnPaymentRequiredHooks: <TWallet>(hooks: ClientHook<TWallet>[] | undefined, context: PaymentRequiredContext) => Promise<void>;
4
+ export declare const selectRequirementWithHooks: <TWallet>(hooks: ClientHook<TWallet>[] | undefined, context: PaymentRequiredContext) => Promise<PaymentRequirementsV2>;
5
+ export declare const runBeforeSignPaymentHooks: <TWallet>(hooks: ClientHook<TWallet>[] | undefined, context: PaymentPayloadContext<TWallet>) => Promise<void>;
6
+ export declare const runAfterPaymentResponseHooks: <TWallet>(hooks: ClientHook<TWallet>[] | undefined, context: PaymentPayloadContext<TWallet> & {
7
+ response: Response;
8
+ }) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type { BalanceOfParams, BalanceOfReturnType, ERC20Abi, NameReturnType, ReceiveWithAuthorizationParams, SymbolReturnType, TransferWithAuthorizationParams, } from "./abi/erc20";
2
2
  export { ERC20_ABI } from "./abi/erc20";
3
+ export { runAfterPaymentResponseHooks, runBeforeSignPaymentHooks, runOnPaymentRequiredHooks, selectRequirementWithHooks, } from "./client-hooks-runtime";
3
4
  export { EURC_BASE, getAllTokens, getEURCTokens, getSKLTokens, getToken, getTokensByChain, getTokensBySymbol, getUSDCTokens, getUSDTTokens, getWBTCTokens, getWETHTokens, SKL_SKALE_BASE, SKL_SKALE_BASE_SEPOLIA, TOKENS, USDC_BASE, USDC_BASE_SEPOLIA, USDC_SKALE_BASE, USDC_SKALE_BASE_SEPOLIA, USDT_SKALE_BASE, USDT_SKALE_BASE_SEPOLIA, WBTC_SKALE_BASE, WBTC_SKALE_BASE_SEPOLIA, WETH_SKALE_BASE, WETH_SKALE_BASE_SEPOLIA, } from "./data/tokens";
4
5
  export type { EIP712Domain, EIP712Types, TransferWithAuthorization, TypedDataDomain, TypedDataField, } from "./eip712";
5
6
  export { createEIP712Domain, createTransferWithAuthorization, EIP712_TYPES, USDC_DOMAIN, validateTransferWithAuthorization, } from "./eip712";
@@ -13,7 +14,7 @@ export type { PaymentConfig, ResolvedRequirementsConfig, } from "./payment-requi
13
14
  export { createPaymentRequirements, findRequirementByNetwork, } from "./payment-requirements";
14
15
  export { calculateValidBefore, detectX402Version, generateNonce, getPaymentHeaderName, parseJsonOrBase64, } from "./protocol";
15
16
  export type { AcceptPaymentOptions, ArmoryPaymentResult, FacilitatorConfig, FacilitatorSettleResult, FacilitatorVerifyResult, NetworkId, PaymentError, PaymentErrorCode, PaymentResult, PayToAddress, PricingConfig, ResolvedFacilitator, ResolvedNetwork, ResolvedPaymentConfig, ResolvedToken, SettlementMode, TokenId, ValidationError, } from "./types/api";
16
- export type { BeforePaymentHook, ExtensionHook, HookConfig, HookRegistry, HookResult, OnPaymentRequiredHook, PaymentPayloadContext, PaymentRequiredContext, } from "./types/hooks";
17
+ export type { BeforePaymentHook, ClientHook, ClientHookErrorContext, ExtensionHook, HookConfig, HookRegistry, HookResult, OnPaymentRequiredHook, PaymentPayloadContext, PaymentRequiredContext, } from "./types/hooks";
17
18
  export type { CustomToken, NetworkConfig } from "./types/networks";
18
19
  export { getAllCustomTokens, getCustomToken, getMainnets, getNetworkByChainId, getNetworkConfig, getTestnets, isCustomToken, NETWORKS, registerToken, unregisterToken, } from "./types/networks";
19
20
  export type { PaymentPayload, PaymentRequired, PaymentRequirements, SettlementResponse, } from "./types/protocol";
package/dist/index.js CHANGED
@@ -57,6 +57,106 @@ var ERC20_ABI = [
57
57
  }
58
58
  ];
59
59
 
60
+ // src/client-hooks-runtime.ts
61
+ var notifyError = async (hooks, context) => {
62
+ if (!hooks?.length) {
63
+ return;
64
+ }
65
+ for (const hook of hooks) {
66
+ if (!hook.onError) {
67
+ continue;
68
+ }
69
+ await hook.onError(context);
70
+ }
71
+ };
72
+ var runOnPaymentRequiredHooks = async (hooks, context) => {
73
+ if (!hooks?.length) {
74
+ return;
75
+ }
76
+ for (const hook of hooks) {
77
+ if (!hook.onPaymentRequired) {
78
+ continue;
79
+ }
80
+ try {
81
+ await hook.onPaymentRequired(context);
82
+ } catch (error) {
83
+ await notifyError(hooks, { error, phase: "onPaymentRequired" });
84
+ throw error;
85
+ }
86
+ }
87
+ };
88
+ var selectRequirementWithHooks = async (hooks, context) => {
89
+ if (!context.accepts.length) {
90
+ throw new Error("No payment requirements found in accepts array");
91
+ }
92
+ let selected = context.accepts[0];
93
+ if (!hooks?.length) {
94
+ context.selectedRequirement = selected;
95
+ context.requirements = selected;
96
+ return selected;
97
+ }
98
+ for (const hook of hooks) {
99
+ if (!hook.selectRequirement) {
100
+ continue;
101
+ }
102
+ try {
103
+ const override = await hook.selectRequirement({
104
+ ...context,
105
+ selectedRequirement: selected,
106
+ requirements: selected
107
+ });
108
+ if (!override) {
109
+ continue;
110
+ }
111
+ const isValid = context.accepts.some((accept) => accept === override);
112
+ if (!isValid) {
113
+ throw new Error(
114
+ "Hook selectRequirement must return an item from accepts"
115
+ );
116
+ }
117
+ selected = override;
118
+ } catch (error) {
119
+ await notifyError(hooks, { error, phase: "selectRequirement" });
120
+ throw error;
121
+ }
122
+ }
123
+ context.selectedRequirement = selected;
124
+ context.requirements = selected;
125
+ return selected;
126
+ };
127
+ var runBeforeSignPaymentHooks = async (hooks, context) => {
128
+ if (!hooks?.length) {
129
+ return;
130
+ }
131
+ for (const hook of hooks) {
132
+ if (!hook.beforeSignPayment) {
133
+ continue;
134
+ }
135
+ try {
136
+ await hook.beforeSignPayment(context);
137
+ } catch (error) {
138
+ await notifyError(hooks, { error, phase: "beforeSignPayment" });
139
+ throw error;
140
+ }
141
+ }
142
+ };
143
+ var runAfterPaymentResponseHooks = async (hooks, context) => {
144
+ if (!hooks?.length) {
145
+ return;
146
+ }
147
+ for (const hook of hooks) {
148
+ if (!hook.afterPaymentResponse) {
149
+ continue;
150
+ }
151
+ try {
152
+ await hook.afterPaymentResponse(context);
153
+ } catch (error) {
154
+ await notifyError(hooks, { error, phase: "afterPaymentResponse" });
155
+ throw error;
156
+ }
157
+ }
158
+ };
159
+
60
160
  // src/data/tokens.ts
61
161
  var USDC_BASE = {
62
162
  symbol: "USDC",
@@ -1636,4 +1736,4 @@ function validateRouteConfig(config) {
1636
1736
  return null;
1637
1737
  }
1638
1738
 
1639
- export { EIP712_TYPES, ERC20_ABI, EURC_BASE, NETWORKS, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_SIGNATURE_HEADER, PaymentException, SCHEMES, SKL_SKALE_BASE, SKL_SKALE_BASE_SEPOLIA, SigningError, TOKENS, USDC_BASE, USDC_BASE_SEPOLIA, USDC_DOMAIN, USDC_SKALE_BASE, USDC_SKALE_BASE_SEPOLIA, USDT_SKALE_BASE, USDT_SKALE_BASE_SEPOLIA, V2_HEADERS, WBTC_SKALE_BASE, WBTC_SKALE_BASE_SEPOLIA, WETH_SKALE_BASE, WETH_SKALE_BASE_SEPOLIA, X402ClientError, X402_VERSION, addressToAssetId, assetIdToAddress, caip2ToNetwork, calculateValidBefore, checkFacilitatorSupport, combineSignature as combineSignatureV2, createEIP712Domain, createError, createNonce, createPaymentRequiredHeaders, createPaymentRequirements, createSettlementHeaders, createTransferWithAuthorization, decodeBase64ToUtf8, decodePayloadHeader, decodePayment, decodePaymentV2, decodeSettlementResponse, decodeSettlementV2, decodeX402Response, detectPaymentVersion, detectX402Version, encodePayment, encodePaymentV2, encodeSettlementResponse, encodeSettlementV2, encodeUtf8ToBase64, encodeX402Response, extractPayerAddress, extractPaymentFromHeaders, findMatchingRoute, findRequirementByNetwork, fromAtomicUnits, generateNonce, getAllCustomTokens, getAllTokens, getAvailableNetworks, getAvailableTokens, getCurrentTimestamp, getCustomToken, getEURCTokens, getMainnets, getNetworkByChainId, getNetworkConfig, getPaymentHeaderName, getSKLTokens, getSupported, getTestnets, getToken, getTokensByChain, getTokensBySymbol, getTxHash, getUSDCTokens, getUSDTTokens, getWBTCTokens, getWETHTokens, isAddress2 as isAddress, isCAIP2ChainId, isCAIPAssetId, isCustomToken, isExactEvmPayload, isPaymentPayload, isPaymentPayloadV2, isPaymentRequiredV2, isPaymentV2, isResolvedNetwork, isResolvedToken, isSettlementSuccessful, isSettlementV2, isValidAddress, isValidationError, isX402V2Payload, isX402V2PaymentRequired, isX402V2Requirements, isX402V2Settlement, matchRoute, networkToCaip2, normalizeAddress, normalizeBase64Url, normalizeNetworkName, parseJsonOrBase64, parseRoutePattern, parseSignature as parseSignatureV2, registerToken, resolveFacilitator, resolveNetwork, resolveToken, safeBase64Decode2 as safeBase64Decode, safeBase64Encode2 as safeBase64Encode, settlePayment, toAtomicUnits, toBase64Url, unregisterToken, validateAcceptConfig, validatePaymentConfig, validateRouteConfig, validateTransferWithAuthorization, verifyPayment };
1739
+ export { EIP712_TYPES, ERC20_ABI, EURC_BASE, NETWORKS, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_SIGNATURE_HEADER, PaymentException, SCHEMES, SKL_SKALE_BASE, SKL_SKALE_BASE_SEPOLIA, SigningError, TOKENS, USDC_BASE, USDC_BASE_SEPOLIA, USDC_DOMAIN, USDC_SKALE_BASE, USDC_SKALE_BASE_SEPOLIA, USDT_SKALE_BASE, USDT_SKALE_BASE_SEPOLIA, V2_HEADERS, WBTC_SKALE_BASE, WBTC_SKALE_BASE_SEPOLIA, WETH_SKALE_BASE, WETH_SKALE_BASE_SEPOLIA, X402ClientError, X402_VERSION, addressToAssetId, assetIdToAddress, caip2ToNetwork, calculateValidBefore, checkFacilitatorSupport, combineSignature as combineSignatureV2, createEIP712Domain, createError, createNonce, createPaymentRequiredHeaders, createPaymentRequirements, createSettlementHeaders, createTransferWithAuthorization, decodeBase64ToUtf8, decodePayloadHeader, decodePayment, decodePaymentV2, decodeSettlementResponse, decodeSettlementV2, decodeX402Response, detectPaymentVersion, detectX402Version, encodePayment, encodePaymentV2, encodeSettlementResponse, encodeSettlementV2, encodeUtf8ToBase64, encodeX402Response, extractPayerAddress, extractPaymentFromHeaders, findMatchingRoute, findRequirementByNetwork, fromAtomicUnits, generateNonce, getAllCustomTokens, getAllTokens, getAvailableNetworks, getAvailableTokens, getCurrentTimestamp, getCustomToken, getEURCTokens, getMainnets, getNetworkByChainId, getNetworkConfig, getPaymentHeaderName, getSKLTokens, getSupported, getTestnets, getToken, getTokensByChain, getTokensBySymbol, getTxHash, getUSDCTokens, getUSDTTokens, getWBTCTokens, getWETHTokens, isAddress2 as isAddress, isCAIP2ChainId, isCAIPAssetId, isCustomToken, isExactEvmPayload, isPaymentPayload, isPaymentPayloadV2, isPaymentRequiredV2, isPaymentV2, isResolvedNetwork, isResolvedToken, isSettlementSuccessful, isSettlementV2, isValidAddress, isValidationError, isX402V2Payload, isX402V2PaymentRequired, isX402V2Requirements, isX402V2Settlement, matchRoute, networkToCaip2, normalizeAddress, normalizeBase64Url, normalizeNetworkName, parseJsonOrBase64, parseRoutePattern, parseSignature as parseSignatureV2, registerToken, resolveFacilitator, resolveNetwork, resolveToken, runAfterPaymentResponseHooks, runBeforeSignPaymentHooks, runOnPaymentRequiredHooks, safeBase64Decode2 as safeBase64Decode, safeBase64Encode2 as safeBase64Encode, selectRequirementWithHooks, settlePayment, toAtomicUnits, toBase64Url, unregisterToken, validateAcceptConfig, validatePaymentConfig, validateRouteConfig, validateTransferWithAuthorization, verifyPayment };
@@ -11,7 +11,9 @@ import type { Address, Extensions, PaymentPayloadV2, PaymentRequirementsV2 } fro
11
11
  export interface PaymentRequiredContext {
12
12
  url: RequestInfo | URL;
13
13
  requestInit: RequestInit | undefined;
14
+ accepts: PaymentRequirementsV2[];
14
15
  requirements: PaymentRequirementsV2;
16
+ selectedRequirement?: PaymentRequirementsV2;
15
17
  serverExtensions: Extensions | undefined;
16
18
  fromAddress: Address;
17
19
  nonce: `0x${string}`;
@@ -33,3 +35,17 @@ export interface HookConfig<TWallet = unknown> {
33
35
  name?: string;
34
36
  }
35
37
  export type HookRegistry<TWallet = unknown> = Record<string, HookConfig<TWallet>>;
38
+ export interface ClientHookErrorContext {
39
+ error: unknown;
40
+ phase: "onPaymentRequired" | "selectRequirement" | "beforeSignPayment" | "afterPaymentResponse";
41
+ }
42
+ export interface ClientHook<TWallet = unknown> {
43
+ name?: string;
44
+ onPaymentRequired?: (context: PaymentRequiredContext) => HookResult;
45
+ selectRequirement?: (context: PaymentRequiredContext) => PaymentRequirementsV2 | undefined | Promise<PaymentRequirementsV2 | undefined>;
46
+ beforeSignPayment?: (context: PaymentPayloadContext<TWallet>) => HookResult;
47
+ afterPaymentResponse?: (context: PaymentPayloadContext<TWallet> & {
48
+ response: Response;
49
+ }) => HookResult;
50
+ onError?: (context: ClientHookErrorContext) => HookResult;
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/base",
3
- "version": "0.2.27-alpha.23.77",
3
+ "version": "0.2.27-alpha.23.78",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "keywords": [
@@ -28,10 +28,21 @@
28
28
  "bun": "./dist/index.js",
29
29
  "default": "./dist/index.js"
30
30
  },
31
+ "./types/hooks": {
32
+ "types": "./src/types/hooks.ts",
33
+ "bun": "./src/types/hooks.ts",
34
+ "default": "./src/types/hooks.ts"
35
+ },
36
+ "./client-hooks-runtime": {
37
+ "types": "./src/client-hooks-runtime.ts",
38
+ "bun": "./src/client-hooks-runtime.ts",
39
+ "default": "./src/client-hooks-runtime.ts"
40
+ },
31
41
  "./dist/*": "./dist/*.js"
32
42
  },
33
43
  "files": [
34
44
  "dist",
45
+ "src",
35
46
  "README.md"
36
47
  ],
37
48
  "publishConfig": {
@@ -0,0 +1,84 @@
1
+ export type TransferWithAuthorizationParams = readonly [
2
+ from: `0x${string}`,
3
+ to: `0x${string}`,
4
+ amount: bigint,
5
+ validAfter: bigint,
6
+ expiry: bigint,
7
+ v: number,
8
+ r: `0x${string}`,
9
+ s: `0x${string}`,
10
+ ];
11
+
12
+ export type ReceiveWithAuthorizationParams = readonly [
13
+ from: `0x${string}`,
14
+ to: `0x${string}`,
15
+ amount: bigint,
16
+ validAfter: bigint,
17
+ expiry: bigint,
18
+ v: number,
19
+ r: `0x${string}`,
20
+ s: `0x${string}`,
21
+ ];
22
+
23
+ export type BalanceOfParams = readonly [account: `0x${string}`];
24
+ export type BalanceOfReturnType = bigint;
25
+ export type NameReturnType = string;
26
+ export type SymbolReturnType = string;
27
+
28
+ export const ERC20_ABI = [
29
+ {
30
+ type: "function",
31
+ name: "transferWithAuthorization",
32
+ stateMutability: "nonpayable",
33
+ inputs: [
34
+ { name: "from", type: "address" },
35
+ { name: "to", type: "address" },
36
+ { name: "amount", type: "uint256" },
37
+ { name: "validAfter", type: "uint256" },
38
+ { name: "expiry", type: "uint256" },
39
+ { name: "v", type: "uint8" },
40
+ { name: "r", type: "bytes32" },
41
+ { name: "s", type: "bytes32" },
42
+ ],
43
+ outputs: [],
44
+ },
45
+ {
46
+ type: "function",
47
+ name: "receiveWithAuthorization",
48
+ stateMutability: "nonpayable",
49
+ inputs: [
50
+ { name: "from", type: "address" },
51
+ { name: "to", type: "address" },
52
+ { name: "amount", type: "uint256" },
53
+ { name: "validAfter", type: "uint256" },
54
+ { name: "expiry", type: "uint256" },
55
+ { name: "v", type: "uint8" },
56
+ { name: "r", type: "bytes32" },
57
+ { name: "s", type: "bytes32" },
58
+ ],
59
+ outputs: [],
60
+ },
61
+ {
62
+ type: "function",
63
+ name: "balanceOf",
64
+ stateMutability: "view",
65
+ inputs: [{ name: "account", type: "address" }],
66
+ outputs: [{ name: "balance", type: "uint256" }],
67
+ },
68
+ {
69
+ type: "function",
70
+ name: "name",
71
+ stateMutability: "view",
72
+ inputs: [],
73
+ outputs: [{ name: "", type: "string" }],
74
+ },
75
+ {
76
+ type: "function",
77
+ name: "symbol",
78
+ stateMutability: "view",
79
+ inputs: [],
80
+ outputs: [{ name: "", type: "string" }],
81
+ },
82
+ ] as const;
83
+
84
+ export type ERC20Abi = typeof ERC20_ABI;
@@ -0,0 +1,133 @@
1
+ import type {
2
+ ClientHook,
3
+ ClientHookErrorContext,
4
+ PaymentPayloadContext,
5
+ PaymentRequiredContext,
6
+ } from "./types/hooks";
7
+ import type { PaymentRequirementsV2 } from "./types/v2";
8
+
9
+ const notifyError = async <TWallet>(
10
+ hooks: ClientHook<TWallet>[] | undefined,
11
+ context: ClientHookErrorContext,
12
+ ): Promise<void> => {
13
+ if (!hooks?.length) {
14
+ return;
15
+ }
16
+
17
+ for (const hook of hooks) {
18
+ if (!hook.onError) {
19
+ continue;
20
+ }
21
+ await hook.onError(context);
22
+ }
23
+ };
24
+
25
+ export const runOnPaymentRequiredHooks = async <TWallet>(
26
+ hooks: ClientHook<TWallet>[] | undefined,
27
+ context: PaymentRequiredContext,
28
+ ): Promise<void> => {
29
+ if (!hooks?.length) {
30
+ return;
31
+ }
32
+
33
+ for (const hook of hooks) {
34
+ if (!hook.onPaymentRequired) {
35
+ continue;
36
+ }
37
+ try {
38
+ await hook.onPaymentRequired(context);
39
+ } catch (error) {
40
+ await notifyError(hooks, { error, phase: "onPaymentRequired" });
41
+ throw error;
42
+ }
43
+ }
44
+ };
45
+
46
+ export const selectRequirementWithHooks = async <TWallet>(
47
+ hooks: ClientHook<TWallet>[] | undefined,
48
+ context: PaymentRequiredContext,
49
+ ): Promise<PaymentRequirementsV2> => {
50
+ if (!context.accepts.length) {
51
+ throw new Error("No payment requirements found in accepts array");
52
+ }
53
+
54
+ let selected = context.accepts[0];
55
+
56
+ if (!hooks?.length) {
57
+ context.selectedRequirement = selected;
58
+ context.requirements = selected;
59
+ return selected;
60
+ }
61
+
62
+ for (const hook of hooks) {
63
+ if (!hook.selectRequirement) {
64
+ continue;
65
+ }
66
+ try {
67
+ const override = await hook.selectRequirement({
68
+ ...context,
69
+ selectedRequirement: selected,
70
+ requirements: selected,
71
+ });
72
+ if (!override) {
73
+ continue;
74
+ }
75
+ const isValid = context.accepts.some((accept) => accept === override);
76
+ if (!isValid) {
77
+ throw new Error(
78
+ "Hook selectRequirement must return an item from accepts",
79
+ );
80
+ }
81
+ selected = override;
82
+ } catch (error) {
83
+ await notifyError(hooks, { error, phase: "selectRequirement" });
84
+ throw error;
85
+ }
86
+ }
87
+
88
+ context.selectedRequirement = selected;
89
+ context.requirements = selected;
90
+ return selected;
91
+ };
92
+
93
+ export const runBeforeSignPaymentHooks = async <TWallet>(
94
+ hooks: ClientHook<TWallet>[] | undefined,
95
+ context: PaymentPayloadContext<TWallet>,
96
+ ): Promise<void> => {
97
+ if (!hooks?.length) {
98
+ return;
99
+ }
100
+
101
+ for (const hook of hooks) {
102
+ if (!hook.beforeSignPayment) {
103
+ continue;
104
+ }
105
+ try {
106
+ await hook.beforeSignPayment(context);
107
+ } catch (error) {
108
+ await notifyError(hooks, { error, phase: "beforeSignPayment" });
109
+ throw error;
110
+ }
111
+ }
112
+ };
113
+
114
+ export const runAfterPaymentResponseHooks = async <TWallet>(
115
+ hooks: ClientHook<TWallet>[] | undefined,
116
+ context: PaymentPayloadContext<TWallet> & { response: Response },
117
+ ): Promise<void> => {
118
+ if (!hooks?.length) {
119
+ return;
120
+ }
121
+
122
+ for (const hook of hooks) {
123
+ if (!hook.afterPaymentResponse) {
124
+ continue;
125
+ }
126
+ try {
127
+ await hook.afterPaymentResponse(context);
128
+ } catch (error) {
129
+ await notifyError(hooks, { error, phase: "afterPaymentResponse" });
130
+ throw error;
131
+ }
132
+ }
133
+ };
@@ -0,0 +1,199 @@
1
+ import type { CustomToken } from "../types/networks";
2
+
3
+ export const USDC_BASE: CustomToken = {
4
+ symbol: "USDC",
5
+ name: "USDC",
6
+ version: "2",
7
+ contractAddress:
8
+ "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" as `0x${string}`,
9
+ chainId: 8453,
10
+ decimals: 6,
11
+ };
12
+
13
+ export const EURC_BASE: CustomToken = {
14
+ symbol: "EURC",
15
+ name: "EURC",
16
+ version: "2",
17
+ contractAddress:
18
+ "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42" as `0x${string}`,
19
+ chainId: 8453,
20
+ decimals: 6,
21
+ };
22
+
23
+ export const USDC_BASE_SEPOLIA: CustomToken = {
24
+ symbol: "USDC",
25
+ name: "USDC",
26
+ version: "2",
27
+ contractAddress:
28
+ "0x036CbD53842c5426634e7929541eC2318f3dCF7e" as `0x${string}`,
29
+ chainId: 84532,
30
+ decimals: 6,
31
+ };
32
+
33
+ export const USDC_SKALE_BASE: CustomToken = {
34
+ symbol: "USDC",
35
+ name: "Bridged USDC (SKALE Bridge)",
36
+ version: "2",
37
+ contractAddress:
38
+ "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20" as `0x${string}`,
39
+ chainId: 1187947933,
40
+ decimals: 6,
41
+ };
42
+
43
+ export const SKL_SKALE_BASE: CustomToken = {
44
+ symbol: "SKL",
45
+ name: "SKALE",
46
+ version: "1",
47
+ contractAddress:
48
+ "0xE0595a049d02b7674572b0d59cd4880Db60EDC50" as `0x${string}`,
49
+ chainId: 1187947933,
50
+ decimals: 18,
51
+ };
52
+
53
+ export const USDT_SKALE_BASE: CustomToken = {
54
+ symbol: "USDT",
55
+ name: "Tether USD",
56
+ version: "1",
57
+ contractAddress:
58
+ "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA" as `0x${string}`,
59
+ chainId: 1187947933,
60
+ decimals: 6,
61
+ };
62
+
63
+ export const WBTC_SKALE_BASE: CustomToken = {
64
+ symbol: "WBTC",
65
+ name: "Wrapped BTC",
66
+ version: "1",
67
+ contractAddress:
68
+ "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e" as `0x${string}`,
69
+ chainId: 1187947933,
70
+ decimals: 8,
71
+ };
72
+
73
+ export const WETH_SKALE_BASE: CustomToken = {
74
+ symbol: "WETH",
75
+ name: "Wrapped Ether",
76
+ version: "1",
77
+ contractAddress:
78
+ "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486" as `0x${string}`,
79
+ chainId: 1187947933,
80
+ decimals: 18,
81
+ };
82
+
83
+ export const SKL_SKALE_BASE_SEPOLIA: CustomToken = {
84
+ symbol: "SKL",
85
+ name: "SKALE",
86
+ version: "1",
87
+ contractAddress:
88
+ "0xaf2e0ff5b5f51553fdb34ce7f04a6c3201cee57b" as `0x${string}`,
89
+ chainId: 324705682,
90
+ decimals: 18,
91
+ };
92
+
93
+ export const USDC_SKALE_BASE_SEPOLIA: CustomToken = {
94
+ symbol: "USDC",
95
+ name: "Bridged USDC (SKALE Bridge)",
96
+ version: "2",
97
+ contractAddress:
98
+ "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD" as `0x${string}`,
99
+ chainId: 324705682,
100
+ decimals: 6,
101
+ };
102
+
103
+ export const USDT_SKALE_BASE_SEPOLIA: CustomToken = {
104
+ symbol: "USDT",
105
+ name: "Tether USD",
106
+ version: "1",
107
+ contractAddress:
108
+ "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf" as `0x${string}`,
109
+ chainId: 324705682,
110
+ decimals: 6,
111
+ };
112
+
113
+ export const WBTC_SKALE_BASE_SEPOLIA: CustomToken = {
114
+ symbol: "WBTC",
115
+ name: "Wrapped BTC",
116
+ version: "1",
117
+ contractAddress:
118
+ "0x4512eacd4186b025186e1cf6cc0d89497c530e87" as `0x${string}`,
119
+ chainId: 324705682,
120
+ decimals: 8,
121
+ };
122
+
123
+ export const WETH_SKALE_BASE_SEPOLIA: CustomToken = {
124
+ symbol: "WETH",
125
+ name: "Wrapped Ether",
126
+ version: "1",
127
+ contractAddress:
128
+ "0xf94056bd7f6965db3757e1b145f200b7346b4fc0" as `0x${string}`,
129
+ chainId: 324705682,
130
+ decimals: 18,
131
+ };
132
+
133
+ export const TOKENS = {
134
+ USDC_BASE,
135
+ USDC_BASE_SEPOLIA,
136
+ EURC_BASE,
137
+ USDC_SKALE_BASE,
138
+ USDT_SKALE_BASE,
139
+ WBTC_SKALE_BASE,
140
+ WETH_SKALE_BASE,
141
+ SKL_SKALE_BASE,
142
+ SKL_SKALE_BASE_SEPOLIA,
143
+ USDC_SKALE_BASE_SEPOLIA,
144
+ USDT_SKALE_BASE_SEPOLIA,
145
+ WBTC_SKALE_BASE_SEPOLIA,
146
+ WETH_SKALE_BASE_SEPOLIA,
147
+ } as const;
148
+
149
+ function getToken(
150
+ chainId: number,
151
+ contractAddress: string,
152
+ ): CustomToken | undefined {
153
+ const tokens = Object.values(TOKENS);
154
+ return tokens.find(
155
+ (t) =>
156
+ t.chainId === chainId &&
157
+ t.contractAddress.toLowerCase() === contractAddress.toLowerCase(),
158
+ );
159
+ }
160
+
161
+ function getAllTokens(): CustomToken[] {
162
+ return Object.values(TOKENS);
163
+ }
164
+
165
+ function getTokensBySymbol(symbol: string): CustomToken[] {
166
+ return getAllTokens().filter(
167
+ (t) => t.symbol.toUpperCase() === symbol.toUpperCase(),
168
+ );
169
+ }
170
+
171
+ function getTokensByChain(chainId: number): CustomToken[] {
172
+ return getAllTokens().filter((t) => t.chainId === chainId);
173
+ }
174
+
175
+ export function getUSDCTokens(): CustomToken[] {
176
+ return getTokensBySymbol("USDC");
177
+ }
178
+
179
+ export function getEURCTokens(): CustomToken[] {
180
+ return getTokensBySymbol("EURC");
181
+ }
182
+
183
+ export function getSKLTokens(): CustomToken[] {
184
+ return getTokensBySymbol("SKL");
185
+ }
186
+
187
+ export function getUSDTTokens(): CustomToken[] {
188
+ return getTokensBySymbol("USDT");
189
+ }
190
+
191
+ export function getWBTCTokens(): CustomToken[] {
192
+ return getTokensBySymbol("WBTC");
193
+ }
194
+
195
+ export function getWETHTokens(): CustomToken[] {
196
+ return getTokensBySymbol("WETH");
197
+ }
198
+
199
+ export { getToken, getAllTokens, getTokensBySymbol, getTokensByChain };