@wireio/stake 0.5.2 → 0.6.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
@@ -8099,8 +8099,31 @@ var __async$d = (__this, __arguments, generator) => {
8099
8099
  });
8100
8100
  };
8101
8101
  const INDEX_SCALE = BigInt(1e12);
8102
- BigInt(1e8);
8103
- const BPS$1 = BigInt(1e4);
8102
+ const USD_SCALE = BigInt(1e8);
8103
+ const BPS = BigInt(1e4);
8104
+ function growSupplyOnce$1(value, growthBps) {
8105
+ const g = BigInt(growthBps);
8106
+ return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
8107
+ }
8108
+ function shrinkSupplyOnce$1(value, growthBps) {
8109
+ const g = BigInt(growthBps);
8110
+ return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
8111
+ }
8112
+ function priceStepUsd1e8(priceGrowthCents) {
8113
+ if (!priceGrowthCents) return BigInt(0);
8114
+ const CENT_SCALE = USD_SCALE / BigInt(100);
8115
+ return BigInt(priceGrowthCents) * CENT_SCALE;
8116
+ }
8117
+ function growPriceOnceUsd1e8(value, priceGrowthCents) {
8118
+ const step = priceStepUsd1e8(priceGrowthCents);
8119
+ return value + step;
8120
+ }
8121
+ function shrinkPriceOnceUsd1e8(value, priceGrowthCents) {
8122
+ const step = priceStepUsd1e8(priceGrowthCents);
8123
+ if (step === BigInt(0)) return value;
8124
+ if (value <= step) return BigInt(0);
8125
+ return value - step;
8126
+ }
8104
8127
  function toBigint(x) {
8105
8128
  if (typeof x === "bigint") return x;
8106
8129
  if (typeof x === "number") return BigInt(x);
@@ -8113,14 +8136,6 @@ function tokensToShares(amount, currentIndex) {
8113
8136
  const r = num % currentIndex;
8114
8137
  return r === BigInt(0) ? q : q + BigInt(1);
8115
8138
  }
8116
- function growOnce$1(value, growthBps) {
8117
- const g = BigInt(growthBps);
8118
- return (value * (BPS$1 + g) + BPS$1 / BigInt(2)) / BPS$1;
8119
- }
8120
- function shrinkOnce$1(value, growthBps) {
8121
- const g = BigInt(growthBps);
8122
- return (value * BPS$1 + (BPS$1 + g) / BigInt(2)) / (BPS$1 + g);
8123
- }
8124
8139
  function buildSolanaTrancheLadder(options) {
8125
8140
  const {
8126
8141
  currentTranche,
@@ -8141,14 +8156,14 @@ function buildSolanaTrancheLadder(options) {
8141
8156
  for (let id = currentTranche + 1; id <= endId; id++) {
8142
8157
  const prevCap = capacity.get(id - 1);
8143
8158
  const prevPrice = price.get(id - 1);
8144
- capacity.set(id, growOnce$1(prevCap, supplyGrowthBps));
8145
- price.set(id, growOnce$1(prevPrice, priceGrowthCents));
8159
+ capacity.set(id, growSupplyOnce$1(prevCap, supplyGrowthBps));
8160
+ price.set(id, growPriceOnceUsd1e8(prevPrice, priceGrowthCents));
8146
8161
  }
8147
8162
  for (let id = currentTranche - 1; id >= startId; id--) {
8148
8163
  const nextCap = capacity.get(id + 1);
8149
8164
  const nextPrice = price.get(id + 1);
8150
- capacity.set(id, shrinkOnce$1(nextCap, supplyGrowthBps));
8151
- price.set(id, shrinkOnce$1(nextPrice, priceGrowthCents));
8165
+ capacity.set(id, shrinkSupplyOnce$1(nextCap, supplyGrowthBps));
8166
+ price.set(id, shrinkPriceOnceUsd1e8(nextPrice, priceGrowthCents));
8152
8167
  }
8153
8168
  const ladder = [];
8154
8169
  for (let id = startId; id <= endId; id++) {
@@ -9414,13 +9429,9 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9414
9429
  getSystemAPY() {
9415
9430
  return __async$8(this, null, function* () {
9416
9431
  const ratePerEpoch = yield this.getEpochRateDecimalFromProgram();
9417
- console.log("epochRateDecimal", ratePerEpoch);
9418
9432
  const epochsPerYear = yield this.getEpochsPerYearFromCluster();
9419
- console.log("epochsPerYear", epochsPerYear);
9420
9433
  const apyDecimal = Math.pow(1 + ratePerEpoch, epochsPerYear) - 1;
9421
- console.log("apyDecimal", apyDecimal);
9422
9434
  const apyPercent = apyDecimal * 100;
9423
- console.log("apyPercent", apyPercent);
9424
9435
  return apyPercent;
9425
9436
  });
9426
9437
  }
@@ -9431,8 +9442,6 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9431
9442
  const stakeMetrics = yield liqSolCoreProgram.account.stakeMetrics.fetch(stakeMetricsPda);
9432
9443
  const raw = BigInt(stakeMetrics.solSystemPayRate.toString());
9433
9444
  const rateDecimal = Number(raw) / Number(PAY_RATE_SCALE_FACTOR);
9434
- console.log("solSystemPayRate(raw)", raw.toString());
9435
- console.log("epochRateDecimal(computed)", rateDecimal);
9436
9445
  return rateDecimal;
9437
9446
  });
9438
9447
  }
@@ -35161,22 +35170,22 @@ const ADDRESSES = {
35161
35170
  WithdrawalVault: "0xC82FAf3Fed135B70A7E797864F504819a98E96c4",
35162
35171
  StakingModule: "0xdd24EffAa4B42f3273E2b44995639119c08daBea",
35163
35172
  YieldOracle: "0x56A27E1d10d4aEc7402dC26693fb7c0Eb66eF802",
35164
- OutpostManagerAuthority: "0xAEcd2aa6EeFa4Aa7Cb9368728aA89Ca59Aa9ea59",
35165
- iodata: "0x2c2ab53F6Bc146bd31B459E832Ce0B9Da78712d8",
35166
- Base58: "0x9F188Ec124c9ad9bF6D195650d8360Fd052F585A",
35167
- sysio_merkle: "0x6eDA3C4c34421Cd667800C17fe33E48f5698e004",
35168
- ReceiptNFT: "0xd083051d9bb8353875abCecAB50C6e4FB5e527a8",
35169
- MockAggregator: "0xFCfc3ddd4CBd9Ad3b3af3A374B8bdA1b66eE6FFF",
35170
- Pool: "0xee5F11aC9b104c18d2423f266c5E737fC95ebA92",
35171
- OutpostManager: "0xB1B6ba7FA156652849069aC7ADB281283D235B9f",
35172
- sysio_write: "0xEfA608136d372349C09a7aA57665C09Fb4a620Ca",
35173
- EthUsdPriceConsumer: "0x6337A23b61f98b1526faF2848385Abe9cB4cFF21",
35174
- BAR: "0x9264eAA449da94caF70Fc18522021a94C8DF32Fb",
35175
- OPPCommon: "0x86A8cA16ce521De3EBdd1C541fAf188795b59FD0",
35176
- OPP: "0x79e8395Bb5131FB285aCEE5329BB43E66f50F88C",
35177
- Pretoken: "0x62f98AF2f9C3EF4eF2fA7bc0245BD5a9315E7541",
35178
- OPPInbound: "0xC85f57Ff069711e0b3472De3963bd2fC2FEfF3e2",
35179
- Depositor: "0xb0BACAb6f13dd96281300be13a6346461b2f35F3"
35173
+ OutpostManagerAuthority: "0x57A3723B9f3C6022CAe394C859655E59382Fad18",
35174
+ iodata: "0x88896d4fa70C3a7Fb833C80BB5763a4c53A6aCB5",
35175
+ Base58: "0x0E9E6e8A32477F3B086Aaa26db2b928a816Da711",
35176
+ sysio_merkle: "0xf5858B784B080A08063FAe06dB6d91c5BBAA48C7",
35177
+ ReceiptNFT: "0xF1F5e063bFF6E0c09b0ac8020376E16c0be8eA10",
35178
+ EthUsdPriceConsumer: "0xFdb3Ab290179CA85204aD1Ffb8c1c3c42AEB768F",
35179
+ Pool: "0x15DaeB9562c6Dd21558f14CcdDf5C855499B8693",
35180
+ OutpostManager: "0x1aCCc78FCA9e2Ea4dcE849bf072C2248f36435cC",
35181
+ sysio_write: "0x513e472904EE67A8E27ebaF2411f3ed3851F4514",
35182
+ Pretoken: "0xd7CDc79B90336720ecf02eD5A355cB0F7099F079",
35183
+ BAR: "0x4A01414dEA81b1961aE986Bc4E95B30f73770f99",
35184
+ OPPCommon: "0x3747Cc19A351BCBCE92055c419e7d710C4b399aA",
35185
+ OPP: "0xF577FDc80014ef19DF258243e0551c888Da809E4",
35186
+ Depositor: "0xD9Eb2A2d4e9eD7e2257153041B29DCeCDee8BCFe",
35187
+ OPPInbound: "0x232C01f2528A5013af3703bE4B4ce30A793Ee8BD",
35188
+ MockAggregator: "0xFCfc3ddd4CBd9Ad3b3af3A374B8bdA1b66eE6FFF"
35180
35189
  };
35181
35190
  const CONTRACTS = {
35182
35191
  LiqEthAuthority: {
@@ -35384,7 +35393,7 @@ var __async$6 = (__this, __arguments, generator) => {
35384
35393
  step((generator = generator.apply(__this, __arguments)).next());
35385
35394
  });
35386
35395
  };
35387
- const BPS = BigInt(1e4);
35396
+ BigInt(1e4);
35388
35397
  function formatContractErrors(err) {
35389
35398
  if (err.errorName && err.errorArgs) {
35390
35399
  const errorObj = {
@@ -35457,20 +35466,27 @@ function sendOPPFinalize(opp, gasLimit) {
35457
35466
  }
35458
35467
  });
35459
35468
  }
35460
- function growOnce(value, growthBps) {
35469
+ const BPS_DENOM = BigInt(1e4);
35470
+ const USD_ONCHAIN_SCALE = BigInt(1e18);
35471
+ const USD_CLIENT_SCALE = BigInt(1e8);
35472
+ const USD_SCALE_DOWN = USD_ONCHAIN_SCALE / USD_CLIENT_SCALE;
35473
+ function growSupplyOnce(value, growthBps) {
35461
35474
  const g = BigInt(growthBps);
35462
- return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
35475
+ return value * (BPS_DENOM + g) / BPS_DENOM;
35463
35476
  }
35464
- function shrinkOnce(value, growthBps) {
35477
+ function shrinkSupplyOnce(value, growthBps) {
35465
35478
  const g = BigInt(growthBps);
35466
- return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
35479
+ return value * BPS_DENOM / (BPS_DENOM + g);
35467
35480
  }
35468
- function getTrancheSize(startSupply, supplyGrowthBps, trancheNumber) {
35469
- let supply = startSupply;
35470
- for (let i = 0; i < trancheNumber; i++) {
35471
- supply = (supply * (BPS + BigInt(supplyGrowthBps)) + BPS / BigInt(2)) / BPS;
35472
- }
35473
- return supply;
35481
+ function growPriceOnceUsd1e18(value, stepUsd1e18) {
35482
+ return value + stepUsd1e18;
35483
+ }
35484
+ function shrinkPriceOnceUsd1e18(value, stepUsd1e18) {
35485
+ if (value <= stepUsd1e18) return BigInt(0);
35486
+ return value - stepUsd1e18;
35487
+ }
35488
+ function usd1e18To1e8(raw) {
35489
+ return raw / USD_SCALE_DOWN;
35474
35490
  }
35475
35491
  function buildEthereumTrancheLadder(options) {
35476
35492
  const {
@@ -35478,29 +35494,32 @@ function buildEthereumTrancheLadder(options) {
35478
35494
  initialTrancheSupply,
35479
35495
  currentTrancheSupply,
35480
35496
  currentPriceUsd,
35481
- supplyGrowthBps,
35482
35497
  priceGrowthCents,
35498
+ supplyGrowthBps,
35483
35499
  windowBefore = 5,
35484
35500
  windowAfter = 5
35485
35501
  } = options;
35486
35502
  const startId = Math.max(0, currentTranche - windowBefore);
35487
35503
  const endId = currentTranche + windowAfter;
35488
- const currentTrancheSize = getTrancheSize(initialTrancheSupply, supplyGrowthBps, currentTranche);
35489
35504
  const capacity = new Map();
35490
- const price = new Map();
35491
- capacity.set(currentTranche, currentTrancheSize);
35492
- price.set(currentTranche, currentPriceUsd);
35505
+ const priceUsd = new Map();
35506
+ let currentCap = initialTrancheSupply;
35507
+ for (let i = 0; i < currentTranche; i++) {
35508
+ currentCap = growSupplyOnce(currentCap, supplyGrowthBps);
35509
+ }
35510
+ capacity.set(currentTranche, currentCap);
35511
+ priceUsd.set(currentTranche, currentPriceUsd);
35493
35512
  for (let id = currentTranche + 1; id <= endId; id++) {
35494
35513
  const prevCap = capacity.get(id - 1);
35495
- const prevPrice = price.get(id - 1);
35496
- capacity.set(id, growOnce(prevCap, supplyGrowthBps));
35497
- price.set(id, growOnce(prevPrice, priceGrowthCents));
35514
+ const prevPrice = priceUsd.get(id - 1);
35515
+ capacity.set(id, growSupplyOnce(prevCap, supplyGrowthBps));
35516
+ priceUsd.set(id, growPriceOnceUsd1e18(prevPrice, priceGrowthCents));
35498
35517
  }
35499
35518
  for (let id = currentTranche - 1; id >= startId; id--) {
35500
35519
  const nextCap = capacity.get(id + 1);
35501
- const nextPrice = price.get(id + 1);
35502
- capacity.set(id, shrinkOnce(nextCap, supplyGrowthBps));
35503
- price.set(id, shrinkOnce(nextPrice, priceGrowthCents));
35520
+ const nextPrice = priceUsd.get(id + 1);
35521
+ capacity.set(id, shrinkSupplyOnce(nextCap, supplyGrowthBps));
35522
+ priceUsd.set(id, shrinkPriceOnceUsd1e18(nextPrice, priceGrowthCents));
35504
35523
  }
35505
35524
  const ladder = [];
35506
35525
  for (let id = startId; id <= endId; id++) {
@@ -35513,12 +35532,14 @@ function buildEthereumTrancheLadder(options) {
35513
35532
  } else {
35514
35533
  sold = BigInt(0);
35515
35534
  }
35535
+ const remaining = cap - sold;
35536
+ const priceClientScale = usd1e18To1e8(priceUsd.get(id));
35516
35537
  ladder.push({
35517
35538
  id,
35518
35539
  capacity: cap,
35519
35540
  sold,
35520
- remaining: cap - sold,
35521
- priceUsd: price.get(id)
35541
+ remaining,
35542
+ priceUsd: priceClientScale
35522
35543
  });
35523
35544
  }
35524
35545
  return ladder;
@@ -35535,7 +35556,7 @@ function buildEthereumTrancheSnapshot(options) {
35535
35556
  indexBn,
35536
35557
  trancheNumberBn,
35537
35558
  currentTrancheSupply,
35538
- tranchePriceWadBn,
35559
+ tranchePriceUsdBn,
35539
35560
  totalTrancheSupply,
35540
35561
  initialTrancheSupply,
35541
35562
  supplyGrowthBps,
@@ -35546,15 +35567,23 @@ function buildEthereumTrancheSnapshot(options) {
35546
35567
  const totalShares = BigInt(totalSharesBn.toString()) / BigInt(1e10);
35547
35568
  const currentIndex = BigInt(indexBn.toString());
35548
35569
  const currentTranche = Number(trancheNumberBn.toString());
35549
- const currentPriceUsd = BigInt(tranchePriceWadBn.toString()) / BigInt(1e10);
35570
+ const currentPriceUsd1e18 = BigInt(tranchePriceUsdBn.toString());
35571
+ const priceGrowthStepUsd1e18 = BigInt(priceGrowthCents.toString());
35572
+ const priceGrowthCentsNumber = Number(
35573
+ priceGrowthStepUsd1e18 / BigInt(1e16)
35574
+ );
35575
+ const currentTrancheSupplyBig = BigInt(currentTrancheSupply.toString());
35576
+ const totalTrancheSupplyBig = BigInt(totalTrancheSupply.toString());
35577
+ const initialTrancheSupplyBig = BigInt(initialTrancheSupply.toString());
35578
+ const currentPriceUsd = currentPriceUsd1e18 / BigInt(1e10);
35550
35579
  const ladder = buildEthereumTrancheLadder({
35551
35580
  currentTranche,
35552
- totalTrancheSupply,
35553
- initialTrancheSupply,
35554
- currentTrancheSupply,
35555
- currentPriceUsd,
35581
+ totalTrancheSupply: totalTrancheSupplyBig,
35582
+ initialTrancheSupply: initialTrancheSupplyBig,
35583
+ currentTrancheSupply: currentTrancheSupplyBig,
35584
+ currentPriceUsd: currentPriceUsd1e18,
35585
+ priceGrowthCents: priceGrowthStepUsd1e18,
35556
35586
  supplyGrowthBps,
35557
- priceGrowthCents,
35558
35587
  windowBefore: ladderWindowBefore,
35559
35588
  windowAfter: ladderWindowAfter
35560
35589
  });
@@ -35565,10 +35594,10 @@ function buildEthereumTrancheSnapshot(options) {
35565
35594
  currentTranche,
35566
35595
  currentPriceUsd,
35567
35596
  supplyGrowthBps,
35568
- priceGrowthCents,
35569
- currentTrancheSupply,
35570
- initialTrancheSupply,
35571
- totalPretokensSold: totalTrancheSupply,
35597
+ priceGrowthCents: priceGrowthCentsNumber,
35598
+ totalPretokensSold: totalTrancheSupplyBig,
35599
+ currentTrancheSupply: currentTrancheSupplyBig,
35600
+ initialTrancheSupply: initialTrancheSupplyBig,
35572
35601
  nativePriceUsd: ethPriceUsd,
35573
35602
  nativePriceTimestamp,
35574
35603
  ladder
@@ -36538,7 +36567,7 @@ class EthereumStakingClient {
36538
36567
  try {
36539
36568
  const blockNumber = yield this.provider.getBlockNumber();
36540
36569
  const blockTag = { blockTag: blockNumber };
36541
- const [totalSharesBn, indexBn, trancheNumberBn, trancheSupplyBn, tranchePriceWadBn, totalSupplyBn, supplyGrowthBps, priceGrowthCents, minPriceUsd, maxPriceUsd] = yield Promise.all([
36570
+ const [totalSharesBn, indexBn, trancheNumberBn, trancheSupplyBn, tranchePriceUsdBn, totalSupplyBn, supplyGrowthBps, priceGrowthCents, minPriceUsd, maxPriceUsd] = yield Promise.all([
36542
36571
  this.contract.Depositor.totalShares(blockTag),
36543
36572
  this.contract.Depositor.index(blockTag),
36544
36573
  this.contract.Pretoken.trancheNumber(blockTag),
@@ -36562,7 +36591,7 @@ class EthereumStakingClient {
36562
36591
  indexBn,
36563
36592
  trancheNumberBn,
36564
36593
  currentTrancheSupply,
36565
- tranchePriceWadBn,
36594
+ tranchePriceUsdBn,
36566
36595
  totalTrancheSupply,
36567
36596
  initialTrancheSupply,
36568
36597
  supplyGrowthBps,
@@ -36575,7 +36604,6 @@ class EthereumStakingClient {
36575
36604
  ladderWindowAfter: windowAfter
36576
36605
  });
36577
36606
  } catch (err) {
36578
- console.log(err);
36579
36607
  throw new Error(`Error fetching Ethereum tranche snapshot: ${(err == null ? void 0 : err.message) || err}`);
36580
36608
  }
36581
36609
  });
@@ -36648,6 +36676,7 @@ class Staker {
36648
36676
  config.forEach((cfg) => {
36649
36677
  switch (cfg.network.chainId) {
36650
36678
  case core.SolChainID.Devnet:
36679
+ case core.SolChainID.WireTestnet:
36651
36680
  this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
36652
36681
  break;
36653
36682
  case core.EvmChainID.Hoodi: