@wireio/stake 0.2.3 → 0.2.4

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/lib/stake.d.ts CHANGED
@@ -31,7 +31,11 @@ interface IStakingClient {
31
31
  * - `TrancheSnapshot` when the chain supports pretoken/tranches
32
32
  * - `null` if this chain has no WIRE/pretoken integration
33
33
  */
34
- getTrancheSnapshot(): Promise<TrancheSnapshot | null>;
34
+ getTrancheSnapshot(options?: {
35
+ chainID?: ChainID;
36
+ windowBefore?: number;
37
+ windowAfter?: number;
38
+ }): Promise<TrancheSnapshot | null>;
35
39
  /** */
36
40
  getBuyQuote(amount: bigint, asset: PurchaseAsset): Promise<PurchaseQuote>;
37
41
  }
@@ -58,23 +62,53 @@ type BalanceView = {
58
62
  symbol: string;
59
63
  ata?: PublicKey$1;
60
64
  };
65
+ interface TrancheLadderItem {
66
+ /** On-chain tranche id, 0-based (0,1,2,...) */
67
+ id: number;
68
+ /** Total capacity for this tranche (pretokens, 1e8 scale) */
69
+ capacity: bigint;
70
+ /** Sold amount in this tranche (1e8 scale) */
71
+ sold: bigint;
72
+ /** Remaining = capacity - sold (1e8 scale) */
73
+ remaining: bigint;
74
+ /** Price for this tranche in USD (1e8 scale) */
75
+ priceUsd: bigint;
76
+ }
61
77
  /**
62
- * Program-global prelaunch WIRE / tranche state for a single chain.
63
- *
64
- * All integer values are raw on-chain integers:
65
- * - `currentTranchePriceUsd`: 1e8 USD
66
- * - supplies / warrants / shares: 1e8 WIRE units (per liqsol_core/ETH analog)
67
- * - index: same scale the program uses (INDEX_SCALE = 1e12 on Solana today)
78
+ * Unified pretoken/tranche snapshot for any chain.
79
+ * ETH / other chains just fill the same shape from their own contracts.
68
80
  */
69
81
  interface TrancheSnapshot {
70
82
  chainID: ChainID;
71
- totalShares: bigint;
83
+ /** Global share index (1e12 on Sol today; other chains can use their own scale) */
72
84
  currentIndex: bigint;
73
- currentTrancheNumber: bigint;
85
+ /** Total accounting shares (wire pretoken “shares”) */
86
+ totalShares: bigint;
87
+ /** Current tranche id as stored on chain (0-based) */
88
+ currentTranche: number;
89
+ /** Current tranche price in USD (1e8 scale) */
90
+ currentPriceUsd: bigint;
91
+ /** Optional min/max bounds for price validation (1e8 scale) */
92
+ minPriceUsd?: bigint;
93
+ maxPriceUsd?: bigint;
94
+ /** Tranche curve config (per-chain) */
95
+ supplyGrowthBps: number;
96
+ priceGrowthBps: number;
97
+ /** Current tranche supply state (1e8 scale) */
74
98
  currentTrancheSupply: bigint;
99
+ initialTrancheSupply: bigint;
75
100
  totalWarrantsSold: bigint;
76
- currentTranchePriceUsd: bigint;
101
+ /** Native token → USD price if available (SOL/USD, ETH/USD, etc, 1e8 scale) */
102
+ nativePriceUsd?: bigint;
103
+ /** Optional timestamp (sec) for the last recorded native price */
104
+ nativePriceTimestamp?: number;
105
+ /**
106
+ * Local window of tranche “rows” centered around current.
107
+ * Used directly by the frontend for ladder graphs.
108
+ */
109
+ ladder: TrancheLadderItem[];
77
110
  }
111
+ /** Purchase asset selection used by staking client(s) */
78
112
  declare enum PurchaseAsset {
79
113
  SOL = "SOL",
80
114
  LIQSOL = "LIQSOL",
@@ -85,8 +119,10 @@ declare enum PurchaseAsset {
85
119
  interface PurchaseQuote {
86
120
  purchaseAsset: PurchaseAsset;
87
121
  amountIn: bigint;
122
+ /** Expected pretoken “shares” (pretokens) and decimals */
88
123
  wireShares: bigint;
89
124
  wireDecimals: number;
125
+ /** Current price + notional in USD (1e8 scale) */
90
126
  wirePriceUsd: bigint;
91
127
  notionalUsd: bigint;
92
128
  }
@@ -581,6 +617,17 @@ declare namespace types {
581
617
  export type { types_CorrectRegisterBuildResult as CorrectRegisterBuildResult, types_CorrectRegisterPlan as CorrectRegisterPlan, types_DistributionState as DistributionState, types_GlobalState as GlobalState, types_MismatchCandidate as MismatchCandidate, types_OutpostWireStateSnapshot as OutpostWireStateSnapshot, types_ParsedAccountInfo as ParsedAccountInfo, types_PriceHistory as PriceHistory, types_SharesPreview as SharesPreview, types_SolanaTransaction as SolanaTransaction, types_TrancheState as TrancheState, types_UserRecord as UserRecord, types_UserWarrantRecord as UserWarrantRecord, types_WalletLike as WalletLike, types_WireReceipt as WireReceipt };
582
618
  }
583
619
 
620
+ /**
621
+ * Solana implementation of IStakingClient.
622
+ *
623
+ * Responsibilities:
624
+ * - Wire together liqSOL deposit/withdraw
625
+ * - Outpost stake/unstake
626
+ * - Prelaunch WIRE (pretokens) buy flows
627
+ * - Unified portfolio + tranche snapshot + buy quotes
628
+ *
629
+ * This class composes lower-level clients; it does not know about UI.
630
+ */
584
631
  declare class SolanaStakingClient implements IStakingClient {
585
632
  private config;
586
633
  pubKey: PublicKey;
@@ -595,77 +642,110 @@ declare class SolanaStakingClient implements IStakingClient {
595
642
  get network(): ExternalNetwork;
596
643
  constructor(config: StakerConfig);
597
644
  /**
598
- * Deposit SOL into liqSOL protocol (liqsol_core deposit flow).
599
- * @param amountLamports Amount of SOL to deposit (smallest unit)
600
- * @return Transaction signature
645
+ * Deposit native SOL into liqSOL (liqsol_core::deposit).
646
+ * Handles tx build, sign, send, and confirmation.
601
647
  */
602
648
  deposit(amountLamports: bigint): Promise<string>;
603
649
  /**
604
650
  * Withdraw SOL from liqSOL protocol.
605
- * (Wire up once you have DepositClient.buildWithdrawTx or equivalent.)
651
+ * NOTE: placeholder until a withdraw flow is implemented in DepositClient.
606
652
  */
607
- withdraw(amountLamports: bigint): Promise<string>;
653
+ withdraw(_amountLamports: bigint): Promise<string>;
608
654
  /**
609
655
  * Stake liqSOL into Outpost (liqSOL -> pool).
610
- * Matches deposit flow: build -> prepare -> sign -> send/confirm.
611
- * @param amountLamports Amount of liqSOL to stake (smallest unit)
656
+ * Ensures user ATA exists, then stakes via outpostClient.
612
657
  */
613
658
  stake(amountLamports: bigint): Promise<string>;
614
659
  /**
615
660
  * Unstake liqSOL from Outpost (pool -> liqSOL).
616
- * Matches deposit flow: build -> prepare -> sign -> send/confirm.
617
- * @param amountLamports Amount of liqSOL principal to unstake (smallest unit)
661
+ * Mirrors stake() but calls withdrawStake.
618
662
  */
619
663
  unstake(amountLamports: bigint): Promise<string>;
620
- /** Buy pretoken (warrants) using specified asset.
621
- * @param amount Amount in smallest units (lamports / wei / token units).
622
- * Required for SOL / LIQSOL / ETH / LIQETH.
623
- * Ignored for YIELD (the program uses tracked yield).
624
- * @param purchaseAsset Asset used to buy pretoken.
625
- * @returns Transaction signature
664
+ /**
665
+ * Buy prelaunch WIRE “pretokens” using a supported asset.
666
+ *
667
+ * - SOL: uses purchase_with_sol
668
+ * - LIQSOL: uses purchase_with_liqsol
669
+ * - YIELD: uses purchase_warrants_from_yield
670
+ *
671
+ * ETH / LIQETH are not valid on Solana.
626
672
  */
627
673
  buy(amountLamports: bigint, purchaseAsset: PurchaseAsset): Promise<string>;
628
674
  /**
629
- * native = SOL in wallet
630
- * liq = liqSOL token balance (from Token-2022 ATA)
631
- * staked = Outpost staked liqSOL principal (from wireReceipt.stakedLiqsol)
632
- * tracked = liqSOL tracked balance (from Distribution.userRecord)
633
- * wire = prelaunch WIRE “shares” (UserWarrantRecord.totalWarrantsPurchased, 1e8)
675
+ * Aggregate view of the user’s balances on Solana:
676
+ * - native: SOL wallet balance
677
+ * - liq: liqSOL token balance (Token-2022 ATA)
678
+ * - staked: Outpost-staked liqSOL principal
679
+ * - tracked: distribution program trackedBalance (liqSOL)
680
+ * - wire: total prelaunch WIRE shares (warrants/pretokens, 1e8)
681
+ * - extras: useful internal addresses and raw state for debugging/UX
634
682
  */
635
683
  getPortfolio(): Promise<Portfolio>;
636
684
  /**
637
- * Program-level prelaunch WIRE / tranche snapshot for Solana.
638
- * Uses the same OutpostWireStateSnapshot primitive as getPortfolio().
685
+ * Unified, chain-agnostic tranche snapshot for Solana.
686
+ *
687
+ * Uses:
688
+ * - liqsol_core.globalState (currentIndex, totalShares, etc.)
689
+ * - liqsol_core.trancheState (price, supply, total sold, etc.)
690
+ * - Chainlink/PriceHistory for SOL/USD (via TokenClient.getSolPriceUsdSafe)
691
+ *
692
+ * windowBefore/windowAfter control how many ladder rows we precompute
693
+ * around the current tranche for UI, but you can pass nothing if you
694
+ * only need current tranche info.
639
695
  */
640
- getTrancheSnapshot(): Promise<TrancheSnapshot | null>;
641
- getBuyQuote(amount: bigint, purchaseAsset: PurchaseAsset): Promise<PurchaseQuote>;
696
+ getTrancheSnapshot(options?: {
697
+ chainID?: ChainID;
698
+ windowBefore?: number;
699
+ windowAfter?: number;
700
+ }): Promise<TrancheSnapshot>;
642
701
  /**
643
- * Exact warrant math reused from your old utils, just phrased in terms
644
- * of already-computed USD notional:
702
+ * Approximate prelaunch WIRE quote for a given amount & asset.
645
703
  *
646
- * expectedWarrants = (notionalUsd * 1e8) / wirePriceUsd
704
+ * Uses TrancheSnapshot + SOL/USD price for:
705
+ * - SOL: amount is lamports
706
+ * - LIQSOL: amount is liqSOL base units (decimals = 9)
707
+ * - YIELD: amount is treated as SOL lamports-equivalent of yield
647
708
  *
648
- * where:
649
- * - notionalUsd, wirePriceUsd are 1e8-scaled USD
650
- * - result is 1e8-scaled WIRE "shares"
709
+ * NOTE: On-chain rounding may differ slightly (this is UI-only).
710
+ */
711
+ getBuyQuote(amount: bigint, asset: PurchaseAsset, opts?: {
712
+ chainID?: ChainID;
713
+ }): Promise<PurchaseQuote>;
714
+ /**
715
+ * Convenience helper to fetch the distribution userRecord for the current user.
716
+ * Used by balance-correction flows and debugging.
651
717
  */
652
- private calculateExpectedWarrants;
653
718
  getUserRecord(): Promise<UserRecord | null>;
719
+ /**
720
+ * Run the "correct & register" flow on Solana:
721
+ * - builds the minimal transaction (maybe multi-user) to reconcile liqSOL
722
+ * - signs and sends the transaction if it can succeed
723
+ */
654
724
  correctBalance(amount?: bigint): Promise<string>;
725
+ /**
726
+ * Send a signed transaction over HTTP RPC and wait for confirmation.
727
+ * Throws if the transaction fails.
728
+ */
655
729
  private sendAndConfirmHttp;
730
+ /**
731
+ * Sign a single Solana transaction using the connected wallet adapter.
732
+ */
656
733
  signTransaction(tx: SolanaTransaction): Promise<SolanaTransaction>;
734
+ /**
735
+ * Generic "fire and forget" send helper if the caller already
736
+ * prepared and signed the transaction.
737
+ */
657
738
  sendTransaction(signed: SolanaTransaction): Promise<TransactionSignature>;
739
+ /**
740
+ * Attach recent blockhash + fee payer to a transaction.
741
+ * Required before signing and sending.
742
+ */
658
743
  prepareTx(tx: Transaction): Promise<{
659
744
  tx: Transaction;
660
745
  blockhash: string;
661
746
  lastValidBlockHeight: number;
662
747
  }>;
663
748
  }
664
- interface TxResult {
665
- signature: string;
666
- slot: number;
667
- confirmed: boolean;
668
- }
669
749
 
670
750
  /**
671
751
  * ---------------------------------------------------------------------------
@@ -5209,6 +5289,47 @@ type LiqsolCore = {
5209
5289
  ];
5210
5290
  };
5211
5291
 
5292
+ /** BN | bigint -> bigint helper (keeps code readable) */
5293
+ declare function toBigint(x: any): bigint;
5294
+ /**
5295
+ * Convert token amount -> shares using the same rule as on-chain tests:
5296
+ * shares = ceil(amount * INDEX_SCALE / currentIndex)
5297
+ */
5298
+ declare function tokensToShares(amount: bigint, currentIndex: bigint): bigint;
5299
+ /**
5300
+ * Build a local tranche ladder around the current tranche
5301
+ * using only on-chain config + current state.
5302
+ *
5303
+ * Rules (from liqsol_core tests):
5304
+ * - past tranches are fully sold
5305
+ * - current tranche has (initial - currentSupply) sold
5306
+ * - future tranches start with 0 sold
5307
+ * - supply/price grow by supplyGrowthBps/priceGrowthBps per tranche
5308
+ */
5309
+ declare function buildSolanaTrancheLadder(options: {
5310
+ currentTranche: number;
5311
+ initialTrancheSupply: bigint;
5312
+ currentTrancheSupply: bigint;
5313
+ totalWarrantsSold: bigint;
5314
+ currentPriceUsd: bigint;
5315
+ supplyGrowthBps: number;
5316
+ priceGrowthBps: number;
5317
+ windowBefore?: number;
5318
+ windowAfter?: number;
5319
+ }): TrancheLadderItem[];
5320
+ /**
5321
+ * Turn raw liqsol_core accounts into a chain-agnostic TrancheSnapshot for SOL.
5322
+ * All math stays here; TokenClient just wires accounts + connection.
5323
+ */
5324
+ declare function buildSolanaTrancheSnapshot(options: {
5325
+ chainID: ChainID;
5326
+ globalState: GlobalState;
5327
+ trancheState: TrancheState;
5328
+ solPriceUsd?: bigint;
5329
+ nativePriceTimestamp?: number;
5330
+ ladderWindowBefore?: number;
5331
+ ladderWindowAfter?: number;
5332
+ }): TrancheSnapshot;
5212
5333
  declare function getLiqsolCoreProgram(connection: Connection): Program<LiqsolCore>;
5213
5334
  declare function getUserLiqSolBalance(connection: Connection, user: PublicKey$1): Promise<number>;
5214
5335
  declare function getBucketLiqSolBalance(connection: Connection): Promise<number>;
@@ -5532,58 +5653,29 @@ declare class OutpostClient {
5532
5653
  private getTokenBalanceSafe;
5533
5654
  }
5534
5655
 
5535
- /**
5536
- * Client for interacting with the Pretoken (Outpost) program on Solana.
5537
- *
5538
- * Provides account fetching and instruction building for pretoken operations.
5539
- * Does NOT send or confirm transactions; keeps SDK composable.
5540
- *
5541
- * TODO: Update to $WIRE Token implementation Post-Launch
5542
- */
5543
5656
  declare class TokenClient {
5544
5657
  private readonly provider;
5545
5658
  private readonly program;
5546
5659
  get wallet(): WalletLike;
5547
5660
  constructor(provider: AnchorProvider);
5548
- /**
5549
- * Single source of truth for outpost/pretoken accounts.
5550
- * Uses your existing PDA + ATA derivations in buildOutpostAccounts().
5551
- */
5552
5661
  getAccounts(user: PublicKey$1): Promise<OutpostAccounts>;
5553
- /**
5554
- * Lightweight, UI-friendly snapshot fetchers.
5555
- * (No decoding assumptions beyond what Anchor already provides.)
5556
- */
5557
5662
  fetchGlobalState(): Promise<GlobalState>;
5558
5663
  fetchTrancheState(): Promise<TrancheState>;
5559
5664
  fetchWireReceipt(user: PublicKey$1): Promise<WireReceipt>;
5560
5665
  fetchUserWarrantRecord(user: PublicKey$1): Promise<UserWarrantRecord>;
5561
- /**
5562
- * purchase_with_sol(amount u64)
5563
- *
5564
- * amountLamports is bigint to match your SDK convention.
5565
- */
5566
5666
  buildPurchaseWithSolIx(amountLamports: bigint, user?: PublicKey$1): Promise<TransactionInstruction>;
5567
- /**
5568
- * purchase_with_liqsol(amount u64)
5569
- *
5570
- * amount is liqSOL *raw base units* (Token-2022 amount).
5571
- */
5572
5667
  buildPurchaseWithLiqsolIx(amountLamports: bigint, user?: PublicKey$1): Promise<TransactionInstruction>;
5573
- /**
5574
- * purchase_warrants_from_yield()
5575
- *
5576
- * No amount arg; it consumes tracked yield according to on-chain rules.
5577
- */
5578
5668
  buildPurchaseFromYieldIx(user?: PublicKey$1): Promise<TransactionInstruction>;
5669
+ getSolPriceUsdSafe(): Promise<{
5670
+ price?: bigint;
5671
+ timestamp?: number;
5672
+ }>;
5579
5673
  /**
5580
- * Fetch the SOL price in 1e8 USD units from liqsol_core.priceHistory.
5581
- *
5582
- * This uses the same ring-buffer semantics as the on-chain program:
5583
- * the latest price is the entry just before `nextIndex`.
5674
+ * Fetch latest SOL/USD price (1e8 scale) from liqsol_core.priceHistory.
5675
+ * Uses the ring-buffer semantics from earlier SDK code.
5584
5676
  */
5585
- getSolPriceUsd(): Promise<BN>;
5677
+ getSolPriceUsd(): Promise<bigint>;
5586
5678
  }
5587
5679
 
5588
- export { ADDRESSES, CHAINLINK_FEED, CHAINLINK_PROGRAM, CONTRACTS, DEFAULT_AVERAGE_PAY_RATE, DEFAULT_PAY_RATE_LOOKBACK, DepositClient, DistributionClient, EPHEMERAL_RENT_EXEMPTION, ERC1155Abi, ERC20Abi, ERC721Abi, types$1 as ETH, EthereumContractService, EthereumStakingClient, LAMPORTS_PER_SOL, LIQSOL_CORE, LIQSOL_TOKEN, LeaderboardClient, OutpostClient, PAY_RATE_SCALE_FACTOR, PDA_SEEDS, PROGRAM_IDS, PurchaseAsset, types as SOL, SolanaStakingClient, Staker, TokenClient, VALIDATOR_LEADERBOARD, airdropSol, buildOutpostAccounts, calculateExpectedFee, deriveBarConfigPda, deriveBondLevelPda, deriveBondedActorPda, deriveBucketAuthorityPda, deriveDepositAuthorityPda, deriveDistributionStatePda, deriveEphemeralStakeAddress, deriveLeaderboardStatePda, deriveLiqsolMintAuthorityPda, deriveLiqsolMintPda, deriveOutpostGlobalStatePda, deriveOutpostPoolAuthorityPda, derivePayRateHistoryPda, derivePayoutStatePda, derivePoolUserRecordPda, derivePriceHistoryPda, deriveReservePoolPda, deriveSolBucketPda, deriveStakeControllerStatePda, deriveStakeControllerVaultPda, deriveTrancheStatePda, deriveUserRecordPda, deriveUserUserRecordPda, deriveUserWarrantRecordPda, deriveValidatorRecordPda, deriveVaultPda, deriveWireReceiptPda, generateRandomDepositAmount, generateTestKeypair, getAveragePayRate, getBucketLiqSolBalance, getEpochSnapshot, getErrorMessage, getLiqsolCoreProgram, getPayoutStateRaw, getReservePoolBalance, getStakeControllerStateRaw, getUserLiqSolBalance, getUserRecordRaw, lamportsToSol, msToEpochEnd, previewDepositEffects, scheduledInstruction, sleep, solToLamports, waitForConfirmation, waitUntilSafeToExecuteFunction };
5589
- export type { BalanceView, ContractConfig, ContractOptions, Contracts, EpochSnapshot, IStakingClient, OutpostAccounts, Portfolio, PurchaseQuote, ScheduleConfig, StakerConfig, TrancheSnapshot, TxResult };
5680
+ export { ADDRESSES, CHAINLINK_FEED, CHAINLINK_PROGRAM, CONTRACTS, DEFAULT_AVERAGE_PAY_RATE, DEFAULT_PAY_RATE_LOOKBACK, DepositClient, DistributionClient, EPHEMERAL_RENT_EXEMPTION, ERC1155Abi, ERC20Abi, ERC721Abi, types$1 as ETH, EthereumContractService, EthereumStakingClient, LAMPORTS_PER_SOL, LIQSOL_CORE, LIQSOL_TOKEN, LeaderboardClient, OutpostClient, PAY_RATE_SCALE_FACTOR, PDA_SEEDS, PROGRAM_IDS, PurchaseAsset, types as SOL, SolanaStakingClient, Staker, TokenClient, VALIDATOR_LEADERBOARD, airdropSol, buildOutpostAccounts, buildSolanaTrancheLadder, buildSolanaTrancheSnapshot, calculateExpectedFee, deriveBarConfigPda, deriveBondLevelPda, deriveBondedActorPda, deriveBucketAuthorityPda, deriveDepositAuthorityPda, deriveDistributionStatePda, deriveEphemeralStakeAddress, deriveLeaderboardStatePda, deriveLiqsolMintAuthorityPda, deriveLiqsolMintPda, deriveOutpostGlobalStatePda, deriveOutpostPoolAuthorityPda, derivePayRateHistoryPda, derivePayoutStatePda, derivePoolUserRecordPda, derivePriceHistoryPda, deriveReservePoolPda, deriveSolBucketPda, deriveStakeControllerStatePda, deriveStakeControllerVaultPda, deriveTrancheStatePda, deriveUserRecordPda, deriveUserUserRecordPda, deriveUserWarrantRecordPda, deriveValidatorRecordPda, deriveVaultPda, deriveWireReceiptPda, generateRandomDepositAmount, generateTestKeypair, getAveragePayRate, getBucketLiqSolBalance, getEpochSnapshot, getErrorMessage, getLiqsolCoreProgram, getPayoutStateRaw, getReservePoolBalance, getStakeControllerStateRaw, getUserLiqSolBalance, getUserRecordRaw, lamportsToSol, msToEpochEnd, previewDepositEffects, scheduledInstruction, sleep, solToLamports, toBigint, tokensToShares, waitForConfirmation, waitUntilSafeToExecuteFunction };
5681
+ export type { BalanceView, ContractConfig, ContractOptions, Contracts, EpochSnapshot, IStakingClient, OutpostAccounts, Portfolio, PurchaseQuote, ScheduleConfig, StakerConfig, TrancheLadderItem, TrancheSnapshot };