@oydual31/more-vaults-sdk 0.2.5 → 0.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oydual31/more-vaults-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "TypeScript SDK for MoreVaults protocol — viem/wagmi and ethers.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -766,12 +766,18 @@ export async function quoteComposeFee(
766
766
  * @param fee ETH to send (from quoteComposeFee). Covers readFee for D7.
767
767
  * @returns Transaction hash of the compose execution
768
768
  */
769
+ /**
770
+ * Event topic0 emitted by the escrow when initVaultActionRequest creates a new request.
771
+ * topic1 = GUID (bytes32). Used to extract the async request GUID from executeCompose receipts.
772
+ */
773
+ const ESCROW_REQUEST_TOPIC = '0x304ac8b57de34b9e6118fb049ba362689cfcfab98c30c9d78e3e2e14be7e0972' as const
774
+
769
775
  export async function executeCompose(
770
776
  walletClient: WalletClient,
771
777
  hubPublicClient: PublicClient,
772
778
  composeData: ComposeData,
773
779
  fee: bigint,
774
- ): Promise<{ txHash: Hash }> {
780
+ ): Promise<{ txHash: Hash; guid?: `0x${string}` }> {
775
781
  const account = walletClient.account!
776
782
  const endpoint = getAddress(composeData.endpoint)
777
783
 
@@ -811,5 +817,21 @@ export async function executeCompose(
811
817
  gas: 5_000_000n, // initVaultActionRequest + LZ Read is gas-heavy
812
818
  })
813
819
 
814
- return { txHash }
820
+ // Parse the GUID from the escrow's event in the TX receipt.
821
+ // The composer calls initVaultActionRequest internally, which emits an event
822
+ // with topic1 = GUID. We need this GUID to poll finalization via waitForAsyncRequest.
823
+ let guid: `0x${string}` | undefined
824
+ try {
825
+ const receipt = await hubPublicClient.waitForTransactionReceipt({ hash: txHash, timeout: 60_000 })
826
+ for (const log of receipt.logs) {
827
+ if (log.topics[0] === ESCROW_REQUEST_TOPIC && log.topics[1]) {
828
+ guid = log.topics[1] as `0x${string}`
829
+ break
830
+ }
831
+ }
832
+ } catch {
833
+ // Receipt timeout — guid will be undefined, caller can still poll by balance
834
+ }
835
+
836
+ return { txHash, guid }
815
837
  }
@@ -625,17 +625,29 @@ export async function getUserPositionMultiChain(
625
625
  return { chainId: spokeChainId, balance: 0n }
626
626
  }
627
627
 
628
- // Read balance on spoke chain
628
+ // Read balance + decimals on spoke chain
629
629
  const spokeClient = createChainClient(spokeChainId)
630
630
  if (!spokeClient) return { chainId: spokeChainId, balance: 0n }
631
631
 
632
- const balance = await (spokeClient as PublicClient).readContract({
633
- address: spokeOft,
634
- abi: ERC20_ABI,
635
- functionName: 'balanceOf',
636
- args: [u],
632
+ const [rawBalance, spokeOftDecimals] = await (spokeClient as PublicClient).multicall({
633
+ contracts: [
634
+ { address: spokeOft, abi: ERC20_ABI, functionName: 'balanceOf', args: [u] },
635
+ { address: spokeOft, abi: METADATA_ABI, functionName: 'decimals' },
636
+ ],
637
+ allowFailure: false,
637
638
  })
638
639
 
640
+ // Normalize SHARE_OFT balance to vault decimals
641
+ // Spoke OFTs may use different decimals (e.g. 18) than the vault shares (e.g. 8)
642
+ let balance: bigint
643
+ if (spokeOftDecimals > decimals) {
644
+ balance = rawBalance / (10n ** BigInt(spokeOftDecimals - decimals))
645
+ } else if (spokeOftDecimals < decimals) {
646
+ balance = rawBalance * (10n ** BigInt(decimals - spokeOftDecimals))
647
+ } else {
648
+ balance = rawBalance
649
+ }
650
+
639
651
  return { chainId: spokeChainId, balance }
640
652
  } catch {
641
653
  return { chainId: spokeChainId, balance: 0n }