@oydual31/more-vaults-sdk 0.2.4 → 0.2.5

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.
@@ -153,8 +153,46 @@ declare function isAsyncMode(publicClient: PublicClient, vault: Address): Promis
153
153
  declare function getAsyncRequestStatus(publicClient: PublicClient, vault: Address, guid: `0x${string}`): Promise<{
154
154
  fulfilled: boolean;
155
155
  finalized: boolean;
156
+ refunded: boolean;
156
157
  result: bigint;
157
158
  }>;
159
+ interface AsyncRequestFinalResult {
160
+ /** 'completed' = assets/shares received, 'refunded' = tokens returned to user */
161
+ status: 'completed' | 'refunded';
162
+ /** For deposit: shares minted. For redeem: assets returned. 0 if refunded. */
163
+ result: bigint;
164
+ }
165
+ /**
166
+ * Poll an async cross-chain request until it finalizes or times out.
167
+ *
168
+ * This is the correct way to wait for smartDeposit/smartRedeem results on
169
+ * async vaults. Do NOT poll balance — use this instead, which reads the
170
+ * on-chain request state by GUID.
171
+ *
172
+ * @param publicClient Public client on the hub chain
173
+ * @param vault Vault address
174
+ * @param guid GUID from smartDeposit/smartRedeem result
175
+ * @param pollInterval Milliseconds between polls (default: 30_000)
176
+ * @param timeout Max wait time in milliseconds (default: 900_000 = 15 min)
177
+ * @param onPoll Optional callback invoked after each poll with current status
178
+ * @returns Final result with status and amount
179
+ * @throws Error if timeout is reached
180
+ *
181
+ * @example
182
+ * const depositResult = await smartDeposit(walletClient, publicClient, { vault }, amount, receiver)
183
+ * if ('guid' in depositResult) {
184
+ * const final = await waitForAsyncRequest(publicClient, vault, depositResult.guid, 30_000, 900_000, (s) => {
185
+ * console.log(`Status: fulfilled=${s.fulfilled}, finalized=${s.finalized}`)
186
+ * })
187
+ * console.log(`Done: ${final.status}, result: ${final.result}`)
188
+ * }
189
+ */
190
+ declare function waitForAsyncRequest(publicClient: PublicClient, vault: Address, guid: `0x${string}`, pollInterval?: number, timeout?: number, onPoll?: (status: {
191
+ fulfilled: boolean;
192
+ finalized: boolean;
193
+ refunded: boolean;
194
+ result: bigint;
195
+ }) => void): Promise<AsyncRequestFinalResult>;
158
196
 
159
197
  interface UserPosition {
160
198
  /** Vault share balance */
@@ -573,4 +611,4 @@ declare function getOutboundRoutes(hubChainId: number, vault: Address): Promise<
573
611
  */
574
612
  declare function quoteRouteDepositFee(route: InboundRoute, hubChainId: number, amount: bigint, userAddress: Address): Promise<bigint>;
575
613
 
576
- export { type AsyncRequestStatus as A, getVaultDistributionWithTopology as B, getVaultMetadata as C, type DepositBlockReason as D, getVaultStatus as E, getVaultSummary as F, getVaultTopology as G, isAsyncMode as H, type InboundRoute as I, isOnHubChain as J, previewDeposit as K, previewRedeem as L, type MaxWithdrawable as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, quoteLzFee as P, quoteRouteDepositFee as Q, waitForTx as R, type SpokeBalance as S, type UserBalances as U, type VaultDistribution as V, type AsyncRequestStatusInfo as a, type DepositEligibility as b, type InboundRouteWithBalance as c, type MultiChainUserPosition as d, type OutboundRoute as e, type UserPosition as f, type VaultMetadata as g, type VaultMode as h, type VaultStatus as i, type VaultSummary as j, type VaultTopology as k, canDeposit as l, discoverVaultTopology as m, ensureAllowance as n, getAllVaultChainIds as o, getAsyncRequestStatus as p, getAsyncRequestStatusLabel as q, getFullVaultTopology as r, getInboundRoutes as s, getMaxWithdrawable as t, getOutboundRoutes as u, getUserBalances as v, getUserBalancesForRoutes as w, getUserPosition as x, getUserPositionMultiChain as y, getVaultDistribution as z };
614
+ export { type AsyncRequestFinalResult as A, getVaultDistribution as B, getVaultDistributionWithTopology as C, type DepositBlockReason as D, getVaultMetadata as E, getVaultStatus as F, getVaultSummary as G, getVaultTopology as H, type InboundRoute as I, isAsyncMode as J, isOnHubChain as K, previewDeposit as L, type MaxWithdrawable as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, previewRedeem as P, quoteLzFee as Q, quoteRouteDepositFee as R, type SpokeBalance as S, waitForAsyncRequest as T, type UserBalances as U, type VaultDistribution as V, waitForTx as W, type AsyncRequestStatus as a, type AsyncRequestStatusInfo as b, type DepositEligibility as c, type InboundRouteWithBalance as d, type MultiChainUserPosition as e, type OutboundRoute as f, type UserPosition as g, type VaultMetadata as h, type VaultMode as i, type VaultStatus as j, type VaultSummary as k, type VaultTopology as l, canDeposit as m, discoverVaultTopology as n, ensureAllowance as o, getAllVaultChainIds as p, getAsyncRequestStatus as q, getAsyncRequestStatusLabel as r, getFullVaultTopology as s, getInboundRoutes as t, getMaxWithdrawable as u, getOutboundRoutes as v, getUserBalances as w, getUserBalancesForRoutes as x, getUserPosition as y, getUserPositionMultiChain as z };
@@ -153,8 +153,46 @@ declare function isAsyncMode(publicClient: PublicClient, vault: Address): Promis
153
153
  declare function getAsyncRequestStatus(publicClient: PublicClient, vault: Address, guid: `0x${string}`): Promise<{
154
154
  fulfilled: boolean;
155
155
  finalized: boolean;
156
+ refunded: boolean;
156
157
  result: bigint;
157
158
  }>;
159
+ interface AsyncRequestFinalResult {
160
+ /** 'completed' = assets/shares received, 'refunded' = tokens returned to user */
161
+ status: 'completed' | 'refunded';
162
+ /** For deposit: shares minted. For redeem: assets returned. 0 if refunded. */
163
+ result: bigint;
164
+ }
165
+ /**
166
+ * Poll an async cross-chain request until it finalizes or times out.
167
+ *
168
+ * This is the correct way to wait for smartDeposit/smartRedeem results on
169
+ * async vaults. Do NOT poll balance — use this instead, which reads the
170
+ * on-chain request state by GUID.
171
+ *
172
+ * @param publicClient Public client on the hub chain
173
+ * @param vault Vault address
174
+ * @param guid GUID from smartDeposit/smartRedeem result
175
+ * @param pollInterval Milliseconds between polls (default: 30_000)
176
+ * @param timeout Max wait time in milliseconds (default: 900_000 = 15 min)
177
+ * @param onPoll Optional callback invoked after each poll with current status
178
+ * @returns Final result with status and amount
179
+ * @throws Error if timeout is reached
180
+ *
181
+ * @example
182
+ * const depositResult = await smartDeposit(walletClient, publicClient, { vault }, amount, receiver)
183
+ * if ('guid' in depositResult) {
184
+ * const final = await waitForAsyncRequest(publicClient, vault, depositResult.guid, 30_000, 900_000, (s) => {
185
+ * console.log(`Status: fulfilled=${s.fulfilled}, finalized=${s.finalized}`)
186
+ * })
187
+ * console.log(`Done: ${final.status}, result: ${final.result}`)
188
+ * }
189
+ */
190
+ declare function waitForAsyncRequest(publicClient: PublicClient, vault: Address, guid: `0x${string}`, pollInterval?: number, timeout?: number, onPoll?: (status: {
191
+ fulfilled: boolean;
192
+ finalized: boolean;
193
+ refunded: boolean;
194
+ result: bigint;
195
+ }) => void): Promise<AsyncRequestFinalResult>;
158
196
 
159
197
  interface UserPosition {
160
198
  /** Vault share balance */
@@ -573,4 +611,4 @@ declare function getOutboundRoutes(hubChainId: number, vault: Address): Promise<
573
611
  */
574
612
  declare function quoteRouteDepositFee(route: InboundRoute, hubChainId: number, amount: bigint, userAddress: Address): Promise<bigint>;
575
613
 
576
- export { type AsyncRequestStatus as A, getVaultDistributionWithTopology as B, getVaultMetadata as C, type DepositBlockReason as D, getVaultStatus as E, getVaultSummary as F, getVaultTopology as G, isAsyncMode as H, type InboundRoute as I, isOnHubChain as J, previewDeposit as K, previewRedeem as L, type MaxWithdrawable as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, quoteLzFee as P, quoteRouteDepositFee as Q, waitForTx as R, type SpokeBalance as S, type UserBalances as U, type VaultDistribution as V, type AsyncRequestStatusInfo as a, type DepositEligibility as b, type InboundRouteWithBalance as c, type MultiChainUserPosition as d, type OutboundRoute as e, type UserPosition as f, type VaultMetadata as g, type VaultMode as h, type VaultStatus as i, type VaultSummary as j, type VaultTopology as k, canDeposit as l, discoverVaultTopology as m, ensureAllowance as n, getAllVaultChainIds as o, getAsyncRequestStatus as p, getAsyncRequestStatusLabel as q, getFullVaultTopology as r, getInboundRoutes as s, getMaxWithdrawable as t, getOutboundRoutes as u, getUserBalances as v, getUserBalancesForRoutes as w, getUserPosition as x, getUserPositionMultiChain as y, getVaultDistribution as z };
614
+ export { type AsyncRequestFinalResult as A, getVaultDistribution as B, getVaultDistributionWithTopology as C, type DepositBlockReason as D, getVaultMetadata as E, getVaultStatus as F, getVaultSummary as G, getVaultTopology as H, type InboundRoute as I, isAsyncMode as J, isOnHubChain as K, previewDeposit as L, type MaxWithdrawable as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, previewRedeem as P, quoteLzFee as Q, quoteRouteDepositFee as R, type SpokeBalance as S, waitForAsyncRequest as T, type UserBalances as U, type VaultDistribution as V, waitForTx as W, type AsyncRequestStatus as a, type AsyncRequestStatusInfo as b, type DepositEligibility as c, type InboundRouteWithBalance as d, type MultiChainUserPosition as e, type OutboundRoute as f, type UserPosition as g, type VaultMetadata as h, type VaultMode as i, type VaultStatus as j, type VaultSummary as k, type VaultTopology as l, canDeposit as m, discoverVaultTopology as n, ensureAllowance as o, getAllVaultChainIds as p, getAsyncRequestStatus as q, getAsyncRequestStatusLabel as r, getFullVaultTopology as s, getInboundRoutes as t, getMaxWithdrawable as u, getOutboundRoutes as v, getUserBalances as w, getUserBalancesForRoutes as x, getUserPosition as y, getUserPositionMultiChain as z };
@@ -1131,9 +1131,27 @@ async function getAsyncRequestStatus(publicClient, vault, guid) {
1131
1131
  return {
1132
1132
  fulfilled: info.fulfilled,
1133
1133
  finalized: info.finalized,
1134
+ refunded: info.refunded,
1134
1135
  result: finalizationResult
1135
1136
  };
1136
1137
  }
1138
+ async function waitForAsyncRequest(publicClient, vault, guid, pollInterval = 3e4, timeout = 9e5, onPoll) {
1139
+ const deadline = Date.now() + timeout;
1140
+ while (Date.now() < deadline) {
1141
+ const status = await getAsyncRequestStatus(publicClient, vault, guid);
1142
+ if (onPoll) onPoll(status);
1143
+ if (status.finalized) {
1144
+ return { status: "completed", result: status.result };
1145
+ }
1146
+ if (status.refunded) {
1147
+ return { status: "refunded", result: 0n };
1148
+ }
1149
+ await new Promise((r) => setTimeout(r, pollInterval));
1150
+ }
1151
+ throw new Error(
1152
+ `[MoreVaults] Async request ${guid} did not finalize within ${timeout / 1e3}s. The request may still complete \u2014 check https://layerzeroscan.com/tx/${guid}`
1153
+ );
1154
+ }
1137
1155
  var PUBLIC_RPCS = {
1138
1156
  1: [
1139
1157
  "https://ethereum-rpc.publicnode.com",
@@ -3209,6 +3227,7 @@ exports.requestRedeem = requestRedeem;
3209
3227
  exports.resolveRedeemAddresses = resolveRedeemAddresses;
3210
3228
  exports.smartDeposit = smartDeposit;
3211
3229
  exports.smartRedeem = smartRedeem;
3230
+ exports.waitForAsyncRequest = waitForAsyncRequest;
3212
3231
  exports.waitForCompose = waitForCompose;
3213
3232
  exports.waitForTx = waitForTx;
3214
3233
  exports.withdrawAssets = withdrawAssets;