@pyefi/sdk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pye Finance
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @pyefi/sdk
2
+
3
+ Core SDK for the [Pye Finance](https://pye.fi) Solana yield protocol — stores, data fetching, and transaction execution.
4
+
5
+ Use this package if you're building a custom UI on top of the Pye protocol. If you just want a drop-in widget, see [`@pyefi/widget`](https://www.npmjs.com/package/@pyefi/widget).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @pyefi/sdk
11
+ ```
12
+
13
+ Peer dependencies (install whichever you actually use):
14
+
15
+ ```bash
16
+ pnpm add @solana/web3.js @solana/spl-token @solana/kit \
17
+ @cks-systems/manifest-sdk @supabase/supabase-js \
18
+ react @solana/wallet-adapter-react
19
+ ```
20
+
21
+ `react`, `@solana/wallet-adapter-react`, and `@supabase/supabase-js` are optional peers — only required if you import from `@pyefi/sdk/react` or use the realtime market store.
22
+
23
+ ## Configuration
24
+
25
+ ```ts
26
+ import { configurePyeSDK } from "@pyefi/sdk";
27
+
28
+ configurePyeSDK({
29
+ rpcUrl: "https://your-rpc-endpoint",
30
+ supabaseUrl: "https://your-project.supabase.co",
31
+ supabaseAnonKey: "your-supabase-anon-key",
32
+ });
33
+ ```
34
+
35
+ ## React hooks
36
+
37
+ ```tsx
38
+ import {
39
+ PyeSDKProvider,
40
+ useMarketStore,
41
+ useBalanceStore,
42
+ useWalletStore,
43
+ } from "@pyefi/sdk/react";
44
+
45
+ function App() {
46
+ return (
47
+ <PyeSDKProvider config={{ rpcUrl, supabaseUrl, supabaseAnonKey }}>
48
+ <MyComponent />
49
+ </PyeSDKProvider>
50
+ );
51
+ }
52
+
53
+ function MyComponent() {
54
+ const markets = useMarketStore((s) => s.markets);
55
+ const stakeAccounts = useBalanceStore((s) => s.userStakeAccounts);
56
+ const walletStatus = useWalletStore((s) => s.status);
57
+ return <div>{markets.length} markets</div>;
58
+ }
59
+ ```
60
+
61
+ ## Key exports
62
+
63
+ | Export | Description |
64
+ |--------|-------------|
65
+ | `validators`, `maturities`, `allowedLockups` | Protocol constants |
66
+ | `fetchUserStakeAccounts()` | Fetch a user's Solana stake accounts |
67
+ | `fetchManifestMarkets()` | Fetch order book data from Supabase |
68
+ | `checkSellLiquidity` / `checkBuyLiquidity` | Order book liquidity checks |
69
+ | `executeStakeDeposit()` | Deposit liquid SOL → mint PT + RT |
70
+ | `executeStakeAccountDeposit()` | Deposit existing stake account → mint PT + RT |
71
+ | `executeRtSell()` | Sell RT on Manifest for SOL |
72
+ | `executeSwap()` / `executeLimitOrder()` / `executeCancelOrder()` | Order management |
73
+ | `executeRedeem()` | Redeem PT at maturity for SOL |
74
+
75
+ ## Documentation
76
+
77
+ Full docs and architecture: [github.com/pyefi/pye-widget](https://github.com/pyefi/pye-widget).
78
+
79
+ ## License
80
+
81
+ [MIT](./LICENSE)
@@ -0,0 +1,225 @@
1
+ import * as immer from 'immer';
2
+ import * as zustand_vanilla from 'zustand/vanilla';
3
+ import { Address } from '@solana/kit';
4
+
5
+ interface Validator {
6
+ name: string;
7
+ symbol: string;
8
+ vote_account: string;
9
+ pt_sol: string;
10
+ rt_sol: string;
11
+ is_allowed: boolean;
12
+ type: "validator" | "lst";
13
+ }
14
+ type ValidatorId = "adrastea" | "alchemy" | "all-nodes" | "alpha-pro" | "anagram" | "anchorage-digital" | "anza" | "astralane" | "asymmetric" | "binance" | "bitwise" | "block-logic" | "blockdaemon" | "blockport" | "blocksize" | "bloxroute" | "blueshift" | "bonk" | "bybit" | "chainflow" | "chorus-one" | "coinbase" | "coyote-staking" | "dawnlabs" | "decentra" | "defi-dev-corp" | "drift" | "dsrv" | "edgevana" | "emory-blockchain" | "everstake" | "exo-tech" | "facilities" | "falconx" | "fd1" | "figment" | "forward-industries" | "galaxy" | "gate-omega" | "gemini" | "genco" | "global-stake" | "greed-academy" | "gripto" | "guardian" | "h2o-nodes" | "hashkey-cloud" | "haus" | "helius" | "hello-moon" | "hinode-tech" | "hubra" | "hylo" | "ice-staking" | "ily-validator" | "infinite-sol" | "jupiter" | "kairos-research" | "kiln" | "kraken" | "kumavalidator" | "laine" | "lakestake" | "lantern" | "ledger" | "luganodes" | "luminal" | "lumos-maxima" | "madlads" | "magic-eden" | "marginfi" | "meria" | "mesh-validator" | "monkedao" | "nansen" | "neodyme" | "nordic-staking" | "nova-consortium" | "okx-earn" | "omakase" | "orang3club" | "orangefin" | "ottersec" | "overclock" | "p-ops" | "p2p" | "parafi" | "phantom" | "phase-labs" | "pier-two" | "portals" | "project-catalyst" | "project-super" | "prostaking" | "pumpkins-pool" | "quicknode" | "radiants" | "rakurai" | "range" | "raposa" | "raydium" | "restake" | "rockaway-x" | "saga-dao" | "sec3" | "sendai" | "sensei-node" | "sentinel" | "shinobi" | "shiro" | "sol-rain-drops" | "sol-strategies" | "solana" | "solana-compass" | "solana-japan" | "solayer" | "solflare" | "solstack" | "solstice" | "solyrae" | "somos" | "squads-validator" | "stachenode" | "stakecraft" | "stakefish" | "stakely" | "stakin-the-tie" | "stakr-space" | "stardust" | "starke-finance" | "step-finance" | "stronghold" | "superfast" | "swyke" | "temporal" | "temporal-opal" | "the-vault" | "theia-capital" | "thw" | "tinydancer" | "triton-one" | "twinstake" | "txtx" | "unruggable" | "upbit-staking" | "valid-blocks" | "validation-cloud" | "valigator" | "vladika" | "vybe-network" | "watchtower" | "xandeum";
15
+ declare const validators: {
16
+ [key in ValidatorId]: Validator;
17
+ };
18
+ declare const ALLOWED_VALIDATORS: {
19
+ name: string;
20
+ symbol: string;
21
+ vote_account: string;
22
+ pt_sol: string;
23
+ rt_sol: string;
24
+ is_allowed: boolean;
25
+ type: "validator" | "lst";
26
+ id: ValidatorId;
27
+ }[];
28
+
29
+ interface Maturity {
30
+ human_readable: string;
31
+ month: string;
32
+ year: string;
33
+ issuance_start_timestamp: string;
34
+ issuance_close_timestamp: string;
35
+ maturity_timestamp: string;
36
+ }
37
+ type MaturityId = "q12026" | "q22026" | "q32026" | "q42026";
38
+ declare const maturities: {
39
+ [key in MaturityId]: Maturity;
40
+ };
41
+ declare const maturitiesArray: Maturity[];
42
+ declare const maturityIdsArray: MaturityId[];
43
+ declare const getMaturity: (maturityId: MaturityId) => Maturity;
44
+
45
+ type WalletStatus = "disconnected" | "connecting" | "connected";
46
+ interface WalletState {
47
+ status: WalletStatus;
48
+ publicKey: Address | null;
49
+ displayAddress: string | null;
50
+ balanceLamports: number | null;
51
+ error: string | null;
52
+ /** True after WalletSyncer has read the adapter state at least once. */
53
+ walletInitialized: boolean;
54
+ }
55
+ interface WalletActions {
56
+ setWalletStatus: (status: WalletStatus) => void;
57
+ setWalletPublicKey: (publicKey: Address | null) => void;
58
+ setDisplayAddress: (displayAddress: string | null) => void;
59
+ setBalanceLamports: (lamports: number | null) => void;
60
+ setError: (error: string | null) => void;
61
+ setWalletInitialized: (initialized: boolean) => void;
62
+ resetWallet: () => void;
63
+ }
64
+ type WalletStore = WalletState & WalletActions;
65
+ declare function createWalletStore(): Omit<zustand_vanilla.StoreApi<WalletStore>, "setState"> & {
66
+ setState(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer.WritableDraft<WalletStore>) => void), shouldReplace?: false): void;
67
+ setState(nextStateOrUpdater: WalletStore | ((state: immer.WritableDraft<WalletStore>) => void), shouldReplace: true): void;
68
+ };
69
+
70
+ type Balances = Record<string, number>;
71
+ type StakeAccountState = "active" | "activating" | "deactivating" | "inactive";
72
+ interface UserStakeAccount {
73
+ pubkey: string;
74
+ validatorVoteAccount: string;
75
+ validatorName: string;
76
+ validatorIcon: string;
77
+ validatorLogo: string | null;
78
+ /** Address Lookup Table pubkey for this validator. Required for v0 txs; null if not yet deployed. */
79
+ validatorAltPubkey: string | null;
80
+ lamports: number;
81
+ state: StakeAccountState;
82
+ }
83
+ interface OpenOrder {
84
+ /** Manifest market pubkey that holds this order */
85
+ marketKey: string;
86
+ /** Whether this is a bid (buy) or ask (sell) */
87
+ isBid: boolean;
88
+ /** Number of base tokens in the order */
89
+ numBaseTokens: number;
90
+ /** Price in quote tokens per base token */
91
+ tokenPrice: number;
92
+ /** Exchange-defined unique order id */
93
+ sequenceNumber: string;
94
+ }
95
+ interface BalanceState {
96
+ walletBalances: Balances;
97
+ exchangeBalances: Balances;
98
+ /** PT/RT open-orders balances keyed by mint address */
99
+ openOrdersBalances: Balances;
100
+ /** Per-market SOL (quote) withdrawable balances, keyed by "validatorId-maturityId-tokenType" */
101
+ solBalances: Balances;
102
+ /** Per-market SOL (quote) open-orders balances, keyed by "validatorId-maturityId-tokenType" */
103
+ solOpenOrdersBalances: Balances;
104
+ /** Individual open orders for the connected trader */
105
+ openOrders: OpenOrder[];
106
+ /** Per-market base (PT/RT) withdrawable balance keyed by marketPubkey */
107
+ perMarketBaseBalances: Record<string, number>;
108
+ /** User's native stake accounts */
109
+ userStakeAccounts: UserStakeAccount[];
110
+ userStakeAccountsLoading: boolean;
111
+ }
112
+ interface BalanceActions {
113
+ setWalletBalances: (updates: Balances) => void;
114
+ setExchangeBalances: (updates: Balances) => void;
115
+ setOpenOrdersBalances: (updates: Balances) => void;
116
+ setSolBalances: (updates: Balances) => void;
117
+ setSolOpenOrdersBalances: (updates: Balances) => void;
118
+ setOpenOrders: (orders: OpenOrder[]) => void;
119
+ setPerMarketBaseBalances: (balances: Record<string, number>) => void;
120
+ setUserStakeAccounts: (accounts: UserStakeAccount[]) => void;
121
+ setUserStakeAccountsLoading: (loading: boolean) => void;
122
+ resetBalances: () => void;
123
+ }
124
+ type BalanceStore = BalanceState & BalanceActions;
125
+ declare function createBalanceStore(): Omit<zustand_vanilla.StoreApi<BalanceStore>, "setState"> & {
126
+ setState(nextStateOrUpdater: BalanceStore | Partial<BalanceStore> | ((state: immer.WritableDraft<BalanceStore>) => void), shouldReplace?: false): void;
127
+ setState(nextStateOrUpdater: BalanceStore | ((state: immer.WritableDraft<BalanceStore>) => void), shouldReplace: true): void;
128
+ };
129
+
130
+ interface IndividualOrder {
131
+ sequenceNumber: string;
132
+ size: number;
133
+ price: number;
134
+ /** The Manifest market pubkey this order belongs to (set during market merge) */
135
+ marketPubkey?: string;
136
+ }
137
+ interface OrderBookSummary {
138
+ totalAskSize: number;
139
+ bestAskPrice: number | null;
140
+ totalBidSize: number;
141
+ bestBidPrice: number | null;
142
+ askCount: number;
143
+ bidCount: number;
144
+ asks: IndividualOrder[];
145
+ bids: IndividualOrder[];
146
+ }
147
+ /**
148
+ * Parse a Manifest market's raw account_data (hex) into an order book summary.
149
+ */
150
+ declare function parseOrderBook(marketPubkey: string, hexData: string): OrderBookSummary;
151
+
152
+ interface ManifestMarketRecord {
153
+ marketPubkey: string;
154
+ bondPubkey: string;
155
+ voteAccount: string;
156
+ tokenType: "PT" | "RT";
157
+ maturityTs: number;
158
+ totalAskSize: number;
159
+ bestAskPrice: number | null;
160
+ totalBidSize: number;
161
+ bestBidPrice: number | null;
162
+ askCount: number;
163
+ bidCount: number;
164
+ asks: IndividualOrder[];
165
+ bids: IndividualOrder[];
166
+ }
167
+ interface MatchedMarket {
168
+ marketPubkey: string;
169
+ bondPubkey: string;
170
+ validatorId: ValidatorId;
171
+ maturityId: MaturityId;
172
+ tokenType: "PT" | "RT";
173
+ totalAskSize: number;
174
+ bestAskPrice: number | null;
175
+ totalBidSize: number;
176
+ bestBidPrice: number | null;
177
+ askCount: number;
178
+ bidCount: number;
179
+ asks: IndividualOrder[];
180
+ bids: IndividualOrder[];
181
+ }
182
+ declare function fetchManifestMarkets(): Promise<MatchedMarket[]>;
183
+ /** Build a lookup keyed by "validatorId-maturityId-PT/RT".
184
+ * One market per key — first match wins (no merging across markets). */
185
+ declare function buildMarketLookup(markets: MatchedMarket[]): Record<string, MatchedMarket>;
186
+
187
+ interface MarketState {
188
+ /** Lookup keyed by "validatorId-maturityId-PT/RT" */
189
+ markets: Record<string, MatchedMarket>;
190
+ /** Reverse map: marketPubkey → store key */
191
+ pubkeyIndex: Record<string, string>;
192
+ /** RT backing per unit, keyed by bond pubkey */
193
+ rtBacking: Record<string, number>;
194
+ loading: boolean;
195
+ lastFetched: number | null;
196
+ }
197
+ interface MarketActions {
198
+ fetchMarkets: () => Promise<void>;
199
+ fetchRtBacking: () => Promise<void>;
200
+ getMarket: (validatorId: string, maturityId: string, tokenType: "PT" | "RT") => MatchedMarket | null;
201
+ updateMarketOrderBook: (marketPubkey: string, summary: OrderBookSummary) => void;
202
+ }
203
+ type MarketStore = MarketState & MarketActions;
204
+ declare function createMarketStore(): Omit<zustand_vanilla.StoreApi<MarketStore>, "setState"> & {
205
+ setState(nextStateOrUpdater: MarketStore | Partial<MarketStore> | ((state: immer.WritableDraft<MarketStore>) => void), shouldReplace?: false): void;
206
+ setState(nextStateOrUpdater: MarketStore | ((state: immer.WritableDraft<MarketStore>) => void), shouldReplace: true): void;
207
+ };
208
+
209
+ interface ApyState {
210
+ /** APY keyed by vote account address (as a decimal, e.g. 0.07 for 7%) */
211
+ apyByVoteAccount: Record<string, number>;
212
+ loading: boolean;
213
+ lastFetched: number | null;
214
+ }
215
+ interface ApyActions {
216
+ /** Fetch APY for specific vote accounts. Merges into existing data. */
217
+ fetchApyForVoteAccounts: (voteAccounts: string[], force?: boolean) => Promise<void>;
218
+ }
219
+ type ApyStore = ApyState & ApyActions;
220
+ declare function createApyStore(): Omit<zustand_vanilla.StoreApi<ApyStore>, "setState"> & {
221
+ setState(nextStateOrUpdater: ApyStore | Partial<ApyStore> | ((state: immer.WritableDraft<ApyStore>) => void), shouldReplace?: false): void;
222
+ setState(nextStateOrUpdater: ApyStore | ((state: immer.WritableDraft<ApyStore>) => void), shouldReplace: true): void;
223
+ };
224
+
225
+ export { ALLOWED_VALIDATORS as A, type BalanceActions as B, maturityIdsArray as C, parseOrderBook as D, validators as E, type IndividualOrder as I, type MaturityId as M, type OpenOrder as O, type StakeAccountState as S, type UserStakeAccount as U, type ValidatorId as V, type WalletActions as W, type MatchedMarket as a, type Maturity as b, type ApyActions as c, type ApyState as d, type ApyStore as e, type BalanceState as f, type BalanceStore as g, type Balances as h, type ManifestMarketRecord as i, type MarketActions as j, type MarketState as k, type MarketStore as l, type OrderBookSummary as m, type Validator as n, type WalletState as o, type WalletStatus as p, type WalletStore as q, buildMarketLookup as r, createApyStore as s, createBalanceStore as t, createMarketStore as u, createWalletStore as v, fetchManifestMarkets as w, getMaturity as x, maturities as y, maturitiesArray as z };