@wireio/stake 2.4.4 → 2.5.1
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 +52 -39
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +19 -6
- package/lib/stake.js +53 -37
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +52 -39
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/solana/clients/outpost.client.ts +61 -42
- 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,11 +75,37 @@ 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> {
|
|
78
|
+
const bal = await this.connection.getTokenAccountBalance(ata);
|
|
79
|
+
return new BN(bal.value.amount);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Fetch an OutpostAccount, handling legacy accounts that pre-date the
|
|
84
|
+
* three trailing Option<u64> fields. If the normal decode throws a
|
|
85
|
+
* RangeError we re-fetch the raw data, pad it to the expected size
|
|
86
|
+
* (zeros → Option::None for each missing field), and let Anchor's
|
|
87
|
+
* coder decode the padded buffer.
|
|
88
|
+
*/
|
|
89
|
+
private async fetchOutpostAccount(address: PublicKey) {
|
|
77
90
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
return await this.program.account.outpostAccount.fetchNullable(address);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
if (!(e instanceof RangeError)) throw e;
|
|
94
|
+
|
|
95
|
+
const info = await this.connection.getAccountInfo(address);
|
|
96
|
+
if (!info) return null;
|
|
97
|
+
|
|
98
|
+
// 3 × Option<u64> encoded as 1-byte tag (0x00 = None) = 3 bytes
|
|
99
|
+
// when present (Some) each is 9 bytes, but None is just 0x00
|
|
100
|
+
const EXPECTED_SIZE = info.data.length + 3;
|
|
101
|
+
const padded = Buffer.alloc(EXPECTED_SIZE);
|
|
102
|
+
info.data.copy(padded);
|
|
103
|
+
// trailing bytes are already 0x00 → Option::None for each field
|
|
104
|
+
|
|
105
|
+
return this.program.coder.accounts.decode(
|
|
106
|
+
'outpostAccount',
|
|
107
|
+
padded,
|
|
108
|
+
);
|
|
82
109
|
}
|
|
83
110
|
}
|
|
84
111
|
|
|
@@ -87,48 +114,40 @@ export class OutpostClient {
|
|
|
87
114
|
*/
|
|
88
115
|
async fetchWireState(user?: PublicKey): Promise<OutpostWireStateSnapshot> {
|
|
89
116
|
const userPk = user ?? this.wallet.publicKey;
|
|
90
|
-
if (!userPk)
|
|
91
|
-
throw new Error('OutpostClient.fetchWireState: wallet not connected');
|
|
92
|
-
}
|
|
117
|
+
if (!userPk) throw new Error('OutpostClient.fetchWireState: wallet not connected');
|
|
93
118
|
|
|
94
119
|
const pdas = await this.buildAccounts(userPk);
|
|
120
|
+
const [
|
|
121
|
+
globalState,
|
|
122
|
+
outpostAccount,
|
|
123
|
+
distributionState,
|
|
124
|
+
userPretokenRecord,
|
|
125
|
+
trancheState,
|
|
126
|
+
liqsolPoolBalance,
|
|
127
|
+
userLiqsolBalance,
|
|
128
|
+
] = await Promise.all([
|
|
129
|
+
safeFetch(this.program.account.globalState.fetch(pdas.globalState), 'globalState'),
|
|
130
|
+
safeFetch(this.fetchOutpostAccount(pdas.outpostAccount), 'outpostAccount'),
|
|
131
|
+
safeFetch(this.program.account.distributionState.fetchNullable(pdas.distributionState), 'distributionState'),
|
|
132
|
+
safeFetch(this.program.account.userPretokenRecord.fetchNullable(pdas.userPretokenRecord), 'userPretokenRecord'),
|
|
133
|
+
safeFetch(this.program.account.trancheState.fetchNullable(pdas.trancheState), 'trancheState'),
|
|
134
|
+
safeFetch(this.getTokenBalance(pdas.liqsolPoolAta), 'liqsolPoolAta'),
|
|
135
|
+
safeFetch(this.getTokenBalance(pdas.userAta), 'userAta'),
|
|
136
|
+
]);
|
|
95
137
|
|
|
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
|
-
}
|
|
138
|
+
return {
|
|
139
|
+
globalState,
|
|
140
|
+
outpostAccount,
|
|
141
|
+
distributionState,
|
|
142
|
+
trancheState,
|
|
143
|
+
userPretokenRecord,
|
|
144
|
+
liqsolPoolBalance,
|
|
145
|
+
userLiqsolBalance,
|
|
146
|
+
};
|
|
130
147
|
}
|
|
131
148
|
|
|
149
|
+
|
|
150
|
+
|
|
132
151
|
// -------------------------------------------------------------------------
|
|
133
152
|
// Outpost stake / unstake builders (synd / desynd)
|
|
134
153
|
// -------------------------------------------------------------------------
|
|
@@ -301,4 +320,4 @@ export class OutpostClient {
|
|
|
301
320
|
const decPart = valueStr.slice(valueStr.length - decimals);
|
|
302
321
|
return `${intPart}.${decPart}`;
|
|
303
322
|
}
|
|
304
|
-
}
|
|
323
|
+
}
|
|
@@ -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
|
+
};
|