@oydual31/more-vaults-sdk 0.2.6 → 0.2.8

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.
@@ -331,9 +331,12 @@ declare function getVaultSummary(publicClient: PublicClient, vault: Address): Pr
331
331
  interface MultiChainUserPosition {
332
332
  /** Shares held directly on the hub vault (vault.balanceOf) */
333
333
  hubShares: bigint;
334
- /** Per-spoke SHARE_OFT balances: { [chainId]: bigint } */
334
+ /** Per-spoke SHARE_OFT balances normalized to vault decimals: { [chainId]: bigint } */
335
335
  spokeShares: Record<number, bigint>;
336
- /** hubShares + sum of all spokeShares */
336
+ /** Per-spoke SHARE_OFT raw balances in OFT native decimals: { [chainId]: bigint }
337
+ * Use these for bridgeSharesToHub() and quoteShareBridgeFee() */
338
+ rawSpokeShares: Record<number, bigint>;
339
+ /** hubShares + sum of all spokeShares (in vault decimals) */
337
340
  totalShares: bigint;
338
341
  /** convertToAssets(totalShares) on the hub */
339
342
  estimatedAssets: bigint;
@@ -331,9 +331,12 @@ declare function getVaultSummary(publicClient: PublicClient, vault: Address): Pr
331
331
  interface MultiChainUserPosition {
332
332
  /** Shares held directly on the hub vault (vault.balanceOf) */
333
333
  hubShares: bigint;
334
- /** Per-spoke SHARE_OFT balances: { [chainId]: bigint } */
334
+ /** Per-spoke SHARE_OFT balances normalized to vault decimals: { [chainId]: bigint } */
335
335
  spokeShares: Record<number, bigint>;
336
- /** hubShares + sum of all spokeShares */
336
+ /** Per-spoke SHARE_OFT raw balances in OFT native decimals: { [chainId]: bigint }
337
+ * Use these for bridgeSharesToHub() and quoteShareBridgeFee() */
338
+ rawSpokeShares: Record<number, bigint>;
339
+ /** hubShares + sum of all spokeShares (in vault decimals) */
337
340
  totalShares: bigint;
338
341
  /** convertToAssets(totalShares) on the hub */
339
342
  estimatedAssets: bigint;
@@ -2587,6 +2587,26 @@ async function smartRedeem(walletClient, publicClient, addresses, shares, receiv
2587
2587
  }
2588
2588
  return redeemShares(walletClient, publicClient, addresses, shares, receiver, owner);
2589
2589
  }
2590
+ async function quoteShareBridgeFee(spokePublicClient, shareOFT, hubChainEid, amountLD, receiver) {
2591
+ const oft = viem.getAddress(shareOFT);
2592
+ const toBytes32 = viem.pad(viem.getAddress(receiver), { size: 32 });
2593
+ const sendParam = {
2594
+ dstEid: hubChainEid,
2595
+ to: toBytes32,
2596
+ amountLD,
2597
+ minAmountLD: amountLD,
2598
+ extraOptions: "0x",
2599
+ composeMsg: "0x",
2600
+ oftCmd: "0x"
2601
+ };
2602
+ const feeResult = await spokePublicClient.readContract({
2603
+ address: oft,
2604
+ abi: OFT_ABI,
2605
+ functionName: "quoteSend",
2606
+ args: [sendParam, false]
2607
+ });
2608
+ return feeResult.nativeFee;
2609
+ }
2590
2610
  async function bridgeSharesToHub(walletClient, publicClient, shareOFT, hubChainEid, shares, receiver, lzFee) {
2591
2611
  const account = walletClient.account;
2592
2612
  const oft = viem.getAddress(shareOFT);
@@ -3020,6 +3040,7 @@ async function getUserPositionMultiChain(vault, user) {
3020
3040
  });
3021
3041
  const [withdrawShares, timelockEndsAt] = withdrawalRequest;
3022
3042
  const spokeShares = {};
3043
+ const rawSpokeShares = {};
3023
3044
  if (topo.spokeChainIds.length > 0) {
3024
3045
  let hubShareOft = null;
3025
3046
  try {
@@ -3042,7 +3063,7 @@ async function getUserPositionMultiChain(vault, user) {
3042
3063
  const spokePromises = topo.spokeChainIds.map(async (spokeChainId) => {
3043
3064
  try {
3044
3065
  const spokeEid = CHAIN_ID_TO_EID[spokeChainId];
3045
- if (!spokeEid) return { chainId: spokeChainId, balance: 0n };
3066
+ if (!spokeEid) return { chainId: spokeChainId, balance: 0n, rawBalance: 0n };
3046
3067
  const spokeOftBytes32 = await hubClient.readContract({
3047
3068
  address: hubShareOft,
3048
3069
  abi: OFT_ABI,
@@ -3051,24 +3072,34 @@ async function getUserPositionMultiChain(vault, user) {
3051
3072
  });
3052
3073
  const spokeOft = viem.getAddress(`0x${spokeOftBytes32.slice(-40)}`);
3053
3074
  if (spokeOft === "0x0000000000000000000000000000000000000000") {
3054
- return { chainId: spokeChainId, balance: 0n };
3075
+ return { chainId: spokeChainId, balance: 0n, rawBalance: 0n };
3055
3076
  }
3056
3077
  const spokeClient = createChainClient(spokeChainId);
3057
- if (!spokeClient) return { chainId: spokeChainId, balance: 0n };
3058
- const balance = await spokeClient.readContract({
3059
- address: spokeOft,
3060
- abi: ERC20_ABI,
3061
- functionName: "balanceOf",
3062
- args: [u]
3078
+ if (!spokeClient) return { chainId: spokeChainId, balance: 0n, rawBalance: 0n };
3079
+ const [rawBalance, spokeOftDecimals] = await spokeClient.multicall({
3080
+ contracts: [
3081
+ { address: spokeOft, abi: ERC20_ABI, functionName: "balanceOf", args: [u] },
3082
+ { address: spokeOft, abi: METADATA_ABI, functionName: "decimals" }
3083
+ ],
3084
+ allowFailure: false
3063
3085
  });
3064
- return { chainId: spokeChainId, balance };
3086
+ let balance;
3087
+ if (spokeOftDecimals > decimals) {
3088
+ balance = rawBalance / 10n ** BigInt(spokeOftDecimals - decimals);
3089
+ } else if (spokeOftDecimals < decimals) {
3090
+ balance = rawBalance * 10n ** BigInt(decimals - spokeOftDecimals);
3091
+ } else {
3092
+ balance = rawBalance;
3093
+ }
3094
+ return { chainId: spokeChainId, balance, rawBalance };
3065
3095
  } catch {
3066
- return { chainId: spokeChainId, balance: 0n };
3096
+ return { chainId: spokeChainId, balance: 0n, rawBalance: 0n };
3067
3097
  }
3068
3098
  });
3069
3099
  const results = await Promise.all(spokePromises);
3070
- for (const { chainId, balance } of results) {
3100
+ for (const { chainId, balance, rawBalance } of results) {
3071
3101
  spokeShares[chainId] = balance;
3102
+ rawSpokeShares[chainId] = rawBalance;
3072
3103
  }
3073
3104
  }
3074
3105
  }
@@ -3088,6 +3119,7 @@ async function getUserPositionMultiChain(vault, user) {
3088
3119
  return {
3089
3120
  hubShares,
3090
3121
  spokeShares,
3122
+ rawSpokeShares,
3091
3123
  totalShares,
3092
3124
  estimatedAssets,
3093
3125
  sharePrice,
@@ -3233,6 +3265,7 @@ exports.quoteComposeFee = quoteComposeFee;
3233
3265
  exports.quoteDepositFromSpokeFee = quoteDepositFromSpokeFee;
3234
3266
  exports.quoteLzFee = quoteLzFee;
3235
3267
  exports.quoteRouteDepositFee = quoteRouteDepositFee;
3268
+ exports.quoteShareBridgeFee = quoteShareBridgeFee;
3236
3269
  exports.redeemAsync = redeemAsync;
3237
3270
  exports.redeemShares = redeemShares;
3238
3271
  exports.requestRedeem = requestRedeem;