diff --git a/.eslintrc.json b/.eslintrc.json index 6a57aacd..2f8ac782 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,5 +12,6 @@ "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended" - ] + ], + "ignorePatterns": ["nibiru/*", "cosmos-sdk/*"] } diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index acfc5022..deed7cf3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,16 +20,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - token: ${{ secrets.NIBIBOT_GIT_TOKEN }} - - - name: Checkout nibiru Repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - repository: NibiruChain/nibiru - ref: releases/v0.21.x - path: "nibiru" - token: ${{ secrets.NIBIBOT_GIT_TOKEN }} + submodules: true - name: Setup NodeJS and npm uses: actions/setup-node@v3 diff --git a/.github/workflows/test-ts-sdk.yaml b/.github/workflows/test-ts-sdk.yaml index 33830222..16444ca8 100644 --- a/.github/workflows/test-ts-sdk.yaml +++ b/.github/workflows/test-ts-sdk.yaml @@ -23,22 +23,13 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Checkout nibiru Repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - repository: NibiruChain/nibiru - ref: main - path: "nibiru" - token: ${{ secrets.NIBIBOT_GIT_TOKEN }} + submodules: true - name: Setup NodeJS with yarn caching uses: actions/setup-node@v3 with: node-version: "lts/hydrogen" cache: "yarn" - cache-dependency-path: "**/yarn.lock" - name: yarn install uses: borales/actions-yarn@v4 diff --git a/.gitignore b/.gitignore index 3c400e39..6e55df51 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,6 @@ src/gql/utils/generated.ts src/gql/utils/schema.graphql dist **/node_modules/* -nibiru/ - reports junit.xml @@ -208,5 +206,3 @@ typings/ # End of https://www.gitignore.io/api/node,intellij+all,visualstudiocode .yarn .DS_Store - -nibiru/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..f82158ce --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "cosmos-sdk"] + path = cosmos-sdk + url = https://github.com/cosmos/cosmos-sdk +[submodule "nibiru"] + path = nibiru + url = https://github.com/NibiruChain/nibiru diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..7436e434 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,213 @@ +/nibiru +/cosmos-sdk + +# Rest of file is .gitignore + +# Created by https://www.gitignore.io/api/node,intellij+all,visualstudiocode +# Edit at https://www.gitignore.io/?templates=node,intellij+all,visualstudiocode + +docs/ +src/protojs/ +proto/ +src/gql/utils/generated.ts +src/gql/utils/schema.graphql +dist +**/node_modules/* + +reports +junit.xml +temp +.build-cache +.DS_STORE + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage* +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ +**/node_modules/* + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/node,intellij+all,visualstudiocode +.yarn +.DS_Store diff --git a/README.md b/README.md index 7e013e1a..d7bab78c 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,14 @@ console.log("perpPositions: %o", perpPositions) yarn ``` -4. Lastly, compile the code in each package. +4. Initialize git submodules + + ```sh + git submodule init + git submodule update + ``` + +5. Lastly, compile the code in each package. ```sh yarn build diff --git a/cosmos-sdk b/cosmos-sdk new file mode 160000 index 00000000..b48fd666 --- /dev/null +++ b/cosmos-sdk @@ -0,0 +1 @@ +Subproject commit b48fd66678a98b915888cc84976399ac17164370 diff --git a/nibiru b/nibiru new file mode 160000 index 00000000..98c2b240 --- /dev/null +++ b/nibiru @@ -0,0 +1 @@ +Subproject commit 98c2b240cb61f3f25ca37442c8400cd3a32807e8 diff --git a/package.json b/package.json index 971d207f..fd268527 100644 --- a/package.json +++ b/package.json @@ -94,11 +94,11 @@ "lint-staged": { "*.{js,ts}": [ "eslint --fix . --ignore-path .gitignore", - "prettier --write . --ignore-path .gitignore", + "prettier --write . --ignore-path .prettierignore", "git add ." ], "*.json": [ - "prettier --write . --ignore-path .gitignore", + "prettier --write . --ignore-path .prettierignore", "git add ." ] }, @@ -117,5 +117,6 @@ "@commitlint/config-conventional" ] }, - "gitHead": "bac1729be8575a9e75bf9e04447a63c45e227c8c" + "gitHead": "bac1729be8575a9e75bf9e04447a63c45e227c8c", + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/scripts/build.sh b/scripts/build.sh index 014725d5..26377f7b 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,22 +1,8 @@ #!/bin/bash set -e -# Test for ./nibiru/ directory -if [ -d "./nibiru/" ]; then - echo "The ./nibiru/ directory exists." - cd nibiru - git checkout main - cd .. -elif [ -d "../nibiru/" ]; then - cd ../nibiru - git checkout main - git pull - cd ../ts-sdk -else - cd .. - git clone git@github.com:NibiruChain/nibiru.git - cd ts-sdk -fi +git submodule init +git submodule update yarn gql-generate & yarn proto-gen yarn build:tsc diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 7a68c8e8..ae5cd124 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -11,11 +11,7 @@ set -eo pipefail # PKG_OUT_DIR: Output path where the generated code will go upon # successful execution. NIBIRU_REPO="./nibiru" - -if [ -d "../nibiru/" ]; then - NIBIRU_REPO="../nibiru" -fi - +COSMOS_SDK_REPO="./cosmos-sdk" PKG_OUT_DIR="./src/protojs" # ----------------------------------------------------------------------------- @@ -25,19 +21,20 @@ echo "Removing old src files" rm -rf $PKG_OUT_DIR/ mkdir -p $PKG_OUT_DIR/ -echo "Copying protos from the 'nibiru' repo" -rm -rf proto/ -mkdir -p proto/ -cp -r $NIBIRU_REPO/proto/ proto/ +for dir in $(find $NIBIRU_REPO/proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | uniq | sort); do \ + for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do + echo "Generating ts proto code for $file" + buf generate --template $NIBIRU_REPO/proto/buf.gen.ts.yaml -o $PKG_OUT_DIR $file + done +done; -for dir in $(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | uniq | sort); do \ +for dir in $(find $COSMOS_SDK_REPO/x/staking/proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | uniq | sort); do \ for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do echo "Generating ts proto code for $file" - buf generate --template proto/proto/buf.gen.ts.yaml -o $PKG_OUT_DIR $file + buf generate --template $NIBIRU_REPO/proto/buf.gen.ts.yaml -o $PKG_OUT_DIR $file done done; -rm -rf proto/ yarn generate-barrels # # the `descriptor.ts` file is only used for gogoproto, and it causes issues with TS-generated code rm $PKG_OUT_DIR/google/protobuf/descriptor.ts @@ -50,12 +47,14 @@ rm -rf $PKG_OUT_DIR/cosmos/msg rm $PKG_OUT_DIR/google/api/annotations.ts rm $PKG_OUT_DIR/index.gogoproto.ts rm $PKG_OUT_DIR/index.amino.ts +rm $PKG_OUT_DIR/index.google.ts rm $PKG_OUT_DIR/index.cosmos.msg.v1.ts rm $PKG_OUT_DIR/index.cosmos.msg.ts +rm $PKG_OUT_DIR/index.cosmos.query.v1.ts +rm $PKG_OUT_DIR/index.cosmos.query.ts sed 's/export \* as gogoproto from \"\.\/index\.gogoproto\"\;//' $PKG_OUT_DIR/index.ts > tmpfile && mv tmpfile $PKG_OUT_DIR/index.ts sed 's/export \* as amino from \"\.\/index\.amino\"\;//' $PKG_OUT_DIR/index.ts > tmpfile && mv tmpfile $PKG_OUT_DIR/index.ts sed 's/export \* as google from \"\.\/index\.google\"\;//' $PKG_OUT_DIR/index.ts > tmpfile && mv tmpfile $PKG_OUT_DIR/index.ts sed 's/export \* from \"\.\/google\/api\/annotations\"\;//' $PKG_OUT_DIR/index.google.api.ts > tmpfile && mv tmpfile $PKG_OUT_DIR/index.google.api.ts -sed 's/export \* as protobuf from \"\.\/index.google.protobuf\"\;//' $PKG_OUT_DIR/index.google.ts > tmpfile && mv tmpfile $PKG_OUT_DIR/index.google.ts sed 's/export \* as msg from \"\.\/index.cosmos.msg\"\;//' $PKG_OUT_DIR/index.cosmos.ts > tmpfile && mv tmpfile $PKG_OUT_DIR/index.cosmos.ts diff --git a/src/gql/query/index.ts b/src/gql/query/index.ts index 7c9dfe71..0724566e 100644 --- a/src/gql/query/index.ts +++ b/src/gql/query/index.ts @@ -16,8 +16,8 @@ export * from "./spotLpPositions" export * from "./spotPoolCreated" export * from "./spotPoolExited" export * from "./spotPoolJoined" -export * from "./spotPoolSwap" export * from "./spotPools" +export * from "./spotPoolSwap" export * from "./staking" export * from "./stats" export * from "./user" diff --git a/src/sdk/query/index.ts b/src/sdk/query/index.ts index bba5ece6..22e95d02 100644 --- a/src/sdk/query/index.ts +++ b/src/sdk/query/index.ts @@ -7,4 +7,5 @@ export * from "./epochs" export * from "./inflation" export * from "./oracle" export * from "./query" +export * from "./staking" export * from "./sudo" diff --git a/src/sdk/query/query.test.ts b/src/sdk/query/query.test.ts index e2775162..a4984111 100644 --- a/src/sdk/query/query.test.ts +++ b/src/sdk/query/query.test.ts @@ -160,7 +160,7 @@ describe("ibc module queries", () => { "channelId", "counterparty", ] - channels.forEach((channel: any) => { + channels.forEach((channel) => { properties.forEach((prop) => { expect(channel).toHaveProperty(prop) }) @@ -179,7 +179,7 @@ describe("ibc module queries", () => { "delayPeriod", "counterparty", ] - connections.forEach((connection: any) => { + connections.forEach((connection) => { properties.forEach((prop) => { expect(connection).toHaveProperty(prop) }) diff --git a/src/sdk/query/query.ts b/src/sdk/query/query.ts index 691c243e..59e2290a 100644 --- a/src/sdk/query/query.ts +++ b/src/sdk/query/query.ts @@ -8,10 +8,10 @@ import { setupDistributionExtension, setupGovExtension, setupIbcExtension, - setupStakingExtension, - StakingExtension, StargateClient, StargateClientOptions, + StakingExtension, + setupStakingExtension, } from "@cosmjs/stargate" import { Tendermint37Client } from "@cosmjs/tendermint-rpc" import { @@ -29,11 +29,13 @@ import { SudoExtension, InflationExtension, setupInflationExtension, + setupStakeExtension, Result, bytesToHex, hexToBytes, setupDevgasExtension, DevgasExtension, + StakeExtension, } from ".." export type NibiruExtensions = StargateQueryClient & @@ -45,6 +47,7 @@ export type NibiruExtensions = StargateQueryClient & DistributionExtension & GovExtension & StakingExtension & + StakeExtension & IbcExtension & WasmExtension & AuthExtension @@ -90,7 +93,8 @@ export class NibiruQuerier extends StargateClient { setupStakingExtension, setupIbcExtension, setupWasmExtension, - setupAuthExtension + setupAuthExtension, + setupStakeExtension ) } diff --git a/src/sdk/query/staking.test.ts b/src/sdk/query/staking.test.ts new file mode 100644 index 00000000..ba06dc87 --- /dev/null +++ b/src/sdk/query/staking.test.ts @@ -0,0 +1,39 @@ +import { QueryClient, coin } from "@cosmjs/stargate" +import * as query from "../../protojs/cosmos/staking/v1beta1/tx" +import { setupStakeExtension } from "." +import Long from "long" + +describe("setupStakingExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + QuerySudoers: jest.fn().mockResolvedValue({ staking: {} }), + } as unknown as query.MsgClientImpl) + + test("should setup sudo extension correctly", () => { + const extension = setupStakeExtension(mockBaseQueryClient) + + expect(extension.staking).toBeDefined() + expect(extension.staking.cancelUnbondingDelegation).toBeInstanceOf(Function) + }) + + describe("sudo.querySudoers", () => { + test("should call QuerySudoersRequest and return the response", async () => { + const querySudoersRequest = jest + .spyOn(query.MsgCancelUnbondingDelegation, "fromPartial") + .mockReturnValue({} as query.MsgCancelUnbondingDelegation) + + const extension = setupStakeExtension(mockBaseQueryClient) + const testArgs = { + validatorAddress: "", + delegatorAddress: "", + amount: coin(1, "unibi"), + creationHeight: new Long(0), + } + const result = await extension.staking.cancelUnbondingDelegation(testArgs) + + expect(querySudoersRequest).toHaveBeenCalledWith(testArgs) + expect(result).toEqual({ staking: {} }) + }) + }) +}) diff --git a/src/sdk/query/staking.ts b/src/sdk/query/staking.ts new file mode 100644 index 00000000..a46e00a1 --- /dev/null +++ b/src/sdk/query/staking.ts @@ -0,0 +1,29 @@ +import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" +import { + MsgCancelUnbondingDelegation, + MsgCancelUnbondingDelegationResponse, + MsgClientImpl, +} from "../../protojs/cosmos/staking/v1beta1/tx" + +export interface StakeExtension { + readonly staking: Readonly<{ + cancelUnbondingDelegation: ( + args: MsgCancelUnbondingDelegation + ) => Promise + }> +} + +export const setupStakeExtension = (base: QueryClient): StakeExtension => { + const rpcClient = createProtobufRpcClient(base) + const queryService = new MsgClientImpl(rpcClient) + + return { + staking: { + cancelUnbondingDelegation: async (args: MsgCancelUnbondingDelegation) => { + const req = MsgCancelUnbondingDelegation.fromPartial(args) + const resp = await queryService.CancelUnbondingDelegation(req) + return resp + }, + }, + } +} diff --git a/src/sdk/tx/txClient.ts b/src/sdk/tx/txClient.ts index 81ef2530..33a498e4 100644 --- a/src/sdk/tx/txClient.ts +++ b/src/sdk/tx/txClient.ts @@ -24,6 +24,7 @@ import { setupOracleExtension, setupEpochsExtension, setupDevgasExtension, + setupStakeExtension, } from ".." export const nibiruRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ @@ -52,6 +53,7 @@ export class NibiruTxClient extends SigningStargateClient { setupDistributionExtension, setupGovExtension, setupStakingExtension, + setupStakeExtension, setupIbcExtension, setupWasmExtension, setupAuthExtension