@heyanon/sdk 2.3.7 → 2.3.9

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/dist/index.js CHANGED
@@ -604,6 +604,35 @@ function isAddress(value) {
604
604
  return result;
605
605
  }
606
606
 
607
+ // src/utils/get-timestamp.ts
608
+ var getTimestamp = () => Math.floor(Date.now() / 1e3);
609
+ var { NATIVE_ADDRESS: NATIVE_ADDRESS2, WETH9: WETH92 } = evm_exports.constants;
610
+ var { isEvmChain: isEvmChain2 } = evm_exports.utils;
611
+ function normalizeAddress(chain, address) {
612
+ const { valid } = isAddress(address);
613
+ if (!valid)
614
+ throw new Error(`This is not a address: ${address}`);
615
+ if (address.toLowerCase() === NATIVE_ADDRESS2.toLowerCase()) {
616
+ if (isEvmChain2(chain)) {
617
+ const weth9 = WETH92[chain];
618
+ if (!weth9)
619
+ throw new Error(`WETH9 not found for ${chain}`);
620
+ return weth9.address;
621
+ }
622
+ if (chain === "solana" /* SOLANA */) {
623
+ return "So11111111111111111111111111111111111111112";
624
+ }
625
+ if (chain === "ton" /* TON */) {
626
+ return "0:0000000000000000000000000000000000000000000000000000000000000000";
627
+ }
628
+ }
629
+ if (chain === "ton" /* TON */) {
630
+ const tonAddress = ton.Address.parse(address);
631
+ return tonAddress.toRawString();
632
+ }
633
+ return address;
634
+ }
635
+
607
636
  // src/adapter/transformers/toResult.ts
608
637
  function toResult(data, error = false) {
609
638
  const formatedData = typeof data === "string" ? data : stringify(data);
@@ -638,7 +667,9 @@ exports.TON = ton_exports;
638
667
  exports.WalletType = WalletType;
639
668
  exports.allChains = allChains;
640
669
  exports.allEvmChains = allEvmChains;
670
+ exports.getTimestamp = getTimestamp;
641
671
  exports.isAddress = isAddress;
672
+ exports.normalizeAddress = normalizeAddress;
642
673
  exports.retry = retry;
643
674
  exports.sleep = sleep;
644
675
  exports.stringify = stringify;
package/dist/index.mjs CHANGED
@@ -602,6 +602,35 @@ function isAddress(value) {
602
602
  return result;
603
603
  }
604
604
 
605
+ // src/utils/get-timestamp.ts
606
+ var getTimestamp = () => Math.floor(Date.now() / 1e3);
607
+ var { NATIVE_ADDRESS: NATIVE_ADDRESS2, WETH9: WETH92 } = evm_exports.constants;
608
+ var { isEvmChain: isEvmChain2 } = evm_exports.utils;
609
+ function normalizeAddress(chain, address) {
610
+ const { valid } = isAddress(address);
611
+ if (!valid)
612
+ throw new Error(`This is not a address: ${address}`);
613
+ if (address.toLowerCase() === NATIVE_ADDRESS2.toLowerCase()) {
614
+ if (isEvmChain2(chain)) {
615
+ const weth9 = WETH92[chain];
616
+ if (!weth9)
617
+ throw new Error(`WETH9 not found for ${chain}`);
618
+ return weth9.address;
619
+ }
620
+ if (chain === "solana" /* SOLANA */) {
621
+ return "So11111111111111111111111111111111111111112";
622
+ }
623
+ if (chain === "ton" /* TON */) {
624
+ return "0:0000000000000000000000000000000000000000000000000000000000000000";
625
+ }
626
+ }
627
+ if (chain === "ton" /* TON */) {
628
+ const tonAddress = Address.parse(address);
629
+ return tonAddress.toRawString();
630
+ }
631
+ return address;
632
+ }
633
+
605
634
  // src/adapter/transformers/toResult.ts
606
635
  function toResult(data, error = false) {
607
636
  const formatedData = typeof data === "string" ? data : stringify(data);
@@ -628,4 +657,4 @@ var AdapterTag = /* @__PURE__ */ ((AdapterTag2) => {
628
657
  return AdapterTag2;
629
658
  })(AdapterTag || {});
630
659
 
631
- export { AdapterTag, Chain, evm_exports as EVM, solana_exports as Solana, ton_exports as TON, WalletType, allChains, allEvmChains, isAddress, retry, sleep, stringify, toResult };
660
+ export { AdapterTag, Chain, evm_exports as EVM, solana_exports as Solana, ton_exports as TON, WalletType, allChains, allEvmChains, getTimestamp, isAddress, normalizeAddress, retry, sleep, stringify, toResult };
@@ -0,0 +1 @@
1
+ export declare const getTimestamp: () => number;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,3 +2,5 @@ export * from './retry';
2
2
  export * from './sleep';
3
3
  export * from './stringify';
4
4
  export * from './is-address';
5
+ export * from './get-timestamp';
6
+ export * from './normalize-address';
@@ -0,0 +1,82 @@
1
+ import { Chain } from '../blockchain';
2
+ /**
3
+ * Normalizes a blockchain address to its canonical form for a specific chain
4
+ *
5
+ * This function performs chain-specific address normalization:
6
+ * - Converts native token address (0xEee...eEe) to wrapped token address (WETH, WMATIC, etc.)
7
+ * - Converts TON addresses to raw string format
8
+ * - Validates address format before normalization
9
+ *
10
+ * @param chain - The blockchain network (Ethereum, Polygon, Solana, TON, etc.)
11
+ * @param address - The address to normalize
12
+ * @returns Normalized address in canonical format
13
+ * @throws Error if address is invalid or WETH9 is not found for the chain
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // EVM: Convert native address to WETH9
18
+ * const normalized = normalizeAddress(
19
+ * Chain.ETHEREUM,
20
+ * '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
21
+ * );
22
+ * // Returns: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' (WETH on Ethereum)
23
+ *
24
+ * // Polygon: Native to Wrapped
25
+ * const wmatic = normalizeAddress(
26
+ * Chain.POLYGON,
27
+ * '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
28
+ * );
29
+ * // Returns: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270' (WMATIC)
30
+ *
31
+ * // Solana: Native address to wrapped SOL
32
+ * const wsol = normalizeAddress(
33
+ * Chain.SOLANA,
34
+ * '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'
35
+ * );
36
+ * // Returns: 'So11111111111111111111111111111111111111112' (Wrapped SOL)
37
+ *
38
+ * // TON: Convert to raw format
39
+ * const tonRaw = normalizeAddress(
40
+ * Chain.TON,
41
+ * 'EQD4FPq-PRDieyQKkizFTRtSDyucUIqrj0v_zXJmqaDp6_0t'
42
+ * );
43
+ * // Returns: '0:...' (raw format)
44
+ *
45
+ * // Regular EVM address (no change)
46
+ * const usdcAddress = normalizeAddress(
47
+ * Chain.ETHEREUM,
48
+ * '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
49
+ * );
50
+ * // Returns: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' (unchanged)
51
+ *
52
+ * // Token swap with normalization
53
+ * async function swapTokens(
54
+ * chain: Chain,
55
+ * tokenIn: string,
56
+ * tokenOut: string,
57
+ * amount: bigint
58
+ * ) {
59
+ * // Normalize addresses for consistent processing
60
+ * const normalizedTokenIn = normalizeAddress(chain, tokenIn);
61
+ * const normalizedTokenOut = normalizeAddress(chain, tokenOut);
62
+ *
63
+ * const swapData = await buildSwapTransaction(
64
+ * chain,
65
+ * normalizedTokenIn,
66
+ * normalizedTokenOut,
67
+ * amount
68
+ * );
69
+ *
70
+ * return swapData;
71
+ * }
72
+ *
73
+ * // Usage: Swap native ETH to USDC
74
+ * await swapTokens(
75
+ * Chain.ETHEREUM,
76
+ * '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // Native ETH
77
+ * '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
78
+ * BigInt('1000000000000000000')
79
+ * );
80
+ * ```
81
+ */
82
+ export declare function normalizeAddress(chain: Chain, address: string): string;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyanon/sdk",
3
- "version": "2.3.7",
3
+ "version": "2.3.9",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",