@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/package.json
CHANGED
|
@@ -66,24 +66,57 @@ export const ADDRESSES: AddressBook = {
|
|
|
66
66
|
YieldOracle: "0x56A27E1d10d4aEc7402dC26693fb7c0Eb66eF802",
|
|
67
67
|
|
|
68
68
|
//Outpost contracts
|
|
69
|
-
OutpostManagerAuthority: "
|
|
70
|
-
iodata: "
|
|
71
|
-
Base58: "
|
|
72
|
-
sysio_merkle: "
|
|
73
|
-
ReceiptNFT: "
|
|
69
|
+
OutpostManagerAuthority: "0x57A3723B9f3C6022CAe394C859655E59382Fad18",
|
|
70
|
+
iodata: "0x88896d4fa70C3a7Fb833C80BB5763a4c53A6aCB5",
|
|
71
|
+
Base58: "0x0E9E6e8A32477F3B086Aaa26db2b928a816Da711",
|
|
72
|
+
sysio_merkle: "0xf5858B784B080A08063FAe06dB6d91c5BBAA48C7",
|
|
73
|
+
ReceiptNFT: "0xF1F5e063bFF6E0c09b0ac8020376E16c0be8eA10",
|
|
74
|
+
EthUsdPriceConsumer: "0xFdb3Ab290179CA85204aD1Ffb8c1c3c42AEB768F",
|
|
75
|
+
Pool: "0x15DaeB9562c6Dd21558f14CcdDf5C855499B8693",
|
|
76
|
+
OutpostManager: "0x1aCCc78FCA9e2Ea4dcE849bf072C2248f36435cC",
|
|
77
|
+
sysio_write: "0x513e472904EE67A8E27ebaF2411f3ed3851F4514",
|
|
78
|
+
Pretoken: "0xd7CDc79B90336720ecf02eD5A355cB0F7099F079",
|
|
79
|
+
BAR: "0x4A01414dEA81b1961aE986Bc4E95B30f73770f99",
|
|
80
|
+
OPPCommon: "0x3747Cc19A351BCBCE92055c419e7d710C4b399aA",
|
|
81
|
+
OPP: "0xF577FDc80014ef19DF258243e0551c888Da809E4",
|
|
82
|
+
Depositor: "0xD9Eb2A2d4e9eD7e2257153041B29DCeCDee8BCFe",
|
|
83
|
+
OPPInbound: "0x232C01f2528A5013af3703bE4B4ce30A793Ee8BD",
|
|
74
84
|
MockAggregator: "0xFCfc3ddd4CBd9Ad3b3af3A374B8bdA1b66eE6FFF",
|
|
75
|
-
|
|
76
|
-
OutpostManager: "0xB1B6ba7FA156652849069aC7ADB281283D235B9f",
|
|
77
|
-
sysio_write: "0xEfA608136d372349C09a7aA57665C09Fb4a620Ca",
|
|
78
|
-
EthUsdPriceConsumer: "0x6337A23b61f98b1526faF2848385Abe9cB4cFF21",
|
|
79
|
-
BAR: "0x9264eAA449da94caF70Fc18522021a94C8DF32Fb",
|
|
80
|
-
OPPCommon: "0x86A8cA16ce521De3EBdd1C541fAf188795b59FD0",
|
|
81
|
-
OPP: "0x79e8395Bb5131FB285aCEE5329BB43E66f50F88C",
|
|
82
|
-
Pretoken: "0x62f98AF2f9C3EF4eF2fA7bc0245BD5a9315E7541",
|
|
83
|
-
OPPInbound: "0xC85f57Ff069711e0b3472De3963bd2fC2FEfF3e2",
|
|
84
|
-
Depositor: "0xb0BACAb6f13dd96281300be13a6346461b2f35F3"
|
|
85
|
+
|
|
85
86
|
};
|
|
86
87
|
|
|
88
|
+
// Latest
|
|
89
|
+
// LiqETH contracts
|
|
90
|
+
// LiqEthAuthority: "0x612536e386801b337363Cfa4CC0a7C33Ad588136",
|
|
91
|
+
// BeaconState: "0x48462108c8254568e1d2D4fE3178579d9298ceC4",
|
|
92
|
+
// WithdrawalQueue: "0x49aeFA8B860d908476724e00b48fDa7529f63DbA",
|
|
93
|
+
// LiqEthToken: "0x1e0fb59F0C1Db95fD8f8743B1B3e709CdccF4002",
|
|
94
|
+
// Accounting: "0x679A76d462B9A499F8D23Cb3Fa6CbeB81B5779b9",
|
|
95
|
+
// DepositManager: "0xe63a8f755195D019Db893BF0542A2533895ec927",
|
|
96
|
+
// WithdrawalVault: "0x5C9C8d9Ec8F1Cb64D231b301712405c5E14C175d",
|
|
97
|
+
// StakingModule: "0x5dB271F09f840b49E5E77A3B8fDA30F56A66af20",
|
|
98
|
+
// YieldOracle: "0x323022827e4922a14f30eF8Ad83A393628e0Ac34",
|
|
99
|
+
|
|
100
|
+
// //Outpost contracts
|
|
101
|
+
// OutpostManagerAuthority: "0x5047Cf5F7bae2d5737B29AAbE910ceE0F3344059",
|
|
102
|
+
// iodata: "0x82A24E7240DaBaAD49A157dB2a203Edb6486d81f",
|
|
103
|
+
// Base58: "0x97aE9B0A8D1678fC73EF7B67539236A85284E2FF",
|
|
104
|
+
// sysio_merkle: "0x3A30901fC4dD25E75dcF9c790b620183aF0Bc3D5",
|
|
105
|
+
// ReceiptNFT: "0xee4f7075B8ac06bb709075D5963C8e012Ef74cc1",
|
|
106
|
+
// EthUsdPriceConsumer: "0x202719423E364aB0C8b4005ee25A20c4A5AB28DC",
|
|
107
|
+
// Pool: "0x8fB1a92c4107Ac1072f51Fac3617A5494Eb71573",
|
|
108
|
+
// OutpostManager: "0x88760aD68a557Aa4FeCde82dA9B024948e7B6074",
|
|
109
|
+
// sysio_write: "0x7485Bb3AA184D33dC54149bBE0BEd548791a6D8f",
|
|
110
|
+
// Pretoken: "0x474B3944e8b9C82264434f394d2367f046869Adc",
|
|
111
|
+
// BAR: "0x779Bb699A0ad10EB8A13d177e594B1268f72C602",
|
|
112
|
+
// OPPCommon: "0x14280b40a8a1F037dDBf9bddf8b78Bc4f11276BA",
|
|
113
|
+
// OPP: "0xBae03C8bb8f557dc48AE9D6F9032d503819B11a7",
|
|
114
|
+
// Depositor: "0x66f41027F9642384c73ce9C8944340a1Af497982",
|
|
115
|
+
// OPPInbound: "0x2AA0833Fc72314faD52a2dA932973abB8491E96F",
|
|
116
|
+
// MockAggregator: "0xFCfc3ddd4CBd9Ad3b3af3A374B8bdA1b66eE6FFF",
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
87
120
|
export type Contracts<T extends string = ContractName> = Record<T, ContractConfig>;
|
|
88
121
|
|
|
89
122
|
export type ContractConfig = {
|
|
@@ -349,7 +349,7 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
349
349
|
|
|
350
350
|
|
|
351
351
|
// Fetch all required contract data
|
|
352
|
-
const [totalSharesBn, indexBn, trancheNumberBn, trancheSupplyBn,
|
|
352
|
+
const [totalSharesBn, indexBn, trancheNumberBn, trancheSupplyBn, tranchePriceUsdBn, totalSupplyBn, supplyGrowthBps, priceGrowthCents, minPriceUsd, maxPriceUsd] = await Promise.all([
|
|
353
353
|
this.contract.Depositor.totalShares(blockTag),
|
|
354
354
|
this.contract.Depositor.index(blockTag),
|
|
355
355
|
this.contract.Pretoken.trancheNumber(blockTag),
|
|
@@ -362,7 +362,6 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
362
362
|
this.contract.EthUsdPriceConsumer.MAX_PRICE(),
|
|
363
363
|
]);
|
|
364
364
|
|
|
365
|
-
|
|
366
365
|
const totalTrancheSupply = BigInt(totalSupplyBn.toString()) / BigInt(1e10);
|
|
367
366
|
const currentTrancheSupply = BigInt(trancheSupplyBn.toString()) / BigInt(1e10);
|
|
368
367
|
|
|
@@ -380,7 +379,7 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
380
379
|
indexBn,
|
|
381
380
|
trancheNumberBn,
|
|
382
381
|
currentTrancheSupply,
|
|
383
|
-
|
|
382
|
+
tranchePriceUsdBn,
|
|
384
383
|
totalTrancheSupply,
|
|
385
384
|
initialTrancheSupply,
|
|
386
385
|
supplyGrowthBps,
|
|
@@ -395,8 +394,6 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
395
394
|
});
|
|
396
395
|
}
|
|
397
396
|
catch (err: any) {
|
|
398
|
-
console.log(err);
|
|
399
|
-
|
|
400
397
|
throw new Error(`Error fetching Ethereum tranche snapshot: ${err?.message || err}`);
|
|
401
398
|
}
|
|
402
399
|
}
|
|
@@ -111,53 +111,57 @@ export async function sendOPPFinalize(opp: ethers.Contract, gasLimit?: ethers.Bi
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
|
|
114
|
+
const BPS_DENOM = BigInt(10_000);
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
// On-chain USD: 1e18 (wei-style)
|
|
117
|
+
const USD_ONCHAIN_SCALE = BigInt(1_000_000_000_000_000_000); // 1e18
|
|
118
|
+
// Client snapshot USD: 1e8 (to match fromScale8)
|
|
119
|
+
const USD_CLIENT_SCALE = BigInt(100_000_000); // 1e8
|
|
120
|
+
// Factor to go from 1e18 → 1e8
|
|
121
|
+
const USD_SCALE_DOWN = USD_ONCHAIN_SCALE / USD_CLIENT_SCALE; // 1e10
|
|
122
|
+
|
|
123
|
+
/** 2.5% growth in BPS for supply side */
|
|
124
|
+
function growSupplyOnce(value: bigint, growthBps: number): bigint {
|
|
120
125
|
const g = BigInt(growthBps);
|
|
121
|
-
return (value * (
|
|
126
|
+
return (value * (BPS_DENOM + g)) / BPS_DENOM;
|
|
122
127
|
}
|
|
123
128
|
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Apply one backward step: value * BPS / (BPS + growthBps).
|
|
127
|
-
* Also integer round-half-up.
|
|
128
|
-
*/
|
|
129
|
-
function shrinkOnce(value: bigint, growthBps: number): bigint {
|
|
129
|
+
function shrinkSupplyOnce(value: bigint, growthBps: number): bigint {
|
|
130
130
|
const g = BigInt(growthBps);
|
|
131
|
-
return (value *
|
|
131
|
+
return (value * BPS_DENOM) / (BPS_DENOM + g);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/** Linear USD price step in on-chain 1e18 scale */
|
|
135
|
+
function growPriceOnceUsd1e18(value: bigint, stepUsd1e18: bigint): bigint {
|
|
136
|
+
return value + stepUsd1e18;
|
|
137
|
+
}
|
|
134
138
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*/
|
|
139
|
-
function getTrancheSize(startSupply: bigint, supplyGrowthBps: number, trancheNumber: number): bigint {
|
|
140
|
-
let supply = startSupply;
|
|
141
|
-
for (let i = 0; i < trancheNumber; i++) {
|
|
142
|
-
supply = (supply * (BPS + BigInt(supplyGrowthBps)) + BPS / BigInt(2)) / BPS;
|
|
143
|
-
}
|
|
144
|
-
return supply;
|
|
139
|
+
function shrinkPriceOnceUsd1e18(value: bigint, stepUsd1e18: bigint): bigint {
|
|
140
|
+
if (value <= stepUsd1e18) return BigInt(0);
|
|
141
|
+
return value - stepUsd1e18;
|
|
145
142
|
}
|
|
146
143
|
|
|
144
|
+
/** Convert on-chain 1e18 USD to client 1e8 USD */
|
|
145
|
+
function usd1e18To1e8(raw: bigint): bigint {
|
|
146
|
+
// 1e18 / 1e8 = 1e10 factor difference
|
|
147
|
+
return raw / USD_SCALE_DOWN;
|
|
148
|
+
}
|
|
147
149
|
|
|
148
150
|
/**
|
|
149
|
-
* Build a local tranche ladder around the current tranche
|
|
150
|
-
* using only on-chain config + current state.
|
|
151
|
+
* Build a local tranche ladder around the current tranche.
|
|
151
152
|
*
|
|
153
|
+
* Inside this function:
|
|
154
|
+
* - `currentPriceUsd` and `priceGrowthCents` are treated as 1e18-scaled USD.
|
|
155
|
+
* - Output `priceUsd` is 1e8-scaled USD (for fromScale8()).
|
|
152
156
|
*/
|
|
153
157
|
export function buildEthereumTrancheLadder(options: {
|
|
154
158
|
currentTranche: number;
|
|
155
|
-
totalTrancheSupply: bigint,
|
|
159
|
+
totalTrancheSupply: bigint; // not used in local window, but kept for API parity
|
|
156
160
|
initialTrancheSupply: bigint;
|
|
157
|
-
currentTrancheSupply: bigint;
|
|
158
|
-
currentPriceUsd: bigint;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
currentTrancheSupply: bigint; // remaining in current tranche (1e8 scale)
|
|
162
|
+
currentPriceUsd: bigint; // 1e18 scale
|
|
163
|
+
priceGrowthCents: bigint; // 1e18 step, e.g. $0.02 → 2e16
|
|
164
|
+
supplyGrowthBps: number; // 250 = 2.5%
|
|
161
165
|
windowBefore?: number;
|
|
162
166
|
windowAfter?: number;
|
|
163
167
|
}): TrancheLadderItem[] {
|
|
@@ -166,44 +170,50 @@ export function buildEthereumTrancheLadder(options: {
|
|
|
166
170
|
initialTrancheSupply,
|
|
167
171
|
currentTrancheSupply,
|
|
168
172
|
currentPriceUsd,
|
|
169
|
-
supplyGrowthBps,
|
|
170
173
|
priceGrowthCents,
|
|
174
|
+
supplyGrowthBps,
|
|
171
175
|
windowBefore = 5,
|
|
172
176
|
windowAfter = 5,
|
|
173
177
|
} = options;
|
|
174
178
|
|
|
175
179
|
const startId = Math.max(0, currentTranche - windowBefore);
|
|
176
180
|
const endId = currentTranche + windowAfter;
|
|
177
|
-
|
|
178
|
-
//calculate total tranche size (e.g. 60,600 on tranche 2)
|
|
179
|
-
const currentTrancheSize = getTrancheSize(initialTrancheSupply, supplyGrowthBps, currentTranche);
|
|
180
181
|
|
|
181
|
-
const capacity = new Map<number, bigint>();
|
|
182
|
-
const
|
|
182
|
+
const capacity = new Map<number, bigint>(); // 1e8 pre-token units
|
|
183
|
+
const priceUsd = new Map<number, bigint>(); // 1e18 USD
|
|
184
|
+
|
|
185
|
+
// Capacity at the current tranche derived from initial supply & BPS growth
|
|
186
|
+
let currentCap = initialTrancheSupply;
|
|
187
|
+
for (let i = 0; i < currentTranche; i++) {
|
|
188
|
+
currentCap = growSupplyOnce(currentCap, supplyGrowthBps);
|
|
189
|
+
}
|
|
183
190
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
price.set(currentTranche, currentPriceUsd);
|
|
191
|
+
capacity.set(currentTranche, currentCap);
|
|
192
|
+
priceUsd.set(currentTranche, currentPriceUsd);
|
|
187
193
|
|
|
188
194
|
// Forward (future tranches)
|
|
189
195
|
for (let id = currentTranche + 1; id <= endId; id++) {
|
|
190
196
|
const prevCap = capacity.get(id - 1)!;
|
|
191
|
-
const prevPrice =
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
const prevPrice = priceUsd.get(id - 1)!;
|
|
198
|
+
|
|
199
|
+
capacity.set(id, growSupplyOnce(prevCap, supplyGrowthBps));
|
|
200
|
+
priceUsd.set(id, growPriceOnceUsd1e18(prevPrice, priceGrowthCents));
|
|
194
201
|
}
|
|
195
202
|
|
|
196
203
|
// Backward (past tranches)
|
|
197
204
|
for (let id = currentTranche - 1; id >= startId; id--) {
|
|
198
205
|
const nextCap = capacity.get(id + 1)!;
|
|
199
|
-
const nextPrice =
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
const nextPrice = priceUsd.get(id + 1)!;
|
|
207
|
+
|
|
208
|
+
capacity.set(id, shrinkSupplyOnce(nextCap, supplyGrowthBps));
|
|
209
|
+
priceUsd.set(id, shrinkPriceOnceUsd1e18(nextPrice, priceGrowthCents));
|
|
202
210
|
}
|
|
203
211
|
|
|
212
|
+
// Build ladder view
|
|
204
213
|
const ladder: TrancheLadderItem[] = [];
|
|
205
214
|
for (let id = startId; id <= endId; id++) {
|
|
206
215
|
const cap = capacity.get(id)!;
|
|
216
|
+
|
|
207
217
|
let sold: bigint;
|
|
208
218
|
if (id < currentTranche) {
|
|
209
219
|
sold = cap;
|
|
@@ -213,19 +223,21 @@ export function buildEthereumTrancheLadder(options: {
|
|
|
213
223
|
sold = BigInt(0);
|
|
214
224
|
}
|
|
215
225
|
|
|
226
|
+
const remaining = cap - sold;
|
|
227
|
+
const priceClientScale = usd1e18To1e8(priceUsd.get(id)!); // 1e8
|
|
228
|
+
|
|
216
229
|
ladder.push({
|
|
217
230
|
id,
|
|
218
231
|
capacity: cap,
|
|
219
232
|
sold,
|
|
220
|
-
remaining
|
|
221
|
-
priceUsd:
|
|
233
|
+
remaining,
|
|
234
|
+
priceUsd: priceClientScale,
|
|
222
235
|
});
|
|
223
236
|
}
|
|
224
237
|
|
|
225
238
|
return ladder;
|
|
226
239
|
}
|
|
227
240
|
|
|
228
|
-
|
|
229
241
|
/**
|
|
230
242
|
* Turn raw liqsol_core accounts into a chain-agnostic TrancheSnapshot for SOL.
|
|
231
243
|
* All math stays here; TokenClient just wires accounts + connection.
|
|
@@ -236,11 +248,11 @@ export async function buildEthereumTrancheSnapshot(options: {
|
|
|
236
248
|
indexBn;
|
|
237
249
|
trancheNumberBn;
|
|
238
250
|
currentTrancheSupply;
|
|
239
|
-
|
|
251
|
+
tranchePriceUsdBn;
|
|
240
252
|
totalTrancheSupply;
|
|
241
253
|
initialTrancheSupply;
|
|
242
254
|
supplyGrowthBps;
|
|
243
|
-
priceGrowthCents;
|
|
255
|
+
priceGrowthCents; // BigNumber from contract (1e18 for $0.02)
|
|
244
256
|
minPriceUsd;
|
|
245
257
|
maxPriceUsd;
|
|
246
258
|
|
|
@@ -256,53 +268,73 @@ export async function buildEthereumTrancheSnapshot(options: {
|
|
|
256
268
|
ladderWindowBefore,
|
|
257
269
|
ladderWindowAfter,
|
|
258
270
|
|
|
259
|
-
totalSharesBn,
|
|
260
|
-
indexBn,
|
|
261
|
-
trancheNumberBn,
|
|
262
|
-
currentTrancheSupply,
|
|
263
|
-
|
|
271
|
+
totalSharesBn,
|
|
272
|
+
indexBn,
|
|
273
|
+
trancheNumberBn,
|
|
274
|
+
currentTrancheSupply,
|
|
275
|
+
tranchePriceUsdBn,
|
|
264
276
|
totalTrancheSupply,
|
|
265
277
|
initialTrancheSupply,
|
|
266
278
|
supplyGrowthBps,
|
|
267
279
|
priceGrowthCents,
|
|
268
|
-
minPriceUsd,
|
|
280
|
+
minPriceUsd,
|
|
269
281
|
maxPriceUsd,
|
|
270
282
|
} = options;
|
|
271
283
|
|
|
284
|
+
// ---- BigNumber -> bigint conversions ----
|
|
285
|
+
|
|
286
|
+
// Shares: keep your prior behaviour (1e8 scale) via /1e10
|
|
287
|
+
const totalShares = BigInt(totalSharesBn.toString()) / BigInt(10_000_000_000); // 1e10
|
|
272
288
|
|
|
273
|
-
// convert default BigNumber to bigint for hub to handle, and partially convert from 1e18 to 1e8 for the hub
|
|
274
|
-
const totalShares = BigInt(totalSharesBn.toString()) / BigInt(1e10);
|
|
275
289
|
const currentIndex = BigInt(indexBn.toString()); // RAY (1e27)
|
|
290
|
+
|
|
276
291
|
const currentTranche = Number(trancheNumberBn.toString());
|
|
277
|
-
const currentPriceUsd = BigInt(tranchePriceWadBn.toString()) / BigInt(1e10); // 1e18 WAD
|
|
278
292
|
|
|
293
|
+
// Prices & step in 1e18 scale from contract
|
|
294
|
+
const currentPriceUsd1e18 = BigInt(tranchePriceUsdBn.toString());
|
|
295
|
+
const priceGrowthStepUsd1e18 = BigInt(priceGrowthCents.toString());
|
|
296
|
+
|
|
297
|
+
// Convert price step to “cents” number for snapshot:
|
|
298
|
+
// 1 USD = 1e18 → 1 cent = 1e16.
|
|
299
|
+
const priceGrowthCentsNumber = Number(
|
|
300
|
+
priceGrowthStepUsd1e18 / BigInt(10_000_000_000_000_000) // 1e16
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
// Pre-token supplies (already 1e8-ish scale on-chain)
|
|
304
|
+
const currentTrancheSupplyBig = BigInt(currentTrancheSupply.toString());
|
|
305
|
+
const totalTrancheSupplyBig = BigInt(totalTrancheSupply.toString());
|
|
306
|
+
const initialTrancheSupplyBig = BigInt(initialTrancheSupply.toString());
|
|
307
|
+
|
|
308
|
+
// UI-current price (1e8 scale)
|
|
309
|
+
const currentPriceUsd = currentPriceUsd1e18 / BigInt(10_000_000_000); // 1e10
|
|
310
|
+
|
|
311
|
+
// ---- Build ladder ----
|
|
279
312
|
|
|
280
313
|
const ladder = buildEthereumTrancheLadder({
|
|
281
314
|
currentTranche,
|
|
282
|
-
totalTrancheSupply,
|
|
283
|
-
initialTrancheSupply,
|
|
284
|
-
currentTrancheSupply,
|
|
285
|
-
currentPriceUsd,
|
|
315
|
+
totalTrancheSupply: totalTrancheSupplyBig,
|
|
316
|
+
initialTrancheSupply: initialTrancheSupplyBig,
|
|
317
|
+
currentTrancheSupply: currentTrancheSupplyBig,
|
|
318
|
+
currentPriceUsd: currentPriceUsd1e18, // 1e18
|
|
319
|
+
priceGrowthCents: priceGrowthStepUsd1e18, // 1e18 step
|
|
286
320
|
supplyGrowthBps,
|
|
287
|
-
priceGrowthCents,
|
|
288
321
|
windowBefore: ladderWindowBefore,
|
|
289
322
|
windowAfter: ladderWindowAfter,
|
|
290
323
|
});
|
|
291
324
|
|
|
292
|
-
|
|
293
325
|
return {
|
|
294
326
|
chainID,
|
|
295
327
|
currentIndex,
|
|
296
328
|
totalShares,
|
|
297
329
|
currentTranche,
|
|
298
|
-
currentPriceUsd,
|
|
330
|
+
currentPriceUsd, // 1e8
|
|
299
331
|
supplyGrowthBps,
|
|
300
|
-
priceGrowthCents,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
332
|
+
priceGrowthCents: priceGrowthCentsNumber, // <-- number as required
|
|
333
|
+
totalPretokensSold: totalTrancheSupplyBig,
|
|
334
|
+
currentTrancheSupply: currentTrancheSupplyBig,
|
|
335
|
+
initialTrancheSupply: initialTrancheSupplyBig,
|
|
304
336
|
nativePriceUsd: ethPriceUsd,
|
|
305
337
|
nativePriceTimestamp,
|
|
306
338
|
ladder,
|
|
307
339
|
};
|
|
308
|
-
}
|
|
340
|
+
}
|
|
@@ -490,19 +490,12 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
490
490
|
async getSystemAPY(): Promise<number> {
|
|
491
491
|
// 1) Per-epoch rate (decimal) from on-chain stakeMetrics
|
|
492
492
|
const ratePerEpoch = await this.getEpochRateDecimalFromProgram();
|
|
493
|
-
console.log('epochRateDecimal', ratePerEpoch);
|
|
494
|
-
|
|
495
493
|
// 2) Live epochs-per-year estimate from cluster
|
|
496
494
|
const epochsPerYear = await this.getEpochsPerYearFromCluster();
|
|
497
|
-
console.log('epochsPerYear', epochsPerYear);
|
|
498
|
-
|
|
499
495
|
// 3) Compound: (1 + r)^N - 1
|
|
500
496
|
const apyDecimal = Math.pow(1 + ratePerEpoch, epochsPerYear) - 1;
|
|
501
|
-
console.log('apyDecimal', apyDecimal);
|
|
502
|
-
|
|
503
497
|
// 4) Convert to percent
|
|
504
498
|
const apyPercent = apyDecimal * 100;
|
|
505
|
-
console.log('apyPercent', apyPercent);
|
|
506
499
|
|
|
507
500
|
return apyPercent;
|
|
508
501
|
}
|
|
@@ -524,9 +517,6 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
524
517
|
// Convert to JS number in **decimal per epoch** units
|
|
525
518
|
const rateDecimal = Number(raw) / Number(PAY_RATE_SCALE_FACTOR);
|
|
526
519
|
|
|
527
|
-
console.log('solSystemPayRate(raw)', raw.toString());
|
|
528
|
-
console.log('epochRateDecimal(computed)', rateDecimal);
|
|
529
|
-
|
|
530
520
|
return rateDecimal;
|
|
531
521
|
}
|
|
532
522
|
|
|
@@ -55,11 +55,51 @@ import { ChainID } from '@wireio/core';
|
|
|
55
55
|
// -----------------------------------------------------------------------------
|
|
56
56
|
// Tranche Support
|
|
57
57
|
// -----------------------------------------------------------------------------
|
|
58
|
-
|
|
59
58
|
const INDEX_SCALE = BigInt(1_000_000_000_000); // 1e12
|
|
60
|
-
const USD_SCALE = BigInt(100_000_000);
|
|
59
|
+
const USD_SCALE = BigInt(100_000_000); // 1e8
|
|
61
60
|
const BPS = BigInt(10_000);
|
|
62
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Apply one forward growth step: value * (BPS + growthBps) / BPS.
|
|
64
|
+
* Simple integer round-half-up.
|
|
65
|
+
*/
|
|
66
|
+
function growSupplyOnce(value: bigint, growthBps: number): bigint {
|
|
67
|
+
const g = BigInt(growthBps);
|
|
68
|
+
return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Apply one backward step: value * BPS / (BPS + growthBps).
|
|
73
|
+
* Also integer round-half-up.
|
|
74
|
+
*/
|
|
75
|
+
function shrinkSupplyOnce(value: bigint, growthBps: number): bigint {
|
|
76
|
+
const g = BigInt(growthBps);
|
|
77
|
+
return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Price step is expressed in *cents*, while prices are 1e8 USD.
|
|
82
|
+
* 1 cent = 0.01 * 1e8 = 1e6, so:
|
|
83
|
+
* step = priceGrowthCents * 1e6
|
|
84
|
+
*/
|
|
85
|
+
function priceStepUsd1e8(priceGrowthCents: number): bigint {
|
|
86
|
+
if (!priceGrowthCents) return BigInt(0);
|
|
87
|
+
const CENT_SCALE = USD_SCALE / BigInt(100); // 1e6
|
|
88
|
+
return BigInt(priceGrowthCents) * CENT_SCALE;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function growPriceOnceUsd1e8(value: bigint, priceGrowthCents: number): bigint {
|
|
92
|
+
const step = priceStepUsd1e8(priceGrowthCents);
|
|
93
|
+
return value + step;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function shrinkPriceOnceUsd1e8(value: bigint, priceGrowthCents: number): bigint {
|
|
97
|
+
const step = priceStepUsd1e8(priceGrowthCents);
|
|
98
|
+
if (step === BigInt(0)) return value;
|
|
99
|
+
if (value <= step) return BigInt(0);
|
|
100
|
+
return value - step;
|
|
101
|
+
}
|
|
102
|
+
|
|
63
103
|
/** BN | bigint -> bigint helper (keeps code readable) */
|
|
64
104
|
export function toBigint(x: any): bigint {
|
|
65
105
|
if (typeof x === 'bigint') return x;
|
|
@@ -80,24 +120,6 @@ export function tokensToShares(amount: bigint, currentIndex: bigint): bigint {
|
|
|
80
120
|
return r === BigInt(0) ? q : q + BigInt(1);
|
|
81
121
|
}
|
|
82
122
|
|
|
83
|
-
/**
|
|
84
|
-
* Apply one forward growth step: value * (BPS + growthBps) / BPS.
|
|
85
|
-
* Simple integer round-half-up.
|
|
86
|
-
*/
|
|
87
|
-
function growOnce(value: bigint, growthBps: number): bigint {
|
|
88
|
-
const g = BigInt(growthBps);
|
|
89
|
-
return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Apply one backward step: value * BPS / (BPS + growthBps).
|
|
94
|
-
* Also integer round-half-up.
|
|
95
|
-
*/
|
|
96
|
-
function shrinkOnce(value: bigint, growthBps: number): bigint {
|
|
97
|
-
const g = BigInt(growthBps);
|
|
98
|
-
return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
123
|
/**
|
|
102
124
|
* Build a local tranche ladder around the current tranche
|
|
103
125
|
* using only on-chain config + current state.
|
|
@@ -112,9 +134,9 @@ export function buildSolanaTrancheLadder(options: {
|
|
|
112
134
|
currentTranche: number;
|
|
113
135
|
initialTrancheSupply: bigint;
|
|
114
136
|
currentTrancheSupply: bigint;
|
|
115
|
-
currentPriceUsd: bigint;
|
|
137
|
+
currentPriceUsd: bigint; // 1e8 scale
|
|
116
138
|
supplyGrowthBps: number;
|
|
117
|
-
priceGrowthCents: number;
|
|
139
|
+
priceGrowthCents: number; // e.g. 2 -> $0.02 per tranche
|
|
118
140
|
windowBefore?: number;
|
|
119
141
|
windowAfter?: number;
|
|
120
142
|
}): TrancheLadderItem[] {
|
|
@@ -135,35 +157,41 @@ export function buildSolanaTrancheLadder(options: {
|
|
|
135
157
|
const capacity = new Map<number, bigint>();
|
|
136
158
|
const price = new Map<number, bigint>();
|
|
137
159
|
|
|
138
|
-
// Seed current
|
|
160
|
+
// Seed current tranche
|
|
139
161
|
capacity.set(currentTranche, initialTrancheSupply);
|
|
140
162
|
price.set(currentTranche, currentPriceUsd);
|
|
141
163
|
|
|
142
|
-
// Forward (future tranches)
|
|
164
|
+
// Forward (future tranches): grow supply by BPS, price by +cents (linear)
|
|
143
165
|
for (let id = currentTranche + 1; id <= endId; id++) {
|
|
144
166
|
const prevCap = capacity.get(id - 1)!;
|
|
145
167
|
const prevPrice = price.get(id - 1)!;
|
|
146
|
-
|
|
147
|
-
|
|
168
|
+
|
|
169
|
+
capacity.set(id, growSupplyOnce(prevCap, supplyGrowthBps));
|
|
170
|
+
price.set(id, growPriceOnceUsd1e8(prevPrice, priceGrowthCents));
|
|
148
171
|
}
|
|
149
172
|
|
|
150
|
-
// Backward (past tranches)
|
|
173
|
+
// Backward (past tranches): shrink supply by inverse BPS, price by -cents
|
|
151
174
|
for (let id = currentTranche - 1; id >= startId; id--) {
|
|
152
175
|
const nextCap = capacity.get(id + 1)!;
|
|
153
176
|
const nextPrice = price.get(id + 1)!;
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
|
|
178
|
+
capacity.set(id, shrinkSupplyOnce(nextCap, supplyGrowthBps));
|
|
179
|
+
price.set(id, shrinkPriceOnceUsd1e8(nextPrice, priceGrowthCents));
|
|
156
180
|
}
|
|
157
181
|
|
|
158
182
|
const ladder: TrancheLadderItem[] = [];
|
|
159
183
|
for (let id = startId; id <= endId; id++) {
|
|
160
184
|
const cap = capacity.get(id)!;
|
|
185
|
+
|
|
161
186
|
let sold: bigint;
|
|
162
187
|
if (id < currentTranche) {
|
|
188
|
+
// Past tranches fully sold
|
|
163
189
|
sold = cap;
|
|
164
190
|
} else if (id === currentTranche) {
|
|
191
|
+
// Current tranche: cap - remaining
|
|
165
192
|
sold = cap - currentTrancheSupply;
|
|
166
193
|
} else {
|
|
194
|
+
// Future tranches not yet opened
|
|
167
195
|
sold = BigInt(0);
|
|
168
196
|
}
|
|
169
197
|
|
|
@@ -172,7 +200,7 @@ export function buildSolanaTrancheLadder(options: {
|
|
|
172
200
|
capacity: cap,
|
|
173
201
|
sold,
|
|
174
202
|
remaining: cap - sold,
|
|
175
|
-
priceUsd: price.get(id)!,
|
|
203
|
+
priceUsd: price.get(id)!, // still 1e8 scale
|
|
176
204
|
});
|
|
177
205
|
}
|
|
178
206
|
|