@oydual31/more-vaults-sdk 1.1.0 → 1.1.2

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.
@@ -997,6 +997,8 @@ interface InboundRoute {
997
997
  lzFeeEstimate: bigint;
998
998
  /** Native gas token symbol for the spoke chain — use this when displaying the fee */
999
999
  nativeSymbol: string;
1000
+ /** Decimals of spokeToken — use this with formatUnits(userBalance, decimals) */
1001
+ decimals: number;
1000
1002
  }
1001
1003
  interface InboundRouteWithBalance extends InboundRoute {
1002
1004
  /** User's token balance on the spoke chain */
@@ -997,6 +997,8 @@ interface InboundRoute {
997
997
  lzFeeEstimate: bigint;
998
998
  /** Native gas token symbol for the spoke chain — use this when displaying the fee */
999
999
  nativeSymbol: string;
1000
+ /** Decimals of spokeToken — use this with formatUnits(userBalance, decimals) */
1001
+ decimals: number;
1000
1002
  }
1001
1003
  interface InboundRouteWithBalance extends InboundRoute {
1002
1004
  /** User's token balance on the spoke chain */
@@ -1553,6 +1553,7 @@ function createChainClient(chainId) {
1553
1553
  });
1554
1554
  }
1555
1555
  var SYMBOL_ABI = [{ name: "symbol", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] }];
1556
+ var DECIMALS_ABI = [{ name: "decimals", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "uint8" }] }];
1556
1557
  async function readTokenSymbol(client, token, fallbackSymbol) {
1557
1558
  if (!client) return fallbackSymbol;
1558
1559
  try {
@@ -1561,6 +1562,14 @@ async function readTokenSymbol(client, token, fallbackSymbol) {
1561
1562
  return fallbackSymbol;
1562
1563
  }
1563
1564
  }
1565
+ async function readTokenDecimals(client, token) {
1566
+ if (!client) return 18;
1567
+ try {
1568
+ return await client.readContract({ address: token, abi: DECIMALS_ABI, functionName: "decimals" });
1569
+ } catch {
1570
+ return 18;
1571
+ }
1572
+ }
1564
1573
  Object.fromEntries(
1565
1574
  Object.entries(PUBLIC_RPCS).map(([k, v]) => [k, v[0]])
1566
1575
  );
@@ -1591,7 +1600,7 @@ async function _getRoutesForAsset(hubChainId, hubEid, vault, singleAsset, userAd
1591
1600
  try {
1592
1601
  const receiverBytes32 = `0x${viem.getAddress(userAddress).slice(2).padStart(64, "0")}`;
1593
1602
  const spokeTokenAddr = viem.getAddress(spokeEntry.token);
1594
- const [fee, sourceTokenSymbol] = await Promise.all([
1603
+ const [fee, sourceTokenSymbol, decimals] = await Promise.all([
1595
1604
  client.readContract({
1596
1605
  address: viem.getAddress(spokeEntry.oft),
1597
1606
  abi: OFT_ABI,
@@ -1606,7 +1615,8 @@ async function _getRoutesForAsset(hubChainId, hubEid, vault, singleAsset, userAd
1606
1615
  oftCmd
1607
1616
  }, false]
1608
1617
  }),
1609
- readTokenSymbol(client, spokeTokenAddr, symbol)
1618
+ readTokenSymbol(client, spokeTokenAddr, symbol),
1619
+ readTokenDecimals(client, spokeTokenAddr)
1610
1620
  ]);
1611
1621
  results.push({
1612
1622
  symbol,
@@ -1618,7 +1628,8 @@ async function _getRoutesForAsset(hubChainId, hubEid, vault, singleAsset, userAd
1618
1628
  hubOft: viem.getAddress(hubEntry.oft),
1619
1629
  oftCmd,
1620
1630
  lzFeeEstimate: fee.nativeFee,
1621
- nativeSymbol: NATIVE_SYMBOL[spokeChainId] ?? "ETH"
1631
+ nativeSymbol: NATIVE_SYMBOL[spokeChainId] ?? "ETH",
1632
+ decimals
1622
1633
  });
1623
1634
  } catch {
1624
1635
  }
@@ -1633,9 +1644,10 @@ async function _getRoutesForAsset(hubChainId, hubEid, vault, singleAsset, userAd
1633
1644
  if (hubOftEntry) {
1634
1645
  const { symbol, hubEntry } = hubOftEntry;
1635
1646
  const hubTokenAddr = viem.getAddress(hubEntry.token);
1636
- const [sourceTokenSymbol, lzFeeEstimate] = await Promise.all([
1647
+ const [sourceTokenSymbol, lzFeeEstimate, decimals] = await Promise.all([
1637
1648
  readTokenSymbol(hubClient, hubTokenAddr, symbol),
1638
- asyncMode ? quoteLzFee(hubClient, vault) : Promise.resolve(0n)
1649
+ asyncMode ? quoteLzFee(hubClient, vault) : Promise.resolve(0n),
1650
+ readTokenDecimals(hubClient, hubTokenAddr)
1639
1651
  ]);
1640
1652
  results.unshift({
1641
1653
  symbol,
@@ -1647,13 +1659,15 @@ async function _getRoutesForAsset(hubChainId, hubEid, vault, singleAsset, userAd
1647
1659
  hubOft: null,
1648
1660
  oftCmd: "0x",
1649
1661
  lzFeeEstimate,
1650
- nativeSymbol: NATIVE_SYMBOL[hubChainId] ?? "ETH"
1662
+ nativeSymbol: NATIVE_SYMBOL[hubChainId] ?? "ETH",
1663
+ decimals
1651
1664
  });
1652
1665
  } else {
1653
1666
  const hubTokenAddr = asset;
1654
- const [sourceTokenSymbol, lzFeeEstimate] = await Promise.all([
1667
+ const [sourceTokenSymbol, lzFeeEstimate, decimals] = await Promise.all([
1655
1668
  readTokenSymbol(hubClient, hubTokenAddr, "UNKNOWN"),
1656
- asyncMode ? quoteLzFee(hubClient, vault) : Promise.resolve(0n)
1669
+ asyncMode ? quoteLzFee(hubClient, vault) : Promise.resolve(0n),
1670
+ readTokenDecimals(hubClient, hubTokenAddr)
1657
1671
  ]);
1658
1672
  results.unshift({
1659
1673
  symbol: sourceTokenSymbol,
@@ -1665,7 +1679,8 @@ async function _getRoutesForAsset(hubChainId, hubEid, vault, singleAsset, userAd
1665
1679
  hubOft: null,
1666
1680
  oftCmd: "0x",
1667
1681
  lzFeeEstimate,
1668
- nativeSymbol: NATIVE_SYMBOL[hubChainId] ?? "ETH"
1682
+ nativeSymbol: NATIVE_SYMBOL[hubChainId] ?? "ETH",
1683
+ decimals
1669
1684
  });
1670
1685
  }
1671
1686
  return results;
@@ -3729,13 +3744,16 @@ function getRouteTokenDecimals(symbol) {
3729
3744
  case "stgUSDC":
3730
3745
  case "USDT":
3731
3746
  case "USDC":
3747
+ case "PYUSD":
3748
+ case "PYUSD0":
3732
3749
  return 6;
3733
3750
  default:
3734
3751
  return 18;
3735
3752
  }
3736
3753
  }
3737
3754
  function useInboundRoutes(hubChainId, vault, vaultAsset, userAddress) {
3738
- const enabled = hubChainId != null && !!vault && !!vaultAsset && !!userAddress;
3755
+ const hasAsset = Array.isArray(vaultAsset) ? vaultAsset.length > 0 : !!vaultAsset;
3756
+ const enabled = hubChainId != null && !!vault && hasAsset && !!userAddress;
3739
3757
  const { data, isLoading, error } = reactQuery.useQuery({
3740
3758
  queryKey: ["inboundRoutes", hubChainId, vault, vaultAsset, userAddress],
3741
3759
  queryFn: async () => {