Explorar o código

fix(staking-sdk): fix staking-sdk build

This commit makes the following related changes:

- Fix `@pythnetwork/staking-sdk` build -- the prior build process created an
  unusable package due to producing invalid references in `package.json`.
- Clean up `@pythnetwork/staking-sdk` typescript configs, using nodenext for the
  target and module resolution strategy
- Fix import statements in `@pythnetwork/staking-sdk` to properly work with
  nodenext resolution
- Distribute `@pythnetwork/staking-sdk` as esm-only -- nowadays supporting cjs
  is making less sense and in particular some of the underlying solana libs are
  distributed as esm-only, so it really doesn't make sense for us to distribute
  cjs
- Stop using nextjs's `transpilePackages` for apps that depend on monorepo
  packages -- this makes less sense nowadays with [turbo
  watch](https://turbo.build/docs/reference/watch) and it has some major
  downsides, in particular it doesn't work if you have different tsconfig
  settings between apps and the packages they depend on.
Connor Prussin hai 7 meses
pai
achega
b0d68f775a
Modificáronse 30 ficheiros con 59 adicións e 115 borrados
  1. 0 2
      apps/api-reference/next.config.js
  2. 0 2
      apps/insights/next.config.js
  3. 0 7
      apps/insights/turbo.json
  4. 0 2
      apps/staking/next.config.js
  5. 0 8
      apps/staking/turbo.json
  6. 8 5
      governance/pyth_staking_sdk/package.json
  7. 0 21
      governance/pyth_staking_sdk/scripts/update-package-json.mjs
  8. 0 0
      governance/pyth_staking_sdk/src/idl/integrity-pool.json
  9. 0 0
      governance/pyth_staking_sdk/src/idl/publisher-caps.json
  10. 0 0
      governance/pyth_staking_sdk/src/idl/stake-caps-parameters.json
  11. 0 0
      governance/pyth_staking_sdk/src/idl/staking.json
  12. 9 9
      governance/pyth_staking_sdk/src/index.ts
  13. 1 1
      governance/pyth_staking_sdk/src/pdas.ts
  14. 19 19
      governance/pyth_staking_sdk/src/pyth-staking-client.ts
  15. 5 5
      governance/pyth_staking_sdk/src/pythnet-client.ts
  16. 2 2
      governance/pyth_staking_sdk/src/types.ts
  17. 0 0
      governance/pyth_staking_sdk/src/types/integrity-pool.ts
  18. 0 0
      governance/pyth_staking_sdk/src/types/publisher-caps.ts
  19. 0 0
      governance/pyth_staking_sdk/src/types/stake-caps-parameters.ts
  20. 0 0
      governance/pyth_staking_sdk/src/types/staking.ts
  21. 1 1
      governance/pyth_staking_sdk/src/utils/apy.ts
  22. 1 1
      governance/pyth_staking_sdk/src/utils/bn.ts
  23. 1 1
      governance/pyth_staking_sdk/src/utils/clock.ts
  24. 3 3
      governance/pyth_staking_sdk/src/utils/pool.ts
  25. 5 5
      governance/pyth_staking_sdk/src/utils/position.ts
  26. 1 1
      governance/pyth_staking_sdk/src/utils/transaction.ts
  27. 1 1
      governance/pyth_staking_sdk/src/utils/vesting.ts
  28. 1 15
      governance/pyth_staking_sdk/tsconfig.json
  29. 0 3
      governance/xc_admin/packages/xc_admin_frontend/turbo.json
  30. 1 1
      turbo.json

+ 0 - 2
apps/api-reference/next.config.js

@@ -29,8 +29,6 @@ export default {
     return config;
   },
 
-  transpilePackages: ["@pythnetwork/*"],
-
   headers: () => [
     {
       source: "/:path*",

+ 0 - 2
apps/insights/next.config.js

@@ -22,8 +22,6 @@ const config = {
     return config;
   },
 
-  transpilePackages: ["@pythnetwork/*"],
-
   headers: async () => [
     {
       source: "/:path*",

+ 0 - 7
apps/insights/turbo.json

@@ -14,13 +14,6 @@
         "DISABLE_ACCESSIBILITY_REPORTING"
       ]
     },
-    "start:dev": {
-      "dependsOn": [
-        "//#install:modules",
-        "pull:env",
-        "@pythnetwork/solana-utils#build"
-      ]
-    },
     "fix:lint": {
       "dependsOn": [
         "//#install:modules",

+ 0 - 2
apps/staking/next.config.js

@@ -22,8 +22,6 @@ export default {
     return config;
   },
 
-  transpilePackages: ["@pythnetwork/*"],
-
   headers: () => [
     {
       source: "/:path*",

+ 0 - 8
apps/staking/turbo.json

@@ -14,14 +14,6 @@
         "AMPLITUDE_API_KEY",
         "GOOGLE_ANALYTICS_ID"
       ]
-    },
-    "start:dev": {
-      "dependsOn": [
-        "//#install:modules",
-        "pull:env",
-        "@pythnetwork/hermes-client#build",
-        "@pythnetwork/solana-utils#build"
-      ]
     }
   }
 }

+ 8 - 5
governance/pyth_staking_sdk/package.json

@@ -1,10 +1,14 @@
 {
   "name": "@pythnetwork/staking-sdk",
-  "version": "0.1.1",
+  "version": "0.2.0",
   "description": "Pyth staking SDK",
-  "main": "src/index.ts",
-  "types": "src/index.d.ts",
   "type": "module",
+  "exports": {
+    "import": {
+      "types": "./dist/index.d.ts",
+      "default": "./dist/index.js"
+    }
+  },
   "files": [
     "dist/**/*"
   ],
@@ -15,10 +19,9 @@
     "access": "public"
   },
   "scripts": {
-    "build": "tsc",
+    "build": "tsc --noEmit false --incremental false --declaration true --outDir ./dist",
     "fix:format": "prettier --write .",
     "fix:lint": "eslint --fix . --max-warnings 0",
-    "prepublishOnly": "node scripts/update-package-json.mjs",
     "test:format": "prettier --check .",
     "test:lint": "eslint . --max-warnings 0",
     "test:types": "tsc"

+ 0 - 21
governance/pyth_staking_sdk/scripts/update-package-json.mjs

@@ -1,21 +0,0 @@
-import fs from "fs";
-import path from "path";
-import { fileURLToPath } from "url";
-
-/**
- * This script updates the package.json file in the dist directory after the TypeScript build.
- *
- * This ensures that the published package correctly references the compiled JavaScript
- * instead of the TypeScript source files.
- */
-
-const __dirname = path.dirname(fileURLToPath(import.meta.url));
-
-const distPackageJsonPath = path.join(__dirname, "..", "package.json");
-
-const packageJson = JSON.parse(fs.readFileSync(distPackageJsonPath, "utf8"));
-
-packageJson.main = "dist/src/index.js";
-packageJson.types = "dist/src/index.d.ts";
-
-fs.writeFileSync(distPackageJsonPath, JSON.stringify(packageJson, null, 2));

+ 0 - 0
governance/pyth_staking_sdk/idl/integrity-pool.json → governance/pyth_staking_sdk/src/idl/integrity-pool.json


+ 0 - 0
governance/pyth_staking_sdk/idl/publisher-caps.json → governance/pyth_staking_sdk/src/idl/publisher-caps.json


+ 0 - 0
governance/pyth_staking_sdk/idl/stake-caps-parameters.json → governance/pyth_staking_sdk/src/idl/stake-caps-parameters.json


+ 0 - 0
governance/pyth_staking_sdk/idl/staking.json → governance/pyth_staking_sdk/src/idl/staking.json


+ 9 - 9
governance/pyth_staking_sdk/src/index.ts

@@ -1,9 +1,9 @@
-export * from "./pdas";
-export * from "./pyth-staking-client";
-export * from "./pythnet-client";
-export * from "./types";
-export * from "./utils/apy";
-export * from "./utils/clock";
-export * from "./utils/pool";
-export * from "./utils/position";
-export * from "./utils/vesting";
+export * from "./pdas.js";
+export * from "./pyth-staking-client.js";
+export * from "./pythnet-client.js";
+export * from "./types.js";
+export * from "./utils/apy.js";
+export * from "./utils/clock.js";
+export * from "./utils/pool.js";
+export * from "./utils/position.js";
+export * from "./utils/vesting.js";

+ 1 - 1
governance/pyth_staking_sdk/src/pdas.ts

@@ -4,7 +4,7 @@ import {
   INTEGRITY_POOL_PROGRAM_ADDRESS,
   STAKE_CAPS_PARAMETERS_PROGRAM_ADDRESS,
   STAKING_PROGRAM_ADDRESS,
-} from "./constants";
+} from "./constants.js";
 
 export const getConfigAddress = () => {
   return PublicKey.findProgramAddressSync(

+ 19 - 19
governance/pyth_staking_sdk/src/pyth-staking-client.ts

@@ -30,7 +30,10 @@ import {
   FRACTION_PRECISION_N,
   ONE_YEAR_IN_SECONDS,
   POSITIONS_ACCOUNT_SIZE,
-} from "./constants";
+} from "./constants.js";
+import IntegrityPoolIdl from "./idl/integrity-pool.json" with { type: "json" };
+import PublisherCapsIdl from "./idl/publisher-caps.json" with { type: "json" };
+import StakingIdl from "./idl/staking.json" with { type: "json" };
 import {
   getConfigAddress,
   getDelegationRecordAddress,
@@ -38,7 +41,10 @@ import {
   getStakeAccountCustodyAddress,
   getStakeAccountMetadataAddress,
   getTargetAccountAddress,
-} from "./pdas";
+} from "./pdas.js";
+import type { IntegrityPool } from "./types/integrity-pool.js";
+import type { PublisherCaps } from "./types/publisher-caps.js";
+import type { Staking } from "./types/staking.js";
 import type {
   GlobalConfig,
   PoolConfig,
@@ -47,27 +53,21 @@ import type {
   TargetAccount,
   VoterWeightAction,
   VestingSchedule,
-} from "./types";
-import { PositionState } from "./types";
-import type { Staking } from "../types/staking";
-import { bigintMax, bigintMin } from "./utils/bigint";
-import { convertBigIntToBN, convertBNToBigInt } from "./utils/bn";
-import { epochToDate, getCurrentEpoch } from "./utils/clock";
-import { extractPublisherData } from "./utils/pool";
+} from "./types.js";
+import { PositionState } from "./types.js";
+import { bigintMax, bigintMin } from "./utils/bigint.js";
+import { convertBigIntToBN, convertBNToBigInt } from "./utils/bn.js";
+import { epochToDate, getCurrentEpoch } from "./utils/clock.js";
+import { extractPublisherData } from "./utils/pool.js";
 import {
   deserializeStakeAccountPositions,
   getPositionState,
   getVotingTokenAmount,
-} from "./utils/position";
-import { sendTransaction } from "./utils/transaction";
-import { getUnlockSchedule } from "./utils/vesting";
-import type { PythStakingWallet } from "./utils/wallet";
-import { DummyWallet } from "./utils/wallet";
-import * as IntegrityPoolIdl from "../idl/integrity-pool.json";
-import * as PublisherCapsIdl from "../idl/publisher-caps.json";
-import * as StakingIdl from "../idl/staking.json";
-import type { IntegrityPool } from "../types/integrity-pool";
-import type { PublisherCaps } from "../types/publisher-caps";
+} from "./utils/position.js";
+import { sendTransaction } from "./utils/transaction.js";
+import { getUnlockSchedule } from "./utils/vesting.js";
+import type { PythStakingWallet } from "./utils/wallet.js";
+import { DummyWallet } from "./utils/wallet.js";
 
 export type PythStakingClientConfig = {
   connection: Connection;

+ 5 - 5
governance/pyth_staking_sdk/src/pythnet-client.ts

@@ -7,11 +7,11 @@ import {
 } from "@pythnetwork/client";
 import { Connection } from "@solana/web3.js";
 
-import { getStakeCapsParametersAddress } from "./pdas";
-import { convertBNToBigInt } from "./utils/bn";
-import { DummyWallet } from "./utils/wallet";
-import * as StakeCapsParametersIdl from "../idl/stake-caps-parameters.json";
-import type { StakeCapsParameters } from "../types/stake-caps-parameters";
+import StakeCapsParametersIdl from "./idl/stake-caps-parameters.json" with { type: "json" };
+import { getStakeCapsParametersAddress } from "./pdas.js";
+import type { StakeCapsParameters } from "./types/stake-caps-parameters.js";
+import { convertBNToBigInt } from "./utils/bn.js";
+import { DummyWallet } from "./utils/wallet.js";
 export class PythnetClient {
   connection: Connection;
   provider: AnchorProvider;

+ 2 - 2
governance/pyth_staking_sdk/src/types.ts

@@ -1,8 +1,8 @@
 import type { BN, IdlAccounts, IdlTypes } from "@coral-xyz/anchor";
 import { PublicKey } from "@solana/web3.js";
 
-import type { IntegrityPool } from "../types/integrity-pool";
-import type { Staking } from "../types/staking";
+import type { IntegrityPool } from "./types/integrity-pool.js";
+import type { Staking } from "./types/staking.js";
 
 // This type converts all From types to To types in a given object.
 export type Convert<T, From, To> = T extends From

+ 0 - 0
governance/pyth_staking_sdk/types/integrity-pool.ts → governance/pyth_staking_sdk/src/types/integrity-pool.ts


+ 0 - 0
governance/pyth_staking_sdk/types/publisher-caps.ts → governance/pyth_staking_sdk/src/types/publisher-caps.ts


+ 0 - 0
governance/pyth_staking_sdk/types/stake-caps-parameters.ts → governance/pyth_staking_sdk/src/types/stake-caps-parameters.ts


+ 0 - 0
governance/pyth_staking_sdk/types/staking.ts → governance/pyth_staking_sdk/src/types/staking.ts


+ 1 - 1
governance/pyth_staking_sdk/src/utils/apy.ts

@@ -1,4 +1,4 @@
-import { FRACTION_PRECISION } from "../constants";
+import { FRACTION_PRECISION } from "../constants.js";
 
 export const convertEpochYieldToApy = (epochYield: bigint) => {
   return (Number(epochYield) * 52 * 100) / FRACTION_PRECISION;

+ 1 - 1
governance/pyth_staking_sdk/src/utils/bn.ts

@@ -3,7 +3,7 @@
 /* eslint-disable @typescript-eslint/no-unsafe-return */
 import { BN } from "@coral-xyz/anchor";
 
-import type { ConvertBigIntToBN, ConvertBNToBigInt } from "../types";
+import type { ConvertBigIntToBN, ConvertBNToBigInt } from "../types.js";
 
 export const convertBNToBigInt = <T>(obj: T): ConvertBNToBigInt<T> => {
   if (obj instanceof BN) {

+ 1 - 1
governance/pyth_staking_sdk/src/utils/clock.ts

@@ -1,6 +1,6 @@
 import { Connection } from "@solana/web3.js";
 
-import { EPOCH_DURATION } from "../constants";
+import { EPOCH_DURATION } from "../constants.js";
 
 export const getCurrentSolanaTimestamp = async (connection: Connection) => {
   const slot = await connection.getSlot("finalized");

+ 3 - 3
governance/pyth_staking_sdk/src/utils/pool.ts

@@ -3,9 +3,9 @@ import { PublicKey } from "@solana/web3.js";
 import {
   computeDelegatorRewardPercentage,
   convertEpochYieldToApy,
-} from "./apy";
-import { FRACTION_PRECISION_N } from "../constants";
-import type { PoolDataAccount, PublisherData } from "../types";
+} from "./apy.js";
+import { FRACTION_PRECISION_N } from "../constants.js";
+import type { PoolDataAccount, PublisherData } from "../types.js";
 
 export const extractPublisherData = (
   poolData: PoolDataAccount,

+ 5 - 5
governance/pyth_staking_sdk/src/utils/position.ts

@@ -1,19 +1,19 @@
 import { BorshCoder } from "@coral-xyz/anchor";
 import { PublicKey } from "@solana/web3.js";
 
-import { convertBNToBigInt } from "./bn";
-import type { Staking } from "../../types/staking";
+import { convertBNToBigInt } from "./bn.js";
 import {
   POSITION_BUFFER_SIZE,
   POSITIONS_ACCOUNT_HEADER_SIZE,
-} from "../constants";
+} from "../constants.js";
+import type { Staking } from "../types/staking.js";
 import type {
   Position,
   PositionAnchor,
   StakeAccountPositions,
   TargetWithParameters,
-} from "../types";
-import { PositionState } from "../types";
+} from "../types.js";
+import { PositionState } from "../types.js";
 
 export const getPositionState = (
   position: Position,

+ 1 - 1
governance/pyth_staking_sdk/src/utils/transaction.ts

@@ -1,7 +1,7 @@
 import { TransactionBuilder } from "@pythnetwork/solana-utils";
 import { Connection, TransactionInstruction } from "@solana/web3.js";
 
-import type { PythStakingWallet } from "./wallet";
+import type { PythStakingWallet } from "./wallet.js";
 
 export const sendTransaction = async (
   instructions: TransactionInstruction[],

+ 1 - 1
governance/pyth_staking_sdk/src/utils/vesting.ts

@@ -1,4 +1,4 @@
-import type { UnlockSchedule, VestingSchedule } from "../types";
+import type { UnlockSchedule, VestingSchedule } from "../types.js";
 
 export const getUnlockSchedule = (options: {
   pythTokenListTime: bigint;

+ 1 - 15
governance/pyth_staking_sdk/tsconfig.json

@@ -1,18 +1,4 @@
 {
   "extends": "@cprussin/tsconfig/base.json",
-  "include": ["**/*.ts", "**/*.json"],
-  "exclude": ["node_modules", "dist"],
-  "compilerOptions": {
-    "outDir": "./dist",
-    "baseUrl": "./",
-    "noEmit": false,
-    "target": "ESNext",
-    "module": "CommonJS",
-    "moduleResolution": "Node",
-    "declaration": true,
-    "composite": true,
-    "declarationMap": true,
-    "esModuleInterop": true,
-    "verbatimModuleSyntax": false
-  }
+  "exclude": ["node_modules", "dist"]
 }

+ 0 - 3
governance/xc_admin/packages/xc_admin_frontend/turbo.json

@@ -8,9 +8,6 @@
         "NEXT_PUBLIC_MAINNET_RPC",
         "NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID"
       ]
-    },
-    "start:dev": {
-      "dependsOn": ["//#install:modules", "pull:env", "^build"]
     }
   }
 }

+ 1 - 1
turbo.json

@@ -133,7 +133,7 @@
       "cache": false
     },
     "start:dev": {
-      "dependsOn": ["//#install:modules", "pull:env"],
+      "dependsOn": ["//#install:modules", "pull:env", "^build"],
       "persistent": true,
       "cache": false
     },