@wireio/stake 0.5.1 → 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 +150 -78
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +958 -0
- package/lib/stake.js +154 -78
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +150 -78
- 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 +97 -14
- package/src/networks/solana/utils.ts +58 -30
- package/src/staker.ts +1 -0
|
@@ -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
|
|