@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.m.js CHANGED
@@ -8013,8 +8013,31 @@ class DepositClient {
8013
8013
  }
8014
8014
 
8015
8015
  const INDEX_SCALE = BigInt(1e12);
8016
- BigInt(1e8);
8017
- const BPS$1 = BigInt(1e4);
8016
+ const USD_SCALE = BigInt(1e8);
8017
+ const BPS = BigInt(1e4);
8018
+ function growSupplyOnce$1(value, growthBps) {
8019
+ const g = BigInt(growthBps);
8020
+ return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
8021
+ }
8022
+ function shrinkSupplyOnce$1(value, growthBps) {
8023
+ const g = BigInt(growthBps);
8024
+ return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
8025
+ }
8026
+ function priceStepUsd1e8(priceGrowthCents) {
8027
+ if (!priceGrowthCents) return BigInt(0);
8028
+ const CENT_SCALE = USD_SCALE / BigInt(100);
8029
+ return BigInt(priceGrowthCents) * CENT_SCALE;
8030
+ }
8031
+ function growPriceOnceUsd1e8(value, priceGrowthCents) {
8032
+ const step = priceStepUsd1e8(priceGrowthCents);
8033
+ return value + step;
8034
+ }
8035
+ function shrinkPriceOnceUsd1e8(value, priceGrowthCents) {
8036
+ const step = priceStepUsd1e8(priceGrowthCents);
8037
+ if (step === BigInt(0)) return value;
8038
+ if (value <= step) return BigInt(0);
8039
+ return value - step;
8040
+ }
8018
8041
  function toBigint(x) {
8019
8042
  if (typeof x === "bigint") return x;
8020
8043
  if (typeof x === "number") return BigInt(x);
@@ -8027,14 +8050,6 @@ function tokensToShares(amount, currentIndex) {
8027
8050
  const r = num % currentIndex;
8028
8051
  return r === BigInt(0) ? q : q + BigInt(1);
8029
8052
  }
8030
- function growOnce$1(value, growthBps) {
8031
- const g = BigInt(growthBps);
8032
- return (value * (BPS$1 + g) + BPS$1 / BigInt(2)) / BPS$1;
8033
- }
8034
- function shrinkOnce$1(value, growthBps) {
8035
- const g = BigInt(growthBps);
8036
- return (value * BPS$1 + (BPS$1 + g) / BigInt(2)) / (BPS$1 + g);
8037
- }
8038
8053
  function buildSolanaTrancheLadder(options) {
8039
8054
  const {
8040
8055
  currentTranche,
@@ -8055,14 +8070,14 @@ function buildSolanaTrancheLadder(options) {
8055
8070
  for (let id = currentTranche + 1; id <= endId; id++) {
8056
8071
  const prevCap = capacity.get(id - 1);
8057
8072
  const prevPrice = price.get(id - 1);
8058
- capacity.set(id, growOnce$1(prevCap, supplyGrowthBps));
8059
- price.set(id, growOnce$1(prevPrice, priceGrowthCents));
8073
+ capacity.set(id, growSupplyOnce$1(prevCap, supplyGrowthBps));
8074
+ price.set(id, growPriceOnceUsd1e8(prevPrice, priceGrowthCents));
8060
8075
  }
8061
8076
  for (let id = currentTranche - 1; id >= startId; id--) {
8062
8077
  const nextCap = capacity.get(id + 1);
8063
8078
  const nextPrice = price.get(id + 1);
8064
- capacity.set(id, shrinkOnce$1(nextCap, supplyGrowthBps));
8065
- price.set(id, shrinkOnce$1(nextPrice, priceGrowthCents));
8079
+ capacity.set(id, shrinkSupplyOnce$1(nextCap, supplyGrowthBps));
8080
+ price.set(id, shrinkPriceOnceUsd1e8(nextPrice, priceGrowthCents));
8066
8081
  }
8067
8082
  const ladder = [];
8068
8083
  for (let id = startId; id <= endId; id++) {
@@ -9118,13 +9133,9 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9118
9133
  }
9119
9134
  async getSystemAPY() {
9120
9135
  const ratePerEpoch = await this.getEpochRateDecimalFromProgram();
9121
- console.log("epochRateDecimal", ratePerEpoch);
9122
9136
  const epochsPerYear = await this.getEpochsPerYearFromCluster();
9123
- console.log("epochsPerYear", epochsPerYear);
9124
9137
  const apyDecimal = Math.pow(1 + ratePerEpoch, epochsPerYear) - 1;
9125
- console.log("apyDecimal", apyDecimal);
9126
9138
  const apyPercent = apyDecimal * 100;
9127
- console.log("apyPercent", apyPercent);
9128
9139
  return apyPercent;
9129
9140
  }
9130
9141
  async getEpochRateDecimalFromProgram() {
@@ -9133,8 +9144,6 @@ const _SolanaStakingClient = class _SolanaStakingClient {
9133
9144
  const stakeMetrics = await liqSolCoreProgram.account.stakeMetrics.fetch(stakeMetricsPda);
9134
9145
  const raw = BigInt(stakeMetrics.solSystemPayRate.toString());
9135
9146
  const rateDecimal = Number(raw) / Number(PAY_RATE_SCALE_FACTOR);
9136
- console.log("solSystemPayRate(raw)", raw.toString());
9137
- console.log("epochRateDecimal(computed)", rateDecimal);
9138
9147
  return rateDecimal;
9139
9148
  }
9140
9149
  async getEpochsPerYearFromCluster() {
@@ -34824,22 +34833,22 @@ const ADDRESSES = {
34824
34833
  WithdrawalVault: "0xC82FAf3Fed135B70A7E797864F504819a98E96c4",
34825
34834
  StakingModule: "0xdd24EffAa4B42f3273E2b44995639119c08daBea",
34826
34835
  YieldOracle: "0x56A27E1d10d4aEc7402dC26693fb7c0Eb66eF802",
34827
- OutpostManagerAuthority: "0xAEcd2aa6EeFa4Aa7Cb9368728aA89Ca59Aa9ea59",
34828
- iodata: "0x2c2ab53F6Bc146bd31B459E832Ce0B9Da78712d8",
34829
- Base58: "0x9F188Ec124c9ad9bF6D195650d8360Fd052F585A",
34830
- sysio_merkle: "0x6eDA3C4c34421Cd667800C17fe33E48f5698e004",
34831
- ReceiptNFT: "0xd083051d9bb8353875abCecAB50C6e4FB5e527a8",
34832
- MockAggregator: "0xFCfc3ddd4CBd9Ad3b3af3A374B8bdA1b66eE6FFF",
34833
- Pool: "0xee5F11aC9b104c18d2423f266c5E737fC95ebA92",
34834
- OutpostManager: "0xB1B6ba7FA156652849069aC7ADB281283D235B9f",
34835
- sysio_write: "0xEfA608136d372349C09a7aA57665C09Fb4a620Ca",
34836
- EthUsdPriceConsumer: "0x6337A23b61f98b1526faF2848385Abe9cB4cFF21",
34837
- BAR: "0x9264eAA449da94caF70Fc18522021a94C8DF32Fb",
34838
- OPPCommon: "0x86A8cA16ce521De3EBdd1C541fAf188795b59FD0",
34839
- OPP: "0x79e8395Bb5131FB285aCEE5329BB43E66f50F88C",
34840
- Pretoken: "0x62f98AF2f9C3EF4eF2fA7bc0245BD5a9315E7541",
34841
- OPPInbound: "0xC85f57Ff069711e0b3472De3963bd2fC2FEfF3e2",
34842
- Depositor: "0xb0BACAb6f13dd96281300be13a6346461b2f35F3"
34836
+ OutpostManagerAuthority: "0x57A3723B9f3C6022CAe394C859655E59382Fad18",
34837
+ iodata: "0x88896d4fa70C3a7Fb833C80BB5763a4c53A6aCB5",
34838
+ Base58: "0x0E9E6e8A32477F3B086Aaa26db2b928a816Da711",
34839
+ sysio_merkle: "0xf5858B784B080A08063FAe06dB6d91c5BBAA48C7",
34840
+ ReceiptNFT: "0xF1F5e063bFF6E0c09b0ac8020376E16c0be8eA10",
34841
+ EthUsdPriceConsumer: "0xFdb3Ab290179CA85204aD1Ffb8c1c3c42AEB768F",
34842
+ Pool: "0x15DaeB9562c6Dd21558f14CcdDf5C855499B8693",
34843
+ OutpostManager: "0x1aCCc78FCA9e2Ea4dcE849bf072C2248f36435cC",
34844
+ sysio_write: "0x513e472904EE67A8E27ebaF2411f3ed3851F4514",
34845
+ Pretoken: "0xd7CDc79B90336720ecf02eD5A355cB0F7099F079",
34846
+ BAR: "0x4A01414dEA81b1961aE986Bc4E95B30f73770f99",
34847
+ OPPCommon: "0x3747Cc19A351BCBCE92055c419e7d710C4b399aA",
34848
+ OPP: "0xF577FDc80014ef19DF258243e0551c888Da809E4",
34849
+ Depositor: "0xD9Eb2A2d4e9eD7e2257153041B29DCeCDee8BCFe",
34850
+ OPPInbound: "0x232C01f2528A5013af3703bE4B4ce30A793Ee8BD",
34851
+ MockAggregator: "0xFCfc3ddd4CBd9Ad3b3af3A374B8bdA1b66eE6FFF"
34843
34852
  };
34844
34853
  const CONTRACTS = {
34845
34854
  LiqEthAuthority: {
@@ -35023,7 +35032,7 @@ class EthereumContractService {
35023
35032
  }
35024
35033
  }
35025
35034
 
35026
- const BPS = BigInt(1e4);
35035
+ BigInt(1e4);
35027
35036
  function formatContractErrors(err) {
35028
35037
  if (err.errorName && err.errorArgs) {
35029
35038
  const errorObj = {
@@ -35093,20 +35102,27 @@ async function sendOPPFinalize(opp, gasLimit) {
35093
35102
  throw err;
35094
35103
  }
35095
35104
  }
35096
- function growOnce(value, growthBps) {
35105
+ const BPS_DENOM = BigInt(1e4);
35106
+ const USD_ONCHAIN_SCALE = BigInt(1e18);
35107
+ const USD_CLIENT_SCALE = BigInt(1e8);
35108
+ const USD_SCALE_DOWN = USD_ONCHAIN_SCALE / USD_CLIENT_SCALE;
35109
+ function growSupplyOnce(value, growthBps) {
35097
35110
  const g = BigInt(growthBps);
35098
- return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
35111
+ return value * (BPS_DENOM + g) / BPS_DENOM;
35099
35112
  }
35100
- function shrinkOnce(value, growthBps) {
35113
+ function shrinkSupplyOnce(value, growthBps) {
35101
35114
  const g = BigInt(growthBps);
35102
- return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
35115
+ return value * BPS_DENOM / (BPS_DENOM + g);
35103
35116
  }
35104
- function getTrancheSize(startSupply, supplyGrowthBps, trancheNumber) {
35105
- let supply = startSupply;
35106
- for (let i = 0; i < trancheNumber; i++) {
35107
- supply = (supply * (BPS + BigInt(supplyGrowthBps)) + BPS / BigInt(2)) / BPS;
35108
- }
35109
- return supply;
35117
+ function growPriceOnceUsd1e18(value, stepUsd1e18) {
35118
+ return value + stepUsd1e18;
35119
+ }
35120
+ function shrinkPriceOnceUsd1e18(value, stepUsd1e18) {
35121
+ if (value <= stepUsd1e18) return BigInt(0);
35122
+ return value - stepUsd1e18;
35123
+ }
35124
+ function usd1e18To1e8(raw) {
35125
+ return raw / USD_SCALE_DOWN;
35110
35126
  }
35111
35127
  function buildEthereumTrancheLadder(options) {
35112
35128
  const {
@@ -35114,29 +35130,32 @@ function buildEthereumTrancheLadder(options) {
35114
35130
  initialTrancheSupply,
35115
35131
  currentTrancheSupply,
35116
35132
  currentPriceUsd,
35117
- supplyGrowthBps,
35118
35133
  priceGrowthCents,
35134
+ supplyGrowthBps,
35119
35135
  windowBefore = 5,
35120
35136
  windowAfter = 5
35121
35137
  } = options;
35122
35138
  const startId = Math.max(0, currentTranche - windowBefore);
35123
35139
  const endId = currentTranche + windowAfter;
35124
- const currentTrancheSize = getTrancheSize(initialTrancheSupply, supplyGrowthBps, currentTranche);
35125
35140
  const capacity = new Map();
35126
- const price = new Map();
35127
- capacity.set(currentTranche, currentTrancheSize);
35128
- price.set(currentTranche, currentPriceUsd);
35141
+ const priceUsd = new Map();
35142
+ let currentCap = initialTrancheSupply;
35143
+ for (let i = 0; i < currentTranche; i++) {
35144
+ currentCap = growSupplyOnce(currentCap, supplyGrowthBps);
35145
+ }
35146
+ capacity.set(currentTranche, currentCap);
35147
+ priceUsd.set(currentTranche, currentPriceUsd);
35129
35148
  for (let id = currentTranche + 1; id <= endId; id++) {
35130
35149
  const prevCap = capacity.get(id - 1);
35131
- const prevPrice = price.get(id - 1);
35132
- capacity.set(id, growOnce(prevCap, supplyGrowthBps));
35133
- price.set(id, growOnce(prevPrice, priceGrowthCents));
35150
+ const prevPrice = priceUsd.get(id - 1);
35151
+ capacity.set(id, growSupplyOnce(prevCap, supplyGrowthBps));
35152
+ priceUsd.set(id, growPriceOnceUsd1e18(prevPrice, priceGrowthCents));
35134
35153
  }
35135
35154
  for (let id = currentTranche - 1; id >= startId; id--) {
35136
35155
  const nextCap = capacity.get(id + 1);
35137
- const nextPrice = price.get(id + 1);
35138
- capacity.set(id, shrinkOnce(nextCap, supplyGrowthBps));
35139
- price.set(id, shrinkOnce(nextPrice, priceGrowthCents));
35156
+ const nextPrice = priceUsd.get(id + 1);
35157
+ capacity.set(id, shrinkSupplyOnce(nextCap, supplyGrowthBps));
35158
+ priceUsd.set(id, shrinkPriceOnceUsd1e18(nextPrice, priceGrowthCents));
35140
35159
  }
35141
35160
  const ladder = [];
35142
35161
  for (let id = startId; id <= endId; id++) {
@@ -35149,12 +35168,14 @@ function buildEthereumTrancheLadder(options) {
35149
35168
  } else {
35150
35169
  sold = BigInt(0);
35151
35170
  }
35171
+ const remaining = cap - sold;
35172
+ const priceClientScale = usd1e18To1e8(priceUsd.get(id));
35152
35173
  ladder.push({
35153
35174
  id,
35154
35175
  capacity: cap,
35155
35176
  sold,
35156
- remaining: cap - sold,
35157
- priceUsd: price.get(id)
35177
+ remaining,
35178
+ priceUsd: priceClientScale
35158
35179
  });
35159
35180
  }
35160
35181
  return ladder;
@@ -35170,7 +35191,7 @@ async function buildEthereumTrancheSnapshot(options) {
35170
35191
  indexBn,
35171
35192
  trancheNumberBn,
35172
35193
  currentTrancheSupply,
35173
- tranchePriceWadBn,
35194
+ tranchePriceUsdBn,
35174
35195
  totalTrancheSupply,
35175
35196
  initialTrancheSupply,
35176
35197
  supplyGrowthBps,
@@ -35181,15 +35202,23 @@ async function buildEthereumTrancheSnapshot(options) {
35181
35202
  const totalShares = BigInt(totalSharesBn.toString()) / BigInt(1e10);
35182
35203
  const currentIndex = BigInt(indexBn.toString());
35183
35204
  const currentTranche = Number(trancheNumberBn.toString());
35184
- const currentPriceUsd = BigInt(tranchePriceWadBn.toString()) / BigInt(1e10);
35205
+ const currentPriceUsd1e18 = BigInt(tranchePriceUsdBn.toString());
35206
+ const priceGrowthStepUsd1e18 = BigInt(priceGrowthCents.toString());
35207
+ const priceGrowthCentsNumber = Number(
35208
+ priceGrowthStepUsd1e18 / BigInt(1e16)
35209
+ );
35210
+ const currentTrancheSupplyBig = BigInt(currentTrancheSupply.toString());
35211
+ const totalTrancheSupplyBig = BigInt(totalTrancheSupply.toString());
35212
+ const initialTrancheSupplyBig = BigInt(initialTrancheSupply.toString());
35213
+ const currentPriceUsd = currentPriceUsd1e18 / BigInt(1e10);
35185
35214
  const ladder = buildEthereumTrancheLadder({
35186
35215
  currentTranche,
35187
- totalTrancheSupply,
35188
- initialTrancheSupply,
35189
- currentTrancheSupply,
35190
- currentPriceUsd,
35216
+ totalTrancheSupply: totalTrancheSupplyBig,
35217
+ initialTrancheSupply: initialTrancheSupplyBig,
35218
+ currentTrancheSupply: currentTrancheSupplyBig,
35219
+ currentPriceUsd: currentPriceUsd1e18,
35220
+ priceGrowthCents: priceGrowthStepUsd1e18,
35191
35221
  supplyGrowthBps,
35192
- priceGrowthCents,
35193
35222
  windowBefore: ladderWindowBefore,
35194
35223
  windowAfter: ladderWindowAfter
35195
35224
  });
@@ -35200,10 +35229,10 @@ async function buildEthereumTrancheSnapshot(options) {
35200
35229
  currentTranche,
35201
35230
  currentPriceUsd,
35202
35231
  supplyGrowthBps,
35203
- priceGrowthCents,
35204
- currentTrancheSupply,
35205
- initialTrancheSupply,
35206
- totalPretokensSold: totalTrancheSupply,
35232
+ priceGrowthCents: priceGrowthCentsNumber,
35233
+ totalPretokensSold: totalTrancheSupplyBig,
35234
+ currentTrancheSupply: currentTrancheSupplyBig,
35235
+ initialTrancheSupply: initialTrancheSupplyBig,
35207
35236
  nativePriceUsd: ethPriceUsd,
35208
35237
  nativePriceTimestamp,
35209
35238
  ladder
@@ -35986,7 +36015,7 @@ class EthereumStakingClient {
35986
36015
  try {
35987
36016
  const blockNumber = await this.provider.getBlockNumber();
35988
36017
  const blockTag = { blockTag: blockNumber };
35989
- const [totalSharesBn, indexBn, trancheNumberBn, trancheSupplyBn, tranchePriceWadBn, totalSupplyBn, supplyGrowthBps, priceGrowthCents, minPriceUsd, maxPriceUsd] = await Promise.all([
36018
+ const [totalSharesBn, indexBn, trancheNumberBn, trancheSupplyBn, tranchePriceUsdBn, totalSupplyBn, supplyGrowthBps, priceGrowthCents, minPriceUsd, maxPriceUsd] = await Promise.all([
35990
36019
  this.contract.Depositor.totalShares(blockTag),
35991
36020
  this.contract.Depositor.index(blockTag),
35992
36021
  this.contract.Pretoken.trancheNumber(blockTag),
@@ -36010,7 +36039,7 @@ class EthereumStakingClient {
36010
36039
  indexBn,
36011
36040
  trancheNumberBn,
36012
36041
  currentTrancheSupply,
36013
- tranchePriceWadBn,
36042
+ tranchePriceUsdBn,
36014
36043
  totalTrancheSupply,
36015
36044
  initialTrancheSupply,
36016
36045
  supplyGrowthBps,
@@ -36023,7 +36052,6 @@ class EthereumStakingClient {
36023
36052
  ladderWindowAfter: windowAfter
36024
36053
  });
36025
36054
  } catch (err) {
36026
- console.log(err);
36027
36055
  throw new Error(`Error fetching Ethereum tranche snapshot: ${err?.message || err}`);
36028
36056
  }
36029
36057
  }
@@ -36090,6 +36118,7 @@ class Staker {
36090
36118
  config.forEach((cfg) => {
36091
36119
  switch (cfg.network.chainId) {
36092
36120
  case SolChainID.Devnet:
36121
+ case SolChainID.WireTestnet:
36093
36122
  this.clients.set(cfg.network.chainId, new SolanaStakingClient(cfg));
36094
36123
  break;
36095
36124
  case EvmChainID.Hoodi: