@wireio/stake 0.2.2 → 0.2.4

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
@@ -6,7 +6,16 @@ var anchor = require('@coral-xyz/anchor');
6
6
  var splToken = require('@solana/spl-token');
7
7
  var ethers = require('ethers');
8
8
 
9
- var address$2 = "HR3t8mA25TdJpwLph2h2L7KhK7ynWoAByYYzgUAfd5rk";
9
+ var PurchaseAsset = ((PurchaseAsset2) => {
10
+ PurchaseAsset2["SOL"] = "SOL";
11
+ PurchaseAsset2["LIQSOL"] = "LIQSOL";
12
+ PurchaseAsset2["ETH"] = "ETH";
13
+ PurchaseAsset2["LIQETH"] = "LIQETH";
14
+ PurchaseAsset2["YIELD"] = "YIELD";
15
+ return PurchaseAsset2;
16
+ })(PurchaseAsset || {});
17
+
18
+ var address$2 = "BBkVcNWNQz1vZ6esv5US4QnNFWPRqxWbdpJHur9GVXSu";
10
19
  var metadata$2 = {
11
20
  name: "liqsol_core",
12
21
  version: "0.1.0",
@@ -3186,58 +3195,8 @@ var events = [
3186
3195
  var errors$2 = [
3187
3196
  {
3188
3197
  code: 6000,
3189
- name: "NoRewardsToClaim",
3190
- msg: "No rewards to claim"
3191
- },
3192
- {
3193
- code: 6001,
3194
- name: "InsufficientBalance",
3195
- msg: "Insufficient balance"
3196
- },
3197
- {
3198
- code: 6002,
3199
- name: "InsufficientFunds",
3200
- msg: "Insufficient funds"
3201
- },
3202
- {
3203
- code: 6003,
3204
- name: "Unauthorized",
3205
- msg: "Unauthorized - caller is not the distribution authority"
3206
- },
3207
- {
3208
- code: 6004,
3209
- name: "InvalidMint",
3210
- msg: "Invalid mint"
3211
- },
3212
- {
3213
- code: 6005,
3214
- name: "InvalidOwner",
3215
- msg: "Invalid owner"
3216
- },
3217
- {
3218
- code: 6006,
3219
- name: "InvalidUserRecord",
3220
- msg: "Invalid user record"
3221
- },
3222
- {
3223
- code: 6007,
3224
- name: "InvalidWithdrawal",
3225
- msg: "Invalid withdrawal - balance increased instead of decreased"
3226
- },
3227
- {
3228
- code: 6008,
3229
- name: "InvalidProgramId",
3230
- msg: "Invalid program ID"
3231
- },
3232
- {
3233
- code: 6009,
3234
- name: "InstructionIntrospectionFailed",
3235
- msg: "Instruction introspection failed"
3236
- },
3237
- {
3238
- code: 6010,
3239
- name: "ReceiptFulfilled",
3240
- msg: "Receipt already fulfilled"
3198
+ name: "AccountBorrowFailed",
3199
+ msg: "Util Acc borrow Failed"
3241
3200
  }
3242
3201
  ];
3243
3202
  var types$4 = [
@@ -4521,7 +4480,7 @@ var liqsolCoreIDL = {
4521
4480
  types: types$4
4522
4481
  };
4523
4482
 
4524
- var address$1 = "HEAKvfg2X7K4zbGDiAbfuu5abxQyk1HbKVgskZZFXrUx";
4483
+ var address$1 = "6cDoerqdV6UQDsGvUEq5Qj5HRxxyDxSuUaB2J6iK8cio";
4525
4484
  var metadata$1 = {
4526
4485
  name: "liqsol_token",
4527
4486
  version: "0.1.0",
@@ -4710,7 +4669,7 @@ var liqsolTokenJson = {
4710
4669
  types: types$3
4711
4670
  };
4712
4671
 
4713
- var address = "BcMW7wN54FexYaB7Xujvag5uUQ1WoDoGbzVg1VEXPBhV";
4672
+ var address = "C4ddPrB1ALYpW4G1Qz4ffvETBA8YGUL7TVZaLiE6bb1q";
4714
4673
  var metadata = {
4715
4674
  name: "validator_leaderboard",
4716
4675
  version: "0.1.0",
@@ -5295,7 +5254,7 @@ var validatorLeaderboardJson = {
5295
5254
  types: types$2
5296
5255
  };
5297
5256
 
5298
- var __async$a = (__this, __arguments, generator) => {
5257
+ var __async$b = (__this, __arguments, generator) => {
5299
5258
  return new Promise((resolve, reject) => {
5300
5259
  var fulfilled = (value) => {
5301
5260
  try {
@@ -5348,7 +5307,8 @@ const PDA_SEEDS = {
5348
5307
  USER_WARRANT_RECORD: "user_warrant_record",
5349
5308
  BAR_STATE_SEED: "bar_state",
5350
5309
  BONDED_ACTOR_SEED: "bonded_actor",
5351
- BOND_LEVEL_SEED: "bond_level"
5310
+ BOND_LEVEL_SEED: "bond_level",
5311
+ PRICE_HISTORY: "price_history"
5352
5312
  };
5353
5313
  const deriveLiqsolMintPda = () => web3_js.PublicKey.findProgramAddressSync(
5354
5314
  [Buffer.from(PDA_SEEDS.LIQSOL_MINT)],
@@ -5450,7 +5410,11 @@ const deriveBondedActorPda = (actor) => web3_js.PublicKey.findProgramAddressSync
5450
5410
  [Buffer.from(PDA_SEEDS.BONDED_ACTOR_SEED), actor.toBuffer()],
5451
5411
  LIQSOL_CORE
5452
5412
  )[0];
5453
- const deriveEphemeralStakeAddress = (user, seed) => __async$a(null, null, function* () {
5413
+ const derivePriceHistoryPda = () => web3_js.PublicKey.findProgramAddressSync(
5414
+ [Buffer.from(PDA_SEEDS.PRICE_HISTORY)],
5415
+ LIQSOL_CORE
5416
+ )[0];
5417
+ const deriveEphemeralStakeAddress = (user, seed) => __async$b(null, null, function* () {
5454
5418
  const seedStr = `ephemeral_${seed}`;
5455
5419
  return yield web3_js.PublicKey.createWithSeed(user, seedStr, web3_js.StakeProgram.programId);
5456
5420
  });
@@ -5512,7 +5476,7 @@ class SolanaProgramService {
5512
5476
  }
5513
5477
 
5514
5478
  var __pow = Math.pow;
5515
- var __async$9 = (__this, __arguments, generator) => {
5479
+ var __async$a = (__this, __arguments, generator) => {
5516
5480
  return new Promise((resolve, reject) => {
5517
5481
  var fulfilled = (value) => {
5518
5482
  try {
@@ -5542,7 +5506,7 @@ let DepositClient$1 = class DepositClient {
5542
5506
  return this.provider.wallet;
5543
5507
  }
5544
5508
  buildDepositTx(_0) {
5545
- return __async$9(this, arguments, function* (amount, user = this.wallet.publicKey) {
5509
+ return __async$a(this, arguments, function* (amount, user = this.wallet.publicKey) {
5546
5510
  const depositAuthority = deriveDepositAuthorityPda();
5547
5511
  const liqsolMint = deriveLiqsolMintPda();
5548
5512
  const liqsolMintAuthority = deriveLiqsolMintAuthorityPda();
@@ -5599,7 +5563,7 @@ let DepositClient$1 = class DepositClient {
5599
5563
  }
5600
5564
  };
5601
5565
 
5602
- var __async$8 = (__this, __arguments, generator) => {
5566
+ var __async$9 = (__this, __arguments, generator) => {
5603
5567
  return new Promise((resolve, reject) => {
5604
5568
  var fulfilled = (value) => {
5605
5569
  try {
@@ -5629,7 +5593,7 @@ class DistributionClient {
5629
5593
  return this.provider.connection;
5630
5594
  }
5631
5595
  getDistributionState() {
5632
- return __async$8(this, null, function* () {
5596
+ return __async$9(this, null, function* () {
5633
5597
  const pda = deriveDistributionStatePda();
5634
5598
  try {
5635
5599
  return yield this.program.account.distributionState.fetch(pda);
@@ -5639,7 +5603,7 @@ class DistributionClient {
5639
5603
  });
5640
5604
  }
5641
5605
  getUserRecord(user) {
5642
- return __async$8(this, null, function* () {
5606
+ return __async$9(this, null, function* () {
5643
5607
  const pda = deriveUserRecordPda(user);
5644
5608
  try {
5645
5609
  return yield this.program.account.userRecord.fetchNullable(pda);
@@ -5649,7 +5613,7 @@ class DistributionClient {
5649
5613
  });
5650
5614
  }
5651
5615
  getActualBalancesByOwner() {
5652
- return __async$8(this, null, function* () {
5616
+ return __async$9(this, null, function* () {
5653
5617
  var _a;
5654
5618
  const liqsolMint = deriveLiqsolMintPda();
5655
5619
  const mintStr = liqsolMint.toBase58();
@@ -5678,7 +5642,7 @@ class DistributionClient {
5678
5642
  });
5679
5643
  }
5680
5644
  getTrackedBalances() {
5681
- return __async$8(this, null, function* () {
5645
+ return __async$9(this, null, function* () {
5682
5646
  var _a;
5683
5647
  const records = yield this.program.account.userRecord.all();
5684
5648
  const map = new Map();
@@ -5700,7 +5664,7 @@ class DistributionClient {
5700
5664
  });
5701
5665
  }
5702
5666
  deriveMismatchCandidates() {
5703
- return __async$8(this, null, function* () {
5667
+ return __async$9(this, null, function* () {
5704
5668
  var _a;
5705
5669
  const [actualByOwner, trackedByOwner] = yield Promise.all([
5706
5670
  this.getActualBalancesByOwner(),
@@ -5719,7 +5683,7 @@ class DistributionClient {
5719
5683
  });
5720
5684
  }
5721
5685
  buildUpdateUserIx(targetUser) {
5722
- return __async$8(this, null, function* () {
5686
+ return __async$9(this, null, function* () {
5723
5687
  const walletPk = this.provider.wallet.publicKey;
5724
5688
  const distributionStatePDA = deriveDistributionStatePda();
5725
5689
  const userRecordPDA = deriveUserRecordPda(targetUser);
@@ -5756,7 +5720,7 @@ class DistributionClient {
5756
5720
  });
5757
5721
  }
5758
5722
  buildCorrectRegisterTx() {
5759
- return __async$8(this, arguments, function* (opts = {}) {
5723
+ return __async$9(this, arguments, function* (opts = {}) {
5760
5724
  var _a, _b, _c;
5761
5725
  const walletPk = this.provider.wallet.publicKey;
5762
5726
  const callerStr = walletPk.toBase58();
@@ -5842,7 +5806,7 @@ class DistributionClient {
5842
5806
  }
5843
5807
  }
5844
5808
 
5845
- var __async$7 = (__this, __arguments, generator) => {
5809
+ var __async$8 = (__this, __arguments, generator) => {
5846
5810
  return new Promise((resolve, reject) => {
5847
5811
  var fulfilled = (value) => {
5848
5812
  try {
@@ -5869,7 +5833,7 @@ class LeaderboardClient {
5869
5833
  this.program = svc.getProgram("validatorLeaderboard");
5870
5834
  }
5871
5835
  getState() {
5872
- return __async$7(this, null, function* () {
5836
+ return __async$8(this, null, function* () {
5873
5837
  const pda = deriveLeaderboardStatePda();
5874
5838
  try {
5875
5839
  return yield this.program.account.leaderboardState.fetch(pda);
@@ -5879,7 +5843,7 @@ class LeaderboardClient {
5879
5843
  });
5880
5844
  }
5881
5845
  getValidatorRecord(voteAccount) {
5882
- return __async$7(this, null, function* () {
5846
+ return __async$8(this, null, function* () {
5883
5847
  const pda = deriveValidatorRecordPda(voteAccount);
5884
5848
  try {
5885
5849
  return yield this.program.account.validatorRecord.fetchNullable(pda);
@@ -5889,7 +5853,7 @@ class LeaderboardClient {
5889
5853
  });
5890
5854
  }
5891
5855
  getTopValidators(limit = 20) {
5892
- return __async$7(this, null, function* () {
5856
+ return __async$8(this, null, function* () {
5893
5857
  const records = yield this.program.account.validatorRecord.all();
5894
5858
  const sorted = records.sort(
5895
5859
  (a, b) => {
@@ -5904,7 +5868,7 @@ class LeaderboardClient {
5904
5868
  }
5905
5869
  }
5906
5870
 
5907
- var __async$6 = (__this, __arguments, generator) => {
5871
+ var __async$7 = (__this, __arguments, generator) => {
5908
5872
  return new Promise((resolve, reject) => {
5909
5873
  var fulfilled = (value) => {
5910
5874
  try {
@@ -5924,15 +5888,138 @@ var __async$6 = (__this, __arguments, generator) => {
5924
5888
  step((generator = generator.apply(__this, __arguments)).next());
5925
5889
  });
5926
5890
  };
5891
+ const INDEX_SCALE = BigInt(1e12);
5892
+ BigInt(1e8);
5893
+ const BPS = BigInt(1e4);
5894
+ function toBigint(x) {
5895
+ if (typeof x === "bigint") return x;
5896
+ if (typeof x === "number") return BigInt(x);
5897
+ return BigInt(x.toString());
5898
+ }
5899
+ function tokensToShares(amount, currentIndex) {
5900
+ if (amount === BigInt(0)) return BigInt(0);
5901
+ const num = amount * INDEX_SCALE;
5902
+ const q = num / currentIndex;
5903
+ const r = num % currentIndex;
5904
+ return r === BigInt(0) ? q : q + BigInt(1);
5905
+ }
5906
+ function growOnce(value, growthBps) {
5907
+ const g = BigInt(growthBps);
5908
+ return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
5909
+ }
5910
+ function shrinkOnce(value, growthBps) {
5911
+ const g = BigInt(growthBps);
5912
+ return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
5913
+ }
5914
+ function buildSolanaTrancheLadder(options) {
5915
+ const {
5916
+ currentTranche,
5917
+ initialTrancheSupply,
5918
+ currentTrancheSupply,
5919
+ currentPriceUsd,
5920
+ supplyGrowthBps,
5921
+ priceGrowthBps,
5922
+ windowBefore = 5,
5923
+ windowAfter = 5
5924
+ } = options;
5925
+ const startId = Math.max(0, currentTranche - windowBefore);
5926
+ const endId = currentTranche + windowAfter;
5927
+ const capacity = new Map();
5928
+ const price = new Map();
5929
+ capacity.set(currentTranche, initialTrancheSupply);
5930
+ price.set(currentTranche, currentPriceUsd);
5931
+ for (let id = currentTranche + 1; id <= endId; id++) {
5932
+ const prevCap = capacity.get(id - 1);
5933
+ const prevPrice = price.get(id - 1);
5934
+ capacity.set(id, growOnce(prevCap, supplyGrowthBps));
5935
+ price.set(id, growOnce(prevPrice, priceGrowthBps));
5936
+ }
5937
+ for (let id = currentTranche - 1; id >= startId; id--) {
5938
+ const nextCap = capacity.get(id + 1);
5939
+ const nextPrice = price.get(id + 1);
5940
+ capacity.set(id, shrinkOnce(nextCap, supplyGrowthBps));
5941
+ price.set(id, shrinkOnce(nextPrice, priceGrowthBps));
5942
+ }
5943
+ const ladder = [];
5944
+ for (let id = startId; id <= endId; id++) {
5945
+ const cap = capacity.get(id);
5946
+ let sold;
5947
+ if (id < currentTranche) {
5948
+ sold = cap;
5949
+ } else if (id === currentTranche) {
5950
+ sold = cap - currentTrancheSupply;
5951
+ } else {
5952
+ sold = BigInt(0);
5953
+ }
5954
+ ladder.push({
5955
+ id,
5956
+ capacity: cap,
5957
+ sold,
5958
+ remaining: cap - sold,
5959
+ priceUsd: price.get(id)
5960
+ });
5961
+ }
5962
+ return ladder;
5963
+ }
5964
+ function buildSolanaTrancheSnapshot(options) {
5965
+ const {
5966
+ chainID,
5967
+ globalState,
5968
+ trancheState,
5969
+ solPriceUsd,
5970
+ nativePriceTimestamp,
5971
+ ladderWindowBefore,
5972
+ ladderWindowAfter
5973
+ } = options;
5974
+ const currentIndex = toBigint(globalState.currentIndex);
5975
+ const totalShares = toBigint(globalState.totalShares);
5976
+ const currentTranche = trancheState.currentTrancheNumber.toNumber();
5977
+ const currentTrancheSupply = toBigint(trancheState.currentTrancheSupply);
5978
+ const initialTrancheSupply = toBigint(trancheState.initialTrancheSupply);
5979
+ const totalWarrantsSold = toBigint(trancheState.totalWarrantsSold);
5980
+ const currentPriceUsd = toBigint(trancheState.currentTranchePriceUsd);
5981
+ const supplyGrowthBps = trancheState.supplyGrowthBps;
5982
+ const priceGrowthBps = trancheState.priceGrowthBps;
5983
+ const minPriceUsd = trancheState.minPriceUsd ? toBigint(trancheState.minPriceUsd) : void 0;
5984
+ const maxPriceUsd = trancheState.maxPriceUsd ? toBigint(trancheState.maxPriceUsd) : void 0;
5985
+ const ladder = buildSolanaTrancheLadder({
5986
+ currentTranche,
5987
+ initialTrancheSupply,
5988
+ currentTrancheSupply,
5989
+ totalWarrantsSold,
5990
+ currentPriceUsd,
5991
+ supplyGrowthBps,
5992
+ priceGrowthBps,
5993
+ windowBefore: ladderWindowBefore,
5994
+ windowAfter: ladderWindowAfter
5995
+ });
5996
+ return {
5997
+ chainID,
5998
+ currentIndex,
5999
+ totalShares,
6000
+ currentTranche,
6001
+ currentPriceUsd,
6002
+ minPriceUsd,
6003
+ maxPriceUsd,
6004
+ supplyGrowthBps,
6005
+ priceGrowthBps,
6006
+ currentTrancheSupply,
6007
+ initialTrancheSupply,
6008
+ totalWarrantsSold,
6009
+ nativePriceUsd: solPriceUsd,
6010
+ nativePriceTimestamp,
6011
+ ladder
6012
+ };
6013
+ }
5927
6014
  let _liqsolCoreProgram = null;
5928
6015
  function getLiqsolCoreProgram(connection) {
5929
6016
  if (_liqsolCoreProgram && _liqsolCoreProgram.provider.connection === connection) {
5930
6017
  return _liqsolCoreProgram;
5931
6018
  }
5932
6019
  const tmpKeypair = web3_js.Keypair.generate();
5933
- const wallet = { publicKey: tmpKeypair.publicKey, signAllTransactions: () => __async$6(null, null, function* () {
6020
+ const wallet = { publicKey: tmpKeypair.publicKey, signAllTransactions: () => __async$7(null, null, function* () {
5934
6021
  return [];
5935
- }), signTransaction: () => __async$6(null, null, function* () {
6022
+ }), signTransaction: () => __async$7(null, null, function* () {
5936
6023
  return tmpKeypair;
5937
6024
  }) };
5938
6025
  const provider = new anchor.AnchorProvider(connection, wallet, {
@@ -5946,7 +6033,7 @@ function getLiqsolCoreProgram(connection) {
5946
6033
  return program;
5947
6034
  }
5948
6035
  function getUserLiqSolBalance(connection, user) {
5949
- return __async$6(this, null, function* () {
6036
+ return __async$7(this, null, function* () {
5950
6037
  const liqsolMint = deriveLiqsolMintPda();
5951
6038
  const ata = yield splToken.getAssociatedTokenAddress(
5952
6039
  liqsolMint,
@@ -5963,7 +6050,7 @@ function getUserLiqSolBalance(connection, user) {
5963
6050
  });
5964
6051
  }
5965
6052
  function getBucketLiqSolBalance(connection) {
5966
- return __async$6(this, null, function* () {
6053
+ return __async$7(this, null, function* () {
5967
6054
  const liqsolMint = deriveLiqsolMintPda();
5968
6055
  const bucketAuthority = deriveBucketAuthorityPda();
5969
6056
  const ata = yield splToken.getAssociatedTokenAddress(
@@ -5981,7 +6068,7 @@ function getBucketLiqSolBalance(connection) {
5981
6068
  });
5982
6069
  }
5983
6070
  function getReservePoolBalance(connection) {
5984
- return __async$6(this, null, function* () {
6071
+ return __async$7(this, null, function* () {
5985
6072
  const reservePool = deriveReservePoolPda();
5986
6073
  try {
5987
6074
  const lamports = yield connection.getBalance(reservePool);
@@ -5992,7 +6079,7 @@ function getReservePoolBalance(connection) {
5992
6079
  });
5993
6080
  }
5994
6081
  function getStakeControllerStateRaw(connection) {
5995
- return __async$6(this, null, function* () {
6082
+ return __async$7(this, null, function* () {
5996
6083
  var _a;
5997
6084
  const pda = deriveStakeControllerStatePda();
5998
6085
  const info = yield connection.getAccountInfo(pda);
@@ -6000,7 +6087,7 @@ function getStakeControllerStateRaw(connection) {
6000
6087
  });
6001
6088
  }
6002
6089
  function getPayoutStateRaw(connection) {
6003
- return __async$6(this, null, function* () {
6090
+ return __async$7(this, null, function* () {
6004
6091
  var _a;
6005
6092
  const pda = derivePayoutStatePda();
6006
6093
  const info = yield connection.getAccountInfo(pda);
@@ -6008,7 +6095,7 @@ function getPayoutStateRaw(connection) {
6008
6095
  });
6009
6096
  }
6010
6097
  function getUserRecordRaw(connection, user) {
6011
- return __async$6(this, null, function* () {
6098
+ return __async$7(this, null, function* () {
6012
6099
  var _a;
6013
6100
  const pda = deriveUserRecordPda(user);
6014
6101
  const info = yield connection.getAccountInfo(pda);
@@ -6016,7 +6103,7 @@ function getUserRecordRaw(connection, user) {
6016
6103
  });
6017
6104
  }
6018
6105
  function getAveragePayRate(_0) {
6019
- return __async$6(this, arguments, function* (connection, lookback = DEFAULT_PAY_RATE_LOOKBACK) {
6106
+ return __async$7(this, arguments, function* (connection, lookback = DEFAULT_PAY_RATE_LOOKBACK) {
6020
6107
  var _a, _b, _c, _d;
6021
6108
  const program = getLiqsolCoreProgram(connection);
6022
6109
  const payRateHistoryPda = derivePayRateHistoryPda();
@@ -6090,7 +6177,7 @@ function previewDepositEffects(params) {
6090
6177
  };
6091
6178
  }
6092
6179
  function buildOutpostAccounts(connection, user) {
6093
- return __async$6(this, null, function* () {
6180
+ return __async$7(this, null, function* () {
6094
6181
  const globalState = deriveOutpostGlobalStatePda();
6095
6182
  const poolAuthority = deriveOutpostPoolAuthorityPda();
6096
6183
  const liqsolMint = deriveLiqsolMintPda();
@@ -6121,8 +6208,17 @@ function buildOutpostAccounts(connection, user) {
6121
6208
  false,
6122
6209
  splToken.TOKEN_2022_PROGRAM_ID
6123
6210
  );
6124
- const chainLinkFeed = CHAINLINK_FEED;
6125
- const chainLinkProgram = CHAINLINK_PROGRAM;
6211
+ let chainLinkFeed = CHAINLINK_FEED;
6212
+ let chainLinkProgram = CHAINLINK_PROGRAM;
6213
+ try {
6214
+ const program = getLiqsolCoreProgram(connection);
6215
+ const ts = yield program.account.trancheState.fetch(trancheState);
6216
+ if (ts.chainlinkFeed && ts.chainlinkProgram) {
6217
+ chainLinkFeed = ts.chainlinkFeed;
6218
+ chainLinkProgram = ts.chainlinkProgram;
6219
+ }
6220
+ } catch (e) {
6221
+ }
6126
6222
  return {
6127
6223
  user,
6128
6224
  globalState,
@@ -6146,7 +6242,7 @@ function buildOutpostAccounts(connection, user) {
6146
6242
  });
6147
6243
  }
6148
6244
  function getEpochSnapshot(connection) {
6149
- return __async$6(this, null, function* () {
6245
+ return __async$7(this, null, function* () {
6150
6246
  var _a;
6151
6247
  const info = yield connection.getEpochInfo();
6152
6248
  let slotTimeMs = Number((_a = process.env.SLOT_TIME_MS_FALLBACK) != null ? _a : 400);
@@ -6177,7 +6273,7 @@ function msToEpochEnd(snapshot) {
6177
6273
  return remainingSlots * snapshot.slotMs;
6178
6274
  }
6179
6275
  function scheduledInstruction(connection, config, instruction) {
6180
- return __async$6(this, null, function* () {
6276
+ return __async$7(this, null, function* () {
6181
6277
  var _a, _b;
6182
6278
  const early = (_a = config.early) != null ? _a : 0.1;
6183
6279
  const late = (_b = config.late) != null ? _b : 0.9;
@@ -6224,14 +6320,14 @@ function generateTestKeypair() {
6224
6320
  return web3_js.Keypair.generate();
6225
6321
  }
6226
6322
  function airdropSol(connection, publicKey, amountSol) {
6227
- return __async$6(this, null, function* () {
6323
+ return __async$7(this, null, function* () {
6228
6324
  const lamports = solToLamports(amountSol);
6229
6325
  const sig = yield connection.requestAirdrop(publicKey, Number(lamports));
6230
6326
  yield connection.confirmTransaction(sig, "confirmed");
6231
6327
  });
6232
6328
  }
6233
6329
  function waitForConfirmation(connection, signature) {
6234
- return __async$6(this, null, function* () {
6330
+ return __async$7(this, null, function* () {
6235
6331
  yield connection.confirmTransaction(signature, "confirmed");
6236
6332
  });
6237
6333
  }
@@ -6239,14 +6335,14 @@ function sleep(ms) {
6239
6335
  return new Promise((resolve) => setTimeout(resolve, ms));
6240
6336
  }
6241
6337
  function waitUntilSafeToExecuteFunction(_0) {
6242
- return __async$6(this, arguments, function* (connection, config = {}) {
6243
- yield scheduledInstruction(connection, config, () => __async$6(null, null, function* () {
6338
+ return __async$7(this, arguments, function* (connection, config = {}) {
6339
+ yield scheduledInstruction(connection, config, () => __async$7(null, null, function* () {
6244
6340
  return;
6245
6341
  }));
6246
6342
  });
6247
6343
  }
6248
6344
 
6249
- var __async$5 = (__this, __arguments, generator) => {
6345
+ var __async$6 = (__this, __arguments, generator) => {
6250
6346
  return new Promise((resolve, reject) => {
6251
6347
  var fulfilled = (value) => {
6252
6348
  try {
@@ -6299,7 +6395,7 @@ const _OutpostClient = class _OutpostClient {
6299
6395
  return `${intPart}.${decPart}`;
6300
6396
  }
6301
6397
  previewExpectedShares(params) {
6302
- return __async$5(this, null, function* () {
6398
+ return __async$6(this, null, function* () {
6303
6399
  var _a;
6304
6400
  const user = (_a = params.user) != null ? _a : this.wallet.publicKey;
6305
6401
  const accounts = yield buildOutpostAccounts(this.connection, user);
@@ -6318,14 +6414,14 @@ const _OutpostClient = class _OutpostClient {
6318
6414
  });
6319
6415
  }
6320
6416
  doesUserAtaExist() {
6321
- return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6417
+ return __async$6(this, arguments, function* (user = this.wallet.publicKey) {
6322
6418
  const accounts = yield buildOutpostAccounts(this.connection, user);
6323
6419
  const info = yield this.connection.getAccountInfo(accounts.userAta);
6324
6420
  return !!info;
6325
6421
  });
6326
6422
  }
6327
6423
  buildCreateUserAtaIx() {
6328
- return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6424
+ return __async$6(this, arguments, function* (user = this.wallet.publicKey) {
6329
6425
  const accounts = yield buildOutpostAccounts(this.connection, user);
6330
6426
  return splToken.createAssociatedTokenAccountInstruction(
6331
6427
  this.wallet.publicKey,
@@ -6338,7 +6434,7 @@ const _OutpostClient = class _OutpostClient {
6338
6434
  });
6339
6435
  }
6340
6436
  maybeBuildCreateUserAtaIx() {
6341
- return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6437
+ return __async$6(this, arguments, function* (user = this.wallet.publicKey) {
6342
6438
  const accounts = yield buildOutpostAccounts(this.connection, user);
6343
6439
  const info = yield this.connection.getAccountInfo(accounts.userAta);
6344
6440
  if (info) return [];
@@ -6346,7 +6442,7 @@ const _OutpostClient = class _OutpostClient {
6346
6442
  });
6347
6443
  }
6348
6444
  getWireStateSnapshot() {
6349
- return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6445
+ return __async$6(this, arguments, function* (user = this.wallet.publicKey) {
6350
6446
  const accounts = yield buildOutpostAccounts(this.connection, user);
6351
6447
  const [
6352
6448
  globalState,
@@ -6383,25 +6479,25 @@ const _OutpostClient = class _OutpostClient {
6383
6479
  });
6384
6480
  }
6385
6481
  getWireReceipt() {
6386
- return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6482
+ return __async$6(this, arguments, function* (user = this.wallet.publicKey) {
6387
6483
  const accounts = yield buildOutpostAccounts(this.connection, user);
6388
6484
  return this.program.account.wireReceipt.fetchNullable(accounts.wireReceipt);
6389
6485
  });
6390
6486
  }
6391
6487
  getTrancheState() {
6392
- return __async$5(this, null, function* () {
6488
+ return __async$6(this, null, function* () {
6393
6489
  const accounts = yield buildOutpostAccounts(this.connection, this.wallet.publicKey);
6394
6490
  return this.program.account.trancheState.fetchNullable(accounts.trancheState);
6395
6491
  });
6396
6492
  }
6397
6493
  getUserWarrantRecord() {
6398
- return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6494
+ return __async$6(this, arguments, function* (user = this.wallet.publicKey) {
6399
6495
  const accounts = yield buildOutpostAccounts(this.connection, user);
6400
6496
  return this.program.account.userWarrantRecord.fetchNullable(accounts.userWarrantRecord);
6401
6497
  });
6402
6498
  }
6403
6499
  buildStakeLiqsolIx(_0) {
6404
- return __async$5(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6500
+ return __async$6(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6405
6501
  const a = yield buildOutpostAccounts(this.connection, userPubKey);
6406
6502
  const amount = new anchor.BN(amountLamports.toString());
6407
6503
  return this.program.methods.stakeLiqsol(amount).accounts({
@@ -6425,7 +6521,7 @@ const _OutpostClient = class _OutpostClient {
6425
6521
  });
6426
6522
  }
6427
6523
  buildWithdrawStakeIx(_0) {
6428
- return __async$5(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6524
+ return __async$6(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6429
6525
  const a = yield buildOutpostAccounts(this.connection, userPubKey);
6430
6526
  const amount = new anchor.BN(amountLamports.toString());
6431
6527
  return this.program.methods.withdrawStake(amount).accounts({
@@ -6448,7 +6544,7 @@ const _OutpostClient = class _OutpostClient {
6448
6544
  });
6449
6545
  }
6450
6546
  buildPurchaseWithLiqsolIx(_0) {
6451
- return __async$5(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6547
+ return __async$6(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6452
6548
  const a = yield buildOutpostAccounts(this.connection, userPubKey);
6453
6549
  const amount = new anchor.BN(amountLamports.toString());
6454
6550
  return this.program.methods.purchaseWithLiqsol(amount).accounts({
@@ -6476,7 +6572,7 @@ const _OutpostClient = class _OutpostClient {
6476
6572
  });
6477
6573
  }
6478
6574
  buildPurchaseWithSolIx(_0) {
6479
- return __async$5(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6575
+ return __async$6(this, arguments, function* (amountLamports, userPubKey = this.wallet.publicKey) {
6480
6576
  const a = yield buildOutpostAccounts(this.connection, userPubKey);
6481
6577
  const amount = new anchor.BN(amountLamports.toString());
6482
6578
  return this.program.methods.purchaseWithSol(amount).accounts({
@@ -6502,7 +6598,7 @@ const _OutpostClient = class _OutpostClient {
6502
6598
  });
6503
6599
  }
6504
6600
  buildPurchaseFromYieldIx() {
6505
- return __async$5(this, arguments, function* (userPubKey = this.wallet.publicKey) {
6601
+ return __async$6(this, arguments, function* (userPubKey = this.wallet.publicKey) {
6506
6602
  const a = yield buildOutpostAccounts(this.connection, userPubKey);
6507
6603
  return this.program.methods.purchaseWarrantsFromYield().accounts({
6508
6604
  user: a.user,
@@ -6526,7 +6622,7 @@ const _OutpostClient = class _OutpostClient {
6526
6622
  });
6527
6623
  }
6528
6624
  sendIx(ix, opts) {
6529
- return __async$5(this, null, function* () {
6625
+ return __async$6(this, null, function* () {
6530
6626
  var _a;
6531
6627
  const tx = new web3_js.Transaction();
6532
6628
  if ((_a = opts == null ? void 0 : opts.additionalIxs) == null ? void 0 : _a.length) {
@@ -6543,7 +6639,7 @@ const _OutpostClient = class _OutpostClient {
6543
6639
  });
6544
6640
  }
6545
6641
  stakeLiqsol(params) {
6546
- return __async$5(this, null, function* () {
6642
+ return __async$6(this, null, function* () {
6547
6643
  var _a, _b;
6548
6644
  const user = (_a = params.user) != null ? _a : this.wallet.publicKey;
6549
6645
  const pre = [];
@@ -6555,7 +6651,7 @@ const _OutpostClient = class _OutpostClient {
6555
6651
  });
6556
6652
  }
6557
6653
  withdrawStake(params) {
6558
- return __async$5(this, null, function* () {
6654
+ return __async$6(this, null, function* () {
6559
6655
  var _a, _b;
6560
6656
  const user = (_a = params.user) != null ? _a : this.wallet.publicKey;
6561
6657
  const pre = [];
@@ -6567,7 +6663,7 @@ const _OutpostClient = class _OutpostClient {
6567
6663
  });
6568
6664
  }
6569
6665
  purchaseWithLiqsol(params) {
6570
- return __async$5(this, null, function* () {
6666
+ return __async$6(this, null, function* () {
6571
6667
  var _a, _b;
6572
6668
  const user = (_a = params.user) != null ? _a : this.wallet.publicKey;
6573
6669
  const pre = [];
@@ -6579,7 +6675,7 @@ const _OutpostClient = class _OutpostClient {
6579
6675
  });
6580
6676
  }
6581
6677
  purchaseWithSol(params) {
6582
- return __async$5(this, null, function* () {
6678
+ return __async$6(this, null, function* () {
6583
6679
  var _a;
6584
6680
  const user = (_a = params.user) != null ? _a : this.wallet.publicKey;
6585
6681
  const ix = yield this.buildPurchaseWithSolIx(params.amount, user);
@@ -6587,7 +6683,7 @@ const _OutpostClient = class _OutpostClient {
6587
6683
  });
6588
6684
  }
6589
6685
  purchaseFromYield(params) {
6590
- return __async$5(this, null, function* () {
6686
+ return __async$6(this, null, function* () {
6591
6687
  var _a;
6592
6688
  const user = (_a = params == null ? void 0 : params.user) != null ? _a : this.wallet.publicKey;
6593
6689
  const ix = yield this.buildPurchaseFromYieldIx(user);
@@ -6595,7 +6691,7 @@ const _OutpostClient = class _OutpostClient {
6595
6691
  });
6596
6692
  }
6597
6693
  getTokenBalanceSafe(ata) {
6598
- return __async$5(this, null, function* () {
6694
+ return __async$6(this, null, function* () {
6599
6695
  try {
6600
6696
  const bal = yield this.connection.getTokenAccountBalance(ata);
6601
6697
  return new anchor.BN(bal.value.amount);
@@ -6608,6 +6704,174 @@ const _OutpostClient = class _OutpostClient {
6608
6704
  _OutpostClient.INDEX_SCALE = new anchor.BN("1000000000000");
6609
6705
  let OutpostClient = _OutpostClient;
6610
6706
 
6707
+ var __async$5 = (__this, __arguments, generator) => {
6708
+ return new Promise((resolve, reject) => {
6709
+ var fulfilled = (value) => {
6710
+ try {
6711
+ step(generator.next(value));
6712
+ } catch (e) {
6713
+ reject(e);
6714
+ }
6715
+ };
6716
+ var rejected = (value) => {
6717
+ try {
6718
+ step(generator.throw(value));
6719
+ } catch (e) {
6720
+ reject(e);
6721
+ }
6722
+ };
6723
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
6724
+ step((generator = generator.apply(__this, __arguments)).next());
6725
+ });
6726
+ };
6727
+ class TokenClient {
6728
+ constructor(provider) {
6729
+ this.provider = provider;
6730
+ const svc = new SolanaProgramService(provider);
6731
+ this.program = svc.getProgram("liqsolCore");
6732
+ }
6733
+ get wallet() {
6734
+ return this.provider.wallet;
6735
+ }
6736
+ getAccounts(user) {
6737
+ return __async$5(this, null, function* () {
6738
+ return buildOutpostAccounts(this.provider.connection, user);
6739
+ });
6740
+ }
6741
+ fetchGlobalState() {
6742
+ return __async$5(this, null, function* () {
6743
+ const { globalState } = yield this.getAccounts(this.wallet.publicKey);
6744
+ return this.program.account.globalState.fetch(globalState);
6745
+ });
6746
+ }
6747
+ fetchTrancheState() {
6748
+ return __async$5(this, null, function* () {
6749
+ const { trancheState } = yield this.getAccounts(this.wallet.publicKey);
6750
+ return this.program.account.trancheState.fetch(trancheState);
6751
+ });
6752
+ }
6753
+ fetchWireReceipt(user) {
6754
+ return __async$5(this, null, function* () {
6755
+ const { wireReceipt } = yield this.getAccounts(user);
6756
+ return this.program.account.wireReceipt.fetch(wireReceipt);
6757
+ });
6758
+ }
6759
+ fetchUserWarrantRecord(user) {
6760
+ return __async$5(this, null, function* () {
6761
+ const { userWarrantRecord } = yield this.getAccounts(user);
6762
+ return this.program.account.userWarrantRecord.fetch(userWarrantRecord);
6763
+ });
6764
+ }
6765
+ buildPurchaseWithSolIx(_0) {
6766
+ return __async$5(this, arguments, function* (amountLamports, user = this.wallet.publicKey) {
6767
+ const a = yield this.getAccounts(user);
6768
+ return this.program.methods.purchaseWithSol(new anchor.BN(amountLamports.toString())).accounts({
6769
+ user: a.user,
6770
+ liqsolMint: a.liqsolMint,
6771
+ globalState: a.globalState,
6772
+ poolAuthority: a.poolAuthority,
6773
+ liqsolPoolAta: a.liqsolPoolAta,
6774
+ liqsolPoolUserRecord: a.poolUserRecord,
6775
+ distributionState: a.distributionState,
6776
+ payRateHistory: a.payRateHistory,
6777
+ bucketAuthority: a.bucketAuthority,
6778
+ bucketTokenAccount: a.bucketTokenAccount,
6779
+ solBucket: a.solBucket,
6780
+ warrantDepositRecord: a.wireReceipt,
6781
+ trancheState: a.trancheState,
6782
+ userWarrantRecord: a.userWarrantRecord,
6783
+ chainlinkFeed: a.chainLinkFeed,
6784
+ chainlinkProgram: a.chainLinkProgram,
6785
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
6786
+ systemProgram: web3_js.SystemProgram.programId
6787
+ }).instruction();
6788
+ });
6789
+ }
6790
+ buildPurchaseWithLiqsolIx(_0) {
6791
+ return __async$5(this, arguments, function* (amountLamports, user = this.wallet.publicKey) {
6792
+ const a = yield this.getAccounts(user);
6793
+ return this.program.methods.purchaseWithLiqsol(new anchor.BN(amountLamports.toString())).accounts({
6794
+ user: a.user,
6795
+ liqsolMint: a.liqsolMint,
6796
+ globalState: a.globalState,
6797
+ buyerAta: a.userAta,
6798
+ poolAuthority: a.poolAuthority,
6799
+ liqsolPoolAta: a.liqsolPoolAta,
6800
+ warrantDepositRecord: a.wireReceipt,
6801
+ liqsolPoolUserRecord: a.poolUserRecord,
6802
+ distributionState: a.distributionState,
6803
+ payRateHistory: a.payRateHistory,
6804
+ bucketAuthority: a.bucketAuthority,
6805
+ bucketTokenAccount: a.bucketTokenAccount,
6806
+ solBucket: a.solBucket,
6807
+ trancheState: a.trancheState,
6808
+ userWarrantRecord: a.userWarrantRecord,
6809
+ chainlinkFeed: a.chainLinkFeed,
6810
+ chainlinkProgram: a.chainLinkProgram,
6811
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
6812
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
6813
+ systemProgram: web3_js.SystemProgram.programId
6814
+ }).instruction();
6815
+ });
6816
+ }
6817
+ buildPurchaseFromYieldIx() {
6818
+ return __async$5(this, arguments, function* (user = this.wallet.publicKey) {
6819
+ const a = yield this.getAccounts(user);
6820
+ return this.program.methods.purchaseWarrantsFromYield().accounts({
6821
+ user: a.user,
6822
+ globalState: a.globalState,
6823
+ liqsolMint: a.liqsolMint,
6824
+ poolAuthority: a.poolAuthority,
6825
+ liqsolPoolAta: a.liqsolPoolAta,
6826
+ solBucket: a.solBucket,
6827
+ liqsolPoolUserRecord: a.poolUserRecord,
6828
+ distributionState: a.distributionState,
6829
+ payRateHistory: a.payRateHistory,
6830
+ bucketAuthority: a.bucketAuthority,
6831
+ bucketTokenAccount: a.bucketTokenAccount,
6832
+ trancheState: a.trancheState,
6833
+ userWarrantRecord: a.userWarrantRecord,
6834
+ chainlinkFeed: a.chainLinkFeed,
6835
+ chainlinkProgram: a.chainLinkProgram,
6836
+ tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
6837
+ systemProgram: web3_js.SystemProgram.programId
6838
+ }).instruction();
6839
+ });
6840
+ }
6841
+ getSolPriceUsdSafe() {
6842
+ return __async$5(this, null, function* () {
6843
+ try {
6844
+ const price = yield this.getSolPriceUsd();
6845
+ return { price, timestamp: void 0 };
6846
+ } catch (e) {
6847
+ return { price: void 0, timestamp: void 0 };
6848
+ }
6849
+ });
6850
+ }
6851
+ getSolPriceUsd() {
6852
+ return __async$5(this, null, function* () {
6853
+ const priceHistoryPda = derivePriceHistoryPda();
6854
+ const history = yield this.program.account.priceHistory.fetch(
6855
+ priceHistoryPda
6856
+ );
6857
+ const { prices, nextIndex, count, windowSize } = history;
6858
+ if (!prices || prices.length === 0 || !count) {
6859
+ throw new Error("Price history is empty \u2013 no SOL price available");
6860
+ }
6861
+ const capacity = prices.length || windowSize;
6862
+ if (!capacity) {
6863
+ throw new Error("Price history capacity is zero \u2013 check account layout");
6864
+ }
6865
+ const lastIndex = nextIndex === 0 ? capacity - 1 : nextIndex - 1;
6866
+ const latest = prices[lastIndex];
6867
+ if (!anchor.BN.isBN(latest)) {
6868
+ throw new Error("Latest price entry is not a BN \u2013 check IDL/decoder");
6869
+ }
6870
+ return BigInt(latest.toString());
6871
+ });
6872
+ }
6873
+ }
6874
+
6611
6875
  var __async$4 = (__this, __arguments, generator) => {
6612
6876
  return new Promise((resolve, reject) => {
6613
6877
  var fulfilled = (value) => {
@@ -6664,6 +6928,8 @@ class SolanaStakingClient {
6664
6928
  this.distributionClient = new DistributionClient(this.anchor);
6665
6929
  this.leaderboardClient = new LeaderboardClient(this.anchor);
6666
6930
  this.outpostClient = new OutpostClient(this.anchor);
6931
+ this.tokenClient = new TokenClient(this.anchor);
6932
+ this.tokenClient = new TokenClient(this.anchor);
6667
6933
  }
6668
6934
  get solPubKey() {
6669
6935
  return new web3_js.PublicKey(this.pubKey.data.array);
@@ -6673,47 +6939,107 @@ class SolanaStakingClient {
6673
6939
  }
6674
6940
  deposit(amountLamports) {
6675
6941
  return __async$4(this, null, function* () {
6676
- if (amountLamports <= BigInt(0)) throw new Error("Deposit amount must be greater than zero.");
6942
+ if (amountLamports <= BigInt(0)) {
6943
+ throw new Error("Deposit amount must be greater than zero.");
6944
+ }
6677
6945
  const tx = yield this.depositClient.buildDepositTx(amountLamports);
6678
- const { tx: prepared, blockhash, lastValidBlockHeight } = yield this.prepareTx(tx);
6946
+ const { tx: prepared, blockhash, lastValidBlockHeight } = yield this.prepareTx(
6947
+ tx
6948
+ );
6679
6949
  const signed = yield this.signTransaction(prepared);
6680
- const result = yield this.sendAndConfirmHttp(signed, { blockhash, lastValidBlockHeight });
6681
- return result.signature;
6950
+ return yield this.sendAndConfirmHttp(signed, {
6951
+ blockhash,
6952
+ lastValidBlockHeight
6953
+ });
6682
6954
  });
6683
6955
  }
6684
- withdraw(amountLamports) {
6956
+ withdraw(_amountLamports) {
6685
6957
  return __async$4(this, null, function* () {
6686
6958
  throw new Error("Withdraw method not yet implemented.");
6687
6959
  });
6688
6960
  }
6689
6961
  stake(amountLamports) {
6690
6962
  return __async$4(this, null, function* () {
6691
- if (amountLamports <= BigInt(0)) throw new Error("Stake amount must be greater than zero.");
6692
- const preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(this.solPubKey);
6963
+ if (amountLamports <= BigInt(0)) {
6964
+ throw new Error("Stake amount must be greater than zero.");
6965
+ }
6966
+ const preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(
6967
+ this.solPubKey
6968
+ );
6693
6969
  const stakeIx = yield this.outpostClient.buildStakeLiqsolIx(amountLamports);
6694
6970
  const tx = new web3_js.Transaction().add(...preIxs, stakeIx);
6695
6971
  const prepared = yield this.prepareTx(tx);
6696
6972
  const signed = yield this.signTransaction(prepared.tx);
6697
- const result = yield this.sendAndConfirmHttp(signed, prepared);
6698
- return result.signature;
6973
+ return yield this.sendAndConfirmHttp(signed, prepared);
6699
6974
  });
6700
6975
  }
6701
6976
  unstake(amountLamports) {
6702
6977
  return __async$4(this, null, function* () {
6703
- if (amountLamports <= BigInt(0)) throw new Error("Unstake amount must be greater than zero.");
6978
+ if (amountLamports <= BigInt(0)) {
6979
+ throw new Error("Unstake amount must be greater than zero.");
6980
+ }
6704
6981
  const user = this.solPubKey;
6705
6982
  const preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(user);
6706
6983
  const withdrawIx = yield this.outpostClient.buildWithdrawStakeIx(amountLamports);
6707
6984
  const tx = new web3_js.Transaction().add(...preIxs, withdrawIx);
6708
6985
  const prepared = yield this.prepareTx(tx);
6709
6986
  const signed = yield this.signTransaction(prepared.tx);
6710
- const result = yield this.sendAndConfirmHttp(signed, prepared);
6711
- return result.signature;
6987
+ return yield this.sendAndConfirmHttp(signed, prepared);
6988
+ });
6989
+ }
6990
+ buy(amountLamports, purchaseAsset) {
6991
+ return __async$4(this, null, function* () {
6992
+ const user = this.solPubKey;
6993
+ let ix;
6994
+ let preIxs = [];
6995
+ switch (purchaseAsset) {
6996
+ case PurchaseAsset.SOL: {
6997
+ if (!amountLamports || amountLamports <= BigInt(0)) {
6998
+ throw new Error("SOL pretoken purchase requires a positive amount.");
6999
+ }
7000
+ ix = yield this.tokenClient.buildPurchaseWithSolIx(
7001
+ amountLamports,
7002
+ user
7003
+ );
7004
+ break;
7005
+ }
7006
+ case PurchaseAsset.LIQSOL: {
7007
+ if (!amountLamports || amountLamports <= BigInt(0)) {
7008
+ throw new Error(
7009
+ "liqSOL pretoken purchase requires a positive amount."
7010
+ );
7011
+ }
7012
+ preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(user);
7013
+ ix = yield this.tokenClient.buildPurchaseWithLiqsolIx(
7014
+ amountLamports,
7015
+ user
7016
+ );
7017
+ break;
7018
+ }
7019
+ case PurchaseAsset.YIELD: {
7020
+ ix = yield this.tokenClient.buildPurchaseFromYieldIx(user);
7021
+ break;
7022
+ }
7023
+ case PurchaseAsset.ETH:
7024
+ case PurchaseAsset.LIQETH: {
7025
+ throw new Error(
7026
+ "ETH / LIQETH pretoken purchases are not supported on Solana."
7027
+ );
7028
+ }
7029
+ default:
7030
+ throw new Error(`Unsupported pretoken purchase asset: ${String(
7031
+ purchaseAsset
7032
+ )}`);
7033
+ }
7034
+ const tx = new web3_js.Transaction().add(...preIxs, ix);
7035
+ const prepared = yield this.prepareTx(tx);
7036
+ const signed = yield this.signTransaction(prepared.tx);
7037
+ return yield this.sendAndConfirmHttp(signed, prepared);
6712
7038
  });
6713
7039
  }
6714
7040
  getPortfolio() {
6715
7041
  return __async$4(this, null, function* () {
6716
- var _a, _b, _c;
7042
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
6717
7043
  const user = this.solPubKey;
6718
7044
  const reservePoolPDA = deriveReservePoolPda();
6719
7045
  const vaultPDA = deriveVaultPda();
@@ -6725,7 +7051,12 @@ class SolanaStakingClient {
6725
7051
  splToken.TOKEN_2022_PROGRAM_ID,
6726
7052
  splToken.ASSOCIATED_TOKEN_PROGRAM_ID
6727
7053
  );
6728
- const [nativeLamports, actualBalResp, userRecord, snapshot] = yield Promise.all([
7054
+ const [
7055
+ nativeLamports,
7056
+ actualBalResp,
7057
+ userRecord,
7058
+ snapshot
7059
+ ] = yield Promise.all([
6729
7060
  this.connection.getBalance(user, "confirmed"),
6730
7061
  this.connection.getTokenAccountBalance(userLiqsolAta, "confirmed").catch(() => null),
6731
7062
  this.distributionClient.getUserRecord(user).catch(() => null),
@@ -6733,9 +7064,13 @@ class SolanaStakingClient {
6733
7064
  ]);
6734
7065
  const LIQSOL_DECIMALS = 9;
6735
7066
  const actualAmountStr = (_b = (_a = actualBalResp == null ? void 0 : actualBalResp.value) == null ? void 0 : _a.amount) != null ? _b : "0";
6736
- const trackedAmountStr = (userRecord == null ? void 0 : userRecord.trackedBalance) ? userRecord.trackedBalance.toString() : "0";
6737
- const wireReceipt = (_c = snapshot == null ? void 0 : snapshot.wireReceipt) != null ? _c : null;
6738
- const stakedAmountStr = (wireReceipt == null ? void 0 : wireReceipt.stakedLiqsol) ? wireReceipt.stakedLiqsol.toString() : "0";
7067
+ const trackedAmountStr = (_d = (_c = userRecord == null ? void 0 : userRecord.trackedBalance) == null ? void 0 : _c.toString()) != null ? _d : "0";
7068
+ const wireReceipt = (_e = snapshot == null ? void 0 : snapshot.wireReceipt) != null ? _e : null;
7069
+ const userWarrantRecord = (_f = snapshot == null ? void 0 : snapshot.userWarrantRecord) != null ? _f : null;
7070
+ const trancheState = (_g = snapshot == null ? void 0 : snapshot.trancheState) != null ? _g : null;
7071
+ const globalState = (_h = snapshot == null ? void 0 : snapshot.globalState) != null ? _h : null;
7072
+ const stakedAmountStr = (_j = (_i = wireReceipt == null ? void 0 : wireReceipt.stakedLiqsol) == null ? void 0 : _i.toString()) != null ? _j : "0";
7073
+ const wireSharesStr = (_l = (_k = userWarrantRecord == null ? void 0 : userWarrantRecord.totalWarrantsPurchased) == null ? void 0 : _k.toString()) != null ? _l : "0";
6739
7074
  return {
6740
7075
  native: {
6741
7076
  amount: BigInt(nativeLamports),
@@ -6753,6 +7088,11 @@ class SolanaStakingClient {
6753
7088
  symbol: "LiqSOL",
6754
7089
  decimals: LIQSOL_DECIMALS
6755
7090
  },
7091
+ wire: {
7092
+ amount: BigInt(wireSharesStr),
7093
+ symbol: "$WIRE",
7094
+ decimals: 8
7095
+ },
6756
7096
  tracked: {
6757
7097
  amount: BigInt(trackedAmountStr),
6758
7098
  symbol: "LiqSOL",
@@ -6762,19 +7102,95 @@ class SolanaStakingClient {
6762
7102
  userLiqsolAta: userLiqsolAta.toBase58(),
6763
7103
  reservePoolPDA: reservePoolPDA.toBase58(),
6764
7104
  vaultPDA: vaultPDA.toBase58(),
6765
- wireReceipt
7105
+ wireReceipt,
7106
+ userWarrantRecord,
7107
+ globalIndex: (_m = globalState == null ? void 0 : globalState.currentIndex) == null ? void 0 : _m.toString(),
7108
+ totalShares: (_n = globalState == null ? void 0 : globalState.totalShares) == null ? void 0 : _n.toString(),
7109
+ currentTrancheNumber: (_o = trancheState == null ? void 0 : trancheState.currentTrancheNumber) == null ? void 0 : _o.toString(),
7110
+ currentTranchePriceUsd: (_p = trancheState == null ? void 0 : trancheState.currentTranchePriceUsd) == null ? void 0 : _p.toString()
6766
7111
  },
6767
7112
  chainID: this.network.chainId
6768
7113
  };
6769
7114
  });
6770
7115
  }
7116
+ getTrancheSnapshot(options) {
7117
+ return __async$4(this, null, function* () {
7118
+ const {
7119
+ chainID = core.SolChainID.WireTestnet,
7120
+ windowBefore,
7121
+ windowAfter
7122
+ } = options != null ? options : {};
7123
+ const [globalState, trancheState] = yield Promise.all([
7124
+ this.tokenClient.fetchGlobalState(),
7125
+ this.tokenClient.fetchTrancheState()
7126
+ ]);
7127
+ const { price: solPriceUsd, timestamp } = yield this.tokenClient.getSolPriceUsdSafe();
7128
+ return buildSolanaTrancheSnapshot({
7129
+ chainID,
7130
+ globalState,
7131
+ trancheState,
7132
+ solPriceUsd,
7133
+ nativePriceTimestamp: timestamp,
7134
+ ladderWindowBefore: windowBefore,
7135
+ ladderWindowAfter: windowAfter
7136
+ });
7137
+ });
7138
+ }
7139
+ getBuyQuote(amount, asset, opts) {
7140
+ return __async$4(this, null, function* () {
7141
+ if (asset !== PurchaseAsset.YIELD && amount <= BigInt(0)) {
7142
+ throw new Error("amount must be > 0 for non-YIELD purchases");
7143
+ }
7144
+ const snapshot = yield this.getTrancheSnapshot({
7145
+ chainID: opts == null ? void 0 : opts.chainID
7146
+ });
7147
+ const wirePriceUsd = snapshot.currentPriceUsd;
7148
+ const solPriceUsd = snapshot.nativePriceUsd;
7149
+ if (!wirePriceUsd || wirePriceUsd <= BigInt(0)) {
7150
+ throw new Error("Invalid WIRE price in tranche snapshot");
7151
+ }
7152
+ if (!solPriceUsd || solPriceUsd <= BigInt(0)) {
7153
+ throw new Error("No SOL/USD price available");
7154
+ }
7155
+ const ONE_E9 = BigInt(web3_js.LAMPORTS_PER_SOL);
7156
+ const ONE_E8 = BigInt(1e8);
7157
+ let notionalUsd;
7158
+ switch (asset) {
7159
+ case PurchaseAsset.SOL: {
7160
+ notionalUsd = amount * solPriceUsd / ONE_E9;
7161
+ break;
7162
+ }
7163
+ case PurchaseAsset.LIQSOL: {
7164
+ notionalUsd = amount * solPriceUsd / ONE_E9;
7165
+ break;
7166
+ }
7167
+ case PurchaseAsset.YIELD: {
7168
+ notionalUsd = amount * solPriceUsd / ONE_E9;
7169
+ break;
7170
+ }
7171
+ case PurchaseAsset.ETH:
7172
+ case PurchaseAsset.LIQETH:
7173
+ throw new Error("getBuyQuote for ETH/LIQETH is not supported on Solana");
7174
+ default:
7175
+ throw new Error(`Unsupported purchase asset: ${String(asset)}`);
7176
+ }
7177
+ const numerator = notionalUsd * ONE_E8;
7178
+ const wireShares = numerator === BigInt(0) ? BigInt(0) : (numerator + wirePriceUsd - BigInt(1)) / wirePriceUsd;
7179
+ return {
7180
+ purchaseAsset: asset,
7181
+ amountIn: amount,
7182
+ wireShares,
7183
+ wireDecimals: 8,
7184
+ wirePriceUsd,
7185
+ notionalUsd
7186
+ };
7187
+ });
7188
+ }
6771
7189
  getUserRecord() {
6772
7190
  return __async$4(this, null, function* () {
6773
7191
  return this.distributionClient.getUserRecord(this.solPubKey);
6774
7192
  });
6775
7193
  }
6776
- getProtocolFee() {
6777
- }
6778
7194
  correctBalance(amount) {
6779
7195
  return __async$4(this, null, function* () {
6780
7196
  var _a;
@@ -6782,27 +7198,39 @@ class SolanaStakingClient {
6782
7198
  if (!build.canSucceed || !build.transaction) {
6783
7199
  throw new Error((_a = build.reason) != null ? _a : "Unable to build Correct&Register transaction");
6784
7200
  }
6785
- const { tx, blockhash, lastValidBlockHeight } = yield this.prepareTx(build.transaction);
7201
+ const { tx, blockhash, lastValidBlockHeight } = yield this.prepareTx(
7202
+ build.transaction
7203
+ );
6786
7204
  const signed = yield this.signTransaction(tx);
6787
- const result = yield this.sendAndConfirmHttp(signed, { blockhash, lastValidBlockHeight });
6788
- return result.signature;
7205
+ const signature = yield this.sendAndConfirmHttp(signed, {
7206
+ blockhash,
7207
+ lastValidBlockHeight
7208
+ });
7209
+ return signature;
6789
7210
  });
6790
7211
  }
6791
7212
  sendAndConfirmHttp(signed, ctx) {
6792
7213
  return __async$4(this, null, function* () {
6793
- const signature = yield this.connection.sendRawTransaction(signed.serialize(), {
6794
- skipPreflight: false,
6795
- preflightCommitment: commitment,
6796
- maxRetries: 3
6797
- });
7214
+ const signature = yield this.connection.sendRawTransaction(
7215
+ signed.serialize(),
7216
+ {
7217
+ skipPreflight: false,
7218
+ preflightCommitment: commitment,
7219
+ maxRetries: 3
7220
+ }
7221
+ );
6798
7222
  const conf = yield this.connection.confirmTransaction(
6799
- { signature, blockhash: ctx.blockhash, lastValidBlockHeight: ctx.lastValidBlockHeight },
7223
+ {
7224
+ signature,
7225
+ blockhash: ctx.blockhash,
7226
+ lastValidBlockHeight: ctx.lastValidBlockHeight
7227
+ },
6800
7228
  commitment
6801
7229
  );
6802
7230
  if (conf.value.err) {
6803
7231
  throw new Error(`Transaction failed: ${JSON.stringify(conf.value.err)}`);
6804
7232
  }
6805
- return { signature, slot: conf.context.slot, confirmed: true };
7233
+ return signature;
6806
7234
  });
6807
7235
  }
6808
7236
  signTransaction(tx) {
@@ -24735,6 +25163,12 @@ class EthereumStakingClient {
24735
25163
  };
24736
25164
  });
24737
25165
  }
25166
+ buy(amount, purchaseAsset) {
25167
+ throw new Error("Method not yet implemented.");
25168
+ }
25169
+ getBuyQuote(amount, purchaseAsset) {
25170
+ throw new Error("Method not yet implemented.");
25171
+ }
24738
25172
  getPortfolio() {
24739
25173
  return __async(this, null, function* () {
24740
25174
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
@@ -24766,11 +25200,21 @@ class EthereumStakingClient {
24766
25200
  decimals: nativeDecimals,
24767
25201
  symbol: liqSymbol
24768
25202
  },
25203
+ wire: {
25204
+ amount: BigInt(0),
25205
+ decimals: 0,
25206
+ symbol: "$WIRE"
25207
+ },
24769
25208
  chainID: this.network.chainId
24770
25209
  };
24771
25210
  return portfolio;
24772
25211
  });
24773
25212
  }
25213
+ getTrancheSnapshot() {
25214
+ return __async(this, null, function* () {
25215
+ return null;
25216
+ });
25217
+ }
24774
25218
  requestWithdraw(amountWei) {
24775
25219
  return __async(this, null, function* () {
24776
25220
  var _a, _b, _c;
@@ -24885,12 +25329,12 @@ const CONTRACT_NAMES = [
24885
25329
  ];
24886
25330
 
24887
25331
  var types$1 = /*#__PURE__*/Object.freeze({
24888
- __proto__: null,
24889
- CONTRACT_NAMES: CONTRACT_NAMES
25332
+ __proto__: null,
25333
+ CONTRACT_NAMES: CONTRACT_NAMES
24890
25334
  });
24891
25335
 
24892
25336
  var types = /*#__PURE__*/Object.freeze({
24893
- __proto__: null
25337
+ __proto__: null
24894
25338
  });
24895
25339
 
24896
25340
  exports.ADDRESSES = ADDRESSES;
@@ -24916,12 +25360,16 @@ exports.OutpostClient = OutpostClient;
24916
25360
  exports.PAY_RATE_SCALE_FACTOR = PAY_RATE_SCALE_FACTOR;
24917
25361
  exports.PDA_SEEDS = PDA_SEEDS;
24918
25362
  exports.PROGRAM_IDS = PROGRAM_IDS;
25363
+ exports.PurchaseAsset = PurchaseAsset;
24919
25364
  exports.SOL = types;
24920
25365
  exports.SolanaStakingClient = SolanaStakingClient;
24921
25366
  exports.Staker = Staker;
25367
+ exports.TokenClient = TokenClient;
24922
25368
  exports.VALIDATOR_LEADERBOARD = VALIDATOR_LEADERBOARD;
24923
25369
  exports.airdropSol = airdropSol;
24924
25370
  exports.buildOutpostAccounts = buildOutpostAccounts;
25371
+ exports.buildSolanaTrancheLadder = buildSolanaTrancheLadder;
25372
+ exports.buildSolanaTrancheSnapshot = buildSolanaTrancheSnapshot;
24925
25373
  exports.calculateExpectedFee = calculateExpectedFee;
24926
25374
  exports.deriveBarConfigPda = deriveBarConfigPda;
24927
25375
  exports.deriveBondLevelPda = deriveBondLevelPda;
@@ -24938,6 +25386,7 @@ exports.deriveOutpostPoolAuthorityPda = deriveOutpostPoolAuthorityPda;
24938
25386
  exports.derivePayRateHistoryPda = derivePayRateHistoryPda;
24939
25387
  exports.derivePayoutStatePda = derivePayoutStatePda;
24940
25388
  exports.derivePoolUserRecordPda = derivePoolUserRecordPda;
25389
+ exports.derivePriceHistoryPda = derivePriceHistoryPda;
24941
25390
  exports.deriveReservePoolPda = deriveReservePoolPda;
24942
25391
  exports.deriveSolBucketPda = deriveSolBucketPda;
24943
25392
  exports.deriveStakeControllerStatePda = deriveStakeControllerStatePda;
@@ -24967,6 +25416,8 @@ exports.previewDepositEffects = previewDepositEffects;
24967
25416
  exports.scheduledInstruction = scheduledInstruction;
24968
25417
  exports.sleep = sleep;
24969
25418
  exports.solToLamports = solToLamports;
25419
+ exports.toBigint = toBigint;
25420
+ exports.tokensToShares = tokensToShares;
24970
25421
  exports.waitForConfirmation = waitForConfirmation;
24971
25422
  exports.waitUntilSafeToExecuteFunction = waitUntilSafeToExecuteFunction;
24972
25423
  //# sourceMappingURL=stake.js.map