keyvan hai 1 ano
pai
achega
a01e26561d

+ 0 - 0
governance/pyth_staking_sdk/eslint.config.js → governance/pyth_staking_sdk/eslint.config.mjs


+ 1 - 1
governance/pyth_staking_sdk/package.json

@@ -8,7 +8,7 @@
     "access": "public"
   },
   "scripts": {
-    "build": "tsc && node scripts/update-package-json.js",
+    "build": "tsc && node scripts/update-package-json.mjs",
     "test": "pnpm run test:format && pnpm run test:lint && pnpm run test:integration && pnpm run test:types",
     "fix": "pnpm fix:lint && pnpm fix:format",
     "fix:format": "prettier --write .",

+ 0 - 0
governance/pyth_staking_sdk/prettier.config.js → governance/pyth_staking_sdk/prettier.config.mjs


+ 1 - 3
governance/pyth_staking_sdk/scripts/update-package-json.js → governance/pyth_staking_sdk/scripts/update-package-json.mjs

@@ -15,8 +15,6 @@ const distPackageJsonPath = path.join(__dirname, "..", "dist", "package.json");
 
 const packageJson = JSON.parse(fs.readFileSync(distPackageJsonPath, "utf8"));
 
-packageJson.exports = {
-  ".": "./src/index.js",
-};
+packageJson.main = "src/index.js";
 
 fs.writeFileSync(distPackageJsonPath, JSON.stringify(packageJson, null, 2));

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

@@ -9,7 +9,7 @@ export const ONE_YEAR_IN_SECONDS = 365n * ONE_DAY_IN_SECONDS;
 
 export const EPOCH_DURATION = ONE_WEEK_IN_SECONDS;
 
-export const MAX_VOTER_WEIGHT = 10_000_000_000_000_000; // 10 Billion with 6 decimals
+export const MAX_VOTER_WEIGHT = 10_000_000_000_000_000n; // 10 Billion with 6 decimals
 
 export const FRACTION_PRECISION = 1_000_000;
 export const FRACTION_PRECISION_N = 1_000_000n;

+ 4 - 6
governance/pyth_staking_sdk/src/pdas.ts

@@ -64,14 +64,12 @@ export const getVoterWeightRecordAddress = (
   return PublicKey.findProgramAddressSync(
     [Buffer.from("voter_weight"), stakeAccountPositions.toBuffer()],
     STAKING_PROGRAM_ADDRESS,
-  )[0];
+  );
 };
 
-export const getMaxVoterWeightRecordAddress = (
-  stakeAccountPositions: PublicKey,
-) => {
+export const getMaxVoterWeightRecordAddress = () => {
   return PublicKey.findProgramAddressSync(
-    [Buffer.from("max_voter"), stakeAccountPositions.toBuffer()],
+    [Buffer.from("max_voter")],
     STAKING_PROGRAM_ADDRESS,
-  )[0];
+  );
 };

+ 9 - 8
governance/pyth_staking_sdk/src/pyth-staking-client.ts

@@ -769,7 +769,7 @@ export class PythStakingClient {
    */
   public async getScalingFactor(): Promise<number> {
     const targetAccount = await this.getTargetAccount();
-    return Number(targetAccount.locked) / MAX_VOTER_WEIGHT;
+    return Number(targetAccount.locked) / Number(MAX_VOTER_WEIGHT);
   }
 
   public async getRecoverAccountInstruction(
@@ -821,8 +821,8 @@ export class PythStakingClient {
       .instruction();
   }
 
-  public async getMainStakeAccount() {
-    const stakeAccountPositions = await this.getAllStakeAccountPositions();
+  public async getMainStakeAccount(owner?: PublicKey) {
+    const stakeAccountPositions = await this.getAllStakeAccountPositions(owner);
     const currentEpoch = await getCurrentEpoch(this.connection);
 
     const stakeAccountVotingTokens = await Promise.all(
@@ -858,17 +858,18 @@ export class PythStakingClient {
     return mainAccount;
   }
 
-  public async getVoterWeight() {
-    const mainAccount = await this.getMainStakeAccount();
+  public async getVoterWeight(owner?: PublicKey) {
+    const mainAccount = await this.getMainStakeAccount(owner);
 
     if (mainAccount === undefined) {
       return 0;
     }
 
-    const scalingFactor = await this.getScalingFactor();
-    return Number(mainAccount.votingTokens) / scalingFactor;
+    const targetAccount = await this.getTargetAccount();
+
+    return (mainAccount.votingTokens * MAX_VOTER_WEIGHT) / targetAccount.locked;
   }
-  
+
   public async getPythTokenMint(): Promise<Mint> {
     const globalConfig = await this.getGlobalConfig();
     return getMint(this.connection, globalConfig.pythTokenMint);