Skip to content

Commit a01e265

Browse files
committed
fix
1 parent da1f031 commit a01e265

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

governance/pyth_staking_sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"access": "public"
99
},
1010
"scripts": {
11-
"build": "tsc && node scripts/update-package-json.js",
11+
"build": "tsc && node scripts/update-package-json.mjs",
1212
"test": "pnpm run test:format && pnpm run test:lint && pnpm run test:integration && pnpm run test:types",
1313
"fix": "pnpm fix:lint && pnpm fix:format",
1414
"fix:format": "prettier --write .",

governance/pyth_staking_sdk/scripts/update-package-json.js renamed to governance/pyth_staking_sdk/scripts/update-package-json.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const distPackageJsonPath = path.join(__dirname, "..", "dist", "package.json");
1515

1616
const packageJson = JSON.parse(fs.readFileSync(distPackageJsonPath, "utf8"));
1717

18-
packageJson.exports = {
19-
".": "./src/index.js",
20-
};
18+
packageJson.main = "src/index.js";
2119

2220
fs.writeFileSync(distPackageJsonPath, JSON.stringify(packageJson, null, 2));

governance/pyth_staking_sdk/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const ONE_YEAR_IN_SECONDS = 365n * ONE_DAY_IN_SECONDS;
99

1010
export const EPOCH_DURATION = ONE_WEEK_IN_SECONDS;
1111

12-
export const MAX_VOTER_WEIGHT = 10_000_000_000_000_000; // 10 Billion with 6 decimals
12+
export const MAX_VOTER_WEIGHT = 10_000_000_000_000_000n; // 10 Billion with 6 decimals
1313

1414
export const FRACTION_PRECISION = 1_000_000;
1515
export const FRACTION_PRECISION_N = 1_000_000n;

governance/pyth_staking_sdk/src/pdas.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ export const getVoterWeightRecordAddress = (
6464
return PublicKey.findProgramAddressSync(
6565
[Buffer.from("voter_weight"), stakeAccountPositions.toBuffer()],
6666
STAKING_PROGRAM_ADDRESS,
67-
)[0];
67+
);
6868
};
6969

70-
export const getMaxVoterWeightRecordAddress = (
71-
stakeAccountPositions: PublicKey,
72-
) => {
70+
export const getMaxVoterWeightRecordAddress = () => {
7371
return PublicKey.findProgramAddressSync(
74-
[Buffer.from("max_voter"), stakeAccountPositions.toBuffer()],
72+
[Buffer.from("max_voter")],
7573
STAKING_PROGRAM_ADDRESS,
76-
)[0];
74+
);
7775
};

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ export class PythStakingClient {
769769
*/
770770
public async getScalingFactor(): Promise<number> {
771771
const targetAccount = await this.getTargetAccount();
772-
return Number(targetAccount.locked) / MAX_VOTER_WEIGHT;
772+
return Number(targetAccount.locked) / Number(MAX_VOTER_WEIGHT);
773773
}
774774

775775
public async getRecoverAccountInstruction(
@@ -821,8 +821,8 @@ export class PythStakingClient {
821821
.instruction();
822822
}
823823

824-
public async getMainStakeAccount() {
825-
const stakeAccountPositions = await this.getAllStakeAccountPositions();
824+
public async getMainStakeAccount(owner?: PublicKey) {
825+
const stakeAccountPositions = await this.getAllStakeAccountPositions(owner);
826826
const currentEpoch = await getCurrentEpoch(this.connection);
827827

828828
const stakeAccountVotingTokens = await Promise.all(
@@ -858,17 +858,18 @@ export class PythStakingClient {
858858
return mainAccount;
859859
}
860860

861-
public async getVoterWeight() {
862-
const mainAccount = await this.getMainStakeAccount();
861+
public async getVoterWeight(owner?: PublicKey) {
862+
const mainAccount = await this.getMainStakeAccount(owner);
863863

864864
if (mainAccount === undefined) {
865865
return 0;
866866
}
867867

868-
const scalingFactor = await this.getScalingFactor();
869-
return Number(mainAccount.votingTokens) / scalingFactor;
868+
const targetAccount = await this.getTargetAccount();
869+
870+
return (mainAccount.votingTokens * MAX_VOTER_WEIGHT) / targetAccount.locked;
870871
}
871-
872+
872873
public async getPythTokenMint(): Promise<Mint> {
873874
const globalConfig = await this.getGlobalConfig();
874875
return getMint(this.connection, globalConfig.pythTokenMint);

0 commit comments

Comments
 (0)