Skip to content

Commit

Permalink
feat: better ts sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Jul 22, 2024
1 parent 0c65154 commit d0e0c8d
Show file tree
Hide file tree
Showing 59 changed files with 14,262 additions and 1,049 deletions.
19 changes: 2 additions & 17 deletions typescript-sdk/.env.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
NODE_ENV="development"
# browser or node. Use node for testing locally (e.g., against anvil account)
CLIENT_MODE="node"
# https://docs.union.build/joining_the_testnet/public_endpoints#rpc
UNION_GRAPHQL_API="https://noble-pika-27.hasura.app/v1/graphql"
SEPOLIA_RPC_URL="https://rpc.sepolia.org"
UNION_RPC_URL="https://union-testnet-rpc.polkachu.com"
UNION_REST_URL="https://api.testnet.bonlulu.uno"
UNION_COIN_TYPE="118"
UNION_ADDRESS_PREFIX="union"
UNION_NATIVE_DENOM="muno"
UNION_CHAIN_ID="union-testnet-6"
UNION_CHAIN_NAME="union-testnet"
UCS01_SEPOLIA_PORT_ID="ucs01-relay"
UCS01_UNION_SOURCE_CHANNEL="channel-0"
UCS01_SEPOLIA_SOURCE_CHANNEL="channel-0"
UCS01_EVM_ADDRESS="0x7f7AC7d5a1a2bD54dBA53a22209C3f96699Ed63c"
UCS01_UNION_ADDRESS="union14pfzjnvzacqsmgjyf0avksc8cr70hsyt5epzcp66tmjpswf8sq8sn5meuy"
DRY_RUN=0 # for ./scripts/publish.ts
HUBBLE_URL="https://noble-pika-27.hasura.app"
39 changes: 38 additions & 1 deletion typescript-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br />

<p align="center">
<img width="175" src="https://union.build/logo.svg" alt="Union logo" />
<img width="675" src="https://i.imgur.com/yFpIuzm.jpeg" alt="Union logo" />
</p>
<br />
<p align="center">
Expand All @@ -18,3 +18,40 @@ Union Labs TypeScript SDK providing utilities for cross-chain transfers and more
npx jsr add @union/client
```

### Quick Start

```ts
import { http } from "viem"
import { sepolia } from "viem/chains"
import { createCosmosSdkClient, cosmosHttp } from "@union/client"


const unionClient = createCosmosSdkClient({
evm: {
chain: sepolia,
// browser wallet or `privateKeyToAccount` from `viem/accounts`
account: evmAccount,
transport: http("https://rpc2.sepolia.org")
},
cosmos: {
// browser wallet or `DirectSecp256k1Wallet.fromKey`
account: cosmosAccount,
gasPrice: { amount: "0.0025", denom: "muno" },
transport: cosmosHttp("https://rpc.testnet.bonlulu.uno")
}
})

const transfer = await unionClient.transferAsset({
amount: 1n,
network: "evm",
sourceChannel: "channel-69",
path: ["11155111", "union-testnet-8"],
recipient: "union14qemq0vw6y3gc3u3e0aty2e764u4gs5lnxk4rv",
denomAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
relayContractAddress: "0x3C148Ec863404e48d88757E88e456963A14238ef"
})
```

You can also fetch contracts, channels, etc. from Hubble by using [`offchainQuery.<chains|chain>`](https://github.com/unionlabs/union/blob/d8228c1bed450850401b84e5885411346b7d5484/typescript-sdk/src/query/off-chain.ts#L25).

See [`./playground/berachain-to-union.ts`](./playground/berachain-to-union.ts) and [`./playground`](./playground) in general for more examples.
Binary file modified typescript-sdk/bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions typescript-sdk/bunfig.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
telemetry = false

preload = ["./scripts/preload.ts"]

[run]
# equivalent to `bun --bun` for all `bun run` commands
bun = true
22 changes: 2 additions & 20 deletions typescript-sdk/environment.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
interface EnvironmentVariables {
readonly NODE_ENV: "development" | "production" | "test"
readonly CLIENT_MODE: "browser" | "node"
readonly SEPOLIA_RPC_URL: string
readonly CHAIN_ID: "1" | "11155111" | "6"
readonly ANVIL_RPC_URL: string
readonly ANVIL_ACCOUNT_PRIVATE_KEY: `0x${string}`

readonly UNION_RPC_URL: string
readonly UNION_REST_URL: string
readonly UNION_GRAPHQL_API: string
readonly UNION_CHAIN_ID: string
readonly MUNO_ERC20_ADDRESS: `0x${string}`
readonly UCS01_EVM_ADDRESS: `0x${string}`
readonly UCS01_UNION_ADDRESS: string
readonly UCS01_UNION_SOURCE_CHANNEL: string
readonly UCS01_SEPOLIA_SOURCE_CHANNEL: string
readonly UCS01_SEPOLIA_PORT_ID: string

readonly ADDRESS_PREFIX: string
readonly UNION_COIN_TYPE: string
readonly UNION_NATIVE_DENOM: string
readonly DRY_RUN: string
readonly HUBBLE_URL: string
}

declare module "bun" {
Expand Down
2 changes: 1 addition & 1 deletion typescript-sdk/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://jsr.io/schema/config-file.v1.json",
"exports": "./src/mod.ts",
"name": "@union/client",
"version": "0.0.1-rc.18",
"version": "0.0.1-rc.32",
"publish": {
"include": ["./src/**/*.ts", "./jsr.json"]
}
Expand Down
Loading

0 comments on commit d0e0c8d

Please sign in to comment.