Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UCS03 in TypeScript SDK #3448

Merged
merged 14 commits into from
Jan 7, 2025
4 changes: 4 additions & 0 deletions .github/workflows/typescript-sdk-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
working-directory: './typescript-sdk'
run: bun install

- name: 'Build Preview SDK'
working-directory: './typescript-sdk'
run: bun run build

- name: 'Publish Preview Version'
run: |
bun x pkg-pr-new publish --no-template --comment=update typescript-sdk
21 changes: 0 additions & 21 deletions app/src/lib/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { sepolia } from "viem/chains"

type Environment = "PRODUCTION" | "STAGING" | "DEVELOPMENT"

export const ENV = (): Environment =>
Expand Down Expand Up @@ -27,28 +25,9 @@ export const URLS = () => {
RPC: "https://rpc.testnet-9.union.build",
// REST: "https://api.testnet.bonlulu.uno"
REST: "https://rest.testnet-9.union.build/"
},
SEPOLIA: {
RPC: "https://rpc.ankr.com/eth_sepolia/6c72c8d164912bed4694cb882fc4ca55574126511a4f5f66828a53fa2448a20a",
REST: null
}
}
}

export const CHAINS = ["SEPOLIA", "UNION"] as const
export type Chain = (typeof CHAINS)[number]

export const CHAIN = {
UNION: {
ID: "union-testnet-9",
NAME: "Union Testnet"
},
SEPOLIA: {
ID: sepolia.id.toString(),
NAME: sepolia.name
}
} satisfies Record<Chain, { ID: string; NAME: string }>

export const CHAIN_URLS = {
[CHAIN.UNION.ID]: URLS().UNION
}
8 changes: 2 additions & 6 deletions app/src/lib/wallet/evm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export const config = createConfig({
key: "unstable_connector-injected-sepolia",
name: "unstable_connector-injected-sepolia"
}),
http(`https://special-summer-film.ethereum-sepolia.quiknode.pro/${KEY.RPC.QUICK_NODE}/`, {
name: "QuickNode - Sepolia"
http(`https://rpc.11155111.sepolia.chain.kitchen`, {
name: "Chain Kitchen - Sepolia"
}),
http(sepolia.rpcUrls.default.http.at(0), { name: "default Sepolia RPC" })
]),
Expand Down Expand Up @@ -80,10 +80,6 @@ export const config = createConfig({
key: "unstable_connector-injected-scroll-sepolia",
name: "unstable_connector-injected-scroll-sepolia"
}),
http(
"https://sparkling-shy-hill.scroll-testnet.quiknode.pro/71674ce271d10786bb3e2fb69e8f788b784c2e89/",
{ name: "QuickNode - Scroll Sepolia" }
),
http(scrollSepolia.rpcUrls.default.http.at(0), { name: "default Scroll Sepolia RPC" })
])
},
Expand Down
22 changes: 11 additions & 11 deletions typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@
"check-package": "deno run --allow-all npm:publint --strict && deno run --allow-all npm:@arethetypeswrong/cli@latest --pack --ignore-rules 'cjs-resolves-to-esm'"
},
"dependencies": {
"@aptos-labs/ts-sdk": "^1.33.0",
"@aptos-labs/ts-sdk": "^1.33.1",
"@cosmjs/amino": "^0.32.4",
"@cosmjs/cosmwasm-stargate": "0.32.4",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "0.32.4",
"@cosmjs/tendermint-rpc": "^0.32.4",
"@scure/base": "^1.1.9",
"@scure/base": "^1.2.1",
"neverthrow": "^8.1.1",
"ofetch": "^1.4.1",
"ox": "^0.2.2",
"ox": "^0.6.0",
"patch-package": "^8.0.0",
"viem": "^2.21.48"
"viem": "^2.22.3"
},
"devDependencies": {
"@total-typescript/ts-reset": "^0.6.1",
"@types/bun": "^1.1.13",
"@types/node": "^22.9.1",
"consola": "^3.2.3",
"@types/bun": "^1.1.15",
"@types/node": "^22.10.5",
"consola": "^3.3.3",
"cosmjs-types": "^0.9.0",
"jsr": "^0.13.2",
"knip": "^5.37.1",
"knip": "^5.41.1",
"tsup": "^8.3.5",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"vite-tsconfig-paths": "^5.1.3",
"vitest": "^2.1.5"
"typescript": "^5.7.2",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^2.1.8"
},
"repository": {
"type": "git",
Expand Down
76 changes: 76 additions & 0 deletions typescript-sdk/playground/holesky-to-sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bun
import { fallback, http } from "viem"
import { parseArgs } from "node:util"
import { consola } from "scripts/logger"
import { raise } from "#utilities/index.ts"
import { privateKeyToAccount } from "viem/accounts"
import { holesky, sepolia } from "viem/chains"
import { createUnionClient, type TransferAssetsParameters } from "#mod.ts"

/* `bun playground/sepolia-to-holesky.ts --private-key "..."` */

const { values } = parseArgs({
args: process.argv.slice(2),
options: {
"private-key": { type: "string" },
"estimate-gas": { type: "boolean", default: false }
}
})

const PRIVATE_KEY = values["private-key"]
if (!PRIVATE_KEY) raise("Private key not found")
const ONLY_ESTIMATE_GAS = values["estimate-gas"] ?? false

const evmAccount = privateKeyToAccount(`0x${PRIVATE_KEY}`)

const LINK_CONTRACT_ADDRESS = "0x685cE6742351ae9b618F383883D6d1e0c5A31B4B"
const RECEIVER = "0x153919669Edc8A5D0c8D1E4507c9CE60435A1177"

try {
const client = createUnionClient({
chainId: "17000",
account: evmAccount,
transport: fallback([
http("https://rpc.holesky.sepolia.chain.kitchen"),
http(holesky?.rpcUrls.default.http.at(0))
])
})

const transactionPayload = {
amount: 421n,
destinationChainId: `${sepolia.id}`,
receiver: RECEIVER,
denomAddress: LINK_CONTRACT_ADDRESS,
autoApprove: true
} satisfies TransferAssetsParameters<"17000">

const gasEstimationResponse = await client.simulateTransaction(transactionPayload)

if (gasEstimationResponse.isErr()) {
consola.error(gasEstimationResponse.error)
process.exit(1)
}

consola.success("Sepolia to Holesky gas cost:", gasEstimationResponse.value)

if (ONLY_ESTIMATE_GAS) process.exit(0)

if (gasEstimationResponse.isErr()) {
console.info("Transaction simulation failed", gasEstimationResponse.error)
process.exit(1)
}

const transfer = await client.transferAsset(transactionPayload)

if (transfer.isErr()) {
console.error(transfer.error)
process.exit(1)
}

consola.info(transfer.value)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : error
console.error(errorMessage)
} finally {
process.exit(0)
}
76 changes: 76 additions & 0 deletions typescript-sdk/playground/sepolia-to-holesky.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bun
import { fallback, http } from "viem"
import { parseArgs } from "node:util"
import { consola } from "scripts/logger"
import { raise } from "#utilities/index.ts"
import { privateKeyToAccount } from "viem/accounts"
import { holesky, sepolia } from "viem/chains"
import { createUnionClient, type TransferAssetsParameters } from "#mod.ts"

/* `bun playground/sepolia-to-holesky.ts --private-key "..."` */

const { values } = parseArgs({
args: process.argv.slice(2),
options: {
"private-key": { type: "string" },
"estimate-gas": { type: "boolean", default: false }
}
})

const PRIVATE_KEY = values["private-key"]
if (!PRIVATE_KEY) raise("Private key not found")
const ONLY_ESTIMATE_GAS = values["estimate-gas"] ?? false

const evmAccount = privateKeyToAccount(`0x${PRIVATE_KEY}`)

const LINK_CONTRACT_ADDRESS = "0x779877A7B0D9E8603169DdbD7836e478b4624789"
const RECEIVER = "0x153919669Edc8A5D0c8D1E4507c9CE60435A1177"

try {
const client = createUnionClient({
chainId: "11155111",
account: evmAccount,
transport: fallback([
http("https://rpc.11155111.sepolia.chain.kitchen"),
http(sepolia?.rpcUrls.default.http.at(0))
])
})

const transactionPayload = {
amount: 420n,
destinationChainId: `${holesky.id}`,
receiver: RECEIVER,
denomAddress: LINK_CONTRACT_ADDRESS,
autoApprove: true
} satisfies TransferAssetsParameters<"11155111">

const gasEstimationResponse = await client.simulateTransaction(transactionPayload)

if (gasEstimationResponse.isErr()) {
consola.error(gasEstimationResponse.error)
process.exit(1)
}

consola.success("Sepolia to Holesky gas cost:", gasEstimationResponse.value)

if (ONLY_ESTIMATE_GAS) process.exit(0)

if (gasEstimationResponse.isErr()) {
console.info("Transaction simulation failed", gasEstimationResponse.error)
process.exit(1)
}

const transfer = await client.transferAsset(transactionPayload)

if (transfer.isErr()) {
console.error(transfer.error)
process.exit(1)
}

consola.info(transfer.value)
} catch (error) {
const errorMessage = error instanceof Error ? error.message : error
console.error(errorMessage)
} finally {
process.exit(0)
}
3 changes: 2 additions & 1 deletion typescript-sdk/src/abi/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./ucs-02.ts"
export * from "./ucs-01.ts"
export * from "./ucs-02.ts"
export * from "./ucs-03.ts"
Loading
Loading