@wireio/stake 2.4.4 → 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 +46 -41
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +11 -6
- package/lib/stake.js +54 -48
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +46 -41
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/solana/clients/outpost.client.ts +33 -44
- package/src/networks/solana/solana.ts +9 -0
- package/src/networks/solana/types.ts +10 -6
- package/src/networks/solana/utils.ts +8 -0
package/package.json
CHANGED
|
@@ -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
|
+
}
|
|
@@ -445,6 +445,15 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
445
445
|
userPretokenRecord?.totalPretokensPurchased?.toString?.() ??
|
|
446
446
|
'0';
|
|
447
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
|
+
|
|
448
457
|
// -----------------------------
|
|
449
458
|
// Yield view (index + shares)
|
|
450
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
|
+
};
|