@wireio/stake 2.4.3 → 2.5.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.
- package/lib/stake.browser.js +55 -48
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +14 -9
- package/lib/stake.js +63 -55
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +55 -48
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/ethereum/ethereum.ts +2 -2
- package/src/networks/solana/clients/convert.client.ts +5 -3
- package/src/networks/solana/clients/outpost.client.ts +33 -44
- package/src/networks/solana/solana.ts +12 -2
- package/src/networks/solana/types.ts +10 -6
- package/src/networks/solana/utils.ts +8 -0
- package/src/types.ts +1 -1
package/package.json
CHANGED
|
@@ -202,12 +202,12 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
202
202
|
* actual = liqETH token balance (ERC-20)
|
|
203
203
|
* tracked = liqETH tracked balance (protocol/accounting view)
|
|
204
204
|
*/
|
|
205
|
-
async getPortfolio(): Promise<Portfolio | null> {
|
|
205
|
+
async getPortfolio(address?: string): Promise<Portfolio | null> {
|
|
206
206
|
|
|
207
207
|
try {
|
|
208
208
|
if (!this.signer) return Promise.resolve(null);
|
|
209
209
|
|
|
210
|
-
const walletAddress = await this.address!;
|
|
210
|
+
const walletAddress = address ?? await this.address!;
|
|
211
211
|
|
|
212
212
|
// 1) Native ETH balance
|
|
213
213
|
const nativeBalance = await this.provider.getBalance(walletAddress);
|
|
@@ -316,10 +316,12 @@ export class ConvertClient {
|
|
|
316
316
|
|
|
317
317
|
let slotTimeSec = 0.4;
|
|
318
318
|
try {
|
|
319
|
-
const samples = await conn.getRecentPerformanceSamples(
|
|
319
|
+
const samples = await conn.getRecentPerformanceSamples(60);
|
|
320
320
|
if (samples?.length) {
|
|
321
|
-
const
|
|
322
|
-
|
|
321
|
+
const valid = samples.filter(s => s.numSlots > 0);
|
|
322
|
+
if (valid.length) {
|
|
323
|
+
slotTimeSec = valid.reduce((sum, s) => sum + s.samplePeriodSecs / s.numSlots, 0) / valid.length;
|
|
324
|
+
}
|
|
323
325
|
}
|
|
324
326
|
} catch (_) {
|
|
325
327
|
// ignore
|
|
@@ -14,6 +14,7 @@ import { LiqsolCore } from '../../../assets/solana/devnet/types/liqsol_core';
|
|
|
14
14
|
import {
|
|
15
15
|
OutpostAccounts,
|
|
16
16
|
buildOutpostAccounts,
|
|
17
|
+
safeFetch,
|
|
17
18
|
} from '../utils';
|
|
18
19
|
|
|
19
20
|
import {
|
|
@@ -74,12 +75,8 @@ export class OutpostClient {
|
|
|
74
75
|
* Internal helper: get raw token balance (BN) for a given ATA.
|
|
75
76
|
*/
|
|
76
77
|
private async getTokenBalance(ata: PublicKey): Promise<BN> {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return new BN(bal.value.amount);
|
|
80
|
-
} catch {
|
|
81
|
-
return new BN(0);
|
|
82
|
-
}
|
|
78
|
+
const bal = await this.connection.getTokenAccountBalance(ata);
|
|
79
|
+
return new BN(bal.value.amount);
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
/**
|
|
@@ -87,48 +84,40 @@ export class OutpostClient {
|
|
|
87
84
|
*/
|
|
88
85
|
async fetchWireState(user?: PublicKey): Promise<OutpostWireStateSnapshot> {
|
|
89
86
|
const userPk = user ?? this.wallet.publicKey;
|
|
90
|
-
if (!userPk)
|
|
91
|
-
throw new Error('OutpostClient.fetchWireState: wallet not connected');
|
|
92
|
-
}
|
|
87
|
+
if (!userPk) throw new Error('OutpostClient.fetchWireState: wallet not connected');
|
|
93
88
|
|
|
94
89
|
const pdas = await this.buildAccounts(userPk);
|
|
90
|
+
const [
|
|
91
|
+
globalState,
|
|
92
|
+
outpostAccount,
|
|
93
|
+
distributionState,
|
|
94
|
+
userPretokenRecord,
|
|
95
|
+
trancheState,
|
|
96
|
+
liqsolPoolBalance,
|
|
97
|
+
userLiqsolBalance,
|
|
98
|
+
] = await Promise.all([
|
|
99
|
+
safeFetch(this.program.account.globalState.fetch(pdas.globalState), 'globalState'),
|
|
100
|
+
safeFetch(this.program.account.outpostAccount.fetchNullable(pdas.outpostAccount), 'outpostAccount'),
|
|
101
|
+
safeFetch(this.program.account.distributionState.fetchNullable(pdas.distributionState), 'distributionState'),
|
|
102
|
+
safeFetch(this.program.account.userPretokenRecord.fetchNullable(pdas.userPretokenRecord), 'userPretokenRecord'),
|
|
103
|
+
safeFetch(this.program.account.trancheState.fetchNullable(pdas.trancheState), 'trancheState'),
|
|
104
|
+
safeFetch(this.getTokenBalance(pdas.liqsolPoolAta), 'liqsolPoolAta'),
|
|
105
|
+
safeFetch(this.getTokenBalance(pdas.userAta), 'userAta'),
|
|
106
|
+
]);
|
|
95
107
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.program.account.outpostAccount.fetchNullable(pdas.outpostAccount),
|
|
106
|
-
this.program.account.distributionState.fetchNullable(pdas.distributionState),
|
|
107
|
-
this.program.account.userPretokenRecord.fetchNullable(pdas.userPretokenRecord),
|
|
108
|
-
this.program.account.trancheState.fetchNullable(pdas.trancheState),
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
const [liqsolPoolBalance, userLiqsolBalance] = await Promise.all([
|
|
112
|
-
this.getTokenBalance(pdas.liqsolPoolAta),
|
|
113
|
-
this.getTokenBalance(pdas.userAta),
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
globalState,
|
|
118
|
-
outpostAccount,
|
|
119
|
-
distributionState,
|
|
120
|
-
trancheState,
|
|
121
|
-
userPretokenRecord,
|
|
122
|
-
liqsolPoolBalance,
|
|
123
|
-
userLiqsolBalance,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
console.error('Error fetching Outpost wire state:', err);
|
|
128
|
-
throw err;
|
|
129
|
-
}
|
|
108
|
+
return {
|
|
109
|
+
globalState,
|
|
110
|
+
outpostAccount,
|
|
111
|
+
distributionState,
|
|
112
|
+
trancheState,
|
|
113
|
+
userPretokenRecord,
|
|
114
|
+
liqsolPoolBalance,
|
|
115
|
+
userLiqsolBalance,
|
|
116
|
+
};
|
|
130
117
|
}
|
|
131
118
|
|
|
119
|
+
|
|
120
|
+
|
|
132
121
|
// -------------------------------------------------------------------------
|
|
133
122
|
// Outpost stake / unstake builders (synd / desynd)
|
|
134
123
|
// -------------------------------------------------------------------------
|
|
@@ -301,4 +290,4 @@ export class OutpostClient {
|
|
|
301
290
|
const decPart = valueStr.slice(valueStr.length - decimals);
|
|
302
291
|
return `${intPart}.${decPart}`;
|
|
303
292
|
}
|
|
304
|
-
}
|
|
293
|
+
}
|
|
@@ -389,10 +389,11 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
389
389
|
* - yield: on-chain index/shares plus an estimated accrued liqSOL yield
|
|
390
390
|
* - extras: useful internal addresses and raw state for debugging/UX
|
|
391
391
|
*/
|
|
392
|
-
async getPortfolio(): Promise<Portfolio> {
|
|
392
|
+
async getPortfolio(address?: string): Promise<Portfolio> {
|
|
393
393
|
// if (!this.pubKey) throw new Error('User pubKey is undefined');
|
|
394
394
|
try {
|
|
395
|
-
const user =
|
|
395
|
+
const user = address ? new SolPubKey(address) :
|
|
396
|
+
!!this.squadsX ? this.squadsVaultPDA! : this.solPubKey;
|
|
396
397
|
|
|
397
398
|
const reservePoolPDA = this.program.deriveReservePoolPda();
|
|
398
399
|
const vaultPDA = this.program.deriveVaultPda();
|
|
@@ -444,6 +445,15 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
444
445
|
userPretokenRecord?.totalPretokensPurchased?.toString?.() ??
|
|
445
446
|
'0';
|
|
446
447
|
|
|
448
|
+
console.log('userPretokenRecord', userPretokenRecord);
|
|
449
|
+
console.log('address', address);
|
|
450
|
+
console.log('userPretokenRecord?.totalPretokensPurchased?.toString', userPretokenRecord?.totalPretokensPurchased?.toString);
|
|
451
|
+
if (userPretokenRecord) {
|
|
452
|
+
for (const [key, value] of Object.entries(userPretokenRecord)) {
|
|
453
|
+
console.log(`userPretokenRecord.${key}: ${value?.toString?.() ?? value}`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
447
457
|
// -----------------------------
|
|
448
458
|
// Yield view (index + shares)
|
|
449
459
|
// -----------------------------
|
|
@@ -34,7 +34,11 @@ export type ParsedAccountInfo = {
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
export type OutpostWireStateSnapshot = {
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Global Wire/outpost state.
|
|
39
|
+
* May be null if the fetch fails.
|
|
40
|
+
*/
|
|
41
|
+
globalState: GlobalState | null;
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Per-user Outpost account (old “wire receipt”), or null if user
|
|
@@ -60,11 +64,11 @@ export type OutpostWireStateSnapshot = {
|
|
|
60
64
|
userPretokenRecord: UserPretokenRecord | null;
|
|
61
65
|
|
|
62
66
|
// Balances
|
|
63
|
-
/** liqSOL in the pool ATA (Token-2022 raw amount) */
|
|
64
|
-
liqsolPoolBalance: BN;
|
|
67
|
+
/** liqSOL in the pool ATA (Token-2022 raw amount), or null on fetch failure */
|
|
68
|
+
liqsolPoolBalance: BN | null;
|
|
65
69
|
|
|
66
|
-
/** liqSOL in the user’s ATA (Token-2022 raw amount) */
|
|
67
|
-
userLiqsolBalance: BN;
|
|
70
|
+
/** liqSOL in the user’s ATA (Token-2022 raw amount), or null on fetch failure */
|
|
71
|
+
userLiqsolBalance: BN | null;
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
/**
|
|
@@ -750,4 +754,4 @@ export type ReceiptData = {
|
|
|
750
754
|
|
|
751
755
|
/** Flag indicating whether this receipt has been fulfilled/claimed (bool) */
|
|
752
756
|
fulfilled: boolean;
|
|
753
|
-
};
|
|
757
|
+
};
|
|
@@ -562,3 +562,11 @@ export function normalizeToBigInt(x: any): bigint {
|
|
|
562
562
|
if (typeof x === 'number') return BigInt(x);
|
|
563
563
|
throw new Error(`normalizeToBigInt: unsupported type ${typeof x}`);
|
|
564
564
|
}
|
|
565
|
+
|
|
566
|
+
export const safeFetch = async <T>(promise: Promise<T>, label?: string): Promise<T | null> => {
|
|
567
|
+
try { return await promise; }
|
|
568
|
+
catch (err) {
|
|
569
|
+
console.error(`Safe Fetch Failed${label ? ` (${label})` : ''}:`,err);
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -50,7 +50,7 @@ export interface IStakingClient {
|
|
|
50
50
|
getPendingWithdraws(address?: string): Promise<WithdrawReceipt[]>
|
|
51
51
|
|
|
52
52
|
/** Fetch the complete user portfolio */
|
|
53
|
-
getPortfolio(): Promise<Portfolio | null>;
|
|
53
|
+
getPortfolio(address?: string): Promise<Portfolio | null>;
|
|
54
54
|
|
|
55
55
|
// Estimated total APY for staking yeild
|
|
56
56
|
getSystemAPY(): Promise<number>;
|