Skip to content

Commit

Permalink
chore: save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Feb 14, 2024
1 parent ff1367e commit cf2cbcf
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 71 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/check-typescript-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish TypeScript SDK

on:
push:
branches: ['main']
pull_request:
paths: ['typescript-sdk/**']
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}

defaults:
run:
shell: bash
working-directory: './typescript-sdk'

env:
NIX_VERSION: nix-2.13.2
NIXPKGS_CHANNEL: nixos-22.11
NODE_OPTIONS: '--no-warnings'
ACTIONS_RUNNER_DEBUG: true

jobs:
test-typescript-sdk:
name: 'Test TypeScript SDK'
runs-on: ['ubuntu-latest']
defaults:
run:
working-directory: './typescript-sdk'
steps:
- name: 'Checkout'
uses: actions/checkout@v4

- name: 'Setup bun'
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'

- name: 'Install Nix'
uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:${{ env.NIXPKGS_CHANNEL }}
github_access_token: ${{ github.token }}
- run: |
nix-channel --add https://nixos.org/channels/${{ env.NIXPKGS_CHANNEL }} nixpkgs
nix-channel --update
- name: 'Build SDK'
working-directory: './typescript-sdk'
run: |
nix build .#typescript-sdk -o dist
106 changes: 106 additions & 0 deletions typescript-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@total-typescript/ts-reset": "^0.5.1",
"@types/node": "^20.11.17",
"bumpp": "^9.3.0",
"bun": "^1.0.26",
"patch-package": "^8.0.0",
"publint": "^0.2.7",
"tsup": "^8.0.2",
Expand Down
49 changes: 49 additions & 0 deletions typescript-sdk/scripts/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { getBalance } from '#/query.ts'
import { unionActions } from '#/actions'
import { isValidChainId } from '#/constants'
import { createPublicClient, fallback, formatUnits, http, walletActions } from 'viem'

/**
* bun ./scripts/balance.ts \
* --chainId '11155111' | '6' \
* --address '0x3a7c1964ea700Ee19887c747C72e68F84Cb9C5DD'
*
* e.g.
* bun ./scripts/balance.ts --chainId 11155111 --address 0x3a7c1964ea700Ee19887c747C72e68F84Cb9C5DD
* bun ./scripts/balance.ts --chainId 6 --address union14qemq0vw6y3gc3u3e0aty2e764u4gs5lnxk4rv
*/

main().catch(_ => {
console.error(_)
process.exit(1)
})

async function main() {
const [chainFlag, chainId, addressFlag, address] = process.argv.slice(2)

if (!chainFlag || !chainId || !addressFlag || !address)
throw new Error('Usage: bun ./scripts/balance.ts --chain <chain> --address <address>')

if (!isValidChainId(chainId)) throw new Error(`Invalid chain: ${chainId}`)
const client = createPublicClient({
transport: fallback([
http(process.env.SEPOLIA_RPC_URL),
http('https://ethereum-sepolia.publicnode.com'),
]),
})
.extend(walletActions)
.extend(unionActions)

// @ts-expect-error
const balance = await getBalance(client, { chainId, address: address })

console.log({
[address]: {
chainId,
balance: {
bigint: balance,
number: chainId === '11155111' ? formatUnits(balance, 18) : formatUnits(balance, 6),
},
},
})
}
69 changes: 37 additions & 32 deletions typescript-sdk/scripts/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import '#/patch.ts'
import { raise } from '#/utilities'
import { unionActions } from '#/actions.ts'
import { privateKeyToAccount } from 'viem/accounts'
import { http, publicActions, createWalletClient } from 'viem'
import { http, publicActions, createWalletClient, fallback } from 'viem'
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
import { privateKeyToAccount, mnemonicToAccount } from 'viem/accounts'
import { UCS01_EVM_ADDRESS, demoPrivateKey, demoMnemonic, chain } from '#/constants'

main().catch(_ => {
Expand All @@ -13,15 +13,16 @@ main().catch(_ => {
})

async function main() {
const demoEthereumAccount = privateKeyToAccount(demoPrivateKey)
// const demoEthereumAccount = privateKeyToAccount(demoPrivateKey)
const demoEthereumAccount = mnemonicToAccount(demoMnemonic)
// 0x3a7c1964ea700Ee19887c747C72e68F84Cb9C5DD
const demoEthereumAddress = demoEthereumAccount.address
const demoUnionAccount = await DirectSecp256k1HdWallet.fromMnemonic(demoMnemonic, {
prefix: 'union',
})
const [demoUnionAccountData] = await demoUnionAccount.getAccounts()
const demoUnionAddress = demoUnionAccountData?.address ?? raise('demoUnionAddress is undefined')
// console.log(demoUnionAddress, demoEthereumAddress)
console.log(demoUnionAddress, demoEthereumAddress)

const SEPOILIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const { sepolia } = chain.ethereum
Expand All @@ -30,7 +31,10 @@ async function main() {
const client = createWalletClient({
chain: sepolia,
account: demoEthereumAccount,
transport: http(SEPOILIA_RPC_URL),
transport: fallback([
http(process.env.SEPOLIA_RPC_URL),
http('https://ethereum-sepolia.publicnode.com'),
]),
})
.extend(publicActions)
.extend(unionActions)
Expand All @@ -45,17 +49,17 @@ async function main() {
})
.then(_ => console.log({ balanceOnUnion: _ }))

await client
.sendAsset({
chainId: '6',
signer: demoUnionAccount,
assetId: unionTestnet.token.address,
amount: '1234',
denom: 'muno',
receiver: demoEthereumAddress,
gasPrice: '0.001muno',
})
.then(_ => console.log(JSON.stringify(_, undefined, 2)))
// await client
// .sendAsset({
// chainId: '6',
// signer: demoUnionAccount,
// assetId: unionTestnet.token.address,
// amount: '1234',
// denom: 'muno',
// receiver: demoEthereumAddress,
// gasPrice: '0.001muno',
// })
// .then(_ => console.log(JSON.stringify(_, undefined, 2)))

await client
.getBalance({
Expand All @@ -64,25 +68,26 @@ async function main() {
})
.then(_ => console.log({ balanceOnSepolia: _ }))

await client
.approveAsset({
chainId: '11155111',
signer: demoEthereumAccount,
amount: 500n,
spender: UCS01_EVM_ADDRESS,
assetId: denomAddress,
})
.then(_ => console.log({ approvalTransactionHash: _ }))

// await client
// .sendAsset({
// .approveAsset({
// chainId: '11155111',
// portId: sepolia.portId,
// signer: demoEthereumAccount,
// amount: 135920n,
// spender: UCS01_EVM_ADDRESS,
// assetId: denomAddress,
// amount: 100n,
// receiver: demoUnionAddress,
// simulate: true,
// // simulate:false,
// })
// .then(_ => console.log({ sendAssetFromEthereumToUnion: _ }))
// .then(_ => console.log({ approvalTransactionHash: _ }))

await client
.sendAsset({
chainId: '11155111',
portId: sepolia.portId,
signer: demoEthereumAccount,
assetId: denomAddress,
amount: 100n,
receiver: demoUnionAddress,
simulate: true,
})
.then(_ => console.log({ sendAssetFromEthereumToUnion: _ }))
}
Loading

0 comments on commit cf2cbcf

Please sign in to comment.