@kronsdk/kron-sdk 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shawn Pearce
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ NOTICE: The TypeScript transaction-builder code under src/native/*.ts and
26
+ src/curve/*.ts was originally developed as part of the KRON project
27
+ (https://kron.technology) and was relicensed under this MIT license for
28
+ publication in this SDK by its copyright holder, Shawn Pearce, on
29
+ 2026-06-30. It remains proprietary in KRON's private application repository;
30
+ this relicensing applies only to the copies published in this repository.
31
+ This package does not include KRON's covenant source (.sil) files or
32
+ compiler, which remain private.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # kron-sdk
2
+
3
+ **Build, sign, and submit transactions against [KRON](https://kron.technology)'s native-L1 Kaspa covenants
4
+ — a bonding-curve launchpad + AMM DEX — from any JS/TS environment.** Browser or Node. No custody, ever:
5
+ this package only *builds* transactions; a wallet (yours, or your user's) signs them.
6
+
7
+ > **Status: v0.1.0, testnet (TN10).** Read paths and the covenant builders are proven byte-identical to
8
+ > KRON's own production code (see "Verification" below). Wallet signing is a documented interface plus a
9
+ > generic reference implementation — see [`docs/WALLETS.md`](docs/WALLETS.md) for the contract and how to
10
+ > adapt it to a specific wallet's injected provider.
11
+
12
+ ## Why this exists
13
+
14
+ KRON is **covenant-native** — there's no rollup, no off-chain ledger of record, no custodial API. Every
15
+ balance is an on-chain UTXO whose script enforces its own rules; every state-changing action is a
16
+ transaction **the user's own wallet signs**. That's great for trust, but it means "integrate with KRON"
17
+ has historically meant embedding KRON's browser bundle. This package extracts the transaction builders for
18
+ **trading against already-deployed KRON tokens** into a standalone, dependency-light package, so a wallet,
19
+ a Telegram bot, or a backend can build those transactions directly — buy, sell, swap, transfer, add/remove
20
+ liquidity, claim vesting.
21
+
22
+ This package does **not** include a covenant compiler and doesn't build the deploy/genesis transactions
23
+ that launch a *new* curve, pool, or token — see "What's in the box" below.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ npm install @kronsdk/kron-sdk
29
+ ```
30
+
31
+ ESM only (`"type": "module"`) in v1 — see [Design notes](#design-notes) for why.
32
+
33
+ ## Quickstart — quote a curve buy (Node)
34
+
35
+ ```ts
36
+ import * as kron from '@kronsdk/kron-sdk';
37
+ import { loadKaspa } from '@kronsdk/kron-sdk/wasm';
38
+
39
+ const k = await loadKaspa();
40
+ const idx = new kron.client.IndexerClient('https://idx.kron.technology/v1/kcc20');
41
+
42
+ // 1. Read live curve state
43
+ const token = await idx.token('ghost');
44
+ const cpState = {
45
+ realKas: BigInt(token.cpState.realKas), tokenReserve: BigInt(token.cpState.tokenReserve),
46
+ vKas: BigInt(token.cp?.curveParams?.vKas ?? 0), graduationKas: BigInt(token.cp?.curveParams?.graduationKas ?? 0),
47
+ creatorFeeBps: 25n, platformFeeBps: 100n,
48
+ };
49
+
50
+ // 2. Quote a buy
51
+ const quote = kron.curve.quoteCpBuy(cpState, 10_000_000_000n); // 100 TKAS in
52
+ if (!quote) throw new Error('quote failed — bad amount or curve state');
53
+ console.log(`100 TKAS -> ${quote.tokenOut} tokens, fee ${quote.fee} sompi`);
54
+
55
+ // 3. Build the covenant spend against the LIVE curve. `cpTemplate`/`tokenTemplate` need the target's
56
+ // already-compiled script bytes + state offset — read them from your indexer's UTXO data
57
+ // (redeemScriptHex etc.), this package doesn't compile them. curveUtxo/inventoryUtxo also come from
58
+ // the indexer. See docs/INTEGRATION.md for the full flow.
59
+ // const spend = kron.curveCp.buildCpBuy(k, cpTemplate, tokenTemplate, curveUtxo, inventoryUtxo, ...);
60
+ // const asm = kron.spend.assembleNativeTx(k, { spend, fundingEntries, changeAddress, networkFee });
61
+ // const pskt = kron.spend.toPsktJson(asm);
62
+ // const signed = await wallet.signPskt(pskt.txJsonString, pskt.signInputs); // user's wallet signs
63
+ ```
64
+
65
+ See [`docs/INTEGRATION.md`](docs/INTEGRATION.md) for the full read/write API + worked recipes (wallet
66
+ portfolio render, "Send" button, TG bot price command, pool swap).
67
+
68
+ ## What's in the box
69
+
70
+ ```
71
+ kron-sdk
72
+ ├─ curve constant-product curve math (BigInt, mirrors curve_cp.sil exactly)
73
+ ├─ curveCp curve_cp builders against an EXISTING curve: buy / sell / graduate
74
+ ├─ poolCp / poolCpV3 amm_pool_cp_v3 builders: swap / addLiquidity / removeLiquidity / bindLp
75
+ ├─ kcc20 the KCC-20 token covenant: transfer / ownership modes / state encoding
76
+ ├─ vesting claim / claimFinal against an EXISTING vesting lock
77
+ ├─ spend tx assembly + the signPskt-style wallet-signing bridge
78
+ ├─ wallet WalletAdapter interface + a generic reference implementation (see docs/WALLETS.md)
79
+ ├─ client typed REST clients: indexer, registry, sequencer
80
+ └─ /wasm loadKaspa() — the only environment-specific (Node vs browser) export
81
+ ```
82
+
83
+ Every builder here operates against an **already-deployed** covenant instance — it takes the target's
84
+ current compiled script bytes (read from your indexer, e.g. a UTXO's `redeemScriptHex`) and splices in the
85
+ new state. This package does not include the covenant `.sil` sources or a compiler, and doesn't build the
86
+ genesis/deploy transactions that create a *new* curve, pool, or token — only KRON's own deploy tooling does
87
+ that.
88
+
89
+ Full guide: [`docs/INTEGRATION.md`](docs/INTEGRATION.md). Wallet-adapter contract:
90
+ [`docs/WALLETS.md`](docs/WALLETS.md).
91
+
92
+ ## Verification
93
+
94
+ This package's covenant builders are **ported, not rewritten**, from KRON's own production code
95
+ (`web/src/native/*`), which is exercised by an offline VM-verifier suite in the private KRON repo (covenant
96
+ transitions run against the real Kaspa txscript engine). `scripts/e2e-offline-flow.mjs` exercises the full
97
+ builder chain here offline (quote math, state-splicing, tx assembly, and the wallet-signing bridge) against
98
+ a synthetic template, and checks the one property that matters most for fund safety: signing touches
99
+ **only** the funding input, never a covenant input.
100
+
101
+ What this package does **not** independently verify: full VM-level execution of the covenant scripts (that
102
+ requires the Kaspa `cli-debugger` + the private KRON repo's verifier suite, which also holds the covenant
103
+ sources and compiler this package doesn't ship) and on-chain broadcast (no network access from a clean
104
+ install). If you're integrating funds-critical logic, treat `scripts/e2e-offline-flow.mjs` as a smoke test,
105
+ not a substitute for testing against TN10 yourself before going to production.
106
+
107
+ ```bash
108
+ npm run build && node scripts/smoke-test-node-wasm.mjs # WASM loads + basic SDK calls work in plain Node
109
+ node scripts/e2e-offline-flow.mjs # offline builder-chain sanity check
110
+ ```
111
+
112
+ ## Design notes
113
+
114
+ - **ESM-only in v1.** The vendored wasm-bindgen glue (`kaspa.js`) is ESM with a top-level `import.meta.url`
115
+ reference; a dual CJS build would need its own async-import indirection for marginal benefit given most
116
+ modern bot/backend frameworks are ESM-first. Open an issue if this blocks you.
117
+ - **Namespaced exports**, not flat. `curve/cpCurve.ts` and `native/curveCpTx.ts` both define their own
118
+ `SCALE`; builder names like `buy`/`sell`/`transfer` are generic enough to collide with your own code. So:
119
+ `import * as kron from '@kronsdk/kron-sdk'` then `kron.curve.quoteCpBuy(...)`, `kron.curveCp.buildCpBuy(...)`.
120
+ - **No covenant compiler.** Builders take a target's already-compiled script bytes (`{script, stateStart}`)
121
+ as input rather than compiling from source — read these from your indexer's live UTXO data. This package
122
+ can build transactions against existing KRON tokens; it can't compile or deploy a new curve/pool/token.
123
+
124
+ ## License
125
+
126
+ MIT — see [`LICENSE`](LICENSE). Vendored third-party component (the Kaspa WASM SDK) is ISC-licensed; see
127
+ [`THIRD_PARTY_LICENSES.md`](THIRD_PARTY_LICENSES.md).