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 Jun 7, 2024
1 parent 2fee720 commit ef99ad6
Show file tree
Hide file tree
Showing 24 changed files with 342 additions and 322 deletions.
260 changes: 20 additions & 240 deletions app/src/generated/graphql-env.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ fastnode
feegrant
feegrantkeeper
feegrantmodule
feegrants
fetchurl
fetchzip
fields
Expand Down
Binary file modified typescript-sdk/bun.lockb
Binary file not shown.
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.17",
"version": "0.0.1-rc.18",
"publish": {
"include": ["./src/**/*.ts", "./jsr.json"]
}
Expand Down
14 changes: 9 additions & 5 deletions typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
"scripts": {
"build": "echo 'No need… jsr.io requires no build step'",
"typecheck": "tsc --project tsconfig.json --noEmit",
"demo": "bun ./scripts/demo.ts",
"faucet": "bun ./scripts/faucet.ts",
"balance": "bun ./scripts/balance.ts",
"transfer": "bun ./scripts/transfer.ts",
"publish": "bun ./scripts/publish.ts",
"publish:dry-run": "bun ./scripts/publish.ts --dry-run",
"demo": "bun ./playground/demo.ts",
"faucet": "bun ./playground/faucet.ts",
"balance": "bun ./playground/balance.ts",
"transfer": "bun ./playground/transfer.ts",
"test": "vitest --run",
"clean": "rm -rf dist node_modules",
"postinstall": "patch-package"
},
"imports": {
"#*": "./src/*"
},
"dependencies": {
"@cosmjs/cosmwasm-stargate": "0.32.3",
"@cosmjs/encoding": "^0.32.3",
Expand All @@ -25,7 +30,6 @@
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@cosmjs/amino": "0.32.3",
"@cosmjs/proto-signing": "0.32.3",
"@scure/base": "^1.1.6",
"@total-typescript/ts-reset": "^0.5.1",
"@types/bun": "^1.1.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bun
import { sepolia } from "viem/chains"
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"
import { privateKeyToAccount } from "viem/accounts"
import { http, publicActions, createWalletClient, fallback } from "viem"

Expand Down Expand Up @@ -41,5 +41,5 @@ const unionClient = await UnionClient.connectWithSecret({
evmSigner
})

const balances = await unionClient.getBalances()
console.info(balances)
// const balances = await unionClient.getBalances()
// console.info(balances)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bun
import { sepolia } from "viem/chains"
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"
import { privateKeyToAccount } from "viem/accounts"
import { http, erc20Abi, publicActions, createWalletClient } from "viem"
import { http, erc20Abi, publicActions, createWalletClient, getAddress } from "viem"
import contracts from "~root/versions/contracts.json" with { type: "json" }

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

Expand Down Expand Up @@ -37,6 +38,9 @@ const LINK_CONTRACT_ADDRESS = "0x779877A7B0D9E8603169DdbD7836e478b4624789"
const wOSMO_CONTRACT_ADDRESS = "0x3C148Ec863404e48d88757E88e456963A14238ef"
const USDC_CONTRACT_ADDRESS = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"

const currentContracts = contracts.find(c => c.latest === true) as (typeof contracts)[0]
const relayContractAddress = getAddress(currentContracts?.sepolia.UCS01)

const approve = await evmSigner.writeContract({
account: evmAccount,
address: LINK_CONTRACT_ADDRESS,
Expand Down Expand Up @@ -67,7 +71,7 @@ const osmoFromSepoliaToUnion = await unionClient.transferEvmAsset({
denomAddress: LINK_CONTRACT_ADDRESS,
amount: 1n,
sourceChannel: "channel-8",
contractAddress: "0xd0081080ae8493cf7340458eaf4412030df5feeb", // SEPOLIA_UCS01_ADDRESS
relayContractAddress,
simulate: true
})
console.log(osmoFromSepoliaToUnion)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bun
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"

/* `bun scripts/from-osmosis.ts --private-key "..."` */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bun
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { timestamp } from "./logger.ts"
import { UnionClient } from "#mod.ts"
import { timestamp } from "../scripts/logger.ts"

/* `bun scripts/from-osmosis.ts --private-key "..."` */

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bun
import { sepolia } from "viem/chains"
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"
import { privateKeyToAccount } from "viem/accounts"
import { http, createWalletClient, fallback } from "viem"
import { http, createWalletClient, fallback, getAddress } from "viem"
import contracts from "~root/versions/contracts.json" with { type: "json" }

/* `bun scripts/sepolia-to-union.ts --private-key "..."` */

Expand All @@ -17,6 +18,8 @@ if (!PRIVATE_KEY) throw new Error("Private key not found")

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

console.info({ address: evmAccount.address })

const evmSigner = createWalletClient({
chain: sepolia,
account: evmAccount,
Expand All @@ -27,7 +30,7 @@ const evmSigner = createWalletClient({
),
http(`https://eth-sepolia.g.alchemy.com/v2/SQAcneXzJzITjplR7cwQhFUqF-SU-ds4`)
])
}) //.extend(publicActions)
})

const unionClient = await UnionClient.connectWithSecret({
rpcUrl: "https://rpc.testnet.bonlulu.uno",
Expand All @@ -43,25 +46,26 @@ const LINK_CONTRACT_ADDRESS = "0x779877A7B0D9E8603169DdbD7836e478b4624789" // LI
const wOSMO_CONTRACT_ADDRESS = "0x3C148Ec863404e48d88757E88e456963A14238ef"
const USDC_CONTRACT_ADDRESS = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"

const currentContracts = contracts.find(c => c.latest === true) as (typeof contracts)[0]
const relayContractAddress = getAddress(currentContracts?.sepolia.UCS01)

const approve = await unionClient.approveEvmAssetTransfer({
account: evmAccount,
amount: 10n,
denomAddress: LINK_CONTRACT_ADDRESS
denomAddress: LINK_CONTRACT_ADDRESS,
relayContractAddress
})

console.log(approve)

const { address: unionAddress } = await unionClient.getCosmosSdkAccount()
console.info(JSON.stringify({ unionAddress }, undefined, 2))

const linkFromSepoliaToUnion = await unionClient.transferEvmAsset({
account: evmAccount,
receiver: unionAddress,
receiver: "union14qemq0vw6y3gc3u3e0aty2e764u4gs5lnxk4rv",
denomAddress: LINK_CONTRACT_ADDRESS,
amount: 2n,
sourceChannel: "channel-1",
contractAddress: "0xD0081080Ae8493cf7340458Eaf4412030df5FEEb",
simulate: true
sourceChannel: "channel-13",
simulate: true,
relayContractAddress
})

console.log(linkFromSepoliaToUnion)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bun
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"

/* `bun scripts/to-osmosis.ts --private-key "..."` */

Expand Down Expand Up @@ -31,7 +31,7 @@ const unoFromUnionToOsmosis = await unionClient.transferAssets({
transfer: {
channel: "channel-6",
receiver: "osmo14qemq0vw6y3gc3u3e0aty2e764u4gs5l32ydm0",
memo: "sending UNO from Union to Osmosissss"
memo: "sending UNO from Union to Osmosis"
}
},
funds: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bun
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bun
import "#/patch.ts"
import "#patch.ts"
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { consola, timestamp } from "./logger.ts"
import { UnionClient } from "#mod.ts"
import { consola, timestamp } from "../scripts/logger.ts"
import type { ExecuteInstruction } from "@cosmjs/cosmwasm-stargate"

/* `bun scripts/to-sepolia.ts --private-key "..."` */
Expand Down Expand Up @@ -30,15 +30,17 @@ const unionClient = await UnionClient.connectWithSecret({
gas: { amount: "0.0025", denom: "muno" }
})

const contractAddress = "union124t57vjgsyknnhmr3fpkmyvw2543448kpt2xhk5p5hxtmjjsrmzsjyc4n7"
const address = await unionClient.getCosmosSdkAccount()
console.info({ address })
const contractAddress = "union1eumfw2ppz8cwl8xdh3upttzp5rdyms48kqhm30f8g9u4zwj0pprqg2vmu3"
const stamp = timestamp()
const unionToSepoliaTransactions: Array<ExecuteInstruction> = Array.from(
{ length: TX_COUNT },
(_, index) => ({
contractAddress,
msg: {
transfer: {
channel: "channel-0",
channel: "channel-23",
receiver: "0x8478B37E983F520dBCB5d7D3aAD8276B82631aBd".slice(2),
memo: `${index} - ${stamp} Sending UNO from Union to Sepolia`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bun
import { parseArgs } from "node:util"
import { UnionClient } from "#/mod.ts"
import { UnionClient } from "#mod.ts"

/* `bun scripts/from-osmosis.ts --private-key "..."` */

Expand Down Expand Up @@ -28,7 +28,7 @@ const sendUnoToUnionAddress = await cwClient.sendTokens(
"union1wv7yh86t0s4lw5lp9wdn59c22us75thmy5233q",
[{ denom: "muno", amount: "100" }],
"auto",
"pepepopo"
"memo"
)

console.log(sendUnoToUnionAddress)
53 changes: 53 additions & 0 deletions typescript-sdk/scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bun
import * as Bun from "bun"
import { UnionClient } from "#mod.ts"
import { consola } from "./logger.ts"
import { parseArgs } from "node:util"
import currentContracts_ from "~root/versions/contracts.json" with { type: "json" }

/**
* Use this script to publish a new version of the TypeScript SDK to JSR registry
* This will check if the contracts in the SDK are up to date with the contracts in the registry
* If not it will fail
*
* Usage:
*
* `bun scripts/publish`
* `bun scripts/publish --dry-run`
*/

const { values } = parseArgs({
args: process.argv.slice(2),
options: { "dry-run": { type: "boolean", default: false } }
})

const DRY_RUN = values["dry-run"] ?? false

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

async function main() {
// TODO: Check if the version in jsr.json is bumped
// const versionBumped = Bun.$`git diff --quiet jsr.json && echo false || echo true`

/**
* Compare contracts in the current version of the SDK with the up to date contracts in $REPO_ROOT/versions/contracts.json.
*/

const { chainId, latest, ...currentContracts } = currentContracts_.find(
c => c.latest === true
) as (typeof currentContracts_)[0]

const pkgContracts = UnionClient.getContractAddresses()

if (!Bun.deepEquals(currentContracts, pkgContracts, true)) {
consola.fail("Contracts in the SDK are outdated:")
consola.box(JSON.stringify({ currentContracts, pkgContracts }, undefined, 2))
}

if (DRY_RUN) return Bun.$ /* sh */`bunx jsr publish --allow-dirty --allow-slow-types --dry-run`

return Bun.$ /* sh */`bunx jsr publish --allow-dirty --allow-slow-types`
}
33 changes: 22 additions & 11 deletions typescript-sdk/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { bech32 } from "@scure/base"
import { raise } from "./utilities.ts"
import { fromBech32 } from "@cosmjs/encoding"
import { getAddress, isHex, isAddress } from "viem"
import type { UnionAddress, EvmAddress } from "./types.ts"
import type { Bech32Address, HexAddress } from "./types.ts"

export const isValidEvmAddress = (address: unknown): address is EvmAddress =>
export const isValidEvmAddress = (address: unknown): address is HexAddress =>
typeof address === "string" && isAddress(address) && getAddress(address) === address

export function isValidCosmosAddress(
address: unknown,
{ expectedPrefixes }: { expectedPrefixes: ["union"] } = { expectedPrefixes: ["union"] }
): address is UnionAddress {
): address is Bech32Address {
if (typeof address !== "string") return false

try {
Expand Down Expand Up @@ -52,7 +52,7 @@ export function hexStringToUint8Array(hexString: string) {
return arrayBuffer
}

export const truncateUnionAddress = (address: string, length = 6) =>
export const truncateBech32Address = (address: string, length = 6) =>
length > 0 ? `${address.slice(0, length)}...${address.slice(-length)}` : address

export const truncateEvmAddress = (address: string, length = 6) =>
Expand All @@ -61,21 +61,32 @@ export const truncateEvmAddress = (address: string, length = 6) =>
export const convertByteArrayToHex = (byteArray: Uint8Array): string =>
byteArray.reduce((hex, byte) => hex + byte.toString(16).padStart(2, "0"), "").toUpperCase()

export function unionToEvmAddress(address: string): EvmAddress {
/**
* convert a bech32 address (cosmos, osmosis, union addresses) to hex address (evm)
* Previously: unionToEvmAddress
*/
export function bech32AddressToHex({ address }: { address: string }): HexAddress {
if (!isValidCosmosAddress(address)) raise("Invalid Cosmos address")
const { words } = bech32.decode(address)
return getAddress(`0x${Buffer.from(bech32.fromWords(words)).toString("hex")}`)
}

export const evmToCosmosAddress = (address: EvmAddress): UnionAddress => {
/**
* convert an Hex address (evm) to a bech32 address (cosmos, osmosis, union addresses)
* Previously: evmToCosmosAddress
*/
export function hexAddressToBech32({
address,
bech32Prefix
}: { address: HexAddress; bech32Prefix: string }): Bech32Address {
const words = bech32.toWords(Buffer.from(address.slice(2), "hex"))
return bech32.encode("union", words)
return bech32.encode(bech32Prefix, words)
}

export const normalizeToCosmosAddress = (address: string): UnionAddress =>
isHex(address) ? evmToCosmosAddress(address) : (address as UnionAddress)
// export const normalizeToCosmosAddress = (address: string): Bech32Address =>
// isHex(address) ? hexAddressToBech32(address) : (address as Bech32Address)

export const normalizeToEvmAddress = (address: string): EvmAddress =>
isHex(address) ? address : unionToEvmAddress(address as UnionAddress)
export const normalizeToEvmAddress = (address: string): HexAddress =>
isHex(address) ? address : bech32AddressToHex({ address })

export const munoToUno = (muno: string | number) => (Number(muno) / 1e6).toFixed(6)
Loading

0 comments on commit ef99ad6

Please sign in to comment.