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

feat: update ts-sdk with Cosmos SDK v0.47 proto #82

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,14 @@ if wormchain:
dockerfile = "./wormchain/Dockerfile",
build_args = {"num_guardians": str(num_guardians)},
only = [],
ignore = ["./wormchain/testing", "./wormchain/ts-sdk", "./wormchain/design", "./wormchain/vue", "./wormchain/build/wormchaind"],
ignore = ["./wormchain/testing", "./wormchain/ts-sdk", "./wormchain/design", "./wormchain/ts-client", "./wormchain/build/wormchaind"],
)

docker_build(
ref = "vue-export",
ref = "ts-client-export",
context = ".",
dockerfile = "./wormchain/Dockerfile.proto",
target = "vue-export",
target = "ts-client-export",
)

docker_build(
Expand Down
4 changes: 2 additions & 2 deletions scripts/check-docker-pin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# - We ignore scratch because it's literally the docker base image
# - We ignore solana AS (builder|ci_tests) because it's a relative reference to another FROM call
# - We ignore cosmwasm_artifacts AS artifacts because it's a local reference only, is built in tilt
# - We ignore base AS (ignite-go-build|ignite-vue-build) because the base image is already pinned in wormchain/Dockerfile.proto
# - We ignore base AS (ignite-go-build|ignite-ts-client-build) because the base image is already pinned in wormchain/Dockerfile.proto
#
git ls-files -z | grep -z "Dockerfile*" | xargs -r -0 grep -s "FROM" | egrep -v 'sha256|scratch|solana|aptos|sui|base|cosmwasm_artifacts|cli-gen|const-gen|dev|wormchain-builder AS (application|base|builder|ci_tests|tests|artifacts|ignite-go-build|ignite-vue-build|cli-export|const-export|build)'
git ls-files -z | grep -z "Dockerfile*" | xargs -r -0 grep -s "FROM" | egrep -v 'sha256|scratch|solana|aptos|sui|base|cosmwasm_artifacts|cli-gen|const-gen|dev|wormchain-builder AS (application|base|builder|ci_tests|tests|artifacts|ignite-go-build|ignite-ts-client|cli-export|const-export|build)'
if [ $? -eq 0 ]; then
echo "[!] Unpinned docker files" >&2
exit 1
Expand Down
1 change: 1 addition & 0 deletions wormchain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ts-sdk/node_modules
ts-sdk/lib
contracts/artifacts
cmd/wormchaind/wormchaind
ts-client/

.idea
*.iml
2 changes: 1 addition & 1 deletion wormchain/Dockerfile.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ COPY ./ts-sdk/package.json ./ts-sdk/package-lock.json /ts-sdk/
RUN --mount=type=cache,uid=1000,gid=1000,target=/home/node/.npm \
npm ci --prefix=/ts-sdk
COPY ./ts-sdk /ts-sdk
COPY --from=vue-export /vue /vue
COPY --from=ts-client-export /ts-client /ts-client
RUN npm run build --prefix=/ts-sdk

COPY ./contracts/tools/package.json ./contracts/tools/package-lock.json /app/tools/
Expand Down
10 changes: 5 additions & 5 deletions wormchain/Dockerfile.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ COPY --from=ignite-go-build /wh/apps/wormchain/x/ibc-composability-mw/types /x/i



## VUE BUILDER STAGE
FROM wormchain-builder AS ignite-vue-build
## TS CLIENT BUILDER STAGE
FROM wormchain-builder AS ignite-ts-client-build
# Ignite only likes minor versions in go.mod
RUN sed -i 's/go 1.22.5/go 1.22/g' go.mod
RUN NODE_OPTIONS="" ignite generate vuex
RUN NODE_OPTIONS="" ignite generate ts-client



## VUE EXPORT STAGE
FROM scratch AS vue-export
COPY --from=ignite-vue-build /wh/apps/wormchain/vue /vue
FROM scratch AS ts-client-export
COPY --from=ignite-ts-client-build /wh/apps/wormchain/ts-client /ts-client
8 changes: 4 additions & 4 deletions wormchain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ install: go.sum
proto: $(PROTO_FILES)
DOCKER_BUILDKIT=1 docker build --target go-export -f Dockerfile.proto -o type=local,dest=. ..

vue: $(GO_FILES) proto
ts-client: $(GO_FILES) proto
mkdir -p $@
touch -m $@
DOCKER_BUILDKIT=1 docker build --target vue-export -f Dockerfile.proto -o type=local,dest=. ..
DOCKER_BUILDKIT=1 docker build --target ts-client-export -f Dockerfile.proto -o type=local,dest=. ..

# For now this is a phony target so we just rebuild it each time instead of
# tracking dependencies
.PHONY: ts-sdk
ts-sdk: vue
ts-sdk: ts-client
npm ci --prefix $@
npm run build --prefix $@

Expand Down Expand Up @@ -91,7 +91,7 @@ bootstrap:

.PHONY: clean
clean:
rm -rf build/wormchaind build/wormchaind-* build/**/*.db build/**/*.wal vue
rm -rf build/wormchaind build/wormchaind-* build/**/*.db build/**/*.wal vue/ ts-client/
echo "{\"height\":\"0\",\"round\":0,\"step\":0}" > build/data/priv_validator_state.json

#####################
Expand Down
2 changes: 1 addition & 1 deletion wormchain/ts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"scripts": {
"test": "jest --config jestconfig.json --verbose",
"build": "npm run genTypes && tsc",
"build": "npm run genTypes && NODE_OPTIONS=--max-old-space-size=8192 npx tsc",
"genTypes": "node src/buildHelper.cjs"
},
"repository": {
Expand Down
45 changes: 12 additions & 33 deletions wormchain/ts-sdk/src/buildHelper.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");

const CERTUS_DIRECTORY =
"../vue/src/store/generated/wormhole-foundation/wormchain/";
const COSMOS_DIRECTORY = "../vue/src/store/generated/cosmos/cosmos-sdk/";
const WASMD_DIRECTORY = "../vue/src/store/generated/CosmWasm/wasmd/";
const TS_CLIENT_DIRECTORY = "../ts-client/";
const MODULE_DIRECTORY = "../ts-sdk/src/modules/";

function execWrapper(command) {
Expand All @@ -28,36 +25,18 @@ function execWrapper(command) {
});
}

const certusFiles = fs.readdirSync(CERTUS_DIRECTORY, { withFileTypes: true }); //should only contain directories for the modules
const cosmosFiles = fs.readdirSync(COSMOS_DIRECTORY, { withFileTypes: true });
const wasmdFiles = fs.readdirSync(WASMD_DIRECTORY, { withFileTypes: true });
const clientFiles = fs.readdirSync(TS_CLIENT_DIRECTORY, { withFileTypes: true });

certusFiles.forEach((directory) => {
execWrapper(`mkdir -p ${MODULE_DIRECTORY + directory.name}/`);
execWrapper(
`cp -R ${CERTUS_DIRECTORY + directory.name}/module/* ${
MODULE_DIRECTORY + directory.name
}/`
); //move all the files from the vue module into the sdk
});

cosmosFiles.forEach((directory) => {
execWrapper(`mkdir -p ${MODULE_DIRECTORY + directory.name}/`);
execWrapper(
`cp -R ${COSMOS_DIRECTORY + directory.name}/module/* ${
MODULE_DIRECTORY + directory.name
}/`
); //move all the files from the vue module into the sdk
});

wasmdFiles.forEach((directory) => {
execWrapper(`mkdir -p ${MODULE_DIRECTORY + directory.name}/`);
execWrapper(
`cp -R ${WASMD_DIRECTORY + directory.name}/module/* ${
MODULE_DIRECTORY + directory.name
}/`
); //move all the files from the vue module into the sdk
});
// Move all module directories from Ignite's ts-client to the ts-sdk
clientFiles
.filter(directory => directory.isDirectory())
.forEach((directory) => {
execWrapper(`mkdir -p ${MODULE_DIRECTORY + directory.name}/`);
execWrapper(
`cp -R ${TS_CLIENT_DIRECTORY + directory.name}/* ${MODULE_DIRECTORY + directory.name
}/`
);
});

//As of 19.5 javascript isn't emitted
//execWrapper(`find ${MODULE_DIRECTORY} -name "*.js" | xargs rm `); //delete all javascript files, so they can be cleanly created based on our tsconfig
Expand Down
38 changes: 20 additions & 18 deletions wormchain/ts-sdk/src/core/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { Api as txApi } from "../modules/cosmos.tx.v1beta1/rest";
import { Api as upgradeApi } from "../modules/cosmos.upgrade.v1beta1/rest";
import { Api as vestingApi } from "../modules/cosmos.vesting.v1beta1/rest";
import { Api as wasmApi } from "../modules/cosmwasm.wasm.v1/rest";
import { Api as coreApi } from "../modules/wormhole_foundation.wormchain.wormhole/rest";
import { Api as coreApi } from "../modules/wormchain.wormhole/rest";


export type WormchainQueryClient = {
core: coreApi<any>;
Expand Down Expand Up @@ -45,23 +46,24 @@ export function getWormholeQueryClient(
//@ts-ignore
globalThis.fetch = fetch;
}
const core = new coreApi({ baseUrl: lcdAddress });
const auth = new authApi({ baseUrl: lcdAddress });
const bank = new bankApi({ baseUrl: lcdAddress });
const base = new baseApi({ baseUrl: lcdAddress });
const crisis = new crisisApi({ baseUrl: lcdAddress });
const distribution = new distributionApi({ baseUrl: lcdAddress });
const evidence = new evidenceApi({ baseUrl: lcdAddress });
const feegrant = new feegrantApi({ baseUrl: lcdAddress });
const gov = new govApi({ baseUrl: lcdAddress });
const mint = new mintApi({ baseUrl: lcdAddress });
const params = new paramsApi({ baseUrl: lcdAddress });
const slashing = new slashingApi({ baseUrl: lcdAddress });
const staking = new stakingApi({ baseUrl: lcdAddress });
const tx = new txApi({ baseUrl: lcdAddress });
const upgrade = new upgradeApi({ baseUrl: lcdAddress });
const vesting = new vestingApi({ baseUrl: lcdAddress });
const wasm = new wasmApi({ baseUrl: lcdAddress });

const core = new coreApi({ baseURL: lcdAddress });
const auth = new authApi({ baseURL: lcdAddress });
const bank = new bankApi({ baseURL: lcdAddress });
const base = new baseApi({ baseURL: lcdAddress });
const crisis = new crisisApi({ baseURL: lcdAddress });
const distribution = new distributionApi({ baseURL: lcdAddress });
const evidence = new evidenceApi({ baseURL: lcdAddress });
const feegrant = new feegrantApi({ baseURL: lcdAddress });
const gov = new govApi({ baseURL: lcdAddress });
const mint = new mintApi({ baseURL: lcdAddress });
const params = new paramsApi({ baseURL: lcdAddress });
const slashing = new slashingApi({ baseURL: lcdAddress });
const staking = new stakingApi({ baseURL: lcdAddress });
const tx = new txApi({ baseURL: lcdAddress });
const upgrade = new upgradeApi({ baseURL: lcdAddress });
const vesting = new vestingApi({ baseURL: lcdAddress });
const wasm = new wasmApi({ baseURL: lcdAddress });

return {
core,
Expand Down
31 changes: 17 additions & 14 deletions wormchain/ts-sdk/src/core/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { bech32 } from "bech32";
import {
coins,
DirectSecp256k1HdWallet,
EncodeObject,
OfflineSigner,
} from "@cosmjs/proto-signing";
import {
Expand All @@ -25,19 +24,18 @@ import {
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import {
RpcStatus,
HttpResponse,
} from "../modules/wormhole_foundation.wormchain.wormhole/rest";
} from "../modules/wormchain.wormhole/rest";
import {
txClient,
queryClient,
} from "../modules/wormhole_foundation.wormchain.wormhole";
} from "../modules/wormchain.wormhole";
import { keccak256 } from "ethers/lib/utils";
import { MsgRegisterAccountAsGuardian } from "../modules/wormhole_foundation.wormchain.wormhole/types/wormhole/tx";
import { GuardianKey } from "../modules/wormhole_foundation.wormchain.wormhole/types/wormhole/guardian_key";
import { MsgRegisterAccountAsGuardian } from "../modules/wormchain.wormhole/types/wormchain/wormhole/tx";
import { AxiosResponse } from "axios";
import { ADDRESS_PREFIX } from "./consts";
let elliptic = require("elliptic"); //No TS defs?

//https://tutorials.cosmos.network/academy/4-my-own-chain/cosmjs.html
const ADDRESS_PREFIX = "wormhole";
const OPERATOR_PREFIX = "wormholevaloper";
export const TENDERMINT_URL = "http://localhost:26658";
export const WORM_DENOM = "uworm";
Expand Down Expand Up @@ -95,10 +93,13 @@ export async function executeGovernanceVAA(
) {
const offline: OfflineSigner = wallet;

const client = await txClient(offline, { addr: TENDERMINT_URL });
const client = await txClient({ signer: offline, addr: TENDERMINT_URL, prefix: ADDRESS_PREFIX });

const msg = client.msgExecuteGovernanceVAA({
vaa: new Uint8Array(),
signer: await getAddress(wallet),
value: {
vaa: new Uint8Array(),
signer: await getAddress(wallet),
},
}); //TODO convert type

const signingClient = await SigningStargateClient.connectWithSigner(
Expand Down Expand Up @@ -156,7 +157,7 @@ export async function getGuardianValidatorRegistrations() {
}

export async function unpackHttpReponse<T>(
response: Promise<HttpResponse<T, RpcStatus>>
response: Promise<AxiosResponse<T, RpcStatus>>
) {
const http = await response;
//TODO check rpc status
Expand Down Expand Up @@ -188,10 +189,12 @@ export async function registerGuardianValidator(
};

const offline: OfflineSigner = wallet;
const client = await txClient(offline, { addr: TENDERMINT_URL });
const msg = client.msgRegisterAccountAsGuardian(args);
const client = await txClient({ signer: offline, addr: TENDERMINT_URL, prefix: ADDRESS_PREFIX });
const msg = client.msgRegisterAccountAsGuardian({
value: args
});

const output = await client.signAndBroadcast([msg]);
const output = await client.sendMsgRegisterAccountAsGuardian(msg);

return output;
}
Expand Down
Loading
Loading