Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions governance/pyth_staking_sdk/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import { base } from "@cprussin/eslint-config";

export default [
...base,
{
rules: {
"n/no-unpublished-import": "off",
"unicorn/no-null": "off",
"unicorn/prefer-node-protocol": "off",
},
},
];
export { base as default } from "@cprussin/eslint-config";
2 changes: 1 addition & 1 deletion governance/pyth_staking_sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/staking-sdk",
"version": "0.2.0",
"version": "0.2.1",
"description": "Pyth staking SDK",
"type": "module",
"exports": {
Expand Down
54 changes: 41 additions & 13 deletions governance/pyth_staking_sdk/src/pyth-staking-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as crypto from "crypto";
import crypto from "crypto"; // eslint-disable-line unicorn/prefer-node-protocol

import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
import {
Expand Down Expand Up @@ -752,7 +752,7 @@ export class PythStakingClient {
publisherStakeAccountPositions: stakeAccount,
publisherStakeAccountCustody: stakeAccount
? getStakeAccountCustodyAddress(stakeAccount)
: null,
: null, // eslint-disable-line unicorn/no-null
stakeAccountPositions,
stakeAccountCustody: getStakeAccountCustodyAddress(
stakeAccountPositions,
Expand Down Expand Up @@ -839,6 +839,7 @@ export class PythStakingClient {
.setPublisherStakeAccount()
.accounts({
currentStakeAccountPositionsOption: stakeAccountPositions,
// eslint-disable-next-line unicorn/no-null
newStakeAccountPositionsOption: newStakeAccountPositions ?? null,
publisher,
})
Expand Down Expand Up @@ -1088,22 +1089,25 @@ export class PythStakingClient {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
const res = await reader.read();
if (res.done) break;
if (typeof res.value === "string") {
if (res.done) {
break;
} else if (
typeof res.value === "string" ||
res.value instanceof Uint8Array
) {
jsonparser.write(res.value);
}
}
};

parse().catch((error: unknown) => {
reject(
error instanceof Error
? error
: new Error(
typeof error === "string" ? error : "Unknown Error",
),
);
});
parse().then(
() => {
reject(new EndOfStreamError());
},
(error: unknown) => {
reject(intoError(error));
},
);
});

return accountSchema
Expand Down Expand Up @@ -1140,6 +1144,16 @@ const accountSchema = z.array(
}),
);

const intoError = (error: unknown): Error => {
if (error instanceof Error) {
return error;
} else if (typeof error === "string") {
return new Error(error);
} else {
return new UnknownError();
}
};

class NotOKError extends Error {
constructor(result: Response) {
super(`Received a ${result.status.toString()} response for ${result.url}`);
Expand All @@ -1154,3 +1168,17 @@ class NoBodyError extends Error {
this.name = "NoBodyError";
}
}

class EndOfStreamError extends Error {
constructor() {
super("Reached end of stream without finding accounts");
this.name = "EndOfStreamError";
}
}

class UnknownError extends Error {
constructor() {
super("Unknown error");
this.name = "UnknownError";
}
}
2 changes: 1 addition & 1 deletion governance/pyth_staking_sdk/src/utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const extractPublisherData = (
stakeAccount:
poolData.publisherStakeAccounts[index] === undefined ||
poolData.publisherStakeAccounts[index].equals(PublicKey.default)
? null
? null // eslint-disable-line unicorn/no-null
: poolData.publisherStakeAccounts[index],
totalDelegation:
(poolData.delState[index]?.totalDelegation ?? 0n) +
Expand Down