@wireio/stake 0.1.2 → 0.2.0

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.
@@ -38,19 +38,30 @@ import {
38
38
  deriveStakeControllerVaultPda,
39
39
  deriveEphemeralStakeAddress,
40
40
  DEFAULT_PAY_RATE_LOOKBACK,
41
+ deriveOutpostGlobalStatePda,
42
+ deriveOutpostPoolAuthorityPda,
43
+ deriveSolBucketPda,
44
+ deriveTrancheStatePda,
45
+ deriveWireReceiptPda,
46
+ derivePoolUserRecordPda,
47
+ deriveUserUserRecordPda,
48
+ deriveUserWarrantRecordPda,
49
+ CHAINLINK_FEED,
50
+ CHAINLINK_PROGRAM,
41
51
  } from './constants';
42
52
 
43
53
  import liqsolCoreIDL from '../../assets/solana/idl/liqsol_core.json';
54
+ import { LiqsolCore } from '../../assets/solana/types/liqsol_core';
44
55
 
45
56
  // -----------------------------------------------------------------------------
46
57
  // Read-only liqsol_core Program helper
47
58
  // -----------------------------------------------------------------------------
48
59
 
49
- let _liqsolCoreProgram: Program | null = null;
60
+ let _liqsolCoreProgram: Program<LiqsolCore> | null = null;
50
61
 
51
62
  export function getLiqsolCoreProgram(
52
63
  connection: Connection,
53
- ): Program {
64
+ ): Program<LiqsolCore> {
54
65
  if (_liqsolCoreProgram && _liqsolCoreProgram.provider.connection === connection) {
55
66
  return _liqsolCoreProgram;
56
67
  }
@@ -66,102 +77,12 @@ export function getLiqsolCoreProgram(
66
77
  const program = new Program(
67
78
  liqsolCoreIDL,
68
79
  provider,
69
- ) as Program;
80
+ ) as Program<LiqsolCore>;
70
81
 
71
82
  _liqsolCoreProgram = program;
72
83
  return program;
73
84
  }
74
85
 
75
- // -----------------------------------------------------------------------------
76
- // Deposit accounts bundle
77
- // -----------------------------------------------------------------------------
78
-
79
- export interface DepositAccounts {
80
- user: PublicKey;
81
- depositAuthority: PublicKey;
82
- liqsolMint: PublicKey;
83
- liqsolMintAuthority: PublicKey;
84
- userAta: PublicKey;
85
- stakeControllerVault: PublicKey;
86
- stakeControllerReservePool: PublicKey;
87
- stakeControllerState: PublicKey;
88
- payoutState: PublicKey;
89
- bucketAuthority: PublicKey;
90
- bucketTokenAccount: PublicKey;
91
- distributionState: PublicKey;
92
- userRecord: PublicKey;
93
- payRateHistory: PublicKey;
94
- ephemeralStake: PublicKey;
95
- ephemeralSeed: string;
96
- }
97
-
98
- /**
99
- * Build a complete DepositAccounts set for a given user, matching the
100
- * on-chain PDAs used by the liqSOL core program.
101
- *
102
- * The optional `seed` lets you make deposit flows replayable/deterministic.
103
- * If omitted, a random u32 seed is generated.
104
- */
105
- export async function buildDepositAccounts(
106
- connection: Connection,
107
- user: PublicKey,
108
- ): Promise<DepositAccounts> {
109
- const depositAuthority = deriveDepositAuthorityPda();
110
- const liqsolMint = deriveLiqsolMintPda();
111
- const liqsolMintAuthority = deriveLiqsolMintAuthorityPda();
112
- const stakeControllerVault = deriveStakeControllerVaultPda();
113
- const stakeControllerReservePool = deriveReservePoolPda();
114
- const stakeControllerState = deriveStakeControllerStatePda();
115
- const payoutState = derivePayoutStatePda();
116
- const bucketAuthority = deriveBucketAuthorityPda();
117
- const distributionState = deriveDistributionStatePda();
118
- const userRecord = deriveUserRecordPda(user);
119
- const payRateHistory = derivePayRateHistoryPda();
120
-
121
- const userAta = await getAssociatedTokenAddress(
122
- liqsolMint,
123
- user,
124
- false,
125
- TOKEN_2022_PROGRAM_ID,
126
- );
127
-
128
- const bucketTokenAccount = await getAssociatedTokenAddress(
129
- liqsolMint,
130
- bucketAuthority,
131
- true,
132
- TOKEN_2022_PROGRAM_ID,
133
- );
134
-
135
- // -------------------------------------------------------------
136
- // Ephemeral stake
137
- // -------------------------------------------------------------
138
- const seed = Math.floor(Math.random() * 2 ** 32);
139
- const ephemeralSeed = `ephemeral_${seed}`;
140
- const ephemeralStake = await deriveEphemeralStakeAddress(user, ephemeralSeed);
141
-
142
- // `connection` is currently unused, but we keep it in the signature
143
- // so this helper can evolve to preflight/validate accounts if needed.
144
- void connection;
145
-
146
- return {
147
- user,
148
- depositAuthority,
149
- liqsolMint,
150
- liqsolMintAuthority,
151
- userAta,
152
- stakeControllerVault,
153
- stakeControllerReservePool,
154
- stakeControllerState,
155
- payoutState,
156
- bucketAuthority,
157
- bucketTokenAccount,
158
- distributionState,
159
- userRecord,
160
- payRateHistory,
161
- ephemeralStake,
162
- ephemeralSeed,
163
- };
164
- }
165
86
 
166
87
  // -----------------------------------------------------------------------------
167
88
  // Balance + state getters (UI-friendly)
@@ -374,6 +295,102 @@ export function previewDepositEffects(params: {
374
295
  };
375
296
  }
376
297
 
298
+ /**
299
+ * ---------------------------------------------------------------------------
300
+ * Outpost-specific helpers
301
+ * ---------------------------------------------------------------------------
302
+ */
303
+ export interface OutpostAccounts {
304
+ user: PublicKey;
305
+
306
+ // Warrant / outpost
307
+ globalState: PublicKey;
308
+ poolAuthority: PublicKey;
309
+ liqsolMint: PublicKey;
310
+ liqsolPoolAta: PublicKey;
311
+ userAta: PublicKey;
312
+ wireReceipt: PublicKey;
313
+ poolUserRecord: PublicKey;
314
+ userUserRecord: PublicKey;
315
+ distributionState: PublicKey;
316
+ payRateHistory: PublicKey;
317
+ bucketAuthority: PublicKey;
318
+ bucketTokenAccount: PublicKey;
319
+ solBucket: PublicKey;
320
+ trancheState: PublicKey;
321
+ userWarrantRecord: PublicKey;
322
+
323
+ // Chainlink
324
+ chainLinkFeed: PublicKey;
325
+ chainLinkProgram: PublicKey;
326
+ }
327
+
328
+ export async function buildOutpostAccounts(
329
+ connection: Connection,
330
+ user: PublicKey,
331
+ ): Promise<OutpostAccounts> {
332
+ const globalState = deriveOutpostGlobalStatePda();
333
+ const poolAuthority = deriveOutpostPoolAuthorityPda();
334
+ const liqsolMint = deriveLiqsolMintPda();
335
+ const distributionState = deriveDistributionStatePda();
336
+ const payRateHistory = derivePayRateHistoryPda();
337
+ const bucketAuthority = deriveBucketAuthorityPda();
338
+ const solBucket = deriveSolBucketPda();
339
+ const trancheState = deriveTrancheStatePda();
340
+ const wireReceipt = deriveWireReceiptPda(user);
341
+ const poolUserRecord = derivePoolUserRecordPda(poolAuthority);
342
+ const userUserRecord = deriveUserUserRecordPda(user);
343
+ const userWarrantRecord = deriveUserWarrantRecordPda(user);
344
+
345
+ const liqsolPoolAta = await getAssociatedTokenAddress(
346
+ liqsolMint,
347
+ poolAuthority,
348
+ true,
349
+ TOKEN_2022_PROGRAM_ID,
350
+ );
351
+
352
+ const bucketTokenAccount = await getAssociatedTokenAddress(
353
+ liqsolMint,
354
+ bucketAuthority,
355
+ true,
356
+ TOKEN_2022_PROGRAM_ID,
357
+ );
358
+
359
+ const userAta = await getAssociatedTokenAddress(
360
+ liqsolMint,
361
+ user,
362
+ false,
363
+ TOKEN_2022_PROGRAM_ID,
364
+ );
365
+
366
+ // Chainlink program feeds
367
+ const chainLinkFeed = CHAINLINK_FEED;
368
+ const chainLinkProgram = CHAINLINK_PROGRAM
369
+
370
+ void connection; // reserved for future extra validation
371
+
372
+ return {
373
+ user,
374
+ globalState,
375
+ poolAuthority,
376
+ liqsolMint,
377
+ liqsolPoolAta,
378
+ userAta,
379
+ wireReceipt,
380
+ poolUserRecord,
381
+ userUserRecord,
382
+ distributionState,
383
+ payRateHistory,
384
+ bucketAuthority,
385
+ bucketTokenAccount,
386
+ solBucket,
387
+ trancheState,
388
+ userWarrantRecord,
389
+ chainLinkFeed,
390
+ chainLinkProgram,
391
+ };
392
+ }
393
+
377
394
  // -----------------------------------------------------------------------------
378
395
  // Epoch / scheduling helpers
379
396
  // -----------------------------------------------------------------------------
@@ -516,7 +533,7 @@ export async function airdropSol(
516
533
  amountSol: number,
517
534
  ): Promise<void> {
518
535
  const lamports = solToLamports(amountSol);
519
- const sig = await connection.requestAirdrop(publicKey, lamports);
536
+ const sig = await connection.requestAirdrop(publicKey, Number(lamports));
520
537
  await connection.confirmTransaction(sig, 'confirmed');
521
538
  }
522
539
 
@@ -52,7 +52,7 @@ export class Staker {
52
52
 
53
53
  this.selectedChainID = selectedChainID;
54
54
  }
55
-
55
+
56
56
  /**
57
57
  * Select a chain. Returns true if a client exists for it, false otherwise.
58
58
  * (We still record the selectedChainID so the UI can reflect the chosen chain.)
@@ -1,17 +1,19 @@
1
- // types.ts
2
-
3
1
  import { BaseSignerWalletAdapter } from '@solana/wallet-adapter-base';
4
2
  import { PublicKey as SolPubKey } from '@solana/web3.js';
5
3
  import { ChainID, ExternalNetwork, PublicKey } from '@wireio/core';
6
- import { BigNumberish, ethers } from 'ethers';
4
+ import { ethers } from 'ethers';
7
5
 
8
6
  export interface IStakingClient {
9
7
  pubKey: PublicKey;
10
8
  network: ExternalNetwork;
11
9
 
12
10
  /** Amount is in the chain's smallest unit (lamports/wei, etc.) */
13
- deposit(amount: number): Promise<string>;
11
+ deposit(amount: bigint): Promise<string>;
12
+ withdraw(amount: bigint): Promise<string>;
13
+ stake(amount: bigint): Promise<string>;
14
+ unstake(amount: bigint): Promise<string>;
14
15
 
16
+ // REMOVED from shared client, SOLANA ONLY
15
17
  /** Register any untracked LIQ staked tokens */
16
18
  // register(): Promise<string>;
17
19
 
@@ -42,7 +44,7 @@ export interface Portfolio {
42
44
  }
43
45
 
44
46
  export type BalanceView = {
45
- amount: BigNumberish; // raw on-chain integer value
47
+ amount: bigint; // raw on-chain integer value
46
48
  decimals: number; // number of decimal places
47
49
  symbol?: string; // optional token symbol identifier
48
50
  ata?: SolPubKey; // associated token account address