@pyefi/sdk 0.1.3 → 0.1.5

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
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
1
  import { PublicKey, Connection } from '@solana/web3.js';
2
+ import { U as UserStakeAccount, B as Balances, O as OpenOrder, M as MatchedMarket, I as IndividualOrder, V as ValidatorRow, a as BondRow } from './validator-store-CirN3_Ac.js';
3
+ export { A as ApyActions, b as ApyState, c as ApyStore, d as BalanceActions, e as BalanceState, f as BalanceStore, C as CanonicalMaturity, L as LockupActions, g as LockupState, h as LockupStore, i as ManifestMarketRecord, j as MarketActions, k as MarketState, l as MarketStore, m as OrderBookSummary, S as StakeAccountState, n as ValidatorActions, o as ValidatorState, p as ValidatorStore, W as WalletActions, q as WalletState, r as WalletStatus, s as WalletStore, t as buildMarketLookup, u as createApyStore, v as createBalanceStore, w as createLockupStore, x as createMarketStore, y as createValidatorStore, z as createWalletStore, D as fetchManifestMarkets, E as parseOrderBook, F as selectBond, G as selectBondsForValidator, H as selectWidgetValidator, J as selectWidgetValidators } from './validator-store-CirN3_Ac.js';
4
4
  import { SupabaseClient } from '@supabase/supabase-js';
5
5
  import { WalletContextState } from '@solana/wallet-adapter-react';
6
6
  import 'immer';
@@ -17,6 +17,46 @@ interface PyeSDKConfig {
17
17
  declare function configurePyeSDK(config: PyeSDKConfig): void;
18
18
  declare function getPyeConfig(): PyeSDKConfig;
19
19
 
20
+ interface Validator {
21
+ name: string;
22
+ symbol: string;
23
+ vote_account: string;
24
+ pt_sol: string;
25
+ rt_sol: string;
26
+ is_allowed: boolean;
27
+ type: "validator" | "lst";
28
+ }
29
+ 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";
30
+ declare const validators: {
31
+ [key in ValidatorId]: Validator;
32
+ };
33
+ declare const ALLOWED_VALIDATORS: {
34
+ name: string;
35
+ symbol: string;
36
+ vote_account: string;
37
+ pt_sol: string;
38
+ rt_sol: string;
39
+ is_allowed: boolean;
40
+ type: "validator" | "lst";
41
+ id: ValidatorId;
42
+ }[];
43
+
44
+ interface Maturity {
45
+ human_readable: string;
46
+ month: string;
47
+ year: string;
48
+ issuance_start_timestamp: string;
49
+ issuance_close_timestamp: string;
50
+ maturity_timestamp: string;
51
+ }
52
+ type MaturityId = "q12026" | "q22026" | "q32026" | "q42026";
53
+ declare const maturities: {
54
+ [key in MaturityId]: Maturity;
55
+ };
56
+ declare const maturitiesArray: Maturity[];
57
+ declare const maturityIdsArray: MaturityId[];
58
+ declare const getMaturity: (maturityId: MaturityId) => Maturity;
59
+
20
60
  interface Bond {
21
61
  pubkey: string;
22
62
  pt_address: string;
@@ -75,6 +115,9 @@ declare function fetchUserStakeAccounts(connection: Connection, owner: PublicKey
75
115
  declare function fetchBalances(connection: Connection, owner: PublicKey): Promise<Record<string, number>>;
76
116
  declare function fetchBalancesForMints(connection: Connection, owner: PublicKey, mints: string[]): Promise<Record<string, number>>;
77
117
 
118
+ declare function readCachedWalletBalances(publicKey: string): Balances | null;
119
+ declare function writeCachedWalletBalances(publicKey: string, balances: Balances): void;
120
+
78
121
  interface ExchangeBalancesResult {
79
122
  exchangeBalances: Record<string, number>;
80
123
  openOrdersBalances: Record<string, number>;
@@ -137,6 +180,48 @@ declare function checkBuyLiquidity(asks: IndividualOrder[], orderSizeTokens: num
137
180
  */
138
181
  declare function checkSellLiquidity(bids: IndividualOrder[], orderSizeTokens: number): LiquidityCheck;
139
182
 
183
+ /**
184
+ * Stable error codes for Sell-Yield gating. Surface these in support messages
185
+ * and telemetry. Format: PYE-<DOMAIN>-<CONDITION>.
186
+ */
187
+ declare const SELL_YIELD_CODES: {
188
+ readonly VALIDATOR_NOT_CONFIGURED: "PYE-VALIDATOR-NOT-CONFIGURED";
189
+ readonly VALIDATOR_WIDGET_DISABLED: "PYE-VALIDATOR-WIDGET-DISABLED";
190
+ readonly VALIDATOR_ALT_MISSING: "PYE-VALIDATOR-ALT-MISSING";
191
+ readonly BOND_MISSING: "PYE-BOND-MISSING";
192
+ readonly BOND_NOT_STANDARD: "PYE-BOND-NOT-STANDARD";
193
+ readonly MARKET_MISSING: "PYE-MARKET-MISSING";
194
+ readonly LIQUIDITY_INSUFFICIENT: "PYE-LIQUIDITY-INSUFFICIENT";
195
+ };
196
+ type SellYieldCode = (typeof SELL_YIELD_CODES)[keyof typeof SELL_YIELD_CODES];
197
+ type SellYieldStatus = {
198
+ ok: true;
199
+ } | {
200
+ ok: false;
201
+ code: SellYieldCode;
202
+ reason: string;
203
+ };
204
+ interface CanSellYieldParams {
205
+ validatorVoteAccount: string;
206
+ maturityId: MaturityId;
207
+ amountSol: number;
208
+ nowTs: number;
209
+ validators: Record<string, ValidatorRow>;
210
+ bonds: Record<string, BondRow>;
211
+ markets: Record<string, MatchedMarket>;
212
+ }
213
+ /**
214
+ * Single source of truth for "can the user sell yield on this (stake, maturity)?".
215
+ * Returns the first failure reason in priority order (validator → bond → market →
216
+ * liquidity) so the caller can show one clear message rather than a stack of them.
217
+ */
218
+ declare function canSellYield(params: CanSellYieldParams): SellYieldStatus;
219
+ /**
220
+ * Lighter check used by screens that only know the validator (Welcome, Select
221
+ * Position). Catches cases 1 + 2 from the gating audit.
222
+ */
223
+ declare function validatorAvailability(voteAccount: string, validators: Record<string, ValidatorRow>): SellYieldStatus;
224
+
140
225
  /**
141
226
  * Returns a UNIX-seconds "now" adjusted so that it aligns with the cluster's
142
227
  * perceived epoch-start boundary. The Bonds program mints RT proportional to
@@ -314,4 +399,4 @@ interface ExecuteRedeemResult {
314
399
  }
315
400
  declare function executeRedeem({ connection, wallet, bondPubkey, principalTokenMint, yieldTokenMint, ptAmountLamports, rtAmountLamports, }: ExecuteRedeemParams): Promise<ExecuteRedeemResult>;
316
401
 
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 };
402
+ export { ALLOWED_VALIDATORS, Balances, type Bond, type BondPayment, BondRow, type CanSellYieldParams, 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, type Maturity, type MaturityId, OpenOrder, PYE_TRADING_FEE_BPS, PYE_TREASURY_WALLET, type PtLookupEntry, type PyeSDKConfig, type RewardBreakdown, SELL_YIELD_CODES, type SellYieldCode, type SellYieldStatus, type Token, type TokenId, type TvlSnapshot, UserStakeAccount, type Validator, type ValidatorId, ValidatorRow, allTokenAddresses, allowedLockups, applyTradingFee, buildPtLookup, calculateFeeLamports, canSellYield, checkBuyLiquidity, checkSellLiquidity, configurePyeSDK, estimateRtFromStake, executeCancelOrder, executeDepositAndSell, executeLimitOrder, executeRedeem, executeRtSell, executeStakeAccountDeposit, executeStakeDeposit, executeSwap, fetchBalances, fetchBalancesForMints, fetchEpochSyncedNowTs, fetchExchangeBalances, fetchLockupMetrics, fetchUserStakeAccounts, getMaturity, getPyeConfig, lockups, lookupBondByVoteAccount, maturities, maturitiesArray, maturityIdsArray, readCachedWalletBalances, tokenIdsArray, tokens, validatorAvailability, validators, writeCachedWalletBalances };
package/dist/index.js CHANGED
@@ -8,7 +8,9 @@ import {
8
8
  configurePyeSDK,
9
9
  createApyStore,
10
10
  createBalanceStore,
11
+ createLockupStore,
11
12
  createMarketStore,
13
+ createValidatorStore,
12
14
  createWalletStore,
13
15
  fetchBalances,
14
16
  fetchBalancesForMints,
@@ -23,10 +25,16 @@ import {
23
25
  maturitiesArray,
24
26
  maturityIdsArray,
25
27
  parseOrderBook,
28
+ readCachedWalletBalances,
29
+ selectBond,
30
+ selectBondsForValidator,
31
+ selectWidgetValidator,
32
+ selectWidgetValidators,
26
33
  tokenIdsArray,
27
34
  tokens,
28
- validators
29
- } from "./chunk-2NO7PNVV.js";
35
+ validators,
36
+ writeCachedWalletBalances
37
+ } from "./chunk-GXXXUTDQ.js";
30
38
 
31
39
  // src/constants/fees.ts
32
40
  import { PublicKey } from "@solana/web3.js";
@@ -242,6 +250,98 @@ function estimateRtFromStake({
242
250
  return amountSol * (remaining / total);
243
251
  }
244
252
 
253
+ // src/lib/can-sell-yield.ts
254
+ var SELL_YIELD_CODES = {
255
+ VALIDATOR_NOT_CONFIGURED: "PYE-VALIDATOR-NOT-CONFIGURED",
256
+ VALIDATOR_WIDGET_DISABLED: "PYE-VALIDATOR-WIDGET-DISABLED",
257
+ VALIDATOR_ALT_MISSING: "PYE-VALIDATOR-ALT-MISSING",
258
+ BOND_MISSING: "PYE-BOND-MISSING",
259
+ BOND_NOT_STANDARD: "PYE-BOND-NOT-STANDARD",
260
+ MARKET_MISSING: "PYE-MARKET-MISSING",
261
+ LIQUIDITY_INSUFFICIENT: "PYE-LIQUIDITY-INSUFFICIENT"
262
+ };
263
+ function canSellYield(params) {
264
+ var _a;
265
+ const validator = params.validators[params.validatorVoteAccount];
266
+ if (!validator) {
267
+ return {
268
+ ok: false,
269
+ code: SELL_YIELD_CODES.VALIDATOR_NOT_CONFIGURED,
270
+ reason: "This validator isn't configured in Pye's metadata yet."
271
+ };
272
+ }
273
+ if (validator.widget !== true) {
274
+ return {
275
+ ok: false,
276
+ code: SELL_YIELD_CODES.VALIDATOR_WIDGET_DISABLED,
277
+ reason: "Sell Yield isn't enabled for this validator yet."
278
+ };
279
+ }
280
+ if (!validator.alt_pubkey) {
281
+ return {
282
+ ok: false,
283
+ code: SELL_YIELD_CODES.VALIDATOR_ALT_MISSING,
284
+ reason: "Setup pending \u2014 Pye hasn't deployed an Address Lookup Table for this validator yet."
285
+ };
286
+ }
287
+ const bond = params.bonds[`${params.validatorVoteAccount}:${params.maturityId}`];
288
+ if (!bond) {
289
+ return {
290
+ ok: false,
291
+ code: SELL_YIELD_CODES.BOND_MISSING,
292
+ reason: "No bond exists for this validator at this maturity yet."
293
+ };
294
+ }
295
+ if (bond.standard !== true) {
296
+ return {
297
+ ok: false,
298
+ code: SELL_YIELD_CODES.BOND_NOT_STANDARD,
299
+ reason: "Setup pending \u2014 this maturity's bond hasn't been promoted to standard yet."
300
+ };
301
+ }
302
+ const market = params.markets[`${params.validatorVoteAccount}-${params.maturityId}-RT`];
303
+ if (!market) {
304
+ return {
305
+ ok: false,
306
+ code: SELL_YIELD_CODES.MARKET_MISSING,
307
+ reason: "No RT market exists for this validator at this maturity yet."
308
+ };
309
+ }
310
+ const maturity = maturities[params.maturityId];
311
+ const estimatedRt = estimateRtFromStake({
312
+ amountSol: params.amountSol,
313
+ maturity,
314
+ nowTs: params.nowTs
315
+ });
316
+ const liquidity = ((_a = market.bids) == null ? void 0 : _a.length) ? checkSellLiquidity(market.bids, estimatedRt) : null;
317
+ if (!(liquidity == null ? void 0 : liquidity.isSufficientLiquidity)) {
318
+ return {
319
+ ok: false,
320
+ code: SELL_YIELD_CODES.LIQUIDITY_INSUFFICIENT,
321
+ reason: "The order book doesn't have enough bids to fill this amount yet."
322
+ };
323
+ }
324
+ return { ok: true };
325
+ }
326
+ function validatorAvailability(voteAccount, validators2) {
327
+ const v = validators2[voteAccount];
328
+ if (!v) {
329
+ return {
330
+ ok: false,
331
+ code: SELL_YIELD_CODES.VALIDATOR_NOT_CONFIGURED,
332
+ reason: "This validator isn't configured in Pye's metadata yet."
333
+ };
334
+ }
335
+ if (v.widget !== true) {
336
+ return {
337
+ ok: false,
338
+ code: SELL_YIELD_CODES.VALIDATOR_WIDGET_DISABLED,
339
+ reason: "Sell Yield isn't enabled for this validator yet."
340
+ };
341
+ }
342
+ return { ok: true };
343
+ }
344
+
245
345
  // src/lib/execute-stake-deposit.ts
246
346
  import {
247
347
  ComputeBudgetProgram,
@@ -1296,18 +1396,22 @@ export {
1296
1396
  ALLOWED_VALIDATORS,
1297
1397
  PYE_TRADING_FEE_BPS,
1298
1398
  PYE_TREASURY_WALLET,
1399
+ SELL_YIELD_CODES,
1299
1400
  allTokenAddresses,
1300
1401
  allowedLockups,
1301
1402
  applyTradingFee,
1302
1403
  buildMarketLookup,
1303
1404
  buildPtLookup,
1304
1405
  calculateFeeLamports,
1406
+ canSellYield,
1305
1407
  checkBuyLiquidity,
1306
1408
  checkSellLiquidity,
1307
1409
  configurePyeSDK,
1308
1410
  createApyStore,
1309
1411
  createBalanceStore,
1412
+ createLockupStore,
1310
1413
  createMarketStore,
1414
+ createValidatorStore,
1311
1415
  createWalletStore,
1312
1416
  estimateRtFromStake,
1313
1417
  executeCancelOrder,
@@ -1333,8 +1437,15 @@ export {
1333
1437
  maturitiesArray,
1334
1438
  maturityIdsArray,
1335
1439
  parseOrderBook,
1440
+ readCachedWalletBalances,
1441
+ selectBond,
1442
+ selectBondsForValidator,
1443
+ selectWidgetValidator,
1444
+ selectWidgetValidators,
1336
1445
  tokenIdsArray,
1337
1446
  tokens,
1338
- validators
1447
+ validatorAvailability,
1448
+ validators,
1449
+ writeCachedWalletBalances
1339
1450
  };
1340
1451
  //# sourceMappingURL=index.js.map