@wireio/stake 2.2.2 → 2.3.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.js CHANGED
@@ -9,213 +9,24 @@ var bs58 = require('bs58');
9
9
  var ethers = require('ethers');
10
10
 
11
11
  function _interopNamespaceDefault(e) {
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
22
20
  });
23
- }
24
- n.default = e;
25
- return Object.freeze(n);
26
- }
27
-
28
- var multisig__namespace = /*#__PURE__*/_interopNamespaceDefault(multisig);
29
-
30
- var __pow = Math.pow;
31
- var __async$h = (__this, __arguments, generator) => {
32
- return new Promise((resolve, reject) => {
33
- var fulfilled = (value) => {
34
- try {
35
- step(generator.next(value));
36
- } catch (e) {
37
- reject(e);
38
21
  }
39
- };
40
- var rejected = (value) => {
41
- try {
42
- step(generator.throw(value));
43
- } catch (e) {
44
- reject(e);
45
- }
46
- };
47
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
48
- step((generator = generator.apply(__this, __arguments)).next());
49
- });
50
- };
51
- class DepositClient {
52
- constructor(provider, pgs) {
53
- this.provider = provider;
54
- this.pgs = pgs;
55
- this.program = pgs.getProgram("liqsolCore");
56
- }
57
- get connection() {
58
- return this.provider.connection;
59
- }
60
- get wallet() {
61
- return this.provider.wallet;
62
- }
63
- buildDepositTx(_0) {
64
- return __async$h(this, arguments, function* (amount, user = this.wallet.publicKey) {
65
- if (!user) {
66
- throw new Error(
67
- "DepositClient.buildDepositTx: wallet not connected"
68
- );
69
- }
70
- if (!amount || amount <= BigInt(0)) {
71
- throw new Error(
72
- "DepositClient.buildDepositTx: amount must be greater than zero."
73
- );
74
- }
75
- const depositAuthority = this.pgs.deriveDepositAuthorityPda();
76
- const liqsolMint = this.pgs.deriveLiqsolMintPda();
77
- const liqsolMintAuthority = this.pgs.deriveLiqsolMintAuthorityPda();
78
- const reservePool = this.pgs.deriveReservePoolPda();
79
- const vault = this.pgs.deriveVaultPda();
80
- const controllerState = this.pgs.deriveStakeControllerStatePda();
81
- const payoutState = this.pgs.derivePayoutStatePda();
82
- const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
83
- const payRateHistory = this.pgs.derivePayRateHistoryPda();
84
- const globalConfig = this.pgs.deriveGlobalConfigPda();
85
- const userAta = splToken.getAssociatedTokenAddressSync(
86
- liqsolMint,
87
- user,
88
- true,
89
- splToken.TOKEN_2022_PROGRAM_ID
90
- );
91
- const distributionState = this.pgs.deriveDistributionStatePda();
92
- const userRecord = this.pgs.deriveUserRecordPda(userAta);
93
- const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
94
- liqsolMint,
95
- bucketAuthority,
96
- true,
97
- splToken.TOKEN_2022_PROGRAM_ID
98
- );
99
- const seed = Math.floor(Math.random() * __pow(2, 32));
100
- const ephemeralStake = yield this.pgs.deriveEphemeralStakeAddress(user, seed);
101
- return yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
102
- user,
103
- depositAuthority,
104
- systemProgram: web3_js.SystemProgram.programId,
105
- tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
106
- associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
107
- liqsolProgram: this.pgs.PROGRAM_IDS.LIQSOL_TOKEN,
108
- stakeProgram: web3_js.StakeProgram.programId,
109
- liqsolMint,
110
- userAta,
111
- liqsolMintAuthority,
112
- reservePool,
113
- vault,
114
- ephemeralStake,
115
- controllerState,
116
- payoutState,
117
- bucketAuthority,
118
- bucketTokenAccount,
119
- userRecord,
120
- distributionState,
121
- payRateHistory,
122
- instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
123
- clock: web3_js.SYSVAR_CLOCK_PUBKEY,
124
- stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
125
- rent: web3_js.SYSVAR_RENT_PUBKEY,
126
- globalConfig
127
- }).instruction();
128
- });
129
- }
130
- buildWithdrawTx(_0) {
131
- return __async$h(this, arguments, function* (amount, user = this.wallet.publicKey) {
132
- if (!user) {
133
- throw new Error(
134
- "DepositClient.buildWithdrawTx: wallet not connected"
135
- );
136
- }
137
- if (!amount || amount <= BigInt(0)) {
138
- throw new Error(
139
- "DepositClient.buildWithdrawTx: amount must be greater than zero."
140
- );
141
- }
142
- const liqsolMint = this.pgs.deriveLiqsolMintPda();
143
- const userAta = splToken.getAssociatedTokenAddressSync(
144
- liqsolMint,
145
- user,
146
- true,
147
- splToken.TOKEN_2022_PROGRAM_ID
148
- );
149
- const userRecord = this.pgs.deriveUserRecordPda(userAta);
150
- const distributionState = this.pgs.deriveDistributionStatePda();
151
- const global = this.pgs.deriveWithdrawGlobalPda();
152
- const reservePool = this.pgs.deriveReservePoolPda();
153
- const stakeAllocationState = this.pgs.deriveStakeAllocationStatePda();
154
- const stakeMetrics = this.pgs.deriveStakeMetricsPda();
155
- const maintenanceLedger = this.pgs.deriveMaintenanceLedgerPda();
156
- const globalConfig = this.pgs.deriveGlobalConfigPda();
157
- const globalAcct = yield this.program.account.global.fetch(global);
158
- const rawId = globalAcct.nextReceiptId;
159
- let receiptId;
160
- if (typeof rawId === "bigint") {
161
- receiptId = rawId;
162
- } else if (rawId != null && typeof rawId === "object" && "toString" in rawId) {
163
- receiptId = BigInt(rawId.toString());
164
- } else if (typeof rawId === "number") {
165
- receiptId = BigInt(rawId);
166
- } else {
167
- throw new Error(
168
- `DepositClient.buildWithdrawTx: unexpected nextReceiptId type (${typeof rawId})`
169
- );
170
- }
171
- const mintAuthority = this.pgs.deriveWithdrawMintAuthorityPda();
172
- const metadata = this.pgs.deriveWithdrawMintMetadataPda();
173
- const nftMint = this.pgs.deriveWithdrawNftMintPda(receiptId);
174
- const receiptData = this.pgs.deriveLiqReceiptDataPda(nftMint);
175
- const owner = user;
176
- const nftAta = splToken.getAssociatedTokenAddressSync(
177
- nftMint,
178
- owner,
179
- true,
180
- splToken.TOKEN_2022_PROGRAM_ID
181
- );
182
- const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
183
- const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
184
- liqsolMint,
185
- bucketAuthority,
186
- true,
187
- splToken.TOKEN_2022_PROGRAM_ID
188
- );
189
- return yield this.program.methods.requestWithdraw(new anchor.BN(amount.toString())).accounts({
190
- user,
191
- owner,
192
- global,
193
- liqsolMint,
194
- userAta,
195
- userRecord,
196
- reservePool,
197
- stakeAllocationState,
198
- stakeMetrics,
199
- maintenanceLedger,
200
- clock: web3_js.SYSVAR_CLOCK_PUBKEY,
201
- mintAuthority,
202
- receiptData,
203
- metadata,
204
- nftMint,
205
- nftAta,
206
- distributionState,
207
- bucketTokenAccount,
208
- tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
209
- tokenInterface: splToken.TOKEN_2022_PROGRAM_ID,
210
- associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
211
- systemProgram: web3_js.SystemProgram.programId,
212
- rent: web3_js.SYSVAR_RENT_PUBKEY,
213
- globalConfig
214
- }).instruction();
215
22
  });
216
23
  }
24
+ n.default = e;
25
+ return Object.freeze(n);
217
26
  }
218
27
 
28
+ var multisig__namespace = /*#__PURE__*/_interopNamespaceDefault(multisig);
29
+
219
30
  var address$7 = "5nBtmutQLrRKBUxNfHJPDjiW5u8id6QM9Hhjg1D1g1XH";
220
31
  var metadata$7 = {
221
32
  name: "liqsol_core",
@@ -14638,7 +14449,7 @@ var devnetTransferHookIDL = {
14638
14449
  types: types$2
14639
14450
  };
14640
14451
 
14641
- var __async$g = (__this, __arguments, generator) => {
14452
+ var __async$h = (__this, __arguments, generator) => {
14642
14453
  return new Promise((resolve, reject) => {
14643
14454
  var fulfilled = (value) => {
14644
14455
  try {
@@ -14716,7 +14527,7 @@ const PDA_SEEDS = {
14716
14527
  LIQ_RECEIPT_DATA: "liq_receipt_data",
14717
14528
  WITHDRAW_MINT: "mint"
14718
14529
  };
14719
- const deriveEphemeralStakeAddress = (user, seed) => __async$g(null, null, function* () {
14530
+ const deriveEphemeralStakeAddress = (user, seed) => __async$h(null, null, function* () {
14720
14531
  const seedStr = `ephemeral_${seed}`;
14721
14532
  return web3_js.PublicKey.createWithSeed(user, seedStr, web3_js.StakeProgram.programId);
14722
14533
  });
@@ -14735,7 +14546,7 @@ const INDEX_SCALE$1 = BigInt(1e12);
14735
14546
  const lamportsToSol = (lamports) => Number(lamports) / LAMPORTS_PER_SOL;
14736
14547
  const solToLamports = (sol) => BigInt(Math.round(sol * LAMPORTS_PER_SOL));
14737
14548
 
14738
- var __async$f = (__this, __arguments, generator) => {
14549
+ var __async$g = (__this, __arguments, generator) => {
14739
14550
  return new Promise((resolve, reject) => {
14740
14551
  var fulfilled = (value) => {
14741
14552
  try {
@@ -14889,7 +14700,7 @@ function buildSolanaTrancheSnapshot(options) {
14889
14700
  };
14890
14701
  }
14891
14702
  function buildOutpostAccounts(connection, user, pgs) {
14892
- return __async$f(this, null, function* () {
14703
+ return __async$g(this, null, function* () {
14893
14704
  const globalState = pgs.deriveOutpostGlobalStatePda();
14894
14705
  const poolAuthority = pgs.deriveOutpostPoolAuthorityPda();
14895
14706
  const liqsolMint = pgs.deriveLiqsolMintPda();
@@ -14954,7 +14765,7 @@ function buildOutpostAccounts(connection, user, pgs) {
14954
14765
  });
14955
14766
  }
14956
14767
  function getEpochSnapshot(connection) {
14957
- return __async$f(this, null, function* () {
14768
+ return __async$g(this, null, function* () {
14958
14769
  var _a;
14959
14770
  const info = yield connection.getEpochInfo();
14960
14771
  let slotTimeMs = Number((_a = process.env.SLOT_TIME_MS_FALLBACK) != null ? _a : 400);
@@ -14985,7 +14796,7 @@ function msToEpochEnd(snapshot) {
14985
14796
  return remainingSlots * snapshot.slotMs;
14986
14797
  }
14987
14798
  function scheduledInstruction(connection, config, instruction) {
14988
- return __async$f(this, null, function* () {
14799
+ return __async$g(this, null, function* () {
14989
14800
  var _a, _b;
14990
14801
  const early = (_a = config.early) != null ? _a : 0.1;
14991
14802
  const late = (_b = config.late) != null ? _b : 0.9;
@@ -15032,14 +14843,14 @@ function generateTestKeypair() {
15032
14843
  return web3_js.Keypair.generate();
15033
14844
  }
15034
14845
  function airdropSol(connection, publicKey, amountSol) {
15035
- return __async$f(this, null, function* () {
14846
+ return __async$g(this, null, function* () {
15036
14847
  const lamports = solToLamports(amountSol);
15037
14848
  const sig = yield connection.requestAirdrop(publicKey, Number(lamports));
15038
14849
  yield connection.confirmTransaction(sig, "confirmed");
15039
14850
  });
15040
14851
  }
15041
14852
  function waitForConfirmation(connection, signature) {
15042
- return __async$f(this, null, function* () {
14853
+ return __async$g(this, null, function* () {
15043
14854
  yield connection.confirmTransaction(signature, "confirmed");
15044
14855
  });
15045
14856
  }
@@ -15047,8 +14858,8 @@ function sleep(ms) {
15047
14858
  return new Promise((resolve) => setTimeout(resolve, ms));
15048
14859
  }
15049
14860
  function waitUntilSafeToExecuteFunction(_0) {
15050
- return __async$f(this, arguments, function* (connection, config = {}) {
15051
- yield scheduledInstruction(connection, config, () => __async$f(null, null, function* () {
14861
+ return __async$g(this, arguments, function* (connection, config = {}) {
14862
+ yield scheduledInstruction(connection, config, () => __async$g(null, null, function* () {
15052
14863
  return;
15053
14864
  }));
15054
14865
  });
@@ -15059,6 +14870,283 @@ function ceilDiv(n, d) {
15059
14870
  }
15060
14871
  return n.add(d.subn(1)).div(d);
15061
14872
  }
14873
+ function normalizeToBigInt(x) {
14874
+ if (typeof x === "bigint") return x;
14875
+ if (x != null && typeof x === "object" && "toString" in x) return BigInt(x.toString());
14876
+ if (typeof x === "number") return BigInt(x);
14877
+ throw new Error(`normalizeToBigInt: unsupported type ${typeof x}`);
14878
+ }
14879
+
14880
+ var __pow = Math.pow;
14881
+ var __async$f = (__this, __arguments, generator) => {
14882
+ return new Promise((resolve, reject) => {
14883
+ var fulfilled = (value) => {
14884
+ try {
14885
+ step(generator.next(value));
14886
+ } catch (e) {
14887
+ reject(e);
14888
+ }
14889
+ };
14890
+ var rejected = (value) => {
14891
+ try {
14892
+ step(generator.throw(value));
14893
+ } catch (e) {
14894
+ reject(e);
14895
+ }
14896
+ };
14897
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
14898
+ step((generator = generator.apply(__this, __arguments)).next());
14899
+ });
14900
+ };
14901
+ let ConvertClient$1 = class ConvertClient {
14902
+ constructor(provider, pgs) {
14903
+ this.provider = provider;
14904
+ this.pgs = pgs;
14905
+ this.program = pgs.getProgram("liqsolCore");
14906
+ }
14907
+ get connection() {
14908
+ return this.provider.connection;
14909
+ }
14910
+ get wallet() {
14911
+ return this.provider.wallet;
14912
+ }
14913
+ buildDepositTx(_0) {
14914
+ return __async$f(this, arguments, function* (amount, user = this.wallet.publicKey) {
14915
+ if (!user) throw new Error("ConvertClient.buildDepositTx: wallet not connected");
14916
+ if (!amount || amount <= BigInt(0))
14917
+ throw new Error("ConvertClient.buildDepositTx: amount must be greater than zero.");
14918
+ const depositAuthority = this.pgs.deriveDepositAuthorityPda();
14919
+ const liqsolMint = this.pgs.deriveLiqsolMintPda();
14920
+ const liqsolMintAuthority = this.pgs.deriveLiqsolMintAuthorityPda();
14921
+ const reservePool = this.pgs.deriveReservePoolPda();
14922
+ const vault = this.pgs.deriveVaultPda();
14923
+ const controllerState = this.pgs.deriveStakeControllerStatePda();
14924
+ const payoutState = this.pgs.derivePayoutStatePda();
14925
+ const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
14926
+ const payRateHistory = this.pgs.derivePayRateHistoryPda();
14927
+ const globalConfig = this.pgs.deriveGlobalConfigPda();
14928
+ const userAta = splToken.getAssociatedTokenAddressSync(liqsolMint, user, true, splToken.TOKEN_2022_PROGRAM_ID);
14929
+ const distributionState = this.pgs.deriveDistributionStatePda();
14930
+ const userRecord = this.pgs.deriveUserRecordPda(userAta);
14931
+ const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
14932
+ liqsolMint,
14933
+ bucketAuthority,
14934
+ true,
14935
+ splToken.TOKEN_2022_PROGRAM_ID
14936
+ );
14937
+ const seed = Math.floor(Math.random() * __pow(2, 32));
14938
+ const ephemeralStake = yield this.pgs.deriveEphemeralStakeAddress(user, seed);
14939
+ return yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
14940
+ user,
14941
+ depositAuthority,
14942
+ systemProgram: web3_js.SystemProgram.programId,
14943
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
14944
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
14945
+ liqsolProgram: this.pgs.PROGRAM_IDS.LIQSOL_TOKEN,
14946
+ stakeProgram: web3_js.StakeProgram.programId,
14947
+ liqsolMint,
14948
+ userAta,
14949
+ liqsolMintAuthority,
14950
+ reservePool,
14951
+ vault,
14952
+ ephemeralStake,
14953
+ controllerState,
14954
+ payoutState,
14955
+ bucketAuthority,
14956
+ bucketTokenAccount,
14957
+ userRecord,
14958
+ distributionState,
14959
+ payRateHistory,
14960
+ instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
14961
+ clock: web3_js.SYSVAR_CLOCK_PUBKEY,
14962
+ stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
14963
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
14964
+ globalConfig
14965
+ }).instruction();
14966
+ });
14967
+ }
14968
+ buildWithdrawTx(_0) {
14969
+ return __async$f(this, arguments, function* (amount, user = this.wallet.publicKey) {
14970
+ if (!user) throw new Error("ConvertClient.buildWithdrawTx: wallet not connected");
14971
+ if (!amount || amount <= BigInt(0))
14972
+ throw new Error("ConvertClient.buildWithdrawTx: amount must be greater than zero.");
14973
+ const liqsolMint = this.pgs.deriveLiqsolMintPda();
14974
+ const userAta = splToken.getAssociatedTokenAddressSync(liqsolMint, user, true, splToken.TOKEN_2022_PROGRAM_ID);
14975
+ const userRecord = this.pgs.deriveUserRecordPda(userAta);
14976
+ const distributionState = this.pgs.deriveDistributionStatePda();
14977
+ const global = this.pgs.deriveWithdrawGlobalPda();
14978
+ const reservePool = this.pgs.deriveReservePoolPda();
14979
+ const stakeAllocationState = this.pgs.deriveStakeAllocationStatePda();
14980
+ const stakeMetrics = this.pgs.deriveStakeMetricsPda();
14981
+ const maintenanceLedger = this.pgs.deriveMaintenanceLedgerPda();
14982
+ const globalConfig = this.pgs.deriveGlobalConfigPda();
14983
+ const globalAcct = yield this.program.account.global.fetch(global);
14984
+ const rawId = globalAcct.nextReceiptId;
14985
+ const receiptId = normalizeToBigInt(rawId);
14986
+ const mintAuthority = this.pgs.deriveWithdrawMintAuthorityPda();
14987
+ const metadata = this.pgs.deriveWithdrawMintMetadataPda();
14988
+ const nftMint = this.pgs.deriveWithdrawNftMintPda(receiptId);
14989
+ const receiptData = this.pgs.deriveLiqReceiptDataPda(nftMint);
14990
+ const owner = user;
14991
+ const nftAta = splToken.getAssociatedTokenAddressSync(nftMint, owner, true, splToken.TOKEN_2022_PROGRAM_ID);
14992
+ const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
14993
+ const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
14994
+ liqsolMint,
14995
+ bucketAuthority,
14996
+ true,
14997
+ splToken.TOKEN_2022_PROGRAM_ID
14998
+ );
14999
+ return yield this.program.methods.requestWithdraw(new anchor.BN(amount.toString())).accounts({
15000
+ user,
15001
+ owner,
15002
+ global,
15003
+ liqsolMint,
15004
+ userAta,
15005
+ userRecord,
15006
+ reservePool,
15007
+ stakeAllocationState,
15008
+ stakeMetrics,
15009
+ maintenanceLedger,
15010
+ clock: web3_js.SYSVAR_CLOCK_PUBKEY,
15011
+ mintAuthority,
15012
+ receiptData,
15013
+ metadata,
15014
+ nftMint,
15015
+ nftAta,
15016
+ distributionState,
15017
+ bucketTokenAccount,
15018
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
15019
+ tokenInterface: splToken.TOKEN_2022_PROGRAM_ID,
15020
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
15021
+ systemProgram: web3_js.SystemProgram.programId,
15022
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
15023
+ globalConfig
15024
+ }).instruction();
15025
+ });
15026
+ }
15027
+ fetchWithdrawReceipts(owner) {
15028
+ return __async$f(this, null, function* () {
15029
+ var _a, _b, _c, _d;
15030
+ const globalPda = this.pgs.deriveWithdrawGlobalPda();
15031
+ const globalAcct = yield this.program.account.global.fetch(globalPda);
15032
+ const nextId = normalizeToBigInt(globalAcct.nextReceiptId);
15033
+ const mintToId = new Map();
15034
+ for (let i = BigInt(0); i < nextId; i++) {
15035
+ const mint = this.pgs.deriveWithdrawNftMintPda(i);
15036
+ mintToId.set(mint.toBase58(), i);
15037
+ }
15038
+ const tokenAccounts = yield this.connection.getParsedTokenAccountsByOwner(owner, {
15039
+ programId: splToken.TOKEN_2022_PROGRAM_ID
15040
+ });
15041
+ const receipts = [];
15042
+ for (const { pubkey, account } of tokenAccounts.value) {
15043
+ const info = (_b = (_a = account.data) == null ? void 0 : _a["parsed"]) == null ? void 0 : _b.info;
15044
+ if (!info) continue;
15045
+ const amount = info.tokenAmount;
15046
+ const decimals = Number((_c = amount == null ? void 0 : amount.decimals) != null ? _c : 0);
15047
+ const uiAmount = Number((_d = amount == null ? void 0 : amount.uiAmount) != null ? _d : 0);
15048
+ if (decimals !== 0 || uiAmount !== 1) continue;
15049
+ const mintStr = info.mint;
15050
+ if (!mintStr) continue;
15051
+ const receiptId = mintToId.get(mintStr);
15052
+ if (receiptId === void 0) continue;
15053
+ const mintKey = new web3_js.PublicKey(mintStr);
15054
+ const receiptDataPda = this.pgs.deriveLiqReceiptDataPda(mintKey);
15055
+ let receiptData;
15056
+ try {
15057
+ const raw = yield this.program.account.liqReceiptData.fetch(receiptDataPda);
15058
+ receiptData = {
15059
+ receiptId: normalizeToBigInt(raw.receiptId),
15060
+ liqports: normalizeToBigInt(raw.liqports),
15061
+ epoch: normalizeToBigInt(raw.epoch),
15062
+ fulfilled: Boolean(raw.fulfilled)
15063
+ };
15064
+ } catch (err) {
15065
+ console.warn(`ConvertClient: failed to fetch receipt data for mint ${mintStr}`, err);
15066
+ continue;
15067
+ }
15068
+ const { etaMs, readyAtMs } = yield this.estimateEpochEta(receiptData.epoch);
15069
+ const status = receiptData.fulfilled ? "claimed" : etaMs <= 0 ? "ready" : "queued";
15070
+ const amountView = {
15071
+ amount: receiptData.liqports,
15072
+ decimals: 9,
15073
+ symbol: "SOL"
15074
+ };
15075
+ receipts.push({
15076
+ tokenId: receiptData.receiptId,
15077
+ receipt: {
15078
+ amount: amountView,
15079
+ readyAt: readyAtMs,
15080
+ chain: "SOL",
15081
+ epoch: receiptData.epoch,
15082
+ status,
15083
+ mint: mintKey.toBase58(),
15084
+ ownerAta: pubkey.toBase58()
15085
+ }
15086
+ });
15087
+ }
15088
+ return receipts;
15089
+ });
15090
+ }
15091
+ buildClaimWithdrawTx(receiptId, user) {
15092
+ return __async$f(this, null, function* () {
15093
+ const mintAccount = this.pgs.deriveWithdrawNftMintPda(receiptId);
15094
+ const receiptData = this.pgs.deriveLiqReceiptDataPda(mintAccount);
15095
+ const ownerAta = splToken.getAssociatedTokenAddressSync(
15096
+ mintAccount,
15097
+ user,
15098
+ true,
15099
+ splToken.TOKEN_2022_PROGRAM_ID
15100
+ );
15101
+ const accounts = {
15102
+ user,
15103
+ global: this.pgs.deriveWithdrawGlobalPda(),
15104
+ mintAuthority: this.pgs.deriveWithdrawMintAuthorityPda(),
15105
+ receiptData,
15106
+ mintAccount,
15107
+ ownerAta,
15108
+ reservePool: this.pgs.deriveReservePoolPda(),
15109
+ vault: this.pgs.deriveVaultPda(),
15110
+ clock: web3_js.SYSVAR_CLOCK_PUBKEY,
15111
+ stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
15112
+ globalConfig: this.pgs.deriveGlobalConfigPda(),
15113
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
15114
+ stakeProgram: web3_js.StakeProgram.programId,
15115
+ systemProgram: web3_js.SystemProgram.programId,
15116
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID
15117
+ };
15118
+ return this.program.methods.claimWithdraw().accounts(accounts).instruction();
15119
+ });
15120
+ }
15121
+ estimateEpochEta(targetEpoch) {
15122
+ return __async$f(this, null, function* () {
15123
+ const conn = this.connection;
15124
+ const epochInfo = yield conn.getEpochInfo();
15125
+ const schedule = yield conn.getEpochSchedule();
15126
+ const currentEpoch = BigInt(epochInfo.epoch);
15127
+ if (targetEpoch <= currentEpoch) {
15128
+ const now = Date.now();
15129
+ return { etaMs: 0, readyAtMs: now };
15130
+ }
15131
+ let slotTimeSec = 0.4;
15132
+ try {
15133
+ const samples = yield conn.getRecentPerformanceSamples(1);
15134
+ if (samples == null ? void 0 : samples.length) {
15135
+ const s = samples[0];
15136
+ slotTimeSec = s.numSlots > 0 ? s.samplePeriodSecs / s.numSlots : slotTimeSec;
15137
+ }
15138
+ } catch (_) {
15139
+ }
15140
+ const slotsPerEpoch = BigInt(schedule.slotsPerEpoch);
15141
+ const slotsRemainingInCurrent = slotsPerEpoch - BigInt(epochInfo.slotIndex);
15142
+ const epochsRemaining = targetEpoch - currentEpoch - BigInt(1);
15143
+ const slotsRemaining = (epochsRemaining > 0 ? epochsRemaining * slotsPerEpoch : BigInt(0)) + slotsRemainingInCurrent;
15144
+ const etaSeconds = Number(slotsRemaining) * slotTimeSec;
15145
+ const etaMs = Math.max(0, Math.round(etaSeconds * 1e3));
15146
+ return { etaMs, readyAtMs: Date.now() + etaMs };
15147
+ });
15148
+ }
15149
+ };
15062
15150
 
15063
15151
  var __async$e = (__this, __arguments, generator) => {
15064
15152
  return new Promise((resolve, reject) => {
@@ -16027,7 +16115,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16027
16115
  commitment
16028
16116
  });
16029
16117
  this.program = new SolanaProgramService(this.anchor, config.network.chainId);
16030
- this.depositClient = new DepositClient(this.anchor, this.program);
16118
+ this.convertClient = new ConvertClient$1(this.anchor, this.program);
16031
16119
  this.distributionClient = new DistributionClient(this.anchor, this.program);
16032
16120
  this.leaderboardClient = new LeaderboardClient(this.anchor, this.program);
16033
16121
  this.outpostClient = new OutpostClient(this.anchor, this.program);
@@ -16056,7 +16144,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16056
16144
  if (amountLamports <= BigInt(0))
16057
16145
  throw new Error("Deposit amount must be greater than zero.");
16058
16146
  try {
16059
- const ix = yield this.depositClient.buildDepositTx(amountLamports, this.squadsVaultPDA);
16147
+ const ix = yield this.convertClient.buildDepositTx(amountLamports, this.squadsVaultPDA);
16060
16148
  return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
16061
16149
  } catch (err) {
16062
16150
  console.log(`Failed to deposit Solana: ${err}`);
@@ -16070,7 +16158,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16070
16158
  if (amountLamports <= BigInt(0))
16071
16159
  throw new Error("Withdraw amount must be greater than zero.");
16072
16160
  try {
16073
- const ix = yield this.depositClient.buildWithdrawTx(amountLamports, this.squadsVaultPDA);
16161
+ const ix = yield this.convertClient.buildWithdrawTx(amountLamports, this.squadsVaultPDA);
16074
16162
  return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
16075
16163
  } catch (err) {
16076
16164
  console.log(`Failed to withdraw Solana: ${err}`);
@@ -16078,6 +16166,28 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16078
16166
  }
16079
16167
  });
16080
16168
  }
16169
+ getPendingWithdraws() {
16170
+ return __async$9(this, null, function* () {
16171
+ var _a;
16172
+ this.ensureUser();
16173
+ const owner = (_a = this.squadsVaultPDA) != null ? _a : this.anchor.wallet.publicKey;
16174
+ return yield this.convertClient.fetchWithdrawReceipts(owner);
16175
+ });
16176
+ }
16177
+ claimWithdraw(tokenId) {
16178
+ return __async$9(this, null, function* () {
16179
+ var _a;
16180
+ this.ensureUser();
16181
+ const owner = (_a = this.squadsVaultPDA) != null ? _a : this.anchor.wallet.publicKey;
16182
+ try {
16183
+ const ix = yield this.convertClient.buildClaimWithdrawTx(tokenId, owner);
16184
+ return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
16185
+ } catch (err) {
16186
+ console.log(`Failed to claim withdraw on Solana: ${err}`);
16187
+ throw err;
16188
+ }
16189
+ });
16190
+ }
16081
16191
  stake(amountLamports) {
16082
16192
  return __async$9(this, null, function* () {
16083
16193
  this.ensureUser();
@@ -41823,34 +41933,6 @@ class ReceiptClient {
41823
41933
  return results;
41824
41934
  });
41825
41935
  }
41826
- getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
41827
- return __async$2(this, null, function* () {
41828
- var _a, _b;
41829
- const receiptContract = this.contract.ReceiptNFT;
41830
- const toLogs = yield receiptContract.queryFilter(
41831
- receiptContract.filters.Transfer(null, owner),
41832
- fromBlock,
41833
- toBlock
41834
- );
41835
- const fromLogs = yield receiptContract.queryFilter(
41836
- receiptContract.filters.Transfer(owner, null),
41837
- fromBlock,
41838
- toBlock
41839
- );
41840
- const owned = new Set();
41841
- for (const e of toLogs) {
41842
- const tokenId = (_a = e.args) == null ? void 0 : _a.tokenId;
41843
- if (!tokenId) continue;
41844
- owned.add(tokenId.toString());
41845
- }
41846
- for (const e of fromLogs) {
41847
- const tokenId = (_b = e.args) == null ? void 0 : _b.tokenId;
41848
- if (!tokenId) continue;
41849
- owned.delete(tokenId.toString());
41850
- }
41851
- return Array.from(owned).map((id) => ethers.BigNumber.from(id));
41852
- });
41853
- }
41854
41936
  fetchWithdrawReceipts(address) {
41855
41937
  return __async$2(this, null, function* () {
41856
41938
  const tokenIds = yield this.getOwnedWithdrawReceiptsFor(address);
@@ -41858,16 +41940,19 @@ class ReceiptClient {
41858
41940
  for (const idBN of tokenIds) {
41859
41941
  try {
41860
41942
  const receiptData = yield this.contract.WithdrawalQueue.info(idBN);
41943
+ const readyAtMs = Number(receiptData.readyAt) * 1e3;
41944
+ const status = readyAtMs <= Date.now() ? "ready" : "queued";
41861
41945
  results.push({
41862
41946
  tokenId: idBN.toBigInt(),
41863
41947
  receipt: {
41864
- ethAmount: receiptData.ethAmount,
41865
- ethBalance: {
41948
+ amount: {
41866
41949
  amount: receiptData.ethAmount.toBigInt(),
41867
41950
  decimals: 18,
41868
41951
  symbol: "ETH"
41869
41952
  },
41870
- readyAt: new Date(Number(receiptData.readyAt.toString()) * 1e3).valueOf()
41953
+ readyAt: readyAtMs,
41954
+ chain: "ETH",
41955
+ status
41871
41956
  }
41872
41957
  });
41873
41958
  } catch (err) {
@@ -41906,6 +41991,34 @@ class ReceiptClient {
41906
41991
  return Array.from(owned).map((id) => ethers.BigNumber.from(id));
41907
41992
  });
41908
41993
  }
41994
+ getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
41995
+ return __async$2(this, null, function* () {
41996
+ var _a, _b;
41997
+ const receiptContract = this.contract.ReceiptNFT;
41998
+ const toLogs = yield receiptContract.queryFilter(
41999
+ receiptContract.filters.Transfer(null, owner),
42000
+ fromBlock,
42001
+ toBlock
42002
+ );
42003
+ const fromLogs = yield receiptContract.queryFilter(
42004
+ receiptContract.filters.Transfer(owner, null),
42005
+ fromBlock,
42006
+ toBlock
42007
+ );
42008
+ const owned = new Set();
42009
+ for (const e of toLogs) {
42010
+ const tokenId = (_a = e.args) == null ? void 0 : _a.tokenId;
42011
+ if (!tokenId) continue;
42012
+ owned.add(tokenId.toString());
42013
+ }
42014
+ for (const e of fromLogs) {
42015
+ const tokenId = (_b = e.args) == null ? void 0 : _b.tokenId;
42016
+ if (!tokenId) continue;
42017
+ owned.delete(tokenId.toString());
42018
+ }
42019
+ return Array.from(owned).map((id) => ethers.BigNumber.from(id));
42020
+ });
42021
+ }
41909
42022
  }
41910
42023
 
41911
42024
  var __async$1 = (__this, __arguments, generator) => {
@@ -42036,7 +42149,7 @@ class EthereumStakingClient {
42036
42149
  return result.txHash;
42037
42150
  });
42038
42151
  }
42039
- loadPendingWithdraws() {
42152
+ getPendingWithdraws() {
42040
42153
  return __async(this, null, function* () {
42041
42154
  this.ensureUser();
42042
42155
  const address = yield this.signer.getAddress();
@@ -42364,12 +42477,12 @@ const CONTRACT_NAMES = [
42364
42477
  ];
42365
42478
 
42366
42479
  var types$1 = /*#__PURE__*/Object.freeze({
42367
- __proto__: null,
42368
- CONTRACT_NAMES: CONTRACT_NAMES
42480
+ __proto__: null,
42481
+ CONTRACT_NAMES: CONTRACT_NAMES
42369
42482
  });
42370
42483
 
42371
42484
  var types = /*#__PURE__*/Object.freeze({
42372
- __proto__: null
42485
+ __proto__: null
42373
42486
  });
42374
42487
 
42375
42488
  exports.ADDRESSES = ADDRESSES;
@@ -42377,9 +42490,9 @@ exports.ADDRESS_BOOK_BY_CHAIN = ADDRESS_BOOK_BY_CHAIN;
42377
42490
  exports.CHAINLINK_FEED = CHAINLINK_FEED;
42378
42491
  exports.CHAINLINK_PROGRAM = CHAINLINK_PROGRAM;
42379
42492
  exports.CONTRACTS_BY_CHAIN = CONTRACTS_BY_CHAIN;
42493
+ exports.ConvertClient = ConvertClient$1;
42380
42494
  exports.DEFAULT_AVERAGE_PAY_RATE = DEFAULT_AVERAGE_PAY_RATE;
42381
42495
  exports.DEFAULT_PAY_RATE_LOOKBACK = DEFAULT_PAY_RATE_LOOKBACK;
42382
- exports.DepositClient = DepositClient;
42383
42496
  exports.DistributionClient = DistributionClient;
42384
42497
  exports.EPHEMERAL_RENT_EXEMPTION = EPHEMERAL_RENT_EXEMPTION;
42385
42498
  exports.ERC1155Abi = ERC1155Abi;
@@ -42420,6 +42533,7 @@ exports.getErrorMessage = getErrorMessage;
42420
42533
  exports.getProgramIds = getProgramIds;
42421
42534
  exports.lamportsToSol = lamportsToSol;
42422
42535
  exports.msToEpochEnd = msToEpochEnd;
42536
+ exports.normalizeToBigInt = normalizeToBigInt;
42423
42537
  exports.scheduledInstruction = scheduledInstruction;
42424
42538
  exports.sleep = sleep;
42425
42539
  exports.solToLamports = solToLamports;