@oydual31/more-vaults-sdk 0.1.13 → 0.1.14

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.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "TypeScript SDK for MoreVaults protocol — viem/wagmi and ethers.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -69,6 +69,18 @@ export function createChainClient(chainId: number) {
69
69
  })
70
70
  }
71
71
 
72
+ const SYMBOL_ABI = [{ name: 'symbol', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'string' }] }] as const
73
+
74
+ /** Read ERC20 symbol() on-chain. Falls back to `fallback` if the call fails. */
75
+ async function readTokenSymbol(client: ReturnType<typeof createChainClient>, token: Address, fallbackSymbol: string): Promise<string> {
76
+ if (!client) return fallbackSymbol
77
+ try {
78
+ return await client.readContract({ address: token, abi: SYMBOL_ABI, functionName: 'symbol' })
79
+ } catch {
80
+ return fallbackSymbol
81
+ }
82
+ }
83
+
72
84
  /** @deprecated use PUBLIC_RPCS — kept for backwards compat in internal checks */
73
85
  const PUBLIC_RPC: Partial<Record<number, string>> = Object.fromEntries(
74
86
  Object.entries(PUBLIC_RPCS).map(([k, v]) => [k, v![0]])
@@ -86,7 +98,7 @@ export const NATIVE_SYMBOL: Partial<Record<number, string>> = {
86
98
  }
87
99
 
88
100
  export interface InboundRoute {
89
- /** Asset symbol from OFT_ROUTES (e.g. 'stgUSDC') */
101
+ /** Internal route identifier from OFT_ROUTES (e.g. 'stgUSDC') — do NOT show to users */
90
102
  symbol: string
91
103
  /** Chain ID where user sends from */
92
104
  spokeChainId: number
@@ -100,6 +112,13 @@ export interface InboundRoute {
100
112
  spokeOft: Address | null
101
113
  /** Token user must approve on spoke chain (zeroAddress = native ETH) */
102
114
  spokeToken: Address
115
+ /**
116
+ * Human-readable symbol of the token the user needs to hold on the spoke chain.
117
+ * For OFTAdapters this is the underlying token symbol (e.g. 'USDC', 'weETH').
118
+ * For pure OFTs this is the OFT's own symbol (e.g. 'sUSDe', 'USDe').
119
+ * Use this — not `symbol` — when displaying the token name to users.
120
+ */
121
+ sourceTokenSymbol: string
103
122
  /** OFT contract on hub chain — receives tokens for the composer. Null for direct deposits. */
104
123
  hubOft: Address | null
105
124
  /** oftCmd to use in SendParam (0x01 for Stargate taxi, 0x for standard OFT) */
@@ -174,31 +193,36 @@ export async function getInboundRoutes(
174
193
  // Validate route via quoteSend — if it reverts, skip
175
194
  try {
176
195
  const receiverBytes32 = `0x${getAddress(userAddress).slice(2).padStart(64, '0')}` as `0x${string}`
177
- const fee = await client.readContract({
178
- address: getAddress(spokeEntry.oft) as Address,
179
- abi: OFT_ABI,
180
- functionName: 'quoteSend',
181
- args: [{
182
- dstEid: hubEid,
183
- to: receiverBytes32,
184
- amountLD: 1_000_000n,
185
- minAmountLD: 0n,
186
- extraOptions: '0x',
187
- composeMsg: '0x',
188
- oftCmd,
189
- }, false],
190
- })
196
+ const spokeTokenAddr = getAddress(spokeEntry.token) as Address
197
+ const [fee, sourceTokenSymbol] = await Promise.all([
198
+ client.readContract({
199
+ address: getAddress(spokeEntry.oft) as Address,
200
+ abi: OFT_ABI,
201
+ functionName: 'quoteSend',
202
+ args: [{
203
+ dstEid: hubEid,
204
+ to: receiverBytes32,
205
+ amountLD: 1_000_000n,
206
+ minAmountLD: 0n,
207
+ extraOptions: '0x',
208
+ composeMsg: '0x',
209
+ oftCmd,
210
+ }, false],
211
+ }),
212
+ readTokenSymbol(client, spokeTokenAddr, symbol),
213
+ ])
191
214
 
192
215
  results.push({
193
216
  symbol,
194
217
  spokeChainId,
195
- depositType: 'oft-compose',
196
- spokeOft: getAddress(spokeEntry.oft) as Address,
197
- spokeToken: getAddress(spokeEntry.token) as Address,
198
- hubOft: getAddress(hubEntry.oft) as Address,
218
+ depositType: 'oft-compose',
219
+ spokeOft: getAddress(spokeEntry.oft) as Address,
220
+ spokeToken: spokeTokenAddr,
221
+ sourceTokenSymbol,
222
+ hubOft: getAddress(hubEntry.oft) as Address,
199
223
  oftCmd,
200
- lzFeeEstimate: fee.nativeFee,
201
- nativeSymbol: NATIVE_SYMBOL[spokeChainId] ?? 'ETH',
224
+ lzFeeEstimate: fee.nativeFee,
225
+ nativeSymbol: NATIVE_SYMBOL[spokeChainId] ?? 'ETH',
202
226
  })
203
227
  } catch {
204
228
  // Route not available — skip silently
@@ -211,16 +235,19 @@ export async function getInboundRoutes(
211
235
  for (const [symbol, chainMap] of Object.entries(OFT_ROUTES)) {
212
236
  const hubEntry = (chainMap as Record<number, { oft: string; token: string }>)[hubChainId]
213
237
  if (hubEntry && getAddress(hubEntry.token) === getAddress(vaultAsset)) {
238
+ const hubTokenAddr = getAddress(hubEntry.token) as Address
239
+ const sourceTokenSymbol = await readTokenSymbol(hubClient, hubTokenAddr, symbol)
214
240
  results.unshift({
215
241
  symbol,
216
- spokeChainId: hubChainId,
217
- depositType: 'direct',
218
- spokeOft: null,
219
- spokeToken: getAddress(hubEntry.token) as Address,
220
- hubOft: null,
221
- oftCmd: '0x',
222
- lzFeeEstimate: 0n,
223
- nativeSymbol: NATIVE_SYMBOL[hubChainId] ?? 'ETH',
242
+ spokeChainId: hubChainId,
243
+ depositType: 'direct',
244
+ spokeOft: null,
245
+ spokeToken: hubTokenAddr,
246
+ sourceTokenSymbol,
247
+ hubOft: null,
248
+ oftCmd: '0x',
249
+ lzFeeEstimate: 0n,
250
+ nativeSymbol: NATIVE_SYMBOL[hubChainId] ?? 'ETH',
224
251
  })
225
252
  break
226
253
  }