From 8ff409f52ec80f01f33f4fa79ac25257a16678b8 Mon Sep 17 00:00:00 2001 From: luca Date: Mon, 17 Feb 2025 21:39:26 +0800 Subject: [PATCH 1/2] refactor: remove cosmjs from chain-admin --- templates/chain-admin/package.json | 5 +- templates/chain-admin/utils/contract.ts | 13 +- templates/chain-admin/utils/faucet.ts | 2 +- .../chain-admin/utils/staking/staking.ts | 3 +- templates/chain-admin/yarn.lock | 330 +++++++----------- 5 files changed, 142 insertions(+), 211 deletions(-) diff --git a/templates/chain-admin/package.json b/templates/chain-admin/package.json index badb1eb7..5815a58b 100644 --- a/templates/chain-admin/package.json +++ b/templates/chain-admin/package.json @@ -20,15 +20,14 @@ }, "dependencies": { "@chain-registry/assets": "1.63.5", - "@cosmjs/stargate": "0.31.1", "@interchain-kit/core": "^0.2.1", "@interchain-kit/keplr-extension": "^0.2.1", "@interchain-kit/leap-extension": "^0.2.1", "@interchain-kit/react": "^0.2.1", "@interchain-ui/react": "1.23.31", "@interchain-ui/react-no-ssr": "0.1.2", - "@interchainjs/cosmos": "^1.9.4", - "@interchainjs/react": "^1.9.4", + "@interchainjs/cosmos": "^1.9.12", + "@interchainjs/react": "^1.9.12", "@tanstack/react-query": "4.32.0", "ace-builds": "1.35.0", "bignumber.js": "9.1.2", diff --git a/templates/chain-admin/utils/contract.ts b/templates/chain-admin/utils/contract.ts index 41891b1b..66dd973a 100644 --- a/templates/chain-admin/utils/contract.ts +++ b/templates/chain-admin/utils/contract.ts @@ -1,11 +1,12 @@ import { AssetList, Chain } from '@chain-registry/v2-types'; -import { toBech32, fromBech32 } from '@cosmjs/encoding'; -import { Coin, logs, parseCoins } from '@cosmjs/stargate'; +import { toBech32, fromBech32 } from '@interchainjs/encoding'; +import { Log, findAttribute } from '@interchainjs/utils'; +import { parseCoins } from '@interchainjs/amino'; import BigNumber from 'bignumber.js'; import { jsd, DeliverTxResponse as DeliverJsdTxResponse } from 'hyperwebjs'; import { AccessType } from '@interchainjs/react/cosmwasm/wasm/v1/types'; import { CodeInfoResponse } from '@interchainjs/react/cosmwasm/wasm/v1/query'; -import { DeliverTxResponse } from '@interchainjs/react/types'; +import { Coin, DeliverTxResponse } from '@interchainjs/react/types'; import { getExponentFromAsset } from './common'; @@ -75,18 +76,18 @@ export const bytesToKb = (bytes: number) => { }; export const findAttr = ( - events: logs.Log['events'], + events: Log['events'], eventType: string, attrKey: string ) => { - const mimicLog: logs.Log = { + const mimicLog: Log = { msg_index: 0, log: '', events, }; try { - return logs.findAttribute([mimicLog], eventType, attrKey).value; + return findAttribute([mimicLog], eventType, attrKey).value; } catch { return undefined; } diff --git a/templates/chain-admin/utils/faucet.ts b/templates/chain-admin/utils/faucet.ts index cceec1a8..9d4c65f3 100644 --- a/templates/chain-admin/utils/faucet.ts +++ b/templates/chain-admin/utils/faucet.ts @@ -1,4 +1,4 @@ -import { fromBech32 } from '@cosmjs/encoding'; +import { fromBech32 } from '@interchainjs/encoding'; export const creditFromFaucet = async ( address: string, diff --git a/templates/chain-admin/utils/staking/staking.ts b/templates/chain-admin/utils/staking/staking.ts index a228b69f..0f7e54cd 100644 --- a/templates/chain-admin/utils/staking/staking.ts +++ b/templates/chain-admin/utils/staking/staking.ts @@ -4,7 +4,7 @@ import { Validator, } from '@interchainjs/react/cosmos/staking/v1beta1/staking'; import { isGreaterThanZero, shiftDigits, toNumber } from '.'; -import { Coin, decodeCosmosSdkDecFromProto } from '@cosmjs/stargate'; +import { decodeCosmosSdkDecFromProto } from '@interchainjs/encoding'; import { QueryDelegatorDelegationsResponse, QueryParamsResponse, @@ -12,6 +12,7 @@ import { import BigNumber from 'bignumber.js'; import { QueryAnnualProvisionsResponse } from '@interchainjs/react/cosmos/mint/v1beta1/query'; import type { Asset } from '@chain-registry/v2-types'; +import type { Coin } from '@interchainjs/react/types'; const DAY_TO_SECONDS = 24 * 60 * 60; const ZERO = '0'; diff --git a/templates/chain-admin/yarn.lock b/templates/chain-admin/yarn.lock index 6c88eebf..346f3a9b 100644 --- a/templates/chain-admin/yarn.lock +++ b/templates/chain-admin/yarn.lock @@ -100,6 +100,20 @@ __metadata: languageName: node linkType: hard +"@chain-registry/v2-types@npm:0.53.68": + version: 0.53.68 + resolution: "@chain-registry/v2-types@npm:0.53.68" + checksum: 10c0/5b4d1d039bce3bc595f83e6950f6c1a5594984ae141461f2225b9a45a3c2dddc243ccb0d1af433dae6d9477a724170d471a365d6905ede854c0fb478f343b918 + languageName: node + linkType: hard + +"@chain-registry/v2-types@npm:0.53.72": + version: 0.53.72 + resolution: "@chain-registry/v2-types@npm:0.53.72" + checksum: 10c0/a86ae13acfc13ec0f954c5c9b2211d1d9e50cc006b02a4113f33f9eaa2be350c01a5838869f4520d574b24019fd1f1b9bfc44781fa1331a2b0569cceba86a40a + languageName: node + linkType: hard + "@chain-registry/v2-types@npm:^0.49.6": version: 0.49.86 resolution: "@chain-registry/v2-types@npm:0.49.86" @@ -114,6 +128,15 @@ __metadata: languageName: node linkType: hard +"@chain-registry/v2@npm:1.71.71": + version: 1.71.71 + resolution: "@chain-registry/v2@npm:1.71.71" + dependencies: + "@chain-registry/v2-types": "npm:^0.53.40" + checksum: 10c0/b498b77509b3750d2533186ca3a4ae49776a1fcf59d4b9be9a43e9287b805a48a300f1ba375e108ac9565f738a4c0089009e186bf27be42edffb7355b5dfc962 + languageName: node + linkType: hard + "@chain-registry/v2@npm:^1.65.6, @chain-registry/v2@npm:^1.71.71": version: 1.71.115 resolution: "@chain-registry/v2@npm:1.71.115" @@ -145,33 +168,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/amino@npm:^0.31.1, @cosmjs/amino@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/amino@npm:0.31.3" - dependencies: - "@cosmjs/crypto": "npm:^0.31.3" - "@cosmjs/encoding": "npm:^0.31.3" - "@cosmjs/math": "npm:^0.31.3" - "@cosmjs/utils": "npm:^0.31.3" - checksum: 10c0/2f5f866df043bef072ef8802844beacd282027dcc32f69428fe98e256d5fec0dd4a45a4c7d6c45c8a7d7f4387893ef02c8b471a32d6450215f56157d6eaa467e - languageName: node - linkType: hard - -"@cosmjs/crypto@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/crypto@npm:0.31.3" - dependencies: - "@cosmjs/encoding": "npm:^0.31.3" - "@cosmjs/math": "npm:^0.31.3" - "@cosmjs/utils": "npm:^0.31.3" - "@noble/hashes": "npm:^1" - bn.js: "npm:^5.2.0" - elliptic: "npm:^6.5.4" - libsodium-wrappers-sumo: "npm:^0.7.11" - checksum: 10c0/595de61be8832c0f012e80343427efc5f7dec6157f31410908edefcae710f31bed723b50d0979b66d961765854e76d89e6942b5430a727f458b8d7e67fc7b174 - languageName: node - linkType: hard - "@cosmjs/crypto@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/crypto@npm:0.32.3" @@ -198,27 +194,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/encoding@npm:^0.31.1, @cosmjs/encoding@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/encoding@npm:0.31.3" - dependencies: - base64-js: "npm:^1.3.0" - bech32: "npm:^1.1.4" - readonly-date: "npm:^1.0.0" - checksum: 10c0/48eb9f9259bdfd88db280b6b5ea970fd1b3b0f81a8f4253f315ff2c736b27dbe0fdf74405c52ad35fcd4b16f1fde4250c4de936997b9d92e79cb97d98cc538c7 - languageName: node - linkType: hard - -"@cosmjs/json-rpc@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/json-rpc@npm:0.31.3" - dependencies: - "@cosmjs/stream": "npm:^0.31.3" - xstream: "npm:^11.14.0" - checksum: 10c0/8cc8fa9490e512a2865e888b162e2cc38477a6a5b6261fce885579712c880087c8bb2733717eb5fe03c131f31064e1f9060f87ae2a4d1d01d6c465761ab1a32d - languageName: node - linkType: hard - "@cosmjs/json-rpc@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/json-rpc@npm:0.32.3" @@ -238,15 +213,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/math@npm:^0.31.1, @cosmjs/math@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/math@npm:0.31.3" - dependencies: - bn.js: "npm:^5.2.0" - checksum: 10c0/7dd742ee6ff52bc322d3cd43b9ab0e15d70b41b74a487f64c23609ffe5abce9a02cbec46a729155608a1abb3bc0067ac97361f0af23453fb0b4c438b17e37a99 - languageName: node - linkType: hard - "@cosmjs/proto-signing@npm:0.32.3, @cosmjs/proto-signing@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/proto-signing@npm:0.32.3" @@ -261,33 +227,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/proto-signing@npm:^0.31.1": - version: 0.31.3 - resolution: "@cosmjs/proto-signing@npm:0.31.3" - dependencies: - "@cosmjs/amino": "npm:^0.31.3" - "@cosmjs/crypto": "npm:^0.31.3" - "@cosmjs/encoding": "npm:^0.31.3" - "@cosmjs/math": "npm:^0.31.3" - "@cosmjs/utils": "npm:^0.31.3" - cosmjs-types: "npm:^0.8.0" - long: "npm:^4.0.0" - checksum: 10c0/91bc6c0d03462b16e85fd6acfd3d28ab56a8de9a199f97601aac30aace75b64250bf0efcdda0aa5e3ea9e6defa46844b5f8e4358aabaeeb16d439480f55bbff7 - languageName: node - linkType: hard - -"@cosmjs/socket@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/socket@npm:0.31.3" - dependencies: - "@cosmjs/stream": "npm:^0.31.3" - isomorphic-ws: "npm:^4.0.1" - ws: "npm:^7" - xstream: "npm:^11.14.0" - checksum: 10c0/35ce93726f1c5c7d4cdf49c68d754b5587ac94fa65fd66f3db625c4794413359e225ddcaa55ee0bb17806a0b9cc13f884a7ec780503267addc6d03aacee1770c - languageName: node - linkType: hard - "@cosmjs/socket@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/socket@npm:0.32.3" @@ -300,26 +239,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/stargate@npm:0.31.1": - version: 0.31.1 - resolution: "@cosmjs/stargate@npm:0.31.1" - dependencies: - "@confio/ics23": "npm:^0.6.8" - "@cosmjs/amino": "npm:^0.31.1" - "@cosmjs/encoding": "npm:^0.31.1" - "@cosmjs/math": "npm:^0.31.1" - "@cosmjs/proto-signing": "npm:^0.31.1" - "@cosmjs/stream": "npm:^0.31.1" - "@cosmjs/tendermint-rpc": "npm:^0.31.1" - "@cosmjs/utils": "npm:^0.31.1" - cosmjs-types: "npm:^0.8.0" - long: "npm:^4.0.0" - protobufjs: "npm:~6.11.3" - xstream: "npm:^11.14.0" - checksum: 10c0/4532669efad7630f32df99d3e4f760d870a210e378169c7fa6311b94c722c710990c311f59054621ea50031f507ea5f5fdfc1b20dc77b5452ae59626421a2d4b - languageName: node - linkType: hard - "@cosmjs/stargate@npm:0.32.3": version: 0.32.3 resolution: "@cosmjs/stargate@npm:0.32.3" @@ -338,15 +257,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/stream@npm:^0.31.1, @cosmjs/stream@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/stream@npm:0.31.3" - dependencies: - xstream: "npm:^11.14.0" - checksum: 10c0/e0279b925c4f02535ba9b1f6f9563a1db4fb53ed1396e4e3958fcad887e047a78b431a227dd7c159aadb6e0e054db9dfb34b7a9128f2082ff3114bcfd74516c3 - languageName: node - linkType: hard - "@cosmjs/stream@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/stream@npm:0.32.3" @@ -356,24 +266,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/tendermint-rpc@npm:^0.31.1": - version: 0.31.3 - resolution: "@cosmjs/tendermint-rpc@npm:0.31.3" - dependencies: - "@cosmjs/crypto": "npm:^0.31.3" - "@cosmjs/encoding": "npm:^0.31.3" - "@cosmjs/json-rpc": "npm:^0.31.3" - "@cosmjs/math": "npm:^0.31.3" - "@cosmjs/socket": "npm:^0.31.3" - "@cosmjs/stream": "npm:^0.31.3" - "@cosmjs/utils": "npm:^0.31.3" - axios: "npm:^0.21.2" - readonly-date: "npm:^1.0.0" - xstream: "npm:^11.14.0" - checksum: 10c0/1d8d8a78cc1dc54884c0916e709c98d533215f2235ce48f2079cbd8b3a9edf7aa14f216b815d727cacabfead54c0b15ca622fd43243260d8d311bc408edd0f11 - languageName: node - linkType: hard - "@cosmjs/tendermint-rpc@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/tendermint-rpc@npm:0.32.3" @@ -392,13 +284,6 @@ __metadata: languageName: node linkType: hard -"@cosmjs/utils@npm:^0.31.1, @cosmjs/utils@npm:^0.31.3": - version: 0.31.3 - resolution: "@cosmjs/utils@npm:0.31.3" - checksum: 10c0/26266e1206ed8c7c4e744db1e97fc7a341ffee383ca9f43e6c9e8ff596039a90068c39aadc4f6524b6f2b5b6d581318657f3eb272f98b9e430f2d0df79382b6a - languageName: node - linkType: hard - "@cosmjs/utils@npm:^0.32.3": version: 0.32.3 resolution: "@cosmjs/utils@npm:0.32.3" @@ -881,6 +766,18 @@ __metadata: languageName: node linkType: hard +"@interchainjs/amino@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/amino@npm:1.9.12" + dependencies: + "@interchainjs/crypto": "npm:1.9.12" + "@interchainjs/encoding": "npm:1.9.12" + "@interchainjs/math": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" + checksum: 10c0/e845903aa5b41190ddc5662a1113131e44ce64feee3588f7e95f85173f6f8855204ed0f3243f4406520399f770b73411721c9cd5bbdbd5a28acda70ba442b862 + languageName: node + linkType: hard + "@interchainjs/auth@npm:1.6.3": version: 1.6.3 resolution: "@interchainjs/auth@npm:1.6.3" @@ -894,17 +791,17 @@ __metadata: languageName: node linkType: hard -"@interchainjs/auth@npm:1.9.4": - version: 1.9.4 - resolution: "@interchainjs/auth@npm:1.9.4" +"@interchainjs/auth@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/auth@npm:1.9.12" dependencies: - "@interchainjs/types": "npm:1.9.4" - "@interchainjs/utils": "npm:1.9.4" + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" "@noble/curves": "npm:^1.1.0" "@noble/hashes": "npm:^1.3.1" "@scure/bip32": "npm:^1.0.10" ethers: "npm:^6.5.1" - checksum: 10c0/a79ef47fd5a619607d03e972cd66636b1087a22dae97821d3210d95d79eca7ed2e7522da8de935d0dc2b9dc2f26e2aafecf50998d3b5961654c733657edd929c + checksum: 10c0/125c0f1a6f60d32ff851e15a1afb4c96cb0fb74823d8251bc83e1c07f99e1bece4879b97f72b43103c903ed1d1ab2550d8c999235302bf26695230f35b9d5bb1 languageName: node linkType: hard @@ -918,13 +815,13 @@ __metadata: languageName: node linkType: hard -"@interchainjs/cosmos-types@npm:1.9.4": - version: 1.9.4 - resolution: "@interchainjs/cosmos-types@npm:1.9.4" +"@interchainjs/cosmos-types@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/cosmos-types@npm:1.9.12" dependencies: - "@interchainjs/types": "npm:1.9.4" - "@interchainjs/utils": "npm:1.9.4" - checksum: 10c0/0b28d2b7347d1e055f743e4f989bfe56ce86c25a377cf3b9acbd41147e7ba44b117c5e6bb5e1c68ad733ec8a0d18952948d390905090fbb26bb059dfd8fd00f5 + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" + checksum: 10c0/6e6e8ccd733b6d94cb35c1a84cff26cc7dacc8259166114128c804a42a48002174fa03d91020585ff7b569c81804e572c05af76f89dee1373357df8d49aa77a2 languageName: node linkType: hard @@ -945,36 +842,87 @@ __metadata: languageName: node linkType: hard -"@interchainjs/cosmos@npm:1.9.4, @interchainjs/cosmos@npm:^1.9.4": - version: 1.9.4 - resolution: "@interchainjs/cosmos@npm:1.9.4" +"@interchainjs/cosmos@npm:1.9.12, @interchainjs/cosmos@npm:^1.9.12": + version: 1.9.12 + resolution: "@interchainjs/cosmos@npm:1.9.12" dependencies: "@chain-registry/v2": "npm:^1.65.6" - "@chain-registry/v2-types": "npm:^0.49.6" - "@interchainjs/auth": "npm:1.9.4" - "@interchainjs/cosmos-types": "npm:1.9.4" - "@interchainjs/types": "npm:1.9.4" - "@interchainjs/utils": "npm:1.9.4" + "@chain-registry/v2-types": "npm:0.53.68" + "@interchainjs/auth": "npm:1.9.12" + "@interchainjs/cosmos-types": "npm:1.9.12" + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" "@noble/curves": "npm:^1.1.0" "@noble/hashes": "npm:^1.3.1" decimal.js: "npm:^10.4.3" - checksum: 10c0/23e5b04ab1a3c3624888aa8f7468f5926c94908abd2f57824c13f479d87d7e5e0de5ec3a186efef762a66713c486fcbba9ad6139d250d0d31471979b2deb6ca3 + checksum: 10c0/4446d4d4a43cbc1dab2d6ddf9f3a327186b73ce4406c6d45d1ddc371471b37e74998441fc64a509dbc1e8578d0dc46bfbf3130a6c8e9090c955d5c9782807c9c + languageName: node + linkType: hard + +"@interchainjs/crypto@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/crypto@npm:1.9.12" + dependencies: + "@interchainjs/encoding": "npm:1.9.12" + "@interchainjs/math": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" + "@noble/hashes": "npm:^1" + bn.js: "npm:^5.2.0" + elliptic: "npm:^6.5.4" + libsodium-wrappers-sumo: "npm:^0.7.11" + checksum: 10c0/4f9821aa442f585ca47785cda77209004e4cc0ee147a3abfb0324a03a88afce50869b053589690a8b67b3a54d3197177d255109dc67d46297affc23c944240a3 + languageName: node + linkType: hard + +"@interchainjs/encoding@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/encoding@npm:1.9.12" + dependencies: + "@interchainjs/math": "npm:1.9.12" + base64-js: "npm:^1.3.0" + bech32: "npm:^1.1.4" + readonly-date: "npm:^1.0.0" + checksum: 10c0/1caddaaf1afbebdd0829c95fd10d45541b41dbf12c4d35cde50a09705881f3e55a7f8d8e4c007d813ae89243603762efd359a1c66648aa70f35f5d658a7f1794 + languageName: node + linkType: hard + +"@interchainjs/math@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/math@npm:1.9.12" + dependencies: + bn.js: "npm:^5.2.0" + checksum: 10c0/771d3b6056941b4c16f950eb977886035f8a7d891f541cce739357b571209c869110f361f3c19a9d4f3470fa75be3cd0d699e366b3917eac3e8433e6936b18ca languageName: node linkType: hard -"@interchainjs/react@npm:^1.9.4": - version: 1.9.4 - resolution: "@interchainjs/react@npm:1.9.4" +"@interchainjs/pubkey@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/pubkey@npm:1.9.12" dependencies: - "@interchainjs/cosmos": "npm:1.9.4" - "@interchainjs/cosmos-types": "npm:1.9.4" - "@interchainjs/types": "npm:1.9.4" - "@interchainjs/utils": "npm:1.9.4" + "@interchainjs/amino": "npm:1.9.12" + "@interchainjs/cosmos-types": "npm:1.9.12" + "@interchainjs/encoding": "npm:1.9.12" + "@interchainjs/math": "npm:1.9.12" + "@interchainjs/types": "npm:1.9.12" + checksum: 10c0/59d1ee9e4b1bb77ed4565f76e09ec3f930bcb4ff59c581e80616401313d89080a09b98dcd28c2c046c08e818d922dd8459fd4101a2aab39b69330715b9abc4cd + languageName: node + linkType: hard + +"@interchainjs/react@npm:^1.9.12": + version: 1.9.12 + resolution: "@interchainjs/react@npm:1.9.12" + dependencies: + "@interchainjs/cosmos": "npm:1.9.12" + "@interchainjs/cosmos-types": "npm:1.9.12" + "@interchainjs/encoding": "npm:1.9.12" + "@interchainjs/pubkey": "npm:1.9.12" + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" "@noble/hashes": "npm:^1.3.1" decimal.js: "npm:^10.4.3" peerDependencies: "@tanstack/react-query": 4.29.1 - checksum: 10c0/429631e61e4e1344341247ce8296f7faa0b08b94b1481b601f9e6d456ca260e79a3846067b3be6dd703abfbb31fe5a93f55ab28fd29d7a8bafb7081d987d6289 + checksum: 10c0/fad36e15f48433e49e84d20750d9423aaad76ee899802f0f01fbc0f64e2cf87b38d11d685dc3e0510babc0553bdff92fd59c53100d076a8d0165bc60f72b2ed9 languageName: node linkType: hard @@ -987,12 +935,12 @@ __metadata: languageName: node linkType: hard -"@interchainjs/types@npm:1.9.4": - version: 1.9.4 - resolution: "@interchainjs/types@npm:1.9.4" +"@interchainjs/types@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/types@npm:1.9.12" dependencies: decimal.js: "npm:^10.4.3" - checksum: 10c0/bd82ba9e74316a9012f866326aba5c3bb37521986861f0c08ccef5b34afc738f73a4d2e436bc90e0b447f3dfe05f1edfaa38e08eebaa202fa1a5629a93d209d8 + checksum: 10c0/30607621c2c4f187a66a420bcee8fbf38884b880bf2dbbdb250eab5bf490bde86ddea0f19d94b06a136199671aff287d7be0bae9bbc2359d797006d5029815c8 languageName: node linkType: hard @@ -1006,14 +954,16 @@ __metadata: languageName: node linkType: hard -"@interchainjs/utils@npm:1.9.4": - version: 1.9.4 - resolution: "@interchainjs/utils@npm:1.9.4" +"@interchainjs/utils@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/utils@npm:1.9.12" dependencies: - "@interchainjs/types": "npm:1.9.4" + "@chain-registry/v2": "npm:1.71.71" + "@chain-registry/v2-types": "npm:0.53.72" + "@interchainjs/types": "npm:1.9.12" bech32: "npm:^2.0.0" decimal.js: "npm:^10.4.3" - checksum: 10c0/93c530c292ad16a24683fe4765eae28e3631535dcf6d745174c9287acb162678ad25f8a8f21e379ab2b287c6ea4bd04ed4d38306346fe5c8d1be1200afa56410 + checksum: 10c0/62e0c147a7f04c574c50702fc10ee9e9d207bbb0fe438593afcf67748ff57112ad7bee8f39954c178b39231bc24811263efd81ee72adbe29746c46fcf229c4da languageName: node linkType: hard @@ -4188,15 +4138,6 @@ __metadata: languageName: node linkType: hard -"axios@npm:^0.21.2": - version: 0.21.4 - resolution: "axios@npm:0.21.4" - dependencies: - follow-redirects: "npm:^1.14.0" - checksum: 10c0/fbcff55ec68f71f02d3773d467db2fcecdf04e749826c82c2427a232f9eba63242150a05f15af9ef15818352b814257541155de0281f8fb2b7e8a5b79f7f2142 - languageName: node - linkType: hard - "axios@npm:^1.6.0": version: 1.6.8 resolution: "axios@npm:1.6.8" @@ -4511,15 +4452,14 @@ __metadata: dependencies: "@chain-registry/assets": "npm:1.63.5" "@chain-registry/types": "npm:0.44.3" - "@cosmjs/stargate": "npm:0.31.1" "@interchain-kit/core": "npm:^0.2.1" "@interchain-kit/keplr-extension": "npm:^0.2.1" "@interchain-kit/leap-extension": "npm:^0.2.1" "@interchain-kit/react": "npm:^0.2.1" "@interchain-ui/react": "npm:1.23.31" "@interchain-ui/react-no-ssr": "npm:0.1.2" - "@interchainjs/cosmos": "npm:^1.9.4" - "@interchainjs/react": "npm:^1.9.4" + "@interchainjs/cosmos": "npm:^1.9.12" + "@interchainjs/react": "npm:^1.9.12" "@starship-ci/cli": "npm:^2.10.2" "@tanstack/react-query": "npm:4.32.0" "@tanstack/react-query-devtools": "npm:4.32.0" @@ -4762,16 +4702,6 @@ __metadata: languageName: node linkType: hard -"cosmjs-types@npm:^0.8.0": - version: 0.8.0 - resolution: "cosmjs-types@npm:0.8.0" - dependencies: - long: "npm:^4.0.0" - protobufjs: "npm:~6.11.2" - checksum: 10c0/910a84d04d17c3a32120bda52063a582325b900e9bb2f5ddffee621c1d053bc562bedc0d39d20e12736445b66d897bdae085247f51c6ffd1ca0154f99b938214 - languageName: node - linkType: hard - "cosmjs-types@npm:^0.9.0": version: 0.9.0 resolution: "cosmjs-types@npm:0.9.0" @@ -5843,7 +5773,7 @@ __metadata: languageName: node linkType: hard -"follow-redirects@npm:^1.14.0, follow-redirects@npm:^1.15.6": +"follow-redirects@npm:^1.15.6": version: 1.15.6 resolution: "follow-redirects@npm:1.15.6" peerDependenciesMeta: @@ -8459,7 +8389,7 @@ __metadata: languageName: node linkType: hard -"protobufjs@npm:^6.11.2, protobufjs@npm:^6.8.8, protobufjs@npm:~6.11.2, protobufjs@npm:~6.11.3": +"protobufjs@npm:^6.11.2, protobufjs@npm:^6.8.8": version: 6.11.4 resolution: "protobufjs@npm:6.11.4" dependencies: From 63e90054bdfe4a8b35699b40a63ebade5f4690ae Mon Sep 17 00:00:00 2001 From: luca Date: Mon, 17 Feb 2025 23:04:46 +0800 Subject: [PATCH 2/2] refactor: remove cosmjs from hyperweb --- .../hyperweb/__tests__/ammContract.test.ts | 100 ++++++---- templates/hyperweb/__tests__/setup.test.ts | 51 +++-- .../hyperweb/__tests__/simpleState.test.ts | 107 ++++++----- .../hyperweb/docs/WRITING_FIRST_CONTRACT.md | 175 +++++++++--------- templates/hyperweb/package.json | 1 + templates/hyperweb/yarn.lock | 109 ++++++++++- 6 files changed, 361 insertions(+), 182 deletions(-) diff --git a/templates/hyperweb/__tests__/ammContract.test.ts b/templates/hyperweb/__tests__/ammContract.test.ts index 00ae684c..2dbff06a 100644 --- a/templates/hyperweb/__tests__/ammContract.test.ts +++ b/templates/hyperweb/__tests__/ammContract.test.ts @@ -1,15 +1,15 @@ // @ts-nocheck -import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; -import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; +import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd"; +import { assertIsDeliverTxSuccess } from "@interchainjs/cosmos/utils"; import path from "path"; -import fs from 'fs'; -import { getSigningJsdClient, jsd } from 'hyperwebjs' -import { useChain, generateMnemonic } from 'starshipjs'; -import { sleep } from '../test-utils/sleep'; -import './setup.test'; +import fs from "fs"; +import { getSigningJsdClient, jsd } from "hyperwebjs"; +import { useChain, generateMnemonic } from "starshipjs"; +import { sleep } from "../test-utils/sleep"; +import "./setup.test"; -describe('Contract 2: AMM contract test', () => { +describe("Contract 2: AMM contract test", () => { let wallet, denom, address, queryClient, signingClient; let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; let contractCode, contractIndex; @@ -17,39 +17,46 @@ describe('Contract 2: AMM contract test', () => { let wallet2, address2; let fee; - const denom2 = "uhypweb", uatom = "uatom", uusdc = "uusdc"; + const denom2 = "uhypweb", + uatom = "uatom", + uusdc = "uusdc"; beforeAll(async () => { - ({ - chainInfo, - getCoin, - getRpcEndpoint, - creditFromFaucet - } = useChain('hyperweb')); + ({ chainInfo, getCoin, getRpcEndpoint, creditFromFaucet } = + useChain("hyperweb")); denom = (await getCoin()).base; + const commonPrefix = chainInfo.chain.bech32_prefix; + const cosmosHdPath = "m/44'/118'/0'/0/0"; + // Initialize wallet - wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { - prefix: chainInfo.chain.bech32_prefix - }); + wallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [ + { + prefix: commonPrefix, + hdPath: cosmosHdPath, + }, + ]); address = (await wallet.getAccounts())[0].address; - console.log(`contract creator address for amm: ${address}`) + console.log(`contract creator address for amm: ${address}`); // Initialize wallet2 - wallet2 = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { - prefix: chainInfo.chain.bech32_prefix - }); + wallet2 = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [ + { + prefix: commonPrefix, + hdPath: cosmosHdPath, + }, + ]); address2 = (await wallet2.getAccounts())[0].address; - console.log(`contract creator address2 for amm: ${address2}`) + console.log(`contract creator address2 for amm: ${address2}`); // Create custom cosmos interchain client queryClient = await jsd.ClientFactory.createRPCQueryClient({ - rpcEndpoint: await getRpcEndpoint() + rpcEndpoint: await getRpcEndpoint(), }); signingClient = await getSigningJsdClient({ rpcEndpoint: await getRpcEndpoint(), - signer: wallet + signer: wallet, }); await creditFromFaucet(address, denom); @@ -60,21 +67,24 @@ describe('Contract 2: AMM contract test', () => { await creditFromFaucet(address2, denom); await creditFromFaucet(address2, denom2); - fee = {amount: [{denom, amount: '100000'}], gas: '550000'}; + fee = { amount: [{ denom, amount: "100000" }], gas: "550000" }; await sleep(2000); // sleep for 1 sec to get tokens transferred from faucet successfully }); - it('check balance', async () => { + it("check balance", async () => { const balance = await signingClient.getBalance(address, denom); expect(balance.amount).toEqual("10000000000"); expect(balance.denom).toEqual(denom); }); - it('instantiate contract', async () => { + it("instantiate contract", async () => { // Read contract code from external file - const contractPath = path.join(__dirname, '../dist/contracts/ammContract.js'); - contractCode = fs.readFileSync(contractPath, 'utf8'); + const contractPath = path.join( + __dirname, + "../dist/contracts/ammContract.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); const msg = jsd.jsd.MessageComposer.fromPartial.instantiate({ creator: address, @@ -85,20 +95,24 @@ describe('Contract 2: AMM contract test', () => { assertIsDeliverTxSuccess(result); // Parse the response to get the contract index - const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg( + result.msgResponses[0] + ); contractIndex = response.index; expect(contractIndex).toBeGreaterThan(0); console.log(`contract index: ${contractIndex}`); }); - it('query for contract based on index', async () => { - const response = await queryClient.jsd.jsd.contracts({index: contractIndex}); + it("query for contract based on index", async () => { + const response = await queryClient.jsd.jsd.contracts({ + index: contractIndex, + }); expect(response.contracts.code).toEqual(contractCode); expect(response.contracts.index).toEqual(contractIndex); expect(response.contracts.creator).toEqual(address); }); - it('perform getTotalSupply eval', async () => { + it("perform getTotalSupply eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -109,11 +123,13 @@ describe('Contract 2: AMM contract test', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("0"); }); - it('perform addLiquidity eval', async () => { + it("perform addLiquidity eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -124,11 +140,13 @@ describe('Contract 2: AMM contract test', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("null"); }); - it('check balance after addLiquidity', async () => { + it("check balance after addLiquidity", async () => { const usdcBalance = await signingClient.getBalance(address, uusdc); expect(usdcBalance.amount).toEqual("9950000000"); @@ -136,7 +154,7 @@ describe('Contract 2: AMM contract test', () => { expect(atomBalance.amount).toEqual("9950000000"); }); - it('perform swap eval', async () => { + it("perform swap eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -147,7 +165,9 @@ describe('Contract 2: AMM contract test', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("9969998.011982398"); }); }); diff --git a/templates/hyperweb/__tests__/setup.test.ts b/templates/hyperweb/__tests__/setup.test.ts index 50d77aea..b8b9166a 100644 --- a/templates/hyperweb/__tests__/setup.test.ts +++ b/templates/hyperweb/__tests__/setup.test.ts @@ -1,27 +1,52 @@ -// @ts-nocheck -import path from 'path'; +import path from "path"; -import { StargateClient } from '@cosmjs/stargate'; - -import { ConfigContext, useChain, useRegistry } from 'starshipjs'; +import { SigningClient } from "@interchainjs/cosmos/signing-client"; +import { DirectGenericOfflineSigner } from "@interchainjs/cosmos/types/wallet"; +import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd"; +import { + ConfigContext, + generateMnemonic, + useChain, + useRegistry, +} from "starshipjs"; beforeAll(async () => { - const configFile = path.join(__dirname, '..', 'configs', 'local.yaml'); + const configFile = path.join(__dirname, "..", "configs", "local.yaml"); ConfigContext.setConfigFile(configFile); ConfigContext.setRegistry(await useRegistry(configFile)); }); -describe('Test clients', () => { - let client; +describe("Test clients", () => { + let client: SigningClient; beforeAll(async () => { - const { getRpcEndpoint } = useChain('hyperweb'); - client = await StargateClient.connect(await getRpcEndpoint()); + const { getRpcEndpoint, chainInfo } = useChain("hyperweb"); + + const commonPrefix = chainInfo?.chain?.bech32_prefix; + const cosmosHdPath = "m/44'/118'/0'/0/0"; + + const directWallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [ + { + prefix: commonPrefix, + hdPath: cosmosHdPath, + }, + ]); + const directSigner = directWallet.toOfflineDirectSigner(); + + client = await SigningClient.connectWithSigner( + await getRpcEndpoint(), + new DirectGenericOfflineSigner(directSigner), + { + signerOptions: { + prefix: commonPrefix, + }, + } + ); }); - it('check chain height', async () => { - const height = await client.getHeight(); + it("check chain height", async () => { + const { header } = await client.getBlock(1); - expect(height).toBeGreaterThan(0); + expect(header.height).toBeGreaterThan(0); }); }); diff --git a/templates/hyperweb/__tests__/simpleState.test.ts b/templates/hyperweb/__tests__/simpleState.test.ts index db463e38..0439c7ed 100644 --- a/templates/hyperweb/__tests__/simpleState.test.ts +++ b/templates/hyperweb/__tests__/simpleState.test.ts @@ -1,15 +1,16 @@ // @ts-nocheck -import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; -import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; +import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd"; +import { assertIsDeliverTxSuccess } from "@interchainjs/cosmos/utils"; import path from "path"; -import fs from 'fs'; -import { getSigningJsdClient, jsd } from 'hyperwebjs' -import { useChain, generateMnemonic } from 'starshipjs'; -import { sleep } from '../test-utils/sleep'; -import './setup.test'; - -describe('JSD tests', () => { +import fs from "fs"; +import { getSigningJsdClient, jsd } from "hyperwebjs"; +import { useChain, generateMnemonic } from "starshipjs"; +import { sleep } from "../test-utils/sleep"; +import "./setup.test"; +import { DirectGenericOfflineSigner } from "@interchainjs/cosmos/types/wallet"; + +describe("JSD tests", () => { let wallet, denom, address, queryClient, signingClient; let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; let contractCode, contractIndex; @@ -17,48 +18,50 @@ describe('JSD tests', () => { let fee; beforeAll(async () => { - ({ - chainInfo, - getCoin, - getRpcEndpoint, - creditFromFaucet - } = useChain('hyperweb')); + ({ chainInfo, getCoin, getRpcEndpoint, creditFromFaucet } = + useChain("hyperweb")); denom = (await getCoin()).base; // Initialize wallet - wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { - prefix: chainInfo.chain.bech32_prefix - }); + wallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [ + { + prefix: chainInfo.chain.bech32_prefix, + hdPath: "m/44'/118'/0'/0/0", + }, + ]); address = (await wallet.getAccounts())[0].address; - console.log(`contract creator address: ${address}`) + console.log(`contract creator address: ${address}`); // Create custom cosmos interchain client queryClient = await jsd.ClientFactory.createRPCQueryClient({ - rpcEndpoint: await getRpcEndpoint() + rpcEndpoint: await getRpcEndpoint(), }); signingClient = await getSigningJsdClient({ rpcEndpoint: await getRpcEndpoint(), - signer: wallet + signer: wallet, }); // set default fee - fee = {amount: [{denom, amount: '100000'}], gas: '550000'}; + fee = { amount: [{ denom, amount: "100000" }], gas: "550000" }; await creditFromFaucet(address); await sleep(2000); // sleep for 1 sec to get tokens transferred from faucet successfully }); - it('check balance', async () => { + it("check balance", async () => { const balance = await signingClient.getBalance(address, denom); expect(balance.amount).toEqual("10000000000"); expect(balance.denom).toEqual(denom); }); - it('instantiate contract', async () => { + it("instantiate contract", async () => { // Read contract code from external file - const contractPath = path.join(__dirname, '../dist/contracts/simpleState.js'); - contractCode = fs.readFileSync(contractPath, 'utf8'); + const contractPath = path.join( + __dirname, + "../dist/contracts/simpleState.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); const msg = jsd.jsd.MessageComposer.fromPartial.instantiate({ creator: address, @@ -69,25 +72,32 @@ describe('JSD tests', () => { assertIsDeliverTxSuccess(result); // Parse the response to get the contract index - const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg( + result.msgResponses[0] + ); contractIndex = response.index; expect(contractIndex).toBeGreaterThan(0); console.log(`contract index: ${contractIndex}`); }); - it('query for contract based on index', async () => { - const response = await queryClient.jsd.jsd.contracts({index: contractIndex}); + it("query for contract based on index", async () => { + const response = await queryClient.jsd.jsd.contracts({ + index: contractIndex, + }); expect(response.contracts.code).toEqual(contractCode); expect(response.contracts.index).toEqual(contractIndex); expect(response.contracts.creator).toEqual(address); }); - it('query state before eval', async () => { - const state = await queryClient.jsd.jsd.localState({index: contractIndex, key: "value"}); - expect(state).toEqual({value: ""}); + it("query state before eval", async () => { + const state = await queryClient.jsd.jsd.localState({ + index: contractIndex, + key: "value", + }); + expect(state).toEqual({ value: "" }); }); - it('perform inc eval', async () => { + it("perform inc eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -98,11 +108,13 @@ describe('JSD tests', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("10"); }); - it('eval read from eval', async () => { + it("eval read from eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -113,16 +125,21 @@ describe('JSD tests', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("10"); }); - it('query state after eval', async () => { - const state = await queryClient.jsd.jsd.localState({index: contractIndex, key: "value"}); - expect(state).toEqual({value: "10"}); + it("query state after eval", async () => { + const state = await queryClient.jsd.jsd.localState({ + index: contractIndex, + key: "value", + }); + expect(state).toEqual({ value: "10" }); }); - it('perform dec eval', async () => { + it("perform dec eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -133,11 +150,13 @@ describe('JSD tests', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("5"); }); - it('eval read from eval', async () => { + it("eval read from eval", async () => { const msg = jsd.jsd.MessageComposer.fromPartial.eval({ creator: address, index: contractIndex, @@ -148,7 +167,9 @@ describe('JSD tests', () => { const result = await signingClient.signAndBroadcast(address, [msg], fee); assertIsDeliverTxSuccess(result); - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); expect(response.result).toEqual("5"); }); }); diff --git a/templates/hyperweb/docs/WRITING_FIRST_CONTRACT.md b/templates/hyperweb/docs/WRITING_FIRST_CONTRACT.md index 6314dff3..8d3f1937 100644 --- a/templates/hyperweb/docs/WRITING_FIRST_CONTRACT.md +++ b/templates/hyperweb/docs/WRITING_FIRST_CONTRACT.md @@ -5,6 +5,7 @@ This guide walks you through creating a simple "Hello World" contract using Hype ## Prerequisites Before starting, ensure you have: + - Set up the Hyperweb development environment (refer to the main [README](../README.md)). - Basic understanding of TypeScript and object-oriented programming. @@ -42,12 +43,12 @@ export interface State { default export class HelloWorldContract { state: State; - + constructor(state: State) { this.state = state; this.state.set('greet', "Hello, World!"); // Set initial greeting in constructor } - + // Retrieve the greeting message greet(): string { return this.state.get('greet'); @@ -69,12 +70,12 @@ To include your contract in the build process: ```ts const configs: BuildConfig[] = [ - // existing contracts - { - entryFile: 'src/hello-world', - outFile: 'dist/contracts/helloWorld.js', - externalPackages: [] - } + // existing contracts + { + entryFile: "src/hello-world", + outFile: "dist/contracts/helloWorld.js", + externalPackages: [], + }, ]; ``` @@ -103,96 +104,102 @@ Testing helps ensure the contract behaves as expected. In the `__tests__/` direc 2. Write test cases for greeting retrieval: ```js - import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; - import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; - + import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd"; + import { assertIsDeliverTxSuccess } from "@interchainjs/cosmos/utils"; + import path from "path"; - import fs from 'fs'; - import { getSigningJsdClient, jsd } from 'hyperwebjs'; - import { useChain, generateMnemonic } from 'starshipjs'; - import { sleep } from '../test-utils/sleep'; - import './setup.test'; - - describe('Hello World Contract Tests', () => { - let wallet, denom, address, queryClient, signingClient; - let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; - let contractCode, contractIndex; - - let fee; - - beforeAll(async () => { - ({ - chainInfo, - getCoin, - getRpcEndpoint, - creditFromFaucet - } = useChain('hyperweb')); + import fs from "fs"; + import { getSigningJsdClient, jsd } from "hyperwebjs"; + import { useChain, generateMnemonic } from "starshipjs"; + import { sleep } from "../test-utils/sleep"; + import "./setup.test"; + + describe("Hello World Contract Tests", () => { + let wallet, denom, address, queryClient, signingClient; + let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; + let contractCode, contractIndex; + + let fee; + + beforeAll(async () => { + ({ chainInfo, getCoin, getRpcEndpoint, creditFromFaucet } = + useChain("hyperweb")); denom = (await getCoin()).base; - + // Initialize wallet - wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { - prefix: chainInfo.chain.bech32_prefix - }); + wallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [ + { + prefix: chainInfo.chain.bech32_prefix, + hdPath: "m/44'/118'/0'/0/0", + }, + ]); address = (await wallet.getAccounts())[0].address; console.log(`contract creator address: ${address}`); - + // Create custom cosmos interchain client queryClient = await jsd.ClientFactory.createRPCQueryClient({ - rpcEndpoint: await getRpcEndpoint() + rpcEndpoint: await getRpcEndpoint(), }); - + signingClient = await getSigningJsdClient({ rpcEndpoint: await getRpcEndpoint(), - signer: wallet + signer: wallet, }); - + // Set default fee - fee = { amount: [{ denom, amount: '100000' }], gas: '550000' }; - + fee = { amount: [{ denom, amount: "100000" }], gas: "550000" }; + await creditFromFaucet(address); await sleep(2000); // Wait for faucet transfer - }); - - it('check balance', async () => { - const balance = await signingClient.getBalance(address, denom); - expect(balance.amount).toEqual("10000000000"); - expect(balance.denom).toEqual(denom); - }); - - it('instantiate Hello World contract', async () => { - // Read contract code from external file - const contractPath = path.join(__dirname, '../dist/contracts/helloWorld.js'); - contractCode = fs.readFileSync(contractPath, 'utf8'); - - const msg = jsd.jsd.MessageComposer.fromPartial.instantiate({ - creator: address, - code: contractCode, - }); - - const result = await signingClient.signAndBroadcast(address, [msg], fee); - assertIsDeliverTxSuccess(result); - - // Parse response to get the contract index - const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); - contractIndex = response.index; - expect(contractIndex).toBeGreaterThan(0); - console.log(`contract index: ${contractIndex}`); - }); - - it('query for initial greeting', async () => { - const msg = jsd.jsd.MessageComposer.fromPartial.eval({ - creator: address, - index: contractIndex, - fnName: "greet", - arg: "", - }); - - const result = await signingClient.signAndBroadcast(address, [msg], fee); - assertIsDeliverTxSuccess(result); - - const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - expect(response.result).toEqual("Hello, World!"); - }); + }); + + it("check balance", async () => { + const balance = await signingClient.getBalance(address, denom); + expect(balance.amount).toEqual("10000000000"); + expect(balance.denom).toEqual(denom); + }); + + it("instantiate Hello World contract", async () => { + // Read contract code from external file + const contractPath = path.join( + __dirname, + "../dist/contracts/helloWorld.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); + + const msg = jsd.jsd.MessageComposer.fromPartial.instantiate({ + creator: address, + code: contractCode, + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + // Parse response to get the contract index + const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg( + result.msgResponses[0] + ); + contractIndex = response.index; + expect(contractIndex).toBeGreaterThan(0); + console.log(`contract index: ${contractIndex}`); + }); + + it("query for initial greeting", async () => { + const msg = jsd.jsd.MessageComposer.fromPartial.eval({ + creator: address, + index: contractIndex, + fnName: "greet", + arg: "", + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = jsd.jsd.MsgEvalResponse.fromProtoMsg( + result.msgResponses[0] + ); + expect(response.result).toEqual("Hello, World!"); + }); }); ``` diff --git a/templates/hyperweb/package.json b/templates/hyperweb/package.json index a86b3da4..88db6161 100644 --- a/templates/hyperweb/package.json +++ b/templates/hyperweb/package.json @@ -54,6 +54,7 @@ }, "devDependencies": { "@hyperweb/build": "^0.0.2", + "@interchainjs/cosmos": "^1.9.12", "@starship-ci/cli": "^2.10.1", "@types/jest": "^29.5.11", "@types/node": "^22.7.4", diff --git a/templates/hyperweb/yarn.lock b/templates/hyperweb/yarn.lock index 5173d5a8..0c03cabc 100644 --- a/templates/hyperweb/yarn.lock +++ b/templates/hyperweb/yarn.lock @@ -492,6 +492,20 @@ __metadata: languageName: node linkType: hard +"@chain-registry/v2-types@npm:0.53.68": + version: 0.53.68 + resolution: "@chain-registry/v2-types@npm:0.53.68" + checksum: 10c0/5b4d1d039bce3bc595f83e6950f6c1a5594984ae141461f2225b9a45a3c2dddc243ccb0d1af433dae6d9477a724170d471a365d6905ede854c0fb478f343b918 + languageName: node + linkType: hard + +"@chain-registry/v2-types@npm:0.53.72": + version: 0.53.72 + resolution: "@chain-registry/v2-types@npm:0.53.72" + checksum: 10c0/a86ae13acfc13ec0f954c5c9b2211d1d9e50cc006b02a4113f33f9eaa2be350c01a5838869f4520d574b24019fd1f1b9bfc44781fa1331a2b0569cceba86a40a + languageName: node + linkType: hard + "@chain-registry/v2-types@npm:^0.49.6": version: 0.49.86 resolution: "@chain-registry/v2-types@npm:0.49.86" @@ -506,6 +520,15 @@ __metadata: languageName: node linkType: hard +"@chain-registry/v2@npm:1.71.71": + version: 1.71.71 + resolution: "@chain-registry/v2@npm:1.71.71" + dependencies: + "@chain-registry/v2-types": "npm:^0.53.40" + checksum: 10c0/b498b77509b3750d2533186ca3a4ae49776a1fcf59d4b9be9a43e9287b805a48a300f1ba375e108ac9565f738a4c0089009e186bf27be42edffb7355b5dfc962 + languageName: node + linkType: hard + "@chain-registry/v2@npm:^1.65.6, @chain-registry/v2@npm:^1.71.71": version: 1.71.103 resolution: "@chain-registry/v2@npm:1.71.103" @@ -1405,6 +1428,20 @@ __metadata: languageName: node linkType: hard +"@interchainjs/auth@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/auth@npm:1.9.12" + dependencies: + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" + "@noble/curves": "npm:^1.1.0" + "@noble/hashes": "npm:^1.3.1" + "@scure/bip32": "npm:^1.0.10" + ethers: "npm:^6.5.1" + checksum: 10c0/125c0f1a6f60d32ff851e15a1afb4c96cb0fb74823d8251bc83e1c07f99e1bece4879b97f72b43103c903ed1d1ab2550d8c999235302bf26695230f35b9d5bb1 + languageName: node + linkType: hard + "@interchainjs/cosmos-types@npm:1.6.3": version: 1.6.3 resolution: "@interchainjs/cosmos-types@npm:1.6.3" @@ -1415,6 +1452,16 @@ __metadata: languageName: node linkType: hard +"@interchainjs/cosmos-types@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/cosmos-types@npm:1.9.12" + dependencies: + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" + checksum: 10c0/6e6e8ccd733b6d94cb35c1a84cff26cc7dacc8259166114128c804a42a48002174fa03d91020585ff7b569c81804e572c05af76f89dee1373357df8d49aa77a2 + languageName: node + linkType: hard + "@interchainjs/cosmos@npm:1.6.3": version: 1.6.3 resolution: "@interchainjs/cosmos@npm:1.6.3" @@ -1432,6 +1479,23 @@ __metadata: languageName: node linkType: hard +"@interchainjs/cosmos@npm:^1.9.12": + version: 1.9.12 + resolution: "@interchainjs/cosmos@npm:1.9.12" + dependencies: + "@chain-registry/v2": "npm:^1.65.6" + "@chain-registry/v2-types": "npm:0.53.68" + "@interchainjs/auth": "npm:1.9.12" + "@interchainjs/cosmos-types": "npm:1.9.12" + "@interchainjs/types": "npm:1.9.12" + "@interchainjs/utils": "npm:1.9.12" + "@noble/curves": "npm:^1.1.0" + "@noble/hashes": "npm:^1.3.1" + decimal.js: "npm:^10.4.3" + checksum: 10c0/4446d4d4a43cbc1dab2d6ddf9f3a327186b73ce4406c6d45d1ddc371471b37e74998441fc64a509dbc1e8578d0dc46bfbf3130a6c8e9090c955d5c9782807c9c + languageName: node + linkType: hard + "@interchainjs/types@npm:1.6.3": version: 1.6.3 resolution: "@interchainjs/types@npm:1.6.3" @@ -1441,6 +1505,15 @@ __metadata: languageName: node linkType: hard +"@interchainjs/types@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/types@npm:1.9.12" + dependencies: + decimal.js: "npm:^10.4.3" + checksum: 10c0/30607621c2c4f187a66a420bcee8fbf38884b880bf2dbbdb250eab5bf490bde86ddea0f19d94b06a136199671aff287d7be0bae9bbc2359d797006d5029815c8 + languageName: node + linkType: hard + "@interchainjs/utils@npm:1.6.3": version: 1.6.3 resolution: "@interchainjs/utils@npm:1.6.3" @@ -1451,6 +1524,19 @@ __metadata: languageName: node linkType: hard +"@interchainjs/utils@npm:1.9.12": + version: 1.9.12 + resolution: "@interchainjs/utils@npm:1.9.12" + dependencies: + "@chain-registry/v2": "npm:1.71.71" + "@chain-registry/v2-types": "npm:0.53.72" + "@interchainjs/types": "npm:1.9.12" + bech32: "npm:^2.0.0" + decimal.js: "npm:^10.4.3" + checksum: 10c0/62e0c147a7f04c574c50702fc10ee9e9d207bbb0fe438593afcf67748ff57112ad7bee8f39954c178b39231bc24811263efd81ee72adbe29746c46fcf229c4da + languageName: node + linkType: hard + "@internationalized/date@npm:^3.7.0": version: 3.7.0 resolution: "@internationalized/date@npm:3.7.0" @@ -2083,7 +2169,7 @@ __metadata: languageName: node linkType: hard -"@noble/curves@npm:^1.1.0": +"@noble/curves@npm:^1.1.0, @noble/curves@npm:~1.8.1": version: 1.8.1 resolution: "@noble/curves@npm:1.8.1" dependencies: @@ -2099,7 +2185,7 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:1.7.1, @noble/hashes@npm:^1.3.1": +"@noble/hashes@npm:1.7.1, @noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.7.1": version: 1.7.1 resolution: "@noble/hashes@npm:1.7.1" checksum: 10c0/2f8ec0338ccc92b576a0f5c16ab9c017a3a494062f1fbb569ae641c5e7eab32072f9081acaa96b5048c0898f972916c818ea63cbedda707886a4b5ffcfbf94e3 @@ -3767,6 +3853,24 @@ __metadata: languageName: node linkType: hard +"@scure/base@npm:~1.2.2": + version: 1.2.4 + resolution: "@scure/base@npm:1.2.4" + checksum: 10c0/469c8aee80d6d6973e1aac6184befa04568f1b4016e40c889025f4a721575db9c1ca0c2ead80613896cce929392740322a18da585a427f157157e797dc0a42a9 + languageName: node + linkType: hard + +"@scure/bip32@npm:^1.0.10": + version: 1.6.2 + resolution: "@scure/bip32@npm:1.6.2" + dependencies: + "@noble/curves": "npm:~1.8.1" + "@noble/hashes": "npm:~1.7.1" + "@scure/base": "npm:~1.2.2" + checksum: 10c0/a0abd62d1fe34b4d90b84feb25fa064ad452fd51be9fd7ea3dcd376059c0e8d08d4fe454099030f43fb91a1bee85cd955f093f221bbc522178919f779fbe565c + languageName: node + linkType: hard + "@sinclair/typebox@npm:^0.27.8": version: 0.27.8 resolution: "@sinclair/typebox@npm:0.27.8" @@ -7563,6 +7667,7 @@ __metadata: "@interchain-kit/react": "npm:0.0.1-beta.62" "@interchain-ui/react": "npm:1.26.1" "@interchain-ui/react-no-ssr": "npm:^0.1.6" + "@interchainjs/cosmos": "npm:^1.9.12" "@starship-ci/cli": "npm:^2.10.1" "@types/jest": "npm:^29.5.11" "@types/node": "npm:^22.7.4"