@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.browser.js +103 -74
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.js +103 -74
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +103 -74
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/ethereum/contract.ts +48 -15
- package/src/networks/ethereum/ethereum.ts +2 -5
- package/src/networks/ethereum/utils.ts +103 -71
- package/src/networks/solana/solana.ts +0 -10
- package/src/networks/solana/utils.ts +58 -30
- package/src/staker.ts +1 -0
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
|
|
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,
|
|
8145
|
-
price.set(id,
|
|
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,
|
|
8151
|
-
price.set(id,
|
|
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: "
|
|
35165
|
-
iodata: "
|
|
35166
|
-
Base58: "
|
|
35167
|
-
sysio_merkle: "
|
|
35168
|
-
ReceiptNFT: "
|
|
35169
|
-
|
|
35170
|
-
Pool: "
|
|
35171
|
-
OutpostManager: "
|
|
35172
|
-
sysio_write: "
|
|
35173
|
-
|
|
35174
|
-
BAR: "
|
|
35175
|
-
OPPCommon: "
|
|
35176
|
-
OPP: "
|
|
35177
|
-
|
|
35178
|
-
OPPInbound: "
|
|
35179
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
35475
|
+
return value * (BPS_DENOM + g) / BPS_DENOM;
|
|
35463
35476
|
}
|
|
35464
|
-
function
|
|
35477
|
+
function shrinkSupplyOnce(value, growthBps) {
|
|
35465
35478
|
const g = BigInt(growthBps);
|
|
35466
|
-
return
|
|
35479
|
+
return value * BPS_DENOM / (BPS_DENOM + g);
|
|
35467
35480
|
}
|
|
35468
|
-
function
|
|
35469
|
-
|
|
35470
|
-
|
|
35471
|
-
|
|
35472
|
-
|
|
35473
|
-
return
|
|
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
|
|
35491
|
-
|
|
35492
|
-
|
|
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 =
|
|
35496
|
-
capacity.set(id,
|
|
35497
|
-
|
|
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 =
|
|
35502
|
-
capacity.set(id,
|
|
35503
|
-
|
|
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
|
|
35521
|
-
priceUsd:
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
35570
|
-
|
|
35571
|
-
|
|
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,
|
|
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
|
-
|
|
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:
|