@across-protocol/sdk 4.3.143-alpha.1 → 4.3.143

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.
@@ -14,8 +14,12 @@ import {
14
14
  union,
15
15
  type,
16
16
  } from "superstruct";
17
- import { CHAIN_IDs, UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
- import { BigNumber, EvmAddress, RawAddress, SvmAddress, toAddressType, toBytes32 } from "../../../utils";
17
+ import { utils as ethersUtils } from "ethers";
18
+ import { isAddress as isValidEvmAddress } from "viem";
19
+ import { isAddress as isValidSvmAddress } from "@solana/kit";
20
+ import { TronWeb } from "tronweb";
21
+ import { UNDEFINED_MESSAGE_HASH } from "../../../constants";
22
+ import { BigNumber, bs58, EvmAddress, RawAddress, SvmAddress, TvmAddress, toBytes32 } from "../../../utils";
19
23
 
20
24
  const PositiveIntegerStringSS = pattern(string(), /\d+/);
21
25
  const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{64}$/);
@@ -31,16 +35,26 @@ const BigNumberType = coerce(instance(BigNumber), union([string(), number()]), (
31
35
  }
32
36
  });
33
37
 
34
- // Accept any concrete implementation of `Address` (Evm, Svm, or Raw) but avoid using the
35
- // abstract `Address` class directly to keep TypeScript happy.
36
- const AddressInstanceSS = union([instance(EvmAddress), instance(SvmAddress), instance(RawAddress)]);
37
-
38
- const AddressType = coerce(AddressInstanceSS, string(), (value) => {
39
- // Addresses are posted to arweave in their native format (base16 for EVM, base58 for SVM). The chainId for
40
- // for the event data is not directly available, so infer it based on the shape of the address. RawAddress
41
- // will be instantiated if the address format does not match the expected family.
42
- const chainId = value.startsWith("0x") ? CHAIN_IDs.MAINNET : CHAIN_IDs.SOLANA;
43
- return toAddressType(value, chainId);
38
+ const AddressInstanceSS = union([
39
+ instance(EvmAddress),
40
+ instance(SvmAddress),
41
+ instance(TvmAddress),
42
+ instance(RawAddress),
43
+ ]);
44
+
45
+ export const AddressType = coerce(AddressInstanceSS, string(), (value) => {
46
+ // Each family is matched by its native-format validator plus a length gate where it
47
+ // disambiguates. Unknown shapes fall to `RawAddress`, forcing future families into explicit
48
+ // branches rather than being absorbed silently.
49
+ try {
50
+ // strict: false preserves the prior byte-level acceptance of all-upper / non-checksummed hex.
51
+ if (value.length === 42 && isValidEvmAddress(value, { strict: false })) return EvmAddress.from(value);
52
+ if (value.length === 34 && TronWeb.isAddress(value)) return TvmAddress.from(value);
53
+ if (isValidSvmAddress(value)) return SvmAddress.from(value);
54
+ } catch {
55
+ // Validator accepted but `from()` rejected (e.g. SVM 12-zero EVM-masquerade) → RawAddress.
56
+ }
57
+ return new RawAddress(value.startsWith("0x") ? ethersUtils.arrayify(value) : bs58.decode(value));
44
58
  });
45
59
 
46
60
  const Web3AddressType = coerce(Web3AddressSS, string(), (value) => {