@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.
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/{spokeRoutes-CXMG7nLp.d.cts → spokeRoutes-z7s_5ooO.d.cts} +39 -1
- package/dist/{spokeRoutes-CXMG7nLp.d.ts → spokeRoutes-z7s_5ooO.d.ts} +39 -1
- package/dist/viem/index.cjs +19 -0
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +1 -1
- package/dist/viem/index.d.ts +1 -1
- package/dist/viem/index.js +19 -1
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/index.ts +2 -1
- package/src/viem/utils.ts +65 -1
package/package.json
CHANGED
package/src/viem/index.ts
CHANGED
|
@@ -83,9 +83,10 @@ export {
|
|
|
83
83
|
quoteLzFee,
|
|
84
84
|
isAsyncMode,
|
|
85
85
|
getAsyncRequestStatus,
|
|
86
|
+
waitForAsyncRequest,
|
|
86
87
|
getVaultStatus,
|
|
87
88
|
} from './utils'
|
|
88
|
-
export type { VaultStatus, VaultMode } from './utils'
|
|
89
|
+
export type { VaultStatus, VaultMode, AsyncRequestFinalResult } from './utils'
|
|
89
90
|
|
|
90
91
|
// --- Pre-flight validation ---
|
|
91
92
|
export { preflightSync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem } from './preflight'
|
package/src/viem/utils.ts
CHANGED
|
@@ -437,7 +437,7 @@ export async function getAsyncRequestStatus(
|
|
|
437
437
|
publicClient: PublicClient,
|
|
438
438
|
vault: Address,
|
|
439
439
|
guid: `0x${string}`,
|
|
440
|
-
): Promise<{ fulfilled: boolean; finalized: boolean; result: bigint }> {
|
|
440
|
+
): Promise<{ fulfilled: boolean; finalized: boolean; refunded: boolean; result: bigint }> {
|
|
441
441
|
const info = (await publicClient.readContract({
|
|
442
442
|
address: getAddress(vault),
|
|
443
443
|
abi: BRIDGE_ABI,
|
|
@@ -455,6 +455,70 @@ export async function getAsyncRequestStatus(
|
|
|
455
455
|
return {
|
|
456
456
|
fulfilled: info.fulfilled,
|
|
457
457
|
finalized: info.finalized,
|
|
458
|
+
refunded: info.refunded,
|
|
458
459
|
result: finalizationResult,
|
|
459
460
|
}
|
|
460
461
|
}
|
|
462
|
+
|
|
463
|
+
export interface AsyncRequestFinalResult {
|
|
464
|
+
/** 'completed' = assets/shares received, 'refunded' = tokens returned to user */
|
|
465
|
+
status: 'completed' | 'refunded'
|
|
466
|
+
/** For deposit: shares minted. For redeem: assets returned. 0 if refunded. */
|
|
467
|
+
result: bigint
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Poll an async cross-chain request until it finalizes or times out.
|
|
472
|
+
*
|
|
473
|
+
* This is the correct way to wait for smartDeposit/smartRedeem results on
|
|
474
|
+
* async vaults. Do NOT poll balance — use this instead, which reads the
|
|
475
|
+
* on-chain request state by GUID.
|
|
476
|
+
*
|
|
477
|
+
* @param publicClient Public client on the hub chain
|
|
478
|
+
* @param vault Vault address
|
|
479
|
+
* @param guid GUID from smartDeposit/smartRedeem result
|
|
480
|
+
* @param pollInterval Milliseconds between polls (default: 30_000)
|
|
481
|
+
* @param timeout Max wait time in milliseconds (default: 900_000 = 15 min)
|
|
482
|
+
* @param onPoll Optional callback invoked after each poll with current status
|
|
483
|
+
* @returns Final result with status and amount
|
|
484
|
+
* @throws Error if timeout is reached
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* const depositResult = await smartDeposit(walletClient, publicClient, { vault }, amount, receiver)
|
|
488
|
+
* if ('guid' in depositResult) {
|
|
489
|
+
* const final = await waitForAsyncRequest(publicClient, vault, depositResult.guid, 30_000, 900_000, (s) => {
|
|
490
|
+
* console.log(`Status: fulfilled=${s.fulfilled}, finalized=${s.finalized}`)
|
|
491
|
+
* })
|
|
492
|
+
* console.log(`Done: ${final.status}, result: ${final.result}`)
|
|
493
|
+
* }
|
|
494
|
+
*/
|
|
495
|
+
export async function waitForAsyncRequest(
|
|
496
|
+
publicClient: PublicClient,
|
|
497
|
+
vault: Address,
|
|
498
|
+
guid: `0x${string}`,
|
|
499
|
+
pollInterval: number = 30_000,
|
|
500
|
+
timeout: number = 900_000,
|
|
501
|
+
onPoll?: (status: { fulfilled: boolean; finalized: boolean; refunded: boolean; result: bigint }) => void,
|
|
502
|
+
): Promise<AsyncRequestFinalResult> {
|
|
503
|
+
const deadline = Date.now() + timeout
|
|
504
|
+
|
|
505
|
+
while (Date.now() < deadline) {
|
|
506
|
+
const status = await getAsyncRequestStatus(publicClient, vault, guid)
|
|
507
|
+
|
|
508
|
+
if (onPoll) onPoll(status)
|
|
509
|
+
|
|
510
|
+
if (status.finalized) {
|
|
511
|
+
return { status: 'completed', result: status.result }
|
|
512
|
+
}
|
|
513
|
+
if (status.refunded) {
|
|
514
|
+
return { status: 'refunded', result: 0n }
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
await new Promise(r => setTimeout(r, pollInterval))
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
throw new Error(
|
|
521
|
+
`[MoreVaults] Async request ${guid} did not finalize within ${timeout / 1000}s. ` +
|
|
522
|
+
`The request may still complete — check https://layerzeroscan.com/tx/${guid}`,
|
|
523
|
+
)
|
|
524
|
+
}
|