@oydual31/more-vaults-sdk 0.3.2 → 0.4.0

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.
Files changed (39) hide show
  1. package/dist/ethers/index.cjs +1794 -315
  2. package/dist/ethers/index.cjs.map +1 -1
  3. package/dist/ethers/index.d.cts +1147 -1
  4. package/dist/ethers/index.d.ts +1147 -1
  5. package/dist/ethers/index.js +1752 -317
  6. package/dist/ethers/index.js.map +1 -1
  7. package/dist/react/index.cjs.map +1 -1
  8. package/dist/react/index.d.cts +1 -1
  9. package/dist/react/index.d.ts +1 -1
  10. package/dist/react/index.js.map +1 -1
  11. package/dist/{spokeRoutes-DK7cIW4z.d.cts → spokeRoutes-BIafSbQ3.d.cts} +13 -2
  12. package/dist/{spokeRoutes-DK7cIW4z.d.ts → spokeRoutes-BIafSbQ3.d.ts} +13 -2
  13. package/dist/viem/index.cjs +34 -28
  14. package/dist/viem/index.cjs.map +1 -1
  15. package/dist/viem/index.d.cts +1 -1
  16. package/dist/viem/index.d.ts +1 -1
  17. package/dist/viem/index.js +34 -29
  18. package/dist/viem/index.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/ethers/abis.ts +92 -0
  21. package/src/ethers/chains.ts +191 -0
  22. package/src/ethers/crossChainFlows.ts +208 -0
  23. package/src/ethers/curatorMulticall.ts +195 -0
  24. package/src/ethers/curatorStatus.ts +319 -0
  25. package/src/ethers/curatorSwaps.ts +192 -0
  26. package/src/ethers/distribution.ts +156 -0
  27. package/src/ethers/index.ts +96 -1
  28. package/src/ethers/preflight.ts +225 -1
  29. package/src/ethers/redeemFlows.ts +160 -1
  30. package/src/ethers/spokeRoutes.ts +361 -0
  31. package/src/ethers/topology.ts +240 -0
  32. package/src/ethers/types.ts +95 -0
  33. package/src/ethers/userHelpers.ts +193 -0
  34. package/src/ethers/utils.ts +28 -0
  35. package/src/viem/crossChainFlows.ts +12 -22
  36. package/src/viem/index.ts +1 -0
  37. package/src/viem/preflight.ts +3 -9
  38. package/src/viem/redeemFlows.ts +4 -5
  39. package/src/viem/utils.ts +40 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oydual31/more-vaults-sdk",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript SDK for MoreVaults protocol — viem/wagmi and ethers.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -85,3 +85,95 @@ export const LZ_ENDPOINT_ABI = [
85
85
  "function composeQueue(address from, address to, bytes32 guid, uint16 index) view returns (bytes32 messageHash)",
86
86
  "function lzCompose(address _from, address _to, bytes32 _guid, uint16 _index, bytes _message, bytes _extraData) payable",
87
87
  ] as const;
88
+
89
+ // ─────────────────────────────────────────────────────────────────────────────
90
+ // Curator Operations ABIs
91
+ // ─────────────────────────────────────────────────────────────────────────────
92
+
93
+ /**
94
+ * MulticallFacet ABI — curator action submission and execution with timelock.
95
+ */
96
+ export const MULTICALL_ABI = [
97
+ "function submitActions(bytes[] actionsData) returns (uint256 nonce)",
98
+ "function executeActions(uint256 actionsNonce)",
99
+ "function getPendingActions(uint256 actionsNonce) view returns (bytes[] actionsData, uint256 pendingUntil)",
100
+ "function getCurrentNonce() view returns (uint256)",
101
+ "function vetoActions(uint256[] actionsNonces)",
102
+ ] as const;
103
+
104
+ /**
105
+ * GenericDexFacet ABI — single and batch token swaps through any DEX aggregator.
106
+ */
107
+ export const DEX_ABI = [
108
+ "function executeSwap(tuple(address targetContract, address tokenIn, address tokenOut, uint256 maxAmountIn, uint256 minAmountOut, bytes swapCallData) params) returns (uint256 amountOut)",
109
+ "function executeBatchSwap(tuple(tuple(address targetContract, address tokenIn, address tokenOut, uint256 maxAmountIn, uint256 minAmountOut, bytes swapCallData)[] swaps) params) returns (uint256[] amountsOut)",
110
+ ] as const;
111
+
112
+ /**
113
+ * BridgeFacet ABI — curator bridging and cross-chain request initiation.
114
+ */
115
+ export const BRIDGE_FACET_ABI = [
116
+ "function executeBridging(address adapter, address token, uint256 amount, bytes bridgeSpecificParams) payable",
117
+ "function initVaultActionRequest(uint8 actionType, bytes actionCallData, uint256 amountLimit, bytes extraOptions) payable returns (bytes32 guid)",
118
+ "function executeRequest(bytes32 guid)",
119
+ ] as const;
120
+
121
+ /**
122
+ * ERC7540Facet ABI — async deposit and redeem operations on ERC7540 vaults.
123
+ */
124
+ export const ERC7540_FACET_ABI = [
125
+ "function erc7540RequestDeposit(address vault, uint256 assets) returns (uint256 requestId)",
126
+ "function erc7540RequestRedeem(address vault, uint256 shares) returns (uint256 requestId)",
127
+ "function erc7540Deposit(address vault, uint256 assets) returns (uint256 shares)",
128
+ "function erc7540Redeem(address vault, uint256 shares) returns (uint256 assets)",
129
+ ] as const;
130
+
131
+ /**
132
+ * ERC4626Facet ABI — synchronous deposit and redeem into whitelisted ERC-4626 vaults.
133
+ */
134
+ export const ERC4626_FACET_ABI = [
135
+ "function erc4626Deposit(address vault, uint256 assets) returns (uint256 shares)",
136
+ "function erc4626Redeem(address vault, uint256 shares) returns (uint256 assets)",
137
+ ] as const;
138
+
139
+ /**
140
+ * ConfigurationFacet ABI — extended with curator-relevant read functions.
141
+ */
142
+ export const CURATOR_CONFIG_ABI = [
143
+ "function curator() view returns (address)",
144
+ "function timeLockPeriod() view returns (uint256)",
145
+ "function getAvailableAssets() view returns (address[])",
146
+ "function getMaxSlippagePercent() view returns (uint256)",
147
+ "function getCrossChainAccountingManager() view returns (address)",
148
+ "function paused() view returns (bool)",
149
+ ] as const;
150
+
151
+ /**
152
+ * LzAdapter ABI — fee quoting for bridge and LZ Read operations.
153
+ */
154
+ export const LZ_ADAPTER_ABI = [
155
+ "function quoteBridgeFee(bytes bridgeSpecificParams) view returns (uint256 nativeFee)",
156
+ "function quoteReadFee(address[] vaults, uint32[] eids, bytes _extraOptions) view returns (tuple(uint256 nativeFee, uint256 lzTokenFee) fee)",
157
+ ] as const;
158
+
159
+ /**
160
+ * Vault analysis ABIs — per-vault whitelist and registry reads.
161
+ */
162
+ export const VAULT_ANALYSIS_ABI = [
163
+ "function getAvailableAssets() view returns (address[])",
164
+ "function getDepositableAssets() view returns (address[])",
165
+ "function isAssetAvailable(address asset) view returns (bool)",
166
+ "function isAssetDepositable(address asset) view returns (bool)",
167
+ "function isDepositWhitelistEnabled() view returns (bool)",
168
+ "function getAvailableToDeposit(address depositor) view returns (uint256)",
169
+ "function moreVaultsRegistry() view returns (address)",
170
+ ] as const;
171
+
172
+ /**
173
+ * MoreVaultsRegistry ABI — global protocol and bridge whitelist checks.
174
+ */
175
+ export const REGISTRY_ABI = [
176
+ "function isWhitelisted(address protocol) view returns (bool)",
177
+ "function isBridgeAllowed(address bridge) view returns (bool)",
178
+ "function getAllowedFacets() view returns (address[])",
179
+ ] as const;
@@ -1,3 +1,6 @@
1
+ import { JsonRpcProvider } from "ethers";
2
+ import type { Provider } from "ethers";
3
+
1
4
  /** EVM Chain IDs for chains supported by MoreVaults */
2
5
  export const CHAIN_IDS = {
3
6
  flowEVMMainnet: 747,
@@ -5,6 +8,9 @@ export const CHAIN_IDS = {
5
8
  arbitrum: 42161,
6
9
  base: 8453,
7
10
  ethereum: 1,
11
+ optimism: 10,
12
+ sonic: 146,
13
+ bsc: 56,
8
14
  } as const;
9
15
 
10
16
  /**
@@ -18,6 +24,9 @@ export const LZ_EIDS = {
18
24
  arbitrum: 30110,
19
25
  base: 30184,
20
26
  ethereum: 30101,
27
+ optimism: 30111,
28
+ sonic: 30332,
29
+ bsc: 30102,
21
30
  } as const;
22
31
 
23
32
  /** LayerZero EID → EVM Chain ID */
@@ -27,6 +36,9 @@ export const EID_TO_CHAIN_ID: Record<number, number> = {
27
36
  [LZ_EIDS.arbitrum]: CHAIN_IDS.arbitrum,
28
37
  [LZ_EIDS.base]: CHAIN_IDS.base,
29
38
  [LZ_EIDS.ethereum]: CHAIN_IDS.ethereum,
39
+ [LZ_EIDS.optimism]: CHAIN_IDS.optimism,
40
+ [LZ_EIDS.sonic]: CHAIN_IDS.sonic,
41
+ [LZ_EIDS.bsc]: CHAIN_IDS.bsc,
30
42
  };
31
43
 
32
44
  /** EVM Chain ID → LayerZero EID */
@@ -36,8 +48,187 @@ export const CHAIN_ID_TO_EID: Record<number, number> = {
36
48
  [CHAIN_IDS.arbitrum]: LZ_EIDS.arbitrum,
37
49
  [CHAIN_IDS.base]: LZ_EIDS.base,
38
50
  [CHAIN_IDS.ethereum]: LZ_EIDS.ethereum,
51
+ [CHAIN_IDS.optimism]: LZ_EIDS.optimism,
52
+ [CHAIN_IDS.sonic]: LZ_EIDS.sonic,
53
+ [CHAIN_IDS.bsc]: LZ_EIDS.bsc,
54
+ };
55
+
56
+ /**
57
+ * LayerZero v2 OFT route config per asset symbol.
58
+ *
59
+ * Each entry maps chainId → { oft, token } where:
60
+ * - `oft` = OFT contract to call send() on (pass as `spokeOFT` to depositFromSpoke)
61
+ * - `token` = underlying ERC-20 the user approves before bridging
62
+ * (zero address = native ETH, no approval needed)
63
+ *
64
+ * All routes verified on-chain via quoteSend() or peers(). Issuers vary per asset.
65
+ */
66
+ export const OFT_ROUTES = {
67
+ /**
68
+ * stgUSDC — USDC bridged via Stargate v2.
69
+ * Underlying on Eth/Arb/Base/Op: native USDC. On Flow: stgUSDC (Stargate's wrapped USDC).
70
+ */
71
+ stgUSDC: {
72
+ [747 /* flowEVMMainnet */]: { oft: '0xAF54BE5B6eEc24d6BFACf1cce4eaF680A8239398', token: '0xF1815bd50389c46847f0Bda824eC8da914045D14' },
73
+ [1 /* ethereum */]: { oft: '0xc026395860Db2d07ee33e05fE50ed7bD583189C7', token: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' },
74
+ [42161 /* arbitrum */]: { oft: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', token: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' },
75
+ [8453 /* base */]: { oft: '0x27a16dc786820B16E5c9028b75B99F6f604b5d26', token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' },
76
+ [10 /* optimism */]: { oft: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', token: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85' },
77
+ [146 /* sonic */]: { oft: '0xA272fFe20cFfe769CdFc4b63088DCD2C82a2D8F9', token: '0x29219dd400f2Bf60E5a23d13Be72B486D4038894' },
78
+ },
79
+ /**
80
+ * USDT — USDT bridged via Stargate v2.
81
+ */
82
+ USDT: {
83
+ [747 /* flowEVMMainnet */]: { oft: '0xAf5191B0De278C7286d6C7CC6ab6BB8A73bA2Cd6', token: '0x674843C06FF83502ddb4D37c2E09C01cdA38cbc8' },
84
+ [1 /* ethereum */]: { oft: '0x933597a323Eb81cAe705C5bC29985172fd5A3973', token: '0xdAC17F958D2ee523a2206206994597C13D831ec7' },
85
+ [42161 /* arbitrum */]: { oft: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', token: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9' },
86
+ [10 /* optimism */]: { oft: '0x19cFCE47eD54a88614648DC3f19A5980097007dD', token: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58' },
87
+ },
88
+ /**
89
+ * USDF — USD Flow OFT. Bridges PYUSD (Ethereum) ↔ USDF (Flow EVM).
90
+ */
91
+ USDF: {
92
+ [747 /* flowEVMMainnet */]: { oft: '0x2aabea2058b5ac2d339b163c6ab6f2b6d53aabed', token: '0x2aabea2058b5ac2d339b163c6ab6f2b6d53aabed' },
93
+ [1 /* ethereum */]: { oft: '0xfa0e06b54986ad96de87a8c56fea76fbd8d493f8', token: '0x6c3ea9036406852006290770BEdFcAbA0e23A0e8' },
94
+ },
95
+ /**
96
+ * PYUSD — PayPal USD bridged via OFTAdapter (Paxos / LayerZero).
97
+ */
98
+ PYUSD: {
99
+ [747 /* flowEVMMainnet */]: { oft: '0x26d27d5AF2F6f1c14F40013C8619d97aaf015509', token: '0x99aF3EeA856556646C98c8B9b2548Fe815240750' },
100
+ [42161 /* arbitrum */]: { oft: '0x3CD2b89C49D130C08f1d683225b2e5DeB63ff876', token: '0x46850aD61C2B7d64d08c9C754F45254596696984' },
101
+ },
102
+ /**
103
+ * WFLOW — Wrapped FLOW NativeOFTAdapter (issued by Flow Foundation).
104
+ */
105
+ WFLOW: {
106
+ [747 /* flowEVMMainnet */]: { oft: '0xd296588850bee2770136464ffdddd78c32f2a07c', token: '0xd296588850bee2770136464ffdddd78c32f2a07c' },
107
+ [1 /* ethereum */]: { oft: '0xc1b45896b5fc9422a8f779653808297bb4f546f9', token: '0x5c147e74D63B1D31AA3Fd78Eb229B65161983B2b' },
108
+ },
109
+ /**
110
+ * WETH — ETH OFT via Stargate v2. underlying = native ETH (no approval needed).
111
+ */
112
+ WETH: {
113
+ [747 /* flowEVMMainnet */]: { oft: '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B', token: '0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590' },
114
+ [1 /* ethereum */]: { oft: '0x77b2043768d28E9C9aB44E1aBfC95944bcE57931', token: '0x0000000000000000000000000000000000000000' },
115
+ [42161 /* arbitrum */]: { oft: '0xA45B5130f36CDcA45667738e2a258AB09f4A5f7F', token: '0x0000000000000000000000000000000000000000' },
116
+ [8453 /* base */]: { oft: '0xdc181Bd607330aeeBEF6ea62e03e5e1Fb4B6F7C7', token: '0x0000000000000000000000000000000000000000' },
117
+ },
118
+ /**
119
+ * sUSDe — Ethena staked USDe (yield-bearing stablecoin).
120
+ */
121
+ sUSDe: {
122
+ [1 /* ethereum */]: { oft: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2', token: '0x9D39A5DE30e57443BfF2A8307A4256c8797A3497' },
123
+ [42161 /* arbitrum */]: { oft: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2', token: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2' },
124
+ [8453 /* base */]: { oft: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2', token: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2' },
125
+ [10 /* optimism */]: { oft: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2', token: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2' },
126
+ [56 /* bsc */]: { oft: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2', token: '0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2' },
127
+ },
128
+ /**
129
+ * USDe — Ethena USD stablecoin.
130
+ */
131
+ USDe: {
132
+ [1 /* ethereum */]: { oft: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34', token: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3' },
133
+ [42161 /* arbitrum */]: { oft: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34', token: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34' },
134
+ [8453 /* base */]: { oft: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34', token: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34' },
135
+ [10 /* optimism */]: { oft: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34', token: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34' },
136
+ [56 /* bsc */]: { oft: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34', token: '0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34' },
137
+ },
138
+ /**
139
+ * weETH — Ether.Fi liquid restaking token.
140
+ */
141
+ weETH: {
142
+ [1 /* ethereum */]: { oft: '0xcd2eb13d6831d4602d80e5db9230a57596cdca63', token: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee' },
143
+ [8453 /* base */]: { oft: '0x04c0599ae5a44757c0af6f9ec3b93da8976c150a', token: '0x04c0599ae5a44757c0af6f9ec3b93da8976c150a' },
144
+ [10 /* optimism */]: { oft: '0x5a7facb970d094b6c7ff1df0ea68d99e6e73cbff', token: '0x5a7facb970d094b6c7ff1df0ea68d99e6e73cbff' },
145
+ [56 /* bsc */]: { oft: '0x04c0599ae5a44757c0af6f9ec3b93da8976c150a', token: '0x04c0599ae5a44757c0af6f9ec3b93da8976c150a' },
146
+ [146 /* sonic */]: { oft: '0xa3d68b74bf0528fdd07263c60d6488749044914b', token: '0xa3d68b74bf0528fdd07263c60d6488749044914b' },
147
+ },
148
+ /**
149
+ * rsETH — Kelp DAO liquid restaking token.
150
+ */
151
+ rsETH: {
152
+ [1 /* ethereum */]: { oft: '0x85d456b2dff1fd8245387c0bfb64dfb700e98ef3', token: '0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7' },
153
+ [42161 /* arbitrum */]: { oft: '0x4186bfc76e2e237523cbc30fd220fe055156b41f', token: '0x4186bfc76e2e237523cbc30fd220fe055156b41f' },
154
+ [8453 /* base */]: { oft: '0x1bc71130a0e39942a7658878169764bbd8a45993', token: '0x1bc71130a0e39942a7658878169764bbd8a45993' },
155
+ [10 /* optimism */]: { oft: '0x4186bfc76e2e237523cbc30fd220fe055156b41f', token: '0x4186bfc76e2e237523cbc30fd220fe055156b41f' },
156
+ [146 /* sonic */]: { oft: '0xd75787ba9aba324420d522bda84c08c87e5099b1', token: '0xd75787ba9aba324420d522bda84c08c87e5099b1' },
157
+ },
158
+ /**
159
+ * rswETH — Swell Network liquid restaking token.
160
+ */
161
+ rswETH: {
162
+ [1 /* ethereum */]: { oft: '0x1486d39646cdee84619bd05997319545a8575079', token: '0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0' },
163
+ [42161 /* arbitrum */]: { oft: '0xb1fe27b32ffb5ce54e272c096547f1e86c19e72f', token: '0xb1fe27b32ffb5ce54e272c096547f1e86c19e72f' },
164
+ [8453 /* base */]: { oft: '0x850cdf416668210ed0c36bfff5d21921c7ada3b8', token: '0x850cdf416668210ed0c36bfff5d21921c7ada3b8' },
165
+ },
166
+ /**
167
+ * USR — Resolv Labs USD stablecoin.
168
+ */
169
+ USR: {
170
+ [1 /* ethereum */]: { oft: '0xd2ee2776f34ef4e7325745b06e6d464b08d4be0e', token: '0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110' },
171
+ [42161 /* arbitrum */]: { oft: '0x2492d0006411af6c8bbb1c8afc1b0197350a79e9', token: '0x2492d0006411af6c8bbb1c8afc1b0197350a79e9' },
172
+ [8453 /* base */]: { oft: '0x35e5db674d8e93a03d814fa0ada70731efe8a4b9', token: '0x35e5db674d8e93a03d814fa0ada70731efe8a4b9' },
173
+ [56 /* bsc */]: { oft: '0x2492d0006411af6c8bbb1c8afc1b0197350a79e9', token: '0x2492d0006411af6c8bbb1c8afc1b0197350a79e9' },
174
+ },
175
+ /**
176
+ * wstUSR — Resolv Labs wrapped staked USR (yield-bearing).
177
+ */
178
+ wstUSR: {
179
+ [1 /* ethereum */]: { oft: '0xab17c1fe647c37ceb9b96d1c27dd189bf8451978', token: '0x1202F5C7b4B9E47a1A484E8B270be34dbbC75055' },
180
+ [42161 /* arbitrum */]: { oft: '0x66cfbd79257dc5217903a36293120282548e2254', token: '0x66cfbd79257dc5217903a36293120282548e2254' },
181
+ [8453 /* base */]: { oft: '0xb67675158b412d53fe6b68946483ba920b135ba1', token: '0xb67675158b412d53fe6b68946483ba920b135ba1' },
182
+ [56 /* bsc */]: { oft: '0x4254813524695def4163a169e901f3d7a1a55429', token: '0x4254813524695def4163a169e901f3d7a1a55429' },
183
+ },
184
+ /**
185
+ * USDtb — Ethena treasury-backed stablecoin.
186
+ */
187
+ USDtb: {
188
+ [1 /* ethereum */]: { oft: '0xc708b6887db46005da033501f8aebee72d191a5d', token: '0xC139190F447e929f090Edeb554D95AbB8b18aC1C' },
189
+ [42161 /* arbitrum */]: { oft: '0xc708b6887db46005da033501f8aebee72d191a5d', token: '0xc708b6887db46005da033501f8aebee72d191a5d' },
190
+ [8453 /* base */]: { oft: '0xc708b6887db46005da033501f8aebee72d191a5d', token: '0xc708b6887db46005da033501f8aebee72d191a5d' },
191
+ },
192
+ } as const;
193
+
194
+ /**
195
+ * Uniswap V3 SwapRouter addresses per chain.
196
+ * Used by curator swap helpers to build calldata for on-chain swaps.
197
+ *
198
+ * Note on struct differences:
199
+ * - SwapRouter (Eth/Arb/Op, 0xE592...): exactInputSingle struct includes `deadline`
200
+ * - SwapRouter02 (Base, 0x2626...): exactInputSingle struct does NOT include `deadline`
201
+ * - FlowSwap V3 (Flow EVM, 0xeEDC...): derived from original UniV3, includes `deadline`
202
+ */
203
+ export const UNISWAP_V3_ROUTERS: Record<number, string> = {
204
+ [8453]: '0x2626664c2603336E57B271c5C0b26F421741e481', // Base — SwapRouter02 (no deadline)
205
+ [1]: '0xE592427A0AEce92De3Edee1F18E0157C05861564', // Ethereum — SwapRouter
206
+ [42161]: '0xE592427A0AEce92De3Edee1F18E0157C05861564', // Arbitrum — SwapRouter
207
+ [10]: '0xE592427A0AEce92De3Edee1F18E0157C05861564', // Optimism — SwapRouter
208
+ [747]: '0xeEDC6Ff75e1b10B903D9013c358e446a73d35341', // Flow EVM — FlowSwap V3 SwapRouter
209
+ };
210
+
211
+ /** Public RPC endpoints per chain for cross-chain reads */
212
+ const PUBLIC_RPCS: Record<number, string[]> = {
213
+ 1: ['https://ethereum-rpc.publicnode.com', 'https://eth.drpc.org', 'https://eth.llamarpc.com'],
214
+ 10: ['https://mainnet.optimism.io', 'https://optimism-rpc.publicnode.com'],
215
+ 42161: ['https://arbitrum-one-rpc.publicnode.com', 'https://arbitrum.publicnode.com'],
216
+ 8453: ['https://base-rpc.publicnode.com', 'https://base.llamarpc.com', 'https://mainnet.base.org'],
217
+ 747: ['https://mainnet.evm.nodes.onflow.org'],
218
+ 146: ['https://rpc.soniclabs.com'],
219
+ 56: ['https://bsc-dataseed1.binance.org', 'https://bsc-dataseed2.binance.org'],
39
220
  };
40
221
 
222
+ /**
223
+ * Create a read-only ethers Provider for a given chain ID using public RPCs.
224
+ * Returns null if no public RPC is configured for that chain.
225
+ */
226
+ export function createChainProvider(chainId: number): Provider | null {
227
+ const rpcs = PUBLIC_RPCS[chainId];
228
+ if (!rpcs?.length) return null;
229
+ return new JsonRpcProvider(rpcs[0], chainId, { staticNetwork: true });
230
+ }
231
+
41
232
  /**
42
233
  * Recommended timeouts for cross-chain operations (milliseconds).
43
234
  * UIs should show a progress indicator and NOT timeout before these values.
@@ -1,6 +1,9 @@
1
1
  import { Contract, AbiCoder, zeroPadValue, Signer, Provider } from "ethers";
2
2
  import { ERC20_ABI, OFT_ABI, BRIDGE_ABI, LZ_ENDPOINT_ABI } from "./abis";
3
3
  import type { ContractTransactionReceipt } from "ethers";
4
+ import { EID_TO_CHAIN_ID, OFT_ROUTES, createChainProvider } from "./chains";
5
+ import { detectStargateOft } from "./utils";
6
+ import { OMNI_FACTORY_ADDRESS } from "./topology";
4
7
 
5
8
  /** LZ Endpoint V2 address — same on all EVM chains */
6
9
  const LZ_ENDPOINT = "0x1a44076050125825900e736c501f859c50fe728c";
@@ -309,3 +312,208 @@ export async function executeCompose(
309
312
 
310
313
  return { receipt };
311
314
  }
315
+
316
+ // ---------------------------------------------------------------------------
317
+ // Compose data types and waitForCompose
318
+ // ---------------------------------------------------------------------------
319
+
320
+ /**
321
+ * Data needed to execute a pending LZ compose on the hub chain.
322
+ * Returned by `depositFromSpoke` when the OFT is a Stargate V2 pool.
323
+ * The SDK user must call `executeCompose()` with this data as TX2 on the hub.
324
+ */
325
+ export interface ComposeData {
326
+ /** LZ Endpoint address on the hub chain */
327
+ endpoint: string
328
+ /** The OFT/pool address that sent the compose (Stargate pool on hub) — resolved by waitForCompose */
329
+ from: string
330
+ /** MoreVaultsComposer address on the hub */
331
+ to: string
332
+ /** LayerZero GUID from the original OFT.send() */
333
+ guid: string
334
+ /** Compose index (default 0) */
335
+ index: number
336
+ /** Full compose message bytes — resolved by waitForCompose from ComposeSent event */
337
+ message: string
338
+ /** Whether this is a Stargate OFT (2-TX flow) */
339
+ isStargate: boolean
340
+ /** Hub chain ID */
341
+ hubChainId: number
342
+ /** Block number on hub chain right before depositFromSpoke TX — used to bound event scan */
343
+ hubBlockStart: bigint
344
+ }
345
+
346
+ /** Minimal ABIs for helper functions used only in this file */
347
+ const FACTORY_COMPOSER_ABI_MIN = [
348
+ "function vaultComposer(address _vault) view returns (address)",
349
+ ] as const;
350
+
351
+ const COMPOSER_SHARE_OFT_ABI = [
352
+ "function SHARE_OFT() view returns (address)",
353
+ ] as const;
354
+
355
+ const OFT_PEERS_ABI = [
356
+ "function peers(uint32 eid) view returns (bytes32)",
357
+ ] as const;
358
+
359
+ const OFT_TOKEN_ABI = [
360
+ "function token() view returns (address)",
361
+ ] as const;
362
+
363
+ const OFT_QUOTE_OFT_ABI = [
364
+ "function quoteOFT(tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd) sendParam) view returns (tuple(uint256 minAmountLD, uint256 maxAmountLD), tuple(int256 feeAmountLD, string description)[], tuple(uint256 amountSentLD, uint256 amountReceivedLD))",
365
+ ] as const;
366
+
367
+ /**
368
+ * Wait for a pending compose to appear in the LZ Endpoint's composeQueue on the hub chain.
369
+ *
370
+ * After `depositFromSpoke` sends tokens via Stargate, the LZ network delivers the message
371
+ * to the hub chain. The endpoint stores the compose hash in `composeQueue` and emits
372
+ * a `ComposeSent` event with the full message bytes.
373
+ *
374
+ * Strategy: scan ComposeSent events on the LZ Endpoint starting from `hubBlockStart`
375
+ * (captured by `depositFromSpoke` right before TX1). We scan forward in 500-block chunks,
376
+ * matching by composer address and receiver in the message body.
377
+ *
378
+ * @param hubProvider Read-only provider on the HUB chain
379
+ * @param composeData Partial compose data (includes hubBlockStart, to, guid)
380
+ * @param receiver Receiver address to match in the compose message
381
+ * @param pollIntervalMs Polling interval (default 20s)
382
+ * @param timeoutMs Timeout (default 30 min)
383
+ * @returns Complete ComposeData ready for executeCompose
384
+ */
385
+ export async function waitForCompose(
386
+ hubProvider: Provider,
387
+ composeData: ComposeData,
388
+ receiver: string,
389
+ pollIntervalMs = 20_000,
390
+ timeoutMs = 1_800_000,
391
+ ): Promise<ComposeData> {
392
+ const deadline = Date.now() + timeoutMs
393
+ const composer = composeData.to.toLowerCase()
394
+ const endpoint = composeData.endpoint
395
+ const receiverNeedle = receiver.replace(/^0x/, '').toLowerCase()
396
+ const startBlock = composeData.hubBlockStart
397
+
398
+ // Collect Stargate OFT addresses on the hub chain
399
+ const hubChainId = composeData.hubChainId
400
+ const candidateAddresses: string[] = []
401
+ for (const chainMap of Object.values(OFT_ROUTES)) {
402
+ const entry = (chainMap as Record<number, { oft: string; token: string }>)[hubChainId]
403
+ if (entry) candidateAddresses.push(entry.oft.toLowerCase())
404
+ }
405
+
406
+ // Filter to Stargate addresses on-chain
407
+ const stargateChecks = await Promise.all(
408
+ candidateAddresses.map(async (addr) => ({
409
+ addr,
410
+ isSg: await detectStargateOft(hubProvider, addr),
411
+ })),
412
+ )
413
+ const knownFromAddresses = stargateChecks.filter((c) => c.isSg).map((c) => c.addr)
414
+
415
+ // ComposeSent event ABI for getLogs
416
+ const endpointContract = new Contract(endpoint, LZ_ENDPOINT_ABI, hubProvider)
417
+
418
+ // ComposeSent event topic
419
+ const COMPOSE_SENT_TOPIC = "0x0c68e6a0b0fb0f33c52455a8da89b21fc640a3dd4a1b21d9bfcc8aeee4a43e84"
420
+
421
+ let attempt = 0
422
+ let scannedUpTo = startBlock - 1n
423
+
424
+ while (Date.now() < deadline) {
425
+ attempt++
426
+ const elapsed = Math.round((Date.now() - (deadline - timeoutMs)) / 1000)
427
+
428
+ try {
429
+ const currentBlock = BigInt(await hubProvider.getBlockNumber())
430
+ const chunkSize = 500n
431
+ let from = scannedUpTo + 1n
432
+
433
+ while (from <= currentBlock) {
434
+ const chunkEnd = from + chunkSize > currentBlock ? currentBlock : from + chunkSize
435
+
436
+ try {
437
+ const logs = await hubProvider.getLogs({
438
+ address: endpoint,
439
+ topics: [COMPOSE_SENT_TOPIC],
440
+ fromBlock: `0x${from.toString(16)}`,
441
+ toBlock: `0x${chunkEnd.toString(16)}`,
442
+ })
443
+
444
+ for (const log of logs) {
445
+ // ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message)
446
+ // All params are non-indexed — decode from data
447
+ try {
448
+ const coder = AbiCoder.defaultAbiCoder()
449
+ const decoded = coder.decode(
450
+ ['address', 'address', 'bytes32', 'uint16', 'bytes'],
451
+ log.data,
452
+ )
453
+ const logFrom = (decoded[0] as string).toLowerCase()
454
+ const logTo = (decoded[1] as string).toLowerCase()
455
+ const logGuid = decoded[2] as string
456
+ const logIndex = Number(decoded[3])
457
+ const logMessage = decoded[4] as string
458
+
459
+ if (
460
+ logTo === composer &&
461
+ logMessage.toLowerCase().includes(receiverNeedle)
462
+ ) {
463
+ // Verify this compose is still pending in composeQueue
464
+ const hash: string = await endpointContract.composeQueue(
465
+ logFrom, composer, logGuid, logIndex,
466
+ )
467
+
468
+ if (hash !== EMPTY_HASH && hash !== RECEIVED_HASH) {
469
+ console.log(`[${elapsed}s] Poll #${attempt} — compose found! (block ${log.blockNumber})`)
470
+ return {
471
+ ...composeData,
472
+ from: decoded[0] as string,
473
+ to: composeData.to,
474
+ guid: logGuid,
475
+ index: logIndex,
476
+ message: logMessage,
477
+ }
478
+ }
479
+ }
480
+ } catch { /* decode failed — skip log */ }
481
+ }
482
+ } catch {
483
+ // Chunk failed (RPC limit) — break inner loop, will retry next poll
484
+ break
485
+ }
486
+
487
+ from = chunkEnd + 1n
488
+ }
489
+
490
+ scannedUpTo = currentBlock
491
+ } catch {
492
+ // getBlockNumber failed — retry next poll
493
+ }
494
+
495
+ // Also try composeQueue directly with spoke GUID (works when GUIDs match)
496
+ let guidMatchFound = false
497
+ for (const fromAddr of knownFromAddresses) {
498
+ try {
499
+ const hash: string = await endpointContract.composeQueue(
500
+ fromAddr, composer, composeData.guid, 0,
501
+ )
502
+ if (hash !== EMPTY_HASH && hash !== RECEIVED_HASH) {
503
+ console.log(`[${elapsed}s] Poll #${attempt} — composeQueue confirms pending (GUID match), re-scanning for message...`)
504
+ scannedUpTo = startBlock - 1n
505
+ guidMatchFound = true
506
+ }
507
+ } catch { /* continue */ }
508
+ }
509
+
510
+ if (!guidMatchFound) {
511
+ console.log(`[${elapsed}s] Poll #${attempt} — compose not found yet, waiting ${pollIntervalMs / 1000}s...`)
512
+ }
513
+ await new Promise(resolve => setTimeout(resolve, pollIntervalMs))
514
+ }
515
+
516
+ throw new Error(
517
+ `Timeout waiting for compose after ${timeoutMs / 60_000} min. Check LayerZero scan for composer ${composeData.to}.`,
518
+ )
519
+ }