@floorlaunchpad/sdk 0.1.1 → 0.3.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/CHANGELOG.md +84 -0
- package/LICENSE +201 -60
- package/README.md +45 -24
- package/dist/abi/evm-event-names.js +12 -0
- package/dist/abi/evm.gen.js +130 -0
- package/dist/abi/functions.gen.js +144 -0
- package/dist/abi/index.js +17 -0
- package/dist/abi/solana.gen.js +128 -0
- package/dist/burn.js +21 -0
- package/dist/client/evm/index.js +191 -0
- package/dist/client/index.js +19 -0
- package/dist/client/solana/index.js +259 -0
- package/dist/client/types.js +5 -0
- package/dist/codec.js +77 -0
- package/dist/config/codeHash.js +9 -0
- package/dist/config/generated.js +746 -0
- package/dist/config/index.js +49 -0
- package/dist/config/registry.gen.js +118 -0
- package/dist/config/solana-genesis.js +7 -0
- package/dist/ed25519.js +31 -0
- package/dist/errors.js +249 -0
- package/dist/events/index.js +40 -0
- package/dist/events/types.gen.js +3 -0
- package/dist/evm/abi.js +283 -0
- package/dist/evm/balances.js +26 -0
- package/dist/evm/chains.js +144 -0
- package/dist/evm/floor/abi.gen.js +195 -0
- package/dist/evm/floor/calls.js +230 -0
- package/dist/evm/floor/create.js +49 -0
- package/dist/evm/floor/events.js +41 -0
- package/dist/evm/floor/iface.js +44 -0
- package/dist/evm/items.js +209 -0
- package/dist/evm/keccak.js +118 -0
- package/dist/evm/multicall.js +30 -0
- package/dist/evm/router.js +184 -0
- package/dist/evm/zap.js +128 -0
- package/dist/fixtures.js +53 -0
- package/dist/generated/index.js +28 -0
- package/dist/generated/interface.gen.js +146 -0
- package/dist/handle.js +22 -0
- package/dist/index.js +91 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +104 -0
- package/dist/indexer/contract.js +349 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +100 -0
- package/dist/indexer/paths.js +127 -0
- package/dist/indexer/read.js +109 -0
- package/dist/indexer/stream.js +71 -0
- package/dist/lock.js +16 -0
- package/dist/math/fixed.js +154 -0
- package/dist/math/genesis.js +39 -0
- package/dist/math/index.js +20 -0
- package/dist/math/u256.js +49 -0
- package/dist/math/v2/ask.js +162 -0
- package/dist/math/v2/book.js +607 -0
- package/dist/math/v2/circulating.js +62 -0
- package/dist/math/v2/create.js +122 -0
- package/dist/math/v2/display.js +208 -0
- package/dist/math/v2/error.js +17 -0
- package/dist/math/v2/feasibility.js +174 -0
- package/dist/math/v2/fees.js +121 -0
- package/dist/math/v2/holders.js +105 -0
- package/dist/math/v2/milestones.js +40 -0
- package/dist/math/v2/pow.js +69 -0
- package/dist/math/v2/preset.js +151 -0
- package/dist/math/v2/receipt.js +108 -0
- package/dist/math/v2/relay.js +217 -0
- package/dist/math/v2/rows.js +365 -0
- package/dist/math/v2/split.js +111 -0
- package/dist/math/v2/sqrt.js +84 -0
- package/dist/math/v2/supply.js +21 -0
- package/dist/math/v2/team.js +75 -0
- package/dist/math/v2/trade.js +126 -0
- package/dist/math/v2/wide.js +51 -0
- package/dist/quote.js +6 -0
- package/dist/registryPrice.js +23 -0
- package/dist/route/edge-jupiter.js +42 -0
- package/dist/route/edge.js +11 -0
- package/dist/route/graph.js +51 -0
- package/dist/route/path.js +75 -0
- package/dist/route/quote.js +15 -0
- package/dist/route-jupiter.js +35 -0
- package/dist/route.js +8 -0
- package/dist/sha256.js +61 -0
- package/dist/solana/alt.js +18 -0
- package/dist/solana/floor/accounts.js +390 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +140 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +435 -0
- package/dist/solana/floor/metadata.js +198 -0
- package/dist/solana/floor/mint.js +206 -0
- package/dist/solana/floor/program.js +64 -0
- package/dist/solana/floor/registry.js +83 -0
- package/dist/solana/instruction.js +49 -0
- package/dist/solana/pda.js +88 -0
- package/dist/solana/tx.js +138 -0
- package/dist/v2/burnPreview.js +35 -0
- package/dist/v2/circulating.js +11 -0
- package/dist/v2/claimAllEvm.js +70 -0
- package/dist/v2/claims-evm.js +120 -0
- package/dist/v2/claims.js +218 -0
- package/dist/v2/dead.js +21 -0
- package/dist/v2/devbuy.js +37 -0
- package/dist/v2/events.js +115 -0
- package/dist/v2/evm.js +299 -0
- package/dist/v2/evmReads.js +76 -0
- package/dist/v2/genesis.js +76 -0
- package/dist/v2/layouts.js +217 -0
- package/dist/v2/market-evm.js +74 -0
- package/dist/v2/presetRowEvm.js +45 -0
- package/dist/v2/press.js +106 -0
- package/dist/v2/quoteMint.js +52 -0
- package/dist/v2/receipt-tx.js +149 -0
- package/dist/v2/route-alt.js +114 -0
- package/dist/v2/route.js +389 -0
- package/dist/v2/solana.js +391 -0
- package/dist/v2/solanaSettle.js +97 -0
- package/dist/v2/tx/evm.js +126 -0
- package/dist/v2/tx/genesis.js +47 -0
- package/dist/v2/tx/index.js +5 -0
- package/dist/v2/tx/solana.js +118 -0
- package/dist/v2/types.js +13 -0
- package/docs/aggregator.md +61 -0
- package/docs/bot.md +50 -0
- package/docs/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/package.json +428 -32
- package/src/abi/evm-event-names.ts +12 -0
- package/src/abi/evm.gen.ts +139 -0
- package/src/abi/functions.gen.ts +154 -0
- package/src/abi/index.ts +30 -0
- package/src/abi/solana.gen.ts +138 -0
- package/src/burn.ts +37 -0
- package/src/client/evm/index.ts +199 -0
- package/src/client/index.ts +23 -0
- package/src/client/solana/index.ts +260 -0
- package/src/client/types.ts +162 -0
- package/src/codec.ts +77 -0
- package/src/config/codeHash.ts +9 -0
- package/src/config/generated.ts +746 -0
- package/src/config/index.ts +91 -0
- package/src/config/registry.gen.ts +118 -0
- package/src/config/solana-genesis.ts +7 -0
- package/src/ed25519.ts +31 -0
- package/src/errors.ts +270 -0
- package/src/events/index.ts +44 -0
- package/src/events/types.gen.ts +831 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +167 -0
- package/src/evm/floor/abi.gen.ts +195 -0
- package/src/evm/floor/calls.ts +247 -0
- package/src/evm/floor/create.ts +68 -0
- package/src/evm/floor/events.ts +51 -0
- package/src/evm/floor/iface.ts +45 -0
- package/src/evm/items.ts +252 -0
- package/src/evm/keccak.ts +118 -0
- package/src/evm/multicall.ts +43 -0
- package/src/evm/router.ts +209 -0
- package/src/evm/zap.ts +152 -0
- package/src/fixtures.ts +53 -0
- package/src/generated/index.ts +29 -0
- package/src/generated/interface.gen.ts +153 -0
- package/src/handle.ts +22 -0
- package/src/index.ts +91 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +178 -0
- package/src/indexer/contract.ts +410 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +109 -0
- package/src/indexer/paths.ts +190 -0
- package/src/indexer/read.ts +119 -0
- package/src/indexer/stream.ts +83 -0
- package/src/lock.ts +16 -0
- package/src/math/fixed.ts +154 -0
- package/src/math/genesis.ts +39 -0
- package/src/math/index.ts +24 -0
- package/src/math/u256.ts +49 -0
- package/src/math/v2/ask.ts +218 -0
- package/src/math/v2/book.ts +660 -0
- package/src/math/v2/circulating.ts +69 -0
- package/src/math/v2/create.ts +139 -0
- package/src/math/v2/display.ts +250 -0
- package/src/math/v2/error.ts +19 -0
- package/src/math/v2/feasibility.ts +200 -0
- package/src/math/v2/fees.ts +121 -0
- package/src/math/v2/holders.ts +124 -0
- package/src/math/v2/milestones.ts +51 -0
- package/src/math/v2/pow.ts +71 -0
- package/src/math/v2/preset.ts +189 -0
- package/src/math/v2/receipt.ts +162 -0
- package/src/math/v2/relay.ts +235 -0
- package/src/math/v2/rows.ts +412 -0
- package/src/math/v2/split.ts +160 -0
- package/src/math/v2/sqrt.ts +86 -0
- package/src/math/v2/supply.ts +27 -0
- package/src/math/v2/team.ts +75 -0
- package/src/math/v2/trade.ts +145 -0
- package/src/math/v2/wide.ts +52 -0
- package/src/quote.ts +6 -0
- package/src/registryPrice.ts +28 -0
- package/src/route/edge-jupiter.ts +71 -0
- package/src/route/edge.ts +22 -0
- package/src/route/graph.ts +77 -0
- package/src/route/path.ts +84 -0
- package/src/route/quote.ts +46 -0
- package/src/route-jupiter.ts +36 -0
- package/src/route.ts +8 -0
- package/src/sha256.ts +61 -0
- package/src/solana/alt.ts +25 -0
- package/src/solana/floor/accounts.ts +393 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +147 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +491 -0
- package/src/solana/floor/metadata.ts +246 -0
- package/src/solana/floor/mint.ts +242 -0
- package/src/solana/floor/program.ts +64 -0
- package/src/solana/floor/registry.ts +96 -0
- package/src/solana/instruction.ts +61 -0
- package/src/solana/pda.ts +91 -0
- package/src/solana/tx.ts +143 -0
- package/src/v2/burnPreview.ts +52 -0
- package/src/v2/circulating.ts +22 -0
- package/src/v2/claimAllEvm.ts +97 -0
- package/src/v2/claims-evm.ts +179 -0
- package/src/v2/claims.ts +288 -0
- package/src/v2/dead.ts +21 -0
- package/src/v2/devbuy.ts +55 -0
- package/src/v2/events.ts +131 -0
- package/src/v2/evm.ts +349 -0
- package/src/v2/evmReads.ts +121 -0
- package/src/v2/genesis.ts +80 -0
- package/src/v2/layouts.ts +219 -0
- package/src/v2/market-evm.ts +95 -0
- package/src/v2/presetRowEvm.ts +54 -0
- package/src/v2/press.ts +124 -0
- package/src/v2/quoteMint.ts +63 -0
- package/src/v2/receipt-tx.ts +251 -0
- package/src/v2/route-alt.ts +114 -0
- package/src/v2/route.ts +494 -0
- package/src/v2/solana.ts +439 -0
- package/src/v2/solanaSettle.ts +117 -0
- package/src/v2/tx/evm.ts +152 -0
- package/src/v2/tx/genesis.ts +66 -0
- package/src/v2/tx/index.ts +5 -0
- package/src/v2/tx/solana.ts +140 -0
- package/src/v2/types.ts +284 -0
- package/dist/adapter.d.ts +0 -28
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -2
- package/dist/adapter.js.map +0 -1
- package/dist/chain.d.ts +0 -23
- package/dist/chain.d.ts.map +0 -1
- package/dist/chain.js +0 -25
- package/dist/chain.js.map +0 -1
- package/dist/client.d.ts +0 -26
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -43
- package/dist/client.js.map +0 -1
- package/dist/dex-adapter.d.ts +0 -228
- package/dist/dex-adapter.d.ts.map +0 -1
- package/dist/dex-adapter.js +0 -407
- package/dist/dex-adapter.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/quotes.d.ts +0 -12
- package/dist/quotes.d.ts.map +0 -1
- package/dist/quotes.gen.d.ts +0 -8
- package/dist/quotes.gen.d.ts.map +0 -1
- package/dist/quotes.gen.js +0 -2170
- package/dist/quotes.gen.js.map +0 -1
- package/dist/quotes.js +0 -24
- package/dist/quotes.js.map +0 -1
- package/dist/types.d.ts +0 -111
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/adapter.ts +0 -20
- package/src/chain.ts +0 -39
- package/src/client.ts +0 -41
- package/src/dex-adapter.ts +0 -477
- package/src/quotes.gen.ts +0 -2170
- package/src/quotes.ts +0 -29
- package/src/types.ts +0 -115
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { v2Fail } from "./error.js";
|
|
4
|
+
import { pow } from "./pow.js";
|
|
5
|
+
import { build } from "./ask.js";
|
|
6
|
+
import { DEFAULT_FEE_PPM } from "./fees.js";
|
|
7
|
+
import { BPS } from "../index.js";
|
|
8
|
+
|
|
9
|
+
export const MAX_STACKS = 9;
|
|
10
|
+
export const MAX_BANDS = 4;
|
|
11
|
+
|
|
12
|
+
export { BPS } from "../index.js";
|
|
13
|
+
|
|
14
|
+
export const CLASS_TEAM = 0;
|
|
15
|
+
export const CLASS_HOLDER = 1;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export const FEE_FROM_GRAD = 0n;
|
|
22
|
+
|
|
23
|
+
export const FEE_TO_TAIL = 0n;
|
|
24
|
+
|
|
25
|
+
export const FEE_REL_ONE = 1n << 32n;
|
|
26
|
+
|
|
27
|
+
export function feeCurve(startPpm , endPpm ) {
|
|
28
|
+
return { startPpm: [...startPpm], endPpm: [...endPpm], fromUsd: FEE_FROM_GRAD, toUsd: FEE_TO_TAIL };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const WAGMI_FEES = [[10_000, 0, 2_000, 500, 1_000], [2_000, 0, 500, 100, 1_000]] ;
|
|
32
|
+
const HODL_FEES = [[2_000, 0, 2_000, 500, 9_000], [1_000, 0, 500, 100, 2_000]] ;
|
|
33
|
+
const WAGMI_GENESIS_FEES = [[6_000, 0, 2_000, 500, 0], [6_000, 0, 500, 100, 0]] ;
|
|
34
|
+
const MOONSHOT_FEES = [[2_000, 9_000, 2_000, 500, 0], [1_000, 2_000, 500, 100, 0]] ;
|
|
35
|
+
|
|
36
|
+
const FLOOR_GENESIS_FEES = [[3_000, 0, 2_000, 0, 0], [2_000, 0, 500, 0, 0]] ;
|
|
37
|
+
|
|
38
|
+
export function feeKnotRel(usd , launchCap ) {
|
|
39
|
+
const x = Math.sqrt(Number(usd) / Number(launchCap)) * Number(FEE_REL_ONE);
|
|
40
|
+
if (!Number.isFinite(x) || x < 1 || x >= 2 ** 64) v2Fail("RowInvalid");
|
|
41
|
+
return f64ToU128(x);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function rowFeeFields(r ) {
|
|
45
|
+
if (!r.feeCurve) return { feePpm: [...DEFAULT_FEE_PPM], feeStartPpm: [0, 0, 0, 0, 0], feeARel: 0n, feeBRel: 0n };
|
|
46
|
+
const c = r.feeCurve;
|
|
47
|
+
const from = c.fromUsd === FEE_FROM_GRAD ? r.launchCap : c.fromUsd;
|
|
48
|
+
const to = c.toUsd === FEE_TO_TAIL ? BigInt(Math.round(build(r).tailStart)) : c.toUsd;
|
|
49
|
+
return { feePpm: [...c.endPpm], feeStartPpm: [...c.startPpm], feeARel: feeKnotRel(from, r.launchCap), feeBRel: feeKnotRel(to, r.launchCap) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function cloneRow(r ) {
|
|
53
|
+
return {
|
|
54
|
+
...r,
|
|
55
|
+
bands: [...r.bands],
|
|
56
|
+
ckBps: r.ckBps,
|
|
57
|
+
feeCurve: r.feeCurve ? { ...r.feeCurve, startPpm: [...r.feeCurve.startPpm], endPpm: [...r.feeCurve.endPpm] } : null,
|
|
58
|
+
stacks: r.stacks.map((s) => ({ ...s })),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const rowWcBps = (r ) => r.bands.reduce((a, b) => a + b, 0);
|
|
63
|
+
|
|
64
|
+
export const rowDepth = (r ) => r.depthX100 / 100.0;
|
|
65
|
+
|
|
66
|
+
export const rowTeamBuyBounds = (r ) => [0n, (r.bondingRaise * BigInt(r.teamBuyBps)) / BPS];
|
|
67
|
+
|
|
68
|
+
export function rowValidate(r ) {
|
|
69
|
+
const bad = r.id === 0
|
|
70
|
+
|| r.id === 2
|
|
71
|
+
|| r.phiBps === 0
|
|
72
|
+
|| r.phiBps >= 10_000
|
|
73
|
+
|| r.wBps >= 10_000
|
|
74
|
+
|| r.thetaBps > 10_000
|
|
75
|
+
|| r.tailBps >= 10_000
|
|
76
|
+
|| r.psiTBps === 0
|
|
77
|
+
|| r.psiTBps > 10_000
|
|
78
|
+
|| r.depthX100 < 100
|
|
79
|
+
|| r.climbStepX100 <= 100
|
|
80
|
+
|| r.spreadBps > 10_000
|
|
81
|
+
|| r.bands.length === 0
|
|
82
|
+
|| r.bands.length > MAX_BANDS
|
|
83
|
+
|| rowWcBps(r) >= 10_000
|
|
84
|
+
|| r.stacks.length === 0
|
|
85
|
+
|| r.stacks.length > MAX_STACKS
|
|
86
|
+
|| r.bondingRaise === 0n
|
|
87
|
+
|| r.launchCap <= r.bondingRaise
|
|
88
|
+
|| r.platformMsBps + r.floorMsBps > 10_000
|
|
89
|
+
|| r.teamBuyBps > 10_000
|
|
90
|
+
|| r.teamSlotMaxBps > 9_500
|
|
91
|
+
|| r.stacks.some((s) => s.level === 0n || (s.spreadBps !== null && s.spreadBps > 10_000))
|
|
92
|
+
|| r.stacks.some((s, i) => i > 0 && s.level <= r.stacks[i - 1] .level);
|
|
93
|
+
if (bad) v2Fail("RowInvalid");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const DEPTH_X100 = 101;
|
|
97
|
+
export const STEP_PHI10_X100 = 150;
|
|
98
|
+
export const STEP_PHI50_X100 = 120;
|
|
99
|
+
|
|
100
|
+
export function r1DepthX100(phiBps , stepX100 ) {
|
|
101
|
+
const phi = phiBps / 1e4;
|
|
102
|
+
const r = stepX100 / 100.0;
|
|
103
|
+
const u = Math.sqrt(r);
|
|
104
|
+
if (phi * u >= 1.0) return null;
|
|
105
|
+
|
|
106
|
+
const need = (phi * (r - 1.0)) / (u * (1.0 - phi * u));
|
|
107
|
+
for (let d = 100; d <= 400; d++) {
|
|
108
|
+
if (pow(r, d / 100.0 / (1.0 / phi - 1.0)) - 1.0 >= need) return d;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const st = (level , milestone ) => ({ level, milestone, spreadBps: null });
|
|
114
|
+
|
|
115
|
+
function base(id , name ) {
|
|
116
|
+
return {
|
|
117
|
+
id,
|
|
118
|
+
name,
|
|
119
|
+
phiBps: 1_000,
|
|
120
|
+
|
|
121
|
+
wBps: 2_500,
|
|
122
|
+
bands: [300],
|
|
123
|
+
thetaBps: 0,
|
|
124
|
+
depthX100: DEPTH_X100,
|
|
125
|
+
climbStepX100: STEP_PHI10_X100,
|
|
126
|
+
spreadBps: 0,
|
|
127
|
+
tailBps: 4_000,
|
|
128
|
+
psiTBps: 8_000,
|
|
129
|
+
bondingRaise: 0n,
|
|
130
|
+
launchCap: 0n,
|
|
131
|
+
stacks: [],
|
|
132
|
+
class: CLASS_TEAM,
|
|
133
|
+
platformMsBps: 0,
|
|
134
|
+
floorMsBps: 0,
|
|
135
|
+
teamBuyBps: 10_000,
|
|
136
|
+
teamSlotMaxBps: 0,
|
|
137
|
+
ckBps: 0,
|
|
138
|
+
feeCurve: null,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const CK_TARGET_CIRC_BPS = 500;
|
|
143
|
+
|
|
144
|
+
export const CK_TARGET_DEFAULT = CK_TARGET_CIRC_BPS;
|
|
145
|
+
|
|
146
|
+
export const MOONSHOT_CK_TARGET = 700;
|
|
147
|
+
|
|
148
|
+
export function withCkTarget(row , ckBps ) {
|
|
149
|
+
return { ...cloneRow(row), ckBps };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function moonshot() {
|
|
153
|
+
return {
|
|
154
|
+
...base(3, "moonshot-10"),
|
|
155
|
+
thetaBps: 1_000,
|
|
156
|
+
spreadBps: 10_000,
|
|
157
|
+
bondingRaise: 2_000n,
|
|
158
|
+
launchCap: 100_000n,
|
|
159
|
+
|
|
160
|
+
tailBps: 200,
|
|
161
|
+
stacks: [
|
|
162
|
+
st(250_000n, 12_000n),
|
|
163
|
+
st(450_000n, 20_000n),
|
|
164
|
+
st(500_000n, 60_000n),
|
|
165
|
+
st(1_000_000n, 150_000n),
|
|
166
|
+
st(2_500_000n, 250_000n),
|
|
167
|
+
|
|
168
|
+
st(5_000_000n, 700_000n),
|
|
169
|
+
st(9_000_000n, 1_500_000n),
|
|
170
|
+
|
|
171
|
+
{ level: 75_000_000n, milestone: 1_280_000n, spreadBps: 144 },
|
|
172
|
+
],
|
|
173
|
+
platformMsBps: 1_000,
|
|
174
|
+
floorMsBps: 1_000,
|
|
175
|
+
teamSlotMaxBps: 6_000,
|
|
176
|
+
ckBps: MOONSHOT_CK_TARGET,
|
|
177
|
+
feeCurve: feeCurve(...MOONSHOT_FEES),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const WAGMI_SPEC_MILESTONES = [11_550_000n];
|
|
182
|
+
|
|
183
|
+
export const WAGMI_END_USD = 177_730_000n;
|
|
184
|
+
|
|
185
|
+
export const WAGMI_THETA_OPTIONS = [
|
|
186
|
+
[250, 1_000_000n],
|
|
187
|
+
[100, 1_000_000n],
|
|
188
|
+
[50, 1_000_000n],
|
|
189
|
+
[0, 1_000_000n],
|
|
190
|
+
];
|
|
191
|
+
|
|
192
|
+
export const WAGMI_THETA_BPS = 250;
|
|
193
|
+
|
|
194
|
+
export function wagmiMsScalePpm(thetaBps ) {
|
|
195
|
+
const o = WAGMI_THETA_OPTIONS.find(([t]) => t === thetaBps);
|
|
196
|
+
return o ? o[1] : null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export const WAGMI_MS_SCALE_PPM = wagmiMsScalePpm(WAGMI_THETA_BPS) ;
|
|
200
|
+
|
|
201
|
+
export const STEP_WAGMI_X100 = 109;
|
|
202
|
+
|
|
203
|
+
function wagmiBase() {
|
|
204
|
+
return {
|
|
205
|
+
...base(1, "wagmi-75"),
|
|
206
|
+
phiBps: 7_500,
|
|
207
|
+
|
|
208
|
+
wBps: 2_000,
|
|
209
|
+
climbStepX100: STEP_WAGMI_X100,
|
|
210
|
+
|
|
211
|
+
tailBps: 1_000,
|
|
212
|
+
bondingRaise: 1_000n,
|
|
213
|
+
launchCap: 10_000_000n,
|
|
214
|
+
stacks: [st(WAGMI_END_USD, WAGMI_SPEC_MILESTONES[0])],
|
|
215
|
+
|
|
216
|
+
spreadBps: 144,
|
|
217
|
+
class: CLASS_HOLDER,
|
|
218
|
+
|
|
219
|
+
platformMsBps: 5_000,
|
|
220
|
+
floorMsBps: 5_000,
|
|
221
|
+
ckBps: CK_TARGET_DEFAULT,
|
|
222
|
+
feeCurve: feeCurve(...WAGMI_FEES),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function wagmiAt(thetaBps ) {
|
|
227
|
+
const k = wagmiMsScalePpm(thetaBps);
|
|
228
|
+
if (k === null) return null;
|
|
229
|
+
const r = wagmiBase();
|
|
230
|
+
r.thetaBps = thetaBps;
|
|
231
|
+
r.stacks = r.stacks.map((s, i) => ({ ...s, milestone: (WAGMI_SPEC_MILESTONES[i] * k) / 1_000_000n }));
|
|
232
|
+
return r;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function wagmi() {
|
|
236
|
+
return wagmiAt(WAGMI_THETA_BPS) ;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const FLOOR_GENESIS_PHI_BPS = 5_000;
|
|
240
|
+
|
|
241
|
+
export function floorGenesis() {
|
|
242
|
+
const phiBps = FLOOR_GENESIS_PHI_BPS;
|
|
243
|
+
return {
|
|
244
|
+
...moonshot(),
|
|
245
|
+
id: 4,
|
|
246
|
+
name: "floor-genesis",
|
|
247
|
+
|
|
248
|
+
ckBps: CK_TARGET_DEFAULT,
|
|
249
|
+
phiBps,
|
|
250
|
+
climbStepX100: STEP_PHI50_X100,
|
|
251
|
+
depthX100: Math.max(r1DepthX100(phiBps, STEP_PHI50_X100) ?? 400, DEPTH_X100),
|
|
252
|
+
bondingRaise: 2_000n,
|
|
253
|
+
launchCap: 5_000_000n,
|
|
254
|
+
teamBuyBps: 0,
|
|
255
|
+
teamSlotMaxBps: 0,
|
|
256
|
+
feeCurve: feeCurve(...FLOOR_GENESIS_FEES),
|
|
257
|
+
|
|
258
|
+
stacks: [
|
|
259
|
+
{ level: 20_000_000n, milestone: 125_000n, spreadBps: 1_000 },
|
|
260
|
+
{ level: 90_000_000n, milestone: 1_125_000n, spreadBps: 1_000 },
|
|
261
|
+
{ level: 500_000_000n, milestone: 102_400_000n, spreadBps: 1_000 },
|
|
262
|
+
],
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function hodl() {
|
|
267
|
+
return {
|
|
268
|
+
...moonshot(),
|
|
269
|
+
id: 6,
|
|
270
|
+
name: "hodl",
|
|
271
|
+
|
|
272
|
+
ckBps: CK_TARGET_DEFAULT,
|
|
273
|
+
phiBps: 3_000,
|
|
274
|
+
climbStepX100: STEP_PHI50_X100,
|
|
275
|
+
depthX100: 125,
|
|
276
|
+
launchCap: 2_000_000n,
|
|
277
|
+
bondingRaise: 12_600n,
|
|
278
|
+
class: CLASS_HOLDER,
|
|
279
|
+
teamSlotMaxBps: 0,
|
|
280
|
+
feeCurve: feeCurve(...HODL_FEES),
|
|
281
|
+
|
|
282
|
+
stacks: [
|
|
283
|
+
{ level: 50_000_000n, milestone: 1_000_000n, spreadBps: 144 },
|
|
284
|
+
{ level: 100_000_000n, milestone: 2_000_000n, spreadBps: 144 },
|
|
285
|
+
{ level: 250_000_000n, milestone: 5_000_000n, spreadBps: 144 },
|
|
286
|
+
{ level: 500_000_000n, milestone: 198_961_000n, spreadBps: 144 },
|
|
287
|
+
],
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function floorGenesisPhiStudy(phiBps ) {
|
|
292
|
+
return {
|
|
293
|
+
...base(4, "floor-genesis"),
|
|
294
|
+
phiBps,
|
|
295
|
+
climbStepX100: phiBps <= 1_000 ? STEP_PHI10_X100 : STEP_PHI50_X100,
|
|
296
|
+
depthX100: Math.max(r1DepthX100(phiBps, phiBps <= 1_000 ? STEP_PHI10_X100 : STEP_PHI50_X100) ?? 400, DEPTH_X100),
|
|
297
|
+
bondingRaise: 20_000n,
|
|
298
|
+
launchCap: 800_000n,
|
|
299
|
+
stacks: [
|
|
300
|
+
st(1_000_000n, 10_000n),
|
|
301
|
+
st(5_000_000n, 50_000n),
|
|
302
|
+
st(10_000_000n, 100_000n),
|
|
303
|
+
st(50_000_000n, 500_000n),
|
|
304
|
+
st(100_000_000n, 1_000_000n),
|
|
305
|
+
st(1_000_000_000n, 10_000_000n),
|
|
306
|
+
],
|
|
307
|
+
teamBuyBps: 0,
|
|
308
|
+
teamSlotMaxBps: 0,
|
|
309
|
+
ckBps: CK_TARGET_DEFAULT,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function f64ToU128(x ) {
|
|
314
|
+
if (!(x > 0)) return 0n;
|
|
315
|
+
if (x >= 2 ** 128) return (1n << 128n) - 1n;
|
|
316
|
+
return BigInt(Math.trunc(x));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export const WAGMI_GENESIS_CAP_USD = 75_530_000n;
|
|
320
|
+
|
|
321
|
+
export const WAGMI_GENESIS_KEEP_USD = 1_711_410n;
|
|
322
|
+
|
|
323
|
+
export const WAGMI_GENESIS_UNUSED_MAX = 1e-4;
|
|
324
|
+
|
|
325
|
+
export function wagmiGenesisAt(raise , target ) {
|
|
326
|
+
const w = wagmi();
|
|
327
|
+
return {
|
|
328
|
+
...w,
|
|
329
|
+
id: 5,
|
|
330
|
+
name: "wagmi-genesis",
|
|
331
|
+
launchCap: WAGMI_GENESIS_CAP_USD,
|
|
332
|
+
bondingRaise: raise,
|
|
333
|
+
teamBuyBps: 0,
|
|
334
|
+
teamSlotMaxBps: 0,
|
|
335
|
+
feeCurve: feeCurve(...WAGMI_GENESIS_FEES),
|
|
336
|
+
stacks: w.stacks.map((s, i) => (i === 0 ? { ...s, milestone: target } : s)),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function wagmiGenesisTarget(raise ) {
|
|
341
|
+
const unused = (t ) => {
|
|
342
|
+
try {
|
|
343
|
+
const a = build(wagmiGenesisAt(raise, t));
|
|
344
|
+
return a;
|
|
345
|
+
} catch {
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
const a0 = unused(0n);
|
|
350
|
+
if (!a0 || !(a0.supplyExcess <= 0) || a0.stacks[0].skipped) return 0n;
|
|
351
|
+
let lo = 0n;
|
|
352
|
+
let hi = 1_000_000_000n;
|
|
353
|
+
while (hi - lo > 1n) {
|
|
354
|
+
const m = (lo + hi) / 2n;
|
|
355
|
+
const a = unused(m);
|
|
356
|
+
if (a && a.unusedShare > WAGMI_GENESIS_UNUSED_MAX) lo = m;
|
|
357
|
+
else hi = m;
|
|
358
|
+
}
|
|
359
|
+
return (lo / 1_000n) * 1_000n;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export function wagmiGenesis(overflow ) {
|
|
363
|
+
const raise = overflow < WAGMI_GENESIS_KEEP_USD ? overflow : WAGMI_GENESIS_KEEP_USD;
|
|
364
|
+
return wagmiGenesisAt(raise, wagmiGenesisTarget(raise));
|
|
365
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { fail } from "../index.js";
|
|
4
|
+
import { KIND_BONDING, KIND_TAIL, PIECES_MAX } from "./book.js";
|
|
5
|
+
|
|
6
|
+
import { flatMoneyForTokens, sqrtOfRatio, sqrtScaleDownBps } from "./sqrt.js";
|
|
7
|
+
|
|
8
|
+
import { U128_MAX, UP } from "./wide.js";
|
|
9
|
+
|
|
10
|
+
export const MS_TEAM = 1;
|
|
11
|
+
export const MS_HOLDER = 2;
|
|
12
|
+
|
|
13
|
+
export { PIECES_MAX };
|
|
14
|
+
|
|
15
|
+
const ov = (x ) => (x === null ? fail("Overflow") : x);
|
|
16
|
+
const u128 = (x ) => (x > U128_MAX ? fail("Overflow") : x);
|
|
17
|
+
const min = (a , b ) => (a < b ? a : b);
|
|
18
|
+
const max = (a , b ) => (a > b ? a : b);
|
|
19
|
+
const sat = (a , b ) => (a > b ? a - b : 0n);
|
|
20
|
+
const cdiv = (a , d ) => (a + d - 1n) / d;
|
|
21
|
+
|
|
22
|
+
const flatUp = (s , n ) => ov(flatMoneyForTokens(s, n, UP));
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export function splitRowOfRowV2(r ) {
|
|
27
|
+
const ck = r.ckTargetBps ?? r.ckBps;
|
|
28
|
+
if (!Number.isInteger(ck)) throw new RangeError("splitRowOfRowV2: the row has no C + K share (`ckTargetBps`)");
|
|
29
|
+
if (r.ckTargetBps !== undefined && r.ckBps !== undefined && r.ckTargetBps !== r.ckBps) {
|
|
30
|
+
throw new RangeError(`splitRowOfRowV2: ckTargetBps ${r.ckTargetBps} and ckBps ${r.ckBps} disagree`);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
phiBps: r.phiBps,
|
|
34
|
+
ckBps: ck ,
|
|
35
|
+
wcBps: 300,
|
|
36
|
+
cShareBps: 5_000,
|
|
37
|
+
msClass: r.msClass,
|
|
38
|
+
platformMsBps: (r.flags & 1) !== 0 ? r.platformMsBps : 0,
|
|
39
|
+
floorMsBps: (r.flags & 2) !== 0 ? r.floorMsBps : 0,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function split(row , ranges , inp , pieces ) {
|
|
44
|
+
let tokensSum = 0n;
|
|
45
|
+
for (const p of pieces) tokensSum += p.tokens;
|
|
46
|
+
let sr = inp.sNew - tokensSum;
|
|
47
|
+
if (sr < 0n) fail("Overflow");
|
|
48
|
+
let fr = inp.fTotal;
|
|
49
|
+
const phi = BigInt(row.phiBps);
|
|
50
|
+
let ckAdd = 0n;
|
|
51
|
+
let ms = 0n;
|
|
52
|
+
let topNeed = 0n;
|
|
53
|
+
const booked = [0n, 0n, 0n, 0n];
|
|
54
|
+
|
|
55
|
+
for (const pc of pieces) {
|
|
56
|
+
const r = ranges[pc.range];
|
|
57
|
+
sr += pc.tokens;
|
|
58
|
+
|
|
59
|
+
const lo = pc.sqrtLo;
|
|
60
|
+
const capA = cdiv(pc.money * BigInt(r.psiBps), 10_000n);
|
|
61
|
+
const capB = cdiv(cdiv(pc.money * inp.sqrtF, lo) * inp.sqrtF, lo);
|
|
62
|
+
const cap = min(max(capA, capB), pc.money);
|
|
63
|
+
const n = sr + inp.held;
|
|
64
|
+
const needAll = max(flatUp(inp.sqrtF, n), cdiv(flatUp(pc.sqrtHi, n) * phi, 10_000n));
|
|
65
|
+
if (r.kind !== KIND_TAIL) topNeed = needAll;
|
|
66
|
+
const need = sat(needAll, fr + inp.fClaims);
|
|
67
|
+
const dF = min(cap, need);
|
|
68
|
+
fr += dF;
|
|
69
|
+
const rem = pc.money - dF;
|
|
70
|
+
if (r.thetaBps >= 10_000) {
|
|
71
|
+
|
|
72
|
+
ckAdd += rem;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const gap = sat(cdiv(flatUp(pc.sqrtHi, sr) * BigInt(row.ckBps), 10_000n), inp.ck0 + ckAdd);
|
|
77
|
+
let ck = min(rem, gap);
|
|
78
|
+
let mm = rem - ck;
|
|
79
|
+
if (r.msCapPpm > 0) {
|
|
80
|
+
const capm = (pc.money * BigInt(r.msCapPpm)) / 1_000_000n;
|
|
81
|
+
if (mm > capm) {
|
|
82
|
+
ck += mm - capm;
|
|
83
|
+
mm = capm;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
ckAdd += ck;
|
|
87
|
+
ms += mm;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let ckTake = 0n;
|
|
91
|
+
const short = sat(topNeed, fr + inp.fClaims);
|
|
92
|
+
if (short > 0n && inp.ck0 + ckAdd > 0n) {
|
|
93
|
+
const a = min(short, ckAdd);
|
|
94
|
+
const m2 = min(short - a, ms);
|
|
95
|
+
ckTake = min(short - a - m2, inp.ck0);
|
|
96
|
+
ckAdd -= a;
|
|
97
|
+
ms -= m2;
|
|
98
|
+
fr += a + m2 + ckTake;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
booked[2] = (ms * BigInt(row.platformMsBps)) / 10_000n;
|
|
102
|
+
booked[3] = (ms * BigInt(row.floorMsBps)) / 10_000n;
|
|
103
|
+
booked[row.msClass === MS_HOLDER ? 1 : 0] += ms - booked[2] - booked[3];
|
|
104
|
+
|
|
105
|
+
const ratio = sqrtOfRatio(fr + inp.fClaims, inp.sNew + inp.held);
|
|
106
|
+
const capSqrt = ov(sqrtScaleDownBps(inp.sqrtP1, row.wcBps));
|
|
107
|
+
const sqrtFNew = max(inp.sqrtF, ratio === null ? inp.sqrtF : min(ratio, capSqrt));
|
|
108
|
+
return { dF: fr - inp.fTotal, ckAdd: u128(ckAdd), ckTake, ms: u128(ms), booked, sqrtFNew };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const pieceEntersSplit = (r ) => r.kind !== KIND_BONDING;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { DOWN, UP, U256_LIMIT, divW, isqrt, mulShr, shlDiv, shlW, shrW, toU128 } from "./wide.js";
|
|
4
|
+
|
|
5
|
+
export const FRAC = 72;
|
|
6
|
+
export const ONE = 1n << 72n;
|
|
7
|
+
|
|
8
|
+
export const SQRT_TAIL_END = 1n << 127n;
|
|
9
|
+
|
|
10
|
+
const sub = (b , a ) => (b < a ? null : b - a);
|
|
11
|
+
|
|
12
|
+
export function moneyBetween(l , a , b , r ) {
|
|
13
|
+
const d = sub(b, a);
|
|
14
|
+
return d === null ? null : mulShr(l, d, FRAC, r);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function tokensBetween(l , a , b , r ) {
|
|
18
|
+
if (a === 0n) return null;
|
|
19
|
+
const d = sub(b, a);
|
|
20
|
+
if (d === null) return null;
|
|
21
|
+
const t = shlDiv(l * d, FRAC, b, r);
|
|
22
|
+
return t === null ? null : toU128(divW(t, a, r));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function sqrtAfterMoney(l , p , money ) {
|
|
26
|
+
const dp = toU128(shlDiv(money, FRAC, l, DOWN));
|
|
27
|
+
return dp === null ? null : toU128(p + dp);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function sqrtAfterTokens(l , p , tokens ) {
|
|
31
|
+
const num = shlW(l * p, FRAC);
|
|
32
|
+
const lw = shlW(l, FRAC);
|
|
33
|
+
if (num === null || lw === null || lw >= U256_LIMIT) return null;
|
|
34
|
+
const den = lw + tokens * p;
|
|
35
|
+
if (den >= U256_LIMIT) return null;
|
|
36
|
+
return toU128(divW(num, den, UP));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function sqrtAfterBuyingTokens(l , p , tokens ) {
|
|
40
|
+
const num = shlW(l * p, FRAC);
|
|
41
|
+
const lw = shlW(l, FRAC);
|
|
42
|
+
if (num === null || lw === null || lw >= U256_LIMIT) return null;
|
|
43
|
+
const den = lw - tokens * p;
|
|
44
|
+
if (den <= 0n) return null;
|
|
45
|
+
return toU128(divW(num, den, UP));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function liquidityForTokens(a , b , tokens ) {
|
|
49
|
+
const d = sub(b, a);
|
|
50
|
+
if (d === null || d === 0n) return null;
|
|
51
|
+
return toU128(divW(shrW(tokens * a * b, FRAC, DOWN), d, DOWN));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function liquidityForMoney(a , b , money ) {
|
|
55
|
+
const d = sub(b, a);
|
|
56
|
+
if (d === null || d === 0n) return null;
|
|
57
|
+
return toU128(shlDiv(money, FRAC, d, DOWN));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function flatTokensForMoney(s , money , r ) {
|
|
61
|
+
if (s === 0n) return null;
|
|
62
|
+
const w = shlW(money, 2 * FRAC);
|
|
63
|
+
if (w === null) return null;
|
|
64
|
+
const t = divW(w, s, r);
|
|
65
|
+
return t === null ? null : toU128(divW(t, s, r));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const flatMoneyForTokens = (s , tokens , r ) => toU128(shrW(tokens * s * s, 2 * FRAC, r));
|
|
69
|
+
|
|
70
|
+
export function sqrtOfRatio(money , tokens ) {
|
|
71
|
+
if (tokens === 0n) return null;
|
|
72
|
+
const w = shlW(money, 2 * FRAC);
|
|
73
|
+
if (w === null) return null;
|
|
74
|
+
const n = divW(w, tokens, DOWN);
|
|
75
|
+
return n === null ? null : isqrt(n);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function sqrtScaleDownBps(s , bps ) {
|
|
79
|
+
if (bps > 10_000) return null;
|
|
80
|
+
const n = divW(shlW(BigInt(10_000 - bps), 2 * FRAC) , 10_000n, DOWN) ;
|
|
81
|
+
return mulShr(s, isqrt(n), FRAC, DOWN);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const priceX64 = (s ) => toU128(shrW(s * s, 2 * FRAC - 64, DOWN)) ?? (1n << 128n) - 1n;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { fail } from "../index.js";
|
|
4
|
+
import { boughtBack, forSale } from "./book.js";
|
|
5
|
+
|
|
6
|
+
export const sCirc = (b , sup ) => circulatingV2(sup.live, 0n, forSale(b), boughtBack(b), sup.dead);
|
|
7
|
+
|
|
8
|
+
export function circulatingV2(minted , burned , forSale , boughtBack , dead ) {
|
|
9
|
+
const s = minted - burned - forSale - boughtBack - dead;
|
|
10
|
+
let x = minted;
|
|
11
|
+
for (const y of [burned, forSale, boughtBack, dead]) {
|
|
12
|
+
if (x < y) fail("Overflow");
|
|
13
|
+
x -= y;
|
|
14
|
+
}
|
|
15
|
+
return s;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function sBelow(s , xC , xK ) {
|
|
19
|
+
const v = s - xC - xK;
|
|
20
|
+
return v < 1n ? 1n : v;
|
|
21
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { fail } from "../index.js";
|
|
4
|
+
import { creatorLegs, platformLegs } from "./fees.js";
|
|
5
|
+
import { U64_MAX, U128_MAX } from "./wide.js";
|
|
6
|
+
|
|
7
|
+
export const MAX_MEMBERS = 10;
|
|
8
|
+
export const WEIGHT_ONE = 1_000_000_000n;
|
|
9
|
+
|
|
10
|
+
export const CREATOR_BUY_LOCK_SECS = 86_400n;
|
|
11
|
+
|
|
12
|
+
export { CREATOR_REF_BPS, TRADER_REF_BPS } from "./fees.js";
|
|
13
|
+
|
|
14
|
+
export { platformLegs as platformLegsV2, creatorLegs as creatorLegsV2 } from "./fees.js";
|
|
15
|
+
|
|
16
|
+
const u128 = (x ) => (x < 0n || x > U128_MAX ? fail("Overflow") : x);
|
|
17
|
+
const members = (n , what ) => {
|
|
18
|
+
if (n !== MAX_MEMBERS) throw new RangeError(`${what}: ${n} entries, want ${MAX_MEMBERS}`);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function weightsV2(paid , bought ) {
|
|
22
|
+
members(paid.length, "paid");
|
|
23
|
+
const w = Array(MAX_MEMBERS).fill(0);
|
|
24
|
+
if (bought === 0n) return w;
|
|
25
|
+
|
|
26
|
+
const t = paid.reduce((a, p) => a + p, 0n);
|
|
27
|
+
if (t > U128_MAX || t > bought) fail("Overflow");
|
|
28
|
+
for (let i = 0; i < MAX_MEMBERS; i++) w[i] = Number(((paid[i] < bought ? paid[i] : bought) * WEIGHT_ONE) / bought);
|
|
29
|
+
return w;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function slotWeightsV2(shares ) {
|
|
33
|
+
members(shares.length, "shares");
|
|
34
|
+
const total = u128(shares.reduce((a, x) => a + x, 0n));
|
|
35
|
+
if (total === 0n) {
|
|
36
|
+
const w = Array(MAX_MEMBERS).fill(0);
|
|
37
|
+
w[0] = Number(WEIGHT_ONE);
|
|
38
|
+
return w;
|
|
39
|
+
}
|
|
40
|
+
return weightsV2(shares, total);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function splitMembersV2(amount , w ) {
|
|
44
|
+
members(w.length, "weights");
|
|
45
|
+
u128(amount);
|
|
46
|
+
const parts = Array(MAX_MEMBERS).fill(0n);
|
|
47
|
+
let given = 0n;
|
|
48
|
+
for (let i = 0; i < MAX_MEMBERS; i++) {
|
|
49
|
+
const wi = BigInt(w[i]) < WEIGHT_ONE ? BigInt(w[i]) : WEIGHT_ONE;
|
|
50
|
+
let p = (amount * wi) / WEIGHT_ONE;
|
|
51
|
+
|
|
52
|
+
if (p > amount - given) p = amount - given;
|
|
53
|
+
parts[i] = p;
|
|
54
|
+
given += p;
|
|
55
|
+
}
|
|
56
|
+
return [parts, amount > given ? amount - given : 0n];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function splitReleaseV2(tokens , w ) {
|
|
60
|
+
members(w.length, "weights");
|
|
61
|
+
if (w.every((x) => x === 0)) {
|
|
62
|
+
const parts = Array(MAX_MEMBERS).fill(0n);
|
|
63
|
+
parts[0] = u128(tokens);
|
|
64
|
+
return parts;
|
|
65
|
+
}
|
|
66
|
+
const [parts, dust] = splitMembersV2(tokens, w);
|
|
67
|
+
parts[0] = u128(parts[0] + dust);
|
|
68
|
+
return parts;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function splitTeamBuyV2(tokens , w , createdAt , now ) {
|
|
72
|
+
const due = createdAt + CREATOR_BUY_LOCK_SECS > U64_MAX ? U64_MAX : createdAt + CREATOR_BUY_LOCK_SECS;
|
|
73
|
+
if (now < due) fail("NotDue");
|
|
74
|
+
return splitReleaseV2(tokens, w);
|
|
75
|
+
}
|