Skip to content

Commit cff86d3

Browse files
authored
fix: non-pfm transfer (#2966)
2 parents ee6cad8 + 17d7c5b commit cff86d3

File tree

15 files changed

+159
-91
lines changed

15 files changed

+159
-91
lines changed

app/app.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
packages = {
1111
app = unstablePkgs.buildNpmPackage {
12-
npmDepsHash = "sha256-edh9+hs4uXoXk96Trb2MHbTNNnk89Ocwc0Nqdk3lQoo=";
12+
npmDepsHash = "sha256-8zhT3p1jem0kR6kGQpMGPb8lDPsshzUNSlT5hYuUb7k=";
1313
src = ./.;
1414
sourceRoot = "app";
1515
npmFlags = [ "--legacy-peer-deps" "--ignore-scripts" ];

app/package-lock.json

+8-8
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
@@ -23,7 +23,7 @@
2323
"@tanstack/svelte-query": "^5.55.4",
2424
"@tanstack/svelte-table": "^8.20.5",
2525
"@tanstack/svelte-virtual": "^3.10.7",
26-
"@unionlabs/client": "^0.0.18",
26+
"@unionlabs/client": "^0.0.22",
2727
"@wagmi/connectors": "^5.1.9",
2828
"@wagmi/core": "^2.13.4",
2929
"bits-ui": "^0.21.13",

app/src/lib/queries/balance/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { raise } from "$lib/utilities/index.ts"
33
import { getCosmosChainBalances } from "./cosmos.ts"
44
import { createQueries } from "@tanstack/svelte-query"
55
import { erc20ReadMulticall } from "./evm/multicall.ts"
6-
import { bytesToBech32Address } from "@unionlabs/client"
6+
import { bech32ToBech32Address } from "@unionlabs/client"
77
import type { Chain, UserAddresses } from "$lib/types.ts"
88
import { getBalancesFromAlchemy } from "./evm/alchemy.ts"
99
import { getBalancesFromRoutescan } from "./evm/routescan.ts"
@@ -72,10 +72,11 @@ export function userBalancesQuery({
7272
const url = chain.rpcs.filter(rpc => rpc.type === "rest").at(0)?.url
7373
if (!url) raise(`No REST RPC available for chain ${chain.chain_id}`)
7474

75-
const bech32Address = bytesToBech32Address({
75+
const bech32Address = bech32ToBech32Address({
7676
toPrefix: chain.addr_prefix,
77-
bytes: userAddr.cosmos.bytes
77+
address: userAddr.cosmos.canonical
7878
})
79+
7980
return getCosmosChainBalances({ url, walletAddress: bech32Address })
8081
}
8182

app/src/lib/utilities/address.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import type { Chain, UserAddresses } from "$lib/types"
2-
import { bytesToBech32Address } from "@unionlabs/client"
2+
import { bech32ToBech32Address } from "@unionlabs/client"
33

44
export const userAddrOnChain = (userAddr: UserAddresses, chain?: Chain): string | null => {
55
if (!chain) return null
66

77
if (chain.rpc_type === "cosmos") {
88
if (userAddr.cosmos?.bytes) {
9-
return bytesToBech32Address({ bytes: userAddr.cosmos.bytes, toPrefix: chain.addr_prefix })
9+
return bech32ToBech32Address({
10+
toPrefix: chain.addr_prefix,
11+
address: userAddr.cosmos.canonical
12+
})
1013
}
1114
console.log("userAddrOnChain got no cosmos address")
1215
return null

app/src/lib/wallet/cosmos/config.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,15 @@ function createCosmosStore(
121121

122122
export const cosmosStore = createCosmosStore()
123123

124-
export const getCosmosOfflineSigner = (chainId: string): OfflineSigner =>
125-
get(cosmosStore).connectedWallet === "keplr"
126-
? window.keplr?.getOfflineSigner(chainId, { disableBalanceCheck: false })
127-
: window.leap?.getOfflineSigner(chainId, { disableBalanceCheck: false })
124+
export const getCosmosOfflineSigner = ({
125+
chainId,
126+
connectedWallet
127+
}: {
128+
chainId: string
129+
connectedWallet: CosmosWalletId
130+
}): Promise<OfflineSigner> =>
131+
// @ts-expect-error
132+
window[connectedWallet]?.getOfflineSignerAuto(chainId, { disableBalanceCheck: false })
128133

129134
export const userAddrCosmos: Readable<UserAddressCosmos | null> = derived(
130135
[cosmosStore],

app/src/routes/transfer/(components)/transfer-form.svelte

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type EvmChainId,
66
createUnionClient,
77
type CosmosChainId,
8+
type OfflineSigner,
89
evmChainFromChainId,
910
bech32ToBech32Address
1011
} from "@unionlabs/client"
@@ -29,6 +30,7 @@ import ChainButton from "./chain-button.svelte"
2930
import { toIsoString } from "$lib/utilities/date"
3031
import AssetsDialog from "./assets-dialog.svelte"
3132
import { truncate } from "$lib/utilities/format.ts"
33+
import { userAddrCosmos } from "$lib/wallet/cosmos"
3234
import Stepper from "$lib/components/stepper.svelte"
3335
import { raise, sleep } from "$lib/utilities/index.ts"
3436
import { userBalancesQuery } from "$lib/queries/balance"
@@ -41,10 +43,9 @@ import { Button } from "$lib/components/ui/button/index.ts"
4143
import { getSupportedAsset } from "$lib/utilities/helpers.ts"
4244
import CardSectionHeading from "./card-section-heading.svelte"
4345
import ArrowLeftRight from "virtual:icons/lucide/arrow-left-right"
44-
import { parseUnits, formatUnits, type HttpTransport, getAddress } from "viem"
4546
import { getCosmosChainInfo } from "$lib/wallet/cosmos/chain-info.ts"
4647
import { submittedTransfers } from "$lib/stores/submitted-transfers.ts"
47-
import { userAddrCosmos, getCosmosOfflineSigner } from "$lib/wallet/cosmos"
48+
import { parseUnits, formatUnits, type HttpTransport, getAddress } from "viem"
4849
import { type Writable, writable, derived, get, type Readable } from "svelte/store"
4950
import { type TransferState, stepBefore, stepAfter } from "$lib/transfer/transfer.ts"
5051
@@ -143,10 +144,6 @@ let receiver = derived([toChain, userAddress], ([$toChain, $userAddress]) => {
143144
}
144145
})
145146
146-
$: {
147-
console.info($receiver)
148-
}
149-
150147
let ucs01Configuration = derived(
151148
[fromChain, toChainId, receiver],
152149
([$fromChain, $toChainId, $receiver]) => {
@@ -234,7 +231,7 @@ const transfer = async () => {
234231
return
235232
}
236233
237-
const wallet = window[connectedWallet as "keplr" | "leap"]
234+
const wallet = window[connectedWallet]
238235
239236
if (!wallet) {
240237
transferState.set({
@@ -244,6 +241,10 @@ const transfer = async () => {
244241
return
245242
}
246243
244+
const cosmosOfflineSigner = (await wallet.getOfflineSignerAuto($fromChainId, {
245+
disableBalanceCheck: false
246+
})) as OfflineSigner
247+
247248
// @ts-ignore
248249
transferState.set({ kind: "SWITCHING_TO_CHAIN" })
249250
@@ -284,8 +285,6 @@ const transfer = async () => {
284285
285286
if (stepBefore($transferState, "TRANSFERRING")) {
286287
try {
287-
const cosmosOfflineSigner = getCosmosOfflineSigner($fromChainId)
288-
289288
const unionClient = createUnionClient({
290289
account: cosmosOfflineSigner,
291290
transport: http(`https://${rpcUrl}`),

typescript-sdk/bun.lockb

392 Bytes
Binary file not shown.

typescript-sdk/jsr.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://jsr.io/schema/config-file.v1.json",
33
"name": "@union/client",
4-
"version": "0.0.19",
4+
"version": "0.0.22",
55
"license": "MIT",
66
"exports": {
77
".": "./src/mod.ts"

typescript-sdk/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@unionlabs/client",
3-
"version": "0.0.19",
3+
"version": "0.0.22",
44
"homepage": "https://jsr.io/@union/client",
55
"description": "Union Labs cross-chain transfers client",
66
"type": "module",
@@ -36,7 +36,7 @@
3636
"@scure/base": "1.1.8",
3737
"neverthrow": "^8.0.0",
3838
"ofetch": "^1.3.4",
39-
"viem": "^2.21.6"
39+
"viem": "^2.21.7"
4040
},
4141
"devDependencies": {
4242
"@arethetypeswrong/cli": "^0.16.2",
@@ -45,7 +45,7 @@
4545
"@cosmjs/tendermint-rpc": "^0.32.4",
4646
"@total-typescript/ts-reset": "^0.6.1",
4747
"@types/bun": "^1.1.9",
48-
"@types/node": "^22.5.4",
48+
"@types/node": "^22.5.5",
4949
"consola": "^3.2.3",
5050
"cosmjs-types": "^0.9.0",
5151
"jsr": "^0.13.2",
@@ -54,7 +54,7 @@
5454
"tsx": "^4.19.1",
5555
"typescript": "^5.6.2",
5656
"vite-tsconfig-paths": "^5.0.1",
57-
"vitest": "^2.1.0"
57+
"vitest": "^2.1.1"
5858
},
5959
"repository": {
6060
"type": "git",

typescript-sdk/playground/stride-to-berachain.ts

-3
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@ try {
4545
amount: 1n,
4646
autoApprove: true,
4747
denomAddress: "ustrd",
48-
// or `client.evm.account.address` if you want to send to yourself
4948
receiver: berachainAccount.address,
5049
destinationChainId: `${berachainTestnetbArtio.id}`
5150
} satisfies TransferAssetsParameters<"stride-internal-1">
5251

53-
consola.info(transactionPayload)
54-
5552
const gasEstimationResponse = await client.simulateTransaction(transactionPayload)
5653

5754
if (gasEstimationResponse.isErr()) {

typescript-sdk/playground/stride-to-union.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bun
2+
import "#patch.ts"
23
import { http } from "viem"
34
import { parseArgs } from "node:util"
45
import { consola } from "scripts/logger"
@@ -31,17 +32,14 @@ try {
3132
const client = createUnionClient({
3233
account: cosmosAccount,
3334
chainId: "stride-internal-1",
34-
gasPrice: { amount: "0.0025", denom: "strd" },
35-
transport: http(
36-
//
37-
// "https://stride.testnet-1.stridenet.co/"
38-
"https://stride-testnet-rpc.polkachu.com/"
39-
)
35+
gasPrice: { amount: "0.0025", denom: "ustrd" },
36+
transport: http("https://stride-testnet-rpc.polkachu.com")
4037
})
4138

4239
const transactionPayload = {
4340
amount: 1n,
44-
denomAddress: "strd",
41+
autoApprove: true,
42+
denomAddress: "ustrd",
4543
destinationChainId: "union-testnet-8",
4644
receiver: "union14qemq0vw6y3gc3u3e0aty2e764u4gs5lnxk4rv"
4745
} satisfies TransferAssetsParameters<"stride-internal-1">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bun
2+
import { http } from "viem"
3+
import { parseArgs } from "node:util"
4+
import { consola } from "scripts/logger"
5+
import { createUnionClient } from "#mod.ts"
6+
import { raise } from "#utilities/index.ts"
7+
import { hexStringToUint8Array } from "#convert.ts"
8+
import { DirectSecp256k1Wallet } from "@cosmjs/proto-signing"
9+
10+
/* `bun playground/union-to-union.ts --private-key "..."` --estimate-gas */
11+
12+
const { values } = parseArgs({
13+
args: process.argv.slice(2),
14+
options: {
15+
"private-key": { type: "string" },
16+
"estimate-gas": { type: "boolean", default: false }
17+
}
18+
})
19+
20+
const PRIVATE_KEY = values["private-key"]
21+
if (!PRIVATE_KEY) raise("Private key not found")
22+
const ONLY_ESTIMATE_GAS = values["estimate-gas"] ?? false
23+
24+
const cosmosAccount = await DirectSecp256k1Wallet.fromKey(
25+
Uint8Array.from(hexStringToUint8Array(PRIVATE_KEY)),
26+
"union"
27+
)
28+
29+
try {
30+
const client = createUnionClient({
31+
account: cosmosAccount,
32+
chainId: "union-testnet-8",
33+
gasPrice: { amount: "0.0025", denom: "muno" },
34+
transport: http("https://rpc.testnet-8.union.build")
35+
})
36+
37+
const transfer = await client.transferAsset({
38+
amount: 1n,
39+
autoApprove: true,
40+
denomAddress: "muno",
41+
destinationChainId: "stride-internal-1",
42+
receiver: "stride14qemq0vw6y3gc3u3e0aty2e764u4gs5l66hpe3"
43+
})
44+
45+
consola.info(transfer)
46+
process.exit(0)
47+
} catch (error) {
48+
const errorMessage = error instanceof Error ? error.message : error
49+
console.error(errorMessage)
50+
} finally {
51+
process.exit(0)
52+
}

0 commit comments

Comments
 (0)