@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/dist/react/index.cjs +33 -16
- 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 +33 -16
- package/dist/react/index.js.map +1 -1
- package/dist/{spokeRoutes-CQeExpAR.d.cts → spokeRoutes-BFIxGa1h.d.cts} +8 -1
- package/dist/{spokeRoutes-CQeExpAR.d.ts → spokeRoutes-BFIxGa1h.d.ts} +8 -1
- package/dist/viem/index.cjs +33 -16
- 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 +33 -16
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/spokeRoutes.ts +56 -29
package/package.json
CHANGED
package/src/viem/spokeRoutes.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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:
|
|
196
|
-
spokeOft:
|
|
197
|
-
spokeToken:
|
|
198
|
-
|
|
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:
|
|
201
|
-
nativeSymbol:
|
|
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:
|
|
217
|
-
depositType:
|
|
218
|
-
spokeOft:
|
|
219
|
-
spokeToken:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
}
|