diff --git a/.github/workflows/ci-main.yaml b/.github/workflows/ci-main.yaml index e37711f..d0d5602 100644 --- a/.github/workflows/ci-main.yaml +++ b/.github/workflows/ci-main.yaml @@ -24,13 +24,20 @@ jobs: - name: Run CI run: bun run ci - - name: Prepare .npmrc for publishing + - name: Publish to NPM package registry + # https://github.com/oven-sh/bun/issues/1976 run: | echo "@secretkeylabs:registry=https://registry.npmjs.org/" > .npmrc - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc + echo "//registry.npmjs.org/:_authToken=$AUTH_TOKEN" >> .npmrc + bunx npm@latest publish --access=public --tag=latest env: - NPM_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} + AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} - - name: Publish to NPM package registry + - name: Publish to GitHub package registry # https://github.com/oven-sh/bun/issues/1976 - run: bunx npm@latest publish --access=public --tag=latest + run: | + echo "@secretkeylabs:registry=https://npm.pkg.github.com/" > .npmrc + echo "//npm.pkg.github.com/:_authToken=$AUTH_TOKEN" >> .npmrc + bunx npm@latest publish --access=public --tag=latest + env: + AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci-pr.yaml b/.github/workflows/ci-pr.yaml index fb7ae3a..7029fd6 100644 --- a/.github/workflows/ci-pr.yaml +++ b/.github/workflows/ci-pr.yaml @@ -31,22 +31,27 @@ jobs: name: Get commit sha run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - name: Set publish version + - name: Set package version with commit sha # https://github.com/oven-sh/bun/issues/1976 run: bunx npm@latest version --no-git-tag-version $CURRENT_VERSION-$SHA env: SHA: ${{ steps.sha.outputs.SHA }} CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }} - - name: Prepare .npmrc for publishing + - name: Publish to NPM package registry + # https://github.com/oven-sh/bun/issues/1976 run: | echo "@secretkeylabs:registry=https://registry.npmjs.org/" > .npmrc - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc + echo "//registry.npmjs.org/:_authToken=$AUTH_TOKEN" >> .npmrc + bunx npm@latest publish --access=public env: - NPM_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} + AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} - - name: Publish to NPM package registry + - name: Publish to GitHub package registry # https://github.com/oven-sh/bun/issues/1976 - run: bunx npm@latest publish --access=public --tag pr-$PR_NUMBER + run: | + echo "@secretkeylabs:registry=https://npm.pkg.github.com/" > .npmrc + echo "//npm.pkg.github.com/:_authToken=$AUTH_TOKEN" >> .npmrc + bunx npm@latest publish --access=public env: - PR_NUMBER: ${{ github.event.number }} + AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..a667944 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,2 @@ +# Use defaults +{} diff --git a/bun.lockb b/bun.lockb index bb60c35..98b8a21 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 72bdd56..c176937 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@secretkeylabs/stacks-tools", - "version": "0.1.0", + "version": "0.2.0", "type": "module", "files": [ "dist" diff --git a/src/queries/get-signer-total-locked.ts b/src/queries/get-signer-total-locked.ts index 147700b..ee971b6 100644 --- a/src/queries/get-signer-total-locked.ts +++ b/src/queries/get-signer-total-locked.ts @@ -8,9 +8,18 @@ import { type SafeError, } from "../utils/safe.js"; -export type Args = { +export type Identifier = + | { + type: "address"; + signerAddress: string; + } + | { + type: "publicKey"; + signerPublicKey: string; + }; + +export type Args = { identifier: Identifier } & { cycleNumber: number; - signerAddress: string; } & ApiRequestOptions; /** @@ -21,7 +30,7 @@ export async function getSignerTotalLocked( ): Promise>> { let totalLocked = 0n; - const { signerAddress, ...rest } = args; + const { identifier, ...rest } = args; let hasMore = true; let offset = 0; @@ -46,10 +55,18 @@ export async function getSignerTotalLocked( } for (const signer of data.results) { - if (signer.signer_address === signerAddress) { - totalLocked = BigInt(signer.stacked_amount); - found = true; - break; + if (identifier.type === "address") { + if (signer.signer_address === identifier.signerAddress) { + totalLocked = BigInt(signer.stacked_amount); + found = true; + break; + } + } else { + if (signer.signing_key === identifier.signerPublicKey) { + totalLocked = BigInt(signer.stacked_amount); + found = true; + break; + } } } @@ -62,7 +79,8 @@ export async function getSignerTotalLocked( name: "SignerNotFound", message: "Signer not found.", data: { - signerAddress, + identifier, + cycle: args.cycleNumber, }, }); }