@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 +21 -0
- package/README.md +81 -0
- package/dist/apy-store-CNq9A4Xc.d.ts +225 -0
- package/dist/chunk-5XHGVQ3Z.js +3626 -0
- package/dist/chunk-5XHGVQ3Z.js.map +1 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +1340 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +53 -0
- package/dist/react.js +415 -0
- package/dist/react.js.map +1 -0
- package/package.json +87 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { V as ValidatorId, M as MaturityId, U as UserStakeAccount, O as OpenOrder, a as MatchedMarket, I as IndividualOrder, b as Maturity } from './apy-store-CNq9A4Xc.js';
|
|
2
|
+
export { A as ALLOWED_VALIDATORS, c as ApyActions, d as ApyState, e as ApyStore, B as BalanceActions, f as BalanceState, g as BalanceStore, h as Balances, i as ManifestMarketRecord, j as MarketActions, k as MarketState, l as MarketStore, m as OrderBookSummary, S as StakeAccountState, n as Validator, W as WalletActions, o as WalletState, p as WalletStatus, q as WalletStore, r as buildMarketLookup, s as createApyStore, t as createBalanceStore, u as createMarketStore, v as createWalletStore, w as fetchManifestMarkets, x as getMaturity, y as maturities, z as maturitiesArray, C as maturityIdsArray, D as parseOrderBook, E as validators } from './apy-store-CNq9A4Xc.js';
|
|
3
|
+
import { PublicKey, Connection } from '@solana/web3.js';
|
|
4
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
5
|
+
import { WalletContextState } from '@solana/wallet-adapter-react';
|
|
6
|
+
import 'immer';
|
|
7
|
+
import 'zustand/vanilla';
|
|
8
|
+
import '@solana/kit';
|
|
9
|
+
|
|
10
|
+
interface PyeSDKConfig {
|
|
11
|
+
rpcUrl: string;
|
|
12
|
+
supabaseUrl: string;
|
|
13
|
+
supabaseAnonKey: string;
|
|
14
|
+
/** If set, only detect stake accounts delegated to this vote account */
|
|
15
|
+
voteAccount?: string;
|
|
16
|
+
}
|
|
17
|
+
declare function configurePyeSDK(config: PyeSDKConfig): void;
|
|
18
|
+
declare function getPyeConfig(): PyeSDKConfig;
|
|
19
|
+
|
|
20
|
+
interface Bond {
|
|
21
|
+
pubkey: string;
|
|
22
|
+
pt_address: string;
|
|
23
|
+
rt_address: string;
|
|
24
|
+
}
|
|
25
|
+
interface Bond {
|
|
26
|
+
pubkey: string;
|
|
27
|
+
pt_address: string;
|
|
28
|
+
rt_address: string;
|
|
29
|
+
}
|
|
30
|
+
declare const lockups: Partial<Record<ValidatorId, Partial<Record<MaturityId, Bond>>>>;
|
|
31
|
+
declare function allowedLockups(): Partial<Record<ValidatorId, Partial<Record<MaturityId, Bond>>>>;
|
|
32
|
+
/** Look up a bond by the stake account's validator vote account and maturity. */
|
|
33
|
+
declare function lookupBondByVoteAccount(voteAccount: string, maturityId: MaturityId): (Bond & {
|
|
34
|
+
validatorId: ValidatorId;
|
|
35
|
+
}) | null;
|
|
36
|
+
interface PtLookupEntry {
|
|
37
|
+
validatorId: ValidatorId;
|
|
38
|
+
maturityId: MaturityId;
|
|
39
|
+
bond: Bond;
|
|
40
|
+
}
|
|
41
|
+
/** Reverse-lookup map: PT mint address → { validatorId, maturityId, bond }. */
|
|
42
|
+
declare function buildPtLookup(): Map<string, PtLookupEntry>;
|
|
43
|
+
|
|
44
|
+
interface Token {
|
|
45
|
+
name: string;
|
|
46
|
+
symbol: string;
|
|
47
|
+
coingecko_id: string;
|
|
48
|
+
icon: string;
|
|
49
|
+
address: string;
|
|
50
|
+
}
|
|
51
|
+
type TokenId = "solana";
|
|
52
|
+
declare const tokens: {
|
|
53
|
+
[key in TokenId]: Token;
|
|
54
|
+
};
|
|
55
|
+
declare const tokenIdsArray: TokenId[];
|
|
56
|
+
declare function allTokenAddresses(): string[];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Pye protocol taker fee charged on RT sales, expressed in basis points.
|
|
60
|
+
* 50 bps = 0.50%. Applied to the SOL out of the Manifest swap.
|
|
61
|
+
*/
|
|
62
|
+
declare const PYE_TRADING_FEE_BPS = 50;
|
|
63
|
+
/**
|
|
64
|
+
* Destination for taker-fee proceeds. Fees are transferred as wSOL to the
|
|
65
|
+
* treasury's wSOL ATA; the treasury unwraps out-of-band.
|
|
66
|
+
*/
|
|
67
|
+
declare const PYE_TREASURY_WALLET: PublicKey;
|
|
68
|
+
/** Gross SOL out × feeBps/10_000, rounded to integer lamports. */
|
|
69
|
+
declare function calculateFeeLamports(expectedSolOut: number): bigint;
|
|
70
|
+
/** Apply fee deduction to a gross SOL quote to get the user-facing net. */
|
|
71
|
+
declare function applyTradingFee(grossSolOut: number): number;
|
|
72
|
+
|
|
73
|
+
declare function fetchUserStakeAccounts(connection: Connection, owner: PublicKey): Promise<UserStakeAccount[]>;
|
|
74
|
+
|
|
75
|
+
declare function fetchBalances(connection: Connection, owner: PublicKey): Promise<Record<string, number>>;
|
|
76
|
+
declare function fetchBalancesForMints(connection: Connection, owner: PublicKey, mints: string[]): Promise<Record<string, number>>;
|
|
77
|
+
|
|
78
|
+
interface ExchangeBalancesResult {
|
|
79
|
+
exchangeBalances: Record<string, number>;
|
|
80
|
+
openOrdersBalances: Record<string, number>;
|
|
81
|
+
solBalances: Record<string, number>;
|
|
82
|
+
solOpenOrdersBalances: Record<string, number>;
|
|
83
|
+
openOrders: OpenOrder[];
|
|
84
|
+
perMarketBaseBalances: Record<string, number>;
|
|
85
|
+
}
|
|
86
|
+
declare function fetchExchangeBalances(connection: Connection, owner: PublicKey, markets: MatchedMarket[]): Promise<ExchangeBalancesResult>;
|
|
87
|
+
|
|
88
|
+
interface BondPayment {
|
|
89
|
+
epoch: number;
|
|
90
|
+
amount: number;
|
|
91
|
+
}
|
|
92
|
+
interface RewardBreakdown {
|
|
93
|
+
epoch: number;
|
|
94
|
+
staking: number;
|
|
95
|
+
mev: number;
|
|
96
|
+
block: number;
|
|
97
|
+
}
|
|
98
|
+
interface TvlSnapshot {
|
|
99
|
+
date: string;
|
|
100
|
+
sol: number;
|
|
101
|
+
}
|
|
102
|
+
interface LockupMetrics {
|
|
103
|
+
depositCap: string;
|
|
104
|
+
depositCapSol: number;
|
|
105
|
+
tvl: string;
|
|
106
|
+
tvlSol: number;
|
|
107
|
+
totalRewards: string;
|
|
108
|
+
apy90d: string | null;
|
|
109
|
+
inflationRewards: string;
|
|
110
|
+
mevRewards: string;
|
|
111
|
+
blockRewards: string;
|
|
112
|
+
payments: BondPayment[];
|
|
113
|
+
rewardBreakdown: RewardBreakdown[];
|
|
114
|
+
tvlHistory: TvlSnapshot[];
|
|
115
|
+
hasChartData: boolean;
|
|
116
|
+
fetchedAt: number;
|
|
117
|
+
}
|
|
118
|
+
declare function fetchLockupMetrics(bondPubkey: string, opts?: {
|
|
119
|
+
includeChartData?: boolean;
|
|
120
|
+
supabaseClient?: SupabaseClient;
|
|
121
|
+
}): Promise<LockupMetrics>;
|
|
122
|
+
|
|
123
|
+
interface LiquidityCheck {
|
|
124
|
+
expectedFillPrice: number | null;
|
|
125
|
+
slippageBps: number;
|
|
126
|
+
totalAvailableSize: number;
|
|
127
|
+
isSufficientLiquidity: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Walk asks (sorted price ascending) to check buy-side liquidity.
|
|
131
|
+
* Returns weighted avg fill price and slippage vs best ask.
|
|
132
|
+
*/
|
|
133
|
+
declare function checkBuyLiquidity(asks: IndividualOrder[], orderSizeTokens: number): LiquidityCheck;
|
|
134
|
+
/**
|
|
135
|
+
* Walk bids (sorted price descending) to check sell-side liquidity.
|
|
136
|
+
* Returns weighted avg fill price and slippage vs best bid.
|
|
137
|
+
*/
|
|
138
|
+
declare function checkSellLiquidity(bids: IndividualOrder[], orderSizeTokens: number): LiquidityCheck;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns a UNIX-seconds "now" adjusted so that it aligns with the cluster's
|
|
142
|
+
* perceived epoch-start boundary. The Bonds program mints RT proportional to
|
|
143
|
+
* the remaining time window of the selected maturity; using a clock derived
|
|
144
|
+
* from `getEpochInfo().slotIndex` matches the on-chain program's view of time
|
|
145
|
+
* more closely than `Date.now()` on its own.
|
|
146
|
+
*
|
|
147
|
+
* Port of the `estNextEpochTs` calculation in pye-frontend-v2's
|
|
148
|
+
* `StakeAccountMigrateForm.tsx`.
|
|
149
|
+
*/
|
|
150
|
+
declare function fetchEpochSyncedNowTs(connection: Connection): Promise<number>;
|
|
151
|
+
interface EstimateRtFromStakeParams {
|
|
152
|
+
/** Amount of SOL being deposited into the bond. */
|
|
153
|
+
amountSol: number;
|
|
154
|
+
/** Target maturity the deposit will issue into. */
|
|
155
|
+
maturity: Maturity;
|
|
156
|
+
/** UNIX seconds; should come from `fetchEpochSyncedNowTs` for best accuracy. */
|
|
157
|
+
nowTs: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Estimates how many RT tokens the Bonds program will mint to the user for a
|
|
161
|
+
* stake deposit of `amountSol` into the selected maturity.
|
|
162
|
+
*
|
|
163
|
+
* The Bonds program issues RT proportional to the remaining issuance window
|
|
164
|
+
* (RT represents claims on future rewards, so later depositors get less RT
|
|
165
|
+
* per SOL than earlier ones).
|
|
166
|
+
*
|
|
167
|
+
* estimatedRt = amountSol * (maturityTs - nowTs) / (maturityTs - issuanceStartTs)
|
|
168
|
+
*
|
|
169
|
+
* Returns 0 if the maturity has already matured or the issuance window is
|
|
170
|
+
* invalid.
|
|
171
|
+
*/
|
|
172
|
+
declare function estimateRtFromStake({ amountSol, maturity, nowTs, }: EstimateRtFromStakeParams): number;
|
|
173
|
+
|
|
174
|
+
interface ExecuteStakeDepositParams {
|
|
175
|
+
connection: Connection;
|
|
176
|
+
wallet: WalletContextState;
|
|
177
|
+
bondPubkey: string;
|
|
178
|
+
principalTokenMint: string;
|
|
179
|
+
yieldTokenMint: string;
|
|
180
|
+
validatorVoteAccount: string;
|
|
181
|
+
amountSol: number;
|
|
182
|
+
}
|
|
183
|
+
interface ExecuteStakeDepositResult {
|
|
184
|
+
signature: string;
|
|
185
|
+
}
|
|
186
|
+
interface ExecuteStakeAccountDepositParams {
|
|
187
|
+
connection: Connection;
|
|
188
|
+
wallet: WalletContextState;
|
|
189
|
+
bondPubkey: string;
|
|
190
|
+
principalTokenMint: string;
|
|
191
|
+
yieldTokenMint: string;
|
|
192
|
+
validatorVoteAccount: string;
|
|
193
|
+
stakeAccountPubkey: string;
|
|
194
|
+
amountSol: number;
|
|
195
|
+
stakeBalanceSol: number;
|
|
196
|
+
}
|
|
197
|
+
declare function executeStakeAccountDeposit({ connection, wallet, bondPubkey, principalTokenMint, yieldTokenMint, validatorVoteAccount, stakeAccountPubkey, amountSol, stakeBalanceSol, }: ExecuteStakeAccountDepositParams): Promise<ExecuteStakeDepositResult>;
|
|
198
|
+
declare function executeStakeDeposit({ connection, wallet, bondPubkey, principalTokenMint, yieldTokenMint, validatorVoteAccount, amountSol, }: ExecuteStakeDepositParams): Promise<ExecuteStakeDepositResult>;
|
|
199
|
+
|
|
200
|
+
interface ExecuteDepositAndSellParams {
|
|
201
|
+
connection: Connection;
|
|
202
|
+
wallet: WalletContextState;
|
|
203
|
+
bondPubkey: string;
|
|
204
|
+
principalTokenMint: string;
|
|
205
|
+
yieldTokenMint: string;
|
|
206
|
+
validatorVoteAccount: string;
|
|
207
|
+
stakeAccountPubkey: string;
|
|
208
|
+
amountSol: number;
|
|
209
|
+
stakeBalanceSol: number;
|
|
210
|
+
marketPubkey: string;
|
|
211
|
+
/**
|
|
212
|
+
* Expected RT tokens the Bonds program will mint to the user for this
|
|
213
|
+
* deposit. The Bonds program mints RT proportional to remaining time in the
|
|
214
|
+
* issuance window, so this is always ≤ amountSol — compute with
|
|
215
|
+
* `estimateRtFromStake` using an epoch-synced `nowTs`.
|
|
216
|
+
*/
|
|
217
|
+
rtAmountToSell: number;
|
|
218
|
+
minReceiveTokens: number;
|
|
219
|
+
/** Gross SOL out (pre-fee) used to size the Pye taker-fee transfer. */
|
|
220
|
+
expectedSolOut: number;
|
|
221
|
+
altPubkey: string;
|
|
222
|
+
}
|
|
223
|
+
interface ExecuteDepositAndSellResult {
|
|
224
|
+
signature: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Deposits a stake account into the Pye lockup and immediately sells the
|
|
228
|
+
* resulting RT tokens on Manifest — all in a single atomic transaction.
|
|
229
|
+
*
|
|
230
|
+
* Instruction order:
|
|
231
|
+
* 1. ComputeBudget (limit + price)
|
|
232
|
+
* 2. StakeProgram.split (only if partial deposit)
|
|
233
|
+
* 3. createATA: ownerPt, ownerYt (RT), feeWalletPt, feeWalletYt, wSOL, treasuryWsol
|
|
234
|
+
* 4. Bonds deposit → mints PT + RT into ownerPt / ownerYt
|
|
235
|
+
* 5. Manifest swapIx → sells RT for wSOL
|
|
236
|
+
* 6. transfer → Pye taker fee (wSOL) from owner's wsolAta to treasuryWsol
|
|
237
|
+
* 7. closeAccount → unwraps remaining wSOL to native SOL
|
|
238
|
+
*/
|
|
239
|
+
declare function executeDepositAndSell({ connection, wallet, bondPubkey, principalTokenMint, yieldTokenMint, validatorVoteAccount, stakeAccountPubkey, amountSol, stakeBalanceSol, marketPubkey, rtAmountToSell, minReceiveTokens, expectedSolOut, altPubkey, }: ExecuteDepositAndSellParams): Promise<ExecuteDepositAndSellResult>;
|
|
240
|
+
|
|
241
|
+
interface ExecuteSwapParams {
|
|
242
|
+
connection: Connection;
|
|
243
|
+
wallet: WalletContextState;
|
|
244
|
+
marketPubkey: string;
|
|
245
|
+
orderSizeTokens: number;
|
|
246
|
+
maxPayTokens: number;
|
|
247
|
+
slippageBps: number;
|
|
248
|
+
}
|
|
249
|
+
interface ExecuteSwapResult {
|
|
250
|
+
signature: string;
|
|
251
|
+
}
|
|
252
|
+
declare function executeSwap({ connection, wallet, marketPubkey, orderSizeTokens, maxPayTokens, slippageBps, }: ExecuteSwapParams): Promise<ExecuteSwapResult>;
|
|
253
|
+
|
|
254
|
+
interface ExecuteRtSellParams {
|
|
255
|
+
connection: Connection;
|
|
256
|
+
wallet: WalletContextState;
|
|
257
|
+
marketPubkey: string;
|
|
258
|
+
rtMint: string;
|
|
259
|
+
/**
|
|
260
|
+
* Amount of RT tokens to sell. This must match what the user actually holds
|
|
261
|
+
* in their RT ATA — for a fresh deposit, compute with `estimateRtFromStake`,
|
|
262
|
+
* not `amountSol`, since the Bonds program mints less than 1:1.
|
|
263
|
+
*/
|
|
264
|
+
orderSizeTokens: number;
|
|
265
|
+
minReceiveTokens: number;
|
|
266
|
+
/** Gross SOL out (pre-fee) used to size the Pye taker-fee transfer. */
|
|
267
|
+
expectedSolOut: number;
|
|
268
|
+
}
|
|
269
|
+
interface ExecuteRtSellResult {
|
|
270
|
+
signature: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Sell RT tokens on a Manifest order book for SOL.
|
|
274
|
+
*
|
|
275
|
+
* Flow: RT (base) → swap → wSOL (quote) → unwrap to native SOL.
|
|
276
|
+
*/
|
|
277
|
+
declare function executeRtSell({ connection, wallet, marketPubkey, rtMint, orderSizeTokens, minReceiveTokens, expectedSolOut, }: ExecuteRtSellParams): Promise<ExecuteRtSellResult>;
|
|
278
|
+
|
|
279
|
+
interface ExecuteLimitOrderParams {
|
|
280
|
+
connection: Connection;
|
|
281
|
+
wallet: WalletContextState;
|
|
282
|
+
marketPubkey: string;
|
|
283
|
+
orderSizeTokens: number;
|
|
284
|
+
limitPrice: number;
|
|
285
|
+
}
|
|
286
|
+
interface ExecuteLimitOrderResult {
|
|
287
|
+
signature: string;
|
|
288
|
+
setupSignature?: string;
|
|
289
|
+
}
|
|
290
|
+
declare function executeLimitOrder({ connection, wallet, marketPubkey, orderSizeTokens, limitPrice, }: ExecuteLimitOrderParams): Promise<ExecuteLimitOrderResult>;
|
|
291
|
+
|
|
292
|
+
interface ExecuteCancelOrderParams {
|
|
293
|
+
connection: Connection;
|
|
294
|
+
wallet: WalletContextState;
|
|
295
|
+
marketPubkey: string;
|
|
296
|
+
sequenceNumber: string;
|
|
297
|
+
}
|
|
298
|
+
interface ExecuteCancelOrderResult {
|
|
299
|
+
signature: string;
|
|
300
|
+
}
|
|
301
|
+
declare function executeCancelOrder({ connection, wallet, marketPubkey, sequenceNumber, }: ExecuteCancelOrderParams): Promise<ExecuteCancelOrderResult>;
|
|
302
|
+
|
|
303
|
+
interface ExecuteRedeemParams {
|
|
304
|
+
connection: Connection;
|
|
305
|
+
wallet: WalletContextState;
|
|
306
|
+
bondPubkey: string;
|
|
307
|
+
principalTokenMint: string;
|
|
308
|
+
yieldTokenMint: string;
|
|
309
|
+
ptAmountLamports: number;
|
|
310
|
+
rtAmountLamports: number;
|
|
311
|
+
}
|
|
312
|
+
interface ExecuteRedeemResult {
|
|
313
|
+
signature: string;
|
|
314
|
+
}
|
|
315
|
+
declare function executeRedeem({ connection, wallet, bondPubkey, principalTokenMint, yieldTokenMint, ptAmountLamports, rtAmountLamports, }: ExecuteRedeemParams): Promise<ExecuteRedeemResult>;
|
|
316
|
+
|
|
317
|
+
export { type Bond, type BondPayment, type EstimateRtFromStakeParams, type ExchangeBalancesResult, type ExecuteCancelOrderParams, type ExecuteCancelOrderResult, type ExecuteDepositAndSellParams, type ExecuteDepositAndSellResult, type ExecuteLimitOrderParams, type ExecuteLimitOrderResult, type ExecuteRedeemParams, type ExecuteRedeemResult, type ExecuteRtSellParams, type ExecuteRtSellResult, type ExecuteStakeAccountDepositParams, type ExecuteStakeDepositParams, type ExecuteStakeDepositResult, type ExecuteSwapParams, type ExecuteSwapResult, IndividualOrder, type LiquidityCheck, type LockupMetrics, MatchedMarket, Maturity, MaturityId, OpenOrder, PYE_TRADING_FEE_BPS, PYE_TREASURY_WALLET, type PtLookupEntry, type PyeSDKConfig, type RewardBreakdown, type Token, type TokenId, type TvlSnapshot, UserStakeAccount, ValidatorId, allTokenAddresses, allowedLockups, applyTradingFee, buildPtLookup, calculateFeeLamports, checkBuyLiquidity, checkSellLiquidity, configurePyeSDK, estimateRtFromStake, executeCancelOrder, executeDepositAndSell, executeLimitOrder, executeRedeem, executeRtSell, executeStakeAccountDeposit, executeStakeDeposit, executeSwap, fetchBalances, fetchBalancesForMints, fetchEpochSyncedNowTs, fetchExchangeBalances, fetchLockupMetrics, fetchUserStakeAccounts, getPyeConfig, lockups, lookupBondByVoteAccount, tokenIdsArray, tokens };
|