Skip to content

Commit

Permalink
Refactor pyth client (#274)
Browse files Browse the repository at this point in the history
* Bump

* Refactor pyth client

* Bump. refactor client
  • Loading branch information
guibescos authored Nov 18, 2023
1 parent 9209595 commit afcd195
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
29 changes: 1 addition & 28 deletions staking/app/PythClient.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
import { AnchorProvider, Wallet } from "@project-serum/anchor";
import { PublicKey } from "@solana/web3.js";
import { STAKING_ADDRESS } from "./constants";
import { StakeConnection } from "./StakeConnection";

export class PythClient {
program: { programId: PublicKey };
cluster: string;
constructor(public stakeConnection: StakeConnection, cluster: string) {
this.cluster = cluster;
this.program = {
programId: STAKING_ADDRESS,
};
}
static async connect(
provider: AnchorProvider,
cluster: string
): Promise<PythClient> {
// only supports localnet and devnet for now
// TODO: update this to support mainnet when program is deployed
return new PythClient(
await StakeConnection.createStakeConnection(
provider.connection,
provider.wallet as unknown as Wallet,
STAKING_ADDRESS
),
cluster
);
}
}
export const PythClient = StakeConnection;
13 changes: 12 additions & 1 deletion staking/app/StakeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
PROGRAM_VERSION_V2,
withCreateTokenOwnerRecord,
} from "@solana/spl-governance";
import { GOVERNANCE_ADDRESS } from "./constants";
import { GOVERNANCE_ADDRESS, STAKING_ADDRESS } from "./constants";
import assert from "assert";
import { PositionAccountJs } from "./PositionAccountJs";
let wasm = wasm2;
Expand Down Expand Up @@ -75,6 +75,17 @@ export class StakeConnection {
this.governanceAddress = GOVERNANCE_ADDRESS();
}

public static async connect(
connection: Connection,
wallet: Wallet
): Promise<StakeConnection> {
return await StakeConnection.createStakeConnection(
connection,
wallet,
STAKING_ADDRESS
);
}

// creates a program connection and loads the staking config
// the constructor cannot be async so we use a static method
public static async createStakeConnection(
Expand Down
2 changes: 1 addition & 1 deletion staking/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/staking",
"version": "1.3.5",
"version": "2.0.0",
"description": "Pyth Network Staking SDK",
"main": "lib/app/index.js",
"types": "lib/app/index.d.ts",
Expand Down

2 comments on commit afcd195

@vercel
Copy link

@vercel vercel bot commented on afcd195 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

staking-devnet – ./

staking-devnet-git-main-pyth-web.vercel.app
governance-nu.vercel.app
staking-devnet-pyth-web.vercel.app

@vercel
Copy link

@vercel vercel bot commented on afcd195 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.