hookr-sdk 0.1.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/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # hookr-sdk
2
+
3
+ Build a market on Hookr's live root hook with a custom rule configuration, quote and swap
4
+ through Hookr's router, read markets, and claim payouts. There is exactly one root today:
5
+ `HookrModularHookV6` on Robinhood Chain (id 4663), `ADDRESSES.root`.
6
+
7
+ ## Install
8
+
9
+ ```
10
+ npm install hookr-sdk viem
11
+ ```
12
+
13
+ ## List and validate rules
14
+
15
+ ```ts
16
+ import { RULES, PARAMS, defaultBlock, validateStack } from "hookr-sdk";
17
+
18
+ console.log(RULES.map((r) => r.key)); // ["snipe", "fee", "burn", "lp", "pot"]
19
+
20
+ const stack = [defaultBlock("fee"), defaultBlock("lp")];
21
+ const { ok, errors } = validateStack(stack);
22
+ ```
23
+
24
+ ## Build and send a create-market call
25
+
26
+ ```ts
27
+ import { createWalletClient, http } from "viem";
28
+ import { CHAIN_ID, RPC_URL, buildExistingTokenMarketCall } from "hookr-sdk";
29
+
30
+ const call = buildExistingTokenMarketCall({
31
+ subject: token, quote: usdcAddress, tickSpacing: 60, sqrtPriceX96,
32
+ rules: { baseFeePips: 3_000, blocks: stack },
33
+ protocolRecipient, protocolShareBps, caps, // read from the coordinator and native block first
34
+ });
35
+ const hash = await walletClient.writeContract(call);
36
+ ```
37
+
38
+ `caps` comes from `nativeMechanicsBlock.validateStack(...)`; `protocolShareBps` from
39
+ `marketCoordinator.protocolShareBps(creator)`. See `market.ts`'s module doc for what this
40
+ package computes and what it takes as an already-resolved input.
41
+
42
+ ## Read a market, quote, and swap
43
+
44
+ ```ts
45
+ import { createPublicClient, http } from "viem";
46
+ import { readMarket, poolKeyFor, quoteExactInput, buildExactInputSwapCall } from "hookr-sdk";
47
+
48
+ const client = createPublicClient({ transport: http(RPC_URL) });
49
+ const market = await readMarket(client, poolId);
50
+ const key = poolKeyFor({ subject: market.subject, quote: market.quote, tickSpacing: market.tickSpacing });
51
+ const { amountOut } = await quoteExactInput(client, { key, user, currencyIn: market.quote, amountIn });
52
+ const swapCall = buildExactInputSwapCall({ key, currencyIn: market.quote, amountIn, amountOutMinimum, recipient: user, deadline });
53
+ ```
54
+
55
+ ## Claim
56
+
57
+ ```ts
58
+ import { claimableCall, claimCall } from "hookr-sdk";
59
+
60
+ const owed = await client.readContract(claimableCall(quoteAddress, account));
61
+ if (owed > 0n) await walletClient.writeContract(claimCall(quoteAddress));
62
+ ```
63
+
64
+ ## Rule catalog
65
+
66
+ `RULES` and `PARAMS` are this package's own machine-readable list of the five public rules and
67
+ their bounds, and the same list is served live at https://hookr.fun/api/hooks/catalog together
68
+ with the root and contract addresses, the fee model, the composition limits and prefilled
69
+ builder links for example configurations. Both come from the same source in the Hookr app, and a
70
+ parity test in that repository keeps the package and the app in step.