Skip to content

Commit f7171f1

Browse files
authored
Fix sdk weth (#3837)
2 parents bfec2e2 + b7d04a2 commit f7171f1

File tree

7 files changed

+46
-21
lines changed

7 files changed

+46
-21
lines changed

app/app.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ _: {
1919
{
2020
packages = {
2121
app = jsPkgs.buildNpmPackage {
22-
npmDepsHash = "sha256-3FrZHjvlX0huij7CqvTvrgVZKpn4DVIH+f4sPlYd3Rg=";
22+
npmDepsHash = "sha256-wGDndu7Oyal8o++4+GVxhlzV81qbwmF8g3debECoI6g=";
2323
src = ./.;
2424
sourceRoot = "app";
2525
npmFlags = [

app/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@tanstack/svelte-query": "5.61.5",
2626
"@tanstack/svelte-table": "^8.20.5",
2727
"@tanstack/svelte-virtual": "3.10.9",
28-
"@unionlabs/client": "^0.1.0",
28+
"@unionlabs/client": "^0.1.2",
2929
"@wagmi/connectors": "5.7.5",
3030
"@wagmi/core": "2.16.3",
3131
"bits-ui": "^0.21.13",

app/src/lib/components/TransferCube/index.svelte

+4-2
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,16 @@ const wethQuoteToken: Readable<Nullable<{ wethAddress: Hex }>> = derived<
123123
return
124124
}
125125
126-
const ucs03address = channel.source_port_id ? `0x${channel.source_port_id}` : null
126+
const ucs03address: `0x${string}` | null = channel.source_port_id
127+
? `0x${channel.source_port_id}`
128+
: null
127129
128130
if (!ucs03address) {
129131
console.error("UCS03 address not found for chain:", sourceChain.chain_id)
130132
return
131133
}
132134
133-
getWethQuoteToken(sourceChain.chain_id, ucs03address)
135+
getWethQuoteToken(sourceChain.chain_id, ucs03address, channel)
134136
.then(result => {
135137
if (result.isOk()) {
136138
const response = result.value

app/src/lib/components/transfer-details.svelte

+19-9
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,25 @@ let processedTransfers = derived(
6161
}
6262
return [$submittedTransfers[source]]
6363
}
64-
return $transfers.data.map(transfer => {
65-
let tx = structuredClone(transfer)
66-
return {
67-
transfer_day: tx.packet_send_timestamp
68-
? toIsoString(new Date(tx.packet_send_timestamp)).split("T")[0]
69-
: null,
70-
...tx
71-
}
72-
})
64+
65+
return $transfers.data
66+
.map(transfer => {
67+
let tx = structuredClone(transfer)
68+
69+
let quoteAmount = tx.quote_amount ? Number.parseInt(tx.quote_amount, 16) : Number.NaN
70+
71+
if (!quoteAmount) {
72+
return null
73+
}
74+
75+
return {
76+
transfer_day: tx.packet_send_timestamp
77+
? toIsoString(new Date(tx.packet_send_timestamp)).split("T")[0]
78+
: null,
79+
...tx
80+
}
81+
})
82+
.filter(Boolean)
7383
}
7484
)
7585
</script>

typescript-sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@unionlabs/client",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"homepage": "https://union.build",
55
"description": "Union Labs cross-chain transfers client",
66
"type": "module",

typescript-sdk/src/query/offchain/ucs03-channels.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,15 @@ export const getQuoteToken = async (
177177

178178
export const getWethQuoteToken = async (
179179
sourceChainId: EvmChainId,
180-
ucs03Address: Hex
180+
ucs03Address: Hex,
181+
channel: Channel
181182
): Promise<Result<{ wethQuoteToken: string } | { type: "NO_WETH_QUOTE" }, Error>> => {
182183
const publicClient = createPublicClient({
183184
chain: evmChainFromChainId(sourceChainId),
184185
transport: http()
185186
})
186187

188+
// Step 1: Get the local WETH address
187189
const wethAddressResult = await ResultAsync.fromPromise(
188190
publicClient.readContract({
189191
address: ucs03Address,
@@ -199,9 +201,20 @@ export const getWethQuoteToken = async (
199201
}
200202

201203
const wethAddress = wethAddressResult.value as Hex
202-
console.log(`Fetched WETH address: ${wethAddress}`)
204+
console.log(`Fetched local WETH address: ${wethAddress}`)
205+
206+
// Step 2: Predict the quote token for WETH, just like a regular token
207+
const quoteResult = await getQuoteToken(sourceChainId, wethAddress, channel)
208+
209+
if (quoteResult.isErr()) {
210+
return err(quoteResult.error)
211+
}
212+
213+
if (quoteResult.value.type === "NO_QUOTE_AVAILABLE") {
214+
return ok({ type: "NO_WETH_QUOTE" })
215+
}
203216

204-
return ok({ wethQuoteToken: wethAddress })
217+
return ok({ wethQuoteToken: quoteResult.value.quote_token })
205218
}
206219

207220
export const getRecommendedChannels = async () => {

0 commit comments

Comments
 (0)