Skip to content

Commit 05a8244

Browse files
committed
fix(staking-sdk): more staking-sdk improvements
- Don't disable eslint rules unnecessarily - Ensure we handle `Uint8Array`s in the response body too - Throw an explicit error if we reach the end of the stream without finding a result
1 parent ea118ba commit 05a8244

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
import { base } from "@cprussin/eslint-config";
2-
3-
export default [
4-
...base,
5-
{
6-
rules: {
7-
"n/no-unpublished-import": "off",
8-
"unicorn/no-null": "off",
9-
"unicorn/prefer-node-protocol": "off",
10-
},
11-
},
12-
];
1+
export { base as default } from "@cprussin/eslint-config";

governance/pyth_staking_sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/staking-sdk",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Pyth staking SDK",
55
"type": "module",
66
"exports": {

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as crypto from "crypto";
1+
import crypto from "crypto"; // eslint-disable-line unicorn/prefer-node-protocol
22

33
import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
44
import {
@@ -752,7 +752,7 @@ export class PythStakingClient {
752752
publisherStakeAccountPositions: stakeAccount,
753753
publisherStakeAccountCustody: stakeAccount
754754
? getStakeAccountCustodyAddress(stakeAccount)
755-
: null,
755+
: null, // eslint-disable-line unicorn/no-null
756756
stakeAccountPositions,
757757
stakeAccountCustody: getStakeAccountCustodyAddress(
758758
stakeAccountPositions,
@@ -839,6 +839,7 @@ export class PythStakingClient {
839839
.setPublisherStakeAccount()
840840
.accounts({
841841
currentStakeAccountPositionsOption: stakeAccountPositions,
842+
// eslint-disable-next-line unicorn/no-null
842843
newStakeAccountPositionsOption: newStakeAccountPositions ?? null,
843844
publisher,
844845
})
@@ -1088,22 +1089,33 @@ export class PythStakingClient {
10881089
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
10891090
while (true) {
10901091
const res = await reader.read();
1091-
if (res.done) break;
1092-
if (typeof res.value === "string") {
1092+
if (res.done) {
1093+
break;
1094+
} else if (
1095+
typeof res.value === "string" ||
1096+
res.value instanceof Uint8Array
1097+
) {
10931098
jsonparser.write(res.value);
10941099
}
10951100
}
10961101
};
10971102

1098-
parse().catch((error: unknown) => {
1099-
reject(
1100-
error instanceof Error
1101-
? error
1102-
: new Error(
1103-
typeof error === "string" ? error : "Unknown Error",
1104-
),
1105-
);
1106-
});
1103+
parse().then(
1104+
() => {
1105+
reject(
1106+
new Error("Reached end of stream without finding accounts"),
1107+
);
1108+
},
1109+
(error: unknown) => {
1110+
reject(
1111+
error instanceof Error
1112+
? error
1113+
: new Error(
1114+
typeof error === "string" ? error : "Unknown Error",
1115+
),
1116+
);
1117+
},
1118+
);
11071119
});
11081120

11091121
return accountSchema

governance/pyth_staking_sdk/src/utils/pool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const extractPublisherData = (
1717
stakeAccount:
1818
poolData.publisherStakeAccounts[index] === undefined ||
1919
poolData.publisherStakeAccounts[index].equals(PublicKey.default)
20-
? null
20+
? null // eslint-disable-line unicorn/no-null
2121
: poolData.publisherStakeAccounts[index],
2222
totalDelegation:
2323
(poolData.delState[index]?.totalDelegation ?? 0n) +

0 commit comments

Comments
 (0)